@earendil-works/chord 1.2.0 → 1.4.0

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 (122) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +69 -14
  3. package/dist/cell.d.ts +30 -9
  4. package/dist/cell.d.ts.map +1 -1
  5. package/dist/cell.js +52 -12
  6. package/dist/cell.js.map +1 -1
  7. package/dist/cluster.d.ts +4 -3
  8. package/dist/cluster.d.ts.map +1 -1
  9. package/dist/cluster.js +58 -42
  10. package/dist/cluster.js.map +1 -1
  11. package/dist/connection.d.ts +171 -58
  12. package/dist/connection.d.ts.map +1 -1
  13. package/dist/connection.js +676 -217
  14. package/dist/connection.js.map +1 -1
  15. package/dist/context/index.d.ts +8 -0
  16. package/dist/context/index.d.ts.map +1 -1
  17. package/dist/context/index.js +15 -0
  18. package/dist/context/index.js.map +1 -1
  19. package/dist/contract.d.ts +120 -45
  20. package/dist/contract.d.ts.map +1 -1
  21. package/dist/contract.js +104 -15
  22. package/dist/contract.js.map +1 -1
  23. package/dist/declare.d.ts +11 -48
  24. package/dist/declare.d.ts.map +1 -1
  25. package/dist/declare.js +1 -21
  26. package/dist/declare.js.map +1 -1
  27. package/dist/delta/index.d.ts +2 -1
  28. package/dist/delta/index.d.ts.map +1 -1
  29. package/dist/delta/index.js +4 -0
  30. package/dist/delta/index.js.map +1 -1
  31. package/dist/errors.d.ts +4 -3
  32. package/dist/errors.d.ts.map +1 -1
  33. package/dist/errors.js +15 -0
  34. package/dist/errors.js.map +1 -1
  35. package/dist/host.d.ts +214 -120
  36. package/dist/host.d.ts.map +1 -1
  37. package/dist/host.js +446 -241
  38. package/dist/host.js.map +1 -1
  39. package/dist/index.d.ts +8 -8
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +4 -4
  42. package/dist/index.js.map +1 -1
  43. package/dist/link.d.ts +47 -12
  44. package/dist/link.d.ts.map +1 -1
  45. package/dist/link.js +200 -14
  46. package/dist/link.js.map +1 -1
  47. package/dist/loader.d.ts.map +1 -1
  48. package/dist/loader.js +7 -2
  49. package/dist/loader.js.map +1 -1
  50. package/dist/manager.d.ts.map +1 -1
  51. package/dist/manager.js +35 -9
  52. package/dist/manager.js.map +1 -1
  53. package/dist/object.d.ts +438 -0
  54. package/dist/object.d.ts.map +1 -0
  55. package/dist/{record.js → object.js} +614 -335
  56. package/dist/object.js.map +1 -0
  57. package/dist/output.d.ts +91 -0
  58. package/dist/output.d.ts.map +1 -0
  59. package/dist/output.js +360 -0
  60. package/dist/output.js.map +1 -0
  61. package/dist/registry.d.ts +3 -3
  62. package/dist/registry.d.ts.map +1 -1
  63. package/dist/registry.js +1 -1
  64. package/dist/registry.js.map +1 -1
  65. package/dist/reload.d.ts +35 -27
  66. package/dist/reload.d.ts.map +1 -1
  67. package/dist/reload.js +256 -192
  68. package/dist/reload.js.map +1 -1
  69. package/dist/remote.d.ts +130 -35
  70. package/dist/remote.d.ts.map +1 -1
  71. package/dist/remote.js +493 -189
  72. package/dist/remote.js.map +1 -1
  73. package/dist/sqlite/cloudflare.d.ts +52 -0
  74. package/dist/sqlite/cloudflare.d.ts.map +1 -0
  75. package/dist/sqlite/cloudflare.js +134 -0
  76. package/dist/sqlite/cloudflare.js.map +1 -0
  77. package/dist/sqlite/database.d.ts +37 -0
  78. package/dist/sqlite/database.d.ts.map +1 -0
  79. package/dist/sqlite/database.js +2 -0
  80. package/dist/sqlite/database.js.map +1 -0
  81. package/dist/sqlite/index.d.ts +4 -0
  82. package/dist/sqlite/index.d.ts.map +1 -0
  83. package/dist/sqlite/index.js +3 -0
  84. package/dist/sqlite/index.js.map +1 -0
  85. package/dist/sqlite/migrations.d.ts +10 -0
  86. package/dist/sqlite/migrations.d.ts.map +1 -0
  87. package/dist/sqlite/migrations.js +33 -0
  88. package/dist/sqlite/migrations.js.map +1 -0
  89. package/dist/sqlite/node.d.ts +38 -0
  90. package/dist/sqlite/node.d.ts.map +1 -0
  91. package/dist/sqlite/node.js +174 -0
  92. package/dist/sqlite/node.js.map +1 -0
  93. package/dist/sqlite/schema.d.ts +3 -0
  94. package/dist/sqlite/schema.d.ts.map +1 -0
  95. package/dist/sqlite/schema.js +10 -0
  96. package/dist/sqlite/schema.js.map +1 -0
  97. package/dist/telemetry-sqlite/index.d.ts +24 -0
  98. package/dist/telemetry-sqlite/index.d.ts.map +1 -0
  99. package/dist/telemetry-sqlite/index.js +273 -0
  100. package/dist/telemetry-sqlite/index.js.map +1 -0
  101. package/dist/telemetry-sqlite/store.d.ts +9 -0
  102. package/dist/telemetry-sqlite/store.d.ts.map +1 -0
  103. package/dist/telemetry-sqlite/store.js +110 -0
  104. package/dist/telemetry-sqlite/store.js.map +1 -0
  105. package/dist/types.d.ts +39 -28
  106. package/dist/types.d.ts.map +1 -1
  107. package/dist/types.js.map +1 -1
  108. package/dist/websocket.d.ts +4 -5
  109. package/dist/websocket.d.ts.map +1 -1
  110. package/dist/websocket.js +3 -2
  111. package/dist/websocket.js.map +1 -1
  112. package/dist/wire.d.ts +210 -129
  113. package/dist/wire.d.ts.map +1 -1
  114. package/dist/wire.js +108 -55
  115. package/dist/wire.js.map +1 -1
  116. package/docs/guide.md +267 -203
  117. package/docs/spec.md +141 -114
  118. package/docs/tutorial.md +257 -235
  119. package/package.json +27 -1
  120. package/dist/record.d.ts +0 -320
  121. package/dist/record.d.ts.map +0 -1
  122. package/dist/record.js.map +0 -1
