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