@hakodb/client 0.6.10 → 0.7.0
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/src/client.ts +58 -11
- package/src/native.ts +6 -0
package/package.json
CHANGED
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,63 @@ 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.
|
|
1470
1523
|
*/
|
|
1471
1524
|
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
|
-
}
|
|
1525
|
+
return this.get({ mode: 'json' });
|
|
1479
1526
|
}
|
|
1480
1527
|
|
|
1481
1528
|
/**
|
package/src/native.ts
CHANGED
|
@@ -115,6 +115,8 @@ 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
|
+
/** Canonical executor: pass null for no cancel, or an HK_Cancel* handle. */
|
|
119
|
+
queryExecuteEx(engine: Handle, query: Handle, cancel: Handle | null): string | null;
|
|
118
120
|
/** #250: reset a handle in place for reuse (no alloc/free). */
|
|
119
121
|
queryReset(query: Handle, collection: string): number;
|
|
120
122
|
queryExecuteWithCancel(engine: Handle, query: Handle, cancel: Handle): string | null;
|
|
@@ -497,6 +499,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
497
499
|
hk_query_offset: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
498
500
|
hk_query_select_field: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
499
501
|
hk_query_execute: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
502
|
+
hk_query_execute_ex: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
500
503
|
hk_query_reset: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
501
504
|
hk_query_execute_with_cancel: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
502
505
|
hk_cancel_new: { args: [], returns: FFIType.ptr },
|
|
@@ -776,6 +779,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
776
779
|
queryOffset: (query, offset) => symbols.hk_query_offset(query, offset),
|
|
777
780
|
querySelectField: (query, field) => symbols.hk_query_select_field(query, toC(field)),
|
|
778
781
|
queryExecute: (engine, query) => ptrToStringAndFree(symbols.hk_query_execute(engine, query)),
|
|
782
|
+
queryExecuteEx: (engine, query, cancel) => ptrToStringAndFree(symbols.hk_query_execute_ex(engine, query, cancel)),
|
|
779
783
|
queryReset: (query, collection) => symbols.hk_query_reset(query, toC(collection)),
|
|
780
784
|
queryExecuteWithCancel: (engine, query, cancel) => ptrToStringAndFree(symbols.hk_query_execute_with_cancel(engine, query, cancel)),
|
|
781
785
|
cancelNew: () => symbols.hk_cancel_new(),
|
|
@@ -1173,6 +1177,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1173
1177
|
hk_query_offset: lib.func('int hk_query_offset(HK_Query* query, size_t offset)'),
|
|
1174
1178
|
hk_query_select_field: lib.func('int hk_query_select_field(HK_Query* query, const char* field)'),
|
|
1175
1179
|
hk_query_execute: lib.func('HeapStr hk_query_execute(HK_Engine* engine, const HK_Query* query)'),
|
|
1180
|
+
hk_query_execute_ex: lib.func('HeapStr hk_query_execute_ex(HK_Engine* engine, const HK_Query* query, HK_Cancel* cancel)'),
|
|
1176
1181
|
hk_query_reset: lib.func('int hk_query_reset(HK_Query* query, const char* collection)'),
|
|
1177
1182
|
hk_query_execute_with_cancel: lib.func('HeapStr hk_query_execute_with_cancel(HK_Engine* engine, const HK_Query* query, HK_Cancel* cancel)'),
|
|
1178
1183
|
hk_cancel_new: lib.func('HK_Cancel* hk_cancel_new()'),
|
|
@@ -1437,6 +1442,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1437
1442
|
queryOffset: (query, offset) => fn.hk_query_offset(query, offset),
|
|
1438
1443
|
querySelectField: (query, field) => fn.hk_query_select_field(query, field),
|
|
1439
1444
|
queryExecute: (engine, query) => ptrToStringAndFree(fn.hk_query_execute(engine, query)),
|
|
1445
|
+
queryExecuteEx: (engine, query, cancel) => ptrToStringAndFree(fn.hk_query_execute_ex(engine, query, cancel)),
|
|
1440
1446
|
queryReset: (query, collection) => fn.hk_query_reset(query, collection),
|
|
1441
1447
|
queryExecuteWithCancel: (engine, query, cancel) => ptrToStringAndFree(fn.hk_query_execute_with_cancel(engine, query, cancel)),
|
|
1442
1448
|
cancelNew: () => fn.hk_cancel_new(),
|