@graphrefly/ts 0.0.0 → 0.0.2
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/README.md +135 -0
- package/dist/actions-types-CSC3NMDl.d.ts +657 -0
- package/dist/actions-types-wl9Mgkmr.d.cts +657 -0
- package/dist/adapters/index.cjs +5219 -2974
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +204 -192
- package/dist/adapters/index.d.ts +204 -192
- package/dist/adapters/index.js +3685 -1833
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/nestjs/microservices.cjs +841 -0
- package/dist/adapters/nestjs/microservices.cjs.map +1 -0
- package/dist/adapters/nestjs/microservices.d.cts +45 -0
- package/dist/adapters/nestjs/microservices.d.ts +45 -0
- package/dist/adapters/nestjs/microservices.js +206 -0
- package/dist/adapters/nestjs/microservices.js.map +1 -0
- package/dist/adapters/nestjs/native.cjs +1391 -0
- package/dist/adapters/nestjs/native.cjs.map +1 -0
- package/dist/adapters/nestjs/native.d.cts +111 -0
- package/dist/adapters/nestjs/native.d.ts +111 -0
- package/dist/adapters/nestjs/native.js +577 -0
- package/dist/adapters/nestjs/native.js.map +1 -0
- package/dist/adapters/nestjs/websockets.cjs +924 -0
- package/dist/adapters/nestjs/websockets.cjs.map +1 -0
- package/dist/adapters/nestjs/websockets.d.cts +47 -0
- package/dist/adapters/nestjs/websockets.d.ts +47 -0
- package/dist/adapters/nestjs/websockets.js +286 -0
- package/dist/adapters/nestjs/websockets.js.map +1 -0
- package/dist/adapters/nestjs.cjs +1085 -0
- package/dist/adapters/nestjs.cjs.map +1 -0
- package/dist/adapters/nestjs.d.cts +385 -0
- package/dist/adapters/nestjs.d.ts +385 -0
- package/dist/adapters/nestjs.js +112 -0
- package/dist/adapters/nestjs.js.map +1 -0
- package/dist/adapters/observe-storage.d.cts +4 -4
- package/dist/adapters/observe-storage.d.ts +4 -4
- package/dist/adapters/observe-storage.js +5 -4
- package/dist/adapters/observe-storage.js.map +1 -1
- package/dist/adapters/react.cjs +166 -0
- package/dist/adapters/react.cjs.map +1 -0
- package/dist/adapters/react.d.cts +31 -0
- package/dist/adapters/react.d.ts +31 -0
- package/dist/adapters/react.js +51 -0
- package/dist/adapters/react.js.map +1 -0
- package/dist/adapters/solid.cjs +157 -0
- package/dist/adapters/solid.cjs.map +1 -0
- package/dist/adapters/solid.d.cts +26 -0
- package/dist/adapters/solid.d.ts +26 -0
- package/dist/adapters/solid.js +48 -0
- package/dist/adapters/solid.js.map +1 -0
- package/dist/adapters/svelte.cjs +148 -0
- package/dist/adapters/svelte.cjs.map +1 -0
- package/dist/adapters/svelte.d.cts +31 -0
- package/dist/adapters/svelte.d.ts +31 -0
- package/dist/adapters/svelte.js +46 -0
- package/dist/adapters/svelte.js.map +1 -0
- package/dist/adapters/vue.cjs +155 -0
- package/dist/adapters/vue.cjs.map +1 -0
- package/dist/adapters/vue.d.cts +26 -0
- package/dist/adapters/vue.d.ts +26 -0
- package/dist/adapters/vue.js +46 -0
- package/dist/adapters/vue.js.map +1 -0
- package/dist/agent-runtime-types-core-CaXfKNtY.d.cts +406 -0
- package/dist/agent-runtime-types-core-hU299uIC.d.ts +406 -0
- package/dist/agent-runtime-types-tool-BEpSINol.d.ts +695 -0
- package/dist/agent-runtime-types-tool-DninPEzk.d.cts +695 -0
- package/dist/agentic-memory-retention-BmGX368S.d.ts +14 -0
- package/dist/agentic-memory-retention-Ih1qhX9Z.d.cts +14 -0
- package/dist/agentic-memory-types-CVSUS6XR.d.ts +473 -0
- package/dist/agentic-memory-types-FnnYlVUs.d.cts +473 -0
- package/dist/capability-admission-BW2CziT6.d.ts +102 -0
- package/dist/capability-admission-lwSecxXs.d.cts +102 -0
- package/dist/chunk-2KUAG2GZ.js +9693 -0
- package/dist/chunk-2KUAG2GZ.js.map +1 -0
- package/dist/chunk-2NJP6GO4.js +1320 -0
- package/dist/chunk-2NJP6GO4.js.map +1 -0
- package/dist/{chunk-GDL26N2T.js → chunk-3KN7NJDR.js} +2 -2
- package/dist/{chunk-COHO25CZ.js → chunk-4NWSNI4K.js} +2232 -1672
- package/dist/chunk-4NWSNI4K.js.map +1 -0
- package/dist/{chunk-Z2ANQ6JW.js → chunk-4Q77MMJY.js} +2 -2
- package/dist/chunk-6E76H4OU.js +132 -0
- package/dist/chunk-6E76H4OU.js.map +1 -0
- package/dist/chunk-7GOTIIQ7.js +819 -0
- package/dist/chunk-7GOTIIQ7.js.map +1 -0
- package/dist/{chunk-D6BG7U6A.js → chunk-7HZRJMN6.js} +3 -3
- package/dist/{chunk-SCRFRCGR.js → chunk-BSQGE5PS.js} +1 -1
- package/dist/{chunk-PKVBHGBM.js → chunk-CJIFGJQG.js} +7 -7
- package/dist/{chunk-G4M3NHRJ.js → chunk-CX6B6PO2.js} +93 -10
- package/dist/chunk-CX6B6PO2.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/{chunk-JIMUDQN3.js → chunk-E4QCH32M.js} +449 -447
- package/dist/chunk-E4QCH32M.js.map +1 -0
- package/dist/{chunk-RIIOUTGM.js → chunk-ECURQ3HD.js} +19 -129
- package/dist/chunk-ECURQ3HD.js.map +1 -0
- package/dist/{chunk-2ILL7HQI.js → chunk-EOKT4QFF.js} +134 -128
- package/dist/chunk-EOKT4QFF.js.map +1 -0
- package/dist/{chunk-K3FXTC3I.js → chunk-HJACH5PU.js} +3 -3
- package/dist/{chunk-GTPCOEOZ.js → chunk-IDMLXLLG.js} +3 -3
- package/dist/{chunk-DKP56CSW.js → chunk-JKAYLDQV.js} +2 -2
- package/dist/{chunk-4VLAQHZI.js → chunk-K7FB3JTD.js} +17 -1
- package/dist/chunk-K7FB3JTD.js.map +1 -0
- package/dist/chunk-L6LDXRWE.js +219 -0
- package/dist/chunk-L6LDXRWE.js.map +1 -0
- package/dist/chunk-M7J6Z4IJ.js +1930 -0
- package/dist/chunk-M7J6Z4IJ.js.map +1 -0
- package/dist/chunk-MQEQMS7B.js +1009 -0
- package/dist/chunk-MQEQMS7B.js.map +1 -0
- package/dist/chunk-MTELVIYR.js +1421 -0
- package/dist/chunk-MTELVIYR.js.map +1 -0
- package/dist/chunk-PVC7WDKI.js +885 -0
- package/dist/chunk-PVC7WDKI.js.map +1 -0
- package/dist/chunk-RAHNUYA5.js +368 -0
- package/dist/chunk-RAHNUYA5.js.map +1 -0
- package/dist/{chunk-DK554R7P.js → chunk-S6HXABGL.js} +2 -1
- package/dist/chunk-S6HXABGL.js.map +1 -0
- package/dist/{chunk-I3IHOHCJ.js → chunk-SHZDP2MQ.js} +1181 -1001
- package/dist/chunk-SHZDP2MQ.js.map +1 -0
- package/dist/{chunk-Y3ZLRGHC.js → chunk-SIDJO2T4.js} +16 -16
- package/dist/chunk-STXRMPW4.js +4131 -0
- package/dist/chunk-STXRMPW4.js.map +1 -0
- package/dist/{chunk-JR4IKCR2.js → chunk-TPND5MJS.js} +5 -5
- package/dist/chunk-TQPCAIQI.js +612 -0
- package/dist/chunk-TQPCAIQI.js.map +1 -0
- package/dist/chunk-UT3MHJCW.js +49 -0
- package/dist/chunk-UT3MHJCW.js.map +1 -0
- package/dist/{chunk-TEW47IVR.js → chunk-VPEFSDME.js} +2 -2
- package/dist/{chunk-SWTLEQL6.js → chunk-WQIA3GFB.js} +2 -2
- package/dist/chunk-WQIA3GFB.js.map +1 -0
- package/dist/{chunk-DJC4CHLQ.js → chunk-YDWBXXQZ.js} +5 -5
- package/dist/{chunk-6PHB5CJS.js → chunk-ZLFRB6FI.js} +2 -2
- package/dist/composition/index.cjs +1256 -1059
- package/dist/composition/index.cjs.map +1 -1
- package/dist/composition/index.d.cts +4 -4
- package/dist/composition/index.d.ts +4 -4
- package/dist/composition/index.js +7 -6
- package/dist/core/index.cjs +1218 -1021
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +5 -4
- package/dist/cqrs/index.cjs.map +1 -1
- package/dist/cqrs/index.d.cts +4 -4
- package/dist/cqrs/index.d.ts +4 -4
- package/dist/cqrs/index.js +3 -2
- package/dist/cqrs/index.js.map +1 -1
- package/dist/cqrs/messaging.cjs +312 -0
- package/dist/cqrs/messaging.cjs.map +1 -0
- package/dist/cqrs/messaging.d.cts +57 -0
- package/dist/cqrs/messaging.d.ts +57 -0
- package/dist/cqrs/messaging.js +274 -0
- package/dist/cqrs/messaging.js.map +1 -0
- package/dist/cqrs/work-queue.cjs +329 -0
- package/dist/cqrs/work-queue.cjs.map +1 -0
- package/dist/cqrs/work-queue.d.cts +90 -0
- package/dist/cqrs/work-queue.d.ts +90 -0
- package/dist/cqrs/work-queue.js +292 -0
- package/dist/cqrs/work-queue.js.map +1 -0
- package/dist/data/index.cjs +19 -0
- package/dist/data/index.cjs.map +1 -0
- package/dist/data/index.d.cts +36 -0
- package/dist/data/index.d.ts +36 -0
- package/dist/data/index.js +1 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data-structures/index.cjs +1252 -1052
- package/dist/data-structures/index.cjs.map +1 -1
- package/dist/data-structures/index.d.cts +9 -8
- package/dist/data-structures/index.d.ts +9 -8
- package/dist/data-structures/index.js +9 -7
- package/dist/{describe-BZb7AS2y.d.ts → describe-B_A5fbXH.d.ts} +1 -1
- package/dist/{describe-Ciu8SUnN.d.cts → describe-CQRrkv-Q.d.cts} +1 -1
- package/dist/executors/tool-provider-adapters.cjs +3091 -0
- package/dist/executors/tool-provider-adapters.cjs.map +1 -0
- package/dist/executors/tool-provider-adapters.d.cts +174 -0
- package/dist/executors/tool-provider-adapters.d.ts +174 -0
- package/dist/executors/tool-provider-adapters.js +1336 -0
- package/dist/executors/tool-provider-adapters.js.map +1 -0
- package/dist/executors/tool-provider-runtime.cjs +5178 -0
- package/dist/executors/tool-provider-runtime.cjs.map +1 -0
- package/dist/executors/tool-provider-runtime.d.cts +17 -0
- package/dist/executors/tool-provider-runtime.d.ts +17 -0
- package/dist/executors/tool-provider-runtime.js +15 -0
- package/dist/executors/tool-provider-runtime.js.map +1 -0
- package/dist/executors/tool-provider.cjs +6392 -0
- package/dist/executors/tool-provider.cjs.map +1 -0
- package/dist/executors/tool-provider.d.cts +60 -0
- package/dist/executors/tool-provider.d.ts +60 -0
- package/dist/executors/tool-provider.js +89 -0
- package/dist/executors/tool-provider.js.map +1 -0
- package/dist/executors/work-queue.cjs +342 -0
- package/dist/executors/work-queue.cjs.map +1 -0
- package/dist/executors/work-queue.d.cts +90 -0
- package/dist/executors/work-queue.d.ts +90 -0
- package/dist/executors/work-queue.js +306 -0
- package/dist/executors/work-queue.js.map +1 -0
- package/dist/graph/index.cjs +1536 -1324
- package/dist/graph/index.cjs.map +1 -1
- package/dist/graph/index.d.cts +10 -9
- package/dist/graph/index.d.ts +10 -9
- package/dist/graph/index.js +22 -20
- package/dist/{graph-s23RbbFO.d.cts → graph-CWK3HLPB.d.cts} +134 -132
- package/dist/{graph-DfdF9zy4.d.ts → graph-ho5sotHP.d.ts} +134 -132
- package/dist/{index-SnzZu3x7.d.ts → index-CQWcE0Dw.d.ts} +18 -4
- package/dist/{index-CAEmLCYF.d.cts → index-DHA1i67c.d.cts} +18 -4
- package/dist/index.cjs +3331 -3020
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +114 -108
- package/dist/inspection/boundary.cjs +98 -0
- package/dist/inspection/boundary.cjs.map +1 -0
- package/dist/inspection/boundary.d.cts +61 -0
- package/dist/inspection/boundary.d.ts +61 -0
- package/dist/inspection/boundary.js +75 -0
- package/dist/inspection/boundary.js.map +1 -0
- package/dist/measurements-C0mAvWU1.d.cts +164 -0
- package/dist/measurements-OMpCeBwh.d.ts +164 -0
- package/dist/{messages-BZqrGGm1.d.ts → messages-CAzUPPJM.d.cts} +10 -5
- package/dist/{messages-BZqrGGm1.d.cts → messages-CAzUPPJM.d.ts} +10 -5
- package/dist/messaging/index.cjs +756 -619
- package/dist/messaging/index.cjs.map +1 -1
- package/dist/messaging/index.d.cts +17 -226
- package/dist/messaging/index.d.ts +17 -226
- package/dist/messaging/index.js +19 -749
- package/dist/messaging/index.js.map +1 -1
- package/dist/operators/index.cjs +1256 -1059
- package/dist/operators/index.cjs.map +1 -1
- package/dist/operators/index.d.cts +6 -6
- package/dist/operators/index.d.ts +6 -6
- package/dist/operators/index.js +9 -8
- package/dist/orchestration/index.cjs +8664 -2617
- package/dist/orchestration/index.cjs.map +1 -1
- package/dist/orchestration/index.d.cts +171 -221
- package/dist/orchestration/index.d.ts +171 -221
- package/dist/orchestration/index.js +74 -982
- package/dist/orchestration/index.js.map +1 -1
- package/dist/orchestration/messaging.cjs +314 -0
- package/dist/orchestration/messaging.cjs.map +1 -0
- package/dist/orchestration/messaging.d.cts +56 -0
- package/dist/orchestration/messaging.d.ts +56 -0
- package/dist/orchestration/messaging.js +276 -0
- package/dist/orchestration/messaging.js.map +1 -0
- package/dist/orchestration/work-queue.cjs +1500 -0
- package/dist/orchestration/work-queue.cjs.map +1 -0
- package/dist/orchestration/work-queue.d.cts +196 -0
- package/dist/orchestration/work-queue.d.ts +196 -0
- package/dist/orchestration/work-queue.js +1289 -0
- package/dist/orchestration/work-queue.js.map +1 -0
- package/dist/patterns/event-flow.cjs +433 -0
- package/dist/patterns/event-flow.cjs.map +1 -0
- package/dist/patterns/event-flow.d.cts +115 -0
- package/dist/patterns/event-flow.d.ts +115 -0
- package/dist/patterns/event-flow.js +14 -0
- package/dist/patterns/event-flow.js.map +1 -0
- package/dist/patterns/index.cjs +748 -355
- package/dist/patterns/index.cjs.map +1 -1
- package/dist/patterns/index.d.cts +9 -5
- package/dist/patterns/index.d.ts +9 -5
- package/dist/patterns/index.js +13 -4
- package/dist/process-types-C9uMYz3i.d.ts +200 -0
- package/dist/process-types-h3uRlzDc.d.cts +200 -0
- package/dist/{reactive-collection-BxBqtIOE.d.cts → reactive-collection-B9R0Bl1P.d.cts} +11 -41
- package/dist/{reactive-collection-Cb1II1Fi.d.ts → reactive-collection-BXFrH0U2.d.ts} +11 -41
- package/dist/{reactive-collection-storage-D-KmjE0J.d.cts → reactive-collection-storage-BLGv8Xp8.d.cts} +5 -5
- package/dist/{reactive-collection-storage-BNiEc-Gd.d.ts → reactive-collection-storage-a4zD3665.d.ts} +5 -5
- package/dist/{reactive-map-BcB4KsQR.d.ts → reactive-map-C_8sOfdS.d.cts} +7 -6
- package/dist/{reactive-map-D-g3dv8I.d.cts → reactive-map-jle5dnok.d.ts} +7 -6
- package/dist/render/index.d.cts +3 -3
- package/dist/render/index.d.ts +3 -3
- package/dist/render/index.js +1 -0
- package/dist/scheduled-readiness-5rwQlyjV.d.ts +91 -0
- package/dist/scheduled-readiness-DpRY8jI0.d.cts +91 -0
- package/dist/semantic-memory-graph-C2ZUwIlq.d.ts +30 -0
- package/dist/semantic-memory-graph-DlZBD_Eu.d.cts +30 -0
- package/dist/{semantic-memory-graph-BYoIlP35.d.cts → semantic-memory-graph-types-BvzdqmkY.d.cts} +2 -28
- package/dist/{semantic-memory-graph-CxyXLms3.d.ts → semantic-memory-graph-types-Ci-OtahO.d.ts} +2 -28
- package/dist/solutions/index.cjs +6788 -2128
- package/dist/solutions/index.cjs.map +1 -1
- package/dist/solutions/index.d.cts +15 -519
- package/dist/solutions/index.d.ts +15 -519
- package/dist/solutions/index.js +91 -7
- package/dist/solutions/reactive-layout/browser/index.cjs +457 -0
- package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/browser/index.d.cts +44 -0
- package/dist/solutions/reactive-layout/browser/index.d.ts +44 -0
- package/dist/solutions/reactive-layout/browser/index.js +69 -0
- package/dist/solutions/reactive-layout/browser/index.js.map +1 -0
- package/dist/solutions/reactive-layout/index.cjs +4494 -0
- package/dist/solutions/reactive-layout/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/index.d.cts +37 -0
- package/dist/solutions/reactive-layout/index.d.ts +37 -0
- package/dist/solutions/reactive-layout/index.js +146 -0
- package/dist/solutions/reactive-layout/index.js.map +1 -0
- package/dist/solutions/reactive-layout/node-canvas/index.cjs +555 -0
- package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/node-canvas/index.d.cts +54 -0
- package/dist/solutions/reactive-layout/node-canvas/index.d.ts +54 -0
- package/dist/solutions/reactive-layout/node-canvas/index.js +131 -0
- package/dist/solutions/reactive-layout/node-canvas/index.js.map +1 -0
- package/dist/solutions/reactive-layout/react-native/index.cjs +504 -0
- package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/react-native/index.d.cts +51 -0
- package/dist/solutions/reactive-layout/react-native/index.d.ts +51 -0
- package/dist/solutions/reactive-layout/react-native/index.js +77 -0
- package/dist/solutions/reactive-layout/react-native/index.js.map +1 -0
- package/dist/solutions/reactive-layout/skia/index.cjs +557 -0
- package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/skia/index.d.cts +64 -0
- package/dist/solutions/reactive-layout/skia/index.d.ts +64 -0
- package/dist/solutions/reactive-layout/skia/index.js +70 -0
- package/dist/solutions/reactive-layout/skia/index.js.map +1 -0
- package/dist/solutions/work-item/actions.cjs +2345 -0
- package/dist/solutions/work-item/actions.cjs.map +1 -0
- package/dist/solutions/work-item/actions.d.cts +40 -0
- package/dist/solutions/work-item/actions.d.ts +40 -0
- package/dist/solutions/work-item/actions.js +2078 -0
- package/dist/solutions/work-item/actions.js.map +1 -0
- package/dist/solutions/work-item/scheduling.cjs +9797 -0
- package/dist/solutions/work-item/scheduling.cjs.map +1 -0
- package/dist/solutions/work-item/scheduling.d.cts +1868 -0
- package/dist/solutions/work-item/scheduling.d.ts +1868 -0
- package/dist/solutions/work-item/scheduling.js +146 -0
- package/dist/solutions/work-item/scheduling.js.map +1 -0
- package/dist/solutions/work-item/work-queue.cjs +306 -0
- package/dist/solutions/work-item/work-queue.cjs.map +1 -0
- package/dist/solutions/work-item/work-queue.d.cts +71 -0
- package/dist/solutions/work-item/work-queue.d.ts +71 -0
- package/dist/solutions/work-item/work-queue.js +270 -0
- package/dist/solutions/work-item/work-queue.js.map +1 -0
- package/dist/sources/browser.cjs +1399 -1052
- package/dist/sources/browser.cjs.map +1 -1
- package/dist/sources/browser.d.cts +33 -6
- package/dist/sources/browser.d.ts +33 -6
- package/dist/sources/browser.js +73 -6
- package/dist/sources/browser.js.map +1 -1
- package/dist/sources/index.cjs +1345 -1065
- package/dist/sources/index.cjs.map +1 -1
- package/dist/sources/index.d.cts +5 -5
- package/dist/sources/index.d.ts +5 -5
- package/dist/sources/index.js +7 -6
- package/dist/sources/node.cjs.map +1 -1
- package/dist/sources/node.d.cts +4 -4
- package/dist/sources/node.d.ts +4 -4
- package/dist/sources/node.js +2 -1
- package/dist/sources/node.js.map +1 -1
- package/dist/storage/browser.cjs +16 -0
- package/dist/storage/browser.cjs.map +1 -1
- package/dist/storage/browser.js +4 -3
- package/dist/storage/browser.js.map +1 -1
- package/dist/storage/index.cjs +16 -0
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.cts +6 -5
- package/dist/storage/index.d.ts +6 -5
- package/dist/storage/index.js +10 -9
- package/dist/storage/node.cjs +16 -0
- package/dist/storage/node.cjs.map +1 -1
- package/dist/storage/node.js +4 -3
- package/dist/storage/node.js.map +1 -1
- package/dist/store-BmtEs9mG.d.ts +123 -0
- package/dist/store-PAAsYvML.d.cts +123 -0
- package/dist/testing/index.cjs +1 -0
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +3 -2
- package/dist/types-BRNKoFHj.d.ts +357 -0
- package/dist/{types-h12mNYbq.d.ts → types-BS6CyR-x.d.cts} +49 -130
- package/dist/types-BWK2ay3e.d.cts +457 -0
- package/dist/types-BXKSAoE1.d.cts +357 -0
- package/dist/types-BaPpZItj.d.ts +457 -0
- package/dist/types-BhveCMg5.d.cts +274 -0
- package/dist/{types-bNMSWKqF.d.cts → types-C9NOgNJw.d.ts} +49 -130
- package/dist/types-CTsQ8Ww4.d.ts +274 -0
- package/dist/types-DL_05n2M.d.ts +34 -0
- package/dist/types-XDoqxYO9.d.cts +34 -0
- package/dist/work-item-runtime-types-BqtWnSCS.d.ts +138 -0
- package/dist/work-item-runtime-types-CHO03AKh.d.cts +138 -0
- package/dist/work-queue/index.cjs +1136 -0
- package/dist/work-queue/index.cjs.map +1 -0
- package/dist/work-queue/index.d.cts +21 -0
- package/dist/work-queue/index.d.ts +21 -0
- package/dist/work-queue/index.js +1082 -0
- package/dist/work-queue/index.js.map +1 -0
- package/package.json +603 -249
- package/dist/chunk-2ILL7HQI.js.map +0 -1
- package/dist/chunk-4VLAQHZI.js.map +0 -1
- package/dist/chunk-COHO25CZ.js.map +0 -1
- package/dist/chunk-DK554R7P.js.map +0 -1
- package/dist/chunk-G4M3NHRJ.js.map +0 -1
- package/dist/chunk-I3IHOHCJ.js.map +0 -1
- package/dist/chunk-JIMUDQN3.js.map +0 -1
- package/dist/chunk-RIIOUTGM.js.map +0 -1
- package/dist/chunk-SWTLEQL6.js.map +0 -1
- /package/dist/{chunk-GDL26N2T.js.map → chunk-3KN7NJDR.js.map} +0 -0
- /package/dist/{chunk-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
- /package/dist/{chunk-D6BG7U6A.js.map → chunk-7HZRJMN6.js.map} +0 -0
- /package/dist/{chunk-SCRFRCGR.js.map → chunk-BSQGE5PS.js.map} +0 -0
- /package/dist/{chunk-PKVBHGBM.js.map → chunk-CJIFGJQG.js.map} +0 -0
- /package/dist/{chunk-K3FXTC3I.js.map → chunk-HJACH5PU.js.map} +0 -0
- /package/dist/{chunk-GTPCOEOZ.js.map → chunk-IDMLXLLG.js.map} +0 -0
- /package/dist/{chunk-DKP56CSW.js.map → chunk-JKAYLDQV.js.map} +0 -0
- /package/dist/{chunk-Y3ZLRGHC.js.map → chunk-SIDJO2T4.js.map} +0 -0
- /package/dist/{chunk-JR4IKCR2.js.map → chunk-TPND5MJS.js.map} +0 -0
- /package/dist/{chunk-TEW47IVR.js.map → chunk-VPEFSDME.js.map} +0 -0
- /package/dist/{chunk-DJC4CHLQ.js.map → chunk-YDWBXXQZ.js.map} +0 -0
- /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
package/dist/storage/index.d.cts
CHANGED
|
@@ -4,13 +4,14 @@ import { b as ChangeLifecycle, S as StorageTimestampNs, N as NonNegativeDecimalI
|
|
|
4
4
|
export { C as ChangeEnvelope, a as ChangeEnvelopeOptions, D as DecimalIntegerString, O as ObserveEventFrame, c as ObserveEventLogPage, d as assertChangeEnvelope, e as assertDecimalIntegerString, f as assertNonNegativeDecimalIntegerString, g as assertObserveEventFrame, h as bigIntToDecimalString, i as bigIntToNonNegativeDecimalString, j as changeEnvelopeCodec, k as decimalStringToBigInt, l as envelopeChange, m as isDecimalIntegerString, n as isNonNegativeDecimalIntegerString, o as nonNegativeDecimalStringToBigInt, p as nowNs, q as observeEventFrame, r as observeEventFrameCodec, s as readObserveEventLogPage } from '../observe-event-log-0SVsx7JG.cjs';
|
|
5
5
|
import { C as Codec } from '../codec-BB7p8fJc.cjs';
|
|
6
6
|
export { S as StrictJsonObject, a as StrictJsonScalar, b as StrictJsonValue, c as assertStrictJsonObject, d as assertStrictJsonValue, j as jsonCodec, e as jsonCodecFor, s as stableJsonString, g as strictJsonCodec, h as strictJsonCodecFor } from '../codec-BB7p8fJc.cjs';
|
|
7
|
-
export { b as LoadReactiveCollectionStateOptions, R as REACTIVE_COLLECTION_CHANGE_FORMAT, d as REACTIVE_COLLECTION_FRAME_VERSION, e as REACTIVE_COLLECTION_SNAPSHOT_FORMAT, f as ReactiveCollectionChangeFrame, g as ReactiveCollectionRestoreState, h as ReactiveCollectionSnapshotFrame, i as ReactiveCollectionStorageKind, o as ReactiveIndexRestoreState, p as ReactiveListRestoreState, q as ReactiveLogRestoreState, r as ReactiveMapRestoreState,
|
|
7
|
+
export { b as LoadReactiveCollectionStateOptions, R as REACTIVE_COLLECTION_CHANGE_FORMAT, d as REACTIVE_COLLECTION_FRAME_VERSION, e as REACTIVE_COLLECTION_SNAPSHOT_FORMAT, f as ReactiveCollectionChangeFrame, g as ReactiveCollectionRestoreState, h as ReactiveCollectionSnapshotFrame, i as ReactiveCollectionStorageKind, o as ReactiveIndexRestoreState, p as ReactiveListRestoreState, q as ReactiveLogRestoreState, r as ReactiveMapRestoreState, t as assertReactiveCollectionChangeFrame, u as assertReactiveCollectionSnapshotFrame, v as collectionSnapshotKey, w as loadReactiveIndexState, x as loadReactiveListState, y as loadReactiveLogState, z as loadReactiveMapState, A as reactiveCollectionChangeFrame, B as reactiveCollectionChangeFrameCodec, C as reactiveCollectionSnapshotFrame, D as reactiveCollectionSnapshotFrameCodec } from '../reactive-collection-B9R0Bl1P.cjs';
|
|
8
8
|
export { R as ReadThroughErrorContext, a as ReadThroughLookupFact, b as ReadThroughLookupTier, c as ReadThroughMissContext, d as ReadThroughPromotionFact, T as TieredReadThroughOptions, e as TieredReadThroughResult, r as readThroughKv, t as tieredReadThrough } from '../read-through-B1CYPfq_.cjs';
|
|
9
|
-
import '../types-
|
|
10
|
-
import '../messages-
|
|
11
|
-
import '../
|
|
9
|
+
import '../types-BS6CyR-x.cjs';
|
|
10
|
+
import '../messages-CAzUPPJM.cjs';
|
|
11
|
+
import '../types-XDoqxYO9.cjs';
|
|
12
|
+
import '../graph-CWK3HLPB.cjs';
|
|
12
13
|
import '../core/index.cjs';
|
|
13
|
-
import '../describe-
|
|
14
|
+
import '../describe-CQRrkv-Q.cjs';
|
|
14
15
|
|
|
15
16
|
/** Content-addressed KV access mode for D82 passive storage helpers. */
|
|
16
17
|
type ContentAddressedMode = "read" | "write" | "read-write" | "read-strict";
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ import { b as ChangeLifecycle, S as StorageTimestampNs, N as NonNegativeDecimalI
|
|
|
4
4
|
export { C as ChangeEnvelope, a as ChangeEnvelopeOptions, D as DecimalIntegerString, O as ObserveEventFrame, c as ObserveEventLogPage, d as assertChangeEnvelope, e as assertDecimalIntegerString, f as assertNonNegativeDecimalIntegerString, g as assertObserveEventFrame, h as bigIntToDecimalString, i as bigIntToNonNegativeDecimalString, j as changeEnvelopeCodec, k as decimalStringToBigInt, l as envelopeChange, m as isDecimalIntegerString, n as isNonNegativeDecimalIntegerString, o as nonNegativeDecimalStringToBigInt, p as nowNs, q as observeEventFrame, r as observeEventFrameCodec, s as readObserveEventLogPage } from '../observe-event-log-Dnm76owp.js';
|
|
5
5
|
import { C as Codec } from '../codec-BB7p8fJc.js';
|
|
6
6
|
export { S as StrictJsonObject, a as StrictJsonScalar, b as StrictJsonValue, c as assertStrictJsonObject, d as assertStrictJsonValue, j as jsonCodec, e as jsonCodecFor, s as stableJsonString, g as strictJsonCodec, h as strictJsonCodecFor } from '../codec-BB7p8fJc.js';
|
|
7
|
-
export { b as LoadReactiveCollectionStateOptions, R as REACTIVE_COLLECTION_CHANGE_FORMAT, d as REACTIVE_COLLECTION_FRAME_VERSION, e as REACTIVE_COLLECTION_SNAPSHOT_FORMAT, f as ReactiveCollectionChangeFrame, g as ReactiveCollectionRestoreState, h as ReactiveCollectionSnapshotFrame, i as ReactiveCollectionStorageKind, o as ReactiveIndexRestoreState, p as ReactiveListRestoreState, q as ReactiveLogRestoreState, r as ReactiveMapRestoreState,
|
|
7
|
+
export { b as LoadReactiveCollectionStateOptions, R as REACTIVE_COLLECTION_CHANGE_FORMAT, d as REACTIVE_COLLECTION_FRAME_VERSION, e as REACTIVE_COLLECTION_SNAPSHOT_FORMAT, f as ReactiveCollectionChangeFrame, g as ReactiveCollectionRestoreState, h as ReactiveCollectionSnapshotFrame, i as ReactiveCollectionStorageKind, o as ReactiveIndexRestoreState, p as ReactiveListRestoreState, q as ReactiveLogRestoreState, r as ReactiveMapRestoreState, t as assertReactiveCollectionChangeFrame, u as assertReactiveCollectionSnapshotFrame, v as collectionSnapshotKey, w as loadReactiveIndexState, x as loadReactiveListState, y as loadReactiveLogState, z as loadReactiveMapState, A as reactiveCollectionChangeFrame, B as reactiveCollectionChangeFrameCodec, C as reactiveCollectionSnapshotFrame, D as reactiveCollectionSnapshotFrameCodec } from '../reactive-collection-BXFrH0U2.js';
|
|
8
8
|
export { R as ReadThroughErrorContext, a as ReadThroughLookupFact, b as ReadThroughLookupTier, c as ReadThroughMissContext, d as ReadThroughPromotionFact, T as TieredReadThroughOptions, e as TieredReadThroughResult, r as readThroughKv, t as tieredReadThrough } from '../read-through-DwyJhGs1.js';
|
|
9
|
-
import '../types-
|
|
10
|
-
import '../messages-
|
|
11
|
-
import '../
|
|
9
|
+
import '../types-C9NOgNJw.js';
|
|
10
|
+
import '../messages-CAzUPPJM.js';
|
|
11
|
+
import '../types-DL_05n2M.js';
|
|
12
|
+
import '../graph-ho5sotHP.js';
|
|
12
13
|
import '../core/index.js';
|
|
13
|
-
import '../describe-
|
|
14
|
+
import '../describe-B_A5fbXH.js';
|
|
14
15
|
|
|
15
16
|
/** Content-addressed KV access mode for D82 passive storage helpers. */
|
|
16
17
|
type ContentAddressedMode = "read" | "write" | "read-write" | "read-strict";
|
package/dist/storage/index.js
CHANGED
|
@@ -26,7 +26,11 @@ import {
|
|
|
26
26
|
walFrameCodec,
|
|
27
27
|
walFrameKey,
|
|
28
28
|
walFramePrefix
|
|
29
|
-
} from "../chunk-
|
|
29
|
+
} from "../chunk-IDMLXLLG.js";
|
|
30
|
+
import {
|
|
31
|
+
readThroughKv,
|
|
32
|
+
tieredReadThrough
|
|
33
|
+
} from "../chunk-4Q77MMJY.js";
|
|
30
34
|
import {
|
|
31
35
|
assertChangeEnvelope,
|
|
32
36
|
assertDecimalIntegerString,
|
|
@@ -44,7 +48,7 @@ import {
|
|
|
44
48
|
observeEventFrame,
|
|
45
49
|
observeEventFrameCodec,
|
|
46
50
|
readObserveEventLogPage
|
|
47
|
-
} from "../chunk-
|
|
51
|
+
} from "../chunk-HJACH5PU.js";
|
|
48
52
|
import {
|
|
49
53
|
APPEND_LOG_SEQ_PAD,
|
|
50
54
|
appendLogKey,
|
|
@@ -53,11 +57,7 @@ import {
|
|
|
53
57
|
memoryMultiWriterAppendLog,
|
|
54
58
|
multiWriterAppendLogStorage,
|
|
55
59
|
readAppendLogPage
|
|
56
|
-
} from "../chunk-
|
|
57
|
-
import {
|
|
58
|
-
readThroughKv,
|
|
59
|
-
tieredReadThrough
|
|
60
|
-
} from "../chunk-Z2ANQ6JW.js";
|
|
60
|
+
} from "../chunk-ZLFRB6FI.js";
|
|
61
61
|
import {
|
|
62
62
|
dictKv,
|
|
63
63
|
hasKvPutIfAbsent,
|
|
@@ -73,7 +73,7 @@ import {
|
|
|
73
73
|
requireStoragePutIfAbsent,
|
|
74
74
|
requireStorageVersioned,
|
|
75
75
|
webStorageBackend
|
|
76
|
-
} from "../chunk-
|
|
76
|
+
} from "../chunk-JKAYLDQV.js";
|
|
77
77
|
import {
|
|
78
78
|
assertStrictJsonObject,
|
|
79
79
|
assertStrictJsonValue,
|
|
@@ -82,7 +82,8 @@ import {
|
|
|
82
82
|
stableJsonString,
|
|
83
83
|
strictJsonCodec,
|
|
84
84
|
strictJsonCodecFor
|
|
85
|
-
} from "../chunk-
|
|
85
|
+
} from "../chunk-K7FB3JTD.js";
|
|
86
|
+
import "../chunk-DGUM43GV.js";
|
|
86
87
|
export {
|
|
87
88
|
APPEND_LOG_SEQ_PAD,
|
|
88
89
|
ContentAddressedMissError,
|
package/dist/storage/node.cjs
CHANGED
|
@@ -86,9 +86,16 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
|
|
|
86
86
|
}
|
|
87
87
|
for (const key of Object.getOwnPropertyNames(value)) {
|
|
88
88
|
const isIndex = /^(0|[1-9]\d*)$/.test(key) && Number.isSafeInteger(Number(key)) && Number(key) < value.length;
|
|
89
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
90
|
+
if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
|
|
91
|
+
throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
|
|
92
|
+
}
|
|
89
93
|
if (key !== "length" && !isIndex) {
|
|
90
94
|
throw new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);
|
|
91
95
|
}
|
|
96
|
+
if (key !== "length" && descriptor !== void 0 && !descriptor.enumerable) {
|
|
97
|
+
throw new TypeError(`stableJsonString: non-enumerable array property at ${path}.${key}`);
|
|
98
|
+
}
|
|
92
99
|
}
|
|
93
100
|
const out2 = [];
|
|
94
101
|
for (let i = 0; i < value.length; i += 1) {
|
|
@@ -102,6 +109,15 @@ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", st
|
|
|
102
109
|
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
103
110
|
throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
|
|
104
111
|
}
|
|
112
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
113
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
114
|
+
if (descriptor !== void 0 && ("get" in descriptor || "set" in descriptor)) {
|
|
115
|
+
throw new TypeError(`stableJsonString: accessor property at ${path}.${key}`);
|
|
116
|
+
}
|
|
117
|
+
if (descriptor !== void 0 && !descriptor.enumerable) {
|
|
118
|
+
throw new TypeError(`stableJsonString: non-enumerable property at ${path}.${key}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
105
121
|
const out = /* @__PURE__ */ Object.create(null);
|
|
106
122
|
for (const key of Object.keys(value).sort()) {
|
|
107
123
|
out[key] = sortedJsonValue(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/storage/node.ts","../../src/storage/backend.ts","../../src/json/codec.ts","../../src/storage/kv.ts","../../src/storage/append-log.ts"],"sourcesContent":["/**\n * Node-only passive storage backends (D103).\n *\n * Import from `@graphrefly/ts/storage/node`; the universal storage barrel stays browser-safe.\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport {\n\tcloseSync,\n\tmkdirSync,\n\topenSync,\n\treaddirSync,\n\treadFileSync,\n\trenameSync,\n\tunlinkSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { basename, dirname, join } from \"node:path\";\nimport { type AppendLogStorageTier, appendLogStorage } from \"./append-log.js\";\nimport type { StorageBackend, StorageGeneration, StorageNamespaceOptions } from \"./backend.js\";\nimport type { Codec } from \"./codec.js\";\nimport { type KvStorageTier, kvStorage } from \"./kv.js\";\n\nexport interface FileBackendOptions extends StorageNamespaceOptions {\n\t/** File suffix used for stored byte blobs. Defaults to `.bin`. */\n\textension?: string;\n}\n\nexport interface FileKvOptions<T> extends FileBackendOptions {\n\tcodec?: Codec<T>;\n}\n\nexport interface FileAppendLogOptions<T> extends FileKvOptions<T> {\n\t/** Append-log key prefix. Defaults to `event-log`. */\n\tprefix?: string;\n}\n\nexport interface SqliteBackendOptions extends StorageNamespaceOptions {\n\t/** Table name used for passive byte storage. Defaults to `graphrefly_storage`. */\n\ttableName?: string;\n}\n\nexport interface SqliteKvOptions<T> extends SqliteBackendOptions {\n\tcodec?: Codec<T>;\n}\n\nexport interface SqliteAppendLogOptions<T> extends SqliteKvOptions<T> {\n\t/** Append-log key prefix. Defaults to `event-log`. */\n\tprefix?: string;\n}\n\nexport interface ClosableStorageBackend extends StorageBackend {\n\treadonly name: string;\n\tclose(): void;\n}\n\ntype SqliteDatabaseConstructor = new (path: string) => SqliteDatabase;\n\ninterface SqliteDatabase {\n\texec(sql: string): void;\n\tprepare(sql: string): SqliteStatement;\n\tclose(): void;\n}\n\ninterface SqliteStatement {\n\tget(...params: unknown[]): unknown;\n\trun(...params: unknown[]): unknown;\n\tall(...params: unknown[]): unknown[];\n}\n\nconst FILE_STEM_PREFIX = \"k-\";\nconst NAMESPACE_SEPARATOR = \"\\u0000\";\nconst SQLITE_GENERATION = Symbol(\"graphrefly.sqliteBackend.generation\");\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\nconst require = createRequire(\"/graphrefly-storage-node.js\");\n\ninterface SqliteGeneration {\n\treadonly [SQLITE_GENERATION]: readonly [\n\t\tstorageId: object,\n\t\tkey: string,\n\t\trowGeneration: number | null,\n\t\tepoch: number,\n\t];\n}\n\nfunction isErrno(error: unknown, code: string): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"code\" in error &&\n\t\t(error as { code?: unknown }).code === code\n\t);\n}\n\nfunction keyToStem(key: string): string {\n\tlet out = \"\";\n\tfor (const ch of key) {\n\t\tif (/^[a-zA-Z0-9_-]$/.test(ch)) {\n\t\t\tout += ch;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const byte of encoder.encode(ch)) out += `%${byte.toString(16).padStart(2, \"0\")}`;\n\t}\n\treturn out;\n}\n\nfunction stemToKey(stem: string): string | null {\n\tconst bytes: number[] = [];\n\tlet i = 0;\n\twhile (i < stem.length) {\n\t\tconst ch = stem[i]!;\n\t\tif (ch === \"%\" && i + 2 < stem.length) {\n\t\t\tconst hex = stem.slice(i + 1, i + 3);\n\t\t\tif (/^[0-9a-f]{2}$/i.test(hex)) {\n\t\t\t\tbytes.push(Number.parseInt(hex, 16));\n\t\t\t\ti += 3;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tconst code = ch.charCodeAt(0);\n\t\tif (code > 0x7f) return null;\n\t\tbytes.push(code);\n\t\ti += 1;\n\t}\n\ttry {\n\t\treturn decoder.decode(new Uint8Array(bytes));\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction validateExtension(extension: string): string {\n\tif (\n\t\textension.length < 2 ||\n\t\t!extension.startsWith(\".\") ||\n\t\textension.includes(\"..\") ||\n\t\t/[/\\\\\\0]/.test(extension) ||\n\t\t!/^[.A-Za-z0-9_-]+$/.test(extension)\n\t) {\n\t\tthrow new TypeError(\"fileBackend: extension must be a simple suffix such as .bin\");\n\t}\n\treturn extension;\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\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 validateSqliteTableName(tableName: string): string {\n\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName)) {\n\t\tthrow new TypeError(\"sqliteBackend: tableName must be a simple SQLite identifier\");\n\t}\n\treturn tableName;\n}\n\nfunction sqliteGeneration(\n\tstorageId: object,\n\tkey: string,\n\trowGeneration: number | null,\n\tepoch: number,\n): SqliteGeneration {\n\treturn Object.freeze({\n\t\t[SQLITE_GENERATION]: Object.freeze([storageId, key, rowGeneration, epoch] as const),\n\t});\n}\n\nfunction readSqliteGeneration(\n\tgeneration: StorageGeneration,\n):\n\t| readonly [storageId: object, key: string, rowGeneration: number | null, epoch: number]\n\t| undefined {\n\tif (typeof generation !== \"object\" || generation === null) return undefined;\n\tconst maybe = generation as Partial<SqliteGeneration>;\n\tconst token = maybe[SQLITE_GENERATION];\n\tif (\n\t\tArray.isArray(token) &&\n\t\ttoken.length === 4 &&\n\t\ttypeof token[0] === \"object\" &&\n\t\ttoken[0] !== null &&\n\t\ttypeof token[1] === \"string\" &&\n\t\t(token[2] === null || typeof token[2] === \"number\") &&\n\t\ttypeof token[3] === \"number\"\n\t) {\n\t\treturn token as readonly [object, string, number | null, number];\n\t}\n\treturn undefined;\n}\n\nfunction sqliteChanges(result: unknown): number {\n\treturn typeof result === \"object\" &&\n\t\tresult !== null &&\n\t\t\"changes\" in result &&\n\t\ttypeof (result as { changes?: unknown }).changes === \"number\"\n\t\t? (result as { changes: number }).changes\n\t\t: 0;\n}\n\nfunction sqliteBytes(value: Uint8Array | ArrayBuffer): Uint8Array {\n\treturn Uint8Array.from(value instanceof Uint8Array ? value : new Uint8Array(value));\n}\n\nfunction loadSqliteDatabaseSync(): SqliteDatabaseConstructor {\n\ttry {\n\t\tconst DatabaseSync = (require(\"node:sqlite\") as { DatabaseSync?: unknown }).DatabaseSync;\n\t\tif (typeof DatabaseSync !== \"function\") {\n\t\t\tthrow new TypeError(\"DatabaseSync export is missing\");\n\t\t}\n\t\treturn DatabaseSync as SqliteDatabaseConstructor;\n\t} catch (error) {\n\t\tthrow new Error(\"sqliteBackend: node:sqlite is not available in this Node runtime\", {\n\t\t\tcause: error,\n\t\t});\n\t}\n}\n\n/** Node filesystem byte backend with atomic replace writes and D85 conditional create. */\nexport function fileBackend(dir: string, opts: FileBackendOptions = {}): StorageBackend {\n\tconst extension = validateExtension(opts.extension ?? \".bin\");\n\tconst namespace =\n\t\topts.namespace === undefined ? \"\" : validateNamespace(\"fileBackend\", opts.namespace);\n\tconst namespacePrefix = namespace.length > 0 ? `${namespace}${NAMESPACE_SEPARATOR}` : \"\";\n\tconst storageKey = (key: string) => `${namespacePrefix}${validateLogicalKey(\"fileBackend\", key)}`;\n\tconst pathFor = (key: string) =>\n\t\tjoin(dir, `${FILE_STEM_PREFIX}${keyToStem(storageKey(key))}${extension}`);\n\tconst keyFromFilename = (filename: string): string | null => {\n\t\tif (!filename.endsWith(extension)) return null;\n\t\tconst stem = filename.slice(0, -extension.length);\n\t\tif (!stem.startsWith(FILE_STEM_PREFIX)) return null;\n\t\tconst key = stemToKey(stem.slice(FILE_STEM_PREFIX.length));\n\t\tif (key === null || !key.startsWith(namespacePrefix)) return null;\n\t\tconst logical = key.slice(namespacePrefix.length);\n\t\tif (logical.includes(NAMESPACE_SEPARATOR)) {\n\t\t\tthrow new TypeError(\"fileBackend: malformed stored key\");\n\t\t}\n\t\treturn logical;\n\t};\n\n\treturn {\n\t\tget(key) {\n\t\t\ttry {\n\t\t\t\treturn Uint8Array.from(readFileSync(pathFor(key)));\n\t\t\t} catch (error) {\n\t\t\t\tif (isErrno(error, \"ENOENT\")) return undefined;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tput(key, value) {\n\t\t\tmkdirSync(dir, { recursive: true });\n\t\t\tconst filePath = pathFor(key);\n\t\t\tconst base = basename(filePath);\n\t\t\tconst parent = dirname(filePath);\n\t\t\tconst tmp = join(parent, `.${base}.${randomBytes(8).toString(\"hex\")}.tmp`);\n\t\t\ttry {\n\t\t\t\twriteFileSync(tmp, value);\n\t\t\t\trenameSync(tmp, filePath);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tunlinkSync(tmp);\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore cleanup failures; the original write error is the useful one.\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tputIfAbsent(key, value) {\n\t\t\tmkdirSync(dir, { recursive: true });\n\t\t\tconst filePath = pathFor(key);\n\t\t\tlet fd: number | undefined;\n\t\t\ttry {\n\t\t\t\tfd = openSync(filePath, \"wx\");\n\t\t\t\twriteFileSync(fd, value);\n\t\t\t\treturn true;\n\t\t\t} catch (error) {\n\t\t\t\tif (isErrno(error, \"EEXIST\")) return false;\n\t\t\t\tif (fd !== undefined) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tunlinkSync(filePath);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Best effort cleanup of a partially-created file.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\tif (fd !== undefined) closeSync(fd);\n\t\t\t}\n\t\t},\n\t\tdelete(key) {\n\t\t\ttry {\n\t\t\t\tunlinkSync(pathFor(key));\n\t\t\t} catch (error) {\n\t\t\t\tif (!isErrno(error, \"ENOENT\")) throw error;\n\t\t\t}\n\t\t},\n\t\tlist(prefix = \"\") {\n\t\t\tconst validatedPrefix = validateListPrefix(\"fileBackend\", prefix);\n\t\t\tlet entries: string[];\n\t\t\ttry {\n\t\t\t\tentries = readdirSync(dir);\n\t\t\t} catch (error) {\n\t\t\t\tif (isErrno(error, \"ENOENT\")) return [];\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst keys: string[] = [];\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (entry.startsWith(\".\")) continue;\n\t\t\t\tconst key = keyFromFilename(entry);\n\t\t\t\tif (key?.startsWith(validatedPrefix)) keys.push(key);\n\t\t\t}\n\t\t\treturn keys.sort();\n\t\t},\n\t};\n}\n\n/**\n * Create a typed KV tier over a Node filesystem backend (D106 passive storage).\n */\nexport function fileKv<T>(dir: string, opts: FileKvOptions<T> = {}): KvStorageTier<T> {\n\treturn kvStorage<T>({\n\t\tbackend: fileBackend(dir, opts),\n\t\tcodec: opts.codec,\n\t});\n}\n\n/**\n * Create an append-log tier over a Node filesystem backend (D106 passive storage).\n */\nexport function fileAppendLog<T>(\n\tdir: string,\n\topts: FileAppendLogOptions<T> = {},\n): AppendLogStorageTier<T> {\n\treturn appendLogStorage<T>({\n\t\tkv: fileKv<T>(dir, opts),\n\t\tprefix: opts.prefix ?? \"event-log\",\n\t});\n}\n\n/**\n * Optional Node SQLite byte backend (D106 passive storage).\n *\n * Uses `node:sqlite` when the current Node runtime provides it; otherwise throws a clear\n * runtime error at construction time. The caller owns `close()`.\n */\nexport function sqliteBackend(\n\tpath: string,\n\topts: SqliteBackendOptions = {},\n): ClosableStorageBackend {\n\tconst table = validateSqliteTableName(opts.tableName ?? \"graphrefly_storage\");\n\tconst metaTable = validateSqliteTableName(`${table}_meta`);\n\tconst namespace =\n\t\topts.namespace === undefined ? \"\" : validateNamespace(\"sqliteBackend\", opts.namespace);\n\tconst DatabaseSync = loadSqliteDatabaseSync();\n\tconst namespacePrefix = namespace.length > 0 ? `${namespace}${NAMESPACE_SEPARATOR}` : \"\";\n\tconst storageKey = (key: string) =>\n\t\t`${namespacePrefix}${validateLogicalKey(\"sqliteBackend\", key)}`;\n\tconst storageId = Object.freeze({});\n\tconst logicalKey = (key: string): string | undefined => {\n\t\tif (typeof key !== \"string\") {\n\t\t\tthrow new TypeError(\"sqliteBackend: stored key is corrupt\");\n\t\t}\n\t\tif (!key.startsWith(namespacePrefix)) return undefined;\n\t\tconst logical = key.slice(namespacePrefix.length);\n\t\tif (logical.includes(NAMESPACE_SEPARATOR)) {\n\t\t\tthrow new TypeError(\"sqliteBackend: malformed stored key\");\n\t\t}\n\t\treturn logical;\n\t};\n\tconst db = new DatabaseSync(path);\n\tdb.exec(\n\t\t`CREATE TABLE IF NOT EXISTS ${table} (k TEXT PRIMARY KEY, v BLOB NOT NULL, g INTEGER NOT NULL DEFAULT 0)`,\n\t);\n\tconst columns = db.prepare(`PRAGMA table_info(${table})`).all() as Array<{ name?: string }>;\n\tif (!columns.some((column) => column.name === \"g\")) {\n\t\tdb.exec(`ALTER TABLE ${table} ADD COLUMN g INTEGER NOT NULL DEFAULT 0`);\n\t}\n\tdb.exec(`CREATE TABLE IF NOT EXISTS ${metaTable} (k TEXT PRIMARY KEY, v INTEGER NOT NULL)`);\n\tdb.exec(`\n\t\tCREATE TRIGGER IF NOT EXISTS ${table}_generation_insert\n\t\tAFTER INSERT ON ${table}\n\t\tBEGIN\n\t\t\tINSERT INTO ${metaTable} (k, v) VALUES (NEW.k, 1)\n\t\t\tON CONFLICT(k) DO UPDATE SET v = ${metaTable}.v + 1;\n\t\tEND\n\t`);\n\tdb.exec(`\n\t\tCREATE TRIGGER IF NOT EXISTS ${table}_generation_update\n\t\tAFTER UPDATE ON ${table}\n\t\tBEGIN\n\t\t\tINSERT INTO ${metaTable} (k, v) VALUES (NEW.k, 1)\n\t\t\tON CONFLICT(k) DO UPDATE SET v = ${metaTable}.v + 1;\n\t\tEND\n\t`);\n\tdb.exec(`\n\t\tCREATE TRIGGER IF NOT EXISTS ${table}_generation_delete\n\t\tAFTER DELETE ON ${table}\n\t\tBEGIN\n\t\t\tINSERT INTO ${metaTable} (k, v) VALUES (OLD.k, 1)\n\t\t\tON CONFLICT(k) DO UPDATE SET v = ${metaTable}.v + 1;\n\t\tEND\n\t`);\n\n\tconst keyEpoch = (key: string): number => {\n\t\tconst row = db.prepare(`SELECT v FROM ${metaTable} WHERE k = ?`).get(key) as\n\t\t\t| { v?: number }\n\t\t\t| undefined;\n\t\tconst value = row?.v ?? 0;\n\t\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) {\n\t\t\tthrow new Error(\"sqliteBackend: per-key generation epoch is corrupt\");\n\t\t}\n\t\treturn value;\n\t};\n\tconst readRow = (\n\t\tkey: string,\n\t):\n\t\t| {\n\t\t\t\treadonly value: Uint8Array;\n\t\t\t\treadonly generation: number;\n\t\t }\n\t\t| undefined => {\n\t\tconst row = db.prepare(`SELECT v, g FROM ${table} WHERE k = ?`).get(storageKey(key)) as\n\t\t\t| { v?: Uint8Array | ArrayBuffer; g?: number }\n\t\t\t| undefined;\n\t\tif (row?.v === undefined) return undefined;\n\t\tconst generation = row.g;\n\t\tif (typeof generation !== \"number\" || !Number.isSafeInteger(generation) || generation < 0) {\n\t\t\tthrow new Error(\"sqliteBackend: row generation is corrupt\");\n\t\t}\n\t\treturn { value: sqliteBytes(row.v), generation };\n\t};\n\n\treturn {\n\t\tname: `sqlite:${path}/${table}`,\n\t\tget(key) {\n\t\t\treturn readRow(key)?.value;\n\t\t},\n\t\tput(key, value) {\n\t\t\tdb.prepare(\n\t\t\t\t`INSERT INTO ${table} (k, v, g) VALUES (?, ?, 0) ON CONFLICT(k) DO UPDATE SET v = excluded.v, g = ${table}.g + 1`,\n\t\t\t).run(storageKey(key), value);\n\t\t},\n\t\tputIfAbsent(key, value) {\n\t\t\tconst result = db\n\t\t\t\t.prepare(`INSERT OR IGNORE INTO ${table} (k, v, g) VALUES (?, ?, 0)`)\n\t\t\t\t.run(storageKey(key), value) as { changes?: number };\n\t\t\treturn sqliteChanges(result) === 1;\n\t\t},\n\t\tgetVersioned(key) {\n\t\t\tconst row = readRow(key);\n\t\t\tif (row === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"miss\",\n\t\t\t\t\tgeneration: sqliteGeneration(storageId, storageKey(key), null, keyEpoch(storageKey(key))),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"hit\",\n\t\t\t\tvalue: row.value,\n\t\t\t\tgeneration: sqliteGeneration(\n\t\t\t\t\tstorageId,\n\t\t\t\t\tstorageKey(key),\n\t\t\t\t\trow.generation,\n\t\t\t\t\tkeyEpoch(storageKey(key)),\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\tsetIfMatch(key, value, generation) {\n\t\t\tconst keyForStorage = storageKey(key);\n\t\t\tconst observed = readSqliteGeneration(generation);\n\t\t\tif (observed === undefined || observed[0] !== storageId || observed[1] !== keyForStorage) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (observed[2] === null) {\n\t\t\t\treturn (\n\t\t\t\t\tsqliteChanges(\n\t\t\t\t\t\tdb\n\t\t\t\t\t\t\t.prepare(\n\t\t\t\t\t\t\t\t`INSERT INTO ${table} (k, v, g) SELECT ?, ?, 0 WHERE COALESCE((SELECT v FROM ${metaTable} WHERE k = ?), 0) = ? AND NOT EXISTS (SELECT 1 FROM ${table} WHERE k = ?)`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.run(keyForStorage, value, keyForStorage, observed[3], keyForStorage),\n\t\t\t\t\t) === 1\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn (\n\t\t\t\tsqliteChanges(\n\t\t\t\t\tdb\n\t\t\t\t\t\t.prepare(\n\t\t\t\t\t\t\t`UPDATE ${table} SET v = ?, g = g + 1 WHERE k = ? AND g = ? AND COALESCE((SELECT v FROM ${metaTable} WHERE k = ?), 0) = ?`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.run(value, keyForStorage, observed[2], keyForStorage, observed[3]),\n\t\t\t\t) === 1\n\t\t\t);\n\t\t},\n\t\tdelete(key) {\n\t\t\tdb.prepare(`DELETE FROM ${table} WHERE k = ?`).run(storageKey(key));\n\t\t},\n\t\tlist(prefix = \"\") {\n\t\t\tconst validatedPrefix = validateListPrefix(\"sqliteBackend\", prefix);\n\t\t\tconst rows = db.prepare(`SELECT k FROM ${table} ORDER BY k`).all() as { k: string }[];\n\t\t\tconst out: string[] = [];\n\t\t\tfor (const row of rows) {\n\t\t\t\tconst key = logicalKey(row.k);\n\t\t\t\tif (key?.startsWith(validatedPrefix)) out.push(key);\n\t\t\t}\n\t\t\treturn out.sort();\n\t\t},\n\t\tclose() {\n\t\t\tdb.close();\n\t\t},\n\t};\n}\n\n/**\n * Create a typed KV tier over an optional Node SQLite backend.\n */\nexport function sqliteKv<T>(\n\tpath: string,\n\topts: SqliteKvOptions<T> = {},\n): KvStorageTier<T> & { close(): void } {\n\tconst backend = sqliteBackend(path, opts);\n\tconst tier = kvStorage<T>({\n\t\tbackend,\n\t\tcodec: opts.codec,\n\t});\n\treturn Object.assign(tier, { close: () => backend.close() });\n}\n\n/**\n * Create an append-log tier over an optional Node SQLite backend.\n */\nexport function sqliteAppendLog<T>(\n\tpath: string,\n\topts: SqliteAppendLogOptions<T> = {},\n): AppendLogStorageTier<T> & { close(): void } {\n\tconst kv = sqliteKv<T>(path, opts);\n\tconst log = appendLogStorage<T>({ kv, prefix: opts.prefix ?? \"event-log\" });\n\treturn Object.assign(log, { close: () => kv.close() });\n}\n","/**\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","/**\n * Neutral JSON/encoding utilities (D96).\n *\n * Shared by graph checkpoints and storage bindings; neither layer owns the strict JSON\n * scanner/canonicalization contract.\n */\n\n/** Typed byte codec for D82 storage binding helpers and D96 shared JSON surfaces. */\nexport interface Codec<T> {\n\tencode(value: T): Uint8Array;\n\tdecode(bytes: Uint8Array): T;\n}\n\nexport type StrictJsonScalar = null | boolean | number | string;\nexport type StrictJsonValue =\n\t| StrictJsonScalar\n\t| readonly StrictJsonValue[]\n\t| { readonly [key: string]: StrictJsonValue };\nexport type StrictJsonObject = Readonly<Record<string, StrictJsonValue>>;\n\ntype JsonValue = StrictJsonValue;\n\nconst JS_MIN_NORMAL_NUMBER = 2 ** -1022;\n\nfunction assertStableJsonNumber(value: number, path: string): void {\n\tif (!Number.isFinite(value)) {\n\t\tthrow new TypeError(`stableJsonString: non-finite number at ${path}`);\n\t}\n}\n\nfunction assertStrictJsonNumber(value: number, path: string): void {\n\tassertStableJsonNumber(value, path);\n\tif (Object.is(value, -0)) {\n\t\tthrow new TypeError(`stableJsonString: non-canonical number at ${path}`);\n\t}\n\tconst abs = Math.abs(value);\n\tif (abs > 0 && abs < JS_MIN_NORMAL_NUMBER) {\n\t\tthrow new TypeError(`stableJsonString: subnormal number at ${path}`);\n\t}\n\tif (Number.isInteger(value) && !Number.isSafeInteger(value)) {\n\t\tthrow new TypeError(`stableJsonString: integer outside safe range at ${path}`);\n\t}\n}\n\nfunction sortedJsonValue(\n\tvalue: unknown,\n\tseen = new Set<object>(),\n\tpath = \"$\",\n\tstrictNumbers = false,\n): JsonValue {\n\tif (value === null) return null;\n\tif (typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\") {\n\t\tif (strictNumbers) assertStrictJsonNumber(value, path);\n\t\telse assertStableJsonNumber(value, path);\n\t\treturn value;\n\t}\n\tif (typeof value !== \"object\") {\n\t\tthrow new TypeError(`stableJsonString: value at ${path} is not JSON-encodable`);\n\t}\n\tif (seen.has(value)) throw new TypeError(`stableJsonString: circular reference at ${path}`);\n\tconst proto = Object.getPrototypeOf(value);\n\tif (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {\n\t\tthrow new TypeError(`stableJsonString: non-plain object at ${path}`);\n\t}\n\tseen.add(value);\n\ttry {\n\t\tif (Array.isArray(value)) {\n\t\t\tif (Object.getOwnPropertySymbols(value).length > 0) {\n\t\t\t\tthrow new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);\n\t\t\t}\n\t\t\tfor (const key of Object.getOwnPropertyNames(value)) {\n\t\t\t\tconst isIndex =\n\t\t\t\t\t/^(0|[1-9]\\d*)$/.test(key) &&\n\t\t\t\t\tNumber.isSafeInteger(Number(key)) &&\n\t\t\t\t\tNumber(key) < value.length;\n\t\t\t\tif (key !== \"length\" && !isIndex) {\n\t\t\t\t\tthrow new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst out: JsonValue[] = [];\n\t\t\tfor (let i = 0; i < value.length; i += 1) {\n\t\t\t\tif (!(i in value)) {\n\t\t\t\t\tthrow new TypeError(`stableJsonString: sparse array hole at ${path}[${i}]`);\n\t\t\t\t}\n\t\t\t\tout.push(sortedJsonValue(value[i], seen, `${path}[${i}]`, strictNumbers));\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tif (Object.getOwnPropertySymbols(value).length > 0) {\n\t\t\tthrow new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);\n\t\t}\n\t\tconst out: Record<string, JsonValue> = Object.create(null);\n\t\tfor (const key of Object.keys(value as Record<string, unknown>).sort()) {\n\t\t\tout[key] = sortedJsonValue(\n\t\t\t\t(value as Record<string, unknown>)[key],\n\t\t\t\tseen,\n\t\t\t\t`${path}.${key}`,\n\t\t\t\tstrictNumbers,\n\t\t\t);\n\t\t}\n\t\treturn out;\n\t} finally {\n\t\tseen.delete(value);\n\t}\n}\n\n/** Stable JSON string: object keys sort by code-unit order for deterministic storage/checkpoint bytes. */\nexport function stableJsonString(value: unknown): string {\n\treturn JSON.stringify(sortedJsonValue(value));\n}\n\nfunction strictStableJsonString(value: unknown): string {\n\treturn JSON.stringify(sortedJsonValue(value, new Set<object>(), \"$\", true));\n}\n\n/** Build a JSON codec using stable object-key ordering. */\nexport function jsonCodecFor<T>(): Codec<T> {\n\tconst encoder = new TextEncoder();\n\tconst decoder = new TextDecoder();\n\treturn {\n\t\tencode(value: T): Uint8Array {\n\t\t\treturn encoder.encode(stableJsonString(value));\n\t\t},\n\t\tdecode(bytes: Uint8Array): T {\n\t\t\treturn JSON.parse(decoder.decode(bytes)) as T;\n\t\t},\n\t};\n}\n\n/** Default stable JSON codec for unknown values. */\nexport const jsonCodec: Codec<unknown> = jsonCodecFor<unknown>();\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n\tif (a.byteLength !== b.byteLength) return false;\n\tfor (let i = 0; i < a.byteLength; i += 1) {\n\t\tif (a[i] !== b[i]) return false;\n\t}\n\treturn true;\n}\n\nfunction hasUnpairedSurrogate(value: string): boolean {\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tconst code = value.charCodeAt(i);\n\t\tif (code >= 0xd800 && code <= 0xdbff) {\n\t\t\tconst next = value.charCodeAt(i + 1);\n\t\t\tif (next >= 0xdc00 && next <= 0xdfff) {\n\t\t\t\ti += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tif (code >= 0xdc00 && code <= 0xdfff) return true;\n\t}\n\treturn false;\n}\n\nfunction assertNoUnpairedSurrogates(value: unknown, seen = new Set<object>(), path = \"$\"): void {\n\tif (typeof value === \"string\") {\n\t\tif (hasUnpairedSurrogate(value)) {\n\t\t\tthrow new TypeError(`strictJsonCodec: unpaired surrogate at ${path}`);\n\t\t}\n\t\treturn;\n\t}\n\tif (value === null || typeof value !== \"object\") return;\n\tif (seen.has(value)) return;\n\tseen.add(value);\n\ttry {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (let i = 0; i < value.length; i += 1) {\n\t\t\t\tassertNoUnpairedSurrogates(value[i], seen, `${path}[${i}]`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(value as Record<string, unknown>)) {\n\t\t\tif (hasUnpairedSurrogate(key)) {\n\t\t\t\tthrow new TypeError(`strictJsonCodec: unpaired surrogate at ${path}.${key}`);\n\t\t\t}\n\t\t\tassertNoUnpairedSurrogates((value as Record<string, unknown>)[key], seen, `${path}.${key}`);\n\t\t}\n\t} finally {\n\t\tseen.delete(value);\n\t}\n}\n\nfunction assertNoDuplicateJsonObjectKeys(text: string): void {\n\tlet index = 0;\n\n\tfunction fail(message: string): never {\n\t\tthrow new TypeError(`strictJsonCodec: ${message}`);\n\t}\n\n\tfunction skipWhitespace(): void {\n\t\twhile (/\\s/.test(text[index] ?? \"\")) index += 1;\n\t}\n\n\tfunction readJsonString(): string {\n\t\tconst start = index;\n\t\tindex += 1;\n\t\twhile (index < text.length) {\n\t\t\tconst ch = text[index];\n\t\t\tif (ch === '\"') {\n\t\t\t\tindex += 1;\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(text.slice(start, index)) as string;\n\t\t\t\t} catch {\n\t\t\t\t\tfail(\"malformed JSON string\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ch === \"\\\\\") {\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tindex += 1;\n\t\t}\n\t\tfail(\"unterminated JSON string\");\n\t}\n\n\tfunction consumeLiteral(literal: string): void {\n\t\tif (text.slice(index, index + literal.length) !== literal) {\n\t\t\tfail(`malformed JSON near byte ${index}`);\n\t\t}\n\t\tindex += literal.length;\n\t}\n\n\tfunction consumeNumber(): void {\n\t\tconst match = /^-?(0|[1-9]\\d*)(\\.\\d+)?([eE][+-]?\\d+)?/.exec(text.slice(index));\n\t\tif (!match) fail(`malformed JSON number near byte ${index}`);\n\t\tindex += match[0].length;\n\t}\n\n\tfunction parseValue(path: string): void {\n\t\tskipWhitespace();\n\t\tconst ch = text[index];\n\t\tif (ch === \"{\") {\n\t\t\tparseObject(path);\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"[\") {\n\t\t\tparseArray(path);\n\t\t\treturn;\n\t\t}\n\t\tif (ch === '\"') {\n\t\t\treadJsonString();\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"t\") {\n\t\t\tconsumeLiteral(\"true\");\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"f\") {\n\t\t\tconsumeLiteral(\"false\");\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"n\") {\n\t\t\tconsumeLiteral(\"null\");\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"-\" || (ch !== undefined && ch >= \"0\" && ch <= \"9\")) {\n\t\t\tconsumeNumber();\n\t\t\treturn;\n\t\t}\n\t\tfail(`malformed JSON near byte ${index}`);\n\t}\n\n\tfunction parseObject(path: string): void {\n\t\tconst keys = new Set<string>();\n\t\tindex += 1;\n\t\tskipWhitespace();\n\t\tif (text[index] === \"}\") {\n\t\t\tindex += 1;\n\t\t\treturn;\n\t\t}\n\t\twhile (index < text.length) {\n\t\t\tskipWhitespace();\n\t\t\tif (text[index] !== '\"') fail(`expected object key near byte ${index}`);\n\t\t\tconst key = readJsonString();\n\t\t\tif (keys.has(key)) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`strictJsonCodec: duplicate object key ${JSON.stringify(key)} at ${path}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tkeys.add(key);\n\t\t\tskipWhitespace();\n\t\t\tif (text[index] !== \":\") fail(`expected ':' after object key near byte ${index}`);\n\t\t\tindex += 1;\n\t\t\tparseValue(`${path}.${key}`);\n\t\t\tskipWhitespace();\n\t\t\tif (text[index] === \",\") {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (text[index] === \"}\") {\n\t\t\t\tindex += 1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfail(`expected ',' or '}' near byte ${index}`);\n\t\t}\n\t\tfail(\"unterminated JSON object\");\n\t}\n\n\tfunction parseArray(path: string): void {\n\t\tindex += 1;\n\t\tskipWhitespace();\n\t\tif (text[index] === \"]\") {\n\t\t\tindex += 1;\n\t\t\treturn;\n\t\t}\n\t\tlet item = 0;\n\t\twhile (index < text.length) {\n\t\t\tparseValue(`${path}[${item}]`);\n\t\t\titem += 1;\n\t\t\tskipWhitespace();\n\t\t\tif (text[index] === \",\") {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (text[index] === \"]\") {\n\t\t\t\tindex += 1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfail(`expected ',' or ']' near byte ${index}`);\n\t\t}\n\t\tfail(\"unterminated JSON array\");\n\t}\n\n\tparseValue(\"$\");\n\tskipWhitespace();\n\tif (index !== text.length) fail(`trailing JSON token near byte ${index}`);\n}\n\n/**\n * Build a strict canonical JSON codec (D84/D87/D96).\n * The strict surface rejects malformed UTF-8, duplicate object keys, non-canonical bytes,\n * unpaired surrogates, and values that cannot round-trip through stable JSON.\n */\nexport function strictJsonCodecFor<T>(): Codec<T> {\n\tconst encoder = new TextEncoder();\n\tconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\treturn {\n\t\tencode(value: T): Uint8Array {\n\t\t\tassertNoUnpairedSurrogates(value);\n\t\t\treturn encoder.encode(strictStableJsonString(value));\n\t\t},\n\t\tdecode(bytes: Uint8Array): T {\n\t\t\tconst text = decoder.decode(bytes);\n\t\t\tassertNoDuplicateJsonObjectKeys(text);\n\t\t\tconst decoded = JSON.parse(text) as unknown;\n\t\t\tassertNoUnpairedSurrogates(decoded);\n\t\t\tconst canonical = encoder.encode(strictStableJsonString(decoded));\n\t\t\tif (!bytesEqual(bytes, canonical)) {\n\t\t\t\tthrow new TypeError(\"strictJsonCodec: bytes are not canonical stable JSON\");\n\t\t\t}\n\t\t\treturn decoded as T;\n\t\t},\n\t};\n}\n\n/** Default strict canonical JSON codec for unknown values. */\nexport const strictJsonCodec: Codec<unknown> = strictJsonCodecFor<unknown>();\n\n/** D113 neutral helper for strict canonical JSON UTF-8 bytes. */\nexport function strictCanonicalJsonBytes(value: unknown): Uint8Array {\n\treturn strictJsonCodec.encode(value);\n}\n\n/** Validate and normalize a host value into strict canonical JSON data. */\nexport function assertStrictJsonValue(value: unknown, label = \"strictJsonValue\"): StrictJsonValue {\n\ttry {\n\t\treturn strictJsonCodec.decode(strictJsonCodec.encode(value)) as StrictJsonValue;\n\t} catch (cause) {\n\t\tconst message = cause instanceof Error ? cause.message : String(cause);\n\t\tthrow new TypeError(`${label}: value is not strict JSON compatible: ${message}`, { cause });\n\t}\n}\n\n/** Validate and normalize a host value into a strict canonical JSON object. */\nexport function assertStrictJsonObject(\n\tvalue: unknown,\n\tlabel = \"strictJsonObject\",\n): StrictJsonObject {\n\tconst normalized = assertStrictJsonValue(value, label);\n\tif (normalized === null || typeof normalized !== \"object\" || Array.isArray(normalized)) {\n\t\tthrow new TypeError(`${label}: value must be a strict JSON object`);\n\t}\n\treturn normalized as StrictJsonObject;\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","import type { KvStorageTier } from \"./kv.js\";\nimport { memoryKv, requireKvPutIfAbsent } from \"./kv.js\";\n\nexport const APPEND_LOG_SEQ_PAD = 20;\n\n/** One append-log record with its storage key and monotonic sequence. */\nexport interface AppendLogEntry<T> {\n\treadonly key: string;\n\treadonly seq: number;\n\treadonly value: T;\n}\n\n/** Cursor and page-size options for append-log reads. */\nexport interface AppendLogReadOptions {\n\t/** Return entries with seq > after. */\n\tafter?: number;\n\tlimit?: number;\n}\n\n/** One bounded append-log page with the cursor for the next read. */\nexport interface AppendLogPage<T> {\n\treadonly entries: readonly AppendLogEntry<T>[];\n\treadonly nextAfter: number;\n\treadonly done: boolean;\n}\n\n/**\n * Append-only tier for durable event/change logs (D82), not graph restore replay.\n *\n * This first-cut helper serializes operations within one handle. Concurrent writers sharing the\n * same KV prefix need an external single-writer discipline or a future CAS-capable backend.\n */\nexport interface AppendLogStorageTier<T = unknown> {\n\tappend(value: T): Promise<AppendLogEntry<T>>;\n\tread(opts?: AppendLogReadOptions): Promise<readonly AppendLogEntry<T>[]>;\n\ttruncateAfter(seq: number): Promise<void>;\n\tsize(): Promise<number>;\n}\n\n/** D85 multi-writer append log; requires a passive conditional-create KV capability. */\nexport type MultiWriterAppendLogStorageTier<T = unknown> = AppendLogStorageTier<T>;\n\n/** Build the deterministic storage key for an append-log sequence number. */\nexport function appendLogKey(prefix: string, seq: number): string {\n\tif (!Number.isSafeInteger(seq) || seq < 0) {\n\t\tthrow new RangeError(`appendLogKey: seq must be a non-negative safe integer, got ${seq}`);\n\t}\n\treturn `${prefix}/${seq.toString().padStart(APPEND_LOG_SEQ_PAD, \"0\")}`;\n}\n\nfunction seqFromKey(prefix: string, key: string): number {\n\tconst head = `${prefix}/`;\n\tif (!key.startsWith(head)) throw new Error(`append log key outside prefix: ${key}`);\n\tconst raw = key.slice(head.length);\n\tif (!/^\\d+$/.test(raw)) {\n\t\tthrow new Error(`append log key has a non-numeric sequence: ${key}`);\n\t}\n\tif (raw.length !== APPEND_LOG_SEQ_PAD) {\n\t\tthrow new Error(`append log key sequence must be ${APPEND_LOG_SEQ_PAD} padded digits: ${key}`);\n\t}\n\tconst seq = Number(raw);\n\tif (!Number.isSafeInteger(seq)) {\n\t\tthrow new Error(`append log key sequence is outside the safe integer range: ${key}`);\n\t}\n\treturn seq;\n}\n\nfunction nextSeqFromKeys(prefix: string, keys: readonly string[]): number {\n\tif (keys.length === 0) return 0;\n\tconst next = Math.max(...keys.map((key) => seqFromKey(prefix, key))) + 1;\n\tif (!Number.isSafeInteger(next)) {\n\t\tthrow new RangeError(`append log next sequence is outside the safe integer range: ${prefix}`);\n\t}\n\treturn next;\n}\n\nfunction sizeFromKeys(prefix: string, keys: readonly string[]): number {\n\tfor (const key of keys) seqFromKey(prefix, key);\n\treturn keys.length;\n}\n\nfunction validateReadOptions(opts: AppendLogReadOptions): {\n\tafter: number;\n\tlimit: number;\n} {\n\tconst after = opts.after ?? -1;\n\tconst limit = opts.limit ?? Number.POSITIVE_INFINITY;\n\tif (!Number.isSafeInteger(after) || after < -1) {\n\t\tthrow new RangeError(\n\t\t\t`appendLogStorage.read: after must be an integer cursor >= -1, got ${after}`,\n\t\t);\n\t}\n\tif (limit !== Number.POSITIVE_INFINITY && (!Number.isSafeInteger(limit) || limit < 0)) {\n\t\tthrow new RangeError(\n\t\t\t`appendLogStorage.read: limit must be a non-negative safe integer or Infinity, got ${limit}`,\n\t\t);\n\t}\n\treturn { after, limit };\n}\n\nfunction validatePageLimit(limit: number): number {\n\tif (!Number.isSafeInteger(limit) || limit < 1) {\n\t\tthrow new RangeError(`readAppendLogPage: limit must be a positive safe integer, got ${limit}`);\n\t}\n\tif (limit >= Number.MAX_SAFE_INTEGER) {\n\t\tthrow new RangeError(\"readAppendLogPage: limit must leave room for one lookahead entry\");\n\t}\n\treturn limit;\n}\n\nfunction readAppendLogEntries<T>(\n\tkv: KvStorageTier<T>,\n\tprefix: string,\n\topts: AppendLogReadOptions,\n): Promise<readonly AppendLogEntry<T>[]> {\n\tconst { after, limit } = validateReadOptions(opts);\n\treturn kv.list(`${prefix}/`).then((listed) => {\n\t\tconst keys = listed\n\t\t\t.map((key) => ({ key, seq: seqFromKey(prefix, key) }))\n\t\t\t.filter(({ seq }) => seq > after)\n\t\t\t.sort((a, b) => a.seq - b.seq)\n\t\t\t.slice(0, limit);\n\t\treturn Promise.all(\n\t\t\tkeys.map(\n\t\t\t\t({ key, seq }): Promise<AppendLogEntry<T> | undefined> =>\n\t\t\t\t\tkv.get(key).then((value) => {\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\tthrow new Error(`append log listed key is missing: ${key}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { key, seq, value };\n\t\t\t\t\t}),\n\t\t\t),\n\t\t).then((entries) => {\n\t\t\tconst out: AppendLogEntry<T>[] = [];\n\t\t\tfor (const entry of entries) if (entry !== undefined) out.push(entry);\n\t\t\treturn out;\n\t\t});\n\t});\n}\n\n/** Read one ordered append-log page without assigning replay or restore semantics. */\nexport function readAppendLogPage<T>(\n\tlog: AppendLogStorageTier<T>,\n\topts: AppendLogReadOptions = {},\n): Promise<AppendLogPage<T>> {\n\tconst { after, limit } = validateReadOptions({ after: opts.after, limit: opts.limit ?? 100 });\n\tconst pageLimit = validatePageLimit(limit);\n\treturn log.read({ after, limit: pageLimit + 1 }).then((entries) => {\n\t\tconst visible = entries.slice(0, pageLimit);\n\t\tconst last = visible[visible.length - 1];\n\t\treturn {\n\t\t\tentries: visible,\n\t\t\tnextAfter: last?.seq ?? after,\n\t\t\tdone: entries.length <= pageLimit,\n\t\t};\n\t});\n}\n\nfunction deleteAppendLogEntriesAfter<T>(\n\tkv: KvStorageTier<T>,\n\tprefix: string,\n\tseq: number,\n): Promise<void> {\n\treturn kv\n\t\t.list(`${prefix}/`)\n\t\t.then((keys) =>\n\t\t\tPromise.all(keys.filter((key) => seqFromKey(prefix, key) > seq).map((key) => kv.delete(key))),\n\t\t)\n\t\t.then(() => kv.list(`${prefix}/`))\n\t\t.then(() => undefined);\n}\n\n/** Options for a typed append log over a KV tier. */\nexport interface AppendLogOptions<T> {\n\tkv: KvStorageTier<T>;\n\tprefix?: string;\n}\n\n/** Options for D85 multi-writer append logs over conditional-create capable KV. */\nexport interface MultiWriterAppendLogOptions<T> extends AppendLogOptions<T> {\n\t/** Bound retry work before refreshing the listed tail after another writer wins slots. */\n\tmaxAttempts?: number;\n}\n\n/**\n * Build a single-writer append-only log over a KV tier, serializing all operations in call order\n * for this handle. D85 multi-handle concurrent appends require multiWriterAppendLogStorage.\n */\nexport function appendLogStorage<T = unknown>(opts: AppendLogOptions<T>): AppendLogStorageTier<T> {\n\tconst { kv, prefix = \"event-log\" } = opts;\n\tlet tail: Promise<unknown> = Promise.resolve();\n\n\tfunction initNextSeq(): Promise<number> {\n\t\treturn kv.list(`${prefix}/`).then((keys) => {\n\t\t\treturn nextSeqFromKeys(prefix, keys);\n\t\t});\n\t}\n\n\tfunction enqueue<R>(task: () => Promise<R>): Promise<R> {\n\t\tconst run = tail.then(task, task);\n\t\ttail = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\treturn {\n\t\tappend(value) {\n\t\t\treturn enqueue(() =>\n\t\t\t\tinitNextSeq().then((seq) => {\n\t\t\t\t\tconst key = appendLogKey(prefix, seq);\n\t\t\t\t\treturn kv.set(key, value).then(() => {\n\t\t\t\t\t\treturn { key, seq, value };\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tread(opts = {}) {\n\t\t\treturn enqueue(() => readAppendLogEntries(kv, prefix, opts));\n\t\t},\n\t\ttruncateAfter(seq) {\n\t\t\treturn enqueue(() => deleteAppendLogEntriesAfter(kv, prefix, seq));\n\t\t},\n\t\tsize() {\n\t\t\treturn enqueue(() => kv.list(`${prefix}/`).then((keys) => sizeFromKeys(prefix, keys)));\n\t\t},\n\t};\n}\n\n/**\n * Build a D85 multi-writer append log over a conditional-create capable KV tier.\n *\n * Sequence allocation is passive storage work: each writer proposes a padded key and retries the\n * next key when another writer already created that slot. This does not provide general CAS,\n * locks, leases, transactions, unsafe truncation, WAL replay, or graph restore semantics.\n */\nexport function multiWriterAppendLogStorage<T = unknown>(\n\topts: MultiWriterAppendLogOptions<T>,\n): MultiWriterAppendLogStorageTier<T> {\n\tconst { kv, prefix = \"event-log\", maxAttempts = 1024 } = opts;\n\tconst capableKv = requireKvPutIfAbsent(kv, \"multiWriterAppendLogStorage\");\n\tlet tail: Promise<unknown> = Promise.resolve();\n\n\tif (!Number.isSafeInteger(maxAttempts) || maxAttempts < 1) {\n\t\tthrow new RangeError(\n\t\t\t`multiWriterAppendLogStorage: maxAttempts must be a positive safe integer, got ${maxAttempts}`,\n\t\t);\n\t}\n\n\tfunction initNextSeq(): Promise<number> {\n\t\treturn kv.list(`${prefix}/`).then((keys) => nextSeqFromKeys(prefix, keys));\n\t}\n\n\tfunction enqueue<R>(task: () => Promise<R>): Promise<R> {\n\t\tconst run = tail.then(task, task);\n\t\ttail = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\treturn {\n\t\tappend(value) {\n\t\t\treturn enqueue(() =>\n\t\t\t\tinitNextSeq().then((startSeq) => {\n\t\t\t\t\tlet seq = startSeq;\n\t\t\t\t\tlet attempt = 0;\n\t\t\t\t\tconst tryNext = (): Promise<AppendLogEntry<T>> => {\n\t\t\t\t\t\tif (attempt >= maxAttempts) {\n\t\t\t\t\t\t\treturn initNextSeq().then((refreshedSeq) => {\n\t\t\t\t\t\t\t\tseq = Math.max(seq, refreshedSeq);\n\t\t\t\t\t\t\t\tattempt = 0;\n\t\t\t\t\t\t\t\treturn tryNext();\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tattempt += 1;\n\t\t\t\t\t\tconst key = appendLogKey(prefix, seq);\n\t\t\t\t\t\treturn capableKv.putIfAbsent(key, value).then((created) => {\n\t\t\t\t\t\t\tif (created) return { key, seq, value };\n\t\t\t\t\t\t\tseq += 1;\n\t\t\t\t\t\t\tif (!Number.isSafeInteger(seq)) {\n\t\t\t\t\t\t\t\tthrow new RangeError(\n\t\t\t\t\t\t\t\t\t`append log next sequence is outside the safe integer range: ${prefix}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn tryNext();\n\t\t\t\t\t\t});\n\t\t\t\t\t};\n\t\t\t\t\treturn tryNext();\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tread(opts = {}) {\n\t\t\treturn enqueue(() => readAppendLogEntries(kv, prefix, opts));\n\t\t},\n\t\ttruncateAfter(seq) {\n\t\t\treturn enqueue(() => {\n\t\t\t\tif (!Number.isSafeInteger(seq) || seq < -1) {\n\t\t\t\t\tthrow new RangeError(\n\t\t\t\t\t\t`multiWriterAppendLogStorage.truncateAfter: seq must be an integer cursor >= -1, got ${seq}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"multiWriterAppendLogStorage.truncateAfter: unsupported without a stronger compaction capability\",\n\t\t\t\t);\n\t\t\t});\n\t\t},\n\t\tsize() {\n\t\t\treturn enqueue(() => kv.list(`${prefix}/`).then((keys) => sizeFromKeys(prefix, keys)));\n\t\t},\n\t};\n}\n\n/** Create an in-memory append log. */\nexport function memoryAppendLog<T = unknown>(prefix?: string): AppendLogStorageTier<T> {\n\treturn appendLogStorage({ kv: memoryKv<T>(), prefix });\n}\n\n/** Create an in-memory D85 multi-writer append log. */\nexport function memoryMultiWriterAppendLog<T = unknown>(\n\tprefix?: string,\n): MultiWriterAppendLogStorageTier<T> {\n\treturn multiWriterAppendLogStorage({ kv: memoryKv<T>(), prefix });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,yBAA4B;AAC5B,qBASO;AACP,yBAA8B;AAC9B,uBAAwC;;;ACdxC,IAAM,YAAY,MAAM,KAAK,EAAE,QAAQ,IAAI,GAAG,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC;AA0GhF,SAAS,sBACf,SACuC;AACvC,SAAO,OAAO,QAAQ,gBAAgB;AACvC;AAcO,SAAS,oBAAoB,SAA6D;AAChG,SAAO,OAAO,QAAQ,iBAAiB,cAAc,OAAO,QAAQ,eAAe;AACpF;;;AC5GA,IAAM,uBAAuB,KAAK;AAElC,SAAS,uBAAuB,OAAe,MAAoB;AAClE,MAAI,CAAC,OAAO,SAAS,KAAK,GAAG;AAC5B,UAAM,IAAI,UAAU,0CAA0C,IAAI,EAAE;AAAA,EACrE;AACD;AAEA,SAAS,uBAAuB,OAAe,MAAoB;AAClE,yBAAuB,OAAO,IAAI;AAClC,MAAI,OAAO,GAAG,OAAO,EAAE,GAAG;AACzB,UAAM,IAAI,UAAU,6CAA6C,IAAI,EAAE;AAAA,EACxE;AACA,QAAM,MAAM,KAAK,IAAI,KAAK;AAC1B,MAAI,MAAM,KAAK,MAAM,sBAAsB;AAC1C,UAAM,IAAI,UAAU,yCAAyC,IAAI,EAAE;AAAA,EACpE;AACA,MAAI,OAAO,UAAU,KAAK,KAAK,CAAC,OAAO,cAAc,KAAK,GAAG;AAC5D,UAAM,IAAI,UAAU,mDAAmD,IAAI,EAAE;AAAA,EAC9E;AAC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AgB,CAAC;AACvB,iBAAW,OAAO,MAAM;AACvB,cAAM,MAAM,WAAW,IAAI,CAAC;AAC5B,YAAI,KAAK,WAAW,eAAe,EAAG,KAAI,KAAK,GAAG;AAAA,MACnD;AACA,aAAO,IAAI,KAAK;AAAA,IACjB;AAAA,IACA,QAAQ;AACP,SAAG,MAAM;AAAA,IACV;AAAA,EACD;AACD;AAKO,SAAS,SACf,MACA,OAA2B,CAAC,GACW;AACvC,QAAM,UAAU,cAAc,MAAM,IAAI;AACxC,QAAM,OAAO,UAAa;AAAA,IACzB;AAAA,IACA,OAAO,KAAK;AAAA,EACb,CAAC;AACD,SAAO,OAAO,OAAO,MAAM,EAAE,OAAO,MAAM,QAAQ,MAAM,EAAE,CAAC;AAC5D;AAKO,SAAS,gBACf,MACA,OAAkC,CAAC,GACW;AAC9C,QAAM,KAAK,SAAY,MAAM,IAAI;AACjC,QAAM,MAAM,iBAAoB,EAAE,IAAI,QAAQ,KAAK,UAAU,YAAY,CAAC;AAC1E,SAAO,OAAO,OAAO,KAAK,EAAE,OAAO,MAAM,GAAG,MAAM,EAAE,CAAC;AACtD;","names":["out","encoder","decoder","opts","require"]}
|
|
1
|
+
{"version":3,"sources":["../../src/storage/node.ts","../../src/storage/backend.ts","../../src/json/codec.ts","../../src/storage/kv.ts","../../src/storage/append-log.ts"],"sourcesContent":["/**\n * Node-only passive storage backends (D103).\n *\n * Import from `@graphrefly/ts/storage/node`; the universal storage barrel stays browser-safe.\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport {\n\tcloseSync,\n\tmkdirSync,\n\topenSync,\n\treaddirSync,\n\treadFileSync,\n\trenameSync,\n\tunlinkSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { basename, dirname, join } from \"node:path\";\nimport { type AppendLogStorageTier, appendLogStorage } from \"./append-log.js\";\nimport type { StorageBackend, StorageGeneration, StorageNamespaceOptions } from \"./backend.js\";\nimport type { Codec } from \"./codec.js\";\nimport { type KvStorageTier, kvStorage } from \"./kv.js\";\n\nexport interface FileBackendOptions extends StorageNamespaceOptions {\n\t/** File suffix used for stored byte blobs. Defaults to `.bin`. */\n\textension?: string;\n}\n\nexport interface FileKvOptions<T> extends FileBackendOptions {\n\tcodec?: Codec<T>;\n}\n\nexport interface FileAppendLogOptions<T> extends FileKvOptions<T> {\n\t/** Append-log key prefix. Defaults to `event-log`. */\n\tprefix?: string;\n}\n\nexport interface SqliteBackendOptions extends StorageNamespaceOptions {\n\t/** Table name used for passive byte storage. Defaults to `graphrefly_storage`. */\n\ttableName?: string;\n}\n\nexport interface SqliteKvOptions<T> extends SqliteBackendOptions {\n\tcodec?: Codec<T>;\n}\n\nexport interface SqliteAppendLogOptions<T> extends SqliteKvOptions<T> {\n\t/** Append-log key prefix. Defaults to `event-log`. */\n\tprefix?: string;\n}\n\nexport interface ClosableStorageBackend extends StorageBackend {\n\treadonly name: string;\n\tclose(): void;\n}\n\ntype SqliteDatabaseConstructor = new (path: string) => SqliteDatabase;\n\ninterface SqliteDatabase {\n\texec(sql: string): void;\n\tprepare(sql: string): SqliteStatement;\n\tclose(): void;\n}\n\ninterface SqliteStatement {\n\tget(...params: unknown[]): unknown;\n\trun(...params: unknown[]): unknown;\n\tall(...params: unknown[]): unknown[];\n}\n\nconst FILE_STEM_PREFIX = \"k-\";\nconst NAMESPACE_SEPARATOR = \"\\u0000\";\nconst SQLITE_GENERATION = Symbol(\"graphrefly.sqliteBackend.generation\");\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\nconst require = createRequire(\"/graphrefly-storage-node.js\");\n\ninterface SqliteGeneration {\n\treadonly [SQLITE_GENERATION]: readonly [\n\t\tstorageId: object,\n\t\tkey: string,\n\t\trowGeneration: number | null,\n\t\tepoch: number,\n\t];\n}\n\nfunction isErrno(error: unknown, code: string): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"code\" in error &&\n\t\t(error as { code?: unknown }).code === code\n\t);\n}\n\nfunction keyToStem(key: string): string {\n\tlet out = \"\";\n\tfor (const ch of key) {\n\t\tif (/^[a-zA-Z0-9_-]$/.test(ch)) {\n\t\t\tout += ch;\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const byte of encoder.encode(ch)) out += `%${byte.toString(16).padStart(2, \"0\")}`;\n\t}\n\treturn out;\n}\n\nfunction stemToKey(stem: string): string | null {\n\tconst bytes: number[] = [];\n\tlet i = 0;\n\twhile (i < stem.length) {\n\t\tconst ch = stem[i]!;\n\t\tif (ch === \"%\" && i + 2 < stem.length) {\n\t\t\tconst hex = stem.slice(i + 1, i + 3);\n\t\t\tif (/^[0-9a-f]{2}$/i.test(hex)) {\n\t\t\t\tbytes.push(Number.parseInt(hex, 16));\n\t\t\t\ti += 3;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tconst code = ch.charCodeAt(0);\n\t\tif (code > 0x7f) return null;\n\t\tbytes.push(code);\n\t\ti += 1;\n\t}\n\ttry {\n\t\treturn decoder.decode(new Uint8Array(bytes));\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction validateExtension(extension: string): string {\n\tif (\n\t\textension.length < 2 ||\n\t\t!extension.startsWith(\".\") ||\n\t\textension.includes(\"..\") ||\n\t\t/[/\\\\\\0]/.test(extension) ||\n\t\t!/^[.A-Za-z0-9_-]+$/.test(extension)\n\t) {\n\t\tthrow new TypeError(\"fileBackend: extension must be a simple suffix such as .bin\");\n\t}\n\treturn extension;\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\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 validateSqliteTableName(tableName: string): string {\n\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName)) {\n\t\tthrow new TypeError(\"sqliteBackend: tableName must be a simple SQLite identifier\");\n\t}\n\treturn tableName;\n}\n\nfunction sqliteGeneration(\n\tstorageId: object,\n\tkey: string,\n\trowGeneration: number | null,\n\tepoch: number,\n): SqliteGeneration {\n\treturn Object.freeze({\n\t\t[SQLITE_GENERATION]: Object.freeze([storageId, key, rowGeneration, epoch] as const),\n\t});\n}\n\nfunction readSqliteGeneration(\n\tgeneration: StorageGeneration,\n):\n\t| readonly [storageId: object, key: string, rowGeneration: number | null, epoch: number]\n\t| undefined {\n\tif (typeof generation !== \"object\" || generation === null) return undefined;\n\tconst maybe = generation as Partial<SqliteGeneration>;\n\tconst token = maybe[SQLITE_GENERATION];\n\tif (\n\t\tArray.isArray(token) &&\n\t\ttoken.length === 4 &&\n\t\ttypeof token[0] === \"object\" &&\n\t\ttoken[0] !== null &&\n\t\ttypeof token[1] === \"string\" &&\n\t\t(token[2] === null || typeof token[2] === \"number\") &&\n\t\ttypeof token[3] === \"number\"\n\t) {\n\t\treturn token as readonly [object, string, number | null, number];\n\t}\n\treturn undefined;\n}\n\nfunction sqliteChanges(result: unknown): number {\n\treturn typeof result === \"object\" &&\n\t\tresult !== null &&\n\t\t\"changes\" in result &&\n\t\ttypeof (result as { changes?: unknown }).changes === \"number\"\n\t\t? (result as { changes: number }).changes\n\t\t: 0;\n}\n\nfunction sqliteBytes(value: Uint8Array | ArrayBuffer): Uint8Array {\n\treturn Uint8Array.from(value instanceof Uint8Array ? value : new Uint8Array(value));\n}\n\nfunction loadSqliteDatabaseSync(): SqliteDatabaseConstructor {\n\ttry {\n\t\tconst DatabaseSync = (require(\"node:sqlite\") as { DatabaseSync?: unknown }).DatabaseSync;\n\t\tif (typeof DatabaseSync !== \"function\") {\n\t\t\tthrow new TypeError(\"DatabaseSync export is missing\");\n\t\t}\n\t\treturn DatabaseSync as SqliteDatabaseConstructor;\n\t} catch (error) {\n\t\tthrow new Error(\"sqliteBackend: node:sqlite is not available in this Node runtime\", {\n\t\t\tcause: error,\n\t\t});\n\t}\n}\n\n/** Node filesystem byte backend with atomic replace writes and D85 conditional create. */\nexport function fileBackend(dir: string, opts: FileBackendOptions = {}): StorageBackend {\n\tconst extension = validateExtension(opts.extension ?? \".bin\");\n\tconst namespace =\n\t\topts.namespace === undefined ? \"\" : validateNamespace(\"fileBackend\", opts.namespace);\n\tconst namespacePrefix = namespace.length > 0 ? `${namespace}${NAMESPACE_SEPARATOR}` : \"\";\n\tconst storageKey = (key: string) => `${namespacePrefix}${validateLogicalKey(\"fileBackend\", key)}`;\n\tconst pathFor = (key: string) =>\n\t\tjoin(dir, `${FILE_STEM_PREFIX}${keyToStem(storageKey(key))}${extension}`);\n\tconst keyFromFilename = (filename: string): string | null => {\n\t\tif (!filename.endsWith(extension)) return null;\n\t\tconst stem = filename.slice(0, -extension.length);\n\t\tif (!stem.startsWith(FILE_STEM_PREFIX)) return null;\n\t\tconst key = stemToKey(stem.slice(FILE_STEM_PREFIX.length));\n\t\tif (key === null || !key.startsWith(namespacePrefix)) return null;\n\t\tconst logical = key.slice(namespacePrefix.length);\n\t\tif (logical.includes(NAMESPACE_SEPARATOR)) {\n\t\t\tthrow new TypeError(\"fileBackend: malformed stored key\");\n\t\t}\n\t\treturn logical;\n\t};\n\n\treturn {\n\t\tget(key) {\n\t\t\ttry {\n\t\t\t\treturn Uint8Array.from(readFileSync(pathFor(key)));\n\t\t\t} catch (error) {\n\t\t\t\tif (isErrno(error, \"ENOENT\")) return undefined;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tput(key, value) {\n\t\t\tmkdirSync(dir, { recursive: true });\n\t\t\tconst filePath = pathFor(key);\n\t\t\tconst base = basename(filePath);\n\t\t\tconst parent = dirname(filePath);\n\t\t\tconst tmp = join(parent, `.${base}.${randomBytes(8).toString(\"hex\")}.tmp`);\n\t\t\ttry {\n\t\t\t\twriteFileSync(tmp, value);\n\t\t\t\trenameSync(tmp, filePath);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tunlinkSync(tmp);\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore cleanup failures; the original write error is the useful one.\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tputIfAbsent(key, value) {\n\t\t\tmkdirSync(dir, { recursive: true });\n\t\t\tconst filePath = pathFor(key);\n\t\t\tlet fd: number | undefined;\n\t\t\ttry {\n\t\t\t\tfd = openSync(filePath, \"wx\");\n\t\t\t\twriteFileSync(fd, value);\n\t\t\t\treturn true;\n\t\t\t} catch (error) {\n\t\t\t\tif (isErrno(error, \"EEXIST\")) return false;\n\t\t\t\tif (fd !== undefined) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tunlinkSync(filePath);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Best effort cleanup of a partially-created file.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\tif (fd !== undefined) closeSync(fd);\n\t\t\t}\n\t\t},\n\t\tdelete(key) {\n\t\t\ttry {\n\t\t\t\tunlinkSync(pathFor(key));\n\t\t\t} catch (error) {\n\t\t\t\tif (!isErrno(error, \"ENOENT\")) throw error;\n\t\t\t}\n\t\t},\n\t\tlist(prefix = \"\") {\n\t\t\tconst validatedPrefix = validateListPrefix(\"fileBackend\", prefix);\n\t\t\tlet entries: string[];\n\t\t\ttry {\n\t\t\t\tentries = readdirSync(dir);\n\t\t\t} catch (error) {\n\t\t\t\tif (isErrno(error, \"ENOENT\")) return [];\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst keys: string[] = [];\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (entry.startsWith(\".\")) continue;\n\t\t\t\tconst key = keyFromFilename(entry);\n\t\t\t\tif (key?.startsWith(validatedPrefix)) keys.push(key);\n\t\t\t}\n\t\t\treturn keys.sort();\n\t\t},\n\t};\n}\n\n/**\n * Create a typed KV tier over a Node filesystem backend (D106 passive storage).\n */\nexport function fileKv<T>(dir: string, opts: FileKvOptions<T> = {}): KvStorageTier<T> {\n\treturn kvStorage<T>({\n\t\tbackend: fileBackend(dir, opts),\n\t\tcodec: opts.codec,\n\t});\n}\n\n/**\n * Create an append-log tier over a Node filesystem backend (D106 passive storage).\n */\nexport function fileAppendLog<T>(\n\tdir: string,\n\topts: FileAppendLogOptions<T> = {},\n): AppendLogStorageTier<T> {\n\treturn appendLogStorage<T>({\n\t\tkv: fileKv<T>(dir, opts),\n\t\tprefix: opts.prefix ?? \"event-log\",\n\t});\n}\n\n/**\n * Optional Node SQLite byte backend (D106 passive storage).\n *\n * Uses `node:sqlite` when the current Node runtime provides it; otherwise throws a clear\n * runtime error at construction time. The caller owns `close()`.\n */\nexport function sqliteBackend(\n\tpath: string,\n\topts: SqliteBackendOptions = {},\n): ClosableStorageBackend {\n\tconst table = validateSqliteTableName(opts.tableName ?? \"graphrefly_storage\");\n\tconst metaTable = validateSqliteTableName(`${table}_meta`);\n\tconst namespace =\n\t\topts.namespace === undefined ? \"\" : validateNamespace(\"sqliteBackend\", opts.namespace);\n\tconst DatabaseSync = loadSqliteDatabaseSync();\n\tconst namespacePrefix = namespace.length > 0 ? `${namespace}${NAMESPACE_SEPARATOR}` : \"\";\n\tconst storageKey = (key: string) =>\n\t\t`${namespacePrefix}${validateLogicalKey(\"sqliteBackend\", key)}`;\n\tconst storageId = Object.freeze({});\n\tconst logicalKey = (key: string): string | undefined => {\n\t\tif (typeof key !== \"string\") {\n\t\t\tthrow new TypeError(\"sqliteBackend: stored key is corrupt\");\n\t\t}\n\t\tif (!key.startsWith(namespacePrefix)) return undefined;\n\t\tconst logical = key.slice(namespacePrefix.length);\n\t\tif (logical.includes(NAMESPACE_SEPARATOR)) {\n\t\t\tthrow new TypeError(\"sqliteBackend: malformed stored key\");\n\t\t}\n\t\treturn logical;\n\t};\n\tconst db = new DatabaseSync(path);\n\tdb.exec(\n\t\t`CREATE TABLE IF NOT EXISTS ${table} (k TEXT PRIMARY KEY, v BLOB NOT NULL, g INTEGER NOT NULL DEFAULT 0)`,\n\t);\n\tconst columns = db.prepare(`PRAGMA table_info(${table})`).all() as Array<{ name?: string }>;\n\tif (!columns.some((column) => column.name === \"g\")) {\n\t\tdb.exec(`ALTER TABLE ${table} ADD COLUMN g INTEGER NOT NULL DEFAULT 0`);\n\t}\n\tdb.exec(`CREATE TABLE IF NOT EXISTS ${metaTable} (k TEXT PRIMARY KEY, v INTEGER NOT NULL)`);\n\tdb.exec(`\n\t\tCREATE TRIGGER IF NOT EXISTS ${table}_generation_insert\n\t\tAFTER INSERT ON ${table}\n\t\tBEGIN\n\t\t\tINSERT INTO ${metaTable} (k, v) VALUES (NEW.k, 1)\n\t\t\tON CONFLICT(k) DO UPDATE SET v = ${metaTable}.v + 1;\n\t\tEND\n\t`);\n\tdb.exec(`\n\t\tCREATE TRIGGER IF NOT EXISTS ${table}_generation_update\n\t\tAFTER UPDATE ON ${table}\n\t\tBEGIN\n\t\t\tINSERT INTO ${metaTable} (k, v) VALUES (NEW.k, 1)\n\t\t\tON CONFLICT(k) DO UPDATE SET v = ${metaTable}.v + 1;\n\t\tEND\n\t`);\n\tdb.exec(`\n\t\tCREATE TRIGGER IF NOT EXISTS ${table}_generation_delete\n\t\tAFTER DELETE ON ${table}\n\t\tBEGIN\n\t\t\tINSERT INTO ${metaTable} (k, v) VALUES (OLD.k, 1)\n\t\t\tON CONFLICT(k) DO UPDATE SET v = ${metaTable}.v + 1;\n\t\tEND\n\t`);\n\n\tconst keyEpoch = (key: string): number => {\n\t\tconst row = db.prepare(`SELECT v FROM ${metaTable} WHERE k = ?`).get(key) as\n\t\t\t| { v?: number }\n\t\t\t| undefined;\n\t\tconst value = row?.v ?? 0;\n\t\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) {\n\t\t\tthrow new Error(\"sqliteBackend: per-key generation epoch is corrupt\");\n\t\t}\n\t\treturn value;\n\t};\n\tconst readRow = (\n\t\tkey: string,\n\t):\n\t\t| {\n\t\t\t\treadonly value: Uint8Array;\n\t\t\t\treadonly generation: number;\n\t\t }\n\t\t| undefined => {\n\t\tconst row = db.prepare(`SELECT v, g FROM ${table} WHERE k = ?`).get(storageKey(key)) as\n\t\t\t| { v?: Uint8Array | ArrayBuffer; g?: number }\n\t\t\t| undefined;\n\t\tif (row?.v === undefined) return undefined;\n\t\tconst generation = row.g;\n\t\tif (typeof generation !== \"number\" || !Number.isSafeInteger(generation) || generation < 0) {\n\t\t\tthrow new Error(\"sqliteBackend: row generation is corrupt\");\n\t\t}\n\t\treturn { value: sqliteBytes(row.v), generation };\n\t};\n\n\treturn {\n\t\tname: `sqlite:${path}/${table}`,\n\t\tget(key) {\n\t\t\treturn readRow(key)?.value;\n\t\t},\n\t\tput(key, value) {\n\t\t\tdb.prepare(\n\t\t\t\t`INSERT INTO ${table} (k, v, g) VALUES (?, ?, 0) ON CONFLICT(k) DO UPDATE SET v = excluded.v, g = ${table}.g + 1`,\n\t\t\t).run(storageKey(key), value);\n\t\t},\n\t\tputIfAbsent(key, value) {\n\t\t\tconst result = db\n\t\t\t\t.prepare(`INSERT OR IGNORE INTO ${table} (k, v, g) VALUES (?, ?, 0)`)\n\t\t\t\t.run(storageKey(key), value) as { changes?: number };\n\t\t\treturn sqliteChanges(result) === 1;\n\t\t},\n\t\tgetVersioned(key) {\n\t\t\tconst row = readRow(key);\n\t\t\tif (row === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"miss\",\n\t\t\t\t\tgeneration: sqliteGeneration(storageId, storageKey(key), null, keyEpoch(storageKey(key))),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"hit\",\n\t\t\t\tvalue: row.value,\n\t\t\t\tgeneration: sqliteGeneration(\n\t\t\t\t\tstorageId,\n\t\t\t\t\tstorageKey(key),\n\t\t\t\t\trow.generation,\n\t\t\t\t\tkeyEpoch(storageKey(key)),\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\tsetIfMatch(key, value, generation) {\n\t\t\tconst keyForStorage = storageKey(key);\n\t\t\tconst observed = readSqliteGeneration(generation);\n\t\t\tif (observed === undefined || observed[0] !== storageId || observed[1] !== keyForStorage) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (observed[2] === null) {\n\t\t\t\treturn (\n\t\t\t\t\tsqliteChanges(\n\t\t\t\t\t\tdb\n\t\t\t\t\t\t\t.prepare(\n\t\t\t\t\t\t\t\t`INSERT INTO ${table} (k, v, g) SELECT ?, ?, 0 WHERE COALESCE((SELECT v FROM ${metaTable} WHERE k = ?), 0) = ? AND NOT EXISTS (SELECT 1 FROM ${table} WHERE k = ?)`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.run(keyForStorage, value, keyForStorage, observed[3], keyForStorage),\n\t\t\t\t\t) === 1\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn (\n\t\t\t\tsqliteChanges(\n\t\t\t\t\tdb\n\t\t\t\t\t\t.prepare(\n\t\t\t\t\t\t\t`UPDATE ${table} SET v = ?, g = g + 1 WHERE k = ? AND g = ? AND COALESCE((SELECT v FROM ${metaTable} WHERE k = ?), 0) = ?`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.run(value, keyForStorage, observed[2], keyForStorage, observed[3]),\n\t\t\t\t) === 1\n\t\t\t);\n\t\t},\n\t\tdelete(key) {\n\t\t\tdb.prepare(`DELETE FROM ${table} WHERE k = ?`).run(storageKey(key));\n\t\t},\n\t\tlist(prefix = \"\") {\n\t\t\tconst validatedPrefix = validateListPrefix(\"sqliteBackend\", prefix);\n\t\t\tconst rows = db.prepare(`SELECT k FROM ${table} ORDER BY k`).all() as { k: string }[];\n\t\t\tconst out: string[] = [];\n\t\t\tfor (const row of rows) {\n\t\t\t\tconst key = logicalKey(row.k);\n\t\t\t\tif (key?.startsWith(validatedPrefix)) out.push(key);\n\t\t\t}\n\t\t\treturn out.sort();\n\t\t},\n\t\tclose() {\n\t\t\tdb.close();\n\t\t},\n\t};\n}\n\n/**\n * Create a typed KV tier over an optional Node SQLite backend.\n */\nexport function sqliteKv<T>(\n\tpath: string,\n\topts: SqliteKvOptions<T> = {},\n): KvStorageTier<T> & { close(): void } {\n\tconst backend = sqliteBackend(path, opts);\n\tconst tier = kvStorage<T>({\n\t\tbackend,\n\t\tcodec: opts.codec,\n\t});\n\treturn Object.assign(tier, { close: () => backend.close() });\n}\n\n/**\n * Create an append-log tier over an optional Node SQLite backend.\n */\nexport function sqliteAppendLog<T>(\n\tpath: string,\n\topts: SqliteAppendLogOptions<T> = {},\n): AppendLogStorageTier<T> & { close(): void } {\n\tconst kv = sqliteKv<T>(path, opts);\n\tconst log = appendLogStorage<T>({ kv, prefix: opts.prefix ?? \"event-log\" });\n\treturn Object.assign(log, { close: () => kv.close() });\n}\n","/**\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","/**\n * Neutral JSON/encoding utilities (D96).\n *\n * Shared by graph checkpoints and storage bindings; neither layer owns the strict JSON\n * scanner/canonicalization contract.\n */\n\n/** Typed byte codec for D82 storage binding helpers and D96 shared JSON surfaces. */\nexport interface Codec<T> {\n\tencode(value: T): Uint8Array;\n\tdecode(bytes: Uint8Array): T;\n}\n\nexport type StrictJsonScalar = null | boolean | number | string;\nexport type StrictJsonValue =\n\t| StrictJsonScalar\n\t| readonly StrictJsonValue[]\n\t| { readonly [key: string]: StrictJsonValue };\nexport type StrictJsonObject = Readonly<Record<string, StrictJsonValue>>;\n\ntype JsonValue = StrictJsonValue;\n\nconst JS_MIN_NORMAL_NUMBER = 2 ** -1022;\n\nfunction assertStableJsonNumber(value: number, path: string): void {\n\tif (!Number.isFinite(value)) {\n\t\tthrow new TypeError(`stableJsonString: non-finite number at ${path}`);\n\t}\n}\n\nfunction assertStrictJsonNumber(value: number, path: string): void {\n\tassertStableJsonNumber(value, path);\n\tif (Object.is(value, -0)) {\n\t\tthrow new TypeError(`stableJsonString: non-canonical number at ${path}`);\n\t}\n\tconst abs = Math.abs(value);\n\tif (abs > 0 && abs < JS_MIN_NORMAL_NUMBER) {\n\t\tthrow new TypeError(`stableJsonString: subnormal number at ${path}`);\n\t}\n\tif (Number.isInteger(value) && !Number.isSafeInteger(value)) {\n\t\tthrow new TypeError(`stableJsonString: integer outside safe range at ${path}`);\n\t}\n}\n\nfunction sortedJsonValue(\n\tvalue: unknown,\n\tseen = new Set<object>(),\n\tpath = \"$\",\n\tstrictNumbers = false,\n): JsonValue {\n\tif (value === null) return null;\n\tif (typeof value === \"string\" || typeof value === \"boolean\") return value;\n\tif (typeof value === \"number\") {\n\t\tif (strictNumbers) assertStrictJsonNumber(value, path);\n\t\telse assertStableJsonNumber(value, path);\n\t\treturn value;\n\t}\n\tif (typeof value !== \"object\") {\n\t\tthrow new TypeError(`stableJsonString: value at ${path} is not JSON-encodable`);\n\t}\n\tif (seen.has(value)) throw new TypeError(`stableJsonString: circular reference at ${path}`);\n\tconst proto = Object.getPrototypeOf(value);\n\tif (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {\n\t\tthrow new TypeError(`stableJsonString: non-plain object at ${path}`);\n\t}\n\tseen.add(value);\n\ttry {\n\t\tif (Array.isArray(value)) {\n\t\t\tif (Object.getOwnPropertySymbols(value).length > 0) {\n\t\t\t\tthrow new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);\n\t\t\t}\n\t\t\tfor (const key of Object.getOwnPropertyNames(value)) {\n\t\t\t\tconst isIndex =\n\t\t\t\t\t/^(0|[1-9]\\d*)$/.test(key) &&\n\t\t\t\t\tNumber.isSafeInteger(Number(key)) &&\n\t\t\t\t\tNumber(key) < value.length;\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\t\tif (descriptor !== undefined && (\"get\" in descriptor || \"set\" in descriptor)) {\n\t\t\t\t\tthrow new TypeError(`stableJsonString: accessor property at ${path}.${key}`);\n\t\t\t\t}\n\t\t\t\tif (key !== \"length\" && !isIndex) {\n\t\t\t\t\tthrow new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);\n\t\t\t\t}\n\t\t\t\tif (key !== \"length\" && descriptor !== undefined && !descriptor.enumerable) {\n\t\t\t\t\tthrow new TypeError(`stableJsonString: non-enumerable array property at ${path}.${key}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst out: JsonValue[] = [];\n\t\t\tfor (let i = 0; i < value.length; i += 1) {\n\t\t\t\tif (!(i in value)) {\n\t\t\t\t\tthrow new TypeError(`stableJsonString: sparse array hole at ${path}[${i}]`);\n\t\t\t\t}\n\t\t\t\tout.push(sortedJsonValue(value[i], seen, `${path}[${i}]`, strictNumbers));\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tif (Object.getOwnPropertySymbols(value).length > 0) {\n\t\t\tthrow new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);\n\t\t}\n\t\tfor (const key of Object.getOwnPropertyNames(value)) {\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key);\n\t\t\tif (descriptor !== undefined && (\"get\" in descriptor || \"set\" in descriptor)) {\n\t\t\t\tthrow new TypeError(`stableJsonString: accessor property at ${path}.${key}`);\n\t\t\t}\n\t\t\tif (descriptor !== undefined && !descriptor.enumerable) {\n\t\t\t\tthrow new TypeError(`stableJsonString: non-enumerable property at ${path}.${key}`);\n\t\t\t}\n\t\t}\n\t\tconst out: Record<string, JsonValue> = Object.create(null);\n\t\tfor (const key of Object.keys(value as Record<string, unknown>).sort()) {\n\t\t\tout[key] = sortedJsonValue(\n\t\t\t\t(value as Record<string, unknown>)[key],\n\t\t\t\tseen,\n\t\t\t\t`${path}.${key}`,\n\t\t\t\tstrictNumbers,\n\t\t\t);\n\t\t}\n\t\treturn out;\n\t} finally {\n\t\tseen.delete(value);\n\t}\n}\n\n/** Stable JSON string: object keys sort by code-unit order for deterministic storage/checkpoint bytes. */\nexport function stableJsonString(value: unknown): string {\n\treturn JSON.stringify(sortedJsonValue(value));\n}\n\nfunction strictStableJsonString(value: unknown): string {\n\treturn JSON.stringify(sortedJsonValue(value, new Set<object>(), \"$\", true));\n}\n\n/** Build a JSON codec using stable object-key ordering. */\nexport function jsonCodecFor<T>(): Codec<T> {\n\tconst encoder = new TextEncoder();\n\tconst decoder = new TextDecoder();\n\treturn {\n\t\tencode(value: T): Uint8Array {\n\t\t\treturn encoder.encode(stableJsonString(value));\n\t\t},\n\t\tdecode(bytes: Uint8Array): T {\n\t\t\treturn JSON.parse(decoder.decode(bytes)) as T;\n\t\t},\n\t};\n}\n\n/** Default stable JSON codec for unknown values. */\nexport const jsonCodec: Codec<unknown> = jsonCodecFor<unknown>();\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n\tif (a.byteLength !== b.byteLength) return false;\n\tfor (let i = 0; i < a.byteLength; i += 1) {\n\t\tif (a[i] !== b[i]) return false;\n\t}\n\treturn true;\n}\n\nfunction hasUnpairedSurrogate(value: string): boolean {\n\tfor (let i = 0; i < value.length; i += 1) {\n\t\tconst code = value.charCodeAt(i);\n\t\tif (code >= 0xd800 && code <= 0xdbff) {\n\t\t\tconst next = value.charCodeAt(i + 1);\n\t\t\tif (next >= 0xdc00 && next <= 0xdfff) {\n\t\t\t\ti += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tif (code >= 0xdc00 && code <= 0xdfff) return true;\n\t}\n\treturn false;\n}\n\nfunction assertNoUnpairedSurrogates(value: unknown, seen = new Set<object>(), path = \"$\"): void {\n\tif (typeof value === \"string\") {\n\t\tif (hasUnpairedSurrogate(value)) {\n\t\t\tthrow new TypeError(`strictJsonCodec: unpaired surrogate at ${path}`);\n\t\t}\n\t\treturn;\n\t}\n\tif (value === null || typeof value !== \"object\") return;\n\tif (seen.has(value)) return;\n\tseen.add(value);\n\ttry {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (let i = 0; i < value.length; i += 1) {\n\t\t\t\tassertNoUnpairedSurrogates(value[i], seen, `${path}[${i}]`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tfor (const key of Object.keys(value as Record<string, unknown>)) {\n\t\t\tif (hasUnpairedSurrogate(key)) {\n\t\t\t\tthrow new TypeError(`strictJsonCodec: unpaired surrogate at ${path}.${key}`);\n\t\t\t}\n\t\t\tassertNoUnpairedSurrogates((value as Record<string, unknown>)[key], seen, `${path}.${key}`);\n\t\t}\n\t} finally {\n\t\tseen.delete(value);\n\t}\n}\n\nfunction assertNoDuplicateJsonObjectKeys(text: string): void {\n\tlet index = 0;\n\n\tfunction fail(message: string): never {\n\t\tthrow new TypeError(`strictJsonCodec: ${message}`);\n\t}\n\n\tfunction skipWhitespace(): void {\n\t\twhile (/\\s/.test(text[index] ?? \"\")) index += 1;\n\t}\n\n\tfunction readJsonString(): string {\n\t\tconst start = index;\n\t\tindex += 1;\n\t\twhile (index < text.length) {\n\t\t\tconst ch = text[index];\n\t\t\tif (ch === '\"') {\n\t\t\t\tindex += 1;\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(text.slice(start, index)) as string;\n\t\t\t\t} catch {\n\t\t\t\t\tfail(\"malformed JSON string\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ch === \"\\\\\") {\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tindex += 1;\n\t\t}\n\t\tfail(\"unterminated JSON string\");\n\t}\n\n\tfunction consumeLiteral(literal: string): void {\n\t\tif (text.slice(index, index + literal.length) !== literal) {\n\t\t\tfail(`malformed JSON near byte ${index}`);\n\t\t}\n\t\tindex += literal.length;\n\t}\n\n\tfunction consumeNumber(): void {\n\t\tconst match = /^-?(0|[1-9]\\d*)(\\.\\d+)?([eE][+-]?\\d+)?/.exec(text.slice(index));\n\t\tif (!match) fail(`malformed JSON number near byte ${index}`);\n\t\tindex += match[0].length;\n\t}\n\n\tfunction parseValue(path: string): void {\n\t\tskipWhitespace();\n\t\tconst ch = text[index];\n\t\tif (ch === \"{\") {\n\t\t\tparseObject(path);\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"[\") {\n\t\t\tparseArray(path);\n\t\t\treturn;\n\t\t}\n\t\tif (ch === '\"') {\n\t\t\treadJsonString();\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"t\") {\n\t\t\tconsumeLiteral(\"true\");\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"f\") {\n\t\t\tconsumeLiteral(\"false\");\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"n\") {\n\t\t\tconsumeLiteral(\"null\");\n\t\t\treturn;\n\t\t}\n\t\tif (ch === \"-\" || (ch !== undefined && ch >= \"0\" && ch <= \"9\")) {\n\t\t\tconsumeNumber();\n\t\t\treturn;\n\t\t}\n\t\tfail(`malformed JSON near byte ${index}`);\n\t}\n\n\tfunction parseObject(path: string): void {\n\t\tconst keys = new Set<string>();\n\t\tindex += 1;\n\t\tskipWhitespace();\n\t\tif (text[index] === \"}\") {\n\t\t\tindex += 1;\n\t\t\treturn;\n\t\t}\n\t\twhile (index < text.length) {\n\t\t\tskipWhitespace();\n\t\t\tif (text[index] !== '\"') fail(`expected object key near byte ${index}`);\n\t\t\tconst key = readJsonString();\n\t\t\tif (keys.has(key)) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`strictJsonCodec: duplicate object key ${JSON.stringify(key)} at ${path}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tkeys.add(key);\n\t\t\tskipWhitespace();\n\t\t\tif (text[index] !== \":\") fail(`expected ':' after object key near byte ${index}`);\n\t\t\tindex += 1;\n\t\t\tparseValue(`${path}.${key}`);\n\t\t\tskipWhitespace();\n\t\t\tif (text[index] === \",\") {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (text[index] === \"}\") {\n\t\t\t\tindex += 1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfail(`expected ',' or '}' near byte ${index}`);\n\t\t}\n\t\tfail(\"unterminated JSON object\");\n\t}\n\n\tfunction parseArray(path: string): void {\n\t\tindex += 1;\n\t\tskipWhitespace();\n\t\tif (text[index] === \"]\") {\n\t\t\tindex += 1;\n\t\t\treturn;\n\t\t}\n\t\tlet item = 0;\n\t\twhile (index < text.length) {\n\t\t\tparseValue(`${path}[${item}]`);\n\t\t\titem += 1;\n\t\t\tskipWhitespace();\n\t\t\tif (text[index] === \",\") {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (text[index] === \"]\") {\n\t\t\t\tindex += 1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfail(`expected ',' or ']' near byte ${index}`);\n\t\t}\n\t\tfail(\"unterminated JSON array\");\n\t}\n\n\tparseValue(\"$\");\n\tskipWhitespace();\n\tif (index !== text.length) fail(`trailing JSON token near byte ${index}`);\n}\n\n/**\n * Build a strict canonical JSON codec (D84/D87/D96).\n * The strict surface rejects malformed UTF-8, duplicate object keys, non-canonical bytes,\n * unpaired surrogates, and values that cannot round-trip through stable JSON.\n */\nexport function strictJsonCodecFor<T>(): Codec<T> {\n\tconst encoder = new TextEncoder();\n\tconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\treturn {\n\t\tencode(value: T): Uint8Array {\n\t\t\tassertNoUnpairedSurrogates(value);\n\t\t\treturn encoder.encode(strictStableJsonString(value));\n\t\t},\n\t\tdecode(bytes: Uint8Array): T {\n\t\t\tconst text = decoder.decode(bytes);\n\t\t\tassertNoDuplicateJsonObjectKeys(text);\n\t\t\tconst decoded = JSON.parse(text) as unknown;\n\t\t\tassertNoUnpairedSurrogates(decoded);\n\t\t\tconst canonical = encoder.encode(strictStableJsonString(decoded));\n\t\t\tif (!bytesEqual(bytes, canonical)) {\n\t\t\t\tthrow new TypeError(\"strictJsonCodec: bytes are not canonical stable JSON\");\n\t\t\t}\n\t\t\treturn decoded as T;\n\t\t},\n\t};\n}\n\n/** Default strict canonical JSON codec for unknown values. */\nexport const strictJsonCodec: Codec<unknown> = strictJsonCodecFor<unknown>();\n\n/** D113 neutral helper for strict canonical JSON UTF-8 bytes. */\nexport function strictCanonicalJsonBytes(value: unknown): Uint8Array {\n\treturn strictJsonCodec.encode(value);\n}\n\n/** Validate and normalize a host value into strict canonical JSON data. */\nexport function assertStrictJsonValue(value: unknown, label = \"strictJsonValue\"): StrictJsonValue {\n\ttry {\n\t\treturn strictJsonCodec.decode(strictJsonCodec.encode(value)) as StrictJsonValue;\n\t} catch (cause) {\n\t\tconst message = cause instanceof Error ? cause.message : String(cause);\n\t\tthrow new TypeError(`${label}: value is not strict JSON compatible: ${message}`, { cause });\n\t}\n}\n\n/** Validate and normalize a host value into a strict canonical JSON object. */\nexport function assertStrictJsonObject(\n\tvalue: unknown,\n\tlabel = \"strictJsonObject\",\n): StrictJsonObject {\n\tconst normalized = assertStrictJsonValue(value, label);\n\tif (normalized === null || typeof normalized !== \"object\" || Array.isArray(normalized)) {\n\t\tthrow new TypeError(`${label}: value must be a strict JSON object`);\n\t}\n\treturn normalized as StrictJsonObject;\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","import type { KvStorageTier } from \"./kv.js\";\nimport { memoryKv, requireKvPutIfAbsent } from \"./kv.js\";\n\nexport const APPEND_LOG_SEQ_PAD = 20;\n\n/** One append-log record with its storage key and monotonic sequence. */\nexport interface AppendLogEntry<T> {\n\treadonly key: string;\n\treadonly seq: number;\n\treadonly value: T;\n}\n\n/** Cursor and page-size options for append-log reads. */\nexport interface AppendLogReadOptions {\n\t/** Return entries with seq > after. */\n\tafter?: number;\n\tlimit?: number;\n}\n\n/** One bounded append-log page with the cursor for the next read. */\nexport interface AppendLogPage<T> {\n\treadonly entries: readonly AppendLogEntry<T>[];\n\treadonly nextAfter: number;\n\treadonly done: boolean;\n}\n\n/**\n * Append-only tier for durable event/change logs (D82), not graph restore replay.\n *\n * This first-cut helper serializes operations within one handle. Concurrent writers sharing the\n * same KV prefix need an external single-writer discipline or a future CAS-capable backend.\n */\nexport interface AppendLogStorageTier<T = unknown> {\n\tappend(value: T): Promise<AppendLogEntry<T>>;\n\tread(opts?: AppendLogReadOptions): Promise<readonly AppendLogEntry<T>[]>;\n\ttruncateAfter(seq: number): Promise<void>;\n\tsize(): Promise<number>;\n}\n\n/** D85 multi-writer append log; requires a passive conditional-create KV capability. */\nexport type MultiWriterAppendLogStorageTier<T = unknown> = AppendLogStorageTier<T>;\n\n/** Build the deterministic storage key for an append-log sequence number. */\nexport function appendLogKey(prefix: string, seq: number): string {\n\tif (!Number.isSafeInteger(seq) || seq < 0) {\n\t\tthrow new RangeError(`appendLogKey: seq must be a non-negative safe integer, got ${seq}`);\n\t}\n\treturn `${prefix}/${seq.toString().padStart(APPEND_LOG_SEQ_PAD, \"0\")}`;\n}\n\nfunction seqFromKey(prefix: string, key: string): number {\n\tconst head = `${prefix}/`;\n\tif (!key.startsWith(head)) throw new Error(`append log key outside prefix: ${key}`);\n\tconst raw = key.slice(head.length);\n\tif (!/^\\d+$/.test(raw)) {\n\t\tthrow new Error(`append log key has a non-numeric sequence: ${key}`);\n\t}\n\tif (raw.length !== APPEND_LOG_SEQ_PAD) {\n\t\tthrow new Error(`append log key sequence must be ${APPEND_LOG_SEQ_PAD} padded digits: ${key}`);\n\t}\n\tconst seq = Number(raw);\n\tif (!Number.isSafeInteger(seq)) {\n\t\tthrow new Error(`append log key sequence is outside the safe integer range: ${key}`);\n\t}\n\treturn seq;\n}\n\nfunction nextSeqFromKeys(prefix: string, keys: readonly string[]): number {\n\tif (keys.length === 0) return 0;\n\tconst next = Math.max(...keys.map((key) => seqFromKey(prefix, key))) + 1;\n\tif (!Number.isSafeInteger(next)) {\n\t\tthrow new RangeError(`append log next sequence is outside the safe integer range: ${prefix}`);\n\t}\n\treturn next;\n}\n\nfunction sizeFromKeys(prefix: string, keys: readonly string[]): number {\n\tfor (const key of keys) seqFromKey(prefix, key);\n\treturn keys.length;\n}\n\nfunction validateReadOptions(opts: AppendLogReadOptions): {\n\tafter: number;\n\tlimit: number;\n} {\n\tconst after = opts.after ?? -1;\n\tconst limit = opts.limit ?? Number.POSITIVE_INFINITY;\n\tif (!Number.isSafeInteger(after) || after < -1) {\n\t\tthrow new RangeError(\n\t\t\t`appendLogStorage.read: after must be an integer cursor >= -1, got ${after}`,\n\t\t);\n\t}\n\tif (limit !== Number.POSITIVE_INFINITY && (!Number.isSafeInteger(limit) || limit < 0)) {\n\t\tthrow new RangeError(\n\t\t\t`appendLogStorage.read: limit must be a non-negative safe integer or Infinity, got ${limit}`,\n\t\t);\n\t}\n\treturn { after, limit };\n}\n\nfunction validatePageLimit(limit: number): number {\n\tif (!Number.isSafeInteger(limit) || limit < 1) {\n\t\tthrow new RangeError(`readAppendLogPage: limit must be a positive safe integer, got ${limit}`);\n\t}\n\tif (limit >= Number.MAX_SAFE_INTEGER) {\n\t\tthrow new RangeError(\"readAppendLogPage: limit must leave room for one lookahead entry\");\n\t}\n\treturn limit;\n}\n\nfunction readAppendLogEntries<T>(\n\tkv: KvStorageTier<T>,\n\tprefix: string,\n\topts: AppendLogReadOptions,\n): Promise<readonly AppendLogEntry<T>[]> {\n\tconst { after, limit } = validateReadOptions(opts);\n\treturn kv.list(`${prefix}/`).then((listed) => {\n\t\tconst keys = listed\n\t\t\t.map((key) => ({ key, seq: seqFromKey(prefix, key) }))\n\t\t\t.filter(({ seq }) => seq > after)\n\t\t\t.sort((a, b) => a.seq - b.seq)\n\t\t\t.slice(0, limit);\n\t\treturn Promise.all(\n\t\t\tkeys.map(\n\t\t\t\t({ key, seq }): Promise<AppendLogEntry<T> | undefined> =>\n\t\t\t\t\tkv.get(key).then((value) => {\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\tthrow new Error(`append log listed key is missing: ${key}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { key, seq, value };\n\t\t\t\t\t}),\n\t\t\t),\n\t\t).then((entries) => {\n\t\t\tconst out: AppendLogEntry<T>[] = [];\n\t\t\tfor (const entry of entries) if (entry !== undefined) out.push(entry);\n\t\t\treturn out;\n\t\t});\n\t});\n}\n\n/** Read one ordered append-log page without assigning replay or restore semantics. */\nexport function readAppendLogPage<T>(\n\tlog: AppendLogStorageTier<T>,\n\topts: AppendLogReadOptions = {},\n): Promise<AppendLogPage<T>> {\n\tconst { after, limit } = validateReadOptions({ after: opts.after, limit: opts.limit ?? 100 });\n\tconst pageLimit = validatePageLimit(limit);\n\treturn log.read({ after, limit: pageLimit + 1 }).then((entries) => {\n\t\tconst visible = entries.slice(0, pageLimit);\n\t\tconst last = visible[visible.length - 1];\n\t\treturn {\n\t\t\tentries: visible,\n\t\t\tnextAfter: last?.seq ?? after,\n\t\t\tdone: entries.length <= pageLimit,\n\t\t};\n\t});\n}\n\nfunction deleteAppendLogEntriesAfter<T>(\n\tkv: KvStorageTier<T>,\n\tprefix: string,\n\tseq: number,\n): Promise<void> {\n\treturn kv\n\t\t.list(`${prefix}/`)\n\t\t.then((keys) =>\n\t\t\tPromise.all(keys.filter((key) => seqFromKey(prefix, key) > seq).map((key) => kv.delete(key))),\n\t\t)\n\t\t.then(() => kv.list(`${prefix}/`))\n\t\t.then(() => undefined);\n}\n\n/** Options for a typed append log over a KV tier. */\nexport interface AppendLogOptions<T> {\n\tkv: KvStorageTier<T>;\n\tprefix?: string;\n}\n\n/** Options for D85 multi-writer append logs over conditional-create capable KV. */\nexport interface MultiWriterAppendLogOptions<T> extends AppendLogOptions<T> {\n\t/** Bound retry work before refreshing the listed tail after another writer wins slots. */\n\tmaxAttempts?: number;\n}\n\n/**\n * Build a single-writer append-only log over a KV tier, serializing all operations in call order\n * for this handle. D85 multi-handle concurrent appends require multiWriterAppendLogStorage.\n */\nexport function appendLogStorage<T = unknown>(opts: AppendLogOptions<T>): AppendLogStorageTier<T> {\n\tconst { kv, prefix = \"event-log\" } = opts;\n\tlet tail: Promise<unknown> = Promise.resolve();\n\n\tfunction initNextSeq(): Promise<number> {\n\t\treturn kv.list(`${prefix}/`).then((keys) => {\n\t\t\treturn nextSeqFromKeys(prefix, keys);\n\t\t});\n\t}\n\n\tfunction enqueue<R>(task: () => Promise<R>): Promise<R> {\n\t\tconst run = tail.then(task, task);\n\t\ttail = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\treturn {\n\t\tappend(value) {\n\t\t\treturn enqueue(() =>\n\t\t\t\tinitNextSeq().then((seq) => {\n\t\t\t\t\tconst key = appendLogKey(prefix, seq);\n\t\t\t\t\treturn kv.set(key, value).then(() => {\n\t\t\t\t\t\treturn { key, seq, value };\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tread(opts = {}) {\n\t\t\treturn enqueue(() => readAppendLogEntries(kv, prefix, opts));\n\t\t},\n\t\ttruncateAfter(seq) {\n\t\t\treturn enqueue(() => deleteAppendLogEntriesAfter(kv, prefix, seq));\n\t\t},\n\t\tsize() {\n\t\t\treturn enqueue(() => kv.list(`${prefix}/`).then((keys) => sizeFromKeys(prefix, keys)));\n\t\t},\n\t};\n}\n\n/**\n * Build a D85 multi-writer append log over a conditional-create capable KV tier.\n *\n * Sequence allocation is passive storage work: each writer proposes a padded key and retries the\n * next key when another writer already created that slot. This does not provide general CAS,\n * locks, leases, transactions, unsafe truncation, WAL replay, or graph restore semantics.\n */\nexport function multiWriterAppendLogStorage<T = unknown>(\n\topts: MultiWriterAppendLogOptions<T>,\n): MultiWriterAppendLogStorageTier<T> {\n\tconst { kv, prefix = \"event-log\", maxAttempts = 1024 } = opts;\n\tconst capableKv = requireKvPutIfAbsent(kv, \"multiWriterAppendLogStorage\");\n\tlet tail: Promise<unknown> = Promise.resolve();\n\n\tif (!Number.isSafeInteger(maxAttempts) || maxAttempts < 1) {\n\t\tthrow new RangeError(\n\t\t\t`multiWriterAppendLogStorage: maxAttempts must be a positive safe integer, got ${maxAttempts}`,\n\t\t);\n\t}\n\n\tfunction initNextSeq(): Promise<number> {\n\t\treturn kv.list(`${prefix}/`).then((keys) => nextSeqFromKeys(prefix, keys));\n\t}\n\n\tfunction enqueue<R>(task: () => Promise<R>): Promise<R> {\n\t\tconst run = tail.then(task, task);\n\t\ttail = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\treturn {\n\t\tappend(value) {\n\t\t\treturn enqueue(() =>\n\t\t\t\tinitNextSeq().then((startSeq) => {\n\t\t\t\t\tlet seq = startSeq;\n\t\t\t\t\tlet attempt = 0;\n\t\t\t\t\tconst tryNext = (): Promise<AppendLogEntry<T>> => {\n\t\t\t\t\t\tif (attempt >= maxAttempts) {\n\t\t\t\t\t\t\treturn initNextSeq().then((refreshedSeq) => {\n\t\t\t\t\t\t\t\tseq = Math.max(seq, refreshedSeq);\n\t\t\t\t\t\t\t\tattempt = 0;\n\t\t\t\t\t\t\t\treturn tryNext();\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tattempt += 1;\n\t\t\t\t\t\tconst key = appendLogKey(prefix, seq);\n\t\t\t\t\t\treturn capableKv.putIfAbsent(key, value).then((created) => {\n\t\t\t\t\t\t\tif (created) return { key, seq, value };\n\t\t\t\t\t\t\tseq += 1;\n\t\t\t\t\t\t\tif (!Number.isSafeInteger(seq)) {\n\t\t\t\t\t\t\t\tthrow new RangeError(\n\t\t\t\t\t\t\t\t\t`append log next sequence is outside the safe integer range: ${prefix}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn tryNext();\n\t\t\t\t\t\t});\n\t\t\t\t\t};\n\t\t\t\t\treturn tryNext();\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tread(opts = {}) {\n\t\t\treturn enqueue(() => readAppendLogEntries(kv, prefix, opts));\n\t\t},\n\t\ttruncateAfter(seq) {\n\t\t\treturn enqueue(() => {\n\t\t\t\tif (!Number.isSafeInteger(seq) || seq < -1) {\n\t\t\t\t\tthrow new RangeError(\n\t\t\t\t\t\t`multiWriterAppendLogStorage.truncateAfter: seq must be an integer cursor >= -1, got ${seq}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"multiWriterAppendLogStorage.truncateAfter: unsupported without a stronger compaction capability\",\n\t\t\t\t);\n\t\t\t});\n\t\t},\n\t\tsize() {\n\t\t\treturn enqueue(() => kv.list(`${prefix}/`).then((keys) => sizeFromKeys(prefix, keys)));\n\t\t},\n\t};\n}\n\n/** Create an in-memory append log. */\nexport function memoryAppendLog<T = unknown>(prefix?: string): AppendLogStorageTier<T> {\n\treturn appendLogStorage({ kv: memoryKv<T>(), prefix });\n}\n\n/** Create an in-memory D85 multi-writer append log. */\nexport function memoryMultiWriterAppendLog<T = unknown>(\n\tprefix?: string,\n): MultiWriterAppendLogStorageTier<T> {\n\treturn multiWriterAppendLogStorage({ kv: memoryKv<T>(), prefix });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,yBAA4B;AAC5B,qBASO;AACP,yBAA8B;AAC9B,uBAAwC;;;ACdxC,IAAM,YAAY,MAAM,KAAK,EAAE,QAAQ,IAAI,GAAG,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC;AA0GhF,SAAS,sBACf,SACuC;AACvC,SAAO,OAAO,QAAQ,gBAAgB;AACvC;AAcO,SAAS,oBAAoB,SAA6D;AAChG,SAAO,OAAO,QAAQ,iBAAiB,cAAc,OAAO,QAAQ,eAAe;AACpF;;;AC5GA,IAAM,uBAAuB,KAAK;AAElC,SAAS,uBAAuB,OAAe,MAAoB;AAClE,MAAI,CAAC,OAAO,SAAS,KAAK,GAAG;AAC5B,UAAM,IAAI,UAAU,0CAA0C,IAAI,EAAE;AAAA,EACrE;AACD;AAEA,SAAS,uBAAuB,OAAe,MAAoB;AAClE,yBAAuB,OAAO,IAAI;AAClC,MAAI,OAAO,GAAG,OAAO,EAAE,GAAG;AACzB,UAAM,IAAI,UAAU,6CAA6C,IAAI,EAAE;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ACzB;AAAA,IACA,OAAO,KAAK;AAAA,EACb,CAAC;AACD,SAAO,OAAO,OAAO,MAAM,EAAE,OAAO,MAAM,QAAQ,MAAM,EAAE,CAAC;AAC5D;AAKO,SAAS,gBACf,MACA,OAAkC,CAAC,GACW;AAC9C,QAAM,KAAK,SAAY,MAAM,IAAI;AACjC,QAAM,MAAM,iBAAoB,EAAE,IAAI,QAAQ,KAAK,UAAU,YAAY,CAAC;AAC1E,SAAO,OAAO,OAAO,KAAK,EAAE,OAAO,MAAM,GAAG,MAAM,EAAE,CAAC;AACtD;","names":["out","encoder","decoder","opts","require"]}
|
package/dist/storage/node.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
appendLogStorage
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-ZLFRB6FI.js";
|
|
4
4
|
import {
|
|
5
5
|
kvStorage
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-JKAYLDQV.js";
|
|
7
|
+
import "../chunk-K7FB3JTD.js";
|
|
8
|
+
import "../chunk-DGUM43GV.js";
|
|
8
9
|
|
|
9
10
|
// src/storage/node.ts
|
|
10
11
|
import { randomBytes } from "crypto";
|