@graphrefly/ts 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapters/index.cjs +9015 -0
  3. package/dist/adapters/index.cjs.map +1 -0
  4. package/dist/adapters/index.d.cts +678 -0
  5. package/dist/adapters/index.d.ts +678 -0
  6. package/dist/adapters/index.js +2894 -0
  7. package/dist/adapters/index.js.map +1 -0
  8. package/dist/adapters/observe-storage.cjs +260 -0
  9. package/dist/adapters/observe-storage.cjs.map +1 -0
  10. package/dist/adapters/observe-storage.d.cts +77 -0
  11. package/dist/adapters/observe-storage.d.ts +77 -0
  12. package/dist/adapters/observe-storage.js +161 -0
  13. package/dist/adapters/observe-storage.js.map +1 -0
  14. package/dist/append-log-DisvEReb.d.cts +189 -0
  15. package/dist/append-log-DzKMmjxx.d.ts +189 -0
  16. package/dist/chunk-2ILL7HQI.js +1189 -0
  17. package/dist/chunk-2ILL7HQI.js.map +1 -0
  18. package/dist/chunk-4VLAQHZI.js +330 -0
  19. package/dist/chunk-4VLAQHZI.js.map +1 -0
  20. package/dist/chunk-6PHB5CJS.js +229 -0
  21. package/dist/chunk-6PHB5CJS.js.map +1 -0
  22. package/dist/chunk-COHO25CZ.js +2449 -0
  23. package/dist/chunk-COHO25CZ.js.map +1 -0
  24. package/dist/chunk-D6BG7U6A.js +161 -0
  25. package/dist/chunk-D6BG7U6A.js.map +1 -0
  26. package/dist/chunk-DJC4CHLQ.js +818 -0
  27. package/dist/chunk-DJC4CHLQ.js.map +1 -0
  28. package/dist/chunk-DK554R7P.js +67 -0
  29. package/dist/chunk-DK554R7P.js.map +1 -0
  30. package/dist/chunk-DKP56CSW.js +322 -0
  31. package/dist/chunk-DKP56CSW.js.map +1 -0
  32. package/dist/chunk-G4M3NHRJ.js +688 -0
  33. package/dist/chunk-G4M3NHRJ.js.map +1 -0
  34. package/dist/chunk-GAJW5I5P.js +1 -0
  35. package/dist/chunk-GAJW5I5P.js.map +1 -0
  36. package/dist/chunk-GDL26N2T.js +282 -0
  37. package/dist/chunk-GDL26N2T.js.map +1 -0
  38. package/dist/chunk-GTPCOEOZ.js +741 -0
  39. package/dist/chunk-GTPCOEOZ.js.map +1 -0
  40. package/dist/chunk-H2HTHFVN.js +1 -0
  41. package/dist/chunk-H2HTHFVN.js.map +1 -0
  42. package/dist/chunk-HDRL4VQQ.js +218 -0
  43. package/dist/chunk-HDRL4VQQ.js.map +1 -0
  44. package/dist/chunk-I3IHOHCJ.js +2267 -0
  45. package/dist/chunk-I3IHOHCJ.js.map +1 -0
  46. package/dist/chunk-JIMUDQN3.js +965 -0
  47. package/dist/chunk-JIMUDQN3.js.map +1 -0
  48. package/dist/chunk-JR4IKCR2.js +462 -0
  49. package/dist/chunk-JR4IKCR2.js.map +1 -0
  50. package/dist/chunk-K3FXTC3I.js +165 -0
  51. package/dist/chunk-K3FXTC3I.js.map +1 -0
  52. package/dist/chunk-OOEN33FB.js +65 -0
  53. package/dist/chunk-OOEN33FB.js.map +1 -0
  54. package/dist/chunk-PKVBHGBM.js +554 -0
  55. package/dist/chunk-PKVBHGBM.js.map +1 -0
  56. package/dist/chunk-RIIOUTGM.js +1857 -0
  57. package/dist/chunk-RIIOUTGM.js.map +1 -0
  58. package/dist/chunk-SCRFRCGR.js +33 -0
  59. package/dist/chunk-SCRFRCGR.js.map +1 -0
  60. package/dist/chunk-SWTLEQL6.js +53 -0
  61. package/dist/chunk-SWTLEQL6.js.map +1 -0
  62. package/dist/chunk-SZAETNNA.js +1 -0
  63. package/dist/chunk-SZAETNNA.js.map +1 -0
  64. package/dist/chunk-TEW47IVR.js +49 -0
  65. package/dist/chunk-TEW47IVR.js.map +1 -0
  66. package/dist/chunk-Y3ZLRGHC.js +1482 -0
  67. package/dist/chunk-Y3ZLRGHC.js.map +1 -0
  68. package/dist/chunk-Z2ANQ6JW.js +149 -0
  69. package/dist/chunk-Z2ANQ6JW.js.map +1 -0
  70. package/dist/codec-BB7p8fJc.d.cts +38 -0
  71. package/dist/codec-BB7p8fJc.d.ts +38 -0
  72. package/dist/composition/index.cjs +2505 -0
  73. package/dist/composition/index.cjs.map +1 -0
  74. package/dist/composition/index.d.cts +95 -0
  75. package/dist/composition/index.d.ts +95 -0
  76. package/dist/composition/index.js +19 -0
  77. package/dist/composition/index.js.map +1 -0
  78. package/dist/core/index.cjs +2475 -0
  79. package/dist/core/index.cjs.map +1 -0
  80. package/dist/core/index.d.cts +25 -0
  81. package/dist/core/index.d.ts +25 -0
  82. package/dist/core/index.js +74 -0
  83. package/dist/core/index.js.map +1 -0
  84. package/dist/cqrs/index.cjs +595 -0
  85. package/dist/cqrs/index.cjs.map +1 -0
  86. package/dist/cqrs/index.d.cts +200 -0
  87. package/dist/cqrs/index.d.ts +200 -0
  88. package/dist/cqrs/index.js +557 -0
  89. package/dist/cqrs/index.js.map +1 -0
  90. package/dist/data-structures/index.cjs +4277 -0
  91. package/dist/data-structures/index.cjs.map +1 -0
  92. package/dist/data-structures/index.d.cts +22 -0
  93. package/dist/data-structures/index.d.ts +22 -0
  94. package/dist/data-structures/index.js +31 -0
  95. package/dist/data-structures/index.js.map +1 -0
  96. package/dist/describe-BZb7AS2y.d.ts +57 -0
  97. package/dist/describe-Ciu8SUnN.d.cts +57 -0
  98. package/dist/graph/index.cjs +7832 -0
  99. package/dist/graph/index.cjs.map +1 -0
  100. package/dist/graph/index.d.cts +251 -0
  101. package/dist/graph/index.d.ts +251 -0
  102. package/dist/graph/index.js +131 -0
  103. package/dist/graph/index.js.map +1 -0
  104. package/dist/graph-DfdF9zy4.d.ts +666 -0
  105. package/dist/graph-s23RbbFO.d.cts +666 -0
  106. package/dist/index-CAEmLCYF.d.cts +166 -0
  107. package/dist/index-SnzZu3x7.d.ts +166 -0
  108. package/dist/index.cjs +15409 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.cts +23 -0
  111. package/dist/index.d.ts +23 -0
  112. package/dist/index.js +582 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/messages-BZqrGGm1.d.cts +55 -0
  115. package/dist/messages-BZqrGGm1.d.ts +55 -0
  116. package/dist/messaging/index.cjs +818 -0
  117. package/dist/messaging/index.cjs.map +1 -0
  118. package/dist/messaging/index.d.cts +235 -0
  119. package/dist/messaging/index.d.ts +235 -0
  120. package/dist/messaging/index.js +767 -0
  121. package/dist/messaging/index.js.map +1 -0
  122. package/dist/observe-event-log-0SVsx7JG.d.cts +88 -0
  123. package/dist/observe-event-log-Dnm76owp.d.ts +88 -0
  124. package/dist/operators/index.cjs +3774 -0
  125. package/dist/operators/index.cjs.map +1 -0
  126. package/dist/operators/index.d.cts +308 -0
  127. package/dist/operators/index.d.ts +308 -0
  128. package/dist/operators/index.js +112 -0
  129. package/dist/operators/index.js.map +1 -0
  130. package/dist/orchestration/index.cjs +3541 -0
  131. package/dist/orchestration/index.cjs.map +1 -0
  132. package/dist/orchestration/index.d.cts +302 -0
  133. package/dist/orchestration/index.d.ts +302 -0
  134. package/dist/orchestration/index.js +1004 -0
  135. package/dist/orchestration/index.js.map +1 -0
  136. package/dist/patterns/index.cjs +1045 -0
  137. package/dist/patterns/index.cjs.map +1 -0
  138. package/dist/patterns/index.d.cts +39 -0
  139. package/dist/patterns/index.d.ts +39 -0
  140. package/dist/patterns/index.js +33 -0
  141. package/dist/patterns/index.js.map +1 -0
  142. package/dist/reactive-collection-BxBqtIOE.d.cts +344 -0
  143. package/dist/reactive-collection-Cb1II1Fi.d.ts +344 -0
  144. package/dist/reactive-collection-storage-BNiEc-Gd.d.ts +217 -0
  145. package/dist/reactive-collection-storage-D-KmjE0J.d.cts +217 -0
  146. package/dist/reactive-map-BcB4KsQR.d.ts +256 -0
  147. package/dist/reactive-map-D-g3dv8I.d.cts +256 -0
  148. package/dist/read-through-B1CYPfq_.d.cts +82 -0
  149. package/dist/read-through-DwyJhGs1.d.ts +82 -0
  150. package/dist/render/index.cjs +250 -0
  151. package/dist/render/index.cjs.map +1 -0
  152. package/dist/render/index.d.cts +58 -0
  153. package/dist/render/index.d.ts +58 -0
  154. package/dist/render/index.js +20 -0
  155. package/dist/render/index.js.map +1 -0
  156. package/dist/resilience-Dig3Q7n0.d.cts +45 -0
  157. package/dist/resilience-Dig3Q7n0.d.ts +45 -0
  158. package/dist/semantic-memory-graph-BYoIlP35.d.cts +356 -0
  159. package/dist/semantic-memory-graph-CxyXLms3.d.ts +356 -0
  160. package/dist/solutions/index.cjs +3249 -0
  161. package/dist/solutions/index.cjs.map +1 -0
  162. package/dist/solutions/index.d.cts +520 -0
  163. package/dist/solutions/index.d.ts +520 -0
  164. package/dist/solutions/index.js +31 -0
  165. package/dist/solutions/index.js.map +1 -0
  166. package/dist/sources/browser.cjs +3095 -0
  167. package/dist/sources/browser.cjs.map +1 -0
  168. package/dist/sources/browser.d.cts +39 -0
  169. package/dist/sources/browser.d.ts +39 -0
  170. package/dist/sources/browser.js +137 -0
  171. package/dist/sources/browser.js.map +1 -0
  172. package/dist/sources/index.cjs +3021 -0
  173. package/dist/sources/index.cjs.map +1 -0
  174. package/dist/sources/index.d.cts +7 -0
  175. package/dist/sources/index.d.ts +7 -0
  176. package/dist/sources/index.js +63 -0
  177. package/dist/sources/index.js.map +1 -0
  178. package/dist/sources/node.cjs +675 -0
  179. package/dist/sources/node.cjs.map +1 -0
  180. package/dist/sources/node.d.cts +109 -0
  181. package/dist/sources/node.d.ts +109 -0
  182. package/dist/sources/node.js +639 -0
  183. package/dist/sources/node.js.map +1 -0
  184. package/dist/storage/browser.cjs +777 -0
  185. package/dist/storage/browser.cjs.map +1 -0
  186. package/dist/storage/browser.d.cts +40 -0
  187. package/dist/storage/browser.d.ts +40 -0
  188. package/dist/storage/browser.js +275 -0
  189. package/dist/storage/browser.js.map +1 -0
  190. package/dist/storage/index.cjs +1989 -0
  191. package/dist/storage/index.cjs.map +1 -0
  192. package/dist/storage/index.d.cts +92 -0
  193. package/dist/storage/index.d.ts +92 -0
  194. package/dist/storage/index.js +161 -0
  195. package/dist/storage/index.js.map +1 -0
  196. package/dist/storage/node.cjs +898 -0
  197. package/dist/storage/node.cjs.map +1 -0
  198. package/dist/storage/node.d.cts +66 -0
  199. package/dist/storage/node.d.ts +66 -0
  200. package/dist/storage/node.js +402 -0
  201. package/dist/storage/node.js.map +1 -0
  202. package/dist/testing/index.cjs +95 -0
  203. package/dist/testing/index.cjs.map +1 -0
  204. package/dist/testing/index.d.cts +20 -0
  205. package/dist/testing/index.d.ts +20 -0
  206. package/dist/testing/index.js +8 -0
  207. package/dist/testing/index.js.map +1 -0
  208. package/dist/types-bNMSWKqF.d.cts +732 -0
  209. package/dist/types-h12mNYbq.d.ts +732 -0
  210. package/package.json +250 -0
