@earendil-works/chord 1.1.0 → 1.2.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 (186) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +77 -194
  3. package/dist/cell.d.ts +101 -0
  4. package/dist/cell.d.ts.map +1 -0
  5. package/dist/cell.js +316 -0
  6. package/dist/cell.js.map +1 -0
  7. package/dist/cluster.d.ts +26 -0
  8. package/dist/cluster.d.ts.map +1 -0
  9. package/dist/cluster.js +214 -0
  10. package/dist/cluster.js.map +1 -0
  11. package/dist/connection.d.ts +157 -0
  12. package/dist/connection.d.ts.map +1 -0
  13. package/dist/connection.js +757 -0
  14. package/dist/connection.js.map +1 -0
  15. package/dist/context/index.d.ts +12 -1
  16. package/dist/context/index.d.ts.map +1 -1
  17. package/dist/context/index.js.map +1 -1
  18. package/dist/contract.d.ts +133 -0
  19. package/dist/contract.d.ts.map +1 -0
  20. package/dist/contract.js +157 -0
  21. package/dist/contract.js.map +1 -0
  22. package/dist/declare.d.ts +70 -0
  23. package/dist/declare.d.ts.map +1 -0
  24. package/dist/declare.js +22 -0
  25. package/dist/declare.js.map +1 -0
  26. package/dist/delta/apply-immutable-trusted.js.map +1 -1
  27. package/dist/delta/diff.d.ts +1 -1
  28. package/dist/delta/diff.d.ts.map +1 -1
  29. package/dist/delta/diff.js.map +1 -1
  30. package/dist/delta/index.d.ts +2 -2
  31. package/dist/delta/index.d.ts.map +1 -1
  32. package/dist/delta/index.js +41 -0
  33. package/dist/delta/index.js.map +1 -1
  34. package/dist/delta/revision-validator.d.ts +1 -1
  35. package/dist/delta/revision-validator.d.ts.map +1 -1
  36. package/dist/delta/revision-validator.js.map +1 -1
  37. package/dist/delta/tracker.d.ts +1 -1
  38. package/dist/delta/tracker.d.ts.map +1 -1
  39. package/dist/delta/tracker.js +40 -4
  40. package/dist/delta/tracker.js.map +1 -1
  41. package/dist/errors.d.ts +27 -0
  42. package/dist/errors.d.ts.map +1 -0
  43. package/dist/errors.js +44 -0
  44. package/dist/errors.js.map +1 -0
  45. package/dist/host.d.ts +254 -0
  46. package/dist/host.d.ts.map +1 -0
  47. package/dist/host.js +795 -0
  48. package/dist/host.js.map +1 -0
  49. package/dist/index.d.ts +17 -10
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +8 -8
  52. package/dist/index.js.map +1 -1
  53. package/dist/json.d.ts +9 -1
  54. package/dist/json.d.ts.map +1 -1
  55. package/dist/json.js.map +1 -1
  56. package/dist/link.d.ts +72 -0
  57. package/dist/link.d.ts.map +1 -0
  58. package/dist/link.js +169 -0
  59. package/dist/link.js.map +1 -0
  60. package/dist/loader.d.ts +4 -0
  61. package/dist/loader.d.ts.map +1 -0
  62. package/dist/loader.js +68 -0
  63. package/dist/loader.js.map +1 -0
  64. package/dist/manager.d.ts +115 -0
  65. package/dist/manager.d.ts.map +1 -0
  66. package/dist/manager.js +319 -0
  67. package/dist/manager.js.map +1 -0
  68. package/dist/node.d.ts +3 -4
  69. package/dist/node.d.ts.map +1 -1
  70. package/dist/node.js +3 -2
  71. package/dist/node.js.map +1 -1
  72. package/dist/publish.d.ts +5 -0
  73. package/dist/publish.d.ts.map +1 -0
  74. package/dist/publish.js +40 -0
  75. package/dist/publish.js.map +1 -0
  76. package/dist/record.d.ts +320 -0
  77. package/dist/record.d.ts.map +1 -0
  78. package/dist/record.js +1292 -0
  79. package/dist/record.js.map +1 -0
  80. package/dist/registry.d.ts +25 -0
  81. package/dist/registry.d.ts.map +1 -0
  82. package/dist/registry.js +6 -0
  83. package/dist/registry.js.map +1 -0
  84. package/dist/reload.d.ts +118 -0
  85. package/dist/reload.d.ts.map +1 -0
  86. package/dist/reload.js +589 -0
  87. package/dist/reload.js.map +1 -0
  88. package/dist/remote.d.ts +70 -0
  89. package/dist/remote.d.ts.map +1 -0
  90. package/dist/remote.js +308 -0
  91. package/dist/remote.js.map +1 -0
  92. package/dist/schema.d.ts +21 -0
  93. package/dist/schema.d.ts.map +1 -0
  94. package/dist/schema.js +228 -0
  95. package/dist/schema.js.map +1 -0
  96. package/dist/state.d.ts +92 -0
  97. package/dist/state.d.ts.map +1 -0
  98. package/dist/{services/state.js → state.js} +28 -138
  99. package/dist/state.js.map +1 -0
  100. package/dist/types.d.ts +62 -262
  101. package/dist/types.d.ts.map +1 -1
  102. package/dist/types.js.map +1 -1
  103. package/dist/websocket.d.ts +16 -0
  104. package/dist/websocket.d.ts.map +1 -0
  105. package/dist/websocket.js +15 -0
  106. package/dist/websocket.js.map +1 -0
  107. package/dist/wire.d.ts +135 -0
  108. package/dist/wire.d.ts.map +1 -0
  109. package/dist/wire.js +112 -0
  110. package/dist/wire.js.map +1 -0
  111. package/docs/guide.md +750 -0
  112. package/docs/spec.md +261 -0
  113. package/docs/tutorial.md +909 -0
  114. package/package.json +9 -10
  115. package/src/delta/README.md +5 -3
  116. package/dist/api.d.ts +0 -20
  117. package/dist/api.d.ts.map +0 -1
  118. package/dist/api.js +0 -77
  119. package/dist/api.js.map +0 -1
  120. package/dist/bundler.d.ts +0 -6
  121. package/dist/bundler.d.ts.map +0 -1
  122. package/dist/bundler.js +0 -3
  123. package/dist/bundler.js.map +0 -1
  124. package/dist/facets/host.d.ts +0 -12
  125. package/dist/facets/host.d.ts.map +0 -1
  126. package/dist/facets/host.js +0 -763
  127. package/dist/facets/host.js.map +0 -1
  128. package/dist/facets/loader.d.ts +0 -3
  129. package/dist/facets/loader.d.ts.map +0 -1
  130. package/dist/facets/loader.js +0 -5
  131. package/dist/facets/loader.js.map +0 -1
  132. package/dist/node/bundle-loader.d.ts +0 -30
  133. package/dist/node/bundle-loader.d.ts.map +0 -1
  134. package/dist/node/bundle-loader.js +0 -377
  135. package/dist/node/bundle-loader.js.map +0 -1
  136. package/dist/node/bundle.d.ts +0 -26
  137. package/dist/node/bundle.d.ts.map +0 -1
  138. package/dist/node/bundle.js +0 -183
  139. package/dist/node/bundle.js.map +0 -1
  140. package/dist/node/manifest.d.ts +0 -36
  141. package/dist/node/manifest.d.ts.map +0 -1
  142. package/dist/node/manifest.js +0 -6
  143. package/dist/node/manifest.js.map +0 -1
  144. package/dist/node/package.d.ts +0 -15
  145. package/dist/node/package.d.ts.map +0 -1
  146. package/dist/node/package.js +0 -199
  147. package/dist/node/package.js.map +0 -1
  148. package/dist/services/consumer.d.ts +0 -11
  149. package/dist/services/consumer.d.ts.map +0 -1
  150. package/dist/services/consumer.js +0 -585
  151. package/dist/services/consumer.js.map +0 -1
  152. package/dist/services/errors.d.ts +0 -8
  153. package/dist/services/errors.d.ts.map +0 -1
  154. package/dist/services/errors.js +0 -22
  155. package/dist/services/errors.js.map +0 -1
  156. package/dist/services/handle.d.ts +0 -15
  157. package/dist/services/handle.d.ts.map +0 -1
  158. package/dist/services/handle.js +0 -101
  159. package/dist/services/handle.js.map +0 -1
  160. package/dist/services/instances.d.ts +0 -26
  161. package/dist/services/instances.d.ts.map +0 -1
  162. package/dist/services/instances.js +0 -140
  163. package/dist/services/instances.js.map +0 -1
  164. package/dist/services/loopback.d.ts +0 -5
  165. package/dist/services/loopback.d.ts.map +0 -1
  166. package/dist/services/loopback.js +0 -15
  167. package/dist/services/loopback.js.map +0 -1
  168. package/dist/services/provider.d.ts +0 -37
  169. package/dist/services/provider.d.ts.map +0 -1
  170. package/dist/services/provider.js +0 -521
  171. package/dist/services/provider.js.map +0 -1
  172. package/dist/services/state-codec.d.ts +0 -15
  173. package/dist/services/state-codec.d.ts.map +0 -1
  174. package/dist/services/state-codec.js +0 -133
  175. package/dist/services/state-codec.js.map +0 -1
  176. package/dist/services/state-internals.d.ts +0 -13
  177. package/dist/services/state-internals.d.ts.map +0 -1
  178. package/dist/services/state-internals.js +0 -10
  179. package/dist/services/state-internals.js.map +0 -1
  180. package/dist/services/state.d.ts +0 -28
  181. package/dist/services/state.d.ts.map +0 -1
  182. package/dist/services/state.js.map +0 -1
  183. package/dist/services/wire.d.ts +0 -63
  184. package/dist/services/wire.d.ts.map +0 -1
  185. package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AAC,CAAC;AAE/F,oGAAoG;AACpG,SAAS,OAAO,CAAC,IAAgB,EAAE,EAAc;IAChD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAc,CAAC;IACnC,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;IACrB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;QAC5B,IAAI,MAAM,KAAK,EAAE;YAAE,OAAO,IAAI,CAAC;QAC/B,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,SAAS;QAC/B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjB,mFAAmF;QACnF,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YACvC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE;gBAAE,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;oBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjG,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { ChildReloads, reconcileChild, runClusterReload } from \"./cluster.ts\";\nimport { type AcceptOptions, Connection, type LinkOptions, type RelayHold } from \"./connection.ts\";\nimport {\n\ttype AnyContract,\n\tbind,\n\ttype Handle,\n\ttype InputOf,\n\ttype LocalContract,\n\ttype LocalDef,\n\ttype RemoteContract,\n\ttype RemoteDef,\n} from \"./contract.ts\";\nimport { ChordError, invalid, runAll } from \"./errors.ts\";\nimport type { Link } from \"./link.ts\";\nimport { enqueue } from \"./publish.ts\";\nimport {\n\tCtxImpl,\n\ttype Decls,\n\ttype Factory,\n\tHandleImpl,\n\ttype Hold,\n\ttype HoldOwner,\n\ttype HostCore,\n\tmakeService,\n\tRecordImpl,\n\ttype ServeOptions,\n\ttype Service,\n} from \"./record.ts\";\nimport type { Registry, RegistryTable, RegistryView } from \"./registry.ts\";\nimport { type ReloadOptions, type ReloadReport, runReload } from \"./reload.ts\";\nimport { RemoteHandle } from \"./remote.ts\";\nimport { canonicalIdentity, canonicalJson, deepEqual, normalize } from \"./schema.ts\";\nimport type { Ctx, GetOptions, Principal } from \"./types.ts\";\nimport type { Frame } from \"./wire.ts\";\n\n/** The principal of in-host code. */\nexport const hostPrincipal: Principal = Object.freeze({ host: true });\n\n/**\n * Registers a factory for a type. Overloaded on the contract's definition (not the contract type) so TypeScript\n * keeps literal `kind`s in factory returns.\n */\nexport interface Serve {\n\t<D extends RemoteDef>(\n\t\ttype: RemoteContract<D>,\n\t\tfactory: Factory<RemoteContract<D>>,\n\t\toptions?: ServeOptions<RemoteContract<D>>,\n\t): void;\n\t<D extends LocalDef>(\n\t\ttype: LocalContract<D>,\n\t\tfactory: Factory<LocalContract<D>>,\n\t\toptions?: ServeOptions<LocalContract<D>>,\n\t): void;\n}\n\ntype AnyServe = (type: AnyContract, factory: Factory<AnyContract>, options?: ServeOptions) => void;\n\n/**\n * What a facet's `setup` gets. `serve` registers types; `root` and `registry` give the facet's code that is not a\n * Chord method, listener or task (Durable tools and hooks, callbacks of native libraries) access to its own host,\n * so plugins never need a process-global host. Both may be kept and used after `setup` returns.\n */\nexport interface FacetApi {\n\treadonly serve: Serve;\n\t/** The host's name (`server`, `session:S1`, ...). */\n\treadonly name: string;\n\t/** Starts a root on the facet's host (in its current epoch at call time). */\n\troot<T>(fn: (ctx: Ctx) => T | Promise<T>, options?: RootOptions): Promise<T>;\n\t/** The facet's host's registry view (`get(key, ctx)` reads the table of `ctx.epoch`). */\n\tregistry<V>(registry: Registry<V>): RegistryView<V>;\n}\n\n/** What a facet module exports (default export): the code that serves its types on one host kind. */\nexport interface FacetDefinition {\n\t/** Contract tokens this facet consumes; checked against providers at reload. */\n\treadonly uses?: readonly AnyContract[];\n\tsetup(api: FacetApi): void;\n}\n\n/** A named facet. Modules are named by their URL; reloading a facet replaces everything it served. */\nexport interface Facet extends FacetDefinition {\n\treadonly name: string;\n}\n\nexport const defineFacet = (\n\tsetup: (api: FacetApi) => void,\n\toptions: { readonly uses?: readonly AnyContract[] } = {},\n): FacetDefinition => ({ setup, uses: options.uses });\n\n/** Imports facet modules (fresh copies on every call) and names them by module URL. */\nexport type FacetLoader = (modules: readonly (string | URL)[]) => Promise<Facet[]>;\n\n/** A facet object, or a module (path or URL) whose default export is a FacetDefinition. */\nexport type PluginRef = Facet | string | URL;\n\nconst isFacet = (ref: PluginRef): ref is Facet => typeof ref === \"object\" && !(ref instanceof URL);\n\nexport interface HostOptions {\n\treadonly name?: string;\n\t/** Maps a principal to its record key (should include connection provenance and grant revision). */\n\treadonly principalKey?: (principal: Principal) => string;\n\t/** Validates every cell write and exposed state value against its schemas. */\n\treadonly dev?: boolean;\n\t/** Errors from background work (disposal, listeners, tasks). Defaults to console.error. */\n\treadonly onError?: (error: unknown) => void;\n\t/** Needed for `load`/`reload` with modules; `nodeLoader` from loader.ts in Node. */\n\treadonly loader?: FacetLoader;\n\t/** `client` (browser): never a reload participant, never carries roots or epochs. Default `host`. */\n\treadonly kind?: \"host\" | \"client\";\n\t/** The link to this host's parent (server). Can also be set later with `connect`. */\n\treadonly upstream?: Link;\n\treadonly upstreamOptions?: LinkOptions;\n}\n\n/** Where requests for hosts named `prefix…` go (on the server). */\nexport interface Route {\n\t/** Checked before resolving (or spawning) and again after: grants may change meanwhile. */\n\tauthorize(principal: Principal, hostName: string): boolean | Promise<boolean>;\n\t/** A link to the host, spawned if needed. */\n\tresolve(hostName: string): Promise<Link>;\n\t/** Principal the resolved host acts as when it calls back (default `{ host: hostName }`). */\n\treadonly principal?: (hostName: string) => Principal;\n}\n\n/** `invalidatePrincipal` matches: a predicate (this host only), or a pattern (fields that must be equal; propagates). */\nexport type PrincipalMatch = ((principal: Principal) => boolean) | Readonly<Record<string, unknown>>;\n\nexport interface RootOptions {\n\treadonly principal?: Principal;\n\treadonly signal?: AbortSignal;\n\t/** Start the root in a retained epoch (links carry epochs). Defaults to the current epoch. */\n\treadonly epoch?: number;\n}\n\nexport interface LoadOptions {\n\t/** Await eager activation (default true). False starts it but leaves readiness to `host.ready()`. */\n\treadonly awaitEager?: boolean;\n}\n\nexport interface Host {\n\treadonly name: string;\n\treadonly epoch: number;\n\treadonly previousEpoch: number | undefined;\n\treadonly serve: Serve;\n\t/** Installs synchronously, then awaits this facet's eager objects unless `awaitEager` is false. */\n\tinstall(facet: Facet, options?: LoadOptions): Promise<void>;\n\t/** Installs all facets before awaiting their eager objects; lazy objects stay lazy. */\n\tload(plugins: readonly PluginRef[], options?: LoadOptions): Promise<void>;\n\t/** Awaits the eager holds present at call time, including those started by `serve` or deferred loads. */\n\tready(): Promise<void>;\n\tget<C extends AnyContract>(type: C, input: InputOf<C>, options?: GetOptions): Handle<C>;\n\troot<T>(fn: (ctx: Ctx) => T | Promise<T>, options?: RootOptions): Promise<T>;\n\tregistry<V>(registry: Registry<V>): RegistryView<V>;\n\t/**\n\t * Force-disposes every record whose principal matches (never the host principal), re-stamps or closes matching\n\t * links, and propagates pattern matches to child hosts.\n\t */\n\tinvalidatePrincipal(match: PrincipalMatch): Promise<void>;\n\t/** Accepts a child link (a worker or a browser); requests on it act as `options.principal`. */\n\taccept(link: Link, options: AcceptOptions): void;\n\t/** Sets (or replaces, after a reconnect) the link to this host's parent; remote handles re-hold over it. */\n\tconnect(link: Link, options?: LinkOptions): void;\n\troute(prefix: string, route: Route): void;\n\t/** Reloads the given facets (modules are re-imported); facets not listed keep running unchanged. */\n\treload(plugins: readonly PluginRef[], options?: ReloadOptions): Promise<ReloadReport>;\n\tclose(): Promise<void>;\n}\n\nexport interface EpochState {\n\treadonly id: number;\n\treadonly services: Map<string, Service>;\n\ttables: ReadonlyMap<string, RegistryTable<unknown>>;\n\t/** Running roots with the number of their calls running here. */\n\treadonly roots: Map<string, number>;\n}\n\nconst EMPTY_TABLE: RegistryTable<never> = new Map<string, never>();\n\nexport function createHost(options: HostOptions = {}): Host {\n\treturn new HostImpl(options);\n}\n\nexport class HostImpl implements Host, HostCore {\n\treadonly name: string;\n\treadonly dev: boolean;\n\treadonly principal: Principal = hostPrincipal;\n\tinFactory = 0;\n\tfailed: unknown;\n\treadonly records = new Map<string, RecordImpl>();\n\treadonly epochs = new Map<number, EpochState>();\n\treadonly facets = new Map<string, Facet>();\n\treadonly eager = new Map<string, Hold>();\n\treadonly kind: \"host\" | \"client\";\n\treadonly connections = new Set<Connection>();\n\tupstream: Connection | undefined;\n\t/** Remote handles this host holds (re-held after an upstream reconnect). */\n\treadonly remotes = new Set<RemoteHandle>();\n\treadonly #routes = new Map<string, Route>();\n\treadonly #childReloads = new ChildReloads(this);\n\t/** Child facet modules by host-name prefix, from every committed cluster reload (for reconciling children). */\n\tremoteModules: Record<string, string[]> = {};\n\t/** Removal tombstones also reconcile children that connected during a transaction. */\n\tremoteRemoved: Record<string, string[]> = {};\n\t/** Highest epoch the parent has retired. */\n\t#retireAllowed = 0;\n\t/** Roots that came over a link, by the link they came from. */\n\t/** Foreign roots (started on another host), by the links they came over. */\n\treadonly #foreign = new Map<string, Set<Connection>>();\n\t/** Roots started on this host that have not ended. */\n\treadonly #local = new Set<string>();\n\treadonly #incarnation = Math.random().toString(36).slice(2, 8);\n\t/** Links each root's calls went out on. */\n\treadonly #rootLinks = new Map<string, Set<Connection>>();\n\tcurrent: EpochState;\n\tprevious: EpochState | undefined;\n\t/** The epoch a running reload will commit; new types activated during prepare install their behavior for it. */\n\tpending: EpochState | undefined;\n\t/** Activations of these types wait (reload gate). */\n\t/** Types behind a reload gate: new records of these types are rejected `upgrade_conflict` until commit/abort. */\n\tgating: ReadonlySet<string> | undefined;\n\treloading = false;\n\tretired: () => void = () => {};\n\treadonly #principalKey: (principal: Principal) => string;\n\treadonly #onError: (error: unknown) => void;\n\treadonly #loader: FacetLoader | undefined;\n\treadonly #dying = new Map<string, RecordImpl>();\n\treadonly #touches = new Map<string, Set<RecordImpl>>();\n\treadonly #order = new Map<string, Map<string, number>>();\n\treadonly #subscribers = new Map<string, Set<(table: RegistryTable<unknown>, epoch: number) => void>>();\n\t#epochSeq = 1;\n\t#rootSeq = 0;\n\n\tconstructor(options: HostOptions) {\n\t\tthis.name = options.name ?? \"host\";\n\t\tthis.dev = options.dev ?? false;\n\t\tthis.#principalKey = options.principalKey ?? canonicalJson;\n\t\tthis.#onError = options.onError ?? ((error) => console.error(\"chord:\", error));\n\t\tthis.#loader = options.loader;\n\t\tthis.current = { id: this.#epochSeq, services: new Map(), tables: new Map(), roots: new Map() };\n\t\tthis.epochs.set(this.current.id, this.current);\n\t\tthis.kind = options.kind ?? \"host\";\n\t\tif (options.upstream !== undefined) this.connect(options.upstream, options.upstreamOptions);\n\t}\n\n\tget epoch(): number {\n\t\treturn this.current.id;\n\t}\n\n\tget previousEpoch(): number | undefined {\n\t\treturn this.previous?.id;\n\t}\n\n\t/** Allocates the next epoch id, or adopts one issued by the coordinating server. */\n\tnextEpochId(given?: number): number {\n\t\tif (given !== undefined && given <= this.current.id)\n\t\t\tthrow new Error(`epoch ${given} is not newer than ${this.current.id}`);\n\t\tthis.#epochSeq = given ?? this.#epochSeq + 1;\n\t\treturn this.#epochSeq;\n\t}\n\n\treport(error: unknown): void {\n\t\tthis.#onError(error);\n\t}\n\n\t// ─── serving ───\n\n\treadonly serve: Serve = ((type, factory, options = {}) => {\n\t\tif (this.reloading) throw new Error(\"host.serve during a reload; serve from a facet passed to reload()\");\n\t\tthis.serveInto(this.current.services, makeService(type, factory, options, \"\"));\n\t\tif (options.eager) this.startEager(this.current.services.get(type.name)!);\n\t}) satisfies AnyServe as Serve;\n\n\tinstall(facet: Facet, options: LoadOptions = {}): Promise<void> {\n\t\tif (this.reloading) throw new Error(\"host.install during a reload\");\n\t\tif (this.facets.has(facet.name)) throw new Error(`facet ${facet.name} is already installed; use reload()`);\n\t\tconst added: Service[] = [];\n\t\tfacet.setup(\n\t\t\tthis.facetApi(((type, factory, options = {}) => {\n\t\t\t\tconst service = makeService(type, factory, options, facet.name);\n\t\t\t\tthis.serveInto(this.current.services, service);\n\t\t\t\tadded.push(service);\n\t\t\t}) satisfies AnyServe as Serve),\n\t\t);\n\t\tthis.facets.set(facet.name, facet);\n\t\tconst holds = added.filter((service) => service.options.eager).map((service) => this.startEager(service));\n\t\treturn options.awaitEager === false ? Promise.resolve() : this.#eagerReady(holds);\n\t}\n\n\tasync load(plugins: readonly PluginRef[], options: LoadOptions = {}): Promise<void> {\n\t\tconst facets = await this.resolve(plugins);\n\t\t// No await between installs: an eager factory may consume a type served by a later facet.\n\t\tawait Promise.all(facets.map((facet) => this.install(facet, options)));\n\t}\n\n\tready(): Promise<void> {\n\t\treturn this.#eagerReady(this.eager.values());\n\t}\n\n\t#eagerReady(holds: Iterable<Hold>): Promise<void> {\n\t\tconst ready = Promise.all([...holds].map((hold) => hold.ready)).then(() => {});\n\t\t// Ignoring install's return still reports through onError without an unhandled rejection.\n\t\tready.catch(() => {});\n\t\treturn ready;\n\t}\n\n\t/** Turns plugin references into facets, importing modules through the loader. */\n\tasync resolve(plugins: readonly PluginRef[]): Promise<Facet[]> {\n\t\tconst modules = plugins.filter((ref): ref is string | URL => !isFacet(ref));\n\t\tif (modules.length > 0 && this.#loader === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t\"loading modules needs createHost({ loader }), e.g. nodeLoader from @earendil-works/chord/node\",\n\t\t\t);\n\t\t}\n\t\tconst loaded = modules.length > 0 && this.#loader !== undefined ? await this.#loader(modules) : [];\n\t\treturn plugins.map((ref) => (isFacet(ref) ? ref : loaded.shift()!));\n\t}\n\n\tfacetApi(serve: Serve): FacetApi {\n\t\treturn {\n\t\t\tserve,\n\t\t\tname: this.name,\n\t\t\troot: (fn, options) => this.root(fn, options),\n\t\t\tregistry: (registry) => this.registry(registry),\n\t\t};\n\t}\n\n\tserveInto(services: Map<string, Service>, service: Service): void {\n\t\tif (services.has(service.contract.name)) throw new Error(`${service.contract.name} is already served`);\n\t\tservices.set(service.contract.name, service);\n\t}\n\n\tstartEager(service: Service): Hold {\n\t\tconst eager = service.options.eager;\n\t\tconst input = typeof eager === \"object\" ? eager.input : {};\n\t\tconst handle = this.acquire(service.contract, input, undefined, \"host\");\n\t\tthis.eager.set(service.contract.name, handle);\n\t\thandle.ready.catch((error: unknown) => this.report(error));\n\t\treturn handle;\n\t}\n\n\t// ─── HostCore ───\n\n\tcurrentEpoch(): number {\n\t\treturn this.current.id;\n\t}\n\n\thasEpoch(epoch: number): boolean {\n\t\treturn this.epochs.has(epoch);\n\t}\n\n\t*retainedEpochs(): Iterable<readonly [number, ReadonlyMap<string, Service>]> {\n\t\tfor (const [id, state] of this.epochs) yield [id, state.services];\n\t\tif (this.pending !== undefined) yield [this.pending.id, this.pending.services];\n\t}\n\n\tpendingEpoch(): number | undefined {\n\t\treturn this.pending?.id;\n\t}\n\n\t/** The current code for a type; a type a running reload adds is served from the pending epoch. */\n\tservice(typeName: string): Service | undefined {\n\t\treturn this.current.services.get(typeName) ?? this.pending?.services.get(typeName);\n\t}\n\n\taddressOf(type: AnyContract, input: unknown, principal: Principal, at?: string, candidate = false): string {\n\t\tif (at !== undefined && at !== this.name)\n\t\t\treturn remoteAddress(at, type, input, principal === this.principal ? undefined : principal);\n\t\tconst service = this.#bindingService(type.name, candidate);\n\t\tif (service === undefined) throw unknownType(type.name, this.name);\n\t\tconst normalized = normalize(service.contract.input, input, `${type.name} input`);\n\t\treturn this.#address(service, normalized, principal);\n\t}\n\n\t#address(service: Service, normalized: unknown, principal: Principal): string {\n\t\tconst key = principal === this.principal ? \"host\" : `p:${this.#principalKey(principal)}`;\n\t\treturn `${service.contract.name}\\u0000${canonicalIdentity(service.contract.input, normalized)}\\u0000${key}`;\n\t}\n\n\tacquire(\n\t\ttype: AnyContract,\n\t\tinput: unknown,\n\t\toptions: GetOptions | undefined,\n\t\towner: HoldOwner,\n\t\tfrom?: RecordImpl,\n\t\tcandidate = false,\n\t): Hold {\n\t\tif (options?.at !== undefined && options.at !== this.name)\n\t\t\treturn this.#acquireRemote(type, input, options, owner);\n\t\tconst service = this.#bindingService(type.name, candidate);\n\t\tif (service === undefined) throw unknownType(type.name, this.name);\n\t\tbind(service.contract, service.options.accepts, type);\n\t\tconst principal = options?.principal ?? this.principal;\n\t\tconst normalized = normalize(service.contract.input, input, `${type.name} input`);\n\t\tconst address = this.#address(service, normalized, principal);\n\t\tlet record = this.records.get(address);\n\t\tif (from !== undefined && record !== undefined && (record === from || reaches(record, from))) {\n\t\t\tthrow invalid(\"cycle\", `${from.address} -> ${address} would create a hold cycle`);\n\t\t}\n\t\tif (record === undefined) {\n\t\t\tif (this.gating?.has(type.name)) {\n\t\t\t\tthrow new ChordError(\"upgrade_conflict\", `${type.name} is being upgraded; retry`, { reason: \"gate\" });\n\t\t\t}\n\t\t\tconst dying = this.#dying.get(address);\n\t\t\tif (dying?.status === \"disposed\") this.#dying.delete(address);\n\t\t\trecord = new RecordImpl(this, {\n\t\t\t\taddress,\n\t\t\t\ttypeName: type.name,\n\t\t\t\tinput: normalized,\n\t\t\t\tprincipal,\n\t\t\t\teager:\n\t\t\t\t\tservice.options.eager !== undefined && service.options.eager !== false && principal === this.principal,\n\t\t\t});\n\t\t\tthis.records.set(address, record);\n\t\t\t// A new record for an address still being disposed waits for that cleanup (exclusive resources).\n\t\t\trecord.start(dying?.status === \"disposing\" ? dying.dispose(false) : undefined);\n\t\t}\n\t\tconst handle = new HandleImpl(record, type, owner);\n\t\trecord.addHold(handle);\n\t\treturn handle;\n\t}\n\n\tforget(record: RecordImpl): void {\n\t\tif (this.records.get(record.address) === record) this.records.delete(record.address);\n\t\tif (record.status === \"disposing\") this.#dying.set(record.address, record);\n\t}\n\n\ttouch(rootId: string, record: RecordImpl): void {\n\t\tlet touched = this.#touches.get(rootId);\n\t\tif (touched === undefined) {\n\t\t\ttouched = new Set();\n\t\t\tthis.#touches.set(rootId, touched);\n\t\t}\n\t\ttouched.add(record);\n\t}\n\n\t// ─── roots ───\n\n\tasync root<T>(fn: (ctx: Ctx) => T | Promise<T>, options: RootOptions = {}): Promise<T> {\n\t\t// The incarnation keeps root ids unique across restarts of a host with the same name.\n\t\tconst rootId = `${this.name}#${this.#incarnation}:${++this.#rootSeq}`;\n\t\tthis.#local.add(rootId);\n\t\treturn this.joinRoot(rootId, options.epoch ?? this.current.id, fn, options);\n\t}\n\n\t/**\n\t * Runs `fn` inside root `rootId` of `epoch`. A root counts as running here (for retirement) while any of its calls\n\t * runs here. A root that started here ends when its last call here settles, even if it went out and came back\n\t * over a link meanwhile. A foreign root (started elsewhere, arriving `from` a link) keeps its leases on records\n\t * until every link it came over announced its end (`root_end`) or closed, so its re-entry stays grandfathered.\n\t */\n\tasync joinRoot<T>(\n\t\trootId: string,\n\t\tepochId: number,\n\t\tfn: (ctx: Ctx) => T | Promise<T>,\n\t\toptions: { readonly principal?: Principal; readonly signal?: AbortSignal; readonly from?: Connection } = {},\n\t): Promise<T> {\n\t\tconst epoch = this.epochs.get(epochId);\n\t\tif (epoch === undefined) {\n\t\t\tthis.#local.delete(rootId);\n\t\t\tthrow new ChordError(\"superseded\", `epoch ${epochId} is not retained by ${this.name}`);\n\t\t}\n\t\tif (options.from !== undefined && !this.#local.has(rootId)) {\n\t\t\tlet links = this.#foreign.get(rootId);\n\t\t\tif (links === undefined) {\n\t\t\t\tlinks = new Set();\n\t\t\t\tthis.#foreign.set(rootId, links);\n\t\t\t}\n\t\t\tlinks.add(options.from);\n\t\t}\n\t\tepoch.roots.set(rootId, (epoch.roots.get(rootId) ?? 0) + 1);\n\t\tconst ctx = new CtxImpl(this, {\n\t\t\tsignal: options.signal ?? new AbortController().signal,\n\t\t\trootId,\n\t\t\tepoch: epoch.id,\n\t\t\tprincipal: options.principal ?? this.principal,\n\t\t});\n\t\ttry {\n\t\t\treturn await fn(ctx);\n\t\t} finally {\n\t\t\tctx.close();\n\t\t\tconst count = (epoch.roots.get(rootId) ?? 1) - 1;\n\t\t\tif (count > 0) epoch.roots.set(rootId, count);\n\t\t\telse {\n\t\t\t\tepoch.roots.delete(rootId);\n\t\t\t\tif (!this.#foreign.has(rootId)) this.endRoot(rootId);\n\t\t\t\tthis.maybeRetire();\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Remembers that calls of `rootId` went out on `connection`, which must hear when the root ends. */\n\trootSent(rootId: string, connection: Connection): void {\n\t\tlet links = this.#rootLinks.get(rootId);\n\t\tif (links === undefined) {\n\t\t\tlinks = new Set();\n\t\t\tthis.#rootLinks.set(rootId, links);\n\t\t}\n\t\tlinks.add(connection);\n\t}\n\n\t/** A root ended (here, or announced by its origin): end its leases and tell the links it went out on. */\n\tendRoot(rootId: string): void {\n\t\tthis.#local.delete(rootId);\n\t\tthis.#foreign.delete(rootId);\n\t\tfor (const record of this.#touches.get(rootId) ?? []) record.rootEnded(rootId);\n\t\tthis.#touches.delete(rootId);\n\t\tfor (const connection of this.#rootLinks.get(rootId) ?? []) connection.send({ t: \"root_end\", rootId });\n\t\tthis.#rootLinks.delete(rootId);\n\t}\n\n\t/**\n\t * `from` announced the end of a foreign root (or closed). Honored only if the root came over `from`: a peer cannot\n\t * end leases of roots it never carried. The root ends when no link that brought it remains.\n\t */\n\tforeignRootEnded(rootId: string, from: Connection): void {\n\t\tconst links = this.#foreign.get(rootId);\n\t\tif (links === undefined || !links.delete(from) || links.size > 0) return;\n\t\tconst running = [...this.epochs.values()].some((epoch) => epoch.roots.has(rootId));\n\t\t// Still running here (a call in flight): the lease ends when it settles.\n\t\tif (running) this.#foreign.delete(rootId);\n\t\telse this.endRoot(rootId);\n\t}\n\n\t/**\n\t * Retires the previous epoch once no local roots of it remain. A child also waits for its parent to retire it:\n\t * roots span hosts, and an old root on the server may still call in.\n\t */\n\tmaybeRetire(): void {\n\t\tconst previous = this.previous;\n\t\tif (previous === undefined || previous.roots.size > 0) return;\n\t\tif (this.kind !== \"client\" && this.upstream !== undefined && previous.id > this.#retireAllowed) return;\n\t\tthis.retire();\n\t}\n\n\tallowRetire(epoch: number): void {\n\t\tthis.#retireAllowed = Math.max(this.#retireAllowed, epoch);\n\t\tthis.maybeRetire();\n\t}\n\n\t/** Drops the previous epoch: its behaviors and the declarations only it used. */\n\tretire(): void {\n\t\tconst previous = this.previous;\n\t\tif (previous === undefined) return;\n\t\tthis.previous = undefined;\n\t\tthis.epochs.delete(previous.id);\n\t\tfor (const record of [...this.records.values()]) this.retireBehavior(record, previous.id);\n\t\tfor (const connection of this.connections) {\n\t\t\tif (connection.role === \"downstream\" && connection.peer?.kind === \"host\")\n\t\t\t\tconnection.send({ t: \"retire\", epoch: previous.id });\n\t\t}\n\t\tthis.retired();\n\t}\n\n\t/**\n\t * Drops a record's behavior for `epoch` and what only that behavior declared, in disposal order: resources close\n\t * (reverse open order) before its holds are released.\n\t */\n\tretireBehavior(record: RecordImpl, epoch: number): void {\n\t\tconst installed = record.behaviors.get(epoch);\n\t\trecord.behaviors.delete(epoch);\n\t\tif (installed === undefined || installed.decls === record.decls) return;\n\t\tconst kept = record.allDecls();\n\t\tconst keep = <T>(pick: (decls: Decls) => Iterable<T>): Set<T> =>\n\t\t\tnew Set([...kept].flatMap((decls) => [...pick(decls)]));\n\t\tconst holds = keep((decls) => decls.holds.values());\n\t\tconst resources = keep((decls) => decls.resources.values());\n\t\tconst derives = keep((decls) => decls.derives.values());\n\t\tfor (const derived of installed.decls.derives.values()) if (!derives.has(derived)) derived.detach();\n\t\tconst closing = [...installed.decls.resources.values()]\n\t\t\t.filter((resource) => !resources.has(resource))\n\t\t\t.sort((a, b) => record.openOrder.indexOf(b) - record.openOrder.indexOf(a));\n\t\tconst releasing = [...installed.decls.holds.values()].filter((hold) => !holds.has(hold));\n\t\trecord.refreshSchemas();\n\t\trunAll(\n\t\t\t[\n\t\t\t\t...closing.map((resource) => () => resource.close(record.openOrder)),\n\t\t\t\t...releasing.map((hold) => () => hold.release()),\n\t\t\t],\n\t\t\t`${record.address}: retiring epoch ${epoch} failed`,\n\t\t).catch((error: unknown) => this.report(error));\n\t}\n\n\t// ─── registries ───\n\n\tregistry<V>(registry: Registry<V>): RegistryView<V> {\n\t\tconst table = (ctx?: Ctx): RegistryTable<V> => {\n\t\t\tconst epoch = ctx === undefined ? this.current : this.epochs.get(ctx.epoch);\n\t\t\tif (epoch === undefined) throw new ChordError(\"superseded\", `epoch ${ctx?.epoch} is retired`);\n\t\t\treturn (epoch.tables.get(registry.name) ?? EMPTY_TABLE) as RegistryTable<V>;\n\t\t};\n\t\treturn {\n\t\t\ttable,\n\t\t\tget: (key, ctx) => table(ctx).get(key),\n\t\t\tsubscribe: (listener) => {\n\t\t\t\tlet set = this.#subscribers.get(registry.name);\n\t\t\t\tif (set === undefined) {\n\t\t\t\t\tset = new Set();\n\t\t\t\t\tthis.#subscribers.set(registry.name, set);\n\t\t\t\t}\n\t\t\t\tconst wrapped = listener as (table: RegistryTable<unknown>, epoch: number) => void;\n\t\t\t\tset.add(wrapped);\n\t\t\t\twrapped(table(), this.current.id);\n\t\t\t\treturn () => set.delete(wrapped);\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Builds registry tables from (record, declarations) pairs. Throws registry_conflict. */\n\tbuildTables(entries: Iterable<readonly [RecordImpl, Decls]>): Map<string, RegistryTable<unknown>> {\n\t\tconst byRegistry = new Map<string, Map<string, { value: unknown; record: RecordImpl }>>();\n\t\tfor (const [record, decls] of entries) {\n\t\t\tfor (const { registry, key, value } of decls.registrations.values()) {\n\t\t\t\tlet entries = byRegistry.get(registry.name);\n\t\t\t\tif (entries === undefined) {\n\t\t\t\t\tentries = new Map();\n\t\t\t\t\tbyRegistry.set(registry.name, entries);\n\t\t\t\t}\n\t\t\t\tconst existing = entries.get(key);\n\t\t\t\tif (existing !== undefined && existing.record !== record && registry.conflict === \"error\") {\n\t\t\t\t\tthrow invalid(\n\t\t\t\t\t\t\"registry_conflict\",\n\t\t\t\t\t\t`${registry.name}: ${key} registered by ${existing.record.address} and ${record.address}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tentries.set(key, { value, record });\n\t\t\t\tlet order = this.#order.get(registry.name);\n\t\t\t\tif (order === undefined) {\n\t\t\t\t\torder = new Map();\n\t\t\t\t\tthis.#order.set(registry.name, order);\n\t\t\t\t}\n\t\t\t\tif (!order.has(key)) order.set(key, order.size);\n\t\t\t}\n\t\t}\n\t\tconst tables = new Map<string, RegistryTable<unknown>>();\n\t\tfor (const [name, entries] of byRegistry) {\n\t\t\tconst order = this.#order.get(name)!;\n\t\t\tconst sorted = [...entries].sort(([a], [b]) => order.get(a)! - order.get(b)!);\n\t\t\ttables.set(name, new Map(sorted.map(([key, entry]) => [key, entry.value])));\n\t\t}\n\t\treturn tables;\n\t}\n\n\t/**\n\t * The service a hold binds against: the current one, or for a prepare rerun (`candidate`) the running reload's\n\t * pending one, so consumer and provider of a breaking change can reload in one batch.\n\t */\n\t#bindingService(typeName: string, candidate: boolean): Service | undefined {\n\t\treturn (candidate ? this.pending?.services.get(typeName) : undefined) ?? this.service(typeName);\n\t}\n\n\t/** Live records with their current declarations; records waiting for a reload's commit only with `candidates`. */\n\tliveDecls(candidates = false): [RecordImpl, Decls][] {\n\t\treturn [...this.records.values()]\n\t\t\t.filter((record) => record.status === \"live\" && (candidates || !record.deferredRuntime))\n\t\t\t.map((record) => [record, record.decls]);\n\t}\n\n\tcheckRegistrations(record: RecordImpl, decls: Decls): void {\n\t\tif (decls.registrations.size === 0) return;\n\t\tthis.buildTables([...this.liveDecls().filter(([other]) => other !== record), [record, decls]]);\n\t}\n\n\tregistriesChanged(including?: RecordImpl): void {\n\t\tconst entries = this.liveDecls().filter(([record]) => record !== including);\n\t\tif (including !== undefined) entries.push([including, including.decls]);\n\t\tthis.installTables(this.current, this.buildTables(entries));\n\t}\n\n\t/** A commit failed midway: from now on this host admits no work (calls fail `unavailable/host_failed`). */\n\tfail(error: unknown): void {\n\t\tthis.failed ??= error;\n\t\tthis.report(error);\n\t}\n\n\t/** Installs tables for `epoch`; subscribers hear about changed tables of the current epoch (all tables when `all`). */\n\tinstallTables(epoch: EpochState, tables: Map<string, RegistryTable<unknown>>, all = false): void {\n\t\tconst before = epoch.tables;\n\t\tepoch.tables = tables;\n\t\tif (epoch !== this.current) return;\n\t\tfor (const [name, listeners] of this.#subscribers) {\n\t\t\tconst next = tables.get(name) ?? EMPTY_TABLE;\n\t\t\tif (!all && sameTable(before.get(name) ?? EMPTY_TABLE, next)) continue;\n\t\t\tconst current = [...listeners];\n\t\t\tenqueue(() => {\n\t\t\t\tfor (const listener of current) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlistener(next, epoch.id);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthis.report(error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t// ─── public API ───\n\n\tget<C extends AnyContract>(type: C, input: InputOf<C>, options?: GetOptions): Handle<C> {\n\t\treturn this.acquire(type, input, options, \"external\").proxy as Handle<C>;\n\t}\n\n\tasync invalidatePrincipal(match: PrincipalMatch): Promise<void> {\n\t\tconst matches = typeof match === \"function\" ? match : (principal: Principal) => matchesPattern(match, principal);\n\t\tconst reason = new ChordError(\"gone\", \"principal invalidated\");\n\t\t// Links acting as a matching principal are re-stamped (if the acceptor can) or closed.\n\t\tfor (const connection of [...this.connections]) {\n\t\t\tif (connection.role !== \"downstream\" || !matches(connection.principal)) continue;\n\t\t\t// Relays under the old principal close at once, including those still resolving their route.\n\t\t\tconnection.revoke(connection.restamp?.(connection.principal));\n\t\t}\n\t\t// Patterns propagate to child hosts, which dispose their own matching records (e.g. relayed guests).\n\t\tif (typeof match !== \"function\") {\n\t\t\tfor (const connection of this.connections) {\n\t\t\t\tif (connection.role === \"downstream\" && connection.peer.kind === \"host\") {\n\t\t\t\t\tconnection.send({ t: \"invalidate\", pattern: match });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst matching = [...this.records.values()].filter(\n\t\t\t(record) => record.principal !== this.principal && matches(record.principal),\n\t\t);\n\t\tawait disposeHoldersFirst(matching, reason, \"invalidatePrincipal: disposal failed\");\n\t}\n\n\t// ─── links ───\n\n\taccept(link: Link, options: AcceptOptions): void {\n\t\tconst kind = options.kind ?? \"client\";\n\t\tif (kind === \"host\" && options.name === undefined) throw new TypeError(\"accepting a host link needs its name\");\n\t\tthis.#addConnection(link, {\n\t\t\t...options,\n\t\t\trole: \"downstream\",\n\t\t\tprincipal: options.principal,\n\t\t\tpeer: { kind, name: kind === \"host\" ? options.name : undefined },\n\t\t});\n\t}\n\n\tconnect(link: Link, options: LinkOptions = {}): void {\n\t\tif (this.upstream?.open) this.upstream.link.close(\"replaced\");\n\t\tconst connection = this.#addConnection(link, {\n\t\t\t...options,\n\t\t\trole: \"upstream\",\n\t\t\tprincipal: undefined,\n\t\t\tpeer: { kind: \"host\", name: undefined },\n\t\t});\n\t\tthis.upstream = connection;\n\t\t// Remote handles that lost their link re-hold over the new one; state subscribers get a reset.\n\t\tfor (const handle of this.remotes) if (handle.binding === undefined) connection.hold(handle);\n\t}\n\n\t#addConnection(link: Link, config: ConstructorParameters<typeof Connection>[2]): Connection {\n\t\tconst connection = new Connection(this, link, config);\n\t\tthis.connections.add(connection);\n\t\treturn connection;\n\t}\n\n\troute(prefix: string, route: Route): void {\n\t\tthis.#routes.set(prefix, route);\n\t}\n\n\t/**\n\t * A child host announced its epoch. In step: usable. Behind: fenced (nothing is routed to it) and reconciled by a\n\t * reload of its modules to this host's epoch, never by renumbering what it runs. Ahead: impossible, refused.\n\t */\n\tpeerHello(connection: Connection, epoch: number): void {\n\t\tif (epoch === this.current.id) {\n\t\t\tconnection.markSynced(epoch);\n\t\t\treturn;\n\t\t}\n\t\tif (epoch > this.current.id) {\n\t\t\tthis.report(new ChordError(\"invalid\", `${connection.name} runs epoch ${epoch}, ahead of ${this.current.id}`));\n\t\t\tconnection.link.close(\"epoch ahead of parent\");\n\t\t\treturn;\n\t\t}\n\t\tconnection.peerEpoch = epoch;\n\t\tconnection.fencedEpochs.add(epoch);\n\t\treconcileChild(this, connection).catch((error: unknown) => {\n\t\t\tthis.report(error);\n\t\t\tconnection.link.close(\"reconciliation failed\");\n\t\t});\n\t}\n\n\tconnectionClosed(connection: Connection): void {\n\t\tthis.connections.delete(connection);\n\t\t// Foreign roots that came over this link will never announce their end over it.\n\t\tfor (const [rootId, links] of [...this.#foreign])\n\t\t\tif (links.has(connection)) this.foreignRootEnded(rootId, connection);\n\t\tfor (const links of this.#rootLinks.values()) links.delete(connection);\n\t\tif (this.upstream === connection) {\n\t\t\tthis.upstream = undefined;\n\t\t\tthis.#childReloads.parentLost();\n\t\t}\n\t}\n\n\tforgetRemote(handle: RemoteHandle): void {\n\t\tthis.remotes.delete(handle);\n\t}\n\n\t/** A downstream host connection by its configured name (never by what a peer announced). */\n\t#childNamed(name: string): Connection | undefined {\n\t\treturn [...this.connections].find(\n\t\t\t(connection) =>\n\t\t\t\tconnection.role === \"downstream\" && connection.peer.kind === \"host\" && connection.peer.name === name,\n\t\t);\n\t}\n\n\t#acquireRemote(type: AnyContract, input: unknown, options: GetOptions, owner: HoldOwner): Hold {\n\t\tconst at = options.at!;\n\t\tif (type.scope !== \"remote\") throw invalid(\"local\", `${type.name} is local and cannot be reached at ${at}`);\n\t\tconst principal =\n\t\t\toptions.principal === undefined || options.principal === this.principal ? undefined : options.principal;\n\t\tconst handle = new RemoteHandle(this, {\n\t\t\tcontract: type,\n\t\t\tat,\n\t\t\tinput,\n\t\t\tprincipal,\n\t\t\towner,\n\t\t\taddress: remoteAddress(at, type, input, principal),\n\t\t});\n\t\tthis.remotes.add(handle);\n\t\tconst bindWhenSynced = (connection: Promise<Connection>): void => {\n\t\t\tconnection.then(\n\t\t\t\t(target) => {\n\t\t\t\t\tif (handle.status === \"loading\" && handle.binding === undefined) target.hold(handle);\n\t\t\t\t},\n\t\t\t\t(error: unknown) => handle.gone(error),\n\t\t\t);\n\t\t};\n\t\tconst direct = this.#childNamed(at);\n\t\tif (this.upstream !== undefined) this.upstream.hold(handle);\n\t\telse if (direct !== undefined) bindWhenSynced(direct.whenSynced().then(() => direct));\n\t\telse {\n\t\t\tconst route = this.#routeFor(at);\n\t\t\tif (route === undefined) handle.gone(new ChordError(\"unavailable\", `no route to ${at}`));\n\t\t\telse bindWhenSynced(this.#resolve(route, at, principal ?? this.principal));\n\t\t}\n\t\treturn handle;\n\t}\n\n\t#routeFor(hostName: string): Route | undefined {\n\t\tlet best: [string, Route] | undefined;\n\t\tfor (const entry of this.#routes) {\n\t\t\tif (hostName.startsWith(entry[0]) && (best === undefined || entry[0].length > best[0].length)) best = entry;\n\t\t}\n\t\treturn best?.[1];\n\t}\n\n\t/** Authorize, resolve (maybe spawn), authorize again; returns the synced connection to the host. */\n\tasync #resolve(\n\t\troute: Route,\n\t\thostName: string,\n\t\tprincipal: Principal,\n\t\tstill: () => boolean = () => true,\n\t): Promise<Connection> {\n\t\tconst refuse = (): ChordError => new ChordError(\"forbidden\", `${hostName} refused for this principal`);\n\t\tconst revoked = (): ChordError => new ChordError(\"gone\", \"principal invalidated while resolving\");\n\t\tif (!(await route.authorize(principal, hostName))) throw refuse();\n\t\tif (!still()) throw revoked();\n\t\tconst link = await route.resolve(hostName);\n\t\tif (!still()) throw revoked();\n\t\tif (!(await route.authorize(principal, hostName))) throw refuse();\n\t\tif (!still()) throw revoked();\n\t\tlet connection = [...this.connections].find((candidate) => candidate.link === link);\n\t\tconnection ??= this.#addConnection(link, {\n\t\t\trole: \"downstream\",\n\t\t\tprincipal: route.principal?.(hostName) ?? { host: hostName },\n\t\t\tpeer: { kind: \"host\", name: hostName },\n\t\t});\n\t\tawait connection.whenSynced();\n\t\tif (!still()) throw revoked();\n\t\treturn connection;\n\t}\n\n\t/**\n\t * Relays a hold from `relay.origin` to the host it names. Relaying needs a route: it is where authorization\n\t * lives. The origin's authorization generation is re-checked after every await and right before forwarding, so a\n\t * revocation during resolution wins.\n\t */\n\tasync relay(relay: RelayHold): Promise<void> {\n\t\tconst at = relay.frame.at;\n\t\tconst route = this.#routeFor(at);\n\t\tif (route === undefined) {\n\t\t\tthrow this.#childNamed(at) === undefined\n\t\t\t\t? new ChordError(\"unavailable\", `no route to ${at}`)\n\t\t\t\t: new ChordError(\"forbidden\", `no route authorizes ${at}`);\n\t\t}\n\t\tconst down = await this.#resolve(route, at, relay.principal, () => relay.current);\n\t\tif (!relay.current) return;\n\t\trelay.open(down);\n\t}\n\n\treload(plugins: readonly PluginRef[], options: ReloadOptions = {}): Promise<ReloadReport> {\n\t\t// Client-local facet epochs never cross the parent link; only child hosts require cluster coordination.\n\t\tif (this.kind !== \"client\" && this.upstream !== undefined) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew ChordError(\"unavailable\", \"reloads are coordinated by the server\", { reason: \"not_coordinator\" }),\n\t\t\t);\n\t\t}\n\t\tconst children = [...this.connections].some(\n\t\t\t(connection) => connection.role === \"downstream\" && connection.peer.kind === \"host\",\n\t\t);\n\t\treturn children || options.remote !== undefined || options.remoteRemove !== undefined\n\t\t\t? runClusterReload(this, plugins, options)\n\t\t\t: runReload(this, plugins, options);\n\t}\n\n\tonReloadFrame(connection: Connection, frame: Extract<Frame, { t: \"prepare\" | \"commit\" | \"abort\" }>): void {\n\t\tthis.#childReloads.handle(connection, frame);\n\t}\n\n\trememberRemoteModules(\n\t\tremote: Readonly<Record<string, readonly string[]>> | undefined,\n\t\tremove: Readonly<Record<string, readonly string[]>> | undefined,\n\t): void {\n\t\tfor (const prefix of new Set([...Object.keys(remote ?? {}), ...Object.keys(remove ?? {})])) {\n\t\t\tconst modules = remote?.[prefix] ?? [];\n\t\t\tconst removed = remove?.[prefix] ?? [];\n\t\t\tthis.remoteModules[prefix] = [...new Set([...(this.remoteModules[prefix] ?? []), ...modules])].filter(\n\t\t\t\t(module) => !removed.includes(module),\n\t\t\t);\n\t\t\tthis.remoteRemoved[prefix] = [...new Set([...(this.remoteRemoved[prefix] ?? []), ...removed])].filter(\n\t\t\t\t(module) => !modules.includes(module),\n\t\t\t);\n\t\t}\n\t}\n\n\t/** The epoch id the next reload would commit. */\n\tpeekNextEpoch(): number {\n\t\treturn this.#epochSeq + 1;\n\t}\n\n\t/**\n\t * Disposes every record, holders before what they hold (a resource's `close` may still use the objects its record\n\t * holds, local or remote), then closes the links.\n\t */\n\tasync close(): Promise<void> {\n\t\tthis.eager.clear();\n\t\tconst reason = new ChordError(\"gone\", `host ${this.name} closed`);\n\t\ttry {\n\t\t\tawait disposeHoldersFirst([...this.records.values()], reason, \"host close: disposal failed\");\n\t\t} finally {\n\t\t\tfor (const connection of [...this.connections]) connection.link.close(\"host closed\");\n\t\t}\n\t}\n}\n\n/**\n * Force-disposes `records` in waves: a record goes once no record of the set that holds it is left, so holders are\n * disposed (and their resources closed) while what they hold is still live. In-host holds are acyclic. Errors of\n * every disposal are collected.\n */\nasync function disposeHoldersFirst(records: readonly RecordImpl[], reason: unknown, message: string): Promise<void> {\n\tconst remaining = new Set(records);\n\tconst held = (record: RecordImpl): Set<RecordImpl> => {\n\t\tconst result = new Set<RecordImpl>();\n\t\tfor (const decls of record.allDecls()) {\n\t\t\tfor (const hold of decls.holds.values()) if (hold.record !== undefined) result.add(hold.record);\n\t\t}\n\t\treturn result;\n\t};\n\tconst holds = new Map(records.map((record) => [record, held(record)] as const));\n\tconst errors: unknown[] = [];\n\twhile (remaining.size > 0) {\n\t\tconst heldByRemaining = new Set<RecordImpl>();\n\t\tfor (const record of remaining) for (const target of holds.get(record) ?? []) heldByRemaining.add(target);\n\t\tlet wave = [...remaining].filter((record) => !heldByRemaining.has(record));\n\t\t// A cycle cannot happen in-host; dispose the rest together rather than loop.\n\t\tif (wave.length === 0) wave = [...remaining];\n\t\tfor (const record of wave) remaining.delete(record);\n\t\tconst results = await Promise.allSettled(wave.map((record) => record.dispose(true, reason)));\n\t\tfor (const result of results) if (result.status === \"rejected\") errors.push(result.reason);\n\t}\n\tif (errors.length === 1) throw errors[0];\n\tif (errors.length > 1) throw new AggregateError(errors, message);\n}\n\nfunction sameTable(a: RegistryTable<unknown>, b: RegistryTable<unknown>): boolean {\n\tif (a.size !== b.size) return false;\n\tconst keys = [...a.keys()];\n\treturn [...b].every(([key, value], index) => keys[index] === key && a.get(key) === value);\n}\n\nconst matchesPattern = (pattern: Readonly<Record<string, unknown>>, principal: Principal): boolean =>\n\tprincipal !== null &&\n\ttypeof principal === \"object\" &&\n\tObject.entries(pattern).every(([key, value]) => deepEqual((principal as Record<string, unknown>)[key], value));\n\n/** Address of a remote hold, as the consumer sees it (the provider normalizes the input). */\nconst remoteAddress = (at: string, type: AnyContract, input: unknown, principal: Principal | undefined): string =>\n\t`@${at}\\u0000${type.name}\\u0000${canonicalJson(input)}\\u0000${principal === undefined ? \"host\" : canonicalJson(principal)}`;\n\nconst unknownType = (type: string, host: string): ChordError =>\n\tnew ChordError(\"unavailable\", `${type} is not served by ${host}`, { reason: \"unknown_type\" });\n\n/** True if `from` holds `to`, directly or transitively, through record-owned holds on this host. */\nfunction reaches(from: RecordImpl, to: RecordImpl): boolean {\n\tconst seen = new Set<RecordImpl>();\n\tconst stack = [from];\n\twhile (stack.length > 0) {\n\t\tconst record = stack.pop()!;\n\t\tif (record === to) return true;\n\t\tif (seen.has(record)) continue;\n\t\tseen.add(record);\n\t\t// Remote holds have no record here: cycles across hosts are avoided by convention.\n\t\tfor (const decls of record.allDecls()) {\n\t\t\tfor (const hold of decls.holds.values()) if (hold.record !== undefined) stack.push(hold.record);\n\t\t}\n\t}\n\treturn false;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,19 @@
