@dikolab/kbdb 0.1.1 → 0.1.2
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/{chunk-QCCN7OZH.mjs → chunk-JG2UCKLI.mjs} +21 -8
- package/dist/chunk-JG2UCKLI.mjs.map +7 -0
- package/dist/cli.cjs +15 -3
- package/dist/cli.cjs.map +3 -3
- package/dist/cli.mjs +1 -1
- package/dist/kbdb-worker.cjs +38 -18
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/src/shared/dir-resolver/functions/join-path.function.d.ts +2 -0
- package/dist/src/shared/dir-resolver/index.d.ts +1 -0
- package/dist/src/shared/worker-daemon/functions/load-wasm-modules.function.d.ts +0 -16
- package/dist/worker.mjs +23 -13
- package/dist/worker.mjs.map +3 -3
- package/package.json +1 -1
- package/src/shared/dir-resolver/functions/join-path.function.ts +13 -0
- package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +2 -2
- package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +3 -3
- package/src/shared/dir-resolver/index.ts +4 -0
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +17 -20
- package/dist/chunk-QCCN7OZH.mjs.map +0 -7
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
import type { DaemonConfig } from '../typings/daemon-config.interface.ts';
|
|
2
2
|
import type { WasmModules } from '../typings/wasm-modules.interface.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Loads and instantiates the `kb-worker` WASM module.
|
|
5
|
-
*
|
|
6
|
-
* `kb-worker.wasm` statically links the `fs-database` and
|
|
7
|
-
* `query-parser` crates, so only one module needs to be
|
|
8
|
-
* instantiated. The module exports its own linear memory;
|
|
9
|
-
* host I/O imports read it through a deferred `MemoryRef`
|
|
10
|
-
* that is wired up immediately after instantiation.
|
|
11
|
-
*
|
|
12
|
-
* @param config - daemon configuration, used to supply the context
|
|
13
|
-
* path to the host I/O imports
|
|
14
|
-
* @param wasmDir - absolute path to the directory containing the
|
|
15
|
-
* compiled WASM subdirectories (`query-parser/`, `fs-database/`,
|
|
16
|
-
* `kb-worker/`)
|
|
17
|
-
* @throws when the WASM file cannot be read or instantiated
|
|
18
|
-
*/
|
|
19
3
|
export declare function loadWasmModules(config: DaemonConfig, wasmDir: string): Promise<WasmModules>;
|
package/dist/worker.mjs
CHANGED
|
@@ -2,9 +2,11 @@ import {
|
|
|
2
2
|
computeSha256,
|
|
3
3
|
getArgs,
|
|
4
4
|
getIpcPath,
|
|
5
|
+
isRemoteUrl,
|
|
6
|
+
joinPath,
|
|
5
7
|
resolveBaseDir,
|
|
6
8
|
resolveWasmDir
|
|
7
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JG2UCKLI.mjs";
|
|
8
10
|
|
|
9
11
|
// src/worker.ts
|
|
10
12
|
import { existsSync as existsSync3 } from "node:fs";
|
|
@@ -76,7 +78,7 @@ function parseWorkerToml(text, contextPath) {
|
|
|
76
78
|
|
|
77
79
|
// src/shared/worker-daemon/functions/start-daemon.function.ts
|
|
78
80
|
import { writeFileSync as writeFileSync3 } from "node:fs";
|
|
79
|
-
import { join as
|
|
81
|
+
import { join as join4 } from "node:path";
|
|
80
82
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
81
83
|
|
|
82
84
|
// src/shared/worker-daemon/classes/worker-daemon.class.ts
|
|
@@ -88,12 +90,11 @@ import {
|
|
|
88
90
|
unlinkSync as unlinkSync2,
|
|
89
91
|
constants
|
|
90
92
|
} from "node:fs";
|
|
91
|
-
import { join as
|
|
93
|
+
import { join as join3 } from "node:path";
|
|
92
94
|
import { tmpdir } from "node:os";
|
|
93
95
|
|
|
94
96
|
// src/shared/worker-daemon/functions/load-wasm-modules.function.ts
|
|
95
97
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
96
|
-
import { join as join3 } from "node:path";
|
|
97
98
|
|
|
98
99
|
// src/shared/worker-daemon/functions/create-host-imports.function.ts
|
|
99
100
|
import {
|
|
@@ -293,8 +294,8 @@ async function loadWasmModules(config, wasmDir2) {
|
|
|
293
294
|
void 0,
|
|
294
295
|
allocator
|
|
295
296
|
);
|
|
296
|
-
const wkPath =
|
|
297
|
-
const wkBytes =
|
|
297
|
+
const wkPath = joinPath(wasmDir2, "kb-worker", "kbdb_worker_bg.wasm");
|
|
298
|
+
const wkBytes = await readWasmFile(wkPath, "kb-worker");
|
|
298
299
|
let wkModule;
|
|
299
300
|
try {
|
|
300
301
|
wkModule = await WebAssembly.compile(wkBytes);
|
|
@@ -318,8 +319,17 @@ async function loadWasmModules(config, wasmDir2) {
|
|
|
318
319
|
};
|
|
319
320
|
return { memory, kbWorker };
|
|
320
321
|
}
|
|
321
|
-
function
|
|
322
|
+
async function readWasmFile(path, label) {
|
|
322
323
|
try {
|
|
324
|
+
if (isRemoteUrl(path)) {
|
|
325
|
+
const response = await fetch(path);
|
|
326
|
+
if (!response.ok) {
|
|
327
|
+
throw new Error(
|
|
328
|
+
`HTTP ${String(response.status)} ${response.statusText}`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
return await response.arrayBuffer();
|
|
332
|
+
}
|
|
323
333
|
const buf = readFileSync3(path);
|
|
324
334
|
return buf.buffer.slice(
|
|
325
335
|
buf.byteOffset,
|
|
@@ -924,7 +934,7 @@ var WorkerDaemon = class {
|
|
|
924
934
|
);
|
|
925
935
|
this._wasmModules = wasmModules;
|
|
926
936
|
this.initWorkerContext();
|
|
927
|
-
const pidPath =
|
|
937
|
+
const pidPath = join3(tmpdir(), `kbdb-${this.ctx}.pid`);
|
|
928
938
|
writeFileSync2(pidPath, process.pid.toString());
|
|
929
939
|
const ipcPath = getIpcPath(this.ctx);
|
|
930
940
|
if (existsSync2(ipcPath)) {
|
|
@@ -964,7 +974,7 @@ var WorkerDaemon = class {
|
|
|
964
974
|
this._server = null;
|
|
965
975
|
}
|
|
966
976
|
this._wasmModules = null;
|
|
967
|
-
const pidPath =
|
|
977
|
+
const pidPath = join3(tmpdir(), `kbdb-${this.ctx}.pid`);
|
|
968
978
|
try {
|
|
969
979
|
unlinkSync2(pidPath);
|
|
970
980
|
} catch {
|
|
@@ -974,7 +984,7 @@ var WorkerDaemon = class {
|
|
|
974
984
|
unlinkSync2(ipcPath);
|
|
975
985
|
} catch {
|
|
976
986
|
}
|
|
977
|
-
const crashPath =
|
|
987
|
+
const crashPath = join3(tmpdir(), `kbdb-${this.ctx}.crash`);
|
|
978
988
|
try {
|
|
979
989
|
unlinkSync2(crashPath);
|
|
980
990
|
} catch {
|
|
@@ -1069,7 +1079,7 @@ var WorkerDaemon = class {
|
|
|
1069
1079
|
}
|
|
1070
1080
|
/** Reads catalog.toml and validates the version field. */
|
|
1071
1081
|
checkCatalogVersion() {
|
|
1072
|
-
const catalogPath =
|
|
1082
|
+
const catalogPath = join3(this.targetDir, "catalog.toml");
|
|
1073
1083
|
let text;
|
|
1074
1084
|
try {
|
|
1075
1085
|
text = readFileSync4(catalogPath, "utf-8");
|
|
@@ -1464,7 +1474,7 @@ var WorkerDaemon = class {
|
|
|
1464
1474
|
}
|
|
1465
1475
|
handleCheckVersion(params) {
|
|
1466
1476
|
const targetPath = typeof params.targetPath === "string" ? params.targetPath : this.targetDir;
|
|
1467
|
-
const catalogPath =
|
|
1477
|
+
const catalogPath = join3(targetPath, "catalog.toml");
|
|
1468
1478
|
let text;
|
|
1469
1479
|
try {
|
|
1470
1480
|
text = readFileSync4(catalogPath, "utf-8");
|
|
@@ -1561,7 +1571,7 @@ async function startDaemon(contextPath, wasmDir2) {
|
|
|
1561
1571
|
}
|
|
1562
1572
|
function writeCrashLog(contextId, message) {
|
|
1563
1573
|
try {
|
|
1564
|
-
const crashPath =
|
|
1574
|
+
const crashPath = join4(tmpdir2(), `kbdb-${contextId}.crash`);
|
|
1565
1575
|
const payload = JSON.stringify({
|
|
1566
1576
|
error: message,
|
|
1567
1577
|
timestamp: Date.now()
|