@hakodb/client 0.5.16 → 0.5.18

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
  # hakojs
2
2
 
3
- > Part of [**HakoDB**](https://github.com/hakodb/hakodb) — embedded Firestore-style document DB in Rust. The engine + C ABI live in `hakodb/hakodb`; this repo holds the JavaScript/TypeScript SDK.
3
+ > Part of [**HakoDB**](https://github.com/hakodb/hakodb) — embedded document DB with native vector search and multi-plane sync, written in Rust. The engine + C ABI live in `hakodb/hakodb`; this repo holds the JavaScript/TypeScript SDK.
4
4
 
5
5
  JavaScript/TypeScript SDK for HakoDB:
6
6
  high-level client (`client.ts`: `HakoClient`, `HakoConfig`) and native
@@ -14,6 +14,8 @@ FFI bindings over koffi/Bun (`native.ts`). Tauri lives in `@hakodb/tauri`
14
14
  | 0.5.13 | `cloud_sync` branch / `v0.8.21`+ release asset |
15
15
  | 0.5.15 | `hakodb v0.12.3` (archive: `relocateDocs`/`load`/`unload`/`unloadedCollections`) |
16
16
  | 0.5.16 | `hakodb v0.13.3` (`createVectorIndex` + `findNear` KNN over `hk_engine_find_near`) |
17
+ | 0.5.17 | `hakodb v0.14.0` (`createTraverseIndex` + `findPaths` graph BFS over `hk_engine_find_paths`) |
18
+ | 0.5.18 | `hakodb v0.15.0` (Phase B: `createEdgeIndex` + `shortestPaths` Dijkstra over `hk_engine_shortest_paths`) |
17
19
 
18
20
  ## Setup — native library
19
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hakodb/client",
3
- "version": "0.5.16",
3
+ "version": "0.5.18",
4
4
  "description": "High-level HakoDB JavaScript/TypeScript client for Node.js and Bun",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,10 +12,10 @@
12
12
  },
13
13
  "keywords": [
14
14
  "hakodb",
15
- "firestore",
16
15
  "embedded",
17
16
  "database",
18
- "ffi"
17
+ "ffi",
18
+ "vector-search"
19
19
  ],
20
20
  "engines": {
21
21
  "node": ">=18"
package/src/client.ts CHANGED
@@ -26,6 +26,18 @@ export interface NearHit {
26
26
  doc: HakoDocData;
27
27
  }
28
28
 
29
+ /** Traversal direction (matches core TraverseDir::from_u32). */
30
+ export type TraverseDirection = 'outgoing' | 'incoming' | 'both';
31
+
32
+ /** One graph hit: collection + id (paths cross collections), BFS depth, doc. */
33
+ export interface PathHit {
34
+ collection: string;
35
+ id: string;
36
+ depth: number;
37
+ cost?: number;
38
+ doc: HakoDocData;
39
+ }
40
+
29
41
  const SERVER_TIMESTAMP_SENTINEL = "__FL_SERVER_TIMESTAMP__";
30
42
 
31
43
  export class HakoReference {
@@ -796,6 +808,32 @@ export class CollectionReference {
796
808
  return JSON.parse(json) as NearHit[];
797
809
  }
798
810
 
811
+ async createTraverseIndex(): Promise<void> {
812
+ ensureOk(this.client.nativeBindings().createTraverseIndex(this.client.engineHandle(), this.name), this.client.nativeBindings(), 'createTraverseIndex');
813
+ }
814
+
815
+ /** Graph BFS from a doc in this collection: [{collection, id, depth, doc}]. edge null = any ref field. */
816
+ async findPaths(id: string, direction: TraverseDirection = 'outgoing', edge: string | null = null, maxDepth = 10, k = 100): Promise<PathHit[]> {
817
+ const native = this.client.nativeBindings();
818
+ const dir = direction === 'incoming' ? 1 : direction === 'both' ? 2 : 0;
819
+ const json = native.engineFindPaths(this.client.engineHandle(), this.name, id, dir, edge, maxDepth, k);
820
+ if (json === null) throw new Error(`findPaths failed: ${native.lastError()}`);
821
+ return JSON.parse(json) as PathHit[];
822
+ }
823
+
824
+ async createEdgeIndex(): Promise<void> {
825
+ ensureOk(this.client.nativeBindings().createEdgeIndex(this.client.engineHandle(), this.name), this.client.nativeBindings(), 'createEdgeIndex');
826
+ }
827
+
828
+ /** Weighted shortest paths via an edge collection: cost-ordered [{collection, id, depth, cost, doc}]. */
829
+ async shortestPaths(id: string, via: string, weight: string | null = null, direction: TraverseDirection = 'outgoing', edge: string | null = null, maxDepth = 10, k = 100): Promise<PathHit[]> {
830
+ const native = this.client.nativeBindings();
831
+ const dir = direction === 'incoming' ? 1 : direction === 'both' ? 2 : 0;
832
+ const json = native.engineShortestPaths(this.client.engineHandle(), this.name, id, dir, edge, via, weight, maxDepth, k);
833
+ if (json === null) throw new Error(`shortestPaths failed: ${native.lastError()}`);
834
+ return JSON.parse(json) as PathHit[];
835
+ }
836
+
799
837
  async createFtsIndex(field: string): Promise<void> {
800
838
  ensureOk(this.client.nativeBindings().createFtsIndex(this.client.engineHandle(), this.name, field), this.client.nativeBindings(), 'createFtsIndex');
801
839
  }
package/src/native.ts CHANGED
@@ -184,6 +184,17 @@ export interface NativeBindings {
184
184
  // lastError); unindexed field returns "[]".
185
185
  createVectorIndex(engine: Handle, collection: string, field: string, dim: number, metric: number): number;
186
186
  engineFindNear(engine: Handle, collection: string, field: string, vec: Float32Array, k: number): string | null;
187
+
188
+ // Graph traversal (core >=0.14.0): one-shot BFS returns owned JSON
189
+ // [{collection, id, depth, doc}] (null = hard error, e.g. incoming
190
+ // into untracked — read lastError); missing anchor returns "[]".
191
+ // direction 0/1/2 = outgoing/incoming/both; edge null = any ref field.
192
+ createTraverseIndex(engine: Handle, collection: string): number;
193
+ engineFindPaths(engine: Handle, collection: string, id: string, direction: number, edge: string | null, maxDepth: number, k: number): string | null;
194
+ // Phase B (core >=0.15.0): edge registration + weighted Dijkstra
195
+ // (same hit shape, cost-ordered; cost rides each hit).
196
+ createEdgeIndex(engine: Handle, collection: string): number;
197
+ engineShortestPaths(engine: Handle, collection: string, id: string, direction: number, edge: string | null, via: string | null, weight: string | null, maxDepth: number, k: number): string | null;
187
198
 
188
199
  // Array API
189
200
  arrayNew(): Handle;
@@ -291,6 +302,10 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
291
302
  hk_engine_create_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.u32 },
292
303
  hk_engine_create_vector_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32], returns: FFIType.i32 },
293
304
  hk_engine_find_near: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
305
+ hk_engine_create_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
306
+ hk_engine_find_paths: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
307
+ hk_engine_create_edge_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
308
+ hk_engine_shortest_paths: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
294
309
 
295
310
  hk_batch_new: { args: [], returns: FFIType.ptr },
296
311
  hk_batch_free: { args: [FFIType.ptr], returns: FFIType.void },
@@ -579,6 +594,11 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
579
594
  // Float32Array crosses as its LE-f32 bytes (bun:ffi takes the typed
580
595
  // array as ptr, like docInsertBin takes bytes).
581
596
  engineFindNear: (engine, collection, field, vec, k) => ptrToStringAndFree(symbols.hk_engine_find_near(engine, toC(collection), toC(field), vec, vec.length, k)),
597
+ createTraverseIndex: (engine, collection) => symbols.hk_engine_create_traverse_index(engine, toC(collection)),
598
+ // Null edge crosses as NULL (any ref field); bun:ffi takes null for ptr/cstring.
599
+ engineFindPaths: (engine, collection, id, direction, edge, maxDepth, k) => ptrToStringAndFree(symbols.hk_engine_find_paths(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), maxDepth, k)),
600
+ createEdgeIndex: (engine, collection) => symbols.hk_engine_create_edge_index(engine, toC(collection)),
601
+ engineShortestPaths: (engine, collection, id, direction, edge, via, weight, maxDepth, k) => ptrToStringAndFree(symbols.hk_engine_shortest_paths(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), weight === null ? null : toC(weight), maxDepth, k)),
582
602
 