@@ -0,0 +1,1989 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/storage/index.ts
21
+ var storage_exports = {};
22
+ __export(storage_exports, {
23
+ APPEND_LOG_SEQ_PAD: () => APPEND_LOG_SEQ_PAD,
24
+ ContentAddressedMissError: () => ContentAddressedMissError,
25
+ REACTIVE_COLLECTION_CHANGE_FORMAT: () => REACTIVE_COLLECTION_CHANGE_FORMAT,
26
+ REACTIVE_COLLECTION_FRAME_VERSION: () => REACTIVE_COLLECTION_FRAME_VERSION,
27
+ REACTIVE_COLLECTION_SNAPSHOT_FORMAT: () => REACTIVE_COLLECTION_SNAPSHOT_FORMAT,
28
+ WAL_FORMAT_VERSION: () => WAL_FORMAT_VERSION,
29
+ WAL_FRAME_SEQ_PAD: () => WAL_FRAME_SEQ_PAD,
30
+ WAL_KEY_SEGMENT: () => WAL_KEY_SEGMENT,
31
+ appendLogKey: () => appendLogKey,
32
+ appendLogStorage: () => appendLogStorage,
33
+ assertChangeEnvelope: () => assertChangeEnvelope,
34
+ assertDecimalIntegerString: () => assertDecimalIntegerString,
35
+ assertNonNegativeDecimalIntegerString: () => assertNonNegativeDecimalIntegerString,
36
+ assertObserveEventFrame: () => assertObserveEventFrame,
37
+ assertReactiveCollectionChangeFrame: () => assertReactiveCollectionChangeFrame,
38
+ assertReactiveCollectionSnapshotFrame: () => assertReactiveCollectionSnapshotFrame,
39
+ assertStrictJsonObject: () => assertStrictJsonObject,
40
+ assertStrictJsonValue: () => assertStrictJsonValue,
41
+ assertWalFrame: () => assertWalFrame,
42
+ bigIntToDecimalString: () => bigIntToDecimalString,
43
+ bigIntToNonNegativeDecimalString: () => bigIntToNonNegativeDecimalString,
44
+ changeEnvelopeCodec: () => changeEnvelopeCodec,
45
+ collectionSnapshotKey: () => collectionSnapshotKey,
46
+ contentAddressedKv: () => contentAddressedKv,
47
+ contentAddressedStorage: () => contentAddressedStorage,
48
+ decimalStringToBigInt: () => decimalStringToBigInt,
49
+ dictKv: () => dictKv,
50
+ envelopeChange: () => envelopeChange,
51
+ hasKvPutIfAbsent: () => hasKvPutIfAbsent,
52
+ hasKvVersioned: () => hasKvVersioned,
53
+ hasStoragePutIfAbsent: () => hasStoragePutIfAbsent,
54
+ hasStorageVersioned: () => hasStorageVersioned,
55
+ isDecimalIntegerString: () => isDecimalIntegerString,
56
+ isNonNegativeDecimalIntegerString: () => isNonNegativeDecimalIntegerString,
57
+ jsonCodec: () => jsonCodec,
58
+ jsonCodecFor: () => jsonCodecFor,
59
+ kvStorage: () => kvStorage,
60
+ listByPrefix: () => listByPrefix2,
61
+ loadReactiveIndexState: () => loadReactiveIndexState,
62
+ loadReactiveListState: () => loadReactiveListState,
63
+ loadReactiveLogState: () => loadReactiveLogState,
64
+ loadReactiveMapState: () => loadReactiveMapState,
65
+ memoryAppendLog: () => memoryAppendLog,
66
+ memoryBackend: () => memoryBackend,
67
+ memoryKv: () => memoryKv,
68
+ memoryMultiWriterAppendLog: () => memoryMultiWriterAppendLog,
69
+ multiWriterAppendLogStorage: () => multiWriterAppendLogStorage,
70
+ nonNegativeDecimalStringToBigInt: () => nonNegativeDecimalStringToBigInt,
71
+ nowNs: () => nowNs,
72
+ observeEventFrame: () => observeEventFrame,
73
+ observeEventFrameCodec: () => observeEventFrameCodec,
74
+ reactiveCollectionChangeFrame: () => reactiveCollectionChangeFrame,
75
+ reactiveCollectionChangeFrameCodec: () => reactiveCollectionChangeFrameCodec,
76
+ reactiveCollectionSnapshotFrame: () => reactiveCollectionSnapshotFrame,
77
+ reactiveCollectionSnapshotFrameCodec: () => reactiveCollectionSnapshotFrameCodec,
78
+ readAppendLogPage: () => readAppendLogPage,
79
+ readObserveEventLogPage: () => readObserveEventLogPage,
80
+ readThroughKv: () => readThroughKv,
81
+ requireKvPutIfAbsent: () => requireKvPutIfAbsent,
82
+ requireKvVersioned: () => requireKvVersioned,
83
+ requireStoragePutIfAbsent: () => requireStoragePutIfAbsent,
84
+ requireStorageVersioned: () => requireStorageVersioned,
85
+ stableJsonString: () => stableJsonString,
86
+ strictJsonCodec: () => strictJsonCodec,
87
+ strictJsonCodecFor: () => strictJsonCodecFor,
88
+ tieredReadThrough: () => tieredReadThrough,
89
+ verifyWalFrameChecksum: () => verifyWalFrameChecksum,
90
+ walFrame: () => walFrame,
91
+ walFrameChecksum: () => walFrameChecksum,
92
+ walFrameCodec: () => walFrameCodec,
93
+ walFrameKey: () => walFrameKey,
94
+ walFramePrefix: () => walFramePrefix,
95
+ webStorageBackend: () => webStorageBackend
96
+ });
97
+ module.exports = __toCommonJS(storage_exports);
98
+
99
+ // src/storage/backend.ts
100
+ var HEX_TABLE = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
101
+ var NAMESPACE_SEPARATOR = "\0";
102
+ function cloneBytes(bytes) {
103
+ return Uint8Array.from(bytes);
104
+ }
105
+ function encodeNamespacePrefix(namespace) {
106
+ return namespace.length > 0 ? `${namespace}${NAMESPACE_SEPARATOR}` : "";
107
+ }
108
+ function encodeBytesToHex(bytes) {
109
+ let out = "";
110
+ for (const byte of bytes) out += HEX_TABLE[byte];
111
+ return out;
112
+ }
113
+ function decodeHexToBytes(raw) {
114
+ if (raw.length % 2 !== 0 || !/^[0-9a-f]*$/i.test(raw)) {
115
+ throw new TypeError("webStorageBackend: malformed stored bytes");
116
+ }
117
+ const out = new Uint8Array(raw.length / 2);
118
+ for (let i = 0; i < raw.length; i += 2) {
119
+ const value = Number.parseInt(raw.slice(i, i + 2), 16);
120
+ if (Number.isNaN(value)) throw new TypeError("webStorageBackend: malformed stored bytes");
121
+ out[i / 2] = value;
122
+ }
123
+ return out;
124
+ }
125
+ function validateLogicalKey(label, key) {
126
+ if (typeof key !== "string") {
127
+ throw new TypeError(`${label}: key must be a string`);
128
+ }
129
+ if (key.includes(NAMESPACE_SEPARATOR)) {
130
+ throw new TypeError(`${label}: key must not contain U+0000`);
131
+ }
132
+ return key;
133
+ }
134
+ function validateListPrefix(label, prefix) {
135
+ if (typeof prefix !== "string") {
136
+ throw new TypeError(`${label}: list prefix must be a string`);
137
+ }
138
+ if (prefix.includes(NAMESPACE_SEPARATOR)) {
139
+ throw new TypeError(`${label}: list prefix must not contain U+0000`);
140
+ }
141
+ return prefix;
142
+ }
143
+ function validateNamespace(label, namespace) {
144
+ if (typeof namespace !== "string") {
145
+ throw new TypeError(`${label}: namespace must be a string`);
146
+ }
147
+ if (namespace.includes(NAMESPACE_SEPARATOR)) {
148
+ throw new TypeError(`${label}: namespace must not contain U+0000`);
149
+ }
150
+ return namespace;
151
+ }
152
+ function hasStoragePutIfAbsent(backend) {
153
+ return typeof backend.putIfAbsent === "function";
154
+ }
155
+ function requireStoragePutIfAbsent(backend, label = "storage backend") {
156
+ if (!hasStoragePutIfAbsent(backend)) {
157
+ throw new Error(`${label}: backend does not support putIfAbsent`);
158
+ }
159
+ return backend;
160
+ }
161
+ function hasStorageVersioned(backend) {
162
+ return typeof backend.getVersioned === "function" && typeof backend.setIfMatch === "function";
163
+ }
164
+ function requireStorageVersioned(backend, label = "storage backend") {
165
+ if (!hasStorageVersioned(backend)) {
166
+ throw new Error(`${label}: backend does not support versioned get/set-if-match`);
167
+ }
168
+ return backend;
169
+ }
170
+ function toStorageKey(namespace, key) {
171
+ return `${encodeNamespacePrefix(namespace)}${key}`;
172
+ }
173
+ function enumerateStorageKeys(storage) {
174
+ if (storage.keys) return [...storage.keys()];
175
+ if (typeof storage.key === "function" && typeof storage.length === "number") {
176
+ const keys = [];
177
+ for (let i = 0; i < storage.length; i += 1) {
178
+ const key = storage.key(i);
179
+ if (key !== null && key !== void 0) keys.push(key);
180
+ }
181
+ return keys;
182
+ }
183
+ const fallback = storage;
184
+ return Object.keys(fallback).filter((key) => typeof fallback[key] === "string");
185
+ }
186
+ function decodeStorageListKey(namespace, rawKey) {
187
+ if (typeof rawKey !== "string") {
188
+ throw new TypeError("webStorageBackend: stored key must be a string");
189
+ }
190
+ const prefix = encodeNamespacePrefix(namespace);
191
+ if (!rawKey.startsWith(prefix)) return void 0;
192
+ const logical = rawKey.slice(prefix.length);
193
+ if (logical.includes(NAMESPACE_SEPARATOR)) {
194
+ throw new TypeError("webStorageBackend: malformed stored key");
195
+ }
196
+ return logical;
197
+ }
198
+ function listByPrefix(namespace, prefix, raw) {
199
+ const out = [];
200
+ for (const key of raw) {
201
+ const logical = decodeStorageListKey(namespace, key);
202
+ if (logical === void 0) continue;
203
+ if (!logical.startsWith(prefix)) continue;
204
+ out.push(logical);
205
+ }
206
+ out.sort();
207
+ return out;
208
+ }
209
+ function webStorageBackend(storage, opts = {}) {
210
+ const namespace = opts.namespace === void 0 ? "" : validateNamespace("webStorageBackend", opts.namespace);
211
+ return {
212
+ get(key) {
213
+ const raw = storage.getItem(
214
+ toStorageKey(namespace, validateLogicalKey("webStorageBackend", key))
215
+ );
216
+ if (raw === null || raw === void 0) return void 0;
217
+ return decodeHexToBytes(raw);
218
+ },
219
+ put(key, value) {
220
+ storage.setItem(
221
+ toStorageKey(namespace, validateLogicalKey("webStorageBackend", key)),
222
+ encodeBytesToHex(cloneBytes(value))
223
+ );
224
+ },
225
+ delete(key) {
226
+ storage.removeItem(toStorageKey(namespace, validateLogicalKey("webStorageBackend", key)));
227
+ },
228
+ list(prefix = "") {
229
+ return listByPrefix(
230
+ namespace,
231
+ validateListPrefix("webStorageBackend", prefix),
232
+ enumerateStorageKeys(storage)
233
+ );
234
+ }
235
+ };
236
+ }
237
+ var MEMORY_GENERATION = /* @__PURE__ */ Symbol("graphrefly.memoryBackend.generation");
238
+ function memoryGeneration(epoch, key, version) {
239
+ return Object.freeze({ [MEMORY_GENERATION]: Object.freeze([epoch, key, version]) });
240
+ }
241
+ function readMemoryGeneration(generation) {
242
+ if (typeof generation !== "object" || generation === null) return void 0;
243
+ const maybe = generation;
244
+ const token = maybe[MEMORY_GENERATION];
245
+ if (Array.isArray(token) && token.length === 3 && typeof token[0] === "number" && typeof token[1] === "string" && typeof token[2] === "number") {
246
+ return token;
247
+ }
248
+ return void 0;
249
+ }
250
+ function memoryBackend(initial = []) {
251
+ const entries = /* @__PURE__ */ new Map();
252
+ const versions = /* @__PURE__ */ new Map();
253
+ let epoch = 0;
254
+ for (const [key, value] of initial) {
255
+ entries.set(validateLogicalKey("memoryBackend", key), cloneBytes(value));
256
+ }
257
+ const versionOf = (key) => versions.get(key) ?? 0;
258
+ const bump = (key) => {
259
+ versions.set(key, versionOf(key) + 1);
260
+ };
261
+ return {
262
+ entries,
263
+ get(key) {
264
+ const value = entries.get(validateLogicalKey("memoryBackend", key));
265
+ return value === void 0 ? void 0 : cloneBytes(value);
266
+ },
267
+ put(key, value) {
268
+ validateLogicalKey("memoryBackend", key);
269
+ entries.set(key, cloneBytes(value));
270
+ bump(key);
271
+ },
272
+ putIfAbsent(key, value) {
273
+ validateLogicalKey("memoryBackend", key);
274
+ if (entries.has(key)) return false;
275
+ entries.set(key, cloneBytes(value));
276
+ bump(key);
277
+ return true;
278
+ },
279
+ getVersioned(key) {
280
+ validateLogicalKey("memoryBackend", key);
281
+ const value = entries.get(key);
282
+ const generation = memoryGeneration(epoch, key, versionOf(key));
283
+ if (value === void 0) return { kind: "miss", generation };
284
+ return { kind: "hit", value: cloneBytes(value), generation };
285
+ },
286
+ setIfMatch(key, value, generation) {
287
+ validateLogicalKey("memoryBackend", key);
288
+ const observed = readMemoryGeneration(generation);
289
+ if (observed === void 0 || observed[0] !== epoch || observed[1] !== key || observed[2] !== versionOf(key)) {
290
+ return false;
291
+ }
292
+ entries.set(key, cloneBytes(value));
293
+ bump(key);
294
+ return true;
295
+ },
296
+ delete(key) {
297
+ validateLogicalKey("memoryBackend", key);
298
+ if (entries.delete(key)) bump(key);
299
+ },
300
+ list(prefix = "") {
301
+ const validatedPrefix = validateListPrefix("memoryBackend", prefix);
302
+ return [...entries.keys()].filter((key) => key.startsWith(validatedPrefix)).sort();
303
+ },
304
+ clear() {
305
+ entries.clear();
306
+ versions.clear();
307
+ epoch += 1;
308
+ }
309
+ };
310
+ }
311
+
312
+ // src/json/codec.ts
313
+ var JS_MIN_NORMAL_NUMBER = 2 ** -1022;
314
+ function assertStableJsonNumber(value, path) {
315
+ if (!Number.isFinite(value)) {
316
+ throw new TypeError(`stableJsonString: non-finite number at ${path}`);
317
+ }
318
+ }
319
+ function assertStrictJsonNumber(value, path) {
320
+ assertStableJsonNumber(value, path);
321
+ if (Object.is(value, -0)) {
322
+ throw new TypeError(`stableJsonString: non-canonical number at ${path}`);
323
+ }
324
+ const abs = Math.abs(value);
325
+ if (abs > 0 && abs < JS_MIN_NORMAL_NUMBER) {
326
+ throw new TypeError(`stableJsonString: subnormal number at ${path}`);
327
+ }
328
+ if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
329
+ throw new TypeError(`stableJsonString: integer outside safe range at ${path}`);
330
+ }
331
+ }
332
+ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", strictNumbers = false) {
333
+ if (value === null) return null;
334
+ if (typeof value === "string" || typeof value === "boolean") return value;
335
+ if (typeof value === "number") {
336
+ if (strictNumbers) assertStrictJsonNumber(value, path);
337
+ else assertStableJsonNumber(value, path);
338
+ return value;
339
+ }
340
+ if (typeof value !== "object") {
341
+ throw new TypeError(`stableJsonString: value at ${path} is not JSON-encodable`);
342
+ }
343
+ if (seen.has(value)) throw new TypeError(`stableJsonString: circular reference at ${path}`);
344
+ const proto = Object.getPrototypeOf(value);
345
+ if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {
346
+ throw new TypeError(`stableJsonString: non-plain object at ${path}`);
347
+ }
348
+ seen.add(value);
349
+ try {
350
+ if (Array.isArray(value)) {
351
+ if (Object.getOwnPropertySymbols(value).length > 0) {
352
+ throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
353
+ }
354
+ for (const key of Object.getOwnPropertyNames(value)) {
355
+ const isIndex = /^(0|[1-9]\d*)$/.test(key) && Number.isSafeInteger(Number(key)) && Number(key) < value.length;
356
+ if (key !== "length" && !isIndex) {
357
+ throw new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);
358
+ }
359
+ }
360
+ const out2 = [];
361
+ for (let i = 0; i < value.length; i += 1) {
362
+ if (!(i in value)) {
363
+ throw new TypeError(`stableJsonString: sparse array hole at ${path}[${i}]`);
364
+ }
365
+ out2.push(sortedJsonValue(value[i], seen, `${path}[${i}]`, strictNumbers));
366
+ }
367
+ return out2;
368
+ }
369
+ if (Object.getOwnPropertySymbols(value).length > 0) {
370
+ throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
371
+ }
372
+ const out = /* @__PURE__ */ Object.create(null);
373
+ for (const key of Object.keys(value).sort()) {
374
+ out[key] = sortedJsonValue(
375
+ value[key],
376
+ seen,
377
+ `${path}.${key}`,
378
+ strictNumbers
379
+ );
380
+ }
381
+ return out;
382
+ } finally {
383
+ seen.delete(value);
384
+ }
385
+ }
386
+ function stableJsonString(value) {
387
+ return JSON.stringify(sortedJsonValue(value));
388
+ }
389
+ function strictStableJsonString(value) {
390
+ return JSON.stringify(sortedJsonValue(value, /* @__PURE__ */ new Set(), "$", true));
391
+ }
392
+ function jsonCodecFor() {
393
+ const encoder = new TextEncoder();
394
+ const decoder = new TextDecoder();
395
+ return {
396
+ encode(value) {
397
+ return encoder.encode(stableJsonString(value));
398
+ },
399
+ decode(bytes) {
400
+ return JSON.parse(decoder.decode(bytes));
401
+ }
402
+ };
403
+ }
404
+ var jsonCodec = jsonCodecFor();
405
+ function bytesEqual(a, b) {
406
+ if (a.byteLength !== b.byteLength) return false;
407
+ for (let i = 0; i < a.byteLength; i += 1) {
408
+ if (a[i] !== b[i]) return false;
409
+ }
410
+ return true;
411
+ }
412
+ function hasUnpairedSurrogate(value) {
413
+ for (let i = 0; i < value.length; i += 1) {
414
+ const code = value.charCodeAt(i);
415
+ if (code >= 55296 && code <= 56319) {
416
+ const next = value.charCodeAt(i + 1);
417
+ if (next >= 56320 && next <= 57343) {
418
+ i += 1;
419
+ continue;
420
+ }
421
+ return true;
422
+ }
423
+ if (code >= 56320 && code <= 57343) return true;
424
+ }
425
+ return false;
426
+ }
427
+ function assertNoUnpairedSurrogates(value, seen = /* @__PURE__ */ new Set(), path = "$") {
428
+ if (typeof value === "string") {
429
+ if (hasUnpairedSurrogate(value)) {
430
+ throw new TypeError(`strictJsonCodec: unpaired surrogate at ${path}`);
431
+ }
432
+ return;
433
+ }
434
+ if (value === null || typeof value !== "object") return;
435
+ if (seen.has(value)) return;
436
+ seen.add(value);
437
+ try {
438
+ if (Array.isArray(value)) {
439
+ for (let i = 0; i < value.length; i += 1) {
440
+ assertNoUnpairedSurrogates(value[i], seen, `${path}[${i}]`);
441
+ }
442
+ return;
443
+ }
444
+ for (const key of Object.keys(value)) {
445
+ if (hasUnpairedSurrogate(key)) {
446
+ throw new TypeError(`strictJsonCodec: unpaired surrogate at ${path}.${key}`);
447
+ }
448
+ assertNoUnpairedSurrogates(value[key], seen, `${path}.${key}`);
449
+ }
450
+ } finally {
451
+ seen.delete(value);
452
+ }
453
+ }
454
+ function assertNoDuplicateJsonObjectKeys(text) {
455
+ let index = 0;
456
+ function fail(message) {
457
+ throw new TypeError(`strictJsonCodec: ${message}`);
458
+ }
459
+ function skipWhitespace() {
460
+ while (/\s/.test(text[index] ?? "")) index += 1;
461
+ }
462
+ function readJsonString() {
463
+ const start = index;
464
+ index += 1;
465
+ while (index < text.length) {
466
+ const ch = text[index];
467
+ if (ch === '"') {
468
+ index += 1;
469
+ try {
470
+ return JSON.parse(text.slice(start, index));
471
+ } catch {
472
+ fail("malformed JSON string");
473
+ }
474
+ }
475
+ if (ch === "\\") {
476
+ index += 2;
477
+ continue;
478
+ }
479
+ index += 1;
480
+ }
481
+ fail("unterminated JSON string");
482
+ }
483
+ function consumeLiteral(literal) {
484
+ if (text.slice(index, index + literal.length) !== literal) {
485
+ fail(`malformed JSON near byte ${index}`);
486
+ }
487
+ index += literal.length;
488
+ }
489
+ function consumeNumber() {
490
+ const match = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/.exec(text.slice(index));
491
+ if (!match) fail(`malformed JSON number near byte ${index}`);
492
+ index += match[0].length;
493
+ }
494
+ function parseValue(path) {
495
+ skipWhitespace();
496
+ const ch = text[index];
497
+ if (ch === "{") {
498
+ parseObject(path);
499
+ return;
500
+ }
501
+ if (ch === "[") {
502
+ parseArray(path);
503
+ return;
504
+ }
505
+ if (ch === '"') {
506
+ readJsonString();
507
+ return;
508
+ }
509
+ if (ch === "t") {
510
+ consumeLiteral("true");
511
+ return;
512
+ }
513
+ if (ch === "f") {
514
+ consumeLiteral("false");
515
+ return;
516
+ }
517
+ if (ch === "n") {
518
+ consumeLiteral("null");
519
+ return;
520
+ }
521
+ if (ch === "-" || ch !== void 0 && ch >= "0" && ch <= "9") {
522
+ consumeNumber();
523
+ return;
524
+ }
525
+ fail(`malformed JSON near byte ${index}`);
526
+ }
527
+ function parseObject(path) {
528
+ const keys = /* @__PURE__ */ new Set();
529
+ index += 1;
530
+ skipWhitespace();
531
+ if (text[index] === "}") {
532
+ index += 1;
533
+ return;
534
+ }
535
+ while (index < text.length) {
536
+ skipWhitespace();
537
+ if (text[index] !== '"') fail(`expected object key near byte ${index}`);
538
+ const key = readJsonString();
539
+ if (keys.has(key)) {
540
+ throw new TypeError(
541
+ `strictJsonCodec: duplicate object key ${JSON.stringify(key)} at ${path}`
542
+ );
543
+ }
544
+ keys.add(key);
545
+ skipWhitespace();
546
+ if (text[index] !== ":") fail(`expected ':' after object key near byte ${index}`);
547
+ index += 1;
548
+ parseValue(`${path}.${key}`);
549
+ skipWhitespace();
550
+ if (text[index] === ",") {
551
+ index += 1;
552
+ continue;
553
+ }
554
+ if (text[index] === "}") {
555
+ index += 1;
556
+ return;
557
+ }
558
+ fail(`expected ',' or '}' near byte ${index}`);
559
+ }
560
+ fail("unterminated JSON object");
561
+ }
562
+ function parseArray(path) {
563
+ index += 1;
564
+ skipWhitespace();
565
+ if (text[index] === "]") {
566
+ index += 1;
567
+ return;
568
+ }
569
+ let item = 0;
570
+ while (index < text.length) {
571
+ parseValue(`${path}[${item}]`);
572
+ item += 1;
573
+ skipWhitespace();
574
+ if (text[index] === ",") {
575
+ index += 1;
576
+ continue;
577
+ }
578
+ if (text[index] === "]") {
579
+ index += 1;
580
+ return;
581
+ }
582
+ fail(`expected ',' or ']' near byte ${index}`);
583
+ }
584
+ fail("unterminated JSON array");
585
+ }
586
+ parseValue("$");
587
+ skipWhitespace();
588
+ if (index !== text.length) fail(`trailing JSON token near byte ${index}`);
589
+ }
590
+ function strictJsonCodecFor() {
591
+ const encoder = new TextEncoder();
592
+ const decoder = new TextDecoder("utf-8", { fatal: true });
593
+ return {
594
+ encode(value) {
595
+ assertNoUnpairedSurrogates(value);
596
+ return encoder.encode(strictStableJsonString(value));
597
+ },
598
+ decode(bytes) {
599
+ const text = decoder.decode(bytes);
600
+ assertNoDuplicateJsonObjectKeys(text);
601
+ const decoded = JSON.parse(text);
602
+ assertNoUnpairedSurrogates(decoded);
603
+ const canonical = encoder.encode(strictStableJsonString(decoded));
604
+ if (!bytesEqual(bytes, canonical)) {
605
+ throw new TypeError("strictJsonCodec: bytes are not canonical stable JSON");
606
+ }
607
+ return decoded;
608
+ }
609
+ };
610
+ }
611
+ var strictJsonCodec = strictJsonCodecFor();
612
+ function strictCanonicalJsonBytes(value) {
613
+ return strictJsonCodec.encode(value);
614
+ }
615
+ function assertStrictJsonValue(value, label = "strictJsonValue") {
616
+ try {
617
+ return strictJsonCodec.decode(strictJsonCodec.encode(value));
618
+ } catch (cause) {
619
+ const message = cause instanceof Error ? cause.message : String(cause);
620
+ throw new TypeError(`${label}: value is not strict JSON compatible: ${message}`, { cause });
621
+ }
622
+ }
623
+ function assertStrictJsonObject(value, label = "strictJsonObject") {
624
+ const normalized = assertStrictJsonValue(value, label);
625
+ if (normalized === null || typeof normalized !== "object" || Array.isArray(normalized)) {
626
+ throw new TypeError(`${label}: value must be a strict JSON object`);
627
+ }
628
+ return normalized;
629
+ }
630
+
631
+ // src/storage/kv.ts
632
+ function hasKvPutIfAbsent(tier) {
633
+ return typeof tier.putIfAbsent === "function";
634
+ }
635
+ function requireKvPutIfAbsent(tier, label = "kvStorage") {
636
+ if (!hasKvPutIfAbsent(tier)) {
637
+ throw new Error(`${label}: KV tier does not support putIfAbsent`);
638
+ }
639
+ return tier;
640
+ }
641
+ function hasKvVersioned(tier) {
642
+ return typeof tier.getVersioned === "function" && typeof tier.setIfMatch === "function";
643
+ }
644
+ function requireKvVersioned(tier, label = "kvStorage") {
645
+ if (!hasKvVersioned(tier)) {
646
+ throw new Error(`${label}: KV tier does not support versioned get/set-if-match`);
647
+ }
648
+ return tier;
649
+ }
650
+ function defer(fn) {
651
+ return Promise.resolve().then(fn);
652
+ }
653
+ function kvStorage(opts) {
654
+ const codec = opts.codec ?? jsonCodecFor();
655
+ const { backend } = opts;
656
+ const tier = {
657
+ get(key) {
658
+ return defer(() => backend.get(key)).then(
659
+ (bytes) => bytes === void 0 ? void 0 : codec.decode(bytes)
660
+ );
661
+ },
662
+ set(key, value) {
663
+ return defer(() => backend.put(key, codec.encode(value))).then(() => void 0);
664
+ },
665
+ delete(key) {
666
+ return defer(() => backend.delete?.(key)).then(() => void 0);
667
+ },
668
+ list(prefix = "") {
669
+ return defer(() => {
670
+ if (!backend.list) throw new Error("kvStorage.list: backend does not support listing");
671
+ return backend.list(prefix);
672
+ }).then((keys) => [...keys].sort());
673
+ }
674
+ };
675
+ let out = tier;
676
+ if (hasStoragePutIfAbsent(backend)) {
677
+ out = {
678
+ ...out,
679
+ putIfAbsent(key, value) {
680
+ return defer(() => backend.putIfAbsent(key, codec.encode(value)));
681
+ }
682
+ };
683
+ }
684
+ if (hasStorageVersioned(backend)) {
685
+ out = {
686
+ ...out,
687
+ getVersioned(key) {
688
+ return defer(() => backend.getVersioned(key)).then((result) => {
689
+ if (result.kind === "miss") return { kind: "miss", generation: result.generation };
690
+ return {
691
+ kind: "hit",
692
+ value: codec.decode(result.value),
693
+ generation: result.generation
694
+ };
695
+ });
696
+ },
697
+ setIfMatch(key, value, generation) {
698
+ return defer(() => backend.setIfMatch(key, codec.encode(value), generation));
699
+ }
700
+ };
701
+ }
702
+ return out;
703
+ }
704
+ function memoryKv(codec = jsonCodecFor()) {
705
+ return kvStorage({ backend: memoryBackend(), codec });
706
+ }
707
+ function dictKv(entries = {}, codec = jsonCodecFor()) {
708
+ const backend = memoryBackend();
709
+ const kv = kvStorage({ backend, codec });
710
+ for (const [key, value] of Object.entries(entries)) {
711
+ backend.put(key, codec.encode(value));
712
+ }
713
+ return kv;
714
+ }
715
+ function listByPrefix2(tier, prefix = "") {
716
+ return tier.list(prefix);
717
+ }
718
+
719
+ // src/storage/append-log.ts
720
+ var APPEND_LOG_SEQ_PAD = 20;
721
+ function appendLogKey(prefix, seq) {
722
+ if (!Number.isSafeInteger(seq) || seq < 0) {
723
+ throw new RangeError(`appendLogKey: seq must be a non-negative safe integer, got ${seq}`);
724
+ }
725
+ return `${prefix}/${seq.toString().padStart(APPEND_LOG_SEQ_PAD, "0")}`;
726
+ }
727
+ function seqFromKey(prefix, key) {
728
+ const head = `${prefix}/`;
729
+ if (!key.startsWith(head)) throw new Error(`append log key outside prefix: ${key}`);
730
+ const raw = key.slice(head.length);
731
+ if (!/^\d+$/.test(raw)) {
732
+ throw new Error(`append log key has a non-numeric sequence: ${key}`);
733
+ }
734
+ if (raw.length !== APPEND_LOG_SEQ_PAD) {
735
+ throw new Error(`append log key sequence must be ${APPEND_LOG_SEQ_PAD} padded digits: ${key}`);
736
+ }
737
+ const seq = Number(raw);
738
+ if (!Number.isSafeInteger(seq)) {
739
+ throw new Error(`append log key sequence is outside the safe integer range: ${key}`);
740
+ }
741
+ return seq;
742
+ }
743
+ function nextSeqFromKeys(prefix, keys) {
744
+ if (keys.length === 0) return 0;
745
+ const next = Math.max(...keys.map((key) => seqFromKey(prefix, key))) + 1;
746
+ if (!Number.isSafeInteger(next)) {
747
+ throw new RangeError(`append log next sequence is outside the safe integer range: ${prefix}`);
748
+ }
749
+ return next;
750
+ }
751
+ function sizeFromKeys(prefix, keys) {
752
+ for (const key of keys) seqFromKey(prefix, key);
753
+ return keys.length;
754
+ }
755
+ function validateReadOptions(opts) {
756
+ const after = opts.after ?? -1;
757
+ const limit = opts.limit ?? Number.POSITIVE_INFINITY;
758
+ if (!Number.isSafeInteger(after) || after < -1) {
759
+ throw new RangeError(
760
+ `appendLogStorage.read: after must be an integer cursor >= -1, got ${after}`
761
+ );
762
+ }
763
+ if (limit !== Number.POSITIVE_INFINITY && (!Number.isSafeInteger(limit) || limit < 0)) {
764
+ throw new RangeError(
765
+ `appendLogStorage.read: limit must be a non-negative safe integer or Infinity, got ${limit}`
766
+ );
767
+ }
768
+ return { after, limit };
769
+ }
770
+ function validatePageLimit(limit) {
771
+ if (!Number.isSafeInteger(limit) || limit < 1) {
772
+ throw new RangeError(`readAppendLogPage: limit must be a positive safe integer, got ${limit}`);
773
+ }
774
+ if (limit >= Number.MAX_SAFE_INTEGER) {
775
+ throw new RangeError("readAppendLogPage: limit must leave room for one lookahead entry");
776
+ }
777
+ return limit;
778
+ }
779
+ function readAppendLogEntries(kv, prefix, opts) {
780
+ const { after, limit } = validateReadOptions(opts);
781
+ return kv.list(`${prefix}/`).then((listed) => {
782
+ const keys = listed.map((key) => ({ key, seq: seqFromKey(prefix, key) })).filter(({ seq }) => seq > after).sort((a, b) => a.seq - b.seq).slice(0, limit);
783
+ return Promise.all(
784
+ keys.map(
785
+ ({ key, seq }) => kv.get(key).then((value) => {
786
+ if (value === void 0) {
787
+ throw new Error(`append log listed key is missing: ${key}`);
788
+ }
789
+ return { key, seq, value };
790
+ })
791
+ )
792
+ ).then((entries) => {
793
+ const out = [];
794
+ for (const entry of entries) if (entry !== void 0) out.push(entry);
795
+ return out;
796
+ });
797
+ });
798
+ }
799
+ function readAppendLogPage(log, opts = {}) {
800
+ const { after, limit } = validateReadOptions({ after: opts.after, limit: opts.limit ?? 100 });
801
+ const pageLimit = validatePageLimit(limit);
802
+ return log.read({ after, limit: pageLimit + 1 }).then((entries) => {
803
+ const visible = entries.slice(0, pageLimit);
804
+ const last = visible[visible.length - 1];
805
+ return {
806
+ entries: visible,
807
+ nextAfter: last?.seq ?? after,
808
+ done: entries.length <= pageLimit
809
+ };
810
+ });
811
+ }
812
+ function deleteAppendLogEntriesAfter(kv, prefix, seq) {
813
+ return kv.list(`${prefix}/`).then(
814
+ (keys) => Promise.all(keys.filter((key) => seqFromKey(prefix, key) > seq).map((key) => kv.delete(key)))
815
+ ).then(() => kv.list(`${prefix}/`)).then(() => void 0);
816
+ }
817
+ function appendLogStorage(opts) {
818
+ const { kv, prefix = "event-log" } = opts;
819
+ let tail = Promise.resolve();
820
+ function initNextSeq() {
821
+ return kv.list(`${prefix}/`).then((keys) => {
822
+ return nextSeqFromKeys(prefix, keys);
823
+ });
824
+ }
825
+ function enqueue(task) {
826
+ const run = tail.then(task, task);
827
+ tail = run.then(
828
+ () => void 0,
829
+ () => void 0
830
+ );
831
+ return run;
832
+ }
833
+ return {
834
+ append(value) {
835
+ return enqueue(
836
+ () => initNextSeq().then((seq) => {
837
+ const key = appendLogKey(prefix, seq);
838
+ return kv.set(key, value).then(() => {
839
+ return { key, seq, value };
840
+ });
841
+ })
842
+ );
843
+ },
844
+ read(opts2 = {}) {
845
+ return enqueue(() => readAppendLogEntries(kv, prefix, opts2));
846
+ },
847
+ truncateAfter(seq) {
848
+ return enqueue(() => deleteAppendLogEntriesAfter(kv, prefix, seq));
849
+ },
850
+ size() {
851
+ return enqueue(() => kv.list(`${prefix}/`).then((keys) => sizeFromKeys(prefix, keys)));
852
+ }
853
+ };
854
+ }
855
+ function multiWriterAppendLogStorage(opts) {
856
+ const { kv, prefix = "event-log", maxAttempts = 1024 } = opts;
857
+ const capableKv = requireKvPutIfAbsent(kv, "multiWriterAppendLogStorage");
858
+ let tail = Promise.resolve();
859
+ if (!Number.isSafeInteger(maxAttempts) || maxAttempts < 1) {
860
+ throw new RangeError(
861
+ `multiWriterAppendLogStorage: maxAttempts must be a positive safe integer, got ${maxAttempts}`
862
+ );
863
+ }
864
+ function initNextSeq() {
865
+ return kv.list(`${prefix}/`).then((keys) => nextSeqFromKeys(prefix, keys));
866
+ }
867
+ function enqueue(task) {
868
+ const run = tail.then(task, task);
869
+ tail = run.then(
870
+ () => void 0,
871
+ () => void 0
872
+ );
873
+ return run;
874
+ }
875
+ return {
876
+ append(value) {
877
+ return enqueue(
878
+ () => initNextSeq().then((startSeq) => {
879
+ let seq = startSeq;
880
+ let attempt = 0;
881
+ const tryNext = () => {
882
+ if (attempt >= maxAttempts) {
883
+ return initNextSeq().then((refreshedSeq) => {
884
+ seq = Math.max(seq, refreshedSeq);
885
+ attempt = 0;
886
+ return tryNext();
887
+ });
888
+ }
889
+ attempt += 1;
890
+ const key = appendLogKey(prefix, seq);
891
+ return capableKv.putIfAbsent(key, value).then((created) => {
892
+ if (created) return { key, seq, value };
893
+ seq += 1;
894
+ if (!Number.isSafeInteger(seq)) {
895
+ throw new RangeError(
896
+ `append log next sequence is outside the safe integer range: ${prefix}`
897
+ );
898
+ }
899
+ return tryNext();
900
+ });
901
+ };
902
+ return tryNext();
903
+ })
904
+ );
905
+ },
906
+ read(opts2 = {}) {
907
+ return enqueue(() => readAppendLogEntries(kv, prefix, opts2));
908
+ },
909
+ truncateAfter(seq) {
910
+ return enqueue(() => {
911
+ if (!Number.isSafeInteger(seq) || seq < -1) {
912
+ throw new RangeError(
913
+ `multiWriterAppendLogStorage.truncateAfter: seq must be an integer cursor >= -1, got ${seq}`
914
+ );
915
+ }
916
+ throw new Error(
917
+ "multiWriterAppendLogStorage.truncateAfter: unsupported without a stronger compaction capability"
918
+ );
919
+ });
920
+ },
921
+ size() {
922
+ return enqueue(() => kv.list(`${prefix}/`).then((keys) => sizeFromKeys(prefix, keys)));
923
+ }
924
+ };
925
+ }
926
+ function memoryAppendLog(prefix) {
927
+ return appendLogStorage({ kv: memoryKv(), prefix });
928
+ }
929
+ function memoryMultiWriterAppendLog(prefix) {
930
+ return multiWriterAppendLogStorage({ kv: memoryKv(), prefix });
931
+ }
932
+
933
+ // src/storage/scalar.ts
934
+ var DECIMAL_INTEGER_RE = /^(0|-?[1-9]\d*)$/;
935
+ var NON_NEGATIVE_DECIMAL_INTEGER_RE = /^(0|[1-9]\d*)$/;
936
+ function isDecimalIntegerString(value) {
937
+ return typeof value === "string" && DECIMAL_INTEGER_RE.test(value);
938
+ }
939
+ function isNonNegativeDecimalIntegerString(value) {
940
+ return typeof value === "string" && NON_NEGATIVE_DECIMAL_INTEGER_RE.test(value);
941
+ }
942
+ function assertDecimalIntegerString(value, label = "decimal integer") {
943
+ if (!isDecimalIntegerString(value)) {
944
+ throw new TypeError(`${label} must be a canonical decimal integer string`);
945
+ }
946
+ return value;
947
+ }
948
+ function assertNonNegativeDecimalIntegerString(value, label = "decimal integer") {
949
+ if (!isNonNegativeDecimalIntegerString(value)) {
950
+ throw new TypeError(`${label} must be a canonical non-negative decimal integer string`);
951
+ }
952
+ return value;
953
+ }
954
+ function bigIntToDecimalString(value) {
955
+ return value.toString();
956
+ }
957
+ function bigIntToNonNegativeDecimalString(value) {
958
+ if (value < 0n) {
959
+ throw new TypeError("decimal integer must be non-negative");
960
+ }
961
+ return value.toString();
962
+ }
963
+ function decimalStringToBigInt(value) {
964
+ return BigInt(assertDecimalIntegerString(value));
965
+ }
966
+ function nonNegativeDecimalStringToBigInt(value) {
967
+ return BigInt(assertNonNegativeDecimalIntegerString(value));
968
+ }
969
+
970
+ // src/storage/change.ts
971
+ function nowNs() {
972
+ return bigIntToNonNegativeDecimalString(BigInt(Date.now()) * 1000000n);
973
+ }
974
+ function envelopeChange(change, opts) {
975
+ const envelope = {
976
+ lifecycle: opts.lifecycle ?? "data",
977
+ structure: opts.structure,
978
+ version: opts.version ?? 1,
979
+ t_ns: opts.t_ns ?? nowNs(),
980
+ ...opts.seq === void 0 ? {} : { seq: opts.seq },
981
+ change
982
+ };
983
+ return assertChangeEnvelope(envelope);
984
+ }
985
+ function isRecord(value) {
986
+ return value !== null && typeof value === "object" && !Array.isArray(value);
987
+ }
988
+ function isLifecycle(value) {
989
+ return value === "spec" || value === "data" || value === "ownership";
990
+ }
991
+ function assertChangeEnvelope(value) {
992
+ if (!isRecord(value)) throw new TypeError("changeEnvelopeCodec: frame must be an object");
993
+ if (!isLifecycle(value.lifecycle)) {
994
+ throw new TypeError("changeEnvelopeCodec: lifecycle must be spec, data, or ownership");
995
+ }
996
+ if (typeof value.structure !== "string" || value.structure.length === 0) {
997
+ throw new TypeError("changeEnvelopeCodec: structure must be a non-empty string");
998
+ }
999
+ if ((typeof value.version !== "number" || !Number.isFinite(value.version)) && typeof value.version !== "string") {
1000
+ throw new TypeError("changeEnvelopeCodec: version must be a finite number or string");
1001
+ }
1002
+ assertNonNegativeDecimalIntegerString(value.t_ns, "changeEnvelopeCodec: t_ns");
1003
+ if (value.seq !== void 0 && (!Number.isSafeInteger(value.seq) || value.seq < 0)) {
1004
+ throw new TypeError(
1005
+ "changeEnvelopeCodec: seq must be a non-negative safe integer when present"
1006
+ );
1007
+ }
1008
+ if (!Object.hasOwn(value, "change")) {
1009
+ throw new TypeError("changeEnvelopeCodec: change payload is required");
1010
+ }
1011
+ return value;
1012
+ }
1013
+ function changeEnvelopeCodec() {
1014
+ const codec = strictJsonCodecFor();
1015
+ return {
1016
+ encode(value) {
1017
+ return codec.encode(assertChangeEnvelope(value));
1018
+ },
1019
+ decode(bytes) {
1020
+ return assertChangeEnvelope(codec.decode(bytes));
1021
+ }
1022
+ };
1023
+ }
1024
+
1025
+ // src/storage/content-addressed.ts
1026
+ var ContentAddressedMissError = class extends Error {
1027
+ key;
1028
+ context;
1029
+ constructor(key, context) {
1030
+ super(`content-addressed lookup miss in read-strict mode: ${key}`);
1031
+ this.name = "ContentAddressedMissError";
1032
+ this.key = key;
1033
+ this.context = context;
1034
+ }
1035
+ };
1036
+ var SHA_256 = "SHA-256";
1037
+ var HEX_TABLE2 = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
1038
+ function bytesToHex(bytes) {
1039
+ let out = "";
1040
+ for (const byte of bytes) out += HEX_TABLE2[byte];
1041
+ return out;
1042
+ }
1043
+ function sha256Hex(data) {
1044
+ const digestInput = Uint8Array.from(data);
1045
+ return globalThis.crypto.subtle.digest(SHA_256, digestInput).then((buf) => bytesToHex(new Uint8Array(buf)));
1046
+ }
1047
+ function contentAddressedKv(opts) {
1048
+ const { kv, keyContext, keyPrefix, mode = "read-write" } = opts;
1049
+ const contextForKey = keyContext ?? ((ctx) => ctx);
1050
+ function keyFor(ctx) {
1051
+ let bytes;
1052
+ try {
1053
+ bytes = strictCanonicalJsonBytes(contextForKey(ctx));
1054
+ } catch (err) {
1055
+ return Promise.resolve().then(() => {
1056
+ throw err;
1057
+ });
1058
+ }
1059
+ return Promise.resolve().then(() => sha256Hex(bytes)).then((hex) => keyPrefix ? `${keyPrefix}:${hex}` : hex);
1060
+ }
1061
+ return {
1062
+ keyFor,
1063
+ lookup(ctx) {
1064
+ if (mode === "write") return Promise.resolve(void 0);
1065
+ return keyFor(ctx).then(
1066
+ (key) => kv.get(key).then((value) => {
1067
+ if (value === void 0 && mode === "read-strict") {
1068
+ throw new ContentAddressedMissError(key, ctx);
1069
+ }
1070
+ return value;
1071
+ })
1072
+ );
1073
+ },
1074
+ store(ctx, value) {
1075
+ if (mode === "read") return Promise.resolve();
1076
+ return keyFor(ctx).then((key) => kv.set(key, value));
1077
+ },
1078
+ forget(ctx) {
1079
+ if (mode === "read" || mode === "write") return Promise.resolve();
1080
+ return keyFor(ctx).then((key) => kv.delete(key));
1081
+ }
1082
+ };
1083
+ }
1084
+ function contentAddressedStorage(opts) {
1085
+ return contentAddressedKv(opts);
1086
+ }
1087
+
1088
+ // src/storage/observe-event-log.ts
1089
+ function observeEventFrame(event, value, opts = {}) {
1090
+ return {
1091
+ ...envelopeChange(value, {
1092
+ lifecycle: "data",
1093
+ structure: "observe-event",
1094
+ version: 1,
1095
+ seq: event.seq
1096
+ }),
1097
+ structure: "observe-event",
1098
+ observeSeq: event.seq,
1099
+ path: event.path,
1100
+ ...opts.stream === void 0 ? {} : { stream: opts.stream }
1101
+ };
1102
+ }
1103
+ function assertObserveEventFrame(value) {
1104
+ const frame = assertChangeEnvelope(value);
1105
+ const record = frame;
1106
+ if (frame.structure !== "observe-event") {
1107
+ throw new TypeError("observeEventFrameCodec: structure must be observe-event");
1108
+ }
1109
+ if (!Number.isSafeInteger(record.observeSeq) || record.observeSeq < 0) {
1110
+ throw new TypeError("observeEventFrameCodec: observeSeq must be a non-negative safe integer");
1111
+ }
1112
+ if (typeof record.path !== "string") {
1113
+ throw new TypeError("observeEventFrameCodec: path must be a string");
1114
+ }
1115
+ if (record.stream !== void 0 && typeof record.stream !== "string") {
1116
+ throw new TypeError("observeEventFrameCodec: stream must be a string when present");
1117
+ }
1118
+ return frame;
1119
+ }
1120
+ function observeEventFrameCodec() {
1121
+ const codec = strictJsonCodecFor();
1122
+ return {
1123
+ encode(value) {
1124
+ return codec.encode(assertObserveEventFrame(value));
1125
+ },
1126
+ decode(bytes) {
1127
+ return assertObserveEventFrame(codec.decode(bytes));
1128
+ }
1129
+ };
1130
+ }
1131
+ function readObserveEventLogPage(log, opts = {}) {
1132
+ return readAppendLogPage(log, opts);
1133
+ }
1134
+
1135
+ // src/storage/reactive-collection.ts
1136
+ var REACTIVE_COLLECTION_SNAPSHOT_FORMAT = "graphrefly.reactive-collection.snapshot.v1";
1137
+ var REACTIVE_COLLECTION_CHANGE_FORMAT = "graphrefly.reactive-collection.change.v1";
1138
+ var REACTIVE_COLLECTION_FRAME_VERSION = 1;
1139
+ function isRecord2(value) {
1140
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1141
+ }
1142
+ function ownKeys(value) {
1143
+ return Object.keys(value).sort();
1144
+ }
1145
+ function assertKeys(value, expected, label) {
1146
+ const actual = ownKeys(value);
1147
+ const want = [...expected].sort();
1148
+ if (actual.length !== want.length || actual.some((key, i) => key !== want[i])) {
1149
+ throw new TypeError(`${label}: unexpected frame fields ${actual.join(",")}`);
1150
+ }
1151
+ }
1152
+ function assertSafeInteger(value, label, min = 0) {
1153
+ if (!Number.isSafeInteger(value) || value < min) {
1154
+ throw new TypeError(`${label} must be a safe integer >= ${min}`);
1155
+ }
1156
+ return value;
1157
+ }
1158
+ function assertKind(value, expected, label) {
1159
+ if (value !== expected) throw new TypeError(`${label}: kind must be ${expected}`);
1160
+ return expected;
1161
+ }
1162
+ function assertArray(value, label) {
1163
+ if (!Array.isArray(value)) throw new TypeError(`${label}: snapshot must be an array`);
1164
+ return value;
1165
+ }
1166
+ function strictJsonIdentity(value) {
1167
+ return Array.from(strictCanonicalJsonBytes(value)).join(",");
1168
+ }
1169
+ function assertEntryArray(value, label) {
1170
+ const entries = assertArray(value, label);
1171
+ const seen = /* @__PURE__ */ new Set();
1172
+ for (const [i, entry] of entries.entries()) {
1173
+ if (!Array.isArray(entry) || entry.length !== 2) {
1174
+ throw new TypeError(`${label}: entry ${i} must be [key,value]`);
1175
+ }
1176
+ const key = strictJsonIdentity(entry[0]);
1177
+ if (seen.has(key)) throw new TypeError(`${label}: entry ${i} duplicates an earlier key`);
1178
+ seen.add(key);
1179
+ }
1180
+ return entries;
1181
+ }
1182
+ function assertIndexRows(value, label) {
1183
+ const rows = assertArray(value, label);
1184
+ const seen = /* @__PURE__ */ new Set();
1185
+ for (const [i, row] of rows.entries()) {
1186
+ if (!isRecord2(row)) throw new TypeError(`${label}: row ${i} must be an object`);
1187
+ assertKeys(row, ["primary", "secondary", "value"], `${label} row`);
1188
+ const primary = strictJsonIdentity(row.primary);
1189
+ if (seen.has(primary)) {
1190
+ throw new TypeError(`${label}: row ${i} duplicates an earlier primary`);
1191
+ }
1192
+ seen.add(primary);
1193
+ }
1194
+ return rows;
1195
+ }
1196
+ function collectionSnapshotKey(storagePrefix = "reactive-collection") {
1197
+ if (storagePrefix.length === 0) throw new TypeError("storagePrefix must be non-empty");
1198
+ return `${storagePrefix}/snapshot`;
1199
+ }
1200
+ function reactiveCollectionSnapshotFrame(kind, snapshot, opts = {}) {
1201
+ const changeCursor = opts.changeCursor ?? -1;
1202
+ if (!Number.isSafeInteger(changeCursor) || changeCursor < -1) {
1203
+ throw new RangeError("reactive collection snapshot changeCursor must be a safe integer >= -1");
1204
+ }
1205
+ return {
1206
+ format: REACTIVE_COLLECTION_SNAPSHOT_FORMAT,
1207
+ version: REACTIVE_COLLECTION_FRAME_VERSION,
1208
+ kind,
1209
+ changeCursor,
1210
+ snapshot
1211
+ };
1212
+ }
1213
+ function reactiveCollectionChangeFrame(kind, change) {
1214
+ return {
1215
+ format: REACTIVE_COLLECTION_CHANGE_FORMAT,
1216
+ version: REACTIVE_COLLECTION_FRAME_VERSION,
1217
+ kind,
1218
+ change
1219
+ };
1220
+ }
1221
+ function assertReactiveCollectionSnapshotFrame(value, expectedKind) {
1222
+ if (!isRecord2(value)) throw new TypeError("reactive collection snapshot frame must be an object");
1223
+ assertKeys(value, ["changeCursor", "format", "kind", "snapshot", "version"], "snapshot frame");
1224
+ if (value.format !== REACTIVE_COLLECTION_SNAPSHOT_FORMAT) {
1225
+ throw new TypeError("snapshot frame: invalid format");
1226
+ }
1227
+ if (value.version !== REACTIVE_COLLECTION_FRAME_VERSION) {
1228
+ throw new TypeError("snapshot frame: invalid version");
1229
+ }
1230
+ assertKind(value.kind, expectedKind, "snapshot frame");
1231
+ assertSafeInteger(value.changeCursor, "snapshot frame changeCursor", -1);
1232
+ strictJsonCodecFor().encode(value);
1233
+ return value;
1234
+ }
1235
+ function assertReactiveCollectionChangeFrame(value, expectedKind) {
1236
+ if (!isRecord2(value)) throw new TypeError("reactive collection change frame must be an object");
1237
+ assertKeys(value, ["change", "format", "kind", "version"], "change frame");
1238
+ if (value.format !== REACTIVE_COLLECTION_CHANGE_FORMAT) {
1239
+ throw new TypeError("change frame: invalid format");
1240
+ }
1241
+ if (value.version !== REACTIVE_COLLECTION_FRAME_VERSION) {
1242
+ throw new TypeError("change frame: invalid version");
1243
+ }
1244
+ assertKind(value.kind, expectedKind, "change frame");
1245
+ if (!Object.hasOwn(value, "change")) throw new TypeError("change frame: change is required");
1246
+ strictJsonCodecFor().encode(value);
1247
+ return value;
1248
+ }
1249
+ function reactiveCollectionSnapshotFrameCodec(kind) {
1250
+ const codec = strictJsonCodecFor();
1251
+ return {
1252
+ encode(value) {
1253
+ return codec.encode(assertReactiveCollectionSnapshotFrame(value, kind));
1254
+ },
1255
+ decode(bytes) {
1256
+ return assertReactiveCollectionSnapshotFrame(codec.decode(bytes), kind);
1257
+ }
1258
+ };
1259
+ }
1260
+ function reactiveCollectionChangeFrameCodec(kind) {
1261
+ const codec = strictJsonCodecFor();
1262
+ return {
1263
+ encode(value) {
1264
+ return codec.encode(assertReactiveCollectionChangeFrame(value, kind));
1265
+ },
1266
+ decode(bytes) {
1267
+ return assertReactiveCollectionChangeFrame(codec.decode(bytes), kind);
1268
+ }
1269
+ };
1270
+ }
1271
+ function assertListChange(value) {
1272
+ if (!isRecord2(value) || typeof value.kind !== "string") {
1273
+ throw new TypeError("reactiveList change must be an object with kind");
1274
+ }
1275
+ switch (value.kind) {
1276
+ case "append":
1277
+ if (!Object.hasOwn(value, "value")) throw new TypeError("reactiveList append.value required");
1278
+ assertKeys(value, ["kind", "value"], "reactiveList append");
1279
+ return value;
1280
+ case "appendMany":
1281
+ assertKeys(value, ["kind", "values"], "reactiveList appendMany");
1282
+ assertArray(value.values, "reactiveList appendMany.values");
1283
+ return value;
1284
+ case "insert":
1285
+ assertKeys(value, ["index", "kind", "value"], "reactiveList insert");
1286
+ assertSafeInteger(value.index, "reactiveList insert.index", 0);
1287
+ return value;
1288
+ case "insertMany":
1289
+ assertKeys(value, ["index", "kind", "values"], "reactiveList insertMany");
1290
+ assertSafeInteger(value.index, "reactiveList insertMany.index", 0);
1291
+ assertArray(value.values, "reactiveList insertMany.values");
1292
+ return value;
1293
+ case "pop":
1294
+ assertKeys(value, ["index", "kind", "value"], "reactiveList pop");
1295
+ assertSafeInteger(value.index, "reactiveList pop.index", 0);
1296
+ return value;
1297
+ case "trimHead":
1298
+ assertKeys(value, ["kind", "n"], "reactiveList trimHead");
1299
+ assertSafeInteger(value.n, "reactiveList trimHead.n", 0);
1300
+ return value;
1301
+ case "clear":
1302
+ assertKeys(value, ["count", "kind"], "reactiveList clear");
1303
+ assertSafeInteger(value.count, "reactiveList clear.count", 0);
1304
+ return value;
1305
+ default:
1306
+ throw new TypeError(`unsupported reactiveList change kind ${value.kind}`);
1307
+ }
1308
+ }
1309
+ function assertLogChange(value) {
1310
+ if (!isRecord2(value) || typeof value.kind !== "string") {
1311
+ throw new TypeError("reactiveLog change must be an object with kind");
1312
+ }
1313
+ switch (value.kind) {
1314
+ case "append":
1315
+ if (!Object.hasOwn(value, "value")) throw new TypeError("reactiveLog append.value required");
1316
+ assertKeys(value, ["kind", "value"], "reactiveLog append");
1317
+ return value;
1318
+ case "appendMany":
1319
+ assertKeys(value, ["kind", "values"], "reactiveLog appendMany");
1320
+ assertArray(value.values, "reactiveLog appendMany.values");
1321
+ return value;
1322
+ case "trimHead":
1323
+ assertKeys(value, ["kind", "n"], "reactiveLog trimHead");
1324
+ assertSafeInteger(value.n, "reactiveLog trimHead.n", 0);
1325
+ return value;
1326
+ case "clear":
1327
+ assertKeys(value, ["count", "kind"], "reactiveLog clear");
1328
+ assertSafeInteger(value.count, "reactiveLog clear.count", 0);
1329
+ return value;
1330
+ default:
1331
+ throw new TypeError(`unsupported reactiveLog change kind ${value.kind}`);
1332
+ }
1333
+ }
1334
+ function assertMapChange(value) {
1335
+ if (!isRecord2(value) || typeof value.kind !== "string") {
1336
+ throw new TypeError("reactiveMap change must be an object with kind");
1337
+ }
1338
+ switch (value.kind) {
1339
+ case "set":
1340
+ if (!Object.hasOwn(value, "key")) throw new TypeError("reactiveMap set.key required");
1341
+ if (!Object.hasOwn(value, "value")) throw new TypeError("reactiveMap set.value required");
1342
+ assertKeys(value, ["key", "kind", "value"], "reactiveMap set");
1343
+ return value;
1344
+ case "delete":
1345
+ if (!Object.hasOwn(value, "key")) throw new TypeError("reactiveMap delete.key required");
1346
+ if (!Object.hasOwn(value, "previous")) {
1347
+ throw new TypeError("reactiveMap delete.previous required");
1348
+ }
1349
+ assertKeys(value, ["key", "kind", "previous", "reason"], "reactiveMap delete");
1350
+ if (value.reason !== "expired" && value.reason !== "lru-evict" && value.reason !== "archived" && value.reason !== "explicit") {
1351
+ throw new TypeError("reactiveMap delete.reason is invalid");
1352
+ }
1353
+ return value;
1354
+ case "clear":
1355
+ assertKeys(value, ["count", "kind"], "reactiveMap clear");
1356
+ assertSafeInteger(value.count, "reactiveMap clear.count", 0);
1357
+ return value;
1358
+ default:
1359
+ throw new TypeError(`unsupported reactiveMap change kind ${value.kind}`);
1360
+ }
1361
+ }
1362
+ function assertIndexChange(value) {
1363
+ if (!isRecord2(value) || typeof value.kind !== "string") {
1364
+ throw new TypeError("reactiveIndex change must be an object with kind");
1365
+ }
1366
+ switch (value.kind) {
1367
+ case "upsert":
1368
+ if (!Object.hasOwn(value, "primary")) {
1369
+ throw new TypeError("reactiveIndex upsert.primary required");
1370
+ }
1371
+ if (!Object.hasOwn(value, "secondary")) {
1372
+ throw new TypeError("reactiveIndex upsert.secondary required");
1373
+ }
1374
+ if (!Object.hasOwn(value, "value"))
1375
+ throw new TypeError("reactiveIndex upsert.value required");
1376
+ assertKeys(value, ["kind", "primary", "secondary", "value"], "reactiveIndex upsert");
1377
+ return value;
1378
+ case "delete":
1379
+ if (!Object.hasOwn(value, "primary")) {
1380
+ throw new TypeError("reactiveIndex delete.primary required");
1381
+ }
1382
+ assertKeys(value, ["kind", "primary"], "reactiveIndex delete");
1383
+ return value;
1384
+ case "deleteMany":
1385
+ assertKeys(value, ["kind", "primaries"], "reactiveIndex deleteMany");
1386
+ assertArray(value.primaries, "reactiveIndex deleteMany.primaries");
1387
+ return value;
1388
+ case "clear":
1389
+ assertKeys(value, ["count", "kind"], "reactiveIndex clear");
1390
+ assertSafeInteger(value.count, "reactiveIndex clear.count", 0);
1391
+ return value;
1392
+ default:
1393
+ throw new TypeError(`unsupported reactiveIndex change kind ${value.kind}`);
1394
+ }
1395
+ }
1396
+ function applyListChange(state, change) {
1397
+ switch (change.kind) {
1398
+ case "append":
1399
+ state.push(change.value);
1400
+ return;
1401
+ case "appendMany":
1402
+ state.push(...change.values);
1403
+ return;
1404
+ case "insert":
1405
+ if (change.index > state.length)
1406
+ throw new Error("reactiveList insert change is out of range");
1407
+ state.splice(change.index, 0, change.value);
1408
+ return;
1409
+ case "insertMany":
1410
+ if (change.index > state.length) {
1411
+ throw new Error("reactiveList insertMany change is out of range");
1412
+ }
1413
+ state.splice(change.index, 0, ...change.values);
1414
+ return;
1415
+ case "pop":
1416
+ if (change.index >= state.length) throw new Error("reactiveList pop change is out of range");
1417
+ if (!strictJsonEquals(state[change.index], change.value)) {
1418
+ throw new Error("reactiveList pop change value does not match current state");
1419
+ }
1420
+ state.splice(change.index, 1);
1421
+ return;
1422
+ case "trimHead":
1423
+ if (change.n > state.length) throw new Error("reactiveList trimHead change is out of range");
1424
+ state.splice(0, change.n);
1425
+ return;
1426
+ case "clear":
1427
+ if (change.count !== state.length) {
1428
+ throw new Error("reactiveList clear change count does not match current state");
1429
+ }
1430
+ state.length = 0;
1431
+ return;
1432
+ }
1433
+ }
1434
+ function strictJsonEquals(a, b) {
1435
+ const left = strictCanonicalJsonBytes(a);
1436
+ const right = strictCanonicalJsonBytes(b);
1437
+ if (left.byteLength !== right.byteLength) return false;
1438
+ for (let i = 0; i < left.byteLength; i += 1) if (left[i] !== right[i]) return false;
1439
+ return true;
1440
+ }
1441
+ function findJsonIndex(values, match, key, label) {
1442
+ let found = -1;
1443
+ for (let i = 0; i < values.length; i += 1) {
1444
+ if (strictJsonEquals(match(values[i]), key)) {
1445
+ if (found !== -1) throw new Error(`${label} duplicate JSON key in restore state`);
1446
+ found = i;
1447
+ }
1448
+ }
1449
+ return found;
1450
+ }
1451
+ function cmpOrd(a, b) {
1452
+ if (a === b) return 0;
1453
+ const ta = typeof a;
1454
+ if (ta === typeof b && (ta === "number" || ta === "string" || ta === "boolean" || ta === "bigint")) {
1455
+ const ax = a;
1456
+ const bx = b;
1457
+ return ax < bx ? -1 : ax > bx ? 1 : 0;
1458
+ }
1459
+ return String(a).localeCompare(String(b));
1460
+ }
1461
+ function applyLogChange(state, change) {
1462
+ switch (change.kind) {
1463
+ case "append":
1464
+ state.push(change.value);
1465
+ return;
1466
+ case "appendMany":
1467
+ state.push(...change.values);
1468
+ return;
1469
+ case "trimHead":
1470
+ if (change.n > state.length) throw new Error("reactiveLog trimHead change is out of range");
1471
+ state.splice(0, change.n);
1472
+ return;
1473
+ case "clear":
1474
+ if (change.count !== state.length) {
1475
+ throw new Error("reactiveLog clear change count does not match current state");
1476
+ }
1477
+ state.length = 0;
1478
+ return;
1479
+ }
1480
+ }
1481
+ function applyMapChange(state, change) {
1482
+ switch (change.kind) {
1483
+ case "set": {
1484
+ const index = findJsonIndex(state, ([key]) => key, change.key, "reactiveMap");
1485
+ if (index === -1) state.push([change.key, change.value]);
1486
+ else state[index] = [change.key, change.value];
1487
+ return;
1488
+ }
1489
+ case "delete": {
1490
+ const index = findJsonIndex(state, ([key]) => key, change.key, "reactiveMap");
1491
+ if (index === -1) throw new Error("reactiveMap delete change key is missing");
1492
+ if (!strictJsonEquals(state[index]?.[1], change.previous)) {
1493
+ throw new Error("reactiveMap delete change previous value does not match current state");
1494
+ }
1495
+ state.splice(index, 1);
1496
+ return;
1497
+ }
1498
+ case "clear":
1499
+ if (change.count !== state.length) {
1500
+ throw new Error("reactiveMap clear change count does not match current state");
1501
+ }
1502
+ state.length = 0;
1503
+ return;
1504
+ }
1505
+ }
1506
+ function sortIndexRows(state) {
1507
+ state.sort((a, b) => {
1508
+ const bySecondary = cmpOrd(a.secondary, b.secondary);
1509
+ return bySecondary === 0 ? cmpOrd(a.primary, b.primary) : bySecondary;
1510
+ });
1511
+ }
1512
+ function applyIndexChange(state, change) {
1513
+ switch (change.kind) {
1514
+ case "upsert": {
1515
+ const index = findJsonIndex(state, (row2) => row2.primary, change.primary, "reactiveIndex");
1516
+ const row = {
1517
+ primary: change.primary,
1518
+ secondary: change.secondary,
1519
+ value: change.value
1520
+ };
1521
+ if (index === -1) state.push(row);
1522
+ else state[index] = row;
1523
+ sortIndexRows(state);
1524
+ return;
1525
+ }
1526
+ case "delete": {
1527
+ const index = findJsonIndex(state, (row) => row.primary, change.primary, "reactiveIndex");
1528
+ if (index === -1) throw new Error("reactiveIndex delete change primary is missing");
1529
+ state.splice(index, 1);
1530
+ return;
1531
+ }
1532
+ case "deleteMany": {
1533
+ for (const primary of change.primaries) {
1534
+ const index = findJsonIndex(state, (row) => row.primary, primary, "reactiveIndex");
1535
+ if (index === -1) {
1536
+ throw new Error("reactiveIndex deleteMany change primary is missing");
1537
+ }
1538
+ state.splice(index, 1);
1539
+ }
1540
+ return;
1541
+ }
1542
+ case "clear":
1543
+ if (change.count !== state.length) {
1544
+ throw new Error("reactiveIndex clear change count does not match current state");
1545
+ }
1546
+ state.length = 0;
1547
+ return;
1548
+ }
1549
+ }
1550
+ function finishState(kind, state, snapshotFound, snapshotCursor, applied, cursor) {
1551
+ return {
1552
+ kind,
1553
+ state,
1554
+ source: snapshotFound ? applied > 0 ? "snapshot+changes" : "snapshot" : applied > 0 ? "changes" : "empty",
1555
+ snapshot: { found: snapshotFound, changeCursor: snapshotCursor },
1556
+ changes: { applied, cursor }
1557
+ };
1558
+ }
1559
+ function loadState(kind, opts, assertSnapshot, assertChange, applyChange) {
1560
+ const key = opts.snapshotKey ?? collectionSnapshotKey(opts.storagePrefix);
1561
+ return opts.snapshotStore.get(key).then((snapshotValue) => {
1562
+ let snapshotFound = false;
1563
+ let snapshotCursor = -1;
1564
+ let state = [];
1565
+ if (snapshotValue !== void 0) {
1566
+ const frame = assertReactiveCollectionSnapshotFrame(snapshotValue, kind);
1567
+ state = [...assertSnapshot(frame.snapshot)];
1568
+ snapshotFound = true;
1569
+ snapshotCursor = frame.changeCursor;
1570
+ }
1571
+ if (opts.changeLog === void 0) {
1572
+ return finishState(kind, state, snapshotFound, snapshotCursor, 0, snapshotCursor);
1573
+ }
1574
+ return opts.changeLog.read({ after: snapshotCursor }).then((entries) => {
1575
+ let applied = 0;
1576
+ let cursor = snapshotCursor;
1577
+ for (const entry of entries) {
1578
+ const expectedSeq = cursor + 1;
1579
+ if (!Number.isSafeInteger(entry.seq) || entry.seq !== expectedSeq) {
1580
+ throw new Error(
1581
+ `reactive collection change log is non-contiguous: expected seq ${expectedSeq}, got ${entry.seq}`
1582
+ );
1583
+ }
1584
+ const frame = assertReactiveCollectionChangeFrame(entry.value, kind);
1585
+ const change = assertChange(frame.change);
1586
+ applyChange(state, change);
1587
+ applied += 1;
1588
+ cursor = entry.seq;
1589
+ }
1590
+ return finishState(kind, state, snapshotFound, snapshotCursor, applied, cursor);
1591
+ });
1592
+ });
1593
+ }
1594
+ function loadReactiveListState(opts) {
1595
+ return loadState(
1596
+ "reactiveList",
1597
+ opts,
1598
+ (value) => assertArray(value, "reactiveList snapshot"),
1599
+ assertListChange,
1600
+ applyListChange
1601
+ );
1602
+ }
1603
+ function loadReactiveLogState(opts) {
1604
+ return loadState(
1605
+ "reactiveLog",
1606
+ opts,
1607
+ (value) => assertArray(value, "reactiveLog snapshot"),
1608
+ assertLogChange,
1609
+ applyLogChange
1610
+ );
1611
+ }
1612
+ function loadReactiveMapState(opts) {
1613
+ return loadState(
1614
+ "reactiveMap",
1615
+ opts,
1616
+ (value) => assertEntryArray(value, "reactiveMap snapshot"),
1617
+ assertMapChange,
1618
+ applyMapChange
1619
+ );
1620
+ }
1621
+ function loadReactiveIndexState(opts) {
1622
+ return loadState(
1623
+ "reactiveIndex",
1624
+ opts,
1625
+ (value) => assertIndexRows(value, "reactiveIndex snapshot"),
1626
+ assertIndexChange,
1627
+ applyIndexChange
1628
+ );
1629
+ }
1630
+
1631
+ // src/storage/read-through.ts
1632
+ function defer2(fn) {
1633
+ return Promise.resolve().then(fn);
1634
+ }
1635
+ function readThroughKv(opts) {
1636
+ return tieredReadThrough(opts);
1637
+ }
1638
+ function tieredReadThrough(opts) {
1639
+ const { key, tiers, tierNames = [], load, promoteTo, onMiss, onError } = opts;
1640
+ const lookupFacts = [];
1641
+ const promotions = [];
1642
+ let hitTier;
1643
+ let value;
1644
+ const safeOnMiss = (tier) => {
1645
+ if (!onMiss) return;
1646
+ try {
1647
+ onMiss({ key, tier });
1648
+ } catch {
1649
+ }
1650
+ };
1651
+ const safeOnError = (context) => {
1652
+ if (!onError) return;
1653
+ try {
1654
+ onError(context);
1655
+ } catch {
1656
+ }
1657
+ };
1658
+ const addFact = (fact) => {
1659
+ lookupFacts.push(fact);
1660
+ };
1661
+ const lookupTier = (index) => ({
1662
+ index,
1663
+ name: tierNames[index]
1664
+ });
1665
+ const lookupNext = (index) => {
1666
+ if (hitTier !== void 0 || index >= tiers.length) return defer2(() => void 0);
1667
+ const tier = tiers[index];
1668
+ const info = lookupTier(index);
1669
+ const read = hasKvVersioned(tier) ? defer2(() => tier.getVersioned(key)).then((result2) => {
1670
+ if (result2.kind === "miss") {
1671
+ return { found: void 0, generation: result2.generation };
1672
+ }
1673
+ return { found: result2.value, generation: result2.generation };
1674
+ }) : defer2(() => tier.get(key)).then((found) => ({ found, generation: void 0 }));
1675
+ return read.then(({ found, generation }) => {
1676
+ if (found === void 0) {
1677
+ addFact({ kind: "miss", key, tier: info, generation });
1678
+ safeOnMiss(info);
1679
+ return lookupNext(index + 1);
1680
+ }
1681
+ addFact({ kind: "hit", key, tier: info, value: found, generation });
1682
+ hitTier = info;
1683
+ value = found;
1684
+ }).catch((error) => {
1685
+ addFact({ kind: "error", key, tier: info, error });
1686
+ safeOnError({ key, tier: info, stage: "lookup", error });
1687
+ return lookupNext(index + 1);
1688
+ });
1689
+ };
1690
+ const runLoader = () => {
1691
+ if (hitTier !== void 0 || typeof load !== "function") return defer2(() => void 0);
1692
+ const loaderTier = { index: -1, name: "load" };
1693
+ return defer2(() => load(key)).then((loaded) => {
1694
+ if (loaded === void 0) {
1695
+ addFact({ kind: "miss", key, tier: loaderTier });
1696
+ safeOnMiss(loaderTier);
1697
+ return;
1698
+ }
1699
+ addFact({ kind: "hit", key, tier: loaderTier, value: loaded });
1700
+ hitTier = loaderTier;
1701
+ value = loaded;
1702
+ }).catch((error) => {
1703
+ addFact({ kind: "error", key, tier: loaderTier, error });
1704
+ safeOnError({ key, tier: loaderTier, stage: "lookup", error });
1705
+ });
1706
+ };
1707
+ const promoteNext = (targets, offset) => {
1708
+ if (offset >= targets.length || value === void 0) return defer2(() => void 0);
1709
+ const index = targets[offset];
1710
+ const info = { index, name: tierNames[index] };
1711
+ const tier = tiers[index];
1712
+ const generation = generationForTier(lookupFacts, index);
1713
+ const write = hasKvVersioned(tier) ? generation === void 0 ? defer2(() => {
1714
+ throw new Error(
1715
+ "tieredReadThrough: versioned promotion target was not observed with a generation"
1716
+ );
1717
+ }) : defer2(() => tier.setIfMatch(key, value, generation)) : defer2(() => tier.set(key, value)).then(() => true);
1718
+ return write.then((ok) => {
1719
+ promotions.push({ tier: info, ok });
1720
+ }).catch((error) => {
1721
+ promotions.push({ tier: info, ok: false, error });
1722
+ safeOnError({ key, tier: info, stage: "promotion", error });
1723
+ }).then(() => promoteNext(targets, offset + 1));
1724
+ };
1725
+ const promote = () => {
1726
+ if (hitTier === void 0 || value === void 0) return defer2(() => void 0);
1727
+ const sourceIndex = hitTier.index === -1 ? tiers.length : hitTier.index;
1728
+ const targets = buildPromotionTargets(tiers.length, sourceIndex, promoteTo);
1729
+ return promoteNext(targets, 0);
1730
+ };
1731
+ const result = () => {
1732
+ const status = (() => {
1733
+ if (hitTier !== void 0 && hitTier.index >= -1 && value !== void 0) return "hit";
1734
+ if (lookupFacts.some((fact) => fact.kind === "error")) return "error";
1735
+ return "miss";
1736
+ })();
1737
+ return {
1738
+ status,
1739
+ key,
1740
+ value,
1741
+ hitTier,
1742
+ facts: lookupFacts,
1743
+ promotions
1744
+ };
1745
+ };
1746
+ return lookupNext(0).then(runLoader).then(promote).then(result);
1747
+ }
1748
+ function generationForTier(facts, index) {
1749
+ return facts.find((fact) => fact.tier.index === index)?.generation;
1750
+ }
1751
+ function buildPromotionTargets(tierCount, hitIndex, promoteTo) {
1752
+ if (promoteTo === false || tierCount <= 0) return [];
1753
+ const maxPromote = Math.max(0, Math.min(hitIndex, tierCount));
1754
+ if (promoteTo === void 0) {
1755
+ return [...Array(maxPromote).keys()];
1756
+ }
1757
+ const normalized = [];
1758
+ const seen = /* @__PURE__ */ new Set();
1759
+ for (const index of promoteTo) {
1760
+ if (!Number.isSafeInteger(index) || index < 0 || index >= tierCount || index >= maxPromote) {
1761
+ continue;
1762
+ }
1763
+ if (!seen.has(index)) {
1764
+ seen.add(index);
1765
+ normalized.push(index);
1766
+ }
1767
+ }
1768
+ return normalized;
1769
+ }
1770
+
1771
+ // src/storage/wal.ts
1772
+ var WAL_KEY_SEGMENT = "wal";
1773
+ var WAL_FRAME_SEQ_PAD = 20;
1774
+ var WAL_FORMAT_VERSION = 1;
1775
+ var SHA_2562 = "SHA-256";
1776
+ var HEX_TABLE3 = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
1777
+ var CHECKSUM_RE = /^[0-9a-f]{64}$/;
1778
+ var WAL_BODY_KEYS = /* @__PURE__ */ new Set([
1779
+ "t",
1780
+ "lifecycle",
1781
+ "path",
1782
+ "change",
1783
+ "frame_seq",
1784
+ "frame_t_ns",
1785
+ "format_version"
1786
+ ]);
1787
+ var WAL_FRAME_KEYS = /* @__PURE__ */ new Set([...WAL_BODY_KEYS, "checksum"]);
1788
+ function bytesToHex2(bytes) {
1789
+ let out = "";
1790
+ for (const byte of bytes) out += HEX_TABLE3[byte];
1791
+ return out;
1792
+ }
1793
+ function sha256Hex2(data) {
1794
+ const digestInput = Uint8Array.from(data);
1795
+ return globalThis.crypto.subtle.digest(SHA_2562, digestInput).then((buf) => bytesToHex2(new Uint8Array(buf)));
1796
+ }
1797
+ function isRecord3(value) {
1798
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1799
+ }
1800
+ function isLifecycle2(value) {
1801
+ return value === "spec" || value === "data" || value === "ownership";
1802
+ }
1803
+ function assertOnlyKeys(value, allowed) {
1804
+ for (const key of Object.keys(value)) {
1805
+ if (!allowed.has(key)) throw new TypeError(`walFrameCodec: unknown field ${key}`);
1806
+ }
1807
+ }
1808
+ function assertFrameSeq(value, label) {
1809
+ if (!Number.isSafeInteger(value) || value < 0) {
1810
+ throw new TypeError(`${label} must be a non-negative safe integer`);
1811
+ }
1812
+ return value;
1813
+ }
1814
+ function assertWalFrameBody(value, allowedKeys = WAL_BODY_KEYS) {
1815
+ if (!isRecord3(value)) throw new TypeError("walFrameCodec: frame must be an object");
1816
+ assertOnlyKeys(value, allowedKeys);
1817
+ if (value.t !== "c") throw new TypeError("walFrameCodec: t must be c");
1818
+ if (!isLifecycle2(value.lifecycle)) {
1819
+ throw new TypeError("walFrameCodec: lifecycle must be spec, data, or ownership");
1820
+ }
1821
+ if (typeof value.path !== "string" || value.path.length === 0) {
1822
+ throw new TypeError("walFrameCodec: path must be a non-empty string");
1823
+ }
1824
+ if (!Object.hasOwn(value, "change")) {
1825
+ throw new TypeError("walFrameCodec: change payload is required");
1826
+ }
1827
+ const frameSeq = assertFrameSeq(value.frame_seq, "walFrameCodec: frame_seq");
1828
+ const frameTimestamp = assertNonNegativeDecimalIntegerString(
1829
+ value.frame_t_ns,
1830
+ "walFrameCodec: frame_t_ns"
1831
+ );
1832
+ if (value.format_version !== WAL_FORMAT_VERSION) {
1833
+ throw new TypeError(`walFrameCodec: format_version must be ${WAL_FORMAT_VERSION}`);
1834
+ }
1835
+ return {
1836
+ t: "c",
1837
+ lifecycle: value.lifecycle,
1838
+ path: value.path,
1839
+ change: value.change,
1840
+ frame_seq: frameSeq,
1841
+ frame_t_ns: frameTimestamp,
1842
+ format_version: WAL_FORMAT_VERSION
1843
+ };
1844
+ }
1845
+ function walFramePrefix(namespace) {
1846
+ if (namespace.length === 0) return WAL_KEY_SEGMENT;
1847
+ return `${namespace}/${WAL_KEY_SEGMENT}`;
1848
+ }
1849
+ function walFrameKey(prefix, frameSeq) {
1850
+ if (!Number.isSafeInteger(frameSeq) || frameSeq < 0) {
1851
+ throw new RangeError(
1852
+ `walFrameKey: frameSeq must be a non-negative safe integer, got ${frameSeq}`
1853
+ );
1854
+ }
1855
+ return `${prefix}/${frameSeq.toString().padStart(WAL_FRAME_SEQ_PAD, "0")}`;
1856
+ }
1857
+ function walFrameChecksum(body) {
1858
+ let bytes;
1859
+ try {
1860
+ bytes = strictCanonicalJsonBytes(assertWalFrameBody(body));
1861
+ } catch (err) {
1862
+ return Promise.resolve().then(() => {
1863
+ throw err;
1864
+ });
1865
+ }
1866
+ return sha256Hex2(bytes);
1867
+ }
1868
+ function walFrame(opts) {
1869
+ const body = {
1870
+ t: "c",
1871
+ lifecycle: opts.lifecycle ?? "data",
1872
+ path: opts.path,
1873
+ change: opts.change,
1874
+ frame_seq: opts.frame_seq,
1875
+ frame_t_ns: opts.frame_t_ns ?? nowNs(),
1876
+ format_version: WAL_FORMAT_VERSION
1877
+ };
1878
+ return walFrameChecksum(body).then((checksum) => ({ ...body, checksum }));
1879
+ }
1880
+ function assertWalFrame(value) {
1881
+ if (!isRecord3(value)) throw new TypeError("walFrameCodec: frame must be an object");
1882
+ assertOnlyKeys(value, WAL_FRAME_KEYS);
1883
+ const body = assertWalFrameBody(value, WAL_FRAME_KEYS);
1884
+ const checksum = value.checksum;
1885
+ if (typeof checksum !== "string" || !CHECKSUM_RE.test(checksum)) {
1886
+ throw new TypeError("walFrameCodec: checksum must be a lowercase sha256 hex string");
1887
+ }
1888
+ return { ...body, checksum };
1889
+ }
1890
+ function verifyWalFrameChecksum(frame) {
1891
+ let checked;
1892
+ try {
1893
+ checked = assertWalFrame(frame);
1894
+ } catch (err) {
1895
+ return Promise.resolve().then(() => {
1896
+ throw err;
1897
+ });
1898
+ }
1899
+ const { checksum, ...body } = checked;
1900
+ return walFrameChecksum(body).then((expected) => expected === checksum);
1901
+ }
1902
+ function walFrameCodec() {
1903
+ const codec = strictJsonCodecFor();
1904
+ return {
1905
+ encode(value) {
1906
+ return codec.encode(assertWalFrame(value));
1907
+ },
1908
+ decode(bytes) {
1909
+ return assertWalFrame(codec.decode(bytes));
1910
+ }
1911
+ };
1912
+ }
1913
+ // Annotate the CommonJS export names for ESM import in node:
1914
+ 0 && (module.exports = {
1915
+ APPEND_LOG_SEQ_PAD,
1916
+ ContentAddressedMissError,
1917
+ REACTIVE_COLLECTION_CHANGE_FORMAT,
1918
+ REACTIVE_COLLECTION_FRAME_VERSION,
1919
+ REACTIVE_COLLECTION_SNAPSHOT_FORMAT,
1920
+ WAL_FORMAT_VERSION,
1921
+ WAL_FRAME_SEQ_PAD,
1922
+ WAL_KEY_SEGMENT,
1923
+ appendLogKey,
1924
+ appendLogStorage,
1925
+ assertChangeEnvelope,
1926
+ assertDecimalIntegerString,
1927
+ assertNonNegativeDecimalIntegerString,
1928
+ assertObserveEventFrame,
1929
+ assertReactiveCollectionChangeFrame,
1930
+ assertReactiveCollectionSnapshotFrame,
1931
+ assertStrictJsonObject,
1932
+ assertStrictJsonValue,
1933
+ assertWalFrame,
1934
+ bigIntToDecimalString,
1935
+ bigIntToNonNegativeDecimalString,
1936
+ changeEnvelopeCodec,
1937
+ collectionSnapshotKey,
1938
+ contentAddressedKv,
1939
+ contentAddressedStorage,
1940
+ decimalStringToBigInt,
1941
+ dictKv,
1942
+ envelopeChange,
1943
+ hasKvPutIfAbsent,
1944
+ hasKvVersioned,
1945
+ hasStoragePutIfAbsent,
1946
+ hasStorageVersioned,
1947
+ isDecimalIntegerString,
1948
+ isNonNegativeDecimalIntegerString,
1949
+ jsonCodec,
1950
+ jsonCodecFor,
1951
+ kvStorage,
1952
+ listByPrefix,
1953
+ loadReactiveIndexState,
1954
+ loadReactiveListState,
1955
+ loadReactiveLogState,
1956
+ loadReactiveMapState,
1957
+ memoryAppendLog,
1958
+ memoryBackend,
1959
+ memoryKv,
1960
+ memoryMultiWriterAppendLog,
1961
+ multiWriterAppendLogStorage,
1962
+ nonNegativeDecimalStringToBigInt,
1963
+ nowNs,
1964
+ observeEventFrame,
1965
+ observeEventFrameCodec,
1966
+ reactiveCollectionChangeFrame,
1967
+ reactiveCollectionChangeFrameCodec,
1968
+ reactiveCollectionSnapshotFrame,
1969
+ reactiveCollectionSnapshotFrameCodec,
1970
+ readAppendLogPage,
1971
+ readObserveEventLogPage,
1972
+ readThroughKv,
1973
+ requireKvPutIfAbsent,
1974
+ requireKvVersioned,
1975
+ requireStoragePutIfAbsent,
1976
+ requireStorageVersioned,
1977
+ stableJsonString,
1978
+ strictJsonCodec,
1979
+ strictJsonCodecFor,
1980
+ tieredReadThrough,
1981
+ verifyWalFrameChecksum,
1982
+ walFrame,
1983
+ walFrameChecksum,
1984
+ walFrameCodec,
1985
+ walFrameKey,
1986
+ walFramePrefix,
1987
+ webStorageBackend
1988
+ });
1989
+ //# sourceMappingURL=index.cjs.map