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