@hakodb/client 0.6.5 → 0.6.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hakodb/client",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "description": "High-level HakoDB JavaScript/TypeScript client for Node.js and Bun",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,40 @@
1
+ // Smoke: projected FFI query keeps ORDER BY on an unselected field (hakodb #237).
2
+ import { loadNativeBindings } from './src/native.ts';
3
+ import { mkdtempSync, rmSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+
7
+ const dir = mkdtempSync(join(tmpdir(), 'hakojs-order-'));
8
+ try {
9
+ const n = await loadNativeBindings(process.env.HAKODB_LIB ?? 'C:/Dev/libs/hakodb/target/release/hakodb.dll');
10
+ const engine = n.engineOpen(dir);
11
+ for (const [id, name, age] of [['u1', 'alice', 30], ['u2', 'bob', 40]]) {
12
+ const doc = n.docNew();
13
+ n.docInsertStr(doc, 'name', name);
14
+ n.docInsertInt(doc, 'age', age);
15
+ if (n.engineInsert(engine, 'users', id, doc) !== 0) throw new Error('insert failed');
16
+ n.docFree(doc);
17
+ }
18
+ const q = n.queryNew('users');
19
+ n.queryOrderBy(q, 'age', false);
20
+ n.querySelectField(q, 'name');
21
+ n.queryLimit(q, 10);
22
+ const rows = JSON.parse(n.queryExecute(engine, q) ?? '[]');
23
+ n.queryFree(q);
24
+ if (rows.length !== 2) throw new Error(`expected 2 rows, got ${rows.length}`);
25
+ if (rows[0].name !== 'bob') throw new Error(`wrong first row: ${JSON.stringify(rows)}`);
26
+ if ('age' in rows[0]) throw new Error(`age must be pruned: ${JSON.stringify(rows)}`);
27
+ console.log('OK: order-by-outside-select projected query', JSON.stringify(rows));
28
+ const cancel = n.cancelNew();
29
+ n.cancel(cancel);
30
+ const q2 = n.queryNew('users');
31
+ n.queryLimit(q2, 10);
32
+ const cancelled = n.queryExecuteWithCancel(engine, q2, cancel);
33
+ n.queryFree(q2);
34
+ n.cancelFree(cancel);
35
+ if (cancelled !== null) throw new Error(`cancelled query should return null: ${cancelled}`);
36
+ n.engineFree(engine);
37
+ console.log('OK: cancel token aborts query');
38
+ } finally {
39
+ rmSync(dir, { recursive: true, force: true });
40
+ }
package/src/native.ts CHANGED
@@ -115,6 +115,10 @@ export interface NativeBindings {
115
115
  queryOffset(query: Handle, offset: number): number;
116
116
  querySelectField(query: Handle, field: string): number;
117
117
  queryExecute(engine: Handle, query: Handle): string | null;
118
+ queryExecuteWithCancel(engine: Handle, query: Handle, cancel: Handle): string | null;
119
+ cancelNew(): Handle;
120
+ cancel(cancel: Handle): void;
121
+ cancelFree(cancel: Handle): void;
118
122
  queryDelete(engine: Handle, query: Handle): number;
119
123
  queryDeleteLocal(engine: Handle, query: Handle): number;
120
124
  queryPatch(engine: Handle, query: Handle, patchDoc: Handle): number;
@@ -213,6 +217,7 @@ export interface NativeBindings {
213
217
  dropTraverseIndex(engine: Handle, collection: string): number;
214
218
  createVectorIndexV2(engine: Handle, collection: string, field: string, dim: number, metric: number, m: number, efConstruction: number, efSearch: number, binaryStage1: number): number;
215
219
  findPathsFull(engine: Handle, collection: string, id: string, direction: number, edge: string | null, via: string | null, maxDepth: number, k: number, includePath: boolean, includeVia: boolean, nodeField: string | null, nodeJSON: string | null, typeField: string | null, typeJSON: string | null, matchField: string | null, matchJSON: string | null): string | null;
220
+ findPathsCount(engine: Handle, collection: string, id: string, direction: number, edge: string | null, maxDepth: number, k: number): bigint;
216
221
  simplePathsFull(engine: Handle, collection: string, id: string, direction: number, edge: string | null, via: string | null, weight: string | null, maxDepth: number, k: number, includePath: boolean, includeVia: boolean, nodeField: string | null, nodeJSON: string | null, typeField: string | null, typeJSON: string | null, matchField: string | null, matchJSON: string | null): string | null;
217
222
  exportGraph(engine: Handle, collection: string, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null): string | null;
218
223
  graphAnalysis(engine: Handle, collection: string, op: string, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null): string | null;
@@ -448,6 +453,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
448
453
  hk_engine_find_near_scored_filtered: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize, FFIType.f64, FFIType.cstring], returns: FFIType.ptr },
449
454
  hk_engine_subgraph_json_projected: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.usize, FFIType.cstring], returns: FFIType.ptr },
