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