@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/remote.js.map
CHANGED
|
@@ -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;AACzC,OAAO,EACN,OAAO,EACP,WAAW,EAGX,YAAY,EACZ,YAAY,EACZ,UAAU,GAEV,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,aAAa,EAAgC,MAAM,WAAW,CAAC;AAExE,MAAM,IAAI,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;AA0B5B;;;GAGG;AACH,MAAM,cAAc;IACV,OAAO,CAAe;IACtB,KAAK,CAAS;IACd,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IAC9C,OAAO,GAAG,IAAI,GAAG,EAAwC,CAAC;IACnE,IAAI,CAAuE;IAC3E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AQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YACrE,MAAM,IAAI,GAAG,WAAW,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACtG,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3G,CAAC;IACF,CAAC;IAED,QAAQ;QACP,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,IAAI,MAAM,GAA6B,IAAI,CAAC;QAC5C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;YAChD,OAAO,GAAG,IAAI,CAAC;YACf,MAAM,GAAG,IAAI,CAAC;QACf,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;CACD","sourcesContent":["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.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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"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SqliteDatabase, SqliteExecutor, SqliteValue } from "./database.ts";
|
|
2
|
+
/** Values a Durable Object SQL binding accepts and returns. */
|
|
3
|
+
type DurableObjectSqlValue = ArrayBuffer | string | number | null;
|
|
4
|
+
/**
|
|
5
|
+
* The parts of a SQLite-backed Durable Object's `ctx.storage` this adapter uses, typed structurally so the package
|
|
6
|
+
* needs no Workers type dependency.
|
|
7
|
+
*/
|
|
8
|
+
export type DurableObjectSqliteStorage = {
|
|
9
|
+
readonly sql: {
|
|
10
|
+
exec(query: string, ...bindings: DurableObjectSqlValue[]): {
|
|
11
|
+
next(): {
|
|
12
|
+
readonly done?: false;
|
|
13
|
+
readonly value: Record<string, DurableObjectSqlValue>;
|
|
14
|
+
} | {
|
|
15
|
+
readonly done: true;
|
|
16
|
+
readonly value?: undefined;
|
|
17
|
+
};
|
|
18
|
+
toArray(): Record<string, DurableObjectSqlValue>[];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
transaction<T>(closure: () => Promise<T>): Promise<T>;
|
|
22
|
+
};
|
|
23
|
+
/** Executes SQL through `ctx.storage.sql`, which has no separate prepare step. */
|
|
24
|
+
declare class DurableObjectSqliteExecutor implements SqliteExecutor {
|
|
25
|
+
protected readonly storage: DurableObjectSqliteStorage;
|
|
26
|
+
constructor(storage: DurableObjectSqliteStorage);
|
|
27
|
+
exec(sql: string): Promise<void>;
|
|
28
|
+
run(sql: string, ...params: SqliteValue[]): Promise<void>;
|
|
29
|
+
get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
|
|
30
|
+
all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
|
|
31
|
+
/** Throws when this handle may no longer run SQL. */
|
|
32
|
+
protected check(): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `SqliteDatabase` adapter for the SQLite storage of a Cloudflare Durable Object. Adapters given the same storage
|
|
36
|
+
* object share a queue; direct calls to the underlying storage bypass it. Integers are JavaScript numbers; binding a
|
|
37
|
+
* `bigint` outside the safe integer range throws.
|
|
38
|
+
*/
|
|
39
|
+
export declare class DurableObjectSqliteDatabase extends DurableObjectSqliteExecutor implements SqliteDatabase {
|
|
40
|
+
private readonly queue;
|
|
41
|
+
constructor(storage: DurableObjectSqliteStorage);
|
|
42
|
+
exec(sql: string): Promise<void>;
|
|
43
|
+
run(sql: string, ...params: SqliteValue[]): Promise<void>;
|
|
44
|
+
get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
|
|
45
|
+
all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
|
|
46
|
+
/** `ctx.storage.transaction()` commits when the callback resolves and rolls back when it rejects. */
|
|
47
|
+
transaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T>;
|
|
48
|
+
/** Waits for queued work. The Durable Object owns its storage, so nothing else closes. */
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/sqlite/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjF,+DAA+D;AAC/D,KAAK,qBAAqB,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACxC,QAAQ,CAAC,GAAG,EAAE;QACb,IAAI,CACH,KAAK,EAAE,MAAM,EACb,GAAG,QAAQ,EAAE,qBAAqB,EAAE,GAClC;YACF,IAAI,IACD;gBAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;gBAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAA;aAAE,GAChF;gBAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;gBAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAA;aAAE,CAAC;YACvD,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,EAAE,CAAC;SACnD,CAAC;KACF,CAAC;IACF,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtD,CAAC;AAiEF,kFAAkF;AAClF,cAAM,2BAA4B,YAAW,cAAc;IAC1D,SAAS,C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F;IAED,qGAAqG;IACrG,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,WAAW,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAWhF;IAED,0FAA0F;IAC1F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAErB;CACD"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/** Runs synchronous operations immediately when idle and holds queued calls behind a transaction. */
|
|
2
|
+
class SerialQueue {
|
|
3
|
+
tail = Promise.resolve();
|
|
4
|
+
pending = 0;
|
|
5
|
+
run(operation) {
|
|
6
|
+
if (this.pending > 0)
|
|
7
|
+
return this.enqueue(operation);
|
|
8
|
+
try {
|
|
9
|
+
return Promise.resolve(operation());
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
return Promise.reject(error);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
hold(operation) {
|
|
16
|
+
return this.enqueue(operation);
|
|
17
|
+
}
|
|
18
|
+
enqueue(operation) {
|
|
19
|
+
this.pending++;
|
|
20
|
+
const result = this.tail.then(operation).finally(() => {
|
|
21
|
+
this.pending--;
|
|
22
|
+
});
|
|
23
|
+
this.tail = result.then(() => { }, () => { });
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const storageQueues = new WeakMap();
|
|
28
|
+
function queueFor(storage) {
|
|
29
|
+
let queue = storageQueues.get(storage);
|
|
30
|
+
if (queue === undefined) {
|
|
31
|
+
queue = new SerialQueue();
|
|
32
|
+
storageQueues.set(storage, queue);
|
|
33
|
+
}
|
|
34
|
+
return queue;
|
|
35
|
+
}
|
|
36
|
+
/** Durable Object SQL binds numbers as doubles: a `bigint` outside the safe integer range would lose precision. */
|
|
37
|
+
function bindValue(value) {
|
|
38
|
+
if (value instanceof Uint8Array)
|
|
39
|
+
return value.slice().buffer;
|
|
40
|
+
if (typeof value !== "bigint")
|
|
41
|
+
return value;
|
|
42
|
+
if (value < BigInt(Number.MIN_SAFE_INTEGER) || value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
43
|
+
throw new RangeError(`Durable Object SQL cannot bind ${value} without losing precision`);
|
|
44
|
+
}
|
|
45
|
+
return Number(value);
|
|
46
|
+
}
|
|
47
|
+
const bind = (params) => params.map(bindValue);
|
|
48
|
+
/** A row as returned, with `BLOB` columns converted to `Uint8Array` in place; no other copy is made. */
|
|
49
|
+
function row(row) {
|
|
50
|
+
for (const key in row) {
|
|
51
|
+
const value = row[key];
|
|
52
|
+
if (value instanceof ArrayBuffer)
|
|
53
|
+
row[key] = new Uint8Array(value);
|
|
54
|
+
}
|
|
55
|
+
return row;
|
|
56
|
+
}
|
|
57
|
+
/** Executes SQL through `ctx.storage.sql`, which has no separate prepare step. */
|
|
58
|
+
class DurableObjectSqliteExecutor {
|
|
59
|
+
storage;
|
|
60
|
+
constructor(storage) {
|
|
61
|
+
this.storage = storage;
|
|
62
|
+
}
|
|
63
|
+
async exec(sql) {
|
|
64
|
+
this.check();
|
|
65
|
+
this.storage.sql.exec(sql);
|
|
66
|
+
}
|
|
67
|
+
async run(sql, ...params) {
|
|
68
|
+
this.check();
|
|
69
|
+
this.storage.sql.exec(sql, ...bind(params));
|
|
70
|
+
}
|
|
71
|
+
async get(sql, ...params) {
|
|
72
|
+
this.check();
|
|
73
|
+
const result = this.storage.sql.exec(sql, ...bind(params)).next();
|
|
74
|
+
return result.done ? undefined : row(result.value);
|
|
75
|
+
}
|
|
76
|
+
async all(sql, ...params) {
|
|
77
|
+
this.check();
|
|
78
|
+
return this.storage.sql
|
|
79
|
+
.exec(sql, ...bind(params))
|
|
80
|
+
.toArray()
|
|
81
|
+
.map((value) => row(value));
|
|
82
|
+
}
|
|
83
|
+
/** Throws when this handle may no longer run SQL. */
|
|
84
|
+
check() { }
|
|
85
|
+
}
|
|
86
|
+
/** The handle a transaction callback receives; invalid once the callback settles. */
|
|
87
|
+
class DurableObjectSqliteTransaction extends DurableObjectSqliteExecutor {
|
|
88
|
+
active = true;
|
|
89
|
+
check() {
|
|
90
|
+
if (!this.active)
|
|
91
|
+
throw new Error("SQLite transaction handle is no longer active");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* `SqliteDatabase` adapter for the SQLite storage of a Cloudflare Durable Object. Adapters given the same storage
|
|
96
|
+
* object share a queue; direct calls to the underlying storage bypass it. Integers are JavaScript numbers; binding a
|
|
97
|
+
* `bigint` outside the safe integer range throws.
|
|
98
|
+
*/
|
|
99
|
+
export class DurableObjectSqliteDatabase extends DurableObjectSqliteExecutor {
|
|
100
|
+
queue;
|
|
101
|
+
constructor(storage) {
|
|
102
|
+
super(storage);
|
|
103
|
+
this.queue = queueFor(storage);
|
|
104
|
+
}
|
|
105
|
+
exec(sql) {
|
|
106
|
+
return this.queue.run(() => super.exec(sql));
|
|
107
|
+
}
|
|
108
|
+
run(sql, ...params) {
|
|
109
|
+
return this.queue.run(() => super.run(sql, ...params));
|
|
110
|
+
}
|
|
111
|
+
get(sql, ...params) {
|
|
112
|
+
return this.queue.run(() => super.get(sql, ...params));
|
|
113
|
+
}
|
|
114
|
+
all(sql, ...params) {
|
|
115
|
+
return this.queue.run(() => super.all(sql, ...params));
|
|
116
|
+
}
|
|
117
|
+
/** `ctx.storage.transaction()` commits when the callback resolves and rolls back when it rejects. */
|
|
118
|
+
transaction(callback) {
|
|
119
|
+
return this.queue.hold(() => this.storage.transaction(async () => {
|
|
120
|
+
const transaction = new DurableObjectSqliteTransaction(this.storage);
|
|
121
|
+
try {
|
|
122
|
+
return await callback(transaction);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
transaction.active = false;
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
/** Waits for queued work. The Durable Object owns its storage, so nothing else closes. */
|
|
130
|
+
close() {
|
|
131
|
+
return this.queue.run(() => { });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=cloudflare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../../src/sqlite/cloudflare.ts"],"names":[],"mappings":"AAwBA,qGAAqG;AACrG,MAAM,WAAW;IACR,IAAI,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IACxC,OAAO,GAAG,CAAC,CAAC;IAEpB,GAAG,CAAI,SAA+B;QACrC,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,CAAC;YACJ,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,IAAI,CAAI,SAA2B;QAClC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;IAEO,OAAO,CAAI,SAA+B;QACjD,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YACrD,IAAI,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CACtB,GAAG,EAAE,GAAE,CAAC,EACR,GAAG,EAAE,GAAE,CAAC,CACR,CAAC;QACF,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAED,MAAM,aAAa,GAAG,IAAI,OAAO,EAA2C,CAAC;AAE7E,SAAS,QAAQ,CAAC,OAAmC;IACpD,IAAI,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC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AAG,KAAK,CAAC;YAC5B,CAAC;QACF,CAAC,CAAC,CACF,CAAC;IACH,CAAC;IAED,0FAA0F;IAC1F,KAAK;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACjC,CAAC;CACD","sourcesContent":["import type { SqliteDatabase, SqliteExecutor, SqliteValue } from \"./database.ts\";\n\n/** Values a Durable Object SQL binding accepts and returns. */\ntype DurableObjectSqlValue = ArrayBuffer | string | number | null;\n\n/**\n * The parts of a SQLite-backed Durable Object's `ctx.storage` this adapter uses, typed structurally so the package\n * needs no Workers type dependency.\n */\nexport type DurableObjectSqliteStorage = {\n\treadonly sql: {\n\t\texec(\n\t\t\tquery: string,\n\t\t\t...bindings: DurableObjectSqlValue[]\n\t\t): {\n\t\t\tnext():\n\t\t\t\t| { readonly done?: false; readonly value: Record<string, DurableObjectSqlValue> }\n\t\t\t\t| { readonly done: true; readonly value?: undefined };\n\t\t\ttoArray(): Record<string, DurableObjectSqlValue>[];\n\t\t};\n\t};\n\ttransaction<T>(closure: () => Promise<T>): Promise<T>;\n};\n\n/** Runs synchronous operations immediately when idle and holds queued calls behind a transaction. */\nclass SerialQueue {\n\tprivate tail: Promise<void> = Promise.resolve();\n\tprivate pending = 0;\n\n\trun<T>(operation: () => T | Promise<T>): Promise<T> {\n\t\tif (this.pending > 0) return this.enqueue(operation);\n\t\ttry {\n\t\t\treturn Promise.resolve(operation());\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t}\n\n\thold<T>(operation: () => Promise<T>): Promise<T> {\n\t\treturn this.enqueue(operation);\n\t}\n\n\tprivate enqueue<T>(operation: () => T | Promise<T>): Promise<T> {\n\t\tthis.pending++;\n\t\tconst result = this.tail.then(operation).finally(() => {\n\t\t\tthis.pending--;\n\t\t});\n\t\tthis.tail = result.then(\n\t\t\t() => {},\n\t\t\t() => {},\n\t\t);\n\t\treturn result;\n\t}\n}\n\nconst storageQueues = new WeakMap<DurableObjectSqliteStorage, SerialQueue>();\n\nfunction queueFor(storage: DurableObjectSqliteStorage): SerialQueue {\n\tlet queue = storageQueues.get(storage);\n\tif (queue === undefined) {\n\t\tqueue = new SerialQueue();\n\t\tstorageQueues.set(storage, queue);\n\t}\n\treturn queue;\n}\n\n/** Durable Object SQL binds numbers as doubles: a `bigint` outside the safe integer range would lose precision. */\nfunction bindValue(value: SqliteValue): DurableObjectSqlValue {\n\tif (value instanceof Uint8Array) return value.slice().buffer as ArrayBuffer;\n\tif (typeof value !== \"bigint\") return value;\n\tif (value < BigInt(Number.MIN_SAFE_INTEGER) || value > BigInt(Number.MAX_SAFE_INTEGER)) {\n\t\tthrow new RangeError(`Durable Object SQL cannot bind ${value} without losing precision`);\n\t}\n\treturn Number(value);\n}\n\nconst bind = (params: readonly SqliteValue[]): DurableObjectSqlValue[] => params.map(bindValue);\n\n/** A row as returned, with `BLOB` columns converted to `Uint8Array` in place; no other copy is made. */\nfunction row<T>(row: Record<string, DurableObjectSqlValue>): T {\n\tfor (const key in row) {\n\t\tconst value = row[key];\n\t\tif (value instanceof ArrayBuffer) (row as Record<string, unknown>)[key] = new Uint8Array(value);\n\t}\n\treturn row as T;\n}\n\n/** Executes SQL through `ctx.storage.sql`, which has no separate prepare step. */\nclass DurableObjectSqliteExecutor implements SqliteExecutor {\n\tprotected readonly storage: DurableObjectSqliteStorage;\n\n\tconstructor(storage: DurableObjectSqliteStorage) {\n\t\tthis.storage = storage;\n\t}\n\n\tasync exec(sql: string): Promise<void> {\n\t\tthis.check();\n\t\tthis.storage.sql.exec(sql);\n\t}\n\n\tasync run(sql: string, ...params: SqliteValue[]): Promise<void> {\n\t\tthis.check();\n\t\tthis.storage.sql.exec(sql, ...bind(params));\n\t}\n\n\tasync get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined> {\n\t\tthis.check();\n\t\tconst result = this.storage.sql.exec(sql, ...bind(params)).next();\n\t\treturn result.done ? undefined : row<T>(result.value);\n\t}\n\n\tasync all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]> {\n\t\tthis.check();\n\t\treturn this.storage.sql\n\t\t\t.exec(sql, ...bind(params))\n\t\t\t.toArray()\n\t\t\t.map((value) => row<T>(value));\n\t}\n\n\t/** Throws when this handle may no longer run SQL. */\n\tprotected check(): void {}\n}\n\n/** The handle a transaction callback receives; invalid once the callback settles. */\nclass DurableObjectSqliteTransaction extends DurableObjectSqliteExecutor {\n\tactive = true;\n\n\tprotected override check(): void {\n\t\tif (!this.active) throw new Error(\"SQLite transaction handle is no longer active\");\n\t}\n}\n\n/**\n * `SqliteDatabase` adapter for the SQLite storage of a Cloudflare Durable Object. Adapters given the same storage\n * object share a queue; direct calls to the underlying storage bypass it. Integers are JavaScript numbers; binding a\n * `bigint` outside the safe integer range throws.\n */\nexport class DurableObjectSqliteDatabase extends DurableObjectSqliteExecutor implements SqliteDatabase {\n\tprivate readonly queue: SerialQueue;\n\n\tconstructor(storage: DurableObjectSqliteStorage) {\n\t\tsuper(storage);\n\t\tthis.queue = queueFor(storage);\n\t}\n\n\toverride exec(sql: string): Promise<void> {\n\t\treturn this.queue.run(() => super.exec(sql));\n\t}\n\n\toverride run(sql: string, ...params: SqliteValue[]): Promise<void> {\n\t\treturn this.queue.run(() => super.run(sql, ...params));\n\t}\n\n\toverride get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined> {\n\t\treturn this.queue.run(() => super.get<T>(sql, ...params));\n\t}\n\n\toverride all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]> {\n\t\treturn this.queue.run(() => super.all<T>(sql, ...params));\n\t}\n\n\t/** `ctx.storage.transaction()` commits when the callback resolves and rolls back when it rejects. */\n\ttransaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T> {\n\t\treturn this.queue.hold(() =>\n\t\t\tthis.storage.transaction(async () => {\n\t\t\t\tconst transaction = new DurableObjectSqliteTransaction(this.storage);\n\t\t\t\ttry {\n\t\t\t\t\treturn await callback(transaction);\n\t\t\t\t} finally {\n\t\t\t\t\ttransaction.active = false;\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t}\n\n\t/** Waits for queued work. The Durable Object owns its storage, so nothing else closes. */\n\tclose(): Promise<void> {\n\t\treturn this.queue.run(() => {});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Values supported by the portable SQLite drivers. */
|
|
2
|
+
export type SqliteValue = null | number | bigint | string | Uint8Array;
|
|
3
|
+
/**
|
|
4
|
+
* Asynchronous SQL operations shared by a database and its transaction handles.
|
|
5
|
+
*
|
|
6
|
+
* `exec` runs SQL text without bindings and may contain several statements. `run`, `get`, and `all`
|
|
7
|
+
* execute one statement with positional bindings. Adapters may cache prepared statements by SQL text,
|
|
8
|
+
* so callers pass values as bindings instead of interpolating them.
|
|
9
|
+
*/
|
|
10
|
+
export interface SqliteExecutor {
|
|
11
|
+
exec(sql: string): Promise<void>;
|
|
12
|
+
run(sql: string, ...params: SqliteValue[]): Promise<void>;
|
|
13
|
+
get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
|
|
14
|
+
all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Minimal portable SQLite database facade.
|
|
18
|
+
*
|
|
19
|
+
* All operations are asynchronous so adapters may execute outside the caller's runtime.
|
|
20
|
+
*
|
|
21
|
+
* `transaction` passes the callback a transaction handle. All work in the transaction
|
|
22
|
+
* must use that handle; the handle is invalid after the callback settles. Adapters must
|
|
23
|
+
* queue unrelated operations and other transactions until the transaction finishes. The
|
|
24
|
+
* returned promise settles after commit or rollback. Calling the database itself (including
|
|
25
|
+
* `transaction` or `close`) from inside a callback therefore waits for that transaction and
|
|
26
|
+
* never settles.
|
|
27
|
+
*
|
|
28
|
+
* When the callback rejects, the adapter must roll the transaction back before rejecting
|
|
29
|
+
* with that same error. If rollback fails, it must reject with a different error (for
|
|
30
|
+
* example an `AggregateError`) so callers cannot mistake the callback error for a
|
|
31
|
+
* guaranteed rollback.
|
|
32
|
+
*/
|
|
33
|
+
export interface SqliteDatabase extends SqliteExecutor {
|
|
34
|
+
transaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T>;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/sqlite/database.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACrF,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CAC3E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,cAAe,SAAQ,cAAc;IACrD,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,WAAW,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAClF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/sqlite/database.ts"],"names":[],"mappings":"","sourcesContent":["/** Values supported by the portable SQLite drivers. */\nexport type SqliteValue = null | number | bigint | string | Uint8Array;\n\n/**\n * Asynchronous SQL operations shared by a database and its transaction handles.\n *\n * `exec` runs SQL text without bindings and may contain several statements. `run`, `get`, and `all`\n * execute one statement with positional bindings. Adapters may cache prepared statements by SQL text,\n * so callers pass values as bindings instead of interpolating them.\n */\nexport interface SqliteExecutor {\n\texec(sql: string): Promise<void>;\n\trun(sql: string, ...params: SqliteValue[]): Promise<void>;\n\tget<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;\n\tall<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;\n}\n\n/**\n * Minimal portable SQLite database facade.\n *\n * All operations are asynchronous so adapters may execute outside the caller's runtime.\n *\n * `transaction` passes the callback a transaction handle. All work in the transaction\n * must use that handle; the handle is invalid after the callback settles. Adapters must\n * queue unrelated operations and other transactions until the transaction finishes. The\n * returned promise settles after commit or rollback. Calling the database itself (including\n * `transaction` or `close`) from inside a callback therefore waits for that transaction and\n * never settles.\n *\n * When the callback rejects, the adapter must roll the transaction back before rejecting\n * with that same error. If rollback fails, it must reject with a different error (for\n * example an `AggregateError`) so callers cannot mistake the callback error for a\n * guaranteed rollback.\n */\nexport interface SqliteDatabase extends SqliteExecutor {\n\ttransaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T>;\n\tclose(): Promise<void>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sqlite/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sqlite/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export type { SqliteDatabase, SqliteExecutor, SqliteValue } from \"./database.ts\";\nexport { applySqliteMigrations, type SqliteMigration } from \"./migrations.ts\";\nexport { validateSqliteSchemaPrefix } from \"./schema.ts\";\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SqliteDatabase } from "./database.ts";
|
|
2
|
+
export type SqliteMigration = {
|
|
3
|
+
readonly version: number;
|
|
4
|
+
readonly statements: readonly string[];
|
|
5
|
+
};
|
|
6
|
+
/** Apply all pending migrations atomically, tracking their version in the named metadata table. */
|
|
7
|
+
export declare function applySqliteMigrations(database: SqliteDatabase, migrations: readonly SqliteMigration[], options: {
|
|
8
|
+
readonly table: string;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/sqlite/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,CAAC;AAIF,mGAAmG;AACnG,wBAAsB,qBAAqB,CAC1C,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,SAAS,eAAe,EAAE,EACtC,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { validateSqliteSchemaPrefix } from "./schema.js";
|
|
2
|
+
/** Apply all pending migrations atomically, tracking their version in the named metadata table. */
|
|
3
|
+
export async function applySqliteMigrations(database, migrations, options) {
|
|
4
|
+
const { table } = options;
|
|
5
|
+
validateSqliteSchemaPrefix(table);
|
|
6
|
+
for (let index = 0; index < migrations.length; index++) {
|
|
7
|
+
if (migrations[index]?.version !== index + 1) {
|
|
8
|
+
throw new Error("SQLite migrations must have contiguous versions starting at 1");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
await database.transaction(async (transaction) => {
|
|
12
|
+
await transaction.exec(`CREATE TABLE IF NOT EXISTS ${table} (
|
|
13
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
14
|
+
version INTEGER NOT NULL CHECK (version >= 0)
|
|
15
|
+
) STRICT`);
|
|
16
|
+
await transaction.run(`INSERT OR IGNORE INTO ${table} (singleton, version) VALUES (1, 0)`);
|
|
17
|
+
const row = await transaction.get(`SELECT version FROM ${table} WHERE singleton = 1`);
|
|
18
|
+
if (row === undefined)
|
|
19
|
+
throw new Error("SQLite schema metadata is missing");
|
|
20
|
+
const currentVersion = migrations.at(-1)?.version ?? 0;
|
|
21
|
+
if (row.version > currentVersion) {
|
|
22
|
+
throw new Error(`SQLite schema version ${row.version} is newer than supported version ${currentVersion}`);
|
|
23
|
+
}
|
|
24
|
+
for (const migration of migrations) {
|
|
25
|
+
if (migration.version <= row.version)
|
|
26
|
+
continue;
|
|
27
|
+
for (const statement of migration.statements)
|
|
28
|
+
await transaction.exec(statement);
|
|
29
|
+
await transaction.run(`UPDATE ${table} SET version = ? WHERE singleton = 1`, migration.version);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mig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C,IAAI,SAAS,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO;gBAAE,SAAS;YAC/C,KAAK,MAAM,SAAS,IAAI,SAAS,CAAC,UAAU;gBAAE,MAAM,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAChF,MAAM,WAAW,CAAC,GAAG,CAAC,UAAU,KAAK,sCAAsC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;QACjG,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { SqliteDatabase } from \"./database.ts\";\nimport { validateSqliteSchemaPrefix } from \"./schema.ts\";\n\nexport type SqliteMigration = {\n\treadonly version: number;\n\treadonly statements: readonly string[];\n};\n\ntype SchemaRow = { readonly version: number };\n\n/** Apply all pending migrations atomically, tracking their version in the named metadata table. */\nexport async function applySqliteMigrations(\n\tdatabase: SqliteDatabase,\n\tmigrations: readonly SqliteMigration[],\n\toptions: { readonly table: string },\n): Promise<void> {\n\tconst { table } = options;\n\tvalidateSqliteSchemaPrefix(table);\n\tfor (let index = 0; index < migrations.length; index++) {\n\t\tif (migrations[index]?.version !== index + 1) {\n\t\t\tthrow new Error(\"SQLite migrations must have contiguous versions starting at 1\");\n\t\t}\n\t}\n\n\tawait database.transaction(async (transaction) => {\n\t\tawait transaction.exec(`CREATE TABLE IF NOT EXISTS ${table} (\n\t\t\tsingleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n\t\t\tversion INTEGER NOT NULL CHECK (version >= 0)\n\t\t) STRICT`);\n\t\tawait transaction.run(`INSERT OR IGNORE INTO ${table} (singleton, version) VALUES (1, 0)`);\n\t\tconst row = await transaction.get<SchemaRow>(`SELECT version FROM ${table} WHERE singleton = 1`);\n\t\tif (row === undefined) throw new Error(\"SQLite schema metadata is missing\");\n\t\tconst currentVersion = migrations.at(-1)?.version ?? 0;\n\t\tif (row.version > currentVersion) {\n\t\t\tthrow new Error(`SQLite schema version ${row.version} is newer than supported version ${currentVersion}`);\n\t\t}\n\t\tfor (const migration of migrations) {\n\t\t\tif (migration.version <= row.version) continue;\n\t\t\tfor (const statement of migration.statements) await transaction.exec(statement);\n\t\t\tawait transaction.run(`UPDATE ${table} SET version = ? WHERE singleton = 1`, migration.version);\n\t\t}\n\t});\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { StatementSync } from "node:sqlite";
|
|
2
|
+
import { DatabaseSync } from "node:sqlite";
|
|
3
|
+
import type { SqliteDatabase, SqliteExecutor, SqliteValue } from "./database.ts";
|
|
4
|
+
/** Node SQLite connection settings for a database file. */
|
|
5
|
+
export type NodeSqliteDatabaseOptions = {
|
|
6
|
+
/** SQLite WAL auto-checkpoint threshold. SQLite and this adapter default to 1,000 pages; 0 disables it. */
|
|
7
|
+
readonly walAutoCheckpointPages?: number;
|
|
8
|
+
/** Time SQLite waits for a competing file lock. SQLite defaults to 0; this adapter defaults to 5,000 ms. */
|
|
9
|
+
readonly busyTimeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Executes SQL on one connection. Prepared statements are cached per connection by SQL text, so the
|
|
13
|
+
* database and its transaction handles share them across transactions.
|
|
14
|
+
*/
|
|
15
|
+
declare abstract class NodeSqliteExecutor implements SqliteExecutor {
|
|
16
|
+
protected readonly database: DatabaseSync;
|
|
17
|
+
protected readonly statements: Map<string, StatementSync>;
|
|
18
|
+
constructor(database: DatabaseSync, statements: Map<string, StatementSync>);
|
|
19
|
+
exec(sql: string): Promise<void>;
|
|
20
|
+
run(sql: string, ...params: SqliteValue[]): Promise<void>;
|
|
21
|
+
get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
|
|
22
|
+
all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
|
|
23
|
+
protected abstract runOperation<T>(operation: () => T): Promise<T>;
|
|
24
|
+
private statement;
|
|
25
|
+
}
|
|
26
|
+
/** `SqliteDatabase` adapter backed by Node's built-in `node:sqlite`. */
|
|
27
|
+
export declare class NodeSqliteDatabase extends NodeSqliteExecutor implements SqliteDatabase {
|
|
28
|
+
private readonly access;
|
|
29
|
+
private closed;
|
|
30
|
+
constructor(database: DatabaseSync);
|
|
31
|
+
transaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T>;
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
protected runOperation<T>(operation: () => T): Promise<T>;
|
|
34
|
+
}
|
|
35
|
+
/** Open and configure a Node-backed SQLite database facade. */
|
|
36
|
+
export declare function openNodeSqliteDatabase(path: string, options?: NodeSqliteDatabaseOptions): Promise<NodeSqliteDatabase>;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/sqlite/node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjF,2DAA2D;AAC3D,MAAM,MAAM,yBAAyB,GAAG;IACvC,2GAA2G;IAC3G,QAAQ,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IACzC,4GAA4G;IAC5G,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AA0DF;;;GAGG;AACH,uBAAe,kBAAmB,YAAW,cAAc;IAC1D,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAC1C,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAE1D,YAAY,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,EAGzE;IAED,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG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