@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.
- package/CHANGELOG.md +71 -0
- package/README.md +69 -14
- package/dist/cell.d.ts +30 -9
- package/dist/cell.d.ts.map +1 -1
- package/dist/cell.js +52 -12
- package/dist/cell.js.map +1 -1
- package/dist/cluster.d.ts +4 -3
- package/dist/cluster.d.ts.map +1 -1
- package/dist/cluster.js +58 -42
- package/dist/cluster.js.map +1 -1
- package/dist/connection.d.ts +171 -58
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +676 -217
- package/dist/connection.js.map +1 -1
- package/dist/context/index.d.ts +8 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +15 -0
- package/dist/context/index.js.map +1 -1
- package/dist/contract.d.ts +120 -45
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +104 -15
- package/dist/contract.js.map +1 -1
- package/dist/declare.d.ts +11 -48
- package/dist/declare.d.ts.map +1 -1
- package/dist/declare.js +1 -21
- package/dist/declare.js.map +1 -1
- package/dist/delta/index.d.ts +2 -1
- package/dist/delta/index.d.ts.map +1 -1
- package/dist/delta/index.js +4 -0
- package/dist/delta/index.js.map +1 -1
- package/dist/errors.d.ts +4 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/host.d.ts +214 -120
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +446 -241
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +47 -12
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +200 -14
- package/dist/link.js.map +1 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +7 -2
- package/dist/loader.js.map +1 -1
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +35 -9
- package/dist/manager.js.map +1 -1
- package/dist/object.d.ts +438 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/{record.js → object.js} +614 -335
- package/dist/object.js.map +1 -0
- package/dist/output.d.ts +91 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +360 -0
- package/dist/output.js.map +1 -0
- package/dist/registry.d.ts +3 -3
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/reload.d.ts +35 -27
- package/dist/reload.d.ts.map +1 -1
- package/dist/reload.js +256 -192
- package/dist/reload.js.map +1 -1
- package/dist/remote.d.ts +130 -35
- package/dist/remote.d.ts.map +1 -1
- package/dist/remote.js +493 -189
- package/dist/remote.js.map +1 -1
- package/dist/sqlite/cloudflare.d.ts +52 -0
- package/dist/sqlite/cloudflare.d.ts.map +1 -0
- package/dist/sqlite/cloudflare.js +134 -0
- package/dist/sqlite/cloudflare.js.map +1 -0
- package/dist/sqlite/database.d.ts +37 -0
- package/dist/sqlite/database.d.ts.map +1 -0
- package/dist/sqlite/database.js +2 -0
- package/dist/sqlite/database.js.map +1 -0
- package/dist/sqlite/index.d.ts +4 -0
- package/dist/sqlite/index.d.ts.map +1 -0
- package/dist/sqlite/index.js +3 -0
- package/dist/sqlite/index.js.map +1 -0
- package/dist/sqlite/migrations.d.ts +10 -0
- package/dist/sqlite/migrations.d.ts.map +1 -0
- package/dist/sqlite/migrations.js +33 -0
- package/dist/sqlite/migrations.js.map +1 -0
- package/dist/sqlite/node.d.ts +38 -0
- package/dist/sqlite/node.d.ts.map +1 -0
- package/dist/sqlite/node.js +174 -0
- package/dist/sqlite/node.js.map +1 -0
- package/dist/sqlite/schema.d.ts +3 -0
- package/dist/sqlite/schema.d.ts.map +1 -0
- package/dist/sqlite/schema.js +10 -0
- package/dist/sqlite/schema.js.map +1 -0
- package/dist/telemetry-sqlite/index.d.ts +24 -0
- package/dist/telemetry-sqlite/index.d.ts.map +1 -0
- package/dist/telemetry-sqlite/index.js +273 -0
- package/dist/telemetry-sqlite/index.js.map +1 -0
- package/dist/telemetry-sqlite/store.d.ts +9 -0
- package/dist/telemetry-sqlite/store.d.ts.map +1 -0
- package/dist/telemetry-sqlite/store.js +110 -0
- package/dist/telemetry-sqlite/store.js.map +1 -0
- package/dist/types.d.ts +39 -28
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/websocket.d.ts +4 -5
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +3 -2
- package/dist/websocket.js.map +1 -1
- package/dist/wire.d.ts +210 -129
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +108 -55
- package/dist/wire.js.map +1 -1
- package/docs/guide.md +267 -203
- package/docs/spec.md +141 -114
- package/docs/tutorial.md +257 -235
- package/package.json +27 -1
- package/dist/record.d.ts +0 -320
- package/dist/record.d.ts.map +0 -1
- package/dist/record.js.map +0 -1
package/dist/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAsB,UAAU,EAAoC,MAAM,iBAAiB,CAAC;AACnG,OAAO,EAEN,IAAI,GAOJ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACN,OAAO,EAGP,UAAU,EAIV,WAAW,EACX,UAAU,GAGV,MAAM,aAAa,CAAC;AAErB,OAAO,EAAyC,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS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I,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"]}
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAsB,UAAU,EAAmC,MAAM,iBAAiB,CAAC;AAClG,OAAO,EAEN,IAAI,EACJ,uBAAuB,EAIvB,QAAQ,EACR,aAAa,EAIb,WAAW,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EACN,UAAU,EACV,OAAO,EAIP,YAAY,EACZ,WAAW,EACX,UAAU,EAEV,OAAO,GAKP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAyC,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAwDrF,gGAAgG;AAChG,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,KAAiC,EACjC,OAAO,GAA+C,EAAE,EACnC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAQzD,MAAM,OAAO,GAAG,CAAC,GAAc,EAAgB,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,YAAY,GAAG,CAAC,CA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OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,SAAS,CAAE,SAAqC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AAEhH,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,IAAY,EAAc,EAAE,CAC9D,IAAI,UAAU,CAAC,aAAa,EAAE,GAAG,IAAI,qBAAqB,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;AAE/F,8GAA8G;AAC9G,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,wFAAwF;QACxF,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YACvC,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;gBAAE,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS;oBAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7F,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { ChildReloads, reconcileChild, runClusterReload } from \"./cluster.ts\";\nimport { type AcceptOptions, Connection, type LinkOptions, type RelayRef } from \"./connection.ts\";\nimport {\n\ttype AnyContract,\n\tbind,\n\tcontractFromDescription,\n\ttype InputOf,\n\ttype LocalContract,\n\ttype LocalDef,\n\tplacedOn,\n\tplacementText,\n\ttype Ref,\n\ttype RemoteContract,\n\ttype RemoteDef,\n\tresolveHost,\n} from \"./contract.ts\";\nimport { ChordError, invalid, runAll } from \"./errors.ts\";\nimport type { Link } from \"./link.ts\";\nimport {\n\tawaitReady,\n\tCtxImpl,\n\ttype Decls,\n\ttype Factory,\n\ttype HostCore,\n\thostLifetime,\n\tmakeService,\n\tObjectImpl,\n\ttype RefCore,\n\tRefImpl,\n\ttype RefOwner,\n\ttype ServeOptions,\n\ttype ServeOptionsFor,\n\ttype Service,\n} from \"./object.ts\";\nimport { enqueue } from \"./publish.ts\";\nimport type { Registry, RegistryTable, RegistryView } from \"./registry.ts\";\nimport { type ReloadOptions, type ReloadReport, runReload } from \"./reload.ts\";\nimport { RemoteBinding, RemoteRef } from \"./remote.ts\";\nimport { canonicalIdentity, canonicalJson, deepEqual, normalize } from \"./schema.ts\";\nimport type { Ctx, GetOptions } from \"./types.ts\";\nimport type { Frame } from \"./wire.ts\";\n\n/**\n * Registers a factory for a type. Overloaded on the contract's definition (not the contract type) so TypeScript\n * keeps literal `variant`s in factory returns. `P` is the app's principal type (see `createHost`).\n */\nexport interface Serve<P = unknown> {\n\t<D extends RemoteDef>(\n\t\ttype: RemoteContract<D>,\n\t\tfactory: Factory<RemoteContract<D>, P>,\n\t\toptions?: ServeOptionsFor<RemoteContract<D>>,\n\t): void;\n\t<D extends LocalDef>(\n\t\ttype: LocalContract<D>,\n\t\tfactory: Factory<LocalContract<D>, P>,\n\t\toptions?: ServeOptionsFor<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<P = unknown> {\n\treadonly serve: Serve<P>;\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 code version at call time). */\n\troot<T>(fn: (ctx: Ctx<P>) => T | Promise<T>, options?: RootOptions<P>): Promise<T>;\n\t/** The facet's host's registry view (`get(key, ctx)` reads the table of `ctx.codeVersion`). */\n\tregistry<V>(registry: Registry<V>): RegistryView<V>;\n\t/**\n\t * Aborted when this run of the facet is no longer installed: a reload that replaced or removed it committed, the reload\n\t * that loaded it aborted, or the host closed. While a reload prepares, the installed and the candidate run are both\n\t * live.\n\t */\n\treadonly signal: AbortSignal;\n}\n\n/** What a facet module exports (default export): the code that serves its types on one host kind. */\nexport interface FacetDefinition<P = unknown> {\n\t/** Contract tokens this facet consumes; checked against providers at reload. */\n\treadonly uses?: readonly AnyContract[];\n\tsetup(api: FacetApi<P>): void;\n}\n\n/** A named facet. Modules are named by their URL; reloading a facet replaces everything it served. */\nexport interface Facet<P = unknown> extends FacetDefinition<P> {\n\treadonly name: string;\n}\n\n/** `defineFacet<P>(…)`: an app passes its principal type, so factories and contexts see `P`. */\nexport const defineFacet = <P = unknown>(\n\tsetup: (api: FacetApi<P>) => void,\n\toptions: { readonly uses?: readonly AnyContract[] } = {},\n): FacetDefinition<P> => ({ 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<P = unknown> = Facet<P> | string | URL;\n\nconst isFacet = (ref: PluginRef): ref is Facet => typeof ref === \"object\" && !(ref instanceof URL);\n\n/**\n * `P` is the app's principal type: who a caller is, JSON-serializable. Chord never makes one up: the app supplies the\n * host's own (`self`), the one its parent's own requests act as (`connect`), the ones links act as (`accept`) and the\n * ones routed hosts act as (`Route.principal`).\n */\nexport interface HostOptions<P = unknown> {\n\treadonly name?: string;\n\t/**\n\t * The principal of the host's own code: roots it starts, code inside its objects, and its `lifetime: \"host\"` objects.\n\t * Compared by `principalKey`, so an equal principal from elsewhere reaches the same objects. Not used to infer `P`:\n\t * pass the app's type as `createHost<P>(…)`.\n\t */\n\treadonly self: NoInfer<P>;\n\t/** Maps a principal to its object key (should include connection provenance and grant revision). */\n\treadonly principalKey?: (principal: P) => 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/**\n\t * Milliseconds a reload waits for an object's aborted tasks to finish before it starts their replacements anyway\n\t * (reported). Default 5000.\n\t */\n\treadonly taskStopDeadline?: number;\n\t/**\n\t * Milliseconds an activation (or a reload's prepare) waits for its references to be ready and hydrated, and an\n\t * awaited `get` for its reference, before failing with `unavailable/ready_timeout`. Default 60000.\n\t */\n\treadonly readyTimeout?: number;\n\t/**\n\t * Consumer-side linger of remote references: when the last reference to a remote object is released, its binding\n\t * stays held, and hydrated, for `types[typeName]` milliseconds, so a reference taken again meanwhile costs nothing\n\t * on the link. At most `cap` bindings (default 4) linger; beyond, the least recently released go first. Types not\n\t * listed do not linger. (The provider's own `serve(…, { linger })` keeps its object after the last reference.)\n\t */\n\treadonly linger?: { readonly types?: Readonly<Record<string, number>>; readonly cap?: number };\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 code versions. 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?: { readonly link: Link } & ConnectOptions<P>;\n}\n\n/** `connect` options: the link's, and the principal its parent's own requests act as. */\nexport interface ConnectOptions<P = unknown> extends LinkOptions {\n\t/** What a request from the parent acts as when the parent does not forward its caller's principal (its own code). */\n\treadonly principal: P;\n}\n\n/** Where requests for hosts named `prefix…` go (on the server). */\nexport interface Route<P = unknown> {\n\t/** Checked before resolving (or spawning) and again after: grants may change meanwhile. */\n\tauthorize(principal: P, hostName: string): boolean | Promise<boolean>;\n\t/** A link to the host, spawned if needed. */\n\tresolve(hostName: string): Promise<Link>;\n\t/** The principal the resolved host acts as when it calls back. */\n\treadonly principal: (hostName: string) => P;\n}\n\n/** Fields a principal must have, equal (`deepEqual`), for an `invalidatePrincipal` pattern. */\nexport type PrincipalPattern<P> = P extends object\n\t? { readonly [K in keyof P]?: P[K] }\n\t: Readonly<Record<string, unknown>>;\n\n/** `invalidatePrincipal` matches: a predicate (this host only), or a pattern (fields that must be equal; propagates). */\nexport type PrincipalMatch<P = unknown> = ((principal: P) => boolean) | PrincipalPattern<P>;\n\nexport interface RootOptions<P = unknown> {\n\treadonly principal?: P;\n\treadonly signal?: AbortSignal;\n\t/** Start the root in a retained code version (links carry code versions). Defaults to the current code version. */\n\treadonly codeVersion?: number;\n}\n\nexport interface LoadOptions {\n\t/**\n\t * Await the activation of the `lifetime: \"host\"` objects the facets serve (default true). False starts them but\n\t * leaves readiness to `host.ready()` (a child host whose objects need its parent, which admits it only later).\n\t */\n\treadonly awaitHostObjects?: boolean;\n}\n\nexport interface Host<P = unknown> {\n\treadonly name: string;\n\treadonly codeVersion: number;\n\treadonly previousCodeVersion: number | undefined;\n\treadonly serve: Serve<P>;\n\t/** Installs synchronously, then awaits this facet's host objects unless `awaitHostObjects` is false. */\n\tinstall(facet: Facet<P>, options?: LoadOptions): Promise<void>;\n\t/** Installs all facets before awaiting their host objects; referenced objects are created when first referenced. */\n\tload(plugins: readonly PluginRef<P>[], options?: LoadOptions): Promise<void>;\n\t/** Awaits the host objects present at call time, including those started by `serve` or deferred loads. */\n\tready(): Promise<void>;\n\t/**\n\t * A reference held until `release()`. Resolves once it is ready: live, with every state member of its variant\n\t * (unless `state: false`). Rejects with the activation error, `aborted` (`signal`), or `unavailable/ready_timeout`\n\t * after `readyTimeout`; the reference is released then.\n\t */\n\tget<C extends AnyContract>(\n\t\ttype: C,\n\t\tinput: InputOf<C>,\n\t\toptions?: GetOptions<P> & { readonly signal?: AbortSignal },\n\t): Promise<Ref<C>>;\n\t/**\n\t * The same reference, synchronously, possibly still `loading`: for UI runtimes that render its status (hooks, a\n\t * TUI watch). Its state members throw `not_ready` until it is live.\n\t */\n\thold<C extends AnyContract>(type: C, input: InputOf<C>, options?: GetOptions<P>): Ref<C>;\n\troot<T>(fn: (ctx: Ctx<P>) => T | Promise<T>, options?: RootOptions<P>): Promise<T>;\n\tregistry<V>(registry: Registry<V>): RegistryView<V>;\n\t/**\n\t * Force-disposes every object whose principal matches (never the host's own principal), re-stamps or closes\n\t * matching links, and propagates pattern matches to child hosts.\n\t */\n\tinvalidatePrincipal(match: PrincipalMatch<P>): 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<P>): void;\n\t/**\n\t * Sets (or replaces, after a reconnect) the link to this host's parent; remote references re-hold over it. The\n\t * parent's own requests act as `options.principal`; requests it relays act as the principal it forwards.\n\t */\n\tconnect(link: Link, options: ConnectOptions<P>): void;\n\troute(prefix: string, route: Route<P>): void;\n\t/** Reloads the given facets (modules are re-imported); facets not listed keep running unchanged. */\n\treload(plugins: readonly PluginRef<P>[], options?: ReloadOptions): Promise<ReloadReport>;\n\tclose(): Promise<void>;\n}\n\nexport interface CodeVersionState {\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\t/** Aborts every root of this code version (forced retirement). */\n\treadonly abort: AbortController;\n}\n\nconst EMPTY_TABLE: RegistryTable<never> = new Map<string, never>();\n\n/** A host whose principals are `P` (the app's type; `unknown` if not given). */\nexport function createHost<P = unknown>(options: HostOptions<P>): Host<P> {\n\treturn new HostImpl(options as HostOptions) as unknown as Host<P>;\n}\n\nexport class HostImpl implements Host, HostCore {\n\treadonly name: string;\n\treadonly dev: boolean;\n\treadonly principal: unknown;\n\tinFactory = 0;\n\tfailed: unknown;\n\treadonly objects = new Map<string, ObjectImpl>();\n\treadonly codeVersions = new Map<number, CodeVersionState>();\n\treadonly facets = new Map<string, Facet>();\n\t/** The host's own references to its `lifetime: \"host\"` objects, by type name. */\n\treadonly hostObjects = new Map<string, RefCore>();\n\treadonly kind: \"host\" | \"client\";\n\treadonly connections = new Set<Connection>();\n\tupstream: Connection | undefined;\n\t/** Shared bindings of this host's remote references, by key (re-held after an upstream reconnect). */\n\treadonly bindings = new Map<string, RemoteBinding>();\n\t/** Bindings without references that linger, least recently released first. */\n\treadonly #lingering = new Map<string, RemoteBinding>();\n\treadonly #lingerTypes: Readonly<Record<string, number>>;\n\treadonly #lingerCap: number;\n\t#originSeq = 0;\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 code version 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: CodeVersionState;\n\tprevious: CodeVersionState | undefined;\n\t/** The code version a running reload will commit; new types activated during prepare install their implementation for it. */\n\tpending: CodeVersionState | undefined;\n\t/** Activations of these types wait (reload gate). */\n\t/** Types behind a reload gate: new objects of these types are rejected `upgrade_conflict` until commit/abort. */\n\tgating: ReadonlySet<string> | undefined;\n\treloading = false;\n\treadonly taskStopDeadline: number;\n\treadonly readyTimeout: number;\n\treadonly #principalKey: (principal: unknown) => string;\n\t/** `principalKey(self)`: an equal principal is the host's own, whatever object carries it. */\n\treadonly #selfKey: string;\n\t/** Called when a root ends, the parent allows a retirement, or the previous code version retires. */\n\treadonly #retirementWatchers = new Set<() => void>();\n\t/** Child hosts whose hello arrived while a reload ran: synced or reconciled once it ends. */\n\treadonly #deferredHellos = new Map<Connection, number>();\n\t/** Resolved when the running reload ends. */\n\treadonly #reloadWaiters: (() => void)[] = [];\n\t/** Aborted when the installed run of a facet (by name) is replaced, removed, or the host closes. */\n\treadonly #facetRuns = new Map<string, AbortController>();\n\treadonly #onError: (error: unknown) => void;\n\treadonly #loader: FacetLoader | undefined;\n\treadonly #dying = new Map<string, ObjectImpl>();\n\treadonly #touches = new Map<string, Set<ObjectImpl>>();\n\treadonly #order = new Map<string, Map<string, number>>();\n\treadonly #subscribers = new Map<string, Set<(table: RegistryTable<unknown>, codeVersion: number) => void>>();\n\t#codeVersionSeq = 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\tif (!(\"self\" in options)) throw new TypeError(\"createHost needs `self`: the principal of the host's own code\");\n\t\tthis.principal = options.self;\n\t\tthis.#principalKey = options.principalKey ?? canonicalJson;\n\t\tthis.#selfKey = this.#principalKey(options.self);\n\t\tthis.#onError = options.onError ?? ((error) => console.error(\"chord:\", error));\n\t\tthis.#loader = options.loader;\n\t\tthis.taskStopDeadline = options.taskStopDeadline ?? 5000;\n\t\tthis.readyTimeout = options.readyTimeout ?? 60_000;\n\t\tthis.#lingerTypes = options.linger?.types ?? {};\n\t\tthis.#lingerCap = options.linger?.cap ?? 4;\n\t\tthis.current = {\n\t\t\tid: this.#codeVersionSeq,\n\t\t\tservices: new Map(),\n\t\t\ttables: new Map(),\n\t\t\troots: new Map(),\n\t\t\tabort: new AbortController(),\n\t\t};\n\t\tthis.codeVersions.set(this.current.id, this.current);\n\t\tthis.kind = options.kind ?? \"host\";\n\t\tif (options.upstream !== undefined) this.connect(options.upstream.link, options.upstream);\n\t}\n\n\t/** Whether `principal` is the host's own: the same key as `self`. */\n\tisSelf(principal: unknown): boolean {\n\t\treturn principal === this.principal || this.#principalKey(principal) === this.#selfKey;\n\t}\n\n\tget codeVersion(): number {\n\t\treturn this.current.id;\n\t}\n\n\tget previousCodeVersion(): number | undefined {\n\t\treturn this.previous?.id;\n\t}\n\n\t/** Allocates the next code version id, or adopts one issued by the coordinating server. */\n\tnextCodeVersionId(given?: number): number {\n\t\tif (given !== undefined && given <= this.current.id)\n\t\t\tthrow new Error(`code version ${given} is not newer than ${this.current.id}`);\n\t\tthis.#codeVersionSeq = given ?? this.#codeVersionSeq + 1;\n\t\treturn this.#codeVersionSeq;\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.lifetime === \"host\") this.startHostObject(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\tconst run = new AbortController();\n\t\ttry {\n\t\t\tfacet.setup(\n\t\t\t\tthis.facetApi(\n\t\t\t\t\t((type, factory, options = {}) => {\n\t\t\t\t\t\tconst service = makeService(type, factory, options, facet.name);\n\t\t\t\t\t\tthis.serveInto(this.current.services, service);\n\t\t\t\t\t\tadded.push(service);\n\t\t\t\t\t}) satisfies AnyServe as Serve,\n\t\t\t\t\trun.signal,\n\t\t\t\t),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\trun.abort(error);\n\t\t\tthrow error;\n\t\t}\n\t\tthis.facets.set(facet.name, facet);\n\t\tthis.facetRunChanged(facet.name, run);\n\t\tconst refs = added.filter(hostLifetime).map((service) => this.startHostObject(service));\n\t\treturn options.awaitHostObjects === false ? Promise.resolve() : this.#hostObjectsReady(refs);\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: a host object's 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.#hostObjectsReady(this.hostObjects.values());\n\t}\n\n\t#hostObjectsReady(refs: Iterable<RefCore>): Promise<void> {\n\t\tconst ready = Promise.all([...refs].map((ref) => ref.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, signal: AbortSignal): 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\tsignal,\n\t\t};\n\t}\n\n\t/** The installed run of facet `name` is now `run` (or none): the run it replaces is aborted. */\n\tfacetRunChanged(name: string, run: AbortController | undefined): void {\n\t\tconst replaced = this.#facetRuns.get(name);\n\t\tif (run === undefined) this.#facetRuns.delete(name);\n\t\telse this.#facetRuns.set(name, run);\n\t\tif (replaced !== run) replaced?.abort(new ChordError(\"gone\", `facet ${name} was replaced or removed`));\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\tconst placement = service.contract.description.host;\n\t\tif (placement !== undefined && !placedOn(placement, this.name)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`${service.contract.name} is declared for ${placementText(placement)}, but ${this.name} serves it`,\n\t\t\t);\n\t\t}\n\t\tservices.set(service.contract.name, service);\n\t}\n\n\tstartHostObject(service: Service): RefCore {\n\t\tconst ref = this.acquire(service.contract, {}, undefined, \"host\");\n\t\tthis.hostObjects.set(service.contract.name, ref);\n\t\tref.ready.catch((error: unknown) => this.report(error));\n\t\treturn ref;\n\t}\n\n\t// ─── HostCore ───\n\n\tcurrentCodeVersion(): number {\n\t\treturn this.current.id;\n\t}\n\n\thasCodeVersion(codeVersion: number): boolean {\n\t\treturn this.codeVersions.has(codeVersion);\n\t}\n\n\t*retainedCodeVersions(): Iterable<readonly [number, ReadonlyMap<string, Service>]> {\n\t\tfor (const [id, state] of this.codeVersions) yield [id, state.services];\n\t\tif (this.pending !== undefined) yield [this.pending.id, this.pending.services];\n\t}\n\n\tpendingCodeVersion(): 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 code version. */\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: unknown, candidate = false): string {\n\t\tconst elsewhere = this.#elsewhere(type, input);\n\t\tif (elsewhere !== undefined) return this.#remoteKey(type, elsewhere.input, principal);\n\t\tconst service = this.#bindingService(type.name, candidate);\n\t\tif (service === undefined) throw unknownType(type.name, this.name);\n\t\treturn this.#locate(service, input, principal).address;\n\t}\n\n\t/**\n\t * Where an object of a remote type lives when that is another host: its name and the input normalized with the\n\t * caller's contract (the placement is read from it). `undefined`: here (and every local type).\n\t */\n\t#elsewhere(type: AnyContract, input: unknown): { readonly at: string; readonly input: unknown } | undefined {\n\t\tconst placement = type.description.host;\n\t\tif (type.scope !== \"remote\" || placement === undefined) return undefined;\n\t\tconst normalized = normalize(type.input, input, `${type.name} input`);\n\t\tconst at = resolveHost(type.name, placement, normalized);\n\t\treturn at === this.name ? undefined : { at, input: normalized };\n\t}\n\n\t/**\n\t * The address of `input` for `principal`, normalized. A `lifetime: \"host\"` type has one object: the empty input, for\n\t * the host principal, whoever asks; another input is invalid.\n\t */\n\t#locate(service: Service, input: unknown, principal: unknown) {\n\t\tconst { name, input: schema } = service.contract;\n\t\tconst normalized = normalize(schema, input, `${name} input`);\n\t\tconst identity = canonicalIdentity(schema, normalized);\n\t\tif (hostLifetime(service)) {\n\t\t\tif (identity !== canonicalIdentity(schema, normalize(schema, {}, `${name} input`)))\n\t\t\t\tthrow invalid(\"input\", `${name} has lifetime \"host\": its one object has the empty input`);\n\t\t\tprincipal = this.principal;\n\t\t}\n\t\treturn { address: `${name}\\u0000${identity}\\u0000${this.#principalPart(principal)}`, normalized, principal };\n\t}\n\n\t#principalPart(principal: unknown): string {\n\t\treturn this.isSelf(principal) ? \"host\" : `p:${this.#principalKey(principal)}`;\n\t}\n\n\t/**\n\t * The key of a remote binding: type, input identity (fields equal to their defaults omitted, as for local objects),\n\t * principal key and the consumer's contract fingerprint. No host name: the type and the input decide where it lives.\n\t */\n\t#remoteKey(type: AnyContract, normalized: unknown, principal: unknown): string {\n\t\tconst identity = canonicalIdentity(type.input, normalized);\n\t\treturn `@${type.name}\\u0000${identity}\\u0000${this.#principalPart(principal)}\\u0000${type.fingerprint}`;\n\t}\n\n\tacquire(\n\t\ttype: AnyContract,\n\t\tinput: unknown,\n\t\toptions: GetOptions | undefined,\n\t\towner: RefOwner,\n\t\tfrom?: ObjectImpl,\n\t\tcandidate = false,\n\t): RefCore {\n\t\tconst elsewhere = this.#elsewhere(type, input);\n\t\tif (elsewhere !== undefined) return this.#acquireRemote(type, elsewhere.at, elsewhere.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 { address, normalized, principal } = this.#locate(service, input, options?.principal ?? this.principal);\n\t\t// The provider's own placement decides, never where a request says it is going (a client picks that).\n\t\tconst placement = service.contract.description.host;\n\t\tif (placement !== undefined && resolveHost(type.name, placement, normalized) !== this.name) {\n\t\t\tthrow invalid(\n\t\t\t\t\"placement\",\n\t\t\t\t`${type.name} with this input lives on ${resolveHost(type.name, placement, normalized)}, not ${this.name}`,\n\t\t\t);\n\t\t}\n\t\tlet object = this.objects.get(address);\n\t\tif (from !== undefined && object !== undefined && (object === from || reaches(object, from))) {\n\t\t\tthrow invalid(\"cycle\", `${from.address} -> ${address} would create a ref cycle`);\n\t\t}\n\t\tif (object === 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\tobject = new ObjectImpl(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\thostLifetime: hostLifetime(service),\n\t\t\t});\n\t\t\tthis.objects.set(address, object);\n\t\t\t// A new object for an address still being disposed waits for that cleanup (exclusive resources).\n\t\t\tobject.start(dying?.status === \"disposing\" ? dying.dispose(false) : undefined);\n\t\t}\n\t\tconst ref = new RefImpl(object, type, owner);\n\t\tobject.addRef(ref);\n\t\treturn ref;\n\t}\n\n\tforget(object: ObjectImpl): void {\n\t\tif (this.objects.get(object.address) === object) this.objects.delete(object.address);\n\t\tif (object.status === \"disposing\") this.#dying.set(object.address, object);\n\t}\n\n\tdisposed(object: ObjectImpl): void {\n\t\tif (this.#dying.get(object.address) === object) this.#dying.delete(object.address);\n\t}\n\n\ttouch(rootId: string, object: ObjectImpl): 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(object);\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.codeVersion ?? this.current.id, fn, options);\n\t}\n\n\t/**\n\t * Runs `fn` inside root `rootId` of `codeVersion`. A root counts as running here (for retirement) while any of its\n\t * calls 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 objects\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\tcodeVersionId: number,\n\t\tfn: (ctx: Ctx) => T | Promise<T>,\n\t\toptions: { readonly principal?: unknown; readonly signal?: AbortSignal; readonly from?: Connection } = {},\n\t): Promise<T> {\n\t\tconst codeVersion = this.codeVersions.get(codeVersionId);\n\t\tif (codeVersion === undefined) {\n\t\t\tthis.#local.delete(rootId);\n\t\t\tthrow new ChordError(\"superseded\", `code version ${codeVersionId} 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\tcodeVersion.roots.set(rootId, (codeVersion.roots.get(rootId) ?? 0) + 1);\n\t\tconst ctx = new CtxImpl(this, {\n\t\t\t// Forced retirement aborts what still runs on a code version before closing what only it used.\n\t\t\tsignals:\n\t\t\t\toptions.signal === undefined ? [codeVersion.abort.signal] : [options.signal, codeVersion.abort.signal],\n\t\t\trootId,\n\t\t\tcodeVersion: codeVersion.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 = (codeVersion.roots.get(rootId) ?? 1) - 1;\n\t\t\tif (count > 0) codeVersion.roots.set(rootId, count);\n\t\t\telse {\n\t\t\t\tcodeVersion.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\tthis.#retirementChanged();\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 object of this.#touches.get(rootId) ?? []) object.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.codeVersions.values()].some((codeVersion) => codeVersion.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 code version once no local roots of it remain. A child also waits for its parent to retire\n\t * it: roots span hosts, and an old root on the server may still call in.\n\t */\n\tmaybeRetire(): void {\n\t\tif (this.retirable()) this.retire();\n\t}\n\n\t/** The previous code version has no roots left here and, on a child host, the parent has retired it. */\n\tretirable(): boolean {\n\t\tconst previous = this.previous;\n\t\tif (previous === undefined || previous.roots.size > 0) return false;\n\t\treturn this.kind === \"client\" || this.upstream === undefined || previous.id <= this.#retireAllowed;\n\t}\n\n\tallowRetire(codeVersion: number): void {\n\t\tthis.#retireAllowed = Math.max(this.#retireAllowed, codeVersion);\n\t\tthis.maybeRetire();\n\t\tthis.#retirementChanged();\n\t}\n\n\t/** Calls `watcher` whenever a root ends, the parent allows a retirement, or a code version retires. */\n\twatchRetirement(watcher: () => void): () => void {\n\t\tthis.#retirementWatchers.add(watcher);\n\t\treturn () => this.#retirementWatchers.delete(watcher);\n\t}\n\n\t#retirementChanged(): void {\n\t\tfor (const watcher of [...this.#retirementWatchers]) watcher();\n\t}\n\n\t/**\n\t * Tells a child that is now in step which code versions this host retired before: every id below the oldest one it\n\t * retains (ids only grow). Without it, a child reconciled after those retirements would never hear a `retire` frame for\n\t * its own previous code version and would wait for the retire deadline at every reload.\n\t */\n\tannounceRetired(connection: Connection): void {\n\t\tconst retired = (this.previous ?? this.current).id - 1;\n\t\tif (retired > 0) connection.send({ t: \"retire\", codeVersion: retired });\n\t}\n\n\t/** Drops the previous code version: its implementations 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.codeVersions.delete(previous.id);\n\t\tfor (const object of [...this.objects.values()]) this.retireImplementation(object, 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\", codeVersion: previous.id });\n\t\t}\n\t\tthis.#retirementChanged();\n\t}\n\n\t/**\n\t * Drops an object's implementation for `codeVersion` and what only that implementation declared, in disposal order:\n\t * resources close (reverse open order) before its references are released.\n\t */\n\tretireImplementation(object: ObjectImpl, codeVersion: number): void {\n\t\tconst installed = object.implementations.get(codeVersion);\n\t\tobject.implementations.delete(codeVersion);\n\t\tif (installed === undefined || installed.decls === object.decls) return;\n\t\tconst kept = object.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 refs = keep((decls) => decls.refs.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) => object.openOrder.indexOf(b) - object.openOrder.indexOf(a));\n\t\tconst releasing = [...installed.decls.refs.values()].filter((ref) => !refs.has(ref));\n\t\tobject.refreshSchemas();\n\t\trunAll(\n\t\t\t[\n\t\t\t\t...closing.map((resource) => () => resource.close(object.openOrder)),\n\t\t\t\t...releasing.map((ref) => () => ref.release()),\n\t\t\t],\n\t\t\t`${object.address}: retiring code version ${codeVersion} 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 codeVersion = ctx === undefined ? this.current : this.codeVersions.get(ctx.codeVersion);\n\t\t\tif (codeVersion === undefined)\n\t\t\t\tthrow new ChordError(\"superseded\", `code version ${ctx?.codeVersion} is retired`);\n\t\t\treturn (codeVersion.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>, codeVersion: 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 (object, declarations) pairs. Throws registry_conflict. */\n\tbuildTables(entries: Iterable<readonly [ObjectImpl, Decls]>): Map<string, RegistryTable<unknown>> {\n\t\tconst byRegistry = new Map<string, Map<string, { value: unknown; object: ObjectImpl }>>();\n\t\tfor (const [object, 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.object !== object && 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.object.address} and ${object.address}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tentries.set(key, { value, object });\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 reference 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 objects with their current declarations; objects waiting for a reload's commit only with `candidates`. */\n\tliveDecls(candidates = false): [ObjectImpl, Decls][] {\n\t\treturn [...this.objects.values()]\n\t\t\t.filter((object) => object.status === \"live\" && (candidates || !object.deferredRuntime))\n\t\t\t.map((object) => [object, object.decls]);\n\t}\n\n\tcheckRegistrations(object: ObjectImpl, decls: Decls): void {\n\t\tif (decls.registrations.size === 0) return;\n\t\tthis.buildTables([...this.liveDecls().filter(([other]) => other !== object), [object, decls]]);\n\t}\n\n\tregistriesChanged(including?: ObjectImpl): void {\n\t\tconst entries = this.liveDecls().filter(([object]) => object !== 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 `codeVersion`; subscribers hear about changed tables of the current code version (all tables when `all`). */\n\tinstallTables(codeVersion: CodeVersionState, tables: Map<string, RegistryTable<unknown>>, all = false): void {\n\t\tconst before = codeVersion.tables;\n\t\tcodeVersion.tables = tables;\n\t\tif (codeVersion !== 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, codeVersion.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\tasync get<C extends AnyContract>(\n\t\ttype: C,\n\t\tinput: InputOf<C>,\n\t\toptions?: GetOptions & { readonly signal?: AbortSignal },\n\t): Promise<Ref<C>> {\n\t\tconst ref = this.acquire(type, input, options, \"external\");\n\t\tawait awaitReady(ref, options?.signal === undefined ? [] : [options.signal], this.readyTimeout);\n\t\treturn ref.proxy as Ref<C>;\n\t}\n\n\thold<C extends AnyContract>(type: C, input: InputOf<C>, options?: GetOptions): Ref<C> {\n\t\treturn this.acquire(type, input, options, \"external\").proxy as Ref<C>;\n\t}\n\n\tasync invalidatePrincipal(match: PrincipalMatch): Promise<void> {\n\t\tconst matches = typeof match === \"function\" ? match : (principal: unknown) => 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 objects (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.objects.values()].filter(\n\t\t\t(object) => !this.isSelf(object.principal) && matches(object.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\t// Holds over a client link carry its id as their origin (also when relayed), so hosts can tell clients apart.\n\t\t\t...(kind === \"client\" ? { originId: `${this.#incarnation}:${++this.#originSeq}` } : {}),\n\t\t});\n\t}\n\n\tconnect(link: Link, options: ConnectOptions): void {\n\t\tif (!(\"principal\" in options))\n\t\t\tthrow new TypeError(\"connect needs `principal`: what the parent's own requests act as\");\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: options.principal,\n\t\t\tpeer: { kind: \"host\", name: undefined },\n\t\t});\n\t\tthis.upstream = connection;\n\t\t// Bindings that lost their link re-hold over the new one (`again`: they keep their values meanwhile).\n\t\tfor (const binding of this.bindings.values())\n\t\t\tif (binding.hold === undefined && !binding.ended) connection.hold(binding, binding.applied);\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\t// A link that was already closed closed the connection in its constructor: keeping it would route to it forever.\n\t\tif (connection.open) this.connections.add(connection);\n\t\treturn connection;\n\t}\n\n\troute(prefix: string, route: Route): void {\n\t\tif (typeof route.principal !== \"function\")\n\t\t\tthrow new TypeError(`route ${prefix} needs \\`principal\\`: what the routed hosts act as when they call back`);\n\t\tthis.#routes.set(prefix, route);\n\t}\n\n\t/**\n\t * A child host announced its code version. In step: usable. Behind: fenced (nothing is routed to it) and reconciled\n\t * by a reload of its modules to this host's code version, never by renumbering what it runs. Ahead: impossible,\n\t * refused.\n\t */\n\tpeerHello(connection: Connection, codeVersion: number): void {\n\t\tif (codeVersion > this.current.id) {\n\t\t\tthis.report(\n\t\t\t\tnew ChordError(\n\t\t\t\t\t\"invalid\",\n\t\t\t\t\t`${connection.name} runs code version ${codeVersion}, ahead of ${this.current.id}`,\n\t\t\t\t),\n\t\t\t);\n\t\t\tconnection.link.close(\"code version ahead of parent\");\n\t\t\treturn;\n\t\t}\n\t\tif (this.reloading) {\n\t\t\t// Not a participant of the running reload (participants are fixed when it starts): in step now, it would miss\n\t\t\t// the commit. Decided when the reload ends. A child already behind is fenced now, so the calls its roots make\n\t\t\t// meanwhile are admitted in this host's code version (never relabeled) instead of being `superseded`.\n\t\t\tconnection.peerCodeVersion = codeVersion;\n\t\t\tif (codeVersion < this.current.id) connection.fencedCodeVersions.add(codeVersion);\n\t\t\tthis.#deferredHellos.set(connection, codeVersion);\n\t\t\treturn;\n\t\t}\n\t\tif (codeVersion === this.current.id) {\n\t\t\tconnection.markSynced(codeVersion);\n\t\t\tthis.announceRetired(connection);\n\t\t\treturn;\n\t\t}\n\t\tconnection.peerCodeVersion = codeVersion;\n\t\tconnection.fencedCodeVersions.add(codeVersion);\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\t/** The host's reload slot was freed: children that said hello meanwhile are synced or reconciled now. */\n\treloadEnded(): void {\n\t\tthis.reloading = false;\n\t\tconst deferred = [...this.#deferredHellos];\n\t\tthis.#deferredHellos.clear();\n\t\tfor (const [connection, codeVersion] of deferred) if (connection.open) this.peerHello(connection, codeVersion);\n\t\tfor (const resolve of this.#reloadWaiters.splice(0)) resolve();\n\t\tthis.maybeRetire();\n\t}\n\n\t/** Resolves once no reload runs on this host. */\n\twhenReloadEnded(): Promise<void> {\n\t\tif (!this.reloading) return Promise.resolve();\n\t\treturn new Promise((resolve) => this.#reloadWaiters.push(resolve));\n\t}\n\n\tconnectionClosed(connection: Connection): void {\n\t\tthis.connections.delete(connection);\n\t\tthis.#deferredHellos.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\t/** The last reference to `binding` was released: it lingers if its type does (`HostOptions.linger`), else closes. */\n\tbindingIdle(binding: RemoteBinding): void {\n\t\tconst ms = Object.hasOwn(this.#lingerTypes, binding.contract.name)\n\t\t\t? this.#lingerTypes[binding.contract.name]!\n\t\t\t: 0;\n\t\t// A binding that never had a shape has nothing worth keeping.\n\t\tif (ms <= 0 || binding.ended || !binding.applied || this.#lingerCap <= 0) {\n\t\t\tbinding.close();\n\t\t\treturn;\n\t\t}\n\t\tbinding.lingerTimer = setTimeout(() => binding.close(), ms);\n\t\t(binding.lingerTimer as { unref?: () => void }).unref?.();\n\t\tthis.#lingering.set(binding.key, binding);\n\t\tfor (const oldest of this.#lingering.values()) {\n\t\t\tif (this.#lingering.size <= this.#lingerCap) break;\n\t\t\toldest.close();\n\t\t}\n\t}\n\n\tforgetBinding(binding: RemoteBinding): void {\n\t\tif (this.bindings.get(binding.key) === binding) this.bindings.delete(binding.key);\n\t\tif (this.#lingering.get(binding.key) === binding) this.#lingering.delete(binding.key);\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.open &&\n\t\t\t\tconnection.role === \"downstream\" &&\n\t\t\t\tconnection.peer.kind === \"host\" &&\n\t\t\t\tconnection.peer.name === name,\n\t\t);\n\t}\n\n\t/**\n\t * A reference to an object on host `at`: a view onto the binding for its key, created (and held) if there is none.\n\t * `input` is normalized with `type` (the hold carries it so).\n\t */\n\t#acquireRemote(\n\t\ttype: AnyContract,\n\t\tat: string,\n\t\tinput: unknown,\n\t\toptions: GetOptions | undefined,\n\t\towner: RefOwner,\n\t): RefCore {\n\t\tconst principal =\n\t\t\toptions?.principal === undefined || this.isSelf(options.principal) ? undefined : options.principal;\n\t\tconst key = this.#remoteKey(type, input, principal ?? this.principal);\n\t\tlet binding = this.bindings.get(key);\n\t\tconst fresh = binding === undefined || binding.ended;\n\t\tif (binding === undefined || binding.ended) {\n\t\t\tbinding = new RemoteBinding(this, { key, contract: type, at, input, principal });\n\t\t\tthis.bindings.set(key, binding);\n\t\t}\n\t\tconst ref = new RemoteRef(binding, owner, options?.state !== false);\n\t\tthis.#lingering.delete(key);\n\t\tbinding.addView(ref);\n\t\tif (fresh) this.#hold(binding);\n\t\treturn ref;\n\t}\n\n\t/** Holds `binding` over the link to its host: the parent's, a child's, or one a route resolves. */\n\t#hold(binding: RemoteBinding): void {\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 (!binding.ended && binding.hold === undefined) target.hold(binding, false);\n\t\t\t\t},\n\t\t\t\t(error: unknown) => binding.gone(error),\n\t\t\t);\n\t\t};\n\t\tconst direct = this.#childNamed(binding.at);\n\t\tif (this.upstream !== undefined) this.upstream.hold(binding, false);\n\t\telse if (direct !== undefined) bindWhenSynced(direct.whenSynced().then(() => direct));\n\t\telse {\n\t\t\tconst route = this.#routeFor(binding.at);\n\t\t\tif (route === undefined) binding.gone(new ChordError(\"unavailable\", `no route to ${binding.at}`));\n\t\t\telse bindWhenSynced(this.#resolve(route, binding.at, binding.principal ?? this.principal));\n\t\t}\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: unknown,\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),\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 reference 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: RelayRef): Promise<void> {\n\t\tconst at = relay.frame.at;\n\t\t// The hold names its target; its contract token says where the type lives. They must agree.\n\t\tconst placement = contractFromDescription(relay.frame.token).description.host;\n\t\tif (placement === undefined || resolveHost(relay.frame.token.name, placement, relay.frame.input) !== at)\n\t\t\tthrow invalid(\"placement\", `${relay.frame.token.name} with this input does not live on ${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 code versions 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 code version id the next reload would commit. */\n\tpeekNextCodeVersion(): number {\n\t\treturn this.#codeVersionSeq + 1;\n\t}\n\n\t/**\n\t * Disposes every object, holders before what they reference (a resource's `close` may still use the objects its object\n\t * references, local or remote), then closes the links.\n\t */\n\tasync close(): Promise<void> {\n\t\tfor (const binding of [...this.#lingering.values()]) binding.close();\n\t\tthis.hostObjects.clear();\n\t\tfor (const name of [...this.#facetRuns.keys()]) this.facetRunChanged(name, undefined);\n\t\tconst reason = new ChordError(\"gone\", `host ${this.name} closed`);\n\t\ttry {\n\t\t\tawait disposeHoldersFirst([...this.objects.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 `objects` in waves: an object goes once no object of the set that references it is left, so holders are\n * disposed (and their resources closed) while what they reference is still live. In-host references are acyclic. Errors of\n * every disposal are collected.\n */\nasync function disposeHoldersFirst(objects: readonly ObjectImpl[], reason: unknown, message: string): Promise<void> {\n\tconst remaining = new Set(objects);\n\tconst held = (object: ObjectImpl): Set<ObjectImpl> => {\n\t\tconst result = new Set<ObjectImpl>();\n\t\tfor (const decls of object.allDecls()) {\n\t\t\tfor (const ref of decls.refs.values()) if (ref.object !== undefined) result.add(ref.object);\n\t\t}\n\t\treturn result;\n\t};\n\tconst refs = new Map(objects.map((object) => [object, held(object)] as const));\n\tconst errors: unknown[] = [];\n\twhile (remaining.size > 0) {\n\t\tconst heldByRemaining = new Set<ObjectImpl>();\n\t\tfor (const object of remaining) for (const target of refs.get(object) ?? []) heldByRemaining.add(target);\n\t\tlet wave = [...remaining].filter((object) => !heldByRemaining.has(object));\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 object of wave) remaining.delete(object);\n\t\tconst results = await Promise.allSettled(wave.map((object) => object.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: unknown): boolean =>\n\tprincipal !== null &&\n\ttypeof principal === \"object\" &&\n\tObject.entries(pattern).every(([key, value]) => deepEqual((principal as Record<string, unknown>)[key], value));\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` references `to`, directly or transitively, through object-owned references on this host. */\nfunction reaches(from: ObjectImpl, to: ObjectImpl): boolean {\n\tconst seen = new Set<ObjectImpl>();\n\tconst stack = [from];\n\twhile (stack.length > 0) {\n\t\tconst object = stack.pop()!;\n\t\tif (object === to) return true;\n\t\tif (seen.has(object)) continue;\n\t\tseen.add(object);\n\t\t// Remote references have no object here: cycles across hosts are avoided by convention.\n\t\tfor (const decls of object.allDecls()) {\n\t\t\tfor (const ref of decls.refs.values()) if (ref.object !== undefined) stack.push(ref.object);\n\t\t}\n\t}\n\treturn false;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export type { Cell } from "./cell.ts";
|
|
2
2
|
export type { AcceptOptions, LinkOptions } from "./connection.ts";
|
|
3
3
|
export type { Context, ContextKey } from "./context/index.ts";
|
|
4
|
-
export { type Accepts, type Adapter, type AnyContract,
|
|
5
|
-
export
|
|
4
|
+
export { type Accepts, type Adapter, type AnyContract, bind, coverage, type Description, type HostFamily, type HostNamed, hostFamily, hostNamed, type ImplementationOf, type InputOf, type LocalContract, local, method, opaque, type Placement, type PlacementFor, type Ref, type RemoteContract, remote, } from "./contract.ts";
|
|
5
|
+
export type { EventOf, Resource, ResourceDeclaration, Subscribable, ValueOf } from "./declare.ts";
|
|
6
6
|
export type { Draft } from "./delta/index.ts";
|
|
7
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,
|
|
8
|
+
export type { ConnectOptions, PrincipalMatch, PrincipalPattern, Route } from "./host.ts";
|
|
9
|
+
export { createHost, defineFacet, type Facet, type FacetApi, type FacetDefinition, type FacetLoader, type Host, type HostOptions, type LoadOptions, type PluginRef, type RootOptions, } from "./host.ts";
|
|
10
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 "./
|
|
11
|
+
export { type IpcChannel, inflateMessage, ipcLink, type Link, memoryLinkPair, PACK_THRESHOLD, type WebSocketLike, type WebSocketLinkOptions, webSocketLink, } from "./link.ts";
|
|
12
|
+
export type { Factory, HostServeOptions, Lifetime, ReferencedServeOptions, Self, ServeOptions, ServeOptionsFor, StateInit, StateOptions, } from "./object.ts";
|
|
13
13
|
export { defineRegistry, type Registry, type RegistryTable, type RegistryView } from "./registry.ts";
|
|
14
14
|
export type { ReloadOptions, ReloadReport } from "./reload.ts";
|
|
15
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,
|
|
16
|
+
export type { Ctx, GetOptions, Readable, RefStatus, Shape, StateEvent } from "./types.ts";
|
|
17
17
|
export { acceptWebSockets, type WebSocketAcceptOptions, type WebSocketServerLike } from "./websocket.ts";
|
|
18
|
-
export type
|
|
18
|
+
export { type Frame, PROTOCOL_VERSION } from "./wire.ts";
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,IAAI,EACJ,QAAQ,EACR,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,UAAU,EACV,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,EACL,MAAM,EACN,MAAM,EACN,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,GAAG,EACR,KAAK,cAAc,EACnB,MAAM,GACN,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAClG,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACh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AgB,EAAE,KAAK,sBAAsB,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAE,KAAK,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { bind, coverage, local, method, opaque, remote, } from "./contract.js";
|
|
2
|
-
export { cell, derivation, listener, resource, } from "./declare.js";
|
|
1
|
+
export { bind, coverage, hostFamily, hostNamed, local, method, opaque, remote, } from "./contract.js";
|
|
3
2
|
export { ChordError, forbidden, invalid, isChordError } from "./errors.js";
|
|
4
|
-
export { createHost, defineFacet,
|
|
3
|
+
export { createHost, defineFacet, } from "./host.js";
|
|
5
4
|
export { copyJson, isJsonValue } from "./json.js";
|
|
6
|
-
export { ipcLink, memoryLinkPair, webSocketLink } from "./link.js";
|
|
5
|
+
export { inflateMessage, ipcLink, memoryLinkPair, PACK_THRESHOLD, webSocketLink, } from "./link.js";
|
|
7
6
|
export { defineRegistry } from "./registry.js";
|
|
8
7
|
export { replicatedState, } from "./state.js";
|
|
9
8
|
export { acceptWebSockets } from "./websocket.js";
|
|
9
|
+
export { PROTOCOL_VERSION } from "./wire.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":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAIN,IAAI,EACJ,QAAQ,EAIR,UAAU,EACV,SAAS,EAIT,KAAK,EACL,MAAM,EACN,MAAM,EAKN,MAAM,GACN,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,UAAU,EAAuB,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhG,OAAO,EACN,UAAU,EACV,WAAW,GAUX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAwB,QAAQ,EAAE,WAAW,EAA2C,MAAM,WAAW,CAAC;AACjH,OAAO,EAEN,cAAc,EACd,OAAO,EAEP,cAAc,EACd,cAAc,EAGd,aAAa,GACb,MAAM,WAAW,CAAC;AAYnB,OAAO,EAAE,cAAc,EAAwD,MAAM,eAAe,CAAC;AAErG,OAAO,EASN,eAAe,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAyD,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAc,gBAAgB,EAAE,MAAM,WAAW,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\tbind,\n\tcoverage,\n\ttype Description,\n\ttype HostFamily,\n\ttype HostNamed,\n\thostFamily,\n\thostNamed,\n\ttype ImplementationOf,\n\ttype InputOf,\n\ttype LocalContract,\n\tlocal,\n\tmethod,\n\topaque,\n\ttype Placement,\n\ttype PlacementFor,\n\ttype Ref,\n\ttype RemoteContract,\n\tremote,\n} from \"./contract.ts\";\nexport type { EventOf, Resource, ResourceDeclaration, Subscribable, ValueOf } from \"./declare.ts\";\nexport type { Draft } from \"./delta/index.ts\";\nexport { ChordError, type ChordErrorCode, forbidden, invalid, isChordError } from \"./errors.ts\";\nexport type { ConnectOptions, PrincipalMatch, PrincipalPattern, 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\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 {\n\ttype IpcChannel,\n\tinflateMessage,\n\tipcLink,\n\ttype Link,\n\tmemoryLinkPair,\n\tPACK_THRESHOLD,\n\ttype WebSocketLike,\n\ttype WebSocketLinkOptions,\n\twebSocketLink,\n} from \"./link.ts\";\nexport type {\n\tFactory,\n\tHostServeOptions,\n\tLifetime,\n\tReferencedServeOptions,\n\tSelf,\n\tServeOptions,\n\tServeOptionsFor,\n\tStateInit,\n\tStateOptions,\n} from \"./object.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, Readable, RefStatus, Shape, StateEvent } from \"./types.ts\";\nexport { acceptWebSockets, type WebSocketAcceptOptions, type WebSocketServerLike } from \"./websocket.ts\";\nexport { type Frame, PROTOCOL_VERSION } from \"./wire.ts\";\n"]}
|