@graphrefly/ts 0.0.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/LICENSE +21 -0
- package/dist/adapters/index.cjs +9015 -0
- package/dist/adapters/index.cjs.map +1 -0
- package/dist/adapters/index.d.cts +678 -0
- package/dist/adapters/index.d.ts +678 -0
- package/dist/adapters/index.js +2894 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/observe-storage.cjs +260 -0
- package/dist/adapters/observe-storage.cjs.map +1 -0
- package/dist/adapters/observe-storage.d.cts +77 -0
- package/dist/adapters/observe-storage.d.ts +77 -0
- package/dist/adapters/observe-storage.js +161 -0
- package/dist/adapters/observe-storage.js.map +1 -0
- package/dist/append-log-DisvEReb.d.cts +189 -0
- package/dist/append-log-DzKMmjxx.d.ts +189 -0
- package/dist/chunk-2ILL7HQI.js +1189 -0
- package/dist/chunk-2ILL7HQI.js.map +1 -0
- package/dist/chunk-4VLAQHZI.js +330 -0
- package/dist/chunk-4VLAQHZI.js.map +1 -0
- package/dist/chunk-6PHB5CJS.js +229 -0
- package/dist/chunk-6PHB5CJS.js.map +1 -0
- package/dist/chunk-COHO25CZ.js +2449 -0
- package/dist/chunk-COHO25CZ.js.map +1 -0
- package/dist/chunk-D6BG7U6A.js +161 -0
- package/dist/chunk-D6BG7U6A.js.map +1 -0
- package/dist/chunk-DJC4CHLQ.js +818 -0
- package/dist/chunk-DJC4CHLQ.js.map +1 -0
- package/dist/chunk-DK554R7P.js +67 -0
- package/dist/chunk-DK554R7P.js.map +1 -0
- package/dist/chunk-DKP56CSW.js +322 -0
- package/dist/chunk-DKP56CSW.js.map +1 -0
- package/dist/chunk-G4M3NHRJ.js +688 -0
- package/dist/chunk-G4M3NHRJ.js.map +1 -0
- package/dist/chunk-GAJW5I5P.js +1 -0
- package/dist/chunk-GAJW5I5P.js.map +1 -0
- package/dist/chunk-GDL26N2T.js +282 -0
- package/dist/chunk-GDL26N2T.js.map +1 -0
- package/dist/chunk-GTPCOEOZ.js +741 -0
- package/dist/chunk-GTPCOEOZ.js.map +1 -0
- package/dist/chunk-H2HTHFVN.js +1 -0
- package/dist/chunk-H2HTHFVN.js.map +1 -0
- package/dist/chunk-HDRL4VQQ.js +218 -0
- package/dist/chunk-HDRL4VQQ.js.map +1 -0
- package/dist/chunk-I3IHOHCJ.js +2267 -0
- package/dist/chunk-I3IHOHCJ.js.map +1 -0
- package/dist/chunk-JIMUDQN3.js +965 -0
- package/dist/chunk-JIMUDQN3.js.map +1 -0
- package/dist/chunk-JR4IKCR2.js +462 -0
- package/dist/chunk-JR4IKCR2.js.map +1 -0
- package/dist/chunk-K3FXTC3I.js +165 -0
- package/dist/chunk-K3FXTC3I.js.map +1 -0
- package/dist/chunk-OOEN33FB.js +65 -0
- package/dist/chunk-OOEN33FB.js.map +1 -0
- package/dist/chunk-PKVBHGBM.js +554 -0
- package/dist/chunk-PKVBHGBM.js.map +1 -0
- package/dist/chunk-RIIOUTGM.js +1857 -0
- package/dist/chunk-RIIOUTGM.js.map +1 -0
- package/dist/chunk-SCRFRCGR.js +33 -0
- package/dist/chunk-SCRFRCGR.js.map +1 -0
- package/dist/chunk-SWTLEQL6.js +53 -0
- package/dist/chunk-SWTLEQL6.js.map +1 -0
- package/dist/chunk-SZAETNNA.js +1 -0
- package/dist/chunk-SZAETNNA.js.map +1 -0
- package/dist/chunk-TEW47IVR.js +49 -0
- package/dist/chunk-TEW47IVR.js.map +1 -0
- package/dist/chunk-Y3ZLRGHC.js +1482 -0
- package/dist/chunk-Y3ZLRGHC.js.map +1 -0
- package/dist/chunk-Z2ANQ6JW.js +149 -0
- package/dist/chunk-Z2ANQ6JW.js.map +1 -0
- package/dist/codec-BB7p8fJc.d.cts +38 -0
- package/dist/codec-BB7p8fJc.d.ts +38 -0
- package/dist/composition/index.cjs +2505 -0
- package/dist/composition/index.cjs.map +1 -0
- package/dist/composition/index.d.cts +95 -0
- package/dist/composition/index.d.ts +95 -0
- package/dist/composition/index.js +19 -0
- package/dist/composition/index.js.map +1 -0
- package/dist/core/index.cjs +2475 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +25 -0
- package/dist/core/index.d.ts +25 -0
- package/dist/core/index.js +74 -0
- package/dist/core/index.js.map +1 -0
- package/dist/cqrs/index.cjs +595 -0
- package/dist/cqrs/index.cjs.map +1 -0
- package/dist/cqrs/index.d.cts +200 -0
- package/dist/cqrs/index.d.ts +200 -0
- package/dist/cqrs/index.js +557 -0
- package/dist/cqrs/index.js.map +1 -0
- package/dist/data-structures/index.cjs +4277 -0
- package/dist/data-structures/index.cjs.map +1 -0
- package/dist/data-structures/index.d.cts +22 -0
- package/dist/data-structures/index.d.ts +22 -0
- package/dist/data-structures/index.js +31 -0
- package/dist/data-structures/index.js.map +1 -0
- package/dist/describe-BZb7AS2y.d.ts +57 -0
- package/dist/describe-Ciu8SUnN.d.cts +57 -0
- package/dist/graph/index.cjs +7832 -0
- package/dist/graph/index.cjs.map +1 -0
- package/dist/graph/index.d.cts +251 -0
- package/dist/graph/index.d.ts +251 -0
- package/dist/graph/index.js +131 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph-DfdF9zy4.d.ts +666 -0
- package/dist/graph-s23RbbFO.d.cts +666 -0
- package/dist/index-CAEmLCYF.d.cts +166 -0
- package/dist/index-SnzZu3x7.d.ts +166 -0
- package/dist/index.cjs +15409 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +582 -0
- package/dist/index.js.map +1 -0
- package/dist/messages-BZqrGGm1.d.cts +55 -0
- package/dist/messages-BZqrGGm1.d.ts +55 -0
- package/dist/messaging/index.cjs +818 -0
- package/dist/messaging/index.cjs.map +1 -0
- package/dist/messaging/index.d.cts +235 -0
- package/dist/messaging/index.d.ts +235 -0
- package/dist/messaging/index.js +767 -0
- package/dist/messaging/index.js.map +1 -0
- package/dist/observe-event-log-0SVsx7JG.d.cts +88 -0
- package/dist/observe-event-log-Dnm76owp.d.ts +88 -0
- package/dist/operators/index.cjs +3774 -0
- package/dist/operators/index.cjs.map +1 -0
- package/dist/operators/index.d.cts +308 -0
- package/dist/operators/index.d.ts +308 -0
- package/dist/operators/index.js +112 -0
- package/dist/operators/index.js.map +1 -0
- package/dist/orchestration/index.cjs +3541 -0
- package/dist/orchestration/index.cjs.map +1 -0
- package/dist/orchestration/index.d.cts +302 -0
- package/dist/orchestration/index.d.ts +302 -0
- package/dist/orchestration/index.js +1004 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/patterns/index.cjs +1045 -0
- package/dist/patterns/index.cjs.map +1 -0
- package/dist/patterns/index.d.cts +39 -0
- package/dist/patterns/index.d.ts +39 -0
- package/dist/patterns/index.js +33 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/reactive-collection-BxBqtIOE.d.cts +344 -0
- package/dist/reactive-collection-Cb1II1Fi.d.ts +344 -0
- package/dist/reactive-collection-storage-BNiEc-Gd.d.ts +217 -0
- package/dist/reactive-collection-storage-D-KmjE0J.d.cts +217 -0
- package/dist/reactive-map-BcB4KsQR.d.ts +256 -0
- package/dist/reactive-map-D-g3dv8I.d.cts +256 -0
- package/dist/read-through-B1CYPfq_.d.cts +82 -0
- package/dist/read-through-DwyJhGs1.d.ts +82 -0
- package/dist/render/index.cjs +250 -0
- package/dist/render/index.cjs.map +1 -0
- package/dist/render/index.d.cts +58 -0
- package/dist/render/index.d.ts +58 -0
- package/dist/render/index.js +20 -0
- package/dist/render/index.js.map +1 -0
- package/dist/resilience-Dig3Q7n0.d.cts +45 -0
- package/dist/resilience-Dig3Q7n0.d.ts +45 -0
- package/dist/semantic-memory-graph-BYoIlP35.d.cts +356 -0
- package/dist/semantic-memory-graph-CxyXLms3.d.ts +356 -0
- package/dist/solutions/index.cjs +3249 -0
- package/dist/solutions/index.cjs.map +1 -0
- package/dist/solutions/index.d.cts +520 -0
- package/dist/solutions/index.d.ts +520 -0
- package/dist/solutions/index.js +31 -0
- package/dist/solutions/index.js.map +1 -0
- package/dist/sources/browser.cjs +3095 -0
- package/dist/sources/browser.cjs.map +1 -0
- package/dist/sources/browser.d.cts +39 -0
- package/dist/sources/browser.d.ts +39 -0
- package/dist/sources/browser.js +137 -0
- package/dist/sources/browser.js.map +1 -0
- package/dist/sources/index.cjs +3021 -0
- package/dist/sources/index.cjs.map +1 -0
- package/dist/sources/index.d.cts +7 -0
- package/dist/sources/index.d.ts +7 -0
- package/dist/sources/index.js +63 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/node.cjs +675 -0
- package/dist/sources/node.cjs.map +1 -0
- package/dist/sources/node.d.cts +109 -0
- package/dist/sources/node.d.ts +109 -0
- package/dist/sources/node.js +639 -0
- package/dist/sources/node.js.map +1 -0
- package/dist/storage/browser.cjs +777 -0
- package/dist/storage/browser.cjs.map +1 -0
- package/dist/storage/browser.d.cts +40 -0
- package/dist/storage/browser.d.ts +40 -0
- package/dist/storage/browser.js +275 -0
- package/dist/storage/browser.js.map +1 -0
- package/dist/storage/index.cjs +1989 -0
- package/dist/storage/index.cjs.map +1 -0
- package/dist/storage/index.d.cts +92 -0
- package/dist/storage/index.d.ts +92 -0
- package/dist/storage/index.js +161 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/node.cjs +898 -0
- package/dist/storage/node.cjs.map +1 -0
- package/dist/storage/node.d.cts +66 -0
- package/dist/storage/node.d.ts +66 -0
- package/dist/storage/node.js +402 -0
- package/dist/storage/node.js.map +1 -0
- package/dist/testing/index.cjs +95 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +20 -0
- package/dist/testing/index.d.ts +20 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types-bNMSWKqF.d.cts +732 -0
- package/dist/types-h12mNYbq.d.ts +732 -0
- package/package.json +250 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/agentic-memory-storage.ts","../src/adapters/reactive-collection-storage.ts"],"sourcesContent":["import type { DeliveryMeta } from \"../ctx/types.js\";\nimport { assertGraphLocalNode, type Graph, type StateNode } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\nimport type { Message } from \"../protocol/messages.js\";\nimport {\n\ttype AgenticMemoryRecord,\n\ttype AgenticMemoryRecordFrame,\n\ttype AgenticMemoryStrictJsonValue,\n\tagenticMemoryRecordCodec,\n\tagenticMemoryRecordFrame,\n\tagenticMemoryRecordFrameCodec,\n\tassertAgenticMemoryRecordFrame,\n} from \"../solutions/index.js\";\nimport type { AppendLogEntry, AppendLogStorageTier, KvStorageTier } from \"../storage/index.js\";\n\nexport const AGENTIC_MEMORY_RECORD_SNAPSHOT_FORMAT =\n\t\"graphrefly.agenticMemory.records.snapshot\" as const;\nexport const AGENTIC_MEMORY_RECORD_CHANGE_FORMAT =\n\t\"graphrefly.agenticMemory.records.change\" as const;\nexport const AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION = 1 as const;\n\nexport interface AgenticMemoryRecordSnapshotFrame<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n> {\n\treadonly format: typeof AGENTIC_MEMORY_RECORD_SNAPSHOT_FORMAT;\n\treadonly version: typeof AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION;\n\treadonly changeCursor: number;\n\treadonly records: readonly AgenticMemoryRecordFrame<TJson>[];\n}\n\nexport interface AgenticMemoryRecordChangeFrame<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n> {\n\treadonly format: typeof AGENTIC_MEMORY_RECORD_CHANGE_FORMAT;\n\treadonly version: typeof AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION;\n\treadonly change: {\n\t\treadonly kind: \"replaceAll\";\n\t\treadonly records: readonly AgenticMemoryRecordFrame<TJson>[];\n\t};\n}\n\nexport interface AgenticMemoryRecordsRestoreState<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n> {\n\treadonly records: readonly AgenticMemoryRecord<TJson>[];\n\treadonly source: \"empty\" | \"changes\" | \"snapshot\" | \"snapshot+changes\";\n\treadonly snapshot: { readonly found: boolean; readonly changeCursor: number };\n\treadonly changes: { readonly applied: number; readonly cursor: number };\n}\n\nexport interface LoadAgenticMemoryRecordsStateOptions {\n\treadonly snapshotStore: KvStorageTier<unknown>;\n\treadonly snapshotKey?: string;\n\treadonly storagePrefix?: string;\n\treadonly changeLog?: AppendLogStorageTier<unknown>;\n}\n\nexport interface AgenticMemoryRecordsPersistenceCursor {\n\treadonly kind: \"persistence.cursor\";\n\treadonly changeSeq: number;\n\treadonly snapshotWrites: number;\n\treadonly changeWrites: number;\n}\n\nexport interface AgenticMemoryRecordsPersistenceStatus {\n\treadonly state: \"starting\" | \"ready\" | \"flushing\" | \"errored\" | \"disposed\";\n\treadonly pending: number;\n\treadonly writes: number;\n\treadonly errors: number;\n\treadonly cursor: AgenticMemoryRecordsPersistenceCursor;\n}\n\nexport interface AgenticMemoryRecordsPersistenceError {\n\treadonly phase: \"snapshot\" | \"change\";\n\treadonly message: string;\n\treadonly cursor: AgenticMemoryRecordsPersistenceCursor;\n}\n\nexport interface PersistAgenticMemoryRecordsOptions {\n\treadonly name?: string;\n\treadonly snapshotStore: KvStorageTier<unknown>;\n\treadonly snapshotKey?: string;\n\treadonly storagePrefix?: string;\n\treadonly changeLog?: AppendLogStorageTier<unknown>;\n\treadonly initialChangeCursor?: number;\n\treadonly snapshotOnAttach?: boolean;\n\treadonly snapshotEveryChanges?: number;\n}\n\nexport interface AgenticMemoryRecordsPersistenceHandle {\n\treadonly ready: StateNode<boolean>;\n\treadonly status: StateNode<AgenticMemoryRecordsPersistenceStatus>;\n\treadonly error: StateNode<AgenticMemoryRecordsPersistenceError | null>;\n\treadonly cursor: StateNode<AgenticMemoryRecordsPersistenceCursor>;\n\tflush(done?: (status: AgenticMemoryRecordsPersistenceStatus) => void): void;\n\tsnapshot(done?: (status: AgenticMemoryRecordsPersistenceStatus) => void): void;\n\tdispose(done?: (status: AgenticMemoryRecordsPersistenceStatus) => void): void;\n}\n\nexport interface OpenPersistentAgenticMemoryRecordsOptions<\n\tTJson extends AgenticMemoryStrictJsonValue,\n> extends LoadAgenticMemoryRecordsStateOptions,\n\t\tOmit<\n\t\t\tPersistAgenticMemoryRecordsOptions,\n\t\t\t\"snapshotStore\" | \"changeLog\" | \"initialChangeCursor\"\n\t\t> {\n\treadonly graph: Graph;\n\treadonly name?: string;\n\treadonly initial?: readonly AgenticMemoryRecord<TJson>[];\n}\n\nexport interface PersistentAgenticMemoryRecords<TJson extends AgenticMemoryStrictJsonValue> {\n\treadonly records: StateNode<readonly AgenticMemoryRecord<TJson>[]>;\n\treadonly persistence: AgenticMemoryRecordsPersistenceHandle;\n\treadonly loaded: AgenticMemoryRecordsRestoreState<TJson>;\n}\n\ninterface QueueItem {\n\treadonly phase: \"snapshot\" | \"change\" | \"flush\" | \"dispose\";\n\treadonly done?: (status: AgenticMemoryRecordsPersistenceStatus) => void;\n\trun(): void | PromiseLike<void>;\n}\n\nexport function agenticMemoryRecordsSnapshotKey(storagePrefix = \"agentic-memory\"): string {\n\tif (storagePrefix.length === 0) throw new TypeError(\"storagePrefix must be non-empty\");\n\treturn `${storagePrefix}/records.snapshot`;\n}\n\nexport function agenticMemoryRecordSnapshotFrame<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n>(\n\trecords: readonly AgenticMemoryRecord<TJson>[],\n\topts: { readonly changeCursor?: number } = {},\n): AgenticMemoryRecordSnapshotFrame<TJson> {\n\tconst changeCursor = validateChangeCursor(opts.changeCursor ?? -1);\n\treturn assertAgenticMemoryRecordSnapshotFrame({\n\t\tformat: AGENTIC_MEMORY_RECORD_SNAPSHOT_FORMAT,\n\t\tversion: AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION,\n\t\tchangeCursor,\n\t\trecords: records.map((record) => agenticMemoryRecordFrame(record)),\n\t});\n}\n\nexport function agenticMemoryRecordChangeFrame<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n>(records: readonly AgenticMemoryRecord<TJson>[]): AgenticMemoryRecordChangeFrame<TJson> {\n\treturn assertAgenticMemoryRecordChangeFrame({\n\t\tformat: AGENTIC_MEMORY_RECORD_CHANGE_FORMAT,\n\t\tversion: AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION,\n\t\tchange: {\n\t\t\tkind: \"replaceAll\",\n\t\t\trecords: records.map((record) => agenticMemoryRecordFrame(record)),\n\t\t},\n\t});\n}\n\nexport function assertAgenticMemoryRecordSnapshotFrame<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n>(value: unknown): AgenticMemoryRecordSnapshotFrame<TJson> {\n\tif (!isPlainRecord(value)) throw new TypeError(\"agentic memory snapshot frame must be an object\");\n\tassertKeys(\n\t\tvalue,\n\t\t[\"changeCursor\", \"format\", \"records\", \"version\"],\n\t\t\"agentic memory snapshot frame\",\n\t);\n\tif (value.format !== AGENTIC_MEMORY_RECORD_SNAPSHOT_FORMAT) {\n\t\tthrow new TypeError(\"agentic memory snapshot frame: invalid format\");\n\t}\n\tif (value.version !== AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION) {\n\t\tthrow new TypeError(\"agentic memory snapshot frame: invalid version\");\n\t}\n\tconst changeCursor = validateChangeCursor(value.changeCursor);\n\tif (!Array.isArray(value.records)) {\n\t\tthrow new TypeError(\"agentic memory snapshot frame: records must be an array\");\n\t}\n\tconst records = assertDenseRecordFrames<TJson>(\n\t\tvalue.records,\n\t\t\"agentic memory snapshot frame records\",\n\t);\n\treturn Object.freeze({\n\t\tformat: AGENTIC_MEMORY_RECORD_SNAPSHOT_FORMAT,\n\t\tversion: AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION,\n\t\tchangeCursor,\n\t\trecords: Object.freeze(records),\n\t});\n}\n\nexport function assertAgenticMemoryRecordChangeFrame<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n>(value: unknown): AgenticMemoryRecordChangeFrame<TJson> {\n\tif (!isPlainRecord(value)) throw new TypeError(\"agentic memory change frame must be an object\");\n\tassertKeys(value, [\"change\", \"format\", \"version\"], \"agentic memory change frame\");\n\tif (value.format !== AGENTIC_MEMORY_RECORD_CHANGE_FORMAT) {\n\t\tthrow new TypeError(\"agentic memory change frame: invalid format\");\n\t}\n\tif (value.version !== AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION) {\n\t\tthrow new TypeError(\"agentic memory change frame: invalid version\");\n\t}\n\tif (!isPlainRecord(value.change)) {\n\t\tthrow new TypeError(\"agentic memory change frame: change must be an object\");\n\t}\n\tassertKeys(value.change, [\"kind\", \"records\"], \"agentic memory change frame change\");\n\tif (value.change.kind !== \"replaceAll\") {\n\t\tthrow new TypeError(\"agentic memory change frame: change.kind must be replaceAll\");\n\t}\n\tif (!Array.isArray(value.change.records)) {\n\t\tthrow new TypeError(\"agentic memory change frame: change.records must be an array\");\n\t}\n\tconst records = assertDenseRecordFrames<TJson>(\n\t\tvalue.change.records,\n\t\t\"agentic memory change frame records\",\n\t);\n\treturn Object.freeze({\n\t\tformat: AGENTIC_MEMORY_RECORD_CHANGE_FORMAT,\n\t\tversion: AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION,\n\t\tchange: Object.freeze({\n\t\t\tkind: \"replaceAll\",\n\t\t\trecords: Object.freeze(records),\n\t\t}),\n\t});\n}\n\nexport function loadAgenticMemoryRecordsState<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n>(opts: LoadAgenticMemoryRecordsStateOptions): Promise<AgenticMemoryRecordsRestoreState<TJson>> {\n\tconst storagePrefix = opts.storagePrefix ?? \"agentic-memory\";\n\tconst snapshotKey = opts.snapshotKey ?? agenticMemoryRecordsSnapshotKey(storagePrefix);\n\treturn opts.snapshotStore.get(snapshotKey).then((rawSnapshot) => {\n\t\tlet records: readonly AgenticMemoryRecord<TJson>[] = [];\n\t\tlet source: AgenticMemoryRecordsRestoreState<TJson>[\"source\"] = \"empty\";\n\t\tlet changeCursor = -1;\n\t\tif (rawSnapshot !== undefined) {\n\t\t\tconst snapshot = assertAgenticMemoryRecordSnapshotFrame<TJson>(rawSnapshot);\n\t\t\trecords = snapshot.records.map(recordFromFrame);\n\t\t\tchangeCursor = snapshot.changeCursor;\n\t\t\tsource = \"snapshot\";\n\t\t}\n\t\tif (opts.changeLog === undefined) {\n\t\t\treturn {\n\t\t\t\trecords,\n\t\t\t\tsource,\n\t\t\t\tsnapshot: { found: rawSnapshot !== undefined, changeCursor },\n\t\t\t\tchanges: { applied: 0, cursor: changeCursor },\n\t\t\t};\n\t\t}\n\t\treturn opts.changeLog.read({ after: changeCursor }).then((entries) => {\n\t\t\tlet applied = 0;\n\t\t\tlet cursor = changeCursor;\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (entry.seq !== cursor + 1) {\n\t\t\t\t\tthrow new Error(\"agentic memory records change log is non-contiguous\");\n\t\t\t\t}\n\t\t\t\tconst change = assertAgenticMemoryRecordChangeFrame<TJson>(entry.value);\n\t\t\t\trecords = change.change.records.map(recordFromFrame);\n\t\t\t\tcursor = entry.seq;\n\t\t\t\tapplied += 1;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trecords,\n\t\t\t\tsource:\n\t\t\t\t\trawSnapshot !== undefined && applied > 0\n\t\t\t\t\t\t? \"snapshot+changes\"\n\t\t\t\t\t\t: rawSnapshot !== undefined\n\t\t\t\t\t\t\t? \"snapshot\"\n\t\t\t\t\t\t\t: applied > 0\n\t\t\t\t\t\t\t\t? \"changes\"\n\t\t\t\t\t\t\t\t: \"empty\",\n\t\t\t\tsnapshot: { found: rawSnapshot !== undefined, changeCursor },\n\t\t\t\tchanges: { applied, cursor },\n\t\t\t};\n\t\t});\n\t});\n}\n\nexport function persistAgenticMemoryRecords<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n>(\n\tgraph: Graph,\n\trecords: Node<readonly AgenticMemoryRecord<TJson>[]>,\n\topts: PersistAgenticMemoryRecordsOptions,\n): AgenticMemoryRecordsPersistenceHandle {\n\tconst name = opts.name ?? \"agenticMemoryRecords.persistence\";\n\tconst snapshotKey =\n\t\topts.snapshotKey ?? agenticMemoryRecordsSnapshotKey(opts.storagePrefix ?? name);\n\tconst snapshotEveryChanges = validateSnapshotEveryChanges(opts.snapshotEveryChanges);\n\tassertGraphLocalNode(graph, records as Node<unknown>, `${name}.records`);\n\tlet cursorValue: AgenticMemoryRecordsPersistenceCursor = {\n\t\tkind: \"persistence.cursor\",\n\t\tchangeSeq: validateChangeCursor(opts.initialChangeCursor ?? -1),\n\t\tsnapshotWrites: 0,\n\t\tchangeWrites: 0,\n\t};\n\tlet statusValue = statusOf(\"starting\", 0, 0, 0, cursorValue);\n\tlet errorCount = 0;\n\tlet writes = 0;\n\tlet running = false;\n\tlet disposed = false;\n\tlet disposeRequested = false;\n\tlet subscribing = true;\n\tlet observedChangesSinceSnapshot = 0;\n\tlet latestRecords: readonly AgenticMemoryRecord<TJson>[] = records.cache ?? [];\n\tlet stop: (() => void) | undefined;\n\tconst queue: QueueItem[] = [];\n\tconst ready = graph.state(false, { name: `${name}/ready` });\n\tconst status = graph.state<AgenticMemoryRecordsPersistenceStatus>(statusValue, {\n\t\tname: `${name}/status`,\n\t});\n\tconst error = graph.state<AgenticMemoryRecordsPersistenceError | null>(null, {\n\t\tname: `${name}/error`,\n\t});\n\tconst cursor = graph.state<AgenticMemoryRecordsPersistenceCursor>(cursorValue, {\n\t\tname: `${name}/cursor`,\n\t});\n\n\tfunction publish(state: AgenticMemoryRecordsPersistenceStatus[\"state\"]): void {\n\t\tconst nextState = statusValue.state === \"errored\" && state !== \"disposed\" ? \"errored\" : state;\n\t\tstatusValue = statusOf(\n\t\t\tnextState,\n\t\t\tqueue.length + (running ? 1 : 0),\n\t\t\twrites,\n\t\t\terrorCount,\n\t\t\tcursorValue,\n\t\t);\n\t\tcursor.set(cursorValue);\n\t\tstatus.set(statusValue);\n\t\tif (nextState === \"ready\") ready.set(true);\n\t\tif (nextState === \"errored\" || nextState === \"disposed\") ready.set(false);\n\t}\n\n\tfunction report(phase: \"snapshot\" | \"change\", caught: unknown): void {\n\t\terrorCount += 1;\n\t\terror.set({ phase, message: errorMessage(caught), cursor: cursorValue });\n\t}\n\n\tfunction callDone(done: QueueItem[\"done\"]): void {\n\t\ttry {\n\t\t\tdone?.(statusValue);\n\t\t} catch {\n\t\t\t// Done callbacks are advisory controls and must not wedge the adapter queue.\n\t\t}\n\t}\n\n\tfunction finish(item: QueueItem): void {\n\t\tif (item.phase === \"dispose\") {\n\t\t\tdisposed = true;\n\t\t\trunning = false;\n\t\t\tpublish(\"disposed\");\n\t\t} else if (statusValue.state !== \"errored\") {\n\t\t\trunning = false;\n\t\t\tpublish(\"ready\");\n\t\t} else {\n\t\t\trunning = false;\n\t\t\tpublish(\"errored\");\n\t\t}\n\t\tcallDone(item.done);\n\t\tdrain();\n\t}\n\n\tfunction fail(item: QueueItem, caught: unknown): void {\n\t\tif (item.phase === \"snapshot\" || item.phase === \"change\") report(item.phase, caught);\n\t\trunning = false;\n\t\tif (item.phase === \"snapshot\" || item.phase === \"change\") publish(\"errored\");\n\t\tcallDone(item.done);\n\t\tdrain();\n\t}\n\n\tfunction chainThenable(item: QueueItem, value: unknown): boolean {\n\t\tif ((typeof value !== \"object\" && typeof value !== \"function\") || value === null) return false;\n\t\tconst then = (value as { then?: unknown }).then;\n\t\tif (typeof then !== \"function\") return false;\n\t\tlet settled = false;\n\t\tconst settle = (next: () => void) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tnext();\n\t\t};\n\t\ttry {\n\t\t\t(then as (onFulfilled: () => void, onRejected: (error: unknown) => void) => unknown).call(\n\t\t\t\tvalue,\n\t\t\t\t() => settle(() => finish(item)),\n\t\t\t\t(caught) => settle(() => fail(item, caught)),\n\t\t\t);\n\t\t} catch (caught) {\n\t\t\tsettle(() => fail(item, caught));\n\t\t}\n\t\treturn true;\n\t}\n\n\tfunction enqueue(item: QueueItem): void {\n\t\tif (disposed || (disposeRequested && item.phase !== \"dispose\" && item.phase !== \"flush\")) {\n\t\t\tcallDone(item.done);\n\t\t\treturn;\n\t\t}\n\t\tqueue.push(item);\n\t\tdrain();\n\t}\n\n\tfunction drain(): void {\n\t\tif (running) return;\n\t\tconst item = queue.shift();\n\t\tif (item === undefined) return;\n\t\trunning = true;\n\t\tpublish(\n\t\t\titem.phase === \"flush\" ? \"flushing\" : statusValue.state === \"starting\" ? \"starting\" : \"ready\",\n\t\t);\n\t\tlet result: void | PromiseLike<void>;\n\t\ttry {\n\t\t\tresult = item.run();\n\t\t} catch (caught) {\n\t\t\tfail(item, caught);\n\t\t\treturn;\n\t\t}\n\t\tif (chainThenable(item, result)) return;\n\t\tfinish(item);\n\t}\n\n\tfunction enqueueSnapshot(done?: (status: AgenticMemoryRecordsPersistenceStatus) => void): void {\n\t\tconst snapshotRecords = latestRecords;\n\t\tobservedChangesSinceSnapshot = 0;\n\t\tenqueue({\n\t\t\tphase: \"snapshot\",\n\t\t\tdone,\n\t\t\trun() {\n\t\t\t\tconst records = Object.freeze(\n\t\t\t\t\tsnapshotRecords.map((record) => agenticMemoryRecordFrame(record)),\n\t\t\t\t);\n\t\t\t\tconst frame = assertAgenticMemoryRecordSnapshotFrame<TJson>({\n\t\t\t\t\tformat: AGENTIC_MEMORY_RECORD_SNAPSHOT_FORMAT,\n\t\t\t\t\tversion: AGENTIC_MEMORY_RECORD_STORAGE_FRAME_VERSION,\n\t\t\t\t\tchangeCursor: cursorValue.changeSeq,\n\t\t\t\t\trecords,\n\t\t\t\t});\n\t\t\t\treturn opts.snapshotStore.set(snapshotKey, frame).then(() => {\n\t\t\t\t\tcursorValue = { ...cursorValue, snapshotWrites: cursorValue.snapshotWrites + 1 };\n\t\t\t\t\twrites += 1;\n\t\t\t\t\tpublish(\"ready\");\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\tfunction enqueueChange(nextRecords: readonly AgenticMemoryRecord<TJson>[]): void {\n\t\tconst changeLog = opts.changeLog;\n\t\tif (changeLog === undefined) return;\n\t\tenqueue({\n\t\t\tphase: \"change\",\n\t\t\trun() {\n\t\t\t\tconst frame = agenticMemoryRecordChangeFrame(nextRecords);\n\t\t\t\treturn changeLog.append(frame).then((written) => {\n\t\t\t\t\tconst entry = written as AppendLogEntry<AgenticMemoryRecordChangeFrame<TJson>>;\n\t\t\t\t\tcursorValue = {\n\t\t\t\t\t\t...cursorValue,\n\t\t\t\t\t\tchangeSeq: entry.seq,\n\t\t\t\t\t\tchangeWrites: cursorValue.changeWrites + 1,\n\t\t\t\t\t};\n\t\t\t\t\twrites += 1;\n\t\t\t\t\tpublish(\"ready\");\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\tfunction cancelQueuedForDispose(): void {\n\t\tconst pending = queue.splice(0);\n\t\tfor (const item of pending) callDone(item.done);\n\t}\n\n\tstop = records.subscribe((msg: Message, delivery?: DeliveryMeta) => {\n\t\tif (disposeRequested) return;\n\t\tconst nextRecords = dataOf<readonly AgenticMemoryRecord<TJson>[]>(msg);\n\t\tif (nextRecords === undefined) return;\n\t\tlatestRecords = nextRecords;\n\t\tif (subscribing && delivery === undefined) return;\n\t\tobservedChangesSinceSnapshot += 1;\n\t\tenqueueChange(nextRecords);\n\t\tif (\n\t\t\tsnapshotEveryChanges !== undefined &&\n\t\t\tobservedChangesSinceSnapshot >= snapshotEveryChanges\n\t\t) {\n\t\t\tenqueueSnapshot();\n\t\t}\n\t});\n\tsubscribing = false;\n\tif (opts.snapshotOnAttach !== false) enqueueSnapshot();\n\telse publish(\"ready\");\n\n\treturn {\n\t\tready,\n\t\tstatus,\n\t\terror,\n\t\tcursor,\n\t\tflush(done?: (status: AgenticMemoryRecordsPersistenceStatus) => void): void {\n\t\t\tif (disposed) {\n\t\t\t\tcallDone(done);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tenqueue({ phase: \"flush\", done, run: () => undefined });\n\t\t},\n\t\tsnapshot(done?: (status: AgenticMemoryRecordsPersistenceStatus) => void): void {\n\t\t\tif (disposed || disposeRequested) {\n\t\t\t\tcallDone(done);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tenqueueSnapshot(done);\n\t\t},\n\t\tdispose(done?: (status: AgenticMemoryRecordsPersistenceStatus) => void): void {\n\t\t\tif (disposed) {\n\t\t\t\tcallDone(done);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdisposeRequested = true;\n\t\t\tstop?.();\n\t\t\tcancelQueuedForDispose();\n\t\t\tenqueue({ phase: \"dispose\", done, run: () => undefined });\n\t\t},\n\t};\n}\n\nexport function openPersistentAgenticMemoryRecords<\n\tTJson extends AgenticMemoryStrictJsonValue = AgenticMemoryStrictJsonValue,\n>(\n\topts: OpenPersistentAgenticMemoryRecordsOptions<TJson>,\n): Promise<PersistentAgenticMemoryRecords<TJson>> {\n\tconst storagePrefix = opts.storagePrefix ?? opts.name ?? \"agentic-memory\";\n\tconst snapshotKey = opts.snapshotKey ?? agenticMemoryRecordsSnapshotKey(storagePrefix);\n\treturn loadAgenticMemoryRecordsState<TJson>({ ...opts, snapshotKey, storagePrefix }).then(\n\t\t(loaded) => {\n\t\t\tconst records =\n\t\t\t\tloaded.source === \"empty\" && opts.initial !== undefined ? opts.initial : loaded.records;\n\t\t\tconst node = opts.graph.state<readonly AgenticMemoryRecord<TJson>[]>(records, {\n\t\t\t\tname: opts.name,\n\t\t\t});\n\t\t\tconst persistence = persistAgenticMemoryRecords(opts.graph, node, {\n\t\t\t\t...opts,\n\t\t\t\tname: opts.name ? `${opts.name}/persistence` : undefined,\n\t\t\t\tsnapshotKey,\n\t\t\t\tstoragePrefix,\n\t\t\t\tinitialChangeCursor: loaded.changes.cursor,\n\t\t\t});\n\t\t\treturn { records: node, persistence, loaded };\n\t\t},\n\t);\n}\n\nfunction recordFromFrame<TJson extends AgenticMemoryStrictJsonValue>(\n\tframe: AgenticMemoryRecordFrame<TJson>,\n): AgenticMemoryRecord<TJson> {\n\treturn agenticMemoryRecordCodec<TJson>().decode(\n\t\tagenticMemoryRecordFrameCodec<TJson>().encode(frame),\n\t);\n}\n\nfunction statusOf(\n\tstate: AgenticMemoryRecordsPersistenceStatus[\"state\"],\n\tpending: number,\n\twrites: number,\n\terrors: number,\n\tcursor: AgenticMemoryRecordsPersistenceCursor,\n): AgenticMemoryRecordsPersistenceStatus {\n\treturn { state, pending, writes, errors, cursor };\n}\n\nfunction dataOf<C>(msg: Message): C | undefined {\n\treturn msg[0] === \"DATA\" ? (msg[1] as C) : undefined;\n}\n\nfunction validateChangeCursor(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < -1) {\n\t\tthrow new RangeError(\"changeCursor must be a safe integer >= -1\");\n\t}\n\treturn value;\n}\n\nfunction validateSnapshotEveryChanges(value: number | undefined): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (!Number.isSafeInteger(value) || value < 1) {\n\t\tthrow new RangeError(\"snapshotEveryChanges must be a positive safe integer\");\n\t}\n\treturn value;\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction assertKeys(\n\tvalue: Record<string, unknown>,\n\texpected: readonly string[],\n\tlabel: string,\n): void {\n\tconst actual = Object.keys(value).sort();\n\tconst want = [...expected].sort();\n\tif (actual.length !== want.length || actual.some((key, i) => key !== want[i])) {\n\t\tthrow new TypeError(`${label}: unexpected frame fields ${actual.join(\",\")}`);\n\t}\n}\n\nfunction assertDenseRecordFrames<TJson extends AgenticMemoryStrictJsonValue>(\n\tvalue: readonly unknown[],\n\tlabel: string,\n): readonly AgenticMemoryRecordFrame<TJson>[] {\n\tconst records: AgenticMemoryRecordFrame<TJson>[] = [];\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tif (!Object.hasOwn(value, i)) {\n\t\t\tthrow new TypeError(`${label}: sparse array hole at ${i}`);\n\t\t}\n\t\trecords.push(assertAgenticMemoryRecordFrame<TJson>(value[i]));\n\t}\n\treturn Object.freeze(records);\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n","import type { DeliveryMeta } from \"../ctx/types.js\";\nimport {\n\ttype ReactiveIndex,\n\ttype ReactiveIndexOptions,\n\ttype ReactiveList,\n\ttype ReactiveListOptions,\n\ttype ReactiveLog,\n\ttype ReactiveLogOptions,\n\ttype ReactiveMap,\n\ttype ReactiveMapOptions,\n\trestoreReactiveIndex,\n\trestoreReactiveList,\n\trestoreReactiveLog,\n\trestoreReactiveMap,\n} from \"../data-structures/index.js\";\nimport type {\n\tIndexChange,\n\tListChange,\n\tLogChange,\n\tMapChange,\n} from \"../graph/data-structures/change.js\";\nimport type { IndexRow } from \"../graph/data-structures/reactive-index.js\";\nimport { assertGraphLocalNode, type Graph, type StateNode } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\nimport type { Message } from \"../protocol/messages.js\";\nimport type {\n\tAppendLogEntry,\n\tAppendLogStorageTier,\n\tKvStorageTier,\n\tLoadReactiveCollectionStateOptions,\n\tReactiveCollectionChangeFrame,\n\tReactiveCollectionSnapshotFrame,\n\tReactiveIndexRestoreState,\n\tReactiveListRestoreState,\n\tReactiveLogRestoreState,\n\tReactiveMapRestoreState,\n} from \"../storage/index.js\";\nimport {\n\tassertReactiveCollectionChangeFrame,\n\tassertReactiveCollectionSnapshotFrame,\n\tcollectionSnapshotKey,\n\tloadReactiveIndexState,\n\tloadReactiveListState,\n\tloadReactiveLogState,\n\tloadReactiveMapState,\n\treactiveCollectionChangeFrame,\n\treactiveCollectionSnapshotFrame,\n} from \"../storage/index.js\";\n\ntype PersistableKind = \"reactiveList\" | \"reactiveLog\" | \"reactiveMap\" | \"reactiveIndex\";\ntype PersistableChange<T, K extends PersistableKind> = K extends \"reactiveList\"\n\t? ListChange<T>\n\t: K extends \"reactiveLog\"\n\t\t? LogChange<T>\n\t\t: K extends \"reactiveMap\"\n\t\t\t? MapChange<unknown, T>\n\t\t\t: IndexChange<unknown, T>;\ntype PersistableCollection<T, K extends PersistableKind> = K extends \"reactiveList\"\n\t? ReactiveList<T>\n\t: K extends \"reactiveLog\"\n\t\t? ReactiveLog<T>\n\t\t: K extends \"reactiveMap\"\n\t\t\t? ReactiveMap<unknown, T>\n\t\t\t: ReactiveIndex<unknown, T>;\n\n/** D161 adapter write-progress cursor; this is not a domain replay or wire-bridge cursor. */\nexport interface ReactiveCollectionPersistenceCursor {\n\treadonly kind: \"persistence.cursor\";\n\treadonly collection: PersistableKind;\n\treadonly changeSeq: number;\n\treadonly snapshotWrites: number;\n\treadonly changeWrites: number;\n}\n\n/** D161 graph-visible persistence sidecar status fact. */\nexport interface ReactiveCollectionPersistenceStatus {\n\treadonly state: \"starting\" | \"ready\" | \"flushing\" | \"errored\" | \"disposed\";\n\treadonly pending: number;\n\treadonly writes: number;\n\treadonly errors: number;\n\treadonly cursor: ReactiveCollectionPersistenceCursor;\n}\n\n/** D161 graph-visible persistence sidecar error fact. */\nexport interface ReactiveCollectionPersistenceError {\n\treadonly phase: \"snapshot\" | \"change\";\n\treadonly message: string;\n\treadonly cursor: ReactiveCollectionPersistenceCursor;\n}\n\n/** Options for the D161 graph-bound persistence sidecar over a reactive collection. */\nexport interface PersistReactiveCollectionOptions<K extends PersistableKind = PersistableKind> {\n\treadonly kind: K;\n\treadonly name?: string;\n\treadonly snapshotStore: KvStorageTier<unknown>;\n\treadonly snapshotKey?: string;\n\treadonly storagePrefix?: string;\n\treadonly changeLog?: AppendLogStorageTier<unknown>;\n\t/** Adapter write cursor seed for wrappers that already folded a change log. */\n\treadonly initialChangeCursor?: number;\n\t/** Default true: write one durable baseline when the adapter attaches. */\n\treadonly snapshotOnAttach?: boolean;\n\t/** Optional snapshot cadence. Manual snapshots remain available via handle.snapshot(). */\n\treadonly snapshotEveryChanges?: number;\n}\n\n/** D161 sidecar controls; flush waits for queued storage promises to settle, not fsync. */\nexport interface ReactiveCollectionPersistenceHandle {\n\treadonly ready: StateNode<boolean>;\n\treadonly status: StateNode<ReactiveCollectionPersistenceStatus>;\n\treadonly error: StateNode<ReactiveCollectionPersistenceError | null>;\n\treadonly cursor: StateNode<ReactiveCollectionPersistenceCursor>;\n\tflush(done?: (status: ReactiveCollectionPersistenceStatus) => void): void;\n\tsnapshot(done?: (status: ReactiveCollectionPersistenceStatus) => void): void;\n\tdispose(done?: (status: ReactiveCollectionPersistenceStatus) => void): void;\n}\n\ninterface QueueItem {\n\treadonly phase: \"snapshot\" | \"change\" | \"flush\" | \"dispose\";\n\treadonly done?: (status: ReactiveCollectionPersistenceStatus) => void;\n\trun(): void | PromiseLike<void>;\n}\n\nfunction emptyCursor(collection: PersistableKind): ReactiveCollectionPersistenceCursor {\n\treturn {\n\t\tkind: \"persistence.cursor\",\n\t\tcollection,\n\t\tchangeSeq: -1,\n\t\tsnapshotWrites: 0,\n\t\tchangeWrites: 0,\n\t};\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction validateSnapshotEveryChanges(value: number | undefined): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (!Number.isSafeInteger(value) || value < 1) {\n\t\tthrow new RangeError(\"snapshotEveryChanges must be a positive safe integer\");\n\t}\n\treturn value;\n}\n\nfunction validateInitialChangeCursor(value: number | undefined): number {\n\tif (value === undefined) return -1;\n\tif (!Number.isSafeInteger(value) || value < -1) {\n\t\tthrow new RangeError(\"initialChangeCursor must be a safe integer >= -1\");\n\t}\n\treturn value;\n}\n\nfunction statusOf(\n\tstate: ReactiveCollectionPersistenceStatus[\"state\"],\n\tpending: number,\n\twrites: number,\n\terrors: number,\n\tcursor: ReactiveCollectionPersistenceCursor,\n): ReactiveCollectionPersistenceStatus {\n\treturn { state, pending, writes, errors, cursor };\n}\n\nfunction dataOf<C>(msg: Message): C | undefined {\n\treturn msg[0] === \"DATA\" ? (msg[1] as C) : undefined;\n}\n\n/**\n * D161 graph-bound sidecar over an existing collection. It writes passive storage frames and\n * exposes adapter progress as graph-visible DATA facts; it never restores or mutates the collection.\n */\nexport function persistReactiveCollection<T, K extends PersistableKind>(\n\tgraph: Graph,\n\tcollection: PersistableCollection<T, K>,\n\topts: PersistReactiveCollectionOptions<K>,\n): ReactiveCollectionPersistenceHandle {\n\tconst kind = opts.kind;\n\tconst name = opts.name ?? `${kind}.persistence`;\n\tconst snapshotKey = opts.snapshotKey ?? collectionSnapshotKey(opts.storagePrefix ?? name);\n\tconst snapshotEveryChanges = validateSnapshotEveryChanges(opts.snapshotEveryChanges);\n\tassertGraphLocalNode(graph, collection.delta as Node<unknown>, `${name}.collection.delta`);\n\tassertGraphLocalNode(graph, collection.snapshot as Node<unknown>, `${name}.collection.snapshot`);\n\n\tlet cursorValue = {\n\t\t...emptyCursor(kind),\n\t\tchangeSeq: validateInitialChangeCursor(opts.initialChangeCursor),\n\t};\n\tlet statusValue = statusOf(\"starting\", 0, 0, 0, cursorValue);\n\tlet errorCount = 0;\n\tlet writes = 0;\n\tlet observedChangesSinceSnapshot = 0;\n\tlet running = false;\n\tlet disposed = false;\n\tlet disposeRequested = false;\n\tlet subscribing = true;\n\tlet stop: (() => void) | undefined;\n\tconst queue: QueueItem[] = [];\n\n\tconst ready = graph.state(false, { name: `${name}/ready` });\n\tconst status = graph.state<ReactiveCollectionPersistenceStatus>(statusValue, {\n\t\tname: `${name}/status`,\n\t});\n\tconst error = graph.state<ReactiveCollectionPersistenceError | null>(null, {\n\t\tname: `${name}/error`,\n\t});\n\tconst cursor = graph.state<ReactiveCollectionPersistenceCursor>(cursorValue, {\n\t\tname: `${name}/cursor`,\n\t});\n\n\tfunction publish(state: ReactiveCollectionPersistenceStatus[\"state\"]): void {\n\t\tconst nextState = statusValue.state === \"errored\" && state !== \"disposed\" ? \"errored\" : state;\n\t\tstatusValue = statusOf(\n\t\t\tnextState,\n\t\t\tqueue.length + (running ? 1 : 0),\n\t\t\twrites,\n\t\t\terrorCount,\n\t\t\tcursorValue,\n\t\t);\n\t\tcursor.set(cursorValue);\n\t\tstatus.set(statusValue);\n\t\tif (nextState === \"ready\") ready.set(true);\n\t\tif (nextState === \"errored\" || nextState === \"disposed\") ready.set(false);\n\t}\n\n\tfunction report(phase: \"snapshot\" | \"change\", caught: unknown): void {\n\t\terrorCount += 1;\n\t\tconst fact = { phase, message: errorMessage(caught), cursor: cursorValue };\n\t\terror.set(fact);\n\t}\n\n\tfunction callDone(done: QueueItem[\"done\"]): void {\n\t\ttry {\n\t\t\tdone?.(statusValue);\n\t\t} catch {\n\t\t\t// Done callbacks are advisory barriers; user code must not wedge the adapter queue.\n\t\t}\n\t}\n\n\tfunction finish(item: QueueItem): void {\n\t\tif (item.phase === \"dispose\") {\n\t\t\tdisposed = true;\n\t\t\trunning = false;\n\t\t\tpublish(\"disposed\");\n\t\t} else if (statusValue.state !== \"errored\") {\n\t\t\trunning = false;\n\t\t\tpublish(\"ready\");\n\t\t} else {\n\t\t\trunning = false;\n\t\t\tpublish(\"errored\");\n\t\t}\n\t\tcallDone(item.done);\n\t\tdrain();\n\t}\n\n\tfunction fail(item: QueueItem, caught: unknown): void {\n\t\tif (item.phase === \"snapshot\" || item.phase === \"change\") report(item.phase, caught);\n\t\trunning = false;\n\t\tif (item.phase === \"snapshot\" || item.phase === \"change\") publish(\"errored\");\n\t\tcallDone(item.done);\n\t\tdrain();\n\t}\n\n\tfunction chainThenable(item: QueueItem, value: unknown): boolean {\n\t\tif ((typeof value !== \"object\" && typeof value !== \"function\") || value === null) return false;\n\t\tlet then: unknown;\n\t\ttry {\n\t\t\tthen = (value as { then?: unknown }).then;\n\t\t} catch (caught) {\n\t\t\tfail(item, caught);\n\t\t\treturn true;\n\t\t}\n\t\tif (typeof then !== \"function\") return false;\n\t\tlet settled = false;\n\t\tconst settle = (next: () => void) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tnext();\n\t\t};\n\t\ttry {\n\t\t\t(then as (onFulfilled: () => void, onRejected: (error: unknown) => void) => unknown).call(\n\t\t\t\tvalue,\n\t\t\t\t() => settle(() => finish(item)),\n\t\t\t\t(caught) => settle(() => fail(item, caught)),\n\t\t\t);\n\t\t} catch (caught) {\n\t\t\tsettle(() => fail(item, caught));\n\t\t}\n\t\treturn true;\n\t}\n\n\tfunction enqueue(item: QueueItem): void {\n\t\tif (disposed || (disposeRequested && item.phase !== \"dispose\" && item.phase !== \"flush\")) {\n\t\t\tcallDone(item.done);\n\t\t\treturn;\n\t\t}\n\t\tqueue.push(item);\n\t\tdrain();\n\t}\n\n\tfunction drain(): void {\n\t\tif (running) return;\n\t\tconst item = queue.shift();\n\t\tif (item === undefined) return;\n\t\trunning = true;\n\t\tpublish(\n\t\t\titem.phase === \"flush\" ? \"flushing\" : statusValue.state === \"starting\" ? \"starting\" : \"ready\",\n\t\t);\n\t\tlet result: void | PromiseLike<void>;\n\t\ttry {\n\t\t\tresult = item.run();\n\t\t} catch (caught) {\n\t\t\tfail(item, caught);\n\t\t\treturn;\n\t\t}\n\t\tif (chainThenable(item, result)) return;\n\t\tfinish(item);\n\t}\n\n\tfunction enqueueSnapshot(done?: (status: ReactiveCollectionPersistenceStatus) => void): void {\n\t\tconst snapshot = collectionSnapshot(collection, kind);\n\t\tobservedChangesSinceSnapshot = 0;\n\t\tenqueue({\n\t\t\tphase: \"snapshot\",\n\t\t\tdone,\n\t\t\trun() {\n\t\t\t\tconst frame: ReactiveCollectionSnapshotFrame<K, readonly unknown[]> =\n\t\t\t\t\treactiveCollectionSnapshotFrame(kind, snapshot, {\n\t\t\t\t\t\tchangeCursor: cursorValue.changeSeq,\n\t\t\t\t\t});\n\t\t\t\tassertReactiveCollectionSnapshotFrame(frame, kind);\n\t\t\t\treturn opts.snapshotStore.set(snapshotKey, frame).then(() => {\n\t\t\t\t\tcursorValue = {\n\t\t\t\t\t\t...cursorValue,\n\t\t\t\t\t\tsnapshotWrites: cursorValue.snapshotWrites + 1,\n\t\t\t\t\t};\n\t\t\t\t\twrites += 1;\n\t\t\t\t\tpublish(\"ready\");\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\tfunction enqueueChange(change: PersistableChange<T, K>): void {\n\t\tconst changeLog = opts.changeLog;\n\t\tif (changeLog === undefined) return;\n\t\tenqueue({\n\t\t\tphase: \"change\",\n\t\t\trun() {\n\t\t\t\tconst frame: ReactiveCollectionChangeFrame<\n\t\t\t\t\tPersistableKind,\n\t\t\t\t\tPersistableChange<T, K>\n\t\t\t\t> = reactiveCollectionChangeFrame(kind, change);\n\t\t\t\tassertReactiveCollectionChangeFrame(frame, kind);\n\t\t\t\treturn changeLog.append(frame).then((written) => {\n\t\t\t\t\tconst entry = written as AppendLogEntry<\n\t\t\t\t\t\tReactiveCollectionChangeFrame<PersistableKind, PersistableChange<T, K>>\n\t\t\t\t\t>;\n\t\t\t\t\tcursorValue = {\n\t\t\t\t\t\t...cursorValue,\n\t\t\t\t\t\tchangeSeq: entry.seq,\n\t\t\t\t\t\tchangeWrites: cursorValue.changeWrites + 1,\n\t\t\t\t\t};\n\t\t\t\t\twrites += 1;\n\t\t\t\t\tpublish(\"ready\");\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\tfunction cancelQueuedForDispose(): void {\n\t\tconst pending = queue.splice(0);\n\t\tfor (const item of pending) callDone(item.done);\n\t}\n\n\tstop = (collection.delta as Node<PersistableChange<T, K>>).subscribe(\n\t\t(msg: Message, delivery?: DeliveryMeta) => {\n\t\t\tif (disposeRequested) return;\n\t\t\tconst change = dataOf<PersistableChange<T, K>>(msg);\n\t\t\tif (change === undefined) return;\n\t\t\tif (subscribing && delivery === undefined) return;\n\t\t\tobservedChangesSinceSnapshot += 1;\n\t\t\tenqueueChange(change);\n\t\t\tif (\n\t\t\t\tsnapshotEveryChanges !== undefined &&\n\t\t\t\tobservedChangesSinceSnapshot >= snapshotEveryChanges\n\t\t\t) {\n\t\t\t\tenqueueSnapshot();\n\t\t\t}\n\t\t},\n\t);\n\tsubscribing = false;\n\n\tif (opts.snapshotOnAttach !== false) enqueueSnapshot();\n\telse publish(\"ready\");\n\n\treturn {\n\t\tready,\n\t\tstatus,\n\t\terror,\n\t\tcursor,\n\t\tflush(done?: (status: ReactiveCollectionPersistenceStatus) => void): void {\n\t\t\tif (disposed) {\n\t\t\t\tcallDone(done);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tenqueue({ phase: \"flush\", done, run: () => undefined });\n\t\t},\n\t\tsnapshot(done?: (status: ReactiveCollectionPersistenceStatus) => void): void {\n\t\t\tif (disposed || disposeRequested) {\n\t\t\t\tcallDone(done);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tenqueueSnapshot(done);\n\t\t},\n\t\tdispose(done?: (status: ReactiveCollectionPersistenceStatus) => void): void {\n\t\t\tif (disposed) {\n\t\t\t\tcallDone(done);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdisposeRequested = true;\n\t\t\tstop?.();\n\t\t\tcancelQueuedForDispose();\n\t\t\tenqueue({ phase: \"dispose\", done, run: () => undefined });\n\t\t},\n\t};\n}\n\nfunction collectionSnapshot<T, K extends PersistableKind>(\n\tcollection: PersistableCollection<T, K>,\n\tkind: K,\n): readonly unknown[] {\n\tif (kind === \"reactiveMap\") {\n\t\treturn [...(collection as ReactiveMap<unknown, unknown>).toMap()];\n\t}\n\tif (kind === \"reactiveIndex\") {\n\t\treturn (collection as ReactiveIndex<unknown, unknown>).toArray();\n\t}\n\treturn (collection as ReactiveList<T> | ReactiveLog<T>).toArray();\n}\n\ntype CollectionOptionsWithoutGraphName<T> = Omit<T, \"graph\" | \"name\">;\n\n/** Options for D161 load -> restore -> persist composition for reactiveList. */\nexport interface OpenPersistentReactiveListOptions<T>\n\textends LoadReactiveCollectionStateOptions,\n\t\tOmit<\n\t\t\tPersistReactiveCollectionOptions<\"reactiveList\">,\n\t\t\t\"kind\" | \"snapshotStore\" | \"changeLog\" | \"initialChangeCursor\"\n\t\t> {\n\treadonly graph: Graph;\n\treadonly name?: string;\n\treadonly initial?: readonly T[];\n\treadonly collection?: CollectionOptionsWithoutGraphName<ReactiveListOptions>;\n}\n\n/** Options for D161 load -> restore -> persist composition for reactiveLog. */\nexport interface OpenPersistentReactiveLogOptions<T>\n\textends LoadReactiveCollectionStateOptions,\n\t\tOmit<\n\t\t\tPersistReactiveCollectionOptions<\"reactiveLog\">,\n\t\t\t\"kind\" | \"snapshotStore\" | \"changeLog\" | \"initialChangeCursor\"\n\t\t> {\n\treadonly graph: Graph;\n\treadonly name?: string;\n\treadonly initial?: readonly T[];\n\treadonly collection?: CollectionOptionsWithoutGraphName<ReactiveLogOptions>;\n}\n\n/** Options for D161 load -> restore -> persist composition for reactiveMap. */\nexport interface OpenPersistentReactiveMapOptions<K, V>\n\textends LoadReactiveCollectionStateOptions,\n\t\tOmit<\n\t\t\tPersistReactiveCollectionOptions<\"reactiveMap\">,\n\t\t\t\"kind\" | \"snapshotStore\" | \"changeLog\" | \"initialChangeCursor\"\n\t\t> {\n\treadonly graph: Graph;\n\treadonly name?: string;\n\treadonly initial?: readonly (readonly [K, V])[];\n\treadonly collection?: CollectionOptionsWithoutGraphName<ReactiveMapOptions<K, V>>;\n}\n\n/** Options for D161 load -> restore -> persist composition for reactiveIndex. */\nexport interface OpenPersistentReactiveIndexOptions<K, V>\n\textends LoadReactiveCollectionStateOptions,\n\t\tOmit<\n\t\t\tPersistReactiveCollectionOptions<\"reactiveIndex\">,\n\t\t\t\"kind\" | \"snapshotStore\" | \"changeLog\" | \"initialChangeCursor\"\n\t\t> {\n\treadonly graph: Graph;\n\treadonly name?: string;\n\treadonly initial?: readonly IndexRow<K, V>[];\n\treadonly collection?: CollectionOptionsWithoutGraphName<ReactiveIndexOptions>;\n}\n\n/** Return value for D161 persistent reactiveList composition. */\nexport interface PersistentReactiveList<T> {\n\treadonly collection: ReactiveList<T>;\n\treadonly persistence: ReactiveCollectionPersistenceHandle;\n\treadonly loaded: ReactiveListRestoreState<T>;\n}\n\n/** Return value for D161 persistent reactiveLog composition. */\nexport interface PersistentReactiveLog<T> {\n\treadonly collection: ReactiveLog<T>;\n\treadonly persistence: ReactiveCollectionPersistenceHandle;\n\treadonly loaded: ReactiveLogRestoreState<T>;\n}\n\n/** Return value for D161 persistent reactiveMap composition. */\nexport interface PersistentReactiveMap<K, V> {\n\treadonly collection: ReactiveMap<K, V>;\n\treadonly persistence: ReactiveCollectionPersistenceHandle;\n\treadonly loaded: ReactiveMapRestoreState<K, V>;\n}\n\n/** Return value for D161 persistent reactiveIndex composition. */\nexport interface PersistentReactiveIndex<K, V> {\n\treadonly collection: ReactiveIndex<K, V>;\n\treadonly persistence: ReactiveCollectionPersistenceHandle;\n\treadonly loaded: ReactiveIndexRestoreState<K, V>;\n}\n\n/** D161 convenience wrapper: passive load, sync restoreReactiveList, then sidecar persist. */\nexport function openPersistentReactiveList<T = unknown>(\n\topts: OpenPersistentReactiveListOptions<T>,\n): Promise<PersistentReactiveList<T>> {\n\tconst storagePrefix = opts.storagePrefix ?? opts.name ?? \"reactive-collection\";\n\tconst snapshotKey = opts.snapshotKey ?? collectionSnapshotKey(storagePrefix);\n\tconst loadOpts = { ...opts, snapshotKey, storagePrefix };\n\treturn loadReactiveListState<T>(loadOpts).then((loaded) => {\n\t\tconst state =\n\t\t\tloaded.source === \"empty\" && opts.initial !== undefined\n\t\t\t\t? { ...loaded, state: opts.initial }\n\t\t\t\t: loaded;\n\t\tconst collection = restoreReactiveList<T>(state, {\n\t\t\t...(opts.collection ?? {}),\n\t\t\tgraph: opts.graph,\n\t\t\tname: opts.name,\n\t\t});\n\t\tconst persistence = persistReactiveCollection<T, \"reactiveList\">(opts.graph, collection, {\n\t\t\t...opts,\n\t\t\tkind: \"reactiveList\",\n\t\t\tname: opts.name ? `${opts.name}/persistence` : undefined,\n\t\t\tsnapshotKey,\n\t\t\tstoragePrefix,\n\t\t\tinitialChangeCursor: loaded.changes.cursor,\n\t\t});\n\t\treturn { collection, persistence, loaded };\n\t});\n}\n\n/** D161 convenience wrapper: passive load, sync restoreReactiveLog, then sidecar persist. */\nexport function openPersistentReactiveLog<T = unknown>(\n\topts: OpenPersistentReactiveLogOptions<T>,\n): Promise<PersistentReactiveLog<T>> {\n\tconst storagePrefix = opts.storagePrefix ?? opts.name ?? \"reactive-collection\";\n\tconst snapshotKey = opts.snapshotKey ?? collectionSnapshotKey(storagePrefix);\n\tconst loadOpts = { ...opts, snapshotKey, storagePrefix };\n\treturn loadReactiveLogState<T>(loadOpts).then((loaded) => {\n\t\tconst state =\n\t\t\tloaded.source === \"empty\" && opts.initial !== undefined\n\t\t\t\t? { ...loaded, state: opts.initial }\n\t\t\t\t: loaded;\n\t\tconst collection = restoreReactiveLog<T>(state, {\n\t\t\t...(opts.collection ?? {}),\n\t\t\tgraph: opts.graph,\n\t\t\tname: opts.name,\n\t\t});\n\t\tconst persistence = persistReactiveCollection<T, \"reactiveLog\">(opts.graph, collection, {\n\t\t\t...opts,\n\t\t\tkind: \"reactiveLog\",\n\t\t\tname: opts.name ? `${opts.name}/persistence` : undefined,\n\t\t\tsnapshotKey,\n\t\t\tstoragePrefix,\n\t\t\tinitialChangeCursor: loaded.changes.cursor,\n\t\t});\n\t\treturn { collection, persistence, loaded };\n\t});\n}\n\n/** D161 convenience wrapper: passive load, sync restoreReactiveMap, then sidecar persist. */\nexport function openPersistentReactiveMap<K = unknown, V = unknown>(\n\topts: OpenPersistentReactiveMapOptions<K, V>,\n): Promise<PersistentReactiveMap<K, V>> {\n\tconst storagePrefix = opts.storagePrefix ?? opts.name ?? \"reactive-collection\";\n\tconst snapshotKey = opts.snapshotKey ?? collectionSnapshotKey(storagePrefix);\n\tconst loadOpts = { ...opts, snapshotKey, storagePrefix };\n\treturn loadReactiveMapState<K, V>(loadOpts).then((loaded) => {\n\t\tconst state =\n\t\t\tloaded.source === \"empty\" && opts.initial !== undefined\n\t\t\t\t? { ...loaded, state: opts.initial }\n\t\t\t\t: loaded;\n\t\tconst collection = restoreReactiveMap<K, V>(state, {\n\t\t\t...(opts.collection ?? {}),\n\t\t\tgraph: opts.graph,\n\t\t\tname: opts.name,\n\t\t});\n\t\tconst persistence = persistReactiveCollection<V, \"reactiveMap\">(opts.graph, collection, {\n\t\t\t...opts,\n\t\t\tkind: \"reactiveMap\",\n\t\t\tname: opts.name ? `${opts.name}/persistence` : undefined,\n\t\t\tsnapshotKey,\n\t\t\tstoragePrefix,\n\t\t\tinitialChangeCursor: loaded.changes.cursor,\n\t\t});\n\t\treturn { collection, persistence, loaded };\n\t});\n}\n\n/** D161 convenience wrapper: passive load, sync restoreReactiveIndex, then sidecar persist. */\nexport function openPersistentReactiveIndex<K = unknown, V = unknown>(\n\topts: OpenPersistentReactiveIndexOptions<K, V>,\n): Promise<PersistentReactiveIndex<K, V>> {\n\tconst storagePrefix = opts.storagePrefix ?? opts.name ?? \"reactive-collection\";\n\tconst snapshotKey = opts.snapshotKey ?? collectionSnapshotKey(storagePrefix);\n\tconst loadOpts = { ...opts, snapshotKey, storagePrefix };\n\treturn loadReactiveIndexState<K, V>(loadOpts).then((loaded) => {\n\t\tconst state =\n\t\t\tloaded.source === \"empty\" && opts.initial !== undefined\n\t\t\t\t? { ...loaded, state: opts.initial }\n\t\t\t\t: loaded;\n\t\tconst collection = restoreReactiveIndex<K, V>(state, {\n\t\t\t...(opts.collection ?? {}),\n\t\t\tgraph: opts.graph,\n\t\t\tname: opts.name,\n\t\t});\n\t\tconst persistence = persistReactiveCollection<V, \"reactiveIndex\">(opts.graph, collection, {\n\t\t\t...opts,\n\t\t\tkind: \"reactiveIndex\",\n\t\t\tname: opts.name ? `${opts.name}/persistence` : undefined,\n\t\t\tsnapshotKey,\n\t\t\tstoragePrefix,\n\t\t\tinitialChangeCursor: loaded.changes.cursor,\n\t\t});\n\t\treturn { collection, persistence, loaded };\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeO,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AAAA,MACN,MAAM,KAAK,OAAO,GAAG,KAAK,IAAI,iBAAiB;AAAA,MAC/C;AAAA,MACA;AAAA,MACA,qBAAqB,OAAO,QAAQ;AAAA,IACrC,CAAC;AACD,WAAO,EAAE,YAAY,aAAa,OAAO;AAAA,EAC1C,CAAC;AACF;AAGO,SAAS,4BACf,MACyC;AACzC,QAAM,gBAAgB,KAAK,iBAAiB,KAAK,QAAQ;AACzD,QAAM,cAAc,KAAK,eAAe,sBAAsB,aAAa;AAC3E,QAAM,WAAW,EAAE,GAAG,MAAM,aAAa,cAAc;AACvD,SAAO,uBAA6B,QAAQ,EAAE,KAAK,CAAC,WAAW;AAC9D,UAAM,QACL,OAAO,WAAW,WAAW,KAAK,YAAY,SAC3C,EAAE,GAAG,QAAQ,OAAO,KAAK,QAAQ,IACjC;AACJ,UAAM,aAAa,qBAA2B,OAAO;AAAA,MACpD,GAAI,KAAK,cAAc,CAAC;AAAA,MACxB,OAAO,KAAK;AAAA,MACZ,MAAM,KAAK;AAAA,IACZ,CAAC;AACD,UAAM,cAAc,0BAA8C,KAAK,OAAO,YAAY;AAAA,MACzF,GAAG;AAAA,MACH,MAAM;AAAA,MACN,MAAM,KAAK,OAAO,GAAG,KAAK,IAAI,iBAAiB;AAAA,MAC/C;AAAA,MACA;AAAA,MACA,qBAAqB,OAAO,QAAQ;AAAA,IACrC,CAAC;AACD,WAAO,EAAE,YAAY,aAAa,OAAO;AAAA,EAC1C,CAAC;AACF;","names":["records","errorMessage","validateSnapshotEveryChanges","statusOf","dataOf"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/protocol/messages.ts
|
|
2
|
+
var SENTINEL = void 0;
|
|
3
|
+
function isInvalidErrorPayload(v) {
|
|
4
|
+
return v === SENTINEL || typeof v === "boolean";
|
|
5
|
+
}
|
|
6
|
+
function errorPayload(reason, fallback = "error without a valid payload") {
|
|
7
|
+
return isInvalidErrorPayload(reason) ? new Error(fallback) : reason;
|
|
8
|
+
}
|
|
9
|
+
var TIER_START = 0;
|
|
10
|
+
var TIER_CONTROL = 1;
|
|
11
|
+
var TIER_NOTIFICATION = 2;
|
|
12
|
+
var TIER_VALUE = 3;
|
|
13
|
+
var TIER_SETTLE = 4;
|
|
14
|
+
var TIER_TERMINAL = 5;
|
|
15
|
+
var TIER_TEARDOWN = 6;
|
|
16
|
+
var TIER = {
|
|
17
|
+
START: TIER_START,
|
|
18
|
+
PAUSE: TIER_CONTROL,
|
|
19
|
+
RESUME: TIER_CONTROL,
|
|
20
|
+
DIRTY: TIER_NOTIFICATION,
|
|
21
|
+
DATA: TIER_VALUE,
|
|
22
|
+
RESOLVED: TIER_VALUE,
|
|
23
|
+
INVALIDATE: TIER_SETTLE,
|
|
24
|
+
COMPLETE: TIER_TERMINAL,
|
|
25
|
+
ERROR: TIER_TERMINAL,
|
|
26
|
+
TEARDOWN: TIER_TEARDOWN
|
|
27
|
+
};
|
|
28
|
+
function messageTier(t) {
|
|
29
|
+
return TIER[t];
|
|
30
|
+
}
|
|
31
|
+
function isDeferredTier(t) {
|
|
32
|
+
return TIER[t] >= TIER_VALUE;
|
|
33
|
+
}
|
|
34
|
+
function isValueTier(t) {
|
|
35
|
+
return TIER[t] === TIER_VALUE;
|
|
36
|
+
}
|
|
37
|
+
function isPauseBufferedTier(t) {
|
|
38
|
+
const tier = TIER[t];
|
|
39
|
+
return tier === TIER_VALUE || tier === TIER_SETTLE;
|
|
40
|
+
}
|
|
41
|
+
function isTerminal(t) {
|
|
42
|
+
return TIER[t] === TIER_TERMINAL;
|
|
43
|
+
}
|
|
44
|
+
function isUpAllowed(t) {
|
|
45
|
+
const tier = TIER[t];
|
|
46
|
+
return tier !== TIER_VALUE && tier !== TIER_TERMINAL;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
SENTINEL,
|
|
51
|
+
isInvalidErrorPayload,
|
|
52
|
+
errorPayload,
|
|
53
|
+
TIER_START,
|
|
54
|
+
TIER_CONTROL,
|
|
55
|
+
TIER_NOTIFICATION,
|
|
56
|
+
TIER_VALUE,
|
|
57
|
+
TIER_SETTLE,
|
|
58
|
+
TIER_TERMINAL,
|
|
59
|
+
TIER_TEARDOWN,
|
|
60
|
+
messageTier,
|
|
61
|
+
isDeferredTier,
|
|
62
|
+
isValueTier,
|
|
63
|
+
isPauseBufferedTier,
|
|
64
|
+
isTerminal,
|
|
65
|
+
isUpAllowed
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=chunk-DK554R7P.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol/messages.ts"],"sourcesContent":["/**\n * Wave-protocol message types and the tier const table.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-msg-format, R-msg-closed-set, R-tier (D34), R-data-payload, R-sentinel.\n */\n\n/** Opaque pause-lock identifier (R-pause-lockset). */\nexport type LockId = string | symbol;\n\n/**\n * The CLOSED set of 10 message types (R-msg-closed-set / D9 + START handshake).\n * No open set, no user-defined custom types. Adding a type is a spec change.\n */\nexport type Message =\n\t| readonly [\"START\"]\n\t| readonly [\"DIRTY\"]\n\t| readonly [\"DATA\", unknown]\n\t| readonly [\"RESOLVED\"]\n\t| readonly [\"INVALIDATE\"]\n\t| readonly [\"COMPLETE\"]\n\t| readonly [\"ERROR\", unknown]\n\t| readonly [\"TEARDOWN\"]\n\t| readonly [\"PAUSE\", LockId]\n\t| readonly [\"RESUME\", LockId];\n\n/** One array of messages delivered in one call = one Wave (R-wave-boundary). */\nexport type Wave = readonly Message[];\n\n/** The message-type tag (the first tuple element). */\nexport type MessageType = Message[0];\n\n/**\n * SENTINEL = absence-of-DATA (R-sentinel / D16). TS representation is `undefined`.\n * Never a valid DATA payload; `null` IS a valid DATA value (domain-level absence).\n */\nexport const SENTINEL = undefined;\n\n/** R-data-payload: ERROR payloads must not collide with terminal metadata shorthand. */\nexport function isInvalidErrorPayload(v: unknown): boolean {\n\treturn v === SENTINEL || typeof v === \"boolean\";\n}\n\n/** R-data-payload / D78: host-language failures that collide with ctx.terminal shorthand become diagnostics. */\nexport function errorPayload(reason: unknown, fallback = \"error without a valid payload\"): unknown {\n\treturn isInvalidErrorPayload(reason) ? new Error(fallback) : reason;\n}\n\nexport const TIER_START = 0;\nexport const TIER_CONTROL = 1;\nexport const TIER_NOTIFICATION = 2;\nexport const TIER_VALUE = 3;\nexport const TIER_SETTLE = 4;\nexport const TIER_TERMINAL = 5;\nexport const TIER_TEARDOWN = 6;\n\n/**\n * Tier const table (R-tier / D34). Tiers below value dispatch immediately; value\n * and above are batch-deferred. This is a compile-time const table (D18), not runtime config.\n */\nconst TIER: Record<MessageType, number> = {\n\tSTART: TIER_START,\n\tPAUSE: TIER_CONTROL,\n\tRESUME: TIER_CONTROL,\n\tDIRTY: TIER_NOTIFICATION,\n\tDATA: TIER_VALUE,\n\tRESOLVED: TIER_VALUE,\n\tINVALIDATE: TIER_SETTLE,\n\tCOMPLETE: TIER_TERMINAL,\n\tERROR: TIER_TERMINAL,\n\tTEARDOWN: TIER_TEARDOWN,\n};\n\nexport function messageTier(t: MessageType): number {\n\treturn TIER[t];\n}\n\n/** Value and above are deferred inside a batch (DATA/RESOLVED/INVALIDATE/terminal/teardown). */\nexport function isDeferredTier(t: MessageType): boolean {\n\treturn TIER[t] >= TIER_VALUE;\n}\n\n/** Value-tier messages (DATA/RESOLVED) occupy the tier-3 slot. */\nexport function isValueTier(t: MessageType): boolean {\n\treturn TIER[t] === TIER_VALUE;\n}\n\n/** The pause buffer holds the settle slice only: value-tier DATA/RESOLVED plus INVALIDATE. */\nexport function isPauseBufferedTier(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier === TIER_VALUE || tier === TIER_SETTLE;\n}\n\n/**\n * A TERMINAL message = tier 5 (COMPLETE | ERROR), R-tier / D34. Detected via the CENTRAL tier\n * table, NOT a per-variant `=== \"COMPLETE\" || === \"ERROR\"` check — so terminal routing stays\n * driven by the one const table (feedback_use_tier_for_signal_routing); discriminate COMPLETE vs\n * ERROR within the tier by the message type only where the handling actually differs.\n */\nexport function isTerminal(t: MessageType): boolean {\n\treturn TIER[t] === TIER_TERMINAL;\n}\n\n/**\n * ctx.up carries control tiers only (R-ctx-up / DR-5): DIRTY, PAUSE, RESUME,\n * INVALIDATE, TEARDOWN. DATA/RESOLVED (tier 3) and COMPLETE/ERROR (tier 5) are\n * down-only.\n */\nexport function isUpAllowed(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier !== TIER_VALUE && tier !== TIER_TERMINAL;\n}\n"],"mappings":";AAoCO,IAAM,WAAW;AAGjB,SAAS,sBAAsB,GAAqB;AAC1D,SAAO,MAAM,YAAY,OAAO,MAAM;AACvC;AAGO,SAAS,aAAa,QAAiB,WAAW,iCAA0C;AAClG,SAAO,sBAAsB,MAAM,IAAI,IAAI,MAAM,QAAQ,IAAI;AAC9D;AAEO,IAAM,aAAa;AACnB,IAAM,eAAe;AACrB,IAAM,oBAAoB;AAC1B,IAAM,aAAa;AACnB,IAAM,cAAc;AACpB,IAAM,gBAAgB;AACtB,IAAM,gBAAgB;AAM7B,IAAM,OAAoC;AAAA,EACzC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,OAAO;AAAA,EACP,UAAU;AACX;AAEO,SAAS,YAAY,GAAwB;AACnD,SAAO,KAAK,CAAC;AACd;AAGO,SAAS,eAAe,GAAyB;AACvD,SAAO,KAAK,CAAC,KAAK;AACnB;AAGO,SAAS,YAAY,GAAyB;AACpD,SAAO,KAAK,CAAC,MAAM;AACpB;AAGO,SAAS,oBAAoB,GAAyB;AAC5D,QAAM,OAAO,KAAK,CAAC;AACnB,SAAO,SAAS,cAAc,SAAS;AACxC;AAQO,SAAS,WAAW,GAAyB;AACnD,SAAO,KAAK,CAAC,MAAM;AACpB;AAOO,SAAS,YAAY,GAAyB;AACpD,QAAM,OAAO,KAAK,CAAC;AACnB,SAAO,SAAS,cAAc,SAAS;AACxC;","names":[]}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import {
|
|
2
|
+
jsonCodecFor
|
|
3
|
+
} from "./chunk-4VLAQHZI.js";
|
|
4
|
+
|
|
5
|
+
// src/storage/backend.ts
|
|
6
|
+
var HEX_TABLE = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
7
|
+
var NAMESPACE_SEPARATOR = "\0";
|
|
8
|
+
function cloneBytes(bytes) {
|
|
9
|
+
return Uint8Array.from(bytes);
|
|
10
|
+
}
|
|
11
|
+
function encodeNamespacePrefix(namespace) {
|
|
12
|
+
return namespace.length > 0 ? `${namespace}${NAMESPACE_SEPARATOR}` : "";
|
|
13
|
+
}
|
|
14
|
+
function encodeBytesToHex(bytes) {
|
|
15
|
+
let out = "";
|
|
16
|
+
for (const byte of bytes) out += HEX_TABLE[byte];
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
function decodeHexToBytes(raw) {
|
|
20
|
+
if (raw.length % 2 !== 0 || !/^[0-9a-f]*$/i.test(raw)) {
|
|
21
|
+
throw new TypeError("webStorageBackend: malformed stored bytes");
|
|
22
|
+
}
|
|
23
|
+
const out = new Uint8Array(raw.length / 2);
|
|
24
|
+
for (let i = 0; i < raw.length; i += 2) {
|
|
25
|
+
const value = Number.parseInt(raw.slice(i, i + 2), 16);
|
|
26
|
+
if (Number.isNaN(value)) throw new TypeError("webStorageBackend: malformed stored bytes");
|
|
27
|
+
out[i / 2] = value;
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function validateLogicalKey(label, key) {
|
|
32
|
+
if (typeof key !== "string") {
|
|
33
|
+
throw new TypeError(`${label}: key must be a string`);
|
|
34
|
+
}
|
|
35
|
+
if (key.includes(NAMESPACE_SEPARATOR)) {
|
|
36
|
+
throw new TypeError(`${label}: key must not contain U+0000`);
|
|
37
|
+
}
|
|
38
|
+
return key;
|
|
39
|
+
}
|
|
40
|
+
function validateListPrefix(label, prefix) {
|
|
41
|
+
if (typeof prefix !== "string") {
|
|
42
|
+
throw new TypeError(`${label}: list prefix must be a string`);
|
|
43
|
+
}
|
|
44
|
+
if (prefix.includes(NAMESPACE_SEPARATOR)) {
|
|
45
|
+
throw new TypeError(`${label}: list prefix must not contain U+0000`);
|
|
46
|
+
}
|
|
47
|
+
return prefix;
|
|
48
|
+
}
|
|
49
|
+
function validateNamespace(label, namespace) {
|
|
50
|
+
if (typeof namespace !== "string") {
|
|
51
|
+
throw new TypeError(`${label}: namespace must be a string`);
|
|
52
|
+
}
|
|
53
|
+
if (namespace.includes(NAMESPACE_SEPARATOR)) {
|
|
54
|
+
throw new TypeError(`${label}: namespace must not contain U+0000`);
|
|
55
|
+
}
|
|
56
|
+
return namespace;
|
|
57
|
+
}
|
|
58
|
+
function hasStoragePutIfAbsent(backend) {
|
|
59
|
+
return typeof backend.putIfAbsent === "function";
|
|
60
|
+
}
|
|
61
|
+
function requireStoragePutIfAbsent(backend, label = "storage backend") {
|
|
62
|
+
if (!hasStoragePutIfAbsent(backend)) {
|
|
63
|
+
throw new Error(`${label}: backend does not support putIfAbsent`);
|
|
64
|
+
}
|
|
65
|
+
return backend;
|
|
66
|
+
}
|
|
67
|
+
function hasStorageVersioned(backend) {
|
|
68
|
+
return typeof backend.getVersioned === "function" && typeof backend.setIfMatch === "function";
|
|
69
|
+
}
|
|
70
|
+
function requireStorageVersioned(backend, label = "storage backend") {
|
|
71
|
+
if (!hasStorageVersioned(backend)) {
|
|
72
|
+
throw new Error(`${label}: backend does not support versioned get/set-if-match`);
|
|
73
|
+
}
|
|
74
|
+
return backend;
|
|
75
|
+
}
|
|
76
|
+
function toStorageKey(namespace, key) {
|
|
77
|
+
return `${encodeNamespacePrefix(namespace)}${key}`;
|
|
78
|
+
}
|
|
79
|
+
function enumerateStorageKeys(storage) {
|
|
80
|
+
if (storage.keys) return [...storage.keys()];
|
|
81
|
+
if (typeof storage.key === "function" && typeof storage.length === "number") {
|
|
82
|
+
const keys = [];
|
|
83
|
+
for (let i = 0; i < storage.length; i += 1) {
|
|
84
|
+
const key = storage.key(i);
|
|
85
|
+
if (key !== null && key !== void 0) keys.push(key);
|
|
86
|
+
}
|
|
87
|
+
return keys;
|
|
88
|
+
}
|
|
89
|
+
const fallback = storage;
|
|
90
|
+
return Object.keys(fallback).filter((key) => typeof fallback[key] === "string");
|
|
91
|
+
}
|
|
92
|
+
function decodeStorageListKey(namespace, rawKey) {
|
|
93
|
+
if (typeof rawKey !== "string") {
|
|
94
|
+
throw new TypeError("webStorageBackend: stored key must be a string");
|
|
95
|
+
}
|
|
96
|
+
const prefix = encodeNamespacePrefix(namespace);
|
|
97
|
+
if (!rawKey.startsWith(prefix)) return void 0;
|
|
98
|
+
const logical = rawKey.slice(prefix.length);
|
|
99
|
+
if (logical.includes(NAMESPACE_SEPARATOR)) {
|
|
100
|
+
throw new TypeError("webStorageBackend: malformed stored key");
|
|
101
|
+
}
|
|
102
|
+
return logical;
|
|
103
|
+
}
|
|
104
|
+
function listByPrefix(namespace, prefix, raw) {
|
|
105
|
+
const out = [];
|
|
106
|
+
for (const key of raw) {
|
|
107
|
+
const logical = decodeStorageListKey(namespace, key);
|
|
108
|
+
if (logical === void 0) continue;
|
|
109
|
+
if (!logical.startsWith(prefix)) continue;
|
|
110
|
+
out.push(logical);
|
|
111
|
+
}
|
|
112
|
+
out.sort();
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
function webStorageBackend(storage, opts = {}) {
|
|
116
|
+
const namespace = opts.namespace === void 0 ? "" : validateNamespace("webStorageBackend", opts.namespace);
|
|
117
|
+
return {
|
|
118
|
+
get(key) {
|
|
119
|
+
const raw = storage.getItem(
|
|
120
|
+
toStorageKey(namespace, validateLogicalKey("webStorageBackend", key))
|
|
121
|
+
);
|
|
122
|
+
if (raw === null || raw === void 0) return void 0;
|
|
123
|
+
return decodeHexToBytes(raw);
|
|
124
|
+
},
|
|
125
|
+
put(key, value) {
|
|
126
|
+
storage.setItem(
|
|
127
|
+
toStorageKey(namespace, validateLogicalKey("webStorageBackend", key)),
|
|
128
|
+
encodeBytesToHex(cloneBytes(value))
|
|
129
|
+
);
|
|
130
|
+
},
|
|
131
|
+
delete(key) {
|
|
132
|
+
storage.removeItem(toStorageKey(namespace, validateLogicalKey("webStorageBackend", key)));
|
|
133
|
+
},
|
|
134
|
+
list(prefix = "") {
|
|
135
|
+
return listByPrefix(
|
|
136
|
+
namespace,
|
|
137
|
+
validateListPrefix("webStorageBackend", prefix),
|
|
138
|
+
enumerateStorageKeys(storage)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
var MEMORY_GENERATION = /* @__PURE__ */ Symbol("graphrefly.memoryBackend.generation");
|
|
144
|
+
function memoryGeneration(epoch, key, version) {
|
|
145
|
+
return Object.freeze({ [MEMORY_GENERATION]: Object.freeze([epoch, key, version]) });
|
|
146
|
+
}
|
|
147
|
+
function readMemoryGeneration(generation) {
|
|
148
|
+
if (typeof generation !== "object" || generation === null) return void 0;
|
|
149
|
+
const maybe = generation;
|
|
150
|
+
const token = maybe[MEMORY_GENERATION];
|
|
151
|
+
if (Array.isArray(token) && token.length === 3 && typeof token[0] === "number" && typeof token[1] === "string" && typeof token[2] === "number") {
|
|
152
|
+
return token;
|
|
153
|
+
}
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
function memoryBackend(initial = []) {
|
|
157
|
+
const entries = /* @__PURE__ */ new Map();
|
|
158
|
+
const versions = /* @__PURE__ */ new Map();
|
|
159
|
+
let epoch = 0;
|
|
160
|
+
for (const [key, value] of initial) {
|
|
161
|
+
entries.set(validateLogicalKey("memoryBackend", key), cloneBytes(value));
|
|
162
|
+
}
|
|
163
|
+
const versionOf = (key) => versions.get(key) ?? 0;
|
|
164
|
+
const bump = (key) => {
|
|
165
|
+
versions.set(key, versionOf(key) + 1);
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
entries,
|
|
169
|
+
get(key) {
|
|
170
|
+
const value = entries.get(validateLogicalKey("memoryBackend", key));
|
|
171
|
+
return value === void 0 ? void 0 : cloneBytes(value);
|
|
172
|
+
},
|
|
173
|
+
put(key, value) {
|
|
174
|
+
validateLogicalKey("memoryBackend", key);
|
|
175
|
+
entries.set(key, cloneBytes(value));
|
|
176
|
+
bump(key);
|
|
177
|
+
},
|
|
178
|
+
putIfAbsent(key, value) {
|
|
179
|
+
validateLogicalKey("memoryBackend", key);
|
|
180
|
+
if (entries.has(key)) return false;
|
|
181
|
+
entries.set(key, cloneBytes(value));
|
|
182
|
+
bump(key);
|
|
183
|
+
return true;
|
|
184
|
+
},
|
|
185
|
+
getVersioned(key) {
|
|
186
|
+
validateLogicalKey("memoryBackend", key);
|
|
187
|
+
const value = entries.get(key);
|
|
188
|
+
const generation = memoryGeneration(epoch, key, versionOf(key));
|
|
189
|
+
if (value === void 0) return { kind: "miss", generation };
|
|
190
|
+
return { kind: "hit", value: cloneBytes(value), generation };
|
|
191
|
+
},
|
|
192
|
+
setIfMatch(key, value, generation) {
|
|
193
|
+
validateLogicalKey("memoryBackend", key);
|
|
194
|
+
const observed = readMemoryGeneration(generation);
|
|
195
|
+
if (observed === void 0 || observed[0] !== epoch || observed[1] !== key || observed[2] !== versionOf(key)) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
entries.set(key, cloneBytes(value));
|
|
199
|
+
bump(key);
|
|
200
|
+
return true;
|
|
201
|
+
},
|
|
202
|
+
delete(key) {
|
|
203
|
+
validateLogicalKey("memoryBackend", key);
|
|
204
|
+
if (entries.delete(key)) bump(key);
|
|
205
|
+
},
|
|
206
|
+
list(prefix = "") {
|
|
207
|
+
const validatedPrefix = validateListPrefix("memoryBackend", prefix);
|
|
208
|
+
return [...entries.keys()].filter((key) => key.startsWith(validatedPrefix)).sort();
|
|
209
|
+
},
|
|
210
|
+
clear() {
|
|
211
|
+
entries.clear();
|
|
212
|
+
versions.clear();
|
|
213
|
+
epoch += 1;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/storage/kv.ts
|
|
219
|
+
function hasKvPutIfAbsent(tier) {
|
|
220
|
+
return typeof tier.putIfAbsent === "function";
|
|
221
|
+
}
|
|
222
|
+
function requireKvPutIfAbsent(tier, label = "kvStorage") {
|
|
223
|
+
if (!hasKvPutIfAbsent(tier)) {
|
|
224
|
+
throw new Error(`${label}: KV tier does not support putIfAbsent`);
|
|
225
|
+
}
|
|
226
|
+
return tier;
|
|
227
|
+
}
|
|
228
|
+
function hasKvVersioned(tier) {
|
|
229
|
+
return typeof tier.getVersioned === "function" && typeof tier.setIfMatch === "function";
|
|
230
|
+
}
|
|
231
|
+
function requireKvVersioned(tier, label = "kvStorage") {
|
|
232
|
+
if (!hasKvVersioned(tier)) {
|
|
233
|
+
throw new Error(`${label}: KV tier does not support versioned get/set-if-match`);
|
|
234
|
+
}
|
|
235
|
+
return tier;
|
|
236
|
+
}
|
|
237
|
+
function defer(fn) {
|
|
238
|
+
return Promise.resolve().then(fn);
|
|
239
|
+
}
|
|
240
|
+
function kvStorage(opts) {
|
|
241
|
+
const codec = opts.codec ?? jsonCodecFor();
|
|
242
|
+
const { backend } = opts;
|
|
243
|
+
const tier = {
|
|
244
|
+
get(key) {
|
|
245
|
+
return defer(() => backend.get(key)).then(
|
|
246
|
+
(bytes) => bytes === void 0 ? void 0 : codec.decode(bytes)
|
|
247
|
+
);
|
|
248
|
+
},
|
|
249
|
+
set(key, value) {
|
|
250
|
+
return defer(() => backend.put(key, codec.encode(value))).then(() => void 0);
|
|
251
|
+
},
|
|
252
|
+
delete(key) {
|
|
253
|
+
return defer(() => backend.delete?.(key)).then(() => void 0);
|
|
254
|
+
},
|
|
255
|
+
list(prefix = "") {
|
|
256
|
+
return defer(() => {
|
|
257
|
+
if (!backend.list) throw new Error("kvStorage.list: backend does not support listing");
|
|
258
|
+
return backend.list(prefix);
|
|
259
|
+
}).then((keys) => [...keys].sort());
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
let out = tier;
|
|
263
|
+
if (hasStoragePutIfAbsent(backend)) {
|
|
264
|
+
out = {
|
|
265
|
+
...out,
|
|
266
|
+
putIfAbsent(key, value) {
|
|
267
|
+
return defer(() => backend.putIfAbsent(key, codec.encode(value)));
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if (hasStorageVersioned(backend)) {
|
|
272
|
+
out = {
|
|
273
|
+
...out,
|
|
274
|
+
getVersioned(key) {
|
|
275
|
+
return defer(() => backend.getVersioned(key)).then((result) => {
|
|
276
|
+
if (result.kind === "miss") return { kind: "miss", generation: result.generation };
|
|
277
|
+
return {
|
|
278
|
+
kind: "hit",
|
|
279
|
+
value: codec.decode(result.value),
|
|
280
|
+
generation: result.generation
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
setIfMatch(key, value, generation) {
|
|
285
|
+
return defer(() => backend.setIfMatch(key, codec.encode(value), generation));
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
function memoryKv(codec = jsonCodecFor()) {
|
|
292
|
+
return kvStorage({ backend: memoryBackend(), codec });
|
|
293
|
+
}
|
|
294
|
+
function dictKv(entries = {}, codec = jsonCodecFor()) {
|
|
295
|
+
const backend = memoryBackend();
|
|
296
|
+
const kv = kvStorage({ backend, codec });
|
|
297
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
298
|
+
backend.put(key, codec.encode(value));
|
|
299
|
+
}
|
|
300
|
+
return kv;
|
|
301
|
+
}
|
|
302
|
+
function listByPrefix2(tier, prefix = "") {
|
|
303
|
+
return tier.list(prefix);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export {
|
|
307
|
+
hasStoragePutIfAbsent,
|
|
308
|
+
requireStoragePutIfAbsent,
|
|
309
|
+
hasStorageVersioned,
|
|
310
|
+
requireStorageVersioned,
|
|
311
|
+
webStorageBackend,
|
|
312
|
+
memoryBackend,
|
|
313
|
+
hasKvPutIfAbsent,
|
|
314
|
+
requireKvPutIfAbsent,
|
|
315
|
+
hasKvVersioned,
|
|
316
|
+
requireKvVersioned,
|
|
317
|
+
kvStorage,
|
|
318
|
+
memoryKv,
|
|
319
|
+
dictKv,
|
|
320
|
+
listByPrefix2 as listByPrefix
|
|
321
|
+
};
|
|
322
|
+
//# sourceMappingURL=chunk-DKP56CSW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/storage/backend.ts","../src/storage/kv.ts"],"sourcesContent":["/**\n * Byte storage backends (D82): passive adapter-owned storage, no graph methods.\n */\n\nconst HEX_TABLE = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, \"0\"));\nconst NAMESPACE_SEPARATOR = \"\\u0000\";\n\nfunction cloneBytes(bytes: Uint8Array): Uint8Array {\n\treturn Uint8Array.from(bytes);\n}\n\nfunction encodeNamespacePrefix(namespace: string): string {\n\treturn namespace.length > 0 ? `${namespace}${NAMESPACE_SEPARATOR}` : \"\";\n}\n\nfunction encodeBytesToHex(bytes: Uint8Array): string {\n\tlet out = \"\";\n\tfor (const byte of bytes) out += HEX_TABLE[byte];\n\treturn out;\n}\n\nfunction decodeHexToBytes(raw: string): Uint8Array {\n\tif (raw.length % 2 !== 0 || !/^[0-9a-f]*$/i.test(raw)) {\n\t\tthrow new TypeError(\"webStorageBackend: malformed stored bytes\");\n\t}\n\tconst out = new Uint8Array(raw.length / 2);\n\tfor (let i = 0; i < raw.length; i += 2) {\n\t\tconst value = Number.parseInt(raw.slice(i, i + 2), 16);\n\t\tif (Number.isNaN(value)) throw new TypeError(\"webStorageBackend: malformed stored bytes\");\n\t\tout[i / 2] = value;\n\t}\n\treturn out;\n}\n\nfunction validateLogicalKey(label: string, key: string): string {\n\tif (typeof key !== \"string\") {\n\t\tthrow new TypeError(`${label}: key must be a string`);\n\t}\n\tif (key.includes(NAMESPACE_SEPARATOR)) {\n\t\tthrow new TypeError(`${label}: key must not contain U+0000`);\n\t}\n\treturn key;\n}\n\nfunction validateListPrefix(label: string, prefix: string): string {\n\tif (typeof prefix !== \"string\") {\n\t\tthrow new TypeError(`${label}: list prefix must be a string`);\n\t}\n\tif (prefix.includes(NAMESPACE_SEPARATOR)) {\n\t\tthrow new TypeError(`${label}: list prefix must not contain U+0000`);\n\t}\n\treturn prefix;\n}\n\nfunction validateNamespace(label: string, namespace: string): string {\n\tif (typeof namespace !== \"string\") {\n\t\tthrow new TypeError(`${label}: namespace must be a string`);\n\t}\n\tif (namespace.includes(NAMESPACE_SEPARATOR)) {\n\t\tthrow new TypeError(`${label}: namespace must not contain U+0000`);\n\t}\n\treturn namespace;\n}\n\n/** Passive byte-addressed backend used by D82 storage binding tiers. */\nexport interface StorageBackend {\n\tget(key: string): undefined | Uint8Array | PromiseLike<undefined | Uint8Array>;\n\tput(key: string, value: Uint8Array): void | PromiseLike<void>;\n\tputIfAbsent?(key: string, value: Uint8Array): boolean | PromiseLike<boolean>;\n\tgetVersioned?(key: string): StorageVersionedRead | PromiseLike<StorageVersionedRead>;\n\tsetIfMatch?(\n\t\tkey: string,\n\t\tvalue: Uint8Array,\n\t\tgeneration: StorageGeneration,\n\t): boolean | PromiseLike<boolean>;\n\tdelete?(key: string): void | PromiseLike<void>;\n\tlist?(prefix?: string): readonly string[] | PromiseLike<readonly string[]>;\n}\n\n/** Passive D85 conditional-create capability for multi-writer storage helpers. */\nexport interface PutIfAbsentStorageBackend extends StorageBackend {\n\tputIfAbsent(key: string, value: Uint8Array): boolean | PromiseLike<boolean>;\n}\n\n/** Opaque D108 per-key generation token for passive storage versioned reads. */\nexport type StorageGeneration = unknown;\n\n/** D108 versioned byte read result with explicit present/absent observations. */\nexport type StorageVersionedRead =\n\t| {\n\t\t\treadonly kind: \"hit\";\n\t\t\treadonly value: Uint8Array;\n\t\t\treadonly generation: StorageGeneration;\n\t }\n\t| {\n\t\t\treadonly kind: \"miss\";\n\t\t\treadonly generation: StorageGeneration;\n\t };\n\n/** Passive D108 versioned read + generation-conditional set capability. */\nexport interface VersionedStorageBackend extends StorageBackend {\n\tgetVersioned(key: string): StorageVersionedRead | PromiseLike<StorageVersionedRead>;\n\tsetIfMatch(\n\t\tkey: string,\n\t\tvalue: Uint8Array,\n\t\tgeneration: StorageGeneration,\n\t): boolean | PromiseLike<boolean>;\n}\n\n/** Runtime guard for D85 conditional-create capable byte backends. */\nexport function hasStoragePutIfAbsent(\n\tbackend: StorageBackend,\n): backend is PutIfAbsentStorageBackend {\n\treturn typeof backend.putIfAbsent === \"function\";\n}\n\n/** Require D85 conditional-create support and produce a clear adapter error when absent. */\nexport function requireStoragePutIfAbsent(\n\tbackend: StorageBackend,\n\tlabel = \"storage backend\",\n): PutIfAbsentStorageBackend {\n\tif (!hasStoragePutIfAbsent(backend)) {\n\t\tthrow new Error(`${label}: backend does not support putIfAbsent`);\n\t}\n\treturn backend;\n}\n\n/** Runtime guard for D108 versioned byte backends. */\nexport function hasStorageVersioned(backend: StorageBackend): backend is VersionedStorageBackend {\n\treturn typeof backend.getVersioned === \"function\" && typeof backend.setIfMatch === \"function\";\n}\n\n/** Require D108 versioned support and produce a clear adapter error when absent. */\nexport function requireStorageVersioned(\n\tbackend: StorageBackend,\n\tlabel = \"storage backend\",\n): VersionedStorageBackend {\n\tif (!hasStorageVersioned(backend)) {\n\t\tthrow new Error(`${label}: backend does not support versioned get/set-if-match`);\n\t}\n\treturn backend;\n}\n\n/** Browser/storage-adapter shape for deterministic byte helpers (DOM-free for portability). */\nexport interface WebStorageLike {\n\treadonly length?: number;\n\tgetItem(key: string): string | null | undefined;\n\tsetItem(key: string, value: string): void;\n\tremoveItem(key: string): void;\n\tkey?(index: number): string | null | undefined;\n\tkeys?(): readonly string[];\n}\n\n/** Storage helper options for namespace isolation and logical-key prefixing. */\nexport interface StorageNamespaceOptions {\n\t/**\n\t * Optional namespace for logical keys.\n\t *\n\t * Namespace is part of key mapping only and is not returned from `list()`.\n\t */\n\tnamespace?: string;\n}\n\nfunction toStorageKey(namespace: string, key: string): string {\n\treturn `${encodeNamespacePrefix(namespace)}${key}`;\n}\n\nfunction enumerateStorageKeys(storage: WebStorageLike): readonly unknown[] {\n\tif (storage.keys) return [...storage.keys()];\n\tif (typeof storage.key === \"function\" && typeof storage.length === \"number\") {\n\t\tconst keys: string[] = [];\n\t\tfor (let i = 0; i < storage.length; i += 1) {\n\t\t\tconst key = storage.key(i);\n\t\t\tif (key !== null && key !== undefined) keys.push(key);\n\t\t}\n\t\treturn keys;\n\t}\n\tconst fallback = storage as unknown as Readonly<Record<string, unknown>>;\n\treturn Object.keys(fallback).filter((key) => typeof fallback[key] === \"string\");\n}\n\nfunction decodeStorageListKey(namespace: string, rawKey: unknown): string | undefined {\n\tif (typeof rawKey !== \"string\") {\n\t\tthrow new TypeError(\"webStorageBackend: stored key must be a string\");\n\t}\n\tconst prefix = encodeNamespacePrefix(namespace);\n\tif (!rawKey.startsWith(prefix)) return undefined;\n\tconst logical = rawKey.slice(prefix.length);\n\tif (logical.includes(NAMESPACE_SEPARATOR)) {\n\t\tthrow new TypeError(\"webStorageBackend: malformed stored key\");\n\t}\n\treturn logical;\n}\n\nfunction listByPrefix(namespace: string, prefix: string, raw: readonly unknown[]): string[] {\n\tconst out: string[] = [];\n\tfor (const key of raw) {\n\t\tconst logical = decodeStorageListKey(namespace, key);\n\t\tif (logical === undefined) continue;\n\t\tif (!logical.startsWith(prefix)) continue;\n\t\tout.push(logical);\n\t}\n\tout.sort();\n\treturn out;\n}\n\n/** Build a deterministic byte backend backed by a browser-like key/value store (D103/D82). */\nexport function webStorageBackend(\n\tstorage: WebStorageLike,\n\topts: StorageNamespaceOptions = {},\n): StorageBackend {\n\tconst namespace =\n\t\topts.namespace === undefined ? \"\" : validateNamespace(\"webStorageBackend\", opts.namespace);\n\treturn {\n\t\tget(key) {\n\t\t\tconst raw = storage.getItem(\n\t\t\t\ttoStorageKey(namespace, validateLogicalKey(\"webStorageBackend\", key)),\n\t\t\t);\n\t\t\tif (raw === null || raw === undefined) return undefined;\n\t\t\treturn decodeHexToBytes(raw);\n\t\t},\n\t\tput(key, value) {\n\t\t\tstorage.setItem(\n\t\t\t\ttoStorageKey(namespace, validateLogicalKey(\"webStorageBackend\", key)),\n\t\t\t\tencodeBytesToHex(cloneBytes(value)),\n\t\t\t);\n\t\t},\n\t\tdelete(key) {\n\t\t\tstorage.removeItem(toStorageKey(namespace, validateLogicalKey(\"webStorageBackend\", key)));\n\t\t},\n\t\tlist(prefix = \"\") {\n\t\t\treturn listByPrefix(\n\t\t\t\tnamespace,\n\t\t\t\tvalidateListPrefix(\"webStorageBackend\", prefix),\n\t\t\t\tenumerateStorageKeys(storage),\n\t\t\t);\n\t\t},\n\t};\n}\n\n/** In-memory backend for tests, adapters, and lightweight local storage. */\nexport interface MemoryBackend extends StorageBackend {\n\treadonly entries: ReadonlyMap<string, Uint8Array>;\n\tclear(): void;\n}\n\nconst MEMORY_GENERATION = Symbol(\"graphrefly.memoryBackend.generation\");\n\ninterface MemoryGeneration {\n\treadonly [MEMORY_GENERATION]: readonly [epoch: number, key: string, version: number];\n}\n\nfunction memoryGeneration(epoch: number, key: string, version: number): MemoryGeneration {\n\treturn Object.freeze({ [MEMORY_GENERATION]: Object.freeze([epoch, key, version] as const) });\n}\n\nfunction readMemoryGeneration(\n\tgeneration: StorageGeneration,\n): readonly [epoch: number, key: string, version: number] | undefined {\n\tif (typeof generation !== \"object\" || generation === null) return undefined;\n\tconst maybe = generation as Partial<MemoryGeneration>;\n\tconst token = maybe[MEMORY_GENERATION];\n\tif (\n\t\tArray.isArray(token) &&\n\t\ttoken.length === 3 &&\n\t\ttypeof token[0] === \"number\" &&\n\t\ttypeof token[1] === \"string\" &&\n\t\ttypeof token[2] === \"number\"\n\t) {\n\t\treturn token as readonly [number, string, number];\n\t}\n\treturn undefined;\n}\n\n/** Create a byte-cloning in-memory backend. */\nexport function memoryBackend(\n\tinitial: Iterable<readonly [string, Uint8Array]> = [],\n): MemoryBackend {\n\tconst entries = new Map<string, Uint8Array>();\n\tconst versions = new Map<string, number>();\n\tlet epoch = 0;\n\tfor (const [key, value] of initial) {\n\t\tentries.set(validateLogicalKey(\"memoryBackend\", key), cloneBytes(value));\n\t}\n\tconst versionOf = (key: string): number => versions.get(key) ?? 0;\n\tconst bump = (key: string): void => {\n\t\tversions.set(key, versionOf(key) + 1);\n\t};\n\treturn {\n\t\tentries,\n\t\tget(key) {\n\t\t\tconst value = entries.get(validateLogicalKey(\"memoryBackend\", key));\n\t\t\treturn value === undefined ? undefined : cloneBytes(value);\n\t\t},\n\t\tput(key, value) {\n\t\t\tvalidateLogicalKey(\"memoryBackend\", key);\n\t\t\tentries.set(key, cloneBytes(value));\n\t\t\tbump(key);\n\t\t},\n\t\tputIfAbsent(key, value) {\n\t\t\tvalidateLogicalKey(\"memoryBackend\", key);\n\t\t\tif (entries.has(key)) return false;\n\t\t\tentries.set(key, cloneBytes(value));\n\t\t\tbump(key);\n\t\t\treturn true;\n\t\t},\n\t\tgetVersioned(key) {\n\t\t\tvalidateLogicalKey(\"memoryBackend\", key);\n\t\t\tconst value = entries.get(key);\n\t\t\tconst generation = memoryGeneration(epoch, key, versionOf(key));\n\t\t\tif (value === undefined) return { kind: \"miss\", generation };\n\t\t\treturn { kind: \"hit\", value: cloneBytes(value), generation };\n\t\t},\n\t\tsetIfMatch(key, value, generation) {\n\t\t\tvalidateLogicalKey(\"memoryBackend\", key);\n\t\t\tconst observed = readMemoryGeneration(generation);\n\t\t\tif (\n\t\t\t\tobserved === undefined ||\n\t\t\t\tobserved[0] !== epoch ||\n\t\t\t\tobserved[1] !== key ||\n\t\t\t\tobserved[2] !== versionOf(key)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tentries.set(key, cloneBytes(value));\n\t\t\tbump(key);\n\t\t\treturn true;\n\t\t},\n\t\tdelete(key) {\n\t\t\tvalidateLogicalKey(\"memoryBackend\", key);\n\t\t\tif (entries.delete(key)) bump(key);\n\t\t},\n\t\tlist(prefix = \"\") {\n\t\t\tconst validatedPrefix = validateListPrefix(\"memoryBackend\", prefix);\n\t\t\treturn [...entries.keys()].filter((key) => key.startsWith(validatedPrefix)).sort();\n\t\t},\n\t\tclear() {\n\t\t\tentries.clear();\n\t\t\tversions.clear();\n\t\t\tepoch += 1;\n\t\t},\n\t};\n}\n","import {\n\thasStoragePutIfAbsent,\n\thasStorageVersioned,\n\tmemoryBackend,\n\ttype StorageBackend,\n\ttype StorageGeneration,\n} from \"./backend.js\";\nimport type { Codec } from \"./codec.js\";\nimport { jsonCodecFor } from \"./codec.js\";\n\n/** Codec-backed key/value tier over a passive byte backend (D82). */\nexport interface KvStorageTier<T = unknown> {\n\tget(key: string): Promise<T | undefined>;\n\tset(key: string, value: T): Promise<void>;\n\tputIfAbsent?(key: string, value: T): Promise<boolean>;\n\tgetVersioned?(key: string): Promise<KvVersionedRead<T>>;\n\tsetIfMatch?(key: string, value: T, generation: StorageGeneration): Promise<boolean>;\n\tdelete(key: string): Promise<void>;\n\tlist(prefix?: string): Promise<readonly string[]>;\n}\n\n/** Typed D85 conditional-create capability over a KV tier. */\nexport interface PutIfAbsentKvStorageTier<T = unknown> extends KvStorageTier<T> {\n\tputIfAbsent(key: string, value: T): Promise<boolean>;\n}\n\n/** Opaque D108 per-key generation token for typed KV versioned reads. */\nexport type KvGeneration = StorageGeneration;\n\n/** D108 versioned typed read result with explicit present/absent observations. */\nexport type KvVersionedRead<T> =\n\t| {\n\t\t\treadonly kind: \"hit\";\n\t\t\treadonly value: T;\n\t\t\treadonly generation: KvGeneration;\n\t }\n\t| {\n\t\t\treadonly kind: \"miss\";\n\t\t\treadonly generation: KvGeneration;\n\t };\n\n/** Typed D108 versioned read + generation-conditional set capability over a KV tier. */\nexport interface VersionedKvStorageTier<T = unknown> extends KvStorageTier<T> {\n\tgetVersioned(key: string): Promise<KvVersionedRead<T>>;\n\tsetIfMatch(key: string, value: T, generation: KvGeneration): Promise<boolean>;\n}\n\n/** Runtime guard for typed KV tiers that expose D85 conditional create. */\nexport function hasKvPutIfAbsent<T>(tier: KvStorageTier<T>): tier is PutIfAbsentKvStorageTier<T> {\n\treturn typeof tier.putIfAbsent === \"function\";\n}\n\n/** Require D85 conditional-create support and produce a clear adapter error when absent. */\nexport function requireKvPutIfAbsent<T>(\n\ttier: KvStorageTier<T>,\n\tlabel = \"kvStorage\",\n): PutIfAbsentKvStorageTier<T> {\n\tif (!hasKvPutIfAbsent(tier)) {\n\t\tthrow new Error(`${label}: KV tier does not support putIfAbsent`);\n\t}\n\treturn tier;\n}\n\n/** Runtime guard for typed KV tiers that expose D108 versioned read/set-if-match. */\nexport function hasKvVersioned<T>(tier: KvStorageTier<T>): tier is VersionedKvStorageTier<T> {\n\treturn typeof tier.getVersioned === \"function\" && typeof tier.setIfMatch === \"function\";\n}\n\n/** Require D108 versioned KV support and produce a clear adapter error when absent. */\nexport function requireKvVersioned<T>(\n\ttier: KvStorageTier<T>,\n\tlabel = \"kvStorage\",\n): VersionedKvStorageTier<T> {\n\tif (!hasKvVersioned(tier)) {\n\t\tthrow new Error(`${label}: KV tier does not support versioned get/set-if-match`);\n\t}\n\treturn tier;\n}\n\n/** Options for wrapping a byte backend as a typed KV tier. */\nexport interface KvStorageOptions<T> {\n\tbackend: StorageBackend;\n\tcodec?: Codec<T>;\n}\n\nfunction defer<T>(fn: () => T | PromiseLike<T>): Promise<T> {\n\treturn Promise.resolve().then(fn);\n}\n\n/** Build a typed KV tier from a byte backend and codec. */\nexport function kvStorage<T = unknown>(opts: KvStorageOptions<T>): KvStorageTier<T> {\n\tconst codec = opts.codec ?? jsonCodecFor<T>();\n\tconst { backend } = opts;\n\tconst tier: KvStorageTier<T> = {\n\t\tget(key) {\n\t\t\treturn defer(() => backend.get(key)).then((bytes) =>\n\t\t\t\tbytes === undefined ? undefined : codec.decode(bytes),\n\t\t\t);\n\t\t},\n\t\tset(key, value) {\n\t\t\treturn defer(() => backend.put(key, codec.encode(value))).then(() => undefined);\n\t\t},\n\t\tdelete(key) {\n\t\t\treturn defer(() => backend.delete?.(key)).then(() => undefined);\n\t\t},\n\t\tlist(prefix = \"\") {\n\t\t\treturn defer(() => {\n\t\t\t\tif (!backend.list) throw new Error(\"kvStorage.list: backend does not support listing\");\n\t\t\t\treturn backend.list(prefix);\n\t\t\t}).then((keys) => [...keys].sort());\n\t\t},\n\t};\n\tlet out = tier;\n\tif (hasStoragePutIfAbsent(backend)) {\n\t\tout = {\n\t\t\t...out,\n\t\t\tputIfAbsent(key, value) {\n\t\t\t\treturn defer(() => backend.putIfAbsent(key, codec.encode(value)));\n\t\t\t},\n\t\t};\n\t}\n\tif (hasStorageVersioned(backend)) {\n\t\tout = {\n\t\t\t...out,\n\t\t\tgetVersioned(key) {\n\t\t\t\treturn defer(() => backend.getVersioned(key)).then((result) => {\n\t\t\t\t\tif (result.kind === \"miss\") return { kind: \"miss\", generation: result.generation };\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"hit\",\n\t\t\t\t\t\tvalue: codec.decode(result.value),\n\t\t\t\t\t\tgeneration: result.generation,\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t},\n\t\t\tsetIfMatch(key, value, generation) {\n\t\t\t\treturn defer(() => backend.setIfMatch(key, codec.encode(value), generation));\n\t\t\t},\n\t\t};\n\t}\n\treturn out;\n}\n\n/** Create an in-memory typed KV tier. */\nexport function memoryKv<T = unknown>(codec: Codec<T> = jsonCodecFor<T>()): KvStorageTier<T> {\n\treturn kvStorage({ backend: memoryBackend(), codec });\n}\n\n/** Create an in-memory typed KV tier preloaded from a record. */\nexport function dictKv<T = unknown>(\n\tentries: Record<string, T> = {},\n\tcodec: Codec<T> = jsonCodecFor<T>(),\n): KvStorageTier<T> {\n\tconst backend = memoryBackend();\n\tconst kv = kvStorage({ backend, codec });\n\tfor (const [key, value] of Object.entries(entries)) {\n\t\tbackend.put(key, codec.encode(value as T));\n\t}\n\treturn kv;\n}\n\n/** Convenience wrapper for deterministic prefix listing. */\nexport function listByPrefix<T>(tier: KvStorageTier<T>, prefix = \"\"): Promise<readonly string[]> {\n\treturn tier.list(prefix);\n}\n"],"mappings":";;;;;AAIA,IAAM,YAAY,MAAM,KAAK,EAAE,QAAQ,IAAI,GAAG,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC;AACvF,IAAM,sBAAsB;AAE5B,SAAS,WAAW,OAA+B;AAClD,SAAO,WAAW,KAAK,KAAK;AAC7B;AAEA,SAAS,sBAAsB,WAA2B;AACzD,SAAO,UAAU,SAAS,IAAI,GAAG,SAAS,GAAG,mBAAmB,KAAK;AACtE;AAEA,SAAS,iBAAiB,OAA2B;AACpD,MAAI,MAAM;AACV,aAAW,QAAQ,MAAO,QAAO,UAAU,IAAI;AAC/C,SAAO;AACR;AAEA,SAAS,iBAAiB,KAAyB;AAClD,MAAI,IAAI,SAAS,MAAM,KAAK,CAAC,eAAe,KAAK,GAAG,GAAG;AACtD,UAAM,IAAI,UAAU,2CAA2C;AAAA,EAChE;AACA,QAAM,MAAM,IAAI,WAAW,IAAI,SAAS,CAAC;AACzC,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK,GAAG;AACvC,UAAM,QAAQ,OAAO,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE;AACrD,QAAI,OAAO,MAAM,KAAK,EAAG,OAAM,IAAI,UAAU,2CAA2C;AACxF,QAAI,IAAI,CAAC,IAAI;AAAA,EACd;AACA,SAAO;AACR;AAEA,SAAS,mBAAmB,OAAe,KAAqB;AAC/D,MAAI,OAAO,QAAQ,UAAU;AAC5B,UAAM,IAAI,UAAU,GAAG,KAAK,wBAAwB;AAAA,EACrD;AACA,MAAI,IAAI,SAAS,mBAAmB,GAAG;AACtC,UAAM,IAAI,UAAU,GAAG,KAA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