@trust0/ridb-mongodb 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/build/index.d.ts +3 -45
- package/build/index.js +342 -354
- package/build/index.mjs +342 -355
- package/package.json +5 -6
package/build/index.js
CHANGED
|
@@ -76,7 +76,7 @@ var require_ridb_core = __commonJS({
|
|
|
76
76
|
var ridb_core_exports = {};
|
|
77
77
|
__export2(ridb_core_exports, {
|
|
78
78
|
BasePlugin: () => BasePlugin,
|
|
79
|
-
BaseStorage: () =>
|
|
79
|
+
BaseStorage: () => BaseStorage,
|
|
80
80
|
Collection: () => Collection,
|
|
81
81
|
CoreStorage: () => CoreStorage,
|
|
82
82
|
Database: () => Database,
|
|
@@ -84,10 +84,10 @@ var require_ridb_core = __commonJS({
|
|
|
84
84
|
InMemory: () => InMemory,
|
|
85
85
|
IndexDB: () => IndexDB,
|
|
86
86
|
OpType: () => OpType2,
|
|
87
|
-
Operation: () =>
|
|
87
|
+
Operation: () => Operation,
|
|
88
88
|
Property: () => Property,
|
|
89
89
|
Query: () => Query,
|
|
90
|
-
QueryOptions: () =>
|
|
90
|
+
QueryOptions: () => QueryOptions,
|
|
91
91
|
RIDBError: () => RIDBError,
|
|
92
92
|
Schema: () => Schema,
|
|
93
93
|
WasmBindgenTestContext: () => WasmBindgenTestContext,
|
|
@@ -272,6 +272,30 @@ ${val.stack}`;
|
|
|
272
272
|
} } : new FinalizationRegistry((state) => {
|
|
273
273
|
wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);
|
|
274
274
|
});
|
|
275
|
+
function makeMutClosure(arg0, arg1, dtor, f) {
|
|
276
|
+
const state = { a: arg0, b: arg1, cnt: 1, dtor };
|
|
277
|
+
const real = (...args) => {
|
|
278
|
+
state.cnt++;
|
|
279
|
+
const a = state.a;
|
|
280
|
+
state.a = 0;
|
|
281
|
+
try {
|
|
282
|
+
return f(a, state.b, ...args);
|
|
283
|
+
} finally {
|
|
284
|
+
if (--state.cnt === 0) {
|
|
285
|
+
wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
|
|
286
|
+
CLOSURE_DTORS.unregister(state);
|
|
287
|
+
} else {
|
|
288
|
+
state.a = a;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
real.original = state;
|
|
293
|
+
CLOSURE_DTORS.register(real, state, state);
|
|
294
|
+
return real;
|
|
295
|
+
}
|
|
296
|
+
function __wbg_adapter_56(arg0, arg1, arg2) {
|
|
297
|
+
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hcf4fe6fd0b7ccc8d(arg0, arg1, addHeapObject(arg2));
|
|
298
|
+
}
|
|
275
299
|
function makeClosure(arg0, arg1, dtor, f) {
|
|
276
300
|
const state = { a: arg0, b: arg1, cnt: 1, dtor };
|
|
277
301
|
const real = (...args) => {
|
|
@@ -290,10 +314,10 @@ ${val.stack}`;
|
|
|
290
314
|
CLOSURE_DTORS.register(real, state, state);
|
|
291
315
|
return real;
|
|
292
316
|
}
|
|
293
|
-
function
|
|
317
|
+
function __wbg_adapter_59(arg0, arg1, arg2, arg3, arg4) {
|
|
294
318
|
try {
|
|
295
319
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
296
|
-
wasm.
|
|
320
|
+
wasm._dyn_core__ops__function__Fn__A_B_C___Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he6024291054ff5aa(retptr, arg0, arg1, addHeapObject(arg2), addHeapObject(arg3), addHeapObject(arg4));
|
|
297
321
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
298
322
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
299
323
|
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
@@ -305,35 +329,8 @@ ${val.stack}`;
|
|
|
305
329
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
306
330
|
}
|
|
307
331
|
}
|
|
308
|
-
function
|
|
309
|
-
|
|
310
|
-
const real = (...args) => {
|
|
311
|
-
state.cnt++;
|
|
312
|
-
const a = state.a;
|
|
313
|
-
state.a = 0;
|
|
314
|
-
try {
|
|
315
|
-
return f(a, state.b, ...args);
|
|
316
|
-
} finally {
|
|
317
|
-
if (--state.cnt === 0) {
|
|
318
|
-
wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
|
|
319
|
-
CLOSURE_DTORS.unregister(state);
|
|
320
|
-
} else {
|
|
321
|
-
state.a = a;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
real.original = state;
|
|
326
|
-
CLOSURE_DTORS.register(real, state, state);
|
|
327
|
-
return real;
|
|
328
|
-
}
|
|
329
|
-
function __wbg_adapter_59(arg0, arg1, arg2) {
|
|
330
|
-
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4e550b82c2b30c7a(arg0, arg1, addHeapObject(arg2));
|
|
331
|
-
}
|
|
332
|
-
function __wbg_adapter_62(arg0, arg1) {
|
|
333
|
-
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hec0cc069f718ed78(arg0, arg1);
|
|
334
|
-
}
|
|
335
|
-
function __wbg_adapter_65(arg0, arg1, arg2) {
|
|
336
|
-
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf401bdfdf8c9bdd9(arg0, arg1, addHeapObject(arg2));
|
|
332
|
+
function __wbg_adapter_62(arg0, arg1, arg2) {
|
|
333
|
+
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hb6eb1f8e3b5e56e9(arg0, arg1, addHeapObject(arg2));
|
|
337
334
|
}
|
|
338
335
|
var cachedUint32Memory0 = null;
|
|
339
336
|
function getUint32Memory0() {
|
|
@@ -352,6 +349,13 @@ ${val.stack}`;
|
|
|
352
349
|
}
|
|
353
350
|
return result;
|
|
354
351
|
}
|
|
352
|
+
function main_js() {
|
|
353
|
+
wasm.main_js();
|
|
354
|
+
}
|
|
355
|
+
function is_debug_mode() {
|
|
356
|
+
const ret = wasm.is_debug_mode();
|
|
357
|
+
return ret !== 0;
|
|
358
|
+
}
|
|
355
359
|
function _assertClass(instance, klass) {
|
|
356
360
|
if (!(instance instanceof klass)) {
|
|
357
361
|
throw new Error(`expected instance of ${klass.name}`);
|
|
@@ -380,13 +384,6 @@ ${val.stack}`;
|
|
|
380
384
|
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
381
385
|
}
|
|
382
386
|
}
|
|
383
|
-
function main_js() {
|
|
384
|
-
wasm.main_js();
|
|
385
|
-
}
|
|
386
|
-
function is_debug_mode() {
|
|
387
|
-
const ret = wasm.is_debug_mode();
|
|
388
|
-
return ret !== 0;
|
|
389
|
-
}
|
|
390
387
|
function __wbgtest_console_log(args) {
|
|
391
388
|
try {
|
|
392
389
|
wasm.__wbgtest_console_log(addBorrowedObject(args));
|
|
@@ -422,14 +419,14 @@ ${val.stack}`;
|
|
|
422
419
|
heap[stack_pointer++] = void 0;
|
|
423
420
|
}
|
|
424
421
|
}
|
|
425
|
-
function
|
|
426
|
-
wasm.
|
|
422
|
+
function __wbg_adapter_285(arg0, arg1) {
|
|
423
|
+
wasm.wasm_bindgen__convert__closures__invoke0_mut__hff00333f3d941090(arg0, arg1);
|
|
427
424
|
}
|
|
428
|
-
function
|
|
429
|
-
wasm.
|
|
425
|
+
function __wbg_adapter_328(arg0, arg1, arg2, arg3, arg4) {
|
|
426
|
+
wasm.wasm_bindgen__convert__closures__invoke3_mut__h703f9c33fd3008bf(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
|
|
430
427
|
}
|
|
431
|
-
function
|
|
432
|
-
wasm.
|
|
428
|
+
function __wbg_adapter_385(arg0, arg1, arg2, arg3) {
|
|
429
|
+
wasm.wasm_bindgen__convert__closures__invoke2_mut__h97988f5fa0547d24(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
433
430
|
}
|
|
434
431
|
var OpType2 = Object.freeze({
|
|
435
432
|
/**
|
|
@@ -531,7 +528,7 @@ ${val.stack}`;
|
|
|
531
528
|
var BaseStorageFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
532
529
|
}, unregister: () => {
|
|
533
530
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_basestorage_free(ptr >>> 0));
|
|
534
|
-
var
|
|
531
|
+
var BaseStorage = class {
|
|
535
532
|
__destroy_into_raw() {
|
|
536
533
|
const ptr = this.__wbg_ptr;
|
|
537
534
|
this.__wbg_ptr = 0;
|
|
@@ -739,7 +736,7 @@ ${val.stack}`;
|
|
|
739
736
|
if (r2) {
|
|
740
737
|
throw takeObject(r1);
|
|
741
738
|
}
|
|
742
|
-
return
|
|
739
|
+
return QueryOptions.__wrap(r0);
|
|
743
740
|
} finally {
|
|
744
741
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
745
742
|
}
|
|
@@ -876,7 +873,7 @@ ${val.stack}`;
|
|
|
876
873
|
try {
|
|
877
874
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
878
875
|
_assertClass(schema, Schema);
|
|
879
|
-
_assertClass(op,
|
|
876
|
+
_assertClass(op, Operation);
|
|
880
877
|
wasm.corestorage_getIndexes(retptr, this.__wbg_ptr, schema.__wbg_ptr, op.__wbg_ptr);
|
|
881
878
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
882
879
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
@@ -901,8 +898,7 @@ ${val.stack}`;
|
|
|
901
898
|
try {
|
|
902
899
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
903
900
|
_assertClass(query, Query);
|
|
904
|
-
|
|
905
|
-
wasm.corestorage_matchesQuery(retptr, this.__wbg_ptr, addBorrowedObject(document2), ptr0);
|
|
901
|
+
wasm.corestorage_matchesQuery(retptr, this.__wbg_ptr, addBorrowedObject(document2), query.__wbg_ptr);
|
|
906
902
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
907
903
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
908
904
|
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
@@ -1050,7 +1046,7 @@ ${val.stack}`;
|
|
|
1050
1046
|
* @returns {Promise<any>}
|
|
1051
1047
|
*/
|
|
1052
1048
|
write(op) {
|
|
1053
|
-
_assertClass(op,
|
|
1049
|
+
_assertClass(op, Operation);
|
|
1054
1050
|
var ptr0 = op.__destroy_into_raw();
|
|
1055
1051
|
const ret = wasm.inmemory_write(this.__wbg_ptr, ptr0);
|
|
1056
1052
|
return takeObject(ret);
|
|
@@ -1064,7 +1060,7 @@ ${val.stack}`;
|
|
|
1064
1060
|
find(collection_name, query_js, options) {
|
|
1065
1061
|
const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1066
1062
|
const len0 = WASM_VECTOR_LEN;
|
|
1067
|
-
_assertClass(options,
|
|
1063
|
+
_assertClass(options, QueryOptions);
|
|
1068
1064
|
var ptr1 = options.__destroy_into_raw();
|
|
1069
1065
|
const ret = wasm.inmemory_find(this.__wbg_ptr, ptr0, len0, addHeapObject(query_js), ptr1);
|
|
1070
1066
|
return takeObject(ret);
|
|
@@ -1089,7 +1085,7 @@ ${val.stack}`;
|
|
|
1089
1085
|
count(collection_name, query_js, options) {
|
|
1090
1086
|
const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1091
1087
|
const len0 = WASM_VECTOR_LEN;
|
|
1092
|
-
_assertClass(options,
|
|
1088
|
+
_assertClass(options, QueryOptions);
|
|
1093
1089
|
var ptr1 = options.__destroy_into_raw();
|
|
1094
1090
|
const ret = wasm.inmemory_count(this.__wbg_ptr, ptr0, len0, addHeapObject(query_js), ptr1);
|
|
1095
1091
|
return takeObject(ret);
|
|
@@ -1185,7 +1181,7 @@ ${val.stack}`;
|
|
|
1185
1181
|
* @returns {Promise<any>}
|
|
1186
1182
|
*/
|
|
1187
1183
|
write(op) {
|
|
1188
|
-
_assertClass(op,
|
|
1184
|
+
_assertClass(op, Operation);
|
|
1189
1185
|
var ptr0 = op.__destroy_into_raw();
|
|
1190
1186
|
const ret = wasm.indexdb_write(this.__wbg_ptr, ptr0);
|
|
1191
1187
|
return takeObject(ret);
|
|
@@ -1199,7 +1195,7 @@ ${val.stack}`;
|
|
|
1199
1195
|
find(collection_name, query, options) {
|
|
1200
1196
|
const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1201
1197
|
const len0 = WASM_VECTOR_LEN;
|
|
1202
|
-
_assertClass(options,
|
|
1198
|
+
_assertClass(options, QueryOptions);
|
|
1203
1199
|
var ptr1 = options.__destroy_into_raw();
|
|
1204
1200
|
const ret = wasm.indexdb_find(this.__wbg_ptr, ptr0, len0, addHeapObject(query), ptr1);
|
|
1205
1201
|
return takeObject(ret);
|
|
@@ -1224,7 +1220,7 @@ ${val.stack}`;
|
|
|
1224
1220
|
count(collection_name, query, options) {
|
|
1225
1221
|
const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1226
1222
|
const len0 = WASM_VECTOR_LEN;
|
|
1227
|
-
_assertClass(options,
|
|
1223
|
+
_assertClass(options, QueryOptions);
|
|
1228
1224
|
var ptr1 = options.__destroy_into_raw();
|
|
1229
1225
|
const ret = wasm.indexdb_count(this.__wbg_ptr, ptr0, len0, addHeapObject(query), ptr1);
|
|
1230
1226
|
return takeObject(ret);
|
|
@@ -1247,7 +1243,7 @@ ${val.stack}`;
|
|
|
1247
1243
|
var OperationFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1248
1244
|
}, unregister: () => {
|
|
1249
1245
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_operation_free(ptr >>> 0));
|
|
1250
|
-
var
|
|
1246
|
+
var Operation = class _Operation {
|
|
1251
1247
|
static __wrap(ptr) {
|
|
1252
1248
|
ptr = ptr >>> 0;
|
|
1253
1249
|
const obj = Object.create(_Operation.prototype);
|
|
@@ -1703,7 +1699,7 @@ ${val.stack}`;
|
|
|
1703
1699
|
var QueryOptionsFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1704
1700
|
}, unregister: () => {
|
|
1705
1701
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_queryoptions_free(ptr >>> 0));
|
|
1706
|
-
var
|
|
1702
|
+
var QueryOptions = class _QueryOptions {
|
|
1707
1703
|
static __wrap(ptr) {
|
|
1708
1704
|
ptr = ptr >>> 0;
|
|
1709
1705
|
const obj = Object.create(_QueryOptions.prototype);
|
|
@@ -2219,54 +2215,35 @@ ${val.stack}`;
|
|
|
2219
2215
|
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
2220
2216
|
takeObject(arg0);
|
|
2221
2217
|
};
|
|
2222
|
-
imports.wbg.
|
|
2223
|
-
|
|
2224
|
-
|
|
2218
|
+
imports.wbg.__wbg_count_19db4c3174d573d5 = function() {
|
|
2219
|
+
return handleError(function(arg0, arg1, arg2, arg3, arg4) {
|
|
2220
|
+
const ret = getObject(arg0).count(getStringFromWasm0(arg1, arg2), takeObject(arg3), QueryOptions.__wrap(arg4));
|
|
2221
|
+
return addHeapObject(ret);
|
|
2222
|
+
}, arguments);
|
|
2225
2223
|
};
|
|
2226
2224
|
imports.wbg.__wbg_ridberror_new = function(arg0) {
|
|
2227
2225
|
const ret = RIDBError.__wrap(arg0);
|
|
2228
2226
|
return addHeapObject(ret);
|
|
2229
2227
|
};
|
|
2228
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
2229
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
2230
|
+
return addHeapObject(ret);
|
|
2231
|
+
};
|
|
2230
2232
|
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
2231
2233
|
const ret = getObject(arg0);
|
|
2232
2234
|
return addHeapObject(ret);
|
|
2233
2235
|
};
|
|
2234
|
-
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
2235
|
-
const obj = getObject(arg1);
|
|
2236
|
-
const ret = typeof obj === "string" ? obj : void 0;
|
|
2237
|
-
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2238
|
-
var len1 = WASM_VECTOR_LEN;
|
|
2239
|
-
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2240
|
-
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2241
|
-
};
|
|
2242
2236
|
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
|
2243
2237
|
const ret = getObject(arg0) === void 0;
|
|
2244
2238
|
return ret;
|
|
2245
2239
|
};
|
|
2246
|
-
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
2247
|
-
const ret = arg0;
|
|
2248
|
-
return addHeapObject(ret);
|
|
2249
|
-
};
|
|
2250
|
-
imports.wbg.__wbg_apply_9f557eba1534d597 = function() {
|
|
2251
|
-
return handleError(function(arg0, arg1, arg2) {
|
|
2252
|
-
const ret = getObject(arg1).apply(takeObject(arg2));
|
|
2253
|
-
const ptr1 = passArrayJsValueToWasm0(ret, wasm.__wbindgen_malloc);
|
|
2254
|
-
const len1 = WASM_VECTOR_LEN;
|
|
2255
|
-
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2256
|
-
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2257
|
-
}, arguments);
|
|
2258
|
-
};
|
|
2259
|
-
imports.wbg.__wbg_inmemory_new = function(arg0) {
|
|
2260
|
-
const ret = InMemory.__wrap(arg0);
|
|
2261
|
-
return addHeapObject(ret);
|
|
2262
|
-
};
|
|
2263
2240
|
imports.wbg.__wbindgen_is_null = function(arg0) {
|
|
2264
2241
|
const ret = getObject(arg0) === null;
|
|
2265
2242
|
return ret;
|
|
2266
2243
|
};
|
|
2267
|
-
imports.wbg.
|
|
2244
|
+
imports.wbg.__wbg_start_76c138c3b73ae6f8 = function() {
|
|
2268
2245
|
return handleError(function(arg0) {
|
|
2269
|
-
const ret = getObject(arg0).
|
|
2246
|
+
const ret = getObject(arg0).start();
|
|
2270
2247
|
return addHeapObject(ret);
|
|
2271
2248
|
}, arguments);
|
|
2272
2249
|
};
|
|
@@ -2279,15 +2256,34 @@ ${val.stack}`;
|
|
|
2279
2256
|
const ret = false;
|
|
2280
2257
|
return ret;
|
|
2281
2258
|
};
|
|
2282
|
-
imports.wbg.
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2259
|
+
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
2260
|
+
const ret = arg0;
|
|
2261
|
+
return addHeapObject(ret);
|
|
2262
|
+
};
|
|
2263
|
+
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
2264
|
+
const obj = getObject(arg1);
|
|
2265
|
+
const ret = typeof obj === "string" ? obj : void 0;
|
|
2266
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2267
|
+
var len1 = WASM_VECTOR_LEN;
|
|
2268
|
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2269
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2270
|
+
};
|
|
2271
|
+
imports.wbg.__wbg_apply_9f557eba1534d597 = function() {
|
|
2272
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
2273
|
+
const ret = getObject(arg1).apply(takeObject(arg2));
|
|
2274
|
+
const ptr1 = passArrayJsValueToWasm0(ret, wasm.__wbindgen_malloc);
|
|
2275
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2276
|
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2277
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2286
2278
|
}, arguments);
|
|
2287
2279
|
};
|
|
2288
|
-
imports.wbg.
|
|
2280
|
+
imports.wbg.__wbg_inmemory_new = function(arg0) {
|
|
2281
|
+
const ret = InMemory.__wrap(arg0);
|
|
2282
|
+
return addHeapObject(ret);
|
|
2283
|
+
};
|
|
2284
|
+
imports.wbg.__wbg_close_6384ed3c27ef25c1 = function() {
|
|
2289
2285
|
return handleError(function(arg0) {
|
|
2290
|
-
const ret = getObject(arg0).
|
|
2286
|
+
const ret = getObject(arg0).close();
|
|
2291
2287
|
return addHeapObject(ret);
|
|
2292
2288
|
}, arguments);
|
|
2293
2289
|
};
|
|
@@ -2299,7 +2295,7 @@ ${val.stack}`;
|
|
|
2299
2295
|
};
|
|
2300
2296
|
imports.wbg.__wbg_find_567c5c9f064fe3d2 = function() {
|
|
2301
2297
|
return handleError(function(arg0, arg1, arg2, arg3, arg4) {
|
|
2302
|
-
const ret = getObject(arg0).find(getStringFromWasm0(arg1, arg2), takeObject(arg3),
|
|
2298
|
+
const ret = getObject(arg0).find(getStringFromWasm0(arg1, arg2), takeObject(arg3), QueryOptions.__wrap(arg4));
|
|
2303
2299
|
return addHeapObject(ret);
|
|
2304
2300
|
}, arguments);
|
|
2305
2301
|
};
|
|
@@ -2311,27 +2307,10 @@ ${val.stack}`;
|
|
|
2311
2307
|
};
|
|
2312
2308
|
imports.wbg.__wbg_write_1159c67c07f62020 = function() {
|
|
2313
2309
|
return handleError(function(arg0, arg1) {
|
|
2314
|
-
const ret = getObject(arg0).write(
|
|
2310
|
+
const ret = getObject(arg0).write(Operation.__wrap(arg1));
|
|
2315
2311
|
return addHeapObject(ret);
|
|
2316
2312
|
}, arguments);
|
|
2317
2313
|
};
|
|
2318
|
-
imports.wbg.__wbg_indexdb_new = function(arg0) {
|
|
2319
|
-
const ret = IndexDB.__wrap(arg0);
|
|
2320
|
-
return addHeapObject(ret);
|
|
2321
|
-
};
|
|
2322
|
-
imports.wbg.__wbg_database_new = function(arg0) {
|
|
2323
|
-
const ret = Database.__wrap(arg0);
|
|
2324
|
-
return addHeapObject(ret);
|
|
2325
|
-
};
|
|
2326
|
-
imports.wbg.__wbg_collection_new = function(arg0) {
|
|
2327
|
-
const ret = Collection.__wrap(arg0);
|
|
2328
|
-
return addHeapObject(ret);
|
|
2329
|
-
};
|
|
2330
|
-
imports.wbg.__wbindgen_is_object = function(arg0) {
|
|
2331
|
-
const val = getObject(arg0);
|
|
2332
|
-
const ret = typeof val === "object" && val !== null;
|
|
2333
|
-
return ret;
|
|
2334
|
-
};
|
|
2335
2314
|
imports.wbg.__wbindgen_is_string = function(arg0) {
|
|
2336
2315
|
const ret = typeof getObject(arg0) === "string";
|
|
2337
2316
|
return ret;
|
|
@@ -2344,18 +2323,23 @@ ${val.stack}`;
|
|
|
2344
2323
|
const ret = Array.isArray(getObject(arg0));
|
|
2345
2324
|
return ret;
|
|
2346
2325
|
};
|
|
2326
|
+
imports.wbg.__wbindgen_is_object = function(arg0) {
|
|
2327
|
+
const val = getObject(arg0);
|
|
2328
|
+
const ret = typeof val === "object" && val !== null;
|
|
2329
|
+
return ret;
|
|
2330
|
+
};
|
|
2347
2331
|
imports.wbg.__wbindgen_boolean_get = function(arg0) {
|
|
2348
2332
|
const v = getObject(arg0);
|
|
2349
2333
|
const ret = typeof v === "boolean" ? v ? 1 : 0 : 2;
|
|
2350
2334
|
return ret;
|
|
2351
2335
|
};
|
|
2352
|
-
imports.wbg.
|
|
2353
|
-
const ret =
|
|
2354
|
-
return ret;
|
|
2336
|
+
imports.wbg.__wbg_database_new = function(arg0) {
|
|
2337
|
+
const ret = Database.__wrap(arg0);
|
|
2338
|
+
return addHeapObject(ret);
|
|
2355
2339
|
};
|
|
2356
|
-
imports.wbg.
|
|
2357
|
-
const ret =
|
|
2358
|
-
return ret;
|
|
2340
|
+
imports.wbg.__wbg_collection_new = function(arg0) {
|
|
2341
|
+
const ret = Collection.__wrap(arg0);
|
|
2342
|
+
return addHeapObject(ret);
|
|
2359
2343
|
};
|
|
2360
2344
|
imports.wbg.__wbindgen_is_function = function(arg0) {
|
|
2361
2345
|
const ret = typeof getObject(arg0) === "function";
|
|
@@ -2365,6 +2349,14 @@ ${val.stack}`;
|
|
|
2365
2349
|
const ret = typeof getObject(arg0) === "bigint";
|
|
2366
2350
|
return ret;
|
|
2367
2351
|
};
|
|
2352
|
+
imports.wbg.__wbg_indexdb_new = function(arg0) {
|
|
2353
|
+
const ret = IndexDB.__wrap(arg0);
|
|
2354
|
+
return addHeapObject(ret);
|
|
2355
|
+
};
|
|
2356
|
+
imports.wbg.__wbindgen_is_falsy = function(arg0) {
|
|
2357
|
+
const ret = !getObject(arg0);
|
|
2358
|
+
return ret;
|
|
2359
|
+
};
|
|
2368
2360
|
imports.wbg.__wbindgen_in = function(arg0, arg1) {
|
|
2369
2361
|
const ret = getObject(arg0) in getObject(arg1);
|
|
2370
2362
|
return ret;
|
|
@@ -2373,6 +2365,10 @@ ${val.stack}`;
|
|
|
2373
2365
|
const ret = arg0;
|
|
2374
2366
|
return addHeapObject(ret);
|
|
2375
2367
|
};
|
|
2368
|
+
imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
|
|
2369
|
+
const ret = getObject(arg0) === getObject(arg1);
|
|
2370
|
+
return ret;
|
|
2371
|
+
};
|
|
2376
2372
|
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
2377
2373
|
const ret = BigInt.asUintN(64, arg0);
|
|
2378
2374
|
return addHeapObject(ret);
|
|
@@ -2429,12 +2425,6 @@ ${val.stack}`;
|
|
|
2429
2425
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2430
2426
|
}, arguments);
|
|
2431
2427
|
};
|
|
2432
|
-
imports.wbg.__wbg_setTimeout_c172d5704ef82276 = function() {
|
|
2433
|
-
return handleError(function(arg0, arg1, arg2) {
|
|
2434
|
-
const ret = getObject(arg0).setTimeout(getObject(arg1), arg2);
|
|
2435
|
-
return ret;
|
|
2436
|
-
}, arguments);
|
|
2437
|
-
};
|
|
2438
2428
|
imports.wbg.__wbg_instanceof_WorkerGlobalScope_46b577f151fad960 = function(arg0) {
|
|
2439
2429
|
let result;
|
|
2440
2430
|
try {
|
|
@@ -2451,12 +2441,6 @@ ${val.stack}`;
|
|
|
2451
2441
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2452
2442
|
}, arguments);
|
|
2453
2443
|
};
|
|
2454
|
-
imports.wbg.__wbg_setTimeout_8502a960d5dde06e = function() {
|
|
2455
|
-
return handleError(function(arg0, arg1, arg2) {
|
|
2456
|
-
const ret = getObject(arg0).setTimeout(getObject(arg1), arg2);
|
|
2457
|
-
return ret;
|
|
2458
|
-
}, arguments);
|
|
2459
|
-
};
|
|
2460
2444
|
imports.wbg.__wbg_debug_5fb96680aecf5dc8 = function(arg0) {
|
|
2461
2445
|
console.debug(getObject(arg0));
|
|
2462
2446
|
};
|
|
@@ -2695,7 +2679,7 @@ ${val.stack}`;
|
|
|
2695
2679
|
const a = state0.a;
|
|
2696
2680
|
state0.a = 0;
|
|
2697
2681
|
try {
|
|
2698
|
-
return
|
|
2682
|
+
return __wbg_adapter_285(a, state0.b);
|
|
2699
2683
|
} finally {
|
|
2700
2684
|
state0.a = a;
|
|
2701
2685
|
}
|
|
@@ -2706,16 +2690,12 @@ ${val.stack}`;
|
|
|
2706
2690
|
}
|
|
2707
2691
|
}, arguments);
|
|
2708
2692
|
};
|
|
2709
|
-
imports.wbg.
|
|
2710
|
-
|
|
2711
|
-
return addHeapObject(ret);
|
|
2693
|
+
imports.wbg.__wbg_wbgtestoutputwriteln_4db3bd64914ec955 = function(arg0) {
|
|
2694
|
+
__wbg_test_output_writeln(takeObject(arg0));
|
|
2712
2695
|
};
|
|
2713
|
-
imports.wbg.
|
|
2714
|
-
const ret = getObject(
|
|
2715
|
-
|
|
2716
|
-
const len1 = WASM_VECTOR_LEN;
|
|
2717
|
-
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2718
|
-
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2696
|
+
imports.wbg.__wbg_stack_436273c21658169b = function(arg0) {
|
|
2697
|
+
const ret = getObject(arg0).stack;
|
|
2698
|
+
return addHeapObject(ret);
|
|
2719
2699
|
};
|
|
2720
2700
|
imports.wbg.__wbg_self_55106357ec10ecd4 = function(arg0) {
|
|
2721
2701
|
const ret = getObject(arg0).self;
|
|
@@ -2743,13 +2723,17 @@ ${val.stack}`;
|
|
|
2743
2723
|
const ret = getObject(arg0).stack;
|
|
2744
2724
|
return addHeapObject(ret);
|
|
2745
2725
|
};
|
|
2746
|
-
imports.wbg.
|
|
2747
|
-
|
|
2748
|
-
};
|
|
2749
|
-
imports.wbg.__wbg_stack_436273c21658169b = function(arg0) {
|
|
2750
|
-
const ret = getObject(arg0).stack;
|
|
2726
|
+
imports.wbg.__wbg_static_accessor_document_d4b6ae7f5578480f = function() {
|
|
2727
|
+
const ret = document;
|
|
2751
2728
|
return addHeapObject(ret);
|
|
2752
2729
|
};
|
|
2730
|
+
imports.wbg.__wbg_stack_17c77e9f5bfe6714 = function(arg0, arg1) {
|
|
2731
|
+
const ret = getObject(arg1).stack;
|
|
2732
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2733
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2734
|
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2735
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2736
|
+
};
|
|
2753
2737
|
imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
|
|
2754
2738
|
const ret = new Error();
|
|
2755
2739
|
return addHeapObject(ret);
|
|
@@ -2772,13 +2756,13 @@ ${val.stack}`;
|
|
|
2772
2756
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
2773
2757
|
}
|
|
2774
2758
|
};
|
|
2775
|
-
imports.wbg.__wbg_queueMicrotask_481971b0d87f3dd4 = function(arg0) {
|
|
2776
|
-
queueMicrotask(getObject(arg0));
|
|
2777
|
-
};
|
|
2778
2759
|
imports.wbg.__wbg_queueMicrotask_3cbae2ec6b6cd3d6 = function(arg0) {
|
|
2779
2760
|
const ret = getObject(arg0).queueMicrotask;
|
|
2780
2761
|
return addHeapObject(ret);
|
|
2781
2762
|
};
|
|
2763
|
+
imports.wbg.__wbg_queueMicrotask_481971b0d87f3dd4 = function(arg0) {
|
|
2764
|
+
queueMicrotask(getObject(arg0));
|
|
2765
|
+
};
|
|
2782
2766
|
imports.wbg.__wbg_get_bd8e338fbd5f5cc8 = function(arg0, arg1) {
|
|
2783
2767
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
2784
2768
|
return addHeapObject(ret);
|
|
@@ -2875,7 +2859,7 @@ ${val.stack}`;
|
|
|
2875
2859
|
const a = state0.a;
|
|
2876
2860
|
state0.a = 0;
|
|
2877
2861
|
try {
|
|
2878
|
-
return
|
|
2862
|
+
return __wbg_adapter_328(a, state0.b, arg02, arg12, arg22);
|
|
2879
2863
|
} finally {
|
|
2880
2864
|
state0.a = a;
|
|
2881
2865
|
}
|
|
@@ -2976,7 +2960,7 @@ ${val.stack}`;
|
|
|
2976
2960
|
const a = state0.a;
|
|
2977
2961
|
state0.a = 0;
|
|
2978
2962
|
try {
|
|
2979
|
-
return
|
|
2963
|
+
return __wbg_adapter_385(a, state0.b, arg02, arg12);
|
|
2980
2964
|
} finally {
|
|
2981
2965
|
state0.a = a;
|
|
2982
2966
|
}
|
|
@@ -3092,20 +3076,16 @@ ${val.stack}`;
|
|
|
3092
3076
|
const ret = wasm.memory;
|
|
3093
3077
|
return addHeapObject(ret);
|
|
3094
3078
|
};
|
|
3095
|
-
imports.wbg.
|
|
3096
|
-
const ret =
|
|
3097
|
-
return addHeapObject(ret);
|
|
3098
|
-
};
|
|
3099
|
-
imports.wbg.__wbindgen_closure_wrapper816 = function(arg0, arg1, arg2) {
|
|
3100
|
-
const ret = makeMutClosure(arg0, arg1, 336, __wbg_adapter_59);
|
|
3079
|
+
imports.wbg.__wbindgen_closure_wrapper566 = function(arg0, arg1, arg2) {
|
|
3080
|
+
const ret = makeMutClosure(arg0, arg1, 207, __wbg_adapter_56);
|
|
3101
3081
|
return addHeapObject(ret);
|
|
3102
3082
|
};
|
|
3103
|
-
imports.wbg.
|
|
3104
|
-
const ret =
|
|
3083
|
+
imports.wbg.__wbindgen_closure_wrapper568 = function(arg0, arg1, arg2) {
|
|
3084
|
+
const ret = makeClosure(arg0, arg1, 207, __wbg_adapter_59);
|
|
3105
3085
|
return addHeapObject(ret);
|
|
3106
3086
|
};
|
|
3107
|
-
imports.wbg.
|
|
3108
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
3087
|
+
imports.wbg.__wbindgen_closure_wrapper1630 = function(arg0, arg1, arg2) {
|
|
3088
|
+
const ret = makeMutClosure(arg0, arg1, 449, __wbg_adapter_62);
|
|
3109
3089
|
return addHeapObject(ret);
|
|
3110
3090
|
};
|
|
3111
3091
|
return imports;
|
|
@@ -3150,220 +3130,228 @@ ${val.stack}`;
|
|
|
3150
3130
|
// src/index.ts
|
|
3151
3131
|
var index_exports = {};
|
|
3152
3132
|
__export(index_exports, {
|
|
3153
|
-
MongoDBStorage: () => MongoDBStorage,
|
|
3154
3133
|
createMongoDB: () => createMongoDB
|
|
3155
3134
|
});
|
|
3156
3135
|
module.exports = __toCommonJS(index_exports);
|
|
3157
|
-
var import_ridb_core = __toESM(require_ridb_core());
|
|
3158
3136
|
var import_ridb = require("@trust0/ridb");
|
|
3159
|
-
var
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
* This ensures that MongoDB's ObjectId instances are never returned to the application layer,
|
|
3170
|
-
* maintaining consistency with RIDB's string-based approach and preventing serialization issues.
|
|
3171
|
-
* Also removes MongoDB's automatic _id field entirely from results.
|
|
3172
|
-
* @private
|
|
3173
|
-
*/
|
|
3174
|
-
convertObjectIdsToStrings(obj) {
|
|
3175
|
-
if (!obj || typeof obj !== "object") {
|
|
3176
|
-
return obj;
|
|
3177
|
-
}
|
|
3178
|
-
if (obj.constructor?.name === "ObjectId" || obj._bsontype && obj._bsontype === "ObjectId") {
|
|
3179
|
-
const stringValue = obj.toString();
|
|
3180
|
-
return stringValue;
|
|
3181
|
-
}
|
|
3182
|
-
if (Array.isArray(obj)) {
|
|
3183
|
-
return obj.map((item) => this.convertObjectIdsToStrings(item));
|
|
3137
|
+
var import_ridb_core = __toESM(require_ridb_core());
|
|
3138
|
+
async function createMongoDB() {
|
|
3139
|
+
const { BaseStorage } = await (0, import_ridb.WasmInternal)();
|
|
3140
|
+
class MongoDBStorage extends BaseStorage {
|
|
3141
|
+
client;
|
|
3142
|
+
db;
|
|
3143
|
+
mongoConfig;
|
|
3144
|
+
constructor(name, schemas, options = {}) {
|
|
3145
|
+
super(name, schemas, options);
|
|
3146
|
+
this.mongoConfig = options;
|
|
3184
3147
|
}
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3148
|
+
/**
|
|
3149
|
+
* Utility method to recursively convert ObjectId values to strings throughout an object
|
|
3150
|
+
* This ensures that MongoDB's ObjectId instances are never returned to the application layer,
|
|
3151
|
+
* maintaining consistency with RIDB's string-based approach and preventing serialization issues.
|
|
3152
|
+
* Also removes MongoDB's automatic _id field entirely from results.
|
|
3153
|
+
* @private
|
|
3154
|
+
*/
|
|
3155
|
+
convertObjectIdsToStrings(obj) {
|
|
3156
|
+
if (!obj || typeof obj !== "object") {
|
|
3157
|
+
return obj;
|
|
3158
|
+
}
|
|
3159
|
+
if (obj.constructor?.name === "ObjectId" || obj._bsontype && obj._bsontype === "ObjectId") {
|
|
3160
|
+
const stringValue = obj.toString();
|
|
3161
|
+
return stringValue;
|
|
3162
|
+
}
|
|
3163
|
+
if (Array.isArray(obj)) {
|
|
3164
|
+
return obj.map((item) => this.convertObjectIdsToStrings(item));
|
|
3189
3165
|
}
|
|
3190
|
-
converted
|
|
3166
|
+
const converted = {};
|
|
3167
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
3168
|
+
if (key === "_id") {
|
|
3169
|
+
continue;
|
|
3170
|
+
}
|
|
3171
|
+
converted[key] = this.convertObjectIdsToStrings(value);
|
|
3172
|
+
}
|
|
3173
|
+
return converted;
|
|
3191
3174
|
}
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
const db = new _MongoDBStorage(name, schemas, options);
|
|
3204
|
-
return db;
|
|
3205
|
-
}
|
|
3206
|
-
/** Start the database connection */
|
|
3207
|
-
async start() {
|
|
3208
|
-
const { MongoClient } = await import("mongodb");
|
|
3209
|
-
const url = this.mongoConfig.url || process.env.MONGODB_URL || "mongodb://localhost:27017";
|
|
3210
|
-
const dbName = this.mongoConfig.dbName || this.name;
|
|
3211
|
-
this.client = new MongoClient(url, this.mongoConfig.mongoOptions || {});
|
|
3212
|
-
await this.client.connect();
|
|
3213
|
-
this.db = this.client.db(dbName);
|
|
3214
|
-
}
|
|
3215
|
-
/** Close the database connection */
|
|
3216
|
-
async close() {
|
|
3217
|
-
if (this.client) {
|
|
3218
|
-
await this.client.close();
|
|
3219
|
-
this.client = void 0;
|
|
3220
|
-
this.db = void 0;
|
|
3175
|
+
/**
|
|
3176
|
+
* Create a new MongoDB storage instance
|
|
3177
|
+
* @param name - Database name
|
|
3178
|
+
* @param schemas - Collection schemas
|
|
3179
|
+
* @param options - Storage options including MongoDB connection details
|
|
3180
|
+
* @returns A new Instance of MongoDB storage
|
|
3181
|
+
* @public
|
|
3182
|
+
*/
|
|
3183
|
+
static async create(name, schemas, options = {}) {
|
|
3184
|
+
const db = new MongoDBStorage(name, schemas, options);
|
|
3185
|
+
return db;
|
|
3221
3186
|
}
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3187
|
+
/** Start the database connection */
|
|
3188
|
+
async start() {
|
|
3189
|
+
const { MongoClient } = await import("mongodb");
|
|
3190
|
+
const url = this.mongoConfig.url || process.env.MONGODB_URL;
|
|
3191
|
+
if (!url) {
|
|
3192
|
+
throw new Error("MONGODB_URL is required");
|
|
3193
|
+
}
|
|
3194
|
+
const dbName = this.mongoConfig.dbName || this.name;
|
|
3195
|
+
this.client = new MongoClient(url, {
|
|
3196
|
+
connectTimeoutMS: 5e3,
|
|
3197
|
+
serverSelectionTimeoutMS: 5e3,
|
|
3198
|
+
socketTimeoutMS: 5e3,
|
|
3199
|
+
maxPoolSize: 10,
|
|
3200
|
+
minPoolSize: 5,
|
|
3201
|
+
maxIdleTimeMS: 5e3,
|
|
3202
|
+
maxConnecting: 5
|
|
3203
|
+
});
|
|
3204
|
+
await this.client.connect();
|
|
3205
|
+
this.db = this.client.db(dbName);
|
|
3227
3206
|
}
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
const primaryKey = schema.primaryKey;
|
|
3236
|
-
const query = { [primaryKey]: id };
|
|
3237
|
-
const doc = await collection.findOne(query);
|
|
3238
|
-
if (!doc) {
|
|
3239
|
-
return null;
|
|
3207
|
+
/** Close the database connection */
|
|
3208
|
+
async close() {
|
|
3209
|
+
if (this.client) {
|
|
3210
|
+
await this.client.close();
|
|
3211
|
+
this.client = void 0;
|
|
3212
|
+
this.db = void 0;
|
|
3213
|
+
}
|
|
3240
3214
|
}
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
const { primaryKey } = this.getSchema(collectionName);
|
|
3249
|
-
switch (op.opType) {
|
|
3250
|
-
case import_ridb_core.OpType.CREATE: {
|
|
3251
|
-
const id = primaryKey in op.data ? op.data[primaryKey] : null;
|
|
3252
|
-
if (!id) {
|
|
3253
|
-
throw new Error("Document ID is required");
|
|
3254
|
-
}
|
|
3255
|
-
const existQuery = { [primaryKey]: id };
|
|
3256
|
-
const existing = await collection.findOne(existQuery);
|
|
3257
|
-
if (existing) {
|
|
3258
|
-
throw new Error(`Document with ${primaryKey} '${id}' already exists`);
|
|
3259
|
-
}
|
|
3260
|
-
const docToInsert = { ...op.data };
|
|
3261
|
-
const insertResult = await collection.insertOne(docToInsert);
|
|
3262
|
-
const result = this.convertObjectIdsToStrings(op.data);
|
|
3263
|
-
return result;
|
|
3264
|
-
}
|
|
3265
|
-
case import_ridb_core.OpType.UPDATE: {
|
|
3266
|
-
const id = primaryKey in op.data ? op.data[primaryKey] : null;
|
|
3267
|
-
if (!id) {
|
|
3268
|
-
throw new Error("Document ID is required");
|
|
3269
|
-
}
|
|
3270
|
-
const updateQuery = { [primaryKey]: id };
|
|
3271
|
-
const updateData = { $set: op.data };
|
|
3272
|
-
const result = await collection.updateOne(updateQuery, updateData);
|
|
3273
|
-
if (result.matchedCount === 0) {
|
|
3274
|
-
throw new Error("Document ID not found");
|
|
3275
|
-
}
|
|
3276
|
-
const convertedResult = this.convertObjectIdsToStrings(op.data);
|
|
3277
|
-
return convertedResult;
|
|
3278
|
-
}
|
|
3279
|
-
case import_ridb_core.OpType.DELETE: {
|
|
3280
|
-
const id = op.data;
|
|
3281
|
-
const deleteQuery = { [primaryKey]: id };
|
|
3282
|
-
const result = await collection.deleteOne(deleteQuery);
|
|
3283
|
-
if (result.deletedCount === 0) {
|
|
3284
|
-
throw new Error("Document ID not found");
|
|
3285
|
-
}
|
|
3286
|
-
const convertedResult = this.convertObjectIdsToStrings(op.data);
|
|
3287
|
-
return convertedResult;
|
|
3288
|
-
}
|
|
3289
|
-
default:
|
|
3290
|
-
throw new Error(`Unknown operation type: ${op.opType}`);
|
|
3215
|
+
/** Get MongoDB collection for a given collection name */
|
|
3216
|
+
getCollection(collectionName) {
|
|
3217
|
+
if (!this.db) {
|
|
3218
|
+
throw new Error("Database not started. Call start() first.");
|
|
3219
|
+
}
|
|
3220
|
+
const collection = this.db.collection(collectionName);
|
|
3221
|
+
return collection;
|
|
3291
3222
|
}
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3223
|
+
/** Find a document by its ID */
|
|
3224
|
+
async findDocumentById(collectionName, id) {
|
|
3225
|
+
const collection = this.getCollection(String(collectionName));
|
|
3226
|
+
const schema = this.getSchema(String(collectionName));
|
|
3227
|
+
const primaryKey = schema.primaryKey;
|
|
3228
|
+
const query = { [primaryKey]: id };
|
|
3229
|
+
const doc = await collection.findOne(query);
|
|
3230
|
+
if (!doc) {
|
|
3231
|
+
return null;
|
|
3232
|
+
}
|
|
3233
|
+
const converted = this.convertObjectIdsToStrings(doc);
|
|
3234
|
+
return converted;
|
|
3235
|
+
}
|
|
3236
|
+
/** Write an operation (insert, update, delete) */
|
|
3237
|
+
async write(op) {
|
|
3238
|
+
const collectionName = String(op.collection);
|
|
3239
|
+
const collection = this.getCollection(collectionName);
|
|
3240
|
+
const { primaryKey } = this.getSchema(collectionName);
|
|
3241
|
+
switch (op.opType) {
|
|
3242
|
+
case import_ridb_core.OpType.CREATE: {
|
|
3243
|
+
const id = primaryKey in op.data ? op.data[primaryKey] : null;
|
|
3244
|
+
if (!id) {
|
|
3245
|
+
throw new Error("Document ID is required");
|
|
3246
|
+
}
|
|
3247
|
+
const existQuery = { [primaryKey]: id };
|
|
3248
|
+
const existing = await collection.findOne(existQuery);
|
|
3249
|
+
if (existing) {
|
|
3250
|
+
throw new Error(`Document with ${primaryKey} '${id}' already exists`);
|
|
3251
|
+
}
|
|
3252
|
+
const docToInsert = { ...op.data };
|
|
3253
|
+
await collection.insertOne(docToInsert);
|
|
3254
|
+
const result = this.convertObjectIdsToStrings(op.data);
|
|
3255
|
+
return result;
|
|
3256
|
+
}
|
|
3257
|
+
case import_ridb_core.OpType.UPDATE: {
|
|
3258
|
+
const id = primaryKey in op.data ? op.data[primaryKey] : null;
|
|
3259
|
+
if (!id) {
|
|
3260
|
+
throw new Error("Document ID is required");
|
|
3261
|
+
}
|
|
3262
|
+
const updateQuery = { [primaryKey]: id };
|
|
3263
|
+
const updateData = { $set: op.data };
|
|
3264
|
+
const result = await collection.updateOne(updateQuery, updateData);
|
|
3265
|
+
if (result.matchedCount === 0) {
|
|
3266
|
+
throw new Error("Document ID not found");
|
|
3267
|
+
}
|
|
3268
|
+
const convertedResult = this.convertObjectIdsToStrings(op.data);
|
|
3269
|
+
return convertedResult;
|
|
3270
|
+
}
|
|
3271
|
+
case import_ridb_core.OpType.DELETE: {
|
|
3272
|
+
const id = op.data;
|
|
3273
|
+
const deleteQuery = { [primaryKey]: id };
|
|
3274
|
+
const result = await collection.deleteOne(deleteQuery);
|
|
3275
|
+
if (result.deletedCount === 0) {
|
|
3276
|
+
throw new Error("Document ID not found");
|
|
3277
|
+
}
|
|
3278
|
+
const convertedResult = this.convertObjectIdsToStrings(op.data);
|
|
3279
|
+
return convertedResult;
|
|
3280
|
+
}
|
|
3281
|
+
default:
|
|
3282
|
+
throw new Error(`Unknown operation type: ${op.opType}`);
|
|
3283
|
+
}
|
|
3297
3284
|
}
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
if (
|
|
3301
|
-
|
|
3302
|
-
}
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
filter[key] = { $
|
|
3307
|
-
} else if ("
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3285
|
+
/** Convert RIDB query to MongoDB filter */
|
|
3286
|
+
convertQueryToMongoFilter(query, _schema) {
|
|
3287
|
+
if (!query || typeof query !== "object") {
|
|
3288
|
+
return {};
|
|
3289
|
+
}
|
|
3290
|
+
const filter = {};
|
|
3291
|
+
for (const [key, value] of Object.entries(query)) {
|
|
3292
|
+
if (value === null || value === void 0) {
|
|
3293
|
+
filter[key] = { $exists: false };
|
|
3294
|
+
} else if (typeof value === "object" && value !== null) {
|
|
3295
|
+
if ("$in" in value) {
|
|
3296
|
+
filter[key] = { $in: this.convertObjectIdsToStrings(value.$in) };
|
|
3297
|
+
} else if ("$nin" in value) {
|
|
3298
|
+
filter[key] = { $nin: this.convertObjectIdsToStrings(value.$nin) };
|
|
3299
|
+
} else if ("$gt" in value) {
|
|
3300
|
+
filter[key] = { $gt: this.convertObjectIdsToStrings(value.$gt) };
|
|
3301
|
+
} else if ("$gte" in value) {
|
|
3302
|
+
filter[key] = { $gte: this.convertObjectIdsToStrings(value.$gte) };
|
|
3303
|
+
} else if ("$lt" in value) {
|
|
3304
|
+
filter[key] = { $lt: this.convertObjectIdsToStrings(value.$lt) };
|
|
3305
|
+
} else if ("$lte" in value) {
|
|
3306
|
+
filter[key] = { $lte: this.convertObjectIdsToStrings(value.$lte) };
|
|
3307
|
+
} else if ("$ne" in value) {
|
|
3308
|
+
filter[key] = { $ne: this.convertObjectIdsToStrings(value.$ne) };
|
|
3309
|
+
} else if ("$regex" in value) {
|
|
3310
|
+
filter[key] = { $regex: value.$regex };
|
|
3311
|
+
} else {
|
|
3312
|
+
filter[key] = this.convertObjectIdsToStrings(value);
|
|
3313
|
+
}
|
|
3319
3314
|
} else {
|
|
3320
3315
|
filter[key] = this.convertObjectIdsToStrings(value);
|
|
3321
3316
|
}
|
|
3322
|
-
} else {
|
|
3323
|
-
filter[key] = this.convertObjectIdsToStrings(value);
|
|
3324
3317
|
}
|
|
3318
|
+
return filter;
|
|
3325
3319
|
}
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
countOptions.
|
|
3320
|
+
/** Count documents matching a query (supports offset & limit) */
|
|
3321
|
+
async count(collectionName, query, options) {
|
|
3322
|
+
const collection = this.getCollection(String(collectionName));
|
|
3323
|
+
const schema = this.getSchema(String(collectionName));
|
|
3324
|
+
const filter = this.convertQueryToMongoFilter(query, schema);
|
|
3325
|
+
const countOptions = {};
|
|
3326
|
+
if (options?.offset) {
|
|
3327
|
+
countOptions.skip = options.offset;
|
|
3328
|
+
}
|
|
3329
|
+
if (options?.limit) {
|
|
3330
|
+
countOptions.limit = options.limit;
|
|
3331
|
+
}
|
|
3332
|
+
const count = await collection.countDocuments(filter, Object.keys(countOptions).length > 0 ? countOptions : void 0);
|
|
3333
|
+
return count;
|
|
3339
3334
|
}
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3335
|
+
/** Find documents matching a query with pagination */
|
|
3336
|
+
async find(collectionName, query, options) {
|
|
3337
|
+
const collection = this.getCollection(String(collectionName));
|
|
3338
|
+
const schema = this.getSchema(String(collectionName));
|
|
3339
|
+
const filter = this.convertQueryToMongoFilter(query, schema);
|
|
3340
|
+
let findQuery = collection.find(filter);
|
|
3341
|
+
if (options?.offset) {
|
|
3342
|
+
findQuery = findQuery.skip(options.offset);
|
|
3343
|
+
}
|
|
3344
|
+
if (options?.limit) {
|
|
3345
|
+
findQuery = findQuery.limit(options.limit);
|
|
3346
|
+
}
|
|
3347
|
+
const docs = await findQuery.toArray();
|
|
3348
|
+
const convertedDocs = docs.map((doc) => this.convertObjectIdsToStrings(doc));
|
|
3349
|
+
return convertedDocs;
|
|
3354
3350
|
}
|
|
3355
|
-
const docs = await findQuery.toArray();
|
|
3356
|
-
const convertedDocs = docs.map((doc) => this.convertObjectIdsToStrings(doc));
|
|
3357
|
-
return convertedDocs;
|
|
3358
3351
|
}
|
|
3359
|
-
};
|
|
3360
|
-
async function createMongoDB() {
|
|
3361
|
-
const { BaseStorage: base } = await (0, import_ridb.WasmInternal)();
|
|
3362
|
-
Object.setPrototypeOf(MongoDBStorage.prototype, base.prototype);
|
|
3363
3352
|
return MongoDBStorage;
|
|
3364
3353
|
}
|
|
3365
3354
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3366
3355
|
0 && (module.exports = {
|
|
3367
|
-
MongoDBStorage,
|
|
3368
3356
|
createMongoDB
|
|
3369
3357
|
});
|