450
455
  hk_engine_find_paths_v4: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.usize, FFIType.usize, FFIType.u32, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
456
+ hk_engine_find_paths_count: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.usize, FFIType.usize], returns: FFIType.i64 },
451
457
  hk_engine_find_simple_paths_v3: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.usize, FFIType.usize, FFIType.u32, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
452
458
  hk_engine_export_graph: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
453
459
  hk_engine_graph_analysis: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
@@ -489,6 +495,10 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
489
495
  hk_query_offset: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
490
496
  hk_query_select_field: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
491
497
  hk_query_execute: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
498
+ hk_query_execute_with_cancel: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
499
+ hk_cancel_new: { args: [], returns: FFIType.ptr },
500
+ hk_cancel: { args: [FFIType.ptr], returns: FFIType.void },
501
+ hk_cancel_free: { args: [FFIType.ptr], returns: FFIType.void },
492
502
  hk_query_delete: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
493
503
  hk_query_delete_local: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
494
504
  hk_query_patch: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
@@ -757,6 +767,10 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
757
767
  queryOffset: (query, offset) => symbols.hk_query_offset(query, offset),
758
768
  querySelectField: (query, field) => symbols.hk_query_select_field(query, toC(field)),
759
769
  queryExecute: (engine, query) => ptrToStringAndFree(symbols.hk_query_execute(engine, query)),
770
+ queryExecuteWithCancel: (engine, query, cancel) => ptrToStringAndFree(symbols.hk_query_execute_with_cancel(engine, query, cancel)),
771
+ cancelNew: () => symbols.hk_cancel_new(),
772
+ cancel: (cancel) => symbols.hk_cancel(cancel),
773
+ cancelFree: (cancel) => symbols.hk_cancel_free(cancel),
760
774
  queryDelete: (engine, query) => symbols.hk_query_delete(engine, query),
761
775
  queryDeleteLocal: (engine, query) => symbols.hk_query_delete_local(engine, query),
762
776
  queryPatch: (engine, query, patchDoc) => symbols.hk_query_patch(engine, query, patchDoc),
@@ -838,6 +852,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
838
852
  dropTraverseIndex: (engine, collection) => symbols.hk_engine_drop_traverse_index(engine, toC(collection)),
839
853
  createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1) => symbols.hk_engine_create_vector_index_v2(engine, toC(collection), toC(field), dim, metric, m, efConstruction, efSearch, binaryStage1),
840
854
  findPathsFull: (engine, collection, id, direction, edge, via, maxDepth, k, includePath, includeVia, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON) => ptrToStringAndFree(symbols.hk_engine_find_paths_v4(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), maxDepth, k, includePath ? 1 : 0, includeVia ? 1 : 0, nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), typeField === null ? null : toC(typeField), typeJSON === null ? null : toC(typeJSON), matchField === null ? null : toC(matchField), matchJSON === null ? null : toC(matchJSON))),
