@hakodb/client 0.5.21 → 0.6.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/README.md +6 -2
- package/examples/node/softdel.ts +70 -0
- package/package.json +1 -1
- package/src/client.ts +417 -1
- package/src/native.ts +523 -3
package/src/native.ts
CHANGED
|
@@ -61,6 +61,11 @@ export interface NativeBindings {
|
|
|
61
61
|
engineGet(engine: Handle, collection: string, docId: string): Handle;
|
|
62
62
|
engineDelete(engine: Handle, collection: string, docId: string): number;
|
|
63
63
|
engineDeleteLocal(engine: Handle, collection: string, docId: string): number;
|
|
64
|
+
engineDeleteEx(engine: Handle, collection: string, docId: string, force: boolean): number;
|
|
65
|
+
engineRestore(engine: Handle, collection: string, docId: string): number;
|
|
66
|
+
engineRestoreAvailable(engine: Handle, collection: string | null): string | null;
|
|
67
|
+
engineDeleteQueue(engine: Handle, collection: string | null): string | null;
|
|
68
|
+
engineSweepNow(engine: Handle): number;
|
|
64
69
|
engineSetCollectionLocal(engine: Handle, collection: string, local: number): number;
|
|
65
70
|
engineReplicateKey(engine: Handle, collection: string, docId: string): number;
|
|
66
71
|
engineReplicateCollection(engine: Handle, collection: string): number;
|
|
@@ -79,6 +84,7 @@ export interface NativeBindings {
|
|
|
79
84
|
batchFree(batch: Handle): void;
|
|
80
85
|
batchSet(batch: Handle, collection: string, docId: string, doc: Handle): number;
|
|
81
86
|
batchDelete(batch: Handle, collection: string, docId: string): number;
|
|
87
|
+
batchDeleteEx(batch: Handle, collection: string, docId: string, force: boolean): number;
|
|
82
88
|
batchCommit(engine: Handle, batch: Handle): number;
|
|
83
89
|
|
|
84
90
|
// Serializable Transactions
|
|
@@ -155,6 +161,8 @@ export interface NativeBindings {
|
|
|
155
161
|
queryAggregateCount(query: Handle): number;
|
|
156
162
|
queryAggregateSum(query: Handle, field: string): number;
|
|
157
163
|
queryAggregateAvg(query: Handle, field: string): number;
|
|
164
|
+
queryAggregateMin(query: Handle, field: string): number;
|
|
165
|
+
queryAggregateMax(query: Handle, field: string): number;
|
|
158
166
|
queryExecuteAggregation(engine: Handle, query: Handle): string | null;
|
|
159
167
|
|
|
160
168
|
engineListCollections(engine: Handle): string | null;
|
|
@@ -195,7 +203,22 @@ export interface NativeBindings {
|
|
|
195
203
|
// (same hit shape, cost-ordered; cost rides each hit).
|
|
196
204
|
createEdgeIndex(engine: Handle, collection: string): number;
|
|
197
205
|
engineShortestPaths(engine: Handle, collection: string, id: string, direction: number, edge: string | null, via: string | null, weight: string | null, maxDepth: number, k: number): string | null;
|
|
198
|
-
|
|
206
|
+
|
|
207
|
+
// v0.19.6 parity: index drops, full graph/traverse API, JSON writes.
|
|
208
|
+
dropSimpleIndex(engine: Handle, collection: string, field: string): number;
|
|
209
|
+
dropVectorIndex(engine: Handle, collection: string, field: string): number;
|
|
210
|
+
dropCompositeIndex(engine: Handle, collection: string, id: number): number;
|
|
211
|
+
dropEdgeIndex(engine: Handle, collection: string): number;
|
|
212
|
+
dropFtsIndex(engine: Handle, collection: string, field: string): number;
|
|
213
|
+
dropTraverseIndex(engine: Handle, collection: string): number;
|
|
214
|
+
createVectorIndexV2(engine: Handle, collection: string, field: string, dim: number, metric: number, m: number, efConstruction: number, efSearch: number): number;
|
|
215
|
+
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;
|
|
216
|
+
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
|
+
exportGraph(engine: Handle, collection: string, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null): string | null;
|
|
218
|
+
graphAnalysis(engine: Handle, collection: string, op: string, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null): string | null;
|
|
219
|
+
insertJSON(engine: Handle, collection: string, id: string, json: string): number;
|
|
220
|
+
batchSetJSON(batch: Handle, collection: string, id: string, json: string): number;
|
|
221
|
+
|
|
199
222
|
// Array API
|
|
200
223
|
arrayNew(): Handle;
|
|
201
224
|
arrayFree(array: Handle): void;
|
|
@@ -218,6 +241,78 @@ export interface NativeBindings {
|
|
|
218
241
|
queryEndAt(query: Handle, anchorDoc: Handle): number;
|
|
219
242
|
queryEndBefore(query: Handle, anchorDoc: Handle): number;
|
|
220
243
|
|
|
244
|
+
// Unix-only hk_socket_sync_* is deliberately absent: Windows builds omit
|
|
245
|
+
// the symbol, so binding it unconditionally would break koffi on Windows.
|
|
246
|
+
|
|
247
|
+
// F8: per-collection schemas over the C ABI.
|
|
248
|
+
engineSetSchema(engine: Handle, collection: string, schemaJson: string): number;
|
|
249
|
+
engineGetSchema(engine: Handle, collection: string): string | null;
|
|
250
|
+
engineClearSchema(engine: Handle, collection: string): number;
|
|
251
|
+
engineListSchemas(engine: Handle): string | null;
|
|
252
|
+
|
|
253
|
+
// F5: versioned reads, transaction patch/get_many, retry classification.
|
|
254
|
+
engineGetVersioned(engine: Handle, collection: string, docId: string): { doc: Handle; version: bigint };
|
|
255
|
+
transactionGetMany(engine: Handle, tx: Handle, collection: string, idsJson: string): string | null;
|
|
256
|
+
transactionPatch(engine: Handle, tx: Handle, collection: string, docId: string, updatesJson: string): number;
|
|
257
|
+
errorLastKind(): number;
|
|
258
|
+
errorIsRetryable(): boolean;
|
|
259
|
+
|
|
260
|
+
// F7/F3: explain + array/graph predicates.
|
|
261
|
+
queryExplain(engine: Handle, query: Handle): string | null;
|
|
262
|
+
queryWhereArrayAllEq(query: Handle, field: string, valueJson: string): number;
|
|
263
|
+
queryWhereElemMatch(query: Handle, field: string, filtersJson: string): number;
|
|
264
|
+
queryWhereNear(query: Handle, field: string, vec: Float32Array): number;
|
|
265
|
+
queryWhereTraverse(query: Handle, startCol: string, startId: string, direction: number, edge: string | null, maxDepth: number): number;
|
|
266
|
+
|
|
267
|
+
// F4: aggregation pipeline (raw handle; typed builder is separate work).
|
|
268
|
+
pipelineNew(collection: string): Handle;
|
|
269
|
+
pipelineFree(pipeline: Handle): void;
|
|
270
|
+
pipelineMatch(pipeline: Handle, query: Handle): number;
|
|
271
|
+
pipelineProject(pipeline: Handle, fieldsJson: string): number;
|
|
272
|
+
pipelineSort(pipeline: Handle, field: string, ascending: boolean): number;
|
|
273
|
+
pipelineLimit(pipeline: Handle, limit: number): number;
|
|
274
|
+
pipelineOffset(pipeline: Handle, offset: number): number;
|
|
275
|
+
pipelineUnwind(pipeline: Handle, field: string): number;
|
|
276
|
+
pipelineGroup(pipeline: Handle, key: string, accumsJson: string): number;
|
|
277
|
+
pipelineExecute(engine: Handle, pipeline: Handle): string | null;
|
|
278
|
+
pipelineExecuteToHandles(engine: Handle, pipeline: Handle): Handle;
|
|
279
|
+
|
|
280
|
+
// Config additions (0.12-0.16 core knobs).
|
|
281
|
+
configSetGroupCommitIntervalMs(config: Handle, ms: number | bigint): void;
|
|
282
|
+
configSetPageCacheCapacity(config: Handle, capacity: number): void;
|
|
283
|
+
configSetSyncExcluded(config: Handle, collectionsJson: string): number;
|
|
284
|
+
configSetLazyCollections(config: Handle, collectionsJson: string): number;
|
|
285
|
+
configSetReplicationCollections(config: Handle, collectionsJson: string): number;
|
|
286
|
+
|
|
287
|
+
// Quiescence / diagnostics / logging.
|
|
288
|
+
engineAwaitQuiescent(engine: Handle, timeoutMs: number | bigint): boolean;
|
|
289
|
+
engineQuiescenceStatus(engine: Handle): string | null;
|
|
290
|
+
debugWriteStats(): string | null;
|
|
291
|
+
logEnableStderr(): void;
|
|
292
|
+
logDisableStderr(): void;
|
|
293
|
+
|
|
294
|
+
// Lazy cursor walks: callbacks copy immediately; returning false stops.
|
|
295
|
+
cursorWalk(engine: Handle, query: Handle, callback: (id: string, bytes: Uint8Array) => boolean): number;
|
|
296
|
+
cursorWalkView(engine: Handle, query: Handle, callback: (id: string, view: Handle) => boolean): number;
|
|
297
|
+
|
|
298
|
+
// Borrowed raw/view reads: copied before return (lifetime is the result set/view).
|
|
299
|
+
rawDocBytes(rawDoc: Handle): Uint8Array | null;
|
|
300
|
+
rawDocId(rawDoc: Handle): string | null;
|
|
301
|
+
viewGetStr(view: Handle, key: string): string | null;
|
|
302
|
+
viewGetBytes(view: Handle, key: string): Uint8Array | null;
|
|
303
|
+
|
|
304
|
+
// P2 (core 0.18): JSON read paths + dotted-path view pulls. JSON strings
|
|
305
|
+
// are owned (free happens in the binding); view pulls copy before return.
|
|
306
|
+
engineGetJson(engine: Handle, collection: string, docId: string): string | null;
|
|
307
|
+
queryExecuteJson(engine: Handle, query: Handle): string | null;
|
|
308
|
+
viewToJson(view: Handle): string | null;
|
|
309
|
+
cursorWalkJson(engine: Handle, query: Handle, callback: (id: string, json: Uint8Array) => boolean): number;
|
|
310
|
+
viewGetPathInt(view: Handle, path: string): number | bigint | null;
|
|
311
|
+
viewGetPathFloat(view: Handle, path: string): number | null;
|
|
312
|
+
viewGetPathBool(view: Handle, path: string): boolean | null;
|
|
313
|
+
viewGetPathStr(view: Handle, path: string): string | null;
|
|
314
|
+
viewGetPathBytes(view: Handle, path: string): Uint8Array | null;
|
|
315
|
+
|
|
221
316
|
lastError(): string;
|
|
222
317
|
}
|
|
223
318
|
|
|
@@ -242,7 +337,7 @@ function resolveLibraryPath(explicitPath?: string): string {
|
|
|
242
337
|
|
|
243
338
|
async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
244
339
|
const ffi = await import('bun:ffi');
|
|
245
|
-
const { dlopen, FFIType, CString, JSCallback } = ffi as any;
|
|
340
|
+
const { dlopen, FFIType, CString, JSCallback, toArrayBuffer } = ffi as any;
|
|
246
341
|
|
|
247
342
|
const symbols = dlopen(libPath, {
|
|
248
343
|
hk_engine_open: { args: [FFIType.cstring], returns: FFIType.ptr },
|
|
@@ -288,6 +383,11 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
288
383
|
hk_engine_get: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
289
384
|
hk_engine_delete: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
290
385
|
hk_engine_delete_local: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
386
|
+
hk_engine_delete_ext: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.i32], returns: FFIType.i32 },
|
|
387
|
+
hk_engine_restore: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
388
|
+
hk_engine_restore_available: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
389
|
+
hk_engine_delete_queue: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
390
|
+
hk_engine_sweep_now: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
291
391
|
hk_engine_set_collection_local: { args: [FFIType.ptr, FFIType.cstring, FFIType.i32], returns: FFIType.i32 },
|
|
292
392
|
hk_engine_replicate_key: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
293
393
|
hk_engine_replicate_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
@@ -308,9 +408,25 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
308
408
|
hk_engine_shortest_paths: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
|
|
309
409
|
|
|
310
410
|
hk_batch_new: { args: [], returns: FFIType.ptr },
|
|
411
|
+
|
|
412
|
+
// v0.19.6 parity
|
|
413
|
+
hk_engine_drop_simple_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
414
|
+
hk_engine_drop_vector_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
415
|
+
hk_engine_drop_composite_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32], returns: FFIType.i32 },
|
|
416
|
+
hk_engine_drop_edge_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
417
|
+
hk_engine_drop_fts_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
418
|
+
hk_engine_drop_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
419
|
+
hk_engine_create_vector_index_v2: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32, FFIType.usize, FFIType.usize, FFIType.usize], returns: FFIType.i32 },
|
|
420
|
+
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 },
|
|
421
|
+
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 },
|
|
422
|
+
hk_engine_export_graph: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
423
|
+
hk_engine_graph_analysis: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
424
|
+
hk_engine_insert_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
425
|
+
hk_batch_set_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
311
426
|
hk_batch_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
312
427
|
hk_batch_set: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
313
428
|
hk_batch_delete: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
429
|
+
hk_batch_delete_ext: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.i32], returns: FFIType.i32 },
|
|
314
430
|
hk_batch_commit: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
315
431
|
|
|
316
432
|
hk_transaction_begin: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
@@ -367,6 +483,8 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
367
483
|
hk_query_aggregate_count: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
368
484
|
hk_query_aggregate_sum: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
369
485
|
hk_query_aggregate_avg: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
486
|
+
hk_query_aggregate_min: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
487
|
+
hk_query_aggregate_max: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
370
488
|
hk_query_execute_aggregation: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
371
489
|
hk_query_where_or_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
372
490
|
hk_query_where_or_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
@@ -407,6 +525,59 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
407
525
|
hk_cloud_sync_stop: { args: [FFIType.ptr], returns: FFIType.void },
|
|
408
526
|
hk_cloud_sync_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
409
527
|
|
|
528
|
+
// 0.16.5 parity: F8 schemas, F5 versioned/tx, F7 explain, F3 predicates,
|
|
529
|
+
// F4 pipelines, config knobs, quiescence, lazy walks and borrowed reads.
|
|
530
|
+
hk_config_set_group_commit_interval_ms: { args: [FFIType.ptr, FFIType.u64], returns: FFIType.void },
|
|
531
|
+
hk_config_set_page_cache_capacity: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.void },
|
|
532
|
+
hk_config_set_sync_excluded: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
533
|
+
hk_config_set_lazy_collections: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
534
|
+
hk_config_set_replication_collections: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
535
|
+
hk_engine_await_quiescent: { args: [FFIType.ptr, FFIType.u64], returns: FFIType.bool },
|
|
536
|
+
hk_engine_quiescence_status: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
537
|
+
hk_engine_get_versioned: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
538
|
+
hk_engine_set_schema: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
539
|
+
hk_engine_get_schema: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
540
|
+
hk_engine_clear_schema: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
541
|
+
hk_engine_list_schemas: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
542
|
+
hk_query_explain: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
543
|
+
hk_query_where_array_all_eq: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
544
|
+
hk_query_where_elem_match: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
545
|
+
hk_query_where_near: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
546
|
+
hk_query_where_traverse: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.usize], returns: FFIType.i32 },
|
|
547
|
+
hk_pipeline_new: { args: [FFIType.cstring], returns: FFIType.ptr },
|
|
548
|
+
hk_pipeline_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
549
|
+
hk_pipeline_match: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
550
|
+
hk_pipeline_project: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
551
|
+
hk_pipeline_sort: { args: [FFIType.ptr, FFIType.cstring, FFIType.bool], returns: FFIType.i32 },
|
|
552
|
+
hk_pipeline_limit: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
553
|
+
hk_pipeline_offset: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
554
|
+
hk_pipeline_unwind: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
555
|
+
hk_pipeline_group: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
556
|
+
hk_pipeline_execute: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
557
|
+
hk_pipeline_execute_to_handles: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
558
|
+
hk_transaction_get_many: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
559
|
+
hk_transaction_patch: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
560
|
+
hk_error_last_kind: { args: [], returns: FFIType.i32 },
|
|
561
|
+
hk_error_is_retryable: { args: [], returns: FFIType.bool },
|
|
562
|
+
hk_debug_write_stats: { args: [], returns: FFIType.ptr },
|
|
563
|
+
hk_log_enable_stderr: { args: [], returns: FFIType.void },
|
|
564
|
+
hk_log_disable_stderr: { args: [], returns: FFIType.void },
|
|
565
|
+
hk_cursor_walk: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
566
|
+
hk_cursor_walk_view: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
567
|
+
hk_rawdoc_bytes: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
568
|
+
hk_rawdoc_id: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
569
|
+
hk_view_get_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
570
|
+
hk_view_get_bytes: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
571
|
+
hk_engine_get_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
572
|
+
hk_query_execute_json: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
573
|
+
hk_cursor_walk_json: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
574
|
+
hk_view_to_json: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
575
|
+
hk_view_get_path_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.bool },
|
|
576
|
+
hk_view_get_path_float: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.bool },
|
|
577
|
+
hk_view_get_path_bool: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
578
|
+
hk_view_get_path_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
579
|
+
hk_view_get_path_bytes: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
580
|
+
|
|
410
581
|
// ================= ERRORS =================
|
|
411
582
|
hk_last_error: { args: [], returns: FFIType.ptr },
|
|
412
583
|
hk_string_free: { args: [FFIType.ptr], returns: FFIType.void }
|
|
@@ -479,6 +650,11 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
479
650
|
engineGet: (engine, collection, docId) => symbols.hk_engine_get(engine, toC(collection), toC(docId)),
|
|
480
651
|
engineDelete: (engine, collection, docId) => symbols.hk_engine_delete(engine, toC(collection), toC(docId)),
|
|
481
652
|
engineDeleteLocal: (engine, collection, docId) => symbols.hk_engine_delete_local(engine, toC(collection), toC(docId)),
|
|
653
|
+
engineDeleteEx: (engine, collection, docId, force) => symbols.hk_engine_delete_ext(engine, toC(collection), toC(docId), force ? 1 : 0),
|
|
654
|
+
engineRestore: (engine, collection, docId) => symbols.hk_engine_restore(engine, toC(collection), toC(docId)),
|
|
655
|
+
engineRestoreAvailable: (engine, collection) => ptrToStringAndFree(symbols.hk_engine_restore_available(engine, (collection ? toC(collection) : null) as unknown as string)),
|
|
656
|
+
engineDeleteQueue: (engine, collection) => ptrToStringAndFree(symbols.hk_engine_delete_queue(engine, (collection ? toC(collection) : null) as unknown as string)),
|
|
657
|
+
engineSweepNow: (engine) => symbols.hk_engine_sweep_now(engine),
|
|
482
658
|
engineSetCollectionLocal: (engine, collection, local) => symbols.hk_engine_set_collection_local(engine, toC(collection), local),
|
|
483
659
|
engineReplicateKey: (engine, collection, docId) => symbols.hk_engine_replicate_key(engine, toC(collection), toC(docId)),
|
|
484
660
|
engineReplicateCollection: (engine, collection) => symbols.hk_engine_replicate_collection(engine, toC(collection)),
|
|
@@ -496,6 +672,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
496
672
|
batchFree: (batch) => symbols.hk_batch_free(batch),
|
|
497
673
|
batchSet: (batch, collection, docId, doc) => symbols.hk_batch_set(batch, toC(collection), toC(docId), doc),
|
|
498
674
|
batchDelete: (batch, collection, docId) => symbols.hk_batch_delete(batch, toC(collection), toC(docId)),
|
|
675
|
+
batchDeleteEx: (batch, collection, docId, force) => symbols.hk_batch_delete_ext(batch, toC(collection), toC(docId), force ? 1 : 0),
|
|
499
676
|
batchCommit: (engine, batch) => symbols.hk_batch_commit(engine, batch),
|
|
500
677
|
|
|
501
678
|
transactionBegin: (engine) => symbols.hk_transaction_begin(engine),
|
|
@@ -569,6 +746,8 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
569
746
|
queryAggregateCount: (q) => symbols.hk_query_aggregate_count(q),
|
|
570
747
|
queryAggregateSum: (q, f) => symbols.hk_query_aggregate_sum(q, toC(f)),
|
|
571
748
|
queryAggregateAvg: (q, f) => symbols.hk_query_aggregate_avg(q, toC(f)),
|
|
749
|
+
queryAggregateMin: (q, f) => symbols.hk_query_aggregate_min(q, toC(f)),
|
|
750
|
+
queryAggregateMax: (q, f) => symbols.hk_query_aggregate_max(q, toC(f)),
|
|
572
751
|
queryExecuteAggregation: (e, q) => ptrToStringAndFree(symbols.hk_query_execute_aggregation(e, q)),
|
|
573
752
|
engineListCollections: (engine) => ptrToStringAndFree(symbols.hk_engine_list_collections(engine)),
|
|
574
753
|
netSyncerNew: (engine, name, roomKey) => symbols.hk_net_syncer_new(engine, toC(name), toC(roomKey)),
|
|
@@ -600,6 +779,21 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
600
779
|
createEdgeIndex: (engine, collection) => symbols.hk_engine_create_edge_index(engine, toC(collection)),
|
|
601
780
|
engineShortestPaths: (engine, collection, id, direction, edge, via, weight, maxDepth, k) => ptrToStringAndFree(symbols.hk_engine_shortest_paths(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), weight === null ? null : toC(weight), maxDepth, k)),
|
|
602
781
|
|
|
782
|
+
// v0.19.6 parity
|
|
783
|
+
dropSimpleIndex: (engine, collection, field) => symbols.hk_engine_drop_simple_index(engine, toC(collection), toC(field)),
|
|
784
|
+
dropVectorIndex: (engine, collection, field) => symbols.hk_engine_drop_vector_index(engine, toC(collection), toC(field)),
|
|
785
|
+
dropCompositeIndex: (engine, collection, id) => symbols.hk_engine_drop_composite_index(engine, toC(collection), id),
|
|
786
|
+
dropEdgeIndex: (engine, collection) => symbols.hk_engine_drop_edge_index(engine, toC(collection)),
|
|
787
|
+
dropFtsIndex: (engine, collection, field) => symbols.hk_engine_drop_fts_index(engine, toC(collection), toC(field)),
|
|
788
|
+
dropTraverseIndex: (engine, collection) => symbols.hk_engine_drop_traverse_index(engine, toC(collection)),
|
|
789
|
+
createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch) => symbols.hk_engine_create_vector_index_v2(engine, toC(collection), toC(field), dim, metric, m, efConstruction, efSearch),
|
|
790
|
+
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))),
|
|
791
|
+
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))),
|
|
792
|
+
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))),
|
|
793
|
+
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))),
|
|
794
|
+
insertJSON: (engine, collection, id, json) => symbols.hk_engine_insert_json(engine, toC(collection), toC(id), toC(json)),
|
|
795
|
+
batchSetJSON: (batch, collection, id, json) => symbols.hk_batch_set_json(batch, toC(collection), toC(id), toC(json)),
|
|
796
|
+
|
|
603
797
|
// Array API
|
|
604
798
|
arrayNew: () => symbols.hk_array_new(),
|
|
605
799
|
arrayFree: (arr) => symbols.hk_array_free(arr),
|
|
@@ -622,6 +816,117 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
622
816
|
queryEndAt: (query, anchorDoc) => symbols.hk_query_end_at(query, anchorDoc),
|
|
623
817
|
queryEndBefore: (query, anchorDoc) => symbols.hk_query_end_before(query, anchorDoc),
|
|
624
818
|
|
|
819
|
+
// 0.16.5 parity.
|
|
820
|
+
engineSetSchema: (e, c, json) => symbols.hk_engine_set_schema(e, toC(c), toC(json)),
|
|
821
|
+
engineGetSchema: (e, c) => ptrToStringAndFree(symbols.hk_engine_get_schema(e, toC(c))),
|
|
822
|
+
engineClearSchema: (e, c) => symbols.hk_engine_clear_schema(e, toC(c)),
|
|
823
|
+
engineListSchemas: (e) => ptrToStringAndFree(symbols.hk_engine_list_schemas(e)),
|
|
824
|
+
engineGetVersioned: (e, c, id) => {
|
|
825
|
+
const out = new BigInt64Array(1);
|
|
826
|
+
const doc = symbols.hk_engine_get_versioned(e, toC(c), toC(id), ptrOf(out));
|
|
827
|
+
return { doc, version: out[0] };
|
|
828
|
+
},
|
|
829
|
+
engineAwaitQuiescent: (e, ms) => symbols.hk_engine_await_quiescent(e, BigInt(ms)),
|
|
830
|
+
engineQuiescenceStatus: (e) => ptrToStringAndFree(symbols.hk_engine_quiescence_status(e)),
|
|
831
|
+
transactionGetMany: (e, tx, c, idsJson) => ptrToStringAndFree(symbols.hk_transaction_get_many(e, tx, toC(c), toC(idsJson))),
|
|
832
|
+
transactionPatch: (e, tx, c, id, updatesJson) => symbols.hk_transaction_patch(e, tx, toC(c), toC(id), toC(updatesJson)),
|
|
833
|
+
errorLastKind: () => symbols.hk_error_last_kind(),
|
|
834
|
+
errorIsRetryable: () => symbols.hk_error_is_retryable(),
|
|
835
|
+
debugWriteStats: () => ptrToStringAndFree(symbols.hk_debug_write_stats()),
|
|
836
|
+
logEnableStderr: () => symbols.hk_log_enable_stderr(),
|
|
837
|
+
logDisableStderr: () => symbols.hk_log_disable_stderr(),
|
|
838
|
+
queryExplain: (e, q) => ptrToStringAndFree(symbols.hk_query_explain(e, q)),
|
|
839
|
+
queryWhereArrayAllEq: (q, f, json) => symbols.hk_query_where_array_all_eq(q, toC(f), toC(json)),
|
|
840
|
+
queryWhereElemMatch: (q, f, json) => symbols.hk_query_where_elem_match(q, toC(f), toC(json)),
|
|
841
|
+
queryWhereNear: (q, f, vec) => symbols.hk_query_where_near(q, toC(f), vec, vec.length),
|
|
842
|
+
queryWhereTraverse: (q, sc, sid, dir, edge, depth) => symbols.hk_query_where_traverse(q, toC(sc), toC(sid), dir, edge === null ? null : toC(edge), depth),
|
|
843
|
+
pipelineNew: (c) => symbols.hk_pipeline_new(toC(c)),
|
|
844
|
+
pipelineFree: (p) => symbols.hk_pipeline_free(p),
|
|
845
|
+
pipelineMatch: (p, q) => symbols.hk_pipeline_match(p, q),
|
|
846
|
+
pipelineProject: (p, json) => symbols.hk_pipeline_project(p, toC(json)),
|
|
847
|
+
pipelineSort: (p, f, asc) => symbols.hk_pipeline_sort(p, toC(f), asc),
|
|
848
|
+
pipelineLimit: (p, n) => symbols.hk_pipeline_limit(p, n),
|
|
849
|
+
pipelineOffset: (p, n) => symbols.hk_pipeline_offset(p, n),
|
|
850
|
+
pipelineUnwind: (p, f) => symbols.hk_pipeline_unwind(p, toC(f)),
|
|
851
|
+
pipelineGroup: (p, k, json) => symbols.hk_pipeline_group(p, toC(k), toC(json)),
|
|
852
|
+
pipelineExecute: (e, p) => ptrToStringAndFree(symbols.hk_pipeline_execute(e, p)),
|
|
853
|
+
pipelineExecuteToHandles: (e, p) => symbols.hk_pipeline_execute_to_handles(e, p),
|
|
854
|
+
configSetGroupCommitIntervalMs: (c, ms) => symbols.hk_config_set_group_commit_interval_ms(c, BigInt(ms)),
|
|
855
|
+
configSetPageCacheCapacity: (c, n) => symbols.hk_config_set_page_cache_capacity(c, n),
|
|
856
|
+
configSetSyncExcluded: (c, json) => symbols.hk_config_set_sync_excluded(c, toC(json)),
|
|
857
|
+
configSetLazyCollections: (c, json) => symbols.hk_config_set_lazy_collections(c, toC(json)),
|
|
858
|
+
configSetReplicationCollections: (c, json) => symbols.hk_config_set_replication_collections(c, toC(json)),
|
|
859
|
+
cursorWalk: (e, q, callback) => {
|
|
860
|
+
const cb = new JSCallback((idPtr: any, idLen: number, bytesPtr: any, bytesLen: number) => {
|
|
861
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
862
|
+
const bytes = new Uint8Array(toArrayBuffer(bytesPtr, 0, Number(bytesLen))).slice();
|
|
863
|
+
return callback(id, bytes);
|
|
864
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.usize, FFIType.ptr], returns: FFIType.bool });
|
|
865
|
+
return Number(symbols.hk_cursor_walk(e, q, cb, null));
|
|
866
|
+
},
|
|
867
|
+
cursorWalkView: (e, q, callback) => {
|
|
868
|
+
const cb = new JSCallback((idPtr: any, idLen: number, view: any) => {
|
|
869
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
870
|
+
return callback(id, view);
|
|
871
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.ptr], returns: FFIType.bool });
|
|
872
|
+
return Number(symbols.hk_cursor_walk_view(e, q, cb, null));
|
|
873
|
+
},
|
|
874
|
+
rawDocBytes: (raw) => {
|
|
875
|
+
const len = new BigInt64Array(1);
|
|
876
|
+
const ptr = symbols.hk_rawdoc_bytes(raw, ptrOf(len));
|
|
877
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
878
|
+
},
|
|
879
|
+
rawDocId: (raw) => {
|
|
880
|
+
const len = new BigInt64Array(1);
|
|
881
|
+
const ptr = symbols.hk_rawdoc_id(raw, ptrOf(len));
|
|
882
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
883
|
+
},
|
|
884
|
+
viewGetStr: (view, key) => {
|
|
885
|
+
const len = new BigInt64Array(1);
|
|
886
|
+
const ptr = symbols.hk_view_get_str(view, toC(key), ptrOf(len));
|
|
887
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
888
|
+
},
|
|
889
|
+
viewGetBytes: (view, key) => {
|
|
890
|
+
const len = new BigInt64Array(1);
|
|
891
|
+
const ptr = symbols.hk_view_get_bytes(view, toC(key), ptrOf(len));
|
|
892
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
893
|
+
},
|
|
894
|
+
|
|
895
|
+
// P2 (core 0.18): JSON read paths + dotted-path pulls.
|
|
896
|
+
engineGetJson: (e, c, id) => ptrToStringAndFree(symbols.hk_engine_get_json(e, toC(c), toC(id))),
|
|
897
|
+
queryExecuteJson: (e, q) => ptrToStringAndFree(symbols.hk_query_execute_json(e, q)),
|
|
898
|
+
viewToJson: (view) => ptrToStringAndFree(symbols.hk_view_to_json(view)),
|
|
899
|
+
cursorWalkJson: (e, q, callback) => {
|
|
900
|
+
const cb = new JSCallback((idPtr: any, idLen: number, jsonPtr: any, jsonLen: number) => {
|
|
901
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
902
|
+
const json = new Uint8Array(toArrayBuffer(jsonPtr, 0, Number(jsonLen))).slice();
|
|
903
|
+
return callback(id, json);
|
|
904
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.usize, FFIType.ptr], returns: FFIType.bool });
|
|
905
|
+
return Number(symbols.hk_cursor_walk_json(e, q, cb, null));
|
|
906
|
+
},
|
|
907
|
+
viewGetPathInt: (view, path) => {
|
|
908
|
+
const out = new BigInt64Array(1);
|
|
909
|
+
return symbols.hk_view_get_path_int(view, toC(path), ptrOf(out)) ? out[0] : null;
|
|
910
|
+
},
|
|
911
|
+
viewGetPathFloat: (view, path) => {
|
|
912
|
+
const out = new Float64Array(1);
|
|
913
|
+
return symbols.hk_view_get_path_float(view, toC(path), ptrOf(out)) ? out[0] : null;
|
|
914
|
+
},
|
|
915
|
+
viewGetPathBool: (view, path) => {
|
|
916
|
+
const r = symbols.hk_view_get_path_bool(view, toC(path));
|
|
917
|
+
return r < 0 ? null : r !== 0;
|
|
918
|
+
},
|
|
919
|
+
viewGetPathStr: (view, path) => {
|
|
920
|
+
const len = new BigInt64Array(1);
|
|
921
|
+
const ptr = symbols.hk_view_get_path_str(view, toC(path), ptrOf(len));
|
|
922
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
923
|
+
},
|
|
924
|
+
viewGetPathBytes: (view, path) => {
|
|
925
|
+
const len = new BigInt64Array(1);
|
|
926
|
+
const ptr = symbols.hk_view_get_path_bytes(view, toC(path), ptrOf(len));
|
|
927
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
928
|
+
},
|
|
929
|
+
|
|
625
930
|
lastError: () => {
|
|
626
931
|
const ptr = symbols.hk_last_error();
|
|
627
932
|
return ptr ? new CString(ptr).toString() : 'unknown ffi error';
|
|
@@ -638,7 +943,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
638
943
|
// these EVERY struct-typed decl throws at bindings creation, i.e. the
|
|
639
944
|
// node backend was dead on arrival (bun resolves pointers structurally
|
|
640
945
|
// and never noticed). Declared once here for all present and future fns.
|
|
641
|
-
for (const t of ['HK_Array', 'HK_Batch', 'HK_CloudSync', 'HK_Config', 'HK_Doc', 'HK_Engine', 'HK_NetSyncer', 'HK_Query', 'HK_RawDoc', 'HK_RawResultSet', 'HK_ResultSet', 'HK_Transaction', 'HK_ViewDoc', 'HK_Watch']) koffi.opaque(t);
|
|
946
|
+
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);
|
|
642
947
|
|
|
643
948
|
// ponytail: owned C strings (Rust-allocated) must come back through a
|
|
644
949
|
// DISPOSABLE type wired to hk_string_free — never bare char* (koffi
|
|
@@ -652,6 +957,9 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
652
957
|
// hako.h). Kept as documentation; register() below takes the
|
|
653
958
|
// typedef NAME as a string, not this proto object.
|
|
654
959
|
const OnSnapshotCB = koffi.proto('void HK_OnSnapshotCallback(const char *collection, const char *path, int32_t kind, void *user_data)');
|
|
960
|
+
// ids are length-delimited (not NUL-terminated): take them as raw bytes.
|
|
961
|
+
const WalkCB = koffi.proto('bool HkWalkCallback(const uint8_t *id, size_t id_len, const uint8_t *bytes, size_t bytes_len, void *userdata)');
|
|
962
|
+
const ViewWalkCB = koffi.proto('bool HkViewWalkCallback(const uint8_t *id, size_t id_len, const HK_ViewDoc *view, void *userdata)');
|
|
655
963
|
|
|
656
964
|
const fn = {
|
|
657
965
|
hk_engine_open: lib.func('HK_Engine* hk_engine_open(const char* path)'),
|
|
@@ -701,6 +1009,11 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
701
1009
|
hk_engine_get: lib.func('HK_Doc* hk_engine_get(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
702
1010
|
hk_engine_delete: lib.func('int hk_engine_delete(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
703
1011
|
hk_engine_delete_local: lib.func('int hk_engine_delete_local(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1012
|
+
hk_engine_delete_ext: lib.func('int hk_engine_delete_ext(HK_Engine* engine, const char* collection, const char* doc_id, int32_t mode)'),
|
|
1013
|
+
hk_engine_restore: lib.func('int hk_engine_restore(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1014
|
+
hk_engine_restore_available: lib.func('HeapStr hk_engine_restore_available(HK_Engine* engine, const char* collection)'),
|
|
1015
|
+
hk_engine_delete_queue: lib.func('HeapStr hk_engine_delete_queue(HK_Engine* engine, const char* collection)'),
|
|
1016
|
+
hk_engine_sweep_now: lib.func('int hk_engine_sweep_now(HK_Engine* engine)'),
|
|
704
1017
|
hk_engine_set_collection_local: lib.func('int hk_engine_set_collection_local(HK_Engine* engine, const char* collection, int local)'),
|
|
705
1018
|
hk_engine_replicate_key: lib.func('int hk_engine_replicate_key(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
706
1019
|
hk_engine_replicate_collection: lib.func('int hk_engine_replicate_collection(HK_Engine* engine, const char* collection)'),
|
|
@@ -720,10 +1033,26 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
720
1033
|
hk_engine_create_edge_index: lib.func('int hk_engine_create_edge_index(HK_Engine* engine, const char* collection)'),
|
|
721
1034
|
hk_engine_shortest_paths: lib.func('HeapStr hk_engine_shortest_paths(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)'),
|
|
722
1035
|
|
|
1036
|
+
// v0.19.6 parity
|
|
1037
|
+
hk_engine_drop_simple_index: lib.func('int hk_engine_drop_simple_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1038
|
+
hk_engine_drop_vector_index: lib.func('int hk_engine_drop_vector_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1039
|
+
hk_engine_drop_composite_index: lib.func('int hk_engine_drop_composite_index(HK_Engine* engine, const char* collection, uint32_t id)'),
|
|
1040
|
+
hk_engine_drop_edge_index: lib.func('int hk_engine_drop_edge_index(HK_Engine* engine, const char* collection)'),
|
|
1041
|
+
hk_engine_drop_fts_index: lib.func('int hk_engine_drop_fts_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1042
|
+
hk_engine_drop_traverse_index: lib.func('int hk_engine_drop_traverse_index(HK_Engine* engine, const char* collection)'),
|
|
1043
|
+
hk_engine_create_vector_index_v2: lib.func('int hk_engine_create_vector_index_v2(HK_Engine* engine, const char* collection, const char* field, uint32_t dim, uint32_t metric, size_t m, size_t ef_construction, size_t ef_search)'),
|
|
1044
|
+
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)'),
|
|
1045
|
+
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)'),
|
|
1046
|
+
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)'),
|
|
1047
|
+
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)'),
|
|
1048
|
+
hk_engine_insert_json: lib.func('int hk_engine_insert_json(HK_Engine* engine, const char* collection, const char* doc_id, const char* json)'),
|
|
1049
|
+
hk_batch_set_json: lib.func('int hk_batch_set_json(HK_Batch* batch, const char* collection, const char* doc_id, const char* json)'),
|
|
1050
|
+
|
|
723
1051
|
hk_batch_new: lib.func('HK_Batch* hk_batch_new()'),
|
|
724
1052
|
hk_batch_free: lib.func('void hk_batch_free(HK_Batch* batch)'),
|
|
725
1053
|
hk_batch_set: lib.func('int hk_batch_set(HK_Batch* batch, const char* collection, const char* doc_id, const HK_Doc* doc)'),
|
|
726
1054
|
hk_batch_delete: lib.func('int hk_batch_delete(HK_Batch* batch, const char* collection, const char* doc_id)'),
|
|
1055
|
+
hk_batch_delete_ext: lib.func('int hk_batch_delete_ext(HK_Batch* batch, const char* collection, const char* doc_id, int32_t mode)'),
|
|
727
1056
|
hk_batch_commit: lib.func('int hk_batch_commit(HK_Engine* engine, HK_Batch* batch)'),
|
|
728
1057
|
|
|
729
1058
|
hk_transaction_begin: lib.func('HK_Transaction* hk_transaction_begin(HK_Engine* engine)'),
|
|
@@ -786,6 +1115,8 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
786
1115
|
hk_query_aggregate_count: lib.func('int hk_query_aggregate_count(HK_Query* query)'),
|
|
787
1116
|
hk_query_aggregate_sum: lib.func('int hk_query_aggregate_sum(HK_Query* query, const char* field)'),
|
|
788
1117
|
hk_query_aggregate_avg: lib.func('int hk_query_aggregate_avg(HK_Query* query, const char* field)'),
|
|
1118
|
+
hk_query_aggregate_min: lib.func('int hk_query_aggregate_min(HK_Query* query, const char* field)'),
|
|
1119
|
+
hk_query_aggregate_max: lib.func('int hk_query_aggregate_max(HK_Query* query, const char* field)'),
|
|
789
1120
|
hk_query_execute_aggregation: lib.func('HeapStr hk_query_execute_aggregation(HK_Engine* engine, const HK_Query* query)'),
|
|
790
1121
|
hk_query_where_or_str: lib.func('int hk_query_where_or_str(HK_Query* query, const char* field, const char* value)'),
|
|
791
1122
|
hk_query_where_or_int: lib.func('int hk_query_where_or_int(HK_Query* query, const char* field, int64_t value)'),
|
|
@@ -833,6 +1164,61 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
833
1164
|
hk_cloud_sync_stop: lib.func('void hk_cloud_sync_stop(HK_CloudSync* cloud_sync)'),
|
|
834
1165
|
hk_cloud_sync_free: lib.func('void hk_cloud_sync_free(HK_CloudSync* cloud_sync)'),
|
|
835
1166
|
|
|
1167
|
+
// 0.16.5 parity: F8 schemas, F5 versioned/tx, F7 explain, F3 predicates,
|
|
1168
|
+
// F4 pipelines, config knobs, quiescence, lazy walks and borrowed reads.
|
|
1169
|
+
hk_config_set_group_commit_interval_ms: lib.func('void hk_config_set_group_commit_interval_ms(HK_Config* config, uint64_t ms)'),
|
|
1170
|
+
hk_config_set_page_cache_capacity: lib.func('void hk_config_set_page_cache_capacity(HK_Config* config, size_t capacity)'),
|
|
1171
|
+
hk_config_set_sync_excluded: lib.func('int hk_config_set_sync_excluded(HK_Config* config, const char* collections_json)'),
|
|
1172
|
+
hk_config_set_lazy_collections: lib.func('int hk_config_set_lazy_collections(HK_Config* config, const char* collections_json)'),
|
|
1173
|
+
hk_config_set_replication_collections: lib.func('int hk_config_set_replication_collections(HK_Config* config, const char* collections_json)'),
|
|
1174
|
+
hk_engine_await_quiescent: lib.func('bool hk_engine_await_quiescent(HK_Engine* engine, uint64_t timeout_ms)'),
|
|
1175
|
+
hk_engine_quiescence_status: lib.func('HeapStr hk_engine_quiescence_status(HK_Engine* engine)'),
|
|
1176
|
+
hk_engine_get_versioned: lib.func('HK_Doc* hk_engine_get_versioned(HK_Engine* engine, const char* collection, const char* doc_id, _Out_ uint64_t *out_version)'),
|
|
1177
|
+
hk_engine_set_schema: lib.func('int hk_engine_set_schema(HK_Engine* engine, const char* collection, const char* schema_json)'),
|
|
1178
|
+
hk_engine_get_schema: lib.func('HeapStr hk_engine_get_schema(HK_Engine* engine, const char* collection)'),
|
|
1179
|
+
hk_engine_clear_schema: lib.func('int hk_engine_clear_schema(HK_Engine* engine, const char* collection)'),
|
|
1180
|
+
hk_engine_list_schemas: lib.func('HeapStr hk_engine_list_schemas(HK_Engine* engine)'),
|
|
1181
|
+
hk_query_explain: lib.func('HeapStr hk_query_explain(HK_Engine* engine, const HK_Query* query)'),
|
|
1182
|
+
hk_query_where_array_all_eq: lib.func('int hk_query_where_array_all_eq(HK_Query* query, const char* field, const char* value_json)'),
|
|
1183
|
+
hk_query_where_elem_match: lib.func('int hk_query_where_elem_match(HK_Query* query, const char* field, const char* filters_json)'),
|
|
1184
|
+
hk_query_where_near: lib.func('int hk_query_where_near(HK_Query* query, const char* field, const float* vec, size_t len)'),
|
|
1185
|
+
hk_query_where_traverse: lib.func('int hk_query_where_traverse(HK_Query* query, const char* start_col, const char* start_id, uint32_t direction, const char* edge_field, size_t max_depth)'),
|
|
1186
|
+
hk_pipeline_new: lib.func('HK_Pipeline* hk_pipeline_new(const char* collection)'),
|
|
1187
|
+
hk_pipeline_free: lib.func('void hk_pipeline_free(HK_Pipeline* pipeline)'),
|
|
1188
|
+
hk_pipeline_match: lib.func('int hk_pipeline_match(HK_Pipeline* pipeline, const HK_Query* query)'),
|
|
1189
|
+
hk_pipeline_project: lib.func('int hk_pipeline_project(HK_Pipeline* pipeline, const char* fields_json)'),
|
|
1190
|
+
hk_pipeline_sort: lib.func('int hk_pipeline_sort(HK_Pipeline* pipeline, const char* field, bool ascending)'),
|
|
1191
|
+
hk_pipeline_limit: lib.func('int hk_pipeline_limit(HK_Pipeline* pipeline, size_t limit)'),
|
|
1192
|
+
hk_pipeline_offset: lib.func('int hk_pipeline_offset(HK_Pipeline* pipeline, size_t offset)'),
|
|
1193
|
+
hk_pipeline_unwind: lib.func('int hk_pipeline_unwind(HK_Pipeline* pipeline, const char* field)'),
|
|
1194
|
+
hk_pipeline_group: lib.func('int hk_pipeline_group(HK_Pipeline* pipeline, const char* key, const char* accums_json)'),
|
|
1195
|
+
hk_pipeline_execute: lib.func('HeapStr hk_pipeline_execute(HK_Engine* engine, const HK_Pipeline* pipeline)'),
|
|
1196
|
+
hk_pipeline_execute_to_handles: lib.func('HK_ResultSet* hk_pipeline_execute_to_handles(HK_Engine* engine, const HK_Pipeline* pipeline)'),
|
|
1197
|
+
hk_transaction_get_many: lib.func('HeapStr hk_transaction_get_many(HK_Engine* engine, HK_Transaction* tx, const char* collection, const char* ids_json)'),
|
|
1198
|
+
hk_transaction_patch: lib.func('int hk_transaction_patch(HK_Engine* engine, HK_Transaction* tx, const char* collection, const char* doc_id, const char* updates_json)'),
|
|
1199
|
+
hk_error_last_kind: lib.func('int hk_error_last_kind()'),
|
|
1200
|
+
hk_error_is_retryable: lib.func('bool hk_error_is_retryable()'),
|
|
1201
|
+
hk_debug_write_stats: lib.func('HeapStr hk_debug_write_stats()'),
|
|
1202
|
+
hk_log_enable_stderr: lib.func('void hk_log_enable_stderr()'),
|
|
1203
|
+
hk_log_disable_stderr: lib.func('void hk_log_disable_stderr()'),
|
|
1204
|
+
hk_cursor_walk: lib.func('int64_t hk_cursor_walk(HK_Engine* engine, const HK_Query* query, HkWalkCallback* callback, void* userdata)'),
|
|
1205
|
+
hk_cursor_walk_view: lib.func('int64_t hk_cursor_walk_view(HK_Engine* engine, const HK_Query* query, HkViewWalkCallback* callback, void* userdata)'),
|
|
1206
|
+
hk_rawdoc_bytes: lib.func('const uint8_t* hk_rawdoc_bytes(const HK_RawDoc* doc, _Out_ uintptr_t *len_out)'),
|
|
1207
|
+
// Return as uint8_t* so koffi hands back a pointer; the id is
|
|
1208
|
+
// length-delimited, not NUL-terminated.
|
|
1209
|
+
hk_rawdoc_id: lib.func('const uint8_t* hk_rawdoc_id(const HK_RawDoc* doc, _Out_ uintptr_t *len_out)'),
|
|
1210
|
+
hk_view_get_str: lib.func('const uint8_t* hk_view_get_str(const HK_ViewDoc* view, const char* key, _Out_ uintptr_t *len_out)'),
|
|
1211
|
+
hk_view_get_bytes: lib.func('const uint8_t* hk_view_get_bytes(const HK_ViewDoc* view, const char* key, _Out_ uintptr_t *len_out)'),
|
|
1212
|
+
hk_engine_get_json: lib.func('HeapStr hk_engine_get_json(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1213
|
+
hk_query_execute_json: lib.func('HeapStr hk_query_execute_json(HK_Engine* engine, const HK_Query* query)'),
|
|
1214
|
+
hk_cursor_walk_json: lib.func('int64_t hk_cursor_walk_json(HK_Engine* engine, const HK_Query* query, HkWalkCallback* callback, void* userdata)'),
|
|
1215
|
+
hk_view_to_json: lib.func('HeapStr hk_view_to_json(const HK_ViewDoc* view)'),
|
|
1216
|
+
hk_view_get_path_int: lib.func('bool hk_view_get_path_int(const HK_ViewDoc* view, const char* path, _Out_ int64_t *out)'),
|
|
1217
|
+
hk_view_get_path_float: lib.func('bool hk_view_get_path_float(const HK_ViewDoc* view, const char* path, _Out_ double *out)'),
|
|
1218
|
+
hk_view_get_path_bool: lib.func('int hk_view_get_path_bool(const HK_ViewDoc* view, const char* path)'),
|
|
1219
|
+
hk_view_get_path_str: lib.func('const uint8_t* hk_view_get_path_str(const HK_ViewDoc* view, const char* path, _Out_ uintptr_t *len_out)'),
|
|
1220
|
+
hk_view_get_path_bytes: lib.func('const uint8_t* hk_view_get_path_bytes(const HK_ViewDoc* view, const char* path, _Out_ uintptr_t *len_out)'),
|
|
1221
|
+
|
|
836
1222
|
hk_last_error: lib.func('const char* hk_last_error()'),
|
|
837
1223
|
hk_string_free: lib.func('void hk_string_free(void* value)')
|
|
838
1224
|
};
|
|
@@ -895,6 +1281,11 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
895
1281
|
engineGet: (engine, collection, docId) => fn.hk_engine_get(engine, collection, docId),
|
|
896
1282
|
engineDelete: (engine, collection, docId) => fn.hk_engine_delete(engine, collection, docId),
|
|
897
1283
|
engineDeleteLocal: (engine, collection, docId) => fn.hk_engine_delete_local(engine, collection, docId),
|
|
1284
|
+
engineDeleteEx: (engine, collection, docId, force) => fn.hk_engine_delete_ext(engine, collection, docId, force ? 1 : 0),
|
|
1285
|
+
engineRestore: (engine, collection, docId) => fn.hk_engine_restore(engine, collection, docId),
|
|
1286
|
+
engineRestoreAvailable: (engine, collection) => ptrToStringAndFree(fn.hk_engine_restore_available(engine, collection as unknown as string)),
|
|
1287
|
+
engineDeleteQueue: (engine, collection) => ptrToStringAndFree(fn.hk_engine_delete_queue(engine, collection as unknown as string)),
|
|
1288
|
+
engineSweepNow: (engine) => fn.hk_engine_sweep_now(engine),
|
|
898
1289
|
engineSetCollectionLocal: (engine, collection, local) => fn.hk_engine_set_collection_local(engine, collection, local),
|
|
899
1290
|
engineReplicateKey: (engine, collection, docId) => fn.hk_engine_replicate_key(engine, collection, docId),
|
|
900
1291
|
engineReplicateCollection: (engine, collection) => fn.hk_engine_replicate_collection(engine, collection),
|
|
@@ -912,6 +1303,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
912
1303
|
batchFree: (batch) => fn.hk_batch_free(batch),
|
|
913
1304
|
batchSet: (batch, collection, docId, doc) => fn.hk_batch_set(batch, collection, docId, doc),
|
|
914
1305
|
batchDelete: (batch, collection, docId) => fn.hk_batch_delete(batch, collection, docId),
|
|
1306
|
+
batchDeleteEx: (batch, collection, docId, force) => fn.hk_batch_delete_ext(batch, collection, docId, force ? 1 : 0),
|
|
915
1307
|
batchCommit: (engine, batch) => fn.hk_batch_commit(engine, batch),
|
|
916
1308
|
|
|
917
1309
|
transactionBegin: (engine) => fn.hk_transaction_begin(engine),
|
|
@@ -985,6 +1377,8 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
985
1377
|
queryAggregateCount: (q) => fn.hk_query_aggregate_count(q),
|
|
986
1378
|
queryAggregateSum: (q, f) => fn.hk_query_aggregate_sum(q, f),
|
|
987
1379
|
queryAggregateAvg: (q, f) => fn.hk_query_aggregate_avg(q, f),
|
|
1380
|
+
queryAggregateMin: (q, f) => fn.hk_query_aggregate_min(q, f),
|
|
1381
|
+
queryAggregateMax: (q, f) => fn.hk_query_aggregate_max(q, f),
|
|
988
1382
|
queryExecuteAggregation: (e, q) => ptrToStringAndFree(fn.hk_query_execute_aggregation(e, q)),
|
|
989
1383
|
engineListCollections: (engine) => ptrToStringAndFree(fn.hk_engine_list_collections(engine)),
|
|
990
1384
|
netSyncerNew: (engine, name, roomKey) => fn.hk_net_syncer_new(engine, name, roomKey),
|
|
@@ -1016,6 +1410,21 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1016
1410
|
createEdgeIndex: (engine, collection) => fn.hk_engine_create_edge_index(engine, collection),
|
|
1017
1411
|
engineShortestPaths: (engine, collection, id, direction, edge, via, weight, maxDepth, k) => fn.hk_engine_shortest_paths(engine, collection, id, direction, edge, via, weight, maxDepth, k),
|
|
1018
1412
|
|
|
1413
|
+
// v0.19.6 parity (koffi takes null for char* directly)
|
|
1414
|
+
dropSimpleIndex: (engine, collection, field) => fn.hk_engine_drop_simple_index(engine, collection, field),
|
|
1415
|
+
dropVectorIndex: (engine, collection, field) => fn.hk_engine_drop_vector_index(engine, collection, field),
|
|
1416
|
+
dropCompositeIndex: (engine, collection, id) => fn.hk_engine_drop_composite_index(engine, collection, id),
|
|
1417
|
+
dropEdgeIndex: (engine, collection) => fn.hk_engine_drop_edge_index(engine, collection),
|
|
1418
|
+
dropFtsIndex: (engine, collection, field) => fn.hk_engine_drop_fts_index(engine, collection, field),
|
|
1419
|
+
dropTraverseIndex: (engine, collection) => fn.hk_engine_drop_traverse_index(engine, collection),
|
|
1420
|
+
createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch) => fn.hk_engine_create_vector_index_v2(engine, collection, field, dim, metric, m, efConstruction, efSearch),
|
|
1421
|
+
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),
|
|
1422
|
+
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),
|
|
1423
|
+
exportGraph: (engine, collection, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_export_graph(engine, collection, direction, edge, via, nodeField, nodeJSON),
|
|
1424
|
+
graphAnalysis: (engine, collection, op, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_graph_analysis(engine, collection, op, direction, edge, via, nodeField, nodeJSON),
|
|
1425
|
+
insertJSON: (engine, collection, id, json) => fn.hk_engine_insert_json(engine, collection, id, json),
|
|
1426
|
+
batchSetJSON: (batch, collection, id, json) => fn.hk_batch_set_json(batch, collection, id, json),
|
|
1427
|
+
|
|
1019
1428
|
// Array API
|
|
1020
1429
|
arrayNew: () => fn.hk_array_new(),
|
|
1021
1430
|
arrayFree: (arr) => fn.hk_array_free(arr),
|
|
@@ -1038,6 +1447,117 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1038
1447
|
queryEndAt: (query, anchorDoc) => fn.hk_query_end_at(query, anchorDoc),
|
|
1039
1448
|
queryEndBefore: (query, anchorDoc) => fn.hk_query_end_before(query, anchorDoc),
|
|
1040
1449
|
|
|
1450
|
+
// 0.16.5 parity.
|
|
1451
|
+
engineSetSchema: (e, c, json) => fn.hk_engine_set_schema(e, c, json),
|
|
1452
|
+
engineGetSchema: (e, c) => ptrToStringAndFree(fn.hk_engine_get_schema(e, c)),
|
|
1453
|
+
engineClearSchema: (e, c) => fn.hk_engine_clear_schema(e, c),
|
|
1454
|
+
engineListSchemas: (e) => ptrToStringAndFree(fn.hk_engine_list_schemas(e)),
|
|
1455
|
+
engineGetVersioned: (e, c, id) => {
|
|
1456
|
+
const out: bigint[] = [0n];
|
|
1457
|
+
const doc = fn.hk_engine_get_versioned(e, c, id, out);
|
|
1458
|
+
return { doc, version: out[0] };
|
|
1459
|
+
},
|
|
1460
|
+
engineAwaitQuiescent: (e, ms) => fn.hk_engine_await_quiescent(e, ms),
|
|
1461
|
+
engineQuiescenceStatus: (e) => ptrToStringAndFree(fn.hk_engine_quiescence_status(e)),
|
|
1462
|
+
transactionGetMany: (e, tx, c, idsJson) => ptrToStringAndFree(fn.hk_transaction_get_many(e, tx, c, idsJson)),
|
|
1463
|
+
transactionPatch: (e, tx, c, id, updatesJson) => fn.hk_transaction_patch(e, tx, c, id, updatesJson),
|
|
1464
|
+
errorLastKind: () => fn.hk_error_last_kind(),
|
|
1465
|
+
errorIsRetryable: () => fn.hk_error_is_retryable(),
|
|
1466
|
+
debugWriteStats: () => ptrToStringAndFree(fn.hk_debug_write_stats()),
|
|
1467
|
+
logEnableStderr: () => fn.hk_log_enable_stderr(),
|
|
1468
|
+
logDisableStderr: () => fn.hk_log_disable_stderr(),
|
|
1469
|
+
queryExplain: (e, q) => ptrToStringAndFree(fn.hk_query_explain(e, q)),
|
|
1470
|
+
queryWhereArrayAllEq: (q, f, json) => fn.hk_query_where_array_all_eq(q, f, json),
|
|
1471
|
+
queryWhereElemMatch: (q, f, json) => fn.hk_query_where_elem_match(q, f, json),
|
|
1472
|
+
queryWhereNear: (q, f, vec) => fn.hk_query_where_near(q, f, Buffer.from(vec.buffer, vec.byteOffset, vec.byteLength), vec.length),
|
|
1473
|
+
queryWhereTraverse: (q, sc, sid, dir, edge, depth) => fn.hk_query_where_traverse(q, sc, sid, dir, edge, depth),
|
|
1474
|
+
pipelineNew: (c) => fn.hk_pipeline_new(c),
|
|
1475
|
+
pipelineFree: (p) => fn.hk_pipeline_free(p),
|
|
1476
|
+
pipelineMatch: (p, q) => fn.hk_pipeline_match(p, q),
|
|
1477
|
+
pipelineProject: (p, json) => fn.hk_pipeline_project(p, json),
|
|
1478
|
+
pipelineSort: (p, f, asc) => fn.hk_pipeline_sort(p, f, asc),
|
|
1479
|
+
pipelineLimit: (p, n) => fn.hk_pipeline_limit(p, n),
|
|
1480
|
+
pipelineOffset: (p, n) => fn.hk_pipeline_offset(p, n),
|
|
1481
|
+
pipelineUnwind: (p, f) => fn.hk_pipeline_unwind(p, f),
|
|
1482
|
+
pipelineGroup: (p, k, json) => fn.hk_pipeline_group(p, k, json),
|
|
1483
|
+
pipelineExecute: (e, p) => ptrToStringAndFree(fn.hk_pipeline_execute(e, p)),
|
|
1484
|
+
pipelineExecuteToHandles: (e, p) => fn.hk_pipeline_execute_to_handles(e, p),
|
|
1485
|
+
configSetGroupCommitIntervalMs: (c, ms) => fn.hk_config_set_group_commit_interval_ms(c, ms),
|
|
1486
|
+
configSetPageCacheCapacity: (c, n) => fn.hk_config_set_page_cache_capacity(c, n),
|
|
1487
|
+
configSetSyncExcluded: (c, json) => fn.hk_config_set_sync_excluded(c, json),
|
|
1488
|
+
configSetLazyCollections: (c, json) => fn.hk_config_set_lazy_collections(c, json),
|
|
1489
|
+
configSetReplicationCollections: (c, json) => fn.hk_config_set_replication_collections(c, json),
|
|
1490
|
+
cursorWalk: (e, q, callback) => {
|
|
1491
|
+
const wrapper = (id: any, idLen: number, bytes: any, bytesLen: number) => {
|
|
1492
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1493
|
+
const rowBytes = Uint8Array.from(koffi.decode(bytes, 'uint8_t', Number(bytesLen)));
|
|
1494
|
+
return callback(rowId, rowBytes);
|
|
1495
|
+
};
|
|
1496
|
+
return Number(fn.hk_cursor_walk(e, q, koffi.register(wrapper, 'HkWalkCallback *'), null));
|
|
1497
|
+
},
|
|
1498
|
+
cursorWalkView: (e, q, callback) => {
|
|
1499
|
+
const wrapper = (id: any, idLen: number, view: any) => {
|
|
1500
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1501
|
+
return callback(rowId, view);
|
|
1502
|
+
};
|
|
1503
|
+
return Number(fn.hk_cursor_walk_view(e, q, koffi.register(wrapper, 'HkViewWalkCallback *'), null));
|
|
1504
|
+
},
|
|
1505
|
+
rawDocBytes: (raw) => {
|
|
1506
|
+
const len: number[] = [0];
|
|
1507
|
+
const ptr = fn.hk_rawdoc_bytes(raw, len);
|
|
1508
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1509
|
+
},
|
|
1510
|
+
rawDocId: (raw) => {
|
|
1511
|
+
const len: number[] = [0];
|
|
1512
|
+
const ptr = fn.hk_rawdoc_id(raw, len);
|
|
1513
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1514
|
+
},
|
|
1515
|
+
viewGetStr: (view, key) => {
|
|
1516
|
+
const len: number[] = [0];
|
|
1517
|
+
const ptr = fn.hk_view_get_str(view, key, len);
|
|
1518
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1519
|
+
},
|
|
1520
|
+
viewGetBytes: (view, key) => {
|
|
1521
|
+
const len: number[] = [0];
|
|
1522
|
+
const ptr = fn.hk_view_get_bytes(view, key, len);
|
|
1523
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1524
|
+
},
|
|
1525
|
+
|
|
1526
|
+
// P2 (core 0.18): JSON read paths + dotted-path pulls.
|
|
1527
|
+
engineGetJson: (e, c, id) => ptrToStringAndFree(fn.hk_engine_get_json(e, c, id)),
|
|
1528
|
+
queryExecuteJson: (e, q) => ptrToStringAndFree(fn.hk_query_execute_json(e, q)),
|
|
1529
|
+
viewToJson: (view) => ptrToStringAndFree(fn.hk_view_to_json(view)),
|
|
1530
|
+
cursorWalkJson: (e, q, callback) => {
|
|
1531
|
+
const wrapper = (id: any, idLen: number, json: any, jsonLen: number) => {
|
|
1532
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1533
|
+
const rowJson = Uint8Array.from(koffi.decode(json, 'uint8_t', Number(jsonLen)));
|
|
1534
|
+
return callback(rowId, rowJson);
|
|
1535
|
+
};
|
|
1536
|
+
return Number(fn.hk_cursor_walk_json(e, q, koffi.register(wrapper, 'HkWalkCallback *'), null));
|
|
1537
|
+
},
|
|
1538
|
+
viewGetPathInt: (view, path) => {
|
|
1539
|
+
const out: bigint[] = [0n];
|
|
1540
|
+
return fn.hk_view_get_path_int(view, path, out) ? out[0] : null;
|
|
1541
|
+
},
|
|
1542
|
+
viewGetPathFloat: (view, path) => {
|
|
1543
|
+
const out: number[] = [0];
|
|
1544
|
+
return fn.hk_view_get_path_float(view, path, out) ? out[0] : null;
|
|
1545
|
+
},
|
|
1546
|
+
viewGetPathBool: (view, path) => {
|
|
1547
|
+
const r: number = fn.hk_view_get_path_bool(view, path);
|
|
1548
|
+
return r < 0 ? null : r !== 0;
|
|
1549
|
+
},
|
|
1550
|
+
viewGetPathStr: (view, path) => {
|
|
1551
|
+
const len: number[] = [0];
|
|
1552
|
+
const ptr = fn.hk_view_get_path_str(view, path, len);
|
|
1553
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1554
|
+
},
|
|
1555
|
+
viewGetPathBytes: (view, path) => {
|
|
1556
|
+
const len: number[] = [0];
|
|
1557
|
+
const ptr = fn.hk_view_get_path_bytes(view, path, len);
|
|
1558
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1559
|
+
},
|
|
1560
|
+
|
|
1041
1561
|
lastError: () => (fn.hk_last_error() as string) || 'unknown ffi error'
|
|
1042
1562
|
};
|
|
1043
1563
|
}
|