@dikolab/kbdb 0.1.2 → 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.
Files changed (41) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/cli.cjs.map +1 -1
  3. package/dist/cli.mjs +1 -1
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/mod.cjs +1 -1
  6. package/dist/mod.cjs.map +1 -1
  7. package/dist/mod.mjs +1 -1
  8. package/dist/mod.mjs.map +1 -1
  9. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  10. package/dist/wasm/fs-database/kbdb_fs_database.d.ts +220 -0
  11. package/dist/wasm/fs-database/kbdb_fs_database.js +458 -0
  12. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  13. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +32 -0
  14. package/dist/wasm/fs-database/package.json +13 -0
  15. package/dist/wasm/kb-worker/kbdb_worker.d.ts +565 -0
  16. package/dist/wasm/kb-worker/kbdb_worker.js +1066 -0
  17. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  18. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +72 -0
  19. package/dist/wasm/kb-worker/package.json +13 -0
  20. package/dist/wasm/query-parser/kbdb_query_parser.d.ts +195 -0
  21. package/dist/wasm/query-parser/kbdb_query_parser.js +403 -0
  22. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  23. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm.d.ts +25 -0
  24. package/dist/wasm/query-parser/package.json +13 -0
  25. package/package.json +1 -1
  26. package/src/shared/version/constants/version.constant.ts +1 -1
  27. package/src/wasm/fs-database/kbdb_fs_database.d.ts +220 -0
  28. package/src/wasm/fs-database/kbdb_fs_database.js +458 -0
  29. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  30. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +32 -0
  31. package/src/wasm/fs-database/package.json +13 -0
  32. package/src/wasm/kb-worker/kbdb_worker.d.ts +565 -0
  33. package/src/wasm/kb-worker/kbdb_worker.js +1066 -0
  34. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  35. package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +72 -0
  36. package/src/wasm/kb-worker/package.json +13 -0
  37. package/src/wasm/query-parser/kbdb_query_parser.d.ts +195 -0
  38. package/src/wasm/query-parser/kbdb_query_parser.js +403 -0
  39. package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  40. package/src/wasm/query-parser/kbdb_query_parser_bg.wasm.d.ts +25 -0
  41. package/src/wasm/query-parser/package.json +13 -0