package/dist/declare.d.ts CHANGED
@@ -1,19 +1,12 @@
1
- import type { Static, TSchema } from "typebox";
2
- import type { Cell, Sources, SourceValues } from "./cell.ts";
3
- import type { Ctx, Readable } from "./types.ts";
4
- declare const DECL: unique symbol;
1
+ import type { Ctx } from "./types.ts";
5
2
  export interface Subscribable<E> {
6
3
  subscribe(listener: (event: E) => void): () => void;
7
4
  }
8
- export interface CellDecl<T> {
9
- readonly [DECL]: "cell";
10
- readonly schema: TSchema;
11
- readonly initial: T;
12
- }
13
- export interface ResourceSpec<T> {
14
- /** Bump to replace the resource at the next reload. */
15
- readonly rev: number;
16
- /** Holds or resources that must be live/open first. A change replaces the resource. */
5
+ /** `self.resource(name, declaration)`: something the object opens and later closes (a database, a watch, a socket). */
6
+ export interface ResourceDeclaration<T> {
7
+ /** Bump to replace the resource at the next reload (a native value has no schema to detect a change). */
8
+ readonly version: number;
9
+ /** References or resources that must be live/open first. A change replaces the resource. */
17
10
  readonly deps?: readonly unknown[];
18
11
  /** Exclusive resources are replaced at the gate: old closed before new opened. */
19
12
  readonly exclusive?: boolean;
@@ -22,49 +15,19 @@ export interface ResourceSpec<T> {
22
15
  }): T | Promise<T>;
23
16
  close?(value: T): void | Promise<void>;
24
17
  }
25
- export interface ResourceDecl<T> {
26
- readonly [DECL]: "resource";
27
- readonly spec: ResourceSpec<T>;
28
- }
29
18
  export interface Resource<T> {
30
19
  readonly key: string;
31
20
  /** Throws not_ready until opened. */
32
21
  readonly value: T;
33
22
  }
