@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.mjs
CHANGED
|
@@ -70,7 +70,7 @@ var require_ridb_core = __commonJS({
|
|
|
70
70
|
var ridb_core_exports = {};
|
|
71
71
|
__export(ridb_core_exports, {
|
|
72
72
|
BasePlugin: () => BasePlugin,
|
|
73
|
-
BaseStorage: () =>
|
|
73
|
+
BaseStorage: () => BaseStorage,
|
|
74
74
|
Collection: () => Collection,
|
|
75
75
|
CoreStorage: () => CoreStorage,
|
|
76
76
|
Database: () => Database,
|
|
@@ -78,10 +78,10 @@ var require_ridb_core = __commonJS({
|
|
|
78
78
|
InMemory: () => InMemory,
|
|
79
79
|
IndexDB: () => IndexDB,
|
|
80
80
|
OpType: () => OpType2,
|
|
81
|
-
Operation: () =>
|
|
81
|
+
Operation: () => Operation,
|
|
82
82
|
Property: () => Property,
|
|
83
83
|
Query: () => Query,
|
|
84
|
-
QueryOptions: () =>
|
|
84
|
+
QueryOptions: () => QueryOptions,
|
|
85
85
|
RIDBError: () => RIDBError,
|
|
86
86
|
Schema: () => Schema,
|
|
87
87
|
WasmBindgenTestContext: () => WasmBindgenTestContext,
|
|
@@ -266,6 +266,30 @@ ${val.stack}`;
|
|
|
266
266
|
} } : new FinalizationRegistry((state) => {
|
|
267
267
|
wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);
|
|
268
268
|
});
|
|
269
|
+
function makeMutClosure(arg0, arg1, dtor, f) {
|
|
270
|
+
const state = { a: arg0, b: arg1, cnt: 1, dtor };
|
|
271
|
+
const real = (...args) => {
|
|
272
|
+
state.cnt++;
|
|
273
|
+
const a = state.a;
|
|
274
|
+
state.a = 0;
|
|
275
|
+
try {
|
|
276
|
+
return f(a, state.b, ...args);
|
|
277
|
+
} finally {
|
|
278
|
+
if (--state.cnt === 0) {
|
|
279
|
+
wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);
|
|
280
|
+
CLOSURE_DTORS.unregister(state);
|
|
281
|
+
} else {
|
|
282
|
+
state.a = a;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
real.original = state;
|
|
287
|
+
CLOSURE_DTORS.register(real, state, state);
|
|
288
|
+
return real;
|
|
289
|
+
}
|
|
290
|
+
function __wbg_adapter_56(arg0, arg1, arg2) {
|
|
291
|
+
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hcf4fe6fd0b7ccc8d(arg0, arg1, addHeapObject(arg2));
|
|
292
|
+
}
|
|
269
293
|
function makeClosure(arg0, arg1, dtor, f) {
|
|
270
294
|
const state = { a: arg0, b: arg1, cnt: 1, dtor };
|
|
271
295
|
const real = (...args) => {
|
|
@@ -284,10 +308,10 @@ ${val.stack}`;
|
|
|
284
308
|
CLOSURE_DTORS.register(real, state, state);
|
|
285
309
|
return real;
|
|
286
310
|
}
|
|
287
|
-
function
|
|
311
|
+
function __wbg_adapter_59(arg0, arg1, arg2, arg3, arg4) {
|
|
288
312
|
try {
|
|
289
313
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
290
|
-
wasm.
|
|
314
|
+
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));
|
|
291
315
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
292
316
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
293
317
|
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
@@ -299,35 +323,8 @@ ${val.stack}`;
|
|
|
299
323
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
300
324
|
}
|
|
301
325
|
}
|
|
302
|
-
function
|
|
303
|
-
|
|
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));
|
|
326
|
+
function __wbg_adapter_62(arg0, arg1, arg2) {
|
|
327
|
+
wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hb6eb1f8e3b5e56e9(arg0, arg1, addHeapObject(arg2));
|
|
331
328
|
}
|
|
332
329
|
var cachedUint32Memory0 = null;
|
|
333
330
|
function getUint32Memory0() {
|
|
@@ -346,6 +343,13 @@ ${val.stack}`;
|
|
|
346
343
|
}
|
|
347
344
|
return result;
|
|
348
345
|
}
|
|
346
|
+
function main_js() {
|
|
347
|
+
wasm.main_js();
|
|
348
|
+
}
|
|
349
|
+
function is_debug_mode() {
|
|
350
|
+
const ret = wasm.is_debug_mode();
|
|
351
|
+
return ret !== 0;
|
|
352
|
+
}
|
|
349
353
|
function _assertClass(instance, klass) {
|
|
350
354
|
if (!(instance instanceof klass)) {
|
|
351
355
|
throw new Error(`expected instance of ${klass.name}`);
|
|
@@ -374,13 +378,6 @@ ${val.stack}`;
|
|
|
374
378
|
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
375
379
|
}
|
|
376
380
|
}
|
|
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
381
|
function __wbgtest_console_log(args) {
|
|
385
382
|
try {
|
|
386
383
|
wasm.__wbgtest_console_log(addBorrowedObject(args));
|
|
@@ -416,14 +413,14 @@ ${val.stack}`;
|
|
|
416
413
|
heap[stack_pointer++] = void 0;
|
|
417
414
|
}
|
|
418
415
|
}
|
|
419
|
-
function
|
|
420
|
-
wasm.
|
|
416
|
+
function __wbg_adapter_285(arg0, arg1) {
|
|
417
|
+
wasm.wasm_bindgen__convert__closures__invoke0_mut__hff00333f3d941090(arg0, arg1);
|
|
421
418
|
}
|
|
422
|
-
function
|
|
423
|
-
wasm.
|
|
419
|
+
function __wbg_adapter_328(arg0, arg1, arg2, arg3, arg4) {
|
|
420
|
+
wasm.wasm_bindgen__convert__closures__invoke3_mut__h703f9c33fd3008bf(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
|
|
424
421
|
}
|
|
425
|
-
function
|
|
426
|
-
wasm.
|
|
422
|
+
function __wbg_adapter_385(arg0, arg1, arg2, arg3) {
|
|
423
|
+
wasm.wasm_bindgen__convert__closures__invoke2_mut__h97988f5fa0547d24(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
427
424
|
}
|
|
428
425
|
var OpType2 = Object.freeze({
|
|
429
426
|
/**
|
|
@@ -525,7 +522,7 @@ ${val.stack}`;
|
|
|
525
522
|
var BaseStorageFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
526
523
|
}, unregister: () => {
|
|
527
524
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_basestorage_free(ptr >>> 0));
|
|
528
|
-
var
|
|
525
|
+
var BaseStorage = class {
|
|
529
526
|
__destroy_into_raw() {
|
|
530
527
|
const ptr = this.__wbg_ptr;
|
|
531
528
|
this.__wbg_ptr = 0;
|
|
@@ -733,7 +730,7 @@ ${val.stack}`;
|
|
|
733
730
|
if (r2) {
|
|
734
731
|
throw takeObject(r1);
|
|
735
732
|
}
|
|
736
|
-
return
|
|
733
|
+
return QueryOptions.__wrap(r0);
|
|
737
734
|
} finally {
|
|
738
735
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
739
736
|
}
|
|
@@ -870,7 +867,7 @@ ${val.stack}`;
|
|
|
870
867
|
try {
|
|
871
868
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
872
869
|
_assertClass(schema, Schema);
|
|
873
|
-
_assertClass(op,
|
|
870
|
+
_assertClass(op, Operation);
|
|
874
871
|
wasm.corestorage_getIndexes(retptr, this.__wbg_ptr, schema.__wbg_ptr, op.__wbg_ptr);
|
|
875
872
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
876
873
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
@@ -895,8 +892,7 @@ ${val.stack}`;
|
|
|
895
892
|
try {
|
|
896
893
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
897
894
|
_assertClass(query, Query);
|
|
898
|
-
|
|
899
|
-
wasm.corestorage_matchesQuery(retptr, this.__wbg_ptr, addBorrowedObject(document2), ptr0);
|
|
895
|
+
wasm.corestorage_matchesQuery(retptr, this.__wbg_ptr, addBorrowedObject(document2), query.__wbg_ptr);
|
|
900
896
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
901
897
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
902
898
|
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
@@ -1044,7 +1040,7 @@ ${val.stack}`;
|
|
|
1044
1040
|
* @returns {Promise<any>}
|
|
1045
1041
|
*/
|
|
1046
1042
|
write(op) {
|
|
1047
|
-
_assertClass(op,
|
|
1043
|
+
_assertClass(op, Operation);
|
|
1048
1044
|
var ptr0 = op.__destroy_into_raw();
|
|
1049
1045
|
const ret = wasm.inmemory_write(this.__wbg_ptr, ptr0);
|
|
1050
1046
|
return takeObject(ret);
|
|
@@ -1058,7 +1054,7 @@ ${val.stack}`;
|
|
|
1058
1054
|
find(collection_name, query_js, options) {
|
|
1059
1055
|
const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1060
1056
|
const len0 = WASM_VECTOR_LEN;
|
|
1061
|
-
_assertClass(options,
|
|
1057
|
+
_assertClass(options, QueryOptions);
|
|
1062
1058
|
var ptr1 = options.__destroy_into_raw();
|
|
1063
1059
|
const ret = wasm.inmemory_find(this.__wbg_ptr, ptr0, len0, addHeapObject(query_js), ptr1);
|
|
1064
1060
|
return takeObject(ret);
|
|
@@ -1083,7 +1079,7 @@ ${val.stack}`;
|
|
|
1083
1079
|
count(collection_name, query_js, options) {
|
|
1084
1080
|
const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1085
1081
|
const len0 = WASM_VECTOR_LEN;
|
|
1086
|
-
_assertClass(options,
|
|
1082
|
+
_assertClass(options, QueryOptions);
|
|
1087
1083
|
var ptr1 = options.__destroy_into_raw();
|
|
1088
1084
|
const ret = wasm.inmemory_count(this.__wbg_ptr, ptr0, len0, addHeapObject(query_js), ptr1);
|
|
1089
1085
|
return takeObject(ret);
|
|
@@ -1179,7 +1175,7 @@ ${val.stack}`;
|
|
|
1179
1175
|
* @returns {Promise<any>}
|
|
1180
1176
|
*/
|
|
1181
1177
|
write(op) {
|
|
1182
|
-
_assertClass(op,
|
|
1178
|
+
_assertClass(op, Operation);
|
|
1183
1179
|
var ptr0 = op.__destroy_into_raw();
|
|
1184
1180
|
const ret = wasm.indexdb_write(this.__wbg_ptr, ptr0);
|
|
1185
1181
|
return takeObject(ret);
|
|
@@ -1193,7 +1189,7 @@ ${val.stack}`;
|
|
|
1193
1189
|
find(collection_name, query, options) {
|
|
1194
1190
|
const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1195
1191
|
const len0 = WASM_VECTOR_LEN;
|
|
1196
|
-
_assertClass(options,
|
|
1192
|
+
_assertClass(options, QueryOptions);
|
|
1197
1193
|
var ptr1 = options.__destroy_into_raw();
|
|
1198
1194
|
const ret = wasm.indexdb_find(this.__wbg_ptr, ptr0, len0, addHeapObject(query), ptr1);
|
|
1199
1195
|
return takeObject(ret);
|
|
@@ -1218,7 +1214,7 @@ ${val.stack}`;
|
|
|
1218
1214
|
count(collection_name, query, options) {
|
|
1219
1215
|
const ptr0 = passStringToWasm0(collection_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1220
1216
|
const len0 = WASM_VECTOR_LEN;
|
|
1221
|
-
_assertClass(options,
|
|
1217
|
+
_assertClass(options, QueryOptions);
|
|
1222
1218
|
var ptr1 = options.__destroy_into_raw();
|
|
1223
1219
|
const ret = wasm.indexdb_count(this.__wbg_ptr, ptr0, len0, addHeapObject(query), ptr1);
|
|
1224
1220
|
return takeObject(ret);
|
|
@@ -1241,7 +1237,7 @@ ${val.stack}`;
|
|
|
1241
1237
|
var OperationFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1242
1238
|
}, unregister: () => {
|
|
1243
1239
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_operation_free(ptr >>> 0));
|
|
1244
|
-
var
|
|
1240
|
+
var Operation = class _Operation {
|
|
1245
1241
|
static __wrap(ptr) {
|
|
1246
1242
|
ptr = ptr >>> 0;
|
|
1247
1243
|
const obj = Object.create(_Operation.prototype);
|
|
@@ -1697,7 +1693,7 @@ ${val.stack}`;
|
|
|
1697
1693
|
var QueryOptionsFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
1698
1694
|
}, unregister: () => {
|
|
1699
1695
|
} } : new FinalizationRegistry((ptr) => wasm.__wbg_queryoptions_free(ptr >>> 0));
|
|
1700
|
-
var
|
|
1696
|
+
var QueryOptions = class _QueryOptions {
|
|
1701
1697
|
static __wrap(ptr) {
|
|
1702
1698
|
ptr = ptr >>> 0;
|
|
1703
1699
|
const obj = Object.create(_QueryOptions.prototype);
|
|
@@ -2213,54 +2209,35 @@ ${val.stack}`;
|
|
|
2213
2209
|
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
2214
2210
|
takeObject(arg0);
|
|
2215
2211
|
};
|
|
2216
|
-
imports.wbg.
|
|
2217
|
-
|
|
2218
|
-
|
|
2212
|
+
imports.wbg.__wbg_count_19db4c3174d573d5 = function() {
|
|
2213
|
+
return handleError(function(arg0, arg1, arg2, arg3, arg4) {
|
|
2214
|
+
const ret = getObject(arg0).count(getStringFromWasm0(arg1, arg2), takeObject(arg3), QueryOptions.__wrap(arg4));
|
|
2215
|
+
return addHeapObject(ret);
|
|
2216
|
+
}, arguments);
|
|
2219
2217
|
};
|
|
2220
2218
|
imports.wbg.__wbg_ridberror_new = function(arg0) {
|
|
2221
2219
|
const ret = RIDBError.__wrap(arg0);
|
|
2222
2220
|
return addHeapObject(ret);
|
|
2223
2221
|
};
|
|
2222
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
2223
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
2224
|
+
return addHeapObject(ret);
|
|
2225
|
+
};
|
|
2224
2226
|
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
2225
2227
|
const ret = getObject(arg0);
|
|
2226
2228
|
return addHeapObject(ret);
|
|
2227
2229
|
};
|
|
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
2230
|
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
|
2237
2231
|
const ret = getObject(arg0) === void 0;
|
|
2238
2232
|
return ret;
|
|
2239
2233
|
};
|
|
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
2234
|
imports.wbg.__wbindgen_is_null = function(arg0) {
|
|
2258
2235
|
const ret = getObject(arg0) === null;
|
|
2259
2236
|
return ret;
|
|
2260
2237
|
};
|
|
2261
|
-
imports.wbg.
|
|
2238
|
+
imports.wbg.__wbg_start_76c138c3b73ae6f8 = function() {
|
|
2262
2239
|
return handleError(function(arg0) {
|
|
2263
|
-
const ret = getObject(arg0).
|
|
2240
|
+
const ret = getObject(arg0).start();
|
|
2264
2241
|
return addHeapObject(ret);
|
|
2265
2242
|
}, arguments);
|
|
2266
2243
|
};
|
|
@@ -2273,15 +2250,34 @@ ${val.stack}`;
|
|
|
2273
2250
|
const ret = false;
|
|
2274
2251
|
return ret;
|
|
2275
2252
|
};
|
|
2276
|
-
imports.wbg.
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2253
|
+
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
2254
|
+
const ret = arg0;
|
|
2255
|
+
return addHeapObject(ret);
|
|
2256
|
+
};
|
|
2257
|
+
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
2258
|
+
const obj = getObject(arg1);
|
|
2259
|
+
const ret = typeof obj === "string" ? obj : void 0;
|
|
2260
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2261
|
+
var len1 = WASM_VECTOR_LEN;
|
|
2262
|
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2263
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2264
|
+
};
|
|
2265
|
+
imports.wbg.__wbg_apply_9f557eba1534d597 = function() {
|
|
2266
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
2267
|
+
const ret = getObject(arg1).apply(takeObject(arg2));
|
|
2268
|
+
const ptr1 = passArrayJsValueToWasm0(ret, wasm.__wbindgen_malloc);
|
|
2269
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2270
|
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2271
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2280
2272
|
}, arguments);
|
|
2281
2273
|
};
|
|
2282
|
-
imports.wbg.
|
|
2274
|
+
imports.wbg.__wbg_inmemory_new = function(arg0) {
|
|
2275
|
+
const ret = InMemory.__wrap(arg0);
|
|
2276
|
+
return addHeapObject(ret);
|
|
2277
|
+
};
|
|
2278
|
+
imports.wbg.__wbg_close_6384ed3c27ef25c1 = function() {
|
|
2283
2279
|
return handleError(function(arg0) {
|
|
2284
|
-
const ret = getObject(arg0).
|
|
2280
|
+
const ret = getObject(arg0).close();
|
|
2285
2281
|
return addHeapObject(ret);
|
|
2286
2282
|
}, arguments);
|
|
2287
2283
|
};
|
|
@@ -2293,7 +2289,7 @@ ${val.stack}`;
|
|
|
2293
2289
|
};
|
|
2294
2290
|
imports.wbg.__wbg_find_567c5c9f064fe3d2 = function() {
|
|
2295
2291
|
return handleError(function(arg0, arg1, arg2, arg3, arg4) {
|
|
2296
|
-
const ret = getObject(arg0).find(getStringFromWasm0(arg1, arg2), takeObject(arg3),
|
|
2292
|
+
const ret = getObject(arg0).find(getStringFromWasm0(arg1, arg2), takeObject(arg3), QueryOptions.__wrap(arg4));
|
|
2297
2293
|
return addHeapObject(ret);
|
|
2298
2294
|
}, arguments);
|
|
2299
2295
|
};
|
|
@@ -2305,27 +2301,10 @@ ${val.stack}`;
|
|
|
2305
2301
|
};
|
|
2306
2302
|
imports.wbg.__wbg_write_1159c67c07f62020 = function() {
|
|
2307
2303
|
return handleError(function(arg0, arg1) {
|
|
2308
|
-
const ret = getObject(arg0).write(
|
|
2304
|
+
const ret = getObject(arg0).write(Operation.__wrap(arg1));
|
|
2309
2305
|
return addHeapObject(ret);
|
|
2310
2306
|
}, arguments);
|
|
2311
2307
|
};
|
|
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
2308
|
imports.wbg.__wbindgen_is_string = function(arg0) {
|
|
2330
2309
|
const ret = typeof getObject(arg0) === "string";
|
|
2331
2310
|
return ret;
|
|
@@ -2338,18 +2317,23 @@ ${val.stack}`;
|
|
|
2338
2317
|
const ret = Array.isArray(getObject(arg0));
|
|
2339
2318
|
return ret;
|
|
2340
2319
|
};
|
|
2320
|
+
imports.wbg.__wbindgen_is_object = function(arg0) {
|
|
2321
|
+
const val = getObject(arg0);
|
|
2322
|
+
const ret = typeof val === "object" && val !== null;
|
|
2323
|
+
return ret;
|
|
2324
|
+
};
|
|
2341
2325
|
imports.wbg.__wbindgen_boolean_get = function(arg0) {
|
|
2342
2326
|
const v = getObject(arg0);
|
|
2343
2327
|
const ret = typeof v === "boolean" ? v ? 1 : 0 : 2;
|
|
2344
2328
|
return ret;
|
|
2345
2329
|
};
|
|
2346
|
-
imports.wbg.
|
|
2347
|
-
const ret =
|
|
2348
|
-
return ret;
|
|
2330
|
+
imports.wbg.__wbg_database_new = function(arg0) {
|
|
2331
|
+
const ret = Database.__wrap(arg0);
|
|
2332
|
+
return addHeapObject(ret);
|
|
2349
2333
|
};
|
|
2350
|
-
imports.wbg.
|
|
2351
|
-
const ret =
|
|
2352
|
-
return ret;
|
|
2334
|
+
imports.wbg.__wbg_collection_new = function(arg0) {
|
|
2335
|
+
const ret = Collection.__wrap(arg0);
|
|
2336
|
+
return addHeapObject(ret);
|
|
2353
2337
|
};
|
|
2354
2338
|
imports.wbg.__wbindgen_is_function = function(arg0) {
|
|
2355
2339
|
const ret = typeof getObject(arg0) === "function";
|
|
@@ -2359,6 +2343,14 @@ ${val.stack}`;
|
|
|
2359
2343
|
const ret = typeof getObject(arg0) === "bigint";
|
|
2360
2344
|
return ret;
|
|
2361
2345
|
};
|
|
2346
|
+
imports.wbg.__wbg_indexdb_new = function(arg0) {
|
|
2347
|
+
const ret = IndexDB.__wrap(arg0);
|
|
2348
|
+
return addHeapObject(ret);
|
|
2349
|
+
};
|
|
2350
|
+
imports.wbg.__wbindgen_is_falsy = function(arg0) {
|
|
2351
|
+
const ret = !getObject(arg0);
|
|
2352
|
+
return ret;
|
|
2353
|
+
};
|
|
2362
2354
|
imports.wbg.__wbindgen_in = function(arg0, arg1) {
|
|
2363
2355
|
const ret = getObject(arg0) in getObject(arg1);
|
|
2364
2356
|
return ret;
|
|
@@ -2367,6 +2359,10 @@ ${val.stack}`;
|
|
|
2367
2359
|
const ret = arg0;
|
|
2368
2360
|
return addHeapObject(ret);
|
|
2369
2361
|
};
|
|
2362
|
+
imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
|
|
2363
|
+
const ret = getObject(arg0) === getObject(arg1);
|
|
2364
|
+
return ret;
|
|
2365
|
+
};
|
|
2370
2366
|
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
2371
2367
|
const ret = BigInt.asUintN(64, arg0);
|
|
2372
2368
|
return addHeapObject(ret);
|
|
@@ -2423,12 +2419,6 @@ ${val.stack}`;
|
|
|
2423
2419
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2424
2420
|
}, arguments);
|
|
2425
2421
|
};
|
|
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
2422
|
imports.wbg.__wbg_instanceof_WorkerGlobalScope_46b577f151fad960 = function(arg0) {
|
|
2433
2423
|
let result;
|
|
2434
2424
|
try {
|
|
@@ -2445,12 +2435,6 @@ ${val.stack}`;
|
|
|
2445
2435
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
2446
2436
|
}, arguments);
|
|
2447
2437
|
};
|
|
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
2438
|
imports.wbg.__wbg_debug_5fb96680aecf5dc8 = function(arg0) {
|
|
2455
2439
|
console.debug(getObject(arg0));
|
|
2456
2440
|
};
|
|
@@ -2689,7 +2673,7 @@ ${val.stack}`;
|
|
|
2689
2673
|
const a = state0.a;
|
|
2690
2674
|
state0.a = 0;
|
|
2691
2675
|
try {
|
|
2692
|
-
return
|
|
2676
|
+
return __wbg_adapter_285(a, state0.b);
|
|
2693
2677
|
} finally {
|
|
2694
2678
|
state0.a = a;
|
|
2695
2679
|
}
|
|
@@ -2700,16 +2684,12 @@ ${val.stack}`;
|
|
|
2700
2684
|
}
|
|
2701
2685
|
}, arguments);
|
|
2702
2686
|
};
|
|
2703
|
-
imports.wbg.
|
|
2704
|
-
|
|
2705
|
-
return addHeapObject(ret);
|
|
2687
|
+
imports.wbg.__wbg_wbgtestoutputwriteln_4db3bd64914ec955 = function(arg0) {
|
|
2688
|
+
__wbg_test_output_writeln(takeObject(arg0));
|
|
2706
2689
|
};
|
|
2707
|
-
imports.wbg.
|
|
2708
|
-
const ret = getObject(
|
|
2709
|
-
|
|
2710
|
-
const len1 = WASM_VECTOR_LEN;
|
|
2711
|
-
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2712
|
-
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2690
|
+
imports.wbg.__wbg_stack_436273c21658169b = function(arg0) {
|
|
2691
|
+
const ret = getObject(arg0).stack;
|
|
2692
|
+
return addHeapObject(ret);
|
|
2713
2693
|
};
|
|
2714
2694
|
imports.wbg.__wbg_self_55106357ec10ecd4 = function(arg0) {
|
|
2715
2695
|
const ret = getObject(arg0).self;
|
|
@@ -2737,13 +2717,17 @@ ${val.stack}`;
|
|
|
2737
2717
|
const ret = getObject(arg0).stack;
|
|
2738
2718
|
return addHeapObject(ret);
|
|
2739
2719
|
};
|
|
2740
|
-
imports.wbg.
|
|
2741
|
-
|
|
2742
|
-
};
|
|
2743
|
-
imports.wbg.__wbg_stack_436273c21658169b = function(arg0) {
|
|
2744
|
-
const ret = getObject(arg0).stack;
|
|
2720
|
+
imports.wbg.__wbg_static_accessor_document_d4b6ae7f5578480f = function() {
|
|
2721
|
+
const ret = document;
|
|
2745
2722
|
return addHeapObject(ret);
|
|
2746
2723
|
};
|
|
2724
|
+
imports.wbg.__wbg_stack_17c77e9f5bfe6714 = function(arg0, arg1) {
|
|
2725
|
+
const ret = getObject(arg1).stack;
|
|
2726
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2727
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2728
|
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
2729
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
2730
|
+
};
|
|
2747
2731
|
imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
|
|
2748
2732
|
const ret = new Error();
|
|
2749
2733
|
return addHeapObject(ret);
|
|
@@ -2766,13 +2750,13 @@ ${val.stack}`;
|
|
|
2766
2750
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
2767
2751
|
}
|
|
2768
2752
|
};
|
|
2769
|
-
imports.wbg.__wbg_queueMicrotask_481971b0d87f3dd4 = function(arg0) {
|
|
2770
|
-
queueMicrotask(getObject(arg0));
|
|
2771
|
-
};
|
|
2772
2753
|
imports.wbg.__wbg_queueMicrotask_3cbae2ec6b6cd3d6 = function(arg0) {
|
|
2773
2754
|
const ret = getObject(arg0).queueMicrotask;
|
|
2774
2755
|
return addHeapObject(ret);
|
|
2775
2756
|
};
|
|
2757
|
+
imports.wbg.__wbg_queueMicrotask_481971b0d87f3dd4 = function(arg0) {
|
|
2758
|
+
queueMicrotask(getObject(arg0));
|
|
2759
|
+
};
|
|
2776
2760
|
imports.wbg.__wbg_get_bd8e338fbd5f5cc8 = function(arg0, arg1) {
|
|
2777
2761
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
2778
2762
|
return addHeapObject(ret);
|
|
@@ -2869,7 +2853,7 @@ ${val.stack}`;
|
|
|
2869
2853
|
const a = state0.a;
|
|
2870
2854
|
state0.a = 0;
|
|
2871
2855
|
try {
|
|
2872
|
-
return
|
|
2856
|
+
return __wbg_adapter_328(a, state0.b, arg02, arg12, arg22);
|
|
2873
2857
|
} finally {
|
|
2874
2858
|
state0.a = a;
|
|
2875
2859
|
}
|
|
@@ -2970,7 +2954,7 @@ ${val.stack}`;
|
|
|
2970
2954
|
const a = state0.a;
|
|
2971
2955
|
state0.a = 0;
|
|
2972
2956
|
try {
|
|
2973
|
-
return
|
|
2957
|
+
return __wbg_adapter_385(a, state0.b, arg02, arg12);
|
|
2974
2958
|
} finally {
|
|
2975
2959
|
state0.a = a;
|
|
2976
2960
|
}
|
|
@@ -3086,20 +3070,16 @@ ${val.stack}`;
|
|
|
3086
3070
|
const ret = wasm.memory;
|
|
3087
3071
|
return addHeapObject(ret);
|
|
3088
3072
|
};
|
|
3089
|
-
imports.wbg.
|
|
3090
|
-
const ret =
|
|
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);
|
|
3073
|
+
imports.wbg.__wbindgen_closure_wrapper566 = function(arg0, arg1, arg2) {
|
|
3074
|
+
const ret = makeMutClosure(arg0, arg1, 207, __wbg_adapter_56);
|
|
3095
3075
|
return addHeapObject(ret);
|
|
3096
3076
|
};
|
|
3097
|
-
imports.wbg.
|
|
3098
|
-
const ret =
|
|
3077
|
+
imports.wbg.__wbindgen_closure_wrapper568 = function(arg0, arg1, arg2) {
|
|
3078
|
+
const ret = makeClosure(arg0, arg1, 207, __wbg_adapter_59);
|
|
3099
3079
|
return addHeapObject(ret);
|
|
3100
3080
|
};
|
|
3101
|
-
imports.wbg.
|
|
3102
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
3081
|
+
imports.wbg.__wbindgen_closure_wrapper1630 = function(arg0, arg1, arg2) {
|
|
3082
|
+
const ret = makeMutClosure(arg0, arg1, 449, __wbg_adapter_62);
|
|
3103
3083
|
return addHeapObject(ret);
|
|
3104
3084
|
};
|
|
3105
3085
|
return imports;
|
|
@@ -3143,216 +3123,223 @@ ${val.stack}`;
|
|
|
3143
3123
|
|
|
3144
3124
|
// src/index.ts
|
|
3145
3125
|
var import_ridb_core = __toESM(require_ridb_core());
|
|
3146
|
-
import {
|
|
3147
|
-
|
|
3148
|
-
}
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
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));
|
|
3126
|
+
import { WasmInternal } from "@trust0/ridb";
|
|
3127
|
+
async function createMongoDB() {
|
|
3128
|
+
const { BaseStorage } = await WasmInternal();
|
|
3129
|
+
class MongoDBStorage extends BaseStorage {
|
|
3130
|
+
client;
|
|
3131
|
+
db;
|
|
3132
|
+
mongoConfig;
|
|
3133
|
+
constructor(name, schemas, options = {}) {
|
|
3134
|
+
super(name, schemas, options);
|
|
3135
|
+
this.mongoConfig = options;
|
|
3174
3136
|
}
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3137
|
+
/**
|
|
3138
|
+
* Utility method to recursively convert ObjectId values to strings throughout an object
|
|
3139
|
+
* This ensures that MongoDB's ObjectId instances are never returned to the application layer,
|
|
3140
|
+
* maintaining consistency with RIDB's string-based approach and preventing serialization issues.
|
|
3141
|
+
* Also removes MongoDB's automatic _id field entirely from results.
|
|
3142
|
+
* @private
|
|
3143
|
+
*/
|
|
3144
|
+
convertObjectIdsToStrings(obj) {
|
|
3145
|
+
if (!obj || typeof obj !== "object") {
|
|
3146
|
+
return obj;
|
|
3147
|
+
}
|
|
3148
|
+
if (obj.constructor?.name === "ObjectId" || obj._bsontype && obj._bsontype === "ObjectId") {
|
|
3149
|
+
const stringValue = obj.toString();
|
|
3150
|
+
return stringValue;
|
|
3151
|
+
}
|
|
3152
|
+
if (Array.isArray(obj)) {
|
|
3153
|
+
return obj.map((item) => this.convertObjectIdsToStrings(item));
|
|
3154
|
+
}
|
|
3155
|
+
const converted = {};
|
|
3156
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
3157
|
+
if (key === "_id") {
|
|
3158
|
+
continue;
|
|
3159
|
+
}
|
|
3160
|
+
converted[key] = this.convertObjectIdsToStrings(value);
|
|
3179
3161
|
}
|
|
3180
|
-
converted
|
|
3162
|
+
return converted;
|
|
3181
3163
|
}
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
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;
|
|
3164
|
+
/**
|
|
3165
|
+
* Create a new MongoDB storage instance
|
|
3166
|
+
* @param name - Database name
|
|
3167
|
+
* @param schemas - Collection schemas
|
|
3168
|
+
* @param options - Storage options including MongoDB connection details
|
|
3169
|
+
* @returns A new Instance of MongoDB storage
|
|
3170
|
+
* @public
|
|
3171
|
+
*/
|
|
3172
|
+
static async create(name, schemas, options = {}) {
|
|
3173
|
+
const db = new MongoDBStorage(name, schemas, options);
|
|
3174
|
+
return db;
|
|
3211
3175
|
}
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3176
|
+
/** Start the database connection */
|
|
3177
|
+
async start() {
|
|
3178
|
+
const { MongoClient } = await import("mongodb");
|
|
3179
|
+
const url = this.mongoConfig.url || process.env.MONGODB_URL;
|
|
3180
|
+
if (!url) {
|
|
3181
|
+
throw new Error("MONGODB_URL is required");
|
|
3182
|
+
}
|
|
3183
|
+
const dbName = this.mongoConfig.dbName || this.name;
|
|
3184
|
+
this.client = new MongoClient(url, {
|
|
3185
|
+
connectTimeoutMS: 5e3,
|
|
3186
|
+
serverSelectionTimeoutMS: 5e3,
|
|
3187
|
+
socketTimeoutMS: 5e3,
|
|
3188
|
+
maxPoolSize: 10,
|
|
3189
|
+
minPoolSize: 5,
|
|
3190
|
+
maxIdleTimeMS: 5e3,
|
|
3191
|
+
maxConnecting: 5
|
|
3192
|
+
});
|
|
3193
|
+
await this.client.connect();
|
|
3194
|
+
this.db = this.client.db(dbName);
|
|
3217
3195
|
}
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
const primaryKey = schema.primaryKey;
|
|
3226
|
-
const query = { [primaryKey]: id };
|
|
3227
|
-
const doc = await collection.findOne(query);
|
|
3228
|
-
if (!doc) {
|
|
3229
|
-
return null;
|
|
3196
|
+
/** Close the database connection */
|
|
3197
|
+
async close() {
|
|
3198
|
+
if (this.client) {
|
|
3199
|
+
await this.client.close();
|
|
3200
|
+
this.client = void 0;
|
|
3201
|
+
this.db = void 0;
|
|
3202
|
+
}
|
|
3230
3203
|
}
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
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}`);
|
|
3204
|
+
/** Get MongoDB collection for a given collection name */
|
|
3205
|
+
getCollection(collectionName) {
|
|
3206
|
+
if (!this.db) {
|
|
3207
|
+
throw new Error("Database not started. Call start() first.");
|
|
3208
|
+
}
|
|
3209
|
+
const collection = this.db.collection(collectionName);
|
|
3210
|
+
return collection;
|
|
3281
3211
|
}
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3212
|
+
/** Find a document by its ID */
|
|
3213
|
+
async findDocumentById(collectionName, id) {
|
|
3214
|
+
const collection = this.getCollection(String(collectionName));
|
|
3215
|
+
const schema = this.getSchema(String(collectionName));
|
|
3216
|
+
const primaryKey = schema.primaryKey;
|
|
3217
|
+
const query = { [primaryKey]: id };
|
|
3218
|
+
const doc = await collection.findOne(query);
|
|
3219
|
+
if (!doc) {
|
|
3220
|
+
return null;
|
|
3221
|
+
}
|
|
3222
|
+
const converted = this.convertObjectIdsToStrings(doc);
|
|
3223
|
+
return converted;
|
|
3287
3224
|
}
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3225
|
+
/** Write an operation (insert, update, delete) */
|
|
3226
|
+
async write(op) {
|
|
3227
|
+
const collectionName = String(op.collection);
|
|
3228
|
+
const collection = this.getCollection(collectionName);
|
|
3229
|
+
const { primaryKey } = this.getSchema(collectionName);
|
|
3230
|
+
switch (op.opType) {
|
|
3231
|
+
case import_ridb_core.OpType.CREATE: {
|
|
3232
|
+
const id = primaryKey in op.data ? op.data[primaryKey] : null;
|
|
3233
|
+
if (!id) {
|
|
3234
|
+
throw new Error("Document ID is required");
|
|
3235
|
+
}
|
|
3236
|
+
const existQuery = { [primaryKey]: id };
|
|
3237
|
+
const existing = await collection.findOne(existQuery);
|
|
3238
|
+
if (existing) {
|
|
3239
|
+
throw new Error(`Document with ${primaryKey} '${id}' already exists`);
|
|
3240
|
+
}
|
|
3241
|
+
const docToInsert = { ...op.data };
|
|
3242
|
+
await collection.insertOne(docToInsert);
|
|
3243
|
+
const result = this.convertObjectIdsToStrings(op.data);
|
|
3244
|
+
return result;
|
|
3245
|
+
}
|
|
3246
|
+
case import_ridb_core.OpType.UPDATE: {
|
|
3247
|
+
const id = primaryKey in op.data ? op.data[primaryKey] : null;
|
|
3248
|
+
if (!id) {
|
|
3249
|
+
throw new Error("Document ID is required");
|
|
3250
|
+
}
|
|
3251
|
+
const updateQuery = { [primaryKey]: id };
|
|
3252
|
+
const updateData = { $set: op.data };
|
|
3253
|
+
const result = await collection.updateOne(updateQuery, updateData);
|
|
3254
|
+
if (result.matchedCount === 0) {
|
|
3255
|
+
throw new Error("Document ID not found");
|
|
3256
|
+
}
|
|
3257
|
+
const convertedResult = this.convertObjectIdsToStrings(op.data);
|
|
3258
|
+
return convertedResult;
|
|
3259
|
+
}
|
|
3260
|
+
case import_ridb_core.OpType.DELETE: {
|
|
3261
|
+
const id = op.data;
|
|
3262
|
+
const deleteQuery = { [primaryKey]: id };
|
|
3263
|
+
const result = await collection.deleteOne(deleteQuery);
|
|
3264
|
+
if (result.deletedCount === 0) {
|
|
3265
|
+
throw new Error("Document ID not found");
|
|
3266
|
+
}
|
|
3267
|
+
const convertedResult = this.convertObjectIdsToStrings(op.data);
|
|
3268
|
+
return convertedResult;
|
|
3269
|
+
}
|
|
3270
|
+
default:
|
|
3271
|
+
throw new Error(`Unknown operation type: ${op.opType}`);
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
/** Convert RIDB query to MongoDB filter */
|
|
3275
|
+
convertQueryToMongoFilter(query, _schema) {
|
|
3276
|
+
if (!query || typeof query !== "object") {
|
|
3277
|
+
return {};
|
|
3278
|
+
}
|
|
3279
|
+
const filter = {};
|
|
3280
|
+
for (const [key, value] of Object.entries(query)) {
|
|
3281
|
+
if (value === null || value === void 0) {
|
|
3282
|
+
filter[key] = { $exists: false };
|
|
3283
|
+
} else if (typeof value === "object" && value !== null) {
|
|
3284
|
+
if ("$in" in value) {
|
|
3285
|
+
filter[key] = { $in: this.convertObjectIdsToStrings(value.$in) };
|
|
3286
|
+
} else if ("$nin" in value) {
|
|
3287
|
+
filter[key] = { $nin: this.convertObjectIdsToStrings(value.$nin) };
|
|
3288
|
+
} else if ("$gt" in value) {
|
|
3289
|
+
filter[key] = { $gt: this.convertObjectIdsToStrings(value.$gt) };
|
|
3290
|
+
} else if ("$gte" in value) {
|
|
3291
|
+
filter[key] = { $gte: this.convertObjectIdsToStrings(value.$gte) };
|
|
3292
|
+
} else if ("$lt" in value) {
|
|
3293
|
+
filter[key] = { $lt: this.convertObjectIdsToStrings(value.$lt) };
|
|
3294
|
+
} else if ("$lte" in value) {
|
|
3295
|
+
filter[key] = { $lte: this.convertObjectIdsToStrings(value.$lte) };
|
|
3296
|
+
} else if ("$ne" in value) {
|
|
3297
|
+
filter[key] = { $ne: this.convertObjectIdsToStrings(value.$ne) };
|
|
3298
|
+
} else if ("$regex" in value) {
|
|
3299
|
+
filter[key] = { $regex: value.$regex };
|
|
3300
|
+
} else {
|
|
3301
|
+
filter[key] = this.convertObjectIdsToStrings(value);
|
|
3302
|
+
}
|
|
3309
3303
|
} else {
|
|
3310
3304
|
filter[key] = this.convertObjectIdsToStrings(value);
|
|
3311
3305
|
}
|
|
3312
|
-
} else {
|
|
3313
|
-
filter[key] = this.convertObjectIdsToStrings(value);
|
|
3314
3306
|
}
|
|
3307
|
+
return filter;
|
|
3315
3308
|
}
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3309
|
+
/** Count documents matching a query (supports offset & limit) */
|
|
3310
|
+
async count(collectionName, query, options) {
|
|
3311
|
+
const collection = this.getCollection(String(collectionName));
|
|
3312
|
+
const schema = this.getSchema(String(collectionName));
|
|
3313
|
+
const filter = this.convertQueryToMongoFilter(query, schema);
|
|
3314
|
+
const countOptions = {};
|
|
3315
|
+
if (options?.offset) {
|
|
3316
|
+
countOptions.skip = options.offset;
|
|
3317
|
+
}
|
|
3318
|
+
if (options?.limit) {
|
|
3319
|
+
countOptions.limit = options.limit;
|
|
3320
|
+
}
|
|
3321
|
+
const count = await collection.countDocuments(filter, Object.keys(countOptions).length > 0 ? countOptions : void 0);
|
|
3322
|
+
return count;
|
|
3326
3323
|
}
|
|
3327
|
-
|
|
3328
|
-
|
|
3324
|
+
/** Find documents matching a query with pagination */
|
|
3325
|
+
async find(collectionName, query, options) {
|
|
3326
|
+
const collection = this.getCollection(String(collectionName));
|
|
3327
|
+
const schema = this.getSchema(String(collectionName));
|
|
3328
|
+
const filter = this.convertQueryToMongoFilter(query, schema);
|
|
3329
|
+
let findQuery = collection.find(filter);
|
|
3330
|
+
if (options?.offset) {
|
|
3331
|
+
findQuery = findQuery.skip(options.offset);
|
|
3332
|
+
}
|
|
3333
|
+
if (options?.limit) {
|
|
3334
|
+
findQuery = findQuery.limit(options.limit);
|
|
3335
|
+
}
|
|
3336
|
+
const docs = await findQuery.toArray();
|
|
3337
|
+
const convertedDocs = docs.map((doc) => this.convertObjectIdsToStrings(doc));
|
|
3338
|
+
return convertedDocs;
|
|
3329
3339
|
}
|
|
3330
|
-
const count = await collection.countDocuments(filter, Object.keys(countOptions).length > 0 ? countOptions : void 0);
|
|
3331
|
-
return count;
|
|
3332
3340
|
}
|
|
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
3341
|
return MongoDBStorage;
|
|
3354
3342
|
}
|
|
3355
3343
|
export {
|
|
3356
|
-
MongoDBStorage,
|
|
3357
3344
|
createMongoDB
|
|
3358
3345
|
};
|