@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/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAgB,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,EAAgB,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAc,aAAa,EAAE,OAAO,EAAgB,WAAW,EAAE,MAAM,WAAW,CAAC;AAoC1F,MAAM,WAAW,GAAG,CAAC,OAAe,EAAc,EAAE,CAAC,IAAI,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAE5F,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,OAAO,SAAS;IACZ,MAAM,CAAa;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AC,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IAC3G,IAAI,WAAW,EAAE,IAAI,KAAK,OAAO;QAAE,WAAW,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,EAAE,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACnH,CAAC;AAED,qFAAqF;AACrF,SAAS,WAAW,CAAC,KAAc;IAClC,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;QACvE,OAAO,IAAI,UAAU,CAAC,kBAAkB,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { contractFromDescription, LOCAL_VARIANT } from \"./contract.ts\";\nimport { type Encoder, encoder } from \"./delta/index.ts\";\nimport { ChordError, invalid } from \"./errors.ts\";\nimport type { HostImpl } from \"./host.ts\";\nimport type { Link } from \"./link.ts\";\nimport { type CtxImpl, HandleImpl, kindOf } from \"./record.ts\";\nimport type { RemoteChannel, RemoteHandle, StateSink } from \"./remote.ts\";\nimport { assertValid } from \"./schema.ts\";\nimport type { Ctx, Principal, Readable, StateEvent } from \"./types.ts\";\nimport { type Frame, fromWireError, isFrame, type RootRef, toWireError } from \"./wire.ts\";\n\nexport interface LinkOptions {\n\t/** Milliseconds between pings (default 15000). */\n\treadonly pingInterval?: number;\n\t/** Close the link when nothing arrived for this long (default 45000). Everything held through it is released. */\n\treadonly pingTimeout?: number;\n}\n\nexport interface AcceptOptions extends LinkOptions {\n\t/** The principal of whatever connects, from the app's authenticator. Every request on the link acts as it. */\n\treadonly principal: Principal;\n\t/**\n\t * What the peer is, decided here and never by its `hello`: `client` (default; a browser: no roots, no epochs, not\n\t * a reload participant, not addressable) or `host` (a child host; needs `name`).\n\t */\n\treadonly kind?: \"host\" | \"client\";\n\t/** A child host's name: its hello must match, and it is reachable `at` this name. */\n\treadonly name?: string;\n\t/** On `invalidatePrincipal`: a new principal keeps the link, `undefined` closes it (default: close). */\n\treadonly restamp?: (principal: Principal) => Principal | undefined;\n}\n\nexport interface Peer {\n\treadonly kind: \"host\" | \"client\";\n\t/** Configured (downstream hosts) or announced by the trusted parent (upstream). */\n\treadonly name: string | undefined;\n}\n\n/** A hold the peer made on this host: served locally or relayed to another link. */\ntype Served =\n\t| { readonly kind: \"local\"; readonly handle: HandleImpl; readonly principal: Principal; readonly feeds: Set<number> }\n\t| { readonly kind: \"relay\"; readonly relay: RelayHold };\n\ntype Pending = { readonly resolve: (value: unknown) => void; readonly reject: (error: unknown) => void };\n\nconst unavailable = (message: string): ChordError => new ChordError(\"unavailable\", message);\n\n// ─── relay ───────────────────────────────────────────────────────────────────\n\n/**\n * A hold relayed from an origin link to a downstream link. It owns everything done through it: subscriptions and\n * calls queued while the route resolves, and the downstream twins once forwarded. `close` undoes all of it exactly\n * once (cancels calls downstream, drops subscriptions, releases the downstream hold, rejects waiters).\n */\nexport class RelayHold {\n\treadonly origin: Connection;\n\treadonly frame: Extract<Frame, { t: \"hold\" }>;\n\treadonly principal: Principal;\n\treadonly client: boolean;\n\t/** The origin's authorization generation when the hold arrived; a revocation bumps it. */\n\treadonly generation: number;\n\tdown: Connection | undefined;\n\tdownId = 0;\n\tclosed = false;\n\treadonly calls = new Map<number, RelayCall>();\n\treadonly subs = new Map<number, { readonly member: string; downId: number | undefined }>();\n\treadonly #waiters = new Set<Pending>();\n\n\tconstructor(origin: Connection, frame: Extract<Frame, { t: \"hold\" }>, principal: Principal, client: boolean) {\n\t\tthis.origin = origin;\n\t\tthis.frame = frame;\n\t\tthis.principal = principal;\n\t\tthis.client = client;\n\t\tthis.generation = origin.generation;\n\t}\n\n\tget originId(): number {\n\t\treturn this.frame.id;\n\t}\n\n\t/** Still authorized as it was when it arrived. */\n\tget current(): boolean {\n\t\treturn !this.closed && this.origin.open && this.origin.generation === this.generation;\n\t}\n\n\t/** The downstream connection once the route resolved; rejects if the relay closes first. */\n\tready(): Promise<Connection> {\n\t\tif (this.closed) return Promise.reject(new ChordError(\"gone\", \"relayed hold closed\"));\n\t\tif (this.down !== undefined) return Promise.resolve(this.down);\n\t\treturn new Promise<Connection>((resolve, reject) => {\n\t\t\tthis.#waiters.add({ resolve: resolve as (value: unknown) => void, reject });\n\t\t});\n\t}\n\n\t/** Forwards the hold (and what queued meanwhile) to `down`. */\n\topen(down: Connection): void {\n\t\tif (this.closed) return;\n\t\tthis.down = down;\n\t\tthis.downId = down.nextId();\n\t\tdown.relayedHolds.set(this.downId, this);\n\t\tdown.send({\n\t\t\t...this.frame,\n\t\t\tid: this.downId,\n\t\t\tprincipal: this.principal,\n\t\t\t...(this.client ? { client: true } : {}),\n\t\t});\n\t\tfor (const [originSubId, entry] of this.subs)\n\t\t\tif (entry.downId === undefined) this.#forwardSub(originSubId, entry);\n\t\tfor (const waiter of this.#waiters) waiter.resolve(down);\n\t\tthis.#waiters.clear();\n\t}\n\n\tsubscribe(originSubId: number, member: string): void {\n\t\tconst entry = { member, downId: undefined as number | undefined };\n\t\tthis.subs.set(originSubId, entry);\n\t\tthis.origin.relaySubs.set(originSubId, this);\n\t\tif (this.down !== undefined) this.#forwardSub(originSubId, entry);\n\t}\n\n\t#forwardSub(originSubId: number, entry: { readonly member: string; downId: number | undefined }): void {\n\t\tconst down = this.down!;\n\t\tentry.downId = down.nextId();\n\t\tdown.relayedSubs.set(entry.downId, { relay: this, originSubId });\n\t\tdown.send({ t: \"sub\", id: entry.downId, hold: this.downId, member: entry.member });\n\t}\n\n\tunsubscribe(originSubId: number, forward = true): void {\n\t\tconst entry = this.subs.get(originSubId);\n\t\tif (entry === undefined) return;\n\t\tthis.subs.delete(originSubId);\n\t\tthis.origin.relaySubs.delete(originSubId);\n\t\tif (entry.downId !== undefined && this.down !== undefined) {\n\t\t\tthis.down.relayedSubs.delete(entry.downId);\n\t\t\tif (forward) this.down.send({ t: \"unsub\", id: entry.downId });\n\t\t}\n\t}\n\n\t/**\n\t * Closes the relay. `releaseDown`: the downstream hold is still there (origin released, disconnected, or was\n\t * revoked): cancel its calls and release it. `notify`: tell the origin the hold is gone.\n\t */\n\tclose(error: unknown, options: { readonly releaseDown: boolean; readonly notify: boolean }): void {\n\t\tif (this.closed) return;\n\t\tthis.closed = true;\n\t\tfor (const call of [...this.calls.values()]) call.cancel(error, options.releaseDown);\n\t\tfor (const originSubId of [...this.subs.keys()]) this.unsubscribe(originSubId, options.releaseDown);\n\t\tif (this.origin.served.get(this.originId)?.kind === \"relay\") this.origin.served.delete(this.originId);\n\t\tif (this.down !== undefined) {\n\t\t\tthis.down.relayedHolds.delete(this.downId);\n\t\t\tif (options.releaseDown) this.down.send({ t: \"release\", id: this.downId });\n\t\t}\n\t\tfor (const waiter of this.#waiters) waiter.reject(error);\n\t\tthis.#waiters.clear();\n\t\tif (options.notify) this.origin.send({ t: \"gone\", id: this.originId, error: toWireError(error) });\n\t}\n}\n\n/** One relayed call: settles once, by result, cancellation or the relay closing; removes both mappings. */\nexport class RelayCall {\n\treadonly relay: RelayHold;\n\treadonly originId: number;\n\treadonly downId: number;\n\treadonly #pending: Pending;\n\t#settled = false;\n\n\tconstructor(relay: RelayHold, originId: number, downId: number, pending: Pending) {\n\t\tthis.relay = relay;\n\t\tthis.originId = originId;\n\t\tthis.downId = downId;\n\t\tthis.#pending = pending;\n\t\trelay.calls.set(originId, this);\n\t\trelay.down?.relayedCalls.set(downId, this);\n\t}\n\n\tfinish(error: unknown, value?: unknown): void {\n\t\tif (this.#settled) return;\n\t\tthis.#settled = true;\n\t\tthis.relay.calls.delete(this.originId);\n\t\tthis.relay.down?.relayedCalls.delete(this.downId);\n\t\tif (error === undefined) this.#pending.resolve(value);\n\t\telse this.#pending.reject(error);\n\t}\n\n\t/** Cancels downstream (when the downstream hold still exists) and settles with `error`. */\n\tcancel(error: unknown, forward: boolean): void {\n\t\tif (this.#settled) return;\n\t\tif (forward) this.relay.down?.send({ t: \"cancel\", id: this.downId });\n\t\tthis.finish(error);\n\t}\n}\n\n// ─── connection ──────────────────────────────────────────────────────────────\n\n/** One end of a link on a host: consumer of remote handles, provider for the peer's holds, and relay. */\nexport class Connection implements RemoteChannel {\n\treadonly host: HostImpl;\n\treadonly link: Link;\n\t/** `upstream`: the link to this host's parent. `downstream`: a link this host accepted. */\n\treadonly role: \"upstream\" | \"downstream\";\n\treadonly peer: Peer;\n\tprincipal: Principal;\n\treadonly restamp: ((principal: Principal) => Principal | undefined) | undefined;\n\t/** Bumped when the stamped principal is revoked or re-stamped: relays from before are refused. */\n\tgeneration = 0;\n\t/** The epoch a downstream host peer runs (from its hello, then from commits). */\n\tpeerEpoch: number | undefined;\n\t/** A downstream host peer is usable once it runs this host's current epoch (see `HostImpl.peerHello`). */\n\tsynced: boolean;\n\t/** Epochs this child announced while behind this host (fenced): this host never ran them. */\n\treadonly fencedEpochs = new Set<number>();\n\t/** Roots of fenced epochs, by the epoch of this host they were admitted in. */\n\treadonly #admitted = new Map<string, number>();\n\t#parentName: string | undefined;\n\treadonly #syncWaiters = new Set<Pending>();\n\t#nextId = 1;\n\t#lastSeen = Date.now();\n\t#pinger: ReturnType<typeof setInterval> | undefined;\n\t// consumer side: what this host asked of the peer\n\treadonly remotes = new Map<number, RemoteHandle>();\n\treadonly calls = new Map<number, Pending>();\n\treadonly subs = new Map<number, (frame: StateSink) => void>();\n\t// provider side: what the peer asked of this host\n\treadonly served = new Map<number, Served>();\n\treadonly incoming = new Map<number, AbortController>();\n\treadonly feeds = new Map<number, () => void>();\n\t/** Origin side of relays: the peer's sub ids that are relayed. */\n\treadonly relaySubs = new Map<number, RelayHold>();\n\t// downstream side of relays: ids this host used on this link\n\treadonly relayedHolds = new Map<number, RelayHold>();\n\treadonly relayedCalls = new Map<number, RelayCall>();\n\treadonly relayedSubs = new Map<number, { readonly relay: RelayHold; readonly originSubId: number }>();\n\t/** Reload votes awaited from this (child) peer. */\n\treadonly votes = new Map<number, Pending>();\n\n\tconstructor(\n\t\thost: HostImpl,\n\t\tlink: Link,\n\t\tconfig: {\n\t\t\treadonly role: \"upstream\" | \"downstream\";\n\t\t\treadonly principal: Principal;\n\t\t\treadonly peer: Peer;\n\t\t\treadonly restamp?: (principal: Principal) => Principal | undefined;\n\t\t} & LinkOptions,\n\t) {\n\t\tthis.host = host;\n\t\tthis.link = link;\n\t\tthis.role = config.role;\n\t\tthis.peer = config.peer;\n\t\tthis.principal = config.principal;\n\t\tthis.restamp = config.restamp;\n\t\tthis.synced = !(this.role === \"downstream\" && this.peer.kind === \"host\");\n\t\tlink.onClose((reason) => this.#closed(reason));\n\t\tlink.receive((frame) => this.#receive(frame));\n\t\tthis.send({ t: \"hello\", name: host.name, kind: host.kind, epoch: host.current.id });\n\t\tconst interval = config.pingInterval ?? 15_000;\n\t\tconst timeout = config.pingTimeout ?? 45_000;\n\t\tlet n = 0;\n\t\tthis.#pinger = setInterval(() => {\n\t\t\tif (Date.now() - this.#lastSeen > timeout) link.close(\"ping timeout\");\n\t\t\telse this.send({ t: \"ping\", n: ++n });\n\t\t}, interval);\n\t\tthis.#pinger.unref?.();\n\t}\n\n\tget open(): boolean {\n\t\treturn !this.link.closed;\n\t}\n\n\t/** The peer's name: configured for downstream hosts, announced by the parent upstream. */\n\tget name(): string | undefined {\n\t\treturn this.role === \"upstream\" ? this.#parentName : this.peer.name;\n\t}\n\n\tsend(frame: Frame): void {\n\t\tthis.link.send(frame);\n\t}\n\n\tnextId(): number {\n\t\treturn this.#nextId++;\n\t}\n\n\t/** Resolves once the peer is usable (a host peer runs this host's epoch); rejects if the link closes first. */\n\twhenSynced(): Promise<void> {\n\t\tif (!this.open) return Promise.reject(unavailable(`link to ${this.name ?? \"peer\"} closed`));\n\t\tif (this.synced) return Promise.resolve();\n\t\treturn new Promise<void>((resolve, reject) => this.#syncWaiters.add({ resolve: resolve as () => void, reject }));\n\t}\n\n\tmarkSynced(epoch: number): void {\n\t\tthis.peerEpoch = epoch;\n\t\tthis.synced = true;\n\t\tfor (const waiter of this.#syncWaiters) waiter.resolve(undefined);\n\t\tthis.#syncWaiters.clear();\n\t}\n\n\t/** Revokes the stamped principal: relays made under it close at once (also those still resolving a route). */\n\trevoke(next: Principal | undefined): void {\n\t\tthis.generation++;\n\t\tconst error = new ChordError(\"gone\", \"principal invalidated\");\n\t\tfor (const served of [...this.served.values()]) {\n\t\t\tif (served.kind === \"relay\") served.relay.close(error, { releaseDown: true, notify: true });\n\t\t}\n\t\tif (next === undefined) this.link.close(\"principal invalidated\");\n\t\telse this.principal = next;\n\t}\n\n\t/** A protocol violation: the peer cannot be trusted with anything on this link any more. */\n\t#violation(reason: string): void {\n\t\tthis.host.report(new ChordError(\"invalid\", `link to ${this.name ?? \"peer\"}: ${reason}`, { reason: \"protocol\" }));\n\t\tthis.link.close(`protocol error: ${reason}`);\n\t}\n\n\t// ─── consumer side (RemoteChannel) ───\n\n\thold(handle: RemoteHandle): number {\n\t\tconst id = this.nextId();\n\t\tthis.remotes.set(id, handle);\n\t\thandle.bound(this, id);\n\t\tconst principal = handle.principal;\n\t\tthis.send({\n\t\t\tt: \"hold\",\n\t\t\tid,\n\t\t\tat: handle.at,\n\t\t\ttoken: handle.contract.description,\n\t\t\tinput: handle.input,\n\t\t\t...(principal === undefined ? {} : { principal }),\n\t\t\t...(handle.owner === \"client\" ? { client: true } : {}),\n\t\t});\n\t\treturn id;\n\t}\n\n\trelease(id: number): void {\n\t\tthis.remotes.delete(id);\n\t\tthis.send({ t: \"release\", id });\n\t}\n\n\tcall(hold: number, member: string, args: unknown, root: RootRef | undefined, signal: AbortSignal): Promise<unknown> {\n\t\tconst id = this.nextId();\n\t\treturn new Promise<unknown>((resolve, reject) => {\n\t\t\tif (signal.aborted) {\n\t\t\t\treject(new ChordError(\"aborted\", \"call aborted\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst onAbort = (): void => {\n\t\t\t\tthis.calls.delete(id);\n\t\t\t\tthis.send({ t: \"cancel\", id });\n\t\t\t\treject(new ChordError(\"aborted\", \"call aborted\", { cause: signal.reason }));\n\t\t\t};\n\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tconst done = (): void => signal.removeEventListener(\"abort\", onAbort);\n\t\t\tthis.calls.set(id, {\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tdone();\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t\t// Clients never carry roots or epochs: the server starts roots for them.\n\t\t\tconst carried = root !== undefined && this.host.kind === \"host\";\n\t\t\tif (carried) this.host.rootSent(root.rootId, this);\n\t\t\tthis.send({ t: \"call\", id, hold, member, args, ...(carried ? { root } : {}) });\n\t\t});\n\t}\n\n\tsub(hold: number, member: string, sink: (frame: StateSink) => void): number {\n\t\tconst id = this.nextId();\n\t\tthis.subs.set(id, sink);\n\t\tthis.send({ t: \"sub\", id, hold, member });\n\t\treturn id;\n\t}\n\n\tunsub(id: number): void {\n\t\tif (this.subs.delete(id)) this.send({ t: \"unsub\", id });\n\t}\n\n\t// ─── receiving ───\n\n\t#receive(frame: unknown): void {\n\t\tthis.#lastSeen = Date.now();\n\t\tif (!isFrame(frame)) {\n\t\t\tthis.#violation(\"malformed frame\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tthis.#dispatch(frame);\n\t\t} catch (error) {\n\t\t\tthis.host.report(error);\n\t\t}\n\t}\n\n\t#dispatch(frame: Frame): void {\n\t\tswitch (frame.t) {\n\t\t\tcase \"hello\":\n\t\t\t\tthis.#onHello(frame);\n\t\t\t\treturn;\n\t\t\tcase \"ping\":\n\t\t\t\tthis.send({ t: \"pong\", n: frame.n });\n\t\t\t\treturn;\n\t\t\tcase \"pong\":\n\t\t\tcase \"bye\":\n\t\t\t\treturn;\n\t\t\tcase \"hold\":\n\t\t\t\tthis.#onHold(frame);\n\t\t\t\treturn;\n\t\t\tcase \"release\":\n\t\t\t\tthis.#dropServed(frame.id, true);\n\t\t\t\treturn;\n\t\t\tcase \"call\":\n\t\t\t\tthis.#onCall(frame);\n\t\t\t\treturn;\n\t\t\tcase \"cancel\":\n\t\t\t\tthis.incoming.get(frame.id)?.abort(new ChordError(\"aborted\", \"cancelled by caller\"));\n\t\t\t\treturn;\n\t\t\tcase \"sub\":\n\t\t\t\tthis.#onSub(frame);\n\t\t\t\treturn;\n\t\t\tcase \"unsub\":\n\t\t\t\tthis.#onUnsub(frame.id);\n\t\t\t\treturn;\n\t\t\tcase \"shape\":\n\t\t\tcase \"gone\":\n\t\t\t\tthis.#onHoldReply(frame);\n\t\t\t\treturn;\n\t\t\tcase \"result\":\n\t\t\t\tthis.#onResult(frame);\n\t\t\t\treturn;\n\t\t\tcase \"state\":\n\t\t\t\tthis.#onState(frame);\n\t\t\t\treturn;\n\t\t\tcase \"root_end\":\n\t\t\t\t// Honored only from the link the root came over (see HostImpl.foreignRootEnded).\n\t\t\t\tthis.#admitted.delete(frame.rootId);\n\t\t\t\tthis.host.foreignRootEnded(frame.rootId, this);\n\t\t\t\treturn;\n\t\t\tcase \"invalidate\":\n\t\t\tcase \"prepare\":\n\t\t\tcase \"commit\":\n\t\t\tcase \"abort\":\n\t\t\tcase \"retire\":\n\t\t\t\t// Control frames only from the parent.\n\t\t\t\tif (this.role !== \"upstream\") {\n\t\t\t\t\tthis.#violation(`${frame.t} from a child`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (frame.t === \"invalidate\") {\n\t\t\t\t\tthis.host.invalidatePrincipal(frame.pattern).catch((error: unknown) => this.host.report(error));\n\t\t\t\t} else if (frame.t === \"retire\") this.host.allowRetire(frame.epoch);\n\t\t\t\telse this.host.onReloadFrame(this, frame);\n\t\t\t\treturn;\n\t\t\tcase \"vote\": {\n\t\t\t\tif (this.role !== \"downstream\" || this.peer.kind !== \"host\") {\n\t\t\t\t\tthis.#violation(\"vote from a non-participant\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst vote = this.votes.get(frame.reload);\n\t\t\t\tthis.votes.delete(frame.reload);\n\t\t\t\tif (frame.error === undefined) vote?.resolve(frame.report);\n\t\t\t\telse vote?.reject(fromWireError(frame.error));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The peer's hello must agree with what this side decided about it. A downstream host announces its epoch: the\n\t * host either finds it in step or fences and reconciles it (never renumbers).\n\t */\n\t#onHello(frame: Extract<Frame, { t: \"hello\" }>): void {\n\t\tif (this.role === \"upstream\") {\n\t\t\tif (frame.kind !== \"host\") {\n\t\t\t\tthis.#violation(\"parent is not a host\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.#parentName ??= frame.name;\n\t\t\treturn;\n\t\t}\n\t\tif (frame.kind !== this.peer.kind || (this.peer.name !== undefined && frame.name !== this.peer.name)) {\n\t\t\tthis.#violation(\n\t\t\t\t`hello ${frame.kind} ${frame.name} does not match the accepted ${this.peer.kind} ${this.peer.name ?? \"\"}`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (this.peer.kind === \"host\") this.host.peerHello(this, frame.epoch);\n\t}\n\n\t/**\n\t * Principal stamping: a downstream link acts as the principal it was accepted with, whatever the frame says. Only\n\t * the parent may forward a principal (relayed requests); its own requests act as `{ host: parentName }`.\n\t */\n\t#principalOf(frame: { readonly principal?: Principal }): Principal {\n\t\tif (this.role === \"downstream\") return this.principal;\n\t\treturn frame.principal ?? { host: this.#parentName ?? \"parent\" };\n\t}\n\n\t#isClient(frame: { readonly client?: boolean }): boolean {\n\t\treturn this.role === \"downstream\" ? this.peer.kind === \"client\" : frame.client === true;\n\t}\n\n\t#onHold(frame: Extract<Frame, { t: \"hold\" }>): void {\n\t\tif (this.served.has(frame.id)) {\n\t\t\tthis.#violation(`duplicate hold id ${frame.id}`);\n\t\t\treturn;\n\t\t}\n\t\tconst principal = this.#principalOf(frame);\n\t\tconst client = this.#isClient(frame);\n\t\tif (frame.at !== this.host.name) {\n\t\t\tif (this.role === \"upstream\") {\n\t\t\t\tthis.send({ t: \"gone\", id: frame.id, error: toWireError(unavailable(`${this.host.name} does not relay`)) });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst relay = new RelayHold(this, frame, principal, client);\n\t\t\tthis.served.set(frame.id, { kind: \"relay\", relay });\n\t\t\tthis.host.relay(relay).catch((error: unknown) => relay.close(error, { releaseDown: true, notify: true }));\n\t\t\treturn;\n\t\t}\n\t\tlet handle: HandleImpl;\n\t\ttry {\n\t\t\tconst token = contractFromDescription(frame.token);\n\t\t\tif (token.scope !== \"remote\") throw invalid(\"token\", `${token.name} is local; only remote types cross links`);\n\t\t\tconst acquired = this.host.acquire(token, frame.input, { principal }, client ? \"client\" : \"connection\");\n\t\t\tif (!(acquired instanceof HandleImpl)) throw unavailable(\"not a local handle\");\n\t\t\thandle = acquired;\n\t\t} catch (error) {\n\t\t\tthis.send({ t: \"gone\", id: frame.id, error: toWireError(client ? clientError(error) : error) });\n\t\t\treturn;\n\t\t}\n\t\tconst served: Served = { kind: \"local\", handle, principal, feeds: new Set() };\n\t\tthis.served.set(frame.id, served);\n\t\tconst shape = (): void => {\n\t\t\tconst current = handle.shape;\n\t\t\tif (current === undefined || this.served.get(frame.id) !== served) return;\n\t\t\tthis.send({\n\t\t\t\tt: \"shape\",\n\t\t\t\tid: frame.id,\n\t\t\t\tkind: current.kind,\n\t\t\t\tmembers: current.members,\n\t\t\t\tcontract: current.contract,\n\t\t\t\tepoch: current.epoch,\n\t\t\t});\n\t\t};\n\t\thandle.onShape(shape);\n\t\thandle.goneListeners.add((error) => {\n\t\t\tif (this.served.get(frame.id) !== served) return;\n\t\t\tthis.#dropServed(frame.id, false);\n\t\t\tthis.send({ t: \"gone\", id: frame.id, error: toWireError(error) });\n\t\t});\n\t\tif (handle.status === \"live\") shape();\n\t}\n\n\t/** Forgets a served hold: unsubscribes its feeds and releases it (locally or downstream). */\n\t#dropServed(id: number, release: boolean): void {\n\t\tconst served = this.served.get(id);\n\t\tif (served === undefined) return;\n\t\tthis.served.delete(id);\n\t\tif (served.kind === \"relay\") {\n\t\t\tserved.relay.close(new ChordError(\"released\", \"relayed hold released\"), {\n\t\t\t\treleaseDown: release,\n\t\t\t\tnotify: false,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tfor (const feed of served.feeds) this.#onUnsub(feed);\n\t\tif (release) served.handle.release();\n\t}\n\n\t#onCall(frame: Extract<Frame, { t: \"call\" }>): void {\n\t\tif (this.incoming.has(frame.id)) {\n\t\t\tthis.#violation(`duplicate call id ${frame.id}`);\n\t\t\treturn;\n\t\t}\n\t\tconst served = this.served.get(frame.hold);\n\t\tif (served === undefined) {\n\t\t\tthis.send({ t: \"result\", id: frame.id, error: toWireError(new ChordError(\"gone\", \"unknown hold\")) });\n\t\t\treturn;\n\t\t}\n\t\tconst controller = new AbortController();\n\t\tthis.incoming.set(frame.id, controller);\n\t\t// Roots are honored from hosts only; a request without one (or from a client) starts one here.\n\t\tconst root = this.peer.kind === \"host\" ? this.#admitRoot(frame.root) : undefined;\n\t\tconst principal = served.kind === \"local\" ? served.principal : served.relay.principal;\n\t\tconst options = { principal, signal: controller.signal };\n\t\tconst run =\n\t\t\tserved.kind === \"local\"\n\t\t\t\t? (ctx: Ctx) => served.handle.record.call(served.handle, frame.member, frame.args, ctx as CtxImpl)\n\t\t\t\t: (ctx: Ctx) =>\n\t\t\t\t\t\trelayCall(\n\t\t\t\t\t\t\tserved.relay,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t\t{ rootId: ctx.rootId, epoch: ctx.epoch },\n\t\t\t\t\t\t\tcontroller.signal,\n\t\t\t\t\t\t\tthis.host,\n\t\t\t\t\t\t);\n\t\tconst result =\n\t\t\troot === undefined\n\t\t\t\t? this.host.root(run, options)\n\t\t\t\t: this.host.joinRoot(root.rootId, root.epoch, run, { ...options, from: this });\n\t\tresult\n\t\t\t.then(\n\t\t\t\t(value) => this.send({ t: \"result\", id: frame.id, value }),\n\t\t\t\t(error: unknown) => this.send({ t: \"result\", id: frame.id, error: toWireError(error) }),\n\t\t\t)\n\t\t\t.finally(() => this.incoming.delete(frame.id));\n\t}\n\n\t/**\n\t * A child that connected behind this host runs roots of an epoch this host never had (it was fenced and is being,\n\t * or was, reconciled). Such a root is admitted in this host's current epoch at its first call here, and keeps that\n\t * epoch for its later calls (`superseded` once this host retired it). Other unknown epochs stay `superseded`.\n\t */\n\t#admitRoot(root: RootRef | undefined): RootRef | undefined {\n\t\tif (root === undefined || this.role !== \"downstream\" || !this.fencedEpochs.has(root.epoch)) return root;\n\t\tif (this.host.hasEpoch(root.epoch)) return root;\n\t\tlet epoch = this.#admitted.get(root.rootId);\n\t\tif (epoch === undefined) {\n\t\t\tepoch = this.host.current.id;\n\t\t\tthis.#admitted.set(root.rootId, epoch);\n\t\t}\n\t\treturn { rootId: root.rootId, epoch };\n\t}\n\n\t#onSub(frame: Extract<Frame, { t: \"sub\" }>): void {\n\t\tif (this.feeds.has(frame.id) || this.relaySubs.has(frame.id)) {\n\t\t\tthis.#violation(`duplicate sub id ${frame.id}`);\n\t\t\treturn;\n\t\t}\n\t\tconst served = this.served.get(frame.hold);\n\t\tif (served === undefined) {\n\t\t\tthis.send({ t: \"state\", id: frame.id, error: toWireError(new ChordError(\"gone\", \"unknown hold\")) });\n\t\t\treturn;\n\t\t}\n\t\tif (served.kind === \"relay\") {\n\t\t\tserved.relay.subscribe(frame.id, frame.member);\n\t\t\treturn;\n\t\t}\n\t\tconst readable = served.handle.member(frame.member) as Readable<unknown> | undefined;\n\t\tif (readable === undefined || typeof readable.events !== \"function\") {\n\t\t\tthis.send({\n\t\t\t\tt: \"state\",\n\t\t\t\tid: frame.id,\n\t\t\t\terror: toWireError(new ChordError(\"not_in_variant\", `${frame.member} is not state`)),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tlet stream: Encoder = encoder();\n\t\tconst send = (event: StateEvent<unknown>): void => {\n\t\t\tif (event.type === \"ops\") {\n\t\t\t\tthis.send({ t: \"state\", id: frame.id, ops: stream.encode(event.ops) });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// A loading provider handle has nothing yet: the hydrated value follows as a reset.\n\t\t\tif (event.value === undefined) return;\n\t\t\t// Snapshots are validated against the effective schema once per (re)subscription; ops only in dev mode.\n\t\t\ttry {\n\t\t\t\tvalidateSnapshot(served.handle, frame.member, event.value);\n\t\t\t} catch (error) {\n\t\t\t\tthis.send({ t: \"state\", id: frame.id, error: toWireError(error) });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstream = encoder();\n\t\t\tthis.send(\n\t\t\t\tevent.type === \"snap\"\n\t\t\t\t\t? { t: \"state\", id: frame.id, snap: event.value }\n\t\t\t\t\t: { t: \"state\", id: frame.id, reset: event.value },\n\t\t\t);\n\t\t};\n\t\tconst unsubscribe = readable.events(send);\n\t\tthis.feeds.set(frame.id, unsubscribe);\n\t\tserved.feeds.add(frame.id);\n\t}\n\n\t#onUnsub(id: number): void {\n\t\tconst unsubscribe = this.feeds.get(id);\n\t\tif (unsubscribe !== undefined) {\n\t\t\tthis.feeds.delete(id);\n\t\t\tunsubscribe();\n\t\t}\n\t\tthis.relaySubs.get(id)?.unsubscribe(id);\n\t}\n\n\t#onHoldReply(frame: Extract<Frame, { t: \"shape\" | \"gone\" }>): void {\n\t\tconst relay = this.relayedHolds.get(frame.id);\n\t\tif (relay !== undefined) {\n\t\t\tif (frame.t === \"gone\") relay.close(fromWireError(frame.error), { releaseDown: false, notify: true });\n\t\t\telse if (!relay.closed) relay.origin.send({ ...frame, id: relay.originId });\n\t\t\treturn;\n\t\t}\n\t\tconst handle = this.remotes.get(frame.id);\n\t\tif (handle === undefined) return;\n\t\tif (frame.t === \"gone\") {\n\t\t\tthis.remotes.delete(frame.id);\n\t\t\thandle.gone(fromWireError(frame.error));\n\t\t\treturn;\n\t\t}\n\t\thandle.shaped({ kind: frame.kind, members: frame.members, contract: frame.contract, epoch: frame.epoch });\n\t}\n\n\t#onResult(frame: Extract<Frame, { t: \"result\" }>): void {\n\t\tconst relayed = this.relayedCalls.get(frame.id);\n\t\tif (relayed !== undefined) {\n\t\t\trelayed.finish(frame.error === undefined ? undefined : fromWireError(frame.error), frame.value);\n\t\t\treturn;\n\t\t}\n\t\tconst pending = this.calls.get(frame.id);\n\t\tthis.calls.delete(frame.id);\n\t\tif (frame.error === undefined) pending?.resolve(frame.value);\n\t\telse pending?.reject(fromWireError(frame.error));\n\t}\n\n\t#onState(frame: Extract<Frame, { t: \"state\" }>): void {\n\t\tconst relayed = this.relayedSubs.get(frame.id);\n\t\tif (relayed !== undefined) {\n\t\t\trelayed.relay.origin.send({ ...frame, id: relayed.originSubId });\n\t\t\treturn;\n\t\t}\n\t\tthis.subs.get(frame.id)?.(frame);\n\t}\n\n\t// ─── lifetime ───\n\n\t#closed(reason: string): void {\n\t\tif (this.#pinger !== undefined) clearInterval(this.#pinger);\n\t\tconst error = unavailable(`link to ${this.name ?? \"peer\"} closed: ${reason}`);\n\t\t// As origin: everything the peer held here, relayed or not, is released (downstream calls cancelled).\n\t\tfor (const id of [...this.served.keys()]) this.#dropServed(id, true);\n\t\tfor (const controller of this.incoming.values()) controller.abort(error);\n\t\tthis.incoming.clear();\n\t\tfor (const pending of this.calls.values()) pending.reject(error);\n\t\tthis.calls.clear();\n\t\tthis.subs.clear();\n\t\tfor (const vote of this.votes.values()) vote.reject(error);\n\t\tthis.votes.clear();\n\t\tfor (const waiter of this.#syncWaiters) waiter.reject(error);\n\t\tthis.#syncWaiters.clear();\n\t\t// As downstream of relays: their origins lose the hold.\n\t\tfor (const relay of [...this.relayedHolds.values()]) relay.close(error, { releaseDown: false, notify: true });\n\t\tthis.relayedHolds.clear();\n\t\tthis.relayedCalls.clear();\n\t\tthis.relayedSubs.clear();\n\t\tfor (const handle of this.remotes.values()) {\n\t\t\t// An upstream link may be replaced (reconnect); a downstream host that went away is gone.\n\t\t\tif (this.role === \"upstream\") handle.detached();\n\t\t\telse handle.gone(error);\n\t\t}\n\t\tthis.remotes.clear();\n\t\tthis.host.connectionClosed(this);\n\t}\n}\n\n/**\n * A call through a relay: waits for the route, then forwards with the root it runs in. It settles exactly once; a\n * cancel (or the origin going away) is forwarded downstream and removes both mappings.\n */\nasync function relayCall(\n\trelay: RelayHold,\n\tframe: Extract<Frame, { t: \"call\" }>,\n\troot: RootRef,\n\tsignal: AbortSignal,\n\thost: HostImpl,\n): Promise<unknown> {\n\tconst abortError = (): ChordError => new ChordError(\"aborted\", \"call cancelled\", { cause: signal.reason });\n\tif (signal.aborted) throw abortError();\n\tlet onAbort = (): void => {};\n\tconst aborted = new Promise<never>((_, reject) => {\n\t\tonAbort = () => reject(abortError());\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n\taborted.catch(() => {});\n\ttry {\n\t\tconst down = await Promise.race([relay.ready(), aborted]);\n\t\tif (relay.closed) throw new ChordError(\"gone\", \"relayed hold closed\");\n\t\treturn await new Promise<unknown>((resolve, reject) => {\n\t\t\tconst call = new RelayCall(relay, frame.id, down.nextId(), { resolve, reject });\n\t\t\tsignal.addEventListener(\"abort\", () => call.cancel(abortError(), true), { once: true });\n\t\t\thost.rootSent(root.rootId, down);\n\t\t\tdown.send({ t: \"call\", id: call.downId, hold: relay.downId, member: frame.member, args: frame.args, root });\n\t\t});\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n\n/**\n * Validates a snapshot against the schema the consumer is promised: the provider's own schema for a direct binding,\n * the consumer's contract for one through an `accepts` adapter (the adapter's view is what the consumer gets).\n */\nfunction validateSnapshot(handle: HandleImpl, member: string, value: unknown): void {\n\tif (value === undefined) return;\n\tconst installed = handle.record.currentInstalled();\n\tif (installed === undefined) return;\n\tconst view = handle.currentView();\n\tconst kind = view === undefined ? kindOf(installed.behavior) : kindOf(view);\n\tconst description =\n\t\tview !== undefined && view !== installed.behavior\n\t\t\t? handle.contract.description.variants[kind ?? LOCAL_VARIANT]?.[member]\n\t\t\t: installed.service.contract.description.variants[kindOf(installed.behavior) ?? LOCAL_VARIANT]?.[member];\n\tif (description?.kind === \"state\") assertValid(\"state\", `${handle.address}.${member}`, description.schema, value);\n}\n\n/** Clients (browsers) holding an outdated contract are told to reload their code. */\nfunction clientError(error: unknown): unknown {\n\tif (error instanceof ChordError && error.code === \"contract_mismatch\") {\n\t\treturn new ChordError(\"upgrade_required\", error.message, { cause: error });\n\t}\n\treturn error;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAgB,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAa,MAAM,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAgB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAc,aAAa,EAAE,OAAO,EAAE,gBAAgB,EAAgB,WAAW,EAAE,MAAM,WAAW,CAAC;AAwB5G,MAAM,cAAc,GAAG,GAAG,GAAG,IAAI,CAAC;AAClC,iEAAiE;AACjE,MAAM,eAAe,GAAG,CAAC,CAAC;AAoF1B,MAAM,WAAW,GAAG,CAAC,OAAe,EAAc,EAAE,CAAC,IAAI,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAE5F,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACX,MAAM,CAAa;IACnB,KAAK,CAAgC;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ourcesContent":["import { contractFromDescription, LOCAL_VARIANT, resolveHost } from \"./contract.ts\";\nimport { type Encoder, encoder } from \"./delta/index.ts\";\nimport { ChordError, invalid } from \"./errors.ts\";\nimport type { HostImpl } from \"./host.ts\";\nimport { type Link, Packed, unpack } from \"./link.ts\";\nimport { type CtxImpl, RefImpl, variantOf } from \"./object.ts\";\nimport type { RemoteBinding, RemoteChannel } from \"./remote.ts\";\nimport { assertValid } from \"./schema.ts\";\nimport type { Ctx, Readable, Shape, StateEvent } from \"./types.ts\";\nimport { type Frame, fromWireError, isFrame, PROTOCOL_VERSION, type RootRef, toWireError } from \"./wire.ts\";\n\nexport interface LinkOptions {\n\t/** Milliseconds between pings (default 15000). */\n\treadonly pingInterval?: number;\n\t/** Close the link when nothing arrived for this long (default 45000). Everything held through it is released. */\n\treadonly pingTimeout?: number;\n\t/**\n\t * Unacknowledged frame bytes (JSON text length) beyond which state frames wait for the peer (default 256 KiB). Only\n\t * applies when both ends acknowledge frames and the link reports sizes; `Infinity` never holds state back.\n\t */\n\treadonly window?: number;\n\t/**\n\t * Bytes of state ops that may wait for the peer on this link (default 4 windows). Beyond, the oldest waiting streams\n\t * are replaced by their current value (a reset), so memory stays bounded however long the peer stalls.\n\t */\n\treadonly pendingCap?: number;\n\t/**\n\t * The peer speaks another link protocol version (`peer`: undefined if it did not say): the link closes, and should\n\t * not be reconnected with the same code. A browser reloads its page, for instance.\n\t */\n\treadonly onProtocolMismatch?: (versions: { readonly local: number; readonly peer: number | undefined }) => void;\n}\n\nconst DEFAULT_WINDOW = 256 * 1024;\n/** The default cap of waiting state ops per link, in windows. */\nconst PENDING_WINDOWS = 4;\n\ntype StateFrame = Extract<Frame, { t: \"state\" }>;\n\n/**\n * How a waiting stream recovers when its ops must be dropped: the provider resends the current value as a reset at\n * flush; a relay (which has no value) asks downstream for one.\n */\ntype Overflow = { readonly resend: () => void } | { readonly resync: () => void };\n\n/**\n * What waits on a link. A unit slot is lazy: the shape and snapshots are built from the current values when it is sent.\n * A state slot keeps a snapshot, reset or error (`base`) and encoded ops to apply after it, in order (as they arrived;\n * the receiving decoder validates them), or, once `lazy`, only the promise of a reset built at flush.\n */\ntype Slot =\n\t| { readonly kind: \"unit\"; readonly hold: number; readonly flush: () => void }\n\t| {\n\t\t\treadonly kind: \"state\";\n\t\t\treadonly hold: number;\n\t\t\treadonly m: string;\n\t\t\tbase: StateFrame | undefined;\n\t\t\tops: (readonly unknown[])[];\n\t\t\tsize: number;\n\t\t\tlazy: boolean;\n\t\t\treadonly overflow: Overflow;\n\t };\n\nexport interface AcceptOptions<P = unknown> extends LinkOptions {\n\t/** The principal of whatever connects, from the app's authenticator. Every request on the link acts as it. */\n\treadonly principal: P;\n\t/**\n\t * What the peer is, decided here and never by its `hello`: `client` (default; a browser: no roots, no code versions,\n\t * not a reload participant, not addressable) or `host` (a child host; needs `name`).\n\t */\n\treadonly kind?: \"host\" | \"client\";\n\t/** A child host's name: its hello must match, and it is reachable `at` this name. */\n\treadonly name?: string;\n\t/** On `invalidatePrincipal`: a new principal keeps the link, `undefined` closes it (default: close). */\n\trestamp?(principal: P): P | undefined;\n\t/**\n\t * Calls the peer may have in progress on this link (default: no limit). Further ones never run: they are answered\n\t * at once with `unavailable` (reason `too_many_calls`), and the link stays open.\n\t */\n\treadonly maxCalls?: number;\n}\n\nexport interface Peer {\n\treadonly kind: \"host\" | \"client\";\n\t/** Configured (downstream hosts) or announced by the trusted parent (upstream). */\n\treadonly name: string | undefined;\n}\n\n/** A state member's stream to the consumer: its subscription and delta encoder. */\ninterface Feed {\n\tunsubscribe: () => void;\n\tencoder: Encoder;\n\t/** Events that arrived while a unit or reset was being built (replayed after it is sent). */\n\tbuffer: StateEvent<unknown>[] | undefined;\n}\n\n/** A hold the peer made on this host and serves locally. */\ninterface ServedLocal {\n\treadonly kind: \"local\";\n\treadonly id: number;\n\treadonly ref: RefImpl;\n\treadonly principal: unknown;\n\t/** The client connection it comes from (see `Frame` hold `origin`); undefined for a host's own holds. */\n\treadonly origin: string | undefined;\n\t/** The consumer wants state (hold without `state: false`, or `sub`). */\n\twantsState: boolean;\n\t/** The consumer had values before (re-hold): its first unit waits for the window like any other. */\n\treadonly again: boolean;\n\t/** A unit was sent. */\n\tunitSent: boolean;\n\t/** The members whose snapshot the consumer has, with their streams. */\n\treadonly feeds: Map<string, Feed>;\n}\n\n/** A hold the peer made on this host: served locally or relayed to another link. */\ntype Served = ServedLocal | { readonly kind: \"relay\"; readonly relay: RelayRef };\n\ntype Pending = { readonly resolve: (value: unknown) => void; readonly reject: (error: unknown) => void };\n\nconst unavailable = (message: string): ChordError => new ChordError(\"unavailable\", message);\n\n// ─── relay ───────────────────────────────────────────────────────────────────\n\n/**\n * A hold relayed from an origin link to a downstream link. It owns everything done through it: state and calls queued\n * while the route resolves, and the downstream twins once forwarded. `close` undoes all of it exactly once (cancels\n * calls downstream, drops what waits for the origin, releases the downstream hold, rejects waiters).\n */\nexport class RelayRef {\n\treadonly origin: Connection;\n\treadonly frame: Extract<Frame, { t: \"hold\" }>;\n\treadonly principal: unknown;\n\t/** The client connection the hold comes from (forwarded downstream); undefined for a host's own holds. */\n\treadonly originTag: string | undefined;\n\t/** The origin's authorization generation when the hold arrived; a revocation bumps it. */\n\treadonly generation: number;\n\tdown: Connection | undefined;\n\tdownId = 0;\n\tclosed = false;\n\t/** The origin wants state (forwarded as `state: false`, `sub`, `unsub`). */\n\tstateWanted: boolean;\n\t/** The members of the first unit, still to forward past the origin's window. */\n\turgent: Set<string> | undefined;\n\t#shaped = false;\n\t/** Members whose ops this relay dropped: downstream ops are ignored until their reset arrives. */\n\treadonly awaiting = new Set<string>();\n\treadonly calls = new Map<number, RelayCall>();\n\treadonly #waiters = new Set<Pending>();\n\n\tconstructor(\n\t\torigin: Connection,\n\t\tframe: Extract<Frame, { t: \"hold\" }>,\n\t\tprincipal: unknown,\n\t\toriginTag: string | undefined,\n\t) {\n\t\tthis.origin = origin;\n\t\tthis.frame = frame;\n\t\tthis.principal = principal;\n\t\tthis.originTag = originTag;\n\t\tthis.stateWanted = frame.state !== false;\n\t\tthis.generation = origin.generation;\n\t}\n\n\tget originId(): number {\n\t\treturn this.frame.id;\n\t}\n\n\tget client(): boolean {\n\t\treturn this.originTag !== undefined;\n\t}\n\n\t/** Still authorized as it was when it arrived. */\n\tget current(): boolean {\n\t\treturn !this.closed && this.origin.open && this.origin.generation === this.generation;\n\t}\n\n\t/** The downstream connection once the route resolved; rejects if the relay closes first. */\n\tready(): Promise<Connection> {\n\t\tif (this.closed) return Promise.reject(new ChordError(\"gone\", \"relayed hold closed\"));\n\t\tif (this.down !== undefined) return Promise.resolve(this.down);\n\t\treturn new Promise<Connection>((resolve, reject) => {\n\t\t\tthis.#waiters.add({ resolve: resolve as (value: unknown) => void, reject });\n\t\t});\n\t}\n\n\t/** Forwards the hold to `down`. */\n\topen(down: Connection): void {\n\t\tif (this.closed) return;\n\t\tthis.down = down;\n\t\tthis.downId = down.nextId();\n\t\tdown.relayedRefs.set(this.downId, this);\n\t\tconst { at, token, input } = this.frame;\n\t\tdown.send({\n\t\t\tt: \"hold\",\n\t\t\tid: this.downId,\n\t\t\tat,\n\t\t\ttoken,\n\t\t\tinput,\n\t\t\tprincipal: this.principal,\n\t\t\t...(this.originTag === undefined ? {} : { origin: this.originTag }),\n\t\t\t...(this.stateWanted ? {} : { state: false as const }),\n\t\t\t...(this.frame.again === true ? { again: true as const } : {}),\n\t\t});\n\t\tfor (const waiter of this.#waiters) waiter.resolve(down);\n\t\tthis.#waiters.clear();\n\t}\n\n\t/** The origin starts or stops the hold's state. */\n\twantState(wanted: boolean): void {\n\t\tif (this.closed || wanted === this.stateWanted) return;\n\t\tthis.stateWanted = wanted;\n\t\tif (!wanted) {\n\t\t\tthis.origin.dropHoldState(this.originId);\n\t\t\tthis.awaiting.clear();\n\t\t}\n\t\tthis.down?.send({ t: wanted ? \"sub\" : \"unsub\", hold: this.downId });\n\t}\n\n\t/**\n\t * The origin could not keep up and dropped what waited for member `m` (or asked for it again): ask downstream for a\n\t * reset, and ignore its ops until the reset arrives.\n\t */\n\tresync(m: string): void {\n\t\tif (this.closed) return;\n\t\tthis.awaiting.add(m);\n\t\tthis.down?.send({ t: \"resync\", hold: this.downId, m });\n\t}\n\n\t/** A shape from downstream: forwarded at once; the members of the first unit then skip the origin's window. */\n\tshape(frame: Extract<Frame, { t: \"shape\" }>): void {\n\t\tif (this.closed) return;\n\t\tif (!this.#shaped) {\n\t\t\tthis.#shaped = true;\n\t\t\tif (this.frame.again !== true) this.urgent = new Set(frame.state);\n\t\t}\n\t\tthis.origin.send({ ...frame, id: this.originId });\n\t}\n\n\t/** A state frame from downstream. */\n\tstate(frame: StateFrame): void {\n\t\tif (this.closed) return;\n\t\tconst m = frame.m;\n\t\tif (this.awaiting.has(m)) {\n\t\t\tif (frame.as === \"ops\") return;\n\t\t\tthis.awaiting.delete(m);\n\t\t}\n\t\tconst out: StateFrame = { ...frame, hold: this.originId };\n\t\tif (this.urgent?.delete(m) === true) {\n\t\t\tthis.origin.send(out);\n\t\t\treturn;\n\t\t}\n\t\tthis.origin.sendState(out, { resync: () => this.resync(m) });\n\t}\n\n\t/**\n\t * Closes the relay. `releaseDown`: the downstream hold is still there (origin released, disconnected, or was\n\t * revoked): cancel its calls and release it. `notify`: tell the origin the hold is gone.\n\t */\n\tclose(error: unknown, options: { readonly releaseDown: boolean; readonly notify: boolean }): void {\n\t\tif (this.closed) return;\n\t\tthis.closed = true;\n\t\tfor (const call of [...this.calls.values()]) call.cancel(error, options.releaseDown);\n\t\tthis.origin.dropHoldState(this.originId);\n\t\tif (this.origin.served.get(this.originId)?.kind === \"relay\") this.origin.served.delete(this.originId);\n\t\tif (this.down !== undefined) {\n\t\t\tthis.down.relayedRefs.delete(this.downId);\n\t\t\tif (options.releaseDown) this.down.send({ t: \"release\", id: this.downId });\n\t\t}\n\t\tfor (const waiter of this.#waiters) waiter.reject(error);\n\t\tthis.#waiters.clear();\n\t\tif (options.notify) this.origin.send({ t: \"gone\", id: this.originId, error: toWireError(error) });\n\t}\n}\n\n/** One relayed call: settles once, by result, cancellation or the relay closing; removes both mappings. */\nexport class RelayCall {\n\treadonly relay: RelayRef;\n\treadonly originId: number;\n\treadonly downId: number;\n\treadonly #pending: Pending;\n\t#settled = false;\n\n\tconstructor(relay: RelayRef, originId: number, downId: number, pending: Pending) {\n\t\tthis.relay = relay;\n\t\tthis.originId = originId;\n\t\tthis.downId = downId;\n\t\tthis.#pending = pending;\n\t\trelay.calls.set(originId, this);\n\t\trelay.down?.relayedCalls.set(downId, this);\n\t}\n\n\tfinish(error: unknown, value?: unknown): void {\n\t\tif (this.#settled) return;\n\t\tthis.#settled = true;\n\t\tthis.relay.calls.delete(this.originId);\n\t\tthis.relay.down?.relayedCalls.delete(this.downId);\n\t\tif (error === undefined) this.#pending.resolve(value);\n\t\telse this.#pending.reject(error);\n\t}\n\n\t/** Cancels downstream (when the downstream hold still exists) and settles with `error`. */\n\tcancel(error: unknown, forward: boolean): void {\n\t\tif (this.#settled) return;\n\t\tif (forward) this.relay.down?.send({ t: \"cancel\", id: this.downId });\n\t\tthis.finish(error);\n\t}\n}\n\n// ─── connection ──────────────────────────────────────────────────────────────\n\n/**\n * One end of a link on a host: consumer of remote references, provider for the peer's holds, and relay.\n *\n * State\n * -----\n *\n * A hold implies the state of its variant (unless it says `state: false`). The provider answers with a unit: the shape,\n * then a snapshot of each state member the consumer does not have yet (`shape.state` lists them), then the members'\n * ops and resets. A reload or a variant change sends another unit with the members that are new; members that left the\n * variant stop. The consumer applies a shape once its snapshots are here (`RemoteBinding`).\n *\n * Flow control\n * ------------\n *\n * Problem: state is pushed as fast as it changes, but a peer may read slowly (a phone behind a relay), and a relay may\n * hide that: Cloudflare forwards to browsers without backpressure. Everything sent then queues in front of the next\n * call result. Example: a browser opens three long transcripts (500 KiB of snapshots each) over a 5 Mbit/s path; a\n * result sent next waits 2.4 s, and the snapshot of a transcript the user already left is still sent in full.\n *\n * Solution: the peer acknowledges what it processed (`ack`, a cumulative frame count), and the sender counts the sizes\n * of the frames not yet acknowledged. While they exceed the window, state waits here in slots, flushed in creation\n * order as acknowledgements come:\n * - a member's stream has one slot: ops are appended (encoded batches of one stream may be concatenated, see\n * `encoder`), a snapshot, reset or error replaces it;\n * - a hold's unit has one slot, built lazily from the current values when it is sent, so a newer unit merges into it;\n * while it waits, the members it introduces have no stream yet.\n *\n * The first unit of a hold that is not a re-hold (`again`) is sent at once, past the window: a `get` waits for it, and\n * must not wait behind other holds' state. Results, shapes, gone, reload control and pings are sent at once too: they\n * are bounded by the requests the peer makes. Hence the one ordering exception of a link: while state waits, a result\n * can arrive before state changes made before it. Frames of one stream stay in order.\n *\n * Waiting ops are capped per link (`pendingCap`): beyond, the oldest streams are replaced by their current value (a\n * reset built at flush), or, on a relay, by a reset asked of the provider (`resync`), so memory stays bounded however\n * long the peer stalls. The window bounds what is unacknowledged when a frame is sent, so one frame (a large snapshot)\n * may exceed it. Both hellos must announce `acks`; with an older peer nothing is acknowledged and nothing waits. Links\n * that do not report sizes (IPC) never fill the window.\n */\nexport class Connection implements RemoteChannel {\n\treadonly host: HostImpl;\n\treadonly link: Link;\n\t/** `upstream`: the link to this host's parent. `downstream`: a link this host accepted. */\n\treadonly role: \"upstream\" | \"downstream\";\n\treadonly peer: Peer;\n\t/** A client connection's opaque id: holds that come over it (directly or relayed) carry it as their `origin`. */\n\treadonly originId: string | undefined;\n\tprincipal: unknown;\n\treadonly restamp: ((principal: unknown) => unknown | undefined) | undefined;\n\t/** Bumped when the stamped principal is revoked or re-stamped: relays from before are refused. */\n\tgeneration = 0;\n\t/** The code version a downstream host peer runs (from its hello, then from commits). */\n\tpeerCodeVersion: number | undefined;\n\t/** A downstream host peer is usable once it runs this host's current code version (see `HostImpl.peerHello`). */\n\tsynced: boolean;\n\t/** Code versions this child announced while behind this host (fenced): this host never ran them. */\n\treadonly fencedCodeVersions = new Set<number>();\n\t/** Roots of fenced code versions, by the code version of this host they were admitted in. */\n\treadonly #admitted = new Map<string, number>();\n\t#parentName: string | undefined;\n\treadonly #syncWaiters = new Set<Pending>();\n\t#nextId = 1;\n\t#lastSeen = Date.now();\n\t#pinger: ReturnType<typeof setInterval> | undefined;\n\treadonly #maxCalls: number;\n\t// flow control (see the class comment)\n\treadonly #window: number;\n\treadonly #pendingCap: number;\n\t/** Whether the peer acknowledges frames; until its hello is here, frames are counted in case it does. */\n\t#peerAcks: boolean | undefined;\n\t#sent = 0;\n\t#acked = 0;\n\t/** Sizes of the frames sent after the last acknowledged one. */\n\t#unacked: number[] = [];\n\t#unackedBytes = 0;\n\treadonly #pending = new Map<string, Slot>();\n\t/** Bytes of ops waiting in `#pending`. */\n\t#pendingBytes = 0;\n\t#received = 0;\n\t#ackTimer: ReturnType<typeof setTimeout> | undefined;\n\treadonly #onProtocolMismatch: LinkOptions[\"onProtocolMismatch\"];\n\t/** The peer speaks another protocol version: nothing it sends is processed any more. */\n\t#mismatched = false;\n\t// consumer side: what this host asked of the peer\n\treadonly remotes = new Map<number, RemoteBinding>();\n\treadonly calls = new Map<number, Pending>();\n\t// provider side: what the peer asked of this host\n\treadonly served = new Map<number, Served>();\n\treadonly incoming = new Map<number, AbortController>();\n\t// downstream side of relays: ids this host used on this link\n\treadonly relayedRefs = new Map<number, RelayRef>();\n\treadonly relayedCalls = new Map<number, RelayCall>();\n\t/** Reload votes awaited from this (child) peer. */\n\treadonly votes = new Map<number, Pending>();\n\n\tconstructor(\n\t\thost: HostImpl,\n\t\tlink: Link,\n\t\tconfig: {\n\t\t\treadonly role: \"upstream\" | \"downstream\";\n\t\t\treadonly principal: unknown;\n\t\t\treadonly peer: Peer;\n\t\t\treadonly originId?: string;\n\t\t\treadonly restamp?: (principal: unknown) => unknown | undefined;\n\t\t\treadonly maxCalls?: number;\n\t\t} & LinkOptions,\n\t) {\n\t\tthis.host = host;\n\t\tthis.link = link;\n\t\tthis.role = config.role;\n\t\tthis.peer = config.peer;\n\t\tthis.originId = config.originId;\n\t\tthis.principal = config.principal;\n\t\tthis.restamp = config.restamp;\n\t\tthis.synced = !(this.role === \"downstream\" && this.peer.kind === \"host\");\n\t\tthis.#window = config.window ?? DEFAULT_WINDOW;\n\t\tthis.#pendingCap = config.pendingCap ?? this.#window * PENDING_WINDOWS;\n\t\tthis.#maxCalls = config.maxCalls ?? Number.POSITIVE_INFINITY;\n\t\tthis.#onProtocolMismatch = config.onProtocolMismatch;\n\t\tlink.onClose((reason) => this.#closed(reason));\n\t\tlink.receive((frame) => this.#receive(frame));\n\t\tthis.send({\n\t\t\tt: \"hello\",\n\t\t\tprotocol: PROTOCOL_VERSION,\n\t\t\tname: host.name,\n\t\t\tkind: host.kind,\n\t\t\tcodeVersion: host.current.id,\n\t\t\tacks: true,\n\t\t});\n\t\tconst interval = config.pingInterval ?? 15_000;\n\t\tconst timeout = config.pingTimeout ?? 45_000;\n\t\t// A link that was already closed closed this connection above; it needs no keepalive.\n\t\tif (link.closed) return;\n\t\tlet n = 0;\n\t\tthis.#pinger = setInterval(() => {\n\t\t\tif (Date.now() - this.#lastSeen > timeout) link.close(\"ping timeout\");\n\t\t\telse this.send({ t: \"ping\", n: ++n });\n\t\t}, interval);\n\t\tthis.#pinger.unref?.();\n\t}\n\n\tget open(): boolean {\n\t\treturn !this.link.closed;\n\t}\n\n\t/** The peer's name: configured for downstream hosts, announced by the parent upstream. */\n\tget name(): string | undefined {\n\t\treturn this.role === \"upstream\" ? this.#parentName : this.peer.name;\n\t}\n\n\tsend(frame: Frame): void {\n\t\tconst size = this.link.send(frame) ?? 0;\n\t\tif (this.#peerAcks === false) return;\n\t\tthis.#sent++;\n\t\tthis.#unacked.push(size);\n\t\tthis.#unackedBytes += size;\n\t}\n\n\t/** Sends a state frame, or keeps it waiting (see the class comment). */\n\tsendState(frame: StateFrame, overflow: Overflow): void {\n\t\tconst key = stateKey(frame.hold, frame.m);\n\t\tlet slot = this.#pending.get(key);\n\t\tif (slot === undefined && !this.#full) {\n\t\t\tthis.send(frame);\n\t\t\treturn;\n\t\t}\n\t\tif (slot?.kind === \"unit\") return;\n\t\tif (slot === undefined) {\n\t\t\tslot = {\n\t\t\t\tkind: \"state\",\n\t\t\t\thold: frame.hold,\n\t\t\t\tm: frame.m,\n\t\t\t\tbase: undefined,\n\t\t\t\tops: [],\n\t\t\t\tsize: 0,\n\t\t\t\tlazy: false,\n\t\t\t\toverflow,\n\t\t\t};\n\t\t\tthis.#pending.set(key, slot);\n\t\t}\n\t\tif (frame.as !== \"ops\") {\n\t\t\tthis.#pendingBytes -= slot.size;\n\t\t\tslot.base = frame;\n\t\t\tslot.ops = [];\n\t\t\tslot.size = 0;\n\t\t\tslot.lazy = false;\n\t\t\treturn;\n\t\t}\n\t\t// A reset built at flush already covers these ops.\n\t\tif (slot.lazy) return;\n\t\tconst size = JSON.stringify(frame.ops).length;\n\t\tif (this.#pendingBytes + size > this.#pendingCap) this.#makeRoom(size, slot);\n\t\tif (slot.lazy || this.#pending.get(key) !== slot) return;\n\t\tfor (const op of frame.ops ?? []) slot.ops.push(op);\n\t\tslot.size += size;\n\t\tthis.#pendingBytes += size;\n\t}\n\n\t/** Replaces the oldest waiting streams by resets until `size` more bytes fit; `current` last, if needed. */\n\t#makeRoom(size: number, current: Extract<Slot, { kind: \"state\" }>): void {\n\t\tfor (const slot of [...this.#pending.values()]) {\n\t\t\tif (this.#pendingBytes + size <= this.#pendingCap) return;\n\t\t\tif (slot.kind === \"state\" && slot !== current && slot.size > 0) this.#drop(slot);\n\t\t}\n\t\tif (this.#pendingBytes + size > this.#pendingCap) this.#drop(current);\n\t}\n\n\t/** Drops what waits for a stream: a lazy reset replaces it (provider), or the relay asks downstream for one. */\n\t#drop(slot: Extract<Slot, { kind: \"state\" }>): void {\n\t\tthis.#pendingBytes -= slot.size;\n\t\tslot.base = undefined;\n\t\tslot.ops = [];\n\t\tslot.size = 0;\n\t\tif (\"resend\" in slot.overflow) {\n\t\t\tslot.lazy = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.#pending.delete(stateKey(slot.hold, slot.m));\n\t\tslot.overflow.resync();\n\t}\n\n\t/** Sends member `m` of a served hold again as a reset, through the window (`resync`). */\n\t#resetLater(hold: number, m: string, resend: () => void): void {\n\t\tconst key = stateKey(hold, m);\n\t\tlet slot = this.#pending.get(key);\n\t\tif (slot?.kind === \"unit\") return;\n\t\tif (slot === undefined) {\n\t\t\tslot = { kind: \"state\", hold, m, base: undefined, ops: [], size: 0, lazy: true, overflow: { resend } };\n\t\t\tthis.#pending.set(key, slot);\n\t\t} else {\n\t\t\tthis.#pendingBytes -= slot.size;\n\t\t\tslot.base = undefined;\n\t\t\tslot.ops = [];\n\t\t\tslot.size = 0;\n\t\t\tslot.lazy = true;\n\t\t}\n\t\tthis.#flush();\n\t}\n\n\t/** Queues a hold's lazy unit (a waiting one already covers this one), and sends what the window allows. */\n\t#queueUnit(hold: number, flush: () => void): void {\n\t\tconst key = unitKey(hold);\n\t\tif (!this.#pending.has(key)) this.#pending.set(key, { kind: \"unit\", hold, flush });\n\t\tthis.#flush();\n\t}\n\n\t/** Forgets what waits for a stream that ended. */\n\tdropState(hold: number, m: string): void {\n\t\tconst slot = this.#pending.get(stateKey(hold, m));\n\t\tif (slot?.kind !== \"state\") return;\n\t\tthis.#pendingBytes -= slot.size;\n\t\tthis.#pending.delete(stateKey(hold, m));\n\t}\n\n\t/** Forgets everything that waits for a hold (released, closed, or its state stopped). */\n\tdropHoldState(hold: number): void {\n\t\tfor (const [key, slot] of this.#pending) {\n\t\t\tif (slot.hold !== hold) continue;\n\t\t\tif (slot.kind === \"state\") this.#pendingBytes -= slot.size;\n\t\t\tthis.#pending.delete(key);\n\t\t}\n\t}\n\n\t/** What waits for the peer: slots and bytes of ops (for tests and diagnostics). */\n\tget waiting(): { readonly slots: number; readonly bytes: number } {\n\t\treturn { slots: this.#pending.size, bytes: this.#pendingBytes };\n\t}\n\n\tget #full(): boolean {\n\t\treturn this.#peerAcks === true && this.#unackedBytes >= this.#window;\n\t}\n\n\t#onAck(n: number): void {\n\t\tif (this.#peerAcks !== true || n < this.#acked || n > this.#sent) {\n\t\t\tthis.#violation(`ack ${n} outside ${this.#acked}..${this.#sent}`);\n\t\t\treturn;\n\t\t}\n\t\tfor (const size of this.#unacked.splice(0, n - this.#acked)) this.#unackedBytes -= size;\n\t\tthis.#acked = n;\n\t\tthis.#flush();\n\t}\n\n\t/** Sends waiting slots in creation order while the window allows. */\n\t#flush(): void {\n\t\tfor (const [key, slot] of this.#pending) {\n\t\t\tif (this.#full) return;\n\t\t\tthis.#pending.delete(key);\n\t\t\tif (slot.kind === \"unit\") {\n\t\t\t\tslot.flush();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.#pendingBytes -= slot.size;\n\t\t\tif (slot.lazy) {\n\t\t\t\tif (\"resend\" in slot.overflow) slot.overflow.resend();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (slot.base !== undefined) this.send(slot.base);\n\t\t\tif (slot.ops.length > 0) this.send({ t: \"state\", hold: slot.hold, m: slot.m, as: \"ops\", ops: slot.ops });\n\t\t}\n\t}\n\n\t/** Acknowledges once the frames that arrived together are processed: one ack per burst, not per frame. */\n\t#scheduleAck(): void {\n\t\tif (this.#peerAcks !== true || this.#ackTimer !== undefined || !this.open) return;\n\t\tthis.#ackTimer = setTimeout(() => {\n\t\t\tthis.#ackTimer = undefined;\n\t\t\tthis.link.send({ t: \"ack\", n: this.#received });\n\t\t}, 0);\n\t\tthis.#ackTimer.unref?.();\n\t}\n\n\tnextId(): number {\n\t\treturn this.#nextId++;\n\t}\n\n\t/** Resolves once the peer is usable (a host peer runs this host's code version); rejects if the link closes first. */\n\twhenSynced(): Promise<void> {\n\t\tif (!this.open) return Promise.reject(unavailable(`link to ${this.name ?? \"peer\"} closed`));\n\t\tif (this.synced) return Promise.resolve();\n\t\treturn new Promise<void>((resolve, reject) => this.#syncWaiters.add({ resolve: resolve as () => void, reject }));\n\t}\n\n\tmarkSynced(codeVersion: number): void {\n\t\tthis.peerCodeVersion = codeVersion;\n\t\tthis.synced = true;\n\t\tfor (const waiter of this.#syncWaiters) waiter.resolve(undefined);\n\t\tthis.#syncWaiters.clear();\n\t}\n\n\t/** Revokes the stamped principal: relays made under it close at once (also those still resolving a route). */\n\trevoke(next: unknown | undefined): void {\n\t\tthis.generation++;\n\t\tconst error = new ChordError(\"gone\", \"principal invalidated\");\n\t\tfor (const served of [...this.served.values()]) {\n\t\t\tif (served.kind === \"relay\") served.relay.close(error, { releaseDown: true, notify: true });\n\t\t}\n\t\tif (next === undefined) this.link.close(\"principal invalidated\");\n\t\telse this.principal = next;\n\t}\n\n\t/**\n\t * Stops talking to a peer of another protocol version: reports it and closes the link. The close reason tells the\n\t * peer this side's version (`protocol-version <n>`); a peer that noticed first told us the same way (`#closed`).\n\t */\n\t#protocolMismatch(peer: number | undefined, close = true): void {\n\t\tif (this.#mismatched) return;\n\t\tthis.#mismatched = true;\n\t\ttry {\n\t\t\tthis.#onProtocolMismatch?.({ local: PROTOCOL_VERSION, peer });\n\t\t} catch (error) {\n\t\t\tthis.host.report(error);\n\t\t}\n\t\tif (close) this.link.close(`protocol-version ${PROTOCOL_VERSION}`);\n\t}\n\n\t/** A protocol violation: the peer cannot be trusted with anything on this link any more. */\n\t#violation(reason: string): void {\n\t\tthis.host.report(new ChordError(\"invalid\", `link to ${this.name ?? \"peer\"}: ${reason}`, { reason: \"protocol\" }));\n\t\tthis.link.close(`protocol error: ${reason}`);\n\t}\n\n\t// ─── consumer side (RemoteChannel) ───\n\n\thold(binding: RemoteBinding, again: boolean): number {\n\t\tconst id = this.nextId();\n\t\tthis.remotes.set(id, binding);\n\t\tbinding.bound(this, id);\n\t\tconst principal = binding.principal;\n\t\tthis.send({\n\t\t\tt: \"hold\",\n\t\t\tid,\n\t\t\tat: binding.at,\n\t\t\ttoken: binding.contract.description,\n\t\t\tinput: binding.input,\n\t\t\t...(principal === undefined ? {} : { principal }),\n\t\t\t...(binding.stateOn ? {} : { state: false as const }),\n\t\t\t...(again ? { again: true as const } : {}),\n\t\t});\n\t\treturn id;\n\t}\n\n\trelease(id: number): void {\n\t\tthis.remotes.delete(id);\n\t\tthis.send({ t: \"release\", id });\n\t}\n\n\twantState(hold: number, wanted: boolean): void {\n\t\tif (this.remotes.has(hold)) this.send({ t: wanted ? \"sub\" : \"unsub\", hold });\n\t}\n\n\tcall(hold: number, member: string, args: unknown, root: RootRef | undefined, signal: AbortSignal): Promise<unknown> {\n\t\tconst id = this.nextId();\n\t\treturn new Promise<unknown>((resolve, reject) => {\n\t\t\tif (signal.aborted) {\n\t\t\t\treject(new ChordError(\"aborted\", \"call aborted\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst onAbort = (): void => {\n\t\t\t\tthis.calls.delete(id);\n\t\t\t\tthis.send({ t: \"cancel\", id });\n\t\t\t\treject(new ChordError(\"aborted\", \"call aborted\", { cause: signal.reason }));\n\t\t\t};\n\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tconst done = (): void => signal.removeEventListener(\"abort\", onAbort);\n\t\t\tthis.calls.set(id, {\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tdone();\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t\t// Clients never carry roots or code versions: the server starts roots for them.\n\t\t\tconst carried = root !== undefined && this.host.kind === \"host\";\n\t\t\tif (carried) this.host.rootSent(root.rootId, this);\n\t\t\tthis.send({ t: \"call\", id, hold, member, args, ...(carried ? { root } : {}) });\n\t\t});\n\t}\n\n\t// ─── receiving ───\n\n\t#receive(frame: unknown): void {\n\t\tif (this.#mismatched) return;\n\t\tthis.#lastSeen = Date.now();\n\t\tif (!isFrame(frame)) {\n\t\t\tthis.#violation(\"malformed frame\");\n\t\t\treturn;\n\t\t}\n\t\tif (frame.t === \"ack\") {\n\t\t\tthis.#onAck(frame.n);\n\t\t\treturn;\n\t\t}\n\t\tthis.#received++;\n\t\ttry {\n\t\t\tthis.#dispatch(frame);\n\t\t} catch (error) {\n\t\t\tthis.host.report(error);\n\t\t}\n\t\tthis.#scheduleAck();\n\t}\n\n\t#dispatch(frame: Frame): void {\n\t\tswitch (frame.t) {\n\t\t\tcase \"hello\":\n\t\t\t\tthis.#onHello(frame);\n\t\t\t\treturn;\n\t\t\tcase \"ping\":\n\t\t\t\tthis.send({ t: \"pong\", n: frame.n });\n\t\t\t\treturn;\n\t\t\tcase \"pong\":\n\t\t\tcase \"bye\":\n\t\t\tcase \"ack\":\n\t\t\t\treturn;\n\t\t\tcase \"hold\":\n\t\t\t\tthis.#onHold(frame);\n\t\t\t\treturn;\n\t\t\tcase \"release\":\n\t\t\t\tthis.#dropServed(frame.id, true);\n\t\t\t\treturn;\n\t\t\tcase \"call\":\n\t\t\t\tthis.#onCall(frame);\n\t\t\t\treturn;\n\t\t\tcase \"cancel\":\n\t\t\t\tthis.incoming.get(frame.id)?.abort(new ChordError(\"aborted\", \"cancelled by caller\"));\n\t\t\t\treturn;\n\t\t\tcase \"sub\":\n\t\t\tcase \"unsub\":\n\t\t\t\tthis.#onWantState(frame.hold, frame.t === \"sub\");\n\t\t\t\treturn;\n\t\t\tcase \"resync\":\n\t\t\t\tthis.#onResync(frame.hold, frame.m);\n\t\t\t\treturn;\n\t\t\tcase \"shape\":\n\t\t\tcase \"gone\":\n\t\t\t\tthis.#onHoldReply(frame);\n\t\t\t\treturn;\n\t\t\tcase \"result\":\n\t\t\t\tthis.#onResult(frame);\n\t\t\t\treturn;\n\t\t\tcase \"state\":\n\t\t\t\tthis.#onState(frame);\n\t\t\t\treturn;\n\t\t\tcase \"root_end\":\n\t\t\t\t// Honored only from the link the root came over (see HostImpl.foreignRootEnded).\n\t\t\t\tthis.#admitted.delete(frame.rootId);\n\t\t\t\tthis.host.foreignRootEnded(frame.rootId, this);\n\t\t\t\treturn;\n\t\t\tcase \"invalidate\":\n\t\t\tcase \"prepare\":\n\t\t\tcase \"commit\":\n\t\t\tcase \"abort\":\n\t\t\tcase \"retire\":\n\t\t\t\t// Control frames only from the parent.\n\t\t\t\tif (this.role !== \"upstream\") {\n\t\t\t\t\tthis.#violation(`${frame.t} from a child`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (frame.t === \"invalidate\") {\n\t\t\t\t\tthis.host.invalidatePrincipal(frame.pattern).catch((error: unknown) => this.host.report(error));\n\t\t\t\t} else if (frame.t === \"retire\") this.host.allowRetire(frame.codeVersion);\n\t\t\t\telse this.host.onReloadFrame(this, frame);\n\t\t\t\treturn;\n\t\t\tcase \"vote\": {\n\t\t\t\tif (this.role !== \"downstream\" || this.peer.kind !== \"host\") {\n\t\t\t\t\tthis.#violation(\"vote from a non-participant\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst vote = this.votes.get(frame.reload);\n\t\t\t\tthis.votes.delete(frame.reload);\n\t\t\t\tif (frame.error === undefined) vote?.resolve(frame.report);\n\t\t\t\telse vote?.reject(fromWireError(frame.error));\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The peer's hello must agree with what this side decided about it. A downstream host announces its code version:\n\t * the host either finds it in step or fences and reconciles it (never renumbers).\n\t */\n\t#onHello(frame: Extract<Frame, { t: \"hello\" }>): void {\n\t\tif ((frame.protocol ?? 1) !== PROTOCOL_VERSION) {\n\t\t\tthis.#protocolMismatch(frame.protocol ?? 1);\n\t\t\treturn;\n\t\t}\n\t\tif (this.#peerAcks === undefined) {\n\t\t\tthis.#peerAcks = frame.acks === true;\n\t\t\tif (!this.#peerAcks) {\n\t\t\t\tthis.#unacked = [];\n\t\t\t\tthis.#unackedBytes = 0;\n\t\t\t}\n\t\t}\n\t\tif (this.role === \"upstream\") {\n\t\t\tif (frame.kind !== \"host\") {\n\t\t\t\tthis.#violation(\"parent is not a host\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.#parentName ??= frame.name;\n\t\t\treturn;\n\t\t}\n\t\tif (frame.kind !== this.peer.kind || (this.peer.name !== undefined && frame.name !== this.peer.name)) {\n\t\t\tthis.#violation(\n\t\t\t\t`hello ${frame.kind} ${frame.name} does not match the accepted ${this.peer.kind} ${this.peer.name ?? \"\"}`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (this.peer.kind === \"host\") this.host.peerHello(this, frame.codeVersion);\n\t}\n\n\t/**\n\t * Principal stamping: a downstream link acts as the principal it was accepted with, whatever the frame says. Only\n\t * the parent may forward a principal (relayed requests); its own requests act as the principal given to `connect`.\n\t */\n\t#principalOf(frame: { readonly principal?: unknown }): unknown {\n\t\tif (this.role === \"downstream\") return this.principal;\n\t\treturn frame.principal ?? this.principal;\n\t}\n\n\t/**\n\t * The client connection a hold comes from: this link's own id for a client link (whatever the frame says), the id\n\t * the parent forwarded for a relayed hold, none for a host's own holds.\n\t */\n\t#originOf(frame: { readonly origin?: string }): string | undefined {\n\t\treturn this.role === \"downstream\" ? this.originId : frame.origin;\n\t}\n\n\t#onHold(frame: Extract<Frame, { t: \"hold\" }>): void {\n\t\tif (this.served.has(frame.id)) {\n\t\t\tthis.#violation(`duplicate hold id ${frame.id}`);\n\t\t\treturn;\n\t\t}\n\t\tconst principal = this.#principalOf(frame);\n\t\tconst origin = this.#originOf(frame);\n\t\tconst client = origin !== undefined;\n\t\tif (frame.at !== this.host.name) {\n\t\t\tif (this.role === \"upstream\") {\n\t\t\t\tthis.send({ t: \"gone\", id: frame.id, error: toWireError(unavailable(`${this.host.name} does not relay`)) });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst relay = new RelayRef(this, frame, principal, origin);\n\t\t\tthis.served.set(frame.id, { kind: \"relay\", relay });\n\t\t\tthis.host.relay(relay).catch((error: unknown) => relay.close(error, { releaseDown: true, notify: true }));\n\t\t\treturn;\n\t\t}\n\t\tlet ref: RefImpl;\n\t\ttry {\n\t\t\tconst token = contractFromDescription(frame.token);\n\t\t\tif (token.scope !== \"remote\") throw invalid(\"token\", `${token.name} is local; only remote types cross links`);\n\t\t\t// Addressed here, so the input must place it here (also by this host's contract, checked when acquiring).\n\t\t\tif (resolveHost(token.name, token.description.host!, frame.input) !== this.host.name)\n\t\t\t\tthrow invalid(\"placement\", `${token.name} with this input does not live on ${this.host.name}`);\n\t\t\tconst acquired = this.host.acquire(token, frame.input, { principal }, client ? \"client\" : \"connection\");\n\t\t\tif (!(acquired instanceof RefImpl)) throw unavailable(\"not a local reference\");\n\t\t\tref = acquired;\n\t\t} catch (error) {\n\t\t\tthis.send({ t: \"gone\", id: frame.id, error: toWireError(client ? clientError(error) : error) });\n\t\t\treturn;\n\t\t}\n\t\tconst served: ServedLocal = {\n\t\t\tkind: \"local\",\n\t\t\tid: frame.id,\n\t\t\tref,\n\t\t\tprincipal,\n\t\t\torigin,\n\t\t\twantsState: frame.state !== false,\n\t\t\tagain: frame.again === true,\n\t\t\tunitSent: false,\n\t\t\tfeeds: new Map(),\n\t\t};\n\t\tthis.served.set(frame.id, served);\n\t\tref.onShape(() => this.#unit(served));\n\t\tref.goneListeners.add((error) => {\n\t\t\tif (this.served.get(frame.id) !== served) return;\n\t\t\tthis.#dropServed(frame.id, false);\n\t\t\tthis.send({ t: \"gone\", id: frame.id, error: toWireError(error) });\n\t\t});\n\t\tif (ref.status === \"live\") this.#unit(served);\n\t}\n\n\t/** The state members of `shape` the consumer's contract knows. */\n\t#stateMembers(ref: RefImpl, shape: Shape): string[] {\n\t\treturn shape.members.filter((name) => ref.describe(shape.variant, name)?.kind === \"state\");\n\t}\n\n\t/**\n\t * The shape changed (live, reload, variant) or state was asked for: members that left lose their stream, and a unit\n\t * goes out with the shape and the members the consumer lacks. The first unit of a hold (not a re-hold) is urgent.\n\t */\n\t#unit(served: ServedLocal): void {\n\t\tif (this.served.get(served.id) !== served) return;\n\t\tconst shape = served.ref.shape;\n\t\tif (shape === undefined) return;\n\t\tconst members = new Set(served.wantsState ? this.#stateMembers(served.ref, shape) : []);\n\t\tfor (const [name, feed] of served.feeds) {\n\t\t\tif (members.has(name)) continue;\n\t\t\tfeed.unsubscribe();\n\t\t\tserved.feeds.delete(name);\n\t\t\tthis.dropState(served.id, name);\n\t\t}\n\t\tconst urgent = served.feeds.size === 0 && !(served.again && !served.unitSent);\n\t\tif (urgent) this.#sendUnit(served);\n\t\telse this.#queueUnit(served.id, () => this.#sendUnit(served));\n\t}\n\n\t/** Builds and sends a unit from the current shape and values. */\n\t#sendUnit(served: ServedLocal): void {\n\t\tthis.#pending.delete(unitKey(served.id));\n\t\tif (this.served.get(served.id) !== served) return;\n\t\tconst shape = served.ref.shape;\n\t\tif (shape === undefined) return;\n\t\tserved.unitSent = true;\n\t\tconst members = served.wantsState ? this.#stateMembers(served.ref, shape) : [];\n\t\tconst listed = members.filter((name) => !served.feeds.has(name));\n\t\tconst snaps: StateFrame[] = [];\n\t\tconst attached: (readonly [string, Feed])[] = [];\n\t\tfor (const name of listed) {\n\t\t\tconst attachment = this.#attach(served, name);\n\t\t\tif (attachment === undefined) continue;\n\t\t\tsnaps.push(attachment.frame);\n\t\t\tattached.push([name, attachment.feed]);\n\t\t}\n\t\tthis.send({\n\t\t\tt: \"shape\",\n\t\t\tid: served.id,\n\t\t\t...(shape.variant === undefined ? {} : { variant: shape.variant }),\n\t\t\tmembers: shape.members,\n\t\t\tcontract: shape.contract,\n\t\t\tstate: snaps.map((frame) => frame.m),\n\t\t});\n\t\tfor (const frame of snaps) this.send(frame);\n\t\tfor (const [name, feed] of attached) this.#replay(served, name, feed);\n\t}\n\n\t/**\n\t * Subscribes member `name` for the consumer: its snapshot (as a frame of type `as`), and a feed whose later events\n\t * wait in its buffer until the snapshot is sent (`#replay`). Undefined if the member is not readable state.\n\t */\n\t#attach(\n\t\tserved: ServedLocal,\n\t\tname: string,\n\t\tas: \"snap\" | \"reset\" = \"snap\",\n\t): { readonly frame: StateFrame; readonly feed: Feed } | undefined {\n\t\tconst readable = served.ref.member(name) as Readable<unknown> | undefined;\n\t\tif (readable === undefined || typeof readable.events !== \"function\") return undefined;\n\t\tconst feed: Feed = { unsubscribe: () => {}, encoder: encoder(), buffer: [] };\n\t\tlet first: StateEvent<unknown> | undefined;\n\t\tfeed.unsubscribe = readable.events((event) => {\n\t\t\tif (first === undefined) first = event;\n\t\t\telse if (feed.buffer !== undefined) feed.buffer.push(event);\n\t\t\telse this.#feedEvent(served, name, feed, event);\n\t\t});\n\t\tserved.feeds.set(name, feed);\n\t\treturn { frame: this.#snapshot(served, name, as, first?.value), feed };\n\t}\n\n\t/** Sends the events that arrived while the snapshot was built, now that it is sent. */\n\t#replay(served: ServedLocal, name: string, feed: Feed): void {\n\t\tconst buffered = feed.buffer ?? [];\n\t\tfeed.buffer = undefined;\n\t\tfor (const event of buffered) this.#feedEvent(served, name, feed, event);\n\t}\n\n\t/** A member's state frame for a snapshot or reset: validated against the schema the consumer is promised. */\n\t#snapshot(served: ServedLocal, name: string, as: \"snap\" | \"reset\", value: unknown): StateFrame {\n\t\ttry {\n\t\t\tvalidateSnapshot(served.ref, name, value);\n\t\t} catch (error) {\n\t\t\treturn { t: \"state\", hold: served.id, m: name, as: \"error\", error: toWireError(error) };\n\t\t}\n\t\treturn { t: \"state\", hold: served.id, m: name, as, ...(value === undefined ? {} : { value }) };\n\t}\n\n\t/** A later event of a member's stream: ops are encoded, a reset starts a new stream. */\n\t#feedEvent(served: ServedLocal, name: string, feed: Feed, event: StateEvent<unknown>): void {\n\t\tif (served.feeds.get(name) !== feed) return;\n\t\tconst overflow = { resend: () => this.#resend(served, name) };\n\t\tif (event.type === \"ops\") {\n\t\t\tthis.sendState(\n\t\t\t\t{ t: \"state\", hold: served.id, m: name, as: \"ops\", ops: feed.encoder.encode(event.ops) },\n\t\t\t\toverflow,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tfeed.encoder = encoder();\n\t\tthis.sendState(this.#snapshot(served, name, \"reset\", event.value), overflow);\n\t}\n\n\t/** Sends member `name` again, now, as a reset from its current value (a lazy slot is flushed, or `resync`). */\n\t#resend(served: ServedLocal, name: string): void {\n\t\tconst feed = served.feeds.get(name);\n\t\tif (feed === undefined || this.served.get(served.id) !== served) return;\n\t\tfeed.unsubscribe();\n\t\tserved.feeds.delete(name);\n\t\tconst attachment = this.#attach(served, name, \"reset\");\n\t\tif (attachment === undefined) return;\n\t\tthis.send(attachment.frame);\n\t\tthis.#replay(served, name, attachment.feed);\n\t}\n\n\t/** The consumer starts (`sub`) or stops (`unsub`) the state of a hold. */\n\t#onWantState(hold: number, wanted: boolean): void {\n\t\tconst served = this.served.get(hold);\n\t\tif (served === undefined) return;\n\t\tif (served.kind === \"relay\") {\n\t\t\tserved.relay.wantState(wanted);\n\t\t\treturn;\n\t\t}\n\t\tif (served.wantsState === wanted) return;\n\t\tserved.wantsState = wanted;\n\t\tif (wanted) {\n\t\t\tthis.#unit(served);\n\t\t\treturn;\n\t\t}\n\t\tfor (const feed of served.feeds.values()) feed.unsubscribe();\n\t\tserved.feeds.clear();\n\t\tthis.dropHoldState(hold);\n\t}\n\n\t/** The consumer (a relay that dropped ops) asks for member `m` again as a reset. */\n\t#onResync(hold: number, m: string): void {\n\t\tconst served = this.served.get(hold);\n\t\tif (served === undefined) return;\n\t\tif (served.kind === \"relay\") {\n\t\t\tserved.relay.resync(m);\n\t\t\treturn;\n\t\t}\n\t\tif (!served.feeds.has(m)) return;\n\t\tthis.#resetLater(hold, m, () => this.#resend(served, m));\n\t}\n\n\t/** Forgets a served hold: unsubscribes its feeds and releases it (locally or downstream). */\n\t#dropServed(id: number, release: boolean): void {\n\t\tconst served = this.served.get(id);\n\t\tif (served === undefined) return;\n\t\tthis.served.delete(id);\n\t\tif (served.kind === \"relay\") {\n\t\t\tserved.relay.close(new ChordError(\"released\", \"relayed hold released\"), {\n\t\t\t\treleaseDown: release,\n\t\t\t\tnotify: false,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tfor (const feed of served.feeds.values()) feed.unsubscribe();\n\t\tserved.feeds.clear();\n\t\tthis.dropHoldState(id);\n\t\tif (release) served.ref.release();\n\t}\n\n\t#onCall(frame: Extract<Frame, { t: \"call\" }>): void {\n\t\tif (this.incoming.has(frame.id)) {\n\t\t\tthis.#violation(`duplicate call id ${frame.id}`);\n\t\t\treturn;\n\t\t}\n\t\tif (this.incoming.size >= this.#maxCalls) {\n\t\t\tconst error = new ChordError(\n\t\t\t\t\"unavailable\",\n\t\t\t\t`Too many calls in progress on this connection (${this.#maxCalls}); wait for earlier ones to finish`,\n\t\t\t\t{ reason: \"too_many_calls\" },\n\t\t\t);\n\t\t\tthis.send({ t: \"result\", id: frame.id, error: toWireError(error) });\n\t\t\treturn;\n\t\t}\n\t\tconst served = this.served.get(frame.hold);\n\t\tif (served === undefined) {\n\t\t\tthis.send({ t: \"result\", id: frame.id, error: toWireError(new ChordError(\"gone\", \"unknown hold\")) });\n\t\t\treturn;\n\t\t}\n\t\tconst controller = new AbortController();\n\t\tthis.incoming.set(frame.id, controller);\n\t\t// Roots are honored from hosts only; a request without one (or from a client) starts one here.\n\t\tconst root = this.peer.kind === \"host\" ? this.#admitRoot(frame.root) : undefined;\n\t\tconst principal = served.kind === \"local\" ? served.principal : served.relay.principal;\n\t\tconst options = { principal, signal: controller.signal };\n\t\tconst run =\n\t\t\tserved.kind === \"local\"\n\t\t\t\t? (ctx: Ctx) => served.ref.object.call(served.ref, frame.member, unpack(frame.args), ctx as CtxImpl)\n\t\t\t\t: (ctx: Ctx) =>\n\t\t\t\t\t\trelayCall(\n\t\t\t\t\t\t\tserved.relay,\n\t\t\t\t\t\t\tframe,\n\t\t\t\t\t\t\t{ rootId: ctx.rootId, codeVersion: ctx.codeVersion },\n\t\t\t\t\t\t\t// The root's signal: a cancel from the origin and the root's code version retiring both reach it.\n\t\t\t\t\t\t\tctx.signal,\n\t\t\t\t\t\t\tthis.host,\n\t\t\t\t\t\t);\n\t\tconst result =\n\t\t\troot === undefined\n\t\t\t\t? this.host.root(run, options)\n\t\t\t\t: this.host.joinRoot(root.rootId, root.codeVersion, run, { ...options, from: this });\n\t\tresult\n\t\t\t.then(\n\t\t\t\t(value) => this.send({ t: \"result\", id: frame.id, value }),\n\t\t\t\t(error: unknown) => this.send({ t: \"result\", id: frame.id, error: toWireError(error) }),\n\t\t\t)\n\t\t\t.finally(() => this.incoming.delete(frame.id));\n\t}\n\n\t/**\n\t * A child that connected behind this host runs roots of a code version this host never had (it was fenced and is\n\t * being, or was, reconciled). Such a root is admitted in this host's current code version at its first call here,\n\t * and keeps that code version for its later calls (`superseded` once this host retired it). Other unknown code\n\t * versions stay `superseded`.\n\t */\n\t#admitRoot(root: RootRef | undefined): RootRef | undefined {\n\t\tif (root === undefined || this.role !== \"downstream\" || !this.fencedCodeVersions.has(root.codeVersion))\n\t\t\treturn root;\n\t\tif (this.host.hasCodeVersion(root.codeVersion)) return root;\n\t\tlet codeVersion = this.#admitted.get(root.rootId);\n\t\tif (codeVersion === undefined) {\n\t\t\tcodeVersion = this.host.current.id;\n\t\t\tthis.#admitted.set(root.rootId, codeVersion);\n\t\t}\n\t\treturn { rootId: root.rootId, codeVersion };\n\t}\n\n\t#onHoldReply(frame: Extract<Frame, { t: \"shape\" | \"gone\" }>): void {\n\t\tconst relay = this.relayedRefs.get(frame.id);\n\t\tif (relay !== undefined) {\n\t\t\tif (frame.t === \"gone\") relay.close(fromWireError(frame.error), { releaseDown: false, notify: true });\n\t\t\telse relay.shape(frame);\n\t\t\treturn;\n\t\t}\n\t\tconst binding = this.remotes.get(frame.id);\n\t\tif (binding === undefined) return;\n\t\tif (frame.t === \"gone\") {\n\t\t\tthis.remotes.delete(frame.id);\n\t\t\tbinding.gone(fromWireError(frame.error));\n\t\t\treturn;\n\t\t}\n\t\tbinding.shaped({ variant: frame.variant, members: frame.members, contract: frame.contract }, frame.state);\n\t}\n\n\t#onResult(frame: Extract<Frame, { t: \"result\" }>): void {\n\t\tconst relayed = this.relayedCalls.get(frame.id);\n\t\tif (relayed !== undefined) {\n\t\t\trelayed.finish(frame.error === undefined ? undefined : fromWireError(frame.error), frame.value);\n\t\t\treturn;\n\t\t}\n\t\tconst pending = this.calls.get(frame.id);\n\t\tthis.calls.delete(frame.id);\n\t\tif (frame.error !== undefined) {\n\t\t\tpending?.reject(fromWireError(frame.error));\n\t\t\treturn;\n\t\t}\n\t\tlet value: unknown;\n\t\ttry {\n\t\t\tvalue = unpack(frame.value);\n\t\t} catch (error) {\n\t\t\tpending?.reject(error);\n\t\t\treturn;\n\t\t}\n\t\tpending?.resolve(value);\n\t}\n\n\t#onState(frame: StateFrame): void {\n\t\tconst relay = this.relayedRefs.get(frame.hold);\n\t\tif (relay !== undefined) {\n\t\t\trelay.state(frame);\n\t\t\treturn;\n\t\t}\n\t\tconst binding = this.remotes.get(frame.hold);\n\t\tif (binding === undefined) return;\n\t\tif (!(frame.value instanceof Packed)) {\n\t\t\tbinding.state(frame.m, frame);\n\t\t\treturn;\n\t\t}\n\t\tlet value: unknown;\n\t\ttry {\n\t\t\tvalue = unpack(frame.value);\n\t\t} catch (error) {\n\t\t\tbinding.state(frame.m, { as: \"error\", error: toWireError(error) });\n\t\t\treturn;\n\t\t}\n\t\tbinding.state(frame.m, { ...frame, value });\n\t}\n\n\t// ─── lifetime ───\n\n\t#closed(reason: string): void {\n\t\tconst told = /^protocol-version (\\d+)$/.exec(reason);\n\t\tif (told !== null && Number(told[1]) !== PROTOCOL_VERSION) this.#protocolMismatch(Number(told[1]), false);\n\t\tif (this.#pinger !== undefined) clearInterval(this.#pinger);\n\t\tif (this.#ackTimer !== undefined) clearTimeout(this.#ackTimer);\n\t\tthis.#pending.clear();\n\t\tthis.#pendingBytes = 0;\n\t\tconst error = unavailable(`link to ${this.name ?? \"peer\"} closed: ${reason}`);\n\t\t// As origin: everything the peer held here, relayed or not, is released (downstream calls cancelled).\n\t\tfor (const id of [...this.served.keys()]) this.#dropServed(id, true);\n\t\tfor (const controller of this.incoming.values()) controller.abort(error);\n\t\tthis.incoming.clear();\n\t\tfor (const pending of this.calls.values()) pending.reject(error);\n\t\tthis.calls.clear();\n\t\tfor (const vote of this.votes.values()) vote.reject(error);\n\t\tthis.votes.clear();\n\t\tfor (const waiter of this.#syncWaiters) waiter.reject(error);\n\t\tthis.#syncWaiters.clear();\n\t\t// As downstream of relays: their origins lose the hold.\n\t\tfor (const relay of [...this.relayedRefs.values()]) relay.close(error, { releaseDown: false, notify: true });\n\t\tthis.relayedRefs.clear();\n\t\tthis.relayedCalls.clear();\n\t\tconst bindings = [...this.remotes.values()];\n\t\tthis.remotes.clear();\n\t\tfor (const binding of bindings) {\n\t\t\t// An upstream link may be replaced (reconnect); a downstream host that went away is gone.\n\t\t\tif (this.role === \"upstream\") binding.detached();\n\t\t\telse binding.gone(error);\n\t\t}\n\t\tthis.host.connectionClosed(this);\n\t}\n}\n\nconst stateKey = (hold: number, m: string): string => `s${hold}\\u0000${m}`;\nconst unitKey = (hold: number): string => `u${hold}`;\n\n/**\n * A call through a relay: waits for the route, then forwards with the root it runs in. It settles exactly once; a\n * cancel (or the origin going away) is forwarded downstream and removes both mappings.\n */\nasync function relayCall(\n\trelay: RelayRef,\n\tframe: Extract<Frame, { t: \"call\" }>,\n\troot: RootRef,\n\tsignal: AbortSignal,\n\thost: HostImpl,\n): Promise<unknown> {\n\tconst abortError = (): ChordError => new ChordError(\"aborted\", \"call cancelled\", { cause: signal.reason });\n\tif (signal.aborted) throw abortError();\n\tlet onAbort = (): void => {};\n\tlet onCancel = (): void => {};\n\tconst aborted = new Promise<never>((_, reject) => {\n\t\tonAbort = () => reject(abortError());\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n\taborted.catch(() => {});\n\ttry {\n\t\tconst down = await Promise.race([relay.ready(), aborted]);\n\t\tif (relay.closed) throw new ChordError(\"gone\", \"relayed hold closed\");\n\t\treturn await new Promise<unknown>((resolve, reject) => {\n\t\t\tconst call = new RelayCall(relay, frame.id, down.nextId(), { resolve, reject });\n\t\t\tonCancel = () => call.cancel(abortError(), true);\n\t\t\tsignal.addEventListener(\"abort\", onCancel, { once: true });\n\t\t\thost.rootSent(root.rootId, down);\n\t\t\tdown.send({ t: \"call\", id: call.downId, hold: relay.downId, member: frame.member, args: frame.args, root });\n\t\t});\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\tsignal.removeEventListener(\"abort\", onCancel);\n\t}\n}\n\n/**\n * Validates a snapshot against the schema the consumer is promised: the provider's own schema for a direct binding,\n * the consumer's contract for one through an `accepts` adapter (the adapter's view is what the consumer gets).\n */\nfunction validateSnapshot(ref: RefImpl, member: string, value: unknown): void {\n\tif (value === undefined) return;\n\tconst installed = ref.object.currentInstalled();\n\tif (installed === undefined) return;\n\tconst view = ref.currentView();\n\tconst variant = view === undefined ? variantOf(installed.implementation) : variantOf(view);\n\tconst description =\n\t\tview !== undefined && view !== installed.implementation\n\t\t\t? ref.contract.description.variants[variant ?? LOCAL_VARIANT]?.[member]\n\t\t\t: installed.service.contract.description.variants[variantOf(installed.implementation) ?? LOCAL_VARIANT]?.[\n\t\t\t\t\tmember\n\t\t\t\t];\n\tif (description?.kind === \"state\") assertValid(\"state\", `${ref.address}.${member}`, description.schema, value);\n}\n\n/** Clients (browsers) holding an outdated contract are told to reload their code. */\nfunction clientError(error: unknown): unknown {\n\tif (error instanceof ChordError && error.code === \"contract_mismatch\") {\n\t\treturn new ChordError(\"upgrade_required\", error.message, { cause: error });\n\t}\n\treturn error;\n}\n"]}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SpanOptions, type TelemetrySpan } from "@earendil-works/pi-telemetry";
|
|
1
2
|
/** Typed identity for one value carried by a {@link Context}. */
|
|
2
3
|
export interface ContextKey<T> {
|
|
3
4
|
readonly token: symbol;
|
|
@@ -7,6 +8,7 @@ export interface ContextKey<T> {
|
|
|
7
8
|
/** Immutable invocation-scoped values passed explicitly through operations. */
|
|
8
9
|
export interface Context {
|
|
9
10
|
readonly abortSignal: AbortSignal | undefined;
|
|
11
|
+
readonly telemetry: TelemetrySpan;
|
|
10
12
|
value<T>(key: ContextKey<T>): T | undefined;
|
|
11
13
|
toString(): string;
|
|
12
14
|
}
|
|
@@ -15,6 +17,12 @@ export declare const TODO_CONTEXT: Context;
|
|
|
15
17
|
export declare function createContextKey<T>(description: string): ContextKey<T>;
|
|
16
18
|
/** Derive a context containing one additional or replaced value. */
|
|
17
19
|
export declare function withContextValue<T>(key: ContextKey<T>, value: T, parent: Context): Context;
|
|
20
|
+
/** Derive an explicit telemetry parent without changing cancellation or application values. */
|
|
21
|
+
export declare function withTelemetry<T extends TelemetrySpan>(telemetry: T, context: Context): Context & {
|
|
22
|
+
readonly telemetry: T;
|
|
23
|
+
};
|
|
24
|
+
/** Run a child span with a derived context whose telemetry member is that span. */
|
|
25
|
+
export declare function traceIn<T>(context: Context, options: SpanOptions, fn: (context: Context) => T | Promise<T>): Promise<T>;
|
|
18
26
|
/**
|
|
19
27
|
* Derive a context cancelled by either the parent signal or the supplied signal.
|
|
20
28
|
* The parent context remains unchanged.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,WAAW,UAAU,CAAC,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iGAAiG;IACjG,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;CACrC;AAED,+EAA+E;AAC/E,MAAM,WAAW,OAAO;IACvB,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC;IAC9C,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC5C,QAAQ,IAAI,MAAM,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,WAA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CAAC,CAAC,CAAC,CAEZ;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAI9E;AAED,6GAA6G;AAC7G,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE5D;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG;IAC7C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C,CAMA;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAkBrF"}
|
package/dist/context/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import { NOOP_TELEMETRY_CONTEXT } from "@earendil-works/pi-telemetry";
|
|
1
2
|
const ABORT_SIGNAL_CONTEXT_KEY = Object.freeze({
|
|
2
3
|
token: Symbol("chord.abortSignal"),
|
|
3
4
|
});
|
|
5
|
+
const TELEMETRY_CONTEXT_KEY = Object.freeze({
|
|
6
|
+
token: Symbol("chord.telemetry"),
|
|
7
|
+
});
|
|
4
8
|
class BaseContext {
|
|
5
9
|
get abortSignal() {
|
|
6
10
|
return this.value(ABORT_SIGNAL_CONTEXT_KEY);
|
|
7
11
|
}
|
|
12
|
+
get telemetry() {
|
|
13
|
+
return this.value(TELEMETRY_CONTEXT_KEY) ?? NOOP_TELEMETRY_CONTEXT;
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
16
|
class EmptyContext extends BaseContext {
|
|
10
17
|
#name;
|
|
@@ -47,6 +54,14 @@ export function createContextKey(description) {
|
|
|
47
54
|
export function withContextValue(key, value, parent) {
|
|
48
55
|
return new ContextValue(parent, key, value);
|
|
49
56
|
}
|
|
57
|
+
/** Derive an explicit telemetry parent without changing cancellation or application values. */
|
|
58
|
+
export function withTelemetry(telemetry, context) {
|
|
59
|
+
return withContextValue(TELEMETRY_CONTEXT_KEY, telemetry, context);
|
|
60
|
+
}
|
|
61
|
+
/** Run a child span with a derived context whose telemetry member is that span. */
|
|
62
|
+
export function traceIn(context, options, fn) {
|
|
63
|
+
return context.telemetry.startSpan(options, (span) => fn(withTelemetry(span, context)));
|
|
64
|
+
}
|
|
50
65
|
/**
|
|
51
66
|
* Derive a context cancelled by either the parent signal or the supplied signal.
|
|
52
67
|
* The parent context remains unchanged.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAwC,MAAM,8BAA8B,CAAC;AAiB5G,MAAM,wBAAwB,GAAwC,MAAM,CAAC,MAAM,CAAC;IACnF,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC;CAClC,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAA8B,MAAM,CAAC,MAAM,CAAC;IACtE,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC;CAChC,CAAC,CAAC;AAEH,MAAe,WAAW;IAIzB,IAAI,WAAW;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,IAAI,sBAAsB,CAAC;IACpE,CAAC;CACD;AAED,MAAM,YAAa,SAAQ,WAAW;IAC5B,KAAK,CAAS;IAEvB,YAAY,IAAY;QACvB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAI,IAAmB;QA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CAAC,WAAW,CAAC;IACnC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IACzC,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,OAAO,GAAG,GAAS,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,KAAK,OAAO,CAAC,IAAI,CAChB,CAAC,KAAK,EAAE,EAAE;YACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7C,OAAO,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;YAClB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7C,MAAM,CAAC,KAAK,CAAC,CAAC;QACf,CAAC,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,MAAmB;IACtC,MAAM,MAAM,GAAY,MAAM,CAAC,MAAM,CAAC;IACtC,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACvG,CAAC","sourcesContent":["import { NOOP_TELEMETRY_CONTEXT, type SpanOptions, type TelemetrySpan } from \"@earendil-works/pi-telemetry\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\treadonly telemetry: TelemetrySpan;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nconst ABORT_SIGNAL_CONTEXT_KEY: ContextKey<AbortSignal | undefined> = Object.freeze({\n\ttoken: Symbol(\"chord.abortSignal\"),\n});\n\nconst TELEMETRY_CONTEXT_KEY: ContextKey<TelemetrySpan> = Object.freeze({\n\ttoken: Symbol(\"chord.telemetry\"),\n});\n\nabstract class BaseContext implements Context {\n\tabstract value<T>(key: ContextKey<T>): T | undefined;\n\tabstract toString(): string;\n\n\tget abortSignal(): AbortSignal | undefined {\n\t\treturn this.value(ABORT_SIGNAL_CONTEXT_KEY);\n\t}\n\n\tget telemetry(): TelemetrySpan {\n\t\treturn this.value(TELEMETRY_CONTEXT_KEY) ?? NOOP_TELEMETRY_CONTEXT;\n\t}\n}\n\nclass EmptyContext extends BaseContext {\n\treadonly #name: string;\n\n\tconstructor(name: string) {\n\t\tsuper();\n\t\tthis.#name = name;\n\t}\n\n\tvalue<T>(_key: ContextKey<T>): T | undefined {\n\t\treturn undefined;\n\t}\n\n\ttoString(): string {\n\t\treturn this.#name;\n\t}\n}\n\nclass ContextValue<T> extends BaseContext {\n\treadonly #parent: Context;\n\treadonly #key: ContextKey<T>;\n\treadonly #value: T;\n\n\tconstructor(parent: Context, key: ContextKey<T>, value: T) {\n\t\tsuper();\n\t\tthis.#parent = parent;\n\t\tthis.#key = key;\n\t\tthis.#value = value;\n\t}\n\n\tvalue<Value>(key: ContextKey<Value>): Value | undefined {\n\t\tif (key.token === this.#key.token) return this.#value as unknown as Value;\n\t\treturn this.#parent.value(key);\n\t}\n\n\ttoString(): string {\n\t\treturn `${this.#parent}.WithValue(${this.#key.token.description ?? \"anonymous\"})`;\n\t}\n}\n\nexport const BACKGROUND_CONTEXT: Context = new EmptyContext(\"[Context BACKGROUND_CONTEXT]\");\nexport const TODO_CONTEXT: Context = new EmptyContext(\"[Context TODO_CONTEXT]\");\n\nexport function createContextKey<T>(description: string): ContextKey<T> {\n\treturn Object.freeze({ token: Symbol(description) });\n}\n\n/** Derive a context containing one additional or replaced value. */\nexport function withContextValue<T>(key: ContextKey<T>, value: T, parent: Context): Context {\n\treturn new ContextValue(parent, key, value);\n}\n\n/** Derive an explicit telemetry parent without changing cancellation or application values. */\nexport function withTelemetry<T extends TelemetrySpan>(\n\ttelemetry: T,\n\tcontext: Context,\n): Context & { readonly telemetry: T } {\n\treturn withContextValue(TELEMETRY_CONTEXT_KEY, telemetry, context) as Context & { readonly telemetry: T };\n}\n\n/** Run a child span with a derived context whose telemetry member is that span. */\nexport function traceIn<T>(\n\tcontext: Context,\n\toptions: SpanOptions,\n\tfn: (context: Context) => T | Promise<T>,\n): Promise<T> {\n\treturn context.telemetry.startSpan(options, (span) => fn(withTelemetry(span, context)));\n}\n\n/**\n * Derive a context cancelled by either the parent signal or the supplied signal.\n * The parent context remains unchanged.\n */\nexport function withAbortSignal(signal: AbortSignal, context: Context): Context {\n\tconst parentSignal = context.abortSignal;\n\tconst combined = parentSignal === undefined ? signal : AbortSignal.any([parentSignal, signal]);\n\treturn withContextValue(ABORT_SIGNAL_CONTEXT_KEY, combined, context);\n}\n\n/** Derive a context retaining all values except caller cancellation. Intended for mandatory cleanup only. */\nexport function withoutAbortSignal(context: Context): Context {\n\treturn withContextValue(ABORT_SIGNAL_CONTEXT_KEY, undefined, context);\n}\n\n/** Derive an independently cancellable child context. */\nexport function withCancel(context: Context): {\n\treadonly context: Context;\n\treadonly cancel: (reason?: unknown) => void;\n} {\n\tconst controller = new AbortController();\n\treturn {\n\t\tcontext: withAbortSignal(controller.signal, context),\n\t\tcancel: (reason?: unknown) => controller.abort(reason),\n\t};\n}\n\n/**\n * Observe a promise until it settles or the invocation is cancelled.\n * Cancellation rejects only this waiter; it does not cancel the underlying promise.\n */\nexport function awaitWithContext<T>(promise: Promise<T>, context: Context): Promise<T> {\n\tconst signal = context.abortSignal;\n\tif (signal === undefined) return promise;\n\tif (signal.aborted) return Promise.reject(abortError(signal));\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst onAbort = (): void => reject(abortError(signal));\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid promise.then(\n\t\t\t(value) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\treject(error);\n\t\t\t},\n\t\t);\n\t});\n}\n\nfunction abortError(signal: AbortSignal): Error {\n\tconst reason: unknown = signal.reason;\n\treturn reason instanceof Error ? reason : new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"]}
|