@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
|
@@ -4,4 +4,8 @@ export {
|
|
|
4
4
|
} from './functions/resolve-base-dir.function.ts';
|
|
5
5
|
export { resolveWorkerScript } from './functions/resolve-worker-script.function.ts';
|
|
6
6
|
export { resolveWasmDir } from './functions/resolve-wasm-dir.function.ts';
|
|
7
|
+
export {
|
|
8
|
+
isRemoteUrl,
|
|
9
|
+
joinPath,
|
|
10
|
+
} from './functions/join-path.function.ts';
|
|
7
11
|
export type { BaseDir } from './typings/base-dir.interface.ts';
|
|
@@ -130,7 +130,8 @@ export function createHostImports(
|
|
|
130
130
|
if (!memoryRef.memory) {
|
|
131
131
|
throw new Error('WASM memory not initialized');
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
134
|
+
return memoryRef.memory.buffer as ArrayBuffer;
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
function readPathArg(ptr: number, len: number): string {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import type { DaemonConfig } from '../typings/daemon-config.interface.ts';
|
|
4
4
|
import type { WasmModules } from '../typings/wasm-modules.interface.ts';
|
|
5
5
|
import { createHostImports } from './create-host-imports.function.ts';
|
|
@@ -7,23 +7,8 @@ import type {
|
|
|
7
7
|
AllocatorRef,
|
|
8
8
|
MemoryRef,
|
|
9
9
|
} from './create-host-imports.function.ts';
|
|
10
|
+
import { isRemoteUrl, joinPath } from '../../dir-resolver/index.ts';
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
* Loads and instantiates the `kb-worker` WASM module.
|
|
13
|
-
*
|
|
14
|
-
* `kb-worker.wasm` statically links the `fs-database` and
|
|
15
|
-
* `query-parser` crates, so only one module needs to be
|
|
16
|
-
* instantiated. The module exports its own linear memory;
|
|
17
|
-
* host I/O imports read it through a deferred `MemoryRef`
|
|
18
|
-
* that is wired up immediately after instantiation.
|
|
19
|
-
*
|
|
20
|
-
* @param config - daemon configuration, used to supply the context
|
|
21
|
-
* path to the host I/O imports
|
|
22
|
-
* @param wasmDir - absolute path to the directory containing the
|
|
23
|
-
* compiled WASM subdirectories (`query-parser/`, `fs-database/`,
|
|
24
|
-
* `kb-worker/`)
|
|
25
|
-
* @throws when the WASM file cannot be read or instantiated
|
|
26
|
-
*/
|
|
27
12
|
export async function loadWasmModules(
|
|
28
13
|
config: DaemonConfig,
|
|
29
14
|
wasmDir: string,
|
|
@@ -38,8 +23,8 @@ export async function loadWasmModules(
|
|
|
38
23
|
allocator,
|
|
39
24
|
);
|
|
40
25
|
|
|
41
|
-
const wkPath =
|
|
42
|
-
const wkBytes =
|
|
26
|
+
const wkPath = joinPath(wasmDir, 'kb-worker', 'kbdb_worker_bg.wasm');
|
|
27
|
+
const wkBytes = await readWasmFile(wkPath, 'kb-worker');
|
|
43
28
|
|
|
44
29
|
let wkModule: WebAssembly.Module;
|
|
45
30
|
try {
|
|
@@ -71,8 +56,20 @@ export async function loadWasmModules(
|
|
|
71
56
|
return { memory, kbWorker };
|
|
72
57
|
}
|
|
73
58
|
|
|
74
|
-
function
|
|
59
|
+
async function readWasmFile(
|
|
60
|
+
path: string,
|
|
61
|
+
label: string,
|
|
62
|
+
): Promise<ArrayBuffer> {
|
|
75
63
|
try {
|
|
64
|
+
if (isRemoteUrl(path)) {
|
|
65
|
+
const response = await fetch(path);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`HTTP ${String(response.status)} ${response.statusText}`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return await response.arrayBuffer();
|
|
72
|
+
}
|
|
76
73
|
const buf = readFileSync(path);
|
|
77
74
|
return buf.buffer.slice(
|
|
78
75
|
buf.byteOffset,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/shared/runtime/functions/detect-runtime.ts", "../src/shared/runtime/functions/get-args.ts", "../src/shared/dir-resolver/functions/resolve-base-dir.function.ts", "../src/shared/dir-resolver/functions/resolve-worker-script.function.ts", "../src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts", "../src/shared/hash/functions/compute-sha256.ts", "../src/shared/platform/functions/get-ipc-path.function.ts", "../src/shared/platform/functions/get-tmpdir.function.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Runtime } from '../typings/runtime.ts';\n\n/**\n * Detects the current JavaScript runtime environment.\n *\n * Returns `'deno'` when the global `Deno` object is present,\n * otherwise returns `'node'`.\n */\nexport function detectRuntime(): Runtime {\n if (typeof globalThis !== 'undefined' && 'Deno' in globalThis) {\n return 'deno';\n }\n return 'node';\n}\n", "import { detectRuntime } from './detect-runtime.ts';\n\n/**\n * Returns the command-line arguments for the current runtime.\n *\n * In Deno, reads `Deno.args`; in Node.js, slices `process.argv`\n * past the interpreter and script entries.\n */\nexport function getArgs(): string[] {\n if (detectRuntime() === 'deno') {\n const g = globalThis as Record<string, unknown>;\n const deno = g['Deno'] as { args: string[] } | undefined;\n return deno?.args ?? [];\n }\n return process.argv.slice(2);\n}\n", "import { dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { BaseDir } from '../typings/base-dir.interface.ts';\n\nexport function resolveScriptDir(\n entryUrl: string,\n entryDirname?: string,\n): string {\n if (entryDirname) return entryDirname;\n if (entryUrl.startsWith('file:'))\n return dirname(fileURLToPath(entryUrl));\n return dirname(entryUrl);\n}\n\nexport function resolveBaseDir(\n entryUrl: string,\n entryDirname?: string,\n): BaseDir {\n const scriptDir =\n typeof __dirname !== 'undefined'\n ? __dirname\n : resolveScriptDir(entryUrl, entryDirname);\n return { scriptDir, cwd: process.cwd() };\n}\n", "import { join } from 'node:path';\n\nimport type { Runtime } from '../../runtime/typings/runtime.ts';\n\nexport function resolveWorkerScript(\n scriptDir: string,\n runtime: Runtime,\n): string {\n if (runtime === 'deno') {\n return join(scriptDir, 'worker.ts');\n }\n return join(scriptDir, 'kbdb-worker.cjs');\n}\n", "import { join } from 'node:path';\n\nexport function resolveWasmDir(scriptDir: string): string {\n return join(scriptDir, 'wasm');\n}\n", "/**\n * Computes the SHA-256 hash of a UTF-8 string.\n *\n * Uses the Web Crypto API (`crypto.subtle`), which is available\n * in both Deno and Node.js >= 20 without additional imports.\n *\n * @param input - the string to hash\n * @returns lowercase hex-encoded SHA-256 digest (64 characters)\n */\nexport async function computeSha256(input: string): Promise<string> {\n const data = new TextEncoder().encode(input);\n const hash = await crypto.subtle.digest('SHA-256', data);\n const bytes = new Uint8Array(hash);\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n", "import { join } from 'node:path';\nimport { getTmpdir } from './get-tmpdir.function.ts';\n\n/**\n * Returns the platform-appropriate IPC socket path for a given\n * context identifier.\n *\n * On Windows, returns a named pipe path (`\\\\.\\pipe\\kbdb-<ctx>`).\n * On POSIX systems, returns a Unix domain socket path under the\n * system temp directory (`<tmpdir>/kbdb-<ctx>.sock`).\n *\n * @param ctx - unique context identifier embedded in the path\n */\nexport function getIpcPath(ctx: string): string {\n if (process.platform === 'win32') {\n return `\\\\\\\\.\\\\pipe\\\\kbdb-${ctx}`;\n }\n return join(getTmpdir(), `kbdb-${ctx}.sock`);\n}\n", "import { tmpdir } from 'node:os';\n\n/**\n * Returns the operating system's default temporary directory path.\n */\nexport function getTmpdir(): string {\n return tmpdir();\n}\n"],
|
|
5
|
-
"mappings": ";AAQO,SAAS,gBAAyB;AACtC,MAAI,OAAO,eAAe,eAAe,UAAU,YAAY;AAC5D,WAAO;AAAA,EACV;AACA,SAAO;AACV;;;ACLO,SAAS,UAAoB;AACjC,MAAI,cAAc,MAAM,QAAQ;AAC7B,UAAM,IAAI;AACV,UAAM,OAAO,EAAE,MAAM;AACrB,WAAO,MAAM,QAAQ,CAAC;AAAA,EACzB;AACA,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC9B;;;ACfA,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAIvB,SAAS,iBACb,UACA,cACO;AACP,MAAI,aAAc,QAAO;AACzB,MAAI,SAAS,WAAW,OAAO;AAC5B,WAAO,QAAQ,cAAc,QAAQ,CAAC;AACzC,SAAO,QAAQ,QAAQ;AAC1B;AAEO,SAAS,eACb,UACA,cACQ;AACR,QAAM,YACH,OAAO,cAAc,cAChB,YACA,iBAAiB,UAAU,YAAY;AAC/C,SAAO,EAAE,WAAW,KAAK,QAAQ,IAAI,EAAE;AAC1C;;;ACxBA,SAAS,YAAY;AAId,SAAS,oBACb,WACA,SACO;AACP,MAAI,YAAY,QAAQ;AACrB,WAAO,KAAK,WAAW,WAAW;AAAA,EACrC;AACA,SAA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