@hakodb/client 0.5.17 → 0.5.19

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
@@ -15,6 +15,7 @@ FFI bindings over koffi/Bun (`native.ts`). Tauri lives in `@hakodb/tauri`
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
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`) |
18
19
 
19
20
  ## Setup — native library
20
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hakodb/client",
3
- "version": "0.5.17",
3
+ "version": "0.5.19",
4
4
  "description": "High-level HakoDB JavaScript/TypeScript client for Node.js and Bun",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,5 +27,8 @@
27
27
  "devDependencies": {
28
28
  "@types/node": "^26.1.2",
29
29
  "typescript": "^7.0.2"
30
+ },
31
+ "scripts": {
32
+ "test": "tsc --noEmit -p tsconfig.json"
30
33
  }
31
34
  }
package/src/client.ts CHANGED
@@ -34,6 +34,7 @@ export interface PathHit {
34
34
  collection: string;
35
35
  id: string;
36
36
  depth: number;
37
+ cost?: number;
37
38
  doc: HakoDocData;
38
39
  }
39
40
 
@@ -820,6 +821,19 @@ export class CollectionReference {
820
821
  return JSON.parse(json) as PathHit[];
821
822
  }
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
+
823
837
  async createFtsIndex(field: string): Promise<void> {
824
838
  ensureOk(this.client.nativeBindings().createFtsIndex(this.client.engineHandle(), this.name, field), this.client.nativeBindings(), 'createFtsIndex');
825
839
  }
package/src/native.ts CHANGED
@@ -191,6 +191,10 @@ export interface NativeBindings {
191
191
  // direction 0/1/2 = outgoing/incoming/both; edge null = any ref field.
192
192
  createTraverseIndex(engine: Handle, collection: string): number;
193
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;
194
198
 
195
199
  // Array API
196
200
  arrayNew(): Handle;
@@ -300,6 +304,8 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
300
304
  hk_engine_find_near: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
301
305
  hk_engine_create_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
302
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 },
303
309
 
304
310
  hk_batch_new: { args: [], returns: FFIType.ptr },
305
311
  hk_batch_free: { args: [FFIType.ptr], returns: FFIType.void },
@@ -591,6 +597,8 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
591
597
  createTraverseIndex: (engine, collection) => symbols.hk_engine_create_traverse_index(engine, toC(collection)),
592
598
  // Null edge crosses as NULL (any ref field); bun:ffi takes null for ptr/cstring.
593
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)),
594
602
 
595
603
  // Array API
596
604
  arrayNew: () => symbols.hk_array_new(),
@@ -709,6 +717,8 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
709
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)'),
710
718
  hk_engine_create_traverse_index: lib.func('int hk_engine_create_traverse_index(HK_Engine* engine, const char* collection)'),
711
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)'),
712
722
 
713
723
  hk_batch_new: lib.func('HK_Batch* hk_batch_new()'),
714
724
  hk_batch_free: lib.func('void hk_batch_free(HK_Batch* batch)'),
@@ -1003,6 +1013,8 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1003
1013
  createTraverseIndex: (engine, collection) => fn.hk_engine_create_traverse_index(engine, collection),
1004
1014
  // Null edge crosses as NULL (koffi takes null for char*).
1005
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),
1006
1018
 
1007
1019
  // Array API
1008
1020
  arrayNew: () => fn.hk_array_new(),