@draht/chord 2026.10.31 → 2026.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/cell.d.ts +7 -7
  2. package/dist/cell.d.ts.map +1 -1
  3. package/dist/cell.js.map +1 -1
  4. package/dist/context/index.d.ts +1 -1
  5. package/dist/context/index.d.ts.map +1 -1
  6. package/dist/context/index.js +1 -1
  7. package/dist/context/index.js.map +1 -1
  8. package/dist/contract.d.ts +51 -52
  9. package/dist/contract.d.ts.map +1 -1
  10. package/dist/contract.js +19 -24
  11. package/dist/contract.js.map +1 -1
  12. package/dist/delta/apply-immutable-trusted.js +3 -4
  13. package/dist/delta/apply-immutable-trusted.js.map +1 -1
  14. package/dist/delta/diff.d.ts.map +1 -1
  15. package/dist/delta/diff.js +5 -3
  16. package/dist/delta/diff.js.map +1 -1
  17. package/dist/delta/index.d.ts +9 -1
  18. package/dist/delta/index.d.ts.map +1 -1
  19. package/dist/delta/index.js +15 -11
  20. package/dist/delta/index.js.map +1 -1
  21. package/dist/delta/pending.d.ts +36 -0
  22. package/dist/delta/pending.d.ts.map +1 -0
  23. package/dist/delta/pending.js +143 -0
  24. package/dist/delta/pending.js.map +1 -0
  25. package/dist/delta/tracker.d.ts +12 -0
  26. package/dist/delta/tracker.d.ts.map +1 -1
  27. package/dist/delta/tracker.js +109 -39
  28. package/dist/delta/tracker.js.map +1 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/object.d.ts +4 -4
  34. package/dist/object.d.ts.map +1 -1
  35. package/dist/object.js +3 -4
  36. package/dist/object.js.map +1 -1
  37. package/dist/output.d.ts +1 -1
  38. package/dist/output.d.ts.map +1 -1
  39. package/dist/output.js +4 -2
  40. package/dist/output.js.map +1 -1
  41. package/dist/remote.d.ts.map +1 -1
  42. package/dist/remote.js +2 -2
  43. package/dist/remote.js.map +1 -1
  44. package/dist/schema.d.ts +8 -4
  45. package/dist/schema.d.ts.map +1 -1
  46. package/dist/schema.js +180 -5
  47. package/dist/schema.js.map +1 -1
  48. package/dist/sqlite/cloudflare.d.ts +2 -0
  49. package/dist/sqlite/cloudflare.d.ts.map +1 -1
  50. package/dist/sqlite/cloudflare.js +10 -0
  51. package/dist/sqlite/cloudflare.js.map +1 -1
  52. package/dist/sqlite/database.d.ts +5 -2
  53. package/dist/sqlite/database.d.ts.map +1 -1
  54. package/dist/sqlite/database.js.map +1 -1
  55. package/dist/sqlite/node.d.ts +4 -1
  56. package/dist/sqlite/node.d.ts.map +1 -1
  57. package/dist/sqlite/node.js +22 -5
  58. package/dist/sqlite/node.js.map +1 -1
  59. package/dist/watch.d.ts +194 -0
  60. package/dist/watch.d.ts.map +1 -0
  61. package/dist/watch.js +383 -0
  62. package/dist/watch.js.map +1 -0
  63. package/dist/wire.d.ts +174 -193
  64. package/dist/wire.d.ts.map +1 -1
  65. package/dist/wire.js +81 -80
  66. package/dist/wire.js.map +1 -1
  67. package/docs/guide.md +15 -15
  68. package/docs/spec.md +8 -8
  69. package/docs/tutorial.md +26 -25
  70. package/package.json +4 -5
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/delta/index.ts"],"names":[],"mappings":"AAIA,MAAM,KAAK,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AA+D/F,gFAAgF;AAEhF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAe,EAAW,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;AAErE;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAA6B,EAAW,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,KAAK,GA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E,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAW,CAAC,CAAC,CAAC;wBACzE,MAAM;oBACP,KAAK,GAAG,EAAE,CAAC;wBACV,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,KAAK;4BAC1B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAgB,CAAC;4BAC1D,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAgB,CAAC,CAAC;wBAC5D,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;wBACnC,MAAM;oBACP,CAAC;oBACD,KAAK,GAAG;wBACP,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAa,CAAC,CAAC,CAAC;wBAC3D,MAAM;gBACR,CAAC;YACF,CAAC;YACD,OAAO,GAAG,CAAC;QACZ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { JsonValue } from \"../json.ts\";\n\nexport type { JsonValue } from \"../json.ts\";\n\nconst isObj = (value: unknown): value is object => value !== null && typeof value === \"object\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// chord/delta — immutable revision tracking and operations over plain JSON.\n//\n// Depends on nothing else in the harness. Session storage, the runtime and the\n// facet host consume it; keep the arrows pointing that way.\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type Seg = string | number;\nexport type Path = readonly Seg[];\nexport type NonEmptyPath = readonly [Seg, ...Seg[]];\n\n/** A path inline, or an id assigned by the encoder on second use. */\nexport type PathRef<P extends Path = Path> = P | number;\n\n/**\n * Tuples are the form — in memory, on the wire, on disk.\n *\n * `r` is the ONLY op that replaces a whole value. `s`/`d`/`a`/`t` cannot target\n * the root: the type forbids it. `p` and `m` may, because a tracked value can\n * itself be an array. Operation shape is not canonical: an array may be emptied by either\n * a replacement or a root splice.\n *\n * `Op` knows nothing about the path dictionary. Interning, id references and\n * omitted paths live in `WireOp` and exist only between `encode` and `decode`.\n */\nexport type Op =\n\t| readonly [\"r\", JsonValue]\n\t| readonly [\"s\", NonEmptyPath, JsonValue]\n\t| readonly [\"d\", NonEmptyPath]\n\t| readonly [\"a\", NonEmptyPath, string]\n\t| readonly [\"t\", NonEmptyPath, number]\n\t| readonly [\"p\", Path, number, number, JsonValue[]]\n\t/** Reorder an array in place: `new[i] = old[permutation[i]]`. */\n\t| readonly [\"m\", Path, number[]];\n\n/**\n * What crosses a boundary. Adds two compressions and nothing else:\n *\n * [\"#\", id, path] defines an id, emitted on a path's SECOND use\n * a numeric PathRef references a previously defined id\n * a shortened tuple reuses the previous op's path; arity disambiguates\n *\n * [\"r\", value] carries no path, so it encodes to itself — which is why isBase\n * works unchanged on either vocabulary.\n */\nexport type WireOp =\n\t| readonly [\"r\", JsonValue]\n\t| readonly [\"s\", PathRef<NonEmptyPath>, JsonValue]\n\t| readonly [\"s\", JsonValue]\n\t| readonly [\"d\", PathRef<NonEmptyPath>]\n\t| readonly [\"d\"]\n\t| readonly [\"a\", PathRef<NonEmptyPath>, string]\n\t| readonly [\"a\", string]\n\t| readonly [\"t\", PathRef<NonEmptyPath>, number]\n\t| readonly [\"t\", number]\n\t| readonly [\"p\", PathRef, number, number, JsonValue[]]\n\t| readonly [\"p\", number, number, JsonValue[]]\n\t| readonly [\"m\", PathRef, number[]]\n\t| readonly [\"m\", number[]]\n\t| readonly [\"#\", number, Path];\n\n// ─── Classification ──────────────────────────────────────────────────────────\n\nexport const isReplace = (op: Op | WireOp): boolean => op[0] === \"r\";\n\n/**\n * A batch begins with a replacement. Flush guarantees `r` is at index 0 or absent,\n * so this is exact rather than a heuristic.\n */\nexport const isBase = (ops: readonly (Op | WireOp)[]): boolean => ops.length > 0 && ops[0]![0] === \"r\";\n\n// ─── Overlap ─────────────────────────────────────────────────────────────────\n\n/**\n * Longest suffix of `a` that is a prefix of `b`. Probes with indexOf and verifies\n * exact substring equality, so the hot loops are native. A hand-written KMP is\n * asymptotically equivalent and much slower in practice.\n *\n * Always correct: the returned n satisfies a.slice(a.length - n) === b.slice(0, n).\n */\nexport function overlap(a: string, b: string, scan: number, probe = 64, maxCandidates = 8): number {\n\tif (a.length === 0 || b.length === 0 || scan === 0) return 0;\n\tconst tail = a.length > scan ? a.slice(a.length - scan) : a;\n\n\t// A probe of length h can only find overlaps of at least h — the head must\n\t// actually occur in `a`. So try a long head first (few candidates, and it\n\t// catches the large overlaps a rolling window produces), then fall back to one\n\t// character, which finds any overlap at the cost of more candidates.\n\t//\n\t// Candidates are bounded because repetitive output — a build log, or any run of\n\t// one character — makes a long head match at thousands of positions. Giving up\n\t// returns 0, which emits a set: larger, never wrong.\n\tfor (const h of [Math.min(probe, b.length), 1]) {\n\t\tconst head = b.slice(0, h);\n\t\tlet tried = 0;\n\t\tfor (let k = tail.indexOf(head); k !== -1; k = tail.indexOf(head, k + 1)) {\n\t\t\tif (++tried > maxCandidates) break;\n\t\t\tconst n = tail.length - k;\n\t\t\tif (n <= b.length && tail.slice(k) === b.slice(0, n)) return n;\n\t\t}\n\t\tif (h === 1) break;\n\t}\n\treturn 0;\n}\n\n// ─── Immutable revision tracking ─────────────────────────────────────────────\n\nexport { diffRevisions } from \"./diff.ts\";\nexport type { Draft } from \"./draft.ts\";\nexport { type Change, type Prepared, type Tracker, track } from \"./tracker.ts\";\n\n// ─── Path safety ─────────────────────────────────────────────────────────────\n\n/**\n * Segments that reach the prototype chain.\n *\n * `JSON.parse` is safe on its own — it makes `__proto__` an own property. What is\n * not safe is `parent[key] = value`, which is exactly what an applier does, and\n * paths are data: `[\"s\", [\"__proto__\", \"isAdmin\"], true]` pollutes\n * `Object.prototype` for the whole process.\n *\n * Ops arrive from a facet, a plugin compartment, or a tool whose details may echo\n * model output, so none of it is trusted input.\n */\nexport const RESERVED_SEGMENTS: ReadonlySet<string> = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nexport class UnsafePathError extends Error {\n\t// Not a parameter property: Node's --experimental-strip-types rejects those,\n\t// and these files are meant to run under it directly.\n\treadonly segment: Seg;\n\tconstructor(segment: Seg) {\n\t\tsuper(`unsafe path segment: ${String(segment)}`);\n\t\tthis.segment = segment;\n\t\tthis.name = \"UnsafePathError\";\n\t}\n}\n\n/**\n * Verb, arity and payload shape for a **decoded** op: paths inline, no `#`, no\n * short forms. `apply` uses this.\n *\n * Validating `Op` against the wire grammar would be laxer than the type: a\n * two-element `[\"s\", value]` would pass, and `apply` would then read the value as\n * a path. Each vocabulary gets the validator that matches it.\n */\nexport function assertValidOp(op: unknown): asserts op is Op {\n\tif (!Array.isArray(op) || op.length === 0) throw new TypeError(\"op is not a tuple\");\n\tswitch (op[0]) {\n\t\tcase \"r\":\n\t\t\tif (op.length !== 2) throw new TypeError(\"r arity\");\n\t\t\treturn;\n\t\tcase \"s\":\n\t\t\tif (op.length !== 3) throw new TypeError(\"s arity\");\n\t\t\tassertPathArg(op[1], true);\n\t\t\treturn;\n\t\tcase \"d\":\n\t\t\tif (op.length !== 2) throw new TypeError(\"d arity\");\n\t\t\tassertPathArg(op[1], true);\n\t\t\treturn;\n\t\tcase \"a\":\n\t\t\tif (op.length !== 3 || typeof op[2] !== \"string\") throw new TypeError(\"a shape\");\n\t\t\tassertPathArg(op[1], true);\n\t\t\treturn;\n\t\tcase \"t\":\n\t\t\tif (op.length !== 3 || !Number.isInteger(op[2]) || op[2] < 0) throw new TypeError(\"t shape\");\n\t\t\tassertPathArg(op[1], true);\n\t\t\treturn;\n\t\tcase \"p\": {\n\t\t\tif (op.length !== 5) throw new TypeError(\"p arity\");\n\t\t\tassertPathArg(op[1]);\n\t\t\tif (!Number.isInteger(op[2]) || op[2] < 0) throw new TypeError(\"p index\");\n\t\t\tif (!Number.isInteger(op[3]) || op[3] < 0) throw new TypeError(\"p remove\");\n\t\t\tif (!Array.isArray(op[4])) throw new TypeError(\"p items\");\n\t\t\treturn;\n\t\t}\n\t\tcase \"m\":\n\t\t\tif (op.length !== 3) throw new TypeError(\"m arity\");\n\t\t\tassertPathArg(op[1]);\n\t\t\tassertPermutation(op[2]);\n\t\t\treturn;\n\t\t// Silently skipping an unknown verb is how a newer producer's op vanishes.\n\t\tdefault:\n\t\t\tthrow new TypeError(`unknown op verb: ${String(op[0])}`);\n\t}\n}\n\nfunction assertPathArg(p: unknown, nonEmpty = false): void {\n\tif (!Array.isArray(p)) throw new TypeError(\"path is not an array\");\n\tif (nonEmpty && p.length === 0) throw new TypeError(\"path is empty\");\n\tassertSafePath(p as Path);\n}\n\nfunction assertPermutation(value: unknown): asserts value is number[] {\n\tif (!Array.isArray(value)) throw new TypeError(\"m permutation is not an array\");\n\tconst seen = new Uint8Array(value.length);\n\tfor (const index of value) {\n\t\tif (!Number.isInteger(index) || index < 0 || index >= value.length || seen[index] !== 0) {\n\t\t\tthrow new TypeError(\"m permutation is not a bijection\");\n\t\t}\n\t\tseen[index] = 1;\n\t}\n}\n\n/** The same, for the wire grammar: ids and short forms are legal here. */\nexport function assertValidWireOp(op: unknown): asserts op is WireOp {\n\tif (!Array.isArray(op) || op.length === 0) throw new TypeError(\"op is not a tuple\");\n\tconst [verb] = op as unknown[];\n\tconst okRef = (r: unknown): void => {\n\t\tif (typeof r === \"number\") {\n\t\t\tif (!Number.isInteger(r) || r < 0) throw new TypeError(\"bad path id\");\n\t\t\treturn;\n\t\t}\n\t\t// A string is not a path. Unchecked, `\"a\".slice(0, -1)` is `\"\"`, so it\n\t\t// resolves to the ROOT and writes there — a path that is not a path, accepted.\n\t\tif (!Array.isArray(r)) throw new TypeError(\"path is not an array\");\n\t\tassertSafePath(r as Path);\n\t};\n\tswitch (verb) {\n\t\tcase \"r\":\n\t\t\tif (op.length !== 2) throw new TypeError(\"r arity\");\n\t\t\treturn;\n\t\tcase \"s\":\n\t\t\tif (op.length === 3) okRef(op[1]);\n\t\t\telse if (op.length !== 2) throw new TypeError(\"s arity\");\n\t\t\treturn;\n\t\tcase \"d\":\n\t\t\tif (op.length === 2) okRef(op[1]);\n\t\t\telse if (op.length !== 1) throw new TypeError(\"d arity\");\n\t\t\treturn;\n\t\tcase \"a\":\n\t\t\tif (op.length === 3) {\n\t\t\t\tokRef(op[1]);\n\t\t\t\tif (typeof op[2] !== \"string\") throw new TypeError(\"a value\");\n\t\t\t} else if (op.length === 2) {\n\t\t\t\tif (typeof op[1] !== \"string\") throw new TypeError(\"a value\");\n\t\t\t} else throw new TypeError(\"a arity\");\n\t\t\treturn;\n\t\tcase \"t\":\n\t\t\tif (op.length === 3) {\n\t\t\t\tokRef(op[1]);\n\t\t\t\tif (!Number.isInteger(op[2]) || (op[2] as number) < 0) throw new TypeError(\"t count\");\n\t\t\t} else if (op.length === 2) {\n\t\t\t\tif (!Number.isInteger(op[1]) || (op[1] as number) < 0) throw new TypeError(\"t count\");\n\t\t\t} else throw new TypeError(\"t arity\");\n\t\t\treturn;\n\t\tcase \"p\": {\n\t\t\tconst [i, r, items] = op.length === 5 ? [op[2], op[3], op[4]] : op.length === 4 ? [op[1], op[2], op[3]] : [];\n\t\t\tif (items === undefined) throw new TypeError(\"p arity\");\n\t\t\tif (op.length === 5) okRef(op[1]);\n\t\t\tif (!Number.isInteger(i) || (i as number) < 0) throw new TypeError(\"p index\");\n\t\t\tif (!Number.isInteger(r) || (r as number) < 0) throw new TypeError(\"p remove\");\n\t\t\tif (!Array.isArray(items)) throw new TypeError(\"p items\");\n\t\t\treturn;\n\t\t}\n\t\tcase \"m\":\n\t\t\tif (op.length === 3) okRef(op[1]);\n\t\t\telse if (op.length !== 2) throw new TypeError(\"m arity\");\n\t\t\tassertPermutation(op[op.length - 1]);\n\t\t\treturn;\n\t\tcase \"#\": {\n\t\t\tif (op.length !== 3 || !Number.isInteger(op[1]) || (op[1] as number) < 0 || !Array.isArray(op[2])) {\n\t\t\t\tthrow new TypeError(\"# shape\");\n\t\t\t}\n\t\t\tassertSafePath(op[2] as Path);\n\t\t\treturn;\n\t\t}\n\t\t// Silently skipping an unknown verb is how a newer producer's op vanishes.\n\t\tdefault:\n\t\t\tthrow new TypeError(`unknown op verb: ${String(verb)}`);\n\t}\n}\n\nexport function assertSafePath(path: Path): void {\n\tfor (const seg of path) {\n\t\tif (typeof seg === \"string\") {\n\t\t\tif (RESERVED_SEGMENTS.has(seg)) throw new UnsafePathError(seg);\n\t\t} else if (!Number.isInteger(seg) || seg < 0) {\n\t\t\tthrow new UnsafePathError(seg);\n\t\t}\n\t}\n}\n\n/**\n * An index may address an existing element or append exactly one past the end.\n *\n * This is not an arbitrary cap — it is what keeps the value a `JsonValue`. A\n * sparse array does not survive a JSON round trip: holes serialise to `null` and\n * return as real properties, so `arr[7] = x` on a length-3 array already produces\n * state a replica cannot match. Rejecting the write is more honest than silently\n * diverging.\n *\n * It also removes the denial of service it would otherwise permit:\n * `[\"s\", [\"xs\", 4294967290], 1]` allocates a 4.29-billion-entry array from one op.\n * Growth stays possible and stays proportional — the tracker already emits\n * `arr.length = n` as a splice of explicit nulls, whose op size grows with the\n * gap, so a large growth costs a large op rather than a small one.\n */\nfunction assertIndexInRange(parent: readonly unknown[], index: number): void {\n\tif (index > parent.length) throw new UnsafePathError(index);\n}\n\n// ─── Applier ─────────────────────────────────────────────────────────────────\n\nexport class PathError extends Error {\n\treadonly path: Path | number;\n\tconstructor(path: Path | number) {\n\t\tsuper(`unresolvable path: ${JSON.stringify(path)}`);\n\t\tthis.path = path;\n\t\tthis.name = \"PathError\";\n\t}\n}\n\n/**\n * Apply ops to a plain mutable value. Returns the value, because `r` replaces it\n * outright and cannot be done in place.\n *\n * Takes decoded ops. Path ids and omitted paths are a wire concern — run\n * `decode` first if the ops came from a boundary.\n */\nexport function apply<T>(target: T | undefined, ops: readonly Op[]): T {\n\treturn applyOps(target, ops);\n}\n\nfunction applyOps<T>(target: T | undefined, ops: readonly Op[]): T {\n\tlet root = target as unknown as JsonValue;\n\n\tfor (const op of ops) {\n\t\tassertValidOp(op);\n\t\tif (op[0] === \"r\") {\n\t\t\t// Adopted, not copied. The consumer owns the batch it was handed.\n\t\t\t//\n\t\t\t// Fanning one batch out to several consumers in-process therefore makes\n\t\t\t// their replicas alias each other. That is an ownership rule, not a\n\t\t\t// defect: copy the batch at the fan-out point, or let each consumer\n\t\t\t// decode its own. A batch that crosses a real boundary is already\n\t\t\t// distinct, because serialisation produces fresh objects.\n\t\t\troot = op[1];\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst path = op[1];\n\t\tassertSafePath(path);\n\n\t\tif (op[0] === \"p\") {\n\t\t\tconst target_ = path.length === 0 ? root : resolve(root, path);\n\t\t\tif (!Array.isArray(target_)) throw new PathError(path);\n\t\t\ttarget_.splice(op[2], op[3]);\n\t\t\tconst chunkSize = 10_000;\n\t\t\tfor (let offset = 0; offset < op[4].length; offset += chunkSize) {\n\t\t\t\ttarget_.splice(op[2] + offset, 0, ...op[4].slice(offset, offset + chunkSize));\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (op[0] === \"m\") {\n\t\t\tconst target_ = path.length === 0 ? root : resolve(root, path);\n\t\t\tif (!Array.isArray(target_) || target_.length !== op[2].length) throw new PathError(path);\n\t\t\tconst previous = target_.slice();\n\t\t\tfor (let index = 0; index < op[2].length; index++) target_[index] = previous[op[2][index]!]!;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// s/d/a/t can never target the root — the type forbids it.\n\t\tconst parent = resolve(root, path.slice(0, -1)) as Record<Seg, JsonValue>;\n\t\tconst key = path[path.length - 1]!;\n\t\tif (Array.isArray(parent)) {\n\t\t\tif (typeof key !== \"number\") throw new UnsafePathError(key);\n\t\t\tassertIndexInRange(parent, key);\n\t\t}\n\t\t// defineProperty rather than assignment: a setter inherited from the prototype\n\t\t// chain would otherwise run on write.\n\t\tconst write = (value: JsonValue) => {\n\t\t\tObject.defineProperty(parent, key, { value, writable: true, enumerable: true, configurable: true });\n\t\t};\n\t\tconst read = (): unknown => (Object.hasOwn(parent, key) ? parent[key] : undefined);\n\t\tswitch (op[0]) {\n\t\t\tcase \"s\":\n\t\t\t\twrite(op[2]);\n\t\t\t\tbreak;\n\t\t\tcase \"d\":\n\t\t\t\tif (Array.isArray(parent)) {\n\t\t\t\t\tif (typeof key !== \"number\" || key >= parent.length) throw new PathError(path);\n\t\t\t\t\t(parent as unknown as JsonValue[]).splice(key, 1);\n\t\t\t\t} else delete parent[key];\n\t\t\t\tbreak;\n\t\t\tcase \"a\": {\n\t\t\t\tconst current = read();\n\t\t\t\tif (typeof current !== \"string\") throw new PathError(path);\n\t\t\t\twrite(`${current}${op[2]}`);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"t\": {\n\t\t\t\tconst current = read();\n\t\t\t\tif (typeof current !== \"string\") throw new PathError(path);\n\t\t\t\twrite(current.slice(op[2]));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn root as unknown as T;\n}\n\n/** Apply one decoded operation batch without mutating the previous immutable value. */\nexport function applyImmutable<T>(target: T | undefined, ops: readonly Op[]): T {\n\treturn applyImmutableBatches(target, [ops]);\n}\n\n/**\n * Apply decoded operation batches as one final-result-only replay.\n *\n * Containers copied for an earlier batch may be mutated while applying a later\n * batch, so this deliberately exposes no intermediate revisions.\n */\nexport function applyImmutableBatches<T>(target: T | undefined, batches: Iterable<readonly Op[]>): T {\n\tlet root = target as unknown as JsonValue;\n\tconst owned = new WeakSet<object>();\n\tfor (const ops of batches) {\n\t\tfor (const op of ops) {\n\t\t\tassertValidOp(op);\n\t\t\tif (op[0] === \"r\") {\n\t\t\t\troot = op[1];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (op[0] === \"p\") {\n\t\t\t\tconst appended = appendCopy(root, op, owned);\n\t\t\t\tif (appended !== undefined) {\n\t\t\t\t\troot = appended;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\troot = copyContainers(root, op[0] === \"p\" || op[0] === \"m\" ? op[1] : op[1].slice(0, -1), owned);\n\t\t\troot = applyOps(root, [op]);\n\t\t}\n\t}\n\treturn root as unknown as T;\n}\n\n/**\n * An append to an array not yet copied in this replay, built as one copy with the items (`concat`) instead of a copy that\n * the insert then grows, which copies it again. `undefined` for any other splice and for any path that is not a plain\n * walk over own properties, which takes the general path and so fails with its errors.\n */\nfunction appendCopy(root: JsonValue, op: Extract<Op, { 0: \"p\" }>, owned: WeakSet<object>): JsonValue | undefined {\n\tconst [, path, index, deleteCount, items] = op;\n\tif (deleteCount !== 0) return undefined;\n\tlet target: JsonValue = root;\n\tfor (const segment of path) {\n\t\tconst valid =\n\t\t\ttypeof segment === \"string\"\n\t\t\t\t? !RESERVED_SEGMENTS.has(segment) && isObj(target) && !Array.isArray(target)\n\t\t\t\t: Number.isInteger(segment) && segment >= 0 && Array.isArray(target);\n\t\tif (!valid || !Object.hasOwn(target as object, segment)) return undefined;\n\t\ttarget = (target as Record<Seg, JsonValue>)[segment]!;\n\t}\n\tif (!Array.isArray(target) || owned.has(target) || index !== target.length) return undefined;\n\tconst appended = target.concat(items);\n\towned.add(appended);\n\tif (path.length === 0) return appended;\n\tconst parentPath = path.slice(0, -1);\n\tconst copiedRoot = copyContainers(root, parentPath, owned);\n\tObject.defineProperty(resolve(copiedRoot, parentPath), path[path.length - 1]!, {\n\t\tvalue: appended,\n\t\twritable: true,\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t});\n\treturn copiedRoot;\n}\n\nfunction copyContainers(root: JsonValue, path: Path, owned: WeakSet<object>): JsonValue {\n\tconst copy = (value: JsonValue): JsonValue[] | Record<string, JsonValue> => {\n\t\tif (Array.isArray(value)) return value.slice();\n\t\tif (!isObj(value)) throw new PathError(path);\n\t\tconst result = Object.create(Object.getPrototypeOf(value) === null ? null : Object.prototype) as Record<\n\t\t\tstring,\n\t\t\tJsonValue\n\t\t>;\n\t\tfor (const key of Object.keys(value)) {\n\t\t\tObject.defineProperty(result, key, {\n\t\t\t\tvalue: (value as Record<string, JsonValue>)[key],\n\t\t\t\twritable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t};\n\tif (!isObj(root)) throw new PathError(path);\n\tlet copiedRoot: JsonValue[] | Record<string, JsonValue>;\n\tif (owned.has(root)) copiedRoot = root as JsonValue[] | Record<string, JsonValue>;\n\telse {\n\t\tcopiedRoot = copy(root);\n\t\towned.add(copiedRoot);\n\t}\n\tlet destination = copiedRoot;\n\tfor (const segment of path) {\n\t\tif (!Object.hasOwn(destination, segment)) throw new PathError(path);\n\t\tif (Array.isArray(destination) && typeof segment !== \"number\") throw new UnsafePathError(segment);\n\t\tconst child = (destination as Record<Seg, JsonValue>)[segment]!;\n\t\tif (!isObj(child)) throw new PathError(path);\n\t\tif (owned.has(child)) {\n\t\t\tdestination = child as JsonValue[] | Record<string, JsonValue>;\n\t\t\tcontinue;\n\t\t}\n\t\tconst copiedChild = copy(child);\n\t\tObject.defineProperty(destination, segment, {\n\t\t\tvalue: copiedChild,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t\towned.add(copiedChild);\n\t\tdestination = copiedChild;\n\t}\n\treturn copiedRoot;\n}\n\nfunction resolveValue(root: JsonValue, path: Path): JsonValue {\n\tlet node: JsonValue = root;\n\tfor (const seg of path) {\n\t\tif (!isObj(node)) throw new PathError(path);\n\t\tif (Array.isArray(node) && typeof seg !== \"number\") throw new UnsafePathError(seg);\n\t\t// Own properties only: an inherited getter must not run, and a walk must not\n\t\t// escape the value into the prototype chain.\n\t\tif (!Object.hasOwn(node, seg as PropertyKey)) throw new PathError(path);\n\t\tnode = (node as Record<Seg, JsonValue>)[seg]!;\n\t}\n\treturn node;\n}\n\nfunction resolve(root: JsonValue, path: Path): JsonValue {\n\tconst node = resolveValue(root, path);\n\tif (!isObj(node)) throw new PathError(path);\n\treturn node;\n}\n\n// ─── Codec ───────────────────────────────────────────────────────────────────\n//\n// Path interning and arity omission live between the tracker and a boundary;\n// `Op` and `apply` know nothing about them.\n//\n// Consecutive batches of one encoder may be concatenated into one batch (links\n// coalesce waiting state this way): only path ids span batches, and every batch\n// starts with an explicit path.\n//\n// ONE PAIR PER INDEPENDENT STATE STREAM. Every decoder must observe exactly the\n// batches encoded by its matching encoder, beginning with that state's base.\n// Sharing a transport connection does not make separately hydrated states one\n// stream.\n\nconst pathKey = (path: Path): string => JSON.stringify(path);\n\nexport interface Encoder {\n\tencode(ops: readonly Op[]): WireOp[];\n}\n\n/**\n * Intern on SECOND use. A definition costs more than the path it replaces, so\n * interning on first use loses on the many paths written exactly once.\n */\nexport function encoder(): Encoder {\n\tconst seen = new Set<string>();\n\tconst ids = new Map<string, number>();\n\tlet nextId = 0;\n\tlet previous: string | undefined; // last path in THIS batch\n\n\treturn {\n\t\tencode(ops) {\n\t\t\t// Arity omission is scoped to a batch. Letting it span batches would make\n\t\t\t// a batch's first op depend on the previous batch's last one, so a reader\n\t\t\t// that skips or reorders a batch decodes into the wrong path. Ids are the\n\t\t\t// only cross-batch state, and the dictionary makes those explicit.\n\t\t\tprevious = undefined;\n\t\t\tconst out: WireOp[] = [];\n\t\t\tfor (const op of ops) {\n\t\t\t\tif (op[0] === \"r\") {\n\t\t\t\t\tout.push(op);\n\t\t\t\t\t// A base batch is a RECOVERY POINT: a reader replays from the last one\n\t\t\t\t\t// with a fresh decoder. So everything after it must be self-contained.\n\t\t\t\t\t// Keeping ids across a replacement emits references to definitions the\n\t\t\t\t\t// reader never saw — recovery fails with an unresolvable path id.\n\t\t\t\t\tseen.clear();\n\t\t\t\t\tids.clear();\n\t\t\t\t\tnextId = 0;\n\t\t\t\t\tprevious = undefined;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst path = op[1];\n\t\t\t\tconst key = pathKey(path);\n\n\t\t\t\t// Same path as the previous op: drop the ref entirely.\n\t\t\t\tif (key === previous) {\n\t\t\t\t\tswitch (op[0]) {\n\t\t\t\t\t\tcase \"s\":\n\t\t\t\t\t\t\tout.push([\"s\", op[2]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"d\":\n\t\t\t\t\t\t\tout.push([\"d\"]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"a\":\n\t\t\t\t\t\t\tout.push([\"a\", op[2]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"t\":\n\t\t\t\t\t\t\tout.push([\"t\", op[2]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"p\":\n\t\t\t\t\t\t\tout.push([\"p\", op[2], op[3], op[4]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"m\":\n\t\t\t\t\t\t\tout.push([\"m\", op[2]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet ref: PathRef = path;\n\t\t\t\tconst existing = ids.get(key);\n\t\t\t\tif (existing !== undefined) {\n\t\t\t\t\tref = existing;\n\t\t\t\t} else if (seen.has(key)) {\n\t\t\t\t\tconst id = nextId++;\n\t\t\t\t\tids.set(key, id);\n\t\t\t\t\tout.push([\"#\", id, path]); // second use: define, then reference\n\t\t\t\t\tref = id;\n\t\t\t\t} else {\n\t\t\t\t\tseen.add(key); // first use: inline\n\t\t\t\t}\n\n\t\t\t\tswitch (op[0]) {\n\t\t\t\t\tcase \"s\":\n\t\t\t\t\t\tout.push([\"s\", ref as PathRef<NonEmptyPath>, op[2]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"d\":\n\t\t\t\t\t\tout.push([\"d\", ref as PathRef<NonEmptyPath>]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"a\":\n\t\t\t\t\t\tout.push([\"a\", ref as PathRef<NonEmptyPath>, op[2]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"t\":\n\t\t\t\t\t\tout.push([\"t\", ref as PathRef<NonEmptyPath>, op[2]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"p\":\n\t\t\t\t\t\tout.push([\"p\", ref, op[2], op[3], op[4]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"m\":\n\t\t\t\t\t\tout.push([\"m\", ref, op[2]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tprevious = key;\n\t\t\t}\n\t\t\treturn out;\n\t\t},\n\t};\n}\n\nexport interface Decoder {\n\t/** Ops as received: each is validated (`assertValidWireOp`) before use. */\n\tdecode(wire: readonly unknown[]): Op[];\n}\n\nexport function decoder(): Decoder {\n\tconst paths = new Map<number, Path>();\n\n\treturn {\n\t\tdecode(wire) {\n\t\t\tlet previous: Path | undefined; // scoped to the batch, as in encode\n\t\t\tconst out: Op[] = [];\n\t\t\tfor (const op of wire) {\n\t\t\t\tassertValidWireOp(op);\n\t\t\t\tif (op[0] === \"#\") {\n\t\t\t\t\tassertSafePath(op[2]);\n\t\t\t\t\tpaths.set(op[1], op[2]);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (op[0] === \"r\") {\n\t\t\t\t\tout.push(op);\n\t\t\t\t\tpaths.clear();\n\t\t\t\t\tprevious = undefined;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Arity tells us whether a ref is present: the short forms omit it.\n\t\t\t\tconst short =\n\t\t\t\t\t(op[0] === \"d\" && op.length === 1) ||\n\t\t\t\t\t(op[0] !== \"d\" && op[0] !== \"p\" && op.length === 2) ||\n\t\t\t\t\t(op[0] === \"p\" && op.length === 4);\n\n\t\t\t\tlet path: Path;\n\t\t\t\tif (short) {\n\t\t\t\t\tif (previous === undefined) throw new PathError([]);\n\t\t\t\t\tpath = previous;\n\t\t\t\t} else {\n\t\t\t\t\tconst ref = op[1] as PathRef;\n\t\t\t\t\tif (typeof ref === \"number\") {\n\t\t\t\t\t\tconst resolved = paths.get(ref);\n\t\t\t\t\t\tif (resolved === undefined) throw new PathError(ref);\n\t\t\t\t\t\tpath = resolved;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpath = ref;\n\t\t\t\t\t}\n\t\t\t\t\tprevious = path;\n\t\t\t\t}\n\n\t\t\t\tif (op[0] !== \"p\" && op[0] !== \"m\" && path.length === 0) throw new PathError(path);\n\t\t\t\tswitch (op[0]) {\n\t\t\t\t\tcase \"s\":\n\t\t\t\t\t\tout.push([\"s\", path as NonEmptyPath, (short ? op[1] : op[2]) as JsonValue]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"d\":\n\t\t\t\t\t\tout.push([\"d\", path as NonEmptyPath]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"a\":\n\t\t\t\t\t\tout.push([\"a\", path as NonEmptyPath, (short ? op[1] : op[2]) as string]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"t\":\n\t\t\t\t\t\tout.push([\"t\", path as NonEmptyPath, (short ? op[1] : op[2]) as number]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"p\": {\n\t\t\t\t\t\tconst [i, r, items] = short\n\t\t\t\t\t\t\t? [op[1] as number, op[2] as number, op[3] as JsonValue[]]\n\t\t\t\t\t\t\t: [op[2] as number, op[3] as number, op[4] as JsonValue[]];\n\t\t\t\t\t\tout.push([\"p\", path, i, r, items]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"m\":\n\t\t\t\t\t\tout.push([\"m\", path, (short ? op[1] : op[2]) as number[]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn out;\n\t\t},\n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EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAa,CAAC,CAAC,CAAC;wBAC3D,MAAM;gBACR,CAAC;YACF,CAAC;YACD,OAAO,GAAG,CAAC;QACZ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { JsonValue } from \"../json.ts\";\n\nexport type { JsonValue } from \"../json.ts\";\n\nconst isObj = (value: unknown): value is object => value !== null && typeof value === \"object\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// chord/delta — immutable revision tracking and operations over plain JSON.\n//\n// Depends on nothing else in the harness. Session storage, the runtime and the\n// facet host consume it; keep the arrows pointing that way.\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type Seg = string | number;\nexport type Path = readonly Seg[];\nexport type NonEmptyPath = readonly [Seg, ...Seg[]];\n\n/** A path inline, or an id assigned by the encoder on second use. */\nexport type PathRef<P extends Path = Path> = P | number;\n\n/**\n * Tuples are the form — in memory, on the wire, on disk.\n *\n * `r` is the ONLY op that replaces a whole value. `s`/`d`/`a`/`t` cannot target\n * the root: the type forbids it. `p` and `m` may, because a tracked value can\n * itself be an array. Operation shape is not canonical: an array may be emptied by either\n * a replacement or a root splice.\n *\n * `Op` knows nothing about the path dictionary. Interning, id references and\n * omitted paths live in `WireOp` and exist only between `encode` and `decode`.\n */\nexport type Op =\n\t| readonly [\"r\", JsonValue]\n\t| readonly [\"s\", NonEmptyPath, JsonValue]\n\t| readonly [\"d\", NonEmptyPath]\n\t| readonly [\"a\", NonEmptyPath, string]\n\t| readonly [\"t\", NonEmptyPath, number]\n\t| readonly [\"p\", Path, number, number, JsonValue[]]\n\t/** Reorder an array in place: `new[i] = old[permutation[i]]`. */\n\t| readonly [\"m\", Path, number[]];\n\n/**\n * What crosses a boundary. Adds two compressions and nothing else:\n *\n * [\"#\", id, path] defines an id, emitted on a path's SECOND use\n * a numeric PathRef references a previously defined id\n * a shortened tuple reuses the previous op's path; arity disambiguates\n *\n * [\"r\", value] carries no path, so it encodes to itself — which is why isBase\n * works unchanged on either vocabulary.\n */\nexport type WireOp =\n\t| readonly [\"r\", JsonValue]\n\t| readonly [\"s\", PathRef<NonEmptyPath>, JsonValue]\n\t| readonly [\"s\", JsonValue]\n\t| readonly [\"d\", PathRef<NonEmptyPath>]\n\t| readonly [\"d\"]\n\t| readonly [\"a\", PathRef<NonEmptyPath>, string]\n\t| readonly [\"a\", string]\n\t| readonly [\"t\", PathRef<NonEmptyPath>, number]\n\t| readonly [\"t\", number]\n\t| readonly [\"p\", PathRef, number, number, JsonValue[]]\n\t| readonly [\"p\", number, number, JsonValue[]]\n\t| readonly [\"m\", PathRef, number[]]\n\t| readonly [\"m\", number[]]\n\t| readonly [\"#\", number, Path];\n\n// ─── Classification ──────────────────────────────────────────────────────────\n\nexport const isReplace = (op: Op | WireOp): boolean => op[0] === \"r\";\n\n/**\n * A batch begins with a replacement. Flush guarantees `r` is at index 0 or absent,\n * so this is exact rather than a heuristic.\n */\nexport const isBase = (ops: readonly (Op | WireOp)[]): boolean => ops.length > 0 && ops[0]![0] === \"r\";\n\n// ─── Overlap ─────────────────────────────────────────────────────────────────\n\n/**\n * Longest suffix of `a` that is a prefix of `b`. Probes with indexOf and verifies\n * exact substring equality, so the hot loops are native. A hand-written KMP is\n * asymptotically equivalent and much slower in practice.\n *\n * Always correct: the returned n satisfies a.slice(a.length - n) === b.slice(0, n).\n */\nexport function overlap(a: string, b: string, scan: number, probe = 64, maxCandidates = 8): number {\n\tif (a.length === 0 || b.length === 0 || scan === 0) return 0;\n\tconst tail = a.length > scan ? a.slice(a.length - scan) : a;\n\n\t// A probe of length h can only find overlaps of at least h — the head must\n\t// actually occur in `a`. So try a long head first (few candidates, and it\n\t// catches the large overlaps a rolling window produces), then fall back to one\n\t// character, which finds any overlap at the cost of more candidates.\n\t//\n\t// Candidates are bounded because repetitive output — a build log, or any run of\n\t// one character — makes a long head match at thousands of positions. Giving up\n\t// returns 0, which emits a set: larger, never wrong.\n\tfor (const h of [Math.min(probe, b.length), 1]) {\n\t\tconst head = b.slice(0, h);\n\t\tlet tried = 0;\n\t\tfor (let k = tail.indexOf(head); k !== -1; k = tail.indexOf(head, k + 1)) {\n\t\t\tif (++tried > maxCandidates) break;\n\t\t\tconst n = tail.length - k;\n\t\t\tif (n <= b.length && tail.slice(k) === b.slice(0, n)) return n;\n\t\t}\n\t\tif (h === 1) break;\n\t}\n\treturn 0;\n}\n\n/**\n * `text.slice(start, end)` as a string of its own. V8 represents a slice of 13 or more characters as a view that keeps\n * all of `text` alive, so an append op cut from a long, growing string would retain that whole string for as long as\n * the op lives: in a delta chain, a watch backlog, or a value built by applying the op. Appending a character and\n * slicing it off again makes V8 copy just the slice.\n */\nexport function ownedSlice(text: string, start: number, end = text.length): string {\n\treturn `${text.slice(start, end)} `.slice(0, -1);\n}\n\n// ─── Immutable revision tracking ─────────────────────────────────────────────\n\nexport { diffRevisions } from \"./diff.ts\";\nexport type { Draft } from \"./draft.ts\";\nexport { appendText, type Change, type Prepared, type StringKeys, type Tracker, track } from \"./tracker.ts\";\n\n// ─── Pending ops of a slow consumer ──────────────────────────────────────────\n\nexport { PendingOps, type PendingTake } from \"./pending.ts\";\n\n// ─── Path safety ─────────────────────────────────────────────────────────────\n\n/**\n * Segments that reach the prototype chain.\n *\n * `JSON.parse` is safe on its own — it makes `__proto__` an own property. What is\n * not safe is `parent[key] = value`, which is exactly what an applier does, and\n * paths are data: `[\"s\", [\"__proto__\", \"isAdmin\"], true]` pollutes\n * `Object.prototype` for the whole process.\n *\n * Ops arrive from a facet, a plugin compartment, or a tool whose details may echo\n * model output, so none of it is trusted input.\n */\nexport const RESERVED_SEGMENTS: ReadonlySet<string> = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nexport class UnsafePathError extends Error {\n\t// Not a parameter property: Node's --experimental-strip-types rejects those,\n\t// and these files are meant to run under it directly.\n\treadonly segment: Seg;\n\tconstructor(segment: Seg) {\n\t\tsuper(`unsafe path segment: ${String(segment)}`);\n\t\tthis.segment = segment;\n\t\tthis.name = \"UnsafePathError\";\n\t}\n}\n\n/**\n * Verb, arity and payload shape for a **decoded** op: paths inline, no `#`, no\n * short forms. `apply` uses this.\n *\n * Validating `Op` against the wire grammar would be laxer than the type: a\n * two-element `[\"s\", value]` would pass, and `apply` would then read the value as\n * a path. Each vocabulary gets the validator that matches it.\n */\nexport function assertValidOp(op: unknown): asserts op is Op {\n\tif (!Array.isArray(op) || op.length === 0) throw new TypeError(\"op is not a tuple\");\n\tswitch (op[0]) {\n\t\tcase \"r\":\n\t\t\tif (op.length !== 2) throw new TypeError(\"r arity\");\n\t\t\treturn;\n\t\tcase \"s\":\n\t\t\tif (op.length !== 3) throw new TypeError(\"s arity\");\n\t\t\tassertPathArg(op[1], true);\n\t\t\treturn;\n\t\tcase \"d\":\n\t\t\tif (op.length !== 2) throw new TypeError(\"d arity\");\n\t\t\tassertPathArg(op[1], true);\n\t\t\treturn;\n\t\tcase \"a\":\n\t\t\tif (op.length !== 3 || typeof op[2] !== \"string\") throw new TypeError(\"a shape\");\n\t\t\tassertPathArg(op[1], true);\n\t\t\treturn;\n\t\tcase \"t\":\n\t\t\tif (op.length !== 3 || !Number.isInteger(op[2]) || op[2] < 0) throw new TypeError(\"t shape\");\n\t\t\tassertPathArg(op[1], true);\n\t\t\treturn;\n\t\tcase \"p\": {\n\t\t\tif (op.length !== 5) throw new TypeError(\"p arity\");\n\t\t\tassertPathArg(op[1]);\n\t\t\tif (!Number.isInteger(op[2]) || op[2] < 0) throw new TypeError(\"p index\");\n\t\t\tif (!Number.isInteger(op[3]) || op[3] < 0) throw new TypeError(\"p remove\");\n\t\t\tif (!Array.isArray(op[4])) throw new TypeError(\"p items\");\n\t\t\treturn;\n\t\t}\n\t\tcase \"m\":\n\t\t\tif (op.length !== 3) throw new TypeError(\"m arity\");\n\t\t\tassertPathArg(op[1]);\n\t\t\tassertPermutation(op[2]);\n\t\t\treturn;\n\t\t// Silently skipping an unknown verb is how a newer producer's op vanishes.\n\t\tdefault:\n\t\t\tthrow new TypeError(`unknown op verb: ${String(op[0])}`);\n\t}\n}\n\nfunction assertPathArg(p: unknown, nonEmpty = false): void {\n\tif (!Array.isArray(p)) throw new TypeError(\"path is not an array\");\n\tif (nonEmpty && p.length === 0) throw new TypeError(\"path is empty\");\n\tassertSafePath(p as Path);\n}\n\nfunction assertPermutation(value: unknown): asserts value is number[] {\n\tif (!Array.isArray(value)) throw new TypeError(\"m permutation is not an array\");\n\tconst seen = new Uint8Array(value.length);\n\tfor (const index of value) {\n\t\tif (!Number.isInteger(index) || index < 0 || index >= value.length || seen[index] !== 0) {\n\t\t\tthrow new TypeError(\"m permutation is not a bijection\");\n\t\t}\n\t\tseen[index] = 1;\n\t}\n}\n\n/** The same, for the wire grammar: ids and short forms are legal here. */\nexport function assertValidWireOp(op: unknown): asserts op is WireOp {\n\tif (!Array.isArray(op) || op.length === 0) throw new TypeError(\"op is not a tuple\");\n\tconst [verb] = op as unknown[];\n\tconst okRef = (r: unknown): void => {\n\t\tif (typeof r === \"number\") {\n\t\t\tif (!Number.isInteger(r) || r < 0) throw new TypeError(\"bad path id\");\n\t\t\treturn;\n\t\t}\n\t\t// A string is not a path. Unchecked, `\"a\".slice(0, -1)` is `\"\"`, so it\n\t\t// resolves to the ROOT and writes there — a path that is not a path, accepted.\n\t\tif (!Array.isArray(r)) throw new TypeError(\"path is not an array\");\n\t\tassertSafePath(r as Path);\n\t};\n\tswitch (verb) {\n\t\tcase \"r\":\n\t\t\tif (op.length !== 2) throw new TypeError(\"r arity\");\n\t\t\treturn;\n\t\tcase \"s\":\n\t\t\tif (op.length === 3) okRef(op[1]);\n\t\t\telse if (op.length !== 2) throw new TypeError(\"s arity\");\n\t\t\treturn;\n\t\tcase \"d\":\n\t\t\tif (op.length === 2) okRef(op[1]);\n\t\t\telse if (op.length !== 1) throw new TypeError(\"d arity\");\n\t\t\treturn;\n\t\tcase \"a\":\n\t\t\tif (op.length === 3) {\n\t\t\t\tokRef(op[1]);\n\t\t\t\tif (typeof op[2] !== \"string\") throw new TypeError(\"a value\");\n\t\t\t} else if (op.length === 2) {\n\t\t\t\tif (typeof op[1] !== \"string\") throw new TypeError(\"a value\");\n\t\t\t} else throw new TypeError(\"a arity\");\n\t\t\treturn;\n\t\tcase \"t\":\n\t\t\tif (op.length === 3) {\n\t\t\t\tokRef(op[1]);\n\t\t\t\tif (!Number.isInteger(op[2]) || (op[2] as number) < 0) throw new TypeError(\"t count\");\n\t\t\t} else if (op.length === 2) {\n\t\t\t\tif (!Number.isInteger(op[1]) || (op[1] as number) < 0) throw new TypeError(\"t count\");\n\t\t\t} else throw new TypeError(\"t arity\");\n\t\t\treturn;\n\t\tcase \"p\": {\n\t\t\tconst [i, r, items] = op.length === 5 ? [op[2], op[3], op[4]] : op.length === 4 ? [op[1], op[2], op[3]] : [];\n\t\t\tif (items === undefined) throw new TypeError(\"p arity\");\n\t\t\tif (op.length === 5) okRef(op[1]);\n\t\t\tif (!Number.isInteger(i) || (i as number) < 0) throw new TypeError(\"p index\");\n\t\t\tif (!Number.isInteger(r) || (r as number) < 0) throw new TypeError(\"p remove\");\n\t\t\tif (!Array.isArray(items)) throw new TypeError(\"p items\");\n\t\t\treturn;\n\t\t}\n\t\tcase \"m\":\n\t\t\tif (op.length === 3) okRef(op[1]);\n\t\t\telse if (op.length !== 2) throw new TypeError(\"m arity\");\n\t\t\tassertPermutation(op[op.length - 1]);\n\t\t\treturn;\n\t\tcase \"#\": {\n\t\t\tif (op.length !== 3 || !Number.isInteger(op[1]) || (op[1] as number) < 0 || !Array.isArray(op[2])) {\n\t\t\t\tthrow new TypeError(\"# shape\");\n\t\t\t}\n\t\t\tassertSafePath(op[2] as Path);\n\t\t\treturn;\n\t\t}\n\t\t// Silently skipping an unknown verb is how a newer producer's op vanishes.\n\t\tdefault:\n\t\t\tthrow new TypeError(`unknown op verb: ${String(verb)}`);\n\t}\n}\n\nexport function assertSafePath(path: Path): void {\n\tfor (const seg of path) {\n\t\tif (typeof seg === \"string\") {\n\t\t\tif (RESERVED_SEGMENTS.has(seg)) throw new UnsafePathError(seg);\n\t\t} else if (!Number.isInteger(seg) || seg < 0) {\n\t\t\tthrow new UnsafePathError(seg);\n\t\t}\n\t}\n}\n\n/**\n * An index may address an existing element or append exactly one past the end.\n *\n * This is not an arbitrary cap — it is what keeps the value a `JsonValue`. A\n * sparse array does not survive a JSON round trip: holes serialise to `null` and\n * return as real properties, so `arr[7] = x` on a length-3 array already produces\n * state a replica cannot match. Rejecting the write is more honest than silently\n * diverging.\n *\n * It also removes the denial of service it would otherwise permit:\n * `[\"s\", [\"xs\", 4294967290], 1]` allocates a 4.29-billion-entry array from one op.\n * Growth stays possible and stays proportional — the tracker already emits\n * `arr.length = n` as a splice of explicit nulls, whose op size grows with the\n * gap, so a large growth costs a large op rather than a small one.\n */\nfunction assertIndexInRange(parent: readonly unknown[], index: number): void {\n\tif (index > parent.length) throw new UnsafePathError(index);\n}\n\n// ─── Applier ─────────────────────────────────────────────────────────────────\n\nexport class PathError extends Error {\n\treadonly path: Path | number;\n\tconstructor(path: Path | number) {\n\t\tsuper(`unresolvable path: ${JSON.stringify(path)}`);\n\t\tthis.path = path;\n\t\tthis.name = \"PathError\";\n\t}\n}\n\n/**\n * Apply ops to a plain mutable value. Returns the value, because `r` replaces it\n * outright and cannot be done in place.\n *\n * Takes decoded ops. Path ids and omitted paths are a wire concern — run\n * `decode` first if the ops came from a boundary.\n */\nexport function apply<T>(target: T | undefined, ops: readonly Op[]): T {\n\treturn applyOps(target, ops);\n}\n\nfunction applyOps<T>(target: T | undefined, ops: readonly Op[]): T {\n\tlet root = target as unknown as JsonValue;\n\n\tfor (const op of ops) {\n\t\tassertValidOp(op);\n\t\tif (op[0] === \"r\") {\n\t\t\t// Adopted, not copied. The consumer owns the batch it was handed.\n\t\t\t//\n\t\t\t// Fanning one batch out to several consumers in-process therefore makes\n\t\t\t// their replicas alias each other. That is an ownership rule, not a\n\t\t\t// defect: copy the batch at the fan-out point, or let each consumer\n\t\t\t// decode its own. A batch that crosses a real boundary is already\n\t\t\t// distinct, because serialisation produces fresh objects.\n\t\t\troot = op[1];\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst path = op[1];\n\t\tassertSafePath(path);\n\n\t\tif (op[0] === \"p\") {\n\t\t\tconst target_ = path.length === 0 ? root : resolve(root, path);\n\t\t\tif (!Array.isArray(target_)) throw new PathError(path);\n\t\t\ttarget_.splice(op[2], op[3]);\n\t\t\tconst chunkSize = 10_000;\n\t\t\tfor (let offset = 0; offset < op[4].length; offset += chunkSize) {\n\t\t\t\ttarget_.splice(op[2] + offset, 0, ...op[4].slice(offset, offset + chunkSize));\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (op[0] === \"m\") {\n\t\t\tconst target_ = path.length === 0 ? root : resolve(root, path);\n\t\t\tif (!Array.isArray(target_) || target_.length !== op[2].length) throw new PathError(path);\n\t\t\tconst previous = target_.slice();\n\t\t\tfor (let index = 0; index < op[2].length; index++) target_[index] = previous[op[2][index]!]!;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// s/d/a/t can never target the root — the type forbids it.\n\t\tconst parent = resolve(root, path.slice(0, -1)) as Record<Seg, JsonValue>;\n\t\tconst key = path[path.length - 1]!;\n\t\tif (Array.isArray(parent)) {\n\t\t\tif (typeof key !== \"number\") throw new UnsafePathError(key);\n\t\t\tassertIndexInRange(parent, key);\n\t\t}\n\t\t// defineProperty rather than assignment: a setter inherited from the prototype\n\t\t// chain would otherwise run on write.\n\t\tconst write = (value: JsonValue) => {\n\t\t\tObject.defineProperty(parent, key, { value, writable: true, enumerable: true, configurable: true });\n\t\t};\n\t\tconst read = (): unknown => (Object.hasOwn(parent, key) ? parent[key] : undefined);\n\t\tswitch (op[0]) {\n\t\t\tcase \"s\":\n\t\t\t\twrite(op[2]);\n\t\t\t\tbreak;\n\t\t\tcase \"d\":\n\t\t\t\tif (Array.isArray(parent)) {\n\t\t\t\t\tif (typeof key !== \"number\" || key >= parent.length) throw new PathError(path);\n\t\t\t\t\t(parent as unknown as JsonValue[]).splice(key, 1);\n\t\t\t\t} else delete parent[key];\n\t\t\t\tbreak;\n\t\t\tcase \"a\": {\n\t\t\t\tconst current = read();\n\t\t\t\tif (typeof current !== \"string\") throw new PathError(path);\n\t\t\t\twrite(`${current}${op[2]}`);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"t\": {\n\t\t\t\tconst current = read();\n\t\t\t\tif (typeof current !== \"string\") throw new PathError(path);\n\t\t\t\twrite(current.slice(op[2]));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn root as unknown as T;\n}\n\n/** Apply one decoded operation batch without mutating the previous immutable value. */\nexport function applyImmutable<T>(target: T | undefined, ops: readonly Op[]): T {\n\treturn applyImmutableBatches(target, [ops]);\n}\n\n/**\n * Apply decoded operation batches as one final-result-only replay.\n *\n * Containers copied for an earlier batch may be mutated while applying a later\n * batch, so this deliberately exposes no intermediate revisions.\n */\nexport function applyImmutableBatches<T>(target: T | undefined, batches: Iterable<readonly Op[]>): T {\n\tlet root = target as unknown as JsonValue;\n\tconst owned = new WeakSet<object>();\n\tfor (const ops of batches) {\n\t\tfor (const op of ops) {\n\t\t\tassertValidOp(op);\n\t\t\tif (op[0] === \"r\") {\n\t\t\t\troot = op[1];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (op[0] === \"p\") {\n\t\t\t\tconst appended = appendCopy(root, op, owned);\n\t\t\t\tif (appended !== undefined) {\n\t\t\t\t\troot = appended;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\troot = copyContainers(root, op[0] === \"p\" || op[0] === \"m\" ? op[1] : op[1].slice(0, -1), owned);\n\t\t\troot = applyOps(root, [op]);\n\t\t}\n\t}\n\treturn root as unknown as T;\n}\n\n/**\n * An append to an array not yet copied in this replay, built as one copy with the items (`concat`) instead of a copy that\n * the insert then grows, which copies it again. `undefined` for any other splice and for any path that is not a plain\n * walk over own properties, which takes the general path and so fails with its errors.\n */\nfunction appendCopy(root: JsonValue, op: Extract<Op, { 0: \"p\" }>, owned: WeakSet<object>): JsonValue | undefined {\n\tconst [, path, index, deleteCount, items] = op;\n\tif (deleteCount !== 0) return undefined;\n\tlet target: JsonValue = root;\n\tfor (const segment of path) {\n\t\tconst valid =\n\t\t\ttypeof segment === \"string\"\n\t\t\t\t? !RESERVED_SEGMENTS.has(segment) && isObj(target) && !Array.isArray(target)\n\t\t\t\t: Number.isInteger(segment) && segment >= 0 && Array.isArray(target);\n\t\tif (!valid || !Object.hasOwn(target as object, segment)) return undefined;\n\t\ttarget = (target as Record<Seg, JsonValue>)[segment]!;\n\t}\n\tif (!Array.isArray(target) || owned.has(target) || index !== target.length) return undefined;\n\tconst appended = target.concat(items);\n\towned.add(appended);\n\tif (path.length === 0) return appended;\n\tconst parentPath = path.slice(0, -1);\n\tconst copiedRoot = copyContainers(root, parentPath, owned);\n\tObject.defineProperty(resolve(copiedRoot, parentPath), path[path.length - 1]!, {\n\t\tvalue: appended,\n\t\twritable: true,\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t});\n\treturn copiedRoot;\n}\n\nfunction copyContainers(root: JsonValue, path: Path, owned: WeakSet<object>): JsonValue {\n\tconst copy = (value: JsonValue): JsonValue[] | Record<string, JsonValue> => {\n\t\tif (Array.isArray(value)) return value.slice();\n\t\tif (!isObj(value)) throw new PathError(path);\n\t\t// Spread and `Object.assign()` onto a null-prototype object define own data properties, `__proto__` included,\n\t\t// as `Object.defineProperty()` per key does, at a fraction of its cost.\n\t\treturn Object.getPrototypeOf(value) === null ? Object.assign(Object.create(null), value) : { ...value };\n\t};\n\tif (!isObj(root)) throw new PathError(path);\n\tlet copiedRoot: JsonValue[] | Record<string, JsonValue>;\n\tif (owned.has(root)) copiedRoot = root as JsonValue[] | Record<string, JsonValue>;\n\telse {\n\t\tcopiedRoot = copy(root);\n\t\towned.add(copiedRoot);\n\t}\n\tlet destination = copiedRoot;\n\tfor (const segment of path) {\n\t\tif (!Object.hasOwn(destination, segment)) throw new PathError(path);\n\t\tif (Array.isArray(destination) && typeof segment !== \"number\") throw new UnsafePathError(segment);\n\t\tconst child = (destination as Record<Seg, JsonValue>)[segment]!;\n\t\tif (!isObj(child)) throw new PathError(path);\n\t\tif (owned.has(child)) {\n\t\t\tdestination = child as JsonValue[] | Record<string, JsonValue>;\n\t\t\tcontinue;\n\t\t}\n\t\tconst copiedChild = copy(child);\n\t\tObject.defineProperty(destination, segment, {\n\t\t\tvalue: copiedChild,\n\t\t\twritable: true,\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t});\n\t\towned.add(copiedChild);\n\t\tdestination = copiedChild;\n\t}\n\treturn copiedRoot;\n}\n\nfunction resolveValue(root: JsonValue, path: Path): JsonValue {\n\tlet node: JsonValue = root;\n\tfor (const seg of path) {\n\t\tif (!isObj(node)) throw new PathError(path);\n\t\tif (Array.isArray(node) && typeof seg !== \"number\") throw new UnsafePathError(seg);\n\t\t// Own properties only: an inherited getter must not run, and a walk must not\n\t\t// escape the value into the prototype chain.\n\t\tif (!Object.hasOwn(node, seg as PropertyKey)) throw new PathError(path);\n\t\tnode = (node as Record<Seg, JsonValue>)[seg]!;\n\t}\n\treturn node;\n}\n\nfunction resolve(root: JsonValue, path: Path): JsonValue {\n\tconst node = resolveValue(root, path);\n\tif (!isObj(node)) throw new PathError(path);\n\treturn node;\n}\n\n// ─── Codec ───────────────────────────────────────────────────────────────────\n//\n// Path interning and arity omission live between the tracker and a boundary;\n// `Op` and `apply` know nothing about them.\n//\n// Consecutive batches of one encoder may be concatenated into one batch (links\n// coalesce waiting state this way): only path ids span batches, and every batch\n// starts with an explicit path.\n//\n// ONE PAIR PER INDEPENDENT STATE STREAM. Every decoder must observe exactly the\n// batches encoded by its matching encoder, beginning with that state's base.\n// Sharing a transport connection does not make separately hydrated states one\n// stream.\n\nconst pathKey = (path: Path): string => JSON.stringify(path);\n\nexport interface Encoder {\n\tencode(ops: readonly Op[]): WireOp[];\n}\n\n/**\n * Intern on SECOND use. A definition costs more than the path it replaces, so\n * interning on first use loses on the many paths written exactly once.\n */\nexport function encoder(): Encoder {\n\tconst seen = new Set<string>();\n\tconst ids = new Map<string, number>();\n\tlet nextId = 0;\n\tlet previous: string | undefined; // last path in THIS batch\n\n\treturn {\n\t\tencode(ops) {\n\t\t\t// Arity omission is scoped to a batch. Letting it span batches would make\n\t\t\t// a batch's first op depend on the previous batch's last one, so a reader\n\t\t\t// that skips or reorders a batch decodes into the wrong path. Ids are the\n\t\t\t// only cross-batch state, and the dictionary makes those explicit.\n\t\t\tprevious = undefined;\n\t\t\tconst out: WireOp[] = [];\n\t\t\tfor (const op of ops) {\n\t\t\t\tif (op[0] === \"r\") {\n\t\t\t\t\tout.push(op);\n\t\t\t\t\t// A base batch is a RECOVERY POINT: a reader replays from the last one\n\t\t\t\t\t// with a fresh decoder. So everything after it must be self-contained.\n\t\t\t\t\t// Keeping ids across a replacement emits references to definitions the\n\t\t\t\t\t// reader never saw — recovery fails with an unresolvable path id.\n\t\t\t\t\tseen.clear();\n\t\t\t\t\tids.clear();\n\t\t\t\t\tnextId = 0;\n\t\t\t\t\tprevious = undefined;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst path = op[1];\n\t\t\t\tconst key = pathKey(path);\n\n\t\t\t\t// Same path as the previous op: drop the ref entirely.\n\t\t\t\tif (key === previous) {\n\t\t\t\t\tswitch (op[0]) {\n\t\t\t\t\t\tcase \"s\":\n\t\t\t\t\t\t\tout.push([\"s\", op[2]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"d\":\n\t\t\t\t\t\t\tout.push([\"d\"]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"a\":\n\t\t\t\t\t\t\tout.push([\"a\", op[2]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"t\":\n\t\t\t\t\t\t\tout.push([\"t\", op[2]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"p\":\n\t\t\t\t\t\t\tout.push([\"p\", op[2], op[3], op[4]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase \"m\":\n\t\t\t\t\t\t\tout.push([\"m\", op[2]]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet ref: PathRef = path;\n\t\t\t\tconst existing = ids.get(key);\n\t\t\t\tif (existing !== undefined) {\n\t\t\t\t\tref = existing;\n\t\t\t\t} else if (seen.has(key)) {\n\t\t\t\t\tconst id = nextId++;\n\t\t\t\t\tids.set(key, id);\n\t\t\t\t\tout.push([\"#\", id, path]); // second use: define, then reference\n\t\t\t\t\tref = id;\n\t\t\t\t} else {\n\t\t\t\t\tseen.add(key); // first use: inline\n\t\t\t\t}\n\n\t\t\t\tswitch (op[0]) {\n\t\t\t\t\tcase \"s\":\n\t\t\t\t\t\tout.push([\"s\", ref as PathRef<NonEmptyPath>, op[2]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"d\":\n\t\t\t\t\t\tout.push([\"d\", ref as PathRef<NonEmptyPath>]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"a\":\n\t\t\t\t\t\tout.push([\"a\", ref as PathRef<NonEmptyPath>, op[2]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"t\":\n\t\t\t\t\t\tout.push([\"t\", ref as PathRef<NonEmptyPath>, op[2]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"p\":\n\t\t\t\t\t\tout.push([\"p\", ref, op[2], op[3], op[4]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"m\":\n\t\t\t\t\t\tout.push([\"m\", ref, op[2]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tprevious = key;\n\t\t\t}\n\t\t\treturn out;\n\t\t},\n\t};\n}\n\nexport interface Decoder {\n\t/** Ops as received: each is validated (`assertValidWireOp`) before use. */\n\tdecode(wire: readonly unknown[]): Op[];\n}\n\nexport function decoder(): Decoder {\n\tconst paths = new Map<number, Path>();\n\n\treturn {\n\t\tdecode(wire) {\n\t\t\tlet previous: Path | undefined; // scoped to the batch, as in encode\n\t\t\tconst out: Op[] = [];\n\t\t\tfor (const op of wire) {\n\t\t\t\tassertValidWireOp(op);\n\t\t\t\tif (op[0] === \"#\") {\n\t\t\t\t\tassertSafePath(op[2]);\n\t\t\t\t\tpaths.set(op[1], op[2]);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (op[0] === \"r\") {\n\t\t\t\t\tout.push(op);\n\t\t\t\t\tpaths.clear();\n\t\t\t\t\tprevious = undefined;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Arity tells us whether a ref is present: the short forms omit it.\n\t\t\t\tconst short =\n\t\t\t\t\t(op[0] === \"d\" && op.length === 1) ||\n\t\t\t\t\t(op[0] !== \"d\" && op[0] !== \"p\" && op.length === 2) ||\n\t\t\t\t\t(op[0] === \"p\" && op.length === 4);\n\n\t\t\t\tlet path: Path;\n\t\t\t\tif (short) {\n\t\t\t\t\tif (previous === undefined) throw new PathError([]);\n\t\t\t\t\tpath = previous;\n\t\t\t\t} else {\n\t\t\t\t\tconst ref = op[1] as PathRef;\n\t\t\t\t\tif (typeof ref === \"number\") {\n\t\t\t\t\t\tconst resolved = paths.get(ref);\n\t\t\t\t\t\tif (resolved === undefined) throw new PathError(ref);\n\t\t\t\t\t\tpath = resolved;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpath = ref;\n\t\t\t\t\t}\n\t\t\t\t\tprevious = path;\n\t\t\t\t}\n\n\t\t\t\tif (op[0] !== \"p\" && op[0] !== \"m\" && path.length === 0) throw new PathError(path);\n\t\t\t\tswitch (op[0]) {\n\t\t\t\t\tcase \"s\":\n\t\t\t\t\t\tout.push([\"s\", path as NonEmptyPath, (short ? op[1] : op[2]) as JsonValue]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"d\":\n\t\t\t\t\t\tout.push([\"d\", path as NonEmptyPath]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"a\":\n\t\t\t\t\t\tout.push([\"a\", path as NonEmptyPath, (short ? op[1] : op[2]) as string]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"t\":\n\t\t\t\t\t\tout.push([\"t\", path as NonEmptyPath, (short ? op[1] : op[2]) as number]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"p\": {\n\t\t\t\t\t\tconst [i, r, items] = short\n\t\t\t\t\t\t\t? [op[1] as number, op[2] as number, op[3] as JsonValue[]]\n\t\t\t\t\t\t\t: [op[2] as number, op[3] as number, op[4] as JsonValue[]];\n\t\t\t\t\t\tout.push([\"p\", path, i, r, items]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"m\":\n\t\t\t\t\t\tout.push([\"m\", path, (short ? op[1] : op[2]) as number[]]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn out;\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import type { Op } from "./index.ts";
2
+ /**
3
+ * What `PendingOps.take()` hands over: the pending ops, folded, or `replace` after an overflow, which the owner of the
4
+ * queue turns into a root replacement with the current value.
5
+ */
6
+ export type PendingTake = {
7
+ readonly kind: "ops";
8
+ readonly ops: readonly Op[];
9
+ } | {
10
+ readonly kind: "replace";
11
+ };
12
+ /** Pending ops past which only "replace with the current value" stays pending. */
13
+ export declare const MAX_PENDING_OPS = 10000;
14
+ /**
15
+ * Pending ops of one state for one consumer, in order and raw (never encoded while they wait). `r` drops everything
16
+ * before it. A leaf op merges into the last pending leaf op on the same path (`a` + `a` joined, `s` replaces `s` or `a`,
17
+ * `a` after a string `s` appends into it); any other op clears the leaf index. Leaf ops on different paths commute,
18
+ * except after an ancestor primitive `s`, after which the descendant cannot be written until a structural op clears the
19
+ * index. Past `MAX_PENDING_OPS` only "replace with the current value" stays pending.
20
+ *
21
+ * Ops are only those of Delta's tracker, `diffRevisions()` and `appendText()`; received op arrays and tuples are never
22
+ * mutated (they feed other consumers too), a merge makes a new tuple.
23
+ */
24
+ export declare class PendingOps {
25
+ #private;
26
+ /** Queue the ops of one commit. */
27
+ push(ops: readonly Op[]): void;
28
+ /**
29
+ * Pending ops after folding; 1 once overflowed (the replacement the owner sends). One batch is counted as received,
30
+ * so a single commit larger than `MAX_PENDING_OPS` counts in full until a second one arrives and overflows.
31
+ */
32
+ get size(): number;
33
+ /** Hand over everything pending and start empty. */
34
+ take(): PendingTake;
35
+ }
36
+ //# sourceMappingURL=pending.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending.d.ts","sourceRoot":"","sources":["../../src/delta/pending.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,EAAE,EAAQ,MAAM,YAAY,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAE/G,kFAAkF;AAClF,eAAO,MAAM,eAAe,QAAS,CAAC;AA6BtC;;;;;;;;;GASG;AACH,qBAAa,UAAU;;IAGtB,mCAAmC;IACnC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,GAAG,IAAI,CAyB7B;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,CAIjB;IAED,oDAAoD;IACpD,IAAI,IAAI,WAAW,CAYlB;CA6BD"}
@@ -0,0 +1,143 @@
1
+ /** Pending ops past which only "replace with the current value" stays pending. */
2
+ export const MAX_PENDING_OPS = 10_000;
3
+ const EMPTY = { kind: "empty" };
4
+ const REPLACE = { kind: "replace" };
5
+ const NO_OPS = { kind: "ops", ops: [] };
6
+ const REPLACE_TAKE = { kind: "replace" };
7
+ /**
8
+ * Pending ops of one state for one consumer, in order and raw (never encoded while they wait). `r` drops everything
9
+ * before it. A leaf op merges into the last pending leaf op on the same path (`a` + `a` joined, `s` replaces `s` or `a`,
10
+ * `a` after a string `s` appends into it); any other op clears the leaf index. Leaf ops on different paths commute,
11
+ * except after an ancestor primitive `s`, after which the descendant cannot be written until a structural op clears the
12
+ * index. Past `MAX_PENDING_OPS` only "replace with the current value" stays pending.
13
+ *
14
+ * Ops are only those of Delta's tracker, `diffRevisions()` and `appendText()`; received op arrays and tuples are never
15
+ * mutated (they feed other consumers too), a merge makes a new tuple.
16
+ */
17
+ export class PendingOps {
18
+ #state = EMPTY;
19
+ /** Queue the ops of one commit. */
20
+ push(ops) {
21
+ if (ops.length === 0)
22
+ return;
23
+ const state = this.#state;
24
+ // A batch that starts with `r` (the tracker's and `diffRevisions()`'s only place for it) drops everything
25
+ // pending, also an overflow, and is kept as received.
26
+ if (ops[0][0] === "r") {
27
+ this.#state = { kind: "batch", ops };
28
+ return;
29
+ }
30
+ switch (state.kind) {
31
+ case "empty":
32
+ this.#state = { kind: "batch", ops };
33
+ return;
34
+ case "batch": {
35
+ const folding = { kind: "folding", ops: [], leaves: new Map() };
36
+ this.#state = folding;
37
+ if (this.#fold(state.ops, folding))
38
+ this.#fold(ops, folding);
39
+ return;
40
+ }
41
+ case "folding":
42
+ this.#fold(ops, state);
43
+ return;
44
+ case "replace":
45
+ return;
46
+ }
47
+ }
48
+ /**
49
+ * Pending ops after folding; 1 once overflowed (the replacement the owner sends). One batch is counted as received,
50
+ * so a single commit larger than `MAX_PENDING_OPS` counts in full until a second one arrives and overflows.
51
+ */
52
+ get size() {
53
+ const state = this.#state;
54
+ if (state.kind === "empty")
55
+ return 0;
56
+ return state.kind === "replace" ? 1 : state.ops.length;
57
+ }
58
+ /** Hand over everything pending and start empty. */
59
+ take() {
60
+ const state = this.#state;
61
+ this.#state = EMPTY;
62
+ switch (state.kind) {
63
+ case "empty":
64
+ return NO_OPS;
65
+ case "batch":
66
+ case "folding":
67
+ return { kind: "ops", ops: state.ops };
68
+ case "replace":
69
+ return REPLACE_TAKE;
70
+ }
71
+ }
72
+ /** Fold `ops` into `folding`; false once the queue overflowed into `replace`. */
73
+ #fold(ops, folding) {
74
+ for (const op of ops) {
75
+ switch (op[0]) {
76
+ case "r":
77
+ folding.ops.length = 0;
78
+ folding.leaves.clear();
79
+ break;
80
+ case "a":
81
+ if (mergeLeaf(op, folding))
82
+ continue;
83
+ break;
84
+ case "s":
85
+ if (isPrimitive(op[2])) {
86
+ if (mergeLeaf(op, folding))
87
+ continue;
88
+ }
89
+ else if (folding.leaves.size > 0)
90
+ folding.leaves.clear();
91
+ break;
92
+ default:
93
+ if (folding.leaves.size > 0)
94
+ folding.leaves.clear();
95
+ }
96
+ folding.ops.push(op);
97
+ if (folding.ops.length > MAX_PENDING_OPS) {
98
+ this.#state = REPLACE;
99
+ return false;
100
+ }
101
+ }
102
+ return true;
103
+ }
104
+ }
105
+ const isPrimitive = (value) => value === null || typeof value !== "object";
106
+ /**
107
+ * Merge the leaf op `op` into the last pending leaf op on its path, or index it as that op at the position it is about
108
+ * to be pushed to. True when merged.
109
+ */
110
+ function mergeLeaf(op, folding) {
111
+ const key = pathKey(op[1]);
112
+ const at = folding.leaves.get(key);
113
+ if (at !== undefined) {
114
+ // The index points at leaf ops only.
115
+ const merged = merge(folding.ops[at], op);
116
+ if (merged !== undefined) {
117
+ folding.ops[at] = merged;
118
+ return true;
119
+ }
120
+ }
121
+ folding.leaves.set(key, folding.ops.length);
122
+ return false;
123
+ }
124
+ /**
125
+ * The key of a path in the leaf index. Injective, as merging two distinct paths would lose a write: `["a.b"]` and
126
+ * `["a", "b"]` are different keys. A number and its string (`1`, `"1"`) may share one: within one index lifetime a
127
+ * parent is either an array or an object, as changing it is a structural op that clears the index.
128
+ */
129
+ function pathKey(path) {
130
+ return JSON.stringify(path);
131
+ }
132
+ /** `next` folded into `previous` (same path), or undefined when they do not fold. */
133
+ function merge(previous, next) {
134
+ if (next[0] === "s")
135
+ return next;
136
+ if (previous[0] === "a")
137
+ return ["a", previous[1], previous[2] + next[2]];
138
+ // Only a string set takes an append; the tracker never appends to another primitive.
139
+ if (typeof previous[2] === "string")
140
+ return ["s", previous[1], previous[2] + next[2]];
141
+ return undefined;
142
+ }
143
+ //# sourceMappingURL=pending.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending.js","sourceRoot":"","sources":["../../src/delta/pending.ts"],"names":[],"mappings":"AAUA,kFAAkF;AAClF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AAqBtC,MAAM,KAAK,GAAU,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAEvC,MAAM,OAAO,GAAU,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAE3C,MAAM,MAAM,GAAgB,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AAErD,MAAM,YAAY,GAAgB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACtB,MAAM,GAAU,KAAK,CAAC;IAEtB,mCAAmC;IACnC,IAAI,CAAC,GAAkB;QACtB,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,0GAA0G;QAC1G,sDAAsD;QACtD,IAAI,GAAG,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACxB,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;YACrC,OAAO;QACR,CAAC;QACD,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACp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AAClB,CAAC","sourcesContent":["// The pending queue: the ops a slow consumer of one state has not taken yet, folded while they wait.\nimport type { JsonValue } from \"../json.ts\";\nimport type { NonEmptyPath, Op, Path } from \"./index.ts\";\n\n/**\n * What `PendingOps.take()` hands over: the pending ops, folded, or `replace` after an overflow, which the owner of the\n * queue turns into a root replacement with the current value.\n */\nexport type PendingTake = { readonly kind: \"ops\"; readonly ops: readonly Op[] } | { readonly kind: \"replace\" };\n\n/** Pending ops past which only \"replace with the current value\" stays pending. */\nexport const MAX_PENDING_OPS = 10_000;\n\n/** A leaf op: an append, or a set of a primitive. The leaf index points at these only. */\ntype LeafOp = readonly [\"a\", NonEmptyPath, string] | readonly [\"s\", NonEmptyPath, JsonValue];\n\ntype Folding = {\n\treadonly kind: \"folding\";\n\t/** Owned by the queue until `take()` hands it over; never one of the received op arrays. */\n\treadonly ops: Op[];\n\t/** Path key to the position of the last pending leaf op on that path. */\n\treadonly leaves: Map<string, number>;\n};\n\ntype State =\n\t| { readonly kind: \"empty\" }\n\t/** One batch, kept by reference: a consumer that keeps up never pays for folding. */\n\t| { readonly kind: \"batch\"; readonly ops: readonly Op[] }\n\t| Folding\n\t/** Overflowed: nothing more accumulates until `take()` or a batch that starts with `r`. */\n\t| { readonly kind: \"replace\" };\n\nconst EMPTY: State = { kind: \"empty\" };\n\nconst REPLACE: State = { kind: \"replace\" };\n\nconst NO_OPS: PendingTake = { kind: \"ops\", ops: [] };\n\nconst REPLACE_TAKE: PendingTake = { kind: \"replace\" };\n\n/**\n * Pending ops of one state for one consumer, in order and raw (never encoded while they wait). `r` drops everything\n * before it. A leaf op merges into the last pending leaf op on the same path (`a` + `a` joined, `s` replaces `s` or `a`,\n * `a` after a string `s` appends into it); any other op clears the leaf index. Leaf ops on different paths commute,\n * except after an ancestor primitive `s`, after which the descendant cannot be written until a structural op clears the\n * index. Past `MAX_PENDING_OPS` only \"replace with the current value\" stays pending.\n *\n * Ops are only those of Delta's tracker, `diffRevisions()` and `appendText()`; received op arrays and tuples are never\n * mutated (they feed other consumers too), a merge makes a new tuple.\n */\nexport class PendingOps {\n\t#state: State = EMPTY;\n\n\t/** Queue the ops of one commit. */\n\tpush(ops: readonly Op[]): void {\n\t\tif (ops.length === 0) return;\n\t\tconst state = this.#state;\n\t\t// A batch that starts with `r` (the tracker's and `diffRevisions()`'s only place for it) drops everything\n\t\t// pending, also an overflow, and is kept as received.\n\t\tif (ops[0]![0] === \"r\") {\n\t\t\tthis.#state = { kind: \"batch\", ops };\n\t\t\treturn;\n\t\t}\n\t\tswitch (state.kind) {\n\t\t\tcase \"empty\":\n\t\t\t\tthis.#state = { kind: \"batch\", ops };\n\t\t\t\treturn;\n\t\t\tcase \"batch\": {\n\t\t\t\tconst folding: Folding = { kind: \"folding\", ops: [], leaves: new Map() };\n\t\t\t\tthis.#state = folding;\n\t\t\t\tif (this.#fold(state.ops, folding)) this.#fold(ops, folding);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"folding\":\n\t\t\t\tthis.#fold(ops, state);\n\t\t\t\treturn;\n\t\t\tcase \"replace\":\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\t/**\n\t * Pending ops after folding; 1 once overflowed (the replacement the owner sends). One batch is counted as received,\n\t * so a single commit larger than `MAX_PENDING_OPS` counts in full until a second one arrives and overflows.\n\t */\n\tget size(): number {\n\t\tconst state = this.#state;\n\t\tif (state.kind === \"empty\") return 0;\n\t\treturn state.kind === \"replace\" ? 1 : state.ops.length;\n\t}\n\n\t/** Hand over everything pending and start empty. */\n\ttake(): PendingTake {\n\t\tconst state = this.#state;\n\t\tthis.#state = EMPTY;\n\t\tswitch (state.kind) {\n\t\t\tcase \"empty\":\n\t\t\t\treturn NO_OPS;\n\t\t\tcase \"batch\":\n\t\t\tcase \"folding\":\n\t\t\t\treturn { kind: \"ops\", ops: state.ops };\n\t\t\tcase \"replace\":\n\t\t\t\treturn REPLACE_TAKE;\n\t\t}\n\t}\n\n\t/** Fold `ops` into `folding`; false once the queue overflowed into `replace`. */\n\t#fold(ops: readonly Op[], folding: Folding): boolean {\n\t\tfor (const op of ops) {\n\t\t\tswitch (op[0]) {\n\t\t\t\tcase \"r\":\n\t\t\t\t\tfolding.ops.length = 0;\n\t\t\t\t\tfolding.leaves.clear();\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"a\":\n\t\t\t\t\tif (mergeLeaf(op, folding)) continue;\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"s\":\n\t\t\t\t\tif (isPrimitive(op[2])) {\n\t\t\t\t\t\tif (mergeLeaf(op, folding)) continue;\n\t\t\t\t\t} else if (folding.leaves.size > 0) folding.leaves.clear();\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tif (folding.leaves.size > 0) folding.leaves.clear();\n\t\t\t}\n\t\t\tfolding.ops.push(op);\n\t\t\tif (folding.ops.length > MAX_PENDING_OPS) {\n\t\t\t\tthis.#state = REPLACE;\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\nconst isPrimitive = (value: JsonValue): boolean => value === null || typeof value !== \"object\";\n\n/**\n * Merge the leaf op `op` into the last pending leaf op on its path, or index it as that op at the position it is about\n * to be pushed to. True when merged.\n */\nfunction mergeLeaf(op: LeafOp, folding: Folding): boolean {\n\tconst key = pathKey(op[1]);\n\tconst at = folding.leaves.get(key);\n\tif (at !== undefined) {\n\t\t// The index points at leaf ops only.\n\t\tconst merged = merge(folding.ops[at] as LeafOp, op);\n\t\tif (merged !== undefined) {\n\t\t\tfolding.ops[at] = merged;\n\t\t\treturn true;\n\t\t}\n\t}\n\tfolding.leaves.set(key, folding.ops.length);\n\treturn false;\n}\n\n/**\n * The key of a path in the leaf index. Injective, as merging two distinct paths would lose a write: `[\"a.b\"]` and\n * `[\"a\", \"b\"]` are different keys. A number and its string (`1`, `\"1\"`) may share one: within one index lifetime a\n * parent is either an array or an object, as changing it is a structural op that clears the index.\n */\nfunction pathKey(path: Path): string {\n\treturn JSON.stringify(path);\n}\n\n/** `next` folded into `previous` (same path), or undefined when they do not fold. */\nfunction merge(previous: LeafOp, next: LeafOp): LeafOp | undefined {\n\tif (next[0] === \"s\") return next;\n\tif (previous[0] === \"a\") return [\"a\", previous[1], previous[2] + next[2]];\n\t// Only a string set takes an append; the tracker never appends to another primitive.\n\tif (typeof previous[2] === \"string\") return [\"s\", previous[1], previous[2] + next[2]];\n\treturn undefined;\n}\n"]}
@@ -2,6 +2,10 @@ import type { JsonValue } from "../json.ts";
2
2
  import type { Draft } from "./draft.ts";