855
+ findPathsCount: (engine, collection, id, direction, edge, maxDepth, k) => symbols.hk_engine_find_paths_count(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), maxDepth, k),
841
856
  simplePathsFull: (engine, collection, id, direction, edge, via, weight, maxDepth, k, includePath, includeVia, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON) => ptrToStringAndFree(symbols.hk_engine_find_simple_paths_v3(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), weight === null ? null : toC(weight), maxDepth, k, includePath ? 1 : 0, includeVia ? 1 : 0, nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), typeField === null ? null : toC(typeField), typeJSON === null ? null : toC(typeJSON), matchField === null ? null : toC(matchField), matchJSON === null ? null : toC(matchJSON))),
842
857
  exportGraph: (engine, collection, direction, edge, via, nodeField, nodeJSON) => ptrToStringAndFree(symbols.hk_engine_export_graph(engine, toC(collection), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON))),
843
858
  graphAnalysis: (engine, collection, op, direction, edge, via, nodeField, nodeJSON) => ptrToStringAndFree(symbols.hk_engine_graph_analysis(engine, toC(collection), toC(op), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON))),
@@ -996,7 +1011,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
996
1011
  // these EVERY struct-typed decl throws at bindings creation, i.e. the
997
1012
  // node backend was dead on arrival (bun resolves pointers structurally
998
1013
  // and never noticed). Declared once here for all present and future fns.
999
- for (const t of ['HK_Array', 'HK_Batch', 'HK_CloudSync', 'HK_Config', 'HK_Doc', 'HK_Engine', 'HK_NetSyncer', 'HK_Pipeline', 'HK_Query', 'HK_RawDoc', 'HK_RawResultSet', 'HK_ResultSet', 'HK_Transaction', 'HK_ViewDoc', 'HK_Watch']) koffi.opaque(t);
1014
+ for (const t of ['HK_Array', 'HK_Batch', 'HK_Cancel', 'HK_CloudSync', 'HK_Config', 'HK_Doc', 'HK_Engine', 'HK_NetSyncer', 'HK_Pipeline', 'HK_Query', 'HK_RawDoc', 'HK_RawResultSet', 'HK_ResultSet', 'HK_Transaction', 'HK_ViewDoc', 'HK_Watch']) koffi.opaque(t);
1000
1015
 
1001
1016
  // ponytail: owned C strings (Rust-allocated) must come back through a
1002
1017
  // DISPOSABLE type wired to hk_string_free — never bare char* (koffi
@@ -1104,6 +1119,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1104
1119
  hk_engine_find_near_scored_filtered: lib.func('HeapStr hk_engine_find_near_scored_filtered(HK_Engine* engine, const char* collection, const char* field, const float* vec, size_t vec_len, size_t k, double max_distance, const char* filters_json)'),
1105
1120
  hk_engine_subgraph_json_projected: lib.func('HeapStr hk_engine_subgraph_json_projected(HK_Engine* engine, const char* collection, const char* seed_id, uint32_t max_depth, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json, size_t node_cap, const char* fields_json)'),
1106
1121
  hk_engine_find_paths_v4: lib.func('HeapStr hk_engine_find_paths_v4(HK_Engine* engine, const char* collection, const char* doc_id, uint32_t direction, const char* edge, const char* via, size_t max_depth, size_t k, uint32_t include_path, uint32_t include_via, const char* filter_field, const char* filter_json, const char* type_field, const char* type_json, const char* match_field, const char* match_json)'),
1122
+ hk_engine_find_paths_count: lib.func('int64_t hk_engine_find_paths_count(HK_Engine* engine, const char* collection, const char* doc_id, uint32_t direction, const char* edge_field, size_t max_depth, size_t k)'),
1107
1123
  hk_engine_find_simple_paths_v3: lib.func('HeapStr hk_engine_find_simple_paths_v3(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, uint32_t include_path, uint32_t include_via, const char* filter_field, const char* filter_json, const char* type_field, const char* type_json, const char* match_field, const char* match_json)'),
1108
1124
  hk_engine_export_graph: lib.func('HeapStr hk_engine_export_graph(HK_Engine* engine, const char* collection, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json)'),
