@trust0/ridb-mongodb 0.0.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.
@@ -0,0 +1,3358 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // ../ridb-core/build/ridb_core.js
28
+ var require_ridb_core = __commonJS({
29
+ "../ridb-core/build/ridb_core.js"(exports, module) {
30
+ "use strict";
31
+ module.exports.SchemaFieldType = {
32
+ /**
33
+ * String type for text data
34
+ */
35
+ string: "string",
36
+ /**
37
+ * Number type for numeric data (integers and floats)
38
+ */
39
+ number: "number",
40
+ /**
41
+ * Boolean type for true/false values
42
+ */
43
+ boolean: "boolean",
44
+ /**
45
+ * Array type for ordered collections of items
46
+ */
47
+ array: "array",
48
+ /**
49
+ * Object type for nested document structures
50
+ */
51
+ object: "object"
52
+ };
53
+ var __defProp2 = Object.defineProperty;
54
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
55
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
56
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
57
+ var __export = (target, all) => {
58
+ for (var name in all)
59
+ __defProp2(target, name, { get: all[name], enumerable: true });
60
+ };
61
+ var __copyProps2 = (to, from, except, desc) => {
62
+ if (from && typeof from === "object" || typeof from === "function") {
63
+ for (let key of __getOwnPropNames2(from))
64
+ if (!__hasOwnProp2.call(to, key) && key !== except)
65
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
66
+ }
67
+ return to;
68
+ };
69
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
70
+ var ridb_core_exports = {};
71
+ __export(ridb_core_exports, {
72
+ BasePlugin: () => BasePlugin,
73
+ BaseStorage: () => BaseStorage2,
74
+ Collection: () => Collection,
75
+ CoreStorage: () => CoreStorage,
76
+ Database: () => Database,
77
+ Errors: () => Errors,
78
+ InMemory: () => InMemory,
79
+ IndexDB: () => IndexDB,
80
+ OpType: () => OpType2,
81
+ Operation: () => Operation2,
82
+ Property: () => Property,
83
+ Query: () => Query,
84
+ QueryOptions: () => QueryOptions2,
85
+ RIDBError: () => RIDBError,
86
+ Schema: () => Schema,
87
+ WasmBindgenTestContext: () => WasmBindgenTestContext,
88
+ __wbgtest_console_debug: () => __wbgtest_console_debug,
89
+ __wbgtest_console_error: () => __wbgtest_console_error,
90
+ __wbgtest_console_info: () => __wbgtest_console_info,
91
+ __wbgtest_console_log: () => __wbgtest_console_log,
92
+ __wbgtest_console_warn: () => __wbgtest_console_warn,
93
+ default: () => ridb_core_default,
94
+ initSync: () => initSync,
95
+ is_debug_mode: () => is_debug_mode,
96
+ main_js: () => main_js
97
+ });
98
+ module.exports = __toCommonJS(ridb_core_exports);
99
+ var wasm;
100
+ var heap = new Array(128).fill(void 0);
101
+ heap.push(void 0, null, true, false);
102
+ function getObject(idx) {
103
+ return heap[idx];
104
+ }
105
+ var heap_next = heap.length;
106
+ function dropObject(idx) {
107
+ if (idx < 132) return;
108
+ heap[idx] = heap_next;
109
+ heap_next = idx;
110
+ }
111
+ function takeObject(idx) {
112
+ const ret = getObject(idx);
113
+ dropObject(idx);
114
+ return ret;
115
+ }
116
+ var cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) : { decode: () => {
117
+ throw Error("TextDecoder not available");
118
+ } };
119
+ if (typeof TextDecoder !== "undefined") {
120
+ cachedTextDecoder.decode();
121
+ }
122
+ var cachedUint8Memory0 = null;
123
+ function getUint8Memory0() {
124
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
125
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
126
+ }
127
+ return cachedUint8Memory0;
128
+ }
129
+ function getStringFromWasm0(ptr, len) {
130
+ ptr = ptr >>> 0;
131
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
132
+ }
133
+ function addHeapObject(obj) {
134
+ if (heap_next === heap.length) heap.push(heap.length + 1);
135
+ const idx = heap_next;
136
+ heap_next = heap[idx];
137
+ heap[idx] = obj;
138
+ return idx;
139
+ }
140
+ var WASM_VECTOR_LEN = 0;
141
+ var cachedTextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder("utf-8") : { encode: () => {
142
+ throw Error("TextEncoder not available");
143
+ } };
144
+ var encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) {
145
+ return cachedTextEncoder.encodeInto(arg, view);
146
+ } : function(arg, view) {
147
+ const buf = cachedTextEncoder.encode(arg);
148
+ view.set(buf);
149
+ return {
150
+ read: arg.length,
151
+ written: buf.length
152
+ };
153
+ };
154
+ function passStringToWasm0(arg, malloc, realloc) {
155
+ if (realloc === void 0) {
156
+ const buf = cachedTextEncoder.encode(arg);
157
+ const ptr2 = malloc(buf.length, 1) >>> 0;
158
+ getUint8Memory0().subarray(ptr2, ptr2 + buf.length).set(buf);
159
+ WASM_VECTOR_LEN = buf.length;
160
+ return ptr2;
161
+ }
162
+ let len = arg.length;
163
+ let ptr = malloc(len, 1) >>> 0;
164
+ const mem = getUint8Memory0();
165
+ let offset = 0;
166
+ for (; offset < len; offset++) {
167
+ const code = arg.charCodeAt(offset);
168
+ if (code > 127) break;
169
+ mem[ptr + offset] = code;
170
+ }
171
+ if (offset !== len) {
172
+ if (offset !== 0) {
173
+ arg = arg.slice(offset);
174
+ }
175
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
176
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
177
+ const ret = encodeString(arg, view);
178
+ offset += ret.written;
179
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
180
+ }
181
+ WASM_VECTOR_LEN = offset;
182
+ return ptr;
183
+ }
184
+ function isLikeNone(x) {
185
+ return x === void 0 || x === null;
186
+ }
187
+ var cachedInt32Memory0 = null;
188
+ function getInt32Memory0() {
189
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
190
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
191
+ }
192
+ return cachedInt32Memory0;
193
+ }
194
+ var cachedFloat64Memory0 = null;
195
+ function getFloat64Memory0() {
196
+ if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {
197
+ cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
198
+ }
199
+ return cachedFloat64Memory0;
200
+ }
201
+ var cachedBigInt64Memory0 = null;
202
+ function getBigInt64Memory0() {
203
+ if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) {
204
+ cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer);
205
+ }
206
+ return cachedBigInt64Memory0;
207
+ }
208
+ function debugString(val) {
209
+ const type = typeof val;
210
+ if (type == "number" || type == "boolean" || val == null) {
211
+ return `${val}`;
212
+ }
213
+ if (type == "string") {
214
+ return `"${val}"`;
215
+ }
216
+ if (type == "symbol") {
217
+ const description = val.description;
218
+ if (description == null) {
219
+ return "Symbol";
220
+ } else {
221
+ return `Symbol(${description})`;
222
+ }
223
+ }
224
+ if (type == "function") {
225
+ const name = val.name;
226
+ if (typeof name == "string" && name.length > 0) {
227
+ return `Function(${name})`;
228
+ } else {
229
+ return "Function";
230
+ }
231
+ }
232
+ if (Array.isArray(val)) {
233
+ const length = val.length;
234
+ let debug = "[";
235
+ if (length > 0) {
236
+ debug += debugString(val[0]);
237
+ }
238
+ for (let i = 1; i < length; i++) {
239
+ debug += ", " + debugString(val[i]);
240
+ }
241
+ debug += "]";
242
+ return debug;
243
+ }
244
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
245
+ let className;
246
+ if (builtInMatches.length > 1) {
247
+ className = builtInMatches[1];
248
+ } else {
249
+ return toString.call(val);
250
+ }
251
+ if (className == "Object") {
252
+ try {
253
+ return "Object(" + JSON.stringify(val) + ")";
254
+ } catch (_) {
255
+ return "Object";
256
+ }
257
+ }
258
+ if (val instanceof Error) {
259
+ return `${val.name}: ${val.message}
260
+ ${val.stack}`;
261
+ }
262
+ return className;
263
+ }
264
+ var CLOSURE_DTORS = typeof FinalizationRegistry === "undefined" ? { register: () => {
265
+ }, unregister: () => {
266
+ } } : new FinalizationRegistry((state) => {
267
+ wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);
268
+ });
269
+ function makeClosure(arg0, arg1, dtor, f) {
270
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
271
+ const real = (...args) => {
272
+ state.cnt++;
273
+ try {
274
+ return f(state.a, state.b, ...args);
275
+ } finally {
276
+ if (--state.cnt === 0) {
277
+ wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);
278
+ state.a = 0;
279
+ CLOSURE_DTORS.unregister(state);
280
+ }
281
+ }
282
+ };
283
+ real.original = state;
284
+ CLOSURE_DTORS.register(real, state, state);
285
+ return real;
286
+ }
287
+ function __wbg_adapter_56(arg0, arg1, arg2, arg3, arg4) {
288
+ try {
289
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
290
+ wasm._dyn_core__ops__function__Fn__A_B_C___Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1d7727fe9471ac49(retptr, arg0, arg1, addHeapObject(arg2), addHeapObject(arg3), addHeapObject(arg4));
291
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
292
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
293
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
294
+ if (r2) {
295
+ throw takeObject(r1);
296
+ }
297
+ return takeObject(r0);
298
+ } finally {
299
+ wasm.__wbindgen_add_to_stack_pointer(16);
300
+ }
301
+ }
302
+ function makeMutClosure(arg0, arg1, dtor, f) {
303
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
304
+ const real = (...args) => {
305
+ state.cnt++;
306
+ const a = state.a;
307
+ state.a = 0;
308
+ try {
309
+ return f(a, state.b, ...args);
310
+ } finally {
311
+ if (--state.cnt === 0) {
312
+ wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
313
+ CLOSURE_DTORS.unregister(state);
314
+ } else {
315
+ state.a = a;
316
+ }
317
+ }
318
+ };
319
+ real.original = state;
320
+ CLOSURE_DTORS.register(real, state, state);
321
+ return real;
322
+ }
323
+ function __wbg_adapter_59(arg0, arg1, arg2) {
324
+ wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4e550b82c2b30c7a(arg0, arg1, addHeapObject(arg2));
325
+ }
326
+ function __wbg_adapter_62(arg0, arg1) {
327
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hec0cc069f718ed78(arg0, arg1);
328
+ }
329
+ function __wbg_adapter_65(arg0, arg1, arg2) {
330
+ wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf401bdfdf8c9bdd9(arg0, arg1, addHeapObject(arg2));
331
+ }
332
+ var cachedUint32Memory0 = null;
333
+ function getUint32Memory0() {
334
+ if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
335
+ cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
336
+ }
337
+ return cachedUint32Memory0;
338
+ }
339
+ function getArrayJsValueFromWasm0(ptr, len) {
340
+ ptr = ptr >>> 0;
341
+ const mem = getUint32Memory0();
342
+ const slice = mem.subarray(ptr / 4, ptr / 4 + len);
343
+ const result = [];
344
+ for (let i = 0; i < slice.length; i++) {
345
+ result.push(takeObject(slice[i]));
346
+ }
347
+ return result;
348
+ }
349
+ function _assertClass(instance, klass) {
350
+ if (!(instance instanceof klass)) {
351
+ throw new Error(`expected instance of ${klass.name}`);
352
+ }
353
+ return instance.ptr;
354
+ }
355
+ var stack_pointer = 128;
356
+ function addBorrowedObject(obj) {
357
+ if (stack_pointer == 1) throw new Error("out of js stack");
358
+ heap[--stack_pointer] = obj;
359
+ return stack_pointer;
360
+ }
361
+ function passArrayJsValueToWasm0(array, malloc) {
362
+ const ptr = malloc(array.length * 4, 4) >>> 0;
363
+ const mem = getUint32Memory0();
364
+ for (let i = 0; i < array.length; i++) {
365
+ mem[ptr / 4 + i] = addHeapObject(array[i]);
366
+ }
367
+ WASM_VECTOR_LEN = array.length;
368
+ return ptr;
369
+ }
370
+ function handleError(f, args) {
371
+ try {
372
+ return f.apply(this, args);
373
+ } catch (e) {
374
+ wasm.__wbindgen_exn_store(addHeapObject(e));
375
+ }
376
+ }
377
+ function main_js() {
378
+ wasm.main_js();
379
+ }
380
+ function is_debug_mode() {
381
+ const ret = wasm.is_debug_mode();
382
+ return ret !== 0;
383
+ }
384
+ function __wbgtest_console_log(args) {
385
+ try {
386
+ wasm.__wbgtest_console_log(addBorrowedObject(args));
387
+ } finally {
388
+ heap[stack_pointer++] = void 0;
389
+ }
390
+ }
391
+ function __wbgtest_console_debug(args) {
392
+ try {
393
+ wasm.__wbgtest_console_debug(addBorrowedObject(args));
394
+ } finally {
395
+ heap[stack_pointer++] = void 0;
396
+ }
397
+ }
398
+ function __wbgtest_console_info(args) {
399
+ try {
400
+ wasm.__wbgtest_console_info(addBorrowedObject(args));
401
+ } finally {
402
+ heap[stack_pointer++] = void 0;
403
+ }
404
+ }
405
+ function __wbgtest_console_warn(args) {
406
+ try {
407
+ wasm.__wbgtest_console_warn(addBorrowedObject(args));
408
+ } finally {
409
+ heap[stack_pointer++] = void 0;
410
+ }
411
+ }
412
+ function __wbgtest_console_error(args) {
413
+ try {
414
+ wasm.__wbgtest_console_error(addBorrowedObject(args));
415
+ } finally {
416
+ heap[stack_pointer++] = void 0;
417
+ }
418
+ }
419
+ function __wbg_adapter_292(arg0, arg1) {
420
+ wasm.wasm_bindgen__convert__closures__invoke0_mut__he68973678185bd11(arg0, arg1);
421
+ }
422
+ function __wbg_adapter_335(arg0, arg1, arg2, arg3, arg4) {
423
+ wasm.wasm_bindgen__convert__closures__invoke3_mut__h711940be5154e055(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
424
+ }
425
+ function __wbg_adapter_392(arg0, arg1, arg2, arg3) {
426
+ wasm.wasm_bindgen__convert__closures__invoke2_mut__hdfe55fa2a247d1ac(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
427
+ }
428
+ var Errors = Object.freeze({ Error: 0, "0": "Error", HookError: 1, "1": "HookError", QueryError: 2, "2": "QueryError", SerializationError: 3, "3": "SerializationError", ValidationError: 4, "4": "ValidationError", AuthenticationError: 5, "5": "AuthenticationError" });
429
+ var OpType2 = Object.freeze({
430
+ /**
431
+ * Create operation.
432
+ */
433
+ CREATE: 0,
434
+ "0": "CREATE",
435
+ /**
436
+ * Update operation.
437
+ */
438
+ UPDATE: 1,
439
+ "1": "UPDATE",
440
+ /**
441
+ * Delete operation.
442
+ */
443
+ DELETE: 2,
444
+ "2": "DELETE",
445
+ /**
446
+ * Query Operation.
447
+ */
448
+ QUERY: 3,
449
+ "3": "QUERY",
450
+ /**
451
+ * Count Operation.
452
+ */
453
+ COUNT: 4,
454
+ "4": "COUNT"
455
+ });
456
+ var BasePluginFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
457
+ }, unregister: () => {
458
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_baseplugin_free(ptr >>> 0));
459
+ var BasePlugin = class {
460
+ __destroy_into_raw() {
461
+ const ptr = this.__wbg_ptr;
462
+ this.__wbg_ptr = 0;
463
+ BasePluginFinalization.unregister(this);
464
+ return ptr;
465
+ }
466
+ free() {
467
+ const ptr = this.__destroy_into_raw();
468
+ wasm.__wbg_baseplugin_free(ptr);
469
+ }
470
+ /**
471
+ * @param {string} name
472
+ */
473
+ constructor(name) {
474
+ try {
475
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
476
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
477
+ const len0 = WASM_VECTOR_LEN;
478
+ wasm.baseplugin_new(retptr, ptr0, len0);
479
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
480
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
481
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
482
+ if (r2) {
483
+ throw takeObject(r1);
484
+ }
485
+ this.__wbg_ptr = r0 >>> 0;
486
+ return this;
487
+ } finally {
488
+ wasm.__wbindgen_add_to_stack_pointer(16);
489
+ }
490
+ }
491
+ /**
492
+ * @returns {any}
493
+ */
494
+ get name() {
495
+ const ret = wasm.baseplugin_name(this.__wbg_ptr);
496
+ return takeObject(ret);
497
+ }
498
+ /**
499
+ * @returns {any}
500
+ */
501
+ get docCreateHook() {
502
+ const ret = wasm.baseplugin_get_doc_create_hook(this.__wbg_ptr);
503
+ return takeObject(ret);
504
+ }
505
+ /**
506
+ * @returns {any}
507
+ */
508
+ get docRecoverHook() {
509
+ const ret = wasm.baseplugin_get_doc_recover_hook(this.__wbg_ptr);
510
+ return takeObject(ret);
511
+ }
512
+ /**
513
+ * @param {any} hook
514
+ */
515
+ set docCreateHook(hook) {
516
+ wasm.baseplugin_set_doc_create_hook(this.__wbg_ptr, addHeapObject(hook));
517
+ }
518
+ /**
519
+ * @param {any} hook
520
+ */
521
+ set docRecoverHook(hook) {
522
+ wasm.baseplugin_set_doc_recover_hook(this.__wbg_ptr, addHeapObject(hook));
523
+ }
524
+ };
525
+ var BaseStorageFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
526
+ }, unregister: () => {
527
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_basestorage_free(ptr >>> 0));
528
+ var BaseStorage2 = class {
529
+ __destroy_into_raw() {
530
+ const ptr = this.__wbg_ptr;
531
+ this.__wbg_ptr = 0;
532
+ BaseStorageFinalization.unregister(this);
533
+ return ptr;
534
+ }
535
+ free() {
536
+ const ptr = this.__destroy_into_raw();
537
+ wasm.__wbg_basestorage_free(ptr);
538
+ }
539
+ /**
540
+ * Creates a new `BaseStorage` instance with the provided name and schema type.
541
+ *
542
+ * # Arguments
543
+ *
544
+ * * `name` - The name of the storage.
545
+ * * `schema_type` - The schema type in `JsValue` format.
546
+ *
547
+ * # Returns
548
+ *
549
+ * * `Result<BaseStorage, JsValue>` - A result containing the new `BaseStorage` instance or an error.
550
+ * @param {string} name
551
+ * @param {object} schemas_js
552
+ * @param {object | undefined} [options]
553
+ */
554
+ constructor(name, schemas_js, options) {
555
+ try {
556
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
557
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
558
+ const len0 = WASM_VECTOR_LEN;
559
+ wasm.basestorage_new(retptr, ptr0, len0, addHeapObject(schemas_js), isLikeNone(options) ? 0 : addHeapObject(options));
560
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
561
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
562
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
563
+ if (r2) {
564
+ throw takeObject(r1);
565
+ }
566
+ this.__wbg_ptr = r0 >>> 0;
567
+ return this;
568
+ } finally {
569
+ wasm.__wbindgen_add_to_stack_pointer(16);
570
+ }
571
+ }
572
+ /**
573
+ * @returns {any}
574
+ */
575
+ addIndexSchemas() {
576
+ try {
577
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
578
+ wasm.basestorage_addIndexSchemas(retptr, this.__wbg_ptr);
579
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
580
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
581
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
582
+ if (r2) {
583
+ throw takeObject(r1);
584
+ }
585
+ return takeObject(r0);
586
+ } finally {
587
+ wasm.__wbindgen_add_to_stack_pointer(16);
588
+ }
589
+ }
590
+ /**
591
+ * @param {string} name
592
+ * @returns {any}
593
+ */
594
+ getOption(name) {
595
+ try {
596
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
597
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
598
+ const len0 = WASM_VECTOR_LEN;
599
+ wasm.basestorage_getOption(retptr, this.__wbg_ptr, ptr0, len0);
600
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
601
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
602
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
603
+ if (r2) {
604
+ throw takeObject(r1);
605
+ }
606
+ return takeObject(r0);
607
+ } finally {
608
+ wasm.__wbindgen_add_to_stack_pointer(16);
609
+ }
610
+ }
611
+ /**
612
+ * @param {string} name
613
+ * @returns {Schema}
614
+ */
615
+ getSchema(name) {
616
+ try {
617
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
618
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
619
+ const len0 = WASM_VECTOR_LEN;
620
+ wasm.basestorage_getSchema(retptr, this.__wbg_ptr, ptr0, len0);
621
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
622
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
623
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
624
+ if (r2) {
625
+ throw takeObject(r1);
626
+ }
627
+ return Schema.__wrap(r0);
628
+ } finally {
629
+ wasm.__wbindgen_add_to_stack_pointer(16);
630
+ }
631
+ }
632
+ /**
633
+ * @returns {CoreStorage}
634
+ */
635
+ get core() {
636
+ try {
637
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
638
+ wasm.basestorage_core(retptr, this.__wbg_ptr);
639
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
640
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
641
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
642
+ if (r2) {
643
+ throw takeObject(r1);
644
+ }
645
+ return CoreStorage.__wrap(r0);
646
+ } finally {
647
+ wasm.__wbindgen_add_to_stack_pointer(16);
648
+ }
649
+ }
650
+ };
651
+ var CollectionFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
652
+ }, unregister: () => {
653
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_collection_free(ptr >>> 0));
654
+ var Collection = class _Collection {
655
+ static __wrap(ptr) {
656
+ ptr = ptr >>> 0;
657
+ const obj = Object.create(_Collection.prototype);
658
+ obj.__wbg_ptr = ptr;
659
+ CollectionFinalization.register(obj, obj.__wbg_ptr, obj);
660
+ return obj;
661
+ }
662
+ __destroy_into_raw() {
663
+ const ptr = this.__wbg_ptr;
664
+ this.__wbg_ptr = 0;
665
+ CollectionFinalization.unregister(this);
666
+ return ptr;
667
+ }
668
+ free() {
669
+ const ptr = this.__destroy_into_raw();
670
+ wasm.__wbg_collection_free(ptr);
671
+ }
672
+ /**
673
+ * @returns {string}
674
+ */
675
+ get name() {
676
+ let deferred1_0;
677
+ let deferred1_1;
678
+ try {
679
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
680
+ wasm.collection_name(retptr, this.__wbg_ptr);
681
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
682
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
683
+ deferred1_0 = r0;
684
+ deferred1_1 = r1;
685
+ return getStringFromWasm0(r0, r1);
686
+ } finally {
687
+ wasm.__wbindgen_add_to_stack_pointer(16);
688
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
689
+ }
690
+ }
691
+ /**
692
+ * @returns {Schema}
693
+ */
694
+ get schema() {
695
+ try {
696
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
697
+ wasm.collection_schema(retptr, this.__wbg_ptr);
698
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
699
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
700
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
701
+ if (r2) {
702
+ throw takeObject(r1);
703
+ }
704
+ return Schema.__wrap(r0);
705
+ } finally {
706
+ wasm.__wbindgen_add_to_stack_pointer(16);
707
+ }
708
+ }
709
+ /**
710
+ * Finds and returns all documents in the collection.
711
+ *
712
+ * This function is asynchronous and returns a `JsValue` representing
713
+ * the documents found in the collection.
714
+ * @param {any} query_js
715
+ * @param {any} options_js
716
+ * @returns {Promise<any>}
717
+ */
718
+ find(query_js, options_js) {
719
+ const ret = wasm.collection_find(this.__wbg_ptr, addHeapObject(query_js), addHeapObject(options_js));
720
+ return takeObject(ret);
721
+ }
722
+ /**
723
+ * @param {any} options
724
+ * @returns {QueryOptions}
725
+ */
726
+ parse_query_options(options) {
727
+ try {
728
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
729
+ wasm.collection_parse_query_options(retptr, this.__wbg_ptr, addHeapObject(options));
730
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
731
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
732
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
733
+ if (r2) {
734
+ throw takeObject(r1);
735
+ }
736
+ return QueryOptions2.__wrap(r0);
737
+ } finally {
738
+ wasm.__wbindgen_add_to_stack_pointer(16);
739
+ }
740
+ }
741
+ /**
742
+ * counts and returns all documents in the collection.
743
+ *
744
+ * This function is asynchronous and returns a `Schema` representing
745
+ * the documents found in the collection.
746
+ * @param {any} query_js
747
+ * @param {any} options_js
748
+ * @returns {Promise<any>}
749
+ */
750
+ count(query_js, options_js) {
751
+ const ret = wasm.collection_count(this.__wbg_ptr, addHeapObject(query_js), addHeapObject(options_js));
752
+ return takeObject(ret);
753
+ }
754
+ /**
755
+ * Finds and returns a single document in the collection by its ID.
756
+ *
757
+ * This function is asynchronous.
758
+ * @param {any} primary_key
759
+ * @returns {Promise<any>}
760
+ */
761
+ findById(primary_key) {
762
+ const ret = wasm.collection_findById(this.__wbg_ptr, addHeapObject(primary_key));
763
+ return takeObject(ret);
764
+ }
765
+ /**
766
+ * Updates a document in the collection with the given data.
767
+ *
768
+ * This function is asynchronous and returns a `Result` indicating success or failure.
769
+ *
770
+ * # Arguments
771
+ *
772
+ * * `document` - A `JsValue` representing the partial document to update.
773
+ * @param {any} document
774
+ * @returns {Promise<any>}
775
+ */
776
+ update(document2) {
777
+ const ret = wasm.collection_update(this.__wbg_ptr, addHeapObject(document2));
778
+ return takeObject(ret);
779
+ }
780
+ /**
781
+ * Creates a new document in the collection.
782
+ *
783
+ * This function is asynchronous and returns a `Result` indicating success or failure.
784
+ *
785
+ * # Arguments
786
+ *
787
+ * * `document` - A `JsValue` representing the document to create.
788
+ * @param {any} document
789
+ * @returns {Promise<any>}
790
+ */
791
+ create(document2) {
792
+ const ret = wasm.collection_create(this.__wbg_ptr, addHeapObject(document2));
793
+ return takeObject(ret);
794
+ }
795
+ /**
796
+ * Deletes a document from the collection by its ID.
797
+ *
798
+ * This function is asynchronous.
799
+ * @param {any} primary_key
800
+ * @returns {Promise<any>}
801
+ */
802
+ delete(primary_key) {
803
+ const ret = wasm.collection_delete(this.__wbg_ptr, addHeapObject(primary_key));
804
+ return takeObject(ret);
805
+ }
806
+ };
807
+ var CoreStorageFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
808
+ }, unregister: () => {
809
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_corestorage_free(ptr >>> 0));
810
+ var CoreStorage = class _CoreStorage {
811
+ static __wrap(ptr) {
812
+ ptr = ptr >>> 0;
813
+ const obj = Object.create(_CoreStorage.prototype);
814
+ obj.__wbg_ptr = ptr;
815
+ CoreStorageFinalization.register(obj, obj.__wbg_ptr, obj);
816
+ return obj;
817
+ }
818
+ __destroy_into_raw() {
819
+ const ptr = this.__wbg_ptr;
820
+ this.__wbg_ptr = 0;
821
+ CoreStorageFinalization.unregister(this);
822
+ return ptr;
823
+ }
824
+ free() {
825
+ const ptr = this.__destroy_into_raw();
826
+ wasm.__wbg_corestorage_free(ptr);
827
+ }
828
+ /**
829
+ */
830
+ constructor() {
831
+ const ret = wasm.corestorage_new();
832
+ this.__wbg_ptr = ret >>> 0;
833
+ return this;
834
+ }
835
+ /**
836
+ * @param {any} value
837
+ * @returns {string}
838
+ */
839
+ getPrimaryKeyTyped(value) {
840
+ let deferred2_0;
841
+ let deferred2_1;
842
+ try {
843
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
844
+ wasm.corestorage_getPrimaryKeyTyped(retptr, this.__wbg_ptr, addHeapObject(value));
845
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
846
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
847
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
848
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
849
+ var ptr1 = r0;
850
+ var len1 = r1;
851
+ if (r3) {
852
+ ptr1 = 0;
853
+ len1 = 0;
854
+ throw takeObject(r2);
855
+ }
856
+ deferred2_0 = ptr1;
857
+ deferred2_1 = len1;
858
+ return getStringFromWasm0(ptr1, len1);
859
+ } finally {
860
+ wasm.__wbindgen_add_to_stack_pointer(16);
861
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
862
+ }
863
+ }
864
+ /**
865
+ * @param {Schema} schema
866
+ * @param {Operation} op
867
+ * @returns {(string)[]}
868
+ */
869
+ getIndexes(schema, op) {
870
+ try {
871
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
872
+ _assertClass(schema, Schema);
873
+ _assertClass(op, Operation2);
874
+ wasm.corestorage_getIndexes(retptr, this.__wbg_ptr, schema.__wbg_ptr, op.__wbg_ptr);
875
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
876
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
877
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
878
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
879
+ if (r3) {
880
+ throw takeObject(r2);
881
+ }
882
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
883
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
884
+ return v1;
885
+ } finally {
886
+ wasm.__wbindgen_add_to_stack_pointer(16);
887
+ }
888
+ }
889
+ /**
890
+ * @param {any} document
891
+ * @param {Query} query
892
+ * @returns {boolean}
893
+ */
894
+ matchesQuery(document2, query) {
895
+ try {
896
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
897
+ _assertClass(query, Query);
898
+ var ptr0 = query.__destroy_into_raw();
899
+ wasm.corestorage_matchesQuery(retptr, this.__wbg_ptr, addBorrowedObject(document2), ptr0);
900
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
901
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
902
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
903
+ if (r2) {
904
+ throw takeObject(r1);
905
+ }
906
+ return r0 !== 0;
907
+ } finally {
908
+ wasm.__wbindgen_add_to_stack_pointer(16);
909
+ heap[stack_pointer++] = void 0;
910
+ }
911
+ }
912
+ };
913
+ var DatabaseFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
914
+ }, unregister: () => {
915
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_database_free(ptr >>> 0));
916
+ var Database = class _Database {
917
+ static __wrap(ptr) {
918
+ ptr = ptr >>> 0;
919
+ const obj = Object.create(_Database.prototype);
920
+ obj.__wbg_ptr = ptr;
921
+ DatabaseFinalization.register(obj, obj.__wbg_ptr, obj);
922
+ return obj;
923
+ }
924
+ __destroy_into_raw() {
925
+ const ptr = this.__wbg_ptr;
926
+ this.__wbg_ptr = 0;
927
+ DatabaseFinalization.unregister(this);
928
+ return ptr;
929
+ }
930
+ free() {
931
+ const ptr = this.__destroy_into_raw();
932
+ wasm.__wbg_database_free(ptr);
933
+ }
934
+ /**
935
+ * @returns {Promise<any>}
936
+ */
937
+ start() {
938
+ const ret = wasm.database_start(this.__wbg_ptr);
939
+ return takeObject(ret);
940
+ }
941
+ /**
942
+ * @returns {Promise<any>}
943
+ */
944
+ close() {
945
+ const ptr = this.__destroy_into_raw();
946
+ const ret = wasm.database_close(ptr);
947
+ return takeObject(ret);
948
+ }
949
+ /**
950
+ * @returns {boolean}
951
+ */
952
+ get started() {
953
+ const ret = wasm.database_started(this.__wbg_ptr);
954
+ return ret !== 0;
955
+ }
956
+ /**
957
+ * @param {string} password
958
+ * @returns {Promise<boolean>}
959
+ */
960
+ authenticate(password) {
961
+ const ptr0 = passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
962
+ const len0 = WASM_VECTOR_LEN;
963
+ const ret = wasm.database_authenticate(this.__wbg_ptr, ptr0, len0);
964
+ return takeObject(ret);
965
+ }
966
+ /**
967
+ * Retrieves the collections in the database.
968
+ *
969
+ * This function returns an `Object` containing the collections.
970
+ *
971
+ * # Returns
972
+ *
973
+ * * `Result<Object, JsValue>` - A result containing an `Object` with the collections or an error.
974
+ * @returns {object}
975
+ */
976
+ get collections() {
977
+ try {
978
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
979
+ wasm.database_collections(retptr, this.__wbg_ptr);
980
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
981
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
982
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
983
+ if (r2) {
984
+ throw takeObject(r1);
985
+ }
986
+ return takeObject(r0);
987
+ } finally {
988
+ wasm.__wbindgen_add_to_stack_pointer(16);
989
+ }
990
+ }
991
+ /**
992
+ * @param {string} db_name
993
+ * @param {object} schemas_js
994
+ * @param {object} migrations_js
995
+ * @param {Array<any>} plugins
996
+ * @param {any} module
997
+ * @param {string | undefined} [password]
998
+ * @param {any | undefined} [storage]
999
+ * @returns {Promise<Database>}
1000
+ */
1001
+ static create(db_name, schemas_js, migrations_js, plugins, module2, password, storage) {
1002
+ const ptr0 = passStringToWasm0(db_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1003
+ const len0 = WASM_VECTOR_LEN;
1004
+ var ptr1 = isLikeNone(password) ? 0 : passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1005
+ var len1 = WASM_VECTOR_LEN;
1006
+ const ret = wasm.database_create(ptr0, len0, addHeapObject(schemas_js), addHeapObject(migrations_js), addHeapObject(plugins), addHeapObject(module2), ptr1, len1, isLikeNone(storage) ? 0 : addHeapObject(storage));
1007
+ return takeObject(ret);
1008
+ }
1009
+ };
1010
+ var InMemoryFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1011
+ }, unregister: () => {
1012
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_inmemory_free(ptr >>> 0));
1013
+ var InMemory = class _InMemory {
1014
+ static __wrap(ptr) {
1015
+ ptr = ptr >>> 0;
1016
+ const obj = Object.create(_InMemory.prototype);
1017
+ obj.__wbg_ptr = ptr;
1018
+ InMemoryFinalization.register(obj, obj.__wbg_ptr, obj);
1019
+ return obj;
1020
+ }
1021
+ __destroy_into_raw() {
1022
+ const ptr = this.__wbg_ptr;
1023
+ this.__wbg_ptr = 0;
1024
+ InMemoryFinalization.unregister(this);
1025
+ return ptr;
1026
+ }
1027
+ free() {
1028
+ const ptr = this.__destroy_into_raw();
1029
+ wasm.__wbg_inmemory_free(ptr);
1030
+ }
1031
+ /**
1032
+ * @param {string} name
1033
+ * @param {object} schemas_js
1034
+ * @returns {Promise<InMemory>}
1035
+ */
1036
+ static create(name, schemas_js) {
1037
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1038
+ const len0 = WASM_VECTOR_LEN;
1039
+ const ret = wasm.inmemory_create(ptr0, len0, addHeapObject(schemas_js));
1040
+ return takeObject(ret);
1041
+ }
1042
+ /**
1043
+ * @param {Operation} op
1044
+ * @returns {Promise<any>}
1045
+ */
1046
+ write(op) {
1047
+ _assertClass(op, Operation2);
1048
+ var ptr0 = op.__destroy_into_raw();
1049
+ const ret = wasm.inmemory_write(this.__wbg_ptr, ptr0);
1050
+ return takeObject(ret);
1051
+ }
1052
+ /**
1053
+ * @param {string} collection_name
1054
+ * @param {any} query_js
1055
+ * @param {QueryOptions} options
1056
+ * @returns {Promise<any>}
1057
+ */
1058
+ find(collection_name, query_js, options) {
1059
+ const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1060
+ const len0 = WASM_VECTOR_LEN;
1061
+ _assertClass(options, QueryOptions2);
1062
+ var ptr1 = options.__destroy_into_raw();
1063
+ const ret = wasm.inmemory_find(this.__wbg_ptr, ptr0, len0, addHeapObject(query_js), ptr1);
1064
+ return takeObject(ret);
1065
+ }
1066
+ /**
1067
+ * @param {string} collection_name
1068
+ * @param {any} primary_key
1069
+ * @returns {Promise<any>}
1070
+ */
1071
+ findDocumentById(collection_name, primary_key) {
1072
+ const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1073
+ const len0 = WASM_VECTOR_LEN;
1074
+ const ret = wasm.inmemory_findDocumentById(this.__wbg_ptr, ptr0, len0, addHeapObject(primary_key));
1075
+ return takeObject(ret);
1076
+ }
1077
+ /**
1078
+ * @param {string} collection_name
1079
+ * @param {any} query_js
1080
+ * @param {QueryOptions} options
1081
+ * @returns {Promise<any>}
1082
+ */
1083
+ count(collection_name, query_js, options) {
1084
+ const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1085
+ const len0 = WASM_VECTOR_LEN;
1086
+ _assertClass(options, QueryOptions2);
1087
+ var ptr1 = options.__destroy_into_raw();
1088
+ const ret = wasm.inmemory_count(this.__wbg_ptr, ptr0, len0, addHeapObject(query_js), ptr1);
1089
+ return takeObject(ret);
1090
+ }
1091
+ /**
1092
+ * @returns {Promise<any>}
1093
+ */
1094
+ close() {
1095
+ const ret = wasm.inmemory_close(this.__wbg_ptr);
1096
+ return takeObject(ret);
1097
+ }
1098
+ /**
1099
+ * @returns {Promise<any>}
1100
+ */
1101
+ start() {
1102
+ const ret = wasm.inmemory_start(this.__wbg_ptr);
1103
+ return takeObject(ret);
1104
+ }
1105
+ };
1106
+ var IndexDBFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1107
+ }, unregister: () => {
1108
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_indexdb_free(ptr >>> 0));
1109
+ var IndexDB = class _IndexDB {
1110
+ static __wrap(ptr) {
1111
+ ptr = ptr >>> 0;
1112
+ const obj = Object.create(_IndexDB.prototype);
1113
+ obj.__wbg_ptr = ptr;
1114
+ IndexDBFinalization.register(obj, obj.__wbg_ptr, obj);
1115
+ return obj;
1116
+ }
1117
+ __destroy_into_raw() {
1118
+ const ptr = this.__wbg_ptr;
1119
+ this.__wbg_ptr = 0;
1120
+ IndexDBFinalization.unregister(this);
1121
+ return ptr;
1122
+ }
1123
+ free() {
1124
+ const ptr = this.__destroy_into_raw();
1125
+ wasm.__wbg_indexdb_free(ptr);
1126
+ }
1127
+ /**
1128
+ * Fetch documents by opening an IndexedDB cursor (on an index or store),
1129
+ * then apply inline filtering and offset/limit constraints.
1130
+ * @returns {(string)[]}
1131
+ */
1132
+ get_stores() {
1133
+ try {
1134
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1135
+ wasm.indexdb_get_stores(retptr, this.__wbg_ptr);
1136
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1137
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1138
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
1139
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
1140
+ return v1;
1141
+ } finally {
1142
+ wasm.__wbindgen_add_to_stack_pointer(16);
1143
+ }
1144
+ }
1145
+ /**
1146
+ * @param {string} store_name
1147
+ * @returns {IDBObjectStore}
1148
+ */
1149
+ get_store(store_name) {
1150
+ try {
1151
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1152
+ const ptr0 = passStringToWasm0(store_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1153
+ const len0 = WASM_VECTOR_LEN;
1154
+ wasm.indexdb_get_store(retptr, this.__wbg_ptr, ptr0, len0);
1155
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1156
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1157
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1158
+ if (r2) {
1159
+ throw takeObject(r1);
1160
+ }
1161
+ return takeObject(r0);
1162
+ } finally {
1163
+ wasm.__wbindgen_add_to_stack_pointer(16);
1164
+ }
1165
+ }
1166
+ /**
1167
+ * @param {string} name
1168
+ * @param {object} schemas_js
1169
+ * @returns {Promise<IndexDB>}
1170
+ */
1171
+ static create(name, schemas_js) {
1172
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1173
+ const len0 = WASM_VECTOR_LEN;
1174
+ const ret = wasm.indexdb_create(ptr0, len0, addHeapObject(schemas_js));
1175
+ return takeObject(ret);
1176
+ }
1177
+ /**
1178
+ * @param {Operation} op
1179
+ * @returns {Promise<any>}
1180
+ */
1181
+ write(op) {
1182
+ _assertClass(op, Operation2);
1183
+ var ptr0 = op.__destroy_into_raw();
1184
+ const ret = wasm.indexdb_write(this.__wbg_ptr, ptr0);
1185
+ return takeObject(ret);
1186
+ }
1187
+ /**
1188
+ * @param {string} collection_name
1189
+ * @param {any} query
1190
+ * @param {QueryOptions} options
1191
+ * @returns {Promise<any>}
1192
+ */
1193
+ find(collection_name, query, options) {
1194
+ const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1195
+ const len0 = WASM_VECTOR_LEN;
1196
+ _assertClass(options, QueryOptions2);
1197
+ var ptr1 = options.__destroy_into_raw();
1198
+ const ret = wasm.indexdb_find(this.__wbg_ptr, ptr0, len0, addHeapObject(query), ptr1);
1199
+ return takeObject(ret);
1200
+ }
1201
+ /**
1202
+ * @param {string} collection_name
1203
+ * @param {any} primary_key
1204
+ * @returns {Promise<any>}
1205
+ */
1206
+ findDocumentById(collection_name, primary_key) {
1207
+ const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1208
+ const len0 = WASM_VECTOR_LEN;
1209
+ const ret = wasm.indexdb_findDocumentById(this.__wbg_ptr, ptr0, len0, addHeapObject(primary_key));
1210
+ return takeObject(ret);
1211
+ }
1212
+ /**
1213
+ * @param {string} collection_name
1214
+ * @param {any} query
1215
+ * @param {QueryOptions} options
1216
+ * @returns {Promise<any>}
1217
+ */
1218
+ count(collection_name, query, options) {
1219
+ const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1220
+ const len0 = WASM_VECTOR_LEN;
1221
+ _assertClass(options, QueryOptions2);
1222
+ var ptr1 = options.__destroy_into_raw();
1223
+ const ret = wasm.indexdb_count(this.__wbg_ptr, ptr0, len0, addHeapObject(query), ptr1);
1224
+ return takeObject(ret);
1225
+ }
1226
+ /**
1227
+ * @returns {Promise<any>}
1228
+ */
1229
+ close() {
1230
+ const ret = wasm.indexdb_close(this.__wbg_ptr);
1231
+ return takeObject(ret);
1232
+ }
1233
+ /**
1234
+ * @returns {Promise<any>}
1235
+ */
1236
+ start() {
1237
+ const ret = wasm.indexdb_start(this.__wbg_ptr);
1238
+ return takeObject(ret);
1239
+ }
1240
+ };
1241
+ var OperationFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1242
+ }, unregister: () => {
1243
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_operation_free(ptr >>> 0));
1244
+ var Operation2 = class _Operation {
1245
+ static __wrap(ptr) {
1246
+ ptr = ptr >>> 0;
1247
+ const obj = Object.create(_Operation.prototype);
1248
+ obj.__wbg_ptr = ptr;
1249
+ OperationFinalization.register(obj, obj.__wbg_ptr, obj);
1250
+ return obj;
1251
+ }
1252
+ __destroy_into_raw() {
1253
+ const ptr = this.__wbg_ptr;
1254
+ this.__wbg_ptr = 0;
1255
+ OperationFinalization.unregister(this);
1256
+ return ptr;
1257
+ }
1258
+ free() {
1259
+ const ptr = this.__destroy_into_raw();
1260
+ wasm.__wbg_operation_free(ptr);
1261
+ }
1262
+ /**
1263
+ * Retrieves the name of the collection.
1264
+ *
1265
+ * # Returns
1266
+ *
1267
+ * * `String` - The name of the collection.
1268
+ * @returns {string}
1269
+ */
1270
+ get collection() {
1271
+ let deferred1_0;
1272
+ let deferred1_1;
1273
+ try {
1274
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1275
+ wasm.operation_collection(retptr, this.__wbg_ptr);
1276
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1277
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1278
+ deferred1_0 = r0;
1279
+ deferred1_1 = r1;
1280
+ return getStringFromWasm0(r0, r1);
1281
+ } finally {
1282
+ wasm.__wbindgen_add_to_stack_pointer(16);
1283
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1284
+ }
1285
+ }
1286
+ /**
1287
+ * Retrieves the type of operation.
1288
+ *
1289
+ * # Returns
1290
+ *
1291
+ * * `OpType` - The type of operation.
1292
+ * @returns {OpType}
1293
+ */
1294
+ get opType() {
1295
+ const ret = wasm.operation_opType(this.__wbg_ptr);
1296
+ return ret;
1297
+ }
1298
+ /**
1299
+ * Retrieves the data involved in the operation.
1300
+ *
1301
+ * # Returns
1302
+ *
1303
+ * * `JsValue` - The data involved in the operation.
1304
+ * @returns {any}
1305
+ */
1306
+ get data() {
1307
+ const ret = wasm.operation_data(this.__wbg_ptr);
1308
+ return takeObject(ret);
1309
+ }
1310
+ /**
1311
+ * Retrieves the primary key field of the current collection.
1312
+ *
1313
+ * # Returns
1314
+ *
1315
+ * * `Option<String>` - The primary key field of the current collection.
1316
+ * @returns {any}
1317
+ */
1318
+ get primaryKeyField() {
1319
+ const ret = wasm.operation_primaryKeyField(this.__wbg_ptr);
1320
+ return takeObject(ret);
1321
+ }
1322
+ /**
1323
+ * Retrieves the primary key value of the current data.
1324
+ *
1325
+ * # Returns
1326
+ *
1327
+ * * `Option<JsValue>` - The primary key value of the current data.
1328
+ * @returns {any}
1329
+ */
1330
+ get primaryKey() {
1331
+ const ret = wasm.operation_primaryKey(this.__wbg_ptr);
1332
+ return takeObject(ret);
1333
+ }
1334
+ /**
1335
+ * @returns {string}
1336
+ */
1337
+ get primaryKeyIndex() {
1338
+ let deferred2_0;
1339
+ let deferred2_1;
1340
+ try {
1341
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1342
+ wasm.operation_primaryKeyIndex(retptr, this.__wbg_ptr);
1343
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1344
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1345
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1346
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
1347
+ var ptr1 = r0;
1348
+ var len1 = r1;
1349
+ if (r3) {
1350
+ ptr1 = 0;
1351
+ len1 = 0;
1352
+ throw takeObject(r2);
1353
+ }
1354
+ deferred2_0 = ptr1;
1355
+ deferred2_1 = len1;
1356
+ return getStringFromWasm0(ptr1, len1);
1357
+ } finally {
1358
+ wasm.__wbindgen_add_to_stack_pointer(16);
1359
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1360
+ }
1361
+ }
1362
+ };
1363
+ var PropertyFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1364
+ }, unregister: () => {
1365
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_property_free(ptr >>> 0));
1366
+ var Property = class {
1367
+ __destroy_into_raw() {
1368
+ const ptr = this.__wbg_ptr;
1369
+ this.__wbg_ptr = 0;
1370
+ PropertyFinalization.unregister(this);
1371
+ return ptr;
1372
+ }
1373
+ free() {
1374
+ const ptr = this.__destroy_into_raw();
1375
+ wasm.__wbg_property_free(ptr);
1376
+ }
1377
+ /**
1378
+ * Checks is the schema is valid.
1379
+ *
1380
+ * # Returns
1381
+ *
1382
+ * Throws exception if not valid
1383
+ * @returns {boolean}
1384
+ */
1385
+ is_valid() {
1386
+ try {
1387
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1388
+ wasm.property_is_valid(retptr, this.__wbg_ptr);
1389
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1390
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1391
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1392
+ if (r2) {
1393
+ throw takeObject(r1);
1394
+ }
1395
+ return r0 !== 0;
1396
+ } finally {
1397
+ wasm.__wbindgen_add_to_stack_pointer(16);
1398
+ }
1399
+ }
1400
+ /**
1401
+ * Retrieves the type of the property.
1402
+ *
1403
+ * # Returns
1404
+ *
1405
+ * * `PropertyType` - The type of the property.
1406
+ * @returns {any}
1407
+ */
1408
+ get type() {
1409
+ const ret = wasm.property_type(this.__wbg_ptr);
1410
+ return takeObject(ret);
1411
+ }
1412
+ /**
1413
+ * Retrieves the items of the property.
1414
+ *
1415
+ * # Returns
1416
+ *
1417
+ * * `Result<JsValue, JsValue>` - A result containing the items as a `JsValue` or an error.
1418
+ * @returns {any}
1419
+ */
1420
+ get items() {
1421
+ try {
1422
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1423
+ wasm.property_items(retptr, this.__wbg_ptr);
1424
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1425
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1426
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1427
+ if (r2) {
1428
+ throw takeObject(r1);
1429
+ }
1430
+ return takeObject(r0);
1431
+ } finally {
1432
+ wasm.__wbindgen_add_to_stack_pointer(16);
1433
+ }
1434
+ }
1435
+ /**
1436
+ * Retrieves the maximum number of items of the property.
1437
+ *
1438
+ * # Returns
1439
+ *
1440
+ * * `Result<JsValue, JsValue>` - A result containing the maximum number of items as a `JsValue` or an error.
1441
+ * @returns {any}
1442
+ */
1443
+ get maxItems() {
1444
+ try {
1445
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1446
+ wasm.property_maxItems(retptr, this.__wbg_ptr);
1447
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1448
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1449
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1450
+ if (r2) {
1451
+ throw takeObject(r1);
1452
+ }
1453
+ return takeObject(r0);
1454
+ } finally {
1455
+ wasm.__wbindgen_add_to_stack_pointer(16);
1456
+ }
1457
+ }
1458
+ /**
1459
+ * Retrieves the minimum number of items of the property.
1460
+ *
1461
+ * # Returns
1462
+ *
1463
+ * * `Result<JsValue, JsValue>` - A result containing the minimum number of items as a `JsValue` or an error.
1464
+ * @returns {any}
1465
+ */
1466
+ get minItems() {
1467
+ try {
1468
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1469
+ wasm.property_minItems(retptr, this.__wbg_ptr);
1470
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1471
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1472
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1473
+ if (r2) {
1474
+ throw takeObject(r1);
1475
+ }
1476
+ return takeObject(r0);
1477
+ } finally {
1478
+ wasm.__wbindgen_add_to_stack_pointer(16);
1479
+ }
1480
+ }
1481
+ /**
1482
+ * Retrieves the maximum length of the property.
1483
+ *
1484
+ * # Returns
1485
+ *
1486
+ * * `Result<JsValue, JsValue>` - A result containing the maximum length as a `JsValue` or an error.
1487
+ * @returns {any}
1488
+ */
1489
+ get maxLength() {
1490
+ try {
1491
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1492
+ wasm.property_maxLength(retptr, this.__wbg_ptr);
1493
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1494
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1495
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1496
+ if (r2) {
1497
+ throw takeObject(r1);
1498
+ }
1499
+ return takeObject(r0);
1500
+ } finally {
1501
+ wasm.__wbindgen_add_to_stack_pointer(16);
1502
+ }
1503
+ }
1504
+ /**
1505
+ * Retrieves the minimum length of the property.
1506
+ *
1507
+ * # Returns
1508
+ *
1509
+ * * `Result<JsValue, JsValue>` - A result containing the minimum length as a `JsValue` or an error.
1510
+ * @returns {any}
1511
+ */
1512
+ get minLength() {
1513
+ try {
1514
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1515
+ wasm.property_minLength(retptr, this.__wbg_ptr);
1516
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1517
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1518
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1519
+ if (r2) {
1520
+ throw takeObject(r1);
1521
+ }
1522
+ return takeObject(r0);
1523
+ } finally {
1524
+ wasm.__wbindgen_add_to_stack_pointer(16);
1525
+ }
1526
+ }
1527
+ /**
1528
+ * Retrieves the nested properties of the property.
1529
+ *
1530
+ * # Returns
1531
+ *
1532
+ * * `Result<JsValue, JsValue>` - A result containing the nested properties as a `JsValue` or an error.
1533
+ * @returns {any}
1534
+ */
1535
+ get properties() {
1536
+ try {
1537
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1538
+ wasm.property_properties(retptr, this.__wbg_ptr);
1539
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1540
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1541
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1542
+ if (r2) {
1543
+ throw takeObject(r1);
1544
+ }
1545
+ return takeObject(r0);
1546
+ } finally {
1547
+ wasm.__wbindgen_add_to_stack_pointer(16);
1548
+ }
1549
+ }
1550
+ };
1551
+ var QueryFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1552
+ }, unregister: () => {
1553
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_query_free(ptr >>> 0));
1554
+ var Query = class {
1555
+ __destroy_into_raw() {
1556
+ const ptr = this.__wbg_ptr;
1557
+ this.__wbg_ptr = 0;
1558
+ QueryFinalization.unregister(this);
1559
+ return ptr;
1560
+ }
1561
+ free() {
1562
+ const ptr = this.__destroy_into_raw();
1563
+ wasm.__wbg_query_free(ptr);
1564
+ }
1565
+ /**
1566
+ * @param {any} query
1567
+ * @param {Schema} schema
1568
+ */
1569
+ constructor(query, schema) {
1570
+ try {
1571
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1572
+ _assertClass(schema, Schema);
1573
+ var ptr0 = schema.__destroy_into_raw();
1574
+ wasm.query_new(retptr, addHeapObject(query), ptr0);
1575
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1576
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1577
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1578
+ if (r2) {
1579
+ throw takeObject(r1);
1580
+ }
1581
+ this.__wbg_ptr = r0 >>> 0;
1582
+ return this;
1583
+ } finally {
1584
+ wasm.__wbindgen_add_to_stack_pointer(16);
1585
+ }
1586
+ }
1587
+ /**
1588
+ * @returns {any}
1589
+ */
1590
+ get query() {
1591
+ try {
1592
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1593
+ wasm.query_query(retptr, this.__wbg_ptr);
1594
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1595
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1596
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1597
+ if (r2) {
1598
+ throw takeObject(r1);
1599
+ }
1600
+ return takeObject(r0);
1601
+ } finally {
1602
+ wasm.__wbindgen_add_to_stack_pointer(16);
1603
+ }
1604
+ }
1605
+ /**
1606
+ * Returns the schema properties (fields) that are used in the query.
1607
+ * The query may contain operators like $and, $or, $gt, $lt, etc.
1608
+ * @returns {(string)[]}
1609
+ */
1610
+ get_properties() {
1611
+ try {
1612
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1613
+ wasm.query_get_properties(retptr, this.__wbg_ptr);
1614
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1615
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1616
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1617
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
1618
+ if (r3) {
1619
+ throw takeObject(r2);
1620
+ }
1621
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
1622
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
1623
+ return v1;
1624
+ } finally {
1625
+ wasm.__wbindgen_add_to_stack_pointer(16);
1626
+ }
1627
+ }
1628
+ /**
1629
+ * @returns {any}
1630
+ */
1631
+ parse() {
1632
+ try {
1633
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1634
+ wasm.query_parse(retptr, this.__wbg_ptr);
1635
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1636
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1637
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1638
+ if (r2) {
1639
+ throw takeObject(r1);
1640
+ }
1641
+ return takeObject(r0);
1642
+ } finally {
1643
+ wasm.__wbindgen_add_to_stack_pointer(16);
1644
+ }
1645
+ }
1646
+ /**
1647
+ * @param {any} query
1648
+ * @returns {any}
1649
+ */
1650
+ process_query(query) {
1651
+ try {
1652
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1653
+ wasm.query_process_query(retptr, this.__wbg_ptr, addBorrowedObject(query));
1654
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1655
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1656
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1657
+ if (r2) {
1658
+ throw takeObject(r1);
1659
+ }
1660
+ return takeObject(r0);
1661
+ } finally {
1662
+ wasm.__wbindgen_add_to_stack_pointer(16);
1663
+ heap[stack_pointer++] = void 0;
1664
+ }
1665
+ }
1666
+ /**
1667
+ * Returns the value of a property from the (normalized) query by its name.
1668
+ * This will scan the normalized query structure (including arrays, $and/$or blocks, etc.)
1669
+ * to find the first occurrence of the given property name and return its corresponding value.
1670
+ *
1671
+ * If not found, an error is returned.
1672
+ *
1673
+ * Example:
1674
+ * let val = query.get("age")?;
1675
+ * // val is a JsValue that might be a number, string, boolean, array, or object (e.g., { "$gt": 30 })
1676
+ * @param {string} property_name
1677
+ * @returns {any}
1678
+ */
1679
+ get(property_name) {
1680
+ try {
1681
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1682
+ const ptr0 = passStringToWasm0(property_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1683
+ const len0 = WASM_VECTOR_LEN;
1684
+ wasm.query_get(retptr, this.__wbg_ptr, ptr0, len0);
1685
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1686
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1687
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1688
+ if (r2) {
1689
+ throw takeObject(r1);
1690
+ }
1691
+ return takeObject(r0);
1692
+ } finally {
1693
+ wasm.__wbindgen_add_to_stack_pointer(16);
1694
+ }
1695
+ }
1696
+ };
1697
+ var QueryOptionsFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1698
+ }, unregister: () => {
1699
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_queryoptions_free(ptr >>> 0));
1700
+ var QueryOptions2 = class _QueryOptions {
1701
+ static __wrap(ptr) {
1702
+ ptr = ptr >>> 0;
1703
+ const obj = Object.create(_QueryOptions.prototype);
1704
+ obj.__wbg_ptr = ptr;
1705
+ QueryOptionsFinalization.register(obj, obj.__wbg_ptr, obj);
1706
+ return obj;
1707
+ }
1708
+ __destroy_into_raw() {
1709
+ const ptr = this.__wbg_ptr;
1710
+ this.__wbg_ptr = 0;
1711
+ QueryOptionsFinalization.unregister(this);
1712
+ return ptr;
1713
+ }
1714
+ free() {
1715
+ const ptr = this.__destroy_into_raw();
1716
+ wasm.__wbg_queryoptions_free(ptr);
1717
+ }
1718
+ /**
1719
+ * @returns {any}
1720
+ */
1721
+ get limit() {
1722
+ try {
1723
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1724
+ wasm.queryoptions_limit(retptr, this.__wbg_ptr);
1725
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1726
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1727
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1728
+ if (r2) {
1729
+ throw takeObject(r1);
1730
+ }
1731
+ return takeObject(r0);
1732
+ } finally {
1733
+ wasm.__wbindgen_add_to_stack_pointer(16);
1734
+ }
1735
+ }
1736
+ /**
1737
+ * @returns {any}
1738
+ */
1739
+ get offset() {
1740
+ try {
1741
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1742
+ wasm.queryoptions_offset(retptr, this.__wbg_ptr);
1743
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1744
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1745
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1746
+ if (r2) {
1747
+ throw takeObject(r1);
1748
+ }
1749
+ return takeObject(r0);
1750
+ } finally {
1751
+ wasm.__wbindgen_add_to_stack_pointer(16);
1752
+ }
1753
+ }
1754
+ };
1755
+ var RIDBErrorFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1756
+ }, unregister: () => {
1757
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_ridberror_free(ptr >>> 0));
1758
+ var RIDBError = class _RIDBError {
1759
+ static __wrap(ptr) {
1760
+ ptr = ptr >>> 0;
1761
+ const obj = Object.create(_RIDBError.prototype);
1762
+ obj.__wbg_ptr = ptr;
1763
+ RIDBErrorFinalization.register(obj, obj.__wbg_ptr, obj);
1764
+ return obj;
1765
+ }
1766
+ toJSON() {
1767
+ return {
1768
+ type: this.type,
1769
+ code: this.code,
1770
+ message: this.message
1771
+ };
1772
+ }
1773
+ toString() {
1774
+ return JSON.stringify(this);
1775
+ }
1776
+ __destroy_into_raw() {
1777
+ const ptr = this.__wbg_ptr;
1778
+ this.__wbg_ptr = 0;
1779
+ RIDBErrorFinalization.unregister(this);
1780
+ return ptr;
1781
+ }
1782
+ free() {
1783
+ const ptr = this.__destroy_into_raw();
1784
+ wasm.__wbg_ridberror_free(ptr);
1785
+ }
1786
+ /**
1787
+ * @param {string} err_type
1788
+ * @param {string} message
1789
+ * @param {number} code
1790
+ */
1791
+ constructor(err_type, message, code) {
1792
+ const ptr0 = passStringToWasm0(err_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1793
+ const len0 = WASM_VECTOR_LEN;
1794
+ const ptr1 = passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1795
+ const len1 = WASM_VECTOR_LEN;
1796
+ const ret = wasm.ridberror_new(ptr0, len0, ptr1, len1, code);
1797
+ this.__wbg_ptr = ret >>> 0;
1798
+ return this;
1799
+ }
1800
+ /**
1801
+ * @returns {string}
1802
+ */
1803
+ get type() {
1804
+ let deferred1_0;
1805
+ let deferred1_1;
1806
+ try {
1807
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1808
+ wasm.ridberror_type(retptr, this.__wbg_ptr);
1809
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1810
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1811
+ deferred1_0 = r0;
1812
+ deferred1_1 = r1;
1813
+ return getStringFromWasm0(r0, r1);
1814
+ } finally {
1815
+ wasm.__wbindgen_add_to_stack_pointer(16);
1816
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1817
+ }
1818
+ }
1819
+ /**
1820
+ * @returns {any}
1821
+ */
1822
+ get code() {
1823
+ const ret = wasm.ridberror_code(this.__wbg_ptr);
1824
+ return takeObject(ret);
1825
+ }
1826
+ /**
1827
+ * @returns {string}
1828
+ */
1829
+ get message() {
1830
+ let deferred1_0;
1831
+ let deferred1_1;
1832
+ try {
1833
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1834
+ wasm.ridberror_message(retptr, this.__wbg_ptr);
1835
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1836
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1837
+ deferred1_0 = r0;
1838
+ deferred1_1 = r1;
1839
+ return getStringFromWasm0(r0, r1);
1840
+ } finally {
1841
+ wasm.__wbindgen_add_to_stack_pointer(16);
1842
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1843
+ }
1844
+ }
1845
+ /**
1846
+ * @param {any} err
1847
+ * @returns {RIDBError}
1848
+ */
1849
+ static from(err) {
1850
+ const ret = wasm.ridberror_from(addHeapObject(err));
1851
+ return _RIDBError.__wrap(ret);
1852
+ }
1853
+ /**
1854
+ * @param {string} err
1855
+ * @param {number} code
1856
+ * @returns {RIDBError}
1857
+ */
1858
+ static error(err, code) {
1859
+ const ptr0 = passStringToWasm0(err, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1860
+ const len0 = WASM_VECTOR_LEN;
1861
+ const ret = wasm.ridberror_error(ptr0, len0, code);
1862
+ return _RIDBError.__wrap(ret);
1863
+ }
1864
+ /**
1865
+ * @param {string} err
1866
+ * @param {number} code
1867
+ * @returns {RIDBError}
1868
+ */
1869
+ static query(err, code) {
1870
+ const ptr0 = passStringToWasm0(err, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1871
+ const len0 = WASM_VECTOR_LEN;
1872
+ const ret = wasm.ridberror_query(ptr0, len0, code);
1873
+ return _RIDBError.__wrap(ret);
1874
+ }
1875
+ /**
1876
+ * @param {string} err
1877
+ * @param {number} code
1878
+ * @returns {RIDBError}
1879
+ */
1880
+ static authentication(err, code) {
1881
+ const ptr0 = passStringToWasm0(err, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1882
+ const len0 = WASM_VECTOR_LEN;
1883
+ const ret = wasm.ridberror_authentication(ptr0, len0, code);
1884
+ return _RIDBError.__wrap(ret);
1885
+ }
1886
+ /**
1887
+ * @param {string} err
1888
+ * @param {number} code
1889
+ * @returns {RIDBError}
1890
+ */
1891
+ static serialisation(err, code) {
1892
+ const ptr0 = passStringToWasm0(err, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1893
+ const len0 = WASM_VECTOR_LEN;
1894
+ const ret = wasm.ridberror_serialisation(ptr0, len0, code);
1895
+ return _RIDBError.__wrap(ret);
1896
+ }
1897
+ /**
1898
+ * @param {string} err
1899
+ * @param {number} code
1900
+ * @returns {RIDBError}
1901
+ */
1902
+ static validation(err, code) {
1903
+ const ptr0 = passStringToWasm0(err, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1904
+ const len0 = WASM_VECTOR_LEN;
1905
+ const ret = wasm.ridberror_validation(ptr0, len0, code);
1906
+ return _RIDBError.__wrap(ret);
1907
+ }
1908
+ /**
1909
+ * @param {string} err
1910
+ * @param {number} code
1911
+ * @returns {RIDBError}
1912
+ */
1913
+ static hook(err, code) {
1914
+ const ptr0 = passStringToWasm0(err, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1915
+ const len0 = WASM_VECTOR_LEN;
1916
+ const ret = wasm.ridberror_hook(ptr0, len0, code);
1917
+ return _RIDBError.__wrap(ret);
1918
+ }
1919
+ };
1920
+ var SchemaFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
1921
+ }, unregister: () => {
1922
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_schema_free(ptr >>> 0));
1923
+ var Schema = class _Schema {
1924
+ static __wrap(ptr) {
1925
+ ptr = ptr >>> 0;
1926
+ const obj = Object.create(_Schema.prototype);
1927
+ obj.__wbg_ptr = ptr;
1928
+ SchemaFinalization.register(obj, obj.__wbg_ptr, obj);
1929
+ return obj;
1930
+ }
1931
+ __destroy_into_raw() {
1932
+ const ptr = this.__wbg_ptr;
1933
+ this.__wbg_ptr = 0;
1934
+ SchemaFinalization.unregister(this);
1935
+ return ptr;
1936
+ }
1937
+ free() {
1938
+ const ptr = this.__destroy_into_raw();
1939
+ wasm.__wbg_schema_free(ptr);
1940
+ }
1941
+ /**
1942
+ * @param {any} document
1943
+ */
1944
+ validate(document2) {
1945
+ try {
1946
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1947
+ wasm.schema_validate(retptr, this.__wbg_ptr, addHeapObject(document2));
1948
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1949
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1950
+ if (r1) {
1951
+ throw takeObject(r0);
1952
+ }
1953
+ } finally {
1954
+ wasm.__wbindgen_add_to_stack_pointer(16);
1955
+ }
1956
+ }
1957
+ /**
1958
+ * @returns {boolean}
1959
+ */
1960
+ is_valid() {
1961
+ try {
1962
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1963
+ wasm.schema_is_valid(retptr, this.__wbg_ptr);
1964
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1965
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1966
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1967
+ if (r2) {
1968
+ throw takeObject(r1);
1969
+ }
1970
+ return r0 !== 0;
1971
+ } finally {
1972
+ wasm.__wbindgen_add_to_stack_pointer(16);
1973
+ }
1974
+ }
1975
+ /**
1976
+ * Creates a new `Schema` instance from a given `JsValue`.
1977
+ *
1978
+ * # Arguments
1979
+ *
1980
+ * * `schema` - A `JsValue` representing the schema.
1981
+ *
1982
+ * # Returns
1983
+ *
1984
+ * * `Result<Schema, JsValue>` - A result containing the new `Schema` instance or an error.
1985
+ * @param {any} schema
1986
+ * @returns {Schema}
1987
+ */
1988
+ static create(schema) {
1989
+ try {
1990
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1991
+ wasm.schema_create(retptr, addHeapObject(schema));
1992
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1993
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1994
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1995
+ if (r2) {
1996
+ throw takeObject(r1);
1997
+ }
1998
+ return _Schema.__wrap(r0);
1999
+ } finally {
2000
+ wasm.__wbindgen_add_to_stack_pointer(16);
2001
+ }
2002
+ }
2003
+ /**
2004
+ * Retrieves the version of the schema.
2005
+ *
2006
+ * # Returns
2007
+ *
2008
+ * * `i32` - The version of the schema.
2009
+ * @returns {number}
2010
+ */
2011
+ get version() {
2012
+ const ret = wasm.schema_version(this.__wbg_ptr);
2013
+ return ret;
2014
+ }
2015
+ /**
2016
+ * Retrieves the primary key of the schema.
2017
+ *
2018
+ * # Returns
2019
+ *
2020
+ * * `String` - The primary key of the schema.
2021
+ * @returns {string}
2022
+ */
2023
+ get primaryKey() {
2024
+ let deferred1_0;
2025
+ let deferred1_1;
2026
+ try {
2027
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2028
+ wasm.schema_primaryKey(retptr, this.__wbg_ptr);
2029
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2030
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2031
+ deferred1_0 = r0;
2032
+ deferred1_1 = r1;
2033
+ return getStringFromWasm0(r0, r1);
2034
+ } finally {
2035
+ wasm.__wbindgen_add_to_stack_pointer(16);
2036
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
2037
+ }
2038
+ }
2039
+ /**
2040
+ * Retrieves the type of the schema.
2041
+ *
2042
+ * # Returns
2043
+ *
2044
+ * * `String` - The type of the schema.
2045
+ * @returns {string}
2046
+ */
2047
+ get type() {
2048
+ let deferred1_0;
2049
+ let deferred1_1;
2050
+ try {
2051
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2052
+ wasm.schema_type(retptr, this.__wbg_ptr);
2053
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2054
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2055
+ deferred1_0 = r0;
2056
+ deferred1_1 = r1;
2057
+ return getStringFromWasm0(r0, r1);
2058
+ } finally {
2059
+ wasm.__wbindgen_add_to_stack_pointer(16);
2060
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
2061
+ }
2062
+ }
2063
+ /**
2064
+ * Retrieves the indexes of the schema, if any.
2065
+ *
2066
+ * # Returns
2067
+ *
2068
+ * * `Option<Vec<String>>` - The indexes of the schema, if any.
2069
+ * @returns {(string)[] | undefined}
2070
+ */
2071
+ get indexes() {
2072
+ try {
2073
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2074
+ wasm.schema_indexes(retptr, this.__wbg_ptr);
2075
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2076
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2077
+ let v1;
2078
+ if (r0 !== 0) {
2079
+ v1 = getArrayJsValueFromWasm0(r0, r1).slice();
2080
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
2081
+ }
2082
+ return v1;
2083
+ } finally {
2084
+ wasm.__wbindgen_add_to_stack_pointer(16);
2085
+ }
2086
+ }
2087
+ /**
2088
+ * @returns {(string)[] | undefined}
2089
+ */
2090
+ get encrypted() {
2091
+ try {
2092
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2093
+ wasm.schema_encrypted(retptr, this.__wbg_ptr);
2094
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2095
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2096
+ let v1;
2097
+ if (r0 !== 0) {
2098
+ v1 = getArrayJsValueFromWasm0(r0, r1).slice();
2099
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
2100
+ }
2101
+ return v1;
2102
+ } finally {
2103
+ wasm.__wbindgen_add_to_stack_pointer(16);
2104
+ }
2105
+ }
2106
+ /**
2107
+ * Retrieves the properties of the schema.
2108
+ *
2109
+ * # Returns
2110
+ *
2111
+ * * `Result<JsValue, JsValue>` - A result containing the properties as a `JsValue` or an error.
2112
+ * @returns {any}
2113
+ */
2114
+ get properties() {
2115
+ try {
2116
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2117
+ wasm.schema_properties(retptr, this.__wbg_ptr);
2118
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2119
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2120
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2121
+ if (r2) {
2122
+ throw takeObject(r1);
2123
+ }
2124
+ return takeObject(r0);
2125
+ } finally {
2126
+ wasm.__wbindgen_add_to_stack_pointer(16);
2127
+ }
2128
+ }
2129
+ };
2130
+ var WasmBindgenTestContextFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
2131
+ }, unregister: () => {
2132
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_wasmbindgentestcontext_free(ptr >>> 0));
2133
+ var WasmBindgenTestContext = class {
2134
+ __destroy_into_raw() {
2135
+ const ptr = this.__wbg_ptr;
2136
+ this.__wbg_ptr = 0;
2137
+ WasmBindgenTestContextFinalization.unregister(this);
2138
+ return ptr;
2139
+ }
2140
+ free() {
2141
+ const ptr = this.__destroy_into_raw();
2142
+ wasm.__wbg_wasmbindgentestcontext_free(ptr);
2143
+ }
2144
+ /**
2145
+ * Creates a new context ready to run tests.
2146
+ *
2147
+ * A `Context` is the main structure through which test execution is
2148
+ * coordinated, and this will collect output and results for all executed
2149
+ * tests.
2150
+ */
2151
+ constructor() {
2152
+ const ret = wasm.wasmbindgentestcontext_new();
2153
+ this.__wbg_ptr = ret >>> 0;
2154
+ return this;
2155
+ }
2156
+ /**
2157
+ * Inform this context about runtime arguments passed to the test
2158
+ * harness.
2159
+ * @param {any[]} args
2160
+ */
2161
+ args(args) {
2162
+ const ptr0 = passArrayJsValueToWasm0(args, wasm.__wbindgen_malloc);
2163
+ const len0 = WASM_VECTOR_LEN;
2164
+ wasm.wasmbindgentestcontext_args(this.__wbg_ptr, ptr0, len0);
2165
+ }
2166
+ /**
2167
+ * Executes a list of tests, returning a promise representing their
2168
+ * eventual completion.
2169
+ *
2170
+ * This is the main entry point for executing tests. All the tests passed
2171
+ * in are the JS `Function` object that was plucked off the
2172
+ * `WebAssembly.Instance` exports list.
2173
+ *
2174
+ * The promise returned resolves to either `true` if all tests passed or
2175
+ * `false` if at least one test failed.
2176
+ * @param {any[]} tests
2177
+ * @returns {Promise<any>}
2178
+ */
2179
+ run(tests) {
2180
+ const ptr0 = passArrayJsValueToWasm0(tests, wasm.__wbindgen_malloc);
2181
+ const len0 = WASM_VECTOR_LEN;
2182
+ const ret = wasm.wasmbindgentestcontext_run(this.__wbg_ptr, ptr0, len0);
2183
+ return takeObject(ret);
2184
+ }
2185
+ };
2186
+ async function __wbg_load(module2, imports) {
2187
+ if (typeof Response === "function" && module2 instanceof Response) {
2188
+ if (typeof WebAssembly.instantiateStreaming === "function") {
2189
+ try {
2190
+ return await WebAssembly.instantiateStreaming(module2, imports);
2191
+ } catch (e) {
2192
+ if (module2.headers.get("Content-Type") != "application/wasm") {
2193
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
2194
+ } else {
2195
+ throw e;
2196
+ }
2197
+ }
2198
+ }
2199
+ const bytes = await module2.arrayBuffer();
2200
+ return await WebAssembly.instantiate(bytes, imports);
2201
+ } else {
2202
+ const instance = await WebAssembly.instantiate(module2, imports);
2203
+ if (instance instanceof WebAssembly.Instance) {
2204
+ return { instance, module: module2 };
2205
+ } else {
2206
+ return instance;
2207
+ }
2208
+ }
2209
+ }
2210
+ function __wbg_get_imports() {
2211
+ const imports = {};
2212
+ imports.wbg = {};
2213
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
2214
+ takeObject(arg0);
2215
+ };
2216
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
2217
+ const ret = getStringFromWasm0(arg0, arg1);
2218
+ return addHeapObject(ret);
2219
+ };
2220
+ imports.wbg.__wbg_ridberror_new = function(arg0) {
2221
+ const ret = RIDBError.__wrap(arg0);
2222
+ return addHeapObject(ret);
2223
+ };
2224
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
2225
+ const ret = getObject(arg0);
2226
+ return addHeapObject(ret);
2227
+ };
2228
+ imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
2229
+ const obj = getObject(arg1);
2230
+ const ret = typeof obj === "string" ? obj : void 0;
2231
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2232
+ var len1 = WASM_VECTOR_LEN;
2233
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2234
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2235
+ };
2236
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
2237
+ const ret = getObject(arg0) === void 0;
2238
+ return ret;
2239
+ };
2240
+ imports.wbg.__wbindgen_number_new = function(arg0) {
2241
+ const ret = arg0;
2242
+ return addHeapObject(ret);
2243
+ };
2244
+ imports.wbg.__wbg_apply_9f557eba1534d597 = function() {
2245
+ return handleError(function(arg0, arg1, arg2) {
2246
+ const ret = getObject(arg1).apply(takeObject(arg2));
2247
+ const ptr1 = passArrayJsValueToWasm0(ret, wasm.__wbindgen_malloc);
2248
+ const len1 = WASM_VECTOR_LEN;
2249
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2250
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2251
+ }, arguments);
2252
+ };
2253
+ imports.wbg.__wbg_inmemory_new = function(arg0) {
2254
+ const ret = InMemory.__wrap(arg0);
2255
+ return addHeapObject(ret);
2256
+ };
2257
+ imports.wbg.__wbindgen_is_null = function(arg0) {
2258
+ const ret = getObject(arg0) === null;
2259
+ return ret;
2260
+ };
2261
+ imports.wbg.__wbg_close_6384ed3c27ef25c1 = function() {
2262
+ return handleError(function(arg0) {
2263
+ const ret = getObject(arg0).close();
2264
+ return addHeapObject(ret);
2265
+ }, arguments);
2266
+ };
2267
+ imports.wbg.__wbindgen_cb_drop = function(arg0) {
2268
+ const obj = takeObject(arg0).original;
2269
+ if (obj.cnt-- == 1) {
2270
+ obj.a = 0;
2271
+ return true;
2272
+ }
2273
+ const ret = false;
2274
+ return ret;
2275
+ };
2276
+ imports.wbg.__wbg_count_19db4c3174d573d5 = function() {
2277
+ return handleError(function(arg0, arg1, arg2, arg3, arg4) {
2278
+ const ret = getObject(arg0).count(getStringFromWasm0(arg1, arg2), takeObject(arg3), QueryOptions2.__wrap(arg4));
2279
+ return addHeapObject(ret);
2280
+ }, arguments);
2281
+ };
2282
+ imports.wbg.__wbg_start_76c138c3b73ae6f8 = function() {
2283
+ return handleError(function(arg0) {
2284
+ const ret = getObject(arg0).start();
2285
+ return addHeapObject(ret);
2286
+ }, arguments);
2287
+ };
2288
+ imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
2289
+ const obj = getObject(arg1);
2290
+ const ret = typeof obj === "number" ? obj : void 0;
2291
+ getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
2292
+ getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
2293
+ };
2294
+ imports.wbg.__wbg_find_567c5c9f064fe3d2 = function() {
2295
+ return handleError(function(arg0, arg1, arg2, arg3, arg4) {
2296
+ const ret = getObject(arg0).find(getStringFromWasm0(arg1, arg2), takeObject(arg3), QueryOptions2.__wrap(arg4));
2297
+ return addHeapObject(ret);
2298
+ }, arguments);
2299
+ };
2300
+ imports.wbg.__wbg_findDocumentById_2edf7350e5f12657 = function() {
2301
+ return handleError(function(arg0, arg1, arg2, arg3) {
2302
+ const ret = getObject(arg0).findDocumentById(getStringFromWasm0(arg1, arg2), takeObject(arg3));
2303
+ return addHeapObject(ret);
2304
+ }, arguments);
2305
+ };
2306
+ imports.wbg.__wbg_write_1159c67c07f62020 = function() {
2307
+ return handleError(function(arg0, arg1) {
2308
+ const ret = getObject(arg0).write(Operation2.__wrap(arg1));
2309
+ return addHeapObject(ret);
2310
+ }, arguments);
2311
+ };
2312
+ imports.wbg.__wbg_indexdb_new = function(arg0) {
2313
+ const ret = IndexDB.__wrap(arg0);
2314
+ return addHeapObject(ret);
2315
+ };
2316
+ imports.wbg.__wbg_database_new = function(arg0) {
2317
+ const ret = Database.__wrap(arg0);
2318
+ return addHeapObject(ret);
2319
+ };
2320
+ imports.wbg.__wbg_collection_new = function(arg0) {
2321
+ const ret = Collection.__wrap(arg0);
2322
+ return addHeapObject(ret);
2323
+ };
2324
+ imports.wbg.__wbindgen_is_object = function(arg0) {
2325
+ const val = getObject(arg0);
2326
+ const ret = typeof val === "object" && val !== null;
2327
+ return ret;
2328
+ };
2329
+ imports.wbg.__wbindgen_is_string = function(arg0) {
2330
+ const ret = typeof getObject(arg0) === "string";
2331
+ return ret;
2332
+ };
2333
+ imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
2334
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
2335
+ return addHeapObject(ret);
2336
+ };
2337
+ imports.wbg.__wbindgen_is_array = function(arg0) {
2338
+ const ret = Array.isArray(getObject(arg0));
2339
+ return ret;
2340
+ };
2341
+ imports.wbg.__wbindgen_boolean_get = function(arg0) {
2342
+ const v = getObject(arg0);
2343
+ const ret = typeof v === "boolean" ? v ? 1 : 0 : 2;
2344
+ return ret;
2345
+ };
2346
+ imports.wbg.__wbindgen_is_falsy = function(arg0) {
2347
+ const ret = !getObject(arg0);
2348
+ return ret;
2349
+ };
2350
+ imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
2351
+ const ret = getObject(arg0) === getObject(arg1);
2352
+ return ret;
2353
+ };
2354
+ imports.wbg.__wbindgen_is_function = function(arg0) {
2355
+ const ret = typeof getObject(arg0) === "function";
2356
+ return ret;
2357
+ };
2358
+ imports.wbg.__wbindgen_is_bigint = function(arg0) {
2359
+ const ret = typeof getObject(arg0) === "bigint";
2360
+ return ret;
2361
+ };
2362
+ imports.wbg.__wbindgen_in = function(arg0, arg1) {
2363
+ const ret = getObject(arg0) in getObject(arg1);
2364
+ return ret;
2365
+ };
2366
+ imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
2367
+ const ret = arg0;
2368
+ return addHeapObject(ret);
2369
+ };
2370
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
2371
+ const ret = BigInt.asUintN(64, arg0);
2372
+ return addHeapObject(ret);
2373
+ };
2374
+ imports.wbg.__wbg_crypto_1d1f22824a6a080c = function(arg0) {
2375
+ const ret = getObject(arg0).crypto;
2376
+ return addHeapObject(ret);
2377
+ };
2378
+ imports.wbg.__wbg_process_4a72847cc503995b = function(arg0) {
2379
+ const ret = getObject(arg0).process;
2380
+ return addHeapObject(ret);
2381
+ };
2382
+ imports.wbg.__wbg_versions_f686565e586dd935 = function(arg0) {
2383
+ const ret = getObject(arg0).versions;
2384
+ return addHeapObject(ret);
2385
+ };
2386
+ imports.wbg.__wbg_node_104a2ff8d6ea03a2 = function(arg0) {
2387
+ const ret = getObject(arg0).node;
2388
+ return addHeapObject(ret);
2389
+ };
2390
+ imports.wbg.__wbg_require_cca90b1a94a0255b = function() {
2391
+ return handleError(function() {
2392
+ const ret = module.require;
2393
+ return addHeapObject(ret);
2394
+ }, arguments);
2395
+ };
2396
+ imports.wbg.__wbg_msCrypto_eb05e62b530a1508 = function(arg0) {
2397
+ const ret = getObject(arg0).msCrypto;
2398
+ return addHeapObject(ret);
2399
+ };
2400
+ imports.wbg.__wbg_randomFillSync_5c9c955aa56b6049 = function() {
2401
+ return handleError(function(arg0, arg1) {
2402
+ getObject(arg0).randomFillSync(takeObject(arg1));
2403
+ }, arguments);
2404
+ };
2405
+ imports.wbg.__wbg_getRandomValues_3aa56aa6edec874c = function() {
2406
+ return handleError(function(arg0, arg1) {
2407
+ getObject(arg0).getRandomValues(getObject(arg1));
2408
+ }, arguments);
2409
+ };
2410
+ imports.wbg.__wbg_instanceof_Window_f401953a2cf86220 = function(arg0) {
2411
+ let result;
2412
+ try {
2413
+ result = getObject(arg0) instanceof Window;
2414
+ } catch (_) {
2415
+ result = false;
2416
+ }
2417
+ const ret = result;
2418
+ return ret;
2419
+ };
2420
+ imports.wbg.__wbg_indexedDB_7c51d9056667f4e0 = function() {
2421
+ return handleError(function(arg0) {
2422
+ const ret = getObject(arg0).indexedDB;
2423
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2424
+ }, arguments);
2425
+ };
2426
+ imports.wbg.__wbg_setTimeout_c172d5704ef82276 = function() {
2427
+ return handleError(function(arg0, arg1, arg2) {
2428
+ const ret = getObject(arg0).setTimeout(getObject(arg1), arg2);
2429
+ return ret;
2430
+ }, arguments);
2431
+ };
2432
+ imports.wbg.__wbg_instanceof_WorkerGlobalScope_46b577f151fad960 = function(arg0) {
2433
+ let result;
2434
+ try {
2435
+ result = getObject(arg0) instanceof WorkerGlobalScope;
2436
+ } catch (_) {
2437
+ result = false;
2438
+ }
2439
+ const ret = result;
2440
+ return ret;
2441
+ };
2442
+ imports.wbg.__wbg_indexedDB_d312f95759a15fdc = function() {
2443
+ return handleError(function(arg0) {
2444
+ const ret = getObject(arg0).indexedDB;
2445
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2446
+ }, arguments);
2447
+ };
2448
+ imports.wbg.__wbg_setTimeout_8502a960d5dde06e = function() {
2449
+ return handleError(function(arg0, arg1, arg2) {
2450
+ const ret = getObject(arg0).setTimeout(getObject(arg1), arg2);
2451
+ return ret;
2452
+ }, arguments);
2453
+ };
2454
+ imports.wbg.__wbg_debug_5fb96680aecf5dc8 = function(arg0) {
2455
+ console.debug(getObject(arg0));
2456
+ };
2457
+ imports.wbg.__wbg_openCursor_425aba9cbe1d4d39 = function() {
2458
+ return handleError(function(arg0) {
2459
+ const ret = getObject(arg0).openCursor();
2460
+ return addHeapObject(ret);
2461
+ }, arguments);
2462
+ };
2463
+ imports.wbg.__wbg_openCursor_e3042770817a8d57 = function() {
2464
+ return handleError(function(arg0, arg1) {
2465
+ const ret = getObject(arg0).openCursor(getObject(arg1));
2466
+ return addHeapObject(ret);
2467
+ }, arguments);
2468
+ };
2469
+ imports.wbg.__wbg_createIndex_b8da1f5571f644be = function() {
2470
+ return handleError(function(arg0, arg1, arg2, arg3, arg4, arg5) {
2471
+ const ret = getObject(arg0).createIndex(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4), getObject(arg5));
2472
+ return addHeapObject(ret);
2473
+ }, arguments);
2474
+ };
2475
+ imports.wbg.__wbg_delete_f60bba7d0ae59a4f = function() {
2476
+ return handleError(function(arg0, arg1) {
2477
+ const ret = getObject(arg0).delete(getObject(arg1));
2478
+ return addHeapObject(ret);
2479
+ }, arguments);
2480
+ };
2481
+ imports.wbg.__wbg_get_5361b64cac0d0826 = function() {
2482
+ return handleError(function(arg0, arg1) {
2483
+ const ret = getObject(arg0).get(getObject(arg1));
2484
+ return addHeapObject(ret);
2485
+ }, arguments);
2486
+ };
2487
+ imports.wbg.__wbg_index_383b6812c1508030 = function() {
2488
+ return handleError(function(arg0, arg1, arg2) {
2489
+ const ret = getObject(arg0).index(getStringFromWasm0(arg1, arg2));
2490
+ return addHeapObject(ret);
2491
+ }, arguments);
2492
+ };
2493
+ imports.wbg.__wbg_openCursor_30d58ae27a327629 = function() {
2494
+ return handleError(function(arg0) {
2495
+ const ret = getObject(arg0).openCursor();
2496
+ return addHeapObject(ret);
2497
+ }, arguments);
2498
+ };
2499
+ imports.wbg.__wbg_openCursor_611b1e488c393dd8 = function() {
2500
+ return handleError(function(arg0, arg1) {
2501
+ const ret = getObject(arg0).openCursor(getObject(arg1));
2502
+ return addHeapObject(ret);
2503
+ }, arguments);
2504
+ };
2505
+ imports.wbg.__wbg_put_22792e17580ca18b = function() {
2506
+ return handleError(function(arg0, arg1, arg2) {
2507
+ const ret = getObject(arg0).put(getObject(arg1), getObject(arg2));
2508
+ return addHeapObject(ret);
2509
+ }, arguments);
2510
+ };
2511
+ imports.wbg.__wbg_target_2fc177e386c8b7b0 = function(arg0) {
2512
+ const ret = getObject(arg0).target;
2513
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2514
+ };
2515
+ imports.wbg.__wbg_instanceof_IdbDatabase_db671cf2454a9542 = function(arg0) {
2516
+ let result;
2517
+ try {
2518
+ result = getObject(arg0) instanceof IDBDatabase;
2519
+ } catch (_) {
2520
+ result = false;
2521
+ }
2522
+ const ret = result;
2523
+ return ret;
2524
+ };
2525
+ imports.wbg.__wbg_objectStoreNames_588b5924274239fd = function(arg0) {
2526
+ const ret = getObject(arg0).objectStoreNames;
2527
+ return addHeapObject(ret);
2528
+ };
2529
+ imports.wbg.__wbg_close_6bfe4ca2fe67cb67 = function(arg0) {
2530
+ getObject(arg0).close();
2531
+ };
2532
+ imports.wbg.__wbg_createObjectStore_882f2f6b1b1ef040 = function() {
2533
+ return handleError(function(arg0, arg1, arg2) {
2534
+ const ret = getObject(arg0).createObjectStore(getStringFromWasm0(arg1, arg2));
2535
+ return addHeapObject(ret);
2536
+ }, arguments);
2537
+ };
2538
+ imports.wbg.__wbg_transaction_c32bb10c9c692f4b = function() {
2539
+ return handleError(function(arg0, arg1, arg2) {
2540
+ const ret = getObject(arg0).transaction(getStringFromWasm0(arg1, arg2));
2541
+ return addHeapObject(ret);
2542
+ }, arguments);
2543
+ };
2544
+ imports.wbg.__wbg_transaction_1e282a79e9bb7387 = function() {
2545
+ return handleError(function(arg0, arg1, arg2, arg3) {
2546
+ const ret = getObject(arg0).transaction(getStringFromWasm0(arg1, arg2), takeObject(arg3));
2547
+ return addHeapObject(ret);
2548
+ }, arguments);
2549
+ };
2550
+ imports.wbg.__wbg_objectStore_da468793bd9df17b = function() {
2551
+ return handleError(function(arg0, arg1, arg2) {
2552
+ const ret = getObject(arg0).objectStore(getStringFromWasm0(arg1, arg2));
2553
+ return addHeapObject(ret);
2554
+ }, arguments);
2555
+ };
2556
+ imports.wbg.__wbg_continue_f1c3e0815924de62 = function() {
2557
+ return handleError(function(arg0) {
2558
+ getObject(arg0).continue();
2559
+ }, arguments);
2560
+ };
2561
+ imports.wbg.__wbg_length_9ae5daf9a690cba9 = function(arg0) {
2562
+ const ret = getObject(arg0).length;
2563
+ return ret;
2564
+ };
2565
+ imports.wbg.__wbg_contains_c65b44400b549286 = function(arg0, arg1, arg2) {
2566
+ const ret = getObject(arg0).contains(getStringFromWasm0(arg1, arg2));
2567
+ return ret;
2568
+ };
2569
+ imports.wbg.__wbg_get_910bbb94abdcf488 = function(arg0, arg1, arg2) {
2570
+ const ret = getObject(arg1)[arg2 >>> 0];
2571
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2572
+ var len1 = WASM_VECTOR_LEN;
2573
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2574
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2575
+ };
2576
+ imports.wbg.__wbg_instanceof_IdbCursorWithValue_abeb44d13d947bc2 = function(arg0) {
2577
+ let result;
2578
+ try {
2579
+ result = getObject(arg0) instanceof IDBCursorWithValue;
2580
+ } catch (_) {
2581
+ result = false;
2582
+ }
2583
+ const ret = result;
2584
+ return ret;
2585
+ };
2586
+ imports.wbg.__wbg_value_86d3334f5075b232 = function() {
2587
+ return handleError(function(arg0) {
2588
+ const ret = getObject(arg0).value;
2589
+ return addHeapObject(ret);
2590
+ }, arguments);
2591
+ };
2592
+ imports.wbg.__wbg_open_f0d7259fd7e689ce = function() {
2593
+ return handleError(function(arg0, arg1, arg2, arg3) {
2594
+ const ret = getObject(arg0).open(getStringFromWasm0(arg1, arg2), arg3 >>> 0);
2595
+ return addHeapObject(ret);
2596
+ }, arguments);
2597
+ };
2598
+ imports.wbg.__wbg_only_cacf767244bdc280 = function() {
2599
+ return handleError(function(arg0) {
2600
+ const ret = IDBKeyRange.only(getObject(arg0));
2601
+ return addHeapObject(ret);
2602
+ }, arguments);
2603
+ };
2604
+ imports.wbg.__wbg_instanceof_IdbOpenDbRequest_3f4a166bc0340578 = function(arg0) {
2605
+ let result;
2606
+ try {
2607
+ result = getObject(arg0) instanceof IDBOpenDBRequest;
2608
+ } catch (_) {
2609
+ result = false;
2610
+ }
2611
+ const ret = result;
2612
+ return ret;
2613
+ };
2614
+ imports.wbg.__wbg_setonupgradeneeded_ad7645373c7d5e1b = function(arg0, arg1) {
2615
+ getObject(arg0).onupgradeneeded = getObject(arg1);
2616
+ };
2617
+ imports.wbg.__wbg_instanceof_IdbRequest_93249da04f5370b6 = function(arg0) {
2618
+ let result;
2619
+ try {
2620
+ result = getObject(arg0) instanceof IDBRequest;
2621
+ } catch (_) {
2622
+ result = false;
2623
+ }
2624
+ const ret = result;
2625
+ return ret;
2626
+ };
2627
+ imports.wbg.__wbg_result_6cedf5f78600a79c = function() {
2628
+ return handleError(function(arg0) {
2629
+ const ret = getObject(arg0).result;
2630
+ return addHeapObject(ret);
2631
+ }, arguments);
2632
+ };
2633
+ imports.wbg.__wbg_error_685b20024dc2d6ca = function() {
2634
+ return handleError(function(arg0) {
2635
+ const ret = getObject(arg0).error;
2636
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2637
+ }, arguments);
2638
+ };
2639
+ imports.wbg.__wbg_setonsuccess_632ce0a1460455c2 = function(arg0, arg1) {
2640
+ getObject(arg0).onsuccess = getObject(arg1);
2641
+ };
2642
+ imports.wbg.__wbg_setonerror_8479b33e7568a904 = function(arg0, arg1) {
2643
+ getObject(arg0).onerror = getObject(arg1);
2644
+ };
2645
+ imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
2646
+ const ret = getObject(arg0) == getObject(arg1);
2647
+ return ret;
2648
+ };
2649
+ imports.wbg.__wbindgen_as_number = function(arg0) {
2650
+ const ret = +getObject(arg0);
2651
+ return ret;
2652
+ };
2653
+ imports.wbg.__wbg_String_389b54bd9d25375f = function(arg0, arg1) {
2654
+ const ret = String(getObject(arg1));
2655
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2656
+ const len1 = WASM_VECTOR_LEN;
2657
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2658
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2659
+ };
2660
+ imports.wbg.__wbg_getwithrefkey_4a92a5eca60879b9 = function(arg0, arg1) {
2661
+ const ret = getObject(arg0)[getObject(arg1)];
2662
+ return addHeapObject(ret);
2663
+ };
2664
+ imports.wbg.__wbg_set_9182712abebf82ef = function(arg0, arg1, arg2) {
2665
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
2666
+ };
2667
+ imports.wbg.__wbg_log_28eee4e6432efd24 = function(arg0, arg1) {
2668
+ console.log(getStringFromWasm0(arg0, arg1));
2669
+ };
2670
+ imports.wbg.__wbg_String_55b8bdc4bc243677 = function(arg0, arg1) {
2671
+ const ret = String(getObject(arg1));
2672
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2673
+ const len1 = WASM_VECTOR_LEN;
2674
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2675
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2676
+ };
2677
+ imports.wbg.__wbg_getElementById_8458f2a6c28467dc = function(arg0, arg1, arg2) {
2678
+ const ret = getObject(arg0).getElementById(getStringFromWasm0(arg1, arg2));
2679
+ return addHeapObject(ret);
2680
+ };
2681
+ imports.wbg.__wbg_settextcontent_fc3ff485b96fcb1d = function(arg0, arg1, arg2) {
2682
+ getObject(arg0).textContent = getStringFromWasm0(arg1, arg2);
2683
+ };
2684
+ imports.wbg.__wbg_wbgtestinvoke_8c20f4132af2bded = function() {
2685
+ return handleError(function(arg0, arg1) {
2686
+ try {
2687
+ var state0 = { a: arg0, b: arg1 };
2688
+ var cb0 = () => {
2689
+ const a = state0.a;
2690
+ state0.a = 0;
2691
+ try {
2692
+ return __wbg_adapter_292(a, state0.b);
2693
+ } finally {
2694
+ state0.a = a;
2695
+ }
2696
+ };
2697
+ __wbg_test_invoke(cb0);
2698
+ } finally {
2699
+ state0.a = state0.b = 0;
2700
+ }
2701
+ }, arguments);
2702
+ };
2703
+ imports.wbg.__wbg_static_accessor_document_d4b6ae7f5578480f = function() {
2704
+ const ret = document;
2705
+ return addHeapObject(ret);
2706
+ };
2707
+ imports.wbg.__wbg_stack_17c77e9f5bfe6714 = function(arg0, arg1) {
2708
+ const ret = getObject(arg1).stack;
2709
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2710
+ const len1 = WASM_VECTOR_LEN;
2711
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2712
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2713
+ };
2714
+ imports.wbg.__wbg_self_55106357ec10ecd4 = function(arg0) {
2715
+ const ret = getObject(arg0).self;
2716
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2717
+ };
2718
+ imports.wbg.__wbg_constructor_fd0d22d60b7dfd72 = function(arg0) {
2719
+ const ret = getObject(arg0).constructor;
2720
+ return addHeapObject(ret);
2721
+ };
2722
+ imports.wbg.__wbg_name_7f439d24ff7ba1d3 = function(arg0, arg1) {
2723
+ const ret = getObject(arg1).name;
2724
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2725
+ const len1 = WASM_VECTOR_LEN;
2726
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2727
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2728
+ };
2729
+ imports.wbg.__wbg_textcontent_67e4e811cbdf00fc = function(arg0, arg1) {
2730
+ const ret = getObject(arg1).textContent;
2731
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2732
+ const len1 = WASM_VECTOR_LEN;
2733
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2734
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2735
+ };
2736
+ imports.wbg.__wbg_stack_44743fb7d71926a0 = function(arg0) {
2737
+ const ret = getObject(arg0).stack;
2738
+ return addHeapObject(ret);
2739
+ };
2740
+ imports.wbg.__wbg_wbgtestoutputwriteln_4db3bd64914ec955 = function(arg0) {
2741
+ __wbg_test_output_writeln(takeObject(arg0));
2742
+ };
2743
+ imports.wbg.__wbg_stack_436273c21658169b = function(arg0) {
2744
+ const ret = getObject(arg0).stack;
2745
+ return addHeapObject(ret);
2746
+ };
2747
+ imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
2748
+ const ret = new Error();
2749
+ return addHeapObject(ret);
2750
+ };
2751
+ imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
2752
+ const ret = getObject(arg1).stack;
2753
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2754
+ const len1 = WASM_VECTOR_LEN;
2755
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
2756
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
2757
+ };
2758
+ imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
2759
+ let deferred0_0;
2760
+ let deferred0_1;
2761
+ try {
2762
+ deferred0_0 = arg0;
2763
+ deferred0_1 = arg1;
2764
+ console.error(getStringFromWasm0(arg0, arg1));
2765
+ } finally {
2766
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
2767
+ }
2768
+ };
2769
+ imports.wbg.__wbg_queueMicrotask_481971b0d87f3dd4 = function(arg0) {
2770
+ queueMicrotask(getObject(arg0));
2771
+ };
2772
+ imports.wbg.__wbg_queueMicrotask_3cbae2ec6b6cd3d6 = function(arg0) {
2773
+ const ret = getObject(arg0).queueMicrotask;
2774
+ return addHeapObject(ret);
2775
+ };
2776
+ imports.wbg.__wbg_get_bd8e338fbd5f5cc8 = function(arg0, arg1) {
2777
+ const ret = getObject(arg0)[arg1 >>> 0];
2778
+ return addHeapObject(ret);
2779
+ };
2780
+ imports.wbg.__wbg_length_cd7af8117672b8b8 = function(arg0) {
2781
+ const ret = getObject(arg0).length;
2782
+ return ret;
2783
+ };
2784
+ imports.wbg.__wbg_new_16b304a2cfa7ff4a = function() {
2785
+ const ret = new Array();
2786
+ return addHeapObject(ret);
2787
+ };
2788
+ imports.wbg.__wbg_newnoargs_e258087cd0daa0ea = function(arg0, arg1) {
2789
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
2790
+ return addHeapObject(ret);
2791
+ };
2792
+ imports.wbg.__wbg_new_d9bc3a0147634640 = function() {
2793
+ const ret = /* @__PURE__ */ new Map();
2794
+ return addHeapObject(ret);
2795
+ };
2796
+ imports.wbg.__wbg_next_40fc327bfc8770e6 = function(arg0) {
2797
+ const ret = getObject(arg0).next;
2798
+ return addHeapObject(ret);
2799
+ };
2800
+ imports.wbg.__wbg_next_196c84450b364254 = function() {
2801
+ return handleError(function(arg0) {
2802
+ const ret = getObject(arg0).next();
2803
+ return addHeapObject(ret);
2804
+ }, arguments);
2805
+ };
2806
+ imports.wbg.__wbg_done_298b57d23c0fc80c = function(arg0) {
2807
+ const ret = getObject(arg0).done;
2808
+ return ret;
2809
+ };
2810
+ imports.wbg.__wbg_value_d93c65011f51a456 = function(arg0) {
2811
+ const ret = getObject(arg0).value;
2812
+ return addHeapObject(ret);
2813
+ };
2814
+ imports.wbg.__wbg_iterator_2cee6dadfd956dfa = function() {
2815
+ const ret = Symbol.iterator;
2816
+ return addHeapObject(ret);
2817
+ };
2818
+ imports.wbg.__wbg_get_e3c254076557e348 = function() {
2819
+ return handleError(function(arg0, arg1) {
2820
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
2821
+ return addHeapObject(ret);
2822
+ }, arguments);
2823
+ };
2824
+ imports.wbg.__wbg_call_27c0f87801dedf93 = function() {
2825
+ return handleError(function(arg0, arg1) {
2826
+ const ret = getObject(arg0).call(getObject(arg1));
2827
+ return addHeapObject(ret);
2828
+ }, arguments);
2829
+ };
2830
+ imports.wbg.__wbg_new_72fb9a18b5ae2624 = function() {
2831
+ const ret = new Object();
2832
+ return addHeapObject(ret);
2833
+ };
2834
+ imports.wbg.__wbg_self_ce0dbfc45cf2f5be = function() {
2835
+ return handleError(function() {
2836
+ const ret = self.self;
2837
+ return addHeapObject(ret);
2838
+ }, arguments);
2839
+ };
2840
+ imports.wbg.__wbg_window_c6fb939a7f436783 = function() {
2841
+ return handleError(function() {
2842
+ const ret = window.window;
2843
+ return addHeapObject(ret);
2844
+ }, arguments);
2845
+ };
2846
+ imports.wbg.__wbg_globalThis_d1e6af4856ba331b = function() {
2847
+ return handleError(function() {
2848
+ const ret = globalThis.globalThis;
2849
+ return addHeapObject(ret);
2850
+ }, arguments);
2851
+ };
2852
+ imports.wbg.__wbg_global_207b558942527489 = function() {
2853
+ return handleError(function() {
2854
+ const ret = global.global;
2855
+ return addHeapObject(ret);
2856
+ }, arguments);
2857
+ };
2858
+ imports.wbg.__wbg_set_d4638f722068f043 = function(arg0, arg1, arg2) {
2859
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
2860
+ };
2861
+ imports.wbg.__wbg_from_89e3fc3ba5e6fb48 = function(arg0) {
2862
+ const ret = Array.from(getObject(arg0));
2863
+ return addHeapObject(ret);
2864
+ };
2865
+ imports.wbg.__wbg_forEach_2be8de7347d63332 = function(arg0, arg1, arg2) {
2866
+ try {
2867
+ var state0 = { a: arg1, b: arg2 };
2868
+ var cb0 = (arg02, arg12, arg22) => {
2869
+ const a = state0.a;
2870
+ state0.a = 0;
2871
+ try {
2872
+ return __wbg_adapter_335(a, state0.b, arg02, arg12, arg22);
2873
+ } finally {
2874
+ state0.a = a;
2875
+ }
2876
+ };
2877
+ getObject(arg0).forEach(cb0);
2878
+ } finally {
2879
+ state0.a = state0.b = 0;
2880
+ }
2881
+ };
2882
+ imports.wbg.__wbg_isArray_2ab64d95e09ea0ae = function(arg0) {
2883
+ const ret = Array.isArray(getObject(arg0));
2884
+ return ret;
2885
+ };
2886
+ imports.wbg.__wbg_of_4a2b313a453ec059 = function(arg0) {
2887
+ const ret = Array.of(getObject(arg0));
2888
+ return addHeapObject(ret);
2889
+ };
2890
+ imports.wbg.__wbg_push_a5b05aedc7234f9f = function(arg0, arg1) {
2891
+ const ret = getObject(arg0).push(getObject(arg1));
2892
+ return ret;
2893
+ };
2894
+ imports.wbg.__wbg_instanceof_ArrayBuffer_836825be07d4c9d2 = function(arg0) {
2895
+ let result;
2896
+ try {
2897
+ result = getObject(arg0) instanceof ArrayBuffer;
2898
+ } catch (_) {
2899
+ result = false;
2900
+ }
2901
+ const ret = result;
2902
+ return ret;
2903
+ };
2904
+ imports.wbg.__wbg_message_5bf28016c2b49cfb = function(arg0) {
2905
+ const ret = getObject(arg0).message;
2906
+ return addHeapObject(ret);
2907
+ };
2908
+ imports.wbg.__wbg_name_e7429f0dda6079e2 = function(arg0) {
2909
+ const ret = getObject(arg0).name;
2910
+ return addHeapObject(ret);
2911
+ };
2912
+ imports.wbg.__wbg_call_b3ca7c6051f9bec1 = function() {
2913
+ return handleError(function(arg0, arg1, arg2) {
2914
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
2915
+ return addHeapObject(ret);
2916
+ }, arguments);
2917
+ };
2918
+ imports.wbg.__wbg_call_938992c832f74314 = function() {
2919
+ return handleError(function(arg0, arg1, arg2, arg3, arg4) {
2920
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4));
2921
+ return addHeapObject(ret);
2922
+ }, arguments);
2923
+ };
2924
+ imports.wbg.__wbg_set_8417257aaedc936b = function(arg0, arg1, arg2) {
2925
+ const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
2926
+ return addHeapObject(ret);
2927
+ };
2928
+ imports.wbg.__wbg_isSafeInteger_f7b04ef02296c4d2 = function(arg0) {
2929
+ const ret = Number.isSafeInteger(getObject(arg0));
2930
+ return ret;
2931
+ };
2932
+ imports.wbg.__wbg_getTime_2bc4375165f02d15 = function(arg0) {
2933
+ const ret = getObject(arg0).getTime();
2934
+ return ret;
2935
+ };
2936
+ imports.wbg.__wbg_new0_7d84e5b2cd9fdc73 = function() {
2937
+ const ret = /* @__PURE__ */ new Date();
2938
+ return addHeapObject(ret);
2939
+ };
2940
+ imports.wbg.__wbg_instanceof_Object_71ca3c0a59266746 = function(arg0) {
2941
+ let result;
2942
+ try {
2943
+ result = getObject(arg0) instanceof Object;
2944
+ } catch (_) {
2945
+ result = false;
2946
+ }
2947
+ const ret = result;
2948
+ return ret;
2949
+ };
2950
+ imports.wbg.__wbg_assign_496d2d14fecafbcf = function(arg0, arg1) {
2951
+ const ret = Object.assign(getObject(arg0), getObject(arg1));
2952
+ return addHeapObject(ret);
2953
+ };
2954
+ imports.wbg.__wbg_entries_95cc2c823b285a09 = function(arg0) {
2955
+ const ret = Object.entries(getObject(arg0));
2956
+ return addHeapObject(ret);
2957
+ };
2958
+ imports.wbg.__wbg_is_010fdc0f4ab96916 = function(arg0, arg1) {
2959
+ const ret = Object.is(getObject(arg0), getObject(arg1));
2960
+ return ret;
2961
+ };
2962
+ imports.wbg.__wbg_keys_91e412b4b222659f = function(arg0) {
2963
+ const ret = Object.keys(getObject(arg0));
2964
+ return addHeapObject(ret);
2965
+ };
2966
+ imports.wbg.__wbg_new_81740750da40724f = function(arg0, arg1) {
2967
+ try {
2968
+ var state0 = { a: arg0, b: arg1 };
2969
+ var cb0 = (arg02, arg12) => {
2970
+ const a = state0.a;
2971
+ state0.a = 0;
2972
+ try {
2973
+ return __wbg_adapter_392(a, state0.b, arg02, arg12);
2974
+ } finally {
2975
+ state0.a = a;
2976
+ }
2977
+ };
2978
+ const ret = new Promise(cb0);
2979
+ return addHeapObject(ret);
2980
+ } finally {
2981
+ state0.a = state0.b = 0;
2982
+ }
2983
+ };
2984
+ imports.wbg.__wbg_resolve_b0083a7967828ec8 = function(arg0) {
2985
+ const ret = Promise.resolve(getObject(arg0));
2986
+ return addHeapObject(ret);
2987
+ };
2988
+ imports.wbg.__wbg_then_0c86a60e8fcfe9f6 = function(arg0, arg1) {
2989
+ const ret = getObject(arg0).then(getObject(arg1));
2990
+ return addHeapObject(ret);
2991
+ };
2992
+ imports.wbg.__wbg_then_a73caa9a87991566 = function(arg0, arg1, arg2) {
2993
+ const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
2994
+ return addHeapObject(ret);
2995
+ };
2996
+ imports.wbg.__wbg_buffer_12d079cc21e14bdb = function(arg0) {
2997
+ const ret = getObject(arg0).buffer;
2998
+ return addHeapObject(ret);
2999
+ };
3000
+ imports.wbg.__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb = function(arg0, arg1, arg2) {
3001
+ const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
3002
+ return addHeapObject(ret);
3003
+ };
3004
+ imports.wbg.__wbg_new_63b92bc8671ed464 = function(arg0) {
3005
+ const ret = new Uint8Array(getObject(arg0));
3006
+ return addHeapObject(ret);
3007
+ };
3008
+ imports.wbg.__wbg_set_a47bac70306a19a7 = function(arg0, arg1, arg2) {
3009
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
3010
+ };
3011
+ imports.wbg.__wbg_length_c20a40f15020d68a = function(arg0) {
3012
+ const ret = getObject(arg0).length;
3013
+ return ret;
3014
+ };
3015
+ imports.wbg.__wbg_instanceof_Uint8Array_2b3bbecd033d19f6 = function(arg0) {
3016
+ let result;
3017
+ try {
3018
+ result = getObject(arg0) instanceof Uint8Array;
3019
+ } catch (_) {
3020
+ result = false;
3021
+ }
3022
+ const ret = result;
3023
+ return ret;
3024
+ };
3025
+ imports.wbg.__wbg_newwithlength_e9b4878cebadb3d3 = function(arg0) {
3026
+ const ret = new Uint8Array(arg0 >>> 0);
3027
+ return addHeapObject(ret);
3028
+ };
3029
+ imports.wbg.__wbg_subarray_a1f73cd4b5b42fe1 = function(arg0, arg1, arg2) {
3030
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
3031
+ return addHeapObject(ret);
3032
+ };
3033
+ imports.wbg.__wbg_apply_0a5aa603881e6d79 = function() {
3034
+ return handleError(function(arg0, arg1, arg2) {
3035
+ const ret = Reflect.apply(getObject(arg0), getObject(arg1), getObject(arg2));
3036
+ return addHeapObject(ret);
3037
+ }, arguments);
3038
+ };
3039
+ imports.wbg.__wbg_deleteProperty_13e721a56f19e842 = function() {
3040
+ return handleError(function(arg0, arg1) {
3041
+ const ret = Reflect.deleteProperty(getObject(arg0), getObject(arg1));
3042
+ return ret;
3043
+ }, arguments);
3044
+ };
3045
+ imports.wbg.__wbg_has_0af94d20077affa2 = function() {
3046
+ return handleError(function(arg0, arg1) {
3047
+ const ret = Reflect.has(getObject(arg0), getObject(arg1));
3048
+ return ret;
3049
+ }, arguments);
3050
+ };
3051
+ imports.wbg.__wbg_set_1f9b04f170055d33 = function() {
3052
+ return handleError(function(arg0, arg1, arg2) {
3053
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
3054
+ return ret;
3055
+ }, arguments);
3056
+ };
3057
+ imports.wbg.__wbg_parse_66d1801634e099ac = function() {
3058
+ return handleError(function(arg0, arg1) {
3059
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
3060
+ return addHeapObject(ret);
3061
+ }, arguments);
3062
+ };
3063
+ imports.wbg.__wbg_stringify_8887fe74e1c50d81 = function() {
3064
+ return handleError(function(arg0) {
3065
+ const ret = JSON.stringify(getObject(arg0));
3066
+ return addHeapObject(ret);
3067
+ }, arguments);
3068
+ };
3069
+ imports.wbg.__wbindgen_bigint_get_as_i64 = function(arg0, arg1) {
3070
+ const v = getObject(arg1);
3071
+ const ret = typeof v === "bigint" ? v : void 0;
3072
+ getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret;
3073
+ getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
3074
+ };
3075
+ imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
3076
+ const ret = debugString(getObject(arg1));
3077
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
3078
+ const len1 = WASM_VECTOR_LEN;
3079
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
3080
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
3081
+ };
3082
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
3083
+ throw new Error(getStringFromWasm0(arg0, arg1));
3084
+ };
3085
+ imports.wbg.__wbindgen_memory = function() {
3086
+ const ret = wasm.memory;
3087
+ return addHeapObject(ret);
3088
+ };
3089
+ imports.wbg.__wbindgen_closure_wrapper814 = function(arg0, arg1, arg2) {
3090
+ const ret = makeClosure(arg0, arg1, 336, __wbg_adapter_56);
3091
+ return addHeapObject(ret);
3092
+ };
3093
+ imports.wbg.__wbindgen_closure_wrapper816 = function(arg0, arg1, arg2) {
3094
+ const ret = makeMutClosure(arg0, arg1, 336, __wbg_adapter_59);
3095
+ return addHeapObject(ret);
3096
+ };
3097
+ imports.wbg.__wbindgen_closure_wrapper818 = function(arg0, arg1, arg2) {
3098
+ const ret = makeMutClosure(arg0, arg1, 336, __wbg_adapter_62);
3099
+ return addHeapObject(ret);
3100
+ };
3101
+ imports.wbg.__wbindgen_closure_wrapper1616 = function(arg0, arg1, arg2) {
3102
+ const ret = makeMutClosure(arg0, arg1, 441, __wbg_adapter_65);
3103
+ return addHeapObject(ret);
3104
+ };
3105
+ return imports;
3106
+ }
3107
+ function __wbg_init_memory(imports, maybe_memory) {
3108
+ }
3109
+ function __wbg_finalize_init(instance, module2) {
3110
+ wasm = instance.exports;
3111
+ __wbg_init.__wbindgen_wasm_module = module2;
3112
+ cachedBigInt64Memory0 = null;
3113
+ cachedFloat64Memory0 = null;
3114
+ cachedInt32Memory0 = null;
3115
+ cachedUint32Memory0 = null;
3116
+ cachedUint8Memory0 = null;
3117
+ wasm.__wbindgen_start();
3118
+ return wasm;
3119
+ }
3120
+ function initSync(module2) {
3121
+ if (wasm !== void 0) return wasm;
3122
+ const imports = __wbg_get_imports();
3123
+ __wbg_init_memory(imports);
3124
+ if (!(module2 instanceof WebAssembly.Module)) {
3125
+ module2 = new WebAssembly.Module(module2);
3126
+ }
3127
+ const instance = new WebAssembly.Instance(module2, imports);
3128
+ return __wbg_finalize_init(instance, module2);
3129
+ }
3130
+ async function __wbg_init(input) {
3131
+ if (wasm !== void 0) return wasm;
3132
+ const imports = __wbg_get_imports();
3133
+ if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
3134
+ input = fetch(input);
3135
+ }
3136
+ __wbg_init_memory(imports);
3137
+ const { instance, module: module2 } = await __wbg_load(await input, imports);
3138
+ return __wbg_finalize_init(instance, module2);
3139
+ }
3140
+ var ridb_core_default = __wbg_init;
3141
+ }
3142
+ });
3143
+
3144
+ // src/index.ts
3145
+ var import_ridb_core = __toESM(require_ridb_core());
3146
+ import {
3147
+ WasmInternal
3148
+ } from "@trust0/ridb";
3149
+ var MongoDBStorage = class _MongoDBStorage extends import_ridb_core.BaseStorage {
3150
+ client;
3151
+ db;
3152
+ mongoConfig;
3153
+ constructor(name, schemas, options = {}) {
3154
+ super(name, schemas, options);
3155
+ this.mongoConfig = options;
3156
+ }
3157
+ /**
3158
+ * Utility method to recursively convert ObjectId values to strings throughout an object
3159
+ * This ensures that MongoDB's ObjectId instances are never returned to the application layer,
3160
+ * maintaining consistency with RIDB's string-based approach and preventing serialization issues.
3161
+ * Also removes MongoDB's automatic _id field entirely from results.
3162
+ * @private
3163
+ */
3164
+ convertObjectIdsToStrings(obj) {
3165
+ if (!obj || typeof obj !== "object") {
3166
+ return obj;
3167
+ }
3168
+ if (obj.constructor?.name === "ObjectId" || obj._bsontype && obj._bsontype === "ObjectId") {
3169
+ const stringValue = obj.toString();
3170
+ return stringValue;
3171
+ }
3172
+ if (Array.isArray(obj)) {
3173
+ return obj.map((item) => this.convertObjectIdsToStrings(item));
3174
+ }
3175
+ const converted = {};
3176
+ for (const [key, value] of Object.entries(obj)) {
3177
+ if (key === "_id") {
3178
+ continue;
3179
+ }
3180
+ converted[key] = this.convertObjectIdsToStrings(value);
3181
+ }
3182
+ return converted;
3183
+ }
3184
+ /**
3185
+ * Create a new MongoDB storage instance
3186
+ * @param name - Database name
3187
+ * @param schemas - Collection schemas
3188
+ * @param options - Storage options including MongoDB connection details
3189
+ * @returns A new Instance of MongoDB storage
3190
+ * @public
3191
+ */
3192
+ static async create(name, schemas, options = {}) {
3193
+ const db = new _MongoDBStorage(name, schemas, options);
3194
+ return db;
3195
+ }
3196
+ /** Start the database connection */
3197
+ async start() {
3198
+ const { MongoClient } = await import("mongodb");
3199
+ const url = this.mongoConfig.url || process.env.MONGODB_URL || "mongodb://localhost:27017";
3200
+ const dbName = this.mongoConfig.dbName || this.name;
3201
+ this.client = new MongoClient(url, this.mongoConfig.mongoOptions || {});
3202
+ await this.client.connect();
3203
+ this.db = this.client.db(dbName);
3204
+ }
3205
+ /** Close the database connection */
3206
+ async close() {
3207
+ if (this.client) {
3208
+ await this.client.close();
3209
+ this.client = void 0;
3210
+ this.db = void 0;
3211
+ }
3212
+ }
3213
+ /** Get MongoDB collection for a given collection name */
3214
+ getCollection(collectionName) {
3215
+ if (!this.db) {
3216
+ throw new Error("Database not started. Call start() first.");
3217
+ }
3218
+ const collection = this.db.collection(collectionName);
3219
+ return collection;
3220
+ }
3221
+ /** Find a document by its ID */
3222
+ async findDocumentById(collectionName, id) {
3223
+ const collection = this.getCollection(String(collectionName));
3224
+ const schema = this.getSchema(String(collectionName));
3225
+ const primaryKey = schema.primaryKey;
3226
+ const query = { [primaryKey]: id };
3227
+ const doc = await collection.findOne(query);
3228
+ if (!doc) {
3229
+ return null;
3230
+ }
3231
+ const converted = this.convertObjectIdsToStrings(doc);
3232
+ return converted;
3233
+ }
3234
+ /** Write an operation (insert, update, delete) */
3235
+ async write(op) {
3236
+ const collectionName = String(op.collection);
3237
+ const collection = this.getCollection(collectionName);
3238
+ const { primaryKey } = this.getSchema(collectionName);
3239
+ switch (op.opType) {
3240
+ case import_ridb_core.OpType.CREATE: {
3241
+ const id = primaryKey in op.data ? op.data[primaryKey] : null;
3242
+ if (!id) {
3243
+ throw new Error("Document ID is required");
3244
+ }
3245
+ const existQuery = { [primaryKey]: id };
3246
+ const existing = await collection.findOne(existQuery);
3247
+ if (existing) {
3248
+ throw new Error(`Document with ${primaryKey} '${id}' already exists`);
3249
+ }
3250
+ const docToInsert = { ...op.data };
3251
+ const insertResult = await collection.insertOne(docToInsert);
3252
+ const result = this.convertObjectIdsToStrings(op.data);
3253
+ return result;
3254
+ }
3255
+ case import_ridb_core.OpType.UPDATE: {
3256
+ const id = primaryKey in op.data ? op.data[primaryKey] : null;
3257
+ if (!id) {
3258
+ throw new Error("Document ID is required");
3259
+ }
3260
+ const updateQuery = { [primaryKey]: id };
3261
+ const updateData = { $set: op.data };
3262
+ const result = await collection.updateOne(updateQuery, updateData);
3263
+ if (result.matchedCount === 0) {
3264
+ throw new Error("Document ID not found");
3265
+ }
3266
+ const convertedResult = this.convertObjectIdsToStrings(op.data);
3267
+ return convertedResult;
3268
+ }
3269
+ case import_ridb_core.OpType.DELETE: {
3270
+ const id = op.data;
3271
+ const deleteQuery = { [primaryKey]: id };
3272
+ const result = await collection.deleteOne(deleteQuery);
3273
+ if (result.deletedCount === 0) {
3274
+ throw new Error("Document ID not found");
3275
+ }
3276
+ const convertedResult = this.convertObjectIdsToStrings(op.data);
3277
+ return convertedResult;
3278
+ }
3279
+ default:
3280
+ throw new Error(`Unknown operation type: ${op.opType}`);
3281
+ }
3282
+ }
3283
+ /** Convert RIDB query to MongoDB filter */
3284
+ convertQueryToMongoFilter(query, schema) {
3285
+ if (!query || typeof query !== "object") {
3286
+ return {};
3287
+ }
3288
+ const filter = {};
3289
+ for (const [key, value] of Object.entries(query)) {
3290
+ if (value === null || value === void 0) {
3291
+ filter[key] = { $exists: false };
3292
+ } else if (typeof value === "object" && value !== null) {
3293
+ if ("$in" in value) {
3294
+ filter[key] = { $in: this.convertObjectIdsToStrings(value.$in) };
3295
+ } else if ("$nin" in value) {
3296
+ filter[key] = { $nin: this.convertObjectIdsToStrings(value.$nin) };
3297
+ } else if ("$gt" in value) {
3298
+ filter[key] = { $gt: this.convertObjectIdsToStrings(value.$gt) };
3299
+ } else if ("$gte" in value) {
3300
+ filter[key] = { $gte: this.convertObjectIdsToStrings(value.$gte) };
3301
+ } else if ("$lt" in value) {
3302
+ filter[key] = { $lt: this.convertObjectIdsToStrings(value.$lt) };
3303
+ } else if ("$lte" in value) {
3304
+ filter[key] = { $lte: this.convertObjectIdsToStrings(value.$lte) };
3305
+ } else if ("$ne" in value) {
3306
+ filter[key] = { $ne: this.convertObjectIdsToStrings(value.$ne) };
3307
+ } else if ("$regex" in value) {
3308
+ filter[key] = { $regex: value.$regex };
3309
+ } else {
3310
+ filter[key] = this.convertObjectIdsToStrings(value);
3311
+ }
3312
+ } else {
3313
+ filter[key] = this.convertObjectIdsToStrings(value);
3314
+ }
3315
+ }
3316
+ return filter;
3317
+ }
3318
+ /** Count documents matching a query (supports offset & limit) */
3319
+ async count(collectionName, query, options) {
3320
+ const collection = this.getCollection(String(collectionName));
3321
+ const schema = this.getSchema(String(collectionName));
3322
+ const filter = this.convertQueryToMongoFilter(query, schema);
3323
+ let countOptions = {};
3324
+ if (options?.offset) {
3325
+ countOptions.skip = options.offset;
3326
+ }
3327
+ if (options?.limit) {
3328
+ countOptions.limit = options.limit;
3329
+ }
3330
+ const count = await collection.countDocuments(filter, Object.keys(countOptions).length > 0 ? countOptions : void 0);
3331
+ return count;
3332
+ }
3333
+ /** Find documents matching a query with pagination */
3334
+ async find(collectionName, query, options) {
3335
+ const collection = this.getCollection(String(collectionName));
3336
+ const schema = this.getSchema(String(collectionName));
3337
+ const filter = this.convertQueryToMongoFilter(query, schema);
3338
+ let findQuery = collection.find(filter);
3339
+ if (options?.offset) {
3340
+ findQuery = findQuery.skip(options.offset);
3341
+ }
3342
+ if (options?.limit) {
3343
+ findQuery = findQuery.limit(options.limit);
3344
+ }
3345
+ const docs = await findQuery.toArray();
3346
+ const convertedDocs = docs.map((doc) => this.convertObjectIdsToStrings(doc));
3347
+ return convertedDocs;
3348
+ }
3349
+ };
3350
+ async function createMongoDB() {
3351
+ const { BaseStorage: base } = await WasmInternal();
3352
+ Object.setPrototypeOf(MongoDBStorage.prototype, base.prototype);
3353
+ return MongoDBStorage;
3354
+ }
3355
+ export {
3356
+ MongoDBStorage,
3357
+ createMongoDB as default
3358
+ };