@earendil-works/chord 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +14 -13
  3. package/dist/cell.d.ts +30 -9
  4. package/dist/cell.d.ts.map +1 -1
  5. package/dist/cell.js +52 -12
  6. package/dist/cell.js.map +1 -1
  7. package/dist/cluster.d.ts +4 -3
  8. package/dist/cluster.d.ts.map +1 -1
  9. package/dist/cluster.js +58 -42
  10. package/dist/cluster.js.map +1 -1
  11. package/dist/connection.d.ts +171 -58
  12. package/dist/connection.d.ts.map +1 -1
  13. package/dist/connection.js +676 -217
  14. package/dist/connection.js.map +1 -1
  15. package/dist/contract.d.ts +120 -45
  16. package/dist/contract.d.ts.map +1 -1
  17. package/dist/contract.js +104 -15
  18. package/dist/contract.js.map +1 -1
  19. package/dist/declare.d.ts +11 -48
  20. package/dist/declare.d.ts.map +1 -1
  21. package/dist/declare.js +1 -21
  22. package/dist/declare.js.map +1 -1
  23. package/dist/delta/index.d.ts +2 -1
  24. package/dist/delta/index.d.ts.map +1 -1
  25. package/dist/delta/index.js +4 -0
  26. package/dist/delta/index.js.map +1 -1
  27. package/dist/errors.d.ts +4 -3
  28. package/dist/errors.d.ts.map +1 -1
  29. package/dist/errors.js +15 -0
  30. package/dist/errors.js.map +1 -1
  31. package/dist/host.d.ts +214 -120
  32. package/dist/host.d.ts.map +1 -1
  33. package/dist/host.js +446 -241
  34. package/dist/host.js.map +1 -1
  35. package/dist/index.d.ts +8 -8
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +4 -4
  38. package/dist/index.js.map +1 -1
  39. package/dist/link.d.ts +47 -12
  40. package/dist/link.d.ts.map +1 -1
  41. package/dist/link.js +200 -14
  42. package/dist/link.js.map +1 -1
  43. package/dist/loader.d.ts.map +1 -1
  44. package/dist/loader.js +7 -2
  45. package/dist/loader.js.map +1 -1
  46. package/dist/manager.d.ts.map +1 -1
  47. package/dist/manager.js +35 -9
  48. package/dist/manager.js.map +1 -1
  49. package/dist/object.d.ts +438 -0
  50. package/dist/object.d.ts.map +1 -0
  51. package/dist/{record.js → object.js} +614 -335
  52. package/dist/object.js.map +1 -0
  53. package/dist/output.d.ts +85 -0
  54. package/dist/output.d.ts.map +1 -0
  55. package/dist/output.js +350 -0
  56. package/dist/output.js.map +1 -0
  57. package/dist/registry.d.ts +3 -3
  58. package/dist/registry.d.ts.map +1 -1
  59. package/dist/registry.js +1 -1
  60. package/dist/registry.js.map +1 -1
  61. package/dist/reload.d.ts +35 -27
  62. package/dist/reload.d.ts.map +1 -1
  63. package/dist/reload.js +256 -192
  64. package/dist/reload.js.map +1 -1
  65. package/dist/remote.d.ts +130 -35
  66. package/dist/remote.d.ts.map +1 -1
  67. package/dist/remote.js +493 -189
  68. package/dist/remote.js.map +1 -1
  69. package/dist/types.d.ts +39 -28
  70. package/dist/types.d.ts.map +1 -1
  71. package/dist/types.js.map +1 -1
  72. package/dist/websocket.d.ts +4 -5
  73. package/dist/websocket.d.ts.map +1 -1
  74. package/dist/websocket.js +3 -2
  75. package/dist/websocket.js.map +1 -1
  76. package/dist/wire.d.ts +210 -129
  77. package/dist/wire.d.ts.map +1 -1
  78. package/dist/wire.js +108 -55
  79. package/dist/wire.js.map +1 -1
  80. package/docs/guide.md +267 -203
  81. package/docs/spec.md +141 -114
  82. package/docs/tutorial.md +257 -235
  83. package/package.json +6 -1
  84. package/dist/record.d.ts +0 -320
  85. package/dist/record.d.ts.map +0 -1
  86. package/dist/record.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAgB,OAAO,EAAe,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC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ent":["import { Value } from \"typebox/value\";\nimport type { AnyContract } from \"./contract.ts\";\nimport { applyImmutable, type Decoder, decoder, type WireOp } from \"./delta/index.ts\";\nimport { ChordError } from \"./errors.ts\";\nimport {\n\tCtxImpl,\n\tHANDLE_BASE,\n\ttype Hold,\n\ttype HoldOwner,\n\tholdsByProxy,\n\tnotifyStatus,\n\traceSignal,\n\ttype StatusListener,\n} from \"./record.ts\";\nimport type { Ctx, HandleStatus, Principal, Readable, Shape, StateEvent } from \"./types.ts\";\nimport { fromWireError, type RootRef, type WireError } from \"./wire.ts\";\n\nconst noop = (): void => {};\n\nexport interface StateSink {\n\tsnap?: unknown;\n\treset?: unknown;\n\tops?: readonly WireOp[];\n\terror?: WireError;\n}\n\n/** What a remote handle needs from the link it is bound to (implemented by Connection). */\nexport interface RemoteChannel {\n\thold(handle: RemoteHandle): number;\n\trelease(id: number): void;\n\tcall(hold: number, member: string, args: unknown, root: RootRef | undefined, signal: AbortSignal): Promise<unknown>;\n\tsub(hold: number, member: string, sink: (frame: StateSink) => void): number;\n\tunsub(id: number): void;\n}\n\n/** What a remote handle needs from its host. */\nexport interface RemoteHost {\n\treadonly inFactory: number;\n\treport(error: unknown): void;\n\troot<T>(fn: (ctx: Ctx) => T | Promise<T>, options?: { signal?: AbortSignal }): Promise<T>;\n\tforgetRemote(handle: RemoteHandle): void;\n}\n\n/**\n * A state member of a remote handle: hydrated while subscribed (snapshot, then decoded ops); `undefined` before.\n * Re-subscribing after a reconnect delivers the new snapshot as a reset.\n */\nclass RemoteReadable implements Readable<unknown> {\n\treadonly #handle: RemoteHandle;\n\treadonly #name: string;\n\treadonly #values = new Set<(value: unknown) => void>();\n\treadonly #events = new Set<(event: StateEvent<unknown>) => void>();\n\t#sub: { readonly channel: RemoteChannel; readonly id: number } | undefined;\n\t#decoder: Decoder = decoder();\n\t#value: unknown;\n\n\tconstructor(handle: RemoteHandle, name: string) {\n\t\tthis.#handle = handle;\n\t\tthis.#name = name;\n\t}\n\n\tget value(): unknown {\n\t\treturn this.#value;\n\t}\n\n\tsubscribe(listener: (value: unknown) => void): () => void {\n\t\tthis.#values.add(listener);\n\t\tthis.#safe(() => listener(this.#value));\n\t\tthis.bind();\n\t\treturn () => this.#remove(this.#values, listener);\n\t}\n\n\tevents(listener: (event: StateEvent<unknown>) => void): () => void {\n\t\tthis.#events.add(listener);\n\t\tthis.#safe(() => listener({ type: \"snap\", value: this.#value }));\n\t\tthis.bind();\n\t\treturn () => this.#remove(this.#events, listener);\n\t}\n\n\t/** Subscribes upstream while someone listens and the handle is bound; drops a subscription on an old link. */\n\tbind(): void {\n\t\tconst listening = this.#values.size + this.#events.size > 0;\n\t\t// Nobody listens: the value would go stale, so forget it. The next subscriber sees `undefined`, then the snapshot.\n\t\tif (!listening) this.#value = undefined;\n\t\tconst binding = listening ? this.#handle.binding : undefined;\n\t\tif (binding !== undefined && this.#sub?.channel === binding.channel) return;\n\t\tif (this.#sub !== undefined) {\n\t\t\tif (this.#sub.channel !== binding?.channel || binding === undefined) this.#sub.channel.unsub(this.#sub.id);\n\t\t\tthis.#sub = undefined;\n\t\t}\n\t\tif (binding === undefined) return;\n\t\tconst channel = binding.channel;\n\t\tthis.#decoder = decoder();\n\t\tconst id = channel.sub(binding.id, this.#name, (frame) => this.#receive(frame));\n\t\tthis.#sub = { channel, id };\n\t}\n\n\t/** The link is gone: keep the last value, resubscribe on the next binding. */\n\tdetach(): void {\n\t\tthis.#sub = undefined;\n\t}\n\n\tstop(): void {\n\t\tthis.#values.clear();\n\t\tthis.#events.clear();\n\t\tthis.bind();\n\t}\n\n\t#receive(frame: StateSink): void {\n\t\tif (frame.error !== undefined) {\n\t\t\tthis.#handle.host.report(fromWireError(frame.error));\n\t\t\treturn;\n\t\t}\n\t\tlet event: StateEvent<unknown>;\n\t\tif (frame.ops === undefined && !(\"snap\" in frame) && !(\"reset\" in frame)) return;\n\t\tif (frame.ops !== undefined) {\n\t\t\tconst ops = this.#decoder.decode(frame.ops);\n\t\t\tthis.#value = applyImmutable(this.#value, ops);\n\t\t\tevent = { type: \"ops\", ops, value: this.#value };\n\t\t} else {\n\t\t\t// Listeners already saw a snapshot (`undefined` or an older value), so every upstream snapshot is a reset.\n\t\t\tthis.#decoder = decoder();\n\t\t\tthis.#value = \"snap\" in frame ? frame.snap : frame.reset;\n\t\t\tevent = { type: \"reset\", value: this.#value };\n\t\t}\n\t\tfor (const listener of [...this.#events]) this.#safe(() => listener(event));\n\t\tfor (const listener of [...this.#values]) this.#safe(() => listener(this.#value));\n\t}\n\n\t#remove<T>(set: Set<T>, listener: T): void {\n\t\tset.delete(listener);\n\t\tthis.bind();\n\t}\n\n\t#safe(fn: () => void): void {\n\t\ttry {\n\t\t\tfn();\n\t\t} catch (error) {\n\t\t\tthis.#handle.host.report(error);\n\t\t}\n\t}\n}\n\n/** A hold on an object on another host, bound to a link. Late-bound like a local handle. */\nexport class RemoteHandle implements Hold {\n\treadonly record = undefined;\n\treadonly host: RemoteHost;\n\treadonly contract: AnyContract;\n\treadonly at: string;\n\treadonly input: unknown;\n\t/** Forwarded principal (omitted for the host's own principal). */\n\treadonly principal: Principal | undefined;\n\treadonly owner: HoldOwner;\n\treadonly address: string;\n\treadonly proxy: object;\n\treadonly ready: Promise<void>;\n\tstatus: HandleStatus = \"loading\";\n\terror: unknown;\n\tshape: Shape | undefined;\n\tbinding: { readonly channel: RemoteChannel; readonly id: number } | undefined;\n\treadonly shapeListeners = new Set<(shape: Shape) => void>();\n\treadonly #readables = new Map<string, RemoteReadable>();\n\treadonly #callers = new Map<string, (args: unknown, ctx?: Ctx) => Promise<unknown>>();\n\t#settleReady: { resolve: () => void; reject: (error: unknown) => void } | undefined;\n\t#live: { promise: Promise<void>; resolve: () => void; reject: (error: unknown) => void };\n\n\tconstructor(\n\t\thost: RemoteHost,\n\t\tfields: {\n\t\t\tcontract: AnyContract;\n\t\t\tat: string;\n\t\t\tinput: unknown;\n\t\t\tprincipal: Principal | undefined;\n\t\t\towner: HoldOwner;\n\t\t\taddress: string;\n\t\t},\n\t) {\n\t\tthis.host = host;\n\t\tthis.contract = fields.contract;\n\t\tthis.at = fields.at;\n\t\tthis.input = fields.input;\n\t\tthis.principal = fields.principal;\n\t\tthis.owner = fields.owner;\n\t\tthis.address = fields.address;\n\t\tthis.ready = new Promise<void>((resolve, reject) => {\n\t\t\tthis.#settleReady = { resolve, reject };\n\t\t});\n\t\tthis.ready.catch(noop);\n\t\tthis.#live = this.#newLive();\n\t\tthis.proxy = new Proxy(this, {\n\t\t\tget: (target, property) => {\n\t\t\t\tif (HANDLE_BASE.has(property)) {\n\t\t\t\t\tconst value: unknown = Reflect.get(target, property, target);\n\t\t\t\t\treturn typeof value === \"function\" ? value.bind(target) : value;\n\t\t\t\t}\n\t\t\t\tif (typeof property !== \"string\" || property === \"then\") return undefined;\n\t\t\t\treturn target.member(property);\n\t\t\t},\n\t\t});\n\t\tholdsByProxy.set(this.proxy, this);\n\t}\n\n\tget kind(): string | undefined {\n\t\treturn this.shape?.kind;\n\t}\n\n\tonShape(listener: (shape: Shape) => void): () => void {\n\t\tthis.shapeListeners.add(listener);\n\t\treturn () => this.shapeListeners.delete(listener);\n\t}\n\n\tonStatus(listener: StatusListener): () => void {\n\t\tthis.#statusListeners.add(listener);\n\t\treturn () => this.#statusListeners.delete(listener);\n\t}\n\n\treadonly #statusListeners = new Set<StatusListener>();\n\n\t#statusChanged(): void {\n\t\tnotifyStatus(this.#statusListeners, this.status, this.error, (error) => this.host.report(error));\n\t}\n\n\trelease(): void {\n\t\tif (this.status === \"released\" || this.status === \"gone\") return;\n\t\tthis.status = \"released\";\n\t\tthis.#statusChanged();\n\t\tconst error = new ChordError(\"released\", `handle ${this.address} released`);\n\t\tthis.#settleReady?.reject(error);\n\t\tthis.#live.reject(error);\n\t\tfor (const readable of this.#readables.values()) readable.stop();\n\t\tif (this.binding !== undefined) this.binding.channel.release(this.binding.id);\n\t\tthis.binding = undefined;\n\t\tthis.host.forgetRemote(this);\n\t}\n\n\t// ─── driven by the link ───\n\n\tbound(channel: RemoteChannel, id: number): void {\n\t\tthis.binding = { channel, id };\n\t}\n\n\tshaped(shape: Shape): void {\n\t\tif (this.status === \"released\" || this.status === \"gone\") return;\n\t\tthis.shape = shape;\n\t\tconst wasLoading = this.status === \"loading\";\n\t\tthis.status = \"live\";\n\t\tif (wasLoading) this.#statusChanged();\n\t\tif (wasLoading) {\n\t\t\tthis.#settleReady?.resolve();\n\t\t\tthis.#settleReady = undefined;\n\t\t\tthis.#live.resolve();\n\t\t}\n\t\tfor (const readable of this.#readables.values()) readable.bind();\n\t\tfor (const listener of [...this.shapeListeners]) {\n\t\t\ttry {\n\t\t\t\tlistener(shape);\n\t\t\t} catch (error) {\n\t\t\t\tthis.host.report(error);\n\t\t\t}\n\t\t}\n\t}\n\n\tgone(error: unknown): void {\n\t\tif (this.status === \"released\" || this.status === \"gone\") return;\n\t\tthis.status = \"gone\";\n\t\tthis.error = error;\n\t\tthis.#statusChanged();\n\t\tthis.binding = undefined;\n\t\tthis.#settleReady?.reject(error);\n\t\tthis.#live.reject(error);\n\t\tfor (const readable of this.#readables.values()) readable.stop();\n\t\tthis.host.forgetRemote(this);\n\t}\n\n\t/** The link went down but may come back (upstream reconnect): wait, then re-hold. */\n\tdetached(): void {\n\t\tif (this.status === \"released\" || this.status === \"gone\") return;\n\t\tthis.binding = undefined;\n\t\tfor (const readable of this.#readables.values()) readable.detach();\n\t\tif (this.status === \"live\") {\n\t\t\tthis.status = \"loading\";\n\t\t\tthis.#live = this.#newLive();\n\t\t\tthis.#statusChanged();\n\t\t}\n\t}\n\n\t// ─── members ───\n\n\tmember(name: string): unknown {\n\t\tconst description = Object.values(this.contract.description.variants)\n\t\t\t.map((members) => members[name])\n\t\t\t.find((member) => member !== undefined);\n\t\tif (description?.kind === \"method\") return this.#caller(name);\n\t\tif (description?.kind === \"state\") {\n\t\t\tlet readable = this.#readables.get(name);\n\t\t\tif (readable === undefined) {\n\t\t\t\treadable = new RemoteReadable(this, name);\n\t\t\t\tthis.#readables.set(name, readable);\n\t\t\t}\n\t\t\treturn readable;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t#caller(name: string): (args: unknown, ctx?: Ctx) => Promise<unknown> {\n\t\tlet caller = this.#callers.get(name);\n\t\tif (caller === undefined) {\n\t\t\tcaller = (args, ctx) => {\n\t\t\t\tif (this.host.inFactory > 0)\n\t\t\t\t\tthrow new ChordError(\"not_ready\", `${this.address}.${name} called inside a factory`);\n\t\t\t\tif (ctx instanceof CtxImpl) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.check(ctx.host);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\treturn Promise.reject(error);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (ctx === undefined || (ctx instanceof CtxImpl && ctx.holder)) {\n\t\t\t\t\treturn this.host.root((root) => this.#call(name, args, root), { signal: ctx?.signal });\n\t\t\t\t}\n\t\t\t\treturn this.#call(name, args, ctx);\n\t\t\t};\n\t\t\tthis.#callers.set(name, caller);\n\t\t}\n\t\treturn caller;\n\t}\n\n\tasync #call(name: string, args: unknown, ctx: Ctx): Promise<unknown> {\n\t\tfor (;;) {\n\t\t\tif (this.status === \"released\" || this.status === \"gone\") {\n\t\t\t\tthrow this.status === \"gone\" ? this.error : new ChordError(\"released\", `handle ${this.address} released`);\n\t\t\t}\n\t\t\tif (this.status === \"loading\") await raceSignal(this.#live.promise, ctx.signal);\n\t\t\tconst binding = this.binding;\n\t\t\tif (binding === undefined) continue;\n\t\t\tconst kind = this.shape?.kind;\n\t\t\tif (kind === undefined || this.contract.description.variants[kind]?.[name]?.kind !== \"method\") {\n\t\t\t\tthrow new ChordError(\"not_in_variant\", `${this.address}: ${name} is not a method of variant ${kind}`);\n\t\t\t}\n\t\t\t// Send only what the consumer's own schema knows (the additive rule's premise; see RecordImpl.call).\n\t\t\tconst description = this.contract.description.variants[kind]?.[name];\n\t\t\tconst sent = description?.kind === \"method\" ? Value.Clean(description.args, Value.Clone(args)) : args;\n\t\t\treturn binding.channel.call(binding.id, name, sent, { rootId: ctx.rootId, epoch: ctx.epoch }, ctx.signal);\n\t\t}\n\t}\n\n\t#newLive(): { promise: Promise<void>; resolve: () => void; reject: (error: unknown) => void } {\n\t\tlet resolve = noop;\n\t\tlet reject: (error: unknown) => void = noop;\n\t\tconst promise = new Promise<void>((done, fail) => {\n\t\t\tresolve = done;\n\t\t\treject = fail;\n\t\t});\n\t\tpromise.catch(noop);\n\t\treturn { promise, resolve, reject };\n\t}\n}\n"]}
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,SAAS,EAAkB,MAAM,WAAW,CAAC;AACtD,OAAO,EAAoB,WAAW,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAgB,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACN,OAAO,EACP,YAAY,EACZ,QAAQ,EAGR,UAAU,EACV,WAAW,GAEX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,aAAa,EAAgC,MAAM,WAAW,CAAC;AAExE,MAAM,IAAI,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;AAiC5B,SAAS,QAAQ;IAChB,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,MAAM,GAA6B,IAAI,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAChD,OAAO,GAAG,IAAI,CAAC;QACf,MAAM,GAAG,IAAI,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACrC,CAAC;AA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,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;YACpC,CAAC,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED,KAAK,CAAC,IAAY,EAAE,IAAa,EAAE,GAAQ;QAC1C,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC;CACD","sourcesContent":["import { Value } from \"typebox/value\";\nimport { HYDRATION, type Hydration } from \"./cell.ts\";\nimport { type AnyContract, takesNoArgs } from \"./contract.ts\";\nimport { applyImmutable, type Decoder, decoder } from \"./delta/index.ts\";\nimport { ChordError, invalid } from \"./errors.ts\";\nimport {\n\tCtxImpl,\n\tnotifyStatus,\n\tREF_BASE,\n\ttype RefCore,\n\ttype RefOwner,\n\traceSignal,\n\trefsByProxy,\n\ttype StatusListener,\n} from \"./object.ts\";\nimport type { Ctx, Readable, RefStatus, Shape, StateEvent } from \"./types.ts\";\nimport { fromWireError, type RootRef, type WireError } from \"./wire.ts\";\n\nconst noop = (): void => {};\n\n/** One state frame for a member, as the binding receives it (payload unpacked). */\nexport interface StateIn {\n\treadonly as: \"snap\" | \"reset\" | \"ops\" | \"error\";\n\treadonly value?: unknown;\n\treadonly ops?: readonly unknown[];\n\treadonly error?: WireError;\n}\n\n/** What a binding needs from the link it is bound to (implemented by Connection). */\nexport interface RemoteChannel {\n\t/** Sends a hold for `binding`; `again`: the binding already has values (a re-hold), its unit is not urgent. */\n\thold(binding: RemoteBinding, again: boolean): number;\n\trelease(id: number): void;\n\tcall(hold: number, member: string, args: unknown, root: RootRef | undefined, signal: AbortSignal): Promise<unknown>;\n\t/** Starts (`sub`) or stops (`unsub`) the state of a hold. */\n\twantState(hold: number, wanted: boolean): void;\n}\n\n/** What a binding needs from its host. */\nexport interface RemoteHost {\n\treadonly inFactory: number;\n\treport(error: unknown): void;\n\troot<T>(fn: (ctx: Ctx) => T | Promise<T>, options?: { signal?: AbortSignal }): Promise<T>;\n\t/** The binding has no views left: the host lingers it or closes it. */\n\tbindingIdle(binding: RemoteBinding): void;\n\t/** The binding ended or was closed: the host forgets it. */\n\tforgetBinding(binding: RemoteBinding): void;\n}\n\ntype Settle = { resolve: () => void; reject: (error: unknown) => void };\n\nfunction deferred(): { promise: Promise<void> } & Settle {\n\tlet resolve = noop;\n\tlet reject: (error: unknown) => void = noop;\n\tconst promise = new Promise<void>((done, fail) => {\n\t\tresolve = done;\n\t\treject = fail;\n\t});\n\tpromise.catch(noop);\n\treturn { promise, resolve, reject };\n}\n\n/** A member's value with the decoder of its current stream. */\ninterface MemberState {\n\tvalue: unknown;\n\tdecoder: Decoder;\n}\n\n/**\n * One hold per host and key (type, normalized input, principal key, contract fingerprint), shared by every reference to\n * it: one hold over the link, one stream per state member, calls over the same hold. References are views onto it.\n *\n * A hold implies the state of its variant (unless no view wants state): the provider answers with a unit, the shape\n * followed by a snapshot of each state member the binding lacks. A shape is applied only once all of its snapshots are\n * here, so a live binding always has every state member of its variant. After the first hydration the values stay\n * readable while the binding re-holds (link loss): status `loading`, last values kept.\n */\nexport class RemoteBinding {\n\treadonly host: RemoteHost;\n\treadonly key: string;\n\treadonly contract: AnyContract;\n\treadonly at: string;\n\treadonly input: unknown;\n\t/** Forwarded principal (omitted for the host's own principal). */\n\treadonly principal: unknown | undefined;\n\t/** `ended`: gone with `error`, or closed (no views, no linger). */\n\tstatus: \"loading\" | \"live\" | \"ended\" = \"loading\";\n\terror: unknown;\n\t/** The applied shape (kept while re-holding). */\n\tshape: Shape | undefined;\n\t/** Every state member of the applied shape has a value (stays true while re-holding). */\n\thydrated = false;\n\t/** The current hold; undefined while resolving the route or after a link loss. */\n\thold: { readonly channel: RemoteChannel; readonly id: number } | undefined;\n\t/** What the provider was told: state for this hold (`state: false` / `sub` / `unsub`). */\n\tstateOn = false;\n\treadonly views = new Set<RemoteRef>();\n\treadonly members = new Map<string, MemberState>();\n\t/** Lingering since (no views): set by the host. */\n\tlingerTimer: ReturnType<typeof setTimeout> | undefined;\n\treadonly #listeners = new Map<string, Set<ViewReadable>>();\n\t/** A shape waiting for its snapshots. */\n\t#pending: { shape: Shape; readonly missing: Set<string>; readonly values: Map<string, MemberState> } | undefined;\n\t/** Resolved while a shape is applied for the current hold (calls wait for it). */\n\t#live = deferred();\n\t/** A shape was applied once (a re-hold says `again`). */\n\t#applied = false;\n\t/** Waiting for the first hydration (`whenHydrated`). */\n\treadonly #hydrationWaiters = new Set<Settle>();\n\n\tconstructor(\n\t\thost: RemoteHost,\n\t\tfields: { key: string; contract: AnyContract; at: string; input: unknown; principal: unknown | undefined },\n\t) {\n\t\tthis.host = host;\n\t\tthis.key = fields.key;\n\t\tthis.contract = fields.contract;\n\t\tthis.at = fields.at;\n\t\tthis.input = fields.input;\n\t\tthis.principal = fields.principal;\n\t}\n\n\tget ended(): boolean {\n\t\treturn this.status === \"ended\";\n\t}\n\n\t/** Views that want state. */\n\tget stateViews(): number {\n\t\tlet count = 0;\n\t\tfor (const view of this.views) if (view.wantsState) count++;\n\t\treturn count;\n\t}\n\n\t/** Whether the next hold should carry state: some view wants it, or nobody is left (lingering keeps it). */\n\tget wantsState(): boolean {\n\t\treturn this.views.size === 0 ? this.stateOn : this.stateViews > 0;\n\t}\n\n\t/** Whether a re-hold is `again` (the binding already has a shape). */\n\tget applied(): boolean {\n\t\treturn this.#applied;\n\t}\n\n\t// ─── views ───\n\n\taddView(view: RemoteRef): void {\n\t\tthis.views.add(view);\n\t\tif (this.lingerTimer !== undefined) {\n\t\t\tclearTimeout(this.lingerTimer);\n\t\t\tthis.lingerTimer = undefined;\n\t\t}\n\t\tthis.#syncState();\n\t\tview.update();\n\t}\n\n\tremoveView(view: RemoteRef): void {\n\t\tif (!this.views.delete(view)) return;\n\t\tfor (const set of this.#listeners.values())\n\t\t\tfor (const readable of set) if (readable.view === view) set.delete(readable);\n\t\tif (this.views.size === 0) {\n\t\t\tthis.host.bindingIdle(this);\n\t\t\treturn;\n\t\t}\n\t\tthis.#syncState();\n\t}\n\n\t/** Tells the provider to start or stop state when the views' wish changed. */\n\t#syncState(): void {\n\t\tif (this.ended || this.views.size === 0) return;\n\t\tconst wanted = this.stateViews > 0;\n\t\tif (wanted === this.stateOn) return;\n\t\tthis.stateOn = wanted;\n\t\tif (!wanted) {\n\t\t\tthis.hydrated = false;\n\t\t\tthis.members.clear();\n\t\t\tif (this.#pending !== undefined) this.#pending.missing.clear();\n\t\t}\n\t\tif (this.hold !== undefined) this.hold.channel.wantState(this.hold.id, wanted);\n\t\tfor (const view of this.views) view.update();\n\t}\n\n\tlisten(name: string, readable: ViewReadable): void {\n\t\tlet set = this.#listeners.get(name);\n\t\tif (set === undefined) {\n\t\t\tset = new Set();\n\t\t\tthis.#listeners.set(name, set);\n\t\t}\n\t\tset.add(readable);\n\t}\n\n\tunlisten(name: string, readable: ViewReadable): void {\n\t\tthis.#listeners.get(name)?.delete(readable);\n\t}\n\n\t/** Whether `name` is a state member of the applied variant (as the consumer's contract describes it). */\n\tinVariant(name: string): boolean {\n\t\tconst variant = this.shape?.variant;\n\t\treturn variant !== undefined && this.contract.description.variants[variant]?.[name]?.kind === \"state\";\n\t}\n\n\t/** The members' value as views read it: throws `not_ready` before the first hydration, `not_in_variant` outside it. */\n\tread(name: string): unknown {\n\t\tif (this.status === \"ended\") throw this.terminalError();\n\t\tif (!this.hydrated) throw new ChordError(\"not_ready\", `${this.key}.${name} is not hydrated yet`);\n\t\tif (!this.inVariant(name))\n\t\t\tthrow new ChordError(\n\t\t\t\t\"not_in_variant\",\n\t\t\t\t`${this.key}: ${name} is not a state member of variant ${this.shape?.variant}`,\n\t\t\t);\n\t\treturn this.members.get(name)?.value;\n\t}\n\n\t/** Resolves once the binding has its state (rejects if it ends first). */\n\twhenHydrated(): Promise<void> {\n\t\tif (this.hydrated) return Promise.resolve();\n\t\tif (this.ended) return Promise.reject(this.terminalError());\n\t\treturn new Promise<void>((resolve, reject) => this.#hydrationWaiters.add({ resolve, reject }));\n\t}\n\n\t#settleHydration(error?: unknown): void {\n\t\tconst waiters = [...this.#hydrationWaiters];\n\t\tthis.#hydrationWaiters.clear();\n\t\tfor (const waiter of waiters) {\n\t\t\tif (error === undefined) waiter.resolve();\n\t\t\telse waiter.reject(error);\n\t\t}\n\t}\n\n\treadable(name: string): boolean {\n\t\treturn this.status !== \"ended\" && this.hydrated && this.inVariant(name);\n\t}\n\n\tterminalError(): unknown {\n\t\treturn this.error ?? new ChordError(\"released\", `reference ${this.key} released`);\n\t}\n\n\t// ─── driven by the host and the link ───\n\n\tbound(channel: RemoteChannel, id: number): void {\n\t\tthis.hold = { channel, id };\n\t\tthis.stateOn = this.wantsState;\n\t}\n\n\t/** A unit begins: `listed` are the members whose snapshots follow. */\n\tshaped(shape: Shape, listed: readonly string[]): void {\n\t\tif (this.ended) return;\n\t\tconst previous = this.#pending;\n\t\tconst missing = new Set<string>(listed);\n\t\t// A newer shape before the older one's snapshots (relays may reorder them): wait for both.\n\t\tif (previous !== undefined) for (const name of previous.missing) missing.add(name);\n\t\tconst wanted = new Set(this.#stateMembers(shape));\n\t\tfor (const name of [...missing]) if (!wanted.has(name) || !this.stateOn) missing.delete(name);\n\t\tthis.#pending = { shape, missing, values: previous?.values ?? new Map() };\n\t\tif (missing.size === 0) this.#apply();\n\t}\n\n\t/** A state frame for member `name` of the current hold. */\n\tstate(name: string, frame: StateIn): void {\n\t\tif (this.ended) return;\n\t\tif (frame.as === \"error\") {\n\t\t\tconst error = fromWireError(frame.error!);\n\t\t\t// Before the first hydration nobody could read anything: the binding fails instead of waiting forever.\n\t\t\tif (!this.hydrated && this.stateOn) {\n\t\t\t\tthis.gone(error);\n\t\t\t\tthis.close();\n\t\t\t} else this.host.report(error);\n\t\t\treturn;\n\t\t}\n\t\tconst pending = this.#pending;\n\t\tif (frame.as === \"ops\") {\n\t\t\tconst target = pending?.values.get(name) ?? this.members.get(name);\n\t\t\tif (target === undefined) return;\n\t\t\tconst ops = target.decoder.decode(frame.ops ?? []);\n\t\t\ttarget.value = applyImmutable(target.value, ops);\n\t\t\tif (target === this.members.get(name)) this.#deliver(name, { type: \"ops\", ops, value: target.value });\n\t\t\treturn;\n\t\t}\n\t\tconst fresh: MemberState = { value: frame.value, decoder: decoder() };\n\t\tif (pending !== undefined && (pending.missing.has(name) || pending.values.has(name))) {\n\t\t\tpending.values.set(name, fresh);\n\t\t\tpending.missing.delete(name);\n\t\t\tif (pending.missing.size === 0) this.#apply();\n\t\t\treturn;\n\t\t}\n\t\tif (!this.inVariant(name)) return;\n\t\tthis.members.set(name, fresh);\n\t\tthis.#deliver(name, { type: \"reset\", value: fresh.value });\n\t}\n\n\t/** The provider ended the object (or refused the hold): every view is gone. */\n\tgone(error: unknown): void {\n\t\tif (this.ended) return;\n\t\tthis.status = \"ended\";\n\t\tthis.error = error;\n\t\tthis.hold = undefined;\n\t\tthis.#pending = undefined;\n\t\tthis.#live.reject(error);\n\t\tthis.#settleHydration(error);\n\t\tfor (const view of [...this.views]) view.end(error);\n\t\tthis.#listeners.clear();\n\t\tthis.host.forgetBinding(this);\n\t}\n\n\t/** The link went down but may come back (upstream reconnect): keep the values, wait for the re-hold. */\n\tdetached(): void {\n\t\tif (this.ended) return;\n\t\tthis.hold = undefined;\n\t\tthis.#pending = undefined;\n\t\tif (this.status === \"live\") {\n\t\t\tthis.status = \"loading\";\n\t\t\tthis.#live = deferred();\n\t\t}\n\t\tfor (const view of this.views) view.update();\n\t}\n\n\t/** No views and no linger: releases the hold and forgets the binding. */\n\tclose(): void {\n\t\tif (this.lingerTimer !== undefined) clearTimeout(this.lingerTimer);\n\t\tthis.lingerTimer = undefined;\n\t\tif (this.hold !== undefined) this.hold.channel.release(this.hold.id);\n\t\tthis.hold = undefined;\n\t\tif (this.status !== \"ended\") {\n\t\t\tthis.status = \"ended\";\n\t\t\tconst error = new ChordError(\"released\", `reference ${this.key} released`);\n\t\t\tthis.#live.reject(error);\n\t\t\tthis.#settleHydration(error);\n\t\t\tfor (const view of [...this.views]) view.end(error);\n\t\t}\n\t\tthis.#pending = undefined;\n\t\tthis.#listeners.clear();\n\t\tthis.host.forgetBinding(this);\n\t}\n\n\t/** Calls `name` over the current hold, waiting for it while the binding (re)holds. */\n\tasync call(name: string, args: unknown, ctx: Ctx): Promise<unknown> {\n\t\tfor (;;) {\n\t\t\tif (this.ended) throw this.terminalError();\n\t\t\tif (this.status !== \"live\" || this.hold === undefined) await raceSignal(this.#live.promise, ctx.signal);\n\t\t\tconst hold = this.hold;\n\t\t\tif (hold === undefined || this.status !== \"live\") continue;\n\t\t\tconst variant = this.shape?.variant;\n\t\t\tconst description = variant === undefined ? undefined : this.contract.description.variants[variant]?.[name];\n\t\t\tif (description?.kind !== \"method\") {\n\t\t\t\tthrow new ChordError(\"not_in_variant\", `${this.key}: ${name} is not a method of variant ${variant}`);\n\t\t\t}\n\t\t\t// Send only what the consumer's own schema knows (the additive rule's premise; see ObjectImpl.call).\n\t\t\tconst sent = description.args === undefined ? undefined : Value.Clean(description.args, Value.Clone(args));\n\t\t\treturn hold.channel.call(\n\t\t\t\thold.id,\n\t\t\t\tname,\n\t\t\t\tsent,\n\t\t\t\t{ rootId: ctx.rootId, codeVersion: ctx.codeVersion },\n\t\t\t\tctx.signal,\n\t\t\t);\n\t\t}\n\t}\n\n\t#stateMembers(shape: Shape): string[] {\n\t\tconst members = shape.variant === undefined ? undefined : this.contract.description.variants[shape.variant];\n\t\tif (members === undefined) return [];\n\t\treturn shape.members.filter((name) => members[name]?.kind === \"state\");\n\t}\n\n\t/** Applies the pending shape with its snapshots: members outside the variant go, new values are announced. */\n\t#apply(): void {\n\t\tconst pending = this.#pending;\n\t\tif (pending === undefined) return;\n\t\tthis.#pending = undefined;\n\t\tthis.shape = pending.shape;\n\t\tconst wanted = new Set(this.#stateMembers(pending.shape));\n\t\tfor (const name of [...this.members.keys()]) if (!wanted.has(name)) this.members.delete(name);\n\t\tfor (const [name, state] of pending.values) if (wanted.has(name)) this.members.set(name, state);\n\t\tthis.hydrated = this.stateOn && [...wanted].every((name) => this.members.has(name));\n\t\tif (this.hydrated) this.#settleHydration();\n\t\tthis.status = \"live\";\n\t\tthis.#applied = true;\n\t\tthis.#live.resolve();\n\t\tfor (const view of this.views) view.update();\n\t\tfor (const [name, state] of pending.values) {\n\t\t\tif (wanted.has(name)) this.#deliver(name, { type: \"reset\", value: state.value });\n\t\t}\n\t\tfor (const view of [...this.views]) view.shapeChanged();\n\t}\n\n\t#deliver(name: string, event: StateEvent<unknown>): void {\n\t\tconst readables = this.#listeners.get(name);\n\t\tif (readables === undefined) return;\n\t\tfor (const readable of [...readables]) readable.deliver(event);\n\t}\n}\n\n/**\n * A state member of a remote reference: the binding's value. Reading throws `not_ready` before the first hydration and\n * `not_in_variant` outside the variant. A listener added before the hydration gets its snapshot then.\n */\nclass ViewReadable implements Readable<unknown> {\n\treadonly view: RemoteRef;\n\treadonly #name: string;\n\treadonly #values = new Set<(value: unknown) => void>();\n\treadonly #events = new Set<(event: StateEvent<unknown>) => void>();\n\t/** Event listeners that have not had their snapshot yet. */\n\treadonly #unseen = new Set<(event: StateEvent<unknown>) => void>();\n\n\tconstructor(view: RemoteRef, name: string) {\n\t\tthis.view = view;\n\t\tthis.#name = name;\n\t}\n\n\tget value(): unknown {\n\t\tif (this.view.ended) throw this.view.terminalError();\n\t\treturn this.view.binding.read(this.#name);\n\t}\n\n\t/** Not hydrated before the binding's first snapshots (a local object forwarding this member waits for them). */\n\tget [HYDRATION](): Hydration | undefined {\n\t\tconst binding = this.view.binding;\n\t\tif (binding.hydrated) return undefined;\n\t\treturn { hydrated: false, whenHydrated: () => binding.whenHydrated() };\n\t}\n\n\tsubscribe(listener: (value: unknown) => void): () => void {\n\t\tthis.#values.add(listener);\n\t\tthis.#attach();\n\t\tif (this.#readable()) this.#safe(() => listener(this.view.binding.members.get(this.#name)?.value));\n\t\treturn () => this.#remove(this.#values, listener);\n\t}\n\n\tevents(listener: (event: StateEvent<unknown>) => void): () => void {\n\t\tthis.#events.add(listener);\n\t\tthis.#attach();\n\t\tif (this.#readable()) {\n\t\t\tconst value = this.view.binding.members.get(this.#name)?.value;\n\t\t\tthis.#safe(() => listener({ type: \"snap\", value }));\n\t\t} else this.#unseen.add(listener);\n\t\treturn () => {\n\t\t\tthis.#unseen.delete(listener);\n\t\t\tthis.#remove(this.#events, listener);\n\t\t};\n\t}\n\n\tdeliver(event: StateEvent<unknown>): void {\n\t\tfor (const listener of [...this.#events]) {\n\t\t\tif (!this.#unseen.delete(listener)) this.#safe(() => listener(event));\n\t\t\telse if (event.type !== \"ops\") this.#safe(() => listener({ type: \"snap\", value: event.value }));\n\t\t}\n\t\tfor (const listener of [...this.#values]) this.#safe(() => listener(event.value));\n\t}\n\n\tstop(): void {\n\t\tthis.#values.clear();\n\t\tthis.#events.clear();\n\t\tthis.#unseen.clear();\n\t\tthis.view.binding.unlisten(this.#name, this);\n\t}\n\n\t#readable(): boolean {\n\t\treturn !this.view.ended && this.view.binding.readable(this.#name);\n\t}\n\n\t#attach(): void {\n\t\tif (!this.view.ended) this.view.binding.listen(this.#name, this);\n\t}\n\n\t#remove<T>(set: Set<T>, listener: T): void {\n\t\tset.delete(listener);\n\t\tif (this.#values.size + this.#events.size === 0) this.view.binding.unlisten(this.#name, this);\n\t}\n\n\t#safe(fn: () => void): void {\n\t\ttry {\n\t\t\tfn();\n\t\t} catch (error) {\n\t\t\tthis.view.binding.host.report(error);\n\t\t}\n\t}\n}\n\n/**\n * A reference to an object on another host: a view onto the host's shared binding for its key. Each view has its own\n * owner, status, observers and `release`; ending by the provider and re-holding belong to the binding.\n */\nexport class RemoteRef implements RefCore {\n\treadonly object = undefined;\n\treadonly binding: RemoteBinding;\n\treadonly owner: RefOwner;\n\t/** False: a method-only view (`state: false`), ready once live. */\n\treadonly wantsState: boolean;\n\treadonly proxy: object;\n\treadonly ready: Promise<void>;\n\tstatus: RefStatus = \"loading\";\n\terror: unknown;\n\treadonly shapeListeners = new Set<(shape: Shape) => void>();\n\treadonly #statusListeners = new Set<StatusListener>();\n\treadonly #readables = new Map<string, ViewReadable>();\n\treadonly #callers = new Map<string, (...given: unknown[]) => Promise<unknown>>();\n\t#settleReady: Settle | undefined;\n\n\tconstructor(binding: RemoteBinding, owner: RefOwner, wantsState: boolean) {\n\t\tthis.binding = binding;\n\t\tthis.owner = owner;\n\t\tthis.wantsState = wantsState;\n\t\tconst ready = deferred();\n\t\tthis.ready = ready.promise;\n\t\tthis.#settleReady = ready;\n\t\tthis.proxy = new Proxy(this, {\n\t\t\tget: (target, property) => {\n\t\t\t\tif (REF_BASE.has(property)) {\n\t\t\t\t\tconst value: unknown = Reflect.get(target, property, target);\n\t\t\t\t\treturn typeof value === \"function\" ? value.bind(target) : value;\n\t\t\t\t}\n\t\t\t\tif (typeof property !== \"string\" || property === \"then\") return undefined;\n\t\t\t\treturn target.member(property);\n\t\t\t},\n\t\t});\n\t\trefsByProxy.set(this.proxy, this);\n\t}\n\n\tget contract(): AnyContract {\n\t\treturn this.binding.contract;\n\t}\n\n\tget address(): string {\n\t\treturn this.binding.key;\n\t}\n\n\tget ended(): boolean {\n\t\treturn this.status === \"released\" || this.status === \"gone\";\n\t}\n\n\tget variant(): string | undefined {\n\t\treturn this.binding.shape?.variant;\n\t}\n\n\tget shape(): Shape | undefined {\n\t\treturn this.binding.shape;\n\t}\n\n\tonShape(listener: (shape: Shape) => void): () => void {\n\t\tthis.shapeListeners.add(listener);\n\t\treturn () => this.shapeListeners.delete(listener);\n\t}\n\n\tonStatus(listener: StatusListener): () => void {\n\t\tthis.#statusListeners.add(listener);\n\t\treturn () => this.#statusListeners.delete(listener);\n\t}\n\n\tterminalError(): unknown {\n\t\treturn this.status === \"gone\" ? this.error : new ChordError(\"released\", `reference ${this.address} released`);\n\t}\n\n\trelease(): void {\n\t\tif (this.ended) return;\n\t\tthis.status = \"released\";\n\t\tthis.#notify();\n\t\tthis.#settleReady?.reject(new ChordError(\"released\", `reference ${this.address} released`));\n\t\tthis.#settleReady = undefined;\n\t\tfor (const readable of this.#readables.values()) readable.stop();\n\t\tthis.binding.removeView(this);\n\t}\n\n\t// ─── driven by the binding ───\n\n\t/** Follows the binding: live once it has a shape (and, for a state view, its state) over a current hold. */\n\tupdate(): void {\n\t\tif (this.ended) return;\n\t\tconst binding = this.binding;\n\t\tconst live = binding.status === \"live\" && binding.hold !== undefined && (!this.wantsState || binding.hydrated);\n\t\tconst next: RefStatus = live ? \"live\" : \"loading\";\n\t\tif (next === this.status) return;\n\t\tthis.status = next;\n\t\tthis.#notify();\n\t\tif (live) {\n\t\t\tthis.#settleReady?.resolve();\n\t\t\tthis.#settleReady = undefined;\n\t\t}\n\t}\n\n\tend(error: unknown): void {\n\t\tif (this.ended) return;\n\t\tconst released = error instanceof ChordError && error.code === \"released\";\n\t\tthis.status = released ? \"released\" : \"gone\";\n\t\tif (!released) this.error = error;\n\t\tthis.#notify();\n\t\tthis.#settleReady?.reject(error);\n\t\tthis.#settleReady = undefined;\n\t\tfor (const readable of this.#readables.values()) readable.stop();\n\t}\n\n\tshapeChanged(): void {\n\t\tconst shape = this.binding.shape;\n\t\tif (shape === undefined || this.ended) return;\n\t\tfor (const listener of [...this.shapeListeners]) {\n\t\t\ttry {\n\t\t\t\tlistener(shape);\n\t\t\t} catch (error) {\n\t\t\t\tthis.binding.host.report(error);\n\t\t\t}\n\t\t}\n\t}\n\n\t#notify(): void {\n\t\tnotifyStatus(this.#statusListeners, this.status, this.error, (error) => this.binding.host.report(error));\n\t}\n\n\t// ─── members ───\n\n\tmember(name: string): unknown {\n\t\tconst description = Object.values(this.contract.description.variants)\n\t\t\t.map((members) => members[name])\n\t\t\t.find((member) => member !== undefined);\n\t\tif (description?.kind === \"method\") return this.#caller(name);\n\t\tif (description?.kind === \"state\") {\n\t\t\tlet readable = this.#readables.get(name);\n\t\t\tif (readable === undefined) {\n\t\t\t\treadable = new ViewReadable(this, name);\n\t\t\t\tthis.#readables.set(name, readable);\n\t\t\t}\n\t\t\treturn readable;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t#caller(name: string): (...given: unknown[]) => Promise<unknown> {\n\t\tlet caller = this.#callers.get(name);\n\t\tif (caller === undefined) {\n\t\t\tconst noArgs = takesNoArgs(this.contract, name);\n\t\t\tcaller = (...given) => {\n\t\t\t\t// A method without arguments is called as `ref.name(ctx)`.\n\t\t\t\tconst [args, ctx] = (noArgs ? [undefined, given[0]] : given) as [unknown, Ctx | undefined];\n\t\t\t\tconst host = this.binding.host;\n\t\t\t\tif (host.inFactory > 0)\n\t\t\t\t\tthrow new ChordError(\"not_ready\", `${this.address}.${name} called inside a factory`);\n\t\t\t\t// The same checks as a local reference's caller (RefImpl.caller and ObjectImpl.call): a ctx from another host\n\t\t\t\t// or one not made by Chord would carry a root this host does not own over its link.\n\t\t\t\tif (ctx !== undefined && !(ctx instanceof CtxImpl)) {\n\t\t\t\t\treturn Promise.reject(invalid(\"foreign_ctx\", \"ctx must come from a Chord host\"));\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tctx?.check(host);\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn Promise.reject(error);\n\t\t\t\t}\n\t\t\t\tif (ctx === undefined || ctx.holder) {\n\t\t\t\t\treturn host.root((root) => this.#call(name, args, root), { signal: ctx?.signal });\n\t\t\t\t}\n\t\t\t\treturn this.#call(name, args, ctx);\n\t\t\t};\n\t\t\tthis.#callers.set(name, caller);\n\t\t}\n\t\treturn caller;\n\t}\n\n\t#call(name: string, args: unknown, ctx: Ctx): Promise<unknown> {\n\t\tif (this.ended) return Promise.reject(this.terminalError());\n\t\treturn this.binding.call(name, args, ctx);\n\t}\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -1,23 +1,35 @@
1
- import type { AnyContract, Handle, InputOf } from "./contract.ts";
1
+ import type { AnyContract, InputOf, Ref } from "./contract.ts";
2
2
  import type { Op } from "./delta/index.ts";