3
3
  import { type Op } from "./index.ts";
4
4
  export type { Draft, JsonValue, Op };
5
+ /** Keys of `T` whose value type is exactly `string`: required, and not a string literal type. */
6
+ export type StringKeys<T> = T extends readonly unknown[] ? never : {
7
+ [Key in keyof T]: string extends T[Key] ? (T[Key] extends string ? Key : never) : never;
8
+ }[keyof T];
5
9
  export interface Prepared<T extends object> {
6
10
  readonly base: T;
7
11
  readonly value: T;
@@ -23,4 +27,12 @@ export interface Tracker<T extends object> {
23
27
  }
24
28
  /** Take immutable ownership of an alias-free strict-JSON root in O(1). */
25
29
  export declare function track<T extends object>(initial: T): Tracker<T>;
30
+ /**
31
+ * Append `text` to the string at `draft[key]`, costing O(text.length). The change is recorded as one append op
32
+ * (several appends to the same key in one change join into one op) without comparing the old and new strings. A plain
33
+ * assignment such as `draft[key] += text` gives the same op, but `prepare()` then has to check that the new string
34
+ * extends the old one, which reads the whole string: O(length) per change. A plain assignment or deletion of the key in
35
+ * the same change falls back to that check.
36
+ */
37
+ export declare function appendText<T extends object>(draft: Draft<T>, key: StringKeys<T>, text: string): void;
26
38
  //# sourceMappingURL=tracker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/delta/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,O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