@hakodb/client 0.7.2 → 0.7.4

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
@@ -25,3 +25,31 @@ Works against the corresponding core release; each release pairs with a matching
25
25
  ```
26
26
 
27
27
  Binaries under `native/` are git-ignored.
28
+
29
+ ## API guidance: query and write paths
30
+
31
+ Consumers should not have to guess which execution or write entry point to use. The core exposes one canonical executor plus advisory-deprecated wrappers and several materialization lanes with different costs.
32
+
33
+ ### Execution lanes
34
+
35
+ | Lane | Returns | Use when |
36
+ |---|---|---|
37
+ | canonical executor (`hk_query_execute_ex` / SDK default) | JSON documents for an application | ordinary API calls |
38
+ | JSON egress (`hk_query_execute_json`) | JSON from pinned bytes, no owned document | wire/egress output |
39
+ | handles (`hk_query_execute_to_handles`) | borrowed document handles | engine throughput, caller reads selected fields |
40
+ | raw (`hk_query_execute_raw`) | pinned storage bytes | index-satisfied scans, zero decode |
41
+ | aggregation / explain | aggregate values or plan report | tuning and aggregate-only queries |
42
+
43
+ Do not compare a JSON-document lane with an engine-only lane and call it the same benchmark. Mark lanes without an equivalent in another engine as not applicable.
44
+
45
+ ### In this repository
46
+
47
+ - Query.get({ mode: "docs" | "json" | "handles" | "raw" }) is the single entry point; getJson() is a deprecated alias
48
+ - queryExecuteEx is canonical; queryExecute/queryExecuteWithCancel are legacy wrappers
49
+ - insertJSON for one document, batch().setJSON() for bulk writes
50
+ - HakoConfig durability and awaitQuiescent before measuring or paging
51
+
52
+ ### Further reading
53
+
54
+ - Core decision table: https://github.com/hakodb/hakodb/blob/main/docs/ffi-query-lanes.md
55
+ - Manual C ABI chapter: https://hakodb.github.io/manual/sdk-c-abi.html
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hakodb/client",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "High-level HakoDB JavaScript/TypeScript client for Node.js and Bun",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,20 +41,48 @@ def bound_symbols(path: Path) -> set[str]:
41
41
  return found - {"hk_socket_sync_"}
42
42
 
43
43
 
44
+ def backend_sections(text: str):
45
+ bun = text[text.index("async function createBunBindings"):text.index("async function createNodeBindings")]
46
+ node = text[text.index("async function createNodeBindings"):text.index("export async function loadNativeBindings")]
47
+ return bun, node
48
+
49
+
50
+ def backend_missing(text: str) -> dict:
51
+ bun, node = backend_sections(text)
52
+ bun_declared = set(re.findall(r"\b(hk_[a-z0-9_]+):\s*\{", bun))
53
+ bun_used = set(re.findall(r"symbols\.(hk_[a-z0-9_]+)", bun))
54
+ node_declared = set(re.findall(r"\b(hk_[a-z0-9_]+):\s*lib\.func", node))
55
+ node_declared |= set(re.findall(r"lib\.func\('[^']*\b(hk_[a-z0-9_]+)\(", node))
56
+ node_used = set(re.findall(r"\bfn\.(hk_[a-z0-9_]+)", node))
57
+ return {
58
+ "bun": sorted(bun_used - bun_declared),
59
+ "node": sorted(node_used - node_declared),
60
+ }
61
+
62
+
44
63
  def main() -> int:
45
64
  if not HEADER.exists() or not BINDINGS.exists():
46
65
  print(f"missing input: header={HEADER} bindings={BINDINGS}", file=sys.stderr)
47
66
  return 2
67
+ text = BINDINGS.read_text(encoding="utf-8")
48
68
  header = header_functions(HEADER)
49
69
  bound = bound_symbols(BINDINGS)
50
70
  missing = sorted(header - bound - ALLOW_UNBOUND)
51
71
  stale = sorted(bound - header)
72
+ backend = backend_missing(text)
52
73
  print(f"header functions: {len(header)}, bound symbols: {len(bound)}")
74
+ failed = False
53
75
  if missing:
54
76
  print("unbound and not allowlisted:", ", ".join(missing), file=sys.stderr)
77
+ failed = True
55
78
  if stale:
56
79
  print("bound symbols absent from header:", ", ".join(stale), file=sys.stderr)
57
- if missing or stale:
80
+ failed = True
81
+ for name, symbols in backend.items():
82
+ if symbols:
83
+ print(f"{name} wrappers using undeclared symbols:", ", ".join(symbols), file=sys.stderr)
84
+ failed = True
85
+ if failed:
58
86
  return 1
59
87
  print("FFI binding parity: OK")
60
88
  return 0
package/src/client.ts CHANGED
@@ -713,6 +713,29 @@ export class HakoClient {
713
713
  return id;
714
714
  }
715
715
 
716
+ /**
717
+ * Declare multiple secondary and composite indexes in one pass. Returns the
718
+ * composite ids in order. Use this instead of N createIndex calls when a
719
+ * collection is populated before its indexes are declared.
720
+ */
721
+ async createIndexes(
722
+ collection: string,
723
+ fields: string[],
724
+ composites: { field: string; desc?: boolean }[][],
725
+ ): Promise<number[]> {
726
+ this.assertOpen();
727
+ const json = this.native.engineCreateIndexes(
728
+ this.engine,
729
+ collection,
730
+ JSON.stringify(fields),
731
+ JSON.stringify(composites.map(group =>
732
+ group.map(f => ({ field: f.field, dir: f.desc ? 'desc' : 'asc' })),
733
+ )),
734
+ );
735
+ if (!json) throw new Error(`engineCreateIndexes failed: ${this.native.lastError()}`);
736
+ return JSON.parse(json) as number[];
737
+ }
738
+
716
739
  async runTransaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T> {
717
740
  this.assertOpen();
718
741
  const tx = new Transaction(this.native, this.engine);
@@ -1110,6 +1133,11 @@ export class CollectionReference {
1110
1133
  return this.client.createCompositeIndex(this.name, fields);
1111
1134
  }
1112
1135
 
1136
+ /** One-pass equivalent of multiple createIndex/createCompositeIndex calls. */
1137
+ async createIndexes(fields: string[], composites: { field: string; desc?: boolean }[][]): Promise<number[]> {
1138
+ return this.client.createIndexes(this.name, fields, composites);
1139
+ }
1140
+
1113
1141
  /** Drop indexes (v0.19.6 parity). Composite drops by the id createCompositeIndex returned. */
1114
1142
  async dropIndex(field: string): Promise<void> {
1115
1143
  ensureOk(this.client.nativeBindings().dropSimpleIndex(this.client.engineHandle(), this.name, field), this.client.nativeBindings(), 'dropIndex');
package/src/native.ts CHANGED
@@ -78,6 +78,8 @@ export interface NativeBindings {
78
78
  engineInsertSubDoc(engine: Handle, col: string, id: string, subCol: string, subId: string, doc: Handle): number;
79
79
  engineGetByRef(engine: Handle, doc: Handle, fieldKey: string): Handle;
80
80
  engineCreateIndex(engine: Handle, collection: string, fieldsJson: string): number;
81
+ /** One-pass declaration; returns a JSON array of composite ids or null. */
82
+ engineCreateIndexes(engine: Handle, collection: string, fieldsJson: string, compositesJson: string): string | null;
81
83
 
82
84
  // Atomic Batch
83
85
  batchNew(): Handle;
@@ -432,6 +434,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
432
434
  hk_engine_insert_subdoc: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
433
435
  hk_engine_get_by_ref: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
434
436
  hk_engine_create_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.u32 },
437
+ hk_engine_create_indexes: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
435
438
  hk_engine_create_vector_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32], returns: FFIType.i32 },
436
439
  hk_engine_find_near: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
437
440
  hk_engine_create_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
@@ -614,6 +617,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
614
617
  hk_cursor_walk_view: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
615
618
  hk_rawdoc_bytes: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
616
619
  hk_rawdoc_id: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
620
+ hk_view_free: { args: [FFIType.ptr], returns: FFIType.void },
617
621
  hk_view_get: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
618
622
  hk_view_get_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.bool },
619
623
  hk_view_get_float: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.bool },
@@ -622,6 +626,8 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
622
626
  hk_view_has_field: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.bool },
623
627
  hk_view_get_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
624
628
  hk_view_get_bytes: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
629
+ hk_view_to_doc: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
630
+ hk_engine_list_collections: { args: [FFIType.ptr], returns: FFIType.ptr },
625
631
  hk_engine_get_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
626
632
  hk_query_execute_json: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
627
633
  hk_cursor_walk_json: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
@@ -741,6 +747,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
741
747
  engineInsertSubDoc: (engine, col, id, subCol, subId, doc) => symbols.hk_engine_insert_subdoc(engine, toC(col), toC(id), toC(subCol), toC(subId), doc),
742
748
  engineGetByRef: (engine, doc, fieldKey) => symbols.hk_engine_get_by_ref(engine, doc, toC(fieldKey)),
743
749
  engineCreateIndex: (engine, collection, fieldsJson) => symbols.hk_engine_create_index(engine, toC(collection), toC(fieldsJson)),
750
+ engineCreateIndexes: (engine, collection, fieldsJson, compositesJson) => ptrToStringAndFree(symbols.hk_engine_create_indexes(engine, toC(collection), toC(fieldsJson), toC(compositesJson))),
744
751
 
745
752
  batchNew: () => symbols.hk_batch_new(),
746
753
  batchFree: (batch) => symbols.hk_batch_free(batch),
@@ -1110,6 +1117,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1110
1117
  hk_engine_insert_subdoc: lib.func('int hk_engine_insert_subdoc(HK_Engine* engine, const char* col, const char* id, const char* sub_col, const char* sub_id, const HK_Doc* doc)'),
1111
1118
  hk_engine_get_by_ref: lib.func('HK_Doc* hk_engine_get_by_ref(HK_Engine* engine, const HK_Doc* doc, const char* field_key)'),
1112
1119
  hk_engine_create_index: lib.func('uint32_t hk_engine_create_index(HK_Engine* engine, const char* collection, const char* fields_json)'),
1120
+ hk_engine_create_indexes: lib.func('HeapStr hk_engine_create_indexes(HK_Engine* engine, const char* collection, const char* fields_json, const char* composites_json)'),
1113
1121
  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)'),
1114
1122
  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)'),
1115
1123
  hk_engine_create_traverse_index: lib.func('int hk_engine_create_traverse_index(HK_Engine* engine, const char* collection)'),
@@ -1404,6 +1412,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
1404
1412
  engineInsertSubDoc: (engine, col, id, subCol, subId, doc) => fn.hk_engine_insert_subdoc(engine, col, id, subCol, subId, doc),
1405
1413
  engineGetByRef: (engine, doc, fieldKey) => fn.hk_engine_get_by_ref(engine, doc, fieldKey),
1406
1414
  engineCreateIndex: (engine, collection, fieldsJson) => fn.hk_engine_create_index(engine, collection, fieldsJson),
1415
+ engineCreateIndexes: (engine, collection, fieldsJson, compositesJson) => ptrToStringAndFree(fn.hk_engine_create_indexes(engine, collection, fieldsJson, compositesJson)),
1407
1416
 
1408
1417
  batchNew: () => fn.hk_batch_new(),
1409
1418
  batchFree: (batch) => fn.hk_batch_free(batch),