1
- /**
2
- * Chord is a standalone application-composition runtime for agentic applications.
3
- */
4
- export { combineFacetLoaders, createFacetHost, createRemoteServiceBinding, createStaticFacetLoader, defineFacet, defineService, replicatedState, } from "./api.ts";
1
+ export type { Cell } from "./cell.ts";
2
+ export type { AcceptOptions, LinkOptions } from "./connection.ts";
3
+ export type { Context, ContextKey } from "./context/index.ts";
4
+ export { type Accepts, type Adapter, type AnyContract, type BehaviorOf, bind, coverage, type Description, type Handle, type InputOf, type LocalContract, local, type MembersOf, method, opaque, type RemoteContract, remote, } from "./contract.ts";
5
+ export { type CellDecl, cell, type DerivationDecl, derivation, type ListenerDecl, listener, type Resource, type ResourceDecl, type ResourceSpec, resource, type Subscribable, } from "./declare.ts";
5
6
  export type { Draft } from "./delta/index.ts";
6
- export { type CopyJsonOptions, copyJson, isJsonValue } from "./json.ts";
7
- export { isRemoteServiceErrorCode, REMOTE_SERVICE_ERROR_CODES, RemoteServiceError, type RemoteServiceErrorCode, } from "./services/errors.ts";
8
- export { createRemoteServiceEndpoint, type RemoteServiceEndpoint, RemoteServiceProvider, type ServiceUpdatePublisher, } from "./services/provider.ts";
9
- export { createServiceStateDecoder, createServiceStateEncoder, type ServiceStateDecoder, type ServiceStateEncoder, } from "./services/state-codec.ts";
10
- export { createServiceCatalogueCall, createServiceSubscribeCall, createServiceUnsubscribeCall, decodeServiceControlCall, parseServiceCall, parseServiceCatalogue, parseServiceProviderUpdate, parseServiceSubscriptionSnapshot, parseWireServiceProviderUpdate, parseWireServiceSubscriptionSnapshot, type ServiceControlCall, type WireServiceInstanceSnapshot, type WireServiceMemberSnapshot, type WireServiceProviderUpdate, type WireServiceSubscriptionSnapshot, } from "./services/wire.ts";
11
- export type { AttachedReplicatedState, Context, ContextKey, Facet, FacetEnvironment, FacetHost, FacetLoader, FacetOptions, JsonRepresentation, JsonValue, LoadedFacets, MutableReplicatedState, RemoteServiceBinding, RemoteServiceBindingOptions, RemoteServiceSource, RemoteServices, RemoteServiceTransport, ReplicatedState, ReplicatedStateDelivery, ReplicatedStateSource, ReplicatedStateSourceAttachment, ReplicatedStateSourceFrame, ReplicatedStateSourceOptions, Service, ServiceCall, ServiceCatalogueEntry, ServiceInstanceAddress, ServiceInstanceSnapshot, ServiceMemberSnapshot, ServiceMode, ServiceProviderUpdate, ServiceSpawner, ServiceSubscription, ServiceSubscriptionSnapshot, } from "./types.ts";
7
+ export { ChordError, type ChordErrorCode, forbidden, invalid, isChordError } from "./errors.ts";
8
+ export type { PrincipalMatch, Route } from "./host.ts";
9
+ export { createHost, defineFacet, type Facet, type FacetApi, type FacetDefinition, type FacetLoader, type Host, type HostOptions, hostPrincipal, type LoadOptions, type PluginRef, type RootOptions, } from "./host.ts";
10
+ export { type CopyJsonOptions, copyJson, isJsonValue, type JsonRepresentation, type JsonValue } from "./json.ts";
11
+ export { type IpcChannel, ipcLink, type Link, memoryLinkPair, type WebSocketLike, webSocketLink } from "./link.ts";
12
+ export type { Factory, Self, ServeOptions } from "./record.ts";
13
+ export { defineRegistry, type Registry, type RegistryTable, type RegistryView } from "./registry.ts";
14
+ export type { ReloadOptions, ReloadReport } from "./reload.ts";
15
+ export { type AttachedReplicatedState, type MutableReplicatedState, type ReplicatedState, type ReplicatedStateDelivery, type ReplicatedStateSource, type ReplicatedStateSourceAttachment, type ReplicatedStateSourceFrame, type ReplicatedStateSourceOptions, replicatedState, } from "./state.ts";
16
+ export type { Ctx, GetOptions, HandleStatus, Principal, Readable, Shape, StateEvent } from "./types.ts";
17
+ export { acceptWebSockets, type WebSocketAcceptOptions, type WebSocketServerLike } from "./websocket.ts";
18
+ export type { Frame } from "./wire.ts";
12
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,0BAA0B,EAC1B,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,eAAe,GACf,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EACN,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,EAClB,KAAK,sBAAsB,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,2BAA2B,EAC3B,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,KAA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,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACrG,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACN,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EACjC,eAAe,GACf,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,KAAK,sBAAsB,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACzG,YAAY,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- /**
2
- * Chord is a standalone application-composition runtime for agentic applications.
3
- */
4
- export { combineFacetLoaders, createFacetHost, createRemoteServiceBinding, createStaticFacetLoader, defineFacet, defineService, replicatedState, } from "./api.js";
1
+ export { bind, coverage, local, method, opaque, remote, } from "./contract.js";
2
+ export { cell, derivation, listener, resource, } from "./declare.js";
3
+ export { ChordError, forbidden, invalid, isChordError } from "./errors.js";
4
+ export { createHost, defineFacet, hostPrincipal, } from "./host.js";
5
5
  export { copyJson, isJsonValue } from "./json.js";
