@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,777 @@
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/browser.ts
21
+ var browser_exports = {};
22
+ __export(browser_exports, {
23
+ indexedDbAppendLog: () => indexedDbAppendLog,
24
+ indexedDbBackend: () => indexedDbBackend,
25
+ indexedDbKv: () => indexedDbKv
26
+ });
27
+ module.exports = __toCommonJS(browser_exports);
28
+
29
+ // src/storage/backend.ts
30
+ var HEX_TABLE = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
31
+ function hasStoragePutIfAbsent(backend) {
32
+ return typeof backend.putIfAbsent === "function";
33
+ }
34
+ function hasStorageVersioned(backend) {
35
+ return typeof backend.getVersioned === "function" && typeof backend.setIfMatch === "function";
36
+ }
37
+
38
+ // src/json/codec.ts
39
+ var JS_MIN_NORMAL_NUMBER = 2 ** -1022;
40
+ function assertStableJsonNumber(value, path) {
41
+ if (!Number.isFinite(value)) {
42
+ throw new TypeError(`stableJsonString: non-finite number at ${path}`);
43
+ }
44
+ }
45
+ function assertStrictJsonNumber(value, path) {
46
+ assertStableJsonNumber(value, path);
47
+ if (Object.is(value, -0)) {
48
+ throw new TypeError(`stableJsonString: non-canonical number at ${path}`);
49
+ }
50
+ const abs = Math.abs(value);
51
+ if (abs > 0 && abs < JS_MIN_NORMAL_NUMBER) {
52
+ throw new TypeError(`stableJsonString: subnormal number at ${path}`);
53
+ }
54
+ if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
55
+ throw new TypeError(`stableJsonString: integer outside safe range at ${path}`);
56
+ }
57
+ }
58
+ function sortedJsonValue(value, seen = /* @__PURE__ */ new Set(), path = "$", strictNumbers = false) {
59
+ if (value === null) return null;
60
+ if (typeof value === "string" || typeof value === "boolean") return value;
61
+ if (typeof value === "number") {
62
+ if (strictNumbers) assertStrictJsonNumber(value, path);
63
+ else assertStableJsonNumber(value, path);
64
+ return value;
65
+ }
66
+ if (typeof value !== "object") {
67
+ throw new TypeError(`stableJsonString: value at ${path} is not JSON-encodable`);
68
+ }
69
+ if (seen.has(value)) throw new TypeError(`stableJsonString: circular reference at ${path}`);
70
+ const proto = Object.getPrototypeOf(value);
71
+ if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {
72
+ throw new TypeError(`stableJsonString: non-plain object at ${path}`);
73
+ }
74
+ seen.add(value);
75
+ try {
76
+ if (Array.isArray(value)) {
77
+ if (Object.getOwnPropertySymbols(value).length > 0) {
78
+ throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
79
+ }
80
+ for (const key of Object.getOwnPropertyNames(value)) {
81
+ const isIndex = /^(0|[1-9]\d*)$/.test(key) && Number.isSafeInteger(Number(key)) && Number(key) < value.length;
82
+ if (key !== "length" && !isIndex) {
83
+ throw new TypeError(`stableJsonString: non-index array property at ${path}.${key}`);
84
+ }
85
+ }
86
+ const out2 = [];
87
+ for (let i = 0; i < value.length; i += 1) {
88
+ if (!(i in value)) {
89
+ throw new TypeError(`stableJsonString: sparse array hole at ${path}[${i}]`);
90
+ }
91
+ out2.push(sortedJsonValue(value[i], seen, `${path}[${i}]`, strictNumbers));
92
+ }
93
+ return out2;
94
+ }
95
+ if (Object.getOwnPropertySymbols(value).length > 0) {
96
+ throw new TypeError(`stableJsonString: symbol-keyed properties at ${path}`);
97
+ }
98
+ const out = /* @__PURE__ */ Object.create(null);
99
+ for (const key of Object.keys(value).sort()) {
100
+ out[key] = sortedJsonValue(
101
+ value[key],
102
+ seen,
103
+ `${path}.${key}`,
104
+ strictNumbers
105
+ );
106
+ }
107
+ return out;
108
+ } finally {
109
+ seen.delete(value);
110
+ }
111
+ }
112
+ function stableJsonString(value) {
113
+ return JSON.stringify(sortedJsonValue(value));
114
+ }
115
+ function strictStableJsonString(value) {
116
+ return JSON.stringify(sortedJsonValue(value, /* @__PURE__ */ new Set(), "$", true));
117
+ }
118
+ function jsonCodecFor() {
119
+ const encoder = new TextEncoder();
120
+ const decoder = new TextDecoder();
121
+ return {
122
+ encode(value) {
123
+ return encoder.encode(stableJsonString(value));
124
+ },
125
+ decode(bytes) {
126
+ return JSON.parse(decoder.decode(bytes));
127
+ }
128
+ };
129
+ }
130
+ var jsonCodec = jsonCodecFor();
131
+ function bytesEqual(a, b) {
132
+ if (a.byteLength !== b.byteLength) return false;
133
+ for (let i = 0; i < a.byteLength; i += 1) {
134
+ if (a[i] !== b[i]) return false;
135
+ }
136
+ return true;
137
+ }
138
+ function hasUnpairedSurrogate(value) {
139
+ for (let i = 0; i < value.length; i += 1) {
140
+ const code = value.charCodeAt(i);
141
+ if (code >= 55296 && code <= 56319) {
142
+ const next = value.charCodeAt(i + 1);
143
+ if (next >= 56320 && next <= 57343) {
144
+ i += 1;
145
+ continue;
146
+ }
147
+ return true;
148
+ }
149
+ if (code >= 56320 && code <= 57343) return true;
150
+ }
151
+ return false;
152
+ }
153
+ function assertNoUnpairedSurrogates(value, seen = /* @__PURE__ */ new Set(), path = "$") {
154
+ if (typeof value === "string") {
155
+ if (hasUnpairedSurrogate(value)) {
156
+ throw new TypeError(`strictJsonCodec: unpaired surrogate at ${path}`);
157
+ }
158
+ return;
159
+ }
160
+ if (value === null || typeof value !== "object") return;
161
+ if (seen.has(value)) return;
162
+ seen.add(value);
163
+ try {
164
+ if (Array.isArray(value)) {
165
+ for (let i = 0; i < value.length; i += 1) {
166
+ assertNoUnpairedSurrogates(value[i], seen, `${path}[${i}]`);
167
+ }
168
+ return;
169
+ }
170
+ for (const key of Object.keys(value)) {
171
+ if (hasUnpairedSurrogate(key)) {
172
+ throw new TypeError(`strictJsonCodec: unpaired surrogate at ${path}.${key}`);
173
+ }
174
+ assertNoUnpairedSurrogates(value[key], seen, `${path}.${key}`);
175
+ }
176
+ } finally {
177
+ seen.delete(value);
178
+ }
179
+ }
180
+ function assertNoDuplicateJsonObjectKeys(text) {
181
+ let index = 0;
182
+ function fail(message) {
183
+ throw new TypeError(`strictJsonCodec: ${message}`);
184
+ }
185
+ function skipWhitespace() {
186
+ while (/\s/.test(text[index] ?? "")) index += 1;
187
+ }
188
+ function readJsonString() {
189
+ const start = index;
190
+ index += 1;
191
+ while (index < text.length) {
192
+ const ch = text[index];
193
+ if (ch === '"') {
194
+ index += 1;
195
+ try {
196
+ return JSON.parse(text.slice(start, index));
197
+ } catch {
198
+ fail("malformed JSON string");
199
+ }
200
+ }
201
+ if (ch === "\\") {
202
+ index += 2;
203
+ continue;
204
+ }
205
+ index += 1;
206
+ }
207
+ fail("unterminated JSON string");
208
+ }
209
+ function consumeLiteral(literal) {
210
+ if (text.slice(index, index + literal.length) !== literal) {
211
+ fail(`malformed JSON near byte ${index}`);
212
+ }
213
+ index += literal.length;
214
+ }
215
+ function consumeNumber() {
216
+ const match = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/.exec(text.slice(index));
217
+ if (!match) fail(`malformed JSON number near byte ${index}`);
218
+ index += match[0].length;
219
+ }
220
+ function parseValue(path) {
221
+ skipWhitespace();
222
+ const ch = text[index];
223
+ if (ch === "{") {
224
+ parseObject(path);
225
+ return;
226
+ }
227
+ if (ch === "[") {
228
+ parseArray(path);
229
+ return;
230
+ }
231
+ if (ch === '"') {
232
+ readJsonString();
233
+ return;
234
+ }
235
+ if (ch === "t") {
236
+ consumeLiteral("true");
237
+ return;
238
+ }
239
+ if (ch === "f") {
240
+ consumeLiteral("false");
241
+ return;
242
+ }
243
+ if (ch === "n") {
244
+ consumeLiteral("null");
245
+ return;
246
+ }
247
+ if (ch === "-" || ch !== void 0 && ch >= "0" && ch <= "9") {
248
+ consumeNumber();
249
+ return;
250
+ }
251
+ fail(`malformed JSON near byte ${index}`);
252
+ }
253
+ function parseObject(path) {
254
+ const keys = /* @__PURE__ */ new Set();
255
+ index += 1;
256
+ skipWhitespace();
257
+ if (text[index] === "}") {
258
+ index += 1;
259
+ return;
260
+ }
261
+ while (index < text.length) {
262
+ skipWhitespace();
263
+ if (text[index] !== '"') fail(`expected object key near byte ${index}`);
264
+ const key = readJsonString();
265
+ if (keys.has(key)) {
266
+ throw new TypeError(
267
+ `strictJsonCodec: duplicate object key ${JSON.stringify(key)} at ${path}`
268
+ );
269
+ }
270
+ keys.add(key);
271
+ skipWhitespace();
272
+ if (text[index] !== ":") fail(`expected ':' after object key near byte ${index}`);
273
+ index += 1;
274
+ parseValue(`${path}.${key}`);
275
+ skipWhitespace();
276
+ if (text[index] === ",") {
277
+ index += 1;
278
+ continue;
279
+ }
280
+ if (text[index] === "}") {
281
+ index += 1;
282
+ return;
283
+ }
284
+ fail(`expected ',' or '}' near byte ${index}`);
285
+ }
286
+ fail("unterminated JSON object");
287
+ }
288
+ function parseArray(path) {
289
+ index += 1;
290
+ skipWhitespace();
291
+ if (text[index] === "]") {
292
+ index += 1;
293
+ return;
294
+ }
295
+ let item = 0;
296
+ while (index < text.length) {
297
+ parseValue(`${path}[${item}]`);
298
+ item += 1;
299
+ skipWhitespace();
300
+ if (text[index] === ",") {
301
+ index += 1;
302
+ continue;
303
+ }
304
+ if (text[index] === "]") {
305
+ index += 1;
306
+ return;
307
+ }
308
+ fail(`expected ',' or ']' near byte ${index}`);
309
+ }
310
+ fail("unterminated JSON array");
311
+ }
312
+ parseValue("$");
313
+ skipWhitespace();
314
+ if (index !== text.length) fail(`trailing JSON token near byte ${index}`);
315
+ }
316
+ function strictJsonCodecFor() {
317
+ const encoder = new TextEncoder();
318
+ const decoder = new TextDecoder("utf-8", { fatal: true });
319
+ return {
320
+ encode(value) {
321
+ assertNoUnpairedSurrogates(value);
322
+ return encoder.encode(strictStableJsonString(value));
323
+ },
324
+ decode(bytes) {
325
+ const text = decoder.decode(bytes);
326
+ assertNoDuplicateJsonObjectKeys(text);
327
+ const decoded = JSON.parse(text);
328
+ assertNoUnpairedSurrogates(decoded);
329
+ const canonical = encoder.encode(strictStableJsonString(decoded));
330
+ if (!bytesEqual(bytes, canonical)) {
331
+ throw new TypeError("strictJsonCodec: bytes are not canonical stable JSON");
332
+ }
333
+ return decoded;
334
+ }
335
+ };
336
+ }
337
+ var strictJsonCodec = strictJsonCodecFor();
338
+
339
+ // src/storage/kv.ts
340
+ function defer(fn) {
341
+ return Promise.resolve().then(fn);
342
+ }
343
+ function kvStorage(opts) {
344
+ const codec = opts.codec ?? jsonCodecFor();
345
+ const { backend } = opts;
346
+ const tier = {
347
+ get(key) {
348
+ return defer(() => backend.get(key)).then(
349
+ (bytes) => bytes === void 0 ? void 0 : codec.decode(bytes)
350
+ );
351
+ },
352
+ set(key, value) {
353
+ return defer(() => backend.put(key, codec.encode(value))).then(() => void 0);
354
+ },
355
+ delete(key) {
356
+ return defer(() => backend.delete?.(key)).then(() => void 0);
357
+ },
358
+ list(prefix = "") {
359
+ return defer(() => {
360
+ if (!backend.list) throw new Error("kvStorage.list: backend does not support listing");
361
+ return backend.list(prefix);
362
+ }).then((keys) => [...keys].sort());
363
+ }
364
+ };
365
+ let out = tier;
366
+ if (hasStoragePutIfAbsent(backend)) {
367
+ out = {
368
+ ...out,
369
+ putIfAbsent(key, value) {
370
+ return defer(() => backend.putIfAbsent(key, codec.encode(value)));
371
+ }
372
+ };
373
+ }
374
+ if (hasStorageVersioned(backend)) {
375
+ out = {
376
+ ...out,
377
+ getVersioned(key) {
378
+ return defer(() => backend.getVersioned(key)).then((result) => {
379
+ if (result.kind === "miss") return { kind: "miss", generation: result.generation };
380
+ return {
381
+ kind: "hit",
382
+ value: codec.decode(result.value),
383
+ generation: result.generation
384
+ };
385
+ });
386
+ },
387
+ setIfMatch(key, value, generation) {
388
+ return defer(() => backend.setIfMatch(key, codec.encode(value), generation));
389
+ }
390
+ };
391
+ }
392
+ return out;
393
+ }
394
+
395
+ // src/storage/append-log.ts
396
+ var APPEND_LOG_SEQ_PAD = 20;
397
+ function appendLogKey(prefix, seq) {
398
+ if (!Number.isSafeInteger(seq) || seq < 0) {
399
+ throw new RangeError(`appendLogKey: seq must be a non-negative safe integer, got ${seq}`);
400
+ }
401
+ return `${prefix}/${seq.toString().padStart(APPEND_LOG_SEQ_PAD, "0")}`;
402
+ }
403
+ function seqFromKey(prefix, key) {
404
+ const head = `${prefix}/`;
405
+ if (!key.startsWith(head)) throw new Error(`append log key outside prefix: ${key}`);
406
+ const raw = key.slice(head.length);
407
+ if (!/^\d+$/.test(raw)) {
408
+ throw new Error(`append log key has a non-numeric sequence: ${key}`);
409
+ }
410
+ if (raw.length !== APPEND_LOG_SEQ_PAD) {
411
+ throw new Error(`append log key sequence must be ${APPEND_LOG_SEQ_PAD} padded digits: ${key}`);
412
+ }
413
+ const seq = Number(raw);
414
+ if (!Number.isSafeInteger(seq)) {
415
+ throw new Error(`append log key sequence is outside the safe integer range: ${key}`);
416
+ }
417
+ return seq;
418
+ }
419
+ function nextSeqFromKeys(prefix, keys) {
420
+ if (keys.length === 0) return 0;
421
+ const next = Math.max(...keys.map((key) => seqFromKey(prefix, key))) + 1;
422
+ if (!Number.isSafeInteger(next)) {
423
+ throw new RangeError(`append log next sequence is outside the safe integer range: ${prefix}`);
424
+ }
425
+ return next;
426
+ }
427
+ function sizeFromKeys(prefix, keys) {
428
+ for (const key of keys) seqFromKey(prefix, key);
429
+ return keys.length;
430
+ }
431
+ function validateReadOptions(opts) {
432
+ const after = opts.after ?? -1;
433
+ const limit = opts.limit ?? Number.POSITIVE_INFINITY;
434
+ if (!Number.isSafeInteger(after) || after < -1) {
435
+ throw new RangeError(
436
+ `appendLogStorage.read: after must be an integer cursor >= -1, got ${after}`
437
+ );
438
+ }
439
+ if (limit !== Number.POSITIVE_INFINITY && (!Number.isSafeInteger(limit) || limit < 0)) {
440
+ throw new RangeError(
441
+ `appendLogStorage.read: limit must be a non-negative safe integer or Infinity, got ${limit}`
442
+ );
443
+ }
444
+ return { after, limit };
445
+ }
446
+ function readAppendLogEntries(kv, prefix, opts) {
447
+ const { after, limit } = validateReadOptions(opts);
448
+ return kv.list(`${prefix}/`).then((listed) => {
449
+ const keys = listed.map((key) => ({ key, seq: seqFromKey(prefix, key) })).filter(({ seq }) => seq > after).sort((a, b) => a.seq - b.seq).slice(0, limit);
450
+ return Promise.all(
451
+ keys.map(
452
+ ({ key, seq }) => kv.get(key).then((value) => {
453
+ if (value === void 0) {
454
+ throw new Error(`append log listed key is missing: ${key}`);
455
+ }
456
+ return { key, seq, value };
457
+ })
458
+ )
459
+ ).then((entries) => {
460
+ const out = [];
461
+ for (const entry of entries) if (entry !== void 0) out.push(entry);
462
+ return out;
463
+ });
464
+ });
465
+ }
466
+ function deleteAppendLogEntriesAfter(kv, prefix, seq) {
467
+ return kv.list(`${prefix}/`).then(
468
+ (keys) => Promise.all(keys.filter((key) => seqFromKey(prefix, key) > seq).map((key) => kv.delete(key)))
469
+ ).then(() => kv.list(`${prefix}/`)).then(() => void 0);
470
+ }
471
+ function appendLogStorage(opts) {
472
+ const { kv, prefix = "event-log" } = opts;
473
+ let tail = Promise.resolve();
474
+ function initNextSeq() {
475
+ return kv.list(`${prefix}/`).then((keys) => {
476
+ return nextSeqFromKeys(prefix, keys);
477
+ });
478
+ }
479
+ function enqueue(task) {
480
+ const run = tail.then(task, task);
481
+ tail = run.then(
482
+ () => void 0,
483
+ () => void 0
484
+ );
485
+ return run;
486
+ }
487
+ return {
488
+ append(value) {
489
+ return enqueue(
490
+ () => initNextSeq().then((seq) => {
491
+ const key = appendLogKey(prefix, seq);
492
+ return kv.set(key, value).then(() => {
493
+ return { key, seq, value };
494
+ });
495
+ })
496
+ );
497
+ },
498
+ read(opts2 = {}) {
499
+ return enqueue(() => readAppendLogEntries(kv, prefix, opts2));
500
+ },
501
+ truncateAfter(seq) {
502
+ return enqueue(() => deleteAppendLogEntriesAfter(kv, prefix, seq));
503
+ },
504
+ size() {
505
+ return enqueue(() => kv.list(`${prefix}/`).then((keys) => sizeFromKeys(prefix, keys)));
506
+ }
507
+ };
508
+ }
509
+
510
+ // src/storage/browser.ts
511
+ var KEY_SEPARATOR = "\0";
512
+ function isConstraintError(error) {
513
+ return error instanceof DOMException && error.name === "ConstraintError";
514
+ }
515
+ function validateKey(key) {
516
+ if (typeof key !== "string") {
517
+ throw new TypeError("indexedDbBackend: key must be a string");
518
+ }
519
+ if (key.includes(KEY_SEPARATOR)) {
520
+ throw new TypeError("indexedDbBackend: key must not contain U+0000");
521
+ }
522
+ return key;
523
+ }
524
+ function validateListPrefix(prefix) {
525
+ if (typeof prefix !== "string") {
526
+ throw new TypeError("indexedDbBackend: list prefix must be a string");
527
+ }
528
+ if (prefix.includes(KEY_SEPARATOR)) {
529
+ throw new TypeError("indexedDbBackend: list prefix must not contain U+0000");
530
+ }
531
+ return prefix;
532
+ }
533
+ function decodeStoredBytes(raw) {
534
+ if (raw === void 0 || raw === null) return void 0;
535
+ if (raw instanceof Uint8Array) return Uint8Array.from(raw);
536
+ if (raw instanceof ArrayBuffer) return new Uint8Array(raw.slice(0));
537
+ throw new TypeError("indexedDbBackend: malformed stored bytes");
538
+ }
539
+ function normalizeKeys(prefix, raw) {
540
+ const out = [];
541
+ for (const key of raw) {
542
+ if (typeof key !== "string") {
543
+ throw new TypeError("indexedDbBackend: stored key must be a string");
544
+ }
545
+ if (key.includes(KEY_SEPARATOR)) {
546
+ throw new TypeError("indexedDbBackend: malformed stored key");
547
+ }
548
+ if (key.startsWith(prefix)) out.push(key);
549
+ }
550
+ out.sort();
551
+ return out;
552
+ }
553
+ function openDb(spec, version = spec.version) {
554
+ return new Promise((resolve, reject) => {
555
+ if (typeof indexedDB === "undefined") {
556
+ reject(new TypeError("indexedDbBackend: indexedDB is not available in this environment"));
557
+ return;
558
+ }
559
+ const req = version === void 0 ? indexedDB.open(spec.dbName) : indexedDB.open(spec.dbName, version);
560
+ req.onupgradeneeded = () => {
561
+ const db = req.result;
562
+ if (!db.objectStoreNames.contains(spec.storeName)) {
563
+ db.createObjectStore(spec.storeName);
564
+ }
565
+ };
566
+ req.onblocked = () => reject(
567
+ new Error("indexedDbBackend: open blocked; close existing database connections and retry")
568
+ );
569
+ req.onsuccess = () => resolve(req.result);
570
+ req.onerror = () => reject(req.error ?? new TypeError("indexedDbBackend: open failed"));
571
+ });
572
+ }
573
+ function openDbWithStore(spec) {
574
+ return openDb(spec).then((db) => {
575
+ if (db.objectStoreNames.contains(spec.storeName)) return db;
576
+ if (spec.version !== void 0) {
577
+ db.close();
578
+ throw new Error(
579
+ `indexedDbBackend: object store "${spec.storeName}" is missing; bump the IndexedDB version to create it`
580
+ );
581
+ }
582
+ const nextVersion = db.version + 1;
583
+ db.close();
584
+ return openDb(spec, nextVersion).then((upgraded) => {
585
+ if (upgraded.objectStoreNames.contains(spec.storeName)) return upgraded;
586
+ upgraded.close();
587
+ throw new Error(`indexedDbBackend: object store "${spec.storeName}" was not created`);
588
+ });
589
+ });
590
+ }
591
+ function indexedDbBackend(spec) {
592
+ let dbCache;
593
+ const db = () => {
594
+ if (dbCache !== void 0) return dbCache;
595
+ const attempt = openDbWithStore(spec);
596
+ const cached = attempt.catch((error) => {
597
+ if (dbCache === cached) dbCache = void 0;
598
+ throw error;
599
+ });
600
+ dbCache = cached;
601
+ return dbCache;
602
+ };
603
+ return {
604
+ name: `idb:${spec.dbName}/${spec.storeName}`,
605
+ get(key) {
606
+ validateKey(key);
607
+ return db().then(
608
+ (database) => new Promise((resolve, reject) => {
609
+ try {
610
+ const tx = database.transaction(spec.storeName, "readonly");
611
+ const store = tx.objectStore(spec.storeName);
612
+ const req = store.get(key);
613
+ req.onsuccess = () => {
614
+ try {
615
+ resolve(decodeStoredBytes(req.result));
616
+ } catch (error) {
617
+ reject(error);
618
+ }
619
+ };
620
+ req.onerror = () => reject(req.error ?? new Error("indexedDbBackend: read failed"));
621
+ tx.onabort = () => reject(tx.error ?? new Error("indexedDbBackend: read transaction aborted"));
622
+ tx.oncomplete = () => {
623
+ };
624
+ } catch (error) {
625
+ reject(error);
626
+ }
627
+ })
628
+ );
629
+ },
630
+ put(key, value) {
631
+ validateKey(key);
632
+ return db().then(
633
+ (database) => new Promise((resolve, reject) => {
634
+ try {
635
+ const tx = database.transaction(spec.storeName, "readwrite");
636
+ const store = tx.objectStore(spec.storeName);
637
+ const req = store.put(value, key);
638
+ req.onerror = () => reject(req.error ?? new Error("indexedDbBackend: write failed"));
639
+ tx.oncomplete = () => resolve();
640
+ tx.onabort = () => reject(tx.error ?? new Error("indexedDbBackend: write transaction aborted"));
641
+ tx.onerror = () => reject(tx.error ?? new Error("indexedDbBackend: write transaction failed"));
642
+ } catch (error) {
643
+ reject(error);
644
+ }
645
+ })
646
+ );
647
+ },
648
+ putIfAbsent(key, value) {
649
+ validateKey(key);
650
+ return db().then(
651
+ (database) => new Promise((resolve, reject) => {
652
+ let requestOk = false;
653
+ let requestConflict = false;
654
+ let requestError;
655
+ let settled = false;
656
+ const settle = (fn) => {
657
+ if (settled) return;
658
+ settled = true;
659
+ fn();
660
+ };
661
+ try {
662
+ const tx = database.transaction(spec.storeName, "readwrite");
663
+ const store = tx.objectStore(spec.storeName);
664
+ const req = store.add(value, key);
665
+ req.onsuccess = () => {
666
+ requestOk = true;
667
+ };
668
+ req.onerror = (event) => {
669
+ const error = req.error;
670
+ if (isConstraintError(error)) {
671
+ requestConflict = true;
672
+ event.preventDefault();
673
+ return;
674
+ }
675
+ requestError = error ?? new Error("indexedDbBackend: write-if-absent failed");
676
+ };
677
+ tx.oncomplete = () => settle(() => {
678
+ if (requestConflict) {
679
+ resolve(false);
680
+ } else if (requestOk) {
681
+ resolve(true);
682
+ } else {
683
+ reject(
684
+ requestError ?? new Error("indexedDbBackend: write-if-absent did not complete")
685
+ );
686
+ }
687
+ });
688
+ tx.onabort = () => {
689
+ const error = tx.error;
690
+ if (isConstraintError(error)) {
691
+ settle(() => resolve(false));
692
+ return;
693
+ }
694
+ settle(
695
+ () => reject(
696
+ requestError ?? tx.error ?? new Error("indexedDbBackend: write-if-absent transaction aborted")
697
+ )
698
+ );
699
+ };
700
+ tx.onerror = () => {
701
+ const error = tx.error;
702
+ if (isConstraintError(error)) {
703
+ settle(() => resolve(false));
704
+ return;
705
+ }
706
+ settle(
707
+ () => reject(
708
+ requestError ?? error ?? new Error("indexedDbBackend: write-if-absent transaction failed")
709
+ )
710
+ );
711
+ };
712
+ } catch (error) {
713
+ settle(() => reject(error));
714
+ }
715
+ })
716
+ );
717
+ },
718
+ delete(key) {
719
+ validateKey(key);
720
+ return db().then(
721
+ (database) => new Promise((resolve, reject) => {
722
+ try {
723
+ const tx = database.transaction(spec.storeName, "readwrite");
724
+ const store = tx.objectStore(spec.storeName);
725
+ const req = store.delete(key);
726
+ req.onerror = () => reject(req.error ?? new Error("indexedDbBackend: delete failed"));
727
+ tx.oncomplete = () => resolve();
728
+ tx.onabort = () => reject(tx.error ?? new Error("indexedDbBackend: delete transaction aborted"));
729
+ tx.onerror = () => reject(tx.error ?? new Error("indexedDbBackend: delete transaction failed"));
730
+ } catch (error) {
731
+ reject(error);
732
+ }
733
+ })
734
+ );
735
+ },
736
+ list(prefix = "") {
737
+ const validatedPrefix = validateListPrefix(prefix);
738
+ return db().then(
739
+ (database) => new Promise((resolve, reject) => {
740
+ try {
741
+ const tx = database.transaction(spec.storeName, "readonly");
742
+ const store = tx.objectStore(spec.storeName);
743
+ const req = store.getAllKeys();
744
+ req.onsuccess = () => {
745
+ try {
746
+ resolve(normalizeKeys(validatedPrefix, req.result));
747
+ } catch (error) {
748
+ reject(error);
749
+ }
750
+ };
751
+ req.onerror = () => reject(req.error ?? new Error("indexedDbBackend: list failed"));
752
+ tx.onabort = () => reject(tx.error ?? new Error("indexedDbBackend: list transaction aborted"));
753
+ } catch (error) {
754
+ reject(error);
755
+ }
756
+ })
757
+ );
758
+ }
759
+ };
760
+ }
761
+ function indexedDbKv(spec, opts = {}) {
762
+ return kvStorage({ backend: indexedDbBackend(spec), ...opts });
763
+ }
764
+ function indexedDbAppendLog(spec, opts = {}) {
765
+ const kv = kvStorage({
766
+ backend: indexedDbBackend(spec),
767
+ codec: opts.codec
768
+ });
769
+ return appendLogStorage({ kv, prefix: opts.prefix ?? "append-log" });
770
+ }
771
+ // Annotate the CommonJS export names for ESM import in node:
772
+ 0 && (module.exports = {
773
+ indexedDbAppendLog,
774
+ indexedDbBackend,
775
+ indexedDbKv
776
+ });
777
+ //# sourceMappingURL=browser.cjs.map