@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.
@@ -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-QCCN7OZH.mjs";
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 join5 } from "node:path";
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 join4 } from "node:path";
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 = join3(wasmDir2, "kb-worker", "kbdb_worker_bg.wasm");
297
- const wkBytes = readWasmFileOrThrow(wkPath, "kb-worker");
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 readWasmFileOrThrow(path, label) {
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 = join4(tmpdir(), `kbdb-${this.ctx}.pid`);
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 = join4(tmpdir(), `kbdb-${this.ctx}.pid`);
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 = join4(tmpdir(), `kbdb-${this.ctx}.crash`);
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 = join4(this.targetDir, "catalog.toml");
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 = join4(targetPath, "catalog.toml");
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 = join5(tmpdir2(), `kbdb-${contextId}.crash`);
1574
+ const crashPath = join4(tmpdir2(), `kbdb-${contextId}.crash`);
1565
1575
  const payload = JSON.stringify({
1566
1576
  error: message,
1567
1577
  timestamp: Date.now()