@dikolab/kbdb 0.1.0 → 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/create-host-imports.function.ts +2 -1
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +17 -20
- package/dist/chunk-QCCN7OZH.mjs.map +0 -7
package/dist/cli.mjs
CHANGED
package/dist/kbdb-worker.cjs
CHANGED
|
@@ -36,10 +36,22 @@ function resolveBaseDir(entryUrl, entryDirname) {
|
|
|
36
36
|
return { scriptDir, cwd: process.cwd() };
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// src/shared/dir-resolver/functions/
|
|
39
|
+
// src/shared/dir-resolver/functions/join-path.function.ts
|
|
40
40
|
var import_node_path2 = require("node:path");
|
|
41
|
+
function isRemoteUrl(path) {
|
|
42
|
+
return path.startsWith("http://") || path.startsWith("https://");
|
|
43
|
+
}
|
|
44
|
+
function joinPath(base, ...segments) {
|
|
45
|
+
if (isRemoteUrl(base)) {
|
|
46
|
+
const trailing = base.endsWith("/") ? "" : "/";
|
|
47
|
+
return base + trailing + segments.join("/");
|
|
48
|
+
}
|
|
49
|
+
return (0, import_node_path2.join)(base, ...segments);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts
|
|
41
53
|
function resolveWasmDir(scriptDir) {
|
|
42
|
-
return (
|
|
54
|
+
return joinPath(scriptDir, "wasm");
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
// src/shared/worker-daemon/functions/read-config.function.ts
|
|
@@ -109,7 +121,7 @@ function parseWorkerToml(text, contextPath) {
|
|
|
109
121
|
|
|
110
122
|
// src/shared/worker-daemon/functions/start-daemon.function.ts
|
|
111
123
|
var import_node_fs5 = require("node:fs");
|
|
112
|
-
var
|
|
124
|
+
var import_node_path7 = require("node:path");
|
|
113
125
|
var import_node_os3 = require("node:os");
|
|
114
126
|
|
|
115
127
|
// src/shared/hash/functions/compute-sha256.ts
|
|
@@ -122,12 +134,11 @@ async function computeSha256(input) {
|
|
|
122
134
|
|
|
123
135
|
// src/shared/worker-daemon/classes/worker-daemon.class.ts
|
|
124
136
|
var import_node_fs4 = require("node:fs");
|
|
125
|
-
var
|
|
137
|
+
var import_node_path6 = require("node:path");
|
|
126
138
|
var import_node_os2 = require("node:os");
|
|
127
139
|
|
|
128
140
|
// src/shared/worker-daemon/functions/load-wasm-modules.function.ts
|
|
129
141
|
var import_node_fs3 = require("node:fs");
|
|
130
|
-
var import_node_path5 = require("node:path");
|
|
131
142
|
|
|
132
143
|
// src/shared/worker-daemon/functions/create-host-imports.function.ts
|
|
133
144
|
var import_node_fs2 = require("node:fs");
|
|
@@ -319,8 +330,8 @@ async function loadWasmModules(config, wasmDir2) {
|
|
|
319
330
|
void 0,
|
|
320
331
|
allocator
|
|
321
332
|
);
|
|
322
|
-
const wkPath = (
|
|
323
|
-
const wkBytes =
|
|
333
|
+
const wkPath = joinPath(wasmDir2, "kb-worker", "kbdb_worker_bg.wasm");
|
|
334
|
+
const wkBytes = await readWasmFile(wkPath, "kb-worker");
|
|
324
335
|
let wkModule;
|
|
325
336
|
try {
|
|
326
337
|
wkModule = await WebAssembly.compile(wkBytes);
|
|
@@ -344,8 +355,17 @@ async function loadWasmModules(config, wasmDir2) {
|
|
|
344
355
|
};
|
|
345
356
|
return { memory, kbWorker };
|
|
346
357
|
}
|
|
347
|
-
function
|
|
358
|
+
async function readWasmFile(path, label) {
|
|
348
359
|
try {
|
|
360
|
+
if (isRemoteUrl(path)) {
|
|
361
|
+
const response = await fetch(path);
|
|
362
|
+
if (!response.ok) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
`HTTP ${String(response.status)} ${response.statusText}`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
return await response.arrayBuffer();
|
|
368
|
+
}
|
|
349
369
|
const buf = (0, import_node_fs3.readFileSync)(path);
|
|
350
370
|
return buf.buffer.slice(
|
|
351
371
|
buf.byteOffset,
|
|
@@ -411,7 +431,7 @@ async function handleLine(line, handler, socket) {
|
|
|
411
431
|
}
|
|
412
432
|
|
|
413
433
|
// src/shared/platform/functions/get-ipc-path.function.ts
|
|
414
|
-
var
|
|
434
|
+
var import_node_path5 = require("node:path");
|
|
415
435
|
|
|
416
436
|
// src/shared/platform/functions/get-tmpdir.function.ts
|
|
417
437
|
var import_node_os = require("node:os");
|
|
@@ -424,7 +444,7 @@ function getIpcPath(ctx) {
|
|
|
424
444
|
if (process.platform === "win32") {
|
|
425
445
|
return `\\\\.\\pipe\\kbdb-${ctx}`;
|
|
426
446
|
}
|
|
427
|
-
return (0,
|
|
447
|
+
return (0, import_node_path5.join)(getTmpdir(), `kbdb-${ctx}.sock`);
|
|
428
448
|
}
|
|
429
449
|
|
|
430
450
|
// src/shared/wasm-codec/functions/encode-string.function.ts
|
|
@@ -967,7 +987,7 @@ var WorkerDaemon = class {
|
|
|
967
987
|
);
|
|
968
988
|
this._wasmModules = wasmModules;
|
|
969
989
|
this.initWorkerContext();
|
|
970
|
-
const pidPath = (0,
|
|
990
|
+
const pidPath = (0, import_node_path6.join)((0, import_node_os2.tmpdir)(), `kbdb-${this.ctx}.pid`);
|
|
971
991
|
(0, import_node_fs4.writeFileSync)(pidPath, process.pid.toString());
|
|
972
992
|
const ipcPath = getIpcPath(this.ctx);
|
|
973
993
|
if ((0, import_node_fs4.existsSync)(ipcPath)) {
|
|
@@ -1007,7 +1027,7 @@ var WorkerDaemon = class {
|
|
|
1007
1027
|
this._server = null;
|
|
1008
1028
|
}
|
|
1009
1029
|
this._wasmModules = null;
|
|
1010
|
-
const pidPath = (0,
|
|
1030
|
+
const pidPath = (0, import_node_path6.join)((0, import_node_os2.tmpdir)(), `kbdb-${this.ctx}.pid`);
|
|
1011
1031
|
try {
|
|
1012
1032
|
(0, import_node_fs4.unlinkSync)(pidPath);
|
|
1013
1033
|
} catch {
|
|
@@ -1017,7 +1037,7 @@ var WorkerDaemon = class {
|
|
|
1017
1037
|
(0, import_node_fs4.unlinkSync)(ipcPath);
|
|
1018
1038
|
} catch {
|
|
1019
1039
|
}
|
|
1020
|
-
const crashPath = (0,
|
|
1040
|
+
const crashPath = (0, import_node_path6.join)((0, import_node_os2.tmpdir)(), `kbdb-${this.ctx}.crash`);
|
|
1021
1041
|
try {
|
|
1022
1042
|
(0, import_node_fs4.unlinkSync)(crashPath);
|
|
1023
1043
|
} catch {
|
|
@@ -1112,7 +1132,7 @@ var WorkerDaemon = class {
|
|
|
1112
1132
|
}
|
|
1113
1133
|
/** Reads catalog.toml and validates the version field. */
|
|
1114
1134
|
checkCatalogVersion() {
|
|
1115
|
-
const catalogPath = (0,
|
|
1135
|
+
const catalogPath = (0, import_node_path6.join)(this.targetDir, "catalog.toml");
|
|
1116
1136
|
let text;
|
|
1117
1137
|
try {
|
|
1118
1138
|
text = (0, import_node_fs4.readFileSync)(catalogPath, "utf-8");
|
|
@@ -1507,7 +1527,7 @@ var WorkerDaemon = class {
|
|
|
1507
1527
|
}
|
|
1508
1528
|
handleCheckVersion(params) {
|
|
1509
1529
|
const targetPath = typeof params.targetPath === "string" ? params.targetPath : this.targetDir;
|
|
1510
|
-
const catalogPath = (0,
|
|
1530
|
+
const catalogPath = (0, import_node_path6.join)(targetPath, "catalog.toml");
|
|
1511
1531
|
let text;
|
|
1512
1532
|
try {
|
|
1513
1533
|
text = (0, import_node_fs4.readFileSync)(catalogPath, "utf-8");
|
|
@@ -1604,7 +1624,7 @@ async function startDaemon(contextPath, wasmDir2) {
|
|
|
1604
1624
|
}
|
|
1605
1625
|
function writeCrashLog(contextId, message) {
|
|
1606
1626
|
try {
|
|
1607
|
-
const crashPath = (0,
|
|
1627
|
+
const crashPath = (0, import_node_path7.join)((0, import_node_os3.tmpdir)(), `kbdb-${contextId}.crash`);
|
|
1608
1628
|
const payload = JSON.stringify({
|
|
1609
1629
|
error: message,
|
|
1610
1630
|
timestamp: Date.now()
|
|
@@ -1615,7 +1635,7 @@ function writeCrashLog(contextId, message) {
|
|
|
1615
1635
|
}
|
|
1616
1636
|
|
|
1617
1637
|
// src/shared/worker-daemon/functions/run-worker.function.ts
|
|
1618
|
-
var
|
|
1638
|
+
var import_node_path8 = require("node:path");
|
|
1619
1639
|
async function runWorker(argv, deps) {
|
|
1620
1640
|
const contextPath = argv[0];
|
|
1621
1641
|
if (!contextPath) {
|
|
@@ -1624,7 +1644,7 @@ async function runWorker(argv, deps) {
|
|
|
1624
1644
|
exitCode: 1
|
|
1625
1645
|
};
|
|
1626
1646
|
}
|
|
1627
|
-
const resolved = (0,
|
|
1647
|
+
const resolved = (0, import_node_path8.resolve)(contextPath);
|
|
1628
1648
|
if (!deps.existsSync(resolved)) {
|
|
1629
1649
|
return {
|
|
1630
1650
|
error: `error: path not found: ${resolved}`,
|