@moltendb-web/core 1.0.0-rc.1 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers.d.ts +4 -0
- package/dist/helpers.js +16 -0
- package/dist/index.js +8 -3
- package/dist/moltendb-worker.js +1 -1
- package/dist/{moltendb.d.ts → wasm/moltendb.d.ts} +3 -3
- package/dist/{moltendb.js → wasm/moltendb.js} +7 -7
- package/dist/wasm/moltendb_bg.wasm +0 -0
- package/dist/{moltendb_bg.wasm.d.ts → wasm/moltendb_bg.wasm.d.ts} +3 -3
- package/package.json +8 -5
- package/dist/moltendb_bg.wasm +0 -0
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively converts JS Maps (WASM default) into Plain Objects.
|
|
3
|
+
*/
|
|
4
|
+
export function mapToObj(data) {
|
|
5
|
+
if (data instanceof Map) {
|
|
6
|
+
const obj = {};
|
|
7
|
+
data.forEach((value, key) => {
|
|
8
|
+
obj[key] = mapToObj(value);
|
|
9
|
+
});
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(data)) {
|
|
13
|
+
return data.map(mapToObj);
|
|
14
|
+
}
|
|
15
|
+
return data;
|
|
16
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mapToObj } from "./helpers";
|
|
1
2
|
export class MoltenDB {
|
|
2
3
|
dbName;
|
|
3
4
|
workerUrl;
|
|
@@ -138,10 +139,14 @@ export class MoltenDB {
|
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
141
|
async sendMessage(action, payload) {
|
|
141
|
-
|
|
142
|
+
// Generate a unique ID (random fallback for test environments without crypto.randomUUID)
|
|
143
|
+
const id = (typeof crypto !== 'undefined' && crypto.randomUUID)
|
|
144
|
+
? crypto.randomUUID()
|
|
145
|
+
: Math.random().toString(36).substring(2, 9);
|
|
142
146
|
return new Promise((resolve, reject) => {
|
|
147
|
+
const successHandler = (res) => resolve(mapToObj(res));
|
|
143
148
|
if (this.isLeader && this.worker) {
|
|
144
|
-
this.pendingRequests.set(id, { resolve, reject });
|
|
149
|
+
this.pendingRequests.set(id, { resolve: successHandler, reject });
|
|
145
150
|
this.worker.postMessage({ id, action, ...payload });
|
|
146
151
|
}
|
|
147
152
|
else {
|
|
@@ -152,7 +157,7 @@ export class MoltenDB {
|
|
|
152
157
|
}
|
|
153
158
|
}, 10000);
|
|
154
159
|
this.pendingRequests.set(id, {
|
|
155
|
-
resolve: (
|
|
160
|
+
resolve: (res) => { clearTimeout(timer); successHandler(res); },
|
|
156
161
|
reject: (e) => { clearTimeout(timer); reject(e); }
|
|
157
162
|
});
|
|
158
163
|
this.bc.postMessage({ type: 'query', id, action, payload });
|
package/dist/moltendb-worker.js
CHANGED
|
@@ -93,9 +93,9 @@ export interface InitOutput {
|
|
|
93
93
|
readonly workerdb_handle_message: (a: number, b: number, c: number) => void;
|
|
94
94
|
readonly workerdb_new: (a: number, b: number) => number;
|
|
95
95
|
readonly workerdb_subscribe: (a: number, b: number) => void;
|
|
96
|
-
readonly
|
|
97
|
-
readonly
|
|
98
|
-
readonly
|
|
96
|
+
readonly __wasm_bindgen_func_elem_3628: (a: number, b: number) => void;
|
|
97
|
+
readonly __wasm_bindgen_func_elem_3707: (a: number, b: number, c: number, d: number) => void;
|
|
98
|
+
readonly __wasm_bindgen_func_elem_3718: (a: number, b: number, c: number, d: number) => void;
|
|
99
99
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
100
100
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
101
101
|
readonly __wbindgen_export3: (a: number) => void;
|
|
@@ -389,7 +389,7 @@ function __wbg_get_imports() {
|
|
|
389
389
|
const a = state0.a;
|
|
390
390
|
state0.a = 0;
|
|
391
391
|
try {
|
|
392
|
-
return
|
|
392
|
+
return __wasm_bindgen_func_elem_3718(a, state0.b, arg0, arg1);
|
|
393
393
|
} finally {
|
|
394
394
|
state0.a = a;
|
|
395
395
|
}
|
|
@@ -509,8 +509,8 @@ function __wbg_get_imports() {
|
|
|
509
509
|
return ret;
|
|
510
510
|
}, arguments); },
|
|
511
511
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
512
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx: 664, function: Function { arguments: [Externref], shim_idx:
|
|
513
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
512
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 664, function: Function { arguments: [Externref], shim_idx: 675, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
513
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_3628, __wasm_bindgen_func_elem_3707);
|
|
514
514
|
return addHeapObject(ret);
|
|
515
515
|
},
|
|
516
516
|
__wbindgen_cast_0000000000000002: function(arg0) {
|
|
@@ -547,10 +547,10 @@ function __wbg_get_imports() {
|
|
|
547
547
|
};
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
-
function
|
|
550
|
+
function __wasm_bindgen_func_elem_3707(arg0, arg1, arg2) {
|
|
551
551
|
try {
|
|
552
552
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
553
|
-
wasm.
|
|
553
|
+
wasm.__wasm_bindgen_func_elem_3707(retptr, arg0, arg1, addHeapObject(arg2));
|
|
554
554
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
555
555
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
556
556
|
if (r1) {
|
|
@@ -561,8 +561,8 @@ function __wasm_bindgen_func_elem_3697(arg0, arg1, arg2) {
|
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
|
|
564
|
-
function
|
|
565
|
-
wasm.
|
|
564
|
+
function __wasm_bindgen_func_elem_3718(arg0, arg1, arg2, arg3) {
|
|
565
|
+
wasm.__wasm_bindgen_func_elem_3718(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
566
566
|
}
|
|
567
567
|
|
|
568
568
|
const WorkerDbFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
Binary file
|
|
@@ -6,9 +6,9 @@ export const workerdb_analytics: (a: number, b: number, c: number, d: number) =>
|
|
|
6
6
|
export const workerdb_handle_message: (a: number, b: number, c: number) => void;
|
|
7
7
|
export const workerdb_new: (a: number, b: number) => number;
|
|
8
8
|
export const workerdb_subscribe: (a: number, b: number) => void;
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
9
|
+
export const __wasm_bindgen_func_elem_3628: (a: number, b: number) => void;
|
|
10
|
+
export const __wasm_bindgen_func_elem_3707: (a: number, b: number, c: number, d: number) => void;
|
|
11
|
+
export const __wasm_bindgen_func_elem_3718: (a: number, b: number, c: number, d: number) => void;
|
|
12
12
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
13
13
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
14
14
|
export const __wbindgen_export3: (a: number) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moltendb-web/core",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.3",
|
|
4
4
|
"description": "MoltenDB WASM runtime — the database engine, Web Worker, and main-thread client in one package.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Maximilian Both <maximilian.both27@outlook.com>",
|
|
@@ -23,14 +23,16 @@
|
|
|
23
23
|
"import": "./dist/moltendb-worker.js",
|
|
24
24
|
"types": "./dist/moltendb-worker.d.ts"
|
|
25
25
|
},
|
|
26
|
-
"./wasm": "./dist/moltendb.js",
|
|
27
|
-
"./wasm-bg": "./dist/moltendb_bg.wasm"
|
|
26
|
+
"./wasm": "./dist/wasm/moltendb.js",
|
|
27
|
+
"./wasm-bg": "./dist/wasm/moltendb_bg.wasm"
|
|
28
28
|
},
|
|
29
29
|
"main": "./dist/index.js",
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "tsc",
|
|
33
|
-
"
|
|
32
|
+
"build": "tsc && npm run copy-wasm",
|
|
33
|
+
"copy-wasm": "copyfiles -u 1 \"src/wasm/**/*\" dist/",
|
|
34
|
+
"dev": "tsc --watch & npm run watch-wasm",
|
|
35
|
+
"watch-wasm": "copyfiles -u 1 -w \"src/wasm/**/*\" dist/",
|
|
34
36
|
"typecheck": "tsc --noEmit",
|
|
35
37
|
"test": "vitest run",
|
|
36
38
|
"test:watch": "vitest",
|
|
@@ -41,6 +43,7 @@
|
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@playwright/test": "^1.58.2",
|
|
43
45
|
"@vitest/coverage-v8": "^4.1.1",
|
|
46
|
+
"copyfiles": "^2.4.1",
|
|
44
47
|
"happy-dom": "^20.8.7",
|
|
45
48
|
"typescript": "^6.0.2",
|
|
46
49
|
"vite": "^8.0.2",
|
package/dist/moltendb_bg.wasm
DELETED
|
Binary file
|