3
- /** App-defined, JSON-serializable identity of a caller. Mapped to a record key by `createHost({ principalKey })`. */
4
- export type Principal = unknown;
5
- export interface GetOptions {
6
- /** Principal the record is created for. Defaults to the host principal. */
7
- readonly principal?: Principal;
8
- /** Host name. Only the local host in phase 1a. */
9
- readonly at?: string;
3
+ /**
4
+ * Options of `get`. `P` is the app's principal type: a JSON-serializable identity of a caller, mapped to an object key
5
+ * by `createHost({ principalKey })`.
6
+ */
7
+ export interface GetOptions<P = unknown> {
8
+ /** Principal the object is created for. Defaults to the host's own principal (`createHost({ self })`). */
9
+ readonly principal?: P;
10
+ /**
11
+ * False: a method-only reference. It receives no state (unless another reference to the same object wants it), and
12
+ * is ready once its object is live.
13
+ */
14
+ readonly state?: boolean;
10
15
  }
11
16
  /**
12
- * The explicit call context of one root (a short Chord call tree). Calls made with it carry its root id and epoch;
13
- * `get` holds are released when the call that received this ctx settles.
17
+ * The explicit call context of one root (a short Chord call tree). Calls made with it carry its root id and code
18
+ * version; `get` references are released when the call that received this ctx settles.
14
19
  */
15
- export interface Ctx {
20
+ export interface Ctx<P = unknown> {
16
21
  readonly signal: AbortSignal;
17
22
  readonly rootId: string;
18
- readonly epoch: number;
19
- readonly principal: Principal;
20
- get<C extends AnyContract>(type: C, input: InputOf<C>, options?: GetOptions): Handle<C>;
23
+ readonly codeVersion: number;
24
+ /** Who the root acts as: the caller at ingress, the host's own principal inside objects. */
25
+ readonly principal: P;
26
+ /**
27
+ * A reference for this call, released when the call settles. Resolves once it is ready: live, with every state
28
+ * member of its variant (unless `state: false`). Rejects with the activation error, `aborted` when the ctx is
29
+ * aborted or the call settles first, or `unavailable/ready_timeout` after the host's `readyTimeout`; the reference
30
+ * is released then.
31
+ */
32
+ get<C extends AnyContract>(type: C, input: InputOf<C>, options?: GetOptions<P>): Promise<Ref<C>>;
21
33
  }
22
34
  export type StateEvent<T> = {
23
35
  readonly type: "snap";
@@ -30,7 +42,7 @@ export type StateEvent<T> = {
30
42
  readonly type: "reset";
31
43
  readonly value: T;
32
44
  };
33
- /** A readable state source: a cell, a derivation, or a handle's state member. Values are immutable by contract. */
45
+ /** A readable state source: a cell, a derivation, or a reference's state member. Values are immutable by contract. */
34
46
  export interface Readable<T> {
35
47
  readonly value: T;
36
48
  /** Called with the current value immediately, then with every new value. */
@@ -39,38 +51,37 @@ export interface Readable<T> {
39
51
  events(listener: (event: StateEvent<T>) => void): () => void;
40
52
  }
41
53
  /**
42
- * What a behavior may expose as a state member: a cell, a derivation, or a held object's state member (whose value is
43
- * `undefined` only while that object is loading; a record is live only after its holds are).
54
+ * What an implementation may expose as a state member: a cell, a derivation, or a held object's state member (an
55
+ * object goes live only once the members it exposes have their values).
44
56
  */
45
- export type StateSource<T> = Readable<T> | Readable<T | undefined>;
57
+ export type StateSource<T> = Readable<T>;
46
58
  declare const EXPOSED: unique symbol;
47
- /** A local member backed by a resource (`self.expose(res.x)`): handles read the resource's value once live. */
59
+ /** A local member backed by a resource (`self.expose(res.x)`): references read the resource's value once live. */
48
60
  export interface Exposed<T> {
49
61
  readonly [EXPOSED]: T;
50
62
  }
51
- export type HandleStatus = "loading" | "live" | "released" | "gone";
63
+ export type RefStatus = "loading" | "live" | "released" | "gone";
52
64
  export interface Shape {
53
- readonly kind: string | undefined;
65
+ readonly variant: string | undefined;
54
66
  readonly members: readonly string[];
55
67
  /** Fingerprint of the provider contract. */
56
68
  readonly contract: string;
57
- readonly epoch: number;
58
69
  }
59
- export interface HandleBase<C extends AnyContract> {
60
- /** The consumer contract token this handle was bound with. */
70
+ export interface RefBase<C extends AnyContract> {
71
+ /** The consumer contract token this reference was bound with. */
61
72
  readonly contract: C;
62
- readonly status: HandleStatus;
73
+ readonly status: RefStatus;
63
74
  readonly ready: Promise<void>;
64
- readonly kind: string | undefined;
75
+ readonly variant: string | undefined;
65
76
  readonly shape: Shape | undefined;
66
- /** Why the handle is gone, if it is. */
77
+ /** Why the reference is gone, if it is. */
67
78
  readonly error: unknown;
68
79
  onShape(listener: (shape: Shape) => void): () => void;
69
80
  /**
70
81
  * Called after every status change (`loading` → `live`, `live` → `loading` while a link reconnects, `released`,
71
82
  * `gone` with `error`). A UI watches for `gone` to `get` again.
72
83
  */
73
- onStatus(listener: (status: HandleStatus, error: unknown) => void): () => void;
84
+ onStatus(listener: (status: RefStatus, error: unknown) => void): () => void;
74
85
  release(): void;
75
86
  }
76
87
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAE3C,qHAAqH;AACrH,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC;AAEhC,MAAM,WAAW,UAAU;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,kDAAkD;IAClD,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,GAAG;IACnB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,GAAG,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;CACxF;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CA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AO,CAAC,CAAC;IACzB,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;CACtB;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;AAEjE,MAAM,WAAW,KAAK;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,WAAW;IAC7C,iEAAiE;IACjE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IAClC,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACtD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5E,OAAO,IAAI,IAAI,CAAC;CAChB"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AnyContract, Handle, InputOf } from \"./contract.ts\";\nimport type { Op } from \"./delta/index.ts\";\n\n/** App-defined, JSON-serializable identity of a caller. Mapped to a record key by `createHost({ principalKey })`. */\nexport type Principal = unknown;\n\nexport interface GetOptions {\n\t/** Principal the record is created for. Defaults to the host principal. */\n\treadonly principal?: Principal;\n\t/** Host name. Only the local host in phase 1a. */\n\treadonly at?: string;\n}\n\n/**\n * The explicit call context of one root (a short Chord call tree). Calls made with it carry its root id and epoch;\n * `get` holds are released when the call that received this ctx settles.\n */\nexport interface Ctx {\n\treadonly signal: AbortSignal;\n\treadonly rootId: string;\n\treadonly epoch: number;\n\treadonly principal: Principal;\n\tget<C extends AnyContract>(type: C, input: InputOf<C>, options?: GetOptions): Handle<C>;\n}\n\nexport type StateEvent<T> =\n\t| { readonly type: \"snap\"; readonly value: T }\n\t| { readonly type: \"ops\"; readonly ops: readonly Op[]; readonly value: T }\n\t| { readonly type: \"reset\"; readonly value: T };\n\n/** A readable state source: a cell, a derivation, or a handle's state member. Values are immutable by contract. */\nexport interface Readable<T> {\n\treadonly value: T;\n\t/** Called with the current value immediately, then with every new value. */\n\tsubscribe(listener: (value: T) => void): () => void;\n\t/** Delta stream: a snapshot immediately, then ops, or a reset after a migration or rebind. */\n\tevents(listener: (event: StateEvent<T>) => void): () => void;\n}\n\n/**\n * What a behavior may expose as a state member: a cell, a derivation, or a held object's state member (whose value is\n * `undefined` only while that object is loading; a record is live only after its holds are).\n */\nexport type StateSource<T> = Readable<T> | Readable<T | undefined>;\n\ndeclare const EXPOSED: unique symbol;\n\n/** A local member backed by a resource (`self.expose(res.x)`): handles read the resource's value once live. */\nexport interface Exposed<T> {\n\treadonly [EXPOSED]: T;\n}\n\nexport type HandleStatus = \"loading\" | \"live\" | \"released\" | \"gone\";\n\nexport interface Shape {\n\treadonly kind: string | undefined;\n\treadonly members: readonly string[];\n\t/** Fingerprint of the provider contract. */\n\treadonly contract: string;\n\treadonly epoch: number;\n}\n\nexport interface HandleBase<C extends AnyContract> {\n\t/** The consumer contract token this handle was bound with. */\n\treadonly contract: C;\n\treadonly status: HandleStatus;\n\treadonly ready: Promise<void>;\n\treadonly kind: string | undefined;\n\treadonly shape: Shape | undefined;\n\t/** Why the handle is gone, if it is. */\n\treadonly error: unknown;\n\tonShape(listener: (shape: Shape) => void): () => void;\n\t/**\n\t * Called after every status change (`loading` → `live`, `live` → `loading` while a link reconnects, `released`,\n\t * `gone` with `error`). A UI watches for `gone` to `get` again.\n\t */\n\tonStatus(listener: (status: HandleStatus, error: unknown) => void): () => void;\n\trelease(): void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AnyContract, InputOf, Ref } from \"./contract.ts\";\nimport type { Op } from \"./delta/index.ts\";\n\n/**\n * Options of `get`. `P` is the app's principal type: a JSON-serializable identity of a caller, mapped to an object key\n * by `createHost({ principalKey })`.\n */\nexport interface GetOptions<P = unknown> {\n\t/** Principal the object is created for. Defaults to the host's own principal (`createHost({ self })`). */\n\treadonly principal?: P;\n\t/**\n\t * False: a method-only reference. It receives no state (unless another reference to the same object wants it), and\n\t * is ready once its object is live.\n\t */\n\treadonly state?: boolean;\n}\n\n/**\n * The explicit call context of one root (a short Chord call tree). Calls made with it carry its root id and code\n * version; `get` references are released when the call that received this ctx settles.\n */\nexport interface Ctx<P = unknown> {\n\treadonly signal: AbortSignal;\n\treadonly rootId: string;\n\treadonly codeVersion: number;\n\t/** Who the root acts as: the caller at ingress, the host's own principal inside objects. */\n\treadonly principal: P;\n\t/**\n\t * A reference for this call, released when the call settles. Resolves once it is ready: live, with every state\n\t * member of its variant (unless `state: false`). Rejects with the activation error, `aborted` when the ctx is\n\t * aborted or the call settles first, or `unavailable/ready_timeout` after the host's `readyTimeout`; the reference\n\t * is released then.\n\t */\n\tget<C extends AnyContract>(type: C, input: InputOf<C>, options?: GetOptions<P>): Promise<Ref<C>>;\n}\n\nexport type StateEvent<T> =\n\t| { readonly type: \"snap\"; readonly value: T }\n\t| { readonly type: \"ops\"; readonly ops: readonly Op[]; readonly value: T }\n\t| { readonly type: \"reset\"; readonly value: T };\n\n/** A readable state source: a cell, a derivation, or a reference's state member. Values are immutable by contract. */\nexport interface Readable<T> {\n\treadonly value: T;\n\t/** Called with the current value immediately, then with every new value. */\n\tsubscribe(listener: (value: T) => void): () => void;\n\t/** Delta stream: a snapshot immediately, then ops, or a reset after a migration or rebind. */\n\tevents(listener: (event: StateEvent<T>) => void): () => void;\n}\n\n/**\n * What an implementation may expose as a state member: a cell, a derivation, or a held object's state member (an\n * object goes live only once the members it exposes have their values).\n */\nexport type StateSource<T> = Readable<T>;\n\ndeclare const EXPOSED: unique symbol;\n\n/** A local member backed by a resource (`self.expose(res.x)`): references read the resource's value once live. */\nexport interface Exposed<T> {\n\treadonly [EXPOSED]: T;\n}\n\nexport type RefStatus = \"loading\" | \"live\" | \"released\" | \"gone\";\n\nexport interface Shape {\n\treadonly variant: string | undefined;\n\treadonly members: readonly string[];\n\t/** Fingerprint of the provider contract. */\n\treadonly contract: string;\n}\n\nexport interface RefBase<C extends AnyContract> {\n\t/** The consumer contract token this reference was bound with. */\n\treadonly contract: C;\n\treadonly status: RefStatus;\n\treadonly ready: Promise<void>;\n\treadonly variant: string | undefined;\n\treadonly shape: Shape | undefined;\n\t/** Why the reference is gone, if it is. */\n\treadonly error: unknown;\n\tonShape(listener: (shape: Shape) => void): () => void;\n\t/**\n\t * Called after every status change (`loading` → `live`, `live` → `loading` while a link reconnects, `released`,\n\t * `gone` with `error`). A UI watches for `gone` to `get` again.\n\t */\n\tonStatus(listener: (status: RefStatus, error: unknown) => void): () => void;\n\trelease(): void;\n}\n"]}
@@ -1,16 +1,15 @@
1
1
  import type { AcceptOptions } from "./connection.ts";
2
2
  import type { Host } from "./host.ts";
3
3
  import { type WebSocketLike } from "./link.ts";
4
- import type { Principal } from "./types.ts";
5
4
  /** A WebSocket server (e.g. `ws`'s `WebSocketServer`), structurally: Chord does not depend on `ws`. */
6
5
  export interface WebSocketServerLike<Request> {
7
6
  on(event: "connection", listener: (socket: WebSocketLike, request: Request) => void): unknown;
8
7
  }
9
- /** WebSocket peers are always accepted as clients: no roots, no epochs, no reload votes, not addressable. */
10
- export interface WebSocketAcceptOptions<Request> extends Omit<AcceptOptions, "principal" | "kind" | "name"> {
8
+ /** WebSocket peers are always accepted as clients: no roots, no code versions, no reload votes, not addressable. */
9
+ export interface WebSocketAcceptOptions<Request, P = unknown> extends Omit<AcceptOptions<P>, "principal" | "kind" | "name"> {
11
10
  /** The authenticator: the principal of the connecting client, or undefined to refuse it. */
12
- principal(request: Request): Principal | undefined | Promise<Principal | undefined>;
11
+ principal(request: Request): P | undefined | Promise<P | undefined>;
13
12
  }
14
13
  /** Accepts every connection of `server` on `host` as a client link stamped with the authenticated principal. */
15
- export declare function acceptWebSockets<Request>(server: WebSocketServerLike<Request>, host: Host, options: WebSocketAcceptOptions<Request>): void;
14
+ export declare function acceptWebSockets<Request, P = unknown>(server: WebSocketServerLike<Request>, host: Host<P>, options: WebSocketAcceptOptions<Request, P>): void;
16
15
  //# sourceMappingURL=websocket.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,uGAAuG;AACvG,MAAM,WAAW,mBAAmB,CAAC,OAAO;IAC3C,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC;CAC9F;AAED,6GAA6G;AAC7G,MAAM,WAAW,sBAAsB,CAAC,OAAO,CAAE,SAAQ,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;IAC1G,4FAA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,CAAC,CAAC,GACzC,IAAI,CAaN"}
package/dist/websocket.js CHANGED
@@ -2,8 +2,9 @@ import { webSocketLink } from "./link.js";
2
2
  /** Accepts every connection of `server` on `host` as a client link stamped with the authenticated principal. */
3
3
  export function acceptWebSockets(server, host, options) {
4
4
  server.on("connection", (socket, request) => {
5
- // Wrap at once so frames sent while authenticating are queued, not lost.
6
- const link = webSocketLink(socket);
5
+ // Wrap at once so frames sent while authenticating are queued, not lost. Large payloads go out deflated; clients
6
+ // may not send packed frames (a small message could inflate to anything).
7
+ const link = webSocketLink(socket, { compress: true, acceptPacked: false });
7
8
  Promise.resolve(options.principal(request)).then((principal) => {
8
9
  if (principal === undefined)
9
10
  link.close("unauthorized");
@@ -1 +1 @@
1
- {"version":3,"file":"websocket.js","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,aAAa,EAAE,MAAM,WAAW,CAAC;AAc9D,gHAAgH;AAChH,MAAM,UAAU,gBAAgB,CAC/B,MAAoC,EACpC,IAAU,EACV,OAAwC;IAExC,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QAC3C,yEAAyE;QACzE,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAC/C,CAAC,SAAS,EAAE,EAAE;YACb,IAAI,SAAS,KAAK,SAAS;gBAAE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;;gBACnD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QACnE,CAAC,EACD,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,CACzC,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { AcceptOptions } from \"./connection.ts\";\nimport type { Host } from \"./host.ts\";\nimport { type WebSocketLike, webSocketLink } from \"./link.ts\";\nimport type { Principal } from \"./types.ts\";\n\n/** A WebSocket server (e.g. `ws`'s `WebSocketServer`), structurally: Chord does not depend on `ws`. */\nexport interface WebSocketServerLike<Request> {\n\ton(event: \"connection\", listener: (socket: WebSocketLike, request: Request) => void): unknown;\n}\n\n/** WebSocket peers are always accepted as clients: no roots, no epochs, no reload votes, not addressable. */\nexport interface WebSocketAcceptOptions<Request> extends Omit<AcceptOptions, \"principal\" | \"kind\" | \"name\"> {\n\t/** The authenticator: the principal of the connecting client, or undefined to refuse it. */\n\tprincipal(request: Request): Principal | undefined | Promise<Principal | undefined>;\n}\n\n/** Accepts every connection of `server` on `host` as a client link stamped with the authenticated principal. */\nexport function acceptWebSockets<Request>(\n\tserver: WebSocketServerLike<Request>,\n\thost: Host,\n\toptions: WebSocketAcceptOptions<Request>,\n): void {\n\tserver.on(\"connection\", (socket, request) => {\n\t\t// Wrap at once so frames sent while authenticating are queued, not lost.\n\t\tconst link = webSocketLink(socket);\n\t\tPromise.resolve(options.principal(request)).then(\n\t\t\t(principal) => {\n\t\t\t\tif (principal === undefined) link.close(\"unauthorized\");\n\t\t\t\telse host.accept(link, { ...options, principal, kind: \"client\" });\n\t\t\t},\n\t\t\t() => link.close(\"authentication failed\"),\n\t\t);\n\t});\n}\n"]}
1
+ {"version":3,"file":"websocket.js","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,aAAa,EAAE,MAAM,WAAW,CAAC;AAc9D,gHAAgH;AAChH,MAAM,UAAU,gBAAgB,CAC/B,MAAoC,EACpC,IAAa,EACb,OAA2C;IAE3C,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QAC3C,iHAAiH;QACjH,0EAA0E;QAC1E,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5E,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAC/C,CAAC,SAAS,EAAE,EAAE;YACb,IAAI,SAAS,KAAK,SAAS;gBAAE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;;gBACnD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QACnE,CAAC,EACD,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,CACzC,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { AcceptOptions } from \"./connection.ts\";\nimport type { Host } from \"./host.ts\";\nimport { type WebSocketLike, webSocketLink } from \"./link.ts\";\n\n/** A WebSocket server (e.g. `ws`'s `WebSocketServer`), structurally: Chord does not depend on `ws`. */\nexport interface WebSocketServerLike<Request> {\n\ton(event: \"connection\", listener: (socket: WebSocketLike, request: Request) => void): unknown;\n}\n\n/** WebSocket peers are always accepted as clients: no roots, no code versions, no reload votes, not addressable. */\nexport interface WebSocketAcceptOptions<Request, P = unknown>\n\textends Omit<AcceptOptions<P>, \"principal\" | \"kind\" | \"name\"> {\n\t/** The authenticator: the principal of the connecting client, or undefined to refuse it. */\n\tprincipal(request: Request): P | undefined | Promise<P | undefined>;\n}\n\n/** Accepts every connection of `server` on `host` as a client link stamped with the authenticated principal. */\nexport function acceptWebSockets<Request, P = unknown>(\n\tserver: WebSocketServerLike<Request>,\n\thost: Host<P>,\n\toptions: WebSocketAcceptOptions<Request, P>,\n): void {\n\tserver.on(\"connection\", (socket, request) => {\n\t\t// Wrap at once so frames sent while authenticating are queued, not lost. Large payloads go out deflated; clients\n\t\t// may not send packed frames (a small message could inflate to anything).\n\t\tconst link = webSocketLink(socket, { compress: true, acceptPacked: false });\n\t\tPromise.resolve(options.principal(request)).then(\n\t\t\t(principal) => {\n\t\t\t\tif (principal === undefined) link.close(\"unauthorized\");\n\t\t\t\telse host.accept(link, { ...options, principal, kind: \"client\" });\n\t\t\t},\n\t\t\t() => link.close(\"authentication failed\"),\n\t\t);\n\t});\n}\n"]}