@moyodb/sdk 0.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/dist/assets/worker-CaOzbBz1.js +2351 -0
- package/dist/assets/worker-CaOzbBz1.js.map +1 -0
- package/dist/change-events.d.ts +29 -0
- package/dist/change-events.d.ts.map +1 -0
- package/dist/codec.d.ts +17 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/compression.d.ts +11 -0
- package/dist/compression.d.ts.map +1 -0
- package/dist/demo.d.ts +21 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/engine/README.md +56 -0
- package/dist/engine/moyodb_engine.d.ts +127 -0
- package/dist/engine/moyodb_engine.js +1193 -0
- package/dist/engine/moyodb_engine_bg.wasm +0 -0
- package/dist/engine/moyodb_engine_bg.wasm.d.ts +52 -0
- package/dist/engine/package.json +21 -0
- package/dist/engine/snippets/moyodb-engine-cff0a0e2441a7a8f/js/opfs_shim.js +402 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/indexing.d.ts +33 -0
- package/dist/indexing.d.ts.map +1 -0
- package/dist/internal.d.ts +4 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/moyodb-sdk.js +1988 -0
- package/dist/moyodb-sdk.js.map +1 -0
- package/dist/moyodb-sdk.umd.cjs +2 -0
- package/dist/moyodb-sdk.umd.cjs.map +1 -0
- package/dist/registry.d.ts +33 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/subscriptions.d.ts +10 -0
- package/dist/subscriptions.d.ts.map +1 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/worker-api.d.ts +51 -0
- package/dist/worker-api.d.ts.map +1 -0
- package/dist/worker-client.d.ts +67 -0
- package/dist/worker-client.d.ts.map +1 -0
- package/dist/worker-protocol.d.ts +86 -0
- package/dist/worker-protocol.d.ts.map +1 -0
- package/dist/worker-server.d.ts +6 -0
- package/dist/worker-server.d.ts.map +1 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.d.ts.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,1988 @@
|
|
|
1
|
+
function v(t) {
|
|
2
|
+
return t !== null && typeof t == "object";
|
|
3
|
+
}
|
|
4
|
+
function L(t, e) {
|
|
5
|
+
return t < e ? -1 : t > e ? 1 : 0;
|
|
6
|
+
}
|
|
7
|
+
function j(t, e, r) {
|
|
8
|
+
return new Promise((n) => {
|
|
9
|
+
const o = setTimeout(() => n(r), e);
|
|
10
|
+
t.then(
|
|
11
|
+
(s) => {
|
|
12
|
+
clearTimeout(o), n(s);
|
|
13
|
+
},
|
|
14
|
+
() => {
|
|
15
|
+
clearTimeout(o), n(r);
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const K = 1, Be = "moyodb:worker-protocol:ready", qe = "moyodb:worker-protocol:request", Le = "moyodb:worker-protocol:response", Ce = [
|
|
21
|
+
"open",
|
|
22
|
+
"close",
|
|
23
|
+
"destroy",
|
|
24
|
+
"deleteDB",
|
|
25
|
+
"begin",
|
|
26
|
+
"commit",
|
|
27
|
+
"rollback",
|
|
28
|
+
"createStore",
|
|
29
|
+
"dropStore",
|
|
30
|
+
"clearStore",
|
|
31
|
+
"get",
|
|
32
|
+
"getMany",
|
|
33
|
+
"has",
|
|
34
|
+
"put",
|
|
35
|
+
"putMany",
|
|
36
|
+
"delete",
|
|
37
|
+
"deleteMany",
|
|
38
|
+
"applyBatch",
|
|
39
|
+
"scan",
|
|
40
|
+
"getByIndex",
|
|
41
|
+
"scanByIndex",
|
|
42
|
+
"getIndexes",
|
|
43
|
+
"reconcileIndexes",
|
|
44
|
+
"listStores",
|
|
45
|
+
"getVersion",
|
|
46
|
+
"changesSince",
|
|
47
|
+
"setSchemaVersion",
|
|
48
|
+
"exportSnapshot",
|
|
49
|
+
"importSnapshot",
|
|
50
|
+
"reset",
|
|
51
|
+
"compact",
|
|
52
|
+
"rebuild",
|
|
53
|
+
"stats",
|
|
54
|
+
"storageInfo",
|
|
55
|
+
"requestPersistence",
|
|
56
|
+
"setFailpoint"
|
|
57
|
+
], de = "moyodb:packed-binary-list:v1", Ne = "moyodb:packed-nullable-binary-list:v1", Ue = "moyodb:packed-scan-rows:v1", De = "moyodb:packed-batch-ops:v1", We = 0, ze = 1, T = 4294967295, $e = [];
|
|
58
|
+
new Set(Ce);
|
|
59
|
+
function Fe(t) {
|
|
60
|
+
return v(t) && t.type === Be && t.version === K;
|
|
61
|
+
}
|
|
62
|
+
function Ve(t) {
|
|
63
|
+
return v(t) && t.type === Le && t.version === K && typeof t.id == "number" && Number.isSafeInteger(t.id) && typeof t.ok == "boolean";
|
|
64
|
+
}
|
|
65
|
+
function je(t) {
|
|
66
|
+
const e = new Error(t.message);
|
|
67
|
+
return e.name = t.name || t.code || "Error", t.stack && (e.stack = t.stack), t.code && Object.defineProperty(e, "code", {
|
|
68
|
+
value: t.code,
|
|
69
|
+
enumerable: !0,
|
|
70
|
+
configurable: !0
|
|
71
|
+
}), e;
|
|
72
|
+
}
|
|
73
|
+
function y(t, e, r = t) {
|
|
74
|
+
const n = new Error(e);
|
|
75
|
+
return n.name = t, Object.defineProperty(n, "code", {
|
|
76
|
+
value: r,
|
|
77
|
+
enumerable: !0,
|
|
78
|
+
configurable: !0
|
|
79
|
+
}), n;
|
|
80
|
+
}
|
|
81
|
+
function Ke(t, e) {
|
|
82
|
+
if (t === "importSnapshot") {
|
|
83
|
+
const r = e[0];
|
|
84
|
+
if (r instanceof Uint8Array) {
|
|
85
|
+
const n = tt(r);
|
|
86
|
+
return {
|
|
87
|
+
args: [n],
|
|
88
|
+
transfer: [n.buffer]
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (t === "getMany" || t === "deleteMany") {
|
|
93
|
+
const [r, n, o] = e;
|
|
94
|
+
if (Array.isArray(o) && o.length > 0) {
|
|
95
|
+
const s = Je(o);
|
|
96
|
+
return {
|
|
97
|
+
args: [r, n, s],
|
|
98
|
+
transfer: [s.bytes.buffer]
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (t === "putMany") {
|
|
103
|
+
const [r, n, o, s] = e;
|
|
104
|
+
if (Array.isArray(o) && o.length > 0) {
|
|
105
|
+
const i = Ye(o);
|
|
106
|
+
return {
|
|
107
|
+
args: [r, n, i, s],
|
|
108
|
+
transfer: [i.bytes.buffer]
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (t === "applyBatch") {
|
|
113
|
+
const [r, n, o] = e;
|
|
114
|
+
if (Array.isArray(o) && o.length > 0) {
|
|
115
|
+
const s = Qe(o);
|
|
116
|
+
return {
|
|
117
|
+
args: [r, n, s],
|
|
118
|
+
transfer: [s.bytes.buffer]
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { args: e, transfer: $e };
|
|
123
|
+
}
|
|
124
|
+
function He(t, e) {
|
|
125
|
+
return t === "getMany" && Ze(e) ? Ge(e) : (t === "scan" || t === "scanByIndex") && et(e) ? Xe(e) : e;
|
|
126
|
+
}
|
|
127
|
+
function Ye(t) {
|
|
128
|
+
const e = t.length, r = I(e * 2, "packed putMany item count"), n = R(r, 4, "packed putMany metadata");
|
|
129
|
+
let o = 0;
|
|
130
|
+
for (let c = 0; c < e; c += 1) {
|
|
131
|
+
const h = t[c], g = h[0], E = h[1];
|
|
132
|
+
if (!(g instanceof Uint8Array) || !(E instanceof Uint8Array))
|
|
133
|
+
throw y("WorkerProtocolError", "putMany entry key/value is not a Uint8Array");
|
|
134
|
+
const B = I(g.byteLength, "putMany key length"), q = I(E.byteLength, "putMany value length");
|
|
135
|
+
if (o += B + q, o > T)
|
|
136
|
+
throw y("WorkerProtocolError", "packed putMany payload exceeds 32-bit payload limit");
|
|
137
|
+
}
|
|
138
|
+
const s = A(4, n, "packed putMany header"), i = A(s, o, "packed putMany total"), d = new Uint8Array(i), u = new DataView(d.buffer);
|
|
139
|
+
u.setUint32(0, r, !0);
|
|
140
|
+
let l = 4, a = s;
|
|
141
|
+
for (let c = 0; c < e; c += 1) {
|
|
142
|
+
const h = t[c], g = h[0], E = h[1], B = g.byteLength, q = E.byteLength;
|
|
143
|
+
u.setUint32(l, B, !0), l += 4, u.setUint32(l, q, !0), l += 4, d.set(g, a), a += B, d.set(E, a), a += q;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
__moyodbPacked: de,
|
|
147
|
+
bytes: d
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function Je(t) {
|
|
151
|
+
const e = t.length, r = R(e, 4, "packed binary-list metadata");
|
|
152
|
+
let n = 0;
|
|
153
|
+
for (let a = 0; a < e; a += 1) {
|
|
154
|
+
const c = t[a];
|
|
155
|
+
if (!(c instanceof Uint8Array))
|
|
156
|
+
throw y("WorkerProtocolError", "binary-list payload item is not a Uint8Array");
|
|
157
|
+
const h = I(c.byteLength, "binary-list item length");
|
|
158
|
+
if (n += h, n > T)
|
|
159
|
+
throw y("WorkerProtocolError", "packed binary-list payload exceeds 32-bit payload limit");
|
|
160
|
+
}
|
|
161
|
+
const o = A(4, r, "packed binary-list header"), s = A(o, n, "packed binary-list total"), i = new Uint8Array(s), d = new DataView(i.buffer);
|
|
162
|
+
d.setUint32(0, e, !0);
|
|
163
|
+
let u = 4, l = o;
|
|
164
|
+
for (let a = 0; a < e; a += 1) {
|
|
165
|
+
const c = t[a], h = c.byteLength;
|
|
166
|
+
d.setUint32(u, h, !0), u += 4, i.set(c, l), l += h;
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
__moyodbPacked: de,
|
|
170
|
+
bytes: i
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function Ge(t) {
|
|
174
|
+
const e = t.bytes;
|
|
175
|
+
if (!(e instanceof Uint8Array) || e.byteLength < 4)
|
|
176
|
+
throw y("WorkerProtocolError", "invalid packed nullable binary-list payload");
|
|
177
|
+
const r = new DataView(e.buffer, e.byteOffset, e.byteLength), n = r.getUint32(0, !0), o = R(n, 5, "packed nullable binary-list metadata"), s = A(4, o, "packed nullable binary-list header");
|
|
178
|
+
if (s > e.byteLength)
|
|
179
|
+
throw y("WorkerProtocolError", "packed nullable binary-list metadata exceeds payload length");
|
|
180
|
+
const i = new Array(n);
|
|
181
|
+
let d = 4, u = s;
|
|
182
|
+
for (let l = 0; l < n; l += 1) {
|
|
183
|
+
const a = r.getUint8(d), c = r.getUint32(d + 1, !0);
|
|
184
|
+
if (d += 5, a === 0) {
|
|
185
|
+
if (c !== 0)
|
|
186
|
+
throw y(
|
|
187
|
+
"WorkerProtocolError",
|
|
188
|
+
"packed nullable binary-list null item has a payload length"
|
|
189
|
+
);
|
|
190
|
+
i[l] = null;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (a !== 1)
|
|
194
|
+
throw y(
|
|
195
|
+
"WorkerProtocolError",
|
|
196
|
+
`packed nullable binary-list item has invalid presence byte: ${a}`
|
|
197
|
+
);
|
|
198
|
+
const h = u + c;
|
|
199
|
+
if (h > T || h > e.byteLength)
|
|
200
|
+
throw y("WorkerProtocolError", "packed nullable binary-list item exceeds payload length");
|
|
201
|
+
i[l] = e.subarray(u, h), u = h;
|
|
202
|
+
}
|
|
203
|
+
if (u !== e.byteLength)
|
|
204
|
+
throw y("WorkerProtocolError", "packed nullable binary-list payload has trailing bytes");
|
|
205
|
+
return i;
|
|
206
|
+
}
|
|
207
|
+
function Xe(t) {
|
|
208
|
+
const e = t.bytes;
|
|
209
|
+
if (!(e instanceof Uint8Array) || e.byteLength < 4)
|
|
210
|
+
throw y("WorkerProtocolError", "invalid packed scan row payload");
|
|
211
|
+
const r = new DataView(e.buffer, e.byteOffset, e.byteLength), n = r.getUint32(0, !0), o = R(n, 8, "packed scan row metadata"), s = A(4, o, "packed scan row header");
|
|
212
|
+
if (s > e.byteLength)
|
|
213
|
+
throw y("WorkerProtocolError", "packed scan row metadata exceeds payload length");
|
|
214
|
+
const i = new Array(n);
|
|
215
|
+
let d = 4, u = s;
|
|
216
|
+
for (let l = 0; l < n; l += 1) {
|
|
217
|
+
const a = r.getUint32(d, !0), c = r.getUint32(d + 4, !0);
|
|
218
|
+
d += 8;
|
|
219
|
+
const h = u + a;
|
|
220
|
+
if (h > T || h > e.byteLength)
|
|
221
|
+
throw y("WorkerProtocolError", "packed scan row key exceeds payload length");
|
|
222
|
+
const g = h + c;
|
|
223
|
+
if (g > T || g > e.byteLength)
|
|
224
|
+
throw y("WorkerProtocolError", "packed scan row value exceeds payload length");
|
|
225
|
+
i[l] = {
|
|
226
|
+
key: e.subarray(u, h),
|
|
227
|
+
value: e.subarray(h, g)
|
|
228
|
+
}, u = g;
|
|
229
|
+
}
|
|
230
|
+
if (u !== e.byteLength)
|
|
231
|
+
throw y("WorkerProtocolError", "packed scan row payload has trailing bytes");
|
|
232
|
+
return i;
|
|
233
|
+
}
|
|
234
|
+
function Qe(t) {
|
|
235
|
+
const e = t.length, r = R(e, 9, "packed batch metadata");
|
|
236
|
+
let n = 0;
|
|
237
|
+
for (let a = 0; a < e; a += 1) {
|
|
238
|
+
const c = t[a];
|
|
239
|
+
if (c.kind !== "put" && c.kind !== "delete")
|
|
240
|
+
throw y(
|
|
241
|
+
"WorkerProtocolError",
|
|
242
|
+
`unknown batch operation kind: ${String(c.kind)}`
|
|
243
|
+
);
|
|
244
|
+
if (!(c.key instanceof Uint8Array))
|
|
245
|
+
throw y("WorkerProtocolError", "batch operation key is not a Uint8Array");
|
|
246
|
+
const h = I(c.key.byteLength, "batch operation key length");
|
|
247
|
+
if (n += h, n > T)
|
|
248
|
+
throw y("WorkerProtocolError", "packed batch payload exceeds 32-bit payload limit");
|
|
249
|
+
if (c.kind === "put") {
|
|
250
|
+
if (!(c.value instanceof Uint8Array))
|
|
251
|
+
throw y("WorkerProtocolError", "batch put value is not a Uint8Array");
|
|
252
|
+
const g = I(c.value.byteLength, "batch put value length");
|
|
253
|
+
if (n += g, n > T)
|
|
254
|
+
throw y("WorkerProtocolError", "packed batch payload exceeds 32-bit payload limit");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const o = A(4, r, "packed batch header"), s = A(o, n, "packed batch total"), i = new Uint8Array(s), d = new DataView(i.buffer);
|
|
258
|
+
d.setUint32(0, e, !0);
|
|
259
|
+
let u = 4, l = o;
|
|
260
|
+
for (let a = 0; a < e; a += 1) {
|
|
261
|
+
const c = t[a], h = c.key, g = h.byteLength, E = c.kind === "put" ? c.value.byteLength : 0;
|
|
262
|
+
d.setUint8(u, c.kind === "put" ? ze : We), d.setUint32(u + 1, g, !0), d.setUint32(u + 5, E, !0), u += 9, i.set(h, l), l += g, c.kind === "put" && (i.set(c.value, l), l += E);
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
__moyodbPacked: De,
|
|
266
|
+
bytes: i
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function Ze(t) {
|
|
270
|
+
return v(t) && t.__moyodbPacked === Ne && t.bytes instanceof Uint8Array;
|
|
271
|
+
}
|
|
272
|
+
function et(t) {
|
|
273
|
+
return v(t) && t.__moyodbPacked === Ue && t.bytes instanceof Uint8Array;
|
|
274
|
+
}
|
|
275
|
+
function R(t, e, r) {
|
|
276
|
+
if (!Number.isSafeInteger(t) || t < 0)
|
|
277
|
+
throw y("WorkerProtocolError", `${r} count is invalid: ${t}`);
|
|
278
|
+
return I(t * e, r);
|
|
279
|
+
}
|
|
280
|
+
function A(t, e, r) {
|
|
281
|
+
const n = t + e;
|
|
282
|
+
return I(n, r);
|
|
283
|
+
}
|
|
284
|
+
function I(t, e) {
|
|
285
|
+
if (!Number.isSafeInteger(t) || t < 0 || t > T)
|
|
286
|
+
throw y("WorkerProtocolError", `${e} exceeds 32-bit payload limit`);
|
|
287
|
+
return t;
|
|
288
|
+
}
|
|
289
|
+
function tt(t) {
|
|
290
|
+
const e = new Uint8Array(t.byteLength);
|
|
291
|
+
return e.set(t), e;
|
|
292
|
+
}
|
|
293
|
+
function W(t) {
|
|
294
|
+
t.timeout && clearTimeout(t.timeout);
|
|
295
|
+
}
|
|
296
|
+
class rt {
|
|
297
|
+
constructor(e, r = {}) {
|
|
298
|
+
this.worker = e, this.requestTimeoutMs = r.requestTimeoutMs ?? 0, this.ready = new Promise((n, o) => {
|
|
299
|
+
this.readyResolve = n, this.readyReject = o;
|
|
300
|
+
}), this.worker.addEventListener("message", this.handleMessage), this.worker.addEventListener("messageerror", this.handleMessageError), this.worker.addEventListener("error", this.handleError);
|
|
301
|
+
}
|
|
302
|
+
worker;
|
|
303
|
+
nextRequestId = 1;
|
|
304
|
+
pending = /* @__PURE__ */ new Map();
|
|
305
|
+
closed = !1;
|
|
306
|
+
readyResolved = !1;
|
|
307
|
+
readyResolve = null;
|
|
308
|
+
readyReject = null;
|
|
309
|
+
ready;
|
|
310
|
+
requestTimeoutMs;
|
|
311
|
+
fatalHandler = null;
|
|
312
|
+
closeReason = null;
|
|
313
|
+
setFatalHandler(e) {
|
|
314
|
+
this.fatalHandler = e;
|
|
315
|
+
}
|
|
316
|
+
whenReady() {
|
|
317
|
+
return this.ready;
|
|
318
|
+
}
|
|
319
|
+
dispose(e = y("WorkerTerminatedError", "worker transport was closed")) {
|
|
320
|
+
this.disposeInternal(e, !1);
|
|
321
|
+
}
|
|
322
|
+
open(e) {
|
|
323
|
+
return this.request("open", [e]);
|
|
324
|
+
}
|
|
325
|
+
close() {
|
|
326
|
+
return this.request("close", []);
|
|
327
|
+
}
|
|
328
|
+
destroy() {
|
|
329
|
+
return this.request("destroy", []);
|
|
330
|
+
}
|
|
331
|
+
deleteDB(e) {
|
|
332
|
+
return this.request("deleteDB", [e]);
|
|
333
|
+
}
|
|
334
|
+
begin(e) {
|
|
335
|
+
return this.request("begin", [e]);
|
|
336
|
+
}
|
|
337
|
+
commit(e) {
|
|
338
|
+
return this.request("commit", [e]);
|
|
339
|
+
}
|
|
340
|
+
rollback(e) {
|
|
341
|
+
return this.request("rollback", [e]);
|
|
342
|
+
}
|
|
343
|
+
createStore(e, r, n) {
|
|
344
|
+
return this.request("createStore", [e, r, n]);
|
|
345
|
+
}
|
|
346
|
+
dropStore(e, r) {
|
|
347
|
+
return this.request("dropStore", [e, r]);
|
|
348
|
+
}
|
|
349
|
+
clearStore(e, r) {
|
|
350
|
+
return this.request("clearStore", [e, r]);
|
|
351
|
+
}
|
|
352
|
+
get(e, r, n) {
|
|
353
|
+
return this.request("get", [e, r, n]);
|
|
354
|
+
}
|
|
355
|
+
getMany(e, r, n) {
|
|
356
|
+
return this.request("getMany", [e, r, n]);
|
|
357
|
+
}
|
|
358
|
+
has(e, r, n) {
|
|
359
|
+
return this.request("has", [e, r, n]);
|
|
360
|
+
}
|
|
361
|
+
put(e, r, n, o, s) {
|
|
362
|
+
return this.request("put", [e, r, n, o, s]);
|
|
363
|
+
}
|
|
364
|
+
putMany(e, r, n, o) {
|
|
365
|
+
return this.request("putMany", [e, r, n, o]);
|
|
366
|
+
}
|
|
367
|
+
delete(e, r, n) {
|
|
368
|
+
return this.request("delete", [e, r, n]);
|
|
369
|
+
}
|
|
370
|
+
deleteMany(e, r, n) {
|
|
371
|
+
return this.request("deleteMany", [e, r, n]);
|
|
372
|
+
}
|
|
373
|
+
applyBatch(e, r, n) {
|
|
374
|
+
return this.request("applyBatch", [e, r, n]);
|
|
375
|
+
}
|
|
376
|
+
scan(e, r, n) {
|
|
377
|
+
return this.request("scan", [e, r, n]);
|
|
378
|
+
}
|
|
379
|
+
getByIndex(e, r, n, o) {
|
|
380
|
+
return this.request("getByIndex", [e, r, n, o]);
|
|
381
|
+
}
|
|
382
|
+
scanByIndex(e, r, n, o) {
|
|
383
|
+
return this.request("scanByIndex", [e, r, n, o]);
|
|
384
|
+
}
|
|
385
|
+
getIndexes() {
|
|
386
|
+
return this.request("getIndexes", []);
|
|
387
|
+
}
|
|
388
|
+
reconcileIndexes(e, r) {
|
|
389
|
+
return this.request("reconcileIndexes", [e, r]);
|
|
390
|
+
}
|
|
391
|
+
listStores() {
|
|
392
|
+
return this.request("listStores", []);
|
|
393
|
+
}
|
|
394
|
+
getVersion() {
|
|
395
|
+
return this.request("getVersion", []);
|
|
396
|
+
}
|
|
397
|
+
changesSince(e, r) {
|
|
398
|
+
return this.request("changesSince", [e, r]);
|
|
399
|
+
}
|
|
400
|
+
setSchemaVersion(e, r) {
|
|
401
|
+
return this.request("setSchemaVersion", [e, r]);
|
|
402
|
+
}
|
|
403
|
+
exportSnapshot(e) {
|
|
404
|
+
return this.request("exportSnapshot", [e]);
|
|
405
|
+
}
|
|
406
|
+
importSnapshot(e) {
|
|
407
|
+
return this.request("importSnapshot", [e]);
|
|
408
|
+
}
|
|
409
|
+
reset() {
|
|
410
|
+
return this.request("reset", []);
|
|
411
|
+
}
|
|
412
|
+
compact() {
|
|
413
|
+
return this.request("compact", []);
|
|
414
|
+
}
|
|
415
|
+
rebuild() {
|
|
416
|
+
return this.request("rebuild", []);
|
|
417
|
+
}
|
|
418
|
+
stats() {
|
|
419
|
+
return this.request("stats", []);
|
|
420
|
+
}
|
|
421
|
+
storageInfo() {
|
|
422
|
+
return this.request("storageInfo", []);
|
|
423
|
+
}
|
|
424
|
+
requestPersistence() {
|
|
425
|
+
return this.request("requestPersistence", []);
|
|
426
|
+
}
|
|
427
|
+
setFailpoint(e) {
|
|
428
|
+
return this.request("setFailpoint", [e]);
|
|
429
|
+
}
|
|
430
|
+
async request(e, r) {
|
|
431
|
+
this.ensureOpen(), await this.ready, this.ensureOpen();
|
|
432
|
+
const n = this.nextRequestId;
|
|
433
|
+
this.nextRequestId += 1;
|
|
434
|
+
const o = Ke(e, r), s = {
|
|
435
|
+
type: qe,
|
|
436
|
+
version: K,
|
|
437
|
+
id: n,
|
|
438
|
+
command: e,
|
|
439
|
+
args: o.args
|
|
440
|
+
};
|
|
441
|
+
return await new Promise((i, d) => {
|
|
442
|
+
const u = this.requestTimeoutMs > 0 ? setTimeout(() => {
|
|
443
|
+
this.pending.delete(n), d(
|
|
444
|
+
y(
|
|
445
|
+
"WorkerRequestTimeoutError",
|
|
446
|
+
`worker command ${e} timed out after ${this.requestTimeoutMs}ms`
|
|
447
|
+
)
|
|
448
|
+
);
|
|
449
|
+
}, this.requestTimeoutMs) : null;
|
|
450
|
+
this.pending.set(n, {
|
|
451
|
+
command: e,
|
|
452
|
+
resolve: (l) => i(l),
|
|
453
|
+
reject: d,
|
|
454
|
+
timeout: u
|
|
455
|
+
});
|
|
456
|
+
try {
|
|
457
|
+
o.transfer.length > 0 ? this.worker.postMessage(s, o.transfer) : this.worker.postMessage(s);
|
|
458
|
+
} catch (l) {
|
|
459
|
+
this.rejectPending(n, l instanceof Error ? l : new Error(String(l)));
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
ensureOpen() {
|
|
464
|
+
if (this.closed)
|
|
465
|
+
throw this.closeReason ?? y("WorkerTerminatedError", "worker transport is closed");
|
|
466
|
+
}
|
|
467
|
+
handleMessage = (e) => {
|
|
468
|
+
const r = e.data;
|
|
469
|
+
if (Fe(r)) {
|
|
470
|
+
this.readyResolved = !0, this.readyResolve?.(), this.readyResolve = null, this.readyReject = null;
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (!Ve(r))
|
|
474
|
+
return;
|
|
475
|
+
const n = this.pending.get(r.id);
|
|
476
|
+
if (n) {
|
|
477
|
+
if (this.pending.delete(r.id), W(n), r.ok) {
|
|
478
|
+
n.resolve(He(n.command, r.result));
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
n.reject(je(r.error));
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
handleMessageError = () => {
|
|
485
|
+
this.disposeInternal(
|
|
486
|
+
y("WorkerMessageError", "worker message could not be deserialized"),
|
|
487
|
+
!0
|
|
488
|
+
);
|
|
489
|
+
};
|
|
490
|
+
handleError = (e) => {
|
|
491
|
+
const r = e.error instanceof Error ? e.error : y("WorkerError", e.message || "worker runtime failed");
|
|
492
|
+
this.disposeInternal(r, !0);
|
|
493
|
+
};
|
|
494
|
+
rejectPending(e, r) {
|
|
495
|
+
const n = this.pending.get(e);
|
|
496
|
+
n && (this.pending.delete(e), W(n), n.reject(r));
|
|
497
|
+
}
|
|
498
|
+
disposeInternal(e, r) {
|
|
499
|
+
if (!this.closed) {
|
|
500
|
+
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;
|
|
501
|
+
for (const n of this.pending.values())
|
|
502
|
+
W(n), n.reject(e);
|
|
503
|
+
this.pending.clear(), r && this.fatalHandler?.(e);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
class p extends Error {
|
|
508
|
+
constructor(e, r) {
|
|
509
|
+
super(r), this.name = e, Object.setPrototypeOf(this, new.target.prototype);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
class O extends p {
|
|
513
|
+
constructor(e) {
|
|
514
|
+
super("UnsupportedPlatformError", e);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
class he extends p {
|
|
518
|
+
constructor(e) {
|
|
519
|
+
super("DatabaseBusyError", e);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
class nt extends p {
|
|
523
|
+
constructor(e) {
|
|
524
|
+
super("CorruptionError", e);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
class ot extends p {
|
|
528
|
+
constructor(e) {
|
|
529
|
+
super("StoreExistsError", e);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
class st extends p {
|
|
533
|
+
constructor(e) {
|
|
534
|
+
super("StoreNotFoundError", e);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
class it extends p {
|
|
538
|
+
constructor(e) {
|
|
539
|
+
super("IndexNotFoundError", e);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
class fe extends p {
|
|
543
|
+
constructor(e) {
|
|
544
|
+
super("ConstraintError", e);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
class at extends fe {
|
|
548
|
+
constructor(e) {
|
|
549
|
+
super(e), this.name = "UniqueIndexConstraintError";
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
class ct extends p {
|
|
553
|
+
constructor(e = "write transaction already open") {
|
|
554
|
+
super("WriteTransactionAlreadyOpenError", e);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
class ut extends p {
|
|
558
|
+
constructor(e = "readonly transaction cannot perform this operation") {
|
|
559
|
+
super("ReadonlyTransactionError", e);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
class z extends p {
|
|
563
|
+
constructor(e = "transaction is already closed") {
|
|
564
|
+
super("TransactionClosedError", e);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
class H extends p {
|
|
568
|
+
constructor(e = "database handle is closed") {
|
|
569
|
+
super("DatabaseClosedError", e);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
class lt extends p {
|
|
573
|
+
constructor(e) {
|
|
574
|
+
super("ValueTooLargeError", e);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
class dt extends p {
|
|
578
|
+
constructor(e) {
|
|
579
|
+
super("KeyTooLargeError", e);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
class ht extends p {
|
|
583
|
+
constructor(e) {
|
|
584
|
+
super("StoreNameTooLongError", e);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
class ye extends p {
|
|
588
|
+
constructor(e) {
|
|
589
|
+
super("ReservedStoreNameError", e);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
class ft extends p {
|
|
593
|
+
constructor(e) {
|
|
594
|
+
super("InvalidRangeError", e);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
class yt extends p {
|
|
598
|
+
constructor(e) {
|
|
599
|
+
super("StorageError", e);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
class _ extends p {
|
|
603
|
+
constructor(e) {
|
|
604
|
+
super("SerializationError", e);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
class pt extends p {
|
|
608
|
+
constructor(e) {
|
|
609
|
+
super("InjectedFailureError", e);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
class bt extends p {
|
|
613
|
+
constructor(e) {
|
|
614
|
+
super("ChangeFeedCompactedError", e);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
class wt extends p {
|
|
618
|
+
constructor(e) {
|
|
619
|
+
super("InternalError", e);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
class b extends p {
|
|
623
|
+
constructor(e) {
|
|
624
|
+
super("InvalidOpenOptionsError", e);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
class C extends p {
|
|
628
|
+
constructor(e) {
|
|
629
|
+
super("VersionError", e);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const gt = {
|
|
633
|
+
UnsupportedPlatformError: O,
|
|
634
|
+
DatabaseBusyError: he,
|
|
635
|
+
CorruptionError: nt,
|
|
636
|
+
StoreExistsError: ot,
|
|
637
|
+
StoreNotFoundError: st,
|
|
638
|
+
IndexNotFoundError: it,
|
|
639
|
+
ConstraintError: fe,
|
|
640
|
+
UniqueIndexConstraintError: at,
|
|
641
|
+
WriteTransactionAlreadyOpenError: ct,
|
|
642
|
+
ReadonlyTransactionError: ut,
|
|
643
|
+
TransactionClosedError: z,
|
|
644
|
+
DatabaseClosedError: H,
|
|
645
|
+
ValueTooLargeError: lt,
|
|
646
|
+
KeyTooLargeError: dt,
|
|
647
|
+
StoreNameTooLongError: ht,
|
|
648
|
+
ReservedStoreNameError: ye,
|
|
649
|
+
InvalidRangeError: ft,
|
|
650
|
+
StorageError: yt,
|
|
651
|
+
SerializationError: _,
|
|
652
|
+
InjectedFailureError: pt,
|
|
653
|
+
ChangeFeedCompactedError: bt,
|
|
654
|
+
InternalError: wt,
|
|
655
|
+
InvalidOpenOptionsError: b,
|
|
656
|
+
VersionError: C
|
|
657
|
+
};
|
|
658
|
+
function Z(t, e) {
|
|
659
|
+
const r = gt[t];
|
|
660
|
+
if (r)
|
|
661
|
+
return new r(e);
|
|
662
|
+
const n = new Error(e);
|
|
663
|
+
return n.name = t, n;
|
|
664
|
+
}
|
|
665
|
+
function x(t) {
|
|
666
|
+
if (t instanceof p)
|
|
667
|
+
return t;
|
|
668
|
+
if (t instanceof Error)
|
|
669
|
+
return t.name === "Error" ? t : Z(t.name, t.message);
|
|
670
|
+
const e = t, r = e?.code ?? e?.name ?? "Error", n = e?.message ?? String(t);
|
|
671
|
+
return Z(r, n);
|
|
672
|
+
}
|
|
673
|
+
const ee = /* @__PURE__ */ new Set([
|
|
674
|
+
"after_wal_flush",
|
|
675
|
+
"after_main_flush",
|
|
676
|
+
"before_superblock_flush"
|
|
677
|
+
]), mt = "moyodb:persistence-bridge:init", kt = "moyodb:persistence-bridge:request", xt = "moyodb:persistence-bridge:response", k = /* @__PURE__ */ new Map();
|
|
678
|
+
function Et(t) {
|
|
679
|
+
if (t === null || typeof t != "object" || Array.isArray(t))
|
|
680
|
+
throw new b("open options must be an object");
|
|
681
|
+
}
|
|
682
|
+
function te(t, e, r) {
|
|
683
|
+
if (t === void 0)
|
|
684
|
+
return r;
|
|
685
|
+
if (typeof t != "boolean")
|
|
686
|
+
throw new b(`${e} must be a boolean`);
|
|
687
|
+
return t;
|
|
688
|
+
}
|
|
689
|
+
function pe(t, e, r) {
|
|
690
|
+
if (t === void 0)
|
|
691
|
+
return r;
|
|
692
|
+
if (typeof t != "number" || !Number.isSafeInteger(t) || t < 0)
|
|
693
|
+
throw new b(`${e} must be a non-negative safe integer`);
|
|
694
|
+
return t;
|
|
695
|
+
}
|
|
696
|
+
function St(t) {
|
|
697
|
+
return Math.max(1, pe(t, "cachePages", 256));
|
|
698
|
+
}
|
|
699
|
+
function It(t) {
|
|
700
|
+
if (t == null)
|
|
701
|
+
return null;
|
|
702
|
+
if (typeof t != "string" || !ee.has(t))
|
|
703
|
+
throw new b(`debugFailpoint must be one of: ${Array.from(ee).join(", ")}`);
|
|
704
|
+
return t;
|
|
705
|
+
}
|
|
706
|
+
function Pt(t = {}) {
|
|
707
|
+
return Et(t), {
|
|
708
|
+
createIfMissing: te(t.createIfMissing, "createIfMissing", !0),
|
|
709
|
+
ownerWaitMs: pe(t.ownerWaitMs, "ownerWaitMs", 0),
|
|
710
|
+
requestPersistence: te(t.requestPersistence, "requestPersistence", !0),
|
|
711
|
+
cachePages: St(t.cachePages),
|
|
712
|
+
debugFailpoint: It(t.debugFailpoint)
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function Tt(t, e, r) {
|
|
716
|
+
if (e.cachePages !== r.cachePages)
|
|
717
|
+
throw new b(
|
|
718
|
+
`database ${t} is already open in this tab with cachePages=${e.cachePages}; requested cachePages=${r.cachePages}`
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
async function At() {
|
|
722
|
+
const t = globalThis.navigator?.storage;
|
|
723
|
+
return typeof t?.persisted != "function" ? !1 : await j(t.persisted(), 1e3, !1);
|
|
724
|
+
}
|
|
725
|
+
async function Ot() {
|
|
726
|
+
const t = globalThis.navigator?.storage;
|
|
727
|
+
return typeof t?.persist != "function" ? !1 : await j(t.persist(), 1e3, !1);
|
|
728
|
+
}
|
|
729
|
+
async function vt(t, e) {
|
|
730
|
+
const r = e.op === "persist" ? await Ot() : await At(), n = {
|
|
731
|
+
type: xt,
|
|
732
|
+
id: e.id,
|
|
733
|
+
granted: r
|
|
734
|
+
};
|
|
735
|
+
t.postMessage(n);
|
|
736
|
+
}
|
|
737
|
+
function Mt(t) {
|
|
738
|
+
const e = new MessageChannel(), r = e.port1;
|
|
739
|
+
return r.addEventListener("message", (n) => {
|
|
740
|
+
const o = n.data;
|
|
741
|
+
!o || o.type !== kt || vt(r, o);
|
|
742
|
+
}), r.start(), t.postMessage({ type: mt }, [e.port2]), {
|
|
743
|
+
close() {
|
|
744
|
+
r.close();
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
function be() {
|
|
749
|
+
const t = new Worker(new URL(
|
|
750
|
+
/* @vite-ignore */
|
|
751
|
+
"/assets/worker-CaOzbBz1.js",
|
|
752
|
+
import.meta.url
|
|
753
|
+
), { type: "module" }), e = new rt(t), r = Mt(t);
|
|
754
|
+
return { worker: t, proxy: e, persistenceBridge: r };
|
|
755
|
+
}
|
|
756
|
+
function Rt(t, e, r, n, o) {
|
|
757
|
+
const s = {
|
|
758
|
+
dbName: t,
|
|
759
|
+
refs: 1,
|
|
760
|
+
worker: e,
|
|
761
|
+
proxy: r,
|
|
762
|
+
persistenceBridge: n,
|
|
763
|
+
options: o,
|
|
764
|
+
invalidated: !1,
|
|
765
|
+
txInvalidationListeners: /* @__PURE__ */ new Set(),
|
|
766
|
+
handleInvalidationListeners: /* @__PURE__ */ new Set()
|
|
767
|
+
};
|
|
768
|
+
return r.setFatalHandler(() => {
|
|
769
|
+
k.get(t) !== s || s.invalidated || (k.delete(t), s.refs = 0, Y(s), s.persistenceBridge.close(), s.worker.terminate());
|
|
770
|
+
}), s;
|
|
771
|
+
}
|
|
772
|
+
function we(t) {
|
|
773
|
+
for (const e of Array.from(t))
|
|
774
|
+
e();
|
|
775
|
+
}
|
|
776
|
+
function _t(t, e) {
|
|
777
|
+
return t.txInvalidationListeners.add(e), () => {
|
|
778
|
+
t.txInvalidationListeners.delete(e);
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
function Bt(t, e) {
|
|
782
|
+
return t.handleInvalidationListeners.add(e), () => {
|
|
783
|
+
t.handleInvalidationListeners.delete(e);
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
function N(t) {
|
|
787
|
+
we(t.txInvalidationListeners);
|
|
788
|
+
}
|
|
789
|
+
function Y(t) {
|
|
790
|
+
t.invalidated || (t.invalidated = !0, N(t), we(t.handleInvalidationListeners));
|
|
791
|
+
}
|
|
792
|
+
function qt(t) {
|
|
793
|
+
const e = k.get(t);
|
|
794
|
+
return e ? (k.delete(t), Y(e), e.refs = 0, e.persistenceBridge.close(), e.proxy.dispose(new Error("worker was terminated by unsafeDebugCrashWorker")), e.worker.terminate(), !0) : !1;
|
|
795
|
+
}
|
|
796
|
+
async function Lt(t, e = {}) {
|
|
797
|
+
const r = Pt(e), n = k.get(t);
|
|
798
|
+
if (n)
|
|
799
|
+
if (n.invalidated)
|
|
800
|
+
k.delete(t);
|
|
801
|
+
else {
|
|
802
|
+
if (Tt(t, n.options, r), r.debugFailpoint !== null)
|
|
803
|
+
try {
|
|
804
|
+
await n.proxy.setFailpoint(r.debugFailpoint);
|
|
805
|
+
} catch (u) {
|
|
806
|
+
throw x(u);
|
|
807
|
+
}
|
|
808
|
+
return n.refs += 1, n;
|
|
809
|
+
}
|
|
810
|
+
const { worker: o, proxy: s, persistenceBridge: i } = be(), d = Rt(t, o, s, i, r);
|
|
811
|
+
try {
|
|
812
|
+
return await s.open({
|
|
813
|
+
dbName: t,
|
|
814
|
+
options: r
|
|
815
|
+
}), k.set(t, d), d;
|
|
816
|
+
} catch (u) {
|
|
817
|
+
throw i.close(), s.dispose(new Error("worker open failed")), o.terminate(), x(u);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
async function Ct(t) {
|
|
821
|
+
if (t.invalidated)
|
|
822
|
+
return;
|
|
823
|
+
const e = k.get(t.dbName);
|
|
824
|
+
if (e && (e.refs -= 1, !(e.refs > 0))) {
|
|
825
|
+
k.delete(t.dbName);
|
|
826
|
+
try {
|
|
827
|
+
await e.proxy.close();
|
|
828
|
+
} finally {
|
|
829
|
+
e.persistenceBridge.close(), e.proxy.dispose(new Error("worker was released")), e.worker.terminate();
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
async function ge(t) {
|
|
834
|
+
const e = k.get(t.dbName) ?? t;
|
|
835
|
+
k.delete(t.dbName), Y(e), e.refs = 0;
|
|
836
|
+
try {
|
|
837
|
+
await e.proxy.destroy();
|
|
838
|
+
} catch (r) {
|
|
839
|
+
throw x(r);
|
|
840
|
+
} finally {
|
|
841
|
+
e.persistenceBridge.close(), e.proxy.dispose(new Error("worker was released")), e.worker.terminate();
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
async function Nt(t) {
|
|
845
|
+
const e = k.get(t);
|
|
846
|
+
if (e) {
|
|
847
|
+
await ge(e);
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
const { worker: r, proxy: n, persistenceBridge: o } = be();
|
|
851
|
+
try {
|
|
852
|
+
await n.deleteDB(t);
|
|
853
|
+
} catch (s) {
|
|
854
|
+
throw x(s);
|
|
855
|
+
} finally {
|
|
856
|
+
o.close(), n.dispose(new Error("temporary worker was terminated")), r.terminate();
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
const Ut = new TextEncoder(), Dt = new TextDecoder(), Wt = 16, zt = 32, $t = 33, Ft = 48, Vt = 64, jt = 80, M = 0, me = 255, $ = 0, Kt = 0xffffffffffffffffn;
|
|
860
|
+
function P(t) {
|
|
861
|
+
return Ut.encode(t);
|
|
862
|
+
}
|
|
863
|
+
function Ht(t) {
|
|
864
|
+
return Dt.decode(t);
|
|
865
|
+
}
|
|
866
|
+
function Mr(t) {
|
|
867
|
+
return P(JSON.stringify(t));
|
|
868
|
+
}
|
|
869
|
+
function Rr(t) {
|
|
870
|
+
return JSON.parse(Ht(t));
|
|
871
|
+
}
|
|
872
|
+
function _r(t) {
|
|
873
|
+
const e = typeof t == "bigint" ? t : BigInt(t);
|
|
874
|
+
if (e < 0n)
|
|
875
|
+
throw new RangeError("u64Key only accepts non-negative values");
|
|
876
|
+
const r = new ArrayBuffer(8);
|
|
877
|
+
return new DataView(r).setBigUint64(0, e, !1), new Uint8Array(r);
|
|
878
|
+
}
|
|
879
|
+
function Br(t) {
|
|
880
|
+
return Array.isArray(t) ? ke(...t) : J(t);
|
|
881
|
+
}
|
|
882
|
+
function ke(...t) {
|
|
883
|
+
return Ee(t.map((e) => J(e)));
|
|
884
|
+
}
|
|
885
|
+
function re(t) {
|
|
886
|
+
return J(t);
|
|
887
|
+
}
|
|
888
|
+
function S(t) {
|
|
889
|
+
return Ee(t);
|
|
890
|
+
}
|
|
891
|
+
function Yt(t) {
|
|
892
|
+
const e = [], r = [];
|
|
893
|
+
for (let n = 0; n < t.length; n += 1) {
|
|
894
|
+
const o = t[n];
|
|
895
|
+
if (o !== M) {
|
|
896
|
+
r.push(o);
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
const s = t[n + 1];
|
|
900
|
+
if (s === me) {
|
|
901
|
+
r.push(M), n += 1;
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
if (s === $) {
|
|
905
|
+
e.push(Uint8Array.from(r)), r.length = 0, n += 1;
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
throw new TypeError("invalid compound key encoding");
|
|
909
|
+
}
|
|
910
|
+
if (r.length !== 0)
|
|
911
|
+
throw new TypeError("compound key terminated unexpectedly");
|
|
912
|
+
return e;
|
|
913
|
+
}
|
|
914
|
+
function F(t) {
|
|
915
|
+
const e = t.slice();
|
|
916
|
+
for (let r = e.length - 1; r >= 0; r -= 1)
|
|
917
|
+
if (e[r] !== 255)
|
|
918
|
+
return e[r] += 1, e.subarray(0, r + 1);
|
|
919
|
+
return null;
|
|
920
|
+
}
|
|
921
|
+
function xe(t) {
|
|
922
|
+
const e = F(t);
|
|
923
|
+
return e ? { gte: t, lt: e } : { gte: t };
|
|
924
|
+
}
|
|
925
|
+
function qr(...t) {
|
|
926
|
+
return xe(ke(...t));
|
|
927
|
+
}
|
|
928
|
+
function J(t) {
|
|
929
|
+
if (t === null)
|
|
930
|
+
return Uint8Array.of(Wt);
|
|
931
|
+
if (typeof t == "boolean")
|
|
932
|
+
return Uint8Array.of(t ? $t : zt);
|
|
933
|
+
if (typeof t == "number")
|
|
934
|
+
return Jt(t);
|
|
935
|
+
if (typeof t == "string") {
|
|
936
|
+
const e = P(t), r = new Uint8Array(1 + e.length);
|
|
937
|
+
return r[0] = Vt, r.set(e, 1), r;
|
|
938
|
+
}
|
|
939
|
+
if (t instanceof Uint8Array) {
|
|
940
|
+
const e = new Uint8Array(1 + t.length);
|
|
941
|
+
return e[0] = jt, e.set(t, 1), e;
|
|
942
|
+
}
|
|
943
|
+
throw new TypeError("compound key parts must be string, number, boolean, null, or Uint8Array");
|
|
944
|
+
}
|
|
945
|
+
function Ee(t) {
|
|
946
|
+
let e = 0;
|
|
947
|
+
for (const o of t) {
|
|
948
|
+
for (const s of o)
|
|
949
|
+
e += s === M ? 2 : 1;
|
|
950
|
+
e += 2;
|
|
951
|
+
}
|
|
952
|
+
const r = new Uint8Array(e);
|
|
953
|
+
let n = 0;
|
|
954
|
+
for (const o of t) {
|
|
955
|
+
for (const s of o)
|
|
956
|
+
s === M ? (r[n] = M, r[n + 1] = me, n += 2) : (r[n] = s, n += 1);
|
|
957
|
+
r[n] = $, r[n + 1] = $, n += 2;
|
|
958
|
+
}
|
|
959
|
+
return r;
|
|
960
|
+
}
|
|
961
|
+
function Jt(t) {
|
|
962
|
+
if (!Number.isFinite(t))
|
|
963
|
+
throw new TypeError("compound key number parts must be finite");
|
|
964
|
+
const e = Object.is(t, -0) ? 0 : t, r = new ArrayBuffer(9), n = new DataView(r);
|
|
965
|
+
n.setUint8(0, Ft), n.setFloat64(1, e, !1);
|
|
966
|
+
let o = n.getBigUint64(1, !1);
|
|
967
|
+
return o = (o & 1n << 63n) !== 0n ? ~o & Kt : o ^ 1n << 63n, n.setBigUint64(1, o, !1), new Uint8Array(r);
|
|
968
|
+
}
|
|
969
|
+
const Gt = new TextEncoder(), Se = new TextDecoder("utf-8", { fatal: !0 }), U = /* @__PURE__ */ Symbol("moyodb.indexing.missing"), Xt = 0xcbf29ce484222325n, Qt = 0x100000001b3n, Zt = 0xffffffffffffffffn, er = "__browserdb:", ne = "__browserdb:index:", Lr = "__browserdb:indexes";
|
|
970
|
+
function tr(t) {
|
|
971
|
+
return t.startsWith(er);
|
|
972
|
+
}
|
|
973
|
+
function w(t) {
|
|
974
|
+
if (tr(t))
|
|
975
|
+
throw new ye(`reserved store name: ${t}`);
|
|
976
|
+
}
|
|
977
|
+
function G(t) {
|
|
978
|
+
if (t === void 0)
|
|
979
|
+
return [];
|
|
980
|
+
if (!Array.isArray(t))
|
|
981
|
+
throw new b("indexes must be an array");
|
|
982
|
+
const e = [], r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
|
|
983
|
+
for (const o of t) {
|
|
984
|
+
if (o === null || typeof o != "object" || Array.isArray(o))
|
|
985
|
+
throw new b("each index definition must be an object");
|
|
986
|
+
const { store: s, name: i, keyPath: d, unique: u } = o;
|
|
987
|
+
if (typeof s != "string" || s.length === 0)
|
|
988
|
+
throw new b("index store must be a non-empty string");
|
|
989
|
+
if (typeof i != "string" || i.length === 0)
|
|
990
|
+
throw new b("index name must be a non-empty string");
|
|
991
|
+
w(s);
|
|
992
|
+
const l = nr(d);
|
|
993
|
+
if (u !== void 0 && typeof u != "boolean")
|
|
994
|
+
throw new b("index unique must be a boolean");
|
|
995
|
+
const a = {
|
|
996
|
+
store: s,
|
|
997
|
+
name: i,
|
|
998
|
+
keyPath: l.paths,
|
|
999
|
+
compound: l.compound,
|
|
1000
|
+
unique: u ?? !1,
|
|
1001
|
+
internalStore: or(s, i)
|
|
1002
|
+
}, c = Ie(a.store, a.name);
|
|
1003
|
+
if (r.has(c))
|
|
1004
|
+
throw new b(`duplicate index definition ${a.store}.${a.name}`);
|
|
1005
|
+
r.add(c);
|
|
1006
|
+
const h = n.get(a.internalStore);
|
|
1007
|
+
if (h && h !== c)
|
|
1008
|
+
throw new b(
|
|
1009
|
+
`index definitions ${h} and ${c} map to the same internal store ${a.internalStore}`
|
|
1010
|
+
);
|
|
1011
|
+
n.set(a.internalStore, c), e.push(a);
|
|
1012
|
+
}
|
|
1013
|
+
return e.sort(rr), e;
|
|
1014
|
+
}
|
|
1015
|
+
function rr(t, e) {
|
|
1016
|
+
const r = L(t.store, e.store);
|
|
1017
|
+
if (r !== 0)
|
|
1018
|
+
return r;
|
|
1019
|
+
const n = L(t.name, e.name);
|
|
1020
|
+
if (n !== 0)
|
|
1021
|
+
return n;
|
|
1022
|
+
const o = Number(t.unique) - Number(e.unique);
|
|
1023
|
+
return o !== 0 ? o : L(ie(t), ie(e));
|
|
1024
|
+
}
|
|
1025
|
+
function Ie(t, e) {
|
|
1026
|
+
return `${t}\0${e}`;
|
|
1027
|
+
}
|
|
1028
|
+
function Cr(t, e, r) {
|
|
1029
|
+
return t.find((n) => n.store === e && n.name === r) ?? null;
|
|
1030
|
+
}
|
|
1031
|
+
function Nr(t, e) {
|
|
1032
|
+
return t.filter((r) => r.store === e);
|
|
1033
|
+
}
|
|
1034
|
+
function Ur(t, e) {
|
|
1035
|
+
return S([P(t), P(e)]);
|
|
1036
|
+
}
|
|
1037
|
+
function Dr(t) {
|
|
1038
|
+
return P(JSON.stringify(Te(t)));
|
|
1039
|
+
}
|
|
1040
|
+
function Wr(t) {
|
|
1041
|
+
let e;
|
|
1042
|
+
try {
|
|
1043
|
+
e = JSON.parse(Se.decode(t));
|
|
1044
|
+
} catch (n) {
|
|
1045
|
+
throw new _(`invalid persisted index metadata: ${String(n)}`);
|
|
1046
|
+
}
|
|
1047
|
+
const [r] = G([e]);
|
|
1048
|
+
return r;
|
|
1049
|
+
}
|
|
1050
|
+
function zr(t, e) {
|
|
1051
|
+
return S([t, e]);
|
|
1052
|
+
}
|
|
1053
|
+
function $r(t) {
|
|
1054
|
+
const e = Yt(t);
|
|
1055
|
+
if (e.length !== 2)
|
|
1056
|
+
throw new _("invalid index entry key encoding");
|
|
1057
|
+
return {
|
|
1058
|
+
logicalKey: e[0],
|
|
1059
|
+
primaryKey: e[1]
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
function Fr(t) {
|
|
1063
|
+
return xe(S([t]));
|
|
1064
|
+
}
|
|
1065
|
+
function Vr(t = {}) {
|
|
1066
|
+
cr(t);
|
|
1067
|
+
const e = {};
|
|
1068
|
+
if (t.reverse !== void 0 && (e.reverse = t.reverse), t.limit !== void 0 && (e.limit = t.limit), t.gte && (e.gte = S([t.gte])), t.gt) {
|
|
1069
|
+
const r = F(S([t.gt]));
|
|
1070
|
+
r && (e.gte = r);
|
|
1071
|
+
}
|
|
1072
|
+
if (t.lt && (e.lt = S([t.lt])), t.lte) {
|
|
1073
|
+
const r = F(S([t.lte]));
|
|
1074
|
+
r && (e.lt = r);
|
|
1075
|
+
}
|
|
1076
|
+
return e;
|
|
1077
|
+
}
|
|
1078
|
+
function jr(t, e) {
|
|
1079
|
+
const r = ir(e);
|
|
1080
|
+
if (t.compound) {
|
|
1081
|
+
const o = [];
|
|
1082
|
+
for (const s of t.keyPath) {
|
|
1083
|
+
const i = ce(r, s);
|
|
1084
|
+
if (i === U)
|
|
1085
|
+
return null;
|
|
1086
|
+
o.push(ue(i));
|
|
1087
|
+
}
|
|
1088
|
+
return S(o);
|
|
1089
|
+
}
|
|
1090
|
+
const n = ce(r, t.keyPath[0]);
|
|
1091
|
+
return n === U ? null : ue(n);
|
|
1092
|
+
}
|
|
1093
|
+
function oe(t) {
|
|
1094
|
+
return JSON.stringify(Pe(t));
|
|
1095
|
+
}
|
|
1096
|
+
function Kr(t) {
|
|
1097
|
+
return t.map((e) => ({
|
|
1098
|
+
store: e.store,
|
|
1099
|
+
name: e.name,
|
|
1100
|
+
keyPath: [...e.keyPath],
|
|
1101
|
+
compound: e.compound,
|
|
1102
|
+
unique: e.unique,
|
|
1103
|
+
internalStore: e.internalStore
|
|
1104
|
+
}));
|
|
1105
|
+
}
|
|
1106
|
+
function Pe(t) {
|
|
1107
|
+
return t.map(Te);
|
|
1108
|
+
}
|
|
1109
|
+
function Te(t) {
|
|
1110
|
+
return {
|
|
1111
|
+
store: t.store,
|
|
1112
|
+
name: t.name,
|
|
1113
|
+
keyPath: t.compound ? [...t.keyPath] : t.keyPath[0],
|
|
1114
|
+
unique: t.unique
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
function nr(t) {
|
|
1118
|
+
if (typeof t == "string")
|
|
1119
|
+
return se(t), { paths: [t], compound: !1 };
|
|
1120
|
+
if (!Array.isArray(t) || t.length === 0 || t.some((e) => typeof e != "string"))
|
|
1121
|
+
throw new b("index keyPath must be a non-empty string or non-empty string[]");
|
|
1122
|
+
for (const e of t)
|
|
1123
|
+
se(e);
|
|
1124
|
+
return { paths: [...t], compound: !0 };
|
|
1125
|
+
}
|
|
1126
|
+
function se(t) {
|
|
1127
|
+
if (t.length === 0)
|
|
1128
|
+
throw new b("index keyPath strings must be non-empty");
|
|
1129
|
+
if (t.startsWith(".") || t.endsWith(".") || t.includes(".."))
|
|
1130
|
+
throw new b(`invalid index keyPath: ${t}`);
|
|
1131
|
+
}
|
|
1132
|
+
function ie(t) {
|
|
1133
|
+
return t.compound ? `[${t.keyPath.join(",")}]` : t.keyPath[0];
|
|
1134
|
+
}
|
|
1135
|
+
function or(t, e) {
|
|
1136
|
+
const r = ae(P(t)), n = ae(P(e)), o = `${ne}${r}:${n}`;
|
|
1137
|
+
if (Gt.encode(o).length <= 255)
|
|
1138
|
+
return o;
|
|
1139
|
+
const s = P(Ie(t, e));
|
|
1140
|
+
return `${ne}h:${sr(s)}`;
|
|
1141
|
+
}
|
|
1142
|
+
function ae(t) {
|
|
1143
|
+
let e = "";
|
|
1144
|
+
for (const r of t)
|
|
1145
|
+
e += String.fromCharCode(r);
|
|
1146
|
+
return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/u, "");
|
|
1147
|
+
}
|
|
1148
|
+
function sr(t) {
|
|
1149
|
+
let e = Xt;
|
|
1150
|
+
for (const r of t)
|
|
1151
|
+
e ^= BigInt(r), e = e * Qt & Zt;
|
|
1152
|
+
return e.toString(16).padStart(16, "0");
|
|
1153
|
+
}
|
|
1154
|
+
function ir(t) {
|
|
1155
|
+
try {
|
|
1156
|
+
return JSON.parse(Se.decode(t));
|
|
1157
|
+
} catch (e) {
|
|
1158
|
+
throw new _(`indexed values must be valid UTF-8 JSON: ${String(e)}`);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
function ce(t, e) {
|
|
1162
|
+
let r = t;
|
|
1163
|
+
for (const n of e.split(".")) {
|
|
1164
|
+
if (r == null)
|
|
1165
|
+
return U;
|
|
1166
|
+
const o = Object(r);
|
|
1167
|
+
if (!(n in o))
|
|
1168
|
+
return U;
|
|
1169
|
+
r = Reflect.get(o, n);
|
|
1170
|
+
}
|
|
1171
|
+
return r;
|
|
1172
|
+
}
|
|
1173
|
+
function ue(t) {
|
|
1174
|
+
if (t instanceof Uint8Array || t === null || typeof t == "string" || typeof t == "number" || typeof t == "boolean")
|
|
1175
|
+
return re(t);
|
|
1176
|
+
throw new _(
|
|
1177
|
+
`indexed keyPath values must resolve to string, number, boolean, null, or Uint8Array; got ${ar(t)}`
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
function ar(t) {
|
|
1181
|
+
return Array.isArray(t) ? "array" : t === null ? "null" : typeof t;
|
|
1182
|
+
}
|
|
1183
|
+
function cr(t) {
|
|
1184
|
+
if (t.gt !== void 0 && t.gte !== void 0)
|
|
1185
|
+
throw new TypeError("index range cannot specify both gt and gte");
|
|
1186
|
+
if (t.lt !== void 0 && t.lte !== void 0)
|
|
1187
|
+
throw new TypeError("index range cannot specify both lt and lte");
|
|
1188
|
+
}
|
|
1189
|
+
function ur(t) {
|
|
1190
|
+
return v(t) && t.key instanceof Uint8Array && (t.kind === "put" || t.kind === "delete");
|
|
1191
|
+
}
|
|
1192
|
+
function lr(t) {
|
|
1193
|
+
return v(t) && typeof t.store == "string" && Array.isArray(t.changes) && t.changes.every(ur);
|
|
1194
|
+
}
|
|
1195
|
+
function dr(t) {
|
|
1196
|
+
return v(t) && t.type === "commit_applied" && typeof t.dbName == "string" && typeof t.txid == "number" && Array.isArray(t.stores) && t.stores.every(lr);
|
|
1197
|
+
}
|
|
1198
|
+
function le(t) {
|
|
1199
|
+
return t.map((e) => ({
|
|
1200
|
+
key: e.key.slice(),
|
|
1201
|
+
kind: e.kind
|
|
1202
|
+
}));
|
|
1203
|
+
}
|
|
1204
|
+
function hr(t, e) {
|
|
1205
|
+
if (e.byteLength > t.byteLength)
|
|
1206
|
+
return !1;
|
|
1207
|
+
for (let r = 0; r < e.byteLength; r += 1)
|
|
1208
|
+
if (t[r] !== e[r])
|
|
1209
|
+
return !1;
|
|
1210
|
+
return !0;
|
|
1211
|
+
}
|
|
1212
|
+
function fr(t, e, r) {
|
|
1213
|
+
if (typeof t == "function") {
|
|
1214
|
+
if (e !== void 0 || r !== void 0)
|
|
1215
|
+
throw new TypeError("subscribe(callback) accepts exactly one callback argument");
|
|
1216
|
+
return {
|
|
1217
|
+
store: null,
|
|
1218
|
+
keyPrefix: null,
|
|
1219
|
+
callback: t
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
if (typeof t != "string")
|
|
1223
|
+
throw new TypeError("subscribe() storeName must be a string");
|
|
1224
|
+
if (w(t), typeof e == "function") {
|
|
1225
|
+
if (r !== void 0)
|
|
1226
|
+
throw new TypeError("subscribe(storeName, callback) accepts exactly two arguments");
|
|
1227
|
+
return {
|
|
1228
|
+
store: t,
|
|
1229
|
+
keyPrefix: null,
|
|
1230
|
+
callback: e
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
if (e instanceof Uint8Array && typeof r == "function")
|
|
1234
|
+
return {
|
|
1235
|
+
store: t,
|
|
1236
|
+
keyPrefix: e.slice(),
|
|
1237
|
+
callback: r
|
|
1238
|
+
};
|
|
1239
|
+
throw new TypeError(
|
|
1240
|
+
"subscribe() expects one of: (callback), (storeName, callback), (storeName, keyPrefix, callback)"
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
class yr {
|
|
1244
|
+
#e;
|
|
1245
|
+
#t = null;
|
|
1246
|
+
#n = /* @__PURE__ */ new Set();
|
|
1247
|
+
#s = !1;
|
|
1248
|
+
constructor(e) {
|
|
1249
|
+
this.#e = e;
|
|
1250
|
+
}
|
|
1251
|
+
subscribe(e, r, n) {
|
|
1252
|
+
if (this.#s)
|
|
1253
|
+
throw new H();
|
|
1254
|
+
const o = fr(e, r, n), s = {
|
|
1255
|
+
active: !0,
|
|
1256
|
+
store: o.store,
|
|
1257
|
+
keyPrefix: o.keyPrefix,
|
|
1258
|
+
callback: o.callback
|
|
1259
|
+
};
|
|
1260
|
+
return this.#r(), this.#n.add(s), () => {
|
|
1261
|
+
s.active && (s.active = !1, this.#n.delete(s), this.#n.size === 0 && this.#i());
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
close() {
|
|
1265
|
+
this.#s || (this.#s = !0, this.#n.clear(), this.#i());
|
|
1266
|
+
}
|
|
1267
|
+
#r() {
|
|
1268
|
+
if (this.#t !== null || this.#s)
|
|
1269
|
+
return;
|
|
1270
|
+
const e = new BroadcastChannel(`db:${this.#e}:events`);
|
|
1271
|
+
e.onmessage = (r) => {
|
|
1272
|
+
this.#c(r.data);
|
|
1273
|
+
}, this.#t = e;
|
|
1274
|
+
}
|
|
1275
|
+
#i() {
|
|
1276
|
+
this.#t?.close(), this.#t = null;
|
|
1277
|
+
}
|
|
1278
|
+
#c(e) {
|
|
1279
|
+
if (!dr(e) || e.dbName !== this.#e || this.#n.size === 0)
|
|
1280
|
+
return;
|
|
1281
|
+
const r = Array.from(this.#n);
|
|
1282
|
+
for (const n of e.stores)
|
|
1283
|
+
for (const o of r) {
|
|
1284
|
+
if (!o.active || o.store !== null && o.store !== n.store)
|
|
1285
|
+
continue;
|
|
1286
|
+
let s;
|
|
1287
|
+
if (o.keyPrefix === null)
|
|
1288
|
+
s = le(n.changes);
|
|
1289
|
+
else if (s = le(
|
|
1290
|
+
n.changes.filter((i) => hr(i.key, o.keyPrefix))
|
|
1291
|
+
), s.length === 0)
|
|
1292
|
+
continue;
|
|
1293
|
+
try {
|
|
1294
|
+
o.callback(n.store, s, e.txid);
|
|
1295
|
+
} catch (i) {
|
|
1296
|
+
queueMicrotask(() => {
|
|
1297
|
+
throw i;
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
async function f(t) {
|
|
1304
|
+
try {
|
|
1305
|
+
return await t();
|
|
1306
|
+
} catch (e) {
|
|
1307
|
+
throw x(e);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
class pr {
|
|
1311
|
+
mode;
|
|
1312
|
+
#e;
|
|
1313
|
+
#t;
|
|
1314
|
+
#n = !1;
|
|
1315
|
+
#s;
|
|
1316
|
+
constructor(e, r, n, o) {
|
|
1317
|
+
this.#e = e, this.#t = r, this.mode = n, this.#s = o;
|
|
1318
|
+
}
|
|
1319
|
+
async get(e, r) {
|
|
1320
|
+
return this.#r(), w(e), f(() => this.#e.proxy.get(this.#t, e, r));
|
|
1321
|
+
}
|
|
1322
|
+
async getMany(e, r) {
|
|
1323
|
+
return this.#r(), w(e), f(() => this.#e.proxy.getMany(this.#t, e, r));
|
|
1324
|
+
}
|
|
1325
|
+
async has(e, r) {
|
|
1326
|
+
return this.#r(), w(e), f(() => this.#e.proxy.has(this.#t, e, r));
|
|
1327
|
+
}
|
|
1328
|
+
async put(e, r, n, o = {}) {
|
|
1329
|
+
return this.#r(), w(e), f(() => this.#e.proxy.put(this.#t, e, r, n, V(o)));
|
|
1330
|
+
}
|
|
1331
|
+
async putMany(e, r, n = {}) {
|
|
1332
|
+
return this.#r(), w(e), f(() => this.#e.proxy.putMany(this.#t, e, r, V(n)));
|
|
1333
|
+
}
|
|
1334
|
+
async delete(e, r) {
|
|
1335
|
+
return this.#r(), w(e), f(() => this.#e.proxy.delete(this.#t, e, r));
|
|
1336
|
+
}
|
|
1337
|
+
async deleteMany(e, r) {
|
|
1338
|
+
return this.#r(), w(e), f(() => this.#e.proxy.deleteMany(this.#t, e, r));
|
|
1339
|
+
}
|
|
1340
|
+
async applyBatch(e, r) {
|
|
1341
|
+
return this.#r(), w(e), f(() => this.#e.proxy.applyBatch(this.#t, e, r));
|
|
1342
|
+
}
|
|
1343
|
+
async scan(e, r = {}) {
|
|
1344
|
+
return this.#r(), w(e), f(() => this.#e.proxy.scan(this.#t, e, r));
|
|
1345
|
+
}
|
|
1346
|
+
async getByIndex(e, r, n) {
|
|
1347
|
+
return this.#r(), w(e), f(() => this.#e.proxy.getByIndex(this.#t, e, r, n));
|
|
1348
|
+
}
|
|
1349
|
+
async *scanByIndex(e, r, n = {}) {
|
|
1350
|
+
this.#r(), w(e);
|
|
1351
|
+
const o = await f(() => this.#e.proxy.scanByIndex(this.#t, e, r, n));
|
|
1352
|
+
for (const s of o)
|
|
1353
|
+
yield [s.key, s.value];
|
|
1354
|
+
}
|
|
1355
|
+
async createStore(e, r = {}) {
|
|
1356
|
+
return this.#r(), w(e), f(() => this.#e.proxy.createStore(this.#t, e, Re(r)));
|
|
1357
|
+
}
|
|
1358
|
+
async dropStore(e) {
|
|
1359
|
+
return this.#r(), w(e), f(() => this.#e.proxy.dropStore(this.#t, e));
|
|
1360
|
+
}
|
|
1361
|
+
async clearStore(e) {
|
|
1362
|
+
return this.#r(), w(e), f(() => this.#e.proxy.clearStore(this.#t, e));
|
|
1363
|
+
}
|
|
1364
|
+
async commit() {
|
|
1365
|
+
this.#r();
|
|
1366
|
+
try {
|
|
1367
|
+
await f(() => this.#e.proxy.commit(this.#t));
|
|
1368
|
+
} finally {
|
|
1369
|
+
this.#i();
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
async rollback() {
|
|
1373
|
+
this.#r();
|
|
1374
|
+
try {
|
|
1375
|
+
await f(() => this.#e.proxy.rollback(this.#t));
|
|
1376
|
+
} finally {
|
|
1377
|
+
this.#i();
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
async rollbackIfOpen() {
|
|
1381
|
+
if (!this.#n) {
|
|
1382
|
+
if (this.#e.invalidated) {
|
|
1383
|
+
this.#i();
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
try {
|
|
1387
|
+
await this.#e.proxy.rollback(this.#t);
|
|
1388
|
+
} catch (e) {
|
|
1389
|
+
const r = x(e);
|
|
1390
|
+
if (!(r instanceof z))
|
|
1391
|
+
throw r;
|
|
1392
|
+
} finally {
|
|
1393
|
+
this.#i();
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
forceClose() {
|
|
1398
|
+
this.#i();
|
|
1399
|
+
}
|
|
1400
|
+
internalId() {
|
|
1401
|
+
return this.#t;
|
|
1402
|
+
}
|
|
1403
|
+
#r() {
|
|
1404
|
+
if (this.#n || this.#e.invalidated)
|
|
1405
|
+
throw new z();
|
|
1406
|
+
}
|
|
1407
|
+
#i() {
|
|
1408
|
+
this.#n || (this.#n = !0, this.#s());
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
class br {
|
|
1412
|
+
#e;
|
|
1413
|
+
#t = !1;
|
|
1414
|
+
#n = /* @__PURE__ */ new Set();
|
|
1415
|
+
#s;
|
|
1416
|
+
#r = null;
|
|
1417
|
+
#i = null;
|
|
1418
|
+
constructor(e) {
|
|
1419
|
+
this.#e = e, this.#s = new yr(e.dbName), this.#r = _t(e, () => {
|
|
1420
|
+
this.#l();
|
|
1421
|
+
}), this.#i = Bt(e, () => {
|
|
1422
|
+
this.#d();
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
async begin(e = "readonly") {
|
|
1426
|
+
return this.#c(e);
|
|
1427
|
+
}
|
|
1428
|
+
async runSchemaMigration(e, r, n, o) {
|
|
1429
|
+
this.#o();
|
|
1430
|
+
const s = await this.#c("readwrite"), i = new wr(), d = new gr(s, i), u = new mr(this, d, i);
|
|
1431
|
+
try {
|
|
1432
|
+
await this.#e.proxy.reconcileIndexes(s.internalId(), o), await n({
|
|
1433
|
+
db: u,
|
|
1434
|
+
oldVersion: e,
|
|
1435
|
+
newVersion: r,
|
|
1436
|
+
transaction: d
|
|
1437
|
+
}), await this.#e.proxy.setSchemaVersion(s.internalId(), r), await s.commit();
|
|
1438
|
+
} catch (l) {
|
|
1439
|
+
try {
|
|
1440
|
+
await s.rollbackIfOpen();
|
|
1441
|
+
} catch {
|
|
1442
|
+
}
|
|
1443
|
+
throw l;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
async listStores() {
|
|
1447
|
+
return this.#o(), f(() => this.#e.proxy.listStores());
|
|
1448
|
+
}
|
|
1449
|
+
async getVersion() {
|
|
1450
|
+
return this.#o(), f(() => this.#e.proxy.getVersion());
|
|
1451
|
+
}
|
|
1452
|
+
async changesSince(e, r = {}) {
|
|
1453
|
+
return this.#o(), f(
|
|
1454
|
+
() => this.#e.proxy.changesSince(Sr(e), Ir(r))
|
|
1455
|
+
);
|
|
1456
|
+
}
|
|
1457
|
+
async #c(e) {
|
|
1458
|
+
return this.#o(), f(async () => {
|
|
1459
|
+
const r = await this.#e.proxy.begin(e);
|
|
1460
|
+
let n;
|
|
1461
|
+
return n = new pr(this.#e, r, e, () => {
|
|
1462
|
+
this.#n.delete(n);
|
|
1463
|
+
}), this.#n.add(n), n;
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
async createStore(e, r = {}) {
|
|
1467
|
+
await this.#a("readwrite", async (n) => {
|
|
1468
|
+
await n.createStore(e, Re(r));
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
async dropStore(e) {
|
|
1472
|
+
await this.#a("readwrite", async (r) => {
|
|
1473
|
+
await r.dropStore(e);
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
async clearStore(e) {
|
|
1477
|
+
await this.#a("readwrite", async (r) => {
|
|
1478
|
+
await r.clearStore(e);
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
async get(e, r) {
|
|
1482
|
+
return this.#a("readonly", (n) => n.get(e, r));
|
|
1483
|
+
}
|
|
1484
|
+
async getMany(e, r) {
|
|
1485
|
+
return this.#a("readonly", (n) => n.getMany(e, r));
|
|
1486
|
+
}
|
|
1487
|
+
async has(e, r) {
|
|
1488
|
+
return this.#a("readonly", (n) => n.has(e, r));
|
|
1489
|
+
}
|
|
1490
|
+
async put(e, r, n, o = {}) {
|
|
1491
|
+
await this.#a("readwrite", async (s) => {
|
|
1492
|
+
await s.put(e, r, n, V(o));
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
async delete(e, r) {
|
|
1496
|
+
return this.#a("readwrite", (n) => n.delete(e, r));
|
|
1497
|
+
}
|
|
1498
|
+
async scan(e, r = {}) {
|
|
1499
|
+
return this.#a("readonly", (n) => n.scan(e, r));
|
|
1500
|
+
}
|
|
1501
|
+
async exportSnapshot(e = {}) {
|
|
1502
|
+
return this.#o(), f(async () => {
|
|
1503
|
+
const r = await this.#e.proxy.exportSnapshot(Er(e));
|
|
1504
|
+
return r instanceof Uint8Array ? r : new Uint8Array(r);
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
async importSnapshot(e) {
|
|
1508
|
+
return this.#o(), f(() => {
|
|
1509
|
+
const r = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1510
|
+
return this.#e.proxy.importSnapshot(r);
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
async reset() {
|
|
1514
|
+
return this.#o(), N(this.#e), f(() => this.#e.proxy.reset());
|
|
1515
|
+
}
|
|
1516
|
+
async compact() {
|
|
1517
|
+
return this.#o(), N(this.#e), f(() => this.#e.proxy.compact());
|
|
1518
|
+
}
|
|
1519
|
+
async rebuild() {
|
|
1520
|
+
return this.#o(), N(this.#e), f(() => this.#e.proxy.rebuild());
|
|
1521
|
+
}
|
|
1522
|
+
async stats() {
|
|
1523
|
+
return this.#o(), f(() => this.#e.proxy.stats());
|
|
1524
|
+
}
|
|
1525
|
+
async storageInfo() {
|
|
1526
|
+
return this.#o(), f(() => this.#e.proxy.storageInfo());
|
|
1527
|
+
}
|
|
1528
|
+
async requestPersistence() {
|
|
1529
|
+
return this.#o(), f(() => this.#e.proxy.requestPersistence());
|
|
1530
|
+
}
|
|
1531
|
+
async destroy() {
|
|
1532
|
+
return this.#o(), f(() => ge(this.#e));
|
|
1533
|
+
}
|
|
1534
|
+
async setFailpoint(e) {
|
|
1535
|
+
return this.#o(), f(() => this.#e.proxy.setFailpoint(e));
|
|
1536
|
+
}
|
|
1537
|
+
subscribe(e, r, n) {
|
|
1538
|
+
if (this.#o(), typeof e == "function")
|
|
1539
|
+
return this.#s.subscribe(e);
|
|
1540
|
+
if (typeof r == "function")
|
|
1541
|
+
return this.#s.subscribe(e, r);
|
|
1542
|
+
if (r instanceof Uint8Array && typeof n == "function")
|
|
1543
|
+
return this.#s.subscribe(e, r, n);
|
|
1544
|
+
throw new TypeError(
|
|
1545
|
+
"subscribe() expects one of: (callback), (storeName, callback), (storeName, keyPrefix, callback)"
|
|
1546
|
+
);
|
|
1547
|
+
}
|
|
1548
|
+
watch(e, r, n) {
|
|
1549
|
+
if (typeof e == "function")
|
|
1550
|
+
return this.subscribe(e);
|
|
1551
|
+
if (typeof r == "function")
|
|
1552
|
+
return this.subscribe(e, r);
|
|
1553
|
+
if (r instanceof Uint8Array && typeof n == "function")
|
|
1554
|
+
return this.subscribe(e, r, n);
|
|
1555
|
+
throw new TypeError(
|
|
1556
|
+
"watch() expects one of: (callback), (storeName, callback), (storeName, keyPrefix, callback)"
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
async close() {
|
|
1560
|
+
if (this.#t)
|
|
1561
|
+
return;
|
|
1562
|
+
this.#t = !0, this.#u(), this.#s.close();
|
|
1563
|
+
let e = null;
|
|
1564
|
+
const r = Array.from(this.#n);
|
|
1565
|
+
if (r.length > 0) {
|
|
1566
|
+
const n = await Promise.allSettled(r.map((o) => o.rollbackIfOpen()));
|
|
1567
|
+
for (const o of n)
|
|
1568
|
+
o.status === "rejected" && e === null && (e = x(o.reason));
|
|
1569
|
+
}
|
|
1570
|
+
try {
|
|
1571
|
+
await Ct(this.#e);
|
|
1572
|
+
} catch (n) {
|
|
1573
|
+
throw x(n);
|
|
1574
|
+
}
|
|
1575
|
+
if (e)
|
|
1576
|
+
throw e;
|
|
1577
|
+
}
|
|
1578
|
+
async #a(e, r) {
|
|
1579
|
+
const n = await this.begin(e);
|
|
1580
|
+
try {
|
|
1581
|
+
const o = await r(n);
|
|
1582
|
+
return e === "readwrite" ? await n.commit() : await n.rollback(), o;
|
|
1583
|
+
} catch (o) {
|
|
1584
|
+
try {
|
|
1585
|
+
await n.rollback();
|
|
1586
|
+
} catch {
|
|
1587
|
+
}
|
|
1588
|
+
throw o;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
#u() {
|
|
1592
|
+
this.#r?.(), this.#r = null, this.#i?.(), this.#i = null;
|
|
1593
|
+
}
|
|
1594
|
+
#l() {
|
|
1595
|
+
for (const e of Array.from(this.#n))
|
|
1596
|
+
e.forceClose();
|
|
1597
|
+
}
|
|
1598
|
+
#d() {
|
|
1599
|
+
this.#t || (this.#t = !0, this.#u(), this.#l(), this.#s.close());
|
|
1600
|
+
}
|
|
1601
|
+
#o() {
|
|
1602
|
+
if (this.#t || this.#e.invalidated)
|
|
1603
|
+
throw new H();
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
class wr {
|
|
1607
|
+
#e = /* @__PURE__ */ new Set();
|
|
1608
|
+
#t = /* @__PURE__ */ new Set();
|
|
1609
|
+
recordCreate(e) {
|
|
1610
|
+
this.#t.delete(e), this.#e.add(e);
|
|
1611
|
+
}
|
|
1612
|
+
recordDrop(e) {
|
|
1613
|
+
this.#e.delete(e) || this.#t.add(e);
|
|
1614
|
+
}
|
|
1615
|
+
apply(e) {
|
|
1616
|
+
const r = new Set(e);
|
|
1617
|
+
for (const n of this.#e)
|
|
1618
|
+
r.add(n);
|
|
1619
|
+
for (const n of this.#t)
|
|
1620
|
+
r.delete(n);
|
|
1621
|
+
return Array.from(r).sort(L);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
class gr {
|
|
1625
|
+
#e;
|
|
1626
|
+
#t;
|
|
1627
|
+
constructor(e, r) {
|
|
1628
|
+
this.#e = e, this.#t = r;
|
|
1629
|
+
}
|
|
1630
|
+
get mode() {
|
|
1631
|
+
return this.#e.mode;
|
|
1632
|
+
}
|
|
1633
|
+
async get(e, r) {
|
|
1634
|
+
return this.#e.get(e, r);
|
|
1635
|
+
}
|
|
1636
|
+
async getMany(e, r) {
|
|
1637
|
+
return this.#e.getMany(e, r);
|
|
1638
|
+
}
|
|
1639
|
+
async has(e, r) {
|
|
1640
|
+
return this.#e.has(e, r);
|
|
1641
|
+
}
|
|
1642
|
+
async put(e, r, n, o = {}) {
|
|
1643
|
+
await this.#e.put(e, r, n, o);
|
|
1644
|
+
}
|
|
1645
|
+
async putMany(e, r, n = {}) {
|
|
1646
|
+
await this.#e.putMany(e, r, n);
|
|
1647
|
+
}
|
|
1648
|
+
async delete(e, r) {
|
|
1649
|
+
return this.#e.delete(e, r);
|
|
1650
|
+
}
|
|
1651
|
+
async deleteMany(e, r) {
|
|
1652
|
+
await this.#e.deleteMany(e, r);
|
|
1653
|
+
}
|
|
1654
|
+
async applyBatch(e, r) {
|
|
1655
|
+
await this.#e.applyBatch(e, r);
|
|
1656
|
+
}
|
|
1657
|
+
async scan(e, r = {}) {
|
|
1658
|
+
return this.#e.scan(e, r);
|
|
1659
|
+
}
|
|
1660
|
+
async getByIndex(e, r, n) {
|
|
1661
|
+
return this.#e.getByIndex(e, r, n);
|
|
1662
|
+
}
|
|
1663
|
+
scanByIndex(e, r, n = {}) {
|
|
1664
|
+
return this.#e.scanByIndex(e, r, n);
|
|
1665
|
+
}
|
|
1666
|
+
async createStore(e, r = {}) {
|
|
1667
|
+
await this.#e.createStore(e, r), this.#t.recordCreate(e);
|
|
1668
|
+
}
|
|
1669
|
+
async dropStore(e) {
|
|
1670
|
+
await this.#e.dropStore(e), this.#t.recordDrop(e);
|
|
1671
|
+
}
|
|
1672
|
+
async clearStore(e) {
|
|
1673
|
+
await this.#e.clearStore(e);
|
|
1674
|
+
}
|
|
1675
|
+
async commit() {
|
|
1676
|
+
throw m("transaction.commit");
|
|
1677
|
+
}
|
|
1678
|
+
async rollback() {
|
|
1679
|
+
throw m("transaction.rollback");
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
class mr {
|
|
1683
|
+
#e;
|
|
1684
|
+
#t;
|
|
1685
|
+
#n;
|
|
1686
|
+
constructor(e, r, n) {
|
|
1687
|
+
this.#e = e, this.#t = r, this.#n = n;
|
|
1688
|
+
}
|
|
1689
|
+
async begin(e = "readonly") {
|
|
1690
|
+
throw m("db.begin");
|
|
1691
|
+
}
|
|
1692
|
+
async createStore(e, r = {}) {
|
|
1693
|
+
await this.#t.createStore(e, r);
|
|
1694
|
+
}
|
|
1695
|
+
async dropStore(e) {
|
|
1696
|
+
await this.#t.dropStore(e);
|
|
1697
|
+
}
|
|
1698
|
+
async clearStore(e) {
|
|
1699
|
+
await this.#t.clearStore(e);
|
|
1700
|
+
}
|
|
1701
|
+
async listStores() {
|
|
1702
|
+
return this.#n.apply(await this.#e.listStores());
|
|
1703
|
+
}
|
|
1704
|
+
async getVersion() {
|
|
1705
|
+
return this.#e.getVersion();
|
|
1706
|
+
}
|
|
1707
|
+
async changesSince(e, r = {}) {
|
|
1708
|
+
throw m("db.changesSince");
|
|
1709
|
+
}
|
|
1710
|
+
async get(e, r) {
|
|
1711
|
+
return this.#t.get(e, r);
|
|
1712
|
+
}
|
|
1713
|
+
async getMany(e, r) {
|
|
1714
|
+
return this.#t.getMany(e, r);
|
|
1715
|
+
}
|
|
1716
|
+
async has(e, r) {
|
|
1717
|
+
return this.#t.has(e, r);
|
|
1718
|
+
}
|
|
1719
|
+
async put(e, r, n, o = {}) {
|
|
1720
|
+
await this.#t.put(e, r, n, o);
|
|
1721
|
+
}
|
|
1722
|
+
async delete(e, r) {
|
|
1723
|
+
return this.#t.delete(e, r);
|
|
1724
|
+
}
|
|
1725
|
+
async scan(e, r = {}) {
|
|
1726
|
+
return this.#t.scan(e, r);
|
|
1727
|
+
}
|
|
1728
|
+
async exportSnapshot(e = {}) {
|
|
1729
|
+
throw m("db.exportSnapshot");
|
|
1730
|
+
}
|
|
1731
|
+
async importSnapshot(e) {
|
|
1732
|
+
throw m("db.importSnapshot");
|
|
1733
|
+
}
|
|
1734
|
+
async reset() {
|
|
1735
|
+
throw m("db.reset");
|
|
1736
|
+
}
|
|
1737
|
+
async compact() {
|
|
1738
|
+
throw m("db.compact");
|
|
1739
|
+
}
|
|
1740
|
+
async rebuild() {
|
|
1741
|
+
throw m("db.rebuild");
|
|
1742
|
+
}
|
|
1743
|
+
async stats() {
|
|
1744
|
+
return this.#e.stats();
|
|
1745
|
+
}
|
|
1746
|
+
async storageInfo() {
|
|
1747
|
+
return this.#e.storageInfo();
|
|
1748
|
+
}
|
|
1749
|
+
async requestPersistence() {
|
|
1750
|
+
return this.#e.requestPersistence();
|
|
1751
|
+
}
|
|
1752
|
+
async close() {
|
|
1753
|
+
throw m("db.close");
|
|
1754
|
+
}
|
|
1755
|
+
async destroy() {
|
|
1756
|
+
throw m("db.destroy");
|
|
1757
|
+
}
|
|
1758
|
+
async setFailpoint(e) {
|
|
1759
|
+
throw m("db.setFailpoint");
|
|
1760
|
+
}
|
|
1761
|
+
subscribe(e, r, n) {
|
|
1762
|
+
throw m("db.subscribe");
|
|
1763
|
+
}
|
|
1764
|
+
watch(e, r, n) {
|
|
1765
|
+
throw m("db.watch");
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
function m(t) {
|
|
1769
|
+
const e = new Error(
|
|
1770
|
+
`${t}() is not available inside openDB() migrations; use the provided migration transaction and wait for openDB() to resolve`
|
|
1771
|
+
);
|
|
1772
|
+
return e.name = "InvalidStateError", e;
|
|
1773
|
+
}
|
|
1774
|
+
function X(t, e) {
|
|
1775
|
+
if (typeof t != "string" || t.length === 0)
|
|
1776
|
+
throw new TypeError(`${e}() database name must be a non-empty string`);
|
|
1777
|
+
return t;
|
|
1778
|
+
}
|
|
1779
|
+
const Ae = (t) => new TypeError(t), Oe = (t) => new b(t);
|
|
1780
|
+
function D(t, e, r = Ae) {
|
|
1781
|
+
if (t === void 0)
|
|
1782
|
+
return {};
|
|
1783
|
+
if (t === null || typeof t != "object" || Array.isArray(t))
|
|
1784
|
+
throw r(e);
|
|
1785
|
+
return t;
|
|
1786
|
+
}
|
|
1787
|
+
function ve(t, e, r = Ae) {
|
|
1788
|
+
if (typeof t != "number" || !Number.isSafeInteger(t) || t < 0)
|
|
1789
|
+
throw r(e);
|
|
1790
|
+
return t;
|
|
1791
|
+
}
|
|
1792
|
+
function Q(t, e, r) {
|
|
1793
|
+
return t === void 0 ? void 0 : ve(t, e, r);
|
|
1794
|
+
}
|
|
1795
|
+
function kr(t) {
|
|
1796
|
+
return D(t, "open options must be an object", Oe);
|
|
1797
|
+
}
|
|
1798
|
+
function xr(t) {
|
|
1799
|
+
return Q(
|
|
1800
|
+
t,
|
|
1801
|
+
"version must be a non-negative safe integer",
|
|
1802
|
+
Oe
|
|
1803
|
+
);
|
|
1804
|
+
}
|
|
1805
|
+
function V(t) {
|
|
1806
|
+
const { ttl: e } = D(t, "put options must be an object"), r = Q(e, "ttl must be a non-negative safe integer");
|
|
1807
|
+
return r === void 0 ? {} : { ttl: r };
|
|
1808
|
+
}
|
|
1809
|
+
function Me(t, e) {
|
|
1810
|
+
const { compression: r } = D(t, e);
|
|
1811
|
+
if (r === void 0)
|
|
1812
|
+
return {};
|
|
1813
|
+
if (r !== !1 && r !== "gzip" && r !== "deflate")
|
|
1814
|
+
throw new TypeError('compression must be "gzip", "deflate", or false');
|
|
1815
|
+
return { compression: r };
|
|
1816
|
+
}
|
|
1817
|
+
function Re(t) {
|
|
1818
|
+
return Me(t, "createStore options must be an object");
|
|
1819
|
+
}
|
|
1820
|
+
function Er(t) {
|
|
1821
|
+
return Me(t, "exportSnapshot options must be an object");
|
|
1822
|
+
}
|
|
1823
|
+
function Sr(t) {
|
|
1824
|
+
return ve(t, "txid must be a non-negative safe integer");
|
|
1825
|
+
}
|
|
1826
|
+
function Ir(t) {
|
|
1827
|
+
const { stores: e, limit: r } = D(t, "change feed options must be an object"), n = {};
|
|
1828
|
+
if (e !== void 0) {
|
|
1829
|
+
if (!Array.isArray(e) || e.some((s) => typeof s != "string"))
|
|
1830
|
+
throw new TypeError("stores must be an array of strings");
|
|
1831
|
+
for (const s of e)
|
|
1832
|
+
w(s);
|
|
1833
|
+
n.stores = [...e];
|
|
1834
|
+
}
|
|
1835
|
+
const o = Q(r, "limit must be a non-negative safe integer");
|
|
1836
|
+
return o !== void 0 && (n.limit = o), n;
|
|
1837
|
+
}
|
|
1838
|
+
function Pr(t) {
|
|
1839
|
+
if (t !== void 0) {
|
|
1840
|
+
if (typeof t != "function")
|
|
1841
|
+
throw new b("migrate must be a function");
|
|
1842
|
+
return t;
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
function Tr(t) {
|
|
1846
|
+
if (t !== void 0)
|
|
1847
|
+
return G(t);
|
|
1848
|
+
}
|
|
1849
|
+
function Ar(t, e) {
|
|
1850
|
+
return oe(t) === oe(e);
|
|
1851
|
+
}
|
|
1852
|
+
async function Or(t) {
|
|
1853
|
+
return G(await t.proxy.getIndexes());
|
|
1854
|
+
}
|
|
1855
|
+
function _e() {
|
|
1856
|
+
if (!globalThis.isSecureContext)
|
|
1857
|
+
throw new O("moyodb requires a secure context (HTTPS)");
|
|
1858
|
+
const t = globalThis.navigator;
|
|
1859
|
+
if (!t?.storage)
|
|
1860
|
+
throw new O("navigator.storage is unavailable");
|
|
1861
|
+
if (typeof t.storage.getDirectory != "function")
|
|
1862
|
+
throw new O("navigator.storage.getDirectory is unavailable");
|
|
1863
|
+
if (typeof globalThis.Worker != "function")
|
|
1864
|
+
throw new O("Worker is unavailable");
|
|
1865
|
+
if (typeof globalThis.BroadcastChannel > "u")
|
|
1866
|
+
throw new O("BroadcastChannel is unavailable");
|
|
1867
|
+
if (!t.locks)
|
|
1868
|
+
throw new O("navigator.locks is unavailable");
|
|
1869
|
+
}
|
|
1870
|
+
async function vr(t) {
|
|
1871
|
+
const e = globalThis.navigator;
|
|
1872
|
+
(t.requestPersistence ?? !0) && typeof e?.storage?.persist == "function" && await j(e.storage.persist(), 1e3, !1);
|
|
1873
|
+
}
|
|
1874
|
+
async function Hr(t, e = {}) {
|
|
1875
|
+
const r = X(t, "openDB"), n = kr(e), o = xr(n.version), s = Pr(n.migrate), i = Tr(n.indexes);
|
|
1876
|
+
if (o === void 0 && s !== void 0)
|
|
1877
|
+
throw new b("migrate requires version");
|
|
1878
|
+
if (o === void 0 && i !== void 0)
|
|
1879
|
+
throw new b("indexes requires version");
|
|
1880
|
+
_e(), await vr(n);
|
|
1881
|
+
const d = await Lt(r, n), u = new br(d);
|
|
1882
|
+
let l = !1;
|
|
1883
|
+
try {
|
|
1884
|
+
if (o === void 0)
|
|
1885
|
+
return l = !0, u;
|
|
1886
|
+
const [a, c] = await Promise.all([u.getVersion(), Or(d)]);
|
|
1887
|
+
if (o < a)
|
|
1888
|
+
throw new C(
|
|
1889
|
+
`cannot open database ${r} at schema version ${o}; current schema version is ${a}`
|
|
1890
|
+
);
|
|
1891
|
+
if (o === a) {
|
|
1892
|
+
if (i !== void 0 && !Ar(i, c))
|
|
1893
|
+
throw new C(
|
|
1894
|
+
`database ${r} is already at schema version ${a}, but the requested index catalog does not match the committed schema`
|
|
1895
|
+
);
|
|
1896
|
+
return l = !0, u;
|
|
1897
|
+
}
|
|
1898
|
+
if (d.refs > 1)
|
|
1899
|
+
throw new he(
|
|
1900
|
+
`database ${r} is already open in this tab; close existing handles before migrating from version ${a} to ${o}`
|
|
1901
|
+
);
|
|
1902
|
+
if (!s)
|
|
1903
|
+
throw new C(
|
|
1904
|
+
`database ${r} requires migration from version ${a} to ${o}, but no migrate hook was provided`
|
|
1905
|
+
);
|
|
1906
|
+
const h = i ?? c;
|
|
1907
|
+
return await u.runSchemaMigration(a, o, s, Pe(h)), l = !0, u;
|
|
1908
|
+
} catch (a) {
|
|
1909
|
+
if (!l)
|
|
1910
|
+
try {
|
|
1911
|
+
await u.close();
|
|
1912
|
+
} catch {
|
|
1913
|
+
}
|
|
1914
|
+
throw x(a);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
async function Yr(t) {
|
|
1918
|
+
const e = X(t, "deleteDB");
|
|
1919
|
+
_e(), await Nt(e);
|
|
1920
|
+
}
|
|
1921
|
+
function Jr(t) {
|
|
1922
|
+
const e = X(t, "unsafeDebugCrashWorker");
|
|
1923
|
+
return qt(e);
|
|
1924
|
+
}
|
|
1925
|
+
export {
|
|
1926
|
+
bt as ChangeFeedCompactedError,
|
|
1927
|
+
fe as ConstraintError,
|
|
1928
|
+
nt as CorruptionError,
|
|
1929
|
+
he as DatabaseBusyError,
|
|
1930
|
+
H as DatabaseClosedError,
|
|
1931
|
+
Lr as INDEX_METADATA_STORE,
|
|
1932
|
+
it as IndexNotFoundError,
|
|
1933
|
+
pt as InjectedFailureError,
|
|
1934
|
+
wt as InternalError,
|
|
1935
|
+
b as InvalidOpenOptionsError,
|
|
1936
|
+
ft as InvalidRangeError,
|
|
1937
|
+
dt as KeyTooLargeError,
|
|
1938
|
+
p as MoyoDbError,
|
|
1939
|
+
ut as ReadonlyTransactionError,
|
|
1940
|
+
ye as ReservedStoreNameError,
|
|
1941
|
+
_ as SerializationError,
|
|
1942
|
+
yt as StorageError,
|
|
1943
|
+
ot as StoreExistsError,
|
|
1944
|
+
ht as StoreNameTooLongError,
|
|
1945
|
+
st as StoreNotFoundError,
|
|
1946
|
+
z as TransactionClosedError,
|
|
1947
|
+
at as UniqueIndexConstraintError,
|
|
1948
|
+
O as UnsupportedPlatformError,
|
|
1949
|
+
lt as ValueTooLargeError,
|
|
1950
|
+
C as VersionError,
|
|
1951
|
+
ct as WriteTransactionAlreadyOpenError,
|
|
1952
|
+
w as assertPublicStoreName,
|
|
1953
|
+
Kr as cloneNormalizedIndexDefinitions,
|
|
1954
|
+
rr as compareNormalizedIndexDefinitions,
|
|
1955
|
+
ke as compoundKey,
|
|
1956
|
+
qr as compoundKeyRange,
|
|
1957
|
+
$r as decodeIndexEntryKey,
|
|
1958
|
+
Wr as decodeIndexMetadataValue,
|
|
1959
|
+
Yr as deleteDB,
|
|
1960
|
+
S as encodeCompoundKeyParts,
|
|
1961
|
+
zr as encodeIndexEntryKey,
|
|
1962
|
+
Ur as encodeIndexMetadataKey,
|
|
1963
|
+
Dr as encodeIndexMetadataValue,
|
|
1964
|
+
re as encodeIndexScalar,
|
|
1965
|
+
jr as extractLogicalIndexKey,
|
|
1966
|
+
Cr as findIndexDefinition,
|
|
1967
|
+
Ie as indexDefinitionIdentity,
|
|
1968
|
+
Br as indexKey,
|
|
1969
|
+
Fr as indexKeyExactRange,
|
|
1970
|
+
Vr as indexRangeToPhysicalRange,
|
|
1971
|
+
Nr as indexesForStore,
|
|
1972
|
+
tr as isInternalStoreName,
|
|
1973
|
+
Rr as jsonDecode,
|
|
1974
|
+
Mr as jsonEncode,
|
|
1975
|
+
x as normalizeError,
|
|
1976
|
+
G as normalizeIndexDefinitions,
|
|
1977
|
+
Hr as openDB,
|
|
1978
|
+
xe as prefixRange,
|
|
1979
|
+
F as prefixSuccessor,
|
|
1980
|
+
oe as serializeNormalizedIndexDefinitions,
|
|
1981
|
+
Yt as splitCompoundKey,
|
|
1982
|
+
Pe as toPublicIndexDefinitions,
|
|
1983
|
+
_r as u64Key,
|
|
1984
|
+
Jr as unsafeDebugCrashWorker,
|
|
1985
|
+
Ht as utf8Decode,
|
|
1986
|
+
P as utf8Encode
|
|
1987
|
+
};
|
|
1988
|
+
//# sourceMappingURL=moyodb-sdk.js.map
|