@duckedup/nidus 0.83.0 → 0.85.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @duckedup/nidus
2
2
 
3
- The JavaScript/TypeScript client for [nidus](https://nidus.duckedup.org) a small,
3
+ The JavaScript/TypeScript client for [nidus](https://nidus.duckedup.org), a small,
4
4
  fast vector store. This package connects to a running `nidus serve` instance over
5
5
  HTTP, whether it's on your laptop or a remote host.
6
6
 
@@ -18,7 +18,7 @@ wire contract lines up.
18
18
 
19
19
  ## Connecting
20
20
 
21
- "Local vs remote" is just the base URL point the client at a local `nidus serve`
21
+ "Local vs remote" is just the base URL: point the client at a local `nidus serve`
22
22
  or any reachable host.
23
23
 
24
24
  ```ts
@@ -36,8 +36,8 @@ const db = new NidusClient({
36
36
 
37
37
  ## Upserting and searching
38
38
 
39
- `attrs` accept plain JS values strings, numbers, booleans, string arrays, `Date`s,
40
- and `null` and are normalized to nidus's typed values for you. (For an explicit
39
+ `attrs` accept plain JS values (strings, numbers, booleans, string arrays, `Date`s,
40
+ and `null`) and are normalized to nidus's typed values for you. (For an explicit
41
41
  type, use the `v.*` helpers.)
42
42
 
43
43
  ```ts
@@ -46,7 +46,7 @@ await db.createCollection("docs");
46
46
  await db.upsert("docs", [
47
47
  { id: "a", vector: [0.1, 0.2, 0.3], attrs: { lang: "rust", year: 2024 } },
48
48
  { id: "b", vector: [0.4, 0.5, 0.6], attrs: { lang: "go", year: 2023 } },
49
- // a text-only doc omit the vector
49
+ // a text-only doc, omit the vector
50
50
  { id: "c", attrs: { body: "vector stores are neat" } },
51
51
  ]);
52
52
 
@@ -57,7 +57,7 @@ for (const hit of hits) {
57
57
  ```
58
58
 
59
59
  nidus has separate `Int` and `Float` attribute types and compares them same-type only,
60
- but JS has one `number` and `1.0 === 1` so a plain number becomes an `Int` when
60
+ but JS has one `number` and `1.0 === 1`, so a plain number becomes an `Int` when
61
61
  `Number.isInteger` says so and a `Float` otherwise. That means a whole-numbered
62
62
  measurement lands as an `Int` in whichever records it came out round, and a `Float`
63
63
  range filter then skips exactly those. Pin such a field with `v.float`:
@@ -70,7 +70,7 @@ await db.upsert("docs", [
70
70
  id: "d",
71
71
  attrs: {
72
72
  score: v.float(1), // a Float even though the value is whole
73
- ratio: 0.75, // already a Float not an integer
73
+ ratio: 0.75, // already a Float, not an integer
74
74
  year: 2024, // an Int
75
75
  seen: new Date(), // a DateTime: a UTC instant, epoch milliseconds
76
76
  },
@@ -80,7 +80,7 @@ await db.upsert("docs", [
80
80
 
81
81
  A `DateTime` carries no timezone and has millisecond resolution; it decodes back to a
82
82
  `Date`, so a decoded `attrs` map re-encodes to what it came from. `NaN` and `Infinity`
83
- throw JSON has no spelling for them. The Go and Python SDKs have the numeric types JS
83
+ throw: JSON has no spelling for them. The Go and Python SDKs have the numeric types JS
84
84
  lacks and decide from those instead, so a Python `2.0` or a Go `float64(2)` is a
85
85
  `Float` where a bare `2` here is an `Int`.
86
86
 
@@ -88,7 +88,7 @@ lacks and decide from those instead, so a Python `2.0` or a Go `float64(2)` is a
88
88
 
89
89
  Build an AND-filter with the `f.*` helpers. Each predicate is a positive assertion
90
90
  about a present attribute (an absent key matches nothing). Comparisons are same-type
91
- only, so an operand must encode to the attribute's type `f.ge("score", v.float(2))`,
91
+ only, so an operand must encode to the attribute's type: `f.ge("score", v.float(2))`,
92
92
  not `f.ge("score", 2)`, for a `Float` attribute.
93
93
 
94
94
  ```ts
@@ -106,7 +106,7 @@ const hits = await db.search({
106
106
  });
107
107
  ```
108
108
 
109
- Beyond the comparisons there are text predicates approximate, token-wise, and
109
+ Beyond the comparisons there are text predicates: approximate, token-wise, and
110
110
  regular-expression matching over a plain attribute (no full-text index required):
111
111
 
112
112
  ```ts
@@ -156,7 +156,7 @@ const hybrid = await db.hybridSearch({
156
156
  ```
157
157
 
158
158
  A query can search several fields at once, each with its own text, by sending `clauses`
159
- instead of the single field folded by `combine`, `"Sum"` (a doc hitting title *and*
159
+ instead of the single field, folded by `combine`, `"Sum"` (a doc hitting title *and*
160
160
  body outranks one hitting either) or `"Max"` (a long body cannot out-accumulate a
161
161
  precise title match). Weight the two hybrid legs with `vectorWeight`/`textWeight`.
162
162
 
@@ -196,7 +196,7 @@ for (const { field, fragments } of hits[0]?.annotations?.highlights ?? []) {
196
196
  ```
197
197
 
198
198
  nidus reports a span as a **UTF-8 byte** range, but a JS string is indexed in UTF-16
199
- code units so a raw span slices the wrong text out of any non-ASCII excerpt. This SDK
199
+ code units, so a raw span slices the wrong text out of any non-ASCII excerpt. This SDK
200
200
  converts them for you: `fragment.spans` are JS string indices, and `fragment.text.slice`
201
201
  is the matched term. If you compare them against the raw HTTP response, expect the
202
202
  numbers to differ wherever the excerpt is not ASCII.
@@ -205,7 +205,7 @@ numbers to differ wherever the excerpt is not ASCII.
205
205
 
206
206
  `searchWithPlan`, `searchSimilarWithPlan`, and `hybridSearchWithPlan` are siblings of
207
207
  `search`/`searchSimilar`/`hybridSearch` that return `{ hits, plan }` instead of a bare
208
- `Hit[]` the plan reports which scan strategy the server took (`ann`, `exact`, …), how
208
+ `Hit[]`: the plan reports which scan strategy the server took (`ann`, `exact`, …), how
209
209
  many rows it scanned, and per-stage timings in microseconds. `textSearch` has no plan.
210
210
 
211
211
  ```ts
@@ -260,7 +260,7 @@ with no usable timestamp is not penalized at all (`missing` defaults to `1`).
260
260
  ## Remembering and recalling (text-native)
261
261
 
262
262
  When the server is started with an embedder (`nidus serve --embed-provider …`), you
263
- can send **text** and let the server embed it no need to compute vectors client-side.
263
+ can send **text** and let the server embed it, no need to compute vectors client-side.
264
264
  `remember` embeds and upserts; `recall` embeds the query and vector-searches.
265
265
 
266
266
  ```ts
@@ -295,7 +295,7 @@ later near-duplicate.
295
295
 
296
296
  Both throw a `NidusError` with status `400` if the server has no embedder configured
297
297
  (the message names `--embed-provider`); `mode: "summarize"` without a summarizer is
298
- likewise a `400`. Dedupe needs that same embedder it is a vector search under the
298
+ likewise a `400`. Dedupe needs that same embedder: it is a vector search under the
299
299
  hood.
300
300
 
301
301
  Pass `reinforce: true` to have a `recall` stamp `nidus.access_count` and
@@ -318,6 +318,19 @@ await db.flush(); await db.compact();
318
318
  await db.dropCollection("docs");
319
319
  ```
320
320
 
321
+ ## Running in the browser (wasm)
322
+
323
+ A separate, ESM-only subpath, `@duckedup/nidus/wasm`, runs nidus itself inside the
324
+ browser via WebAssembly, storing data in the browser's Origin Private File System
325
+ instead of talking to a `nidus serve` over HTTP. It is lazily imported so the default
326
+ entry point above stays small.
327
+
328
+ ```ts
329
+ import { acquireOpfsPool } from "@duckedup/nidus/wasm";
330
+ ```
331
+
332
+ See https://nidus.duckedup.org for the full guide.
333
+
321
334
  ## Errors
322
335
 
323
336
  A failed request throws a `NidusError` carrying the HTTP status the server reported,
@@ -338,7 +351,7 @@ try {
338
351
  ```
339
352
 
340
353
  A status of `0` means a transport-level failure (the server was unreachable, or the
341
- request timed out configure `timeoutMs` on the client).
354
+ request timed out; configure `timeoutMs` on the client).
342
355
 
343
356
  ## License
344
357
 
@@ -0,0 +1,39 @@
1
+ declare global {
2
+ interface FileSystemFileHandle {
3
+ createSyncAccessHandle(): Promise<FileSystemSyncAccessHandle>;
4
+ }
5
+ interface FileSystemSyncAccessHandle {
6
+ close(): void;
7
+ }
8
+ }
9
+ /** Mirrors `bindings/wasm/src/lib.rs`'s `#[wasm_bindgen]` exports. Can drift if that changes. */
10
+ interface NidusHandleInstance {
11
+ upsert(collection: string, records: unknown): number;
12
+ search(collection: string, query: number[], topK: number): unknown;
13
+ flush(): void;
14
+ close(): void;
15
+ }
16
+ interface NidusHandleClass {
17
+ open(location: string, dimension: number): NidusHandleInstance;
18
+ }
19
+ interface OpfsPoolOptions {
20
+ /** Handles opened per grow (directory slot + body slots). Defaults to 8. */
21
+ slots?: number;
22
+ /** Directory name under the OPFS root to open slot files in. Defaults to "nidus". */
23
+ dir?: string;
24
+ }
25
+ interface OpfsPool {
26
+ /** The store constructor, ready to use: the pool it needs is already registered. */
27
+ readonly NidusHandle: NidusHandleClass;
28
+ /** Open `slots` more handles and register them with the wasm pool (async growth step). */
29
+ grow(): Promise<void>;
30
+ /** Run `writeOnce`; on a pool-exhausted error, grow the pool once and retry. */
31
+ withPoolGrowth<T>(writeOnce: () => T): Promise<T>;
32
+ }
33
+ /**
34
+ * Load the wasm module and open+register an initial pool of OPFS sync access handles.
35
+ * Mirrors `bindings/wasm/demo/worker.js`'s `openSlots`/`withPoolGrowth` (:17-25, :36-44).
36
+ */
37
+ declare function acquireOpfsPool(opts?: OpfsPoolOptions): Promise<OpfsPool>;
38
+
39
+ export { type NidusHandleClass, type NidusHandleInstance, type OpfsPool, type OpfsPoolOptions, acquireOpfsPool };
@@ -0,0 +1,49 @@
1
+ // src/wasm-helper.ts
2
+ var modPromise;
3
+ async function loadWasm() {
4
+ if (!modPromise) {
5
+ const specifier = "./nidus_wasm.js";
6
+ modPromise = import(specifier);
7
+ }
8
+ const mod = await modPromise;
9
+ await mod.default();
10
+ return mod;
11
+ }
12
+ async function openSlots(dir, count, next) {
13
+ const opened = [];
14
+ for (let i = 0; i < count; i++) {
15
+ const fileHandle = await dir.getFileHandle(`slot-${next.n++}`, { create: true });
16
+ opened.push(await fileHandle.createSyncAccessHandle());
17
+ }
18
+ return opened;
19
+ }
20
+ async function acquireOpfsPool(opts) {
21
+ const slots = opts?.slots ?? 8;
22
+ const mod = await loadWasm();
23
+ const root = await navigator.storage.getDirectory();
24
+ const dir = await root.getDirectoryHandle(opts?.dir ?? "nidus", { create: true });
25
+ const next = { n: 0 };
26
+ mod.init_opfs_pool(await openSlots(dir, slots, next));
27
+ return {
28
+ NidusHandle: mod.NidusHandle,
29
+ async grow() {
30
+ mod.grow_opfs_pool(await openSlots(dir, slots, next));
31
+ },
32
+ // Retries once on "OPFS pool exhausted" after growing (nidus-y67's documented
33
+ // design, not a bug): a sync write can't perform the async grow step itself.
34
+ async withPoolGrowth(writeOnce) {
35
+ try {
36
+ return writeOnce();
37
+ } catch (e) {
38
+ if (!String(e).includes("OPFS pool exhausted")) throw e;
39
+ mod.grow_opfs_pool(await openSlots(dir, slots, next));
40
+ return writeOnce();
41
+ }
42
+ }
43
+ };
44
+ }
45
+ export {
46
+ acquireOpfsPool
47
+ };
48
+ //! `@duckedup/nidus/wasm` — browser helper over the generated `nidus_wasm` module.
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/wasm-helper.ts"],"sourcesContent":["//! `@duckedup/nidus/wasm` — browser helper over the generated `nidus_wasm` module.\n//\n// Must typecheck with `bindings/wasm/pkg` absent (nidus-3hc): the module's surface is\n// declared locally below and reached via a dynamic `import()` of a non-literal\n// specifier, never a static import of the `nidus_wasm.js` this package copies into place.\n\n// OPFS sync access is worker-only and still missing from TS's lib.dom.d.ts.\ndeclare global {\n interface FileSystemFileHandle {\n createSyncAccessHandle(): Promise<FileSystemSyncAccessHandle>;\n }\n interface FileSystemSyncAccessHandle {\n close(): void;\n }\n}\n\n/** Mirrors `bindings/wasm/src/lib.rs`'s `#[wasm_bindgen]` exports. Can drift if that changes. */\nexport interface NidusHandleInstance {\n upsert(collection: string, records: unknown): number;\n search(collection: string, query: number[], topK: number): unknown;\n flush(): void;\n close(): void;\n}\n\nexport interface NidusHandleClass {\n open(location: string, dimension: number): NidusHandleInstance;\n}\n\ninterface WasmModule {\n default: (input?: unknown) => Promise<unknown>;\n NidusHandle: NidusHandleClass;\n init_opfs_pool: (handles: FileSystemSyncAccessHandle[]) => void;\n grow_opfs_pool: (handles: FileSystemSyncAccessHandle[]) => void;\n}\n\nlet modPromise: Promise<WasmModule> | undefined;\n\nasync function loadWasm(): Promise<WasmModule> {\n if (!modPromise) {\n const specifier = \"./nidus_wasm.js\";\n modPromise = import(specifier) as Promise<WasmModule>;\n }\n const mod = await modPromise;\n await mod.default();\n return mod;\n}\n\nexport interface OpfsPoolOptions {\n /** Handles opened per grow (directory slot + body slots). Defaults to 8. */\n slots?: number;\n /** Directory name under the OPFS root to open slot files in. Defaults to \"nidus\". */\n dir?: string;\n}\n\nexport interface OpfsPool {\n /** The store constructor, ready to use: the pool it needs is already registered. */\n readonly NidusHandle: NidusHandleClass;\n /** Open `slots` more handles and register them with the wasm pool (async growth step). */\n grow(): Promise<void>;\n /** Run `writeOnce`; on a pool-exhausted error, grow the pool once and retry. */\n withPoolGrowth<T>(writeOnce: () => T): Promise<T>;\n}\n\n// Mirrors bindings/wasm/demo/worker.js:17-25 (openSlots): the one async step OPFS needs\n// per handle (getFileHandle + createSyncAccessHandle); everything after is sync wasm.\nasync function openSlots(dir: FileSystemDirectoryHandle, count: number, next: { n: number }) {\n const opened: FileSystemSyncAccessHandle[] = [];\n for (let i = 0; i < count; i++) {\n const fileHandle = await dir.getFileHandle(`slot-${next.n++}`, { create: true });\n opened.push(await fileHandle.createSyncAccessHandle());\n }\n return opened;\n}\n\n/**\n * Load the wasm module and open+register an initial pool of OPFS sync access handles.\n * Mirrors `bindings/wasm/demo/worker.js`'s `openSlots`/`withPoolGrowth` (:17-25, :36-44).\n */\nexport async function acquireOpfsPool(opts?: OpfsPoolOptions): Promise<OpfsPool> {\n const slots = opts?.slots ?? 8;\n const mod = await loadWasm();\n const root = await navigator.storage.getDirectory();\n const dir = await root.getDirectoryHandle(opts?.dir ?? \"nidus\", { create: true });\n const next = { n: 0 };\n\n mod.init_opfs_pool(await openSlots(dir, slots, next));\n\n return {\n NidusHandle: mod.NidusHandle,\n async grow() {\n mod.grow_opfs_pool(await openSlots(dir, slots, next));\n },\n // Retries once on \"OPFS pool exhausted\" after growing (nidus-y67's documented\n // design, not a bug): a sync write can't perform the async grow step itself.\n async withPoolGrowth<T>(writeOnce: () => T): Promise<T> {\n try {\n return writeOnce();\n } catch (e) {\n if (!String(e).includes(\"OPFS pool exhausted\")) throw e;\n mod.grow_opfs_pool(await openSlots(dir, slots, next));\n return writeOnce();\n }\n },\n };\n}\n"],"mappings":";AAmCA,IAAI;AAEJ,eAAe,WAAgC;AAC7C,MAAI,CAAC,YAAY;AACf,UAAM,YAAY;AAClB,iBAAa,OAAO;AAAA,EACtB;AACA,QAAM,MAAM,MAAM;AAClB,QAAM,IAAI,QAAQ;AAClB,SAAO;AACT;AAoBA,eAAe,UAAU,KAAgC,OAAe,MAAqB;AAC3F,QAAM,SAAuC,CAAC;AAC9C,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK;AAC9B,UAAM,aAAa,MAAM,IAAI,cAAc,QAAQ,KAAK,GAAG,IAAI,EAAE,QAAQ,KAAK,CAAC;AAC/E,WAAO,KAAK,MAAM,WAAW,uBAAuB,CAAC;AAAA,EACvD;AACA,SAAO;AACT;AAMA,eAAsB,gBAAgB,MAA2C;AAC/E,QAAM,QAAQ,MAAM,SAAS;AAC7B,QAAM,MAAM,MAAM,SAAS;AAC3B,QAAM,OAAO,MAAM,UAAU,QAAQ,aAAa;AAClD,QAAM,MAAM,MAAM,KAAK,mBAAmB,MAAM,OAAO,SAAS,EAAE,QAAQ,KAAK,CAAC;AAChF,QAAM,OAAO,EAAE,GAAG,EAAE;AAEpB,MAAI,eAAe,MAAM,UAAU,KAAK,OAAO,IAAI,CAAC;AAEpD,SAAO;AAAA,IACL,aAAa,IAAI;AAAA,IACjB,MAAM,OAAO;AACX,UAAI,eAAe,MAAM,UAAU,KAAK,OAAO,IAAI,CAAC;AAAA,IACtD;AAAA;AAAA;AAAA,IAGA,MAAM,eAAkB,WAAgC;AACtD,UAAI;AACF,eAAO,UAAU;AAAA,MACnB,SAAS,GAAG;AACV,YAAI,CAAC,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAG,OAAM;AACtD,YAAI,eAAe,MAAM,UAAU,KAAK,OAAO,IAAI,CAAC;AACpD,eAAO,UAAU;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,106 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * An open store. Wraps `nidus::Nidus`; every method must run on the worker thread that
6
+ * registered its OPFS pool (for an `opfs://` location).
7
+ */
8
+ export class NidusHandle {
9
+ private constructor();
10
+ free(): void;
11
+ [Symbol.dispose](): void;
12
+ /**
13
+ * Close the store. Consumes the handle: nidus's `Drop` releases the writer lock (a
14
+ * trivial always-held guard on OPFS), and the JS wrapper is invalidated with it.
15
+ */
16
+ close(): void;
17
+ /**
18
+ * Drop a collection's rows. The terminal's `clear` — dropping rather than deleting
19
+ * OPFS files underneath the pool's open handles.
20
+ */
21
+ drop_collection(collection: string): void;
22
+ /**
23
+ * fsync both files.
24
+ */
25
+ flush(): void;
26
+ /**
27
+ * A RAM/disk footprint snapshot, shaped like `FootprintDto`. The terminal's `stats`.
28
+ */
29
+ footprint(): any;
30
+ /**
31
+ * Open (creating if absent) a store at `location` — `opfs://name` (needs
32
+ * `init_opfs_pool` first, same thread) or `file://…`/a bare path.
33
+ */
34
+ static open(location: string, dimension: number): NidusHandle;
35
+ /**
36
+ * Open a RAM-only store, no persistence config. The terminal's fallback when the
37
+ * worker/OPFS handshake fails.
38
+ */
39
+ static open_in_memory(dimension: number): NidusHandle;
40
+ /**
41
+ * Nearest-neighbour search in `collection`, returning a JS array of hits shaped like
42
+ * `server::dto::HitDto`: `{collection, id, score, attrs}`.
43
+ */
44
+ search(collection: string, query: Float32Array, top_k: number): any;
45
+ /**
46
+ * Upsert records given as a JS array of `{id, vector?, attrs}` (mirrors
47
+ * `server::dto::UpsertRequest`'s `Record` shape); returns the count written.
48
+ */
49
+ upsert(collection: string, records: any): number;
50
+ }
51
+
52
+ /**
53
+ * Add freshly-opened handles to the pool already registered on this thread — the async
54
+ * growth step a `put` exhaustion error asks for. Same thread as `init_opfs_pool` only.
55
+ */
56
+ export function grow_opfs_pool(handles: Array<any>): void;
57
+
58
+ /**
59
+ * Adopt a fresh pool of already-opened OPFS handles (`handles[0]` is the directory slot,
60
+ * `handles[1..]` are body slots) and register it on this worker thread. Must run before any
61
+ * `NidusHandle::open("opfs://…")` call on the same thread.
62
+ */
63
+ export function init_opfs_pool(handles: Array<any>): void;
64
+
65
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
66
+
67
+ export interface InitOutput {
68
+ readonly memory: WebAssembly.Memory;
69
+ readonly __wbg_nidushandle_free: (a: number, b: number) => void;
70
+ readonly grow_opfs_pool: (a: number, b: number) => void;
71
+ readonly init_opfs_pool: (a: number, b: number) => void;
72
+ readonly nidushandle_close: (a: number) => void;
73
+ readonly nidushandle_drop_collection: (a: number, b: number, c: number, d: number) => void;
74
+ readonly nidushandle_flush: (a: number, b: number) => void;
75
+ readonly nidushandle_footprint: (a: number, b: number) => void;
76
+ readonly nidushandle_open: (a: number, b: number, c: number, d: number) => void;
77
+ readonly nidushandle_open_in_memory: (a: number, b: number) => void;
78
+ readonly nidushandle_search: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
79
+ readonly nidushandle_upsert: (a: number, b: number, c: number, d: number, e: number) => void;
80
+ readonly __wbindgen_export: (a: number, b: number) => number;
81
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
82
+ readonly __wbindgen_export3: (a: number) => void;
83
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
84
+ }
85
+
86
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
87
+
88
+ /**
89
+ * Instantiates the given `module`, which can either be bytes or
90
+ * a precompiled `WebAssembly.Module`.
91
+ *
92
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
93
+ *
94
+ * @returns {InitOutput}
95
+ */
96
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
97
+
98
+ /**
99
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
100
+ * for everything else, calls `WebAssembly.instantiate` directly.
101
+ *
102
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
103
+ *
104
+ * @returns {Promise<InitOutput>}
105
+ */
106
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,803 @@
1
+ /* @ts-self-types="./nidus_wasm.d.ts" */
2
+
3
+ /**
4
+ * An open store. Wraps `nidus::Nidus`; every method must run on the worker thread that
5
+ * registered its OPFS pool (for an `opfs://` location).
6
+ */
7
+ export class NidusHandle {
8
+ static __wrap(ptr) {
9
+ const obj = Object.create(NidusHandle.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ NidusHandleFinalization.register(obj, obj.__wbg_ptr, obj);
12
+ return obj;
13
+ }
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ NidusHandleFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_nidushandle_free(ptr, 0);
23
+ }
24
+ /**
25
+ * Close the store. Consumes the handle: nidus's `Drop` releases the writer lock (a
26
+ * trivial always-held guard on OPFS), and the JS wrapper is invalidated with it.
27
+ */
28
+ close() {
29
+ const ptr = this.__destroy_into_raw();
30
+ wasm.nidushandle_close(ptr);
31
+ }
32
+ /**
33
+ * Drop a collection's rows. The terminal's `clear` — dropping rather than deleting
34
+ * OPFS files underneath the pool's open handles.
35
+ * @param {string} collection
36
+ */
37
+ drop_collection(collection) {
38
+ try {
39
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
40
+ const ptr0 = passStringToWasm0(collection, wasm.__wbindgen_export, wasm.__wbindgen_export2);
41
+ const len0 = WASM_VECTOR_LEN;
42
+ wasm.nidushandle_drop_collection(retptr, this.__wbg_ptr, ptr0, len0);
43
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
44
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
45
+ if (r1) {
46
+ throw takeObject(r0);
47
+ }
48
+ } finally {
49
+ wasm.__wbindgen_add_to_stack_pointer(16);
50
+ }
51
+ }
52
+ /**
53
+ * fsync both files.
54
+ */
55
+ flush() {
56
+ try {
57
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
58
+ wasm.nidushandle_flush(retptr, this.__wbg_ptr);
59
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
60
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
61
+ if (r1) {
62
+ throw takeObject(r0);
63
+ }
64
+ } finally {
65
+ wasm.__wbindgen_add_to_stack_pointer(16);
66
+ }
67
+ }
68
+ /**
69
+ * A RAM/disk footprint snapshot, shaped like `FootprintDto`. The terminal's `stats`.
70
+ * @returns {any}
71
+ */
72
+ footprint() {
73
+ try {
74
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
75
+ wasm.nidushandle_footprint(retptr, this.__wbg_ptr);
76
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
77
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
78
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
79
+ if (r2) {
80
+ throw takeObject(r1);
81
+ }
82
+ return takeObject(r0);
83
+ } finally {
84
+ wasm.__wbindgen_add_to_stack_pointer(16);
85
+ }
86
+ }
87
+ /**
88
+ * Open (creating if absent) a store at `location` — `opfs://name` (needs
89
+ * `init_opfs_pool` first, same thread) or `file://…`/a bare path.
90
+ * @param {string} location
91
+ * @param {number} dimension
92
+ * @returns {NidusHandle}
93
+ */
94
+ static open(location, dimension) {
95
+ try {
96
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
97
+ const ptr0 = passStringToWasm0(location, wasm.__wbindgen_export, wasm.__wbindgen_export2);
98
+ const len0 = WASM_VECTOR_LEN;
99
+ wasm.nidushandle_open(retptr, ptr0, len0, dimension);
100
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
101
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
102
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
103
+ if (r2) {
104
+ throw takeObject(r1);
105
+ }
106
+ return NidusHandle.__wrap(r0);
107
+ } finally {
108
+ wasm.__wbindgen_add_to_stack_pointer(16);
109
+ }
110
+ }
111
+ /**
112
+ * Open a RAM-only store, no persistence config. The terminal's fallback when the
113
+ * worker/OPFS handshake fails.
114
+ * @param {number} dimension
115
+ * @returns {NidusHandle}
116
+ */
117
+ static open_in_memory(dimension) {
118
+ try {
119
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
120
+ wasm.nidushandle_open_in_memory(retptr, dimension);
121
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
122
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
123
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
124
+ if (r2) {
125
+ throw takeObject(r1);
126
+ }
127
+ return NidusHandle.__wrap(r0);
128
+ } finally {
129
+ wasm.__wbindgen_add_to_stack_pointer(16);
130
+ }
131
+ }
132
+ /**
133
+ * Nearest-neighbour search in `collection`, returning a JS array of hits shaped like
134
+ * `server::dto::HitDto`: `{collection, id, score, attrs}`.
135
+ * @param {string} collection
136
+ * @param {Float32Array} query
137
+ * @param {number} top_k
138
+ * @returns {any}
139
+ */
140
+ search(collection, query, top_k) {
141
+ try {
142
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
143
+ const ptr0 = passStringToWasm0(collection, wasm.__wbindgen_export, wasm.__wbindgen_export2);
144
+ const len0 = WASM_VECTOR_LEN;
145
+ const ptr1 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
146
+ const len1 = WASM_VECTOR_LEN;
147
+ wasm.nidushandle_search(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, top_k);
148
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
149
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
150
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
151
+ if (r2) {
152
+ throw takeObject(r1);
153
+ }
154
+ return takeObject(r0);
155
+ } finally {
156
+ wasm.__wbindgen_add_to_stack_pointer(16);
157
+ }
158
+ }
159
+ /**
160
+ * Upsert records given as a JS array of `{id, vector?, attrs}` (mirrors
161
+ * `server::dto::UpsertRequest`'s `Record` shape); returns the count written.
162
+ * @param {string} collection
163
+ * @param {any} records
164
+ * @returns {number}
165
+ */
166
+ upsert(collection, records) {
167
+ try {
168
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
169
+ const ptr0 = passStringToWasm0(collection, wasm.__wbindgen_export, wasm.__wbindgen_export2);
170
+ const len0 = WASM_VECTOR_LEN;
171
+ wasm.nidushandle_upsert(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(records));
172
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
173
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
174
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
175
+ if (r2) {
176
+ throw takeObject(r1);
177
+ }
178
+ return r0 >>> 0;
179
+ } finally {
180
+ wasm.__wbindgen_add_to_stack_pointer(16);
181
+ }
182
+ }
183
+ }
184
+ if (Symbol.dispose) NidusHandle.prototype[Symbol.dispose] = NidusHandle.prototype.free;
185
+
186
+ /**
187
+ * Add freshly-opened handles to the pool already registered on this thread — the async
188
+ * growth step a `put` exhaustion error asks for. Same thread as `init_opfs_pool` only.
189
+ * @param {Array<any>} handles
190
+ */
191
+ export function grow_opfs_pool(handles) {
192
+ try {
193
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
194
+ wasm.grow_opfs_pool(retptr, addHeapObject(handles));
195
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
196
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
197
+ if (r1) {
198
+ throw takeObject(r0);
199
+ }
200
+ } finally {
201
+ wasm.__wbindgen_add_to_stack_pointer(16);
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Adopt a fresh pool of already-opened OPFS handles (`handles[0]` is the directory slot,
207
+ * `handles[1..]` are body slots) and register it on this worker thread. Must run before any
208
+ * `NidusHandle::open("opfs://…")` call on the same thread.
209
+ * @param {Array<any>} handles
210
+ */
211
+ export function init_opfs_pool(handles) {
212
+ try {
213
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
214
+ wasm.init_opfs_pool(retptr, addHeapObject(handles));
215
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
216
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
217
+ if (r1) {
218
+ throw takeObject(r0);
219
+ }
220
+ } finally {
221
+ wasm.__wbindgen_add_to_stack_pointer(16);
222
+ }
223
+ }
224
+ function __wbg_get_imports() {
225
+ const import0 = {
226
+ __proto__: null,
227
+ __wbg_Error_ef53bc310eb298a0: function(arg0, arg1) {
228
+ const ret = Error(getStringFromWasm0(arg0, arg1));
229
+ return addHeapObject(ret);
230
+ },
231
+ __wbg_Number_6b506e6536831eaa: function(arg0) {
232
+ const ret = Number(getObject(arg0));
233
+ return ret;
234
+ },
235
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
236
+ const ret = String(getObject(arg1));
237
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
238
+ const len1 = WASM_VECTOR_LEN;
239
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
240
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
241
+ },
242
+ __wbg___wbindgen_bigint_get_as_i64_38130e98eecd467d: function(arg0, arg1) {
243
+ const v = getObject(arg1);
244
+ const ret = typeof(v) === 'bigint' ? v : undefined;
245
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
246
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
247
+ },
248
+ __wbg___wbindgen_boolean_get_1a45e2c38d4d41b9: function(arg0) {
249
+ const v = getObject(arg0);
250
+ const ret = typeof(v) === 'boolean' ? v : undefined;
251
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
252
+ },
253
+ __wbg___wbindgen_debug_string_0accd80f45e5faa2: function(arg0, arg1) {
254
+ const ret = debugString(getObject(arg1));
255
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
256
+ const len1 = WASM_VECTOR_LEN;
257
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
258
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
259
+ },
260
+ __wbg___wbindgen_in_70a403a56e771704: function(arg0, arg1) {
261
+ const ret = getObject(arg0) in getObject(arg1);
262
+ return ret;
263
+ },
264
+ __wbg___wbindgen_is_bigint_6ffd6468a9bc44b9: function(arg0) {
265
+ const ret = typeof(getObject(arg0)) === 'bigint';
266
+ return ret;
267
+ },
268
+ __wbg___wbindgen_is_function_754e9f305ff6029e: function(arg0) {
269
+ const ret = typeof(getObject(arg0)) === 'function';
270
+ return ret;
271
+ },
272
+ __wbg___wbindgen_is_object_56732c2bc353f41d: function(arg0) {
273
+ const val = getObject(arg0);
274
+ const ret = typeof(val) === 'object' && val !== null;
275
+ return ret;
276
+ },
277
+ __wbg___wbindgen_is_string_c236cabd84a4d769: function(arg0) {
278
+ const ret = typeof(getObject(arg0)) === 'string';
279
+ return ret;
280
+ },
281
+ __wbg___wbindgen_is_undefined_67b456be8673d3d7: function(arg0) {
282
+ const ret = getObject(arg0) === undefined;
283
+ return ret;
284
+ },
285
+ __wbg___wbindgen_jsval_eq_1068e624fa87f6ab: function(arg0, arg1) {
286
+ const ret = getObject(arg0) === getObject(arg1);
287
+ return ret;
288
+ },
289
+ __wbg___wbindgen_jsval_loose_eq_2c56564c75129511: function(arg0, arg1) {
290
+ const ret = getObject(arg0) == getObject(arg1);
291
+ return ret;
292
+ },
293
+ __wbg___wbindgen_number_get_9bb1761122181af2: function(arg0, arg1) {
294
+ const obj = getObject(arg1);
295
+ const ret = typeof(obj) === 'number' ? obj : undefined;
296
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
297
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
298
+ },
299
+ __wbg___wbindgen_string_get_72bdf95d3ae505b1: function(arg0, arg1) {
300
+ const obj = getObject(arg1);
301
+ const ret = typeof(obj) === 'string' ? obj : undefined;
302
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
303
+ var len1 = WASM_VECTOR_LEN;
304
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
305
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
306
+ },
307
+ __wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
308
+ throw new Error(getStringFromWasm0(arg0, arg1));
309
+ },
310
+ __wbg_call_40e4174f169eaca7: function() { return handleError(function (arg0, arg1, arg2, arg3) {
311
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3));
312
+ return addHeapObject(ret);
313
+ }, arguments); },
314
+ __wbg_call_8a89609d89f6608a: function() { return handleError(function (arg0, arg1) {
315
+ const ret = getObject(arg0).call(getObject(arg1));
316
+ return addHeapObject(ret);
317
+ }, arguments); },
318
+ __wbg_call_9c758de292015997: function() { return handleError(function (arg0, arg1, arg2) {
319
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
320
+ return addHeapObject(ret);
321
+ }, arguments); },
322
+ __wbg_done_60cf307fcc680536: function(arg0) {
323
+ const ret = getObject(arg0).done;
324
+ return ret;
325
+ },
326
+ __wbg_entries_04b37a02507f1713: function(arg0) {
327
+ const ret = Object.entries(getObject(arg0));
328
+ return addHeapObject(ret);
329
+ },
330
+ __wbg_get_1f8f054ddbaa7db2: function() { return handleError(function (arg0, arg1) {
331
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
332
+ return addHeapObject(ret);
333
+ }, arguments); },
334
+ __wbg_get_2b48c7d0d006a781: function(arg0, arg1) {
335
+ const ret = getObject(arg0)[arg1 >>> 0];
336
+ return addHeapObject(ret);
337
+ },
338
+ __wbg_get_de6a0f7d4d18a304: function() { return handleError(function (arg0, arg1) {
339
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
340
+ return addHeapObject(ret);
341
+ }, arguments); },
342
+ __wbg_get_unchecked_33f6e5c9e2f2d6b2: function(arg0, arg1) {
343
+ const ret = getObject(arg0)[arg1 >>> 0];
344
+ return addHeapObject(ret);
345
+ },
346
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
347
+ const ret = getObject(arg0)[getObject(arg1)];
348
+ return addHeapObject(ret);
349
+ },
350
+ __wbg_instanceof_ArrayBuffer_8f49811467741499: function(arg0) {
351
+ let result;
352
+ try {
353
+ result = getObject(arg0) instanceof ArrayBuffer;
354
+ } catch (_) {
355
+ result = false;
356
+ }
357
+ const ret = result;
358
+ return ret;
359
+ },
360
+ __wbg_instanceof_Uint8Array_86f30649f63ef9c2: function(arg0) {
361
+ let result;
362
+ try {
363
+ result = getObject(arg0) instanceof Uint8Array;
364
+ } catch (_) {
365
+ result = false;
366
+ }
367
+ const ret = result;
368
+ return ret;
369
+ },
370
+ __wbg_isArray_67c2c9c4313f4448: function(arg0) {
371
+ const ret = Array.isArray(getObject(arg0));
372
+ return ret;
373
+ },
374
+ __wbg_isSafeInteger_66acec27e09e99a7: function(arg0) {
375
+ const ret = Number.isSafeInteger(getObject(arg0));
376
+ return ret;
377
+ },
378
+ __wbg_iterator_8732428d309e270e: function() {
379
+ const ret = Symbol.iterator;
380
+ return addHeapObject(ret);
381
+ },
382
+ __wbg_length_4a591ecaa01354d9: function(arg0) {
383
+ const ret = getObject(arg0).length;
384
+ return ret;
385
+ },
386
+ __wbg_length_66f1a4b2e9026940: function(arg0) {
387
+ const ret = getObject(arg0).length;
388
+ return ret;
389
+ },
390
+ __wbg_new_578aeef4b6b94378: function(arg0) {
391
+ const ret = new Uint8Array(getObject(arg0));
392
+ return addHeapObject(ret);
393
+ },
394
+ __wbg_new_622fc80556be2e26: function() {
395
+ const ret = new Map();
396
+ return addHeapObject(ret);
397
+ },
398
+ __wbg_new_ce1ab61c1c2b300d: function() {
399
+ const ret = new Object();
400
+ return addHeapObject(ret);
401
+ },
402
+ __wbg_new_d90091b82fdf5b91: function() {
403
+ const ret = new Array();
404
+ return addHeapObject(ret);
405
+ },
406
+ __wbg_new_with_length_36a4998e27b014c5: function(arg0) {
407
+ const ret = new Uint8Array(arg0 >>> 0);
408
+ return addHeapObject(ret);
409
+ },
410
+ __wbg_next_9e03acdf51c4960d: function(arg0) {
411
+ const ret = getObject(arg0).next;
412
+ return addHeapObject(ret);
413
+ },
414
+ __wbg_next_eb8ca7351fa27906: function() { return handleError(function (arg0) {
415
+ const ret = getObject(arg0).next();
416
+ return addHeapObject(ret);
417
+ }, arguments); },
418
+ __wbg_now_190933fa139cc119: function() {
419
+ const ret = Date.now();
420
+ return ret;
421
+ },
422
+ __wbg_prototypesetcall_3249fc62a0fafa30: function(arg0, arg1, arg2) {
423
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
424
+ },
425
+ __wbg_set_29c99a8aac1c01e5: function(arg0, arg1, arg2) {
426
+ getObject(arg0).set(getArrayU8FromWasm0(arg1, arg2));
427
+ },
428
+ __wbg_set_52b1e1eb5bed906a: function(arg0, arg1, arg2) {
429
+ const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
430
+ return addHeapObject(ret);
431
+ },
432
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
433
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
434
+ },
435
+ __wbg_set_6e30c9374c26414c: function() { return handleError(function (arg0, arg1, arg2) {
436
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
437
+ return ret;
438
+ }, arguments); },
439
+ __wbg_set_dca99999bba88a9a: function(arg0, arg1, arg2) {
440
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
441
+ },
442
+ __wbg_static_accessor_GLOBAL_9d53f2689e622ca1: function() {
443
+ const ret = typeof global === 'undefined' ? null : global;
444
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
445
+ },
446
+ __wbg_static_accessor_GLOBAL_THIS_a1a35cec07001a8a: function() {
447
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
448
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
449
+ },
450
+ __wbg_static_accessor_SELF_4c59f6c7ea29a144: function() {
451
+ const ret = typeof self === 'undefined' ? null : self;
452
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
453
+ },
454
+ __wbg_static_accessor_WINDOW_e70ae9f2eb052253: function() {
455
+ const ret = typeof window === 'undefined' ? null : window;
456
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
457
+ },
458
+ __wbg_value_f3625092ee4b37f4: function(arg0) {
459
+ const ret = getObject(arg0).value;
460
+ return addHeapObject(ret);
461
+ },
462
+ __wbindgen_cast_0000000000000001: function(arg0) {
463
+ // Cast intrinsic for `F64 -> Externref`.
464
+ const ret = arg0;
465
+ return addHeapObject(ret);
466
+ },
467
+ __wbindgen_cast_0000000000000002: function(arg0) {
468
+ // Cast intrinsic for `I64 -> Externref`.
469
+ const ret = arg0;
470
+ return addHeapObject(ret);
471
+ },
472
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
473
+ // Cast intrinsic for `Ref(String) -> Externref`.
474
+ const ret = getStringFromWasm0(arg0, arg1);
475
+ return addHeapObject(ret);
476
+ },
477
+ __wbindgen_cast_0000000000000004: function(arg0) {
478
+ // Cast intrinsic for `U64 -> Externref`.
479
+ const ret = BigInt.asUintN(64, arg0);
480
+ return addHeapObject(ret);
481
+ },
482
+ __wbindgen_object_clone_ref: function(arg0) {
483
+ const ret = getObject(arg0);
484
+ return addHeapObject(ret);
485
+ },
486
+ __wbindgen_object_drop_ref: function(arg0) {
487
+ takeObject(arg0);
488
+ },
489
+ };
490
+ return {
491
+ __proto__: null,
492
+ "./nidus_wasm_bg.js": import0,
493
+ };
494
+ }
495
+
496
+ const NidusHandleFinalization = (typeof FinalizationRegistry === 'undefined')
497
+ ? { register: () => {}, unregister: () => {} }
498
+ : new FinalizationRegistry(ptr => wasm.__wbg_nidushandle_free(ptr, 1));
499
+
500
+ function addHeapObject(obj) {
501
+ if (heap_next === heap.length) heap.push(heap.length + 1);
502
+ const idx = heap_next;
503
+ heap_next = heap[idx];
504
+
505
+ heap[idx] = obj;
506
+ return idx;
507
+ }
508
+
509
+ function debugString(val) {
510
+ // primitive types
511
+ const type = typeof val;
512
+ if (type == 'number' || type == 'boolean' || val == null) {
513
+ return `${val}`;
514
+ }
515
+ if (type == 'string') {
516
+ return `"${val}"`;
517
+ }
518
+ if (type == 'symbol') {
519
+ const description = val.description;
520
+ if (description == null) {
521
+ return 'Symbol';
522
+ } else {
523
+ return `Symbol(${description})`;
524
+ }
525
+ }
526
+ if (type == 'function') {
527
+ const name = val.name;
528
+ if (typeof name == 'string' && name.length > 0) {
529
+ return `Function(${name})`;
530
+ } else {
531
+ return 'Function';
532
+ }
533
+ }
534
+ // objects
535
+ if (Array.isArray(val)) {
536
+ const length = val.length;
537
+ let debug = '[';
538
+ if (length > 0) {
539
+ debug += debugString(val[0]);
540
+ }
541
+ for(let i = 1; i < length; i++) {
542
+ debug += ', ' + debugString(val[i]);
543
+ }
544
+ debug += ']';
545
+ return debug;
546
+ }
547
+ // Test for built-in
548
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
549
+ let className;
550
+ if (builtInMatches && builtInMatches.length > 1) {
551
+ className = builtInMatches[1];
552
+ } else {
553
+ // Failed to match the standard '[object ClassName]'
554
+ return toString.call(val);
555
+ }
556
+ if (className == 'Object') {
557
+ // we're a user defined class or Object
558
+ // JSON.stringify avoids problems with cycles, and is generally much
559
+ // easier than looping through ownProperties of `val`.
560
+ try {
561
+ return 'Object(' + JSON.stringify(val) + ')';
562
+ } catch (_) {
563
+ return 'Object';
564
+ }
565
+ }
566
+ // errors
567
+ if (val instanceof Error) {
568
+ return `${val.name}: ${val.message}\n${val.stack}`;
569
+ }
570
+ // TODO we could test for more things here, like `Set`s and `Map`s.
571
+ return className;
572
+ }
573
+
574
+ function dropObject(idx) {
575
+ if (idx < 1028) return;
576
+ heap[idx] = heap_next;
577
+ heap_next = idx;
578
+ }
579
+
580
+ function getArrayU8FromWasm0(ptr, len) {
581
+ ptr = ptr >>> 0;
582
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
583
+ }
584
+
585
+ let cachedDataViewMemory0 = null;
586
+ function getDataViewMemory0() {
587
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
588
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
589
+ }
590
+ return cachedDataViewMemory0;
591
+ }
592
+
593
+ let cachedFloat32ArrayMemory0 = null;
594
+ function getFloat32ArrayMemory0() {
595
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
596
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
597
+ }
598
+ return cachedFloat32ArrayMemory0;
599
+ }
600
+
601
+ function getStringFromWasm0(ptr, len) {
602
+ return decodeText(ptr >>> 0, len);
603
+ }
604
+
605
+ let cachedUint8ArrayMemory0 = null;
606
+ function getUint8ArrayMemory0() {
607
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
608
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
609
+ }
610
+ return cachedUint8ArrayMemory0;
611
+ }
612
+
613
+ function getObject(idx) { return heap[idx]; }
614
+
615
+ function handleError(f, args) {
616
+ try {
617
+ return f.apply(this, args);
618
+ } catch (e) {
619
+ wasm.__wbindgen_export3(addHeapObject(e));
620
+ }
621
+ }
622
+
623
+ let heap = new Array(1024).fill(undefined);
624
+ heap.push(undefined, null, true, false);
625
+
626
+ let heap_next = heap.length;
627
+
628
+ function isLikeNone(x) {
629
+ return x === undefined || x === null;
630
+ }
631
+
632
+ function passArrayF32ToWasm0(arg, malloc) {
633
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
634
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
635
+ WASM_VECTOR_LEN = arg.length;
636
+ return ptr;
637
+ }
638
+
639
+ function passStringToWasm0(arg, malloc, realloc) {
640
+ if (realloc === undefined) {
641
+ const buf = cachedTextEncoder.encode(arg);
642
+ const ptr = malloc(buf.length, 1) >>> 0;
643
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
644
+ WASM_VECTOR_LEN = buf.length;
645
+ return ptr;
646
+ }
647
+
648
+ let len = arg.length;
649
+ let ptr = malloc(len, 1) >>> 0;
650
+
651
+ const mem = getUint8ArrayMemory0();
652
+
653
+ let offset = 0;
654
+
655
+ for (; offset < len; offset++) {
656
+ const code = arg.charCodeAt(offset);
657
+ if (code > 0x7F) break;
658
+ mem[ptr + offset] = code;
659
+ }
660
+ if (offset !== len) {
661
+ if (offset !== 0) {
662
+ arg = arg.slice(offset);
663
+ }
664
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
665
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
666
+ const ret = cachedTextEncoder.encodeInto(arg, view);
667
+
668
+ offset += ret.written;
669
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
670
+ }
671
+
672
+ WASM_VECTOR_LEN = offset;
673
+ return ptr;
674
+ }
675
+
676
+ function takeObject(idx) {
677
+ const ret = getObject(idx);
678
+ dropObject(idx);
679
+ return ret;
680
+ }
681
+
682
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
683
+ cachedTextDecoder.decode();
684
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
685
+ let numBytesDecoded = 0;
686
+ function decodeText(ptr, len) {
687
+ numBytesDecoded += len;
688
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
689
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
690
+ cachedTextDecoder.decode();
691
+ numBytesDecoded = len;
692
+ }
693
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
694
+ }
695
+
696
+ const cachedTextEncoder = new TextEncoder();
697
+
698
+ if (!('encodeInto' in cachedTextEncoder)) {
699
+ cachedTextEncoder.encodeInto = function (arg, view) {
700
+ const buf = cachedTextEncoder.encode(arg);
701
+ view.set(buf);
702
+ return {
703
+ read: arg.length,
704
+ written: buf.length
705
+ };
706
+ };
707
+ }
708
+
709
+ let WASM_VECTOR_LEN = 0;
710
+
711
+ let wasmModule, wasmInstance, wasm;
712
+ function __wbg_finalize_init(instance, module) {
713
+ wasmInstance = instance;
714
+ wasm = instance.exports;
715
+ wasmModule = module;
716
+ cachedDataViewMemory0 = null;
717
+ cachedFloat32ArrayMemory0 = null;
718
+ cachedUint8ArrayMemory0 = null;
719
+ return wasm;
720
+ }
721
+
722
+ async function __wbg_load(module, imports) {
723
+ if (typeof Response === 'function' && module instanceof Response) {
724
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
725
+ try {
726
+ return await WebAssembly.instantiateStreaming(module, imports);
727
+ } catch (e) {
728
+ const validResponse = module.ok && expectedResponseType(module.type);
729
+
730
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
731
+ 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);
732
+
733
+ } else { throw e; }
734
+ }
735
+ }
736
+
737
+ const bytes = await module.arrayBuffer();
738
+ return await WebAssembly.instantiate(bytes, imports);
739
+ } else {
740
+ const instance = await WebAssembly.instantiate(module, imports);
741
+
742
+ if (instance instanceof WebAssembly.Instance) {
743
+ return { instance, module };
744
+ } else {
745
+ return instance;
746
+ }
747
+ }
748
+
749
+ function expectedResponseType(type) {
750
+ switch (type) {
751
+ case 'basic': case 'cors': case 'default': return true;
752
+ }
753
+ return false;
754
+ }
755
+ }
756
+
757
+ function initSync(module) {
758
+ if (wasm !== undefined) return wasm;
759
+
760
+
761
+ if (module !== undefined) {
762
+ if (Object.getPrototypeOf(module) === Object.prototype) {
763
+ ({module} = module)
764
+ } else {
765
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
766
+ }
767
+ }
768
+
769
+ const imports = __wbg_get_imports();
770
+ if (!(module instanceof WebAssembly.Module)) {
771
+ module = new WebAssembly.Module(module);
772
+ }
773
+ const instance = new WebAssembly.Instance(module, imports);
774
+ return __wbg_finalize_init(instance, module);
775
+ }
776
+
777
+ async function __wbg_init(module_or_path) {
778
+ if (wasm !== undefined) return wasm;
779
+
780
+
781
+ if (module_or_path !== undefined) {
782
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
783
+ ({module_or_path} = module_or_path)
784
+ } else {
785
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
786
+ }
787
+ }
788
+
789
+ if (module_or_path === undefined) {
790
+ module_or_path = new URL('nidus_wasm_bg.wasm', import.meta.url);
791
+ }
792
+ const imports = __wbg_get_imports();
793
+
794
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
795
+ module_or_path = fetch(module_or_path);
796
+ }
797
+
798
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
799
+
800
+ return __wbg_finalize_init(instance, module);
801
+ }
802
+
803
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,18 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_nidushandle_free: (a: number, b: number) => void;
5
+ export const grow_opfs_pool: (a: number, b: number) => void;
6
+ export const init_opfs_pool: (a: number, b: number) => void;
7
+ export const nidushandle_close: (a: number) => void;
8
+ export const nidushandle_drop_collection: (a: number, b: number, c: number, d: number) => void;
9
+ export const nidushandle_flush: (a: number, b: number) => void;
10
+ export const nidushandle_footprint: (a: number, b: number) => void;
11
+ export const nidushandle_open: (a: number, b: number, c: number, d: number) => void;
12
+ export const nidushandle_open_in_memory: (a: number, b: number) => void;
13
+ export const nidushandle_search: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
14
+ export const nidushandle_upsert: (a: number, b: number, c: number, d: number, e: number) => void;
15
+ export const __wbindgen_export: (a: number, b: number) => number;
16
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
17
+ export const __wbindgen_export3: (a: number) => void;
18
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckedup/nidus",
3
- "version": "0.83.0",
3
+ "version": "0.85.0",
4
4
  "description": "JavaScript/TypeScript client for nidus — a small, fast vector store. Connects to a local or remote `nidus serve` over HTTP.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,6 +35,10 @@