1109
1125
  hk_engine_graph_analysis: lib.func('HeapStr hk_engine_graph_analysis(HK_Engine* engine, const char* collection, const char* op, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json)'),
@@ -1147,6 +1163,10 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1147
1163
  hk_query_offset: lib.func('int hk_query_offset(HK_Query* query, size_t offset)'),
1148
1164
  hk_query_select_field: lib.func('int hk_query_select_field(HK_Query* query, const char* field)'),
1149
1165
  hk_query_execute: lib.func('HeapStr hk_query_execute(HK_Engine* engine, const HK_Query* query)'),
1166
+ hk_query_execute_with_cancel: lib.func('HeapStr hk_query_execute_with_cancel(HK_Engine* engine, const HK_Query* query, HK_Cancel* cancel)'),
1167
+ hk_cancel_new: lib.func('HK_Cancel* hk_cancel_new()'),
1168
+ hk_cancel: lib.func('void hk_cancel(HK_Cancel* cancel)'),
1169
+ hk_cancel_free: lib.func('void hk_cancel_free(HK_Cancel* cancel)'),
1150
1170
  hk_query_delete: lib.func('int hk_query_delete(HK_Engine* engine, HK_Query* query)'),
1151
1171
  hk_query_delete_local: lib.func('int hk_query_delete_local(HK_Engine* engine, HK_Query* query)'),
1152
1172
  hk_query_patch: lib.func('int hk_query_patch(HK_Engine* engine, HK_Query* query, const HK_Doc* patch_doc)'),
@@ -1406,6 +1426,10 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1406
1426
  queryOffset: (query, offset) => fn.hk_query_offset(query, offset),
1407
1427
  querySelectField: (query, field) => fn.hk_query_select_field(query, field),
1408
1428
  queryExecute: (engine, query) => ptrToStringAndFree(fn.hk_query_execute(engine, query)),
1429
+ queryExecuteWithCancel: (engine, query, cancel) => ptrToStringAndFree(fn.hk_query_execute_with_cancel(engine, query, cancel)),
1430
+ cancelNew: () => fn.hk_cancel_new(),
1431
+ cancel: (cancel) => fn.hk_cancel(cancel),
1432
+ cancelFree: (cancel) => fn.hk_cancel_free(cancel),
1409
1433
  queryDelete: (engine, query) => fn.hk_query_delete(engine, query),
1410
1434
  queryDeleteLocal: (engine, query) => fn.hk_query_delete_local(engine, query),
1411
1435
  queryPatch: (engine, query, patchDoc) => fn.hk_query_patch(engine, query, patchDoc),
@@ -1487,6 +1511,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1487
1511
  dropTraverseIndex: (engine, collection) => fn.hk_engine_drop_traverse_index(engine, collection),
1488
1512
  createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1) => fn.hk_engine_create_vector_index_v2(engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1),
1489
1513
  findPathsFull: (engine, collection, id, direction, edge, via, maxDepth, k, includePath, includeVia, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON) => fn.hk_engine_find_paths_v4(engine, collection, id, direction, edge, via, maxDepth, k, includePath ? 1 : 0, includeVia ? 1 : 0, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON),
1514
+ findPathsCount: (engine, collection, id, direction, edge, maxDepth, k) => fn.hk_engine_find_paths_count(engine, collection, id, direction, edge, maxDepth, k),
1490
1515
  simplePathsFull: (engine, collection, id, direction, edge, via, weight, maxDepth, k, includePath, includeVia, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON) => fn.hk_engine_find_simple_paths_v3(engine, collection, id, direction, edge, via, weight, maxDepth, k, includePath ? 1 : 0, includeVia ? 1 : 0, nodeField, nodeJSON, typeField, typeJSON, matchField, matchJSON),
1491
1516
  exportGraph: (engine, collection, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_export_graph(engine, collection, direction, edge, via, nodeField, nodeJSON),
1492
1517
  graphAnalysis: (engine, collection, op, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_graph_analysis(engine, collection, op, direction, edge, via, nodeField, nodeJSON),