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