@moyodb/sdk 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +46 -0
- package/README.md +4 -2
- package/dist/assets/browser-worker-Bj2ErRvC.js +4 -0
- package/dist/assets/browser-worker-Bj2ErRvC.js.map +1 -0
- package/dist/assets/shared-worker-CMeTcusa.js +2 -0
- package/dist/assets/shared-worker-CMeTcusa.js.map +1 -0
- package/dist/chunks/{indexing-CKtbpaZn.js → indexing-B0duqlUs.js} +43 -117
- package/dist/chunks/indexing-B0duqlUs.js.map +1 -0
- package/dist/demo.d.ts.map +1 -1
- package/dist/engine/README.md +4 -2
- package/dist/engine/moyodb_engine.d.ts +4 -2
- package/dist/engine/moyodb_engine.js +45 -22
- package/dist/engine/moyodb_engine_bg.wasm +0 -0
- package/dist/engine/moyodb_engine_bg.wasm.d.ts +3 -2
- package/dist/engine/package.json +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/indexing.d.ts.map +1 -1
- package/dist/moyodb-sdk.js +648 -653
- package/dist/moyodb-sdk.js.map +1 -1
- package/dist/node-engine.js +30 -35
- package/dist/node-engine.js.map +1 -1
- package/dist/node.js +23 -31
- package/dist/node.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/worker-api.d.ts +2 -5
- package/dist/worker-api.d.ts.map +1 -1
- package/dist/worker-protocol.d.ts +7 -2
- package/dist/worker-protocol.d.ts.map +1 -1
- package/dist/worker.d.ts +2 -2
- package/dist/worker.d.ts.map +1 -1
- package/package.json +4 -3
- package/dist/assets/browser-worker-DBt51gsS.js +0 -4
- package/dist/assets/browser-worker-DBt51gsS.js.map +0 -1
- package/dist/assets/shared-worker-NdniRuEL.js +0 -2
- package/dist/assets/shared-worker-NdniRuEL.js.map +0 -1
- package/dist/chunks/indexing-CKtbpaZn.js.map +0 -1
- /package/dist/engine/snippets/{moyodb-engine-54a406e33b0fb849 → moyodb-engine-1d53039816cbc2f7}/js/opfs_shim.js +0 -0
package/dist/moyodb-sdk.js
CHANGED
|
@@ -58,12 +58,12 @@ function oe(t, n, r) {
|
|
|
58
58
|
}
|
|
59
59
|
function se(t) {
|
|
60
60
|
if (e(t)) {
|
|
61
|
-
let e =
|
|
61
|
+
let e = Se(t.code);
|
|
62
62
|
return {
|
|
63
|
-
name:
|
|
63
|
+
name: Se(t.name) ?? e ?? "Error",
|
|
64
64
|
code: e,
|
|
65
|
-
message:
|
|
66
|
-
stack:
|
|
65
|
+
message: Se(t.message) ?? "Unknown error",
|
|
66
|
+
stack: Se(t.stack)
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
return {
|
|
@@ -74,25 +74,24 @@ function se(t) {
|
|
|
74
74
|
function ce(t) {
|
|
75
75
|
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 h("WorkerProtocolError", "invalid serialized worker error");
|
|
76
76
|
let n = Error(t.message);
|
|
77
|
-
return n.name = t.name || t.code || "Error", t.stack && (n.stack = t.stack), t.code &&
|
|
78
|
-
value: t.code,
|
|
79
|
-
enumerable: !0,
|
|
80
|
-
configurable: !0
|
|
81
|
-
}), n;
|
|
77
|
+
return n.name = t.name || t.code || "Error", t.stack && (n.stack = t.stack), t.code && le(n, t.code), n;
|
|
82
78
|
}
|
|
83
79
|
function h(e, t, n = e) {
|
|
84
80
|
let r = Error(t);
|
|
85
|
-
return r.name = e,
|
|
86
|
-
|
|
81
|
+
return r.name = e, le(r, n), r;
|
|
82
|
+
}
|
|
83
|
+
function le(e, t) {
|
|
84
|
+
Object.defineProperty(e, "code", {
|
|
85
|
+
value: t,
|
|
87
86
|
enumerable: !0,
|
|
88
87
|
configurable: !0
|
|
89
|
-
})
|
|
88
|
+
});
|
|
90
89
|
}
|
|
91
|
-
function
|
|
90
|
+
function ue(e, t) {
|
|
92
91
|
if (e === "autocommit") {
|
|
93
92
|
let [e, n, r] = t;
|
|
94
93
|
if (o(n) && Array.isArray(r)) {
|
|
95
|
-
let t =
|
|
94
|
+
let t = ue(n, [0, ...r]);
|
|
96
95
|
return {
|
|
97
96
|
args: [
|
|
98
97
|
e,
|
|
@@ -108,7 +107,7 @@ function le(e, t) {
|
|
|
108
107
|
for (let a = n; a <= (e === "put" ? 3 : n); a += 1) {
|
|
109
108
|
let e = t[a];
|
|
110
109
|
if (e instanceof Uint8Array && e.buffer instanceof ArrayBuffer && (e.byteOffset !== 0 || e.byteLength !== e.buffer.byteLength)) {
|
|
111
|
-
let n =
|
|
110
|
+
let n = xe(e);
|
|
112
111
|
r ??= [...t], r[a] = n, (i ??= []).push(n.buffer);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
@@ -120,7 +119,7 @@ function le(e, t) {
|
|
|
120
119
|
if (e === "importSnapshot") {
|
|
121
120
|
let e = t[0];
|
|
122
121
|
if (e instanceof Uint8Array) {
|
|
123
|
-
let t =
|
|
122
|
+
let t = xe(e);
|
|
124
123
|
return {
|
|
125
124
|
args: [t],
|
|
126
125
|
transfer: [t.buffer]
|
|
@@ -130,7 +129,7 @@ function le(e, t) {
|
|
|
130
129
|
if (e === "getMany" || e === "deleteMany") {
|
|
131
130
|
let [e, n, r] = t;
|
|
132
131
|
if (Array.isArray(r) && r.length > 0) {
|
|
133
|
-
let t =
|
|
132
|
+
let t = _e(r);
|
|
134
133
|
return {
|
|
135
134
|
args: [
|
|
136
135
|
e,
|
|
@@ -144,7 +143,7 @@ function le(e, t) {
|
|
|
144
143
|
if (e === "putMany") {
|
|
145
144
|
let [e, n, r, i] = t;
|
|
146
145
|
if (Array.isArray(r) && r.length > 0) {
|
|
147
|
-
let t =
|
|
146
|
+
let t = ge(r);
|
|
148
147
|
return {
|
|
149
148
|
args: [
|
|
150
149
|
e,
|
|
@@ -159,7 +158,7 @@ function le(e, t) {
|
|
|
159
158
|
if (e === "applyBatch") {
|
|
160
159
|
let [e, n, r] = t;
|
|
161
160
|
if (Array.isArray(r) && r.length > 0) {
|
|
162
|
-
let t =
|
|
161
|
+
let t = be(r);
|
|
163
162
|
return {
|
|
164
163
|
args: [
|
|
165
164
|
e,
|
|
@@ -175,9 +174,9 @@ function le(e, t) {
|
|
|
175
174
|
transfer: te
|
|
176
175
|
};
|
|
177
176
|
}
|
|
178
|
-
function
|
|
177
|
+
function de(e) {
|
|
179
178
|
if (!(e instanceof Uint8Array) || e.byteLength < 4) throw h("WorkerProtocolError", "invalid packed optional-values payload");
|
|
180
|
-
let t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint32(0, !0), r =
|
|
179
|
+
let t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint32(0, !0), r = v(4, _(n, 4, "packed optional-values metadata"), "packed optional-values header");
|
|
181
180
|
if (r > e.byteLength) throw h("WorkerProtocolError", "packed optional-values metadata exceeds payload length");
|
|
182
181
|
let i = Array(n), a = r;
|
|
183
182
|
for (let r = 0; r < n; r += 1) {
|
|
@@ -193,10 +192,10 @@ function ue(e) {
|
|
|
193
192
|
if (a !== e.byteLength) throw h("WorkerProtocolError", "packed optional-values payload has trailing bytes");
|
|
194
193
|
return i;
|
|
195
194
|
}
|
|
196
|
-
function
|
|
195
|
+
function fe(t, n) {
|
|
197
196
|
if (t === "scanPage") {
|
|
198
197
|
if (!e(n) || typeof n.done != "boolean" || typeof n.bytes != "number" || !Number.isSafeInteger(n.bytes) || n.bytes < 4 || n.cursorId !== void 0 && (typeof n.cursorId != "number" || !Number.isSafeInteger(n.cursorId) || n.cursorId <= 0) || (n.done ? n.cursorId !== void 0 : n.cursorId === void 0)) throw h("WorkerProtocolError", "invalid scan page response");
|
|
199
|
-
let t =
|
|
198
|
+
let t = pe(n.rows) ? me(n.rows.bytes) : g(n.rows, l) ? ye(n.rows) : n.rows;
|
|
200
199
|
if (!Array.isArray(t)) throw h("WorkerProtocolError", "invalid scan page rows");
|
|
201
200
|
let r = 4;
|
|
202
201
|
for (let n of t) {
|
|
@@ -211,25 +210,25 @@ function de(t, n) {
|
|
|
211
210
|
bytes: n.bytes
|
|
212
211
|
};
|
|
213
212
|
}
|
|
214
|
-
if ((t === "scan" || t === "scanByIndex") &&
|
|
215
|
-
if (t === "getMany" &&
|
|
216
|
-
if (t === "getMany" &&
|
|
213
|
+
if ((t === "scan" || t === "scanByIndex") && pe(n)) return me(n.bytes);
|
|
214
|
+
if (t === "getMany" && g(n, c)) return ve(n);
|
|
215
|
+
if (t === "getMany" && g(n, f)) return de(n.bytes);
|
|
217
216
|
if (t === "getMany" && !Array.isArray(n)) throw h("WorkerProtocolError", "invalid packed getMany response");
|
|
218
217
|
if (t === "scanByIndexPage") {
|
|
219
|
-
if (!e(n) || !Array.isArray(n.rows) && !
|
|
218
|
+
if (!e(n) || !Array.isArray(n.rows) && !g(n.rows, l) || n.cursor !== null && !(n.cursor instanceof Uint8Array)) throw h("WorkerProtocolError", "invalid packed index scan page response");
|
|
220
219
|
return {
|
|
221
|
-
rows:
|
|
220
|
+
rows: g(n.rows, l) ? ye(n.rows) : n.rows,
|
|
222
221
|
cursor: n.cursor
|
|
223
222
|
};
|
|
224
223
|
}
|
|
225
|
-
if ((t === "scan" || t === "scanByIndex") &&
|
|
224
|
+
if ((t === "scan" || t === "scanByIndex") && g(n, l)) return ye(n);
|
|
226
225
|
if ((t === "scan" || t === "scanByIndex") && !Array.isArray(n)) throw h("WorkerProtocolError", "invalid packed scan response");
|
|
227
226
|
return n;
|
|
228
227
|
}
|
|
229
|
-
function
|
|
228
|
+
function pe(t) {
|
|
230
229
|
return e(t) && t.__moyodbPacked === u && t.bytes instanceof Uint8Array;
|
|
231
230
|
}
|
|
232
|
-
function
|
|
231
|
+
function me(e) {
|
|
233
232
|
if (!(e instanceof Uint8Array) || e.byteLength < 4) throw h("WorkerProtocolError", "invalid engine scan packet");
|
|
234
233
|
let t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = t.getUint32(0, !0);
|
|
235
234
|
if (n > (e.byteLength - 4) / 8) throw h("WorkerProtocolError", "engine scan row count exceeds packet length");
|
|
@@ -246,7 +245,7 @@ function pe(e) {
|
|
|
246
245
|
if (i !== e.byteLength) throw h("WorkerProtocolError", "engine scan packet has trailing bytes");
|
|
247
246
|
return r;
|
|
248
247
|
}
|
|
249
|
-
function
|
|
248
|
+
function he(e, t) {
|
|
250
249
|
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) => {
|
|
251
250
|
if (typeof e == "string") {
|
|
252
251
|
a += 8 + e.length * 2;
|
|
@@ -275,15 +274,15 @@ function me(e, t) {
|
|
|
275
274
|
byteLength: a
|
|
276
275
|
};
|
|
277
276
|
}
|
|
278
|
-
function
|
|
279
|
-
let t = e.length, n =
|
|
277
|
+
function ge(e) {
|
|
278
|
+
let t = e.length, n = y(t * 2, "packed putMany item count"), r = _(n, 4, "packed putMany metadata"), i = 0;
|
|
280
279
|
for (let n = 0; n < t; n += 1) {
|
|
281
280
|
let t = e[n], r = t[0], a = t[1];
|
|
282
281
|
if (!(r instanceof Uint8Array) || !(a instanceof Uint8Array)) throw h("WorkerProtocolError", "putMany entry key/value is not a Uint8Array");
|
|
283
|
-
let o =
|
|
282
|
+
let o = y(r.byteLength, "putMany key length"), s = y(a.byteLength, "putMany value length");
|
|
284
283
|
if (i += o + s, i > m) throw h("WorkerProtocolError", "packed putMany payload exceeds 32-bit payload limit");
|
|
285
284
|
}
|
|
286
|
-
let a =
|
|
285
|
+
let a = v(4, r, "packed putMany header"), o = v(a, i, "packed putMany total"), c = new Uint8Array(o), l = new DataView(c.buffer);
|
|
287
286
|
l.setUint32(0, n, !0);
|
|
288
287
|
let u = 4, d = a;
|
|
289
288
|
for (let n = 0; n < t; n += 1) {
|
|
@@ -295,15 +294,15 @@ function he(e) {
|
|
|
295
294
|
bytes: c
|
|
296
295
|
};
|
|
297
296
|
}
|
|
298
|
-
function
|
|
299
|
-
let t = e.length, n =
|
|
297
|
+
function _e(e) {
|
|
298
|
+
let t = e.length, n = _(t, 4, "packed binary-list metadata"), r = 0;
|
|
300
299
|
for (let n = 0; n < t; n += 1) {
|
|
301
300
|
let t = e[n];
|
|
302
301
|
if (!(t instanceof Uint8Array)) throw h("WorkerProtocolError", "binary-list payload item is not a Uint8Array");
|
|
303
|
-
let i =
|
|
302
|
+
let i = y(t.byteLength, "binary-list item length");
|
|
304
303
|
if (r += i, r > m) throw h("WorkerProtocolError", "packed binary-list payload exceeds 32-bit payload limit");
|
|
305
304
|
}
|
|
306
|
-
let i =
|
|
305
|
+
let i = v(4, n, "packed binary-list header"), a = v(i, r, "packed binary-list total"), o = new Uint8Array(a), c = new DataView(o.buffer);
|
|
307
306
|
c.setUint32(0, t, !0);
|
|
308
307
|
let l = 4, u = i;
|
|
309
308
|
for (let n = 0; n < t; n += 1) {
|
|
@@ -315,10 +314,10 @@ function ge(e) {
|
|
|
315
314
|
bytes: o
|
|
316
315
|
};
|
|
317
316
|
}
|
|
318
|
-
function
|
|
317
|
+
function ve(e) {
|
|
319
318
|
let t = e.bytes;
|
|
320
319
|
if (!(t instanceof Uint8Array) || t.byteLength < 4) throw h("WorkerProtocolError", "invalid packed nullable binary-list payload");
|
|
321
|
-
let n = new DataView(t.buffer, t.byteOffset, t.byteLength), r = n.getUint32(0, !0), i =
|
|
320
|
+
let n = new DataView(t.buffer, t.byteOffset, t.byteLength), r = n.getUint32(0, !0), i = v(4, _(r, 5, "packed nullable binary-list metadata"), "packed nullable binary-list header");
|
|
322
321
|
if (i > t.byteLength) throw h("WorkerProtocolError", "packed nullable binary-list metadata exceeds payload length");
|
|
323
322
|
let a = Array(r), o = 4, s = i;
|
|
324
323
|
for (let e = 0; e < r; e += 1) {
|
|
@@ -336,10 +335,10 @@ function _e(e) {
|
|
|
336
335
|
if (s !== t.byteLength) throw h("WorkerProtocolError", "packed nullable binary-list payload has trailing bytes");
|
|
337
336
|
return a;
|
|
338
337
|
}
|
|
339
|
-
function
|
|
338
|
+
function ye(e) {
|
|
340
339
|
let t = e.bytes;
|
|
341
340
|
if (!(t instanceof Uint8Array) || t.byteLength < 4) throw h("WorkerProtocolError", "invalid packed scan row payload");
|
|
342
|
-
let n = new DataView(t.buffer, t.byteOffset, t.byteLength), r = n.getUint32(0, !0), i =
|
|
341
|
+
let n = new DataView(t.buffer, t.byteOffset, t.byteLength), r = n.getUint32(0, !0), i = v(4, _(r, 8, "packed scan row metadata"), "packed scan row header");
|
|
343
342
|
if (i > t.byteLength) throw h("WorkerProtocolError", "packed scan row metadata exceeds payload length");
|
|
344
343
|
let a = Array(r), o = 4, s = i;
|
|
345
344
|
for (let e = 0; e < r; e += 1) {
|
|
@@ -357,21 +356,21 @@ function ve(e) {
|
|
|
357
356
|
if (s !== t.byteLength) throw h("WorkerProtocolError", "packed scan row payload has trailing bytes");
|
|
358
357
|
return a;
|
|
359
358
|
}
|
|
360
|
-
function
|
|
361
|
-
let n = t.length, r =
|
|
359
|
+
function be(t) {
|
|
360
|
+
let n = t.length, r = _(n, 9, "packed batch metadata"), i = 0;
|
|
362
361
|
for (let r = 0; r < n; r += 1) {
|
|
363
362
|
let n = t[r];
|
|
364
363
|
if (!e(n) || n.kind !== "put" && n.kind !== "delete") throw h("WorkerProtocolError", "batch operation kind is not put or delete");
|
|
365
364
|
if (!(n.key instanceof Uint8Array)) throw h("WorkerProtocolError", "batch operation key is not a Uint8Array");
|
|
366
|
-
let a =
|
|
365
|
+
let a = y(n.key.byteLength, "batch operation key length");
|
|
367
366
|
if (i += a, i > m) throw h("WorkerProtocolError", "packed batch payload exceeds 32-bit payload limit");
|
|
368
367
|
if (n.kind === "put") {
|
|
369
368
|
if (!(n.value instanceof Uint8Array)) throw h("WorkerProtocolError", "batch put value is not a Uint8Array");
|
|
370
|
-
let e =
|
|
369
|
+
let e = y(n.value.byteLength, "batch put value length");
|
|
371
370
|
if (i += e, i > m) throw h("WorkerProtocolError", "packed batch payload exceeds 32-bit payload limit");
|
|
372
371
|
}
|
|
373
372
|
}
|
|
374
|
-
let a =
|
|
373
|
+
let a = v(4, r, "packed batch header"), o = v(a, i, "packed batch total"), s = new Uint8Array(o), c = new DataView(s.buffer);
|
|
375
374
|
c.setUint32(0, n, !0);
|
|
376
375
|
let l = 4, u = a;
|
|
377
376
|
for (let e = 0; e < n; e += 1) {
|
|
@@ -383,39 +382,33 @@ function ye(t) {
|
|
|
383
382
|
bytes: s
|
|
384
383
|
};
|
|
385
384
|
}
|
|
386
|
-
function
|
|
387
|
-
return e(t) && t.__moyodbPacked ===
|
|
388
|
-
}
|
|
389
|
-
function xe(t) {
|
|
390
|
-
return e(t) && t.__moyodbPacked === l && t.bytes instanceof Uint8Array;
|
|
385
|
+
function g(t, n) {
|
|
386
|
+
return e(t) && t.__moyodbPacked === n && t.bytes instanceof Uint8Array;
|
|
391
387
|
}
|
|
392
|
-
function
|
|
393
|
-
return e(t) && t.__moyodbPacked === f && t.bytes instanceof Uint8Array;
|
|
394
|
-
}
|
|
395
|
-
function g(e, t, n) {
|
|
388
|
+
function _(e, t, n) {
|
|
396
389
|
if (!Number.isSafeInteger(e) || e < 0) throw h("WorkerProtocolError", `${n} count is invalid: ${e}`);
|
|
397
|
-
return
|
|
390
|
+
return y(e * t, n);
|
|
398
391
|
}
|
|
399
|
-
function
|
|
400
|
-
return
|
|
392
|
+
function v(e, t, n) {
|
|
393
|
+
return y(e + t, n);
|
|
401
394
|
}
|
|
402
|
-
function
|
|
395
|
+
function y(e, t) {
|
|
403
396
|
if (!Number.isSafeInteger(e) || e < 0 || e > m) throw h("WorkerProtocolError", `${t} exceeds 32-bit payload limit`);
|
|
404
397
|
return e;
|
|
405
398
|
}
|
|
406
|
-
function
|
|
399
|
+
function xe(e) {
|
|
407
400
|
let t = new Uint8Array(e.byteLength);
|
|
408
401
|
return t.set(e), t;
|
|
409
402
|
}
|
|
410
|
-
function
|
|
403
|
+
function Se(e) {
|
|
411
404
|
return typeof e == "string" ? e : void 0;
|
|
412
405
|
}
|
|
413
406
|
//#endregion
|
|
414
407
|
//#region src/worker-client.ts
|
|
415
|
-
function
|
|
408
|
+
function Ce(e) {
|
|
416
409
|
e.timeout &&= (clearTimeout(e.timeout), null);
|
|
417
410
|
}
|
|
418
|
-
var
|
|
411
|
+
var we = class {
|
|
419
412
|
worker;
|
|
420
413
|
nextRequestId = 1;
|
|
421
414
|
pending = /* @__PURE__ */ new Map();
|
|
@@ -653,7 +646,7 @@ var Ee = class {
|
|
|
653
646
|
this.ensureOpen();
|
|
654
647
|
let r = this.batching && (this.awaitingReady > 0 || this.queuedRequests.length > 0), i = this.nextRequestId;
|
|
655
648
|
this.nextRequestId += 1;
|
|
656
|
-
let a =
|
|
649
|
+
let a = ue(e, t), o = {
|
|
657
650
|
type: "moyodb:worker-protocol:request",
|
|
658
651
|
version: 1,
|
|
659
652
|
id: i,
|
|
@@ -679,7 +672,7 @@ var Ee = class {
|
|
|
679
672
|
});
|
|
680
673
|
}
|
|
681
674
|
queueRequest(e, t) {
|
|
682
|
-
let n =
|
|
675
|
+
let n = he(e, t);
|
|
683
676
|
this.pending.has(e.id) && (this.queuedRequests.length > 0 && this.queuedBytes + n.byteLength > 1048576 && this.flushRequests(), this.queuedRequests.push({
|
|
684
677
|
message: n.value,
|
|
685
678
|
transfer: n.transfer,
|
|
@@ -741,9 +734,9 @@ var Ee = class {
|
|
|
741
734
|
}
|
|
742
735
|
let n = this.pending.get(t.id);
|
|
743
736
|
if (n) {
|
|
744
|
-
this.pending.delete(t.id),
|
|
737
|
+
this.pending.delete(t.id), Ce(n);
|
|
745
738
|
try {
|
|
746
|
-
t.ok ? n.resolve(this.forwardScanPackets && (n.command === "scanPage" || n.command === "scan" || n.command === "scanByIndex" || n.command === "scanByIndexPage") ? t.result :
|
|
739
|
+
t.ok ? n.resolve(this.forwardScanPackets && (n.command === "scanPage" || n.command === "scan" || n.command === "scanByIndex" || n.command === "scanByIndexPage") ? t.result : fe(n.command, t.result)) : n.reject(ce(t.error));
|
|
747
740
|
} catch (e) {
|
|
748
741
|
n.reject(e instanceof Error && e.name === "WorkerProtocolError" ? e : h("WorkerProtocolError", "worker response could not be decoded"));
|
|
749
742
|
}
|
|
@@ -758,46 +751,46 @@ var Ee = class {
|
|
|
758
751
|
};
|
|
759
752
|
rejectPending(e, t) {
|
|
760
753
|
let n = this.pending.get(e);
|
|
761
|
-
n && (this.pending.delete(e),
|
|
754
|
+
n && (this.pending.delete(e), Ce(n), n.reject(t));
|
|
762
755
|
}
|
|
763
756
|
disposeInternal(e, t) {
|
|
764
757
|
if (!this.closed) {
|
|
765
758
|
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.readyTimeout && clearTimeout(this.readyTimeout), this.readyTimeout = null, this.readyResolved || this.readyReject?.(e), this.readyResolve = null, this.readyReject = null, this.queuedRequests = [], this.queuedBytes = 0;
|
|
766
|
-
for (let t of this.pending.values())
|
|
759
|
+
for (let t of this.pending.values()) Ce(t), t.reject(e);
|
|
767
760
|
this.pending.clear(), t && this.fatalHandler?.(e);
|
|
768
761
|
}
|
|
769
762
|
}
|
|
770
|
-
},
|
|
763
|
+
}, Te = "moyodb:shared-worker:control", Ee = "moyodb:shared-worker:owner-response", De = "moyodb:shared-worker:owner-host-message", Oe = 5e3;
|
|
771
764
|
//#endregion
|
|
772
765
|
//#region src/shared-worker-client.ts
|
|
773
|
-
function
|
|
766
|
+
function ke(e) {
|
|
774
767
|
try {
|
|
775
768
|
return ce(e);
|
|
776
769
|
} catch {
|
|
777
770
|
return h("WorkerProtocolError", "invalid shared worker error");
|
|
778
771
|
}
|
|
779
772
|
}
|
|
780
|
-
function
|
|
773
|
+
function Ae() {
|
|
781
774
|
let t = new Worker(new URL(
|
|
782
775
|
/* @vite-ignore */
|
|
783
|
-
new URL("assets/browser-worker-
|
|
776
|
+
new URL("assets/browser-worker-Bj2ErRvC.js", import.meta.url).href,
|
|
784
777
|
"" + import.meta.url
|
|
785
778
|
), { type: "module" }), n = new MessageChannel(), i = new MessageChannel(), a = new MessageChannel(), o = setInterval(() => {
|
|
786
779
|
i.port1.postMessage({
|
|
787
|
-
type:
|
|
780
|
+
type: De,
|
|
788
781
|
op: "ping"
|
|
789
782
|
});
|
|
790
|
-
},
|
|
783
|
+
}, Oe), s = !1, c = () => {
|
|
791
784
|
s || (s = !0, clearInterval(o), t.terminate(), i.port1.close(), a.port1.close(), globalThis.removeEventListener?.("pagehide", l));
|
|
792
785
|
}, l = () => {
|
|
793
786
|
i.port1.postMessage({
|
|
794
|
-
type:
|
|
787
|
+
type: De,
|
|
795
788
|
op: "gone"
|
|
796
789
|
}), c();
|
|
797
790
|
};
|
|
798
791
|
return t.addEventListener("error", (e) => {
|
|
799
792
|
i.port1.postMessage({
|
|
800
|
-
type:
|
|
793
|
+
type: De,
|
|
801
794
|
op: "error",
|
|
802
795
|
error: se(e.error ?? h("WorkerError", e.message))
|
|
803
796
|
}), c();
|
|
@@ -819,7 +812,7 @@ function Me() {
|
|
|
819
812
|
hostPort: i.port2
|
|
820
813
|
};
|
|
821
814
|
}
|
|
822
|
-
var
|
|
815
|
+
var je = class extends we {
|
|
823
816
|
sharedWorker;
|
|
824
817
|
controlId = 1;
|
|
825
818
|
controls = /* @__PURE__ */ new Map();
|
|
@@ -837,7 +830,7 @@ var Ne = class extends Ee {
|
|
|
837
830
|
return;
|
|
838
831
|
}
|
|
839
832
|
this.sendControl("ping", 0);
|
|
840
|
-
},
|
|
833
|
+
}, Oe);
|
|
841
834
|
}
|
|
842
835
|
acquireMigration() {
|
|
843
836
|
return this.control("acquireMigration");
|
|
@@ -877,7 +870,7 @@ var Ne = class extends Ee {
|
|
|
877
870
|
}
|
|
878
871
|
sendControl(e, t) {
|
|
879
872
|
let n = {
|
|
880
|
-
type:
|
|
873
|
+
type: Te,
|
|
881
874
|
op: e,
|
|
882
875
|
id: t
|
|
883
876
|
};
|
|
@@ -892,15 +885,15 @@ var Ne = class extends Ee {
|
|
|
892
885
|
}
|
|
893
886
|
if (n.type === "moyodb:shared-worker:owner-request" && typeof n.id == "number") {
|
|
894
887
|
try {
|
|
895
|
-
let { workerPort: e, hostPort: t } =
|
|
888
|
+
let { workerPort: e, hostPort: t } = Ae();
|
|
896
889
|
this.sharedWorker.port.postMessage({
|
|
897
|
-
type:
|
|
890
|
+
type: Ee,
|
|
898
891
|
id: n.id,
|
|
899
892
|
ok: !0
|
|
900
893
|
}, [e, t]);
|
|
901
894
|
} catch (e) {
|
|
902
895
|
this.sharedWorker.port.postMessage({
|
|
903
|
-
type:
|
|
896
|
+
type: Ee,
|
|
904
897
|
id: n.id,
|
|
905
898
|
ok: !1,
|
|
906
899
|
error: se(e)
|
|
@@ -909,7 +902,7 @@ var Ne = class extends Ee {
|
|
|
909
902
|
return;
|
|
910
903
|
}
|
|
911
904
|
if (n.type === "moyodb:shared-worker:fatal") {
|
|
912
|
-
this.fail(
|
|
905
|
+
this.fail(ke(n.error));
|
|
913
906
|
return;
|
|
914
907
|
}
|
|
915
908
|
if (n.type === "moyodb:shared-worker:invalidate-transactions") {
|
|
@@ -923,7 +916,7 @@ var Ne = class extends Ee {
|
|
|
923
916
|
}
|
|
924
917
|
if (typeof n.id != "number") return;
|
|
925
918
|
let r = this.controls.get(n.id);
|
|
926
|
-
r && (this.controls.delete(n.id), n.ok === !0 ? r.resolve() : r.reject(
|
|
919
|
+
r && (this.controls.delete(n.id), n.ok === !0 ? r.resolve() : r.reject(ke(n.error)));
|
|
927
920
|
};
|
|
928
921
|
handleSharedError = (e) => {
|
|
929
922
|
this.fail(h("WorkerError", e.message || "shared worker runtime failed"));
|
|
@@ -949,260 +942,256 @@ var Ne = class extends Ee {
|
|
|
949
942
|
for (let t of this.controls.values()) t.reject(e);
|
|
950
943
|
this.controls.clear(), this.invalidationHandler = null;
|
|
951
944
|
}
|
|
952
|
-
},
|
|
945
|
+
}, b = class extends Error {
|
|
953
946
|
constructor(e, t) {
|
|
954
947
|
super(t), this.name = e, Object.setPrototypeOf(this, new.target.prototype);
|
|
955
948
|
}
|
|
956
|
-
},
|
|
949
|
+
}, x = class extends b {
|
|
957
950
|
constructor(e) {
|
|
958
951
|
super("UnsupportedPlatformError", e);
|
|
959
952
|
}
|
|
960
|
-
},
|
|
953
|
+
}, Me = class extends b {
|
|
961
954
|
constructor(e) {
|
|
962
955
|
super("DatabaseBusyError", e);
|
|
963
956
|
}
|
|
964
|
-
},
|
|
957
|
+
}, Ne = class extends b {
|
|
965
958
|
constructor(e) {
|
|
966
959
|
super("CorruptionError", e);
|
|
967
960
|
}
|
|
968
|
-
},
|
|
961
|
+
}, Pe = class extends b {
|
|
969
962
|
constructor(e) {
|
|
970
963
|
super("StoreExistsError", e);
|
|
971
964
|
}
|
|
972
|
-
},
|
|
965
|
+
}, Fe = class extends b {
|
|
973
966
|
constructor(e) {
|
|
974
967
|
super("StoreNotFoundError", e);
|
|
975
968
|
}
|
|
976
|
-
},
|
|
969
|
+
}, Ie = class extends b {
|
|
977
970
|
constructor(e) {
|
|
978
971
|
super("IndexNotFoundError", e);
|
|
979
972
|
}
|
|
980
|
-
},
|
|
973
|
+
}, S = class extends b {
|
|
981
974
|
constructor(e) {
|
|
982
975
|
super("ConstraintError", e);
|
|
983
976
|
}
|
|
984
|
-
},
|
|
977
|
+
}, Le = class extends S {
|
|
985
978
|
constructor(e) {
|
|
986
979
|
super(e), this.name = "UniqueIndexConstraintError";
|
|
987
980
|
}
|
|
988
|
-
},
|
|
981
|
+
}, Re = class extends b {
|
|
989
982
|
constructor(e = "write transaction already open") {
|
|
990
983
|
super("WriteTransactionAlreadyOpenError", e);
|
|
991
984
|
}
|
|
992
|
-
},
|
|
985
|
+
}, ze = class extends b {
|
|
993
986
|
constructor(e = "transaction snapshot is stale; start a new transaction") {
|
|
994
987
|
super("TransactionConflictError", e);
|
|
995
988
|
}
|
|
996
|
-
},
|
|
989
|
+
}, Be = class extends b {
|
|
997
990
|
constructor(e = "readonly transaction cannot perform this operation") {
|
|
998
991
|
super("ReadonlyTransactionError", e);
|
|
999
992
|
}
|
|
1000
|
-
},
|
|
993
|
+
}, C = class extends b {
|
|
1001
994
|
constructor(e = "transaction is already closed") {
|
|
1002
995
|
super("TransactionClosedError", e);
|
|
1003
996
|
}
|
|
1004
|
-
},
|
|
997
|
+
}, w = class extends b {
|
|
1005
998
|
constructor(e = "database handle is closed") {
|
|
1006
999
|
super("DatabaseClosedError", e);
|
|
1007
1000
|
}
|
|
1008
|
-
},
|
|
1001
|
+
}, Ve = class extends b {
|
|
1009
1002
|
constructor(e) {
|
|
1010
1003
|
super("ValueTooLargeError", e);
|
|
1011
1004
|
}
|
|
1012
|
-
},
|
|
1005
|
+
}, He = class extends b {
|
|
1013
1006
|
constructor(e) {
|
|
1014
1007
|
super("KeyTooLargeError", e);
|
|
1015
1008
|
}
|
|
1016
|
-
},
|
|
1009
|
+
}, Ue = class extends b {
|
|
1017
1010
|
constructor(e) {
|
|
1018
1011
|
super("StoreNameTooLongError", e);
|
|
1019
1012
|
}
|
|
1020
|
-
},
|
|
1013
|
+
}, We = class extends b {
|
|
1021
1014
|
constructor(e) {
|
|
1022
1015
|
super("ReservedStoreNameError", e);
|
|
1023
1016
|
}
|
|
1024
|
-
},
|
|
1017
|
+
}, Ge = class extends b {
|
|
1025
1018
|
constructor(e) {
|
|
1026
1019
|
super("InvalidRangeError", e);
|
|
1027
1020
|
}
|
|
1028
|
-
},
|
|
1021
|
+
}, Ke = class extends b {
|
|
1029
1022
|
constructor(e) {
|
|
1030
1023
|
super("StorageError", e);
|
|
1031
1024
|
}
|
|
1032
|
-
},
|
|
1025
|
+
}, T = class extends b {
|
|
1033
1026
|
constructor(e) {
|
|
1034
1027
|
super("SerializationError", e);
|
|
1035
1028
|
}
|
|
1036
|
-
},
|
|
1029
|
+
}, qe = class extends b {
|
|
1037
1030
|
constructor(e) {
|
|
1038
1031
|
super("InjectedFailureError", e);
|
|
1039
1032
|
}
|
|
1040
|
-
},
|
|
1033
|
+
}, Je = class extends b {
|
|
1041
1034
|
constructor(e) {
|
|
1042
1035
|
super("ChangeFeedCompactedError", e);
|
|
1043
1036
|
}
|
|
1044
|
-
},
|
|
1037
|
+
}, Ye = class extends b {
|
|
1045
1038
|
constructor(e) {
|
|
1046
1039
|
super("RecoveryRequiredError", e);
|
|
1047
1040
|
}
|
|
1048
|
-
},
|
|
1041
|
+
}, Xe = class extends b {
|
|
1049
1042
|
constructor(e) {
|
|
1050
1043
|
super("InternalError", e);
|
|
1051
1044
|
}
|
|
1052
|
-
},
|
|
1045
|
+
}, E = class extends b {
|
|
1053
1046
|
constructor(e) {
|
|
1054
1047
|
super("InvalidOpenOptionsError", e);
|
|
1055
1048
|
}
|
|
1056
|
-
},
|
|
1049
|
+
}, D = class extends b {
|
|
1057
1050
|
constructor(e) {
|
|
1058
1051
|
super("VersionError", e);
|
|
1059
1052
|
}
|
|
1060
|
-
},
|
|
1061
|
-
UnsupportedPlatformError:
|
|
1062
|
-
DatabaseBusyError:
|
|
1063
|
-
CorruptionError:
|
|
1064
|
-
StoreExistsError:
|
|
1065
|
-
StoreNotFoundError:
|
|
1066
|
-
IndexNotFoundError:
|
|
1067
|
-
ConstraintError:
|
|
1068
|
-
UniqueIndexConstraintError:
|
|
1069
|
-
WriteTransactionAlreadyOpenError:
|
|
1070
|
-
TransactionConflictError:
|
|
1071
|
-
ReadonlyTransactionError:
|
|
1072
|
-
TransactionClosedError:
|
|
1073
|
-
DatabaseClosedError:
|
|
1074
|
-
ValueTooLargeError:
|
|
1075
|
-
KeyTooLargeError:
|
|
1076
|
-
StoreNameTooLongError:
|
|
1077
|
-
ReservedStoreNameError:
|
|
1078
|
-
InvalidRangeError:
|
|
1079
|
-
StorageError:
|
|
1080
|
-
SerializationError:
|
|
1081
|
-
InjectedFailureError:
|
|
1082
|
-
ChangeFeedCompactedError:
|
|
1083
|
-
RecoveryRequiredError:
|
|
1084
|
-
InternalError:
|
|
1085
|
-
InvalidOpenOptionsError:
|
|
1086
|
-
VersionError:
|
|
1053
|
+
}, Ze = {
|
|
1054
|
+
UnsupportedPlatformError: x,
|
|
1055
|
+
DatabaseBusyError: Me,
|
|
1056
|
+
CorruptionError: Ne,
|
|
1057
|
+
StoreExistsError: Pe,
|
|
1058
|
+
StoreNotFoundError: Fe,
|
|
1059
|
+
IndexNotFoundError: Ie,
|
|
1060
|
+
ConstraintError: S,
|
|
1061
|
+
UniqueIndexConstraintError: Le,
|
|
1062
|
+
WriteTransactionAlreadyOpenError: Re,
|
|
1063
|
+
TransactionConflictError: ze,
|
|
1064
|
+
ReadonlyTransactionError: Be,
|
|
1065
|
+
TransactionClosedError: C,
|
|
1066
|
+
DatabaseClosedError: w,
|
|
1067
|
+
ValueTooLargeError: Ve,
|
|
1068
|
+
KeyTooLargeError: He,
|
|
1069
|
+
StoreNameTooLongError: Ue,
|
|
1070
|
+
ReservedStoreNameError: We,
|
|
1071
|
+
InvalidRangeError: Ge,
|
|
1072
|
+
StorageError: Ke,
|
|
1073
|
+
SerializationError: T,
|
|
1074
|
+
InjectedFailureError: qe,
|
|
1075
|
+
ChangeFeedCompactedError: Je,
|
|
1076
|
+
RecoveryRequiredError: Ye,
|
|
1077
|
+
InternalError: Xe,
|
|
1078
|
+
InvalidOpenOptionsError: E,
|
|
1079
|
+
VersionError: D
|
|
1087
1080
|
};
|
|
1088
|
-
function
|
|
1089
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
1090
|
-
let n =
|
|
1081
|
+
function Qe(e, t) {
|
|
1082
|
+
if (Object.prototype.hasOwnProperty.call(Ze, e)) {
|
|
1083
|
+
let n = Ze[e];
|
|
1091
1084
|
return new n(t);
|
|
1092
1085
|
}
|
|
1093
1086
|
let n = Error(t);
|
|
1094
1087
|
return n.name = e, n;
|
|
1095
1088
|
}
|
|
1096
|
-
function
|
|
1097
|
-
if (e instanceof
|
|
1098
|
-
if (e instanceof Error) return e.name === "Error" ? e :
|
|
1089
|
+
function O(e) {
|
|
1090
|
+
if (e instanceof b) return e;
|
|
1091
|
+
if (e instanceof Error) return e.name === "Error" ? e : Qe(e.name, e.message);
|
|
1099
1092
|
let t = e;
|
|
1100
|
-
return
|
|
1093
|
+
return Qe(t?.code ?? t?.name ?? "Error", t?.message ?? String(e));
|
|
1101
1094
|
}
|
|
1102
1095
|
//#endregion
|
|
1103
1096
|
//#region src/registry.ts
|
|
1104
|
-
var
|
|
1097
|
+
var $e = /* @__PURE__ */ new Set([
|
|
1105
1098
|
"after_wal_flush",
|
|
1106
1099
|
"after_main_flush",
|
|
1107
1100
|
"before_superblock_flush"
|
|
1108
|
-
]),
|
|
1109
|
-
function
|
|
1110
|
-
return e(t) && t.type ===
|
|
1111
|
-
}
|
|
1112
|
-
var
|
|
1113
|
-
function
|
|
1114
|
-
let n = (
|
|
1115
|
-
return
|
|
1116
|
-
|
|
1101
|
+
]), et = "moyodb:persistence-bridge:init", tt = "moyodb:persistence-bridge:request", nt = "moyodb:persistence-bridge:response";
|
|
1102
|
+
function rt(t) {
|
|
1103
|
+
return e(t) && t.type === tt && typeof t.id == "number" && (t.op === "persist" || t.op === "persisted");
|
|
1104
|
+
}
|
|
1105
|
+
var it = 1e5, k = /* @__PURE__ */ new Map(), at = /* @__PURE__ */ new Map();
|
|
1106
|
+
function ot(e, t) {
|
|
1107
|
+
let n = (at.get(e) ?? Promise.resolve()).then(t), r = n.then(() => void 0, () => void 0);
|
|
1108
|
+
return at.set(e, r), r.then(() => {
|
|
1109
|
+
at.get(e) === r && at.delete(e);
|
|
1117
1110
|
}), n;
|
|
1118
1111
|
}
|
|
1119
|
-
function
|
|
1120
|
-
if (typeof e != "object" || !e || Array.isArray(e)) throw new
|
|
1112
|
+
function st(e) {
|
|
1113
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw new E("open options must be an object");
|
|
1121
1114
|
}
|
|
1122
|
-
function
|
|
1115
|
+
function ct(e, t, n) {
|
|
1123
1116
|
if (e === void 0) return n;
|
|
1124
|
-
if (typeof e != "boolean") throw new
|
|
1117
|
+
if (typeof e != "boolean") throw new E(`${t} must be a boolean`);
|
|
1125
1118
|
return e;
|
|
1126
1119
|
}
|
|
1127
|
-
function
|
|
1120
|
+
function lt(e, t, n) {
|
|
1128
1121
|
if (e === void 0) return n;
|
|
1129
|
-
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw new
|
|
1122
|
+
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw new E(`${t} must be a non-negative safe integer`);
|
|
1130
1123
|
return e;
|
|
1131
1124
|
}
|
|
1132
|
-
function
|
|
1133
|
-
return Math.max(1,
|
|
1125
|
+
function ut(e) {
|
|
1126
|
+
return Math.max(1, lt(e, "cachePages", 256));
|
|
1134
1127
|
}
|
|
1135
|
-
function
|
|
1128
|
+
function dt(e) {
|
|
1136
1129
|
if (e == null) return null;
|
|
1137
|
-
if (typeof e != "string" ||
|
|
1130
|
+
if (typeof e != "string" || !$e.has(e)) throw new E(`debugFailpoint must be one of: ${Array.from($e).join(", ")}`);
|
|
1138
1131
|
return e;
|
|
1139
1132
|
}
|
|
1140
|
-
function
|
|
1133
|
+
function ft(e) {
|
|
1141
1134
|
if (e === void 0) return null;
|
|
1142
|
-
if (typeof e != "object" || !e || Array.isArray(e)) throw new
|
|
1143
|
-
let t = e, n =
|
|
1135
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw new E("changeFeed must be an object");
|
|
1136
|
+
let t = e, n = ct(t.enabled, "changeFeed.enabled", !0), r = it;
|
|
1144
1137
|
if (t.retainTxids === null) r = null;
|
|
1145
|
-
else if (t.retainTxids !== void 0 && (r =
|
|
1138
|
+
else if (t.retainTxids !== void 0 && (r = lt(t.retainTxids, "changeFeed.retainTxids", 0), r === 0)) throw new E("changeFeed.retainTxids must be positive; disable the feed instead");
|
|
1146
1139
|
return {
|
|
1147
1140
|
enabled: n,
|
|
1148
1141
|
retainTxids: r
|
|
1149
1142
|
};
|
|
1150
1143
|
}
|
|
1151
|
-
function
|
|
1144
|
+
function pt(e) {
|
|
1152
1145
|
if (e === void 0) return "dedicated";
|
|
1153
|
-
if (e !== "dedicated" && e !== "shared") throw new
|
|
1146
|
+
if (e !== "dedicated" && e !== "shared") throw new E("workerMode must be dedicated or shared");
|
|
1154
1147
|
return e;
|
|
1155
1148
|
}
|
|
1156
|
-
function
|
|
1157
|
-
return
|
|
1158
|
-
workerMode:
|
|
1159
|
-
createIfMissing:
|
|
1160
|
-
ownerWaitMs:
|
|
1161
|
-
requestPersistence:
|
|
1162
|
-
cachePages:
|
|
1163
|
-
debugFailpoint:
|
|
1164
|
-
changeFeed:
|
|
1149
|
+
function mt(e = {}) {
|
|
1150
|
+
return st(e), {
|
|
1151
|
+
workerMode: pt(e.workerMode),
|
|
1152
|
+
createIfMissing: ct(e.createIfMissing, "createIfMissing", !0),
|
|
1153
|
+
ownerWaitMs: lt(e.ownerWaitMs, "ownerWaitMs", 0),
|
|
1154
|
+
requestPersistence: ct(e.requestPersistence, "requestPersistence", !0),
|
|
1155
|
+
cachePages: ut(e.cachePages),
|
|
1156
|
+
debugFailpoint: dt(e.debugFailpoint),
|
|
1157
|
+
changeFeed: ft(e.changeFeed)
|
|
1165
1158
|
};
|
|
1166
1159
|
}
|
|
1167
|
-
function
|
|
1160
|
+
function ht(e, t) {
|
|
1168
1161
|
return e?.enabled === t?.enabled && e?.retainTxids === t?.retainTxids;
|
|
1169
1162
|
}
|
|
1170
|
-
function
|
|
1171
|
-
if (t.workerMode !== n.workerMode) throw new
|
|
1172
|
-
if (t.cachePages !== n.cachePages) throw new
|
|
1173
|
-
if (n.changeFeed !== null && !
|
|
1174
|
-
}
|
|
1175
|
-
async function yt() {
|
|
1176
|
-
let e = globalThis.navigator.storage;
|
|
1177
|
-
return typeof e.persisted == "function" && await r(e.persisted(), 1e3, !1);
|
|
1163
|
+
function gt(e, t, n) {
|
|
1164
|
+
if (t.workerMode !== n.workerMode) throw new E(`database ${e} is already open with workerMode=${t.workerMode}`);
|
|
1165
|
+
if (t.cachePages !== n.cachePages) throw new E(`database ${e} is already open in this tab with cachePages=${t.cachePages}; requested cachePages=${n.cachePages}`);
|
|
1166
|
+
if (n.changeFeed !== null && !ht(t.changeFeed, n.changeFeed)) throw new E(`database ${e} is already open in this tab with a different changeFeed policy`);
|
|
1178
1167
|
}
|
|
1179
|
-
async function
|
|
1180
|
-
let
|
|
1181
|
-
return typeof e
|
|
1168
|
+
async function _t(e) {
|
|
1169
|
+
let t = globalThis.navigator.storage;
|
|
1170
|
+
return typeof t[e] == "function" && await r(t[e](), 1e3, !1);
|
|
1182
1171
|
}
|
|
1183
|
-
async function
|
|
1184
|
-
let n = t.op
|
|
1185
|
-
type:
|
|
1172
|
+
async function vt(e, t) {
|
|
1173
|
+
let n = await _t(t.op), r = {
|
|
1174
|
+
type: nt,
|
|
1186
1175
|
id: t.id,
|
|
1187
1176
|
granted: n
|
|
1188
1177
|
};
|
|
1189
1178
|
e.postMessage(r);
|
|
1190
1179
|
}
|
|
1191
|
-
function
|
|
1180
|
+
function yt(e) {
|
|
1192
1181
|
let t = new MessageChannel(), n = t.port1;
|
|
1193
1182
|
return n.addEventListener("message", (e) => {
|
|
1194
1183
|
let t = e.data;
|
|
1195
|
-
|
|
1196
|
-
}), n.start(), e.postMessage({ type:
|
|
1184
|
+
rt(t) && vt(n, t);
|
|
1185
|
+
}), n.start(), e.postMessage({ type: et }, [t.port2]), { close() {
|
|
1197
1186
|
n.close();
|
|
1198
1187
|
} };
|
|
1199
1188
|
}
|
|
1200
|
-
function
|
|
1189
|
+
function bt(e, t = "dedicated") {
|
|
1201
1190
|
if (t === "shared") {
|
|
1202
|
-
if (typeof globalThis.SharedWorker != "function") throw new
|
|
1203
|
-
let t = new
|
|
1191
|
+
if (typeof globalThis.SharedWorker != "function") throw new x("SharedWorker is unavailable; workerMode=shared cannot be opened");
|
|
1192
|
+
let t = new je(new SharedWorker(new URL(
|
|
1204
1193
|
/* @vite-ignore */
|
|
1205
|
-
new URL("assets/shared-worker-
|
|
1194
|
+
new URL("assets/shared-worker-CMeTcusa.js", import.meta.url).href,
|
|
1206
1195
|
"" + import.meta.url
|
|
1207
1196
|
), {
|
|
1208
1197
|
type: "module",
|
|
@@ -1216,16 +1205,16 @@ function Ct(e, t = "dedicated") {
|
|
|
1216
1205
|
}
|
|
1217
1206
|
let n = new Worker(new URL(
|
|
1218
1207
|
/* @vite-ignore */
|
|
1219
|
-
new URL("assets/browser-worker-
|
|
1208
|
+
new URL("assets/browser-worker-Bj2ErRvC.js", import.meta.url).href,
|
|
1220
1209
|
"" + import.meta.url
|
|
1221
1210
|
), { type: "module" });
|
|
1222
1211
|
return {
|
|
1223
1212
|
worker: n,
|
|
1224
|
-
proxy: new
|
|
1225
|
-
persistenceBridge:
|
|
1213
|
+
proxy: new we(n),
|
|
1214
|
+
persistenceBridge: yt(n)
|
|
1226
1215
|
};
|
|
1227
1216
|
}
|
|
1228
|
-
function
|
|
1217
|
+
function xt(e, t, n, r, i) {
|
|
1229
1218
|
let a = {
|
|
1230
1219
|
dbName: e,
|
|
1231
1220
|
refs: 1,
|
|
@@ -1238,64 +1227,64 @@ function wt(e, t, n, r, i) {
|
|
|
1238
1227
|
txInvalidationListeners: /* @__PURE__ */ new Set(),
|
|
1239
1228
|
handleInvalidationListeners: /* @__PURE__ */ new Set()
|
|
1240
1229
|
};
|
|
1241
|
-
return n.setTransactionsInvalidatedHandler?.(() =>
|
|
1242
|
-
|
|
1230
|
+
return n.setTransactionsInvalidatedHandler?.(() => Tt(a)), n.setFatalHandler(() => {
|
|
1231
|
+
k.get(e) !== a || a.invalidated || (k.delete(e), a.refs = 0, Et(a), a.persistenceBridge.close(), a.worker.terminate());
|
|
1243
1232
|
}), a;
|
|
1244
1233
|
}
|
|
1245
|
-
function
|
|
1234
|
+
function St(e) {
|
|
1246
1235
|
for (let t of Array.from(e)) t();
|
|
1247
1236
|
}
|
|
1248
|
-
function
|
|
1237
|
+
function Ct(e, t) {
|
|
1249
1238
|
return e.txInvalidationListeners.add(t), () => {
|
|
1250
1239
|
e.txInvalidationListeners.delete(t);
|
|
1251
1240
|
};
|
|
1252
1241
|
}
|
|
1253
|
-
function
|
|
1242
|
+
function wt(e, t) {
|
|
1254
1243
|
return e.handleInvalidationListeners.add(t), () => {
|
|
1255
1244
|
e.handleInvalidationListeners.delete(t);
|
|
1256
1245
|
};
|
|
1257
1246
|
}
|
|
1258
|
-
function
|
|
1259
|
-
|
|
1247
|
+
function Tt(e) {
|
|
1248
|
+
St(e.txInvalidationListeners);
|
|
1260
1249
|
}
|
|
1261
|
-
function
|
|
1262
|
-
e.invalidated || (e.invalidated = !0,
|
|
1250
|
+
function Et(e) {
|
|
1251
|
+
e.invalidated || (e.invalidated = !0, Tt(e), St(e.handleInvalidationListeners));
|
|
1263
1252
|
}
|
|
1264
|
-
function
|
|
1265
|
-
let t =
|
|
1266
|
-
return t ? (
|
|
1253
|
+
function Dt(e) {
|
|
1254
|
+
let t = k.get(e);
|
|
1255
|
+
return t ? (k.delete(e), Et(t), t.refs = 0, t.persistenceBridge.close(), t.proxy.crash?.(), t.proxy.dispose(/* @__PURE__ */ Error("worker was terminated by unsafeDebugCrashWorker")), t.worker.terminate(), !0) : !1;
|
|
1267
1256
|
}
|
|
1268
|
-
async function
|
|
1269
|
-
let n =
|
|
1270
|
-
return
|
|
1271
|
-
let t =
|
|
1257
|
+
async function Ot(e, t = {}) {
|
|
1258
|
+
let n = mt(t);
|
|
1259
|
+
return ot(e, async () => {
|
|
1260
|
+
let t = k.get(e);
|
|
1272
1261
|
if (t) {
|
|
1273
|
-
if (t.invalidated)
|
|
1262
|
+
if (t.invalidated) k.delete(e);
|
|
1274
1263
|
else {
|
|
1275
|
-
if (t.schemaMigrationInProgress) throw new
|
|
1276
|
-
if (
|
|
1264
|
+
if (t.schemaMigrationInProgress) throw new Me(`database ${e} is migrating; wait for openDB() to resolve`);
|
|
1265
|
+
if (gt(e, t.options, n), n.debugFailpoint !== null) try {
|
|
1277
1266
|
await t.proxy.setFailpoint(n.debugFailpoint);
|
|
1278
1267
|
} catch (e) {
|
|
1279
|
-
throw
|
|
1268
|
+
throw O(e);
|
|
1280
1269
|
}
|
|
1281
1270
|
return t.refs += 1, t;
|
|
1282
1271
|
}
|
|
1283
1272
|
}
|
|
1284
|
-
let { worker: r, proxy: i, persistenceBridge: a } =
|
|
1273
|
+
let { worker: r, proxy: i, persistenceBridge: a } = bt(e, n.workerMode), o = xt(e, r, i, a, n);
|
|
1285
1274
|
try {
|
|
1286
1275
|
return await i.open({
|
|
1287
1276
|
dbName: e,
|
|
1288
1277
|
options: n
|
|
1289
|
-
}),
|
|
1278
|
+
}), k.set(e, o), o;
|
|
1290
1279
|
} catch (e) {
|
|
1291
|
-
throw a.close(), i.dispose(/* @__PURE__ */ Error("worker open failed")), await r.terminate(),
|
|
1280
|
+
throw a.close(), i.dispose(/* @__PURE__ */ Error("worker open failed")), await r.terminate(), O(e);
|
|
1292
1281
|
}
|
|
1293
1282
|
});
|
|
1294
1283
|
}
|
|
1295
|
-
async function
|
|
1296
|
-
return e.release ? e.release() :
|
|
1297
|
-
if (!(e.invalidated ||
|
|
1298
|
-
|
|
1284
|
+
async function kt(e) {
|
|
1285
|
+
return e.release ? e.release() : ot(e.dbName, async () => {
|
|
1286
|
+
if (!(e.invalidated || k.get(e.dbName) !== e) && (--e.refs, !(e.refs > 0))) {
|
|
1287
|
+
k.delete(e.dbName);
|
|
1299
1288
|
try {
|
|
1300
1289
|
await e.proxy.close();
|
|
1301
1290
|
} finally {
|
|
@@ -1304,41 +1293,41 @@ async function jt(e) {
|
|
|
1304
1293
|
}
|
|
1305
1294
|
});
|
|
1306
1295
|
}
|
|
1307
|
-
async function
|
|
1308
|
-
return e.destroy ? e.destroy() :
|
|
1296
|
+
async function At(e) {
|
|
1297
|
+
return e.destroy ? e.destroy() : ot(e.dbName, () => jt(e));
|
|
1309
1298
|
}
|
|
1310
|
-
async function
|
|
1311
|
-
if (e.invalidated ||
|
|
1299
|
+
async function jt(e) {
|
|
1300
|
+
if (e.invalidated || k.get(e.dbName) !== e) throw new w();
|
|
1312
1301
|
if (e.options.workerMode === "shared") {
|
|
1313
1302
|
try {
|
|
1314
1303
|
await e.proxy.destroy();
|
|
1315
1304
|
} catch (e) {
|
|
1316
|
-
throw
|
|
1305
|
+
throw O(e);
|
|
1317
1306
|
}
|
|
1318
|
-
|
|
1307
|
+
k.delete(e.dbName), Et(e), e.refs = 0, e.persistenceBridge.close(), e.proxy.dispose(/* @__PURE__ */ Error("worker was released")), await e.worker.terminate();
|
|
1319
1308
|
return;
|
|
1320
1309
|
}
|
|
1321
|
-
|
|
1310
|
+
k.delete(e.dbName), Et(e), e.refs = 0;
|
|
1322
1311
|
try {
|
|
1323
1312
|
await e.proxy.destroy();
|
|
1324
1313
|
} catch (e) {
|
|
1325
|
-
throw
|
|
1314
|
+
throw O(e);
|
|
1326
1315
|
} finally {
|
|
1327
1316
|
e.persistenceBridge.close(), e.proxy.dispose(/* @__PURE__ */ Error("worker was released")), await e.worker.terminate();
|
|
1328
1317
|
}
|
|
1329
1318
|
}
|
|
1330
|
-
async function
|
|
1331
|
-
return
|
|
1332
|
-
let t =
|
|
1319
|
+
async function Mt(e) {
|
|
1320
|
+
return ot(e, async () => {
|
|
1321
|
+
let t = k.get(e);
|
|
1333
1322
|
if (t) {
|
|
1334
|
-
await
|
|
1323
|
+
await jt(t);
|
|
1335
1324
|
return;
|
|
1336
1325
|
}
|
|
1337
|
-
let { worker: n, proxy: r, persistenceBridge: i } =
|
|
1326
|
+
let { worker: n, proxy: r, persistenceBridge: i } = bt(e);
|
|
1338
1327
|
try {
|
|
1339
1328
|
await r.deleteDB(e);
|
|
1340
1329
|
} catch (e) {
|
|
1341
|
-
throw
|
|
1330
|
+
throw O(e);
|
|
1342
1331
|
} finally {
|
|
1343
1332
|
i.close(), r.dispose(/* @__PURE__ */ Error("temporary worker was terminated")), await n.terminate();
|
|
1344
1333
|
}
|
|
@@ -1346,45 +1335,45 @@ async function Pt(e) {
|
|
|
1346
1335
|
}
|
|
1347
1336
|
//#endregion
|
|
1348
1337
|
//#region src/codec.ts
|
|
1349
|
-
var
|
|
1338
|
+
var Nt = new TextEncoder(), Pt = new TextDecoder(), Ft = new TextDecoder("utf-8", { fatal: !0 }), It = 16, Lt = 32, Rt = 33, zt = 48, Bt = 64, Vt = 80, A = 0, Ht = 255, Ut = 0, Wt = BigInt("0xffffffffffffffff");
|
|
1350
1339
|
function j(e) {
|
|
1351
|
-
return
|
|
1340
|
+
return Nt.encode(e);
|
|
1352
1341
|
}
|
|
1353
|
-
function
|
|
1354
|
-
return
|
|
1342
|
+
function Gt(e) {
|
|
1343
|
+
return Pt.decode(e);
|
|
1355
1344
|
}
|
|
1356
1345
|
function M(e) {
|
|
1357
1346
|
let t = JSON.stringify(e);
|
|
1358
1347
|
if (t === void 0) throw TypeError("value has no JSON representation");
|
|
1359
1348
|
return j(t);
|
|
1360
1349
|
}
|
|
1361
|
-
function
|
|
1362
|
-
return JSON.parse(
|
|
1350
|
+
function Kt(e) {
|
|
1351
|
+
return JSON.parse(Ft.decode(e));
|
|
1363
1352
|
}
|
|
1364
|
-
function
|
|
1353
|
+
function qt(e) {
|
|
1365
1354
|
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");
|
|
1366
1355
|
let t = typeof e == "bigint" ? e : BigInt(e);
|
|
1367
1356
|
if (t < 0n) throw RangeError("u64Key only accepts non-negative values");
|
|
1368
|
-
if (t >
|
|
1357
|
+
if (t > Wt) throw RangeError("u64Key value exceeds the unsigned 64-bit range");
|
|
1369
1358
|
let n = /* @__PURE__ */ new ArrayBuffer(8);
|
|
1370
1359
|
return new DataView(n).setBigUint64(0, t, !1), new Uint8Array(n);
|
|
1371
1360
|
}
|
|
1372
|
-
function
|
|
1361
|
+
function Jt(e) {
|
|
1373
1362
|
return Array.isArray(e);
|
|
1374
1363
|
}
|
|
1375
1364
|
function N(e) {
|
|
1376
|
-
return
|
|
1365
|
+
return Jt(e) ? Yt(...e) : en(e);
|
|
1377
1366
|
}
|
|
1378
|
-
function
|
|
1379
|
-
return
|
|
1367
|
+
function Yt(...e) {
|
|
1368
|
+
return tn(e.map((e) => en(e)));
|
|
1380
1369
|
}
|
|
1381
1370
|
function P(e) {
|
|
1382
|
-
return
|
|
1371
|
+
return en(e);
|
|
1383
1372
|
}
|
|
1384
1373
|
function F(e) {
|
|
1385
|
-
return
|
|
1374
|
+
return tn(e);
|
|
1386
1375
|
}
|
|
1387
|
-
function
|
|
1376
|
+
function Xt(e) {
|
|
1388
1377
|
let t = [], n = [];
|
|
1389
1378
|
for (let r = 0; r < e.length; r += 1) {
|
|
1390
1379
|
let i = e[r];
|
|
@@ -1393,11 +1382,11 @@ function Qt(e) {
|
|
|
1393
1382
|
continue;
|
|
1394
1383
|
}
|
|
1395
1384
|
let a = e[r + 1];
|
|
1396
|
-
if (a ===
|
|
1385
|
+
if (a === Ht) {
|
|
1397
1386
|
n.push(A), r += 1;
|
|
1398
1387
|
continue;
|
|
1399
1388
|
}
|
|
1400
|
-
if (a ===
|
|
1389
|
+
if (a === Ut) {
|
|
1401
1390
|
t.push(Uint8Array.from(n)), n.length = 0, r += 1;
|
|
1402
1391
|
continue;
|
|
1403
1392
|
}
|
|
@@ -1406,40 +1395,40 @@ function Qt(e) {
|
|
|
1406
1395
|
if (n.length !== 0) throw TypeError("compound key terminated unexpectedly");
|
|
1407
1396
|
return t;
|
|
1408
1397
|
}
|
|
1409
|
-
function
|
|
1398
|
+
function Zt(e) {
|
|
1410
1399
|
let t = e.slice();
|
|
1411
1400
|
for (let e = t.length - 1; e >= 0; --e) if (t[e] !== 255) return t[e] += 1, t.subarray(0, e + 1);
|
|
1412
1401
|
return null;
|
|
1413
1402
|
}
|
|
1414
|
-
function
|
|
1415
|
-
let t =
|
|
1403
|
+
function Qt(e) {
|
|
1404
|
+
let t = Zt(e);
|
|
1416
1405
|
return t ? {
|
|
1417
1406
|
gte: e,
|
|
1418
1407
|
lt: t
|
|
1419
1408
|
} : { gte: e };
|
|
1420
1409
|
}
|
|
1421
|
-
function
|
|
1422
|
-
return
|
|
1410
|
+
function $t(...e) {
|
|
1411
|
+
return Qt(Yt(...e));
|
|
1423
1412
|
}
|
|
1424
|
-
function
|
|
1425
|
-
if (e === null) return Uint8Array.of(
|
|
1426
|
-
if (typeof e == "boolean") return Uint8Array.of(e ?
|
|
1427
|
-
if (typeof e == "number") return
|
|
1413
|
+
function en(e) {
|
|
1414
|
+
if (e === null) return Uint8Array.of(It);
|
|
1415
|
+
if (typeof e == "boolean") return Uint8Array.of(e ? Rt : Lt);
|
|
1416
|
+
if (typeof e == "number") return nn(e);
|
|
1428
1417
|
if (typeof e == "string") {
|
|
1429
1418
|
for (let t of e) {
|
|
1430
1419
|
let e = t.codePointAt(0);
|
|
1431
1420
|
if (e >= 55296 && e <= 57343) throw TypeError("compound key string parts must contain valid Unicode scalar values");
|
|
1432
1421
|
}
|
|
1433
1422
|
let t = j(e), n = new Uint8Array(1 + t.length);
|
|
1434
|
-
return n[0] =
|
|
1423
|
+
return n[0] = Bt, n.set(t, 1), n;
|
|
1435
1424
|
}
|
|
1436
1425
|
if (e instanceof Uint8Array) {
|
|
1437
1426
|
let t = new Uint8Array(1 + e.length);
|
|
1438
|
-
return t[0] =
|
|
1427
|
+
return t[0] = Vt, t.set(e, 1), t;
|
|
1439
1428
|
}
|
|
1440
1429
|
throw TypeError("compound key parts must be string, number, boolean, null, or Uint8Array");
|
|
1441
1430
|
}
|
|
1442
|
-
function
|
|
1431
|
+
function tn(e) {
|
|
1443
1432
|
let t = 0;
|
|
1444
1433
|
for (let n of e) {
|
|
1445
1434
|
for (let e of n) t += e === A ? 2 : 1;
|
|
@@ -1447,144 +1436,144 @@ function rn(e) {
|
|
|
1447
1436
|
}
|
|
1448
1437
|
let n = new Uint8Array(t), r = 0;
|
|
1449
1438
|
for (let t of e) {
|
|
1450
|
-
for (let e of t) e === A ? (n[r] = A, n[r + 1] =
|
|
1451
|
-
n[r] =
|
|
1439
|
+
for (let e of t) e === A ? (n[r] = A, n[r + 1] = Ht, r += 2) : (n[r] = e, r += 1);
|
|
1440
|
+
n[r] = Ut, n[r + 1] = Ut, r += 2;
|
|
1452
1441
|
}
|
|
1453
1442
|
return n;
|
|
1454
1443
|
}
|
|
1455
|
-
function
|
|
1444
|
+
function nn(e) {
|
|
1456
1445
|
if (!Number.isFinite(e)) throw TypeError("compound key number parts must be finite");
|
|
1457
1446
|
let t = Object.is(e, -0) ? 0 : e, n = /* @__PURE__ */ new ArrayBuffer(9), r = new DataView(n);
|
|
1458
|
-
r.setUint8(0,
|
|
1447
|
+
r.setUint8(0, zt), r.setFloat64(1, t, !1);
|
|
1459
1448
|
let i = r.getBigUint64(1, !1);
|
|
1460
|
-
return i = (i & 1n << 63n) == 0n ? i ^ 1n << 63n : ~i &
|
|
1449
|
+
return i = (i & 1n << 63n) == 0n ? i ^ 1n << 63n : ~i & Wt, r.setBigUint64(1, i, !1), new Uint8Array(n);
|
|
1461
1450
|
}
|
|
1462
1451
|
//#endregion
|
|
1463
1452
|
//#region src/indexing.ts
|
|
1464
|
-
var
|
|
1465
|
-
function
|
|
1466
|
-
return e.startsWith(
|
|
1453
|
+
var rn = new TextDecoder("utf-8", { fatal: !0 }), an = Symbol("moyodb.indexing.missing"), on = BigInt("0xcbf29ce484222325"), sn = BigInt("0x100000001b3"), cn = BigInt("0xffffffffffffffff"), ln = "__browserdb:", un = "__browserdb:index:", dn = "__browserdb:indexes";
|
|
1454
|
+
function fn(e) {
|
|
1455
|
+
return e.startsWith(ln);
|
|
1467
1456
|
}
|
|
1468
1457
|
function I(e) {
|
|
1469
|
-
if (
|
|
1458
|
+
if (fn(e)) throw new We(`reserved store name: ${e}`);
|
|
1470
1459
|
}
|
|
1471
1460
|
function L(e) {
|
|
1472
1461
|
if (e === void 0) return [];
|
|
1473
|
-
if (!Array.isArray(e)) throw new
|
|
1462
|
+
if (!Array.isArray(e)) throw new E("indexes must be an array");
|
|
1474
1463
|
let t = [], n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
|
|
1475
1464
|
for (let i of e) {
|
|
1476
|
-
if (typeof i != "object" || !i || Array.isArray(i)) throw new
|
|
1465
|
+
if (typeof i != "object" || !i || Array.isArray(i)) throw new E("each index definition must be an object");
|
|
1477
1466
|
let { store: e, name: a, keyPath: o, unique: s } = i;
|
|
1478
|
-
if (typeof e != "string" || e.length === 0) throw new
|
|
1479
|
-
if (typeof a != "string" || a.length === 0) throw new
|
|
1467
|
+
if (typeof e != "string" || e.length === 0) throw new E("index store must be a non-empty string");
|
|
1468
|
+
if (typeof a != "string" || a.length === 0) throw new E("index name must be a non-empty string");
|
|
1480
1469
|
I(e);
|
|
1481
|
-
let c =
|
|
1482
|
-
if (s !== void 0 && typeof s != "boolean") throw new
|
|
1470
|
+
let c = An(o);
|
|
1471
|
+
if (s !== void 0 && typeof s != "boolean") throw new E("index unique must be a boolean");
|
|
1483
1472
|
let l = {
|
|
1484
1473
|
store: e,
|
|
1485
1474
|
name: a,
|
|
1486
1475
|
keyPath: c.paths,
|
|
1487
1476
|
compound: c.compound,
|
|
1488
1477
|
unique: s ?? !1,
|
|
1489
|
-
internalStore:
|
|
1490
|
-
}, u =
|
|
1491
|
-
if (n.has(u)) throw new
|
|
1478
|
+
internalStore: Nn(e, a)
|
|
1479
|
+
}, u = mn(l.store, l.name);
|
|
1480
|
+
if (n.has(u)) throw new E(`duplicate index definition ${l.store}.${l.name}`);
|
|
1492
1481
|
n.add(u);
|
|
1493
1482
|
let d = r.get(l.internalStore);
|
|
1494
|
-
if (d && d !== u) throw new
|
|
1483
|
+
if (d && d !== u) throw new E(`index definitions ${d} and ${u} map to the same internal store ${l.internalStore}`);
|
|
1495
1484
|
r.set(l.internalStore, u), t.push(l);
|
|
1496
1485
|
}
|
|
1497
|
-
return t.sort(
|
|
1486
|
+
return t.sort(pn), t;
|
|
1498
1487
|
}
|
|
1499
|
-
function
|
|
1488
|
+
function pn(e, n) {
|
|
1500
1489
|
let r = t(e.store, n.store);
|
|
1501
1490
|
if (r !== 0) return r;
|
|
1502
1491
|
let i = t(e.name, n.name);
|
|
1503
1492
|
if (i !== 0) return i;
|
|
1504
1493
|
let a = Number(e.unique) - Number(n.unique);
|
|
1505
|
-
return a === 0 ? t(
|
|
1494
|
+
return a === 0 ? t(Mn(e), Mn(n)) : a;
|
|
1506
1495
|
}
|
|
1507
|
-
function
|
|
1496
|
+
function mn(e, t) {
|
|
1508
1497
|
return JSON.stringify([e, t]);
|
|
1509
1498
|
}
|
|
1510
|
-
function
|
|
1499
|
+
function hn(e, t, n) {
|
|
1511
1500
|
return e.find((e) => e.store === t && e.name === n) ?? null;
|
|
1512
1501
|
}
|
|
1513
|
-
function
|
|
1502
|
+
function gn(e, t) {
|
|
1514
1503
|
return e.filter((e) => e.store === t);
|
|
1515
1504
|
}
|
|
1516
|
-
function
|
|
1505
|
+
function _n(e, t) {
|
|
1517
1506
|
return F([j(e), j(t)]);
|
|
1518
1507
|
}
|
|
1519
|
-
function
|
|
1520
|
-
return j(JSON.stringify(
|
|
1508
|
+
function vn(e) {
|
|
1509
|
+
return j(JSON.stringify(kn(e)));
|
|
1521
1510
|
}
|
|
1522
|
-
function
|
|
1511
|
+
function yn(e) {
|
|
1523
1512
|
let t;
|
|
1524
1513
|
try {
|
|
1525
|
-
t = JSON.parse(
|
|
1514
|
+
t = JSON.parse(rn.decode(e));
|
|
1526
1515
|
let [n] = L([t]);
|
|
1527
1516
|
return n;
|
|
1528
1517
|
} catch (e) {
|
|
1529
|
-
throw new
|
|
1518
|
+
throw new T(`invalid persisted index metadata: ${String(e)}`);
|
|
1530
1519
|
}
|
|
1531
1520
|
}
|
|
1532
|
-
function
|
|
1521
|
+
function bn(e, t) {
|
|
1533
1522
|
return F([e, t]);
|
|
1534
1523
|
}
|
|
1535
|
-
function
|
|
1524
|
+
function xn(e) {
|
|
1536
1525
|
let t;
|
|
1537
1526
|
try {
|
|
1538
|
-
t =
|
|
1527
|
+
t = Xt(e);
|
|
1539
1528
|
} catch (e) {
|
|
1540
|
-
throw new
|
|
1529
|
+
throw new T(`invalid index entry key encoding: ${String(e)}`);
|
|
1541
1530
|
}
|
|
1542
|
-
if (t.length !== 2) throw new
|
|
1531
|
+
if (t.length !== 2) throw new T("invalid index entry key encoding");
|
|
1543
1532
|
return {
|
|
1544
1533
|
logicalKey: t[0],
|
|
1545
1534
|
primaryKey: t[1]
|
|
1546
1535
|
};
|
|
1547
1536
|
}
|
|
1548
|
-
function
|
|
1549
|
-
return
|
|
1537
|
+
function Sn(e) {
|
|
1538
|
+
return Qt(F([e]));
|
|
1550
1539
|
}
|
|
1551
|
-
function
|
|
1552
|
-
|
|
1540
|
+
function Cn(e = {}) {
|
|
1541
|
+
Bn(e);
|
|
1553
1542
|
let t = {};
|
|
1554
1543
|
if (e.reverse !== void 0 && (t.reverse = e.reverse), e.limit !== void 0 && (t.limit = e.limit), e.gte && (t.gte = F([e.gte])), e.gt) {
|
|
1555
|
-
let n =
|
|
1544
|
+
let n = Zt(F([e.gt]));
|
|
1556
1545
|
n && (t.gte = n);
|
|
1557
1546
|
}
|
|
1558
1547
|
if (e.lt && (t.lt = F([e.lt])), e.lte) {
|
|
1559
|
-
let n =
|
|
1548
|
+
let n = Zt(F([e.lte]));
|
|
1560
1549
|
n && (t.lt = n);
|
|
1561
1550
|
}
|
|
1562
1551
|
return t;
|
|
1563
1552
|
}
|
|
1564
|
-
function
|
|
1565
|
-
return
|
|
1553
|
+
function wn(e, t) {
|
|
1554
|
+
return En(e, In(t));
|
|
1566
1555
|
}
|
|
1567
|
-
function
|
|
1556
|
+
function Tn(e) {
|
|
1568
1557
|
let t = !1, n;
|
|
1569
|
-
return (r) => (t ||= (n =
|
|
1558
|
+
return (r) => (t ||= (n = In(e), !0), En(r, n));
|
|
1570
1559
|
}
|
|
1571
|
-
function
|
|
1560
|
+
function En(e, t) {
|
|
1572
1561
|
if (e.compound) {
|
|
1573
1562
|
let n = [];
|
|
1574
1563
|
for (let r of e.keyPath) {
|
|
1575
|
-
let e =
|
|
1576
|
-
if (e ===
|
|
1577
|
-
n.push(
|
|
1564
|
+
let e = Ln(t, r);
|
|
1565
|
+
if (e === an) return null;
|
|
1566
|
+
n.push(Rn(e));
|
|
1578
1567
|
}
|
|
1579
1568
|
return F(n);
|
|
1580
1569
|
}
|
|
1581
|
-
let n =
|
|
1582
|
-
return n ===
|
|
1570
|
+
let n = Ln(t, e.keyPath[0]);
|
|
1571
|
+
return n === an ? null : Rn(n);
|
|
1583
1572
|
}
|
|
1584
1573
|
function R(e) {
|
|
1585
|
-
return JSON.stringify(
|
|
1574
|
+
return JSON.stringify(On(e));
|
|
1586
1575
|
}
|
|
1587
|
-
function
|
|
1576
|
+
function Dn(e) {
|
|
1588
1577
|
return e.map((e) => ({
|
|
1589
1578
|
store: e.store,
|
|
1590
1579
|
name: e.name,
|
|
@@ -1594,10 +1583,10 @@ function An(e) {
|
|
|
1594
1583
|
internalStore: e.internalStore
|
|
1595
1584
|
}));
|
|
1596
1585
|
}
|
|
1597
|
-
function
|
|
1598
|
-
return e.map(
|
|
1586
|
+
function On(e) {
|
|
1587
|
+
return e.map(kn);
|
|
1599
1588
|
}
|
|
1600
|
-
function
|
|
1589
|
+
function kn(e) {
|
|
1601
1590
|
return {
|
|
1602
1591
|
store: e.store,
|
|
1603
1592
|
name: e.name,
|
|
@@ -1605,94 +1594,94 @@ function Mn(e) {
|
|
|
1605
1594
|
unique: e.unique
|
|
1606
1595
|
};
|
|
1607
1596
|
}
|
|
1608
|
-
function
|
|
1609
|
-
if (typeof e == "string") return
|
|
1597
|
+
function An(e) {
|
|
1598
|
+
if (typeof e == "string") return jn(e), {
|
|
1610
1599
|
paths: [e],
|
|
1611
1600
|
compound: !1
|
|
1612
1601
|
};
|
|
1613
|
-
if (!Array.isArray(e) || e.length === 0 || !e.every((e) => typeof e == "string")) throw new
|
|
1614
|
-
for (let t of e)
|
|
1602
|
+
if (!Array.isArray(e) || e.length === 0 || !e.every((e) => typeof e == "string")) throw new E("index keyPath must be a non-empty string or non-empty string[]");
|
|
1603
|
+
for (let t of e) jn(t);
|
|
1615
1604
|
return {
|
|
1616
1605
|
paths: [...e],
|
|
1617
1606
|
compound: !0
|
|
1618
1607
|
};
|
|
1619
1608
|
}
|
|
1620
|
-
function
|
|
1621
|
-
if (e.length === 0) throw new
|
|
1622
|
-
if (e.startsWith(".") || e.endsWith(".") || e.includes("..")) throw new
|
|
1609
|
+
function jn(e) {
|
|
1610
|
+
if (e.length === 0) throw new E("index keyPath strings must be non-empty");
|
|
1611
|
+
if (e.startsWith(".") || e.endsWith(".") || e.includes("..")) throw new E(`invalid index keyPath: ${e}`);
|
|
1623
1612
|
}
|
|
1624
|
-
function
|
|
1613
|
+
function Mn(e) {
|
|
1625
1614
|
return e.compound ? `[${e.keyPath.join(",")}]` : e.keyPath[0];
|
|
1626
1615
|
}
|
|
1627
|
-
function
|
|
1628
|
-
let n = `${
|
|
1629
|
-
return
|
|
1616
|
+
function Nn(e, t) {
|
|
1617
|
+
let n = `${un}${Pn(j(e))}:${Pn(j(t))}`;
|
|
1618
|
+
return j(n).length <= 255 ? n : `${un}h:${Fn(j(`${e}\u0000${t}`))}`;
|
|
1630
1619
|
}
|
|
1631
|
-
function
|
|
1620
|
+
function Pn(e) {
|
|
1632
1621
|
let t = "";
|
|
1633
1622
|
for (let n of e) t += String.fromCharCode(n);
|
|
1634
1623
|
return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/u, "");
|
|
1635
1624
|
}
|
|
1636
|
-
function
|
|
1637
|
-
let t =
|
|
1638
|
-
for (let n of e) t ^= BigInt(n), t = t *
|
|
1625
|
+
function Fn(e) {
|
|
1626
|
+
let t = on;
|
|
1627
|
+
for (let n of e) t ^= BigInt(n), t = t * sn & cn;
|
|
1639
1628
|
return t.toString(16).padStart(16, "0");
|
|
1640
1629
|
}
|
|
1641
|
-
function
|
|
1630
|
+
function In(e) {
|
|
1642
1631
|
try {
|
|
1643
|
-
return JSON.parse(
|
|
1632
|
+
return JSON.parse(rn.decode(e));
|
|
1644
1633
|
} catch (e) {
|
|
1645
|
-
throw new
|
|
1634
|
+
throw new T(`indexed values must be valid UTF-8 JSON: ${String(e)}`);
|
|
1646
1635
|
}
|
|
1647
1636
|
}
|
|
1648
|
-
function
|
|
1637
|
+
function Ln(e, t) {
|
|
1649
1638
|
let n = e;
|
|
1650
1639
|
for (let e of t.split(".")) {
|
|
1651
|
-
if (typeof n != "object" || !n || !Object.hasOwn(n, e)) return
|
|
1640
|
+
if (typeof n != "object" || !n || !Object.hasOwn(n, e)) return an;
|
|
1652
1641
|
n = Reflect.get(n, e);
|
|
1653
1642
|
}
|
|
1654
1643
|
return n;
|
|
1655
1644
|
}
|
|
1656
|
-
function
|
|
1645
|
+
function Rn(e) {
|
|
1657
1646
|
if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e instanceof Uint8Array) try {
|
|
1658
1647
|
return P(e);
|
|
1659
1648
|
} catch (e) {
|
|
1660
|
-
throw e instanceof TypeError ? new
|
|
1649
|
+
throw e instanceof TypeError ? new T(`invalid indexed keyPath value: ${e.message}`) : e;
|
|
1661
1650
|
}
|
|
1662
|
-
throw new
|
|
1651
|
+
throw new T(`indexed keyPath values must resolve to string, number, boolean, null, or Uint8Array; got ${zn(e)}`);
|
|
1663
1652
|
}
|
|
1664
|
-
function
|
|
1653
|
+
function zn(e) {
|
|
1665
1654
|
return Array.isArray(e) ? "array" : typeof e;
|
|
1666
1655
|
}
|
|
1667
|
-
function
|
|
1656
|
+
function Bn(e) {
|
|
1668
1657
|
if (e.gt !== void 0 && e.gte !== void 0) throw TypeError("index range cannot specify both gt and gte");
|
|
1669
1658
|
if (e.lt !== void 0 && e.lte !== void 0) throw TypeError("index range cannot specify both lt and lte");
|
|
1670
1659
|
}
|
|
1671
1660
|
//#endregion
|
|
1672
1661
|
//#region src/change-events.ts
|
|
1673
|
-
function
|
|
1662
|
+
function Vn(t) {
|
|
1674
1663
|
return !e(t) || !(t.key instanceof Uint8Array) ? !1 : t.kind === "put" || t.kind === "delete" || (t.kind === "clear" || t.kind === "drop") && t.key.byteLength === 0;
|
|
1675
1664
|
}
|
|
1676
|
-
function
|
|
1677
|
-
return e(t) && typeof t.store == "string" && Array.isArray(t.changes) && t.changes.every(
|
|
1665
|
+
function Hn(t) {
|
|
1666
|
+
return e(t) && typeof t.store == "string" && Array.isArray(t.changes) && t.changes.every(Vn);
|
|
1678
1667
|
}
|
|
1679
|
-
function
|
|
1680
|
-
return e(t) && t.type === "commit_applied" && typeof t.dbName == "string" && typeof t.txid == "number" && Array.isArray(t.stores) && t.stores.every(
|
|
1668
|
+
function Un(t) {
|
|
1669
|
+
return e(t) && t.type === "commit_applied" && typeof t.dbName == "string" && typeof t.txid == "number" && Array.isArray(t.stores) && t.stores.every(Hn);
|
|
1681
1670
|
}
|
|
1682
1671
|
//#endregion
|
|
1683
1672
|
//#region src/subscriptions.ts
|
|
1684
|
-
function
|
|
1673
|
+
function Wn(e) {
|
|
1685
1674
|
return e.map((e) => ({
|
|
1686
1675
|
key: e.key.slice(),
|
|
1687
1676
|
kind: e.kind
|
|
1688
1677
|
}));
|
|
1689
1678
|
}
|
|
1690
|
-
function
|
|
1679
|
+
function Gn(e, t) {
|
|
1691
1680
|
if (t.byteLength > e.byteLength) return !1;
|
|
1692
1681
|
for (let n = 0; n < t.byteLength; n += 1) if (e[n] !== t[n]) return !1;
|
|
1693
1682
|
return !0;
|
|
1694
1683
|
}
|
|
1695
|
-
function
|
|
1684
|
+
function Kn(e, t, n) {
|
|
1696
1685
|
if (typeof e == "function") {
|
|
1697
1686
|
if (t !== void 0 || n !== void 0) throw TypeError("subscribe(callback) accepts exactly one callback argument");
|
|
1698
1687
|
return {
|
|
@@ -1717,7 +1706,7 @@ function Yn(e, t, n) {
|
|
|
1717
1706
|
};
|
|
1718
1707
|
throw TypeError("subscribe() expects one of: (callback), (storeName, callback), (storeName, keyPrefix, callback)");
|
|
1719
1708
|
}
|
|
1720
|
-
var
|
|
1709
|
+
var qn = class {
|
|
1721
1710
|
#e;
|
|
1722
1711
|
#t;
|
|
1723
1712
|
#n = null;
|
|
@@ -1727,8 +1716,8 @@ var Xn = class {
|
|
|
1727
1716
|
this.#e = e, this.#t = t;
|
|
1728
1717
|
}
|
|
1729
1718
|
subscribe(e, t, n) {
|
|
1730
|
-
if (this.#i) throw new
|
|
1731
|
-
let r =
|
|
1719
|
+
if (this.#i) throw new w();
|
|
1720
|
+
let r = Kn(e, t, n), i = {
|
|
1732
1721
|
active: !0,
|
|
1733
1722
|
store: r.store,
|
|
1734
1723
|
keyPrefix: r.keyPrefix,
|
|
@@ -1756,13 +1745,13 @@ var Xn = class {
|
|
|
1756
1745
|
this.#n?.close(), this.#n = null;
|
|
1757
1746
|
}
|
|
1758
1747
|
#s(e) {
|
|
1759
|
-
if (!
|
|
1748
|
+
if (!Un(e) || e.dbName !== this.#e || this.#r.size === 0) return;
|
|
1760
1749
|
let t = Array.from(this.#r);
|
|
1761
1750
|
for (let n of e.stores) for (let r of t) {
|
|
1762
1751
|
if (!r.active || r.store !== null && r.store !== n.store) continue;
|
|
1763
1752
|
let t, i = r.keyPrefix;
|
|
1764
|
-
if (i === null) t =
|
|
1765
|
-
else if (t =
|
|
1753
|
+
if (i === null) t = Wn(n.changes);
|
|
1754
|
+
else if (t = Wn(n.changes.filter((e) => e.kind === "clear" || e.kind === "drop" || Gn(e.key, i))), t.length === 0) continue;
|
|
1766
1755
|
try {
|
|
1767
1756
|
r.callback(n.store, t, e.txid);
|
|
1768
1757
|
} catch (e) {
|
|
@@ -1772,11 +1761,11 @@ var Xn = class {
|
|
|
1772
1761
|
}
|
|
1773
1762
|
}
|
|
1774
1763
|
}
|
|
1775
|
-
},
|
|
1776
|
-
function
|
|
1764
|
+
}, Jn = new TextDecoder("utf-8", { fatal: !0 }), Yn = (1n << 64n) - 1n, Xn = 1n << 63n;
|
|
1765
|
+
function Zn(e, t) {
|
|
1777
1766
|
return e.length === t.length && e.every((e, n) => e === t[n]);
|
|
1778
1767
|
}
|
|
1779
|
-
function
|
|
1768
|
+
function Qn(e) {
|
|
1780
1769
|
if (!(e instanceof Uint8Array) || e.length === 0) throw TypeError("invalid scalar key encoding");
|
|
1781
1770
|
let t;
|
|
1782
1771
|
switch (e[0]) {
|
|
@@ -1791,24 +1780,24 @@ function tr(e) {
|
|
|
1791
1780
|
break;
|
|
1792
1781
|
case 48: {
|
|
1793
1782
|
if (e.length !== 9) throw TypeError("invalid number key encoding");
|
|
1794
|
-
let n = new DataView(e.buffer, e.byteOffset + 1, 8).getBigUint64(0, !1), r = (n &
|
|
1783
|
+
let n = new DataView(e.buffer, e.byteOffset + 1, 8).getBigUint64(0, !1), r = (n & Xn) === 0n ? n ^ Yn : n ^ Xn, i = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
|
|
1795
1784
|
i.setBigUint64(0, r, !1), t = i.getFloat64(0, !1);
|
|
1796
1785
|
break;
|
|
1797
1786
|
}
|
|
1798
1787
|
case 64:
|
|
1799
|
-
t =
|
|
1788
|
+
t = Jn.decode(e.subarray(1));
|
|
1800
1789
|
break;
|
|
1801
1790
|
case 80:
|
|
1802
1791
|
t = e.slice(1);
|
|
1803
1792
|
break;
|
|
1804
1793
|
default: throw TypeError("invalid scalar key type");
|
|
1805
1794
|
}
|
|
1806
|
-
if (!
|
|
1795
|
+
if (!Zn(P(t), e)) throw TypeError("noncanonical scalar key encoding");
|
|
1807
1796
|
return t;
|
|
1808
1797
|
}
|
|
1809
|
-
var
|
|
1798
|
+
var $n = Object.freeze({
|
|
1810
1799
|
encode: P,
|
|
1811
|
-
decode:
|
|
1800
|
+
decode: Qn
|
|
1812
1801
|
});
|
|
1813
1802
|
function z(e, t) {
|
|
1814
1803
|
function n(n) {
|
|
@@ -1820,31 +1809,31 @@ function z(e, t) {
|
|
|
1820
1809
|
return P(n(e));
|
|
1821
1810
|
},
|
|
1822
1811
|
decode(e) {
|
|
1823
|
-
return n(
|
|
1812
|
+
return n(Qn(e));
|
|
1824
1813
|
}
|
|
1825
1814
|
});
|
|
1826
1815
|
}
|
|
1827
|
-
var
|
|
1816
|
+
var er = Object.freeze({
|
|
1828
1817
|
string: z("a string", (e) => typeof e == "string"),
|
|
1829
1818
|
number: z("a finite number", (e) => typeof e == "number"),
|
|
1830
1819
|
boolean: z("a boolean", (e) => typeof e == "boolean"),
|
|
1831
1820
|
null: z("null", (e) => e === null),
|
|
1832
1821
|
bytes: z("Uint8Array", (e) => e instanceof Uint8Array)
|
|
1833
1822
|
});
|
|
1834
|
-
function
|
|
1823
|
+
function tr(...e) {
|
|
1835
1824
|
return Object.freeze({
|
|
1836
1825
|
encode(t) {
|
|
1837
1826
|
if (!Array.isArray(t) || t.length !== e.length) throw TypeError(`compound key must contain ${e.length} parts`);
|
|
1838
1827
|
return F(e.map((e, n) => e.encode(t[n])));
|
|
1839
1828
|
},
|
|
1840
1829
|
decode(t) {
|
|
1841
|
-
let n =
|
|
1830
|
+
let n = Xt(t);
|
|
1842
1831
|
if (n.length !== e.length) throw TypeError(`compound key must contain ${e.length} parts`);
|
|
1843
1832
|
return e.map((e, t) => e.decode(n[t]));
|
|
1844
1833
|
}
|
|
1845
1834
|
});
|
|
1846
1835
|
}
|
|
1847
|
-
function
|
|
1836
|
+
function nr(e) {
|
|
1848
1837
|
let t = [{ value: e }], n = /* @__PURE__ */ new Set();
|
|
1849
1838
|
for (; t.length > 0;) {
|
|
1850
1839
|
let e = t.pop(), r = e.value;
|
|
@@ -1872,11 +1861,11 @@ function ar(e) {
|
|
|
1872
1861
|
}
|
|
1873
1862
|
}
|
|
1874
1863
|
}
|
|
1875
|
-
function
|
|
1864
|
+
function rr(e) {
|
|
1876
1865
|
function t(t) {
|
|
1877
|
-
if (
|
|
1866
|
+
if (nr(t), e) {
|
|
1878
1867
|
if (!e(t)) throw TypeError("record does not match its schema");
|
|
1879
|
-
|
|
1868
|
+
nr(t);
|
|
1880
1869
|
}
|
|
1881
1870
|
return t;
|
|
1882
1871
|
}
|
|
@@ -1885,11 +1874,11 @@ function or(e) {
|
|
|
1885
1874
|
return M(t(e));
|
|
1886
1875
|
},
|
|
1887
1876
|
decode(e) {
|
|
1888
|
-
return t(
|
|
1877
|
+
return t(Kt(e));
|
|
1889
1878
|
}
|
|
1890
1879
|
});
|
|
1891
1880
|
}
|
|
1892
|
-
function
|
|
1881
|
+
function ir(e, t) {
|
|
1893
1882
|
let n = {};
|
|
1894
1883
|
for (let r of [
|
|
1895
1884
|
"gt",
|
|
@@ -1899,7 +1888,7 @@ function sr(e, t) {
|
|
|
1899
1888
|
]) Object.hasOwn(t, r) && (n[r] = e.encode(t[r]));
|
|
1900
1889
|
return t.reverse !== void 0 && (n.reverse = t.reverse), t.limit !== void 0 && (n.limit = t.limit), n;
|
|
1901
1890
|
}
|
|
1902
|
-
async function
|
|
1891
|
+
async function ar(e, t, n) {
|
|
1903
1892
|
let r = await e.begin(t), i;
|
|
1904
1893
|
try {
|
|
1905
1894
|
i = await n(r);
|
|
@@ -1907,16 +1896,16 @@ async function cr(e, t, n) {
|
|
|
1907
1896
|
try {
|
|
1908
1897
|
await r.rollback();
|
|
1909
1898
|
} catch (t) {
|
|
1910
|
-
if (!(t instanceof
|
|
1899
|
+
if (!(t instanceof C)) throw AggregateError([e, t], "record transaction and rollback failed", { cause: t });
|
|
1911
1900
|
}
|
|
1912
1901
|
throw e;
|
|
1913
1902
|
}
|
|
1914
1903
|
return t === "readwrite" ? await r.commit() : await r.rollback(), i;
|
|
1915
1904
|
}
|
|
1916
1905
|
function B(e, t, n) {
|
|
1917
|
-
return "begin" in e ?
|
|
1906
|
+
return "begin" in e ? ar(e, t, n) : n(e);
|
|
1918
1907
|
}
|
|
1919
|
-
var
|
|
1908
|
+
var or = class {
|
|
1920
1909
|
name;
|
|
1921
1910
|
#e;
|
|
1922
1911
|
#t;
|
|
@@ -1933,7 +1922,7 @@ var lr = class {
|
|
|
1933
1922
|
});
|
|
1934
1923
|
}
|
|
1935
1924
|
async scan(e = {}) {
|
|
1936
|
-
let t =
|
|
1925
|
+
let t = ir(this.#n, e);
|
|
1937
1926
|
return B(this.#e, "readonly", async (e) => {
|
|
1938
1927
|
let n = [];
|
|
1939
1928
|
for await (let [r, i] of e.scanByIndex(this.#t, this.name, t)) n.push({
|
|
@@ -1943,7 +1932,7 @@ var lr = class {
|
|
|
1943
1932
|
return n;
|
|
1944
1933
|
});
|
|
1945
1934
|
}
|
|
1946
|
-
},
|
|
1935
|
+
}, sr = class e {
|
|
1947
1936
|
name;
|
|
1948
1937
|
#e;
|
|
1949
1938
|
#t;
|
|
@@ -1991,7 +1980,7 @@ var lr = class {
|
|
|
1991
1980
|
await B(this.#e, "readwrite", (e) => e.applyBatch(this.name, t));
|
|
1992
1981
|
}
|
|
1993
1982
|
async scan(e = {}) {
|
|
1994
|
-
return (await this.#e.scan(this.name,
|
|
1983
|
+
return (await this.#e.scan(this.name, ir(this.#t.key, e))).map(({ key: e, value: t }) => ({
|
|
1995
1984
|
key: this.#t.key.decode(e),
|
|
1996
1985
|
value: this.#t.value.decode(t)
|
|
1997
1986
|
}));
|
|
@@ -2000,31 +1989,31 @@ var lr = class {
|
|
|
2000
1989
|
await this.#e.clearStore(this.name);
|
|
2001
1990
|
}
|
|
2002
1991
|
index(e, t) {
|
|
2003
|
-
return new
|
|
1992
|
+
return new or(this.#e, this.name, e, t, this.#t);
|
|
2004
1993
|
}
|
|
2005
1994
|
transaction(t, n) {
|
|
2006
|
-
return "begin" in this.#e ?
|
|
1995
|
+
return "begin" in this.#e ? ar(this.#e, t, (t) => n(new e(t, this.name, this.#t), t)) : Promise.reject(/* @__PURE__ */ TypeError("record store already belongs to a transaction"));
|
|
2007
1996
|
}
|
|
2008
1997
|
};
|
|
2009
|
-
function
|
|
2010
|
-
return new
|
|
1998
|
+
function cr(e, t, n) {
|
|
1999
|
+
return new sr(e, t, n);
|
|
2011
2000
|
}
|
|
2012
|
-
async function
|
|
2013
|
-
return await e.createStore(t, r),
|
|
2001
|
+
async function lr(e, t, n, r) {
|
|
2002
|
+
return await e.createStore(t, r), cr(e, t, n);
|
|
2014
2003
|
}
|
|
2015
2004
|
//#endregion
|
|
2016
2005
|
//#region src/sql-types.ts
|
|
2017
|
-
var
|
|
2006
|
+
var ur = -(1n << 63n), dr = (1n << 63n) - 1n, fr = 1048576, pr = 16384, mr = 64, hr = 128, gr = 128, _r = 1024, vr = /* @__PURE__ */ new Set([
|
|
2018
2007
|
"__proto__",
|
|
2019
2008
|
"prototype",
|
|
2020
2009
|
"constructor"
|
|
2021
|
-
]),
|
|
2010
|
+
]), yr = /* @__PURE__ */ new Set([
|
|
2022
2011
|
"INTEGER",
|
|
2023
2012
|
"REAL",
|
|
2024
2013
|
"TEXT",
|
|
2025
2014
|
"BOOLEAN",
|
|
2026
2015
|
"BLOB"
|
|
2027
|
-
]),
|
|
2016
|
+
]), br = /* @__PURE__ */ new Set([
|
|
2028
2017
|
"CREATE",
|
|
2029
2018
|
"TABLE",
|
|
2030
2019
|
"IF",
|
|
@@ -2079,33 +2068,33 @@ var pr = -(1n << 63n), mr = (1n << 63n) - 1n, hr = 1048576, gr = 16384, _r = 64,
|
|
|
2079
2068
|
"AUTOINCREMENT",
|
|
2080
2069
|
"RETURNING",
|
|
2081
2070
|
"CONFLICT",
|
|
2082
|
-
...
|
|
2071
|
+
...yr
|
|
2083
2072
|
]), V = class extends SyntaxError {
|
|
2084
2073
|
position;
|
|
2085
2074
|
constructor(e, t) {
|
|
2086
2075
|
super(`${e} at position ${t}`), this.name = "SqlSyntaxError", this.position = t;
|
|
2087
2076
|
}
|
|
2088
2077
|
};
|
|
2089
|
-
function
|
|
2078
|
+
function xr(e) {
|
|
2090
2079
|
if (typeof e != "string") throw TypeError("SQL must be a string");
|
|
2091
|
-
if (e.length >
|
|
2092
|
-
return new
|
|
2080
|
+
if (e.length > fr) throw new V(`SQL exceeds ${fr} characters`, fr);
|
|
2081
|
+
return new Cr(wr(e)).parse();
|
|
2093
2082
|
}
|
|
2094
|
-
function
|
|
2083
|
+
function Sr(e, t = []) {
|
|
2095
2084
|
if (!Array.isArray(t)) throw TypeError("SQL parameters must be an array");
|
|
2096
2085
|
if (t.length !== e.parameterCount) throw RangeError(`SQL expects ${e.parameterCount} parameters; received ${t.length}`);
|
|
2097
2086
|
return Array.from(t, (e, t) => {
|
|
2098
2087
|
if (e === null || typeof e == "boolean") return e;
|
|
2099
2088
|
if (typeof e == "number") {
|
|
2100
|
-
if (!Number.isFinite(e) || Number.isInteger(e) && !Number.isSafeInteger(e) &&
|
|
2089
|
+
if (!Number.isFinite(e) || Number.isInteger(e) && !Number.isSafeInteger(e) && Tr(e)) throw RangeError(`SQL parameter ${t + 1} must be finite; use bigint for integers outside the safe range`);
|
|
2101
2090
|
return e;
|
|
2102
2091
|
}
|
|
2103
2092
|
if (typeof e == "bigint") {
|
|
2104
|
-
if (e <
|
|
2093
|
+
if (e < ur || e > dr) throw RangeError(`SQL parameter ${t + 1} exceeds the signed 64-bit integer range`);
|
|
2105
2094
|
return e;
|
|
2106
2095
|
}
|
|
2107
2096
|
if (typeof e == "string") {
|
|
2108
|
-
if (!
|
|
2097
|
+
if (!Dr(e)) throw TypeError(`SQL parameter ${t + 1} must contain valid Unicode scalar values`);
|
|
2109
2098
|
return e;
|
|
2110
2099
|
}
|
|
2111
2100
|
if (e instanceof Uint8Array) return Uint8Array.from(e);
|
|
@@ -2119,7 +2108,7 @@ function H(e, t) {
|
|
|
2119
2108
|
if (n === void 0) throw RangeError(`SQL parameter ${e.index + 1} is missing`);
|
|
2120
2109
|
return n;
|
|
2121
2110
|
}
|
|
2122
|
-
var
|
|
2111
|
+
var Cr = class {
|
|
2123
2112
|
#e;
|
|
2124
2113
|
#t = 0;
|
|
2125
2114
|
#n = 0;
|
|
@@ -2156,7 +2145,7 @@ var Er = class {
|
|
|
2156
2145
|
let e = this.#y();
|
|
2157
2146
|
this.#b(r, e, "column");
|
|
2158
2147
|
let t = this.#x(), a = t.text.toUpperCase();
|
|
2159
|
-
if (t.kind !== "word" || !
|
|
2148
|
+
if (t.kind !== "word" || !yr.has(a)) throw this.#E("Expected INTEGER, REAL, TEXT, BOOLEAN, or BLOB column type");
|
|
2160
2149
|
this.#t += 1;
|
|
2161
2150
|
let o = !1, s = !0, c = !1;
|
|
2162
2151
|
for (;;) if (this.#S("PRIMARY")) {
|
|
@@ -2288,11 +2277,11 @@ var Er = class {
|
|
|
2288
2277
|
}
|
|
2289
2278
|
#h() {
|
|
2290
2279
|
if (this.#w("(")) {
|
|
2291
|
-
if (this.#r += 1, this.#r >
|
|
2280
|
+
if (this.#r += 1, this.#r > mr) throw this.#E(`WHERE nesting exceeds ${mr}`);
|
|
2292
2281
|
let e = this.#p();
|
|
2293
2282
|
return this.#T(")"), --this.#r, e;
|
|
2294
2283
|
}
|
|
2295
|
-
if (this.#i += 1, this.#i >
|
|
2284
|
+
if (this.#i += 1, this.#i > hr) throw this.#E(`WHERE predicates exceed ${hr}`);
|
|
2296
2285
|
let e = this.#y();
|
|
2297
2286
|
if (this.#S("IS")) {
|
|
2298
2287
|
let t = this.#S("NOT");
|
|
@@ -2349,7 +2338,7 @@ var Er = class {
|
|
|
2349
2338
|
let t = this.#w("-") ? "-" : this.#w("+") ? "+" : "", n = this.#x();
|
|
2350
2339
|
if (n.kind === "number") return this.#t += 1, {
|
|
2351
2340
|
kind: "literal",
|
|
2352
|
-
value:
|
|
2341
|
+
value: Er(t + n.text, e.position)
|
|
2353
2342
|
};
|
|
2354
2343
|
throw this.#E("Expected a scalar literal or positional ? parameter");
|
|
2355
2344
|
}
|
|
@@ -2363,8 +2352,8 @@ var Er = class {
|
|
|
2363
2352
|
}
|
|
2364
2353
|
#y() {
|
|
2365
2354
|
let e = this.#x();
|
|
2366
|
-
if (e.kind !== "identifier" && (e.kind !== "word" ||
|
|
2367
|
-
if (e.text.length === 0 || e.text.length >
|
|
2355
|
+
if (e.kind !== "identifier" && (e.kind !== "word" || br.has(e.text.toUpperCase()))) throw this.#E("Expected an identifier; use double quotes for keywords");
|
|
2356
|
+
if (e.text.length === 0 || e.text.length > gr || Or(e.text) || vr.has(e.text.toLowerCase()) || !Dr(e.text)) throw this.#E("Invalid or reserved identifier");
|
|
2368
2357
|
return this.#t += 1, e.text;
|
|
2369
2358
|
}
|
|
2370
2359
|
#b(e, t, n) {
|
|
@@ -2392,7 +2381,7 @@ var Er = class {
|
|
|
2392
2381
|
return new V(e, this.#x().position);
|
|
2393
2382
|
}
|
|
2394
2383
|
};
|
|
2395
|
-
function
|
|
2384
|
+
function wr(e) {
|
|
2396
2385
|
let t = [], n = 0;
|
|
2397
2386
|
for (; n < e.length;) {
|
|
2398
2387
|
let r = e[n];
|
|
@@ -2410,7 +2399,7 @@ function Dr(e) {
|
|
|
2410
2399
|
n = t + 2;
|
|
2411
2400
|
continue;
|
|
2412
2401
|
}
|
|
2413
|
-
if (t.length >=
|
|
2402
|
+
if (t.length >= pr) throw new V(`SQL token count exceeds ${pr}`, n);
|
|
2414
2403
|
let i = n;
|
|
2415
2404
|
if (r === "'" || r === "\"") {
|
|
2416
2405
|
let a = r, o = "", s = !1;
|
|
@@ -2422,7 +2411,7 @@ function Dr(e) {
|
|
|
2422
2411
|
}
|
|
2423
2412
|
} else o += e[n++];
|
|
2424
2413
|
if (!s) throw new V("Unterminated quoted token", i);
|
|
2425
|
-
if (!
|
|
2414
|
+
if (!Dr(o)) throw new V("Quoted token must contain valid Unicode scalar values", i);
|
|
2426
2415
|
t.push({
|
|
2427
2416
|
kind: a === "'" ? "string" : "identifier",
|
|
2428
2417
|
text: o,
|
|
@@ -2445,7 +2434,7 @@ function Dr(e) {
|
|
|
2445
2434
|
if (n === t) throw new V("Invalid numeric exponent", i);
|
|
2446
2435
|
}
|
|
2447
2436
|
let a = e.slice(i, n);
|
|
2448
|
-
if (a.length >
|
|
2437
|
+
if (a.length > _r) throw new V(`Numeric literal exceeds ${_r} characters`, i);
|
|
2449
2438
|
t.push({
|
|
2450
2439
|
kind: "number",
|
|
2451
2440
|
text: a,
|
|
@@ -2482,19 +2471,19 @@ function Dr(e) {
|
|
|
2482
2471
|
position: e.length
|
|
2483
2472
|
}), t;
|
|
2484
2473
|
}
|
|
2485
|
-
function
|
|
2474
|
+
function Tr(e) {
|
|
2486
2475
|
if (!Number.isInteger(e)) return !1;
|
|
2487
2476
|
let t = BigInt(e);
|
|
2488
|
-
return t >=
|
|
2477
|
+
return t >= ur && t <= dr;
|
|
2489
2478
|
}
|
|
2490
|
-
function
|
|
2479
|
+
function Er(e, t) {
|
|
2491
2480
|
if (/^[+-]?\d+$/u.test(e)) {
|
|
2492
2481
|
let n = BigInt(e);
|
|
2493
|
-
if (n <
|
|
2482
|
+
if (n < ur || n > dr) throw new V("Integer literal exceeds the signed 64-bit range", t);
|
|
2494
2483
|
return n >= BigInt(-(2 ** 53 - 1)) && n <= BigInt(2 ** 53 - 1) ? Number(n) : n;
|
|
2495
2484
|
}
|
|
2496
2485
|
let n = Number(e);
|
|
2497
|
-
if (!Number.isFinite(n) || Number.isInteger(n) && !Number.isSafeInteger(n) &&
|
|
2486
|
+
if (!Number.isFinite(n) || Number.isInteger(n) && !Number.isSafeInteger(n) && Tr(n)) throw new V("REAL literal must be finite; use integer notation for large integers", t);
|
|
2498
2487
|
let [r, i = "0"] = e.toLowerCase().split("e"), a = r.replace(/[+.-]/gu, ""), o = /[1-9]/u.test(a);
|
|
2499
2488
|
if (n === 0 && o) throw new V("REAL literal underflows to zero", t);
|
|
2500
2489
|
if (Number.isInteger(n) && o) {
|
|
@@ -2503,14 +2492,14 @@ function kr(e, t) {
|
|
|
2503
2492
|
}
|
|
2504
2493
|
return n;
|
|
2505
2494
|
}
|
|
2506
|
-
function
|
|
2495
|
+
function Dr(e) {
|
|
2507
2496
|
for (let t of e) {
|
|
2508
2497
|
let e = t.codePointAt(0);
|
|
2509
2498
|
if (e >= 55296 && e <= 57343) return !1;
|
|
2510
2499
|
}
|
|
2511
2500
|
return !0;
|
|
2512
2501
|
}
|
|
2513
|
-
function
|
|
2502
|
+
function Or(e) {
|
|
2514
2503
|
for (let t of e) {
|
|
2515
2504
|
let e = t.codePointAt(0);
|
|
2516
2505
|
if (e < 32 || e === 127) return !0;
|
|
@@ -2519,10 +2508,10 @@ function jr(e) {
|
|
|
2519
2508
|
}
|
|
2520
2509
|
//#endregion
|
|
2521
2510
|
//#region src/sql.ts
|
|
2522
|
-
var U = "_moyodb_sql_catalog",
|
|
2511
|
+
var U = "_moyodb_sql_catalog", kr = Uint8Array.of(0), Ar = {
|
|
2523
2512
|
format: "moyodb.sql",
|
|
2524
2513
|
version: 1
|
|
2525
|
-
},
|
|
2514
|
+
}, jr = Uint8Array.of(255), Mr = "\0moyodb.sql.table", Nr = -(1n << 63n), Pr = (1n << 63n) - 1n, Fr = (1n << 64n) - 1n, Ir = /* @__PURE__ */ new Set([
|
|
2526
2515
|
"INTEGER",
|
|
2527
2516
|
"REAL",
|
|
2528
2517
|
"TEXT",
|
|
@@ -2537,15 +2526,15 @@ var U = "_moyodb_sql_catalog", Mr = Uint8Array.of(0), Nr = {
|
|
|
2537
2526
|
super(e), this.name = "SqlTypeError";
|
|
2538
2527
|
}
|
|
2539
2528
|
};
|
|
2540
|
-
function
|
|
2529
|
+
function Lr(e, t = {}) {
|
|
2541
2530
|
let n = t.indexes === void 0 ? null : L(t.indexes), r = async (t, r, i) => {
|
|
2542
|
-
let a =
|
|
2543
|
-
if (i && !
|
|
2531
|
+
let a = xr(t), o = Sr(a, r), s = a.statement;
|
|
2532
|
+
if (i && !ui(s)) throw new W("EXPLAIN requires SELECT, UPDATE, or DELETE");
|
|
2544
2533
|
let c = await e.begin(s.kind === "select" || i ? "readonly" : "readwrite"), l = !1;
|
|
2545
2534
|
try {
|
|
2546
2535
|
let e = L(await c.listIndexes?.() ?? []);
|
|
2547
2536
|
if (n && R(n) !== R(e)) throw new W("SQL index definitions do not match the transaction catalog");
|
|
2548
|
-
let t = await
|
|
2537
|
+
let t = await Rr(c, s, o, e, i);
|
|
2549
2538
|
return l = !0, c.mode === "readwrite" ? await c.commit() : await c.rollback(), t;
|
|
2550
2539
|
} catch (e) {
|
|
2551
2540
|
if (!l) try {
|
|
@@ -2559,7 +2548,7 @@ function Br(e, t = {}) {
|
|
|
2559
2548
|
return {
|
|
2560
2549
|
execute: (e, t = []) => r(e, t, !1),
|
|
2561
2550
|
async query(e, t = []) {
|
|
2562
|
-
if (
|
|
2551
|
+
if (xr(e).statement.kind !== "select") throw new W("query() requires SELECT");
|
|
2563
2552
|
return (await r(e, t, !1)).rows;
|
|
2564
2553
|
},
|
|
2565
2554
|
async explain(e, t = []) {
|
|
@@ -2569,10 +2558,10 @@ function Br(e, t = {}) {
|
|
|
2569
2558
|
}
|
|
2570
2559
|
};
|
|
2571
2560
|
}
|
|
2572
|
-
async function
|
|
2573
|
-
|
|
2574
|
-
let a = await
|
|
2575
|
-
if (o && await
|
|
2561
|
+
async function Rr(e, t, n, r, i) {
|
|
2562
|
+
li(t.table);
|
|
2563
|
+
let a = await zr(e), o = a ? await Br(e, t.table) : null;
|
|
2564
|
+
if (o && await Vr(e, o), t.kind === "createTable") {
|
|
2576
2565
|
if (o) {
|
|
2577
2566
|
if (t.ifNotExists) return {
|
|
2578
2567
|
rows: [],
|
|
@@ -2586,7 +2575,7 @@ async function Vr(e, t, n, r, i) {
|
|
|
2586
2575
|
columns: t.columns,
|
|
2587
2576
|
nextRowId: "1"
|
|
2588
2577
|
};
|
|
2589
|
-
return
|
|
2578
|
+
return Ur(n, t.table), a || (await e.createStore(U), await e.put(U, kr, M(Ar))), await e.createStore(t.table), await e.put(t.table, jr, Hr(n)), await e.put(U, ci(t.table), M(n)), {
|
|
2590
2579
|
rows: [],
|
|
2591
2580
|
rowsAffected: 0
|
|
2592
2581
|
};
|
|
@@ -2598,28 +2587,28 @@ async function Vr(e, t, n, r, i) {
|
|
|
2598
2587
|
};
|
|
2599
2588
|
throw new W(`table does not exist: ${t.table}`);
|
|
2600
2589
|
}
|
|
2601
|
-
if (t.kind === "dropTable") return await e.dropStore(t.table), await e.delete(U,
|
|
2590
|
+
if (t.kind === "dropTable") return await e.dropStore(t.table), await e.delete(U, ci(t.table)), {
|
|
2602
2591
|
rows: [],
|
|
2603
2592
|
rowsAffected: 0
|
|
2604
2593
|
};
|
|
2605
|
-
if (t.kind === "insert") return
|
|
2606
|
-
if (
|
|
2607
|
-
|
|
2594
|
+
if (t.kind === "insert") return Wr(e, o, t, n);
|
|
2595
|
+
if (Jr(o, t.where, n), t.kind === "select") {
|
|
2596
|
+
si(o, t.columns);
|
|
2608
2597
|
for (let e of t.orderBy) J(o, e.column);
|
|
2609
2598
|
}
|
|
2610
2599
|
if (t.kind === "update") {
|
|
2611
|
-
|
|
2600
|
+
si(o, t.assignments.map((e) => e.column));
|
|
2612
2601
|
for (let e of t.assignments) K(J(o, e.column), H(e.value, n));
|
|
2613
2602
|
}
|
|
2614
|
-
let s = t.kind === "select" ? t.orderBy : [], c =
|
|
2603
|
+
let s = t.kind === "select" ? t.orderBy : [], c = Xr(o, t.where, s, n, r), l = t.kind === "select" ? ai(t.limit, n, "LIMIT") : null, u = t.kind === "select" ? ai(t.offset, n, "OFFSET") ?? 0 : 0;
|
|
2615
2604
|
if (i) return {
|
|
2616
2605
|
rows: [],
|
|
2617
2606
|
rowsAffected: 0,
|
|
2618
2607
|
plan: c.public
|
|
2619
2608
|
};
|
|
2620
|
-
let d = t.kind === "select" && c.public.sort === "none" && l !== null ? Math.min(2 ** 53 - 1, u + l) : void 0, f = l === 0 ? [] : await
|
|
2621
|
-
if (t.kind === "select") return c.public.sort === "memory" && f.sort((e, t) =>
|
|
2622
|
-
rows: f.slice(u, l === null ? void 0 : u + l).map(({ row: e }) =>
|
|
2609
|
+
let d = t.kind === "select" && c.public.sort === "none" && l !== null ? Math.min(2 ** 53 - 1, u + l) : void 0, f = l === 0 ? [] : await ni(e, o, c, t.where, n, d);
|
|
2610
|
+
if (t.kind === "select") return c.public.sort === "memory" && f.sort((e, t) => ri(e, t, s)), {
|
|
2611
|
+
rows: f.slice(u, l === null ? void 0 : u + l).map(({ row: e }) => oi(e, t.columns ?? o.columns.map((e) => e.name))),
|
|
2623
2612
|
rowsAffected: 0,
|
|
2624
2613
|
plan: c.public
|
|
2625
2614
|
};
|
|
@@ -2637,67 +2626,67 @@ async function Vr(e, t, n, r, i) {
|
|
|
2637
2626
|
key: a ? q(a, i[a.name]) : e,
|
|
2638
2627
|
row: i
|
|
2639
2628
|
};
|
|
2640
|
-
}), ee = /* @__PURE__ */ new Set(), m = new Set(f.map(({ key: e }) =>
|
|
2629
|
+
}), ee = /* @__PURE__ */ new Set(), m = new Set(f.map(({ key: e }) => pi(e)));
|
|
2641
2630
|
for (let t of p) {
|
|
2642
|
-
let n =
|
|
2643
|
-
if (ee.has(n) || (ee.add(n), !m.has(n) && await e.has(o.table, t.key))) throw new
|
|
2631
|
+
let n = pi(t.key);
|
|
2632
|
+
if (ee.has(n) || (ee.add(n), !m.has(n) && await e.has(o.table, t.key))) throw new S(`duplicate primary key in ${o.table}`);
|
|
2644
2633
|
}
|
|
2645
2634
|
await e.deleteMany(o.table, p.map(({ oldKey: e }) => e));
|
|
2646
|
-
for (let t of p) await e.put(o.table, t.key,
|
|
2635
|
+
for (let t of p) await e.put(o.table, t.key, Gr(o, t.row));
|
|
2647
2636
|
return {
|
|
2648
2637
|
rows: [],
|
|
2649
2638
|
rowsAffected: p.length,
|
|
2650
2639
|
plan: c.public
|
|
2651
2640
|
};
|
|
2652
2641
|
}
|
|
2653
|
-
async function
|
|
2642
|
+
async function zr(e) {
|
|
2654
2643
|
let t;
|
|
2655
2644
|
try {
|
|
2656
|
-
t = await e.get(U,
|
|
2645
|
+
t = await e.get(U, kr);
|
|
2657
2646
|
} catch (e) {
|
|
2658
|
-
if (e instanceof
|
|
2647
|
+
if (e instanceof Fe || e instanceof Error && e.name === "StoreNotFoundError") return !1;
|
|
2659
2648
|
throw e;
|
|
2660
2649
|
}
|
|
2661
2650
|
if (!t) throw new W(`SQL catalog store is not owned by SQL: ${U}`);
|
|
2662
|
-
let n =
|
|
2663
|
-
if (!
|
|
2651
|
+
let n = fi(t);
|
|
2652
|
+
if (!di(n) || n.format !== Ar.format || n.version !== Ar.version) throw new W("invalid SQL catalog metadata");
|
|
2664
2653
|
return !0;
|
|
2665
2654
|
}
|
|
2666
|
-
async function
|
|
2667
|
-
let n = await e.get(U,
|
|
2655
|
+
async function Br(e, t) {
|
|
2656
|
+
let n = await e.get(U, ci(t));
|
|
2668
2657
|
if (!n) return null;
|
|
2669
|
-
let r =
|
|
2670
|
-
return
|
|
2658
|
+
let r = fi(n);
|
|
2659
|
+
return Ur(r, t), r;
|
|
2671
2660
|
}
|
|
2672
|
-
async function
|
|
2661
|
+
async function Vr(e, t) {
|
|
2673
2662
|
let n;
|
|
2674
2663
|
try {
|
|
2675
|
-
n = await e.get(t.table,
|
|
2664
|
+
n = await e.get(t.table, jr);
|
|
2676
2665
|
} catch (e) {
|
|
2677
|
-
throw e instanceof
|
|
2666
|
+
throw e instanceof Fe || e instanceof Error && e.name === "StoreNotFoundError" ? new W(`SQL table store is missing: ${t.table}`, { cause: e }) : e;
|
|
2678
2667
|
}
|
|
2679
|
-
if (!n || X(n,
|
|
2668
|
+
if (!n || X(n, Hr(t)) !== 0) throw new W(`SQL table ownership does not match its catalog: ${t.table}`);
|
|
2680
2669
|
}
|
|
2681
|
-
function
|
|
2682
|
-
return M({ [
|
|
2670
|
+
function Hr(e) {
|
|
2671
|
+
return M({ [Mr]: JSON.stringify({
|
|
2683
2672
|
format: "moyodb.sql.table",
|
|
2684
2673
|
version: e.version,
|
|
2685
2674
|
table: e.table,
|
|
2686
2675
|
columns: e.columns
|
|
2687
2676
|
}) });
|
|
2688
2677
|
}
|
|
2689
|
-
function
|
|
2690
|
-
if (!
|
|
2678
|
+
function Ur(e, t) {
|
|
2679
|
+
if (!di(e) || e.version !== 1 || e.table !== t || !Array.isArray(e.columns) || !e.columns.length || typeof e.nextRowId != "string" || e.nextRowId.length > 20 || !/^[1-9]\d*$/u.test(e.nextRowId) || BigInt(e.nextRowId) > Fr + 1n) throw new W(`invalid schema metadata for ${t}`);
|
|
2691
2680
|
let n = /* @__PURE__ */ new Set(), r = 0;
|
|
2692
2681
|
for (let i of e.columns) {
|
|
2693
|
-
if (!
|
|
2682
|
+
if (!di(i) || typeof i.name != "string" || !i.name.length || typeof i.type != "string" || !Ir.has(i.type) || typeof i.primaryKey != "boolean" || typeof i.nullable != "boolean" || n.has(i.name) || i.primaryKey && i.nullable) throw new W(`invalid column metadata for ${t}`);
|
|
2694
2683
|
n.add(i.name), i.primaryKey && (r += 1);
|
|
2695
2684
|
}
|
|
2696
2685
|
if (r > 1) throw new W(`multiple primary keys in ${t}`);
|
|
2697
2686
|
}
|
|
2698
|
-
async function
|
|
2687
|
+
async function Wr(e, t, n, r) {
|
|
2699
2688
|
let i = n.columns ?? t.columns.map((e) => e.name);
|
|
2700
|
-
|
|
2689
|
+
si(t, i);
|
|
2701
2690
|
let a = Y(t), o = BigInt(t.nextRowId), s = [], c = /* @__PURE__ */ new Set();
|
|
2702
2691
|
for (let l of n.rows) {
|
|
2703
2692
|
if (l.length !== i.length) throw new W("INSERT column count does not match VALUES");
|
|
@@ -2707,26 +2696,26 @@ async function qr(e, t, n, r) {
|
|
|
2707
2696
|
n[i[t]] = H(e, r);
|
|
2708
2697
|
});
|
|
2709
2698
|
for (let e of t.columns) n[e.name] = K(e, n[e.name]);
|
|
2710
|
-
if (!a && o >
|
|
2711
|
-
let u = a ? q(a, n[a.name]) :
|
|
2712
|
-
if (c.has(d) || await e.has(t.table, u)) throw new
|
|
2713
|
-
c.add(d), s.push([u,
|
|
2699
|
+
if (!a && o > Fr) throw new S(`row identifier space exhausted in ${t.table}`);
|
|
2700
|
+
let u = a ? q(a, n[a.name]) : qt(o++), d = pi(u);
|
|
2701
|
+
if (c.has(d) || await e.has(t.table, u)) throw new S(`duplicate primary key in ${t.table}`);
|
|
2702
|
+
c.add(d), s.push([u, Gr(t, n)]);
|
|
2714
2703
|
}
|
|
2715
|
-
return await e.putMany(t.table, s), a || (t.nextRowId = o.toString(), await e.put(U,
|
|
2704
|
+
return await e.putMany(t.table, s), a || (t.nextRowId = o.toString(), await e.put(U, ci(t.table), M(t))), {
|
|
2716
2705
|
rows: [],
|
|
2717
2706
|
rowsAffected: s.length
|
|
2718
2707
|
};
|
|
2719
2708
|
}
|
|
2720
2709
|
function K(e, t) {
|
|
2721
2710
|
if (t === null) {
|
|
2722
|
-
if (!e.nullable) throw new
|
|
2711
|
+
if (!e.nullable) throw new S(`column ${e.name} cannot be NULL`);
|
|
2723
2712
|
return null;
|
|
2724
2713
|
}
|
|
2725
2714
|
switch (e.type) {
|
|
2726
2715
|
case "INTEGER": {
|
|
2727
2716
|
if (typeof t != "bigint" && (typeof t != "number" || !Number.isSafeInteger(t))) break;
|
|
2728
2717
|
let e = typeof t == "bigint" ? t : BigInt(t);
|
|
2729
|
-
if (e <
|
|
2718
|
+
if (e < Nr || e > Pr) break;
|
|
2730
2719
|
return e >= BigInt(-(2 ** 53 - 1)) && e <= BigInt(2 ** 53 - 1) ? Number(e) : e;
|
|
2731
2720
|
}
|
|
2732
2721
|
case "REAL":
|
|
@@ -2747,22 +2736,22 @@ function K(e, t) {
|
|
|
2747
2736
|
throw new G(`column ${e.name} requires ${e.type}`);
|
|
2748
2737
|
}
|
|
2749
2738
|
function q(e, t) {
|
|
2750
|
-
if (t === null) throw new
|
|
2751
|
-
if (e.type === "INTEGER") return
|
|
2739
|
+
if (t === null) throw new S(`primary key ${e.name} cannot be NULL`);
|
|
2740
|
+
if (e.type === "INTEGER") return qt(BigInt(t) - Nr);
|
|
2752
2741
|
if (typeof t == "bigint") throw new G(`invalid primary key ${e.name}`);
|
|
2753
2742
|
return N(t);
|
|
2754
2743
|
}
|
|
2755
|
-
function
|
|
2744
|
+
function Gr(e, t) {
|
|
2756
2745
|
let n = Object.create(null);
|
|
2757
|
-
for (let r of e.columns) n[r.name] =
|
|
2746
|
+
for (let r of e.columns) n[r.name] = Kr(t[r.name]);
|
|
2758
2747
|
return M(n);
|
|
2759
2748
|
}
|
|
2760
|
-
function
|
|
2761
|
-
return typeof e == "bigint" ? e.toString() : e instanceof Uint8Array ?
|
|
2749
|
+
function Kr(e) {
|
|
2750
|
+
return typeof e == "bigint" ? e.toString() : e instanceof Uint8Array ? pi(e) : e;
|
|
2762
2751
|
}
|
|
2763
|
-
function
|
|
2764
|
-
let n =
|
|
2765
|
-
if (!
|
|
2752
|
+
function qr(e, t) {
|
|
2753
|
+
let n = fi(t.value);
|
|
2754
|
+
if (!di(n) || Object.keys(n).length !== e.columns.length) throw new T(`invalid SQL row in ${e.table}`);
|
|
2766
2755
|
let r = Object.create(null);
|
|
2767
2756
|
try {
|
|
2768
2757
|
for (let t of e.columns) {
|
|
@@ -2781,17 +2770,17 @@ function Xr(e, t) {
|
|
|
2781
2770
|
let i = Y(e);
|
|
2782
2771
|
if (i && X(q(i, r[i.name]), t.key) !== 0) throw Error("SQL row primary key differs from storage key");
|
|
2783
2772
|
} catch (t) {
|
|
2784
|
-
throw new
|
|
2773
|
+
throw new T(`invalid SQL row in ${e.table}: ${t instanceof Error ? t.message : "invalid value"}`);
|
|
2785
2774
|
}
|
|
2786
2775
|
return {
|
|
2787
2776
|
key: t.key,
|
|
2788
2777
|
row: r
|
|
2789
2778
|
};
|
|
2790
2779
|
}
|
|
2791
|
-
function
|
|
2780
|
+
function Jr(e, t, n) {
|
|
2792
2781
|
if (!t) return;
|
|
2793
2782
|
if ("left" in t) {
|
|
2794
|
-
|
|
2783
|
+
Jr(e, t.left, n), Jr(e, t.right, n);
|
|
2795
2784
|
return;
|
|
2796
2785
|
}
|
|
2797
2786
|
let r = J(e, t.column);
|
|
@@ -2808,16 +2797,16 @@ function Zr(e, t, n) {
|
|
|
2808
2797
|
}, e);
|
|
2809
2798
|
}
|
|
2810
2799
|
}
|
|
2811
|
-
function
|
|
2800
|
+
function Yr(e, t, n) {
|
|
2812
2801
|
if ("left" in t) {
|
|
2813
|
-
let r =
|
|
2802
|
+
let r = Yr(e, t.left, n), i = Yr(e, t.right, n);
|
|
2814
2803
|
return t.kind === "and" ? r === !1 || i === !1 ? !1 : r === null || i === null ? null : !0 : r === !0 || i === !0 ? !0 : r === null || i === null ? null : !1;
|
|
2815
2804
|
}
|
|
2816
2805
|
let r = e[t.column];
|
|
2817
2806
|
if (t.kind === "isNull") return t.negated ? r !== null : r === null;
|
|
2818
2807
|
let i = H(t.value, n);
|
|
2819
2808
|
if (r === null || i === null) return null;
|
|
2820
|
-
let a =
|
|
2809
|
+
let a = ii(r, i);
|
|
2821
2810
|
switch (t.operator) {
|
|
2822
2811
|
case "=": return a === 0;
|
|
2823
2812
|
case "!=": return a !== 0;
|
|
@@ -2827,8 +2816,8 @@ function Qr(e, t, n) {
|
|
|
2827
2816
|
case ">=": return a >= 0;
|
|
2828
2817
|
}
|
|
2829
2818
|
}
|
|
2830
|
-
function
|
|
2831
|
-
let a =
|
|
2819
|
+
function Xr(e, t, n, r, i) {
|
|
2820
|
+
let a = $r(t), o = Y(e), s = [];
|
|
2832
2821
|
o && s.push({ column: o });
|
|
2833
2822
|
for (let t of i) if (t.store === e.table && !t.compound && t.keyPath.length === 1 && !t.keyPath[0].includes(".")) {
|
|
2834
2823
|
let n = e.columns.find((e) => e.name === t.keyPath[0]);
|
|
@@ -2845,17 +2834,17 @@ function $r(e, t, n, r, i) {
|
|
|
2845
2834
|
">="
|
|
2846
2835
|
].includes(e.operator))), s, c = {};
|
|
2847
2836
|
for (let e of o) {
|
|
2848
|
-
let n = H(e.value, r), a =
|
|
2837
|
+
let n = H(e.value, r), a = Qr(i.column, n, !!i.index, t);
|
|
2849
2838
|
if (a) {
|
|
2850
2839
|
if (t) {
|
|
2851
2840
|
s = a;
|
|
2852
2841
|
break;
|
|
2853
2842
|
}
|
|
2854
|
-
|
|
2843
|
+
ei(c, e.operator, a);
|
|
2855
2844
|
}
|
|
2856
2845
|
}
|
|
2857
2846
|
if (!s && !Object.keys(c).length) continue;
|
|
2858
|
-
let l = i.index ? t ? "index-lookup" : "index-range" : t ? "primary-key-lookup" : "primary-key-range", u =
|
|
2847
|
+
let l = i.index ? t ? "index-lookup" : "index-range" : t ? "primary-key-lookup" : "primary-key-range", u = Zr(e, i.column, i.index, n, s);
|
|
2859
2848
|
return u && n[0]?.direction === "desc" && (c.reverse = !0), {
|
|
2860
2849
|
public: {
|
|
2861
2850
|
table: e.table,
|
|
@@ -2867,11 +2856,11 @@ function $r(e, t, n, r, i) {
|
|
|
2867
2856
|
},
|
|
2868
2857
|
key: s,
|
|
2869
2858
|
range: c,
|
|
2870
|
-
empty: !s &&
|
|
2859
|
+
empty: !s && ti(c)
|
|
2871
2860
|
};
|
|
2872
2861
|
}
|
|
2873
2862
|
if (n.length) {
|
|
2874
|
-
for (let t of s) if (
|
|
2863
|
+
for (let t of s) if (Zr(e, t.column, t.index, n)) return {
|
|
2875
2864
|
public: {
|
|
2876
2865
|
table: e.table,
|
|
2877
2866
|
access: t.index ? "index-range" : "table-scan",
|
|
@@ -2890,7 +2879,7 @@ function $r(e, t, n, r, i) {
|
|
|
2890
2879
|
reason: "no supported primary key or index bound; filter table rows"
|
|
2891
2880
|
} };
|
|
2892
2881
|
}
|
|
2893
|
-
function
|
|
2882
|
+
function Zr(e, t, n, r, i) {
|
|
2894
2883
|
if (!r.length || i && !n) return !0;
|
|
2895
2884
|
if (r[0].column !== t.name) return !1;
|
|
2896
2885
|
if (!n) return r.length === 1;
|
|
@@ -2899,7 +2888,7 @@ function ei(e, t, n, r, i) {
|
|
|
2899
2888
|
let a = Y(e);
|
|
2900
2889
|
return r.length === 2 && r[1].column === a?.name && r[1].direction === r[0].direction;
|
|
2901
2890
|
}
|
|
2902
|
-
function
|
|
2891
|
+
function Qr(e, t, n, r) {
|
|
2903
2892
|
if (t === null) return null;
|
|
2904
2893
|
if (e.type === "INTEGER") {
|
|
2905
2894
|
if (typeof t != "bigint" && (typeof t != "number" || !Number.isSafeInteger(t)) || n && !r) return null;
|
|
@@ -2907,19 +2896,19 @@ function ti(e, t, n, r) {
|
|
|
2907
2896
|
...e,
|
|
2908
2897
|
nullable: !0
|
|
2909
2898
|
}, t);
|
|
2910
|
-
return n ? N(
|
|
2899
|
+
return n ? N(Kr(i)) : q(e, i);
|
|
2911
2900
|
}
|
|
2912
2901
|
if (e.type === "REAL" && typeof t == "bigint" && (t < BigInt(-(2 ** 53 - 1)) || t > BigInt(2 ** 53 - 1))) return null;
|
|
2913
2902
|
let i = K({
|
|
2914
2903
|
...e,
|
|
2915
2904
|
nullable: !0
|
|
2916
2905
|
}, t);
|
|
2917
|
-
return n ? N(
|
|
2906
|
+
return n ? N(Kr(i)) : q(e, i);
|
|
2918
2907
|
}
|
|
2919
|
-
function
|
|
2920
|
-
return e ? e.kind === "comparison" ? [e] : e.kind === "and" ? [
|
|
2908
|
+
function $r(e) {
|
|
2909
|
+
return e ? e.kind === "comparison" ? [e] : e.kind === "and" ? [...$r(e.left), ...$r(e.right)] : [] : [];
|
|
2921
2910
|
}
|
|
2922
|
-
function
|
|
2911
|
+
function ei(e, t, n) {
|
|
2923
2912
|
if (t === ">" || t === ">=") {
|
|
2924
2913
|
let r = e.gt ?? e.gte, i = r ? X(n, r) : 1;
|
|
2925
2914
|
(i > 0 || i === 0 && t === ">") && (delete e.gt, delete e.gte, t === ">" ? e.gt = n : e.gte = n);
|
|
@@ -2928,18 +2917,18 @@ function ri(e, t, n) {
|
|
|
2928
2917
|
(i < 0 || i === 0 && t === "<") && (delete e.lt, delete e.lte, t === "<" ? e.lt = n : e.lte = n);
|
|
2929
2918
|
}
|
|
2930
2919
|
}
|
|
2931
|
-
function
|
|
2920
|
+
function ti(e) {
|
|
2932
2921
|
let t = e.gt ?? e.gte, n = e.lt ?? e.lte;
|
|
2933
2922
|
if (!t || !n) return !1;
|
|
2934
2923
|
let r = X(t, n);
|
|
2935
2924
|
return r > 0 || r === 0 && (!!e.gt || !!e.lt);
|
|
2936
2925
|
}
|
|
2937
|
-
async function
|
|
2926
|
+
async function ni(e, t, n, r, i, a) {
|
|
2938
2927
|
if (n.empty) return [];
|
|
2939
2928
|
let o = [], s = (e) => {
|
|
2940
|
-
if (e.key.length === 1 && e.key[0] ===
|
|
2941
|
-
let n =
|
|
2942
|
-
return (!r ||
|
|
2929
|
+
if (e.key.length === 1 && e.key[0] === jr[0]) return !1;
|
|
2930
|
+
let n = qr(t, e);
|
|
2931
|
+
return (!r || Yr(n.row, r, i) === !0) && o.push(n), a !== void 0 && o.length >= a;
|
|
2943
2932
|
};
|
|
2944
2933
|
if (n.public.index) {
|
|
2945
2934
|
let r = n.key ? {
|
|
@@ -2975,14 +2964,14 @@ async function ai(e, t, n, r, i, a) {
|
|
|
2975
2964
|
} else for (let r of await e.scan(t.table, n.range)) if (s(r)) break;
|
|
2976
2965
|
return o;
|
|
2977
2966
|
}
|
|
2978
|
-
function
|
|
2967
|
+
function ri(e, t, n) {
|
|
2979
2968
|
for (let r of n) {
|
|
2980
|
-
let n =
|
|
2969
|
+
let n = ii(e.row[r.column], t.row[r.column]);
|
|
2981
2970
|
if (n) return r.direction === "desc" ? -n : n;
|
|
2982
2971
|
}
|
|
2983
2972
|
return X(e.key, t.key);
|
|
2984
2973
|
}
|
|
2985
|
-
function
|
|
2974
|
+
function ii(e, t) {
|
|
2986
2975
|
if (e === null) return t === null ? 0 : -1;
|
|
2987
2976
|
if (t === null) return 1;
|
|
2988
2977
|
if ((typeof e == "number" || typeof e == "bigint") && (typeof t == "number" || typeof t == "bigint")) return e < t ? -1 : +(e > t);
|
|
@@ -2991,13 +2980,13 @@ function si(e, t) {
|
|
|
2991
2980
|
if (e instanceof Uint8Array && t instanceof Uint8Array) return X(e, t);
|
|
2992
2981
|
throw new G("comparison values have different SQL types");
|
|
2993
2982
|
}
|
|
2994
|
-
function
|
|
2983
|
+
function ai(e, t, n) {
|
|
2995
2984
|
if (!e) return null;
|
|
2996
2985
|
let r = H(e, t);
|
|
2997
2986
|
if (typeof r != "number" || !Number.isSafeInteger(r) || r < 0) throw new G(`${n} requires a non-negative safe integer`);
|
|
2998
2987
|
return r;
|
|
2999
2988
|
}
|
|
3000
|
-
function
|
|
2989
|
+
function oi(e, t) {
|
|
3001
2990
|
let n = {};
|
|
3002
2991
|
for (let r of t) Object.defineProperty(n, r, {
|
|
3003
2992
|
value: e[r] instanceof Uint8Array ? e[r].slice() : e[r],
|
|
@@ -3007,7 +2996,7 @@ function li(e, t) {
|
|
|
3007
2996
|
});
|
|
3008
2997
|
return n;
|
|
3009
2998
|
}
|
|
3010
|
-
function
|
|
2999
|
+
function si(e, t) {
|
|
3011
3000
|
if (!t) return;
|
|
3012
3001
|
let n = /* @__PURE__ */ new Set();
|
|
3013
3002
|
for (let r of t) {
|
|
@@ -3023,26 +3012,26 @@ function J(e, t) {
|
|
|
3023
3012
|
function Y(e) {
|
|
3024
3013
|
return e.columns.find((e) => e.primaryKey);
|
|
3025
3014
|
}
|
|
3026
|
-
function
|
|
3015
|
+
function ci(e) {
|
|
3027
3016
|
return j(`table:${e}`);
|
|
3028
3017
|
}
|
|
3029
|
-
function
|
|
3018
|
+
function li(e) {
|
|
3030
3019
|
if (e === U || e.startsWith("__browserdb:")) throw new W(`reserved SQL table name: ${e}`);
|
|
3031
3020
|
}
|
|
3032
|
-
function
|
|
3021
|
+
function ui(e) {
|
|
3033
3022
|
return e.kind === "select" || e.kind === "update" || e.kind === "delete";
|
|
3034
3023
|
}
|
|
3035
|
-
function
|
|
3024
|
+
function di(e) {
|
|
3036
3025
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
3037
3026
|
}
|
|
3038
|
-
function
|
|
3027
|
+
function fi(e) {
|
|
3039
3028
|
try {
|
|
3040
|
-
return
|
|
3029
|
+
return Kt(e);
|
|
3041
3030
|
} catch {
|
|
3042
|
-
throw new
|
|
3031
|
+
throw new T("invalid SQL JSON data");
|
|
3043
3032
|
}
|
|
3044
3033
|
}
|
|
3045
|
-
function
|
|
3034
|
+
function pi(e) {
|
|
3046
3035
|
return Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
3047
3036
|
}
|
|
3048
3037
|
function X(e, t) {
|
|
@@ -3051,15 +3040,15 @@ function X(e, t) {
|
|
|
3051
3040
|
}
|
|
3052
3041
|
//#endregion
|
|
3053
3042
|
//#region src/index.ts
|
|
3054
|
-
var
|
|
3043
|
+
var mi = 256, hi = 256, gi = 8389662;
|
|
3055
3044
|
async function Z(e) {
|
|
3056
3045
|
try {
|
|
3057
3046
|
return await e();
|
|
3058
3047
|
} catch (e) {
|
|
3059
|
-
throw
|
|
3048
|
+
throw O(e);
|
|
3060
3049
|
}
|
|
3061
3050
|
}
|
|
3062
|
-
var
|
|
3051
|
+
var _i = class {
|
|
3063
3052
|
mode;
|
|
3064
3053
|
#e;
|
|
3065
3054
|
#t;
|
|
@@ -3082,10 +3071,10 @@ var bi = class {
|
|
|
3082
3071
|
return this.#a(), I(e), Z(() => this.#e.proxy.has(this.#t, e, t));
|
|
3083
3072
|
}
|
|
3084
3073
|
async put(e, t, n, r = {}) {
|
|
3085
|
-
return this.#a(), I(e), Z(() => this.#e.proxy.put(this.#t, e, t, n,
|
|
3074
|
+
return this.#a(), I(e), Z(() => this.#e.proxy.put(this.#t, e, t, n, Ni(r)));
|
|
3086
3075
|
}
|
|
3087
3076
|
async putMany(e, t, n = {}) {
|
|
3088
|
-
return this.#a(), I(e), Z(() => this.#e.proxy.putMany(this.#t, e, t,
|
|
3077
|
+
return this.#a(), I(e), Z(() => this.#e.proxy.putMany(this.#t, e, t, Ni(n)));
|
|
3089
3078
|
}
|
|
3090
3079
|
async delete(e, t) {
|
|
3091
3080
|
return this.#a(), I(e), Z(() => this.#e.proxy.delete(this.#t, e, t));
|
|
@@ -3101,7 +3090,7 @@ var bi = class {
|
|
|
3101
3090
|
}
|
|
3102
3091
|
async scanPage(e, t = {}, n = {}) {
|
|
3103
3092
|
this.#a(), I(e);
|
|
3104
|
-
let r =
|
|
3093
|
+
let r = wi(n);
|
|
3105
3094
|
if (r.cursor !== void 0 && !this.#r.has(r.cursor)) throw TypeError("scan cursor does not belong to this transaction");
|
|
3106
3095
|
let i = await Z(() => this.#e.proxy.scanPage({
|
|
3107
3096
|
txId: this.#t,
|
|
@@ -3111,30 +3100,30 @@ var bi = class {
|
|
|
3111
3100
|
maxRows: r.maxRows,
|
|
3112
3101
|
maxBytes: r.maxBytes
|
|
3113
3102
|
}));
|
|
3114
|
-
return this.#a(), r.cursor !== void 0 && this.#r.delete(r.cursor), i.cursorId !== void 0 && !this.#n && this.#r.add(i.cursorId),
|
|
3103
|
+
return this.#a(), r.cursor !== void 0 && this.#r.delete(r.cursor), i.cursorId !== void 0 && !this.#n && this.#r.add(i.cursorId), Si(i);
|
|
3115
3104
|
}
|
|
3116
3105
|
scanIter(e, t = {}, n = {}) {
|
|
3117
|
-
return
|
|
3106
|
+
return Ti(this, e, t, n);
|
|
3118
3107
|
}
|
|
3119
3108
|
async closeScanCursor(e) {
|
|
3120
|
-
|
|
3109
|
+
Ci(e), this.#r.delete(e) && !this.#e.invalidated && await Z(() => this.#e.proxy.closeCursor(e));
|
|
3121
3110
|
}
|
|
3122
3111
|
async getByIndex(e, t, n) {
|
|
3123
3112
|
return this.#a(), I(e), Z(() => this.#e.proxy.getByIndex(this.#t, e, t, n));
|
|
3124
3113
|
}
|
|
3125
3114
|
async *scanByIndex(e, t, n = {}, r = {}) {
|
|
3126
3115
|
this.#a(), I(e);
|
|
3127
|
-
let { maxRows: i, maxBytes: a } =
|
|
3116
|
+
let { maxRows: i, maxBytes: a } = wi(r), o = n.limit ?? Infinity, s = null;
|
|
3128
3117
|
for (; o > 0;) {
|
|
3129
3118
|
this.#a();
|
|
3130
|
-
let r = Math.min(o, i,
|
|
3119
|
+
let r = Math.min(o, i, mi), c = s, l = await Z(() => this.#e.proxy.scanByIndexPage(this.#t, e, t, n, c, r, a));
|
|
3131
3120
|
for (let e of l.rows) yield [e.key, e.value];
|
|
3132
3121
|
if (o -= l.rows.length, l.cursor === null) return;
|
|
3133
3122
|
s = l.cursor;
|
|
3134
3123
|
}
|
|
3135
3124
|
}
|
|
3136
3125
|
async createStore(e, t = {}) {
|
|
3137
|
-
return this.#a(), I(e), Z(() => this.#e.proxy.createStore(this.#t, e,
|
|
3126
|
+
return this.#a(), I(e), Z(() => this.#e.proxy.createStore(this.#t, e, Fi(t)));
|
|
3138
3127
|
}
|
|
3139
3128
|
async dropStore(e) {
|
|
3140
3129
|
return this.#a(), I(e), Z(() => this.#e.proxy.dropStore(this.#t, e));
|
|
@@ -3167,8 +3156,8 @@ var bi = class {
|
|
|
3167
3156
|
try {
|
|
3168
3157
|
await this.#e.proxy.rollback(this.#t);
|
|
3169
3158
|
} catch (e) {
|
|
3170
|
-
let t =
|
|
3171
|
-
if (!(t instanceof
|
|
3159
|
+
let t = O(e);
|
|
3160
|
+
if (!(t instanceof C)) throw t;
|
|
3172
3161
|
} finally {
|
|
3173
3162
|
this.#o();
|
|
3174
3163
|
}
|
|
@@ -3181,12 +3170,12 @@ var bi = class {
|
|
|
3181
3170
|
return this.#t;
|
|
3182
3171
|
}
|
|
3183
3172
|
#a() {
|
|
3184
|
-
if (this.#n || this.#e.invalidated) throw new
|
|
3173
|
+
if (this.#n || this.#e.invalidated) throw new C();
|
|
3185
3174
|
}
|
|
3186
3175
|
#o() {
|
|
3187
3176
|
this.#n || (this.#n = !0, this.#r.clear(), this.#i());
|
|
3188
3177
|
}
|
|
3189
|
-
},
|
|
3178
|
+
}, vi = class {
|
|
3190
3179
|
#e;
|
|
3191
3180
|
#t = !1;
|
|
3192
3181
|
#n = null;
|
|
@@ -3199,9 +3188,9 @@ var bi = class {
|
|
|
3199
3188
|
#l = null;
|
|
3200
3189
|
#u = null;
|
|
3201
3190
|
constructor(e) {
|
|
3202
|
-
this.#e = e, this.#c = new
|
|
3191
|
+
this.#e = e, this.#c = new qn(e.dbName, e.channelName), this.#l = Ct(e, () => {
|
|
3203
3192
|
this.#h();
|
|
3204
|
-
}), this.#u =
|
|
3193
|
+
}), this.#u = wt(e, () => {
|
|
3205
3194
|
this.#g();
|
|
3206
3195
|
});
|
|
3207
3196
|
}
|
|
@@ -3209,8 +3198,8 @@ var bi = class {
|
|
|
3209
3198
|
return this.#d(e);
|
|
3210
3199
|
}
|
|
3211
3200
|
async runSchemaMigration(e, t, n, r) {
|
|
3212
|
-
this.#
|
|
3213
|
-
let i = await this.#d("readwrite"), a = new
|
|
3201
|
+
this.#y();
|
|
3202
|
+
let i = await this.#d("readwrite"), a = new yi(), o = new bi(i, a), s = new xi(this, o, a);
|
|
3214
3203
|
try {
|
|
3215
3204
|
await this.#e.proxy.reconcileIndexes(i.internalId(), r), await n({
|
|
3216
3205
|
db: s,
|
|
@@ -3226,25 +3215,25 @@ var bi = class {
|
|
|
3226
3215
|
}
|
|
3227
3216
|
}
|
|
3228
3217
|
async listStores() {
|
|
3229
|
-
return this.#_(
|
|
3218
|
+
return this.#_(() => this.#e.proxy.listStores());
|
|
3230
3219
|
}
|
|
3231
3220
|
async listIndexes() {
|
|
3232
|
-
return this.#
|
|
3221
|
+
return this.#y(), Z(() => this.#e.proxy.getIndexes());
|
|
3233
3222
|
}
|
|
3234
3223
|
async getVersion() {
|
|
3235
|
-
return this.#_(
|
|
3224
|
+
return this.#_(() => this.#e.proxy.getVersion());
|
|
3236
3225
|
}
|
|
3237
3226
|
async changesSince(e, t = {}) {
|
|
3238
|
-
return this.#_(
|
|
3227
|
+
return this.#_(() => this.#e.proxy.changesSince(Li(e), Ri(t)));
|
|
3239
3228
|
}
|
|
3240
3229
|
async #d(e) {
|
|
3241
|
-
this.#
|
|
3230
|
+
this.#y();
|
|
3242
3231
|
let t = this.#s, n = Z(async () => {
|
|
3243
|
-
let n = await this.#e.proxy.begin(e), r = new
|
|
3232
|
+
let n = await this.#e.proxy.begin(e), r = new _i(this.#e, n, e, () => {
|
|
3244
3233
|
this.#r.delete(r);
|
|
3245
3234
|
});
|
|
3246
|
-
if (this.#r.add(r), this.#t || this.#e.invalidated) throw this.#e.invalidated && r.forceClose(), new
|
|
3247
|
-
if (t !== this.#s) throw await r.rollbackIfOpen(), new
|
|
3235
|
+
if (this.#r.add(r), this.#t || this.#e.invalidated) throw this.#e.invalidated && r.forceClose(), new w();
|
|
3236
|
+
if (t !== this.#s) throw await r.rollbackIfOpen(), new C();
|
|
3248
3237
|
return r;
|
|
3249
3238
|
});
|
|
3250
3239
|
this.#i.add(n);
|
|
@@ -3255,7 +3244,7 @@ var bi = class {
|
|
|
3255
3244
|
}
|
|
3256
3245
|
}
|
|
3257
3246
|
async createStore(e, t = {}) {
|
|
3258
|
-
I(e), await this.#f("readwrite", "createStore", [e,
|
|
3247
|
+
I(e), await this.#f("readwrite", "createStore", [e, Fi(t)]);
|
|
3259
3248
|
}
|
|
3260
3249
|
async dropStore(e) {
|
|
3261
3250
|
I(e), await this.#f("readwrite", "dropStore", [e]);
|
|
@@ -3277,7 +3266,7 @@ var bi = class {
|
|
|
3277
3266
|
e,
|
|
3278
3267
|
t,
|
|
3279
3268
|
n,
|
|
3280
|
-
|
|
3269
|
+
Ni(r)
|
|
3281
3270
|
]);
|
|
3282
3271
|
}
|
|
3283
3272
|
async delete(e, t) {
|
|
@@ -3287,8 +3276,8 @@ var bi = class {
|
|
|
3287
3276
|
return I(e), this.#f("readonly", "scan", [e, t]);
|
|
3288
3277
|
}
|
|
3289
3278
|
async scanPage(e, t = {}, n = {}) {
|
|
3290
|
-
this.#
|
|
3291
|
-
let r =
|
|
3279
|
+
this.#y(), I(e);
|
|
3280
|
+
let r = wi(n);
|
|
3292
3281
|
if (r.cursor !== void 0 && !this.#a.has(r.cursor)) throw TypeError("scan cursor does not belong to this database handle");
|
|
3293
3282
|
let i = this.#s, a = Z(() => this.#e.proxy.scanPage({
|
|
3294
3283
|
store: e,
|
|
@@ -3300,59 +3289,59 @@ var bi = class {
|
|
|
3300
3289
|
this.#o.add(a);
|
|
3301
3290
|
try {
|
|
3302
3291
|
let e = await a;
|
|
3303
|
-
if (r.cursor !== void 0 && this.#a.delete(r.cursor), e.cursorId !== void 0 && this.#a.add(e.cursorId), this.#
|
|
3304
|
-
return
|
|
3292
|
+
if (r.cursor !== void 0 && this.#a.delete(r.cursor), e.cursorId !== void 0 && this.#a.add(e.cursorId), this.#y(), i !== this.#s) throw e.cursorId !== void 0 && await this.closeScanCursor(e.cursorId), new C();
|
|
3293
|
+
return Si(e);
|
|
3305
3294
|
} finally {
|
|
3306
3295
|
this.#o.delete(a);
|
|
3307
3296
|
}
|
|
3308
3297
|
}
|
|
3309
3298
|
scanIter(e, t = {}, n = {}) {
|
|
3310
|
-
return
|
|
3299
|
+
return Ti(this, e, t, n);
|
|
3311
3300
|
}
|
|
3312
3301
|
async closeScanCursor(e) {
|
|
3313
|
-
|
|
3302
|
+
Ci(e), this.#a.delete(e) && !this.#e.invalidated && await Z(() => this.#e.proxy.closeCursor(e));
|
|
3314
3303
|
}
|
|
3315
3304
|
async #f(e, t, n) {
|
|
3316
|
-
return this.#
|
|
3305
|
+
return this.#y(), Z(() => this.#e.proxy.autocommit(e, t, n));
|
|
3317
3306
|
}
|
|
3318
3307
|
async exportSnapshot(e = {}) {
|
|
3319
|
-
return this.#_(
|
|
3320
|
-
let t = await this.#e.proxy.exportSnapshot(
|
|
3308
|
+
return this.#_(async () => {
|
|
3309
|
+
let t = await this.#e.proxy.exportSnapshot(Ii(e));
|
|
3321
3310
|
return t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
3322
3311
|
});
|
|
3323
3312
|
}
|
|
3324
3313
|
async importSnapshot(e) {
|
|
3325
|
-
return this.#
|
|
3314
|
+
return this.#v(() => {
|
|
3326
3315
|
let t = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
3327
3316
|
return this.#e.proxy.importSnapshot(t);
|
|
3328
3317
|
});
|
|
3329
3318
|
}
|
|
3330
3319
|
async reset() {
|
|
3331
|
-
return this.#
|
|
3320
|
+
return this.#v(() => this.#e.proxy.reset());
|
|
3332
3321
|
}
|
|
3333
3322
|
async compact() {
|
|
3334
|
-
return this.#
|
|
3323
|
+
return this.#v(() => this.#e.proxy.compact());
|
|
3335
3324
|
}
|
|
3336
3325
|
async rebuild() {
|
|
3337
|
-
return this.#
|
|
3326
|
+
return this.#v(() => this.#e.proxy.rebuild());
|
|
3338
3327
|
}
|
|
3339
3328
|
async stats() {
|
|
3340
|
-
return this.#_(
|
|
3329
|
+
return this.#_(() => this.#e.proxy.stats());
|
|
3341
3330
|
}
|
|
3342
3331
|
async storageInfo() {
|
|
3343
|
-
return this.#_(
|
|
3332
|
+
return this.#_(() => this.#e.proxy.storageInfo());
|
|
3344
3333
|
}
|
|
3345
3334
|
async requestPersistence() {
|
|
3346
|
-
return this.#_(
|
|
3335
|
+
return this.#_(() => this.#e.proxy.requestPersistence());
|
|
3347
3336
|
}
|
|
3348
3337
|
async destroy() {
|
|
3349
|
-
return this.#_(
|
|
3338
|
+
return this.#_(() => this.#e.destroy?.() ?? At(this.#e));
|
|
3350
3339
|
}
|
|
3351
3340
|
async setFailpoint(e) {
|
|
3352
|
-
return this.#_(
|
|
3341
|
+
return this.#_(() => this.#e.proxy.setFailpoint(e));
|
|
3353
3342
|
}
|
|
3354
3343
|
subscribe(e, t, n) {
|
|
3355
|
-
if (this.#
|
|
3344
|
+
if (this.#y(), typeof e == "function") return this.#c.subscribe(e);
|
|
3356
3345
|
if (typeof t == "function") return this.#c.subscribe(e, t);
|
|
3357
3346
|
if (t instanceof Uint8Array && typeof n == "function") return this.#c.subscribe(e, t, n);
|
|
3358
3347
|
throw TypeError("subscribe() expects one of: (callback), (storeName, callback), (storeName, keyPrefix, callback)");
|
|
@@ -3369,16 +3358,16 @@ var bi = class {
|
|
|
3369
3358
|
async #p() {
|
|
3370
3359
|
await Promise.allSettled(Array.from(this.#i)), await Promise.allSettled(Array.from(this.#o));
|
|
3371
3360
|
let e = null, t = await Promise.allSettled(Array.from(this.#a, (e) => this.closeScanCursor(e)));
|
|
3372
|
-
for (let n of t) n.status === "rejected" && e === null && (e =
|
|
3361
|
+
for (let n of t) n.status === "rejected" && e === null && (e = O(n.reason));
|
|
3373
3362
|
let n = Array.from(this.#r);
|
|
3374
3363
|
if (n.length > 0) {
|
|
3375
3364
|
let t = await Promise.allSettled(n.map((e) => e.rollbackIfOpen()));
|
|
3376
|
-
for (let n of t) n.status === "rejected" && e === null && (e =
|
|
3365
|
+
for (let n of t) n.status === "rejected" && e === null && (e = O(n.reason));
|
|
3377
3366
|
}
|
|
3378
3367
|
try {
|
|
3379
|
-
await (this.#e.release?.() ??
|
|
3368
|
+
await (this.#e.release?.() ?? kt(this.#e));
|
|
3380
3369
|
} catch (e) {
|
|
3381
|
-
throw
|
|
3370
|
+
throw O(e);
|
|
3382
3371
|
}
|
|
3383
3372
|
if (e) throw e;
|
|
3384
3373
|
}
|
|
@@ -3392,10 +3381,16 @@ var bi = class {
|
|
|
3392
3381
|
#g() {
|
|
3393
3382
|
this.#t || (this.#t = !0, this.#m(), this.#h(), this.#c.close());
|
|
3394
3383
|
}
|
|
3395
|
-
#_() {
|
|
3396
|
-
|
|
3384
|
+
#_(e) {
|
|
3385
|
+
return this.#y(), Z(e);
|
|
3386
|
+
}
|
|
3387
|
+
#v(e) {
|
|
3388
|
+
return this.#y(), Tt(this.#e), Z(e);
|
|
3389
|
+
}
|
|
3390
|
+
#y() {
|
|
3391
|
+
if (this.#t || this.#e.invalidated) throw new w();
|
|
3397
3392
|
}
|
|
3398
|
-
},
|
|
3393
|
+
}, yi = class {
|
|
3399
3394
|
#e = /* @__PURE__ */ new Set();
|
|
3400
3395
|
#t = /* @__PURE__ */ new Set();
|
|
3401
3396
|
recordCreate(e) {
|
|
@@ -3410,7 +3405,7 @@ var bi = class {
|
|
|
3410
3405
|
for (let e of this.#t) n.delete(e);
|
|
3411
3406
|
return Array.from(n).sort(t);
|
|
3412
3407
|
}
|
|
3413
|
-
},
|
|
3408
|
+
}, bi = class {
|
|
3414
3409
|
#e;
|
|
3415
3410
|
#t;
|
|
3416
3411
|
constructor(e, t) {
|
|
@@ -3479,7 +3474,7 @@ var bi = class {
|
|
|
3479
3474
|
rollback() {
|
|
3480
3475
|
return Promise.reject(Q("transaction.rollback"));
|
|
3481
3476
|
}
|
|
3482
|
-
},
|
|
3477
|
+
}, xi = class {
|
|
3483
3478
|
#e;
|
|
3484
3479
|
#t;
|
|
3485
3480
|
#n;
|
|
@@ -3581,7 +3576,7 @@ function Q(e) {
|
|
|
3581
3576
|
let t = /* @__PURE__ */ Error(`${e}() is not available inside openDB() migrations; use the provided migration transaction and wait for openDB() to resolve`);
|
|
3582
3577
|
return t.name = "InvalidStateError", t;
|
|
3583
3578
|
}
|
|
3584
|
-
function
|
|
3579
|
+
function Si(e) {
|
|
3585
3580
|
return {
|
|
3586
3581
|
rows: e.rows,
|
|
3587
3582
|
cursor: e.cursorId,
|
|
@@ -3589,21 +3584,21 @@ function Ti(e) {
|
|
|
3589
3584
|
bytes: e.bytes
|
|
3590
3585
|
};
|
|
3591
3586
|
}
|
|
3592
|
-
function
|
|
3587
|
+
function Ci(e) {
|
|
3593
3588
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e <= 0) throw TypeError("scan cursor must be a positive safe integer");
|
|
3594
3589
|
return e;
|
|
3595
3590
|
}
|
|
3596
|
-
function
|
|
3597
|
-
let t = $(e, "scan page options must be an object"), n = t.maxRows ??
|
|
3591
|
+
function wi(e) {
|
|
3592
|
+
let t = $(e, "scan page options must be an object"), n = t.maxRows ?? hi, r = t.maxBytes ?? gi;
|
|
3598
3593
|
if (!Number.isSafeInteger(n) || n <= 0 || n > 4294967295) throw TypeError("scan page maxRows must be a positive 32-bit integer");
|
|
3599
3594
|
if (!Number.isSafeInteger(r) || r < 4 || r > 4294967295) throw TypeError("scan page maxBytes must be a 32-bit integer of at least 4");
|
|
3600
3595
|
return {
|
|
3601
3596
|
maxRows: n,
|
|
3602
3597
|
maxBytes: r,
|
|
3603
|
-
cursor: t.cursor === void 0 ? void 0 :
|
|
3598
|
+
cursor: t.cursor === void 0 ? void 0 : Ci(t.cursor)
|
|
3604
3599
|
};
|
|
3605
3600
|
}
|
|
3606
|
-
async function*
|
|
3601
|
+
async function* Ti(e, t, n, r) {
|
|
3607
3602
|
let i = { ...n };
|
|
3608
3603
|
for (let e of [
|
|
3609
3604
|
"gt",
|
|
@@ -3614,7 +3609,7 @@ async function* Oi(e, t, n, r) {
|
|
|
3614
3609
|
let t = i[e];
|
|
3615
3610
|
t instanceof Uint8Array && (i[e] = t.slice());
|
|
3616
3611
|
}
|
|
3617
|
-
let a =
|
|
3612
|
+
let a = wi(r), o;
|
|
3618
3613
|
try {
|
|
3619
3614
|
for (;;) {
|
|
3620
3615
|
let n = await e.scanPage(t, i, {
|
|
@@ -3629,109 +3624,109 @@ async function* Oi(e, t, n, r) {
|
|
|
3629
3624
|
o !== void 0 && await e.closeScanCursor(o);
|
|
3630
3625
|
}
|
|
3631
3626
|
}
|
|
3632
|
-
function
|
|
3627
|
+
function Ei(e, t) {
|
|
3633
3628
|
if (typeof e != "string" || e.length === 0) throw TypeError(`${t}() database name must be a non-empty string`);
|
|
3634
3629
|
if (/[\uD800-\uDFFF]/u.test(e)) throw TypeError(`${t}() database name must contain valid Unicode`);
|
|
3635
3630
|
if (new TextEncoder().encode(e).length > 127) throw TypeError(`${t}() database name must contain at most 127 UTF-8 bytes`);
|
|
3636
3631
|
return e;
|
|
3637
3632
|
}
|
|
3638
|
-
var
|
|
3639
|
-
function $(e, t, n =
|
|
3633
|
+
var Di = (e) => TypeError(e), Oi = (e) => new E(e);
|
|
3634
|
+
function $(e, t, n = Di) {
|
|
3640
3635
|
if (e === void 0) return {};
|
|
3641
3636
|
if (typeof e != "object" || !e || Array.isArray(e)) throw n(t);
|
|
3642
3637
|
return e;
|
|
3643
3638
|
}
|
|
3644
|
-
function
|
|
3639
|
+
function ki(e, t, n = Di) {
|
|
3645
3640
|
if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw n(t);
|
|
3646
3641
|
return e;
|
|
3647
3642
|
}
|
|
3648
|
-
function
|
|
3649
|
-
return e === void 0 ? void 0 :
|
|
3643
|
+
function Ai(e, t, n) {
|
|
3644
|
+
return e === void 0 ? void 0 : ki(e, t, n);
|
|
3650
3645
|
}
|
|
3651
|
-
function
|
|
3652
|
-
return $(e, "open options must be an object",
|
|
3646
|
+
function ji(e) {
|
|
3647
|
+
return $(e, "open options must be an object", Oi);
|
|
3653
3648
|
}
|
|
3654
|
-
function
|
|
3655
|
-
return
|
|
3649
|
+
function Mi(e) {
|
|
3650
|
+
return Ai(e, "version must be a non-negative safe integer", Oi);
|
|
3656
3651
|
}
|
|
3657
|
-
function
|
|
3658
|
-
let { ttl: t } = $(e, "put options must be an object"), n =
|
|
3652
|
+
function Ni(e) {
|
|
3653
|
+
let { ttl: t } = $(e, "put options must be an object"), n = Ai(t, "ttl must be a non-negative safe integer");
|
|
3659
3654
|
return n === void 0 ? {} : { ttl: n };
|
|
3660
3655
|
}
|
|
3661
|
-
function
|
|
3656
|
+
function Pi(e, t, n) {
|
|
3662
3657
|
let { compression: r } = $(e, t);
|
|
3663
3658
|
if (r === void 0) return {};
|
|
3664
3659
|
if (r !== !1 && r !== "gzip" && r !== "deflate" && !(n && r === "snappy")) throw TypeError(n ? "compression must be \"gzip\", \"deflate\", \"snappy\", or false" : "compression must be \"gzip\", \"deflate\", or false");
|
|
3665
3660
|
return { compression: r };
|
|
3666
3661
|
}
|
|
3667
|
-
function
|
|
3668
|
-
return
|
|
3662
|
+
function Fi(e) {
|
|
3663
|
+
return Pi(e, "createStore options must be an object", !0);
|
|
3669
3664
|
}
|
|
3670
|
-
function
|
|
3671
|
-
return
|
|
3665
|
+
function Ii(e) {
|
|
3666
|
+
return Pi(e, "exportSnapshot options must be an object", !1);
|
|
3672
3667
|
}
|
|
3673
|
-
function
|
|
3674
|
-
return
|
|
3668
|
+
function Li(e) {
|
|
3669
|
+
return ki(e, "txid must be a non-negative safe integer");
|
|
3675
3670
|
}
|
|
3676
|
-
function
|
|
3671
|
+
function Ri(e) {
|
|
3677
3672
|
let { stores: t, limit: n } = $(e, "change feed options must be an object"), r = {};
|
|
3678
3673
|
if (t !== void 0) {
|
|
3679
3674
|
if (!Array.isArray(t) || !t.every((e) => typeof e == "string")) throw TypeError("stores must be an array of strings");
|
|
3680
3675
|
for (let e of t) I(e);
|
|
3681
3676
|
r.stores = [...t];
|
|
3682
3677
|
}
|
|
3683
|
-
let i =
|
|
3678
|
+
let i = Ai(n, "limit must be a non-negative safe integer");
|
|
3684
3679
|
return i !== void 0 && (r.limit = i), r;
|
|
3685
3680
|
}
|
|
3686
|
-
function
|
|
3681
|
+
function zi(e) {
|
|
3687
3682
|
if (e !== void 0) {
|
|
3688
|
-
if (typeof e != "function") throw new
|
|
3683
|
+
if (typeof e != "function") throw new E("migrate must be a function");
|
|
3689
3684
|
return e;
|
|
3690
3685
|
}
|
|
3691
3686
|
}
|
|
3692
|
-
function
|
|
3687
|
+
function Bi(e) {
|
|
3693
3688
|
if (e !== void 0) return L(e);
|
|
3694
3689
|
}
|
|
3695
|
-
function
|
|
3690
|
+
function Vi(e, t) {
|
|
3696
3691
|
return R(e) === R(t);
|
|
3697
3692
|
}
|
|
3698
|
-
async function
|
|
3693
|
+
async function Hi(e) {
|
|
3699
3694
|
return L(await e.proxy.getIndexes());
|
|
3700
3695
|
}
|
|
3701
|
-
function
|
|
3702
|
-
if (!globalThis.isSecureContext) throw new
|
|
3703
|
-
if (typeof globalThis.navigator?.storage?.getDirectory != "function") throw new
|
|
3704
|
-
if (typeof globalThis.Worker != "function") throw new
|
|
3705
|
-
if (globalThis.BroadcastChannel === void 0) throw new
|
|
3696
|
+
function Ui() {
|
|
3697
|
+
if (!globalThis.isSecureContext) throw new x("moyodb requires a secure context (HTTPS)");
|
|
3698
|
+
if (typeof globalThis.navigator?.storage?.getDirectory != "function") throw new x("navigator.storage.getDirectory is unavailable");
|
|
3699
|
+
if (typeof globalThis.Worker != "function") throw new x("Worker is unavailable");
|
|
3700
|
+
if (globalThis.BroadcastChannel === void 0) throw new x("BroadcastChannel is unavailable");
|
|
3706
3701
|
}
|
|
3707
|
-
async function
|
|
3702
|
+
async function Wi(e) {
|
|
3708
3703
|
let t = globalThis.navigator;
|
|
3709
3704
|
(e.requestPersistence ?? !0) && typeof t.storage.persist == "function" && await r(t.storage.persist(), 1e3, !1);
|
|
3710
3705
|
}
|
|
3711
|
-
async function
|
|
3712
|
-
return
|
|
3706
|
+
async function Gi(e, t = {}) {
|
|
3707
|
+
return Ki(e, t, async (e, t) => (Ui(), await Wi(t), Ot(e, t)));
|
|
3713
3708
|
}
|
|
3714
|
-
async function
|
|
3715
|
-
let r =
|
|
3716
|
-
if (a === void 0 && o !== void 0) throw new
|
|
3717
|
-
if (a === void 0 && s !== void 0) throw new
|
|
3718
|
-
let c = await n(r, i), l = new
|
|
3709
|
+
async function Ki(e, t, n) {
|
|
3710
|
+
let r = Ei(e, "openDB"), i = ji(t), a = Mi(i.version), o = zi(i.migrate), s = Bi(i.indexes);
|
|
3711
|
+
if (a === void 0 && o !== void 0) throw new E("migrate requires version");
|
|
3712
|
+
if (a === void 0 && s !== void 0) throw new E("indexes requires version");
|
|
3713
|
+
let c = await n(r, i), l = new vi(c);
|
|
3719
3714
|
try {
|
|
3720
3715
|
await c.proxy.acquireMigration?.();
|
|
3721
3716
|
try {
|
|
3722
3717
|
if (a === void 0) return l;
|
|
3723
|
-
let [e, t] = await Promise.all([l.getVersion(),
|
|
3724
|
-
if (a < e) throw new
|
|
3718
|
+
let [e, t] = await Promise.all([l.getVersion(), Hi(c)]);
|
|
3719
|
+
if (a < e) throw new D(`cannot open database ${r} at schema version ${a}; current schema version is ${e}`);
|
|
3725
3720
|
if (a === e) {
|
|
3726
|
-
if (s !== void 0 && !
|
|
3721
|
+
if (s !== void 0 && !Vi(s, t)) throw new D(`database ${r} is already at schema version ${e}, but the requested index catalog does not match the committed schema`);
|
|
3727
3722
|
return l;
|
|
3728
3723
|
}
|
|
3729
|
-
if (c.refs > 1) throw new
|
|
3730
|
-
if (!o) throw new
|
|
3724
|
+
if (c.refs > 1) throw new Me(`database ${r} is already open in this tab; close existing handles before migrating from version ${e} to ${a}`);
|
|
3725
|
+
if (!o) throw new D(`database ${r} requires migration from version ${e} to ${a}, but no migrate hook was provided`);
|
|
3731
3726
|
let n = s ?? t;
|
|
3732
3727
|
c.schemaMigrationInProgress = !0;
|
|
3733
3728
|
try {
|
|
3734
|
-
await l.runSchemaMigration(e, a, o,
|
|
3729
|
+
await l.runSchemaMigration(e, a, o, On(n));
|
|
3735
3730
|
} finally {
|
|
3736
3731
|
c.schemaMigrationInProgress = !1;
|
|
3737
3732
|
}
|
|
@@ -3743,17 +3738,17 @@ async function Yi(e, t, n) {
|
|
|
3743
3738
|
try {
|
|
3744
3739
|
await l.close();
|
|
3745
3740
|
} catch {}
|
|
3746
|
-
throw
|
|
3741
|
+
throw O(e);
|
|
3747
3742
|
}
|
|
3748
3743
|
}
|
|
3749
|
-
async function
|
|
3750
|
-
let t =
|
|
3751
|
-
|
|
3744
|
+
async function qi(e) {
|
|
3745
|
+
let t = Ei(e, "deleteDB");
|
|
3746
|
+
Ui(), await Mt(t);
|
|
3752
3747
|
}
|
|
3753
|
-
function
|
|
3754
|
-
return
|
|
3748
|
+
function Ji(e) {
|
|
3749
|
+
return Dt(Ei(e, "unsafeDebugCrashWorker"));
|
|
3755
3750
|
}
|
|
3756
3751
|
//#endregion
|
|
3757
|
-
export {
|
|
3752
|
+
export { Je as ChangeFeedCompactedError, S as ConstraintError, Ne as CorruptionError, Me as DatabaseBusyError, w as DatabaseClosedError, dn as INDEX_METADATA_STORE, Ie as IndexNotFoundError, qe as InjectedFailureError, Xe as InternalError, E as InvalidOpenOptionsError, Ge as InvalidRangeError, He as KeyTooLargeError, b as MoyoDbError, Be as ReadonlyTransactionError, or as RecordIndex, sr as RecordStore, Ye as RecoveryRequiredError, We as ReservedStoreNameError, T as SerializationError, W as SqlSchemaError, V as SqlSyntaxError, G as SqlTypeError, Ke as StorageError, Pe as StoreExistsError, Ue as StoreNameTooLongError, Fe as StoreNotFoundError, C as TransactionClosedError, ze as TransactionConflictError, Le as UniqueIndexConstraintError, x as UnsupportedPlatformError, Ve as ValueTooLargeError, D as VersionError, Re as WriteTransactionAlreadyOpenError, I as assertPublicStoreName, Dn as cloneNormalizedIndexDefinitions, pn as compareNormalizedIndexDefinitions, Yt as compoundKey, tr as compoundKeyCodec, $t as compoundKeyRange, Tn as createIndexKeyExtractor, lr as createRecordStore, Lr as createSqlClient, xn as decodeIndexEntryKey, yn as decodeIndexMetadataValue, In as decodeIndexedDocument, qi as deleteDB, F as encodeCompoundKeyParts, bn as encodeIndexEntryKey, _n as encodeIndexMetadataKey, vn as encodeIndexMetadataValue, P as encodeIndexScalar, wn as extractLogicalIndexKey, En as extractLogicalIndexKeyFromDocument, hn as findIndexDefinition, mn as indexDefinitionIdentity, N as indexKey, Sn as indexKeyExactRange, Cn as indexRangeToPhysicalRange, gn as indexesForStore, fn as isInternalStoreName, Kt as jsonDecode, M as jsonEncode, rr as jsonRecordCodec, er as keyCodecs, O as normalizeError, L as normalizeIndexDefinitions, Gi as openDB, Ki as openDBWithWorker, cr as openRecordStore, Qt as prefixRange, Zt as prefixSuccessor, $n as scalarKeyCodec, R as serializeNormalizedIndexDefinitions, Xt as splitCompoundKey, On as toPublicIndexDefinitions, qt as u64Key, Ji as unsafeDebugCrashWorker, Gt as utf8Decode, j as utf8Encode, ar as withRecordTransaction };
|
|
3758
3753
|
|
|
3759
3754
|
//# sourceMappingURL=moyodb-sdk.js.map
|