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