23
+ /** A listener as `self.on` declares it. */
34
24
  export interface ListenerDecl {
35
- readonly [DECL]: "listener";
36
25
  readonly source: unknown;
37
26
  readonly select: ((value: never) => Subscribable<unknown>) | undefined;
38
27
  readonly fn: (event: unknown, ctx: Ctx) => void | Promise<void>;
39
28
  }
40
- export interface DerivationDecl<T> {
41
- readonly [DECL]: "derivation";
42
- readonly sources: Sources;
43
- readonly fn: (...values: never[]) => T;
44
- }
45
- /** A state cell: schema (required; there is no TypeScript at runtime) and initial value (validated). */
46
- export declare const cell: <S extends TSchema>(schema: S, initial: Static<S>) => CellDecl<Static<S>>;
47
- export declare const resource: <T>(spec: ResourceSpec<T>) => ResourceDecl<T>;
48
- type ValueOf<S> = S extends Resource<infer T> ? T : S;
49
- type EventOf<S> = S extends Resource<infer T> ? EventOf<T> : S extends Subscribable<infer E> ? E : never;
50
- /**
51
- * Reacts to a source once the record is live. `listener(source, fn)` subscribes to the source itself: a readable
52
- * (cell, derivation, handle state member: called with each value, starting with the current one), an event source,
53
- * or a resource whose value is one. `listener(source, select, fn)` subscribes to `select(value)`, where value is the
54
- * opened resource for a resource source. Each event runs `fn` in a fresh root.
55
- */
56
- export declare function listener<S>(source: S, fn: (event: EventOf<S>, ctx: Ctx) => void | Promise<void>): ListenerDecl;
57
- export declare function listener<S, E>(source: S, select: (value: ValueOf<S>) => Subscribable<E>, fn: (event: E, ctx: Ctx) => void | Promise<void>): ListenerDecl;
58
- export declare const derivation: <const S extends Sources, T>(sources: S, fn: (...values: SourceValues<S>) => T) => DerivationDecl<T>;
59
- export declare const declKind: (value: unknown) => string | undefined;
60
- export type Cells<D> = {
61
- readonly [K in keyof D]: D[K] extends CellDecl<infer T> ? Cell<T> : never;
62
- };
63
- export type Resources<D> = {
64
- readonly [K in keyof D]: D[K] extends ResourceDecl<infer T> ? Resource<T> : never;
65
- };
66
- export type Derivations<D> = {
67
- readonly [K in keyof D]: D[K] extends DerivationDecl<infer T> ? Readable<T> : never;
68
- };
69
- export {};
29
+ /** What `self.on(name, source, …)` passes to `select`: a resource's opened value, or the source itself. */
30
+ export type ValueOf<S> = S extends Subscribable<unknown> ? S : S extends Resource<infer T> ? T : S;
31
+ /** What `self.on(name, source, handler)` delivers: a readable's values, an event source's events. */
32
+ export type EventOf<S> = S extends Subscribable<infer E> ? E : S extends Resource<infer T> ? EventOf<T> : never;
70
33
  //# sourceMappingURL=declare.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"declare.d.ts","sourceRoot":"","sources":["../src/declare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKhD,QAAA,MAAM,IAAI,eAAuB,CAAC;AAElC,MAAM,WAAW,YAAY,CAAC,CAAC;IAC9B,SAAS,CAAC,QAAQ,EAAE,CAAC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,GAAG,CAAC,GAAG,CAAC,CAAC;AACnG,qGAAqG;AACrG,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC"}
