@hakodb/client 0.6.10 → 0.7.1
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 +2 -2
- package/scripts/check_ffi_parity.py +64 -0
- package/src/client.ts +59 -11
- package/src/native.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hakodb/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "High-level HakoDB JavaScript/TypeScript client for Node.js and Bun",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
"typescript": "^7.0.2"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"test": "tsc --noEmit -p tsconfig.json"
|
|
36
|
+
"test": "tsc --noEmit -p tsconfig.json && python3 scripts/check_ffi_parity.py"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Check that every C ABI query/sync symbol is either bound or allowlisted.
|
|
3
|
+
|
|
4
|
+
Generic guard: it reads the generated header and the SDK binding source, so
|
|
5
|
+
it does not depend on a particular deployment, machine or consumer.
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
import re
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
13
|
+
HEADER = Path(os.environ.get("HAKODB_HEADER", ROOT / "native" / "hakodb.h"))
|
|
14
|
+
BINDINGS = Path(os.environ.get("HAKODB_BINDINGS", ROOT / "src" / "native.ts"))
|
|
15
|
+
|
|
16
|
+
# Symbols intentionally not exposed by the high-level SDK.
|
|
17
|
+
# - Unix-only socket transport (declarations exist on every target by design).
|
|
18
|
+
# - Superseded graph path variants; the *_v4 / *_v3 successors are bound.
|
|
19
|
+
ALLOW_UNBOUND = {
|
|
20
|
+
"hk_socket_sync_dial",
|
|
21
|
+
"hk_socket_sync_free",
|
|
22
|
+
"hk_socket_sync_new",
|
|
23
|
+
"hk_socket_sync_serve",
|
|
24
|
+
"hk_socket_sync_status",
|
|
25
|
+
"hk_engine_find_paths_v2",
|
|
26
|
+
"hk_engine_find_paths_v3",
|
|
27
|
+
"hk_engine_find_simple_paths",
|
|
28
|
+
"hk_engine_find_simple_paths_v2",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def header_functions(path: Path) -> set[str]:
|
|
33
|
+
text = path.read_text(encoding="utf-8", errors="replace")
|
|
34
|
+
return set(re.findall(r"\b(hk_[a-z0-9_]+)\s*\(", text))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def bound_symbols(path: Path) -> set[str]:
|
|
38
|
+
text = path.read_text(encoding="utf-8")
|
|
39
|
+
found = set(re.findall(r"\b(hk_[a-z0-9_]+)\b", text))
|
|
40
|
+
# Partial identifier from a source comment, not a function.
|
|
41
|
+
return found - {"hk_socket_sync_"}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def main() -> int:
|
|
45
|
+
if not HEADER.exists() or not BINDINGS.exists():
|
|
46
|
+
print(f"missing input: header={HEADER} bindings={BINDINGS}", file=sys.stderr)
|
|
47
|
+
return 2
|
|
48
|
+
header = header_functions(HEADER)
|
|
49
|
+
bound = bound_symbols(BINDINGS)
|
|
50
|
+
missing = sorted(header - bound - ALLOW_UNBOUND)
|
|
51
|
+
stale = sorted(bound - header)
|
|
52
|
+
print(f"header functions: {len(header)}, bound symbols: {len(bound)}")
|
|
53
|
+
if missing:
|
|
54
|
+
print("unbound and not allowlisted:", ", ".join(missing), file=sys.stderr)
|
|
55
|
+
if stale:
|
|
56
|
+
print("bound symbols absent from header:", ", ".join(stale), file=sys.stderr)
|
|
57
|
+
if missing or stale:
|
|
58
|
+
return 1
|
|
59
|
+
print("FFI binding parity: OK")
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
raise SystemExit(main())
|
package/src/client.ts
CHANGED
|
@@ -1229,6 +1229,18 @@ export class DocumentReference {
|
|
|
1229
1229
|
}
|
|
1230
1230
|
}
|
|
1231
1231
|
|
|
1232
|
+
/**
|
|
1233
|
+
* Which FFI execution lane `Query.get()` uses. All modes return JS objects;
|
|
1234
|
+
* they differ in materialization cost, not in output shape.
|
|
1235
|
+
* - `docs` (default): canonical `hk_query_execute_ex` path.
|
|
1236
|
+
* - `json`: pinned-byte JSON egress (`hk_query_execute_json`).
|
|
1237
|
+
* - `handles` / `raw`: advanced native lanes, materialized to JS objects
|
|
1238
|
+
* for convenience; use `nativeBindings()` directly for zero-copy access.
|
|
1239
|
+
*/
|
|
1240
|
+
export interface QueryGetOptions {
|
|
1241
|
+
mode?: 'docs' | 'json' | 'handles' | 'raw';
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1232
1244
|
export class Query {
|
|
1233
1245
|
private _startAfterSnapshot?: DocumentSnapshot;
|
|
1234
1246
|
private _startAtSnapshot?: DocumentSnapshot;
|
|
@@ -1454,28 +1466,64 @@ return this;
|
|
|
1454
1466
|
}
|
|
1455
1467
|
}
|
|
1456
1468
|
|
|
1457
|
-
|
|
1469
|
+
/**
|
|
1470
|
+
* Execute the query. `mode` selects the FFI execution lane; all modes
|
|
1471
|
+
* return the same JS shape. Default is the canonical `docs` path.
|
|
1472
|
+
*/
|
|
1473
|
+
async get(options: QueryGetOptions = {}): Promise<HakoDocData[]> {
|
|
1458
1474
|
const native = this.client.nativeBindings();
|
|
1475
|
+
const engine = this.client.engineHandle();
|
|
1459
1476
|
const handle = this.prepareNativeQuery();
|
|
1460
1477
|
try {
|
|
1461
|
-
|
|
1478
|
+
switch (options.mode ?? 'docs') {
|
|
1479
|
+
case 'json':
|
|
1480
|
+
return parseQueryRows(native.queryExecuteJson(engine, handle));
|
|
1481
|
+
case 'handles': {
|
|
1482
|
+
const rs = native.queryExecuteToHandles(engine, handle);
|
|
1483
|
+
try {
|
|
1484
|
+
return parseQueryRows(native.resultSetToJson(rs));
|
|
1485
|
+
} finally {
|
|
1486
|
+
native.resultSetFree(rs);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
case 'raw': {
|
|
1490
|
+
const rs = native.queryExecuteRaw(engine, handle);
|
|
1491
|
+
const rows: HakoDocData[] = [];
|
|
1492
|
+
try {
|
|
1493
|
+
const count = native.rawResultCount(rs);
|
|
1494
|
+
for (let i = 0; i < count; i++) {
|
|
1495
|
+
const raw = native.rawResultGet(rs, i);
|
|
1496
|
+
if (!raw) continue;
|
|
1497
|
+
const doc = native.rawDocToDoc(engine, raw, this.collection);
|
|
1498
|
+
if (!doc) continue;
|
|
1499
|
+
try {
|
|
1500
|
+
const json = native.docToJson(doc);
|
|
1501
|
+
if (json) rows.push(JSON.parse(json) as HakoDocData);
|
|
1502
|
+
} finally {
|
|
1503
|
+
native.docFree(doc);
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
} finally {
|
|
1507
|
+
native.rawResultFree(rs);
|
|
1508
|
+
}
|
|
1509
|
+
return rows;
|
|
1510
|
+
}
|
|
1511
|
+
case 'docs':
|
|
1512
|
+
default:
|
|
1513
|
+
return parseQueryRows(native.queryExecuteEx(engine, handle, null));
|
|
1514
|
+
}
|
|
1462
1515
|
} finally {
|
|
1463
1516
|
this.client.releaseQuery(this.collection, handle);
|
|
1464
1517
|
}
|
|
1465
1518
|
}
|
|
1466
1519
|
|
|
1467
1520
|
/**
|
|
1468
|
-
*
|
|
1469
|
-
* shape as get()
|
|
1521
|
+
* Alias for `get({ mode: 'json' })`: JSON emitted from pinned bytes,
|
|
1522
|
+
* same shape as `get()`. Projections keep the projected executor's shape.
|
|
1523
|
+
* @deprecated Prefer `get({ mode: 'json' })` so the materialization lane is explicit.
|
|
1470
1524
|
*/
|
|
1471
1525
|
async getJson(): Promise<HakoDocData[]> {
|
|
1472
|
-
|
|
1473
|
-
const handle = this.prepareNativeQuery();
|
|
1474
|
-
try {
|
|
1475
|
-
return parseQueryRows(native.queryExecuteJson(this.client.engineHandle(), handle));
|
|
1476
|
-
} finally {
|
|
1477
|
-
this.client.releaseQuery(this.collection, handle);
|
|
1478
|
-
}
|
|
1526
|
+
return this.get({ mode: 'json' });
|
|
1479
1527
|
}
|
|
1480
1528
|
|
|
1481
1529
|
/**
|
package/src/native.ts
CHANGED
|
@@ -114,9 +114,13 @@ export interface NativeBindings {
|
|
|
114
114
|
queryLimit(query: Handle, limit: number): number;
|
|
115
115
|
queryOffset(query: Handle, offset: number): number;
|
|
116
116
|
querySelectField(query: Handle, field: string): number;
|
|
117
|
+
/** @deprecated Use queryExecuteEx(engine, query, null). */
|
|
117
118
|
queryExecute(engine: Handle, query: Handle): string | null;
|
|
119
|
+
/** Canonical executor: pass null for no cancel, or an HK_Cancel* handle. */
|
|
120
|
+
queryExecuteEx(engine: Handle, query: Handle, cancel: Handle | null): string | null;
|
|
118
121
|
/** #250: reset a handle in place for reuse (no alloc/free). */
|
|
119
122
|
queryReset(query: Handle, collection: string): number;
|
|
123
|
+
/** @deprecated Use queryExecuteEx(engine, query, cancel). */
|
|
120
124
|
queryExecuteWithCancel(engine: Handle, query: Handle, cancel: Handle): string | null;
|
|
121
125
|
cancelNew(): Handle;
|
|
122
126
|
cancel(cancel: Handle): void;
|
|
@@ -497,6 +501,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
497
501
|
hk_query_offset: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
498
502
|
hk_query_select_field: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
499
503
|
hk_query_execute: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
504
|
+
hk_query_execute_ex: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
500
505
|
hk_query_reset: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
501
506
|
hk_query_execute_with_cancel: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
502
507
|
hk_cancel_new: { args: [], returns: FFIType.ptr },
|
|
@@ -776,6 +781,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
776
781
|
queryOffset: (query, offset) => symbols.hk_query_offset(query, offset),
|
|
777
782
|
querySelectField: (query, field) => symbols.hk_query_select_field(query, toC(field)),
|
|
778
783
|
queryExecute: (engine, query) => ptrToStringAndFree(symbols.hk_query_execute(engine, query)),
|
|
784
|
+
queryExecuteEx: (engine, query, cancel) => ptrToStringAndFree(symbols.hk_query_execute_ex(engine, query, cancel)),
|
|
779
785
|
queryReset: (query, collection) => symbols.hk_query_reset(query, toC(collection)),
|
|
780
786
|
queryExecuteWithCancel: (engine, query, cancel) => ptrToStringAndFree(symbols.hk_query_execute_with_cancel(engine, query, cancel)),
|
|
781
787
|
cancelNew: () => symbols.hk_cancel_new(),
|
|
@@ -1173,6 +1179,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1173
1179
|
hk_query_offset: lib.func('int hk_query_offset(HK_Query* query, size_t offset)'),
|
|
1174
1180
|
hk_query_select_field: lib.func('int hk_query_select_field(HK_Query* query, const char* field)'),
|
|
1175
1181
|
hk_query_execute: lib.func('HeapStr hk_query_execute(HK_Engine* engine, const HK_Query* query)'),
|
|
1182
|
+
hk_query_execute_ex: lib.func('HeapStr hk_query_execute_ex(HK_Engine* engine, const HK_Query* query, HK_Cancel* cancel)'),
|
|
1176
1183
|
hk_query_reset: lib.func('int hk_query_reset(HK_Query* query, const char* collection)'),
|
|
1177
1184
|
hk_query_execute_with_cancel: lib.func('HeapStr hk_query_execute_with_cancel(HK_Engine* engine, const HK_Query* query, HK_Cancel* cancel)'),
|
|
1178
1185
|
hk_cancel_new: lib.func('HK_Cancel* hk_cancel_new()'),
|
|
@@ -1437,6 +1444,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1437
1444
|
queryOffset: (query, offset) => fn.hk_query_offset(query, offset),
|
|
1438
1445
|
querySelectField: (query, field) => fn.hk_query_select_field(query, field),
|
|
1439
1446
|
queryExecute: (engine, query) => ptrToStringAndFree(fn.hk_query_execute(engine, query)),
|
|
1447
|
+
queryExecuteEx: (engine, query, cancel) => ptrToStringAndFree(fn.hk_query_execute_ex(engine, query, cancel)),
|
|
1440
1448
|
queryReset: (query, collection) => fn.hk_query_reset(query, collection),
|
|
1441
1449
|
queryExecuteWithCancel: (engine, query, cancel) => ptrToStringAndFree(fn.hk_query_execute_with_cancel(engine, query, cancel)),
|
|
1442
1450
|
cancelNew: () => fn.hk_cancel_new(),
|