@dikolab/kbdb 0.1.1 → 0.1.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/{chunk-QCCN7OZH.mjs → chunk-JG2UCKLI.mjs} +21 -8
- package/dist/chunk-JG2UCKLI.mjs.map +7 -0
- package/dist/cli.cjs +16 -4
- package/dist/cli.cjs.map +3 -3
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/kbdb-worker.cjs +38 -18
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +1 -1
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.mjs +1 -1
- package/dist/mod.mjs.map +1 -1
- 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/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/worker-daemon/functions/load-wasm-modules.function.d.ts +0 -16
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +220 -0
- package/dist/wasm/fs-database/kbdb_fs_database.js +458 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +32 -0
- package/dist/wasm/fs-database/package.json +13 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +565 -0
- package/dist/wasm/kb-worker/kbdb_worker.js +1066 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +72 -0
- package/dist/wasm/kb-worker/package.json +13 -0
- package/dist/wasm/query-parser/kbdb_query_parser.d.ts +195 -0
- package/dist/wasm/query-parser/kbdb_query_parser.js +403 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm.d.ts +25 -0
- package/dist/wasm/query-parser/package.json +13 -0
- 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/version/constants/version.constant.ts +1 -1
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +17 -20
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +220 -0
- package/src/wasm/fs-database/kbdb_fs_database.js +458 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +32 -0
- package/src/wasm/fs-database/package.json +13 -0
- package/src/wasm/kb-worker/kbdb_worker.d.ts +565 -0
- package/src/wasm/kb-worker/kbdb_worker.js +1066 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +72 -0
- package/src/wasm/kb-worker/package.json +13 -0
- package/src/wasm/query-parser/kbdb_query_parser.d.ts +195 -0
- package/src/wasm/query-parser/kbdb_query_parser.js +403 -0
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm.d.ts +25 -0
- package/src/wasm/query-parser/package.json +13 -0
- 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';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Current package version, kept in sync with package.json. */
|
|
2
|
-
export const VERSION = '0.1.
|
|
2
|
+
export const VERSION = '0.1.3';
|
|
@@ -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,
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
declare namespace wasm_bindgen {
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Adds a section. `ptr`/`len` point to an encoded `AddSectionParams`.
|
|
7
|
+
*
|
|
8
|
+
* On success: writes encoded kbid string to return slot, returns 0.
|
|
9
|
+
* On error: writes error message to return slot, returns -1.
|
|
10
|
+
*/
|
|
11
|
+
export function db_add_section(ptr: number, len: number): number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Adds a section's terms to the inverted and positional indexes.
|
|
15
|
+
* `ptr`/`len` point to encoded
|
|
16
|
+
* (kbid_str, term_count, [(term_str, pos_count, [positions], heading_tf, body_tf, code_tf)]).
|
|
17
|
+
*/
|
|
18
|
+
export function db_add_to_index(ptr: number, len: number): number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checks database integrity. Returns 0 on success.
|
|
22
|
+
* On success a summary string is placed in the return slot.
|
|
23
|
+
*/
|
|
24
|
+
export function db_check_integrity(_ptr: number, _len: number): number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Reads `catalog.toml` from the path at `ptr`/`len` and returns the version
|
|
28
|
+
* status without modifying state.
|
|
29
|
+
*
|
|
30
|
+
* On success, the return slot contains 8 bytes:
|
|
31
|
+
* - bytes 0-3: `catalog_version` as little-endian u32
|
|
32
|
+
* - bytes 4-7: `required_version` (DB_FORMAT_VERSION) as little-endian u32
|
|
33
|
+
*
|
|
34
|
+
* Return value:
|
|
35
|
+
* - 0: compatible (versions match)
|
|
36
|
+
* - 1: needs migration (catalog version < required)
|
|
37
|
+
* - 2: too new (catalog version > required)
|
|
38
|
+
* - -1: I/O or parse error (message in return slot)
|
|
39
|
+
*
|
|
40
|
+
* Note: this export accepts a path directly and does NOT require `db_init`
|
|
41
|
+
* to have been called first.
|
|
42
|
+
*/
|
|
43
|
+
export function db_check_version(ptr: number, len: number): number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Runs garbage collection. Returns 0 on success.
|
|
47
|
+
* On success a summary string is placed in the return slot.
|
|
48
|
+
*/
|
|
49
|
+
export function db_gc(_ptr: number, _len: number): number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Initialises the database context path.
|
|
53
|
+
*
|
|
54
|
+
* The JS host must call this before any other function.
|
|
55
|
+
* `ptr`/`len` point to a UTF-8 context path string in WASM memory.
|
|
56
|
+
*/
|
|
57
|
+
export function db_init(ptr: number, len: number): number;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Initialises a new empty catalog at the current context path.
|
|
61
|
+
* Writes the default catalog to disk and returns 0 on success.
|
|
62
|
+
*/
|
|
63
|
+
export function db_init_catalog(_ptr: number, _len: number): number;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Creates the full directory scaffold for a new database at `ptr`/`len` path.
|
|
67
|
+
*
|
|
68
|
+
* Creates directories, seeds `catalog.toml` (stamped with `DB_FORMAT_VERSION`),
|
|
69
|
+
* empty index files, `worker.toml`, and `.gitignore`.
|
|
70
|
+
*
|
|
71
|
+
* Returns 0 on success. Returns -1 with an error message in the return slot
|
|
72
|
+
* if the directory already exists or any I/O fails.
|
|
73
|
+
*
|
|
74
|
+
* Note: this export accepts a path directly and does NOT require `db_init`
|
|
75
|
+
* to have been called first.
|
|
76
|
+
*/
|
|
77
|
+
export function db_init_directory(ptr: number, len: number): number;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Lists all document manifests. No input parameters (`ptr`/`len` are ignored).
|
|
81
|
+
*
|
|
82
|
+
* On success encodes a `u32 count` followed by each `DocumentManifest` into
|
|
83
|
+
* the return slot and returns 0. On error writes an error message and returns -1.
|
|
84
|
+
*/
|
|
85
|
+
export function db_list_documents(_ptr: number, _len: number): number;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Lists all section records. No input parameters (`ptr`/`len` are ignored).
|
|
89
|
+
*
|
|
90
|
+
* On success encodes a `u32 count` followed by each `SectionRecord` into the
|
|
91
|
+
* return slot and returns 0. On error writes an error message and returns -1.
|
|
92
|
+
*/
|
|
93
|
+
export function db_list_sections(_ptr: number, _len: number): number;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Executes a query plan against the loaded indexes.
|
|
97
|
+
* `ptr`/`len` point to an encoded `QueryPlan`.
|
|
98
|
+
* On success writes encoded `Vec<RawMatch>` to the return slot.
|
|
99
|
+
*/
|
|
100
|
+
export function db_query(ptr: number, len: number): number;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Reads the catalog. Returns 0 on success.
|
|
104
|
+
* On success the serialised catalog TOML text is in the return slot.
|
|
105
|
+
*/
|
|
106
|
+
export function db_read_catalog(_ptr: number, _len: number): number;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Reads corpus statistics from `<ctx>/corpus.bin`.
|
|
110
|
+
* On success places encoded `CorpusStats` bytes in the return slot.
|
|
111
|
+
*/
|
|
112
|
+
export function db_read_corpus_stats(_ptr: number, _len: number): number;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Reads a document manifest. `ptr`/`len` point to a UTF-8 docid string.
|
|
116
|
+
*/
|
|
117
|
+
export function db_read_document(ptr: number, len: number): number;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Reads a section by kbid. `ptr`/`len` point to a UTF-8 kbid string.
|
|
121
|
+
*/
|
|
122
|
+
export function db_read_section(ptr: number, len: number): number;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Reads multiple sections. `ptr`/`len` point to encoded `Vec<KbId>` (count + kbids).
|
|
126
|
+
*/
|
|
127
|
+
export function db_read_sections(ptr: number, len: number): number;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Rebuilds indexes from scratch.
|
|
131
|
+
*
|
|
132
|
+
* Clears the existing inverted and positional indexes, then drives the
|
|
133
|
+
* section-scan rebuild loop. Full per-field tokenization is handled by
|
|
134
|
+
* `kb-worker.wasm` orchestration; this function provides the read-pass
|
|
135
|
+
* scaffolding and the final index write.
|
|
136
|
+
*/
|
|
137
|
+
export function db_rebuild_index(_ptr: number, _len: number): number;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Removes a document manifest. `ptr`/`len` point to a UTF-8 docid string.
|
|
141
|
+
*/
|
|
142
|
+
export function db_remove_document(ptr: number, len: number): number;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Removes a section's entries from the indexes.
|
|
146
|
+
* `ptr`/`len` point to a UTF-8 kbid string.
|
|
147
|
+
*/
|
|
148
|
+
export function db_remove_from_index(ptr: number, len: number): number;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Removes a section by kbid. `ptr`/`len` point to a UTF-8 kbid string.
|
|
152
|
+
*/
|
|
153
|
+
export function db_remove_section(ptr: number, len: number): number;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Updates a section. `ptr`/`len` point to encoded (old_kbid_str, AddSectionParams).
|
|
157
|
+
*/
|
|
158
|
+
export function db_update_section(ptr: number, len: number): number;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Writes/updates the catalog. `ptr`/`len` point to encoded catalog TOML text.
|
|
162
|
+
*/
|
|
163
|
+
export function db_write_catalog(ptr: number, len: number): number;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Writes corpus statistics to `<ctx>/corpus.bin`.
|
|
167
|
+
* `ptr`/`len` point to 12 bytes of encoded `CorpusStats`.
|
|
168
|
+
*/
|
|
169
|
+
export function db_write_corpus_stats(ptr: number, len: number): number;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Writes a document manifest. `ptr`/`len` point to an encoded `DocumentManifest`.
|
|
173
|
+
*/
|
|
174
|
+
export function db_write_document(ptr: number, len: number): number;
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
declare type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
178
|
+
|
|
179
|
+
declare interface InitOutput {
|
|
180
|
+
readonly memory: WebAssembly.Memory;
|
|
181
|
+
readonly set_return: (a: number, b: number) => void;
|
|
182
|
+
readonly kbdb_free: (a: number, b: number) => void;
|
|
183
|
+
readonly db_add_section: (a: number, b: number) => number;
|
|
184
|
+
readonly db_add_to_index: (a: number, b: number) => number;
|
|
185
|
+
readonly db_check_integrity: (a: number, b: number) => number;
|
|
186
|
+
readonly db_check_version: (a: number, b: number) => number;
|
|
187
|
+
readonly db_gc: (a: number, b: number) => number;
|
|
188
|
+
readonly db_init: (a: number, b: number) => number;
|
|
189
|
+
readonly db_init_catalog: (a: number, b: number) => number;
|
|
190
|
+
readonly db_init_directory: (a: number, b: number) => number;
|
|
191
|
+
readonly db_list_documents: (a: number, b: number) => number;
|
|
192
|
+
readonly db_list_sections: (a: number, b: number) => number;
|
|
193
|
+
readonly db_query: (a: number, b: number) => number;
|
|
194
|
+
readonly db_read_catalog: (a: number, b: number) => number;
|
|
195
|
+
readonly db_read_corpus_stats: (a: number, b: number) => number;
|
|
196
|
+
readonly db_read_document: (a: number, b: number) => number;
|
|
197
|
+
readonly db_read_section: (a: number, b: number) => number;
|
|
198
|
+
readonly db_read_sections: (a: number, b: number) => number;
|
|
199
|
+
readonly db_rebuild_index: (a: number, b: number) => number;
|
|
200
|
+
readonly db_remove_document: (a: number, b: number) => number;
|
|
201
|
+
readonly db_remove_from_index: (a: number, b: number) => number;
|
|
202
|
+
readonly db_remove_section: (a: number, b: number) => number;
|
|
203
|
+
readonly db_update_section: (a: number, b: number) => number;
|
|
204
|
+
readonly db_write_catalog: (a: number, b: number) => number;
|
|
205
|
+
readonly db_write_corpus_stats: (a: number, b: number) => number;
|
|
206
|
+
readonly db_write_document: (a: number, b: number) => number;
|
|
207
|
+
readonly kbdb_alloc: (a: number) => number;
|
|
208
|
+
readonly get_return_len: () => number;
|
|
209
|
+
readonly get_return_ptr: () => number;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
214
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
215
|
+
*
|
|
216
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
217
|
+
*
|
|
218
|
+
* @returns {Promise<InitOutput>}
|
|
219
|
+
*/
|
|
220
|
+
declare function wasm_bindgen (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|