package/dist/declare.js CHANGED
@@ -1,22 +1,2 @@
1
- // Declaration descriptors. A factory passes them in object literals; the property name identifies the declaration
2
- // across factory reruns (reload), independent of call order.
3
- const DECL = Symbol("chord.decl");
4
- /** A state cell: schema (required; there is no TypeScript at runtime) and initial value (validated). */
5
- export const cell = (schema, initial) => ({
6
- [DECL]: "cell",
7
- schema,
8
- initial,
9
- });
10
- export const resource = (spec) => ({ [DECL]: "resource", spec });
11
- export function listener(source, ...rest) {
12
- const [select, fn] = rest.length === 1 ? [undefined, rest[0]] : [rest[0], rest[1]];
13
- return {
14
- [DECL]: "listener",
15
- source,
16
- select: select,
17
- fn: fn,
18
- };
19
- }
20
- export const derivation = (sources, fn) => ({ [DECL]: "derivation", sources, fn: fn });
21
- export const declKind = (value) => value !== null && typeof value === "object" ? value[DECL] : undefined;
1
+ export {};
22
2
  //# sourceMappingURL=declare.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"declare.js","sourceRoot":"","sources":["../src/declare.ts"],"names":[],"mappings":"AAIA,kHAAkH;AAClH,6DAA6D;AAE7D,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AA+ClC,wGAAwG;AACxG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAoB,MAAS,EAAE,OAAkB,EAAuB,EAAE,CAAC,CAAC;IAC/F,CAAC,IAAI,CAAC,EAAE,MAAM;IACd,MAAM;IACN,OAAO;CACP,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAI,IAAqB,EAAmB,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;AAiBtG,MAAM,UAAU,QAAQ,CAAC,MAAe,EAAE,GAAG,IAAwB;IACpE,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnF,OAAO;QACN,CAAC,IAAI,CAAC,EAAE,UAAU;QAClB,MAAM;QACN,MAAM,EAAE,MAAgC;QACxC,EAAE,EAAE,EAAwB;KAC5B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CACzB,OAAU,EACV,EAAqC,EACjB,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,EAAE,EAA0C,EAAE,CAAC,CAAC;AAE5G,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAsB,EAAE,CAC9D,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,KAA6B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC","sourcesContent":["import type { Static, TSchema } from \"typebox\";\nimport type { Cell, Sources, SourceValues } from \"./cell.ts\";\nimport type { Ctx, Readable } from \"./types.ts\";\n\n// Declaration descriptors. A factory passes them in object literals; the property name identifies the declaration\n// across factory reruns (reload), independent of call order.\n\nconst DECL = Symbol(\"chord.decl\");\n\nexport interface Subscribable<E> {\n\tsubscribe(listener: (event: E) => void): () => void;\n}\n\nexport interface CellDecl<T> {\n\treadonly [DECL]: \"cell\";\n\treadonly schema: TSchema;\n\treadonly initial: T;\n}\n\nexport interface ResourceSpec<T> {\n\t/** Bump to replace the resource at the next reload. */\n\treadonly rev: number;\n\t/** Holds or resources that must be live/open first. A change replaces the resource. */\n\treadonly deps?: readonly unknown[];\n\t/** Exclusive resources are replaced at the gate: old closed before new opened. */\n\treadonly exclusive?: boolean;\n\topen(options: { readonly signal: AbortSignal }): T | Promise<T>;\n\tclose?(value: T): void | Promise<void>;\n}\n\nexport interface ResourceDecl<T> {\n\treadonly [DECL]: \"resource\";\n\treadonly spec: ResourceSpec<T>;\n}\n\nexport interface Resource<T> {\n\treadonly key: string;\n\t/** Throws not_ready until opened. */\n\treadonly value: T;\n}\n\nexport interface ListenerDecl {\n\treadonly [DECL]: \"listener\";\n\treadonly source: unknown;\n\treadonly select: ((value: never) => Subscribable<unknown>) | undefined;\n\treadonly fn: (event: unknown, ctx: Ctx) => void | Promise<void>;\n}\n\nexport interface DerivationDecl<T> {\n\treadonly [DECL]: \"derivation\";\n\treadonly sources: Sources;\n\treadonly fn: (...values: never[]) => T;\n}\n\n/** A state cell: schema (required; there is no TypeScript at runtime) and initial value (validated). */\nexport const cell = <S extends TSchema>(schema: S, initial: Static<S>): CellDecl<Static<S>> => ({\n\t[DECL]: \"cell\",\n\tschema,\n\tinitial,\n});\n\nexport const resource = <T>(spec: ResourceSpec<T>): ResourceDecl<T> => ({ [DECL]: \"resource\", spec });\n\ntype ValueOf<S> = S extends Resource<infer T> ? T : S;\ntype EventOf<S> = S extends Resource<infer T> ? EventOf<T> : S extends Subscribable<infer E> ? E : never;\n\n/**\n * Reacts to a source once the record is live. `listener(source, fn)` subscribes to the source itself: a readable\n * (cell, derivation, handle state member: called with each value, starting with the current one), an event source,\n * or a resource whose value is one. `listener(source, select, fn)` subscribes to `select(value)`, where value is the\n * opened resource for a resource source. Each event runs `fn` in a fresh root.\n */\nexport function listener<S>(source: S, fn: (event: EventOf<S>, ctx: Ctx) => void | Promise<void>): ListenerDecl;\nexport function listener<S, E>(\n\tsource: S,\n\tselect: (value: ValueOf<S>) => Subscribable<E>,\n\tfn: (event: E, ctx: Ctx) => void | Promise<void>,\n): ListenerDecl;\nexport function listener(source: unknown, ...rest: readonly unknown[]): ListenerDecl {\n\tconst [select, fn] = rest.length === 1 ? [undefined, rest[0]] : [rest[0], rest[1]];\n\treturn {\n\t\t[DECL]: \"listener\",\n\t\tsource,\n\t\tselect: select as ListenerDecl[\"select\"],\n\t\tfn: fn as ListenerDecl[\"fn\"],\n\t};\n}\n\nexport const derivation = <const S extends Sources, T>(\n\tsources: S,\n\tfn: (...values: SourceValues<S>) => T,\n): DerivationDecl<T> => ({ [DECL]: \"derivation\", sources, fn: fn as unknown as (...values: never[]) => T });\n\nexport const declKind = (value: unknown): string | undefined =>\n\tvalue !== null && typeof value === \"object\" ? (value as { [DECL]?: string })[DECL] : undefined;\n\nexport type Cells<D> = { readonly [K in keyof D]: D[K] extends CellDecl<infer T> ? Cell<T> : never };\nexport type Resources<D> = { readonly [K in keyof D]: D[K] extends ResourceDecl<infer T> ? Resource<T> : never };\nexport type Derivations<D> = { readonly [K in keyof D]: D[K] extends DerivationDecl<infer T> ? Readable<T> : never };\n"]}