35
35
  "types": "./dist/index.d.ts",
36
36
  "import": "./dist/index.js",
37
37
  "require": "./dist/index.cjs"
38
+ },
39
+ "./wasm": {
40
+ "types": "./dist/wasm/index.d.ts",
41
+ "import": "./dist/wasm/index.js"
38
42
  }
39
43
  },
40
44
  "sideEffects": false,
@@ -46,12 +50,14 @@
46
50
  "provenance": true
47
51
  },
48
52
  "scripts": {
49
- "build": "tsup",
53
+ "build": "npm run clean && tsup && node scripts/build-wasm-subpath.mjs",
54
+ "build:wasm-required": "npm run clean && tsup && NIDUS_WASM_REQUIRED=1 node scripts/build-wasm-subpath.mjs",
50
55
  "typecheck": "tsc --noEmit",
51
56
  "test": "vitest run",
52
- "test:unit": "vitest run test/unit.test.ts",
57
+ "test:unit": "vitest run test/unit.test.ts test/wasm-subpath.test.ts",
53
58
  "test:integration": "vitest run test/integration.test.ts",
54
- "prepublishOnly": "npm run build"
59
+ "prepublishOnly": "npm run build",
60
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
55
61
  },
56
62
  "devDependencies": {
57
63
  "@types/node": "^22.10.0",