@@ -0,0 +1,1066 @@
1
+ let wasm_bindgen = (function(exports) {
2
+ let script_src;
3
+ if (typeof document !== 'undefined' && document.currentScript !== null) {
4
+ script_src = new URL(document.currentScript.src, location.href).toString();
5
+ }
6
+
7
+ /**
8
+ * Adds a section. `ptr`/`len` point to an encoded `AddSectionParams`.
9
+ *
10
+ * On success: writes encoded kbid string to return slot, returns 0.
11
+ * On error: writes error message to return slot, returns -1.
12
+ * @param {number} ptr
13
+ * @param {number} len
14
+ * @returns {number}
15
+ */
16
+ function db_add_section(ptr, len) {
17
+ const ret = wasm.db_add_section(ptr, len);
18
+ return ret;
19
+ }
20
+ exports.db_add_section = db_add_section;
21
+
22
+ /**
23
+ * Adds a section's terms to the inverted and positional indexes.
24
+ * `ptr`/`len` point to encoded
25
+ * (kbid_str, term_count, [(term_str, pos_count, [positions], heading_tf, body_tf, code_tf)]).
26
+ * @param {number} ptr
27
+ * @param {number} len
28
+ * @returns {number}
29
+ */
30
+ function db_add_to_index(ptr, len) {
31
+ const ret = wasm.db_add_to_index(ptr, len);
32
+ return ret;
33
+ }
34
+ exports.db_add_to_index = db_add_to_index;
35
+
36
+ /**
37
+ * Checks database integrity. Returns 0 on success.
38
+ * On success a summary string is placed in the return slot.
39
+ * @param {number} _ptr
40
+ * @param {number} _len
41
+ * @returns {number}
42
+ */
43
+ function db_check_integrity(_ptr, _len) {
44
+ const ret = wasm.db_check_integrity(_ptr, _len);
45
+ return ret;
46
+ }
47
+ exports.db_check_integrity = db_check_integrity;
48
+
49
+ /**
50
+ * Reads `catalog.toml` from the path at `ptr`/`len` and returns the version
51
+ * status without modifying state.
52
+ *
53
+ * On success, the return slot contains 8 bytes:
54
+ * - bytes 0-3: `catalog_version` as little-endian u32
55
+ * - bytes 4-7: `required_version` (DB_FORMAT_VERSION) as little-endian u32
56
+ *
57
+ * Return value:
58
+ * - 0: compatible (versions match)
59
+ * - 1: needs migration (catalog version < required)
60
+ * - 2: too new (catalog version > required)
61
+ * - -1: I/O or parse error (message in return slot)
62
+ *
63
+ * Note: this export accepts a path directly and does NOT require `db_init`
64
+ * to have been called first.
65
+ * @param {number} ptr
66
+ * @param {number} len
67
+ * @returns {number}
68
+ */
69
+ function db_check_version(ptr, len) {
70
+ const ret = wasm.db_check_version(ptr, len);
71
+ return ret;
72
+ }
73
+ exports.db_check_version = db_check_version;
74
+
75
+ /**
76
+ * Runs garbage collection. Returns 0 on success.
77
+ * On success a summary string is placed in the return slot.
78
+ * @param {number} _ptr
79
+ * @param {number} _len
80
+ * @returns {number}
81
+ */
82
+ function db_gc(_ptr, _len) {
83
+ const ret = wasm.db_gc(_ptr, _len);
84
+ return ret;
85
+ }
86
+ exports.db_gc = db_gc;
87
+
88
+ /**
89
+ * Initialises the database context path.
90
+ *
91
+ * The JS host must call this before any other function.
92
+ * `ptr`/`len` point to a UTF-8 context path string in WASM memory.
93
+ * @param {number} ptr
94
+ * @param {number} len
95
+ * @returns {number}
96
+ */
97
+ function db_init(ptr, len) {
98
+ const ret = wasm.db_init(ptr, len);
99
+ return ret;
100
+ }
101
+ exports.db_init = db_init;
102
+
103
+ /**
104
+ * Initialises a new empty catalog at the current context path.
105
+ * Writes the default catalog to disk and returns 0 on success.
106
+ * @param {number} _ptr
107
+ * @param {number} _len
108
+ * @returns {number}
109
+ */
110
+ function db_init_catalog(_ptr, _len) {
111
+ const ret = wasm.db_init_catalog(_ptr, _len);
112
+ return ret;
113
+ }
114
+ exports.db_init_catalog = db_init_catalog;
115
+
116
+ /**
117
+ * Creates the full directory scaffold for a new database at `ptr`/`len` path.
118
+ *
119
+ * Creates directories, seeds `catalog.toml` (stamped with `DB_FORMAT_VERSION`),
120
+ * empty index files, `worker.toml`, and `.gitignore`.
121
+ *
122
+ * Returns 0 on success. Returns -1 with an error message in the return slot
123
+ * if the directory already exists or any I/O fails.
124
+ *
125
+ * Note: this export accepts a path directly and does NOT require `db_init`
126
+ * to have been called first.
127
+ * @param {number} ptr
128
+ * @param {number} len
129
+ * @returns {number}
130
+ */
131
+ function db_init_directory(ptr, len) {
132
+ const ret = wasm.db_init_directory(ptr, len);
133
+ return ret;
134
+ }
135
+ exports.db_init_directory = db_init_directory;
136
+
137
+ /**
138
+ * Lists all document manifests. No input parameters (`ptr`/`len` are ignored).
139
+ *
140
+ * On success encodes a `u32 count` followed by each `DocumentManifest` into
141
+ * the return slot and returns 0. On error writes an error message and returns -1.
142
+ * @param {number} _ptr
143
+ * @param {number} _len
144
+ * @returns {number}
145
+ */
146
+ function db_list_documents(_ptr, _len) {
147
+ const ret = wasm.db_list_documents(_ptr, _len);
148
+ return ret;
149
+ }
150
+ exports.db_list_documents = db_list_documents;
151
+
152
+ /**
153
+ * Lists all section records. No input parameters (`ptr`/`len` are ignored).
154
+ *
155
+ * On success encodes a `u32 count` followed by each `SectionRecord` into the
156
+ * return slot and returns 0. On error writes an error message and returns -1.
157
+ * @param {number} _ptr
158
+ * @param {number} _len
159
+ * @returns {number}
160
+ */
161
+ function db_list_sections(_ptr, _len) {
162
+ const ret = wasm.db_list_sections(_ptr, _len);
163
+ return ret;
164
+ }
165
+ exports.db_list_sections = db_list_sections;
166
+
167
+ /**
168
+ * Executes a query plan against the loaded indexes.
169
+ * `ptr`/`len` point to an encoded `QueryPlan`.
170
+ * On success writes encoded `Vec<RawMatch>` to the return slot.
171
+ * @param {number} ptr
172
+ * @param {number} len
173
+ * @returns {number}
174
+ */
175
+ function db_query(ptr, len) {
176
+ const ret = wasm.db_query(ptr, len);
177
+ return ret;
178
+ }
179
+ exports.db_query = db_query;
180
+
181
+ /**
182
+ * Reads the catalog. Returns 0 on success.
183
+ * On success the serialised catalog TOML text is in the return slot.
184
+ * @param {number} _ptr
185
+ * @param {number} _len
186
+ * @returns {number}
187
+ */
188
+ function db_read_catalog(_ptr, _len) {
189
+ const ret = wasm.db_read_catalog(_ptr, _len);
190
+ return ret;
191
+ }
192
+ exports.db_read_catalog = db_read_catalog;
193
+
194
+ /**
195
+ * Reads corpus statistics from `<ctx>/corpus.bin`.
196
+ * On success places encoded `CorpusStats` bytes in the return slot.
197
+ * @param {number} _ptr
198
+ * @param {number} _len
199
+ * @returns {number}
200
+ */
201
+ function db_read_corpus_stats(_ptr, _len) {
202
+ const ret = wasm.db_read_corpus_stats(_ptr, _len);
203
+ return ret;
204
+ }
205
+ exports.db_read_corpus_stats = db_read_corpus_stats;
206
+
207
+ /**
208
+ * Reads a document manifest. `ptr`/`len` point to a UTF-8 docid string.
209
+ * @param {number} ptr
210
+ * @param {number} len
211
+ * @returns {number}
212
+ */
213
+ function db_read_document(ptr, len) {
214
+ const ret = wasm.db_read_document(ptr, len);
215
+ return ret;
216
+ }
217
+ exports.db_read_document = db_read_document;
218
+
219
+ /**
220
+ * Reads a section by kbid. `ptr`/`len` point to a UTF-8 kbid string.
221
+ * @param {number} ptr
222
+ * @param {number} len
223
+ * @returns {number}
224
+ */
225
+ function db_read_section(ptr, len) {
226
+ const ret = wasm.db_read_section(ptr, len);
227
+ return ret;
228
+ }
229
+ exports.db_read_section = db_read_section;
230
+
231
+ /**
232
+ * Reads multiple sections. `ptr`/`len` point to encoded `Vec<KbId>` (count + kbids).
233
+ * @param {number} ptr
234
+ * @param {number} len
235
+ * @returns {number}
236
+ */
237
+ function db_read_sections(ptr, len) {
238
+ const ret = wasm.db_read_sections(ptr, len);
239
+ return ret;
240
+ }
241
+ exports.db_read_sections = db_read_sections;
242
+
243
+ /**
244
+ * Rebuilds indexes from scratch.
245
+ *
246
+ * Clears the existing inverted and positional indexes, then drives the
247
+ * section-scan rebuild loop. Full per-field tokenization is handled by
248
+ * `kb-worker.wasm` orchestration; this function provides the read-pass
249
+ * scaffolding and the final index write.
250
+ * @param {number} _ptr
251
+ * @param {number} _len
252
+ * @returns {number}
253
+ */
254
+ function db_rebuild_index(_ptr, _len) {
255
+ const ret = wasm.db_rebuild_index(_ptr, _len);
256
+ return ret;
257
+ }
258
+ exports.db_rebuild_index = db_rebuild_index;
259
+
260
+ /**
261
+ * Removes a document manifest. `ptr`/`len` point to a UTF-8 docid string.
262
+ * @param {number} ptr
263
+ * @param {number} len
264
+ * @returns {number}
265
+ */
266
+ function db_remove_document(ptr, len) {
267
+ const ret = wasm.db_remove_document(ptr, len);
268
+ return ret;
269
+ }
270
+ exports.db_remove_document = db_remove_document;
271
+
272
+ /**
273
+ * Removes a section's entries from the indexes.
274
+ * `ptr`/`len` point to a UTF-8 kbid string.
275
+ * @param {number} ptr
276
+ * @param {number} len
277
+ * @returns {number}
278
+ */
279
+ function db_remove_from_index(ptr, len) {
280
+ const ret = wasm.db_remove_from_index(ptr, len);
281
+ return ret;
282
+ }
283
+ exports.db_remove_from_index = db_remove_from_index;
284
+
285
+ /**
286
+ * Removes a section by kbid. `ptr`/`len` point to a UTF-8 kbid string.
287
+ * @param {number} ptr
288
+ * @param {number} len
289
+ * @returns {number}
290
+ */
291
+ function db_remove_section(ptr, len) {
292
+ const ret = wasm.db_remove_section(ptr, len);
293
+ return ret;
294
+ }
295
+ exports.db_remove_section = db_remove_section;
296
+
297
+ /**
298
+ * Updates a section. `ptr`/`len` point to encoded (old_kbid_str, AddSectionParams).
299
+ * @param {number} ptr
300
+ * @param {number} len
301
+ * @returns {number}
302
+ */
303
+ function db_update_section(ptr, len) {
304
+ const ret = wasm.db_update_section(ptr, len);
305
+ return ret;
306
+ }
307
+ exports.db_update_section = db_update_section;
308
+
309
+ /**
310
+ * Writes/updates the catalog. `ptr`/`len` point to encoded catalog TOML text.
311
+ * @param {number} ptr
312
+ * @param {number} len
313
+ * @returns {number}
314
+ */
315
+ function db_write_catalog(ptr, len) {
316
+ const ret = wasm.db_write_catalog(ptr, len);
317
+ return ret;
318
+ }
319
+ exports.db_write_catalog = db_write_catalog;
320
+
321
+ /**
322
+ * Writes corpus statistics to `<ctx>/corpus.bin`.
323
+ * `ptr`/`len` point to 12 bytes of encoded `CorpusStats`.
324
+ * @param {number} ptr
325
+ * @param {number} len
326
+ * @returns {number}
327
+ */
328
+ function db_write_corpus_stats(ptr, len) {
329
+ const ret = wasm.db_write_corpus_stats(ptr, len);
330
+ return ret;
331
+ }
332
+ exports.db_write_corpus_stats = db_write_corpus_stats;
333
+
334
+ /**
335
+ * Writes a document manifest. `ptr`/`len` point to an encoded `DocumentManifest`.
336
+ * @param {number} ptr
337
+ * @param {number} len
338
+ * @returns {number}
339
+ */
340
+ function db_write_document(ptr, len) {
341
+ const ret = wasm.db_write_document(ptr, len);
342
+ return ret;
343
+ }
344
+ exports.db_write_document = db_write_document;
345
+
346
+ /**
347
+ * Clear all entries from the query cache. Returns 1 always.
348
+ * @returns {number}
349
+ */
350
+ function qp_cache_clear() {
351
+ const ret = wasm.qp_cache_clear();
352
+ return ret >>> 0;
353
+ }
354
+ exports.qp_cache_clear = qp_cache_clear;
355
+
356
+ /**
357
+ * Retrieve the bytes cached under the UTF-8 key at `(ptr, len)`.
358
+ *
359
+ * On hit: writes the bytes via `set_return` and returns 1.
360
+ * On miss: calls `set_return(null, 0)` and returns 0.
361
+ * @param {number} ptr
362
+ * @param {number} len
363
+ * @returns {number}
364
+ */
365
+ function qp_cache_get(ptr, len) {
366
+ const ret = wasm.qp_cache_get(ptr, len);
367
+ return ret >>> 0;
368
+ }
369
+ exports.qp_cache_get = qp_cache_get;
370
+
371
+ /**
372
+ * Cache the bytes at `(val_ptr, val_len)` under the UTF-8 key at
373
+ * `(key_ptr, key_len)`. Returns 1 always.
374
+ * @param {number} key_ptr
375
+ * @param {number} key_len
376
+ * @param {number} val_ptr
377
+ * @param {number} val_len
378
+ * @returns {number}
379
+ */
380
+ function qp_cache_insert(key_ptr, key_len, val_ptr, val_len) {
381
+ const ret = wasm.qp_cache_insert(key_ptr, key_len, val_ptr, val_len);
382
+ return ret >>> 0;
383
+ }
384
+ exports.qp_cache_insert = qp_cache_insert;
385
+
386
+ /**
387
+ * Compute per-field TF values from raw field occurrence and token counts.
388
+ *
389
+ * The buffer at `(ptr, len)` contains:
390
+ * - u32 heading_count, u32 body_count, u32 code_count
391
+ * - u32 heading_tokens, u32 body_tokens, u32 code_tokens
392
+ *
393
+ * The result is 3 × f32 (heading_tf, body_tf, code_tf) written via
394
+ * `set_return`. Returns 1 on success, 0 if buffer is too short.
395
+ * @param {number} ptr
396
+ * @param {number} len
397
+ * @returns {number}
398
+ */
399
+ function qp_compute_field_tf(ptr, len) {
400
+ const ret = wasm.qp_compute_field_tf(ptr, len);
401
+ return ret >>> 0;
402
+ }
403
+ exports.qp_compute_field_tf = qp_compute_field_tf;
404
+
405
+ /**
406
+ * Compute TF-IDF for a term.
407
+ *
408
+ * The buffer at `(ptr, len)` contains:
409
+ * - u32 term_count (occurrences in document)
410
+ * - u32 total_terms (all terms in document)
411
+ * - u32 doc_freq (documents containing the term)
412
+ * - u32 total_docs (documents in corpus)
413
+ *
414
+ * The result is a single f32 TF-IDF score written via `set_return`.
415
+ * Returns 1 on success, 0 if the buffer is too short.
416
+ * @param {number} ptr
417
+ * @param {number} len
418
+ * @returns {number}
419
+ */
420
+ function qp_compute_tfidf(ptr, len) {
421
+ const ret = wasm.qp_compute_tfidf(ptr, len);
422
+ return ret >>> 0;
423
+ }
424
+ exports.qp_compute_tfidf = qp_compute_tfidf;
425
+
426
+ /**
427
+ * Extract keyphrases from the UTF-8 text at `(ptr, len)`.
428
+ *
429
+ * `n_top` — maximum number of keyphrases to return.
430
+ *
431
+ * Encodes result as:
432
+ * - u32 count
433
+ * - for each keyphrase: String phrase, f32 score
434
+ *
435
+ * Returns 1 on success, 0 on error.
436
+ * @param {number} ptr
437
+ * @param {number} len
438
+ * @param {number} n_top
439
+ * @returns {number}
440
+ */
441
+ function qp_extract_keyphrases(ptr, len, n_top) {
442
+ const ret = wasm.qp_extract_keyphrases(ptr, len, n_top);
443
+ return ret >>> 0;
444
+ }
445
+ exports.qp_extract_keyphrases = qp_extract_keyphrases;
446
+
447
+ /**
448
+ * Extract bigrams and trigrams from the token stream of the text at
449
+ * `(ptr, len)`.
450
+ *
451
+ * Encodes the result as:
452
+ * - u32 bigram count, then each bigram as a String
453
+ * - u32 trigram count, then each trigram as a String
454
+ *
455
+ * Returns 1 on success.
456
+ * @param {number} ptr
457
+ * @param {number} len
458
+ * @returns {number}
459
+ */
460
+ function qp_extract_ngrams(ptr, len) {
461
+ const ret = wasm.qp_extract_ngrams(ptr, len);
462
+ return ret >>> 0;
463
+ }
464
+ exports.qp_extract_ngrams = qp_extract_ngrams;
465
+
466
+ /**
467
+ * Parse the UTF-8 query string at `(ptr, len)` into a `QueryPlan`.
468
+ *
469
+ * The result is encoded using `QueryPlan`'s `Encode` implementation.
470
+ * Returns 1 on success, 0 on parse error.
471
+ * @param {number} ptr
472
+ * @param {number} len
473
+ * @returns {number}
474
+ */
475
+ function qp_parse_query(ptr, len) {
476
+ const ret = wasm.qp_parse_query(ptr, len);
477
+ return ret >>> 0;
478
+ }
479
+ exports.qp_parse_query = qp_parse_query;
480
+
481
+ /**
482
+ * Compute BM25F score for all matched terms in a `RawMatch`.
483
+ *
484
+ * The buffer at `(ptr, len)` contains an encoded `RawMatch` followed
485
+ * immediately by an encoded `CorpusStats`. Default BM25F parameters are
486
+ * used (k1=1.2, b=0.75, heading=2.0, body=1.0, code=1.5).
487
+ *
488
+ * The result is a single f32 written via `set_return`.
489
+ * Returns 1 on success, 0 if the buffer cannot be decoded.
490
+ * @param {number} ptr
491
+ * @param {number} len
492
+ * @returns {number}
493
+ */
494
+ function qp_score_bm25f(ptr, len) {
495
+ const ret = wasm.qp_score_bm25f(ptr, len);
496
+ return ret >>> 0;
497
+ }
498
+ exports.qp_score_bm25f = qp_score_bm25f;
499
+
500
+ /**
501
+ * Compute BM25F score for a single term/field using explicit document frequency.
502
+ *
503
+ * Parameters are passed as a packed binary buffer at `(ptr, len)`:
504
+ * - f32 tf, u32 df, u32 total_docs, f32 avg_dl, f32 dl, f32 k1, f32 b
505
+ *
506
+ * The result is a single f32 written via `set_return`.
507
+ * Returns 1 on success, 0 if the buffer is too short.
508
+ * @param {number} ptr
509
+ * @param {number} len
510
+ * @returns {number}
511
+ */
512
+ function qp_score_bm25f_field(ptr, len) {
513
+ const ret = wasm.qp_score_bm25f_field(ptr, len);
514
+ return ret >>> 0;
515
+ }
516
+ exports.qp_score_bm25f_field = qp_score_bm25f_field;
517
+
518
+ /**
519
+ * Compute freshness weight.
520
+ *
521
+ * The buffer at `(ptr, len)` contains:
522
+ * - u64 created_at (ms)
523
+ * - u64 now (ms)
524
+ * - u64 half_life_ms
525
+ *
526
+ * Returns 1 on success, 0 if buffer is too short.
527
+ * @param {number} ptr
528
+ * @param {number} len
529
+ * @returns {number}
530
+ */
531
+ function qp_score_freshness(ptr, len) {
532
+ const ret = wasm.qp_score_freshness(ptr, len);
533
+ return ret >>> 0;
534
+ }
535
+ exports.qp_score_freshness = qp_score_freshness;
536
+
537
+ /**
538
+ * Compute a proximity score.
539
+ *
540
+ * The buffer at `(ptr, len)` contains:
541
+ * - u32 count of pairs
542
+ * - count × (u32 pos_a, u32 pos_b)
543
+ *
544
+ * Returns 1 on success, 0 on error.
545
+ * @param {number} ptr
546
+ * @param {number} len
547
+ * @returns {number}
548
+ */
549
+ function qp_score_proximity(ptr, len) {
550
+ const ret = wasm.qp_score_proximity(ptr, len);
551
+ return ret >>> 0;
552
+ }
553
+ exports.qp_score_proximity = qp_score_proximity;
554
+
555
+ /**
556
+ * Apply zone weighting.
557
+ *
558
+ * The buffer at `(ptr, len)` contains:
559
+ * - u8 is_heading (0/1)
560
+ * - u8 is_first_para (0/1)
561
+ * - f32 base_score
562
+ *
563
+ * Returns 1 on success, 0 if buffer is too short.
564
+ * @param {number} ptr
565
+ * @param {number} len
566
+ * @returns {number}
567
+ */
568
+ function qp_score_zone(ptr, len) {
569
+ const ret = wasm.qp_score_zone(ptr, len);
570
+ return ret >>> 0;
571
+ }
572
+ exports.qp_score_zone = qp_score_zone;
573
+
574
+ /**
575
+ * Tokenise the UTF-8 text at `(ptr, len)`.
576
+ *
577
+ * Encodes the result as a length-prefixed list of `(original, stemmed,
578
+ * position)` records using the shared binary encoding:
579
+ * - u32 count
580
+ * - for each token: String original, String stemmed, u32 position
581
+ *
582
+ * Returns 1 on success, 0 on error.
583
+ * @param {number} ptr
584
+ * @param {number} len
585
+ * @returns {number}
586
+ */
587
+ function qp_tokenize(ptr, len) {
588
+ const ret = wasm.qp_tokenize(ptr, len);
589
+ return ret >>> 0;
590
+ }
591
+ exports.qp_tokenize = qp_tokenize;
592
+
593
+ /**
594
+ * Return the crate version string.
595
+ * @returns {string}
596
+ */
597
+ function version() {
598
+ let deferred1_0;
599
+ let deferred1_1;
600
+ try {
601
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
602
+ wasm.version(retptr);
603
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
604
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
605
+ deferred1_0 = r0;
606
+ deferred1_1 = r1;
607
+ return getStringFromWasm0(r0, r1);
608
+ } finally {
609
+ wasm.__wbindgen_add_to_stack_pointer(16);
610
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
611
+ }
612
+ }
613
+ exports.version = version;
614
+
615
+ /**
616
+ * Adds a section. Returns 0 on success, -1 on error.
617
+ * @param {number} ptr
618
+ * @param {number} len
619
+ * @returns {number}
620
+ */
621
+ function worker_add_section(ptr, len) {
622
+ const ret = wasm.worker_add_section(ptr, len);
623
+ return ret;
624
+ }
625
+ exports.worker_add_section = worker_add_section;
626
+
627
+ /**
628
+ * Runs a database integrity check.
629
+ * @returns {number}
630
+ */
631
+ function worker_check_integrity() {
632
+ const ret = wasm.worker_check_integrity();
633
+ return ret;
634
+ }
635
+ exports.worker_check_integrity = worker_check_integrity;
636
+
637
+ /**
638
+ * Composes a Markdown document from an ordered list of identifiers.
639
+ *
640
+ * The identifier list is encoded as `u32 count + String` entries in shared
641
+ * memory at `(ptr, len)`. Each identifier is tried first as a kbid (section),
642
+ * then as a docid (document). Missing identifiers are silently skipped.
643
+ *
644
+ * On success the composed markdown and total character count are encoded into
645
+ * the return slot (String markdown + u64 total_chars), and 0 is returned.
646
+ * On error -1 is returned and an error message is in the return slot.
647
+ * @param {number} ptr
648
+ * @param {number} len
649
+ * @returns {number}
650
+ */
651
+ function worker_compose(ptr, len) {
652
+ const ret = wasm.worker_compose(ptr, len);
653
+ return ret;
654
+ }
655
+ exports.worker_compose = worker_compose;
656
+
657
+ /**
658
+ * Runs garbage collection and invalidates all cache entries.
659
+ *
660
+ * After GC the set of valid sections may have changed; the whole cache is
661
+ * invalidated to prevent stale reads.
662
+ * @returns {number}
663
+ */
664
+ function worker_garbage_collect() {
665
+ const ret = wasm.worker_garbage_collect();
666
+ return ret;
667
+ }
668
+ exports.worker_garbage_collect = worker_garbage_collect;
669
+
670
+ /**
671
+ * Retrieves and removes the result for `token`.
672
+ *
673
+ * Result bytes are written to the return slot. Returns 0 on success, -1 if
674
+ * the token is not found or has an error.
675
+ * @param {number} token
676
+ * @returns {number}
677
+ */
678
+ function worker_get_result(token) {
679
+ const ret = wasm.worker_get_result(token);
680
+ return ret;
681
+ }
682
+ exports.worker_get_result = worker_get_result;
683
+
684
+ /**
685
+ * Creates a document grouping. Returns 0 on success, -1 on error.
686
+ * @param {number} ptr
687
+ * @param {number} len
688
+ * @returns {number}
689
+ */
690
+ function worker_group_sections(ptr, len) {
691
+ const ret = wasm.worker_group_sections(ptr, len);
692
+ return ret;
693
+ }
694
+ exports.worker_group_sections = worker_group_sections;
695
+
696
+ /**
697
+ * Initialises the worker context from an encoded config in shared memory.
698
+ *
699
+ * Format: UTF-8 context path string (the rest of the config uses defaults).
700
+ *
701
+ * Returns 0 on success, -1 on error (error message in return slot).
702
+ * @param {number} ptr
703
+ * @param {number} len
704
+ * @returns {number}
705
+ */
706
+ function worker_init(ptr, len) {
707
+ const ret = wasm.worker_init(ptr, len);
708
+ return ret;
709
+ }
710
+ exports.worker_init = worker_init;
711
+
712
+ /**
713
+ * Creates the full directory scaffold for a new database at `ptr`/`len` path.
714
+ *
715
+ * Delegates to `db_init_directory` in `kbdb-fs-database`. Does not require
716
+ * `worker_init` to have been called first.
717
+ *
718
+ * Returns 0 on success, -1 on error (message in return slot).
719
+ * @param {number} ptr
720
+ * @param {number} len
721
+ * @returns {number}
722
+ */
723
+ function worker_init_directory(ptr, len) {
724
+ const ret = wasm.worker_init_directory(ptr, len);
725
+ return ret;
726
+ }
727
+ exports.worker_init_directory = worker_init_directory;
728
+
729
+ /**
730
+ * Invalidates the cache entry for the kbid at `(ptr, len)`.
731
+ * @param {number} ptr
732
+ * @param {number} len
733
+ * @returns {number}
734
+ */
735
+ function worker_invalidate(ptr, len) {
736
+ const ret = wasm.worker_invalidate(ptr, len);
737
+ return ret;
738
+ }
739
+ exports.worker_invalidate = worker_invalidate;
740
+
741
+ /**
742
+ * Clears all cache entries.
743
+ * @returns {number}
744
+ */
745
+ function worker_invalidate_all() {
746
+ const ret = wasm.worker_invalidate_all();
747
+ return ret;
748
+ }
749
+ exports.worker_invalidate_all = worker_invalidate_all;
750
+
751
+ /**
752
+ * Lists all sections whose `type_name` matches the UTF-8 string at `(ptr, len)`.
753
+ *
754
+ * On success encodes `u32 count + SectionRecord[]` into the return slot and
755
+ * returns 0. On error writes an error message and returns -1.
756
+ * @param {number} ptr
757
+ * @param {number} len
758
+ * @returns {number}
759
+ */
760
+ function worker_list_by_type(ptr, len) {
761
+ const ret = wasm.worker_list_by_type(ptr, len);
762
+ return ret;
763
+ }
764
+ exports.worker_list_by_type = worker_list_by_type;
765
+
766
+ /**
767
+ * Lists all document manifests whose `doc_type` matches the UTF-8 string at
768
+ * `(ptr, len)`.
769
+ *
770
+ * On success encodes `u32 count + DocumentManifest[]` into the return slot and
771
+ * returns 0. On error writes an error message and returns -1.
772
+ * @param {number} ptr
773
+ * @param {number} len
774
+ * @returns {number}
775
+ */
776
+ function worker_list_docs_by_type(ptr, len) {
777
+ const ret = wasm.worker_list_docs_by_type(ptr, len);
778
+ return ret;
779
+ }
780
+ exports.worker_list_docs_by_type = worker_list_docs_by_type;
781
+
782
+ /**
783
+ * Async query returning a token. The result can be polled via `worker_result_status`.
784
+ * @param {number} ptr
785
+ * @param {number} len
786
+ * @returns {number}
787
+ */
788
+ function worker_query(ptr, len) {
789
+ const ret = wasm.worker_query(ptr, len);
790
+ return ret >>> 0;
791
+ }
792
+ exports.worker_query = worker_query;
793
+
794
+ /**
795
+ * Reads sections by kbid list. Returns 0 on success, -1 on error.
796
+ * @param {number} ptr
797
+ * @param {number} len
798
+ * @returns {number}
799
+ */
800
+ function worker_read_sections(ptr, len) {
801
+ const ret = wasm.worker_read_sections(ptr, len);
802
+ return ret;
803
+ }
804
+ exports.worker_read_sections = worker_read_sections;
805
+
806
+ /**
807
+ * Rebuilds all database indexes.
808
+ * @returns {number}
809
+ */
810
+ function worker_rebuild_indexes() {
811
+ const ret = wasm.worker_rebuild_indexes();
812
+ return ret;
813
+ }
814
+ exports.worker_rebuild_indexes = worker_rebuild_indexes;
815
+
816
+ /**
817
+ * Removes a document grouping. Returns 0 on success, -1 on error.
818
+ * @param {number} ptr
819
+ * @param {number} len
820
+ * @returns {number}
821
+ */
822
+ function worker_remove_grouping(ptr, len) {
823
+ const ret = wasm.worker_remove_grouping(ptr, len);
824
+ return ret;
825
+ }
826
+ exports.worker_remove_grouping = worker_remove_grouping;
827
+
828
+ /**
829
+ * Removes a section. Returns 0 on success, -1 on error.
830
+ * @param {number} ptr
831
+ * @param {number} len
832
+ * @returns {number}
833
+ */
834
+ function worker_remove_section(ptr, len) {
835
+ const ret = wasm.worker_remove_section(ptr, len);
836
+ return ret;
837
+ }
838
+ exports.worker_remove_section = worker_remove_section;
839
+
840
+ /**
841
+ * Returns a numeric status code for a token:
842
+ * - 0 = unknown token
843
+ * - 1 = pending
844
+ * - 2 = ready
845
+ * - 3 = error
846
+ * @param {number} token
847
+ * @returns {number}
848
+ */
849
+ function worker_result_status(token) {
850
+ const ret = wasm.worker_result_status(token);
851
+ return ret >>> 0;
852
+ }
853
+ exports.worker_result_status = worker_result_status;
854
+
855
+ /**
856
+ * Reads a document manifest. Returns 0 on success, -1 on error.
857
+ * @param {number} ptr
858
+ * @param {number} len
859
+ * @returns {number}
860
+ */
861
+ function worker_retrieve_doc(ptr, len) {
862
+ const ret = wasm.worker_retrieve_doc(ptr, len);
863
+ return ret;
864
+ }
865
+ exports.worker_retrieve_doc = worker_retrieve_doc;
866
+
867
+ /**
868
+ * Performs a search, returning an async result token.
869
+ * @param {number} ptr
870
+ * @param {number} len
871
+ * @returns {number}
872
+ */
873
+ function worker_search(ptr, len) {
874
+ const ret = wasm.worker_search(ptr, len);
875
+ return ret >>> 0;
876
+ }
877
+ exports.worker_search = worker_search;
878
+
879
+ /**
880
+ * Returns worker status. Always returns 0.
881
+ *
882
+ * As a side effect, evicts any expired cache entries using the
883
+ * configured TTL. The status string is written to the return slot.
884
+ * @returns {number}
885
+ */
886
+ function worker_status() {
887
+ const ret = wasm.worker_status();
888
+ return ret;
889
+ }
890
+ exports.worker_status = worker_status;
891
+
892
+ /**
893
+ * Updates a section. Returns 0 on success, -1 on error.
894
+ * @param {number} ptr
895
+ * @param {number} len
896
+ * @returns {number}
897
+ */
898
+ function worker_update_section(ptr, len) {
899
+ const ret = wasm.worker_update_section(ptr, len);
900
+ return ret;
901
+ }
902
+ exports.worker_update_section = worker_update_section;
903
+
904
+ /**
905
+ * Crate version.
906
+ * @returns {string}
907
+ */
908
+ function worker_version() {
909
+ let deferred1_0;
910
+ let deferred1_1;
911
+ try {
912
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
913
+ wasm.worker_version(retptr);
914
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
915
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
916
+ deferred1_0 = r0;
917
+ deferred1_1 = r1;
918
+ return getStringFromWasm0(r0, r1);
919
+ } finally {
920
+ wasm.__wbindgen_add_to_stack_pointer(16);
921
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
922
+ }
923
+ }
924
+ exports.worker_version = worker_version;
925
+ const import1 = require("env");
926
+ const import2 = require("env");
927
+ const import3 = require("env");
928
+ const import4 = require("env");
929
+ const import5 = require("env");
930
+ const import6 = require("env");
931
+
932
+ function __wbg_get_imports() {
933
+ const import0 = {
934
+ __proto__: null,
935
+ };
936
+ return {
937
+ __proto__: null,
938
+ "./kbdb_worker_bg.js": import0,
939
+ "env": import1,
940
+ "env": import2,
941
+ "env": import3,
942
+ "env": import4,
943
+ "env": import5,
944
+ "env": import6,
945
+ };
946
+ }
947
+
948
+ let cachedDataViewMemory0 = null;
949
+ function getDataViewMemory0() {
950
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
951
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
952
+ }
953
+ return cachedDataViewMemory0;
954
+ }
955
+
956
+ function getStringFromWasm0(ptr, len) {
957
+ return decodeText(ptr >>> 0, len);
958
+ }
959
+
960
+ let cachedUint8ArrayMemory0 = null;
961
+ function getUint8ArrayMemory0() {
962
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
963
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
964
+ }
965
+ return cachedUint8ArrayMemory0;
966
+ }
967
+
968
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
969
+ cachedTextDecoder.decode();
970
+ function decodeText(ptr, len) {
971
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
972
+ }
973
+
974
+ let wasmModule, wasmInstance, wasm;
975
+ function __wbg_finalize_init(instance, module) {
976
+ wasmInstance = instance;
977
+ wasm = instance.exports;
978
+ wasmModule = module;
979
+ cachedDataViewMemory0 = null;
980
+ cachedUint8ArrayMemory0 = null;
981
+ return wasm;
982
+ }
983
+
984
+ async function __wbg_load(module, imports) {
985
+ if (typeof Response === 'function' && module instanceof Response) {
986
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
987
+ try {
988
+ return await WebAssembly.instantiateStreaming(module, imports);
989
+ } catch (e) {
990
+ const validResponse = module.ok && expectedResponseType(module.type);
991
+
992
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
993
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
994
+
995
+ } else { throw e; }
996
+ }
997
+ }
998
+
999
+ const bytes = await module.arrayBuffer();
1000
+ return await WebAssembly.instantiate(bytes, imports);
1001
+ } else {
1002
+ const instance = await WebAssembly.instantiate(module, imports);
1003
+
1004
+ if (instance instanceof WebAssembly.Instance) {
1005
+ return { instance, module };
1006
+ } else {
1007
+ return instance;
1008
+ }
1009
+ }
1010
+
1011
+ function expectedResponseType(type) {
1012
+ switch (type) {
1013
+ case 'basic': case 'cors': case 'default': return true;
1014
+ }
1015
+ return false;
1016
+ }
1017
+ }
1018
+
1019
+ function initSync(module) {
1020
+ if (wasm !== undefined) return wasm;
1021
+
1022
+
1023
+ if (module !== undefined) {
1024
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1025
+ ({module} = module)
1026
+ } else {
1027
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1028
+ }
1029
+ }
1030
+
1031
+ const imports = __wbg_get_imports();
1032
+ if (!(module instanceof WebAssembly.Module)) {
1033
+ module = new WebAssembly.Module(module);
1034
+ }
1035
+ const instance = new WebAssembly.Instance(module, imports);
1036
+ return __wbg_finalize_init(instance, module);
1037
+ }
1038
+
1039
+ async function __wbg_init(module_or_path) {
1040
+ if (wasm !== undefined) return wasm;
1041
+
1042
+
1043
+ if (module_or_path !== undefined) {
1044
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1045
+ ({module_or_path} = module_or_path)
1046
+ } else {
1047
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1048
+ }
1049
+ }
1050
+
1051
+ if (module_or_path === undefined && script_src !== undefined) {
1052
+ module_or_path = script_src.replace(/\.js$/, "_bg.wasm");
1053
+ }
1054
+ const imports = __wbg_get_imports();
1055
+
1056
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1057
+ module_or_path = fetch(module_or_path);
1058
+ }
1059
+
1060
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1061
+
1062
+ return __wbg_finalize_init(instance, module);
1063
+ }
1064
+
1065
+ return Object.assign(__wbg_init, { initSync }, exports);
1066
+ })({ __proto__: null });