1
+ {"version":3,"file":"declare.js","sourceRoot":"","sources":["../src/declare.ts"],"names":[],"mappings":"","sourcesContent":["import type { Ctx } from \"./types.ts\";\n\n// What a factory declares through `self` besides state cells: the shapes of resources and listeners.\n\nexport interface Subscribable<E> {\n\tsubscribe(listener: (event: E) => void): () => void;\n}\n\n/** `self.resource(name, declaration)`: something the object opens and later closes (a database, a watch, a socket). */\nexport interface ResourceDeclaration<T> {\n\t/** Bump to replace the resource at the next reload (a native value has no schema to detect a change). */\n\treadonly version: number;\n\t/** References or resources that must be live/open first. A change replaces the resource. */\n\treadonly deps?: readonly unknown[];\n\t/** Exclusive resources are replaced at the gate: old closed before new opened. */\n\treadonly exclusive?: boolean;\n\topen(options: { readonly signal: AbortSignal }): T | Promise<T>;\n\tclose?(value: T): void | Promise<void>;\n}\n\nexport interface Resource<T> {\n\treadonly key: string;\n\t/** Throws not_ready until opened. */\n\treadonly value: T;\n}\n\n/** A listener as `self.on` declares it. */\nexport interface ListenerDecl {\n\treadonly source: unknown;\n\treadonly select: ((value: never) => Subscribable<unknown>) | undefined;\n\treadonly fn: (event: unknown, ctx: Ctx) => void | Promise<void>;\n}\n\n// A cell has a `key` and a `value` too: sources are matched before resources.\n/** What `self.on(name, source, …)` passes to `select`: a resource's opened value, or the source itself. */\nexport type ValueOf<S> = S extends Subscribable<unknown> ? S : S extends Resource<infer T> ? T : S;\n/** What `self.on(name, source, handler)` delivers: a readable's values, an event source's events. */\nexport type EventOf<S> = S extends Subscribable<infer E> ? E : S extends Resource<infer T> ? EventOf<T> : never;\n"]}
@@ -105,7 +105,8 @@ export interface Encoder {
105
105
  */
106
106
  export declare function encoder(): Encoder;
107
107
  export interface Decoder {
108
- decode(wire: readonly WireOp[]): Op[];
108
+ /** Ops as received: each is validated (`assertValidWireOp`) before use. */
109
+ decode(wire: readonly unknown[]): Op[];
109
110
  }
110
111
  export declare function decoder(): Decoder;
111
112
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/delta/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAW5C,MAAM,MAAM,GAAG,GAAG,MAAM,GAAG,MAAM,CAAC;AAClC,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,EAAE,CAAC;AAClC,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;AAEpD,qEAAqE;AACrE,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,MAAM,CAAC;AAExD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,EAAE,GACX,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,GACzB,SAAS,CAAC,GAAG,EAAE,YAAY,EAAE,SAAS,CAAC,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AgFD,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,GAAG,CAAC,CAE9E;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAsBnG;AAqHD,MAAM,WAAW,OAAO;IACvB,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC;CACrC;AAED;;;GAGG;AACH,wBAAgB,OAAO,IAAI,OAAO,CA6FjC;AAED,MAAM,WAAW,OAAO;IACvB,2EAA2E;IAC3E,MAAM,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC;CACvC;AAED,wBAAgB,OAAO,IAAI,OAAO,CAwEjC"}
@@ -512,6 +512,10 @@ function resolve(root, path) {
512
512
  // Path interning and arity omission live between the tracker and a boundary;
513
513
  // `Op` and `apply` know nothing about them.
514
514
  //
515
+ // Consecutive batches of one encoder may be concatenated into one batch (links
516
+ // coalesce waiting state this way): only path ids span batches, and every batch
517
+ // starts with an explicit path.
518
+ //
515
519
  // ONE PAIR PER INDEPENDENT STATE STREAM. Every decoder must observe exactly the
516
520
  // batches encoded by its matching encoder, beginning with that state's base.
517
521
  // Sharing a transport connection does not make separately hydrated states one
@@ -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,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AC,CAAC,CAAC,CAAW,CAAC,CAAC,CAAC;wBACzE,MAAM;oBACP,KAAK,GAAG;wBACP,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAoB,EAAE,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// 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\tdecode(wire: readonly WireOp[]): 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;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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\t};\n}\n"]}
package/dist/errors.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  /** Error codes callers see (guide table). A refused or aborted reload keeps the code of its cause. */
2
- export type ChordErrorCode = "aborted" | "contract_mismatch" | "forbidden" | "gone" | "invalid" | "not_in_variant" | "not_ready" | "released" | "superseded" | "unavailable" | "upgrade_conflict" | "upgrade_required";
2
+ export declare const CHORD_ERROR_CODES: readonly ["aborted", "contract_mismatch", "forbidden", "gone", "invalid", "not_in_variant", "not_ready", "released", "superseded", "unavailable", "upgrade_conflict", "upgrade_required"];
3
+ export type ChordErrorCode = (typeof CHORD_ERROR_CODES)[number];
3
4
  /**
4
- * Finer cause inside a code, for logs and tests: e.g. `invalid` + `args`, `result`, `state`, `input`, `behavior`,
5
- * `duplicate`, `cycle`, `read_only`, `not_eager`, `registry_conflict`; `unavailable` + `unknown_type`.
5
+ * Finer cause inside a code, for logs and tests: e.g. `invalid` + `args`, `result`, `state`, `input`, `implementation`,
6
+ * `duplicate`, `cycle`, `read_only`, `not_host_lifetime`, `registry_conflict`; `unavailable` + `unknown_type`.
6
7
  */
7
8
  export type ChordErrorReason = string;
8
9
  export declare class ChordError extends Error {
@@ -1 +1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AO,CAAC,IAAI,CAAC,CAW9F"}
package/dist/errors.js CHANGED
@@ -1,3 +1,18 @@
1
+ /** Error codes callers see (guide table). A refused or aborted reload keeps the code of its cause. */
2
+ export const CHORD_ERROR_CODES = [
3
+ "aborted",
4
+ "contract_mismatch",
5
+ "forbidden",
6
+ "gone",
7
+ "invalid",
8
+ "not_in_variant",
9
+ "not_ready",
10
+ "released",
11
+ "superseded",
12
+ "unavailable",
13
+ "upgrade_conflict",
14
+ "upgrade_required",
15
+ ];
1
16
  const RETRYABLE = new Set(["superseded", "upgrade_conflict"]);
2
17
  export class ChordError extends Error {
3
18
  code;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAqBA,MAAM,SAAS,GAAgC,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAE3F,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC3B,IAAI,CAAiB;IACrB,MAAM,CAA+B;IACrC,SAAS,CAAU;IACnB,OAAO,CAAU;IAC1B,YACC,IAAoB,EACpB,OAAe,EACf,OAA2E;QAE3E,KAAK,CAAC,GAAG,IAAI,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,EAAE,EAAE;YAC1E,KAAK,EAAE,OAAO,EAAE,KAAK;SACrB,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;IACjC,CAAC;CACD;AAED,MAAM,CAAC,MAAM,YAAY,GAAG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AI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC","sourcesContent":["/** Error codes callers see (guide table). A refused or aborted reload keeps the code of its cause. */\nexport type ChordErrorCode =\n\t| \"aborted\"\n\t| \"contract_mismatch\"\n\t| \"forbidden\"\n\t| \"gone\"\n\t| \"invalid\"\n\t| \"not_in_variant\"\n\t| \"not_ready\"\n\t| \"released\"\n\t| \"superseded\"\n\t| \"unavailable\"\n\t| \"upgrade_conflict\"\n\t| \"upgrade_required\";\n\n/**\n * Finer cause inside a code, for logs and tests: e.g. `invalid` + `args`, `result`, `state`, `input`, `behavior`,\n * `duplicate`, `cycle`, `read_only`, `not_eager`, `registry_conflict`; `unavailable` + `unknown_type`.\n */\nexport type ChordErrorReason = string;\n\nconst RETRYABLE: ReadonlySet<ChordErrorCode> = new Set([\"superseded\", \"upgrade_conflict\"]);\n\nexport class ChordError extends Error {\n\treadonly code: ChordErrorCode;\n\treadonly reason: ChordErrorReason | undefined;\n\treadonly retryable: boolean;\n\treadonly details: unknown;\n\tconstructor(\n\t\tcode: ChordErrorCode,\n\t\tmessage: string,\n\t\toptions?: { cause?: unknown; details?: unknown; reason?: ChordErrorReason },\n\t) {\n\t\tsuper(`${code}${options?.reason ? `/${options.reason}` : \"\"}: ${message}`, {\n\t\t\tcause: options?.cause,\n\t\t});\n\t\tthis.name = \"ChordError\";\n\t\tthis.code = code;\n\t\tthis.reason = options?.reason;\n\t\tthis.retryable = RETRYABLE.has(code);\n\t\tthis.details = options?.details;\n\t}\n}\n\nexport const isChordError = (error: unknown, code?: ChordErrorCode): error is ChordError =>\n\terror instanceof ChordError && (code === undefined || error.code === code);\n\n/** For factories and methods refusing a principal: `throw forbidden()`. */\nexport const forbidden = (message = \"forbidden\"): ChordError => new ChordError(\"forbidden\", message);\n\nexport const invalid = (reason: ChordErrorReason, message: string, details?: unknown): ChordError =>\n\tnew ChordError(\"invalid\", message, { reason, details });\n\n/** Keeps a ChordError's code; anything else becomes `unavailable` with the original as cause. */\nexport const asChordError = (error: unknown, context: string): ChordError =>\n\terror instanceof ChordError\n\t\t? error\n\t\t: new ChordError(\"unavailable\", `${context}: ${error instanceof Error ? error.message : String(error)}`, {\n\t\t\t\tcause: error,\n\t\t\t});\n\n/** Runs every step, then throws one error, or an AggregateError when several failed. */\nexport async function runAll(steps: readonly (() => unknown)[], message: string): Promise<void> {\n\tconst errors: unknown[] = [];\n\tfor (const step of steps) {\n\t\ttry {\n\t\t\tawait step();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t}\n\tif (errors.length === 1) throw errors[0];\n\tif (errors.length > 1) throw new AggregateError(errors, message);\n}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAChC,SAAS;IACT,mBAAmB;IACnB,WAAW;IACX,MAAM;IACN,SAAS;IACT,gBAAgB;IAChB,WAAW;IACX,UAAU;IACV,YAAY;IACZ,aAAa;IACb,kBAAkB;IAClB,kBAAkB;CACT,CAAC;AASX,MAAM,SAAS,GAAgC,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAE3F,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC3B,IAAI,CAAiB;IACrB,MAAM,CAA+B;IACrC,SAAS,CAAU;IACnB,OAAO,CAAU;IAC1B,YACC,IAAoB,EACpB,OAAe,EACf,OAA2E;QAE3E,KAAK,CAAC,GAAG,IAAI,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,EAAE,EAAE;YAC1E,KAAK,EAAE,OAAO,EAAE,KAAK;SACrB,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACz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KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC;YACJ,MAAM,IAAI,EAAE,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;IACzC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC","sourcesContent":["/** Error codes callers see (guide table). A refused or aborted reload keeps the code of its cause. */\nexport const CHORD_ERROR_CODES = [\n\t\"aborted\",\n\t\"contract_mismatch\",\n\t\"forbidden\",\n\t\"gone\",\n\t\"invalid\",\n\t\"not_in_variant\",\n\t\"not_ready\",\n\t\"released\",\n\t\"superseded\",\n\t\"unavailable\",\n\t\"upgrade_conflict\",\n\t\"upgrade_required\",\n] as const;\nexport type ChordErrorCode = (typeof CHORD_ERROR_CODES)[number];\n\n/**\n * Finer cause inside a code, for logs and tests: e.g. `invalid` + `args`, `result`, `state`, `input`, `implementation`,\n * `duplicate`, `cycle`, `read_only`, `not_host_lifetime`, `registry_conflict`; `unavailable` + `unknown_type`.\n */\nexport type ChordErrorReason = string;\n\nconst RETRYABLE: ReadonlySet<ChordErrorCode> = new Set([\"superseded\", \"upgrade_conflict\"]);\n\nexport class ChordError extends Error {\n\treadonly code: ChordErrorCode;\n\treadonly reason: ChordErrorReason | undefined;\n\treadonly retryable: boolean;\n\treadonly details: unknown;\n\tconstructor(\n\t\tcode: ChordErrorCode,\n\t\tmessage: string,\n\t\toptions?: { cause?: unknown; details?: unknown; reason?: ChordErrorReason },\n\t) {\n\t\tsuper(`${code}${options?.reason ? `/${options.reason}` : \"\"}: ${message}`, {\n\t\t\tcause: options?.cause,\n\t\t});\n\t\tthis.name = \"ChordError\";\n\t\tthis.code = code;\n\t\tthis.reason = options?.reason;\n\t\tthis.retryable = RETRYABLE.has(code);\n\t\tthis.details = options?.details;\n\t}\n}\n\nexport const isChordError = (error: unknown, code?: ChordErrorCode): error is ChordError =>\n\terror instanceof ChordError && (code === undefined || error.code === code);\n\n/** For factories and methods refusing a principal: `throw forbidden()`. */\nexport const forbidden = (message = \"forbidden\"): ChordError => new ChordError(\"forbidden\", message);\n\nexport const invalid = (reason: ChordErrorReason, message: string, details?: unknown): ChordError =>\n\tnew ChordError(\"invalid\", message, { reason, details });\n\n/** Keeps a ChordError's code; anything else becomes `unavailable` with the original as cause. */\nexport const asChordError = (error: unknown, context: string): ChordError =>\n\terror instanceof ChordError\n\t\t? error\n\t\t: new ChordError(\"unavailable\", `${context}: ${error instanceof Error ? error.message : String(error)}`, {\n\t\t\t\tcause: error,\n\t\t\t});\n\n/** Runs every step, then throws one error, or an AggregateError when several failed. */\nexport async function runAll(steps: readonly (() => unknown)[], message: string): Promise<void> {\n\tconst errors: unknown[] = [];\n\tfor (const step of steps) {\n\t\ttry {\n\t\t\tawait step();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t}\n\tif (errors.length === 1) throw errors[0];\n\tif (errors.length > 1) throw new AggregateError(errors, message);\n}\n"]}