MCPcopy
hub / github.com/google-labs-code/design.md / diffMaps

Function diffMaps

packages/cli/src/utils.ts:161–184  ·  view source on GitHub ↗
(
  before: Map<string, V>,
  after: Map<string, V>,
)

Source from the content-addressed store, hash-verified

159 * Diff two Maps — returns added, removed, and modified keys.
160 */
161export function diffMaps<V>(
162 before: Map<string, V>,
163 after: Map<string, V>,
164): { added: string[]; removed: string[]; modified: string[] } {
165 const added: string[] = [];
166 const removed: string[] = [];
167 const modified: string[] = [];
168
169 for (const key of after.keys()) {
170 if (!before.has(key)) {
171 added.push(key);
172 } else if (JSON.stringify(before.get(key)) !== JSON.stringify(after.get(key))) {
173 modified.push(key);
174 }
175 }
176
177 for (const key of before.keys()) {
178 if (!after.has(key)) {
179 removed.push(key);
180 }
181 }
182
183 return { added, removed, modified };
184}

Callers 2

runFunction · 0.85
diff.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…