@moyodb/sdk 0.0.0-alpha.3 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/LICENSE +202 -0
- package/dist/assets/worker-KDc8Khl_.js +4 -0
- package/dist/assets/worker-KDc8Khl_.js.map +1 -0
- package/dist/change-events.d.ts.map +1 -1
- package/dist/codec.d.ts.map +1 -1
- package/dist/compression.d.ts.map +1 -1
- package/dist/engine/README.md +26 -9
- package/dist/engine/moyodb_engine.d.ts +125 -54
- package/dist/engine/moyodb_engine.js +935 -391
- package/dist/engine/moyodb_engine_bg.wasm +0 -0
- package/dist/engine/moyodb_engine_bg.wasm.d.ts +57 -47
- package/dist/engine/package.json +3 -3
- package/dist/engine/snippets/moyodb-engine-8ebe6af0cc2e81b7/js/opfs_shim.js +602 -0
- package/dist/engine/snippets/moyodb-engine-cff0a0e2441a7a8f/js/opfs_shim.js +192 -81
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/indexing.d.ts +8 -0
- package/dist/indexing.d.ts.map +1 -1
- package/dist/moyodb-sdk.js +2034 -1985
- package/dist/moyodb-sdk.js.map +1 -1
- package/dist/registry.d.ts +3 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/subscriptions.d.ts.map +1 -1
- package/dist/types.d.ts +29 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/worker-api.d.ts +50 -37
- package/dist/worker-api.d.ts.map +1 -1
- package/dist/worker-client.d.ts +13 -2
- package/dist/worker-client.d.ts.map +1 -1
- package/dist/worker-protocol.d.ts +42 -3
- package/dist/worker-protocol.d.ts.map +1 -1
- package/dist/worker-server.d.ts.map +1 -1
- package/package.json +13 -9
- package/dist/assets/worker-CaOzbBz1.js +0 -2351
- package/dist/assets/worker-CaOzbBz1.js.map +0 -1
- package/dist/moyodb-sdk.umd.cjs +0 -2
- package/dist/moyodb-sdk.umd.cjs.map +0 -1
package/dist/moyodb-sdk.js
CHANGED
|
@@ -1,1988 +1,2037 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"rebuild",
|
|
53
|
-
"stats",
|
|
54
|
-
"storageInfo",
|
|
55
|
-
"requestPersistence",
|
|
56
|
-
"setFailpoint"
|
|
57
|
-
], de = "moyodb:packed-binary-list:v1", Ne = "moyodb:packed-nullable-binary-list:v1", Ue = "moyodb:packed-scan-rows:v1", De = "moyodb:packed-batch-ops:v1", We = 0, ze = 1, T = 4294967295, $e = [];
|
|
58
|
-
new Set(Ce);
|
|
59
|
-
function Fe(t) {
|
|
60
|
-
return v(t) && t.type === Be && t.version === K;
|
|
61
|
-
}
|
|
62
|
-
function Ve(t) {
|
|
63
|
-
return v(t) && t.type === Le && t.version === K && typeof t.id == "number" && Number.isSafeInteger(t.id) && typeof t.ok == "boolean";
|
|
64
|
-
}
|
|
65
|
-
function je(t) {
|
|
66
|
-
const e = new Error(t.message);
|
|
67
|
-
return e.name = t.name || t.code || "Error", t.stack && (e.stack = t.stack), t.code && Object.defineProperty(e, "code", {
|
|
68
|
-
value: t.code,
|
|
69
|
-
enumerable: !0,
|
|
70
|
-
configurable: !0
|
|
71
|
-
}), e;
|
|
72
|
-
}
|
|
73
|
-
function y(t, e, r = t) {
|
|
74
|
-
const n = new Error(e);
|
|
75
|
-
return n.name = t, Object.defineProperty(n, "code", {
|
|
76
|
-
value: r,
|
|
77
|
-
enumerable: !0,
|
|
78
|
-
configurable: !0
|
|
79
|
-
}), n;
|
|
80
|
-
}
|
|
81
|
-
function Ke(t, e) {
|
|
82
|
-
if (t === "importSnapshot") {
|
|
83
|
-
const r = e[0];
|
|
84
|
-
if (r instanceof Uint8Array) {
|
|
85
|
-
const n = tt(r);
|
|
86
|
-
return {
|
|
87
|
-
args: [n],
|
|
88
|
-
transfer: [n.buffer]
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (t === "getMany" || t === "deleteMany") {
|
|
93
|
-
const [r, n, o] = e;
|
|
94
|
-
if (Array.isArray(o) && o.length > 0) {
|
|
95
|
-
const s = Je(o);
|
|
96
|
-
return {
|
|
97
|
-
args: [r, n, s],
|
|
98
|
-
transfer: [s.bytes.buffer]
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (t === "putMany") {
|
|
103
|
-
const [r, n, o, s] = e;
|
|
104
|
-
if (Array.isArray(o) && o.length > 0) {
|
|
105
|
-
const i = Ye(o);
|
|
106
|
-
return {
|
|
107
|
-
args: [r, n, i, s],
|
|
108
|
-
transfer: [i.bytes.buffer]
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (t === "applyBatch") {
|
|
113
|
-
const [r, n, o] = e;
|
|
114
|
-
if (Array.isArray(o) && o.length > 0) {
|
|
115
|
-
const s = Qe(o);
|
|
116
|
-
return {
|
|
117
|
-
args: [r, n, s],
|
|
118
|
-
transfer: [s.bytes.buffer]
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return { args: e, transfer: $e };
|
|
123
|
-
}
|
|
124
|
-
function He(t, e) {
|
|
125
|
-
return t === "getMany" && Ze(e) ? Ge(e) : (t === "scan" || t === "scanByIndex") && et(e) ? Xe(e) : e;
|
|
126
|
-
}
|
|
127
|
-
function Ye(t) {
|
|
128
|
-
const e = t.length, r = I(e * 2, "packed putMany item count"), n = R(r, 4, "packed putMany metadata");
|
|
129
|
-
let o = 0;
|
|
130
|
-
for (let c = 0; c < e; c += 1) {
|
|
131
|
-
const h = t[c], g = h[0], E = h[1];
|
|
132
|
-
if (!(g instanceof Uint8Array) || !(E instanceof Uint8Array))
|
|
133
|
-
throw y("WorkerProtocolError", "putMany entry key/value is not a Uint8Array");
|
|
134
|
-
const B = I(g.byteLength, "putMany key length"), q = I(E.byteLength, "putMany value length");
|
|
135
|
-
if (o += B + q, o > T)
|
|
136
|
-
throw y("WorkerProtocolError", "packed putMany payload exceeds 32-bit payload limit");
|
|
137
|
-
}
|
|
138
|
-
const s = A(4, n, "packed putMany header"), i = A(s, o, "packed putMany total"), d = new Uint8Array(i), u = new DataView(d.buffer);
|
|
139
|
-
u.setUint32(0, r, !0);
|
|
140
|
-
let l = 4, a = s;
|
|
141
|
-
for (let c = 0; c < e; c += 1) {
|
|
142
|
-
const h = t[c], g = h[0], E = h[1], B = g.byteLength, q = E.byteLength;
|
|
143
|
-
u.setUint32(l, B, !0), l += 4, u.setUint32(l, q, !0), l += 4, d.set(g, a), a += B, d.set(E, a), a += q;
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
__moyodbPacked: de,
|
|
147
|
-
bytes: d
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function Je(t) {
|
|
151
|
-
const e = t.length, r = R(e, 4, "packed binary-list metadata");
|
|
152
|
-
let n = 0;
|
|
153
|
-
for (let a = 0; a < e; a += 1) {
|
|
154
|
-
const c = t[a];
|
|
155
|
-
if (!(c instanceof Uint8Array))
|
|
156
|
-
throw y("WorkerProtocolError", "binary-list payload item is not a Uint8Array");
|
|
157
|
-
const h = I(c.byteLength, "binary-list item length");
|
|
158
|
-
if (n += h, n > T)
|
|
159
|
-
throw y("WorkerProtocolError", "packed binary-list payload exceeds 32-bit payload limit");
|
|
160
|
-
}
|
|
161
|
-
const o = A(4, r, "packed binary-list header"), s = A(o, n, "packed binary-list total"), i = new Uint8Array(s), d = new DataView(i.buffer);
|
|
162
|
-
d.setUint32(0, e, !0);
|
|
163
|
-
let u = 4, l = o;
|
|
164
|
-
for (let a = 0; a < e; a += 1) {
|
|
165
|
-
const c = t[a], h = c.byteLength;
|
|
166
|
-
d.setUint32(u, h, !0), u += 4, i.set(c, l), l += h;
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
__moyodbPacked: de,
|
|
170
|
-
bytes: i
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
function Ge(t) {
|
|
174
|
-
const e = t.bytes;
|
|
175
|
-
if (!(e instanceof Uint8Array) || e.byteLength < 4)
|
|
176
|
-
throw y("WorkerProtocolError", "invalid packed nullable binary-list payload");
|
|
177
|
-
const r = new DataView(e.buffer, e.byteOffset, e.byteLength), n = r.getUint32(0, !0), o = R(n, 5, "packed nullable binary-list metadata"), s = A(4, o, "packed nullable binary-list header");
|
|
178
|
-
if (s > e.byteLength)
|
|
179
|
-
throw y("WorkerProtocolError", "packed nullable binary-list metadata exceeds payload length");
|
|
180
|
-
const i = new Array(n);
|
|
181
|
-
let d = 4, u = s;
|
|
182
|
-
for (let l = 0; l < n; l += 1) {
|
|
183
|
-
const a = r.getUint8(d), c = r.getUint32(d + 1, !0);
|
|
184
|
-
if (d += 5, a === 0) {
|
|
185
|
-
if (c !== 0)
|
|
186
|
-
throw y(
|
|
187
|
-
"WorkerProtocolError",
|
|
188
|
-
"packed nullable binary-list null item has a payload length"
|
|
189
|
-
);
|
|
190
|
-
i[l] = null;
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
if (a !== 1)
|
|
194
|
-
throw y(
|
|
195
|
-
"WorkerProtocolError",
|
|
196
|
-
`packed nullable binary-list item has invalid presence byte: ${a}`
|
|
197
|
-
);
|
|
198
|
-
const h = u + c;
|
|
199
|
-
if (h > T || h > e.byteLength)
|
|
200
|
-
throw y("WorkerProtocolError", "packed nullable binary-list item exceeds payload length");
|
|
201
|
-
i[l] = e.subarray(u, h), u = h;
|
|
202
|
-
}
|
|
203
|
-
if (u !== e.byteLength)
|
|
204
|
-
throw y("WorkerProtocolError", "packed nullable binary-list payload has trailing bytes");
|
|
205
|
-
return i;
|
|
206
|
-
}
|
|
207
|
-
function Xe(t) {
|
|
208
|
-
const e = t.bytes;
|
|
209
|
-
if (!(e instanceof Uint8Array) || e.byteLength < 4)
|
|
210
|
-
throw y("WorkerProtocolError", "invalid packed scan row payload");
|
|
211
|
-
const r = new DataView(e.buffer, e.byteOffset, e.byteLength), n = r.getUint32(0, !0), o = R(n, 8, "packed scan row metadata"), s = A(4, o, "packed scan row header");
|
|
212
|
-
if (s > e.byteLength)
|
|
213
|
-
throw y("WorkerProtocolError", "packed scan row metadata exceeds payload length");
|
|
214
|
-
const i = new Array(n);
|
|
215
|
-
let d = 4, u = s;
|
|
216
|
-
for (let l = 0; l < n; l += 1) {
|
|
217
|
-
const a = r.getUint32(d, !0), c = r.getUint32(d + 4, !0);
|
|
218
|
-
d += 8;
|
|
219
|
-
const h = u + a;
|
|
220
|
-
if (h > T || h > e.byteLength)
|
|
221
|
-
throw y("WorkerProtocolError", "packed scan row key exceeds payload length");
|
|
222
|
-
const g = h + c;
|
|
223
|
-
if (g > T || g > e.byteLength)
|
|
224
|
-
throw y("WorkerProtocolError", "packed scan row value exceeds payload length");
|
|
225
|
-
i[l] = {
|
|
226
|
-
key: e.subarray(u, h),
|
|
227
|
-
value: e.subarray(h, g)
|
|
228
|
-
}, u = g;
|
|
229
|
-
}
|
|
230
|
-
if (u !== e.byteLength)
|
|
231
|
-
throw y("WorkerProtocolError", "packed scan row payload has trailing bytes");
|
|
232
|
-
return i;
|
|
233
|
-
}
|
|
234
|
-
function Qe(t) {
|
|
235
|
-
const e = t.length, r = R(e, 9, "packed batch metadata");
|
|
236
|
-
let n = 0;
|
|
237
|
-
for (let a = 0; a < e; a += 1) {
|
|
238
|
-
const c = t[a];
|
|
239
|
-
if (c.kind !== "put" && c.kind !== "delete")
|
|
240
|
-
throw y(
|
|
241
|
-
"WorkerProtocolError",
|
|
242
|
-
`unknown batch operation kind: ${String(c.kind)}`
|
|
243
|
-
);
|
|
244
|
-
if (!(c.key instanceof Uint8Array))
|
|
245
|
-
throw y("WorkerProtocolError", "batch operation key is not a Uint8Array");
|
|
246
|
-
const h = I(c.key.byteLength, "batch operation key length");
|
|
247
|
-
if (n += h, n > T)
|
|
248
|
-
throw y("WorkerProtocolError", "packed batch payload exceeds 32-bit payload limit");
|
|
249
|
-
if (c.kind === "put") {
|
|
250
|
-
if (!(c.value instanceof Uint8Array))
|
|
251
|
-
throw y("WorkerProtocolError", "batch put value is not a Uint8Array");
|
|
252
|
-
const g = I(c.value.byteLength, "batch put value length");
|
|
253
|
-
if (n += g, n > T)
|
|
254
|
-
throw y("WorkerProtocolError", "packed batch payload exceeds 32-bit payload limit");
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const o = A(4, r, "packed batch header"), s = A(o, n, "packed batch total"), i = new Uint8Array(s), d = new DataView(i.buffer);
|
|
258
|
-
d.setUint32(0, e, !0);
|
|
259
|
-
let u = 4, l = o;
|
|
260
|
-
for (let a = 0; a < e; a += 1) {
|
|
261
|
-
const c = t[a], h = c.key, g = h.byteLength, E = c.kind === "put" ? c.value.byteLength : 0;
|
|
262
|
-
d.setUint8(u, c.kind === "put" ? ze : We), d.setUint32(u + 1, g, !0), d.setUint32(u + 5, E, !0), u += 9, i.set(h, l), l += g, c.kind === "put" && (i.set(c.value, l), l += E);
|
|
263
|
-
}
|
|
264
|
-
return {
|
|
265
|
-
__moyodbPacked: De,
|
|
266
|
-
bytes: i
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
function Ze(t) {
|
|
270
|
-
return v(t) && t.__moyodbPacked === Ne && t.bytes instanceof Uint8Array;
|
|
271
|
-
}
|
|
272
|
-
function et(t) {
|
|
273
|
-
return v(t) && t.__moyodbPacked === Ue && t.bytes instanceof Uint8Array;
|
|
274
|
-
}
|
|
275
|
-
function R(t, e, r) {
|
|
276
|
-
if (!Number.isSafeInteger(t) || t < 0)
|
|
277
|
-
throw y("WorkerProtocolError", `${r} count is invalid: ${t}`);
|
|
278
|
-
return I(t * e, r);
|
|
279
|
-
}
|
|
280
|
-
function A(t, e, r) {
|
|
281
|
-
const n = t + e;
|
|
282
|
-
return I(n, r);
|
|
283
|
-
}
|
|
284
|
-
function I(t, e) {
|
|
285
|
-
if (!Number.isSafeInteger(t) || t < 0 || t > T)
|
|
286
|
-
throw y("WorkerProtocolError", `${e} exceeds 32-bit payload limit`);
|
|
287
|
-
return t;
|
|
288
|
-
}
|
|
289
|
-
function tt(t) {
|
|
290
|
-
const e = new Uint8Array(t.byteLength);
|
|
291
|
-
return e.set(t), e;
|
|
292
|
-
}
|
|
293
|
-
function W(t) {
|
|
294
|
-
t.timeout && clearTimeout(t.timeout);
|
|
295
|
-
}
|
|
296
|
-
class rt {
|
|
297
|
-
constructor(e, r = {}) {
|
|
298
|
-
this.worker = e, this.requestTimeoutMs = r.requestTimeoutMs ?? 0, this.ready = new Promise((n, o) => {
|
|
299
|
-
this.readyResolve = n, this.readyReject = o;
|
|
300
|
-
}), this.worker.addEventListener("message", this.handleMessage), this.worker.addEventListener("messageerror", this.handleMessageError), this.worker.addEventListener("error", this.handleError);
|
|
301
|
-
}
|
|
302
|
-
worker;
|
|
303
|
-
nextRequestId = 1;
|
|
304
|
-
pending = /* @__PURE__ */ new Map();
|
|
305
|
-
closed = !1;
|
|
306
|
-
readyResolved = !1;
|
|
307
|
-
readyResolve = null;
|
|
308
|
-
readyReject = null;
|
|
309
|
-
ready;
|
|
310
|
-
requestTimeoutMs;
|
|
311
|
-
fatalHandler = null;
|
|
312
|
-
closeReason = null;
|
|
313
|
-
setFatalHandler(e) {
|
|
314
|
-
this.fatalHandler = e;
|
|
315
|
-
}
|
|
316
|
-
whenReady() {
|
|
317
|
-
return this.ready;
|
|
318
|
-
}
|
|
319
|
-
dispose(e = y("WorkerTerminatedError", "worker transport was closed")) {
|
|
320
|
-
this.disposeInternal(e, !1);
|
|
321
|
-
}
|
|
322
|
-
open(e) {
|
|
323
|
-
return this.request("open", [e]);
|
|
324
|
-
}
|
|
325
|
-
close() {
|
|
326
|
-
return this.request("close", []);
|
|
327
|
-
}
|
|
328
|
-
destroy() {
|
|
329
|
-
return this.request("destroy", []);
|
|
330
|
-
}
|
|
331
|
-
deleteDB(e) {
|
|
332
|
-
return this.request("deleteDB", [e]);
|
|
333
|
-
}
|
|
334
|
-
begin(e) {
|
|
335
|
-
return this.request("begin", [e]);
|
|
336
|
-
}
|
|
337
|
-
commit(e) {
|
|
338
|
-
return this.request("commit", [e]);
|
|
339
|
-
}
|
|
340
|
-
rollback(e) {
|
|
341
|
-
return this.request("rollback", [e]);
|
|
342
|
-
}
|
|
343
|
-
createStore(e, r, n) {
|
|
344
|
-
return this.request("createStore", [e, r, n]);
|
|
345
|
-
}
|
|
346
|
-
dropStore(e, r) {
|
|
347
|
-
return this.request("dropStore", [e, r]);
|
|
348
|
-
}
|
|
349
|
-
clearStore(e, r) {
|
|
350
|
-
return this.request("clearStore", [e, r]);
|
|
351
|
-
}
|
|
352
|
-
get(e, r, n) {
|
|
353
|
-
return this.request("get", [e, r, n]);
|
|
354
|
-
}
|
|
355
|
-
getMany(e, r, n) {
|
|
356
|
-
return this.request("getMany", [e, r, n]);
|
|
357
|
-
}
|
|
358
|
-
has(e, r, n) {
|
|
359
|
-
return this.request("has", [e, r, n]);
|
|
360
|
-
}
|
|
361
|
-
put(e, r, n, o, s) {
|
|
362
|
-
return this.request("put", [e, r, n, o, s]);
|
|
363
|
-
}
|
|
364
|
-
putMany(e, r, n, o) {
|
|
365
|
-
return this.request("putMany", [e, r, n, o]);
|
|
366
|
-
}
|
|
367
|
-
delete(e, r, n) {
|
|
368
|
-
return this.request("delete", [e, r, n]);
|
|
369
|
-
}
|
|
370
|
-
deleteMany(e, r, n) {
|
|
371
|
-
return this.request("deleteMany", [e, r, n]);
|
|
372
|
-
}
|
|
373
|
-
applyBatch(e, r, n) {
|
|
374
|
-
return this.request("applyBatch", [e, r, n]);
|
|
375
|
-
}
|
|
376
|
-
scan(e, r, n) {
|
|
377
|
-
return this.request("scan", [e, r, n]);
|
|
378
|
-
}
|
|
379
|
-
getByIndex(e, r, n, o) {
|
|
380
|
-
return this.request("getByIndex", [e, r, n, o]);
|
|
381
|
-
}
|
|
382
|
-
scanByIndex(e, r, n, o) {
|
|
383
|
-
return this.request("scanByIndex", [e, r, n, o]);
|
|
384
|
-
}
|
|
385
|
-
getIndexes() {
|
|
386
|
-
return this.request("getIndexes", []);
|
|
387
|
-
}
|
|
388
|
-
reconcileIndexes(e, r) {
|
|
389
|
-
return this.request("reconcileIndexes", [e, r]);
|
|
390
|
-
}
|
|
391
|
-
listStores() {
|
|
392
|
-
return this.request("listStores", []);
|
|
393
|
-
}
|
|
394
|
-
getVersion() {
|
|
395
|
-
return this.request("getVersion", []);
|
|
396
|
-
}
|
|
397
|
-
changesSince(e, r) {
|
|
398
|
-
return this.request("changesSince", [e, r]);
|
|
399
|
-
}
|
|
400
|
-
setSchemaVersion(e, r) {
|
|
401
|
-
return this.request("setSchemaVersion", [e, r]);
|
|
402
|
-
}
|
|
403
|
-
exportSnapshot(e) {
|
|
404
|
-
return this.request("exportSnapshot", [e]);
|
|
405
|
-
}
|
|
406
|
-
importSnapshot(e) {
|
|
407
|
-
return this.request("importSnapshot", [e]);
|
|
408
|
-
}
|
|
409
|
-
reset() {
|
|
410
|
-
return this.request("reset", []);
|
|
411
|
-
}
|
|
412
|
-
compact() {
|
|
413
|
-
return this.request("compact", []);
|
|
414
|
-
}
|
|
415
|
-
rebuild() {
|
|
416
|
-
return this.request("rebuild", []);
|
|
417
|
-
}
|
|
418
|
-
stats() {
|
|
419
|
-
return this.request("stats", []);
|
|
420
|
-
}
|
|
421
|
-
storageInfo() {
|
|
422
|
-
return this.request("storageInfo", []);
|
|
423
|
-
}
|
|
424
|
-
requestPersistence() {
|
|
425
|
-
return this.request("requestPersistence", []);
|
|
426
|
-
}
|
|
427
|
-
setFailpoint(e) {
|
|
428
|
-
return this.request("setFailpoint", [e]);
|
|
429
|
-
}
|
|
430
|
-
async request(e, r) {
|
|
431
|
-
this.ensureOpen(), await this.ready, this.ensureOpen();
|
|
432
|
-
const n = this.nextRequestId;
|
|
433
|
-
this.nextRequestId += 1;
|
|
434
|
-
const o = Ke(e, r), s = {
|
|
435
|
-
type: qe,
|
|
436
|
-
version: K,
|
|
437
|
-
id: n,
|
|
438
|
-
command: e,
|
|
439
|
-
args: o.args
|
|
440
|
-
};
|
|
441
|
-
return await new Promise((i, d) => {
|
|
442
|
-
const u = this.requestTimeoutMs > 0 ? setTimeout(() => {
|
|
443
|
-
this.pending.delete(n), d(
|
|
444
|
-
y(
|
|
445
|
-
"WorkerRequestTimeoutError",
|
|
446
|
-
`worker command ${e} timed out after ${this.requestTimeoutMs}ms`
|
|
447
|
-
)
|
|
448
|
-
);
|
|
449
|
-
}, this.requestTimeoutMs) : null;
|
|
450
|
-
this.pending.set(n, {
|
|
451
|
-
command: e,
|
|
452
|
-
resolve: (l) => i(l),
|
|
453
|
-
reject: d,
|
|
454
|
-
timeout: u
|
|
455
|
-
});
|
|
456
|
-
try {
|
|
457
|
-
o.transfer.length > 0 ? this.worker.postMessage(s, o.transfer) : this.worker.postMessage(s);
|
|
458
|
-
} catch (l) {
|
|
459
|
-
this.rejectPending(n, l instanceof Error ? l : new Error(String(l)));
|
|
460
|
-
}
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
ensureOpen() {
|
|
464
|
-
if (this.closed)
|
|
465
|
-
throw this.closeReason ?? y("WorkerTerminatedError", "worker transport is closed");
|
|
466
|
-
}
|
|
467
|
-
handleMessage = (e) => {
|
|
468
|
-
const r = e.data;
|
|
469
|
-
if (Fe(r)) {
|
|
470
|
-
this.readyResolved = !0, this.readyResolve?.(), this.readyResolve = null, this.readyReject = null;
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
if (!Ve(r))
|
|
474
|
-
return;
|
|
475
|
-
const n = this.pending.get(r.id);
|
|
476
|
-
if (n) {
|
|
477
|
-
if (this.pending.delete(r.id), W(n), r.ok) {
|
|
478
|
-
n.resolve(He(n.command, r.result));
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
n.reject(je(r.error));
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
handleMessageError = () => {
|
|
485
|
-
this.disposeInternal(
|
|
486
|
-
y("WorkerMessageError", "worker message could not be deserialized"),
|
|
487
|
-
!0
|
|
488
|
-
);
|
|
489
|
-
};
|
|
490
|
-
handleError = (e) => {
|
|
491
|
-
const r = e.error instanceof Error ? e.error : y("WorkerError", e.message || "worker runtime failed");
|
|
492
|
-
this.disposeInternal(r, !0);
|
|
493
|
-
};
|
|
494
|
-
rejectPending(e, r) {
|
|
495
|
-
const n = this.pending.get(e);
|
|
496
|
-
n && (this.pending.delete(e), W(n), n.reject(r));
|
|
497
|
-
}
|
|
498
|
-
disposeInternal(e, r) {
|
|
499
|
-
if (!this.closed) {
|
|
500
|
-
this.closed = !0, this.closeReason = e, this.worker.removeEventListener("message", this.handleMessage), this.worker.removeEventListener("messageerror", this.handleMessageError), this.worker.removeEventListener("error", this.handleError), this.readyResolved || this.readyReject?.(e), this.readyResolve = null, this.readyReject = null;
|
|
501
|
-
for (const n of this.pending.values())
|
|
502
|
-
W(n), n.reject(e);
|
|
503
|
-
this.pending.clear(), r && this.fatalHandler?.(e);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
class p extends Error {
|
|
508
|
-
constructor(e, r) {
|
|
509
|
-
super(r), this.name = e, Object.setPrototypeOf(this, new.target.prototype);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
class O extends p {
|
|
513
|
-
constructor(e) {
|
|
514
|
-
super("UnsupportedPlatformError", e);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
class he extends p {
|
|
518
|
-
constructor(e) {
|
|
519
|
-
super("DatabaseBusyError", e);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
class nt extends p {
|
|
523
|
-
constructor(e) {
|
|
524
|
-
super("CorruptionError", e);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
class ot extends p {
|
|
528
|
-
constructor(e) {
|
|
529
|
-
super("StoreExistsError", e);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
class st extends p {
|
|
533
|
-
constructor(e) {
|
|
534
|
-
super("StoreNotFoundError", e);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
class it extends p {
|
|
538
|
-
constructor(e) {
|
|
539
|
-
super("IndexNotFoundError", e);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
class fe extends p {
|
|
543
|
-
constructor(e) {
|
|
544
|
-
super("ConstraintError", e);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
class at extends fe {
|
|
548
|
-
constructor(e) {
|
|
549
|
-
super(e), this.name = "UniqueIndexConstraintError";
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
class ct extends p {
|
|
553
|
-
constructor(e = "write transaction already open") {
|
|
554
|
-
super("WriteTransactionAlreadyOpenError", e);
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
class ut extends p {
|
|
558
|
-
constructor(e = "readonly transaction cannot perform this operation") {
|
|
559
|
-
super("ReadonlyTransactionError", e);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
class z extends p {
|
|
563
|
-
constructor(e = "transaction is already closed") {
|
|
564
|
-
super("TransactionClosedError", e);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
class H extends p {
|
|
568
|
-
constructor(e = "database handle is closed") {
|
|
569
|
-
super("DatabaseClosedError", e);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
class lt extends p {
|
|
573
|
-
constructor(e) {
|
|
574
|
-
super("ValueTooLargeError", e);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
class dt extends p {
|
|
578
|
-
constructor(e) {
|
|
579
|
-
super("KeyTooLargeError", e);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
class ht extends p {
|
|
583
|
-
constructor(e) {
|
|
584
|
-
super("StoreNameTooLongError", e);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
class ye extends p {
|
|
588
|
-
constructor(e) {
|
|
589
|
-
super("ReservedStoreNameError", e);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
class ft extends p {
|
|
593
|
-
constructor(e) {
|
|
594
|
-
super("InvalidRangeError", e);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
class yt extends p {
|
|
598
|
-
constructor(e) {
|
|
599
|
-
super("StorageError", e);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
class _ extends p {
|
|
603
|
-
constructor(e) {
|
|
604
|
-
super("SerializationError", e);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
class pt extends p {
|
|
608
|
-
constructor(e) {
|
|
609
|
-
super("InjectedFailureError", e);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
class bt extends p {
|
|
613
|
-
constructor(e) {
|
|
614
|
-
super("ChangeFeedCompactedError", e);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
class wt extends p {
|
|
618
|
-
constructor(e) {
|
|
619
|
-
super("InternalError", e);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
class b extends p {
|
|
623
|
-
constructor(e) {
|
|
624
|
-
super("InvalidOpenOptionsError", e);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
class C extends p {
|
|
628
|
-
constructor(e) {
|
|
629
|
-
super("VersionError", e);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
const gt = {
|
|
633
|
-
UnsupportedPlatformError: O,
|
|
634
|
-
DatabaseBusyError: he,
|
|
635
|
-
CorruptionError: nt,
|
|
636
|
-
StoreExistsError: ot,
|
|
637
|
-
StoreNotFoundError: st,
|
|
638
|
-
IndexNotFoundError: it,
|
|
639
|
-
ConstraintError: fe,
|
|
640
|
-
UniqueIndexConstraintError: at,
|
|
641
|
-
WriteTransactionAlreadyOpenError: ct,
|
|
642
|
-
ReadonlyTransactionError: ut,
|
|
643
|
-
TransactionClosedError: z,
|
|
644
|
-
DatabaseClosedError: H,
|
|
645
|
-
ValueTooLargeError: lt,
|
|
646
|
-
KeyTooLargeError: dt,
|
|
647
|
-
StoreNameTooLongError: ht,
|
|
648
|
-
ReservedStoreNameError: ye,
|
|
649
|
-
InvalidRangeError: ft,
|
|
650
|
-
StorageError: yt,
|
|
651
|
-
SerializationError: _,
|
|
652
|
-
InjectedFailureError: pt,
|
|
653
|
-
ChangeFeedCompactedError: bt,
|
|
654
|
-
InternalError: wt,
|
|
655
|
-
InvalidOpenOptionsError: b,
|
|
656
|
-
VersionError: C
|
|
657
|
-
};
|
|
658
|
-
function Z(t, e) {
|
|
659
|
-
const r = gt[t];
|
|
660
|
-
if (r)
|
|
661
|
-
return new r(e);
|
|
662
|
-
const n = new Error(e);
|
|
663
|
-
return n.name = t, n;
|
|
664
|
-
}
|
|
665
|
-
function x(t) {
|
|
666
|
-
if (t instanceof p)
|
|
667
|
-
return t;
|
|
668
|
-
if (t instanceof Error)
|
|
669
|
-
return t.name === "Error" ? t : Z(t.name, t.message);
|
|
670
|
-
const e = t, r = e?.code ?? e?.name ?? "Error", n = e?.message ?? String(t);
|
|
671
|
-
return Z(r, n);
|
|
672
|
-
}
|
|
673
|
-
const ee = /* @__PURE__ */ new Set([
|
|
674
|
-
"after_wal_flush",
|
|
675
|
-
"after_main_flush",
|
|
676
|
-
"before_superblock_flush"
|
|
677
|
-
]), mt = "moyodb:persistence-bridge:init", kt = "moyodb:persistence-bridge:request", xt = "moyodb:persistence-bridge:response", k = /* @__PURE__ */ new Map();
|
|
678
|
-
function Et(t) {
|
|
679
|
-
if (t === null || typeof t != "object" || Array.isArray(t))
|
|
680
|
-
throw new b("open options must be an object");
|
|
681
|
-
}
|
|
682
|
-
function te(t, e, r) {
|
|
683
|
-
if (t === void 0)
|
|
684
|
-
return r;
|
|
685
|
-
if (typeof t != "boolean")
|
|
686
|
-
throw new b(`${e} must be a boolean`);
|
|
687
|
-
return t;
|
|
688
|
-
}
|
|
689
|
-
function pe(t, e, r) {
|
|
690
|
-
if (t === void 0)
|
|
691
|
-
return r;
|
|
692
|
-
if (typeof t != "number" || !Number.isSafeInteger(t) || t < 0)
|
|
693
|
-
throw new b(`${e} must be a non-negative safe integer`);
|
|
694
|
-
return t;
|
|
695
|
-
}
|
|
696
|
-
function St(t) {
|
|
697
|
-
return Math.max(1, pe(t, "cachePages", 256));
|
|
698
|
-
}
|
|
699
|
-
function It(t) {
|
|
700
|
-
if (t == null)
|
|
701
|
-
return null;
|
|
702
|
-
if (typeof t != "string" || !ee.has(t))
|
|
703
|
-
throw new b(`debugFailpoint must be one of: ${Array.from(ee).join(", ")}`);
|
|
704
|
-
return t;
|
|
705
|
-
}
|
|
706
|
-
function Pt(t = {}) {
|
|
707
|
-
return Et(t), {
|
|
708
|
-
createIfMissing: te(t.createIfMissing, "createIfMissing", !0),
|
|
709
|
-
ownerWaitMs: pe(t.ownerWaitMs, "ownerWaitMs", 0),
|
|
710
|
-
requestPersistence: te(t.requestPersistence, "requestPersistence", !0),
|
|
711
|
-
cachePages: St(t.cachePages),
|
|
712
|
-
debugFailpoint: It(t.debugFailpoint)
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
function Tt(t, e, r) {
|
|
716
|
-
if (e.cachePages !== r.cachePages)
|
|
717
|
-
throw new b(
|
|
718
|
-
`database ${t} is already open in this tab with cachePages=${e.cachePages}; requested cachePages=${r.cachePages}`
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
|
-
async function At() {
|
|
722
|
-
const t = globalThis.navigator?.storage;
|
|
723
|
-
return typeof t?.persisted != "function" ? !1 : await j(t.persisted(), 1e3, !1);
|
|
724
|
-
}
|
|
725
|
-
async function Ot() {
|
|
726
|
-
const t = globalThis.navigator?.storage;
|
|
727
|
-
return typeof t?.persist != "function" ? !1 : await j(t.persist(), 1e3, !1);
|
|
728
|
-
}
|
|
729
|
-
async function vt(t, e) {
|
|
730
|
-
const r = e.op === "persist" ? await Ot() : await At(), n = {
|
|
731
|
-
type: xt,
|
|
732
|
-
id: e.id,
|
|
733
|
-
granted: r
|
|
734
|
-
};
|
|
735
|
-
t.postMessage(n);
|
|
736
|
-
}
|
|
737
|
-
function Mt(t) {
|
|
738
|
-
const e = new MessageChannel(), r = e.port1;
|
|
739
|
-
return r.addEventListener("message", (n) => {
|
|
740
|
-
const o = n.data;
|
|
741
|
-
!o || o.type !== kt || vt(r, o);
|
|
742
|
-
}), r.start(), t.postMessage({ type: mt }, [e.port2]), {
|
|
743
|
-
close() {
|
|
744
|
-
r.close();
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
function be() {
|
|
749
|
-
const t = new Worker(new URL(
|
|
750
|
-
/* @vite-ignore */
|
|
751
|
-
"/assets/worker-CaOzbBz1.js",
|
|
752
|
-
import.meta.url
|
|
753
|
-
), { type: "module" }), e = new rt(t), r = Mt(t);
|
|
754
|
-
return { worker: t, proxy: e, persistenceBridge: r };
|
|
755
|
-
}
|
|
756
|
-
function Rt(t, e, r, n, o) {
|
|
757
|
-
const s = {
|
|
758
|
-
dbName: t,
|
|
759
|
-
refs: 1,
|
|
760
|
-
worker: e,
|
|
761
|
-
proxy: r,
|
|
762
|
-
persistenceBridge: n,
|
|
763
|
-
options: o,
|
|
764
|
-
invalidated: !1,
|
|
765
|
-
txInvalidationListeners: /* @__PURE__ */ new Set(),
|
|
766
|
-
handleInvalidationListeners: /* @__PURE__ */ new Set()
|
|
767
|
-
};
|
|
768
|
-
return r.setFatalHandler(() => {
|
|
769
|
-
k.get(t) !== s || s.invalidated || (k.delete(t), s.refs = 0, Y(s), s.persistenceBridge.close(), s.worker.terminate());
|
|
770
|
-
}), s;
|
|
771
|
-
}
|
|
772
|
-
function we(t) {
|
|
773
|
-
for (const e of Array.from(t))
|
|
774
|
-
e();
|
|
775
|
-
}
|
|
776
|
-
function _t(t, e) {
|
|
777
|
-
return t.txInvalidationListeners.add(e), () => {
|
|
778
|
-
t.txInvalidationListeners.delete(e);
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
function Bt(t, e) {
|
|
782
|
-
return t.handleInvalidationListeners.add(e), () => {
|
|
783
|
-
t.handleInvalidationListeners.delete(e);
|
|
784
|
-
};
|
|
785
|
-
}
|
|
786
|
-
function N(t) {
|
|
787
|
-
we(t.txInvalidationListeners);
|
|
788
|
-
}
|
|
789
|
-
function Y(t) {
|
|
790
|
-
t.invalidated || (t.invalidated = !0, N(t), we(t.handleInvalidationListeners));
|
|
791
|
-
}
|
|
792
|
-
function qt(t) {
|
|
793
|
-
const e = k.get(t);
|
|
794
|
-
return e ? (k.delete(t), Y(e), e.refs = 0, e.persistenceBridge.close(), e.proxy.dispose(new Error("worker was terminated by unsafeDebugCrashWorker")), e.worker.terminate(), !0) : !1;
|
|
795
|
-
}
|
|
796
|
-
async function Lt(t, e = {}) {
|
|
797
|
-
const r = Pt(e), n = k.get(t);
|
|
798
|
-
if (n)
|
|
799
|
-
if (n.invalidated)
|
|
800
|
-
k.delete(t);
|
|
801
|
-
else {
|
|
802
|
-
if (Tt(t, n.options, r), r.debugFailpoint !== null)
|
|
803
|
-
try {
|
|
804
|
-
await n.proxy.setFailpoint(r.debugFailpoint);
|
|
805
|
-
} catch (u) {
|
|
806
|
-
throw x(u);
|
|
807
|
-
}
|
|
808
|
-
return n.refs += 1, n;
|
|
809
|
-
}
|
|
810
|
-
const { worker: o, proxy: s, persistenceBridge: i } = be(), d = Rt(t, o, s, i, r);
|
|
811
|
-
try {
|
|
812
|
-
return await s.open({
|
|
813
|
-
dbName: t,
|
|
814
|
-
options: r
|
|
815
|
-
}), k.set(t, d), d;
|
|
816
|
-
} catch (u) {
|
|
817
|
-
throw i.close(), s.dispose(new Error("worker open failed")), o.terminate(), x(u);
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
async function Ct(t) {
|
|
821
|
-
if (t.invalidated)
|
|
822
|
-
return;
|
|
823
|
-
const e = k.get(t.dbName);
|
|
824
|
-
if (e && (e.refs -= 1, !(e.refs > 0))) {
|
|
825
|
-
k.delete(t.dbName);
|
|
826
|
-
try {
|
|
827
|
-
await e.proxy.close();
|
|
828
|
-
} finally {
|
|
829
|
-
e.persistenceBridge.close(), e.proxy.dispose(new Error("worker was released")), e.worker.terminate();
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
async function ge(t) {
|
|
834
|
-
const e = k.get(t.dbName) ?? t;
|
|
835
|
-
k.delete(t.dbName), Y(e), e.refs = 0;
|
|
836
|
-
try {
|
|
837
|
-
await e.proxy.destroy();
|
|
838
|
-
} catch (r) {
|
|
839
|
-
throw x(r);
|
|
840
|
-
} finally {
|
|
841
|
-
e.persistenceBridge.close(), e.proxy.dispose(new Error("worker was released")), e.worker.terminate();
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
async function Nt(t) {
|
|
845
|
-
const e = k.get(t);
|
|
846
|
-
if (e) {
|
|
847
|
-
await ge(e);
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
const { worker: r, proxy: n, persistenceBridge: o } = be();
|
|
851
|
-
try {
|
|
852
|
-
await n.deleteDB(t);
|
|
853
|
-
} catch (s) {
|
|
854
|
-
throw x(s);
|
|
855
|
-
} finally {
|
|
856
|
-
o.close(), n.dispose(new Error("temporary worker was terminated")), r.terminate();
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
const Ut = new TextEncoder(), Dt = new TextDecoder(), Wt = 16, zt = 32, $t = 33, Ft = 48, Vt = 64, jt = 80, M = 0, me = 255, $ = 0, Kt = 0xffffffffffffffffn;
|
|
860
|
-
function P(t) {
|
|
861
|
-
return Ut.encode(t);
|
|
862
|
-
}
|
|
863
|
-
function Ht(t) {
|
|
864
|
-
return Dt.decode(t);
|
|
865
|
-
}
|
|
866
|
-
function Mr(t) {
|
|
867
|
-
return P(JSON.stringify(t));
|
|
868
|
-
}
|
|
869
|
-
function Rr(t) {
|
|
870
|
-
return JSON.parse(Ht(t));
|
|
871
|
-
}
|
|
872
|
-
function _r(t) {
|
|
873
|
-
const e = typeof t == "bigint" ? t : BigInt(t);
|
|
874
|
-
if (e < 0n)
|
|
875
|
-
throw new RangeError("u64Key only accepts non-negative values");
|
|
876
|
-
const r = new ArrayBuffer(8);
|
|
877
|
-
return new DataView(r).setBigUint64(0, e, !1), new Uint8Array(r);
|
|
878
|
-
}
|
|
879
|
-
function Br(t) {
|
|
880
|
-
return Array.isArray(t) ? ke(...t) : J(t);
|
|
881
|
-
}
|
|
882
|
-
function ke(...t) {
|
|
883
|
-
return Ee(t.map((e) => J(e)));
|
|
884
|
-
}
|
|
885
|
-
function re(t) {
|
|
886
|
-
return J(t);
|
|
887
|
-
}
|
|
888
|
-
function S(t) {
|
|
889
|
-
return Ee(t);
|
|
890
|
-
}
|
|
891
|
-
function Yt(t) {
|
|
892
|
-
const e = [], r = [];
|
|
893
|
-
for (let n = 0; n < t.length; n += 1) {
|
|
894
|
-
const o = t[n];
|
|
895
|
-
if (o !== M) {
|
|
896
|
-
r.push(o);
|
|
897
|
-
continue;
|
|
898
|
-
}
|
|
899
|
-
const s = t[n + 1];
|
|
900
|
-
if (s === me) {
|
|
901
|
-
r.push(M), n += 1;
|
|
902
|
-
continue;
|
|
903
|
-
}
|
|
904
|
-
if (s === $) {
|
|
905
|
-
e.push(Uint8Array.from(r)), r.length = 0, n += 1;
|
|
906
|
-
continue;
|
|
907
|
-
}
|
|
908
|
-
throw new TypeError("invalid compound key encoding");
|
|
909
|
-
}
|
|
910
|
-
if (r.length !== 0)
|
|
911
|
-
throw new TypeError("compound key terminated unexpectedly");
|
|
912
|
-
return e;
|
|
913
|
-
}
|
|
914
|
-
function F(t) {
|
|
915
|
-
const e = t.slice();
|
|
916
|
-
for (let r = e.length - 1; r >= 0; r -= 1)
|
|
917
|
-
if (e[r] !== 255)
|
|
918
|
-
return e[r] += 1, e.subarray(0, r + 1);
|
|
919
|
-
return null;
|
|
920
|
-
}
|
|
921
|
-
function xe(t) {
|
|
922
|
-
const e = F(t);
|
|
923
|
-
return e ? { gte: t, lt: e } : { gte: t };
|
|
924
|
-
}
|
|
925
|
-
function qr(...t) {
|
|
926
|
-
return xe(ke(...t));
|
|
927
|
-
}
|
|
928
|
-
function J(t) {
|
|
929
|
-
if (t === null)
|
|
930
|
-
return Uint8Array.of(Wt);
|
|
931
|
-
if (typeof t == "boolean")
|
|
932
|
-
return Uint8Array.of(t ? $t : zt);
|
|
933
|
-
if (typeof t == "number")
|
|
934
|
-
return Jt(t);
|
|
935
|
-
if (typeof t == "string") {
|
|
936
|
-
const e = P(t), r = new Uint8Array(1 + e.length);
|
|
937
|
-
return r[0] = Vt, r.set(e, 1), r;
|
|
938
|
-
}
|
|
939
|
-
if (t instanceof Uint8Array) {
|
|
940
|
-
const e = new Uint8Array(1 + t.length);
|
|
941
|
-
return e[0] = jt, e.set(t, 1), e;
|
|
942
|
-
}
|
|
943
|
-
throw new TypeError("compound key parts must be string, number, boolean, null, or Uint8Array");
|
|
944
|
-
}
|
|
945
|
-
function Ee(t) {
|
|
946
|
-
let e = 0;
|
|
947
|
-
for (const o of t) {
|
|
948
|
-
for (const s of o)
|
|
949
|
-
e += s === M ? 2 : 1;
|
|
950
|
-
e += 2;
|
|
951
|
-
}
|
|
952
|
-
const r = new Uint8Array(e);
|
|
953
|
-
let n = 0;
|
|
954
|
-
for (const o of t) {
|
|
955
|
-
for (const s of o)
|
|
956
|
-
s === M ? (r[n] = M, r[n + 1] = me, n += 2) : (r[n] = s, n += 1);
|
|
957
|
-
r[n] = $, r[n + 1] = $, n += 2;
|
|
958
|
-
}
|
|
959
|
-
return r;
|
|
960
|
-
}
|
|
961
|
-
function Jt(t) {
|
|
962
|
-
if (!Number.isFinite(t))
|
|
963
|
-
throw new TypeError("compound key number parts must be finite");
|
|
964
|
-
const e = Object.is(t, -0) ? 0 : t, r = new ArrayBuffer(9), n = new DataView(r);
|
|
965
|
-
n.setUint8(0, Ft), n.setFloat64(1, e, !1);
|
|
966
|
-
let o = n.getBigUint64(1, !1);
|
|
967
|
-
return o = (o & 1n << 63n) !== 0n ? ~o & Kt : o ^ 1n << 63n, n.setBigUint64(1, o, !1), new Uint8Array(r);
|
|
968
|
-
}
|
|
969
|
-
const Gt = new TextEncoder(), Se = new TextDecoder("utf-8", { fatal: !0 }), U = /* @__PURE__ */ Symbol("moyodb.indexing.missing"), Xt = 0xcbf29ce484222325n, Qt = 0x100000001b3n, Zt = 0xffffffffffffffffn, er = "__browserdb:", ne = "__browserdb:index:", Lr = "__browserdb:indexes";
|
|
970
|
-
function tr(t) {
|
|
971
|
-
return t.startsWith(er);
|
|
972
|
-
}
|
|
973
|
-
function w(t) {
|
|
974
|
-
if (tr(t))
|
|
975
|
-
throw new ye(`reserved store name: ${t}`);
|
|
976
|
-
}
|
|
977
|
-
function G(t) {
|
|
978
|
-
if (t === void 0)
|
|
979
|
-
return [];
|
|
980
|
-
if (!Array.isArray(t))
|
|
981
|
-
throw new b("indexes must be an array");
|
|
982
|
-
const e = [], r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
|
|
983
|
-
for (const o of t) {
|
|
984
|
-
if (o === null || typeof o != "object" || Array.isArray(o))
|
|
985
|
-
throw new b("each index definition must be an object");
|
|
986
|
-
const { store: s, name: i, keyPath: d, unique: u } = o;
|
|
987
|
-
if (typeof s != "string" || s.length === 0)
|
|
988
|
-
throw new b("index store must be a non-empty string");
|
|
989
|
-
if (typeof i != "string" || i.length === 0)
|
|
990
|
-
throw new b("index name must be a non-empty string");
|
|
991
|
-
w(s);
|
|
992
|
-
const l = nr(d);
|
|
993
|
-
if (u !== void 0 && typeof u != "boolean")
|
|
994
|
-
throw new b("index unique must be a boolean");
|
|
995
|
-
const a = {
|
|
996
|
-
store: s,
|
|
997
|
-
name: i,
|
|
998
|
-
keyPath: l.paths,
|
|
999
|
-
compound: l.compound,
|
|
1000
|
-
unique: u ?? !1,
|
|
1001
|
-
internalStore: or(s, i)
|
|
1002
|
-
}, c = Ie(a.store, a.name);
|
|
1003
|
-
if (r.has(c))
|
|
1004
|
-
throw new b(`duplicate index definition ${a.store}.${a.name}`);
|
|
1005
|
-
r.add(c);
|
|
1006
|
-
const h = n.get(a.internalStore);
|
|
1007
|
-
if (h && h !== c)
|
|
1008
|
-
throw new b(
|
|
1009
|
-
`index definitions ${h} and ${c} map to the same internal store ${a.internalStore}`
|
|
1010
|
-
);
|
|
1011
|
-
n.set(a.internalStore, c), e.push(a);
|
|
1012
|
-
}
|
|
1013
|
-
return e.sort(rr), e;
|
|
1014
|
-
}
|
|
1015
|
-
function rr(t, e) {
|
|
1016
|
-
const r = L(t.store, e.store);
|
|
1017
|
-
if (r !== 0)
|
|
1018
|
-
return r;
|
|
1019
|
-
const n = L(t.name, e.name);
|
|
1020
|
-
if (n !== 0)
|
|
1021
|
-
return n;
|
|
1022
|
-
const o = Number(t.unique) - Number(e.unique);
|
|
1023
|
-
return o !== 0 ? o : L(ie(t), ie(e));
|
|
1024
|
-
}
|
|
1025
|
-
function Ie(t, e) {
|
|
1026
|
-
return `${t}\0${e}`;
|
|
1027
|
-
}
|
|
1028
|
-
function Cr(t, e, r) {
|
|
1029
|
-
return t.find((n) => n.store === e && n.name === r) ?? null;
|
|
1030
|
-
}
|
|
1031
|
-
function Nr(t, e) {
|
|
1032
|
-
return t.filter((r) => r.store === e);
|
|
1033
|
-
}
|
|
1034
|
-
function Ur(t, e) {
|
|
1035
|
-
return S([P(t), P(e)]);
|
|
1036
|
-
}
|
|
1037
|
-
function Dr(t) {
|
|
1038
|
-
return P(JSON.stringify(Te(t)));
|
|
1039
|
-
}
|
|
1040
|
-
function Wr(t) {
|
|
1041
|
-
let e;
|
|
1042
|
-
try {
|
|
1043
|
-
e = JSON.parse(Se.decode(t));
|
|
1044
|
-
} catch (n) {
|
|
1045
|
-
throw new _(`invalid persisted index metadata: ${String(n)}`);
|
|
1046
|
-
}
|
|
1047
|
-
const [r] = G([e]);
|
|
1048
|
-
return r;
|
|
1049
|
-
}
|
|
1050
|
-
function zr(t, e) {
|
|
1051
|
-
return S([t, e]);
|
|
1052
|
-
}
|
|
1053
|
-
function $r(t) {
|
|
1054
|
-
const e = Yt(t);
|
|
1055
|
-
if (e.length !== 2)
|
|
1056
|
-
throw new _("invalid index entry key encoding");
|
|
1057
|
-
return {
|
|
1058
|
-
logicalKey: e[0],
|
|
1059
|
-
primaryKey: e[1]
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
function Fr(t) {
|
|
1063
|
-
return xe(S([t]));
|
|
1064
|
-
}
|
|
1065
|
-
function Vr(t = {}) {
|
|
1066
|
-
cr(t);
|
|
1067
|
-
const e = {};
|
|
1068
|
-
if (t.reverse !== void 0 && (e.reverse = t.reverse), t.limit !== void 0 && (e.limit = t.limit), t.gte && (e.gte = S([t.gte])), t.gt) {
|
|
1069
|
-
const r = F(S([t.gt]));
|
|
1070
|
-
r && (e.gte = r);
|
|
1071
|
-
}
|
|
1072
|
-
if (t.lt && (e.lt = S([t.lt])), t.lte) {
|
|
1073
|
-
const r = F(S([t.lte]));
|
|
1074
|
-
r && (e.lt = r);
|
|
1075
|
-
}
|
|
1076
|
-
return e;
|
|
1077
|
-
}
|
|
1078
|
-
function jr(t, e) {
|
|
1079
|
-
const r = ir(e);
|
|
1080
|
-
if (t.compound) {
|
|
1081
|
-
const o = [];
|
|
1082
|
-
for (const s of t.keyPath) {
|
|
1083
|
-
const i = ce(r, s);
|
|
1084
|
-
if (i === U)
|
|
1085
|
-
return null;
|
|
1086
|
-
o.push(ue(i));
|
|
1087
|
-
}
|
|
1088
|
-
return S(o);
|
|
1089
|
-
}
|
|
1090
|
-
const n = ce(r, t.keyPath[0]);
|
|
1091
|
-
return n === U ? null : ue(n);
|
|
1092
|
-
}
|
|
1093
|
-
function oe(t) {
|
|
1094
|
-
return JSON.stringify(Pe(t));
|
|
1095
|
-
}
|
|
1096
|
-
function Kr(t) {
|
|
1097
|
-
return t.map((e) => ({
|
|
1098
|
-
store: e.store,
|
|
1099
|
-
name: e.name,
|
|
1100
|
-
keyPath: [...e.keyPath],
|
|
1101
|
-
compound: e.compound,
|
|
1102
|
-
unique: e.unique,
|
|
1103
|
-
internalStore: e.internalStore
|
|
1104
|
-
}));
|
|
1105
|
-
}
|
|
1106
|
-
function Pe(t) {
|
|
1107
|
-
return t.map(Te);
|
|
1108
|
-
}
|
|
1109
|
-
function Te(t) {
|
|
1110
|
-
return {
|
|
1111
|
-
store: t.store,
|
|
1112
|
-
name: t.name,
|
|
1113
|
-
keyPath: t.compound ? [...t.keyPath] : t.keyPath[0],
|
|
1114
|
-
unique: t.unique
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
function nr(t) {
|
|
1118
|
-
if (typeof t == "string")
|
|
1119
|
-
return se(t), { paths: [t], compound: !1 };
|
|
1120
|
-
if (!Array.isArray(t) || t.length === 0 || t.some((e) => typeof e != "string"))
|
|
1121
|
-
throw new b("index keyPath must be a non-empty string or non-empty string[]");
|
|
1122
|
-
for (const e of t)
|
|
1123
|
-
se(e);
|
|
1124
|
-
return { paths: [...t], compound: !0 };
|
|
1125
|
-
}
|
|
1126
|
-
function se(t) {
|
|
1127
|
-
if (t.length === 0)
|
|
1128
|
-
throw new b("index keyPath strings must be non-empty");
|
|
1129
|
-
if (t.startsWith(".") || t.endsWith(".") || t.includes(".."))
|
|
1130
|
-
throw new b(`invalid index keyPath: ${t}`);
|
|
1131
|
-
}
|
|
1132
|
-
function ie(t) {
|
|
1133
|
-
return t.compound ? `[${t.keyPath.join(",")}]` : t.keyPath[0];
|
|
1134
|
-
}
|
|
1135
|
-
function or(t, e) {
|
|
1136
|
-
const r = ae(P(t)), n = ae(P(e)), o = `${ne}${r}:${n}`;
|
|
1137
|
-
if (Gt.encode(o).length <= 255)
|
|
1138
|
-
return o;
|
|
1139
|
-
const s = P(Ie(t, e));
|
|
1140
|
-
return `${ne}h:${sr(s)}`;
|
|
1
|
+
//#region src/internal.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return typeof e == "object" && !!e;
|
|
4
|
+
}
|
|
5
|
+
function t(e, t) {
|
|
6
|
+
return e < t ? -1 : +(e > t);
|
|
7
|
+
}
|
|
8
|
+
function n(e, t, n) {
|
|
9
|
+
return new Promise((r) => {
|
|
10
|
+
let i = setTimeout(() => r(n), t);
|
|
11
|
+
e.then((e) => {
|
|
12
|
+
clearTimeout(i), r(e);
|
|
13
|
+
}, () => {
|
|
14
|
+
clearTimeout(i), r(n);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
var r = /* @__PURE__ */ "open.close.destroy.deleteDB.begin.commit.rollback.autocommit.createStore.dropStore.clearStore.get.getMany.has.put.putMany.delete.deleteMany.applyBatch.scan.getByIndex.scanByIndex.scanByIndexPage.getIndexes.reconcileIndexes.listStores.getVersion.changesSince.setSchemaVersion.exportSnapshot.importSnapshot.reset.compact.rebuild.stats.storageInfo.requestPersistence.setFailpoint".split("."), i = /* @__PURE__ */ new Set([
|
|
19
|
+
"get",
|
|
20
|
+
"getMany",
|
|
21
|
+
"has",
|
|
22
|
+
"put",
|
|
23
|
+
"putMany",
|
|
24
|
+
"delete",
|
|
25
|
+
"deleteMany",
|
|
26
|
+
"applyBatch",
|
|
27
|
+
"scan",
|
|
28
|
+
"getByIndex",
|
|
29
|
+
"scanByIndex",
|
|
30
|
+
"createStore",
|
|
31
|
+
"dropStore",
|
|
32
|
+
"clearStore"
|
|
33
|
+
]);
|
|
34
|
+
function a(e) {
|
|
35
|
+
return typeof e == "string" && i.has(e);
|
|
36
|
+
}
|
|
37
|
+
var o = "moyodb:packed-binary-list:v1", s = "moyodb:packed-nullable-binary-list:v1", c = "moyodb:packed-scan-rows:v1", l = "moyodb:packed-batch-ops:v1", u = "moyodb:packed-optional-values:v1", d = 0, ee = 1, f = 4294967295, p = [];
|
|
38
|
+
new Set(r);
|
|
39
|
+
function te(t) {
|
|
40
|
+
return e(t) && t.type === "moyodb:worker-protocol:ready" && t.version === 1;
|
|
41
|
+
}
|
|
42
|
+
function ne(t) {
|
|
43
|
+
return e(t) && t.type === "moyodb:worker-protocol:response" && t.version === 1 && typeof t.id == "number" && Number.isSafeInteger(t.id) && typeof t.ok == "boolean";
|
|
44
|
+
}
|
|
45
|
+
function re(e) {
|
|
46
|
+
if (!ie(e, "moyodb:worker-protocol:response-batch", "responses")) return !1;
|
|
47
|
+
for (let t of e.responses) if (!ne(t)) return !1;
|
|
48
|
+
return !0;
|
|
49
|
+
}
|
|
50
|
+
function ie(t, n, r) {
|
|
51
|
+
return e(t) && t.type === n && t.version === 1 && Array.isArray(t[r]) && t[r].length > 0 && t[r].length <= 128;
|
|
1141
52
|
}
|
|
1142
53
|
function ae(t) {
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
}
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
54
|
+
if (!e(t) || typeof t.name != "string" || typeof t.message != "string" || t.code !== void 0 && typeof t.code != "string" || t.stack !== void 0 && typeof t.stack != "string") throw m("WorkerProtocolError", "invalid serialized worker error");
|
|
55
|
+
let n = Error(t.message);
|
|
56
|
+
return n.name = t.name || t.code || "Error", t.stack && (n.stack = t.stack), t.code && Object.defineProperty(n, "code", {
|
|
57
|
+
value: t.code,
|
|
58
|
+
enumerable: !0,
|
|
59
|
+
configurable: !0
|
|
60
|
+
}), n;
|
|
61
|
+
}
|
|
62
|
+
function m(e, t, n = e) {
|
|
63
|
+
let r = Error(t);
|
|
64
|
+
return r.name = e, Object.defineProperty(r, "code", {
|
|
65
|
+
value: n,
|
|
66
|
+
enumerable: !0,
|
|
67
|
+
configurable: !0
|
|
68
|
+
}), r;
|
|
69
|
+
}
|
|
70
|
+
function oe(e, t) {
|
|
71
|
+
if (e === "autocommit") {
|
|
72
|
+
let [e, n, r] = t;
|
|
73
|
+
if (a(n) && Array.isArray(r)) {
|
|
74
|
+
let t = oe(n, [0, ...r]);
|
|
75
|
+
return {
|
|
76
|
+
args: [
|
|
77
|
+
e,
|
|
78
|
+
n,
|
|
79
|
+
t.args.slice(1)
|
|
80
|
+
],
|
|
81
|
+
transfer: t.transfer
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (e === "get" || e === "has" || e === "delete" || e === "getByIndex" || e === "put") {
|
|
86
|
+
let n = e === "getByIndex" ? 3 : 2, r = null, i = null;
|
|
87
|
+
for (let a = n; a <= (e === "put" ? 3 : n); a += 1) {
|
|
88
|
+
let e = t[a];
|
|
89
|
+
if (e instanceof Uint8Array && e.buffer instanceof ArrayBuffer && (e.byteOffset !== 0 || e.byteLength !== e.buffer.byteLength)) {
|
|
90
|
+
let n = _e(e);
|
|
91
|
+
r ??= [...t], r[a] = n, (i ??= []).push(n.buffer);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (r !== null) return {
|
|
95
|
+
args: r,
|
|
96
|
+
transfer: i ?? p
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (e === "importSnapshot") {
|
|
100
|
+
let e = t[0];
|
|
101
|
+
if (e instanceof Uint8Array) {
|
|
102
|
+
let t = _e(e);
|
|
103
|
+
return {
|
|
104
|
+
args: [t],
|
|
105
|
+
transfer: [t.buffer]
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (e === "getMany" || e === "deleteMany") {
|
|
110
|
+
let [e, n, r] = t;
|
|
111
|
+
if (Array.isArray(r) && r.length > 0) {
|
|
112
|
+
let t = de(r);
|
|
113
|
+
return {
|
|
114
|
+
args: [
|
|
115
|
+
e,
|
|
116
|
+
n,
|
|
117
|
+
t
|
|
118
|
+
],
|
|
119
|
+
transfer: [t.bytes.buffer]
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (e === "putMany") {
|
|
124
|
+
let [e, n, r, i] = t;
|
|
125
|
+
if (Array.isArray(r) && r.length > 0) {
|
|
126
|
+
let t = ue(r);
|
|
127
|
+
return {
|
|
128
|
+
args: [
|
|
129
|
+
e,
|
|
130
|
+
n,
|
|
131
|
+
t,
|
|
132
|
+
i
|
|
133
|
+
],
|
|
134
|
+
transfer: [t.bytes.buffer]
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (e === "applyBatch") {
|
|
139
|
+
let [e, n, r] = t;
|
|
140
|
+
if (Array.isArray(r) && r.length > 0) {
|
|
141
|
+
let t = me(r);
|
|
142
|
+
return {
|
|
143
|
+
args: [
|
|
144
|
+
e,
|
|
145
|
+
n,
|
|
146
|
+
t
|
|
147
|
+
],
|
|
148
|
+
transfer: [t.bytes.buffer]
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
args: t,
|
|
154
|
+
transfer: p
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function se(e) {
|
|
158
|
+
if (!(e instanceof Uint8Array) || e.byteLength < 4) throw m("WorkerProtocolError", "invalid packed optional-values payload");
|
|
159
|
+
let t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint32(0, !0), r = _(4, g(n, 4, "packed optional-values metadata"), "packed optional-values header");
|
|
160
|
+
if (r > e.byteLength) throw m("WorkerProtocolError", "packed optional-values metadata exceeds payload length");
|
|
161
|
+
let i = Array(n), a = r;
|
|
162
|
+
for (let r = 0; r < n; r += 1) {
|
|
163
|
+
let n = t.getUint32(4 + r * 4, !0);
|
|
164
|
+
if (n === f) {
|
|
165
|
+
i[r] = null;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
let o = a + n;
|
|
169
|
+
if (o > e.byteLength) throw m("WorkerProtocolError", "packed optional-values item exceeds payload length");
|
|
170
|
+
i[r] = e.subarray(a, o), a = o;
|
|
171
|
+
}
|
|
172
|
+
if (a !== e.byteLength) throw m("WorkerProtocolError", "packed optional-values payload has trailing bytes");
|
|
173
|
+
return i;
|
|
174
|
+
}
|
|
175
|
+
function ce(t, n) {
|
|
176
|
+
if (t === "getMany" && he(n)) return fe(n);
|
|
177
|
+
if (t === "getMany" && ge(n)) return se(n.bytes);
|
|
178
|
+
if (t === "getMany" && !Array.isArray(n)) throw m("WorkerProtocolError", "invalid packed getMany response");
|
|
179
|
+
if (t === "scanByIndexPage") {
|
|
180
|
+
if (!e(n) || !Array.isArray(n.rows) && !h(n.rows) || n.cursor !== null && !(n.cursor instanceof Uint8Array)) throw m("WorkerProtocolError", "invalid packed index scan page response");
|
|
181
|
+
return {
|
|
182
|
+
rows: h(n.rows) ? pe(n.rows) : n.rows,
|
|
183
|
+
cursor: n.cursor
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
if ((t === "scan" || t === "scanByIndex") && h(n)) return pe(n);
|
|
187
|
+
if ((t === "scan" || t === "scanByIndex") && !Array.isArray(n)) throw m("WorkerProtocolError", "invalid packed scan response");
|
|
188
|
+
return n;
|
|
189
|
+
}
|
|
190
|
+
function le(e, t) {
|
|
191
|
+
let n = t.length > 0 ? structuredClone(e, { transfer: t.length === 1 ? t : Array.from(new Set(t)) }) : structuredClone(e), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new WeakSet(), a = 0, o = (e) => {
|
|
192
|
+
if (typeof e == "string") {
|
|
193
|
+
a += 8 + e.length * 2;
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (typeof e != "object" || !e) {
|
|
197
|
+
a += 8;
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (!i.has(e)) {
|
|
201
|
+
if (i.add(e), a += 8, e instanceof ArrayBuffer) r.add(e), a += e.byteLength;
|
|
202
|
+
else if (typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer) a += e.byteLength;
|
|
203
|
+
else if (ArrayBuffer.isView(e)) o(e.buffer);
|
|
204
|
+
else if (Array.isArray(e)) for (let t of e) o(t);
|
|
205
|
+
else if (e instanceof Map) for (let [t, n] of e) o(t), o(n);
|
|
206
|
+
else if (e instanceof Set) for (let t of e) o(t);
|
|
207
|
+
else {
|
|
208
|
+
let t = e;
|
|
209
|
+
for (let e in t) Object.prototype.hasOwnProperty.call(t, e) && (a += 8 + e.length * 2, o(t[e]));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
return o(n), {
|
|
214
|
+
value: n,
|
|
215
|
+
transfer: r.size === 0 ? p : Array.from(r),
|
|
216
|
+
byteLength: a
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function ue(e) {
|
|
220
|
+
let t = e.length, n = v(t * 2, "packed putMany item count"), r = g(n, 4, "packed putMany metadata"), i = 0;
|
|
221
|
+
for (let n = 0; n < t; n += 1) {
|
|
222
|
+
let t = e[n], r = t[0], a = t[1];
|
|
223
|
+
if (!(r instanceof Uint8Array) || !(a instanceof Uint8Array)) throw m("WorkerProtocolError", "putMany entry key/value is not a Uint8Array");
|
|
224
|
+
let o = v(r.byteLength, "putMany key length"), s = v(a.byteLength, "putMany value length");
|
|
225
|
+
if (i += o + s, i > f) throw m("WorkerProtocolError", "packed putMany payload exceeds 32-bit payload limit");
|
|
226
|
+
}
|
|
227
|
+
let a = _(4, r, "packed putMany header"), s = _(a, i, "packed putMany total"), c = new Uint8Array(s), l = new DataView(c.buffer);
|
|
228
|
+
l.setUint32(0, n, !0);
|
|
229
|
+
let u = 4, d = a;
|
|
230
|
+
for (let n = 0; n < t; n += 1) {
|
|
231
|
+
let t = e[n], r = t[0], i = t[1], a = r.byteLength, o = i.byteLength;
|
|
232
|
+
l.setUint32(u, a, !0), u += 4, l.setUint32(u, o, !0), u += 4, c.set(r, d), d += a, c.set(i, d), d += o;
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
__moyodbPacked: o,
|
|
236
|
+
bytes: c
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function de(e) {
|
|
240
|
+
let t = e.length, n = g(t, 4, "packed binary-list metadata"), r = 0;
|
|
241
|
+
for (let n = 0; n < t; n += 1) {
|
|
242
|
+
let t = e[n];
|
|
243
|
+
if (!(t instanceof Uint8Array)) throw m("WorkerProtocolError", "binary-list payload item is not a Uint8Array");
|
|
244
|
+
let i = v(t.byteLength, "binary-list item length");
|
|
245
|
+
if (r += i, r > f) throw m("WorkerProtocolError", "packed binary-list payload exceeds 32-bit payload limit");
|
|
246
|
+
}
|
|
247
|
+
let i = _(4, n, "packed binary-list header"), a = _(i, r, "packed binary-list total"), s = new Uint8Array(a), c = new DataView(s.buffer);
|
|
248
|
+
c.setUint32(0, t, !0);
|
|
249
|
+
let l = 4, u = i;
|
|
250
|
+
for (let n = 0; n < t; n += 1) {
|
|
251
|
+
let t = e[n], r = t.byteLength;
|
|
252
|
+
c.setUint32(l, r, !0), l += 4, s.set(t, u), u += r;
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
__moyodbPacked: o,
|
|
256
|
+
bytes: s
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function fe(e) {
|
|
260
|
+
let t = e.bytes;
|
|
261
|
+
if (!(t instanceof Uint8Array) || t.byteLength < 4) throw m("WorkerProtocolError", "invalid packed nullable binary-list payload");
|
|
262
|
+
let n = new DataView(t.buffer, t.byteOffset, t.byteLength), r = n.getUint32(0, !0), i = _(4, g(r, 5, "packed nullable binary-list metadata"), "packed nullable binary-list header");
|
|
263
|
+
if (i > t.byteLength) throw m("WorkerProtocolError", "packed nullable binary-list metadata exceeds payload length");
|
|
264
|
+
let a = Array(r), o = 4, s = i;
|
|
265
|
+
for (let e = 0; e < r; e += 1) {
|
|
266
|
+
let r = n.getUint8(o), i = n.getUint32(o + 1, !0);
|
|
267
|
+
if (o += 5, r === 0) {
|
|
268
|
+
if (i !== 0) throw m("WorkerProtocolError", "packed nullable binary-list null item has a payload length");
|
|
269
|
+
a[e] = null;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (r !== 1) throw m("WorkerProtocolError", `packed nullable binary-list item has invalid presence byte: ${r}`);
|
|
273
|
+
let c = s + i;
|
|
274
|
+
if (c > f || c > t.byteLength) throw m("WorkerProtocolError", "packed nullable binary-list item exceeds payload length");
|
|
275
|
+
a[e] = t.subarray(s, c), s = c;
|
|
276
|
+
}
|
|
277
|
+
if (s !== t.byteLength) throw m("WorkerProtocolError", "packed nullable binary-list payload has trailing bytes");
|
|
278
|
+
return a;
|
|
279
|
+
}
|
|
280
|
+
function pe(e) {
|
|
281
|
+
let t = e.bytes;
|
|
282
|
+
if (!(t instanceof Uint8Array) || t.byteLength < 4) throw m("WorkerProtocolError", "invalid packed scan row payload");
|
|
283
|
+
let n = new DataView(t.buffer, t.byteOffset, t.byteLength), r = n.getUint32(0, !0), i = _(4, g(r, 8, "packed scan row metadata"), "packed scan row header");
|
|
284
|
+
if (i > t.byteLength) throw m("WorkerProtocolError", "packed scan row metadata exceeds payload length");
|
|
285
|
+
let a = Array(r), o = 4, s = i;
|
|
286
|
+
for (let e = 0; e < r; e += 1) {
|
|
287
|
+
let r = n.getUint32(o, !0), i = n.getUint32(o + 4, !0);
|
|
288
|
+
o += 8;
|
|
289
|
+
let c = s + r;
|
|
290
|
+
if (c > f || c > t.byteLength) throw m("WorkerProtocolError", "packed scan row key exceeds payload length");
|
|
291
|
+
let l = c + i;
|
|
292
|
+
if (l > f || l > t.byteLength) throw m("WorkerProtocolError", "packed scan row value exceeds payload length");
|
|
293
|
+
a[e] = {
|
|
294
|
+
key: t.subarray(s, c),
|
|
295
|
+
value: t.subarray(c, l)
|
|
296
|
+
}, s = l;
|
|
297
|
+
}
|
|
298
|
+
if (s !== t.byteLength) throw m("WorkerProtocolError", "packed scan row payload has trailing bytes");
|
|
299
|
+
return a;
|
|
300
|
+
}
|
|
301
|
+
function me(t) {
|
|
302
|
+
let n = t.length, r = g(n, 9, "packed batch metadata"), i = 0;
|
|
303
|
+
for (let r = 0; r < n; r += 1) {
|
|
304
|
+
let n = t[r];
|
|
305
|
+
if (!e(n) || n.kind !== "put" && n.kind !== "delete") throw m("WorkerProtocolError", "batch operation kind is not put or delete");
|
|
306
|
+
if (!(n.key instanceof Uint8Array)) throw m("WorkerProtocolError", "batch operation key is not a Uint8Array");
|
|
307
|
+
let a = v(n.key.byteLength, "batch operation key length");
|
|
308
|
+
if (i += a, i > f) throw m("WorkerProtocolError", "packed batch payload exceeds 32-bit payload limit");
|
|
309
|
+
if (n.kind === "put") {
|
|
310
|
+
if (!(n.value instanceof Uint8Array)) throw m("WorkerProtocolError", "batch put value is not a Uint8Array");
|
|
311
|
+
let e = v(n.value.byteLength, "batch put value length");
|
|
312
|
+
if (i += e, i > f) throw m("WorkerProtocolError", "packed batch payload exceeds 32-bit payload limit");
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
let a = _(4, r, "packed batch header"), o = _(a, i, "packed batch total"), s = new Uint8Array(o), c = new DataView(s.buffer);
|
|
316
|
+
c.setUint32(0, n, !0);
|
|
317
|
+
let u = 4, p = a;
|
|
318
|
+
for (let e = 0; e < n; e += 1) {
|
|
319
|
+
let n = t[e], r = n.key, i = r.byteLength, a = n.kind === "put" ? n.value.byteLength : 0;
|
|
320
|
+
c.setUint8(u, n.kind === "put" ? ee : d), c.setUint32(u + 1, i, !0), c.setUint32(u + 5, a, !0), u += 9, s.set(r, p), p += i, n.kind === "put" && (s.set(n.value, p), p += a);
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
__moyodbPacked: l,
|
|
324
|
+
bytes: s
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function he(t) {
|
|
328
|
+
return e(t) && t.__moyodbPacked === s && t.bytes instanceof Uint8Array;
|
|
329
|
+
}
|
|
330
|
+
function h(t) {
|
|
331
|
+
return e(t) && t.__moyodbPacked === c && t.bytes instanceof Uint8Array;
|
|
332
|
+
}
|
|
333
|
+
function ge(t) {
|
|
334
|
+
return e(t) && t.__moyodbPacked === u && t.bytes instanceof Uint8Array;
|
|
335
|
+
}
|
|
336
|
+
function g(e, t, n) {
|
|
337
|
+
if (!Number.isSafeInteger(e) || e < 0) throw m("WorkerProtocolError", `${n} count is invalid: ${e}`);
|
|
338
|
+
return v(e * t, n);
|
|
339
|
+
}
|
|
340
|
+
function _(e, t, n) {
|
|
341
|
+
return v(e + t, n);
|
|
342
|
+
}
|
|
343
|
+
function v(e, t) {
|
|
344
|
+
if (!Number.isSafeInteger(e) || e < 0 || e > f) throw m("WorkerProtocolError", `${t} exceeds 32-bit payload limit`);
|
|
345
|
+
return e;
|
|
346
|
+
}
|
|
347
|
+
function _e(e) {
|
|
348
|
+
let t = new Uint8Array(e.byteLength);
|
|
349
|
+
return t.set(e), t;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/worker-client.ts
|
|
353
|
+
function y(e) {
|
|
354
|
+
e.timeout && clearTimeout(e.timeout);
|
|
355
|
+
}
|
|
356
|
+
var ve = class {
|
|
357
|
+
worker;
|
|
358
|
+
nextRequestId = 1;
|
|
359
|
+
pending = /* @__PURE__ */ new Map();
|
|
360
|
+
closed = !1;
|
|
361
|
+
readyResolved = !1;
|
|
362
|
+
readyResolve = null;
|
|
363
|
+
readyReject = null;
|
|
364
|
+
ready;
|
|
365
|
+
requestTimeoutMs;
|
|
366
|
+
fatalHandler = null;
|
|
367
|
+
closeReason = null;
|
|
368
|
+
batching = !1;
|
|
369
|
+
queuedRequests = [];
|
|
370
|
+
queuedBytes = 0;
|
|
371
|
+
flushScheduled = !1;
|
|
372
|
+
awaitingReady = 0;
|
|
373
|
+
constructor(e, t = {}) {
|
|
374
|
+
this.worker = e, this.requestTimeoutMs = t.requestTimeoutMs ?? 0, this.ready = new Promise((e, t) => {
|
|
375
|
+
this.readyResolve = e, this.readyReject = t;
|
|
376
|
+
}), this.worker.addEventListener("message", this.handleMessage), this.worker.addEventListener("messageerror", this.handleMessageError), this.worker.addEventListener("error", this.handleError);
|
|
377
|
+
}
|
|
378
|
+
setFatalHandler(e) {
|
|
379
|
+
this.fatalHandler = e;
|
|
380
|
+
}
|
|
381
|
+
whenReady() {
|
|
382
|
+
return this.ready;
|
|
383
|
+
}
|
|
384
|
+
dispose(e = m("WorkerTerminatedError", "worker transport was closed")) {
|
|
385
|
+
this.disposeInternal(e, !1);
|
|
386
|
+
}
|
|
387
|
+
open(e) {
|
|
388
|
+
return this.request("open", [e]);
|
|
389
|
+
}
|
|
390
|
+
close() {
|
|
391
|
+
return this.request("close", []);
|
|
392
|
+
}
|
|
393
|
+
destroy() {
|
|
394
|
+
return this.request("destroy", []);
|
|
395
|
+
}
|
|
396
|
+
deleteDB(e) {
|
|
397
|
+
return this.request("deleteDB", [e]);
|
|
398
|
+
}
|
|
399
|
+
begin(e) {
|
|
400
|
+
return this.request("begin", [e]);
|
|
401
|
+
}
|
|
402
|
+
commit(e) {
|
|
403
|
+
return this.request("commit", [e]);
|
|
404
|
+
}
|
|
405
|
+
rollback(e) {
|
|
406
|
+
return this.request("rollback", [e]);
|
|
407
|
+
}
|
|
408
|
+
autocommit(e, t, n) {
|
|
409
|
+
return this.send("autocommit", [
|
|
410
|
+
e,
|
|
411
|
+
t,
|
|
412
|
+
n
|
|
413
|
+
], t);
|
|
414
|
+
}
|
|
415
|
+
createStore(e, t, n) {
|
|
416
|
+
return this.request("createStore", [
|
|
417
|
+
e,
|
|
418
|
+
t,
|
|
419
|
+
n
|
|
420
|
+
]);
|
|
421
|
+
}
|
|
422
|
+
dropStore(e, t) {
|
|
423
|
+
return this.request("dropStore", [e, t]);
|
|
424
|
+
}
|
|
425
|
+
clearStore(e, t) {
|
|
426
|
+
return this.request("clearStore", [e, t]);
|
|
427
|
+
}
|
|
428
|
+
get(e, t, n) {
|
|
429
|
+
return this.request("get", [
|
|
430
|
+
e,
|
|
431
|
+
t,
|
|
432
|
+
n
|
|
433
|
+
]);
|
|
434
|
+
}
|
|
435
|
+
getMany(e, t, n) {
|
|
436
|
+
return this.request("getMany", [
|
|
437
|
+
e,
|
|
438
|
+
t,
|
|
439
|
+
n
|
|
440
|
+
]);
|
|
441
|
+
}
|
|
442
|
+
has(e, t, n) {
|
|
443
|
+
return this.request("has", [
|
|
444
|
+
e,
|
|
445
|
+
t,
|
|
446
|
+
n
|
|
447
|
+
]);
|
|
448
|
+
}
|
|
449
|
+
put(e, t, n, r, i) {
|
|
450
|
+
return this.request("put", [
|
|
451
|
+
e,
|
|
452
|
+
t,
|
|
453
|
+
n,
|
|
454
|
+
r,
|
|
455
|
+
i
|
|
456
|
+
]);
|
|
457
|
+
}
|
|
458
|
+
putMany(e, t, n, r) {
|
|
459
|
+
return this.request("putMany", [
|
|
460
|
+
e,
|
|
461
|
+
t,
|
|
462
|
+
n,
|
|
463
|
+
r
|
|
464
|
+
]);
|
|
465
|
+
}
|
|
466
|
+
delete(e, t, n) {
|
|
467
|
+
return this.request("delete", [
|
|
468
|
+
e,
|
|
469
|
+
t,
|
|
470
|
+
n
|
|
471
|
+
]);
|
|
472
|
+
}
|
|
473
|
+
deleteMany(e, t, n) {
|
|
474
|
+
return this.request("deleteMany", [
|
|
475
|
+
e,
|
|
476
|
+
t,
|
|
477
|
+
n
|
|
478
|
+
]);
|
|
479
|
+
}
|
|
480
|
+
applyBatch(e, t, n) {
|
|
481
|
+
return this.request("applyBatch", [
|
|
482
|
+
e,
|
|
483
|
+
t,
|
|
484
|
+
n
|
|
485
|
+
]);
|
|
486
|
+
}
|
|
487
|
+
scan(e, t, n) {
|
|
488
|
+
return this.request("scan", [
|
|
489
|
+
e,
|
|
490
|
+
t,
|
|
491
|
+
n
|
|
492
|
+
]);
|
|
493
|
+
}
|
|
494
|
+
getByIndex(e, t, n, r) {
|
|
495
|
+
return this.request("getByIndex", [
|
|
496
|
+
e,
|
|
497
|
+
t,
|
|
498
|
+
n,
|
|
499
|
+
r
|
|
500
|
+
]);
|
|
501
|
+
}
|
|
502
|
+
scanByIndex(e, t, n, r) {
|
|
503
|
+
return this.request("scanByIndex", [
|
|
504
|
+
e,
|
|
505
|
+
t,
|
|
506
|
+
n,
|
|
507
|
+
r
|
|
508
|
+
]);
|
|
509
|
+
}
|
|
510
|
+
scanByIndexPage(e, t, n, r, i, a) {
|
|
511
|
+
return this.request("scanByIndexPage", [
|
|
512
|
+
e,
|
|
513
|
+
t,
|
|
514
|
+
n,
|
|
515
|
+
r,
|
|
516
|
+
i,
|
|
517
|
+
a
|
|
518
|
+
]);
|
|
519
|
+
}
|
|
520
|
+
getIndexes() {
|
|
521
|
+
return this.request("getIndexes", []);
|
|
522
|
+
}
|
|
523
|
+
reconcileIndexes(e, t) {
|
|
524
|
+
return this.request("reconcileIndexes", [e, t]);
|
|
525
|
+
}
|
|
526
|
+
listStores() {
|
|
527
|
+
return this.request("listStores", []);
|
|
528
|
+
}
|
|
529
|
+
getVersion() {
|
|
530
|
+
return this.request("getVersion", []);
|
|
531
|
+
}
|
|
532
|
+
changesSince(e, t) {
|
|
533
|
+
return this.request("changesSince", [e, t]);
|
|
534
|
+
}
|
|
535
|
+
setSchemaVersion(e, t) {
|
|
536
|
+
return this.request("setSchemaVersion", [e, t]);
|
|
537
|
+
}
|
|
538
|
+
exportSnapshot(e) {
|
|
539
|
+
return this.request("exportSnapshot", [e]);
|
|
540
|
+
}
|
|
541
|
+
importSnapshot(e) {
|
|
542
|
+
return this.request("importSnapshot", [e]);
|
|
543
|
+
}
|
|
544
|
+
reset() {
|
|
545
|
+
return this.request("reset", []);
|
|
546
|
+
}
|
|
547
|
+
compact() {
|
|
548
|
+
return this.request("compact", []);
|
|
549
|
+
}
|
|
550
|
+
rebuild() {
|
|
551
|
+
return this.request("rebuild", []);
|
|
552
|
+
}
|
|
553
|
+
stats() {
|
|
554
|
+
return this.request("stats", []);
|
|
555
|
+
}
|
|
556
|
+
storageInfo() {
|
|
557
|
+
return this.request("storageInfo", []);
|
|
558
|
+
}
|
|
559
|
+
requestPersistence() {
|
|
560
|
+
return this.request("requestPersistence", []);
|
|
561
|
+
}
|
|
562
|
+
setFailpoint(e) {
|
|
563
|
+
return this.request("setFailpoint", [e]);
|
|
564
|
+
}
|
|
565
|
+
async request(e, t) {
|
|
566
|
+
return await this.send(e, t, e);
|
|
567
|
+
}
|
|
568
|
+
async send(e, t, n) {
|
|
569
|
+
this.ensureOpen(), this.awaitingReady += 1;
|
|
570
|
+
try {
|
|
571
|
+
await this.ready;
|
|
572
|
+
} finally {
|
|
573
|
+
--this.awaitingReady;
|
|
574
|
+
}
|
|
575
|
+
this.ensureOpen();
|
|
576
|
+
let r = this.batching && (this.awaitingReady > 0 || this.queuedRequests.length > 0), i = this.nextRequestId;
|
|
577
|
+
this.nextRequestId += 1;
|
|
578
|
+
let a = oe(e, t), o = {
|
|
579
|
+
type: "moyodb:worker-protocol:request",
|
|
580
|
+
version: 1,
|
|
581
|
+
id: i,
|
|
582
|
+
command: e,
|
|
583
|
+
args: a.args
|
|
584
|
+
};
|
|
585
|
+
return await new Promise((t, s) => {
|
|
586
|
+
let c = this.requestTimeoutMs > 0 ? setTimeout(() => {
|
|
587
|
+
this.pending.delete(i), s(m("WorkerRequestTimeoutError", `worker command ${e} timed out after ${this.requestTimeoutMs}ms`));
|
|
588
|
+
}, this.requestTimeoutMs) : null;
|
|
589
|
+
this.pending.set(i, {
|
|
590
|
+
command: n,
|
|
591
|
+
resolve: (e) => t(e),
|
|
592
|
+
reject: s,
|
|
593
|
+
timeout: c
|
|
594
|
+
});
|
|
595
|
+
try {
|
|
596
|
+
r ? this.queueRequest(o, a.transfer) : a.transfer.length > 0 ? this.worker.postMessage(o, a.transfer) : this.worker.postMessage(o);
|
|
597
|
+
} catch (e) {
|
|
598
|
+
this.rejectPending(i, e instanceof Error ? e : Error(String(e)));
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
queueRequest(e, t) {
|
|
603
|
+
let n = le(e, t);
|
|
604
|
+
this.pending.has(e.id) && (this.queuedRequests.length > 0 && this.queuedBytes + n.byteLength > 1048576 && this.flushRequests(), this.queuedRequests.push({
|
|
605
|
+
message: n.value,
|
|
606
|
+
transfer: n.transfer,
|
|
607
|
+
byteLength: n.byteLength
|
|
608
|
+
}), this.queuedBytes += n.byteLength, this.flushScheduled || (this.flushScheduled = !0, queueMicrotask(() => {
|
|
609
|
+
this.flushScheduled = !1, this.flushRequests();
|
|
610
|
+
})), (this.queuedRequests.length >= 128 || this.queuedBytes >= 1048576) && this.flushRequests());
|
|
611
|
+
}
|
|
612
|
+
flushRequests() {
|
|
613
|
+
let e = this.queuedRequests;
|
|
614
|
+
if (this.queuedRequests = [], this.queuedBytes = 0, this.closed) return;
|
|
615
|
+
let t = e.filter((e) => this.pending.has(e.message.id));
|
|
616
|
+
if (t.length === 0) return;
|
|
617
|
+
let n = t.length === 1 ? t[0].message : {
|
|
618
|
+
type: "moyodb:worker-protocol:request-batch",
|
|
619
|
+
version: 1,
|
|
620
|
+
requests: t.map((e) => e.message)
|
|
621
|
+
}, r = [];
|
|
622
|
+
for (let e of t) for (let t of e.transfer) r.push(t);
|
|
623
|
+
try {
|
|
624
|
+
r.length > 0 ? this.worker.postMessage(n, r) : this.worker.postMessage(n);
|
|
625
|
+
} catch (e) {
|
|
626
|
+
let n = e instanceof Error ? e : Error(String(e));
|
|
627
|
+
for (let e of t) this.rejectPending(e.message.id, n);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
ensureOpen() {
|
|
631
|
+
if (this.closed) throw this.closeReason ?? m("WorkerTerminatedError", "worker transport is closed");
|
|
632
|
+
}
|
|
633
|
+
handleMessage = (t) => {
|
|
634
|
+
let n = t.data;
|
|
635
|
+
if (te(n)) {
|
|
636
|
+
if (this.readyResolved) return;
|
|
637
|
+
this.batching = n.batching === 1, this.readyResolved = !0, this.readyResolve?.(), this.readyResolve = null, this.readyReject = null;
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (re(n)) {
|
|
641
|
+
for (let e of n.responses) this.handleResponse(e);
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (e(n) && n.type === "moyodb:worker-protocol:response-batch" && n.version === 1) {
|
|
645
|
+
this.disposeInternal(m("WorkerProtocolError", "invalid worker response batch"), !0);
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
this.handleResponse(n);
|
|
649
|
+
};
|
|
650
|
+
handleResponse(t) {
|
|
651
|
+
if (!ne(t)) {
|
|
652
|
+
e(t) && t.type === "moyodb:worker-protocol:response" && t.version === 1 && typeof t.id == "number" && Number.isSafeInteger(t.id) && this.rejectPending(t.id, m("WorkerProtocolError", "invalid worker response"));
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
let n = this.pending.get(t.id);
|
|
656
|
+
if (n) {
|
|
657
|
+
this.pending.delete(t.id), y(n);
|
|
658
|
+
try {
|
|
659
|
+
t.ok ? n.resolve(ce(n.command, t.result)) : n.reject(ae(t.error));
|
|
660
|
+
} catch (e) {
|
|
661
|
+
n.reject(e instanceof Error && e.name === "WorkerProtocolError" ? e : m("WorkerProtocolError", "worker response could not be decoded"));
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
handleMessageError = () => {
|
|
666
|
+
this.disposeInternal(m("WorkerMessageError", "worker message could not be deserialized"), !0);
|
|
667
|
+
};
|
|
668
|
+
handleError = (e) => {
|
|
669
|
+
let t = e.error instanceof Error ? e.error : m("WorkerError", e.message || "worker runtime failed");
|
|
670
|
+
this.disposeInternal(t, !0);
|
|
671
|
+
};
|
|
672
|
+
rejectPending(e, t) {
|
|
673
|
+
let n = this.pending.get(e);
|
|
674
|
+
n && (this.pending.delete(e), y(n), n.reject(t));
|
|
675
|
+
}
|
|
676
|
+
disposeInternal(e, t) {
|
|
677
|
+
if (!this.closed) {
|
|
678
|
+
this.closed = !0, this.closeReason = e, this.worker.removeEventListener("message", this.handleMessage), this.worker.removeEventListener("messageerror", this.handleMessageError), this.worker.removeEventListener("error", this.handleError), this.readyResolved || this.readyReject?.(e), this.readyResolve = null, this.readyReject = null, this.queuedRequests = [], this.queuedBytes = 0;
|
|
679
|
+
for (let t of this.pending.values()) y(t), t.reject(e);
|
|
680
|
+
this.pending.clear(), t && this.fatalHandler?.(e);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}, b = class extends Error {
|
|
684
|
+
constructor(e, t) {
|
|
685
|
+
super(t), this.name = e, Object.setPrototypeOf(this, new.target.prototype);
|
|
686
|
+
}
|
|
687
|
+
}, x = class extends b {
|
|
688
|
+
constructor(e) {
|
|
689
|
+
super("UnsupportedPlatformError", e);
|
|
690
|
+
}
|
|
691
|
+
}, S = class extends b {
|
|
692
|
+
constructor(e) {
|
|
693
|
+
super("DatabaseBusyError", e);
|
|
694
|
+
}
|
|
695
|
+
}, ye = class extends b {
|
|
696
|
+
constructor(e) {
|
|
697
|
+
super("CorruptionError", e);
|
|
698
|
+
}
|
|
699
|
+
}, be = class extends b {
|
|
700
|
+
constructor(e) {
|
|
701
|
+
super("StoreExistsError", e);
|
|
702
|
+
}
|
|
703
|
+
}, xe = class extends b {
|
|
704
|
+
constructor(e) {
|
|
705
|
+
super("StoreNotFoundError", e);
|
|
706
|
+
}
|
|
707
|
+
}, Se = class extends b {
|
|
708
|
+
constructor(e) {
|
|
709
|
+
super("IndexNotFoundError", e);
|
|
710
|
+
}
|
|
711
|
+
}, C = class extends b {
|
|
712
|
+
constructor(e) {
|
|
713
|
+
super("ConstraintError", e);
|
|
714
|
+
}
|
|
715
|
+
}, Ce = class extends C {
|
|
716
|
+
constructor(e) {
|
|
717
|
+
super(e), this.name = "UniqueIndexConstraintError";
|
|
718
|
+
}
|
|
719
|
+
}, we = class extends b {
|
|
720
|
+
constructor(e = "write transaction already open") {
|
|
721
|
+
super("WriteTransactionAlreadyOpenError", e);
|
|
722
|
+
}
|
|
723
|
+
}, Te = class extends b {
|
|
724
|
+
constructor(e = "readonly transaction cannot perform this operation") {
|
|
725
|
+
super("ReadonlyTransactionError", e);
|
|
726
|
+
}
|
|
727
|
+
}, w = class extends b {
|
|
728
|
+
constructor(e = "transaction is already closed") {
|
|
729
|
+
super("TransactionClosedError", e);
|
|
730
|
+
}
|
|
731
|
+
}, T = class extends b {
|
|
732
|
+
constructor(e = "database handle is closed") {
|
|
733
|
+
super("DatabaseClosedError", e);
|
|
734
|
+
}
|
|
735
|
+
}, Ee = class extends b {
|
|
736
|
+
constructor(e) {
|
|
737
|
+
super("ValueTooLargeError", e);
|
|
738
|
+
}
|
|
739
|
+
}, De = class extends b {
|
|
740
|
+
constructor(e) {
|
|
741
|
+
super("KeyTooLargeError", e);
|
|
742
|
+
}
|
|
743
|
+
}, Oe = class extends b {
|
|
744
|
+
constructor(e) {
|
|
745
|
+
super("StoreNameTooLongError", e);
|
|
746
|
+
}
|
|
747
|
+
}, E = class extends b {
|
|
748
|
+
constructor(e) {
|
|
749
|
+
super("ReservedStoreNameError", e);
|
|
750
|
+
}
|
|
751
|
+
}, ke = class extends b {
|
|
752
|
+
constructor(e) {
|
|
753
|
+
super("InvalidRangeError", e);
|
|
754
|
+
}
|
|
755
|
+
}, Ae = class extends b {
|
|
756
|
+
constructor(e) {
|
|
757
|
+
super("StorageError", e);
|
|
758
|
+
}
|
|
759
|
+
}, D = class extends b {
|
|
760
|
+
constructor(e) {
|
|
761
|
+
super("SerializationError", e);
|
|
762
|
+
}
|
|
763
|
+
}, je = class extends b {
|
|
764
|
+
constructor(e) {
|
|
765
|
+
super("InjectedFailureError", e);
|
|
766
|
+
}
|
|
767
|
+
}, Me = class extends b {
|
|
768
|
+
constructor(e) {
|
|
769
|
+
super("ChangeFeedCompactedError", e);
|
|
770
|
+
}
|
|
771
|
+
}, Ne = class extends b {
|
|
772
|
+
constructor(e) {
|
|
773
|
+
super("RecoveryRequiredError", e);
|
|
774
|
+
}
|
|
775
|
+
}, Pe = class extends b {
|
|
776
|
+
constructor(e) {
|
|
777
|
+
super("InternalError", e);
|
|
778
|
+
}
|
|
779
|
+
}, O = class extends b {
|
|
780
|
+
constructor(e) {
|
|
781
|
+
super("InvalidOpenOptionsError", e);
|
|
782
|
+
}
|
|
783
|
+
}, k = class extends b {
|
|
784
|
+
constructor(e) {
|
|
785
|
+
super("VersionError", e);
|
|
786
|
+
}
|
|
787
|
+
}, Fe = {
|
|
788
|
+
UnsupportedPlatformError: x,
|
|
789
|
+
DatabaseBusyError: S,
|
|
790
|
+
CorruptionError: ye,
|
|
791
|
+
StoreExistsError: be,
|
|
792
|
+
StoreNotFoundError: xe,
|
|
793
|
+
IndexNotFoundError: Se,
|
|
794
|
+
ConstraintError: C,
|
|
795
|
+
UniqueIndexConstraintError: Ce,
|
|
796
|
+
WriteTransactionAlreadyOpenError: we,
|
|
797
|
+
ReadonlyTransactionError: Te,
|
|
798
|
+
TransactionClosedError: w,
|
|
799
|
+
DatabaseClosedError: T,
|
|
800
|
+
ValueTooLargeError: Ee,
|
|
801
|
+
KeyTooLargeError: De,
|
|
802
|
+
StoreNameTooLongError: Oe,
|
|
803
|
+
ReservedStoreNameError: E,
|
|
804
|
+
InvalidRangeError: ke,
|
|
805
|
+
StorageError: Ae,
|
|
806
|
+
SerializationError: D,
|
|
807
|
+
InjectedFailureError: je,
|
|
808
|
+
ChangeFeedCompactedError: Me,
|
|
809
|
+
RecoveryRequiredError: Ne,
|
|
810
|
+
InternalError: Pe,
|
|
811
|
+
InvalidOpenOptionsError: O,
|
|
812
|
+
VersionError: k
|
|
813
|
+
};
|
|
814
|
+
function Ie(e, t) {
|
|
815
|
+
if (Object.prototype.hasOwnProperty.call(Fe, e)) {
|
|
816
|
+
let n = Fe[e];
|
|
817
|
+
return new n(t);
|
|
818
|
+
}
|
|
819
|
+
let n = Error(t);
|
|
820
|
+
return n.name = e, n;
|
|
821
|
+
}
|
|
822
|
+
function A(e) {
|
|
823
|
+
if (e instanceof b) return e;
|
|
824
|
+
if (e instanceof Error) return e.name === "Error" ? e : Ie(e.name, e.message);
|
|
825
|
+
let t = e;
|
|
826
|
+
return Ie(t?.code ?? t?.name ?? "Error", t?.message ?? String(e));
|
|
827
|
+
}
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/registry.ts
|
|
830
|
+
var Le = /* @__PURE__ */ new Set([
|
|
831
|
+
"after_wal_flush",
|
|
832
|
+
"after_main_flush",
|
|
833
|
+
"before_superblock_flush"
|
|
834
|
+
]), Re = "moyodb:persistence-bridge:init", ze = "moyodb:persistence-bridge:request", Be = "moyodb:persistence-bridge:response";
|
|
835
|
+
function Ve(t) {
|
|
836
|
+
return e(t) && t.type === ze && typeof t.id == "number" && (t.op === "persist" || t.op === "persisted");
|
|
837
|
+
}
|
|
838
|
+
var He = 1e5, j = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map();
|
|
839
|
+
function N(e, t) {
|
|
840
|
+
let n = (M.get(e) ?? Promise.resolve()).then(t), r = n.then(() => void 0, () => void 0);
|
|
841
|
+
return M.set(e, r), r.then(() => {
|
|
842
|
+
M.get(e) === r && M.delete(e);
|
|
843
|
+
}), n;
|
|
844
|
+
}
|
|
845
|
+
function Ue(e) {
|
|
846
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw new O("open options must be an object");
|
|
847
|
+
}
|
|
848
|
+
function P(e, t, n) {
|
|
849
|
+
if (e === void 0) return n;
|
|
850
|
+
if (typeof e != "boolean") throw new O(`${t} must be a boolean`);
|
|
851
|
+
return e;
|
|
852
|
+
}
|
|
853
|
+
function F(e, t, n) {
|
|
854
|
+
if (e === void 0) return n;
|
|
855
|
+
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw new O(`${t} must be a non-negative safe integer`);
|
|
856
|
+
return e;
|
|
857
|
+
}
|
|
858
|
+
function We(e) {
|
|
859
|
+
return Math.max(1, F(e, "cachePages", 256));
|
|
860
|
+
}
|
|
861
|
+
function Ge(e) {
|
|
862
|
+
if (e == null) return null;
|
|
863
|
+
if (typeof e != "string" || !Le.has(e)) throw new O(`debugFailpoint must be one of: ${Array.from(Le).join(", ")}`);
|
|
864
|
+
return e;
|
|
865
|
+
}
|
|
866
|
+
function Ke(e) {
|
|
867
|
+
if (e === void 0) return null;
|
|
868
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw new O("changeFeed must be an object");
|
|
869
|
+
let t = e, n = P(t.enabled, "changeFeed.enabled", !0), r = He;
|
|
870
|
+
if (t.retainTxids === null) r = null;
|
|
871
|
+
else if (t.retainTxids !== void 0 && (r = F(t.retainTxids, "changeFeed.retainTxids", 0), r === 0)) throw new O("changeFeed.retainTxids must be positive; disable the feed instead");
|
|
872
|
+
return {
|
|
873
|
+
enabled: n,
|
|
874
|
+
retainTxids: r
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
function qe(e = {}) {
|
|
878
|
+
return Ue(e), {
|
|
879
|
+
createIfMissing: P(e.createIfMissing, "createIfMissing", !0),
|
|
880
|
+
ownerWaitMs: F(e.ownerWaitMs, "ownerWaitMs", 0),
|
|
881
|
+
requestPersistence: P(e.requestPersistence, "requestPersistence", !0),
|
|
882
|
+
cachePages: We(e.cachePages),
|
|
883
|
+
debugFailpoint: Ge(e.debugFailpoint),
|
|
884
|
+
changeFeed: Ke(e.changeFeed)
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
function Je(e, t) {
|
|
888
|
+
return e?.enabled === t?.enabled && e?.retainTxids === t?.retainTxids;
|
|
889
|
+
}
|
|
890
|
+
function Ye(e, t, n) {
|
|
891
|
+
if (t.cachePages !== n.cachePages) throw new O(`database ${e} is already open in this tab with cachePages=${t.cachePages}; requested cachePages=${n.cachePages}`);
|
|
892
|
+
if (n.changeFeed !== null && !Je(t.changeFeed, n.changeFeed)) throw new O(`database ${e} is already open in this tab with a different changeFeed policy`);
|
|
893
|
+
}
|
|
894
|
+
async function Xe() {
|
|
895
|
+
let e = globalThis.navigator.storage;
|
|
896
|
+
return typeof e.persisted == "function" && await n(e.persisted(), 1e3, !1);
|
|
897
|
+
}
|
|
898
|
+
async function Ze() {
|
|
899
|
+
let e = globalThis.navigator.storage;
|
|
900
|
+
return typeof e.persist == "function" && await n(e.persist(), 1e3, !1);
|
|
901
|
+
}
|
|
902
|
+
async function Qe(e, t) {
|
|
903
|
+
let n = t.op === "persist" ? await Ze() : await Xe(), r = {
|
|
904
|
+
type: Be,
|
|
905
|
+
id: t.id,
|
|
906
|
+
granted: n
|
|
907
|
+
};
|
|
908
|
+
e.postMessage(r);
|
|
909
|
+
}
|
|
910
|
+
function $e(e) {
|
|
911
|
+
let t = new MessageChannel(), n = t.port1;
|
|
912
|
+
return n.addEventListener("message", (e) => {
|
|
913
|
+
let t = e.data;
|
|
914
|
+
Ve(t) && Qe(n, t);
|
|
915
|
+
}), n.start(), e.postMessage({ type: Re }, [t.port2]), { close() {
|
|
916
|
+
n.close();
|
|
917
|
+
} };
|
|
918
|
+
}
|
|
919
|
+
function et() {
|
|
920
|
+
let e = new Worker(new URL(
|
|
921
|
+
/* @vite-ignore */
|
|
922
|
+
"/assets/worker-KDc8Khl_.js",
|
|
923
|
+
"" + import.meta.url
|
|
924
|
+
), { type: "module" });
|
|
925
|
+
return {
|
|
926
|
+
worker: e,
|
|
927
|
+
proxy: new ve(e),
|
|
928
|
+
persistenceBridge: $e(e)
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
function tt(e, t, n, r, i) {
|
|
932
|
+
let a = {
|
|
933
|
+
dbName: e,
|
|
934
|
+
refs: 1,
|
|
935
|
+
worker: t,
|
|
936
|
+
proxy: n,
|
|
937
|
+
persistenceBridge: r,
|
|
938
|
+
options: i,
|
|
939
|
+
invalidated: !1,
|
|
940
|
+
schemaMigrationInProgress: !1,
|
|
941
|
+
txInvalidationListeners: /* @__PURE__ */ new Set(),
|
|
942
|
+
handleInvalidationListeners: /* @__PURE__ */ new Set()
|
|
943
|
+
};
|
|
944
|
+
return n.setFatalHandler(() => {
|
|
945
|
+
j.get(e) !== a || a.invalidated || (j.delete(e), a.refs = 0, L(a), a.persistenceBridge.close(), a.worker.terminate());
|
|
946
|
+
}), a;
|
|
947
|
+
}
|
|
948
|
+
function nt(e) {
|
|
949
|
+
for (let t of Array.from(e)) t();
|
|
950
|
+
}
|
|
951
|
+
function rt(e, t) {
|
|
952
|
+
return e.txInvalidationListeners.add(t), () => {
|
|
953
|
+
e.txInvalidationListeners.delete(t);
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
function it(e, t) {
|
|
957
|
+
return e.handleInvalidationListeners.add(t), () => {
|
|
958
|
+
e.handleInvalidationListeners.delete(t);
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
function I(e) {
|
|
962
|
+
nt(e.txInvalidationListeners);
|
|
963
|
+
}
|
|
964
|
+
function L(e) {
|
|
965
|
+
e.invalidated || (e.invalidated = !0, I(e), nt(e.handleInvalidationListeners));
|
|
966
|
+
}
|
|
967
|
+
function at(e) {
|
|
968
|
+
let t = j.get(e);
|
|
969
|
+
return t ? (j.delete(e), L(t), t.refs = 0, t.persistenceBridge.close(), t.proxy.dispose(/* @__PURE__ */ Error("worker was terminated by unsafeDebugCrashWorker")), t.worker.terminate(), !0) : !1;
|
|
970
|
+
}
|
|
971
|
+
async function ot(e, t = {}) {
|
|
972
|
+
let n = qe(t);
|
|
973
|
+
return N(e, async () => {
|
|
974
|
+
let t = j.get(e);
|
|
975
|
+
if (t) {
|
|
976
|
+
if (t.invalidated) j.delete(e);
|
|
977
|
+
else {
|
|
978
|
+
if (t.schemaMigrationInProgress) throw new S(`database ${e} is migrating; wait for openDB() to resolve`);
|
|
979
|
+
if (Ye(e, t.options, n), n.debugFailpoint !== null) try {
|
|
980
|
+
await t.proxy.setFailpoint(n.debugFailpoint);
|
|
981
|
+
} catch (e) {
|
|
982
|
+
throw A(e);
|
|
983
|
+
}
|
|
984
|
+
return t.refs += 1, t;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
let { worker: r, proxy: i, persistenceBridge: a } = et(), o = tt(e, r, i, a, n);
|
|
988
|
+
try {
|
|
989
|
+
return await i.open({
|
|
990
|
+
dbName: e,
|
|
991
|
+
options: n
|
|
992
|
+
}), j.set(e, o), o;
|
|
993
|
+
} catch (e) {
|
|
994
|
+
throw a.close(), i.dispose(/* @__PURE__ */ Error("worker open failed")), r.terminate(), A(e);
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
async function st(e) {
|
|
999
|
+
return N(e.dbName, async () => {
|
|
1000
|
+
if (!(e.invalidated || j.get(e.dbName) !== e) && (--e.refs, !(e.refs > 0))) {
|
|
1001
|
+
j.delete(e.dbName);
|
|
1002
|
+
try {
|
|
1003
|
+
await e.proxy.close();
|
|
1004
|
+
} finally {
|
|
1005
|
+
e.persistenceBridge.close(), e.proxy.dispose(/* @__PURE__ */ Error("worker was released")), e.worker.terminate();
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
async function ct(e) {
|
|
1011
|
+
return N(e.dbName, () => lt(e));
|
|
1012
|
+
}
|
|
1013
|
+
async function lt(e) {
|
|
1014
|
+
if (e.invalidated || j.get(e.dbName) !== e) throw new T();
|
|
1015
|
+
j.delete(e.dbName), L(e), e.refs = 0;
|
|
1016
|
+
try {
|
|
1017
|
+
await e.proxy.destroy();
|
|
1018
|
+
} catch (e) {
|
|
1019
|
+
throw A(e);
|
|
1020
|
+
} finally {
|
|
1021
|
+
e.persistenceBridge.close(), e.proxy.dispose(/* @__PURE__ */ Error("worker was released")), e.worker.terminate();
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
async function ut(e) {
|
|
1025
|
+
return N(e, async () => {
|
|
1026
|
+
let t = j.get(e);
|
|
1027
|
+
if (t) {
|
|
1028
|
+
await lt(t);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
let { worker: n, proxy: r, persistenceBridge: i } = et();
|
|
1032
|
+
try {
|
|
1033
|
+
await r.deleteDB(e);
|
|
1034
|
+
} catch (e) {
|
|
1035
|
+
throw A(e);
|
|
1036
|
+
} finally {
|
|
1037
|
+
i.close(), r.dispose(/* @__PURE__ */ Error("temporary worker was terminated")), n.terminate();
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
//#endregion
|
|
1042
|
+
//#region src/codec.ts
|
|
1043
|
+
var dt = new TextEncoder(), ft = new TextDecoder(), pt = new TextDecoder("utf-8", { fatal: !0 }), mt = 16, ht = 32, gt = 33, _t = 48, vt = 64, yt = 80, R = 0, bt = 255, z = 0, xt = BigInt("0xffffffffffffffff");
|
|
1044
|
+
function B(e) {
|
|
1045
|
+
return dt.encode(e);
|
|
1046
|
+
}
|
|
1047
|
+
function St(e) {
|
|
1048
|
+
return ft.decode(e);
|
|
1049
|
+
}
|
|
1050
|
+
function Ct(e) {
|
|
1051
|
+
let t = JSON.stringify(e);
|
|
1052
|
+
if (t === void 0) throw TypeError("value has no JSON representation");
|
|
1053
|
+
return B(t);
|
|
1054
|
+
}
|
|
1055
|
+
function wt(e) {
|
|
1056
|
+
return JSON.parse(pt.decode(e));
|
|
1057
|
+
}
|
|
1058
|
+
function Tt(e) {
|
|
1059
|
+
if (typeof e == "number" && (!Number.isSafeInteger(e) || e < 0)) throw RangeError("u64Key number inputs must be safe non-negative integers; use bigint for larger values");
|
|
1060
|
+
let t = typeof e == "bigint" ? e : BigInt(e);
|
|
1061
|
+
if (t < 0n) throw RangeError("u64Key only accepts non-negative values");
|
|
1062
|
+
if (t > xt) throw RangeError("u64Key value exceeds the unsigned 64-bit range");
|
|
1063
|
+
let n = /* @__PURE__ */ new ArrayBuffer(8);
|
|
1064
|
+
return new DataView(n).setBigUint64(0, t, !1), new Uint8Array(n);
|
|
1065
|
+
}
|
|
1066
|
+
function Et(e) {
|
|
1067
|
+
return Array.isArray(e);
|
|
1068
|
+
}
|
|
1069
|
+
function Dt(e) {
|
|
1070
|
+
return Et(e) ? V(...e) : G(e);
|
|
1071
|
+
}
|
|
1072
|
+
function V(...e) {
|
|
1073
|
+
return jt(e.map((e) => G(e)));
|
|
1074
|
+
}
|
|
1075
|
+
function Ot(e) {
|
|
1076
|
+
return G(e);
|
|
1077
|
+
}
|
|
1078
|
+
function H(e) {
|
|
1079
|
+
return jt(e);
|
|
1080
|
+
}
|
|
1081
|
+
function kt(e) {
|
|
1082
|
+
let t = [], n = [];
|
|
1083
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
1084
|
+
let i = e[r];
|
|
1085
|
+
if (i !== R) {
|
|
1086
|
+
n.push(i);
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
let a = e[r + 1];
|
|
1090
|
+
if (a === bt) {
|
|
1091
|
+
n.push(R), r += 1;
|
|
1092
|
+
continue;
|
|
1093
|
+
}
|
|
1094
|
+
if (a === z) {
|
|
1095
|
+
t.push(Uint8Array.from(n)), n.length = 0, r += 1;
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
throw TypeError("invalid compound key encoding");
|
|
1099
|
+
}
|
|
1100
|
+
if (n.length !== 0) throw TypeError("compound key terminated unexpectedly");
|
|
1101
|
+
return t;
|
|
1102
|
+
}
|
|
1103
|
+
function U(e) {
|
|
1104
|
+
let t = e.slice();
|
|
1105
|
+
for (let e = t.length - 1; e >= 0; --e) if (t[e] !== 255) return t[e] += 1, t.subarray(0, e + 1);
|
|
1106
|
+
return null;
|
|
1107
|
+
}
|
|
1108
|
+
function W(e) {
|
|
1109
|
+
let t = U(e);
|
|
1110
|
+
return t ? {
|
|
1111
|
+
gte: e,
|
|
1112
|
+
lt: t
|
|
1113
|
+
} : { gte: e };
|
|
1114
|
+
}
|
|
1115
|
+
function At(...e) {
|
|
1116
|
+
return W(V(...e));
|
|
1117
|
+
}
|
|
1118
|
+
function G(e) {
|
|
1119
|
+
if (e === null) return Uint8Array.of(mt);
|
|
1120
|
+
if (typeof e == "boolean") return Uint8Array.of(e ? gt : ht);
|
|
1121
|
+
if (typeof e == "number") return Mt(e);
|
|
1122
|
+
if (typeof e == "string") {
|
|
1123
|
+
for (let t of e) {
|
|
1124
|
+
let e = t.codePointAt(0);
|
|
1125
|
+
if (e >= 55296 && e <= 57343) throw TypeError("compound key string parts must contain valid Unicode scalar values");
|
|
1126
|
+
}
|
|
1127
|
+
let t = B(e), n = new Uint8Array(1 + t.length);
|
|
1128
|
+
return n[0] = vt, n.set(t, 1), n;
|
|
1129
|
+
}
|
|
1130
|
+
if (e instanceof Uint8Array) {
|
|
1131
|
+
let t = new Uint8Array(1 + e.length);
|
|
1132
|
+
return t[0] = yt, t.set(e, 1), t;
|
|
1133
|
+
}
|
|
1134
|
+
throw TypeError("compound key parts must be string, number, boolean, null, or Uint8Array");
|
|
1135
|
+
}
|
|
1136
|
+
function jt(e) {
|
|
1137
|
+
let t = 0;
|
|
1138
|
+
for (let n of e) {
|
|
1139
|
+
for (let e of n) t += e === R ? 2 : 1;
|
|
1140
|
+
t += 2;
|
|
1141
|
+
}
|
|
1142
|
+
let n = new Uint8Array(t), r = 0;
|
|
1143
|
+
for (let t of e) {
|
|
1144
|
+
for (let e of t) e === R ? (n[r] = R, n[r + 1] = bt, r += 2) : (n[r] = e, r += 1);
|
|
1145
|
+
n[r] = z, n[r + 1] = z, r += 2;
|
|
1146
|
+
}
|
|
1147
|
+
return n;
|
|
1148
|
+
}
|
|
1149
|
+
function Mt(e) {
|
|
1150
|
+
if (!Number.isFinite(e)) throw TypeError("compound key number parts must be finite");
|
|
1151
|
+
let t = Object.is(e, -0) ? 0 : e, n = /* @__PURE__ */ new ArrayBuffer(9), r = new DataView(n);
|
|
1152
|
+
r.setUint8(0, _t), r.setFloat64(1, t, !1);
|
|
1153
|
+
let i = r.getBigUint64(1, !1);
|
|
1154
|
+
return i = (i & 1n << 63n) == 0n ? i ^ 1n << 63n : ~i & xt, r.setBigUint64(1, i, !1), new Uint8Array(n);
|
|
1155
|
+
}
|
|
1156
|
+
//#endregion
|
|
1157
|
+
//#region src/indexing.ts
|
|
1158
|
+
var Nt = new TextEncoder(), Pt = new TextDecoder("utf-8", { fatal: !0 }), K = Symbol("moyodb.indexing.missing"), Ft = BigInt("0xcbf29ce484222325"), It = BigInt("0x100000001b3"), Lt = BigInt("0xffffffffffffffff"), Rt = "__browserdb:", zt = "__browserdb:index:", Bt = "__browserdb:indexes";
|
|
1159
|
+
function Vt(e) {
|
|
1160
|
+
return e.startsWith(Rt);
|
|
1161
|
+
}
|
|
1162
|
+
function q(e) {
|
|
1163
|
+
if (Vt(e)) throw new E(`reserved store name: ${e}`);
|
|
1164
|
+
}
|
|
1165
|
+
function J(e) {
|
|
1166
|
+
if (e === void 0) return [];
|
|
1167
|
+
if (!Array.isArray(e)) throw new O("indexes must be an array");
|
|
1168
|
+
let t = [], n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
|
|
1169
|
+
for (let i of e) {
|
|
1170
|
+
if (typeof i != "object" || !i || Array.isArray(i)) throw new O("each index definition must be an object");
|
|
1171
|
+
let { store: e, name: a, keyPath: o, unique: s } = i;
|
|
1172
|
+
if (typeof e != "string" || e.length === 0) throw new O("index store must be a non-empty string");
|
|
1173
|
+
if (typeof a != "string" || a.length === 0) throw new O("index name must be a non-empty string");
|
|
1174
|
+
q(e);
|
|
1175
|
+
let c = sn(o);
|
|
1176
|
+
if (s !== void 0 && typeof s != "boolean") throw new O("index unique must be a boolean");
|
|
1177
|
+
let l = {
|
|
1178
|
+
store: e,
|
|
1179
|
+
name: a,
|
|
1180
|
+
keyPath: c.paths,
|
|
1181
|
+
compound: c.compound,
|
|
1182
|
+
unique: s ?? !1,
|
|
1183
|
+
internalStore: un(e, a)
|
|
1184
|
+
}, u = Ut(l.store, l.name);
|
|
1185
|
+
if (n.has(u)) throw new O(`duplicate index definition ${l.store}.${l.name}`);
|
|
1186
|
+
n.add(u);
|
|
1187
|
+
let d = r.get(l.internalStore);
|
|
1188
|
+
if (d && d !== u) throw new O(`index definitions ${d} and ${u} map to the same internal store ${l.internalStore}`);
|
|
1189
|
+
r.set(l.internalStore, u), t.push(l);
|
|
1190
|
+
}
|
|
1191
|
+
return t.sort(Ht), t;
|
|
1192
|
+
}
|
|
1193
|
+
function Ht(e, n) {
|
|
1194
|
+
let r = t(e.store, n.store);
|
|
1195
|
+
if (r !== 0) return r;
|
|
1196
|
+
let i = t(e.name, n.name);
|
|
1197
|
+
if (i !== 0) return i;
|
|
1198
|
+
let a = Number(e.unique) - Number(n.unique);
|
|
1199
|
+
return a === 0 ? t(ln(e), ln(n)) : a;
|
|
1200
|
+
}
|
|
1201
|
+
function Ut(e, t) {
|
|
1202
|
+
return JSON.stringify([e, t]);
|
|
1203
|
+
}
|
|
1204
|
+
function Wt(e, t, n) {
|
|
1205
|
+
return e.find((e) => e.store === t && e.name === n) ?? null;
|
|
1206
|
+
}
|
|
1207
|
+
function Gt(e, t) {
|
|
1208
|
+
return e.filter((e) => e.store === t);
|
|
1209
|
+
}
|
|
1210
|
+
function Kt(e, t) {
|
|
1211
|
+
return H([B(e), B(t)]);
|
|
1212
|
+
}
|
|
1213
|
+
function qt(e) {
|
|
1214
|
+
return B(JSON.stringify(on(e)));
|
|
1215
|
+
}
|
|
1216
|
+
function Jt(e) {
|
|
1217
|
+
let t;
|
|
1218
|
+
try {
|
|
1219
|
+
t = JSON.parse(Pt.decode(e));
|
|
1220
|
+
let [n] = J([t]);
|
|
1221
|
+
return n;
|
|
1222
|
+
} catch (e) {
|
|
1223
|
+
throw new D(`invalid persisted index metadata: ${String(e)}`);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
function Yt(e, t) {
|
|
1227
|
+
return H([e, t]);
|
|
1228
|
+
}
|
|
1229
|
+
function Xt(e) {
|
|
1230
|
+
let t;
|
|
1231
|
+
try {
|
|
1232
|
+
t = kt(e);
|
|
1233
|
+
} catch (e) {
|
|
1234
|
+
throw new D(`invalid index entry key encoding: ${String(e)}`);
|
|
1235
|
+
}
|
|
1236
|
+
if (t.length !== 2) throw new D("invalid index entry key encoding");
|
|
1237
|
+
return {
|
|
1238
|
+
logicalKey: t[0],
|
|
1239
|
+
primaryKey: t[1]
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
function Zt(e) {
|
|
1243
|
+
return W(H([e]));
|
|
1244
|
+
}
|
|
1245
|
+
function Qt(e = {}) {
|
|
1246
|
+
_n(e);
|
|
1247
|
+
let t = {};
|
|
1248
|
+
if (e.reverse !== void 0 && (t.reverse = e.reverse), e.limit !== void 0 && (t.limit = e.limit), e.gte && (t.gte = H([e.gte])), e.gt) {
|
|
1249
|
+
let n = U(H([e.gt]));
|
|
1250
|
+
n && (t.gte = n);
|
|
1251
|
+
}
|
|
1252
|
+
if (e.lt && (t.lt = H([e.lt])), e.lte) {
|
|
1253
|
+
let n = U(H([e.lte]));
|
|
1254
|
+
n && (t.lt = n);
|
|
1255
|
+
}
|
|
1256
|
+
return t;
|
|
1257
|
+
}
|
|
1258
|
+
function $t(e, t) {
|
|
1259
|
+
return tn(e, pn(t));
|
|
1260
|
+
}
|
|
1261
|
+
function en(e) {
|
|
1262
|
+
let t = !1, n;
|
|
1263
|
+
return (r) => (t ||= (n = pn(e), !0), tn(r, n));
|
|
1264
|
+
}
|
|
1265
|
+
function tn(e, t) {
|
|
1266
|
+
if (e.compound) {
|
|
1267
|
+
let n = [];
|
|
1268
|
+
for (let r of e.keyPath) {
|
|
1269
|
+
let e = mn(t, r);
|
|
1270
|
+
if (e === K) return null;
|
|
1271
|
+
n.push(hn(e));
|
|
1272
|
+
}
|
|
1273
|
+
return H(n);
|
|
1274
|
+
}
|
|
1275
|
+
let n = mn(t, e.keyPath[0]);
|
|
1276
|
+
return n === K ? null : hn(n);
|
|
1277
|
+
}
|
|
1278
|
+
function nn(e) {
|
|
1279
|
+
return JSON.stringify(an(e));
|
|
1280
|
+
}
|
|
1281
|
+
function rn(e) {
|
|
1282
|
+
return e.map((e) => ({
|
|
1283
|
+
store: e.store,
|
|
1284
|
+
name: e.name,
|
|
1285
|
+
keyPath: [...e.keyPath],
|
|
1286
|
+
compound: e.compound,
|
|
1287
|
+
unique: e.unique,
|
|
1288
|
+
internalStore: e.internalStore
|
|
1289
|
+
}));
|
|
1290
|
+
}
|
|
1291
|
+
function an(e) {
|
|
1292
|
+
return e.map(on);
|
|
1293
|
+
}
|
|
1294
|
+
function on(e) {
|
|
1295
|
+
return {
|
|
1296
|
+
store: e.store,
|
|
1297
|
+
name: e.name,
|
|
1298
|
+
keyPath: e.compound ? [...e.keyPath] : e.keyPath[0],
|
|
1299
|
+
unique: e.unique
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
function sn(e) {
|
|
1303
|
+
if (typeof e == "string") return cn(e), {
|
|
1304
|
+
paths: [e],
|
|
1305
|
+
compound: !1
|
|
1306
|
+
};
|
|
1307
|
+
if (!Array.isArray(e) || e.length === 0 || !e.every((e) => typeof e == "string")) throw new O("index keyPath must be a non-empty string or non-empty string[]");
|
|
1308
|
+
for (let t of e) cn(t);
|
|
1309
|
+
return {
|
|
1310
|
+
paths: [...e],
|
|
1311
|
+
compound: !0
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
function cn(e) {
|
|
1315
|
+
if (e.length === 0) throw new O("index keyPath strings must be non-empty");
|
|
1316
|
+
if (e.startsWith(".") || e.endsWith(".") || e.includes("..")) throw new O(`invalid index keyPath: ${e}`);
|
|
1317
|
+
}
|
|
1318
|
+
function ln(e) {
|
|
1319
|
+
return e.compound ? `[${e.keyPath.join(",")}]` : e.keyPath[0];
|
|
1320
|
+
}
|
|
1321
|
+
function un(e, t) {
|
|
1322
|
+
let n = `${zt}${dn(B(e))}:${dn(B(t))}`;
|
|
1323
|
+
return Nt.encode(n).length <= 255 ? n : `${zt}h:${fn(B(`${e}\u0000${t}`))}`;
|
|
1324
|
+
}
|
|
1325
|
+
function dn(e) {
|
|
1326
|
+
let t = "";
|
|
1327
|
+
for (let n of e) t += String.fromCharCode(n);
|
|
1328
|
+
return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/u, "");
|
|
1329
|
+
}
|
|
1330
|
+
function fn(e) {
|
|
1331
|
+
let t = Ft;
|
|
1332
|
+
for (let n of e) t ^= BigInt(n), t = t * It & Lt;
|
|
1333
|
+
return t.toString(16).padStart(16, "0");
|
|
1334
|
+
}
|
|
1335
|
+
function pn(e) {
|
|
1336
|
+
try {
|
|
1337
|
+
return JSON.parse(Pt.decode(e));
|
|
1338
|
+
} catch (e) {
|
|
1339
|
+
throw new D(`indexed values must be valid UTF-8 JSON: ${String(e)}`);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
function mn(e, t) {
|
|
1343
|
+
let n = e;
|
|
1344
|
+
for (let e of t.split(".")) {
|
|
1345
|
+
if (n == null) return K;
|
|
1346
|
+
let t = Object(n);
|
|
1347
|
+
if (!Object.hasOwn(t, e)) return K;
|
|
1348
|
+
n = Reflect.get(t, e);
|
|
1349
|
+
}
|
|
1350
|
+
return n;
|
|
1351
|
+
}
|
|
1352
|
+
function hn(e) {
|
|
1353
|
+
if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e instanceof Uint8Array) try {
|
|
1354
|
+
return Ot(e);
|
|
1355
|
+
} catch (e) {
|
|
1356
|
+
throw e instanceof TypeError ? new D(`invalid indexed keyPath value: ${e.message}`) : e;
|
|
1357
|
+
}
|
|
1358
|
+
throw new D(`indexed keyPath values must resolve to string, number, boolean, null, or Uint8Array; got ${gn(e)}`);
|
|
1359
|
+
}
|
|
1360
|
+
function gn(e) {
|
|
1361
|
+
return Array.isArray(e) ? "array" : typeof e;
|
|
1362
|
+
}
|
|
1363
|
+
function _n(e) {
|
|
1364
|
+
if (e.gt !== void 0 && e.gte !== void 0) throw TypeError("index range cannot specify both gt and gte");
|
|
1365
|
+
if (e.lt !== void 0 && e.lte !== void 0) throw TypeError("index range cannot specify both lt and lte");
|
|
1366
|
+
}
|
|
1367
|
+
//#endregion
|
|
1368
|
+
//#region src/change-events.ts
|
|
1369
|
+
function vn(t) {
|
|
1370
|
+
return !e(t) || !(t.key instanceof Uint8Array) ? !1 : t.kind === "put" || t.kind === "delete" || (t.kind === "clear" || t.kind === "drop") && t.key.byteLength === 0;
|
|
1371
|
+
}
|
|
1372
|
+
function yn(t) {
|
|
1373
|
+
return e(t) && typeof t.store == "string" && Array.isArray(t.changes) && t.changes.every(vn);
|
|
1374
|
+
}
|
|
1375
|
+
function bn(t) {
|
|
1376
|
+
return e(t) && t.type === "commit_applied" && typeof t.dbName == "string" && typeof t.txid == "number" && Array.isArray(t.stores) && t.stores.every(yn);
|
|
1377
|
+
}
|
|
1378
|
+
//#endregion
|
|
1379
|
+
//#region src/subscriptions.ts
|
|
1380
|
+
function xn(e) {
|
|
1381
|
+
return e.map((e) => ({
|
|
1382
|
+
key: e.key.slice(),
|
|
1383
|
+
kind: e.kind
|
|
1384
|
+
}));
|
|
1385
|
+
}
|
|
1386
|
+
function Sn(e, t) {
|
|
1387
|
+
if (t.byteLength > e.byteLength) return !1;
|
|
1388
|
+
for (let n = 0; n < t.byteLength; n += 1) if (e[n] !== t[n]) return !1;
|
|
1389
|
+
return !0;
|
|
1390
|
+
}
|
|
1391
|
+
function Cn(e, t, n) {
|
|
1392
|
+
if (typeof e == "function") {
|
|
1393
|
+
if (t !== void 0 || n !== void 0) throw TypeError("subscribe(callback) accepts exactly one callback argument");
|
|
1394
|
+
return {
|
|
1395
|
+
store: null,
|
|
1396
|
+
keyPrefix: null,
|
|
1397
|
+
callback: e
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
if (typeof e != "string") throw TypeError("subscribe() storeName must be a string");
|
|
1401
|
+
if (q(e), typeof t == "function") {
|
|
1402
|
+
if (n !== void 0) throw TypeError("subscribe(storeName, callback) accepts exactly two arguments");
|
|
1403
|
+
return {
|
|
1404
|
+
store: e,
|
|
1405
|
+
keyPrefix: null,
|
|
1406
|
+
callback: t
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
if (t instanceof Uint8Array && typeof n == "function") return {
|
|
1410
|
+
store: e,
|
|
1411
|
+
keyPrefix: t.slice(),
|
|
1412
|
+
callback: n
|
|
1413
|
+
};
|
|
1414
|
+
throw TypeError("subscribe() expects one of: (callback), (storeName, callback), (storeName, keyPrefix, callback)");
|
|
1415
|
+
}
|
|
1416
|
+
var wn = class {
|
|
1417
|
+
#e;
|
|
1418
|
+
#t = null;
|
|
1419
|
+
#n = /* @__PURE__ */ new Set();
|
|
1420
|
+
#r = !1;
|
|
1421
|
+
constructor(e) {
|
|
1422
|
+
this.#e = e;
|
|
1423
|
+
}
|
|
1424
|
+
subscribe(e, t, n) {
|
|
1425
|
+
if (this.#r) throw new T();
|
|
1426
|
+
let r = Cn(e, t, n), i = {
|
|
1427
|
+
active: !0,
|
|
1428
|
+
store: r.store,
|
|
1429
|
+
keyPrefix: r.keyPrefix,
|
|
1430
|
+
callback: r.callback
|
|
1431
|
+
};
|
|
1432
|
+
return this.#i(), this.#n.add(i), () => {
|
|
1433
|
+
i.active && (i.active = !1, this.#n.delete(i), this.#n.size === 0 && this.#a());
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
close() {
|
|
1437
|
+
if (!this.#r) {
|
|
1438
|
+
this.#r = !0;
|
|
1439
|
+
for (let e of this.#n) e.active = !1;
|
|
1440
|
+
this.#n.clear(), this.#a();
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
#i() {
|
|
1444
|
+
if (this.#t !== null || this.#r) return;
|
|
1445
|
+
let e = new BroadcastChannel(`db:${this.#e}:events`);
|
|
1446
|
+
e.onmessage = (e) => {
|
|
1447
|
+
this.#o(e.data);
|
|
1448
|
+
}, this.#t = e;
|
|
1449
|
+
}
|
|
1450
|
+
#a() {
|
|
1451
|
+
this.#t?.close(), this.#t = null;
|
|
1452
|
+
}
|
|
1453
|
+
#o(e) {
|
|
1454
|
+
if (!bn(e) || e.dbName !== this.#e || this.#n.size === 0) return;
|
|
1455
|
+
let t = Array.from(this.#n);
|
|
1456
|
+
for (let n of e.stores) for (let r of t) {
|
|
1457
|
+
if (!r.active || r.store !== null && r.store !== n.store) continue;
|
|
1458
|
+
let t, i = r.keyPrefix;
|
|
1459
|
+
if (i === null) t = xn(n.changes);
|
|
1460
|
+
else if (t = xn(n.changes.filter((e) => e.kind === "clear" || e.kind === "drop" || Sn(e.key, i))), t.length === 0) continue;
|
|
1461
|
+
try {
|
|
1462
|
+
r.callback(n.store, t, e.txid);
|
|
1463
|
+
} catch (e) {
|
|
1464
|
+
queueMicrotask(() => {
|
|
1465
|
+
throw e;
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
}, Tn = 256;
|
|
1471
|
+
async function Y(e) {
|
|
1472
|
+
try {
|
|
1473
|
+
return await e();
|
|
1474
|
+
} catch (e) {
|
|
1475
|
+
throw A(e);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
var En = class {
|
|
1479
|
+
mode;
|
|
1480
|
+
#e;
|
|
1481
|
+
#t;
|
|
1482
|
+
#n = !1;
|
|
1483
|
+
#r;
|
|
1484
|
+
constructor(e, t, n, r) {
|
|
1485
|
+
this.#e = e, this.#t = t, this.mode = n, this.#r = r;
|
|
1486
|
+
}
|
|
1487
|
+
async get(e, t) {
|
|
1488
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.get(this.#t, e, t));
|
|
1489
|
+
}
|
|
1490
|
+
async getMany(e, t) {
|
|
1491
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.getMany(this.#t, e, t));
|
|
1492
|
+
}
|
|
1493
|
+
async has(e, t) {
|
|
1494
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.has(this.#t, e, t));
|
|
1495
|
+
}
|
|
1496
|
+
async put(e, t, n, r = {}) {
|
|
1497
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.put(this.#t, e, t, n, $(r)));
|
|
1498
|
+
}
|
|
1499
|
+
async putMany(e, t, n = {}) {
|
|
1500
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.putMany(this.#t, e, t, $(n)));
|
|
1501
|
+
}
|
|
1502
|
+
async delete(e, t) {
|
|
1503
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.delete(this.#t, e, t));
|
|
1504
|
+
}
|
|
1505
|
+
async deleteMany(e, t) {
|
|
1506
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.deleteMany(this.#t, e, t));
|
|
1507
|
+
}
|
|
1508
|
+
async applyBatch(e, t) {
|
|
1509
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.applyBatch(this.#t, e, t));
|
|
1510
|
+
}
|
|
1511
|
+
async scan(e, t = {}) {
|
|
1512
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.scan(this.#t, e, t));
|
|
1513
|
+
}
|
|
1514
|
+
async getByIndex(e, t, n) {
|
|
1515
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.getByIndex(this.#t, e, t, n));
|
|
1516
|
+
}
|
|
1517
|
+
async *scanByIndex(e, t, n = {}) {
|
|
1518
|
+
this.#i(), q(e);
|
|
1519
|
+
let r = n.limit ?? Infinity, i = null;
|
|
1520
|
+
for (; r > 0;) {
|
|
1521
|
+
this.#i();
|
|
1522
|
+
let a = Math.min(r, Tn), o = i, s = await Y(() => this.#e.proxy.scanByIndexPage(this.#t, e, t, n, o, a));
|
|
1523
|
+
for (let e of s.rows) yield [e.key, e.value];
|
|
1524
|
+
if (r -= s.rows.length, s.cursor === null) return;
|
|
1525
|
+
i = s.cursor;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
async createStore(e, t = {}) {
|
|
1529
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.createStore(this.#t, e, Rn(t)));
|
|
1530
|
+
}
|
|
1531
|
+
async dropStore(e) {
|
|
1532
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.dropStore(this.#t, e));
|
|
1533
|
+
}
|
|
1534
|
+
async clearStore(e) {
|
|
1535
|
+
return this.#i(), q(e), Y(() => this.#e.proxy.clearStore(this.#t, e));
|
|
1536
|
+
}
|
|
1537
|
+
async commit() {
|
|
1538
|
+
this.#i();
|
|
1539
|
+
try {
|
|
1540
|
+
await Y(() => this.#e.proxy.commit(this.#t));
|
|
1541
|
+
} finally {
|
|
1542
|
+
this.#a();
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
async rollback() {
|
|
1546
|
+
this.#i();
|
|
1547
|
+
try {
|
|
1548
|
+
await Y(() => this.#e.proxy.rollback(this.#t));
|
|
1549
|
+
} finally {
|
|
1550
|
+
this.#a();
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
async rollbackIfOpen() {
|
|
1554
|
+
if (!this.#n) {
|
|
1555
|
+
if (this.#e.invalidated) {
|
|
1556
|
+
this.#a();
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
try {
|
|
1560
|
+
await this.#e.proxy.rollback(this.#t);
|
|
1561
|
+
} catch (e) {
|
|
1562
|
+
let t = A(e);
|
|
1563
|
+
if (!(t instanceof w)) throw t;
|
|
1564
|
+
} finally {
|
|
1565
|
+
this.#a();
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
forceClose() {
|
|
1570
|
+
this.#a();
|
|
1571
|
+
}
|
|
1572
|
+
internalId() {
|
|
1573
|
+
return this.#t;
|
|
1574
|
+
}
|
|
1575
|
+
#i() {
|
|
1576
|
+
if (this.#n || this.#e.invalidated) throw new w();
|
|
1577
|
+
}
|
|
1578
|
+
#a() {
|
|
1579
|
+
this.#n || (this.#n = !0, this.#r());
|
|
1580
|
+
}
|
|
1581
|
+
}, Dn = class {
|
|
1582
|
+
#e;
|
|
1583
|
+
#t = !1;
|
|
1584
|
+
#n = null;
|
|
1585
|
+
#r = /* @__PURE__ */ new Set();
|
|
1586
|
+
#i = /* @__PURE__ */ new Set();
|
|
1587
|
+
#a = 0;
|
|
1588
|
+
#o;
|
|
1589
|
+
#s = null;
|
|
1590
|
+
#c = null;
|
|
1591
|
+
constructor(e) {
|
|
1592
|
+
this.#e = e, this.#o = new wn(e.dbName), this.#s = rt(e, () => {
|
|
1593
|
+
this.#p();
|
|
1594
|
+
}), this.#c = it(e, () => {
|
|
1595
|
+
this.#m();
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
async begin(e = "readonly") {
|
|
1599
|
+
return this.#l(e);
|
|
1600
|
+
}
|
|
1601
|
+
async runSchemaMigration(e, t, n, r) {
|
|
1602
|
+
this.#h();
|
|
1603
|
+
let i = await this.#l("readwrite"), a = new On(), o = new kn(i, a), s = new An(this, o, a);
|
|
1604
|
+
try {
|
|
1605
|
+
await this.#e.proxy.reconcileIndexes(i.internalId(), r), await n({
|
|
1606
|
+
db: s,
|
|
1607
|
+
oldVersion: e,
|
|
1608
|
+
newVersion: t,
|
|
1609
|
+
transaction: o
|
|
1610
|
+
}), await this.#e.proxy.setSchemaVersion(i.internalId(), t), await i.commit();
|
|
1611
|
+
} catch (e) {
|
|
1612
|
+
try {
|
|
1613
|
+
await i.rollbackIfOpen();
|
|
1614
|
+
} catch {}
|
|
1615
|
+
throw e;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
async listStores() {
|
|
1619
|
+
return this.#h(), Y(() => this.#e.proxy.listStores());
|
|
1620
|
+
}
|
|
1621
|
+
async getVersion() {
|
|
1622
|
+
return this.#h(), Y(() => this.#e.proxy.getVersion());
|
|
1623
|
+
}
|
|
1624
|
+
async changesSince(e, t = {}) {
|
|
1625
|
+
return this.#h(), Y(() => this.#e.proxy.changesSince(Bn(e), Vn(t)));
|
|
1626
|
+
}
|
|
1627
|
+
async #l(e) {
|
|
1628
|
+
this.#h();
|
|
1629
|
+
let t = this.#a, n = Y(async () => {
|
|
1630
|
+
let n = await this.#e.proxy.begin(e), r = new En(this.#e, n, e, () => {
|
|
1631
|
+
this.#r.delete(r);
|
|
1632
|
+
});
|
|
1633
|
+
if (this.#r.add(r), this.#t || this.#e.invalidated) throw this.#e.invalidated && r.forceClose(), new T();
|
|
1634
|
+
if (t !== this.#a) throw await r.rollbackIfOpen(), new w();
|
|
1635
|
+
return r;
|
|
1636
|
+
});
|
|
1637
|
+
this.#i.add(n);
|
|
1638
|
+
try {
|
|
1639
|
+
return await n;
|
|
1640
|
+
} finally {
|
|
1641
|
+
this.#i.delete(n);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
async createStore(e, t = {}) {
|
|
1645
|
+
q(e), await this.#u("readwrite", "createStore", [e, Rn(t)]);
|
|
1646
|
+
}
|
|
1647
|
+
async dropStore(e) {
|
|
1648
|
+
q(e), await this.#u("readwrite", "dropStore", [e]);
|
|
1649
|
+
}
|
|
1650
|
+
async clearStore(e) {
|
|
1651
|
+
q(e), await this.#u("readwrite", "clearStore", [e]);
|
|
1652
|
+
}
|
|
1653
|
+
async get(e, t) {
|
|
1654
|
+
return q(e), this.#u("readonly", "get", [e, t]);
|
|
1655
|
+
}
|
|
1656
|
+
async getMany(e, t) {
|
|
1657
|
+
return q(e), this.#u("readonly", "getMany", [e, t]);
|
|
1658
|
+
}
|
|
1659
|
+
async has(e, t) {
|
|
1660
|
+
return q(e), this.#u("readonly", "has", [e, t]);
|
|
1661
|
+
}
|
|
1662
|
+
async put(e, t, n, r = {}) {
|
|
1663
|
+
q(e), await this.#u("readwrite", "put", [
|
|
1664
|
+
e,
|
|
1665
|
+
t,
|
|
1666
|
+
n,
|
|
1667
|
+
$(r)
|
|
1668
|
+
]);
|
|
1669
|
+
}
|
|
1670
|
+
async delete(e, t) {
|
|
1671
|
+
return q(e), this.#u("readwrite", "delete", [e, t]);
|
|
1672
|
+
}
|
|
1673
|
+
async scan(e, t = {}) {
|
|
1674
|
+
return q(e), this.#u("readonly", "scan", [e, t]);
|
|
1675
|
+
}
|
|
1676
|
+
async #u(e, t, n) {
|
|
1677
|
+
return this.#h(), Y(() => this.#e.proxy.autocommit(e, t, n));
|
|
1678
|
+
}
|
|
1679
|
+
async exportSnapshot(e = {}) {
|
|
1680
|
+
return this.#h(), Y(async () => {
|
|
1681
|
+
let t = await this.#e.proxy.exportSnapshot(zn(e));
|
|
1682
|
+
return t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
async importSnapshot(e) {
|
|
1686
|
+
return this.#h(), I(this.#e), Y(() => {
|
|
1687
|
+
let t = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1688
|
+
return this.#e.proxy.importSnapshot(t);
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
async reset() {
|
|
1692
|
+
return this.#h(), I(this.#e), Y(() => this.#e.proxy.reset());
|
|
1693
|
+
}
|
|
1694
|
+
async compact() {
|
|
1695
|
+
return this.#h(), I(this.#e), Y(() => this.#e.proxy.compact());
|
|
1696
|
+
}
|
|
1697
|
+
async rebuild() {
|
|
1698
|
+
return this.#h(), I(this.#e), Y(() => this.#e.proxy.rebuild());
|
|
1699
|
+
}
|
|
1700
|
+
async stats() {
|
|
1701
|
+
return this.#h(), Y(() => this.#e.proxy.stats());
|
|
1702
|
+
}
|
|
1703
|
+
async storageInfo() {
|
|
1704
|
+
return this.#h(), Y(() => this.#e.proxy.storageInfo());
|
|
1705
|
+
}
|
|
1706
|
+
async requestPersistence() {
|
|
1707
|
+
return this.#h(), Y(() => this.#e.proxy.requestPersistence());
|
|
1708
|
+
}
|
|
1709
|
+
async destroy() {
|
|
1710
|
+
return this.#h(), Y(() => ct(this.#e));
|
|
1711
|
+
}
|
|
1712
|
+
async setFailpoint(e) {
|
|
1713
|
+
return this.#h(), Y(() => this.#e.proxy.setFailpoint(e));
|
|
1714
|
+
}
|
|
1715
|
+
subscribe(e, t, n) {
|
|
1716
|
+
if (this.#h(), typeof e == "function") return this.#o.subscribe(e);
|
|
1717
|
+
if (typeof t == "function") return this.#o.subscribe(e, t);
|
|
1718
|
+
if (t instanceof Uint8Array && typeof n == "function") return this.#o.subscribe(e, t, n);
|
|
1719
|
+
throw TypeError("subscribe() expects one of: (callback), (storeName, callback), (storeName, keyPrefix, callback)");
|
|
1720
|
+
}
|
|
1721
|
+
watch(e, t, n) {
|
|
1722
|
+
if (typeof e == "function") return this.subscribe(e);
|
|
1723
|
+
if (typeof t == "function") return this.subscribe(e, t);
|
|
1724
|
+
if (t instanceof Uint8Array && typeof n == "function") return this.subscribe(e, t, n);
|
|
1725
|
+
throw TypeError("watch() expects one of: (callback), (storeName, callback), (storeName, keyPrefix, callback)");
|
|
1726
|
+
}
|
|
1727
|
+
close() {
|
|
1728
|
+
return this.#n === null ? this.#t ? Promise.resolve() : (this.#t = !0, this.#f(), this.#o.close(), this.#n = this.#d(), this.#n) : this.#n;
|
|
1729
|
+
}
|
|
1730
|
+
async #d() {
|
|
1731
|
+
await Promise.allSettled(Array.from(this.#i));
|
|
1732
|
+
let e = null, t = Array.from(this.#r);
|
|
1733
|
+
if (t.length > 0) {
|
|
1734
|
+
let n = await Promise.allSettled(t.map((e) => e.rollbackIfOpen()));
|
|
1735
|
+
for (let t of n) t.status === "rejected" && e === null && (e = A(t.reason));
|
|
1736
|
+
}
|
|
1737
|
+
try {
|
|
1738
|
+
await st(this.#e);
|
|
1739
|
+
} catch (e) {
|
|
1740
|
+
throw A(e);
|
|
1741
|
+
}
|
|
1742
|
+
if (e) throw e;
|
|
1743
|
+
}
|
|
1744
|
+
#f() {
|
|
1745
|
+
this.#s?.(), this.#s = null, this.#c?.(), this.#c = null;
|
|
1746
|
+
}
|
|
1747
|
+
#p() {
|
|
1748
|
+
this.#a += 1;
|
|
1749
|
+
for (let e of Array.from(this.#r)) e.forceClose();
|
|
1750
|
+
}
|
|
1751
|
+
#m() {
|
|
1752
|
+
this.#t || (this.#t = !0, this.#f(), this.#p(), this.#o.close());
|
|
1753
|
+
}
|
|
1754
|
+
#h() {
|
|
1755
|
+
if (this.#t || this.#e.invalidated) throw new T();
|
|
1756
|
+
}
|
|
1757
|
+
}, On = class {
|
|
1758
|
+
#e = /* @__PURE__ */ new Set();
|
|
1759
|
+
#t = /* @__PURE__ */ new Set();
|
|
1760
|
+
recordCreate(e) {
|
|
1761
|
+
this.#t.delete(e), this.#e.add(e);
|
|
1762
|
+
}
|
|
1763
|
+
recordDrop(e) {
|
|
1764
|
+
this.#e.delete(e) || this.#t.add(e);
|
|
1765
|
+
}
|
|
1766
|
+
apply(e) {
|
|
1767
|
+
let n = new Set(e);
|
|
1768
|
+
for (let e of this.#e) n.add(e);
|
|
1769
|
+
for (let e of this.#t) n.delete(e);
|
|
1770
|
+
return Array.from(n).sort(t);
|
|
1771
|
+
}
|
|
1772
|
+
}, kn = class {
|
|
1773
|
+
#e;
|
|
1774
|
+
#t;
|
|
1775
|
+
constructor(e, t) {
|
|
1776
|
+
this.#e = e, this.#t = t;
|
|
1777
|
+
}
|
|
1778
|
+
get mode() {
|
|
1779
|
+
return this.#e.mode;
|
|
1780
|
+
}
|
|
1781
|
+
async get(e, t) {
|
|
1782
|
+
return this.#e.get(e, t);
|
|
1783
|
+
}
|
|
1784
|
+
async getMany(e, t) {
|
|
1785
|
+
return this.#e.getMany(e, t);
|
|
1786
|
+
}
|
|
1787
|
+
async has(e, t) {
|
|
1788
|
+
return this.#e.has(e, t);
|
|
1789
|
+
}
|
|
1790
|
+
async put(e, t, n, r = {}) {
|
|
1791
|
+
await this.#e.put(e, t, n, r);
|
|
1792
|
+
}
|
|
1793
|
+
async putMany(e, t, n = {}) {
|
|
1794
|
+
await this.#e.putMany(e, t, n);
|
|
1795
|
+
}
|
|
1796
|
+
async delete(e, t) {
|
|
1797
|
+
return this.#e.delete(e, t);
|
|
1798
|
+
}
|
|
1799
|
+
async deleteMany(e, t) {
|
|
1800
|
+
await this.#e.deleteMany(e, t);
|
|
1801
|
+
}
|
|
1802
|
+
async applyBatch(e, t) {
|
|
1803
|
+
await this.#e.applyBatch(e, t);
|
|
1804
|
+
}
|
|
1805
|
+
async scan(e, t = {}) {
|
|
1806
|
+
return this.#e.scan(e, t);
|
|
1807
|
+
}
|
|
1808
|
+
async getByIndex(e, t, n) {
|
|
1809
|
+
return this.#e.getByIndex(e, t, n);
|
|
1810
|
+
}
|
|
1811
|
+
scanByIndex(e, t, n = {}) {
|
|
1812
|
+
return this.#e.scanByIndex(e, t, n);
|
|
1813
|
+
}
|
|
1814
|
+
async createStore(e, t = {}) {
|
|
1815
|
+
await this.#e.createStore(e, t), this.#t.recordCreate(e);
|
|
1816
|
+
}
|
|
1817
|
+
async dropStore(e) {
|
|
1818
|
+
await this.#e.dropStore(e), this.#t.recordDrop(e);
|
|
1819
|
+
}
|
|
1820
|
+
async clearStore(e) {
|
|
1821
|
+
await this.#e.clearStore(e);
|
|
1822
|
+
}
|
|
1823
|
+
commit() {
|
|
1824
|
+
return Promise.reject(X("transaction.commit"));
|
|
1825
|
+
}
|
|
1826
|
+
rollback() {
|
|
1827
|
+
return Promise.reject(X("transaction.rollback"));
|
|
1828
|
+
}
|
|
1829
|
+
}, An = class {
|
|
1830
|
+
#e;
|
|
1831
|
+
#t;
|
|
1832
|
+
#n;
|
|
1833
|
+
constructor(e, t, n) {
|
|
1834
|
+
this.#e = e, this.#t = t, this.#n = n;
|
|
1835
|
+
}
|
|
1836
|
+
begin(e = "readonly") {
|
|
1837
|
+
return Promise.reject(X("db.begin"));
|
|
1838
|
+
}
|
|
1839
|
+
async createStore(e, t = {}) {
|
|
1840
|
+
await this.#t.createStore(e, t);
|
|
1841
|
+
}
|
|
1842
|
+
async dropStore(e) {
|
|
1843
|
+
await this.#t.dropStore(e);
|
|
1844
|
+
}
|
|
1845
|
+
async clearStore(e) {
|
|
1846
|
+
await this.#t.clearStore(e);
|
|
1847
|
+
}
|
|
1848
|
+
async listStores() {
|
|
1849
|
+
return this.#n.apply(await this.#e.listStores());
|
|
1850
|
+
}
|
|
1851
|
+
async getVersion() {
|
|
1852
|
+
return this.#e.getVersion();
|
|
1853
|
+
}
|
|
1854
|
+
changesSince(e, t = {}) {
|
|
1855
|
+
return Promise.reject(X("db.changesSince"));
|
|
1856
|
+
}
|
|
1857
|
+
async get(e, t) {
|
|
1858
|
+
return this.#t.get(e, t);
|
|
1859
|
+
}
|
|
1860
|
+
async getMany(e, t) {
|
|
1861
|
+
return this.#t.getMany(e, t);
|
|
1862
|
+
}
|
|
1863
|
+
async has(e, t) {
|
|
1864
|
+
return this.#t.has(e, t);
|
|
1865
|
+
}
|
|
1866
|
+
async put(e, t, n, r = {}) {
|
|
1867
|
+
await this.#t.put(e, t, n, r);
|
|
1868
|
+
}
|
|
1869
|
+
async delete(e, t) {
|
|
1870
|
+
return this.#t.delete(e, t);
|
|
1871
|
+
}
|
|
1872
|
+
async scan(e, t = {}) {
|
|
1873
|
+
return this.#t.scan(e, t);
|
|
1874
|
+
}
|
|
1875
|
+
exportSnapshot(e = {}) {
|
|
1876
|
+
return Promise.reject(X("db.exportSnapshot"));
|
|
1877
|
+
}
|
|
1878
|
+
importSnapshot(e) {
|
|
1879
|
+
return Promise.reject(X("db.importSnapshot"));
|
|
1880
|
+
}
|
|
1881
|
+
reset() {
|
|
1882
|
+
return Promise.reject(X("db.reset"));
|
|
1883
|
+
}
|
|
1884
|
+
compact() {
|
|
1885
|
+
return Promise.reject(X("db.compact"));
|
|
1886
|
+
}
|
|
1887
|
+
rebuild() {
|
|
1888
|
+
return Promise.reject(X("db.rebuild"));
|
|
1889
|
+
}
|
|
1890
|
+
async stats() {
|
|
1891
|
+
return this.#e.stats();
|
|
1892
|
+
}
|
|
1893
|
+
async storageInfo() {
|
|
1894
|
+
return this.#e.storageInfo();
|
|
1895
|
+
}
|
|
1896
|
+
async requestPersistence() {
|
|
1897
|
+
return this.#e.requestPersistence();
|
|
1898
|
+
}
|
|
1899
|
+
close() {
|
|
1900
|
+
return Promise.reject(X("db.close"));
|
|
1901
|
+
}
|
|
1902
|
+
destroy() {
|
|
1903
|
+
return Promise.reject(X("db.destroy"));
|
|
1904
|
+
}
|
|
1905
|
+
setFailpoint(e) {
|
|
1906
|
+
return Promise.reject(X("db.setFailpoint"));
|
|
1907
|
+
}
|
|
1908
|
+
subscribe(e, t, n) {
|
|
1909
|
+
throw X("db.subscribe");
|
|
1910
|
+
}
|
|
1911
|
+
watch(e, t, n) {
|
|
1912
|
+
throw X("db.watch");
|
|
1913
|
+
}
|
|
1987
1914
|
};
|
|
1988
|
-
|
|
1915
|
+
function X(e) {
|
|
1916
|
+
let t = /* @__PURE__ */ Error(`${e}() is not available inside openDB() migrations; use the provided migration transaction and wait for openDB() to resolve`);
|
|
1917
|
+
return t.name = "InvalidStateError", t;
|
|
1918
|
+
}
|
|
1919
|
+
function jn(e, t) {
|
|
1920
|
+
if (typeof e != "string" || e.length === 0) throw TypeError(`${t}() database name must be a non-empty string`);
|
|
1921
|
+
return e;
|
|
1922
|
+
}
|
|
1923
|
+
var Mn = (e) => TypeError(e), Nn = (e) => new O(e);
|
|
1924
|
+
function Z(e, t, n = Mn) {
|
|
1925
|
+
if (e === void 0) return {};
|
|
1926
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw n(t);
|
|
1927
|
+
return e;
|
|
1928
|
+
}
|
|
1929
|
+
function Pn(e, t, n = Mn) {
|
|
1930
|
+
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw n(t);
|
|
1931
|
+
return e;
|
|
1932
|
+
}
|
|
1933
|
+
function Q(e, t, n) {
|
|
1934
|
+
return e === void 0 ? void 0 : Pn(e, t, n);
|
|
1935
|
+
}
|
|
1936
|
+
function Fn(e) {
|
|
1937
|
+
return Z(e, "open options must be an object", Nn);
|
|
1938
|
+
}
|
|
1939
|
+
function In(e) {
|
|
1940
|
+
return Q(e, "version must be a non-negative safe integer", Nn);
|
|
1941
|
+
}
|
|
1942
|
+
function $(e) {
|
|
1943
|
+
let { ttl: t } = Z(e, "put options must be an object"), n = Q(t, "ttl must be a non-negative safe integer");
|
|
1944
|
+
return n === void 0 ? {} : { ttl: n };
|
|
1945
|
+
}
|
|
1946
|
+
function Ln(e, t) {
|
|
1947
|
+
let { compression: n } = Z(e, t);
|
|
1948
|
+
if (n === void 0) return {};
|
|
1949
|
+
if (n !== !1 && n !== "gzip" && n !== "deflate") throw TypeError("compression must be \"gzip\", \"deflate\", or false");
|
|
1950
|
+
return { compression: n };
|
|
1951
|
+
}
|
|
1952
|
+
function Rn(e) {
|
|
1953
|
+
return Ln(e, "createStore options must be an object");
|
|
1954
|
+
}
|
|
1955
|
+
function zn(e) {
|
|
1956
|
+
return Ln(e, "exportSnapshot options must be an object");
|
|
1957
|
+
}
|
|
1958
|
+
function Bn(e) {
|
|
1959
|
+
return Pn(e, "txid must be a non-negative safe integer");
|
|
1960
|
+
}
|
|
1961
|
+
function Vn(e) {
|
|
1962
|
+
let { stores: t, limit: n } = Z(e, "change feed options must be an object"), r = {};
|
|
1963
|
+
if (t !== void 0) {
|
|
1964
|
+
if (!Array.isArray(t) || !t.every((e) => typeof e == "string")) throw TypeError("stores must be an array of strings");
|
|
1965
|
+
for (let e of t) q(e);
|
|
1966
|
+
r.stores = [...t];
|
|
1967
|
+
}
|
|
1968
|
+
let i = Q(n, "limit must be a non-negative safe integer");
|
|
1969
|
+
return i !== void 0 && (r.limit = i), r;
|
|
1970
|
+
}
|
|
1971
|
+
function Hn(e) {
|
|
1972
|
+
if (e !== void 0) {
|
|
1973
|
+
if (typeof e != "function") throw new O("migrate must be a function");
|
|
1974
|
+
return e;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
function Un(e) {
|
|
1978
|
+
if (e !== void 0) return J(e);
|
|
1979
|
+
}
|
|
1980
|
+
function Wn(e, t) {
|
|
1981
|
+
return nn(e) === nn(t);
|
|
1982
|
+
}
|
|
1983
|
+
async function Gn(e) {
|
|
1984
|
+
return J(await e.proxy.getIndexes());
|
|
1985
|
+
}
|
|
1986
|
+
function Kn() {
|
|
1987
|
+
if (!globalThis.isSecureContext) throw new x("moyodb requires a secure context (HTTPS)");
|
|
1988
|
+
if (typeof globalThis.navigator.storage.getDirectory != "function") throw new x("navigator.storage.getDirectory is unavailable");
|
|
1989
|
+
if (typeof globalThis.Worker != "function") throw new x("Worker is unavailable");
|
|
1990
|
+
if (globalThis.BroadcastChannel === void 0) throw new x("BroadcastChannel is unavailable");
|
|
1991
|
+
}
|
|
1992
|
+
async function qn(e) {
|
|
1993
|
+
let t = globalThis.navigator;
|
|
1994
|
+
(e.requestPersistence ?? !0) && typeof t.storage.persist == "function" && await n(t.storage.persist(), 1e3, !1);
|
|
1995
|
+
}
|
|
1996
|
+
async function Jn(e, t = {}) {
|
|
1997
|
+
let n = jn(e, "openDB"), r = Fn(t), i = In(r.version), a = Hn(r.migrate), o = Un(r.indexes);
|
|
1998
|
+
if (i === void 0 && a !== void 0) throw new O("migrate requires version");
|
|
1999
|
+
if (i === void 0 && o !== void 0) throw new O("indexes requires version");
|
|
2000
|
+
Kn(), await qn(r);
|
|
2001
|
+
let s = await ot(n, r), c = new Dn(s);
|
|
2002
|
+
try {
|
|
2003
|
+
if (i === void 0) return c;
|
|
2004
|
+
let [e, t] = await Promise.all([c.getVersion(), Gn(s)]);
|
|
2005
|
+
if (i < e) throw new k(`cannot open database ${n} at schema version ${i}; current schema version is ${e}`);
|
|
2006
|
+
if (i === e) {
|
|
2007
|
+
if (o !== void 0 && !Wn(o, t)) throw new k(`database ${n} is already at schema version ${e}, but the requested index catalog does not match the committed schema`);
|
|
2008
|
+
return c;
|
|
2009
|
+
}
|
|
2010
|
+
if (s.refs > 1) throw new S(`database ${n} is already open in this tab; close existing handles before migrating from version ${e} to ${i}`);
|
|
2011
|
+
if (!a) throw new k(`database ${n} requires migration from version ${e} to ${i}, but no migrate hook was provided`);
|
|
2012
|
+
let r = o ?? t;
|
|
2013
|
+
s.schemaMigrationInProgress = !0;
|
|
2014
|
+
try {
|
|
2015
|
+
await c.runSchemaMigration(e, i, a, an(r));
|
|
2016
|
+
} finally {
|
|
2017
|
+
s.schemaMigrationInProgress = !1;
|
|
2018
|
+
}
|
|
2019
|
+
return c;
|
|
2020
|
+
} catch (e) {
|
|
2021
|
+
try {
|
|
2022
|
+
await c.close();
|
|
2023
|
+
} catch {}
|
|
2024
|
+
throw A(e);
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
async function Yn(e) {
|
|
2028
|
+
let t = jn(e, "deleteDB");
|
|
2029
|
+
Kn(), await ut(t);
|
|
2030
|
+
}
|
|
2031
|
+
function Xn(e) {
|
|
2032
|
+
return at(jn(e, "unsafeDebugCrashWorker"));
|
|
2033
|
+
}
|
|
2034
|
+
//#endregion
|
|
2035
|
+
export { Me as ChangeFeedCompactedError, C as ConstraintError, ye as CorruptionError, S as DatabaseBusyError, T as DatabaseClosedError, Bt as INDEX_METADATA_STORE, Se as IndexNotFoundError, je as InjectedFailureError, Pe as InternalError, O as InvalidOpenOptionsError, ke as InvalidRangeError, De as KeyTooLargeError, b as MoyoDbError, Te as ReadonlyTransactionError, Ne as RecoveryRequiredError, E as ReservedStoreNameError, D as SerializationError, Ae as StorageError, be as StoreExistsError, Oe as StoreNameTooLongError, xe as StoreNotFoundError, w as TransactionClosedError, Ce as UniqueIndexConstraintError, x as UnsupportedPlatformError, Ee as ValueTooLargeError, k as VersionError, we as WriteTransactionAlreadyOpenError, q as assertPublicStoreName, rn as cloneNormalizedIndexDefinitions, Ht as compareNormalizedIndexDefinitions, V as compoundKey, At as compoundKeyRange, en as createIndexKeyExtractor, Xt as decodeIndexEntryKey, Jt as decodeIndexMetadataValue, pn as decodeIndexedDocument, Yn as deleteDB, H as encodeCompoundKeyParts, Yt as encodeIndexEntryKey, Kt as encodeIndexMetadataKey, qt as encodeIndexMetadataValue, Ot as encodeIndexScalar, $t as extractLogicalIndexKey, tn as extractLogicalIndexKeyFromDocument, Wt as findIndexDefinition, Ut as indexDefinitionIdentity, Dt as indexKey, Zt as indexKeyExactRange, Qt as indexRangeToPhysicalRange, Gt as indexesForStore, Vt as isInternalStoreName, wt as jsonDecode, Ct as jsonEncode, A as normalizeError, J as normalizeIndexDefinitions, Jn as openDB, W as prefixRange, U as prefixSuccessor, nn as serializeNormalizedIndexDefinitions, kt as splitCompoundKey, an as toPublicIndexDefinitions, Tt as u64Key, Xn as unsafeDebugCrashWorker, St as utf8Decode, B as utf8Encode };
|
|
2036
|
+
|
|
2037
|
+
//# sourceMappingURL=moyodb-sdk.js.map
|