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