@tinycloud/node-sdk 3.2.0-beta.4 → 3.2.0-beta.6
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/dist/{WasmKeyProvider-DjfRu9aL.d.cts → WasmKeyProvider-C3NFgOmv.d.cts} +24 -5
- package/dist/{WasmKeyProvider-DjfRu9aL.d.ts → WasmKeyProvider-C3NFgOmv.d.ts} +24 -5
- package/dist/{authority-mTQEgN56.d.cts → authority-DDGtccBK.d.cts} +5 -6
- package/dist/{authority-mTQEgN56.d.ts → authority-DDGtccBK.d.ts} +5 -6
- package/dist/core.cjs +78 -44
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.js +80 -45
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +130 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +121 -65
- package/dist/index.js.map +1 -1
- package/dist/replication/authority.cjs +51 -37
- package/dist/replication/authority.cjs.map +1 -1
- package/dist/replication/authority.d.cts +1 -1
- package/dist/replication/authority.d.ts +1 -1
- package/dist/replication/authority.js +48 -36
- package/dist/replication/authority.js.map +1 -1
- package/dist/replication/runtime.cjs +1 -0
- package/dist/replication/runtime.cjs.map +1 -1
- package/dist/replication/runtime.d.cts +1 -1
- package/dist/replication/runtime.d.ts +1 -1
- package/dist/replication/runtime.js +1 -0
- package/dist/replication/runtime.js.map +1 -1
- package/dist/{runtime-DyYwHW8j.d.cts → runtime-B5P5SRpC.d.cts} +1 -0
- package/dist/{runtime-DyYwHW8j.d.ts → runtime-B5P5SRpC.d.ts} +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/replication/runtime.ts"],"sourcesContent":["import { pkhDid } from \"@tinycloud/sdk-core\";\nimport type { FetchFunction, ServiceContext, ServiceSession } from \"@tinycloud/sdk-core\";\nimport type {\n KVReadThrough,\n KVReplicaStorage,\n KVReplicationController,\n PendingWriteStore,\n ReplicationAuthority,\n ReplicationControl,\n ReplicationEvent,\n ReplicationIdentity,\n ReplicationOptions,\n ReplicationScheduler,\n} from \"@tinycloud/sdk-services\";\ntype ReplicationServices = typeof import(\"@tinycloud/sdk-services/kv/replication\");\n\nexport interface ReplicationRuntimeOptions extends ReplicationOptions {\n storage: KVReplicaStorage;\n mode?: \"background\" | \"foreground\";\n}\n\nexport interface ReplicationRuntimeBinding {\n context: ServiceContext;\n session: ServiceSession;\n address?: string;\n chainId?: number;\n principal?: string;\n authority: ReplicationAuthority;\n primaryKV: Array<{ space: string; kv: { setReadThrough(readThrough: KVReadThrough | null): void } }>;\n}\n\nconst scheduler: ReplicationScheduler = {\n now: () => Date.now(),\n setTimeout(fn, ms) {\n const timer = setTimeout(fn, ms);\n timer.unref?.();\n return () => clearTimeout(timer);\n },\n};\n\nfunction resolvedOptions(options: ReplicationRuntimeOptions) {\n return {\n ...options,\n syncIntervalMs: options.syncIntervalMs ?? 60_000,\n maxStalenessMs: options.maxStalenessMs ?? 120_000,\n staleSyncTimeoutMs: options.staleSyncTimeoutMs ?? 5_000,\n allowSecrets: options.allowSecrets === true,\n verify: options.verify === true,\n };\n}\ntype ReadThroughKV = {\n setReadThrough(readThrough: KVReadThrough | null): void;\n setReadThroughReady?(ready: Promise<unknown>): void;\n};\n\nexport class ReplicationRuntime {\n readonly control: ReplicationControl;\n private readonly pending = new Map<string, PendingWriteStore>();\n private readonly attached = new Map<ReadThroughKV, string>();\n private current?: KVReplicationController;\n private lastController?: KVReplicationController;\n private previous: Promise<void> = Promise.resolve();\n private binding: Promise<void> = Promise.resolve();\n private services?: Promise<ReplicationServices>;\n private generation = 0;\n private lastIdentity?: ReplicationIdentity;\n private lastPending?: PendingWriteStore;\n private primarySpace?: string;\n private pendingPurge?: Parameters<KVReplicationController[\"purge\"]>[0];\n private pendingPurgeResult?: ReturnType<KVReplicationController[\"purge\"]>;\n private bindingActive = false;\n private pendingPurgeSet = false;\n private purgedGeneration?: number;\n private closed = false;\n constructor(\n private readonly options: ReplicationRuntimeOptions,\n private readonly clock: ReplicationScheduler = scheduler,\n ) {\n this.control = {\n status: async () => {\n await this.binding;\n return this.current ? this.current.status() : [];\n },\n sync: async (input) => {\n await this.binding;\n if (this.purgedGeneration === this.generation) return;\n if (this.current) await this.current.sync(input);\n },\n purge: (input) => {\n if (this.bindingActive) {\n this.pendingPurge = input;\n this.pendingPurgeSet = true;\n const existing = this.current ?? this.lastController;\n if (existing) {\n this.pendingPurgeResult = existing.purge(input);\n this.purgedGeneration = this.generation;\n }\n return this.binding.then(() => this.pendingPurgeResult ?? { purged: [], failed: [] });\n }\n const controller = this.current ?? this.lastController;\n if (!controller) return Promise.resolve({ purged: [], failed: [] });\n this.purgedGeneration = this.generation;\n return controller.purge(input);\n },\n clearPending: async () => {\n await this.binding;\n if (this.current) return this.current.clearPending();\n const pending = this.lastPending;\n if (!pending) return 0;\n return pending.update((state) => {\n const before = state.records.length;\n state.records = state.records.filter((record) =>\n record.state === \"committed\" ||\n (record.state === \"in_flight\" && this.clock.now() - Date.parse(record.at) <= 10 * 60_000),\n );\n return before - state.records.length;\n });\n },\n close: async () => {\n this.closed = true;\n this.unbind();\n await this.binding.catch(() => undefined);\n await this.previous;\n },\n };\n }\n\n private loadServices(): Promise<ReplicationServices> {\n return (this.services ??= import(\"@tinycloud/sdk-services/kv/replication\"));\n }\n\n private detachAll(): void {\n for (const kv of this.attached.keys()) kv.setReadThrough(null);\n this.attached.clear();\n }\n\n bind(input: ReplicationRuntimeBinding): Promise<void> {\n if (this.closed || !this.options.enabled) return Promise.resolve();\n this.bindingActive = true;\n const generation = ++this.generation;\n this.purgedGeneration = undefined;\n const { context, session } = input;\n const emit = (event: ReplicationEvent): void => {\n try { this.options.onEvent?.(event); } catch { /* Observability must not affect KV behavior. */ }\n const { type, ...data } = event;\n context.emit(type, data);\n };\n const previous = this.current;\n this.current = undefined;\n for (const kv of this.attached.keys()) kv.setReadThrough(null);\n this.primarySpace = session.spaceId;\n const close = previous ? previous.close().catch(() => undefined) : Promise.resolve();\n this.previous = this.previous.then(() => close);\n const previousClose = this.previous;\n this.binding = this.loadServices().then((services) => {\n if (generation !== this.generation || this.closed) return;\n let identity: ReplicationIdentity;\n try {\n identity = services.canonicalReplicationIdentity({\n host: context.hosts[0]!,\n space: session.spaceId,\n principal: input.principal ?? pkhDid(input.address!, input.chainId!),\n });\n } catch {\n for (const prefix of this.options.prefixes) {\n emit({ type: \"replication.state\", at: new Date(this.clock.now()).toISOString(), space: session.spaceId, replica: prefix, state: \"unavailable\", code: \"CONFIG_INVALID\" });\n }\n return;\n }\n const key = services.replicationIdentityKey(identity);\n let pending = this.pending.get(key);\n if (!pending) {\n pending = this.options.storage.pendingWrites?.(identity) ?? services.createMemoryPendingStore(identity);\n this.pending.set(key, pending);\n }\n this.lastPending = pending;\n const controller = services.createKVReplication({\n options: resolvedOptions(this.options),\n mode: this.options.mode ?? \"background\",\n storage: this.options.storage,\n identity,\n session: { id: session.delegationCid, did: session.verificationMethod, space: session.spaceId },\n authority: input.authority,\n pending,\n scheduler: this.clock,\n emit,\n fetch: context.fetch as FetchFunction,\n previous: previousClose,\n });\n this.current = controller;\n this.lastController = controller;\n this.lastIdentity = identity;\n for (const [kv, space] of this.attached) {\n kv.setReadThrough(space === this.primarySpace ? controller : null);\n }\n for (const scoped of input.primaryKV) this.attach(scoped.space, scoped.kv);\n if (this.pendingPurgeSet) {\n this.pendingPurgeResult = controller.purge(this.pendingPurge);\n this.purgedGeneration = generation;\n this.pendingPurge = undefined;\n this.pendingPurgeSet = false;\n }\n }).finally(() => {\n if (generation === this.generation) this.bindingActive = false;\n });\n for (const kv of this.attached.keys()) kv.setReadThroughReady?.(this.binding);\n return this.binding;\n }\n\n attach(space: string, kv: ReadThroughKV): Promise<void> {\n this.attached.set(kv, space);\n kv.setReadThrough(space === this.primarySpace ? this.current ?? null : null);\n return this.binding.then(() => {\n kv.setReadThrough(space === this.primarySpace ? this.current ?? null : null);\n });\n }\n\n unbind(): Promise<void> {\n this.generation++;\n this.bindingActive = false;\n this.pendingPurgeSet = false;\n const controller = this.current;\n this.current = undefined;\n this.primarySpace = undefined;\n this.detachAll();\n const binding = this.binding;\n const close = binding.then(() => controller?.close()).catch(() => undefined);\n this.previous = this.previous.then(() => close);\n return this.previous;\n }\n\n get boundIdentity(): ReplicationIdentity | undefined {\n return this.lastIdentity;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AA+BvB,IAAM,YAAkC;AAAA,EACtC,KAAK,MAAM,KAAK,IAAI;AAAA,EACpB,WAAW,IAAI,IAAI;AACjB,UAAM,QAAQ,WAAW,IAAI,EAAE;AAC/B,UAAM,QAAQ;AACd,WAAO,MAAM,aAAa,KAAK;AAAA,EACjC;AACF;AAEA,SAAS,gBAAgB,SAAoC;AAC3D,SAAO;AAAA,IACL,GAAG;AAAA,IACH,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,oBAAoB,QAAQ,sBAAsB;AAAA,IAClD,cAAc,QAAQ,iBAAiB;AAAA,IACvC,QAAQ,QAAQ,WAAW;AAAA,EAC7B;AACF;AAMO,IAAM,qBAAN,MAAyB;AAAA,EAmB9B,YACmB,SACA,QAA8B,WAC/C;AAFiB;AACA;AAnBnB,SAAiB,UAAU,oBAAI,IAA+B;AAC9D,SAAiB,WAAW,oBAAI,IAA2B;AAG3D,SAAQ,WAA0B,QAAQ,QAAQ;AAClD,SAAQ,UAAyB,QAAQ,QAAQ;AAEjD,SAAQ,aAAa;AAMrB,SAAQ,gBAAgB;AACxB,SAAQ,kBAAkB;AAE1B,SAAQ,SAAS;AAKf,SAAK,UAAU;AAAA,MACb,QAAQ,YAAY;AAClB,cAAM,KAAK;AACX,eAAO,KAAK,UAAU,KAA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AACxB,aAAK,eAAe;AACpB,aAAK,kBAAkB;AAAA,MACzB;AAAA,IACF,CAAC,EAAE,QAAQ,MAAM;AACf,UAAI,eAAe,KAAK,WAAY,MAAK,gBAAgB;AAAA,IAC3D,CAAC;AACD,eAAW,MAAM,KAAK,SAAS,KAAK,EAAG,IAAG,sBAAsB,KAAK,OAAO;AAC5E,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,OAAO,OAAe,IAAkC;AACtD,SAAK,SAAS,IAAI,IAAI,KAAK;AAC3B,OAAG,eAAe,UAAU,KAAK,eAAe,KAAK,WAAW,OAAO,IAAI;AAC3E,WAAO,KAAK,QAAQ,KAAK,MAAM;AAC7B,SAAG,eAAe,UAAU,KAAK,eAAe,KAAK,WAAW,OAAO,IAAI;AAAA,IAC7E,CAAC;AAAA,EACH;AAAA,EAEA,SAAwB;AACtB,SAAK;AACL,SAAK,gBAAgB;AACrB,SAAK,kBAAkB;AACvB,UAAM,aAAa,KAAK;AACxB,SAAK,UAAU;AACf,SAAK,eAAe;AACpB,SAAK,UAAU;AACf,UAAM,UAAU,KAAK;AACrB,UAAM,QAAQ,QAAQ,KAAK,MAAM,YAAY,MAAM,CAAC,EAAE,MAAM,MAAM,MAAS;AAC3E,SAAK,WAAW,KAAK,SAAS,KAAK,MAAM,KAAK;AAC9C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,gBAAiD;AACnD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/replication/runtime.ts"],"sourcesContent":["import { pkhDid } from \"@tinycloud/sdk-core\";\nimport type { FetchFunction, ServiceContext, ServiceSession } from \"@tinycloud/sdk-core\";\nimport type {\n KVReadThrough,\n KVReplicaStorage,\n KVReplicationController,\n PendingWriteStore,\n ReplicationAuthority,\n ReplicationControl,\n ReplicationEvent,\n ReplicationIdentity,\n ReplicationOptions,\n ReplicationScheduler,\n} from \"@tinycloud/sdk-services\";\ntype ReplicationServices = typeof import(\"@tinycloud/sdk-services/kv/replication\");\n\nexport interface ReplicationRuntimeOptions extends ReplicationOptions {\n storage: KVReplicaStorage;\n mode?: \"background\" | \"foreground\";\n}\n\nexport interface ReplicationRuntimeBinding {\n context: ServiceContext;\n session: ServiceSession;\n address?: string;\n chainId?: number;\n principal?: string;\n authority: ReplicationAuthority;\n nodeFeatures?: readonly string[];\n primaryKV: Array<{ space: string; kv: { setReadThrough(readThrough: KVReadThrough | null): void } }>;\n}\n\nconst scheduler: ReplicationScheduler = {\n now: () => Date.now(),\n setTimeout(fn, ms) {\n const timer = setTimeout(fn, ms);\n timer.unref?.();\n return () => clearTimeout(timer);\n },\n};\n\nfunction resolvedOptions(options: ReplicationRuntimeOptions) {\n return {\n ...options,\n syncIntervalMs: options.syncIntervalMs ?? 60_000,\n maxStalenessMs: options.maxStalenessMs ?? 120_000,\n staleSyncTimeoutMs: options.staleSyncTimeoutMs ?? 5_000,\n allowSecrets: options.allowSecrets === true,\n verify: options.verify === true,\n };\n}\ntype ReadThroughKV = {\n setReadThrough(readThrough: KVReadThrough | null): void;\n setReadThroughReady?(ready: Promise<unknown>): void;\n};\n\nexport class ReplicationRuntime {\n readonly control: ReplicationControl;\n private readonly pending = new Map<string, PendingWriteStore>();\n private readonly attached = new Map<ReadThroughKV, string>();\n private current?: KVReplicationController;\n private lastController?: KVReplicationController;\n private previous: Promise<void> = Promise.resolve();\n private binding: Promise<void> = Promise.resolve();\n private services?: Promise<ReplicationServices>;\n private generation = 0;\n private lastIdentity?: ReplicationIdentity;\n private lastPending?: PendingWriteStore;\n private primarySpace?: string;\n private pendingPurge?: Parameters<KVReplicationController[\"purge\"]>[0];\n private pendingPurgeResult?: ReturnType<KVReplicationController[\"purge\"]>;\n private bindingActive = false;\n private pendingPurgeSet = false;\n private purgedGeneration?: number;\n private closed = false;\n constructor(\n private readonly options: ReplicationRuntimeOptions,\n private readonly clock: ReplicationScheduler = scheduler,\n ) {\n this.control = {\n status: async () => {\n await this.binding;\n return this.current ? this.current.status() : [];\n },\n sync: async (input) => {\n await this.binding;\n if (this.purgedGeneration === this.generation) return;\n if (this.current) await this.current.sync(input);\n },\n purge: (input) => {\n if (this.bindingActive) {\n this.pendingPurge = input;\n this.pendingPurgeSet = true;\n const existing = this.current ?? this.lastController;\n if (existing) {\n this.pendingPurgeResult = existing.purge(input);\n this.purgedGeneration = this.generation;\n }\n return this.binding.then(() => this.pendingPurgeResult ?? { purged: [], failed: [] });\n }\n const controller = this.current ?? this.lastController;\n if (!controller) return Promise.resolve({ purged: [], failed: [] });\n this.purgedGeneration = this.generation;\n return controller.purge(input);\n },\n clearPending: async () => {\n await this.binding;\n if (this.current) return this.current.clearPending();\n const pending = this.lastPending;\n if (!pending) return 0;\n return pending.update((state) => {\n const before = state.records.length;\n state.records = state.records.filter((record) =>\n record.state === \"committed\" ||\n (record.state === \"in_flight\" && this.clock.now() - Date.parse(record.at) <= 10 * 60_000),\n );\n return before - state.records.length;\n });\n },\n close: async () => {\n this.closed = true;\n this.unbind();\n await this.binding.catch(() => undefined);\n await this.previous;\n },\n };\n }\n\n private loadServices(): Promise<ReplicationServices> {\n return (this.services ??= import(\"@tinycloud/sdk-services/kv/replication\"));\n }\n\n private detachAll(): void {\n for (const kv of this.attached.keys()) kv.setReadThrough(null);\n this.attached.clear();\n }\n\n bind(input: ReplicationRuntimeBinding): Promise<void> {\n if (this.closed || !this.options.enabled) return Promise.resolve();\n this.bindingActive = true;\n const generation = ++this.generation;\n this.purgedGeneration = undefined;\n const { context, session } = input;\n const emit = (event: ReplicationEvent): void => {\n try { this.options.onEvent?.(event); } catch { /* Observability must not affect KV behavior. */ }\n const { type, ...data } = event;\n context.emit(type, data);\n };\n const previous = this.current;\n this.current = undefined;\n for (const kv of this.attached.keys()) kv.setReadThrough(null);\n this.primarySpace = session.spaceId;\n const close = previous ? previous.close().catch(() => undefined) : Promise.resolve();\n this.previous = this.previous.then(() => close);\n const previousClose = this.previous;\n this.binding = this.loadServices().then((services) => {\n if (generation !== this.generation || this.closed) return;\n let identity: ReplicationIdentity;\n try {\n identity = services.canonicalReplicationIdentity({\n host: context.hosts[0]!,\n space: session.spaceId,\n principal: input.principal ?? pkhDid(input.address!, input.chainId!),\n });\n } catch {\n for (const prefix of this.options.prefixes) {\n emit({ type: \"replication.state\", at: new Date(this.clock.now()).toISOString(), space: session.spaceId, replica: prefix, state: \"unavailable\", code: \"CONFIG_INVALID\" });\n }\n return;\n }\n const key = services.replicationIdentityKey(identity);\n let pending = this.pending.get(key);\n if (!pending) {\n pending = this.options.storage.pendingWrites?.(identity) ?? services.createMemoryPendingStore(identity);\n this.pending.set(key, pending);\n }\n this.lastPending = pending;\n const controller = services.createKVReplication({\n options: resolvedOptions(this.options),\n mode: this.options.mode ?? \"background\",\n storage: this.options.storage,\n identity,\n session: { id: session.delegationCid, did: session.verificationMethod, space: session.spaceId },\n authority: input.authority,\n pending,\n scheduler: this.clock,\n emit,\n fetch: context.fetch as FetchFunction,\n nodeFeatures: input.nodeFeatures,\n previous: previousClose,\n });\n this.current = controller;\n this.lastController = controller;\n this.lastIdentity = identity;\n for (const [kv, space] of this.attached) {\n kv.setReadThrough(space === this.primarySpace ? controller : null);\n }\n for (const scoped of input.primaryKV) this.attach(scoped.space, scoped.kv);\n if (this.pendingPurgeSet) {\n this.pendingPurgeResult = controller.purge(this.pendingPurge);\n this.purgedGeneration = generation;\n this.pendingPurge = undefined;\n this.pendingPurgeSet = false;\n }\n }).finally(() => {\n if (generation === this.generation) this.bindingActive = false;\n });\n for (const kv of this.attached.keys()) kv.setReadThroughReady?.(this.binding);\n return this.binding;\n }\n\n attach(space: string, kv: ReadThroughKV): Promise<void> {\n this.attached.set(kv, space);\n kv.setReadThrough(space === this.primarySpace ? this.current ?? null : null);\n return this.binding.then(() => {\n kv.setReadThrough(space === this.primarySpace ? this.current ?? null : null);\n });\n }\n\n unbind(): Promise<void> {\n this.generation++;\n this.bindingActive = false;\n this.pendingPurgeSet = false;\n const controller = this.current;\n this.current = undefined;\n this.primarySpace = undefined;\n this.detachAll();\n const binding = this.binding;\n const close = binding.then(() => controller?.close()).catch(() => undefined);\n this.previous = this.previous.then(() => close);\n return this.previous;\n }\n\n get boundIdentity(): ReplicationIdentity | undefined {\n return this.lastIdentity;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuB;AAgCvB,IAAM,YAAkC;AAAA,EACtC,KAAK,MAAM,KAAK,IAAI;AAAA,EACpB,WAAW,IAAI,IAAI;AACjB,UAAM,QAAQ,WAAW,IAAI,EAAE;AAC/B,UAAM,QAAQ;AACd,WAAO,MAAM,aAAa,KAAK;AAAA,EACjC;AACF;AAEA,SAAS,gBAAgB,SAAoC;AAC3D,SAAO;AAAA,IACL,GAAG;AAAA,IACH,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,oBAAoB,QAAQ,sBAAsB;AAAA,IAClD,cAAc,QAAQ,iBAAiB;AAAA,IACvC,QAAQ,QAAQ,WAAW;AAAA,EAC7B;AACF;AAMO,IAAM,qBAAN,MAAyB;AAAA,EAmB9B,YACmB,SACA,QAA8B,WAC/C;AAFiB;AACA;AAnBnB,SAAiB,UAAU,oBAAI,IAA+B;AAC9D,SAAiB,WAAW,oBAAI,IAA2B;AAG3D,SAAQ,WAA0B,QAAQ,QAAQ;AAClD,SAAQ,UAAyB,QAAQ,QAAQ;AAEjD,SAAQ,aAAa;AAMrB,SAAQ,gBAAgB;AACxB,SAAQ,kBAAkB;AAE1B,SAAQ,SAAS;AAKf,SAAK,UAAU;AAAA,MACb,QAAQ,YAAY;AAClB,cAAM,KAAK;AACX,eAAO,KAAK,UAAU,KAAK,QAAQ,OAAO,IAAI,CAAC;AAAA,MACjD;AAAA,MACA,MAAM,OAAO,UAAU;AACrB,cAAM,KAAK;AACX,YAAI,KAAK,qBAAqB,KAAK,WAAY;AAC/C,YAAI,KAAK,QAAS,O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gB;AAAA,IAC3D,CAAC;AACD,eAAW,MAAM,KAAK,SAAS,KAAK,EAAG,IAAG,sBAAsB,KAAK,OAAO;AAC5E,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,OAAO,OAAe,IAAkC;AACtD,SAAK,SAAS,IAAI,IAAI,KAAK;AAC3B,OAAG,eAAe,UAAU,KAAK,eAAe,KAAK,WAAW,OAAO,IAAI;AAC3E,WAAO,KAAK,QAAQ,KAAK,MAAM;AAC7B,SAAG,eAAe,UAAU,KAAK,eAAe,KAAK,WAAW,OAAO,IAAI;AAAA,IAC7E,CAAC;AAAA,EACH;AAAA,EAEA,SAAwB;AACtB,SAAK;AACL,SAAK,gBAAgB;AACrB,SAAK,kBAAkB;AACvB,UAAM,aAAa,KAAK;AACxB,SAAK,UAAU;AACf,SAAK,eAAe;AACpB,SAAK,UAAU;AACf,UAAM,UAAU,KAAK;AACrB,UAAM,QAAQ,QAAQ,KAAK,MAAM,YAAY,MAAM,CAAC,EAAE,MAAM,MAAM,MAAS;AAC3E,SAAK,WAAW,KAAK,SAAS,KAAK,MAAM,KAAK;AAC9C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,gBAAiD;AACnD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import '@tinycloud/sdk-core';
|
|
2
2
|
import '@tinycloud/sdk-services';
|
|
3
|
-
export { R as ReplicationRuntime, a as ReplicationRuntimeBinding, b as ReplicationRuntimeOptions } from '../runtime-
|
|
3
|
+
export { R as ReplicationRuntime, a as ReplicationRuntimeBinding, b as ReplicationRuntimeOptions } from '../runtime-B5P5SRpC.cjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import '@tinycloud/sdk-core';
|
|
2
2
|
import '@tinycloud/sdk-services';
|
|
3
|
-
export { R as ReplicationRuntime, a as ReplicationRuntimeBinding, b as ReplicationRuntimeOptions } from '../runtime-
|
|
3
|
+
export { R as ReplicationRuntime, a as ReplicationRuntimeBinding, b as ReplicationRuntimeOptions } from '../runtime-B5P5SRpC.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/replication/runtime.ts"],"sourcesContent":["import { pkhDid } from \"@tinycloud/sdk-core\";\nimport type { FetchFunction, ServiceContext, ServiceSession } from \"@tinycloud/sdk-core\";\nimport type {\n KVReadThrough,\n KVReplicaStorage,\n KVReplicationController,\n PendingWriteStore,\n ReplicationAuthority,\n ReplicationControl,\n ReplicationEvent,\n ReplicationIdentity,\n ReplicationOptions,\n ReplicationScheduler,\n} from \"@tinycloud/sdk-services\";\ntype ReplicationServices = typeof import(\"@tinycloud/sdk-services/kv/replication\");\n\nexport interface ReplicationRuntimeOptions extends ReplicationOptions {\n storage: KVReplicaStorage;\n mode?: \"background\" | \"foreground\";\n}\n\nexport interface ReplicationRuntimeBinding {\n context: ServiceContext;\n session: ServiceSession;\n address?: string;\n chainId?: number;\n principal?: string;\n authority: ReplicationAuthority;\n primaryKV: Array<{ space: string; kv: { setReadThrough(readThrough: KVReadThrough | null): void } }>;\n}\n\nconst scheduler: ReplicationScheduler = {\n now: () => Date.now(),\n setTimeout(fn, ms) {\n const timer = setTimeout(fn, ms);\n timer.unref?.();\n return () => clearTimeout(timer);\n },\n};\n\nfunction resolvedOptions(options: ReplicationRuntimeOptions) {\n return {\n ...options,\n syncIntervalMs: options.syncIntervalMs ?? 60_000,\n maxStalenessMs: options.maxStalenessMs ?? 120_000,\n staleSyncTimeoutMs: options.staleSyncTimeoutMs ?? 5_000,\n allowSecrets: options.allowSecrets === true,\n verify: options.verify === true,\n };\n}\ntype ReadThroughKV = {\n setReadThrough(readThrough: KVReadThrough | null): void;\n setReadThroughReady?(ready: Promise<unknown>): void;\n};\n\nexport class ReplicationRuntime {\n readonly control: ReplicationControl;\n private readonly pending = new Map<string, PendingWriteStore>();\n private readonly attached = new Map<ReadThroughKV, string>();\n private current?: KVReplicationController;\n private lastController?: KVReplicationController;\n private previous: Promise<void> = Promise.resolve();\n private binding: Promise<void> = Promise.resolve();\n private services?: Promise<ReplicationServices>;\n private generation = 0;\n private lastIdentity?: ReplicationIdentity;\n private lastPending?: PendingWriteStore;\n private primarySpace?: string;\n private pendingPurge?: Parameters<KVReplicationController[\"purge\"]>[0];\n private pendingPurgeResult?: ReturnType<KVReplicationController[\"purge\"]>;\n private bindingActive = false;\n private pendingPurgeSet = false;\n private purgedGeneration?: number;\n private closed = false;\n constructor(\n private readonly options: ReplicationRuntimeOptions,\n private readonly clock: ReplicationScheduler = scheduler,\n ) {\n this.control = {\n status: async () => {\n await this.binding;\n return this.current ? this.current.status() : [];\n },\n sync: async (input) => {\n await this.binding;\n if (this.purgedGeneration === this.generation) return;\n if (this.current) await this.current.sync(input);\n },\n purge: (input) => {\n if (this.bindingActive) {\n this.pendingPurge = input;\n this.pendingPurgeSet = true;\n const existing = this.current ?? this.lastController;\n if (existing) {\n this.pendingPurgeResult = existing.purge(input);\n this.purgedGeneration = this.generation;\n }\n return this.binding.then(() => this.pendingPurgeResult ?? { purged: [], failed: [] });\n }\n const controller = this.current ?? this.lastController;\n if (!controller) return Promise.resolve({ purged: [], failed: [] });\n this.purgedGeneration = this.generation;\n return controller.purge(input);\n },\n clearPending: async () => {\n await this.binding;\n if (this.current) return this.current.clearPending();\n const pending = this.lastPending;\n if (!pending) return 0;\n return pending.update((state) => {\n const before = state.records.length;\n state.records = state.records.filter((record) =>\n record.state === \"committed\" ||\n (record.state === \"in_flight\" && this.clock.now() - Date.parse(record.at) <= 10 * 60_000),\n );\n return before - state.records.length;\n });\n },\n close: async () => {\n this.closed = true;\n this.unbind();\n await this.binding.catch(() => undefined);\n await this.previous;\n },\n };\n }\n\n private loadServices(): Promise<ReplicationServices> {\n return (this.services ??= import(\"@tinycloud/sdk-services/kv/replication\"));\n }\n\n private detachAll(): void {\n for (const kv of this.attached.keys()) kv.setReadThrough(null);\n this.attached.clear();\n }\n\n bind(input: ReplicationRuntimeBinding): Promise<void> {\n if (this.closed || !this.options.enabled) return Promise.resolve();\n this.bindingActive = true;\n const generation = ++this.generation;\n this.purgedGeneration = undefined;\n const { context, session } = input;\n const emit = (event: ReplicationEvent): void => {\n try { this.options.onEvent?.(event); } catch { /* Observability must not affect KV behavior. */ }\n const { type, ...data } = event;\n context.emit(type, data);\n };\n const previous = this.current;\n this.current = undefined;\n for (const kv of this.attached.keys()) kv.setReadThrough(null);\n this.primarySpace = session.spaceId;\n const close = previous ? previous.close().catch(() => undefined) : Promise.resolve();\n this.previous = this.previous.then(() => close);\n const previousClose = this.previous;\n this.binding = this.loadServices().then((services) => {\n if (generation !== this.generation || this.closed) return;\n let identity: ReplicationIdentity;\n try {\n identity = services.canonicalReplicationIdentity({\n host: context.hosts[0]!,\n space: session.spaceId,\n principal: input.principal ?? pkhDid(input.address!, input.chainId!),\n });\n } catch {\n for (const prefix of this.options.prefixes) {\n emit({ type: \"replication.state\", at: new Date(this.clock.now()).toISOString(), space: session.spaceId, replica: prefix, state: \"unavailable\", code: \"CONFIG_INVALID\" });\n }\n return;\n }\n const key = services.replicationIdentityKey(identity);\n let pending = this.pending.get(key);\n if (!pending) {\n pending = this.options.storage.pendingWrites?.(identity) ?? services.createMemoryPendingStore(identity);\n this.pending.set(key, pending);\n }\n this.lastPending = pending;\n const controller = services.createKVReplication({\n options: resolvedOptions(this.options),\n mode: this.options.mode ?? \"background\",\n storage: this.options.storage,\n identity,\n session: { id: session.delegationCid, did: session.verificationMethod, space: session.spaceId },\n authority: input.authority,\n pending,\n scheduler: this.clock,\n emit,\n fetch: context.fetch as FetchFunction,\n previous: previousClose,\n });\n this.current = controller;\n this.lastController = controller;\n this.lastIdentity = identity;\n for (const [kv, space] of this.attached) {\n kv.setReadThrough(space === this.primarySpace ? controller : null);\n }\n for (const scoped of input.primaryKV) this.attach(scoped.space, scoped.kv);\n if (this.pendingPurgeSet) {\n this.pendingPurgeResult = controller.purge(this.pendingPurge);\n this.purgedGeneration = generation;\n this.pendingPurge = undefined;\n this.pendingPurgeSet = false;\n }\n }).finally(() => {\n if (generation === this.generation) this.bindingActive = false;\n });\n for (const kv of this.attached.keys()) kv.setReadThroughReady?.(this.binding);\n return this.binding;\n }\n\n attach(space: string, kv: ReadThroughKV): Promise<void> {\n this.attached.set(kv, space);\n kv.setReadThrough(space === this.primarySpace ? this.current ?? null : null);\n return this.binding.then(() => {\n kv.setReadThrough(space === this.primarySpace ? this.current ?? null : null);\n });\n }\n\n unbind(): Promise<void> {\n this.generation++;\n this.bindingActive = false;\n this.pendingPurgeSet = false;\n const controller = this.current;\n this.current = undefined;\n this.primarySpace = undefined;\n this.detachAll();\n const binding = this.binding;\n const close = binding.then(() => controller?.close()).catch(() => undefined);\n this.previous = this.previous.then(() => close);\n return this.previous;\n }\n\n get boundIdentity(): ReplicationIdentity | undefined {\n return this.lastIdentity;\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc;AA+BvB,IAAM,YAAkC;AAAA,EACtC,KAAK,MAAM,KAAK,IAAI;AAAA,EACpB,WAAW,IAAI,IAAI;AACjB,UAAM,QAAQ,WAAW,IAAI,EAAE;AAC/B,UAAM,QAAQ;AACd,WAAO,MAAM,aAAa,KAAK;AAAA,EACjC;AACF;AAEA,SAAS,gBAAgB,SAAoC;AAC3D,SAAO;AAAA,IACL,GAAG;AAAA,IACH,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,oBAAoB,QAAQ,sBAAsB;AAAA,IAClD,cAAc,QAAQ,iBAAiB;AAAA,IACvC,QAAQ,QAAQ,WAAW;AAAA,EAC7B;AACF;AAMO,IAAM,qBAAN,MAAyB;AAAA,EAmB9B,YACmB,SACA,QAA8B,WAC/C;AAFiB;AACA;AAnBnB,SAAiB,UAAU,oBAAI,IAA+B;AAC9D,SAAiB,WAAW,oBAAI,IAA2B;AAG3D,SAAQ,WAA0B,QAAQ,QAAQ;AAClD,SAAQ,UAAyB,QAAQ,QAAQ;AAEjD,SAAQ,aAA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AAW,UAAU,MAAM,UAAW,MAAK,OAAO,OAAO,OAAO,OAAO,EAAE;AACzE,UAAI,KAAK,iBAAiB;AACxB,aAAK,qBAAqB,WAAW,MAAM,KAAK,YAAY;AAC5D,aAAK,mBAAmB;AACxB,aAAK,eAAe;AACpB,aAAK,kBAAkB;AAAA,MACzB;AAAA,IACF,CAAC,EAAE,QAAQ,MAAM;AACf,UAAI,eAAe,KAAK,WAAY,MAAK,gBAAgB;AAAA,IAC3D,CAAC;AACD,eAAW,MAAM,KAAK,SAAS,KAAK,EAAG,IAAG,sBAAsB,KAAK,OAAO;AAC5E,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,OAAO,OAAe,IAAkC;AACtD,SAAK,SAAS,IAAI,IAAI,KAAK;AAC3B,OAAG,eAAe,UAAU,KAAK,eAAe,KAAK,WAAW,OAAO,IAAI;AAC3E,WAAO,KAAK,QAAQ,KAAK,MAAM;AAC7B,SAAG,eAAe,UAAU,KAAK,eAAe,KAAK,WAAW,OAAO,IAAI;AAAA,IAC7E,CAAC;AAAA,EACH;AAAA,EAEA,SAAwB;AACtB,SAAK;AACL,SAAK,gBAAgB;AACrB,SAAK,kBAAkB;AACvB,UAAM,aAAa,KAAK;AACxB,SAAK,UAAU;AACf,SAAK,eAAe;AACpB,SAAK,UAAU;AACf,UAAM,UAAU,KAAK;AACrB,UAAM,QAAQ,QAAQ,KAAK,MAAM,YAAY,MAAM,CAAC,EAAE,MAAM,MAAM,MAAS;AAC3E,SAAK,WAAW,KAAK,SAAS,KAAK,MAAM,KAAK;AAC9C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,gBAAiD;AACnD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/replication/runtime.ts"],"sourcesContent":["import { pkhDid } from \"@tinycloud/sdk-core\";\nimport type { FetchFunction, ServiceContext, ServiceSession } from \"@tinycloud/sdk-core\";\nimport type {\n KVReadThrough,\n KVReplicaStorage,\n KVReplicationController,\n PendingWriteStore,\n ReplicationAuthority,\n ReplicationControl,\n ReplicationEvent,\n ReplicationIdentity,\n ReplicationOptions,\n ReplicationScheduler,\n} from \"@tinycloud/sdk-services\";\ntype ReplicationServices = typeof import(\"@tinycloud/sdk-services/kv/replication\");\n\nexport interface ReplicationRuntimeOptions extends ReplicationOptions {\n storage: KVReplicaStorage;\n mode?: \"background\" | \"foreground\";\n}\n\nexport interface ReplicationRuntimeBinding {\n context: ServiceContext;\n session: ServiceSession;\n address?: string;\n chainId?: number;\n principal?: string;\n authority: ReplicationAuthority;\n nodeFeatures?: readonly string[];\n primaryKV: Array<{ space: string; kv: { setReadThrough(readThrough: KVReadThrough | null): void } }>;\n}\n\nconst scheduler: ReplicationScheduler = {\n now: () => Date.now(),\n setTimeout(fn, ms) {\n const timer = setTimeout(fn, ms);\n timer.unref?.();\n return () => clearTimeout(timer);\n },\n};\n\nfunction resolvedOptions(options: ReplicationRuntimeOptions) {\n return {\n ...options,\n syncIntervalMs: options.syncIntervalMs ?? 60_000,\n maxStalenessMs: options.maxStalenessMs ?? 120_000,\n staleSyncTimeoutMs: options.staleSyncTimeoutMs ?? 5_000,\n allowSecrets: options.allowSecrets === true,\n verify: options.verify === true,\n };\n}\ntype ReadThroughKV = {\n setReadThrough(readThrough: KVReadThrough | null): void;\n setReadThroughReady?(ready: Promise<unknown>): void;\n};\n\nexport class ReplicationRuntime {\n readonly control: ReplicationControl;\n private readonly pending = new Map<string, PendingWriteStore>();\n private readonly attached = new Map<ReadThroughKV, string>();\n private current?: KVReplicationController;\n private lastController?: KVReplicationController;\n private previous: Promise<void> = Promise.resolve();\n private binding: Promise<void> = Promise.resolve();\n private services?: Promise<ReplicationServices>;\n private generation = 0;\n private lastIdentity?: ReplicationIdentity;\n private lastPending?: PendingWriteStore;\n private primarySpace?: string;\n private pendingPurge?: Parameters<KVReplicationController[\"purge\"]>[0];\n private pendingPurgeResult?: ReturnType<KVReplicationController[\"purge\"]>;\n private bindingActive = false;\n private pendingPurgeSet = false;\n private purgedGeneration?: number;\n private closed = false;\n constructor(\n private readonly options: ReplicationRuntimeOptions,\n private readonly clock: ReplicationScheduler = scheduler,\n ) {\n this.control = {\n status: async () => {\n await this.binding;\n return this.current ? this.current.status() : [];\n },\n sync: async (input) => {\n await this.binding;\n if (this.purgedGeneration === this.generation) return;\n if (this.current) await this.current.sync(input);\n },\n purge: (input) => {\n if (this.bindingActive) {\n this.pendingPurge = input;\n this.pendingPurgeSet = true;\n const existing = this.current ?? this.lastController;\n if (existing) {\n this.pendingPurgeResult = existing.purge(input);\n this.purgedGeneration = this.generation;\n }\n return this.binding.then(() => this.pendingPurgeResult ?? { purged: [], failed: [] });\n }\n const controller = this.current ?? this.lastController;\n if (!controller) return Promise.resolve({ purged: [], failed: [] });\n this.purgedGeneration = this.generation;\n return controller.purge(input);\n },\n clearPending: async () => {\n await this.binding;\n if (this.current) return this.current.clearPending();\n const pending = this.lastPending;\n if (!pending) return 0;\n return pending.update((state) => {\n const before = state.records.length;\n state.records = state.records.filter((record) =>\n record.state === \"committed\" ||\n (record.state === \"in_flight\" && this.clock.now() - Date.parse(record.at) <= 10 * 60_000),\n );\n return before - state.records.length;\n });\n },\n close: async () => {\n this.closed = true;\n this.unbind();\n await this.binding.catch(() => undefined);\n await this.previous;\n },\n };\n }\n\n private loadServices(): Promise<ReplicationServices> {\n return (this.services ??= import(\"@tinycloud/sdk-services/kv/replication\"));\n }\n\n private detachAll(): void {\n for (const kv of this.attached.keys()) kv.setReadThrough(null);\n this.attached.clear();\n }\n\n bind(input: ReplicationRuntimeBinding): Promise<void> {\n if (this.closed || !this.options.enabled) return Promise.resolve();\n this.bindingActive = true;\n const generation = ++this.generation;\n this.purgedGeneration = undefined;\n const { context, session } = input;\n const emit = (event: ReplicationEvent): void => {\n try { this.options.onEvent?.(event); } catch { /* Observability must not affect KV behavior. */ }\n const { type, ...data } = event;\n context.emit(type, data);\n };\n const previous = this.current;\n this.current = undefined;\n for (const kv of this.attached.keys()) kv.setReadThrough(null);\n this.primarySpace = session.spaceId;\n const close = previous ? previous.close().catch(() => undefined) : Promise.resolve();\n this.previous = this.previous.then(() => close);\n const previousClose = this.previous;\n this.binding = this.loadServices().then((services) => {\n if (generation !== this.generation || this.closed) return;\n let identity: ReplicationIdentity;\n try {\n identity = services.canonicalReplicationIdentity({\n host: context.hosts[0]!,\n space: session.spaceId,\n principal: input.principal ?? pkhDid(input.address!, input.chainId!),\n });\n } catch {\n for (const prefix of this.options.prefixes) {\n emit({ type: \"replication.state\", at: new Date(this.clock.now()).toISOString(), space: session.spaceId, replica: prefix, state: \"unavailable\", code: \"CONFIG_INVALID\" });\n }\n return;\n }\n const key = services.replicationIdentityKey(identity);\n let pending = this.pending.get(key);\n if (!pending) {\n pending = this.options.storage.pendingWrites?.(identity) ?? services.createMemoryPendingStore(identity);\n this.pending.set(key, pending);\n }\n this.lastPending = pending;\n const controller = services.createKVReplication({\n options: resolvedOptions(this.options),\n mode: this.options.mode ?? \"background\",\n storage: this.options.storage,\n identity,\n session: { id: session.delegationCid, did: session.verificationMethod, space: session.spaceId },\n authority: input.authority,\n pending,\n scheduler: this.clock,\n emit,\n fetch: context.fetch as FetchFunction,\n nodeFeatures: input.nodeFeatures,\n previous: previousClose,\n });\n this.current = controller;\n this.lastController = controller;\n this.lastIdentity = identity;\n for (const [kv, space] of this.attached) {\n kv.setReadThrough(space === this.primarySpace ? controller : null);\n }\n for (const scoped of input.primaryKV) this.attach(scoped.space, scoped.kv);\n if (this.pendingPurgeSet) {\n this.pendingPurgeResult = controller.purge(this.pendingPurge);\n this.purgedGeneration = generation;\n this.pendingPurge = undefined;\n this.pendingPurgeSet = false;\n }\n }).finally(() => {\n if (generation === this.generation) this.bindingActive = false;\n });\n for (const kv of this.attached.keys()) kv.setReadThroughReady?.(this.binding);\n return this.binding;\n }\n\n attach(space: string, kv: ReadThroughKV): Promise<void> {\n this.attached.set(kv, space);\n kv.setReadThrough(space === this.primarySpace ? this.current ?? null : null);\n return this.binding.then(() => {\n kv.setReadThrough(space === this.primarySpace ? this.current ?? null : null);\n });\n }\n\n unbind(): Promise<void> {\n this.generation++;\n this.bindingActive = false;\n this.pendingPurgeSet = false;\n const controller = this.current;\n this.current = undefined;\n this.primarySpace = undefined;\n this.detachAll();\n const binding = this.binding;\n const close = binding.then(() => controller?.close()).catch(() => undefined);\n this.previous = this.previous.then(() => close);\n return this.previous;\n }\n\n get boundIdentity(): ReplicationIdentity | undefined {\n return this.lastIdentity;\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc;AAgCvB,IAAM,YAAkC;AAAA,EACtC,KAAK,MAAM,KAAK,IAAI;AAAA,EACpB,WAAW,IAAI,IAAI;AACjB,UAAM,QAAQ,WAAW,IAAI,EAAE;AAC/B,UAAM,QAAQ;AACd,WAAO,MAAM,aAAa,KAAK;AAAA,EACjC;AACF;AAEA,SAAS,gBAAgB,SAAoC;AAC3D,SAAO;AAAA,IACL,GAAG;AAAA,IACH,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,gBAAgB,QAAQ,kBAAkB;AAAA,IAC1C,oBAAoB,QAAQ,sBAAsB;AAAA,IAClD,cAAc,QAAQ,iBAAiB;AAAA,IACvC,QAAQ,QAAQ,WAAW;AAAA,EAC7B;AACF;AAMO,IAAM,qBAAN,MAAyB;AAAA,EAmB9B,YACmB,SACA,QAA8B,WAC/C;AAFiB;AACA;AAnBnB,SAAiB,UAAU,oBAAI,IAA+B;AAC9D,SAAiB,WAAW,oBAAI,IAA2B;AAG3D,SAAQ,WAA0B,QAAQ,QAAQ;AAClD,SAAQ,UAAyB,QAAQ,QAAQ;AAEjD,SAAQ,aAAa;AAMrB,SAAQ,gBAAgB;AACxB,SAAQ,kBAAkB;AAE1B,SAAQ,SAAS;AAKf,SAAK,UAAU;AAAA,MACb,QAAQ,YAAY;AAClB,cAAM,KAAK;AACX,eAAO,KAAK,UAAU,KAAK,QAAQ,OAAO,IAAI,CAAC;AAAA,MACjD;AAAA,MACA,MAAM,OAA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AAAA,MACzB;AAAA,IACF,CAAC,EAAE,QAAQ,MAAM;AACf,UAAI,eAAe,KAAK,WAAY,MAAK,gBAAgB;AAAA,IAC3D,CAAC;AACD,eAAW,MAAM,KAAK,SAAS,KAAK,EAAG,IAAG,sBAAsB,KAAK,OAAO;AAC5E,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,OAAO,OAAe,IAAkC;AACtD,SAAK,SAAS,IAAI,IAAI,KAAK;AAC3B,OAAG,eAAe,UAAU,KAAK,eAAe,KAAK,WAAW,OAAO,IAAI;AAC3E,WAAO,KAAK,QAAQ,KAAK,MAAM;AAC7B,SAAG,eAAe,UAAU,KAAK,eAAe,KAAK,WAAW,OAAO,IAAI;AAAA,IAC7E,CAAC;AAAA,EACH;AAAA,EAEA,SAAwB;AACtB,SAAK;AACL,SAAK,gBAAgB;AACrB,SAAK,kBAAkB;AACvB,UAAM,aAAa,KAAK;AACxB,SAAK,UAAU;AACf,SAAK,eAAe;AACpB,SAAK,UAAU;AACf,UAAM,UAAU,KAAK;AACrB,UAAM,QAAQ,QAAQ,KAAK,MAAM,YAAY,MAAM,CAAC,EAAE,MAAM,MAAM,MAAS;AAC3E,SAAK,WAAW,KAAK,SAAS,KAAK,MAAM,KAAK;AAC9C,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,gBAAiD;AACnD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinycloud/node-sdk",
|
|
3
|
-
"version": "3.2.0-beta.
|
|
3
|
+
"version": "3.2.0-beta.6",
|
|
4
4
|
"description": "TinyCloud SDK for Node.js with configurable authorization strategies",
|
|
5
5
|
"author": "TinyCloud, Inc.",
|
|
6
6
|
"license": "EGPL",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"test:integration": "echo 'Integration tests live in tests/node-sdk workspace'"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@tinycloud/replica": "0.
|
|
58
|
-
"@tinycloud/sdk-services": "3.2.0-beta.
|
|
59
|
-
"@tinycloud/sdk-core": "3.2.0-beta.
|
|
57
|
+
"@tinycloud/replica": "0.2.0-beta.2",
|
|
58
|
+
"@tinycloud/sdk-services": "3.2.0-beta.5",
|
|
59
|
+
"@tinycloud/sdk-core": "3.2.0-beta.5",
|
|
60
60
|
"@tinycloud/node-sdk-wasm": "1.7.7",
|
|
61
61
|
"siwe": "^3.0.0"
|
|
62
62
|
},
|