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