{
  "version": 3,
  "sources": ["../../src/diff/diff.ts"],
  "sourcesContent": ["/**\n * Represents the possible types of changes that can be made to a document.\n * - 'add': A new property is added\n * - 'update': An existing property's value is changed\n * - 'delete': A property is removed\n */\ntype ChangeType = 'add' | 'update' | 'delete'\n\n/**\n * Represents a single difference between two documents.\n * @property path - Array of strings representing the path to the changed property\n * @property changes - The new value for the property (for add/update) or the old value (for delete)\n * @property type - The type of change that occurred\n */\nexport type Difference<_T> = { path: string[]; changes: any; type: ChangeType }\n\n/**\n * Get the difference between two objects.\n *\n * This function performs a breadth-first comparison between two objects and returns\n * a list of operations needed to transform the first object into the second.\n *\n * @param doc1 - The source object to compare from\n * @param doc2 - The target object to compare to\n * @returns A list of operations (add/update/delete) with their paths and changes\n *\n * @example\n * // Compare two simple objects\n * const original = { name: 'John', age: 30 }\n * const updated = { name: 'John', age: 31, city: 'New York' }\n * const differences = diff(original, updated)\n * // Returns:\n * // [\n * //   { path: ['age'], changes: 31, type: 'update' },\n * //   { path: ['city'], changes: 'New York', type: 'add' }\n * // ]\n *\n * @example\n * // Compare nested objects\n * const original = {\n *   user: { name: 'John', settings: { theme: 'light' } }\n * }\n * const updated = {\n *   user: { name: 'John', settings: { theme: 'dark' } }\n * }\n * const differences = diff(original, updated)\n * // Returns:\n * // [\n * //   { path: ['user', 'settings', 'theme'], changes: 'dark', type: 'update' }\n * // ]\n */\nexport const diff = <T extends Record<string, unknown>>(doc1: Record<string, unknown>, doc2: T) => {\n  const diff: Difference<T>[] = []\n\n  const bfs = (el1: unknown, el2: unknown, prefix = []) => {\n    // If the types are different, we know that the property has been added, deleted or updated\n    if (typeof el1 !== typeof el2) {\n      if (typeof el1 === 'undefined') {\n        diff.push({ path: prefix, changes: el2, type: 'add' })\n        return\n      }\n\n      if (typeof el2 === 'undefined') {\n        diff.push({ path: prefix, changes: el1, type: 'delete' })\n        return\n      }\n\n      diff.push({ path: prefix, changes: el2, type: 'update' })\n      return\n    }\n\n    // We now can assume that el1 and el2 are of the same type\n\n    // For nested objects, we need to recursively check the properties\n    if (typeof el1 === 'object' && typeof el2 === 'object' && el1 !== null && el2 !== null) {\n      const keys = new Set([...Object.keys(el1), ...Object.keys(el2)])\n\n      for (const key of keys) {\n        bfs(el1[key], el2[key], [...prefix, key])\n      }\n      return\n    }\n\n    // For primitives, we can just compare the values\n    if (el1 !== el2) {\n      diff.push({ path: prefix, changes: el2, type: 'update' })\n    }\n  }\n\n  // Run breadth-first search\n  bfs(doc1, doc2)\n  return diff\n}\n"],
  "mappings": "AAmDO,MAAM,OAAO,CAAoC,MAA+B,SAAY;AACjG,QAAMA,QAAwB,CAAC;AAE/B,QAAM,MAAM,CAAC,KAAc,KAAc,SAAS,CAAC,MAAM;AAEvD,QAAI,OAAO,QAAQ,OAAO,KAAK;AAC7B,UAAI,OAAO,QAAQ,aAAa;AAC9B,QAAAA,MAAK,KAAK,EAAE,MAAM,QAAQ,SAAS,KAAK,MAAM,MAAM,CAAC;AACrD;AAAA,MACF;AAEA,UAAI,OAAO,QAAQ,aAAa;AAC9B,QAAAA,MAAK,KAAK,EAAE,MAAM,QAAQ,SAAS,KAAK,MAAM,SAAS,CAAC;AACxD;AAAA,MACF;AAEA,MAAAA,MAAK,KAAK,EAAE,MAAM,QAAQ,SAAS,KAAK,MAAM,SAAS,CAAC;AACxD;AAAA,IACF;AAKA,QAAI,OAAO,QAAQ,YAAY,OAAO,QAAQ,YAAY,QAAQ,QAAQ,QAAQ,MAAM;AACtF,YAAM,OAAO,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,GAAG,GAAG,GAAG,OAAO,KAAK,GAAG,CAAC,CAAC;AAE/D,iBAAW,OAAO,MAAM;AACtB,YAAI,IAAI,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,QAAQ,GAAG,CAAC;AAAA,MAC1C;AACA;AAAA,IACF;AAGA,QAAI,QAAQ,KAAK;AACf,MAAAA,MAAK,KAAK,EAAE,MAAM,QAAQ,SAAS,KAAK,MAAM,SAAS,CAAC;AAAA,IAC1D;AAAA,EACF;AAGA,MAAI,MAAM,IAAI;AACd,SAAOA;AACT;",
  "names": ["diff"]
}