6
- export { isRemoteServiceErrorCode, REMOTE_SERVICE_ERROR_CODES, RemoteServiceError, } from "./services/errors.js";
7
- export { createRemoteServiceEndpoint, RemoteServiceProvider, } from "./services/provider.js";
8
- export { createServiceStateDecoder, createServiceStateEncoder, } from "./services/state-codec.js";
9
- export { createServiceCatalogueCall, createServiceSubscribeCall, createServiceUnsubscribeCall, decodeServiceControlCall, parseServiceCall, parseServiceCatalogue, parseServiceProviderUpdate, parseServiceSubscriptionSnapshot, parseWireServiceProviderUpdate, parseWireServiceSubscriptionSnapshot, } from "./services/wire.js";
6
+ export { ipcLink, memoryLinkPair, webSocketLink } from "./link.js";
7
+ export { defineRegistry } from "./registry.js";
8
+ export { replicatedState, } from "./state.js";
9
+ export { acceptWebSockets } from "./websocket.js";
10
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,0BAA0B,EAC1B,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,eAAe,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EAAwB,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EACN,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,GAElB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,2BAA2B,EAE3B,qBAAqB,GAErB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,yBAAyB,EACzB,yBAAyB,GAGzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,EAC1B,gCAAgC,EAChC,8BAA8B,EAC9B,oCAAoC,GAMpC,MAAM,oBAAoB,CAAC","sourcesContent":["/**\n * Chord is a standalone application-composition runtime for agentic applications.\n */\nexport {\n\tcombineFacetLoaders,\n\tcreateFacetHost,\n\tcreateRemoteServiceBinding,\n\tcreateStaticFacetLoader,\n\tdefineFacet,\n\tdefineService,\n\treplicatedState,\n} from \"./api.ts\";\nexport type { Draft } from \"./delta/index.ts\";\nexport { type CopyJsonOptions, copyJson, isJsonValue } from \"./json.ts\";\nexport {\n\tisRemoteServiceErrorCode,\n\tREMOTE_SERVICE_ERROR_CODES,\n\tRemoteServiceError,\n\ttype RemoteServiceErrorCode,\n} from \"./services/errors.ts\";\nexport {\n\tcreateRemoteServiceEndpoint,\n\ttype RemoteServiceEndpoint,\n\tRemoteServiceProvider,\n\ttype ServiceUpdatePublisher,\n} from \"./services/provider.ts\";\nexport {\n\tcreateServiceStateDecoder,\n\tcreateServiceStateEncoder,\n\ttype ServiceStateDecoder,\n\ttype ServiceStateEncoder,\n} from \"./services/state-codec.ts\";\nexport {\n\tcreateServiceCatalogueCall,\n\tcreateServiceSubscribeCall,\n\tcreateServiceUnsubscribeCall,\n\tdecodeServiceControlCall,\n\tparseServiceCall,\n\tparseServiceCatalogue,\n\tparseServiceProviderUpdate,\n\tparseServiceSubscriptionSnapshot,\n\tparseWireServiceProviderUpdate,\n\tparseWireServiceSubscriptionSnapshot,\n\ttype ServiceControlCall,\n\ttype WireServiceInstanceSnapshot,\n\ttype WireServiceMemberSnapshot,\n\ttype WireServiceProviderUpdate,\n\ttype WireServiceSubscriptionSnapshot,\n} from \"./services/wire.ts\";\nexport type {\n\tAttachedReplicatedState,\n\tContext,\n\tContextKey,\n\tFacet,\n\tFacetEnvironment,\n\tFacetHost,\n\tFacetLoader,\n\tFacetOptions,\n\tJsonRepresentation,\n\tJsonValue,\n\tLoadedFacets,\n\tMutableReplicatedState,\n\tRemoteServiceBinding,\n\tRemoteServiceBindingOptions,\n\tRemoteServiceSource,\n\tRemoteServices,\n\tRemoteServiceTransport,\n\tReplicatedState,\n\tReplicatedStateDelivery,\n\tReplicatedStateSource,\n\tReplicatedStateSourceAttachment,\n\tReplicatedStateSourceFrame,\n\tReplicatedStateSourceOptions,\n\tService,\n\tServiceCall,\n\tServiceCatalogueEntry,\n\tServiceInstanceAddress,\n\tServiceInstanceSnapshot,\n\tServiceMemberSnapshot,\n\tServiceMode,\n\tServiceProviderUpdate,\n\tServiceSpawner,\n\tServiceSubscription,\n\tServiceSubscriptionSnapshot,\n} from \"./types.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAKN,IAAI,EACJ,QAAQ,EAKR,KAAK,EAEL,MAAM,EACN,MAAM,EAEN,MAAM,GACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAEN,IAAI,EAEJ,UAAU,EAEV,QAAQ,EAIR,QAAQ,GAER,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAuB,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhG,OAAO,EACN,UAAU,EACV,WAAW,EAOX,aAAa,GAIb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAwB,QAAQ,EAAE,WAAW,EAA2C,MAAM,WAAW,CAAC;AACjH,OAAO,EAAmB,OAAO,EAAa,cAAc,EAAsB,aAAa,EAAE,MAAM,WAAW,CAAC;AAEnH,OAAO,EAAE,cAAc,EAAwD,MAAM,eAAe,CAAC;AAErG,OAAO,EASN,eAAe,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAyD,MAAM,gBAAgB,CAAC","sourcesContent":["export type { Cell } from \"./cell.ts\";\nexport type { AcceptOptions, LinkOptions } from \"./connection.ts\";\nexport type { Context, ContextKey } from \"./context/index.ts\";\nexport {\n\ttype Accepts,\n\ttype Adapter,\n\ttype AnyContract,\n\ttype BehaviorOf,\n\tbind,\n\tcoverage,\n\ttype Description,\n\ttype Handle,\n\ttype InputOf,\n\ttype LocalContract,\n\tlocal,\n\ttype MembersOf,\n\tmethod,\n\topaque,\n\ttype RemoteContract,\n\tremote,\n} from \"./contract.ts\";\nexport {\n\ttype CellDecl,\n\tcell,\n\ttype DerivationDecl,\n\tderivation,\n\ttype ListenerDecl,\n\tlistener,\n\ttype Resource,\n\ttype ResourceDecl,\n\ttype ResourceSpec,\n\tresource,\n\ttype Subscribable,\n} from \"./declare.ts\";\nexport type { Draft } from \"./delta/index.ts\";\nexport { ChordError, type ChordErrorCode, forbidden, invalid, isChordError } from \"./errors.ts\";\nexport type { PrincipalMatch, Route } from \"./host.ts\";\nexport {\n\tcreateHost,\n\tdefineFacet,\n\ttype Facet,\n\ttype FacetApi,\n\ttype FacetDefinition,\n\ttype FacetLoader,\n\ttype Host,\n\ttype HostOptions,\n\thostPrincipal,\n\ttype LoadOptions,\n\ttype PluginRef,\n\ttype RootOptions,\n} from \"./host.ts\";\nexport { type CopyJsonOptions, copyJson, isJsonValue, type JsonRepresentation, type JsonValue } from \"./json.ts\";\nexport { type IpcChannel, ipcLink, type Link, memoryLinkPair, type WebSocketLike, webSocketLink } from \"./link.ts\";\nexport type { Factory, Self, ServeOptions } from \"./record.ts\";\nexport { defineRegistry, type Registry, type RegistryTable, type RegistryView } from \"./registry.ts\";\nexport type { ReloadOptions, ReloadReport } from \"./reload.ts\";\nexport {\n\ttype AttachedReplicatedState,\n\ttype MutableReplicatedState,\n\ttype ReplicatedState,\n\ttype ReplicatedStateDelivery,\n\ttype ReplicatedStateSource,\n\ttype ReplicatedStateSourceAttachment,\n\ttype ReplicatedStateSourceFrame,\n\ttype ReplicatedStateSourceOptions,\n\treplicatedState,\n} from \"./state.ts\";\nexport type { Ctx, GetOptions, HandleStatus, Principal, Readable, Shape, StateEvent } from \"./types.ts\";\nexport { acceptWebSockets, type WebSocketAcceptOptions, type WebSocketServerLike } from \"./websocket.ts\";\nexport type { Frame } from \"./wire.ts\";\n"]}
package/dist/json.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- import type { JsonValue } from "./types.ts";
1
+ export type JsonValue = null | boolean | number | string | JsonValue[] | {
2
+ [key: string]: JsonValue;
3
+ };
4
+ type IsAny<T> = 0 extends 1 & T ? true : false;
5
+ /** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */
6
+ export type JsonRepresentation<T> = IsAny<T> extends true ? JsonValue : unknown extends T ? JsonValue : T extends null | boolean | number | string ? T : T extends readonly (infer TItem)[] ? JsonRepresentation<TItem>[] : T extends object ? {
7
+ [TKey in keyof T]: JsonRepresentation<T[TKey]>;
8
+ } : never;
2
9
  export type CopyJsonOptions = {
3
10
  /** Omit undefined object properties while preserving strict array semantics. */
4
11
  readonly omitUndefinedProperties?: boolean;
@@ -7,4 +14,5 @@ export type CopyJsonOptions = {
7
14
  export declare function copyJson(value: unknown, options?: CopyJsonOptions): JsonValue;
8
15
  /** Return whether a value is finite strict JSON with plain objects and no cycles. */
9
16
  export declare function isJsonValue(value: unknown): value is JsonValue;
17
+ export {};
10
18
  //# sourceMappingURL=json.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAS5C,MAAM,MAAM,eAAe,GAAG;IAC7B,gFAAgF;IAChF,QAAQ,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CAC3C,CAAC;AAEF,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAE7E;AAuDD,qFAAqF;AACrF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D"}
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtG,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAE/C,iGAAiG;AACjG,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,SAAS,IAAI,GACtD,SAAS,GACT,OAAO,SAAS,CAAC,GAChB,SAAS,GACT,CAAC,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D,OAAO,IAAI,CAAC;IACb,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;AACF,CAAC","sourcesContent":["import type { JsonValue } from \"./types.ts\";\n\nconst DATA_DESCRIPTOR: PropertyDescriptor = {\n\tvalue: undefined,\n\twritable: true,\n\tenumerable: true,\n\tconfigurable: true,\n};\n\nexport type CopyJsonOptions = {\n\t/** Omit undefined object properties while preserving strict array semantics. */\n\treadonly omitUndefinedProperties?: boolean;\n};\n\n/** Copy a value into an alias-free strict-JSON tree owned by the caller. */\nexport function copyJson(value: unknown, options?: CopyJsonOptions): JsonValue {\n\treturn copy(value, undefined, options?.omitUndefinedProperties === true);\n}\n\nfunction copy(value: unknown, ancestors: Set<object> | undefined, omitUndefinedProperties: boolean): JsonValue {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\") {\n\t\tif (Number.isFinite(value)) return value;\n\t\tthrow new TypeError(\"Value contains a non-finite number and is not strict JSON\");\n\t}\n\tif (typeof value !== \"object\")\n\t\tthrow new TypeError(`Value contains a non-JSON ${typeof value}; expected strict JSON`);\n\tconst active = ancestors ?? new Set<object>();\n\tif (active.has(value)) throw new TypeError(\"Value contains cycles and is not strict JSON\");\n\tactive.add(value);\n\ttry {\n\t\tif (Array.isArray(value)) {\n\t\t\t// Indices plus `length` only: extra, symbol, and missing keys all change the count.\n\t\t\tif (Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1) {\n\t\t\t\tthrow new TypeError(\"Value must contain strict JSON dense plain arrays\");\n\t\t\t}\n\t\t\tconst result = new Array<JsonValue>(value.length);\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, index);\n\t\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\t\tthrow new TypeError(\"Value must contain strict JSON enumerable indexed data properties\");\n\t\t\t\t}\n\t\t\t\tdefineData(result, String(index), copy(descriptor.value, active, omitUndefinedProperties));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t\tconst prototype = Object.getPrototypeOf(value);\n\t\tif (prototype !== Object.prototype && prototype !== null) {\n\t\t\tthrow new TypeError(\"Value must contain strict JSON plain objects or arrays\");\n\t\t}\n\t\tconst result = Object.create(prototype) as Record<string, JsonValue>;\n\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Value contains a symbol key and is not strict JSON\");\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key)!;\n\t\t\tif (!descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\tthrow new TypeError(\"Value must contain strict JSON enumerable data properties\");\n\t\t\t}\n\t\t\tif (descriptor.value === undefined && omitUndefinedProperties) continue;\n\t\t\tdefineData(result, key, copy(descriptor.value, active, omitUndefinedProperties));\n\t\t}\n\t\treturn result;\n\t} finally {\n\t\tactive.delete(value);\n\t}\n}\n\nfunction defineData(target: object, key: PropertyKey, value: JsonValue): void {\n\tDATA_DESCRIPTOR.value = value;\n\tObject.defineProperty(target, key, DATA_DESCRIPTOR);\n\tDATA_DESCRIPTOR.value = undefined;\n}\n\n/** Return whether a value is finite strict JSON with plain objects and no cycles. */\nexport function isJsonValue(value: unknown): value is JsonValue {\n\treturn check(value, new Set<object>());\n}\n\nfunction check(value: unknown, ancestors: Set<object>): boolean {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) {\n\t\tif (Object.getPrototypeOf(value) !== Array.prototype) return false;\n\t\tconst keys = Reflect.ownKeys(value);\n\t\tif (keys.length !== value.length + 1 || keys.some((key) => typeof key !== \"string\")) return false;\n\t\tif (ancestors.has(value)) return false;\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\t\t\tif (\n\t\t\t\t\tdescriptor === undefined ||\n\t\t\t\t\t!descriptor.enumerable ||\n\t\t\t\t\t!(\"value\" in descriptor) ||\n\t\t\t\t\t!check(descriptor.value, ancestors)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) return false;\n\tif (Reflect.ownKeys(value).some((key) => typeof key !== \"string\")) return false;\n\tif (ancestors.has(value)) return false;\n\tancestors.add(value);\n\ttry {\n\t\tfor (const descriptor of Object.values(Object.getOwnPropertyDescriptors(value))) {\n\t\t\tif (!descriptor.enumerable || !(\"value\" in descriptor) || !check(descriptor.value, ancestors)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t} finally {\n\t\tancestors.delete(value);\n\t}\n}\n"]}
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAiBA,MAAM,eAAe,GAAuB;IAC3C,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE,IAAI;CAClB,CAAC;AAOF,4EAA4E;AAC5E,MAAM,UAAU,QAAQ,CAAC,KAAc,EAAE,OAAyB;IACjE,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,uBAAuB,KAAK,IAAI,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,IAAI,CAAC,KAAc,EAAE,SAAkC,EAAE,uBAAgC;IACjG,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5F,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;gBAC/F,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;AACF,CAAC","sourcesContent":["export type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\n/** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */\nexport type JsonRepresentation<T> = IsAny<T> extends true\n\t? JsonValue\n\t: unknown extends T\n\t\t? JsonValue\n\t\t: T extends null | boolean | number | string\n\t\t\t? T\n\t\t\t: T extends readonly (infer TItem)[]\n\t\t\t\t? JsonRepresentation<TItem>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { [TKey in keyof T]: JsonRepresentation<T[TKey]> }\n\t\t\t\t\t: never;\n\nconst DATA_DESCRIPTOR: PropertyDescriptor = {\n\tvalue: undefined,\n\twritable: true,\n\tenumerable: true,\n\tconfigurable: true,\n};\n\nexport type CopyJsonOptions = {\n\t/** Omit undefined object properties while preserving strict array semantics. */\n\treadonly omitUndefinedProperties?: boolean;\n};\n\n/** Copy a value into an alias-free strict-JSON tree owned by the caller. */\nexport function copyJson(value: unknown, options?: CopyJsonOptions): JsonValue {\n\treturn copy(value, undefined, options?.omitUndefinedProperties === true);\n}\n\nfunction copy(value: unknown, ancestors: Set<object> | undefined, omitUndefinedProperties: boolean): JsonValue {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\") {\n\t\tif (Number.isFinite(value)) return value;\n\t\tthrow new TypeError(\"Value contains a non-finite number and is not strict JSON\");\n\t}\n\tif (typeof value !== \"object\")\n\t\tthrow new TypeError(`Value contains a non-JSON ${typeof value}; expected strict JSON`);\n\tconst active = ancestors ?? new Set<object>();\n\tif (active.has(value)) throw new TypeError(\"Value contains cycles and is not strict JSON\");\n\tactive.add(value);\n\ttry {\n\t\tif (Array.isArray(value)) {\n\t\t\t// Indices plus `length` only: extra, symbol, and missing keys all change the count.\n\t\t\tif (Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1) {\n\t\t\t\tthrow new TypeError(\"Value must contain strict JSON dense plain arrays\");\n\t\t\t}\n\t\t\tconst result = new Array<JsonValue>(value.length);\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, index);\n\t\t\t\tif (descriptor === undefined || !descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\t\tthrow new TypeError(\"Value must contain strict JSON enumerable indexed data properties\");\n\t\t\t\t}\n\t\t\t\tdefineData(result, String(index), copy(descriptor.value, active, omitUndefinedProperties));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t\tconst prototype = Object.getPrototypeOf(value);\n\t\tif (prototype !== Object.prototype && prototype !== null) {\n\t\t\tthrow new TypeError(\"Value must contain strict JSON plain objects or arrays\");\n\t\t}\n\t\tconst result = Object.create(prototype) as Record<string, JsonValue>;\n\t\tfor (const key of Reflect.ownKeys(value)) {\n\t\t\tif (typeof key === \"symbol\") throw new TypeError(\"Value contains a symbol key and is not strict JSON\");\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key)!;\n\t\t\tif (!descriptor.enumerable || !(\"value\" in descriptor)) {\n\t\t\t\tthrow new TypeError(\"Value must contain strict JSON enumerable data properties\");\n\t\t\t}\n\t\t\tif (descriptor.value === undefined && omitUndefinedProperties) continue;\n\t\t\tdefineData(result, key, copy(descriptor.value, active, omitUndefinedProperties));\n\t\t}\n\t\treturn result;\n\t} finally {\n\t\tactive.delete(value);\n\t}\n}\n\nfunction defineData(target: object, key: PropertyKey, value: JsonValue): void {\n\tDATA_DESCRIPTOR.value = value;\n\tObject.defineProperty(target, key, DATA_DESCRIPTOR);\n\tDATA_DESCRIPTOR.value = undefined;\n}\n\n/** Return whether a value is finite strict JSON with plain objects and no cycles. */\nexport function isJsonValue(value: unknown): value is JsonValue {\n\treturn check(value, new Set<object>());\n}\n\nfunction check(value: unknown, ancestors: Set<object>): boolean {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) {\n\t\tif (Object.getPrototypeOf(value) !== Array.prototype) return false;\n\t\tconst keys = Reflect.ownKeys(value);\n\t\tif (keys.length !== value.length + 1 || keys.some((key) => typeof key !== \"string\")) return false;\n\t\tif (ancestors.has(value)) return false;\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\t\t\tif (\n\t\t\t\t\tdescriptor === undefined ||\n\t\t\t\t\t!descriptor.enumerable ||\n\t\t\t\t\t!(\"value\" in descriptor) ||\n\t\t\t\t\t!check(descriptor.value, ancestors)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) return false;\n\tif (Reflect.ownKeys(value).some((key) => typeof key !== \"string\")) return false;\n\tif (ancestors.has(value)) return false;\n\tancestors.add(value);\n\ttry {\n\t\tfor (const descriptor of Object.values(Object.getOwnPropertyDescriptors(value))) {\n\t\t\tif (!descriptor.enumerable || !(\"value\" in descriptor) || !check(descriptor.value, ancestors)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t} finally {\n\t\tancestors.delete(value);\n\t}\n}\n"]}
package/dist/link.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import type { Frame } from "./wire.ts";
2
+ /** An ordered (FIFO), bidirectional frame channel between two hosts. */
3
+ export interface Link {
4
+ readonly closed: boolean;
5
+ send(frame: Frame): void;
6
+ /** Sets the single receiver. Frames arriving earlier are queued. */
7
+ receive(handler: (frame: Frame) => void): void;
8
+ onClose(handler: (reason: string) => void): void;
9
+ /** Closes both ends: the peer gets a `bye`. */
10
+ close(reason?: string): void;
11
+ }
12
+ /** Shared plumbing: receive queue, close handlers, `bye`. Transports implement `transmit` and `shutdown`. */
13
+ declare abstract class BaseLink implements Link {
14
+ #private;
15
+ get closed(): boolean;
16
+ protected abstract transmit(frame: Frame): void;
17
+ protected abstract shutdown(): void;
18
+ send(frame: Frame): void;
19
+ receive(handler: (frame: Frame) => void): void;
20
+ onClose(handler: (reason: string) => void): void;
21
+ close(reason?: string): void;
22
+ /** Delivers a parsed frame from the transport. */
23
+ protected deliver(frame: Frame): void;
24
+ /** Marks the link closed (transport ended) and notifies once. */
25
+ protected ended(reason: string): void;
26
+ }
27
+ export declare class MemoryLink extends BaseLink {
28
+ #private;
29
+ peer: MemoryLink | undefined;
30
+ /** Simulates a dead network: frames are dropped silently in both directions and no close is signalled. */
31
+ sever(): void;
32
+ protected transmit(frame: Frame): void;
33
+ protected shutdown(): void;
34
+ }
35
+ /** Two connected in-memory links (tests). */
36
+ export declare function memoryLinkPair(): [MemoryLink, MemoryLink];
37
+ /** `process` in a forked child, or the parent's `ChildProcess`. Structural, so Chord needs no Node types here. */
38
+ export interface IpcChannel {
39
+ readonly connected: boolean;
40
+ send(message: unknown): boolean;
41
+ on(event: "message", listener: (message: unknown) => void): unknown;
42
+ on(event: "disconnect", listener: () => void): unknown;
43
+ off(event: "message", listener: (message: unknown) => void): unknown;
44
+ off(event: "disconnect", listener: () => void): unknown;
45
+ }
46
+ /** Chord frames on an IPC channel are wrapped as `{ chord2: frame }`; other messages (control) pass by. */
47
+ export declare class IpcLink extends BaseLink {
48
+ #private;
49
+ constructor(channel: IpcChannel);
50
+ protected transmit(frame: Frame): void;
51
+ protected shutdown(): void;
52
+ }
53
+ export declare const ipcLink: (channel: IpcChannel) => IpcLink;
54
+ /** The WHATWG WebSocket surface: the browser `WebSocket`, Node's global `WebSocket`, and `ws` sockets. */
55
+ export interface WebSocketLike {
56
+ readonly readyState: number;
57
+ send(data: string): void;
58
+ close(code?: number, reason?: string): void;
59
+ addEventListener(type: "message", listener: (event: {
60
+ readonly data: unknown;
61
+ }) => void): void;
62
+ addEventListener(type: "open" | "close" | "error", listener: () => void): void;
63
+ }
64
+ export declare class WebSocketLink extends BaseLink {
65
+ #private;
66
+ constructor(socket: WebSocketLike);
67
+ protected transmit(frame: Frame): void;
68
+ protected shutdown(): void;
69
+ }
70
+ export declare const webSocketLink: (socket: WebSocketLike) => WebSocketLink;
71
+ export {};
72
+ //# sourceMappingURL=link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,wEAAwE;AACxE,MAAM,WAAW,IAAI;IACpB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACzB,oEAAoE;IACpE,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI,CAAC;IAC/C,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IACjD,+CAA+C;IAC/C,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,6GAA6G;AAC7G,uBAAe,QAAS,YAAW,IAAI;;IAMtC,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAChD,SAAS,CAAC,QAAQ,CAAC,QAAQ,IAAI,IAAI,CAAC;IAEpC,IAAI,CAAC,KAAK,EAAE,KAAK,GA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,OAAO,CAAC;CACxD;AAED,2GAA2G;AAC3G,qBAAa,OAAQ,SAAQ,QAAQ;;IAQpC,YAAY,OAAO,EAAE,UAAU,EAK9B;IAED,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAErC;IAED,SAAS,CAAC,QAAQ,IAAI,IAAI,CAGzB;CACD;AAED,eAAO,MAAM,OAAO,YAAa,UAAU,KAAG,OAA+B,CAAC;AAI9E,0GAA0G;AAC1G,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAC/F,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAC/E;AAID,qBAAa,aAAc,SAAQ,QAAQ;;IAI1C,YAAY,MAAM,EAAE,aAAa,EAchC;IAED,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAIrC;IAED,SAAS,CAAC,QAAQ,IAAI,IAAI,CAGzB;CACD;AAED,eAAO,MAAM,aAAa,WAAY,aAAa,KAAG,aAA0C,CAAC"}
package/dist/link.js ADDED
@@ -0,0 +1,169 @@
1
+ /** Shared plumbing: receive queue, close handlers, `bye`. Transports implement `transmit` and `shutdown`. */
2
+ class BaseLink {
3
+ #handler;
4
+ #queue = [];
5
+ #closeHandlers = new Set();
6
+ #closed = false;
7
+ get closed() {
8
+ return this.#closed;
9
+ }
10
+ send(frame) {
11
+ if (this.#closed)
12
+ return;
13
+ this.transmit(frame);
14
+ }
15
+ receive(handler) {
16
+ this.#handler = handler;
17
+ for (const frame of this.#queue.splice(0))
18
+ handler(frame);
19
+ }
20
+ onClose(handler) {
21
+ if (this.#closed)
22
+ handler("closed");
23
+ else
24
+ this.#closeHandlers.add(handler);
25
+ }
26
+ close(reason = "closed") {
27
+ if (this.#closed)
28
+ return;
29
+ try {
30
+ this.transmit({ t: "bye", reason });
31
+ }
32
+ catch {
33
+ // The transport may already be gone.
34
+ }
35
+ this.ended(reason);
36
+ }
37
+ /** Delivers a parsed frame from the transport. */
38
+ deliver(frame) {
39
+ if (this.#closed)
40
+ return;
41
+ if (frame.t === "bye") {
42
+ this.ended(frame.reason ?? "peer closed");
43
+ return;
44
+ }
45
+ if (this.#handler === undefined)
46
+ this.#queue.push(frame);
47
+ else
48
+ this.#handler(frame);
49
+ }
50
+ /** Marks the link closed (transport ended) and notifies once. */
51
+ ended(reason) {
52
+ if (this.#closed)
53
+ return;
54
+ this.#closed = true;
55
+ this.#queue = [];
56
+ try {
57
+ this.shutdown();
58
+ }
59
+ finally {
60
+ for (const handler of this.#closeHandlers)
61
+ handler(reason);
62
+ this.#closeHandlers.clear();
63
+ }
64
+ }
65
+ }
66
+ /** Parses a JSON frame; anything else is a protocol error. */
67
+ function parseFrame(data) {
68
+ const frame = JSON.parse(data);
69
+ if (frame === null || typeof frame !== "object" || typeof frame.t !== "string")
70
+ throw new TypeError("not a frame");
71
+ return frame;
72
+ }
73
+ // ─── memory ──────────────────────────────────────────────────────────────────
74
+ export class MemoryLink extends BaseLink {
75
+ peer;
76
+ #severed = false;
77
+ #pending = Promise.resolve();
78
+ /** Simulates a dead network: frames are dropped silently in both directions and no close is signalled. */
79
+ sever() {
80
+ this.#severed = true;
81
+ if (this.peer)
82
+ this.peer.#severed = true;
83
+ }
84
+ transmit(frame) {
85
+ if (this.#severed)
86
+ return;
87
+ // A JSON round trip detaches the frame (and rejects what JSON would mangle silently, e.g. bigint).
88
+ const data = JSON.stringify(frame);
89
+ const peer = this.peer;
90
+ // One promise chain per direction keeps delivery FIFO and asynchronous, like a real transport.
91
+ this.#pending = this.#pending.then(() => {
92
+ if (!this.#severed && peer !== undefined)
93
+ peer.deliver(parseFrame(data));
94
+ });
95
+ }
96
+ shutdown() {
97
+ const peer = this.peer;
98
+ this.#pending = this.#pending.then(() => peer?.ended("peer closed"));
99
+ }
100
+ }
101
+ /** Two connected in-memory links (tests). */
102
+ export function memoryLinkPair() {
103
+ const a = new MemoryLink();
104
+ const b = new MemoryLink();
105
+ a.peer = b;
106
+ b.peer = a;
107
+ return [a, b];
108
+ }
109
+ /** Chord frames on an IPC channel are wrapped as `{ chord2: frame }`; other messages (control) pass by. */
110
+ export class IpcLink extends BaseLink {
111
+ #channel;
112
+ #onMessage = (message) => {
113
+ const frame = message?.chord2;
114
+ if (frame !== undefined)
115
+ this.deliver(frame);
116
+ };
117
+ #onDisconnect = () => this.ended("ipc disconnected");
118
+ constructor(channel) {
119
+ super();
120
+ this.#channel = channel;
121
+ channel.on("message", this.#onMessage);
122
+ channel.on("disconnect", this.#onDisconnect);
123
+ }
124
+ transmit(frame) {
125
+ if (this.#channel.connected)
126
+ this.#channel.send({ chord2: frame });
127
+ }
128
+ shutdown() {
129
+ this.#channel.off("message", this.#onMessage);
130
+ this.#channel.off("disconnect", this.#onDisconnect);
131
+ }
132
+ }
133
+ export const ipcLink = (channel) => new IpcLink(channel);
134
+ const OPEN = 1;
135
+ export class WebSocketLink extends BaseLink {
136
+ #socket;
137
+ #outbox = [];
138
+ constructor(socket) {
139
+ super();
140
+ this.#socket = socket;
141
+ socket.addEventListener("open", () => {
142
+ for (const data of this.#outbox.splice(0))
143
+ socket.send(data);
144
+ });
145
+ socket.addEventListener("message", (event) => {
146
+ try {
147
+ this.deliver(parseFrame(typeof event.data === "string" ? event.data : String(event.data)));
148
+ }
149
+ catch {
150
+ this.close("protocol error");
151
+ }
152
+ });
153
+ socket.addEventListener("close", () => this.ended("socket closed"));
154
+ }
155
+ transmit(frame) {
156
+ const data = JSON.stringify(frame);
157
+ if (this.#socket.readyState === OPEN)
158
+ this.#socket.send(data);
159
+ else
160
+ this.#outbox.push(data);
161
+ }
162
+ shutdown() {
163
+ this.#outbox = [];
164
+ if (this.#socket.readyState <= OPEN)
165
+ this.#socket.close(1000);
166
+ }
167
+ }
168
+ export const webSocketLink = (socket) => new WebSocketLink(socket);
169
+ //# sourceMappingURL=link.js.map