583
603
  // Array API
584
604
  arrayNew: () => symbols.hk_array_new(),
@@ -695,6 +715,10 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
695
715
  hk_engine_create_index: lib.func('uint32_t hk_engine_create_index(HK_Engine* engine, const char* collection, const char* fields_json)'),
696
716
  hk_engine_create_vector_index: lib.func('int hk_engine_create_vector_index(HK_Engine* engine, const char* collection, const char* field, uint32_t dim, uint32_t metric)'),
697
717
  hk_engine_find_near: lib.func('HeapStr hk_engine_find_near(HK_Engine* engine, const char* collection, const char* field, const float* vec, size_t len, size_t k)'),
718
+ hk_engine_create_traverse_index: lib.func('int hk_engine_create_traverse_index(HK_Engine* engine, const char* collection)'),
719
+ hk_engine_find_paths: lib.func('HeapStr hk_engine_find_paths(HK_Engine* engine, const char* collection, const char* doc_id, uint32_t direction, const char* edge, size_t max_depth, size_t k)'),
720
+ hk_engine_create_edge_index: lib.func('int hk_engine_create_edge_index(HK_Engine* engine, const char* collection)'),
721
+ hk_engine_shortest_paths: lib.func('HeapStr hk_engine_shortest_paths(HK_Engine* engine, const char* collection, const char* doc_id, uint32_t direction, const char* edge, const char* via, const char* weight, size_t max_depth, size_t k)'),
698
722
 
699
723
  hk_batch_new: lib.func('HK_Batch* hk_batch_new()'),
700
724
  hk_batch_free: lib.func('void hk_batch_free(HK_Batch* batch)'),
@@ -986,6 +1010,11 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
986
1010
  // LE-f32 bytes via Buffer over the Float32Array (koffi takes Buffer
987
1011
  // for float*, same as docInsertBin takes Buffer for uint8_t*).
988
1012
  engineFindNear: (engine, collection, field, vec, k) => fn.hk_engine_find_near(engine, collection, field, Buffer.from(vec.buffer, vec.byteOffset, vec.byteLength), vec.length, k),
1013
+ createTraverseIndex: (engine, collection) => fn.hk_engine_create_traverse_index(engine, collection),
1014
+ // Null edge crosses as NULL (koffi takes null for char*).
1015
+ engineFindPaths: (engine, collection, id, direction, edge, maxDepth, k) => fn.hk_engine_find_paths(engine, collection, id, direction, edge, maxDepth, k),
1016
+ createEdgeIndex: (engine, collection) => fn.hk_engine_create_edge_index(engine, collection),
1017
+ engineShortestPaths: (engine, collection, id, direction, edge, via, weight, maxDepth, k) => fn.hk_engine_shortest_paths(engine, collection, id, direction, edge, via, weight, maxDepth, k),
989
1018
 
990
1019
  // Array API
991
1020
  arrayNew: () => fn.hk_array_new(),