@hakodb/client 0.6.4 → 0.6.6
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 +1 -1
- package/smoke-order-select.mjs +40 -0
- package/src/native.ts +52 -1
package/package.json
CHANGED
|
@@ -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;
|
|
@@ -219,6 +223,13 @@ export interface NativeBindings {
|
|
|
219
223
|
graphPagerank(engine: Handle, collection: string, seeds: string | null, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null, damping: number, top: number): string | null;
|
|
220
224
|
subgraph(engine: Handle, collection: string, seedId: string, maxDepth: number, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null, nodeCap: number): string | null;
|
|
221
225
|
hybridSearch(engine: Handle, collection: string, textField: string, textQuery: string, vecField: string, vec: Float32Array, k: number, rrfK: number): string | null;
|
|
226
|
+
// v0.21.0 parity (#217 wave): exclusive open, idempotent boot schema,
|
|
227
|
+
// filtered hybrid/KNN, subgraph projection.
|
|
228
|
+
engineOpenExclusive(path: string): Handle;
|
|
229
|
+
engineEnsureIndexes(engine: Handle, schemaJson: string): number;
|
|
230
|
+
hybridSearchFiltered(engine: Handle, collection: string, textField: string, textQuery: string, vecField: string, vec: Float32Array, k: number, rrfK: number, filtersJson: string | null): string | null;
|
|
231
|
+
findNearScoredFiltered(engine: Handle, collection: string, vecField: string, vec: Float32Array, k: number, maxDistance: number, filtersJson: string | null): string | null;
|
|
232
|
+
subgraphProjected(engine: Handle, collection: string, seedId: string, maxDepth: number, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null, nodeCap: number, fieldsJson: string | null): string | null;
|
|
222
233
|
insertJSON(engine: Handle, collection: string, id: string, json: string): number;
|
|
223
234
|
batchSetJSON(batch: Handle, collection: string, id: string, json: string): number;
|
|
224
235
|
|
|
@@ -434,6 +445,12 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
434
445
|
hk_engine_graph_pagerank: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.f64, FFIType.usize], returns: FFIType.ptr },
|
|
435
446
|
hk_engine_subgraph: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.usize], returns: FFIType.ptr },
|
|
436
447
|
hk_engine_hybrid_search: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
|
|
448
|
+
// v0.21.0 parity (#217 wave)
|
|
449
|
+
hk_engine_open_exclusive: { args: [FFIType.cstring], returns: FFIType.ptr },
|
|
450
|
+
hk_engine_ensure_indexes: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
451
|
+
hk_engine_hybrid_search_filtered: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize, FFIType.usize, FFIType.cstring], returns: FFIType.ptr },
|
|
452
|
+
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 },
|
|
453
|
+
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 },
|
|
437
454
|
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 },
|
|
438
455
|
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 },
|
|
439
456
|
hk_engine_export_graph: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
@@ -476,6 +493,10 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
476
493
|
hk_query_offset: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
477
494
|
hk_query_select_field: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
478
495
|
hk_query_execute: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
496
|
+
hk_query_execute_with_cancel: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
497
|
+
hk_cancel_new: { args: [], returns: FFIType.ptr },
|
|
498
|
+
hk_cancel: { args: [FFIType.ptr], returns: FFIType.void },
|
|
499
|
+
hk_cancel_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
479
500
|
hk_query_delete: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
480
501
|
hk_query_delete_local: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
481
502
|
hk_query_patch: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
@@ -619,6 +640,12 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
619
640
|
|
|
620
641
|
return {
|
|
621
642
|
engineOpen: (path) => symbols.hk_engine_open(toC(path)),
|
|
643
|
+
// v0.21.0 parity (#217 wave)
|
|
644
|
+
engineOpenExclusive: (path) => symbols.hk_engine_open_exclusive(toC(path)),
|
|
645
|
+
engineEnsureIndexes: (engine, schemaJson) => symbols.hk_engine_ensure_indexes(engine, toC(schemaJson)),
|
|
646
|
+
hybridSearchFiltered: (engine, collection, textField, textQuery, vecField, vec, k, rrfK, filtersJson) => ptrToStringAndFree(symbols.hk_engine_hybrid_search_filtered(engine, toC(collection), toC(textField), toC(textQuery), toC(vecField), vec, vec.length, k, rrfK, filtersJson === null ? null : toC(filtersJson))),
|
|
647
|
+
findNearScoredFiltered: (engine, collection, vecField, vec, k, maxDistance, filtersJson) => ptrToStringAndFree(symbols.hk_engine_find_near_scored_filtered(engine, toC(collection), toC(vecField), vec, vec.length, k, maxDistance, filtersJson === null ? null : toC(filtersJson))),
|
|
648
|
+
subgraphProjected: (engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap, fieldsJson) => ptrToStringAndFree(symbols.hk_engine_subgraph_json_projected(engine, toC(collection), toC(seedId), maxDepth, direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), nodeCap, fieldsJson === null ? null : toC(fieldsJson))),
|
|
622
649
|
engineIsIndexesReady: (engine) => symbols.hk_engine_is_indexes_ready(engine),
|
|
623
650
|
engineOpenWithConfig: (path, config) => symbols.hk_engine_open_with_config(toC(path), config),
|
|
624
651
|
engineFree: (engine) => symbols.hk_engine_free(engine),
|
|
@@ -738,6 +765,10 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
738
765
|
queryOffset: (query, offset) => symbols.hk_query_offset(query, offset),
|
|
739
766
|
querySelectField: (query, field) => symbols.hk_query_select_field(query, toC(field)),
|
|
740
767
|
queryExecute: (engine, query) => ptrToStringAndFree(symbols.hk_query_execute(engine, query)),
|
|
768
|
+
queryExecuteWithCancel: (engine, query, cancel) => ptrToStringAndFree(symbols.hk_query_execute_with_cancel(engine, query, cancel)),
|
|
769
|
+
cancelNew: () => symbols.hk_cancel_new(),
|
|
770
|
+
cancel: (cancel) => symbols.hk_cancel(cancel),
|
|
771
|
+
cancelFree: (cancel) => symbols.hk_cancel_free(cancel),
|
|
741
772
|
queryDelete: (engine, query) => symbols.hk_query_delete(engine, query),
|
|
742
773
|
queryDeleteLocal: (engine, query) => symbols.hk_query_delete_local(engine, query),
|
|
743
774
|
queryPatch: (engine, query, patchDoc) => symbols.hk_query_patch(engine, query, patchDoc),
|
|
@@ -977,7 +1008,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
977
1008
|
// these EVERY struct-typed decl throws at bindings creation, i.e. the
|
|
978
1009
|
// node backend was dead on arrival (bun resolves pointers structurally
|
|
979
1010
|
// and never noticed). Declared once here for all present and future fns.
|
|
980
|
-
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);
|
|
1011
|
+
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);
|
|
981
1012
|
|
|
982
1013
|
// ponytail: owned C strings (Rust-allocated) must come back through a
|
|
983
1014
|
// DISPOSABLE type wired to hk_string_free — never bare char* (koffi
|
|
@@ -1078,6 +1109,12 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1078
1109
|
hk_engine_graph_pagerank: lib.func('HeapStr hk_engine_graph_pagerank(HK_Engine* engine, const char* collection, const char* seeds_json, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json, double damping, size_t top)'),
|
|
1079
1110
|
hk_engine_subgraph: lib.func('HeapStr hk_engine_subgraph(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)'),
|
|
1080
1111
|
hk_engine_hybrid_search: lib.func('HeapStr hk_engine_hybrid_search(HK_Engine* engine, const char* collection, const char* text_field, const char* text_query, const char* vec_field, const float* vec, size_t vec_len, size_t k, size_t rrf_k)'),
|
|
1112
|
+
// v0.21.0 parity (#217 wave)
|
|
1113
|
+
hk_engine_open_exclusive: lib.func('HK_Engine* hk_engine_open_exclusive(const char* path)'),
|
|
1114
|
+
hk_engine_ensure_indexes: lib.func('int hk_engine_ensure_indexes(HK_Engine* engine, const char* schema_json)'),
|
|
1115
|
+
hk_engine_hybrid_search_filtered: lib.func('HeapStr hk_engine_hybrid_search_filtered(HK_Engine* engine, const char* collection, const char* text_field, const char* text_query, const char* vec_field, const float* vec, size_t vec_len, size_t k, size_t rrf_k, const char* filters_json)'),
|
|
1116
|
+
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)'),
|
|
1117
|
+
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)'),
|
|
1081
1118
|
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)'),
|
|
1082
1119
|
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)'),
|
|
1083
1120
|
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)'),
|
|
@@ -1122,6 +1159,10 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1122
1159
|
hk_query_offset: lib.func('int hk_query_offset(HK_Query* query, size_t offset)'),
|
|
1123
1160
|
hk_query_select_field: lib.func('int hk_query_select_field(HK_Query* query, const char* field)'),
|
|
1124
1161
|
hk_query_execute: lib.func('HeapStr hk_query_execute(HK_Engine* engine, const HK_Query* query)'),
|
|
1162
|
+
hk_query_execute_with_cancel: lib.func('HeapStr hk_query_execute_with_cancel(HK_Engine* engine, const HK_Query* query, HK_Cancel* cancel)'),
|
|
1163
|
+
hk_cancel_new: lib.func('HK_Cancel* hk_cancel_new()'),
|
|
1164
|
+
hk_cancel: lib.func('void hk_cancel(HK_Cancel* cancel)'),
|
|
1165
|
+
hk_cancel_free: lib.func('void hk_cancel_free(HK_Cancel* cancel)'),
|
|
1125
1166
|
hk_query_delete: lib.func('int hk_query_delete(HK_Engine* engine, HK_Query* query)'),
|
|
1126
1167
|
hk_query_delete_local: lib.func('int hk_query_delete_local(HK_Engine* engine, HK_Query* query)'),
|
|
1127
1168
|
hk_query_patch: lib.func('int hk_query_patch(HK_Engine* engine, HK_Query* query, const HK_Doc* patch_doc)'),
|
|
@@ -1270,6 +1311,12 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1270
1311
|
|
|
1271
1312
|
return {
|
|
1272
1313
|
engineOpen: (path) => fn.hk_engine_open(path),
|
|
1314
|
+
// v0.21.0 parity (#217 wave) — koffi takes null for char* directly
|
|
1315
|
+
engineOpenExclusive: (path) => fn.hk_engine_open_exclusive(path),
|
|
1316
|
+
engineEnsureIndexes: (engine, schemaJson) => fn.hk_engine_ensure_indexes(engine, schemaJson),
|
|
1317
|
+
hybridSearchFiltered: (engine, collection, textField, textQuery, vecField, vec, k, rrfK, filtersJson) => fn.hk_engine_hybrid_search_filtered(engine, collection, textField, textQuery, vecField, Buffer.from(vec.buffer, vec.byteOffset, vec.byteLength), vec.length, k, rrfK, filtersJson),
|
|
1318
|
+
findNearScoredFiltered: (engine, collection, vecField, vec, k, maxDistance, filtersJson) => fn.hk_engine_find_near_scored_filtered(engine, collection, vecField, Buffer.from(vec.buffer, vec.byteOffset, vec.byteLength), vec.length, k, maxDistance, filtersJson),
|
|
1319
|
+
subgraphProjected: (engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap, fieldsJson) => fn.hk_engine_subgraph_json_projected(engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap, fieldsJson),
|
|
1273
1320
|
engineIsIndexesReady: (engine) => fn.hk_engine_is_indexes_ready(engine),
|
|
1274
1321
|
engineOpenWithConfig: (path, config) => fn.hk_engine_open_with_config(path, config),
|
|
1275
1322
|
engineFree: (engine) => fn.hk_engine_free(engine),
|
|
@@ -1375,6 +1422,10 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1375
1422
|
queryOffset: (query, offset) => fn.hk_query_offset(query, offset),
|
|
1376
1423
|
querySelectField: (query, field) => fn.hk_query_select_field(query, field),
|
|
1377
1424
|
queryExecute: (engine, query) => ptrToStringAndFree(fn.hk_query_execute(engine, query)),
|
|
1425
|
+
queryExecuteWithCancel: (engine, query, cancel) => ptrToStringAndFree(fn.hk_query_execute_with_cancel(engine, query, cancel)),
|
|
1426
|
+
cancelNew: () => fn.hk_cancel_new(),
|
|
1427
|
+
cancel: (cancel) => fn.hk_cancel(cancel),
|
|
1428
|
+
cancelFree: (cancel) => fn.hk_cancel_free(cancel),
|
|
1378
1429
|
queryDelete: (engine, query) => fn.hk_query_delete(engine, query),
|
|
1379
1430
|
queryDeleteLocal: (engine, query) => fn.hk_query_delete_local(engine, query),
|
|
1380
1431
|
queryPatch: (engine, query, patchDoc) => fn.hk_query_patch(engine, query, patchDoc),
|