@hakodb/client 0.5.20 → 0.6.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/README.md +6 -2
- package/package.json +1 -1
- package/src/client.ts +371 -1
- package/src/native.ts +494 -4
package/README.md
CHANGED
|
@@ -18,6 +18,10 @@ FFI bindings over koffi/Bun (`native.ts`). Tauri lives in `@hakodb/tauri`
|
|
|
18
18
|
| 0.5.18 | `hakodb v0.15.0` (Phase B: `createEdgeIndex` + `shortestPaths` Dijkstra over `hk_engine_shortest_paths`) |
|
|
19
19
|
| 0.5.19 | `hakodb v0.15.3` (native DLL refresh: ring-only TLS + shared sync framing) |
|
|
20
20
|
| 0.5.20 | `hakodb v0.16.0` (`createCloudSyncServer` room params: `roomName`/`roomKey`) |
|
|
21
|
+
| 0.5.21 | `hakodb v0.16.0` (Bun FFI arity fix) |
|
|
22
|
+
| 0.5.22 | `hakodb v0.16.5` (schemas, versioned reads, quiescence, explain, elemMatch/allEq/near/traverse, raw C-ABI parity) |
|
|
23
|
+
| 0.5.23 | `hakodb v0.18.0` (P2 JSON read paths: `getJson` point + query fast paths, view dotted-path pulls) |
|
|
24
|
+
| 0.5.24 | `hakodb v0.19.0` (`min`/`max` simple aggregation, `null` when no numeric value) |
|
|
21
25
|
|
|
22
26
|
## Setup — native library
|
|
23
27
|
|
|
@@ -26,8 +30,8 @@ FFI bindings over koffi/Bun (`native.ts`). Tauri lives in `@hakodb/tauri`
|
|
|
26
30
|
`./native/<lib>`. Populate it with the sync script:
|
|
27
31
|
|
|
28
32
|
```powershell
|
|
29
|
-
.\sync-native.ps1 -CoreDir C:\Dev\libs\
|
|
30
|
-
.\sync-native.ps1 -Tag v0.
|
|
33
|
+
.\sync-native.ps1 -CoreDir C:\Dev\libs\hakodb
|
|
34
|
+
.\sync-native.ps1 -Tag v0.19.0
|
|
31
35
|
```
|
|
32
36
|
|
|
33
37
|
Binaries under `native/` are git-ignored.
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -36,6 +36,55 @@ export interface PathHit {
|
|
|
36
36
|
depth: number;
|
|
37
37
|
cost?: number;
|
|
38
38
|
doc: HakoDocData;
|
|
39
|
+
/** Route projections, only present when opted in via PathOptions. */
|
|
40
|
+
path?: string[];
|
|
41
|
+
/** Edge docs as JSON strings; null for anonymous edges. */
|
|
42
|
+
via?: (string | null)[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A predicate: docs whose `field` equals `equals` travel (or stop). */
|
|
46
|
+
export interface PathFilter {
|
|
47
|
+
field: string;
|
|
48
|
+
equals: unknown;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** v0.19 traverse extensions shared by findPathsFull/shortestPathsFull/exportGraph/graphAnalysis. */
|
|
52
|
+
export interface PathOptions {
|
|
53
|
+
direction?: TraverseDirection;
|
|
54
|
+
edge?: string | null;
|
|
55
|
+
via?: string | null;
|
|
56
|
+
maxDepth?: number;
|
|
57
|
+
k?: number;
|
|
58
|
+
includePath?: boolean;
|
|
59
|
+
includeVia?: boolean;
|
|
60
|
+
nodeFilter?: PathFilter;
|
|
61
|
+
edgeType?: PathFilter;
|
|
62
|
+
edgeMatch?: PathFilter;
|
|
63
|
+
/** Shortest paths only: numeric prop name on edge docs (null = uniform 1.0). */
|
|
64
|
+
weight?: string | null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function resolvePathOptions(opts: PathOptions) {
|
|
68
|
+
const f = (p?: PathFilter) => (p ? { field: p.field, json: JSON.stringify(p.equals ?? null) } : { field: null, json: null });
|
|
69
|
+
const node = f(opts.nodeFilter);
|
|
70
|
+
const type = f(opts.edgeType);
|
|
71
|
+
const match = f(opts.edgeMatch);
|
|
72
|
+
return {
|
|
73
|
+
direction: opts.direction === 'incoming' ? 1 : opts.direction === 'both' ? 2 : 0,
|
|
74
|
+
edge: opts.edge ?? null,
|
|
75
|
+
via: opts.via ?? null,
|
|
76
|
+
maxDepth: opts.maxDepth ?? 10,
|
|
77
|
+
k: opts.k ?? 100,
|
|
78
|
+
includePath: opts.includePath ?? false,
|
|
79
|
+
includeVia: opts.includeVia ?? false,
|
|
80
|
+
nodeField: node.field,
|
|
81
|
+
nodeJSON: node.json,
|
|
82
|
+
typeField: type.field,
|
|
83
|
+
typeJSON: type.json,
|
|
84
|
+
matchField: match.field,
|
|
85
|
+
matchJSON: match.json,
|
|
86
|
+
weight: opts.weight ?? null,
|
|
87
|
+
};
|
|
39
88
|
}
|
|
40
89
|
|
|
41
90
|
const SERVER_TIMESTAMP_SENTINEL = "__FL_SERVER_TIMESTAMP__";
|
|
@@ -65,15 +114,35 @@ export interface HakoClientOptions {
|
|
|
65
114
|
// 2. FIXED: Added 'in' to the interface to match the Query class
|
|
66
115
|
export interface QueryConstraint {
|
|
67
116
|
field: string;
|
|
68
|
-
op: '==' | '!=' | '>' | '>=' | '<' | '<=' | 'match' | 'matchPrefix' | 'contains' | 'startsWith' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';
|
|
117
|
+
op: '==' | '!=' | '>' | '>=' | '<' | '<=' | 'match' | 'matchPrefix' | 'contains' | 'startsWith' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any' | 'elemMatch' | 'arrayAllEq';
|
|
69
118
|
value: any; // Use any because 'in' takes an array
|
|
70
119
|
}
|
|
71
120
|
|
|
121
|
+
/** One element-relative predicate for whereElemMatch (F3). */
|
|
122
|
+
export interface ElemFilter {
|
|
123
|
+
field: string;
|
|
124
|
+
op: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'match' | 'match_prefix' | 'contains' | 'starts_with' | 'in' | 'not_in' | 'array_contains' | 'array_contains_any' | 'array_all_eq';
|
|
125
|
+
value: unknown;
|
|
126
|
+
}
|
|
127
|
+
|
|
72
128
|
export interface QueryOrder {
|
|
73
129
|
field: string;
|
|
74
130
|
ascending: boolean;
|
|
75
131
|
}
|
|
76
132
|
|
|
133
|
+
/** One declared field rule (F8). Kind names match the core wire format. */
|
|
134
|
+
export interface HakoFieldRule {
|
|
135
|
+
name: string;
|
|
136
|
+
kind: 'string' | 'int' | 'float' | 'bool' | 'null' | 'array' | 'map' | 'bytes' | 'timestamp' | 'any';
|
|
137
|
+
required?: boolean;
|
|
138
|
+
default?: unknown;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Per-collection schema declaration (F8). Empty fields = no constraints. */
|
|
142
|
+
export interface HakoSchema {
|
|
143
|
+
fields: HakoFieldRule[];
|
|
144
|
+
}
|
|
145
|
+
|
|
77
146
|
export type Unsubscribe = () => Promise<void>;
|
|
78
147
|
|
|
79
148
|
/**
|
|
@@ -139,6 +208,31 @@ export class HakoConfig {
|
|
|
139
208
|
return this;
|
|
140
209
|
}
|
|
141
210
|
|
|
211
|
+
setGroupCommitIntervalMs(ms: number): this {
|
|
212
|
+
this._native.configSetGroupCommitIntervalMs(this._handle, ms);
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
setPageCacheCapacity(capacity: number): this {
|
|
217
|
+
this._native.configSetPageCacheCapacity(this._handle, capacity);
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setSyncExcluded(...collections: string[]): this {
|
|
222
|
+
ensureOk(this._native.configSetSyncExcluded(this._handle, JSON.stringify(collections)), this._native, 'configSetSyncExcluded');
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
setLazyCollections(...collections: string[]): this {
|
|
227
|
+
ensureOk(this._native.configSetLazyCollections(this._handle, JSON.stringify(collections)), this._native, 'configSetLazyCollections');
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
setReplicationCollections(...collections: string[]): this {
|
|
232
|
+
ensureOk(this._native.configSetReplicationCollections(this._handle, JSON.stringify(collections)), this._native, 'configSetReplicationCollections');
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
|
|
142
236
|
getHandle(): unknown {
|
|
143
237
|
return this._handle;
|
|
144
238
|
}
|
|
@@ -328,6 +422,27 @@ export class ViewDocSnapshot {
|
|
|
328
422
|
return this.client.nativeBindings().viewGetBool(this.handle, field);
|
|
329
423
|
}
|
|
330
424
|
|
|
425
|
+
/** Dotted-path pulls (core 0.18+): `a.b.c` reads without a full decode. */
|
|
426
|
+
getPathInt(path: string): number | bigint | null {
|
|
427
|
+
return this.client.nativeBindings().viewGetPathInt(this.handle, path);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
getPathFloat(path: string): number | null {
|
|
431
|
+
return this.client.nativeBindings().viewGetPathFloat(this.handle, path);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
getPathBool(path: string): boolean | null {
|
|
435
|
+
return this.client.nativeBindings().viewGetPathBool(this.handle, path);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
getPathString(path: string): string | null {
|
|
439
|
+
return this.client.nativeBindings().viewGetPathStr(this.handle, path);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
getPathBytes(path: string): Uint8Array | null {
|
|
443
|
+
return this.client.nativeBindings().viewGetPathBytes(this.handle, path);
|
|
444
|
+
}
|
|
445
|
+
|
|
331
446
|
/** Full decode + inflate. Prefer pulls for sparse reads. */
|
|
332
447
|
async resolve(): Promise<HakoDocData | undefined> {
|
|
333
448
|
const native = this.client.nativeBindings();
|
|
@@ -401,6 +516,51 @@ export class HakoClient {
|
|
|
401
516
|
return json ? JSON.parse(json) : [];
|
|
402
517
|
}
|
|
403
518
|
|
|
519
|
+
/** Declare or replace a collection schema (F8). */
|
|
520
|
+
async setSchema(collection: string, schema: HakoSchema): Promise<void> {
|
|
521
|
+
this.assertOpen();
|
|
522
|
+
ensureOk(this.native.engineSetSchema(this.engine, collection, JSON.stringify(schema)), this.native, 'engineSetSchema');
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** Absent collection returns null, not an error. */
|
|
526
|
+
async getSchema(collection: string): Promise<HakoSchema | null> {
|
|
527
|
+
this.assertOpen();
|
|
528
|
+
const json = this.native.engineGetSchema(this.engine, collection);
|
|
529
|
+
return json ? (JSON.parse(json) as HakoSchema) : null;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
async clearSchema(collection: string): Promise<void> {
|
|
533
|
+
this.assertOpen();
|
|
534
|
+
ensureOk(this.native.engineClearSchema(this.engine, collection), this.native, 'engineClearSchema');
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async listSchemas(): Promise<Record<string, HakoSchema>> {
|
|
538
|
+
this.assertOpen();
|
|
539
|
+
const json = this.native.engineListSchemas(this.engine);
|
|
540
|
+
return json ? (JSON.parse(json) as Record<string, HakoSchema>) : {};
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** Read a doc and the commit version it was read at (F5). */
|
|
544
|
+
async getVersioned(collection: string, docId: string): Promise<{ snapshot: DocumentSnapshot; version: bigint } | null> {
|
|
545
|
+
this.assertOpen();
|
|
546
|
+
const { doc, version } = this.native.engineGetVersioned(this.engine, collection, docId);
|
|
547
|
+
if (!doc) return null;
|
|
548
|
+
const json = this.native.docToJson(doc);
|
|
549
|
+
return { snapshot: new DocumentSnapshot(docId, true, parseDocJson(json), doc), version };
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/** Wait for background index/blob/maintenance work, bounded by timeoutMs. */
|
|
553
|
+
async awaitQuiescent(timeoutMs: number = 5000): Promise<boolean> {
|
|
554
|
+
this.assertOpen();
|
|
555
|
+
return this.native.engineAwaitQuiescent(this.engine, timeoutMs);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
async quiescenceStatus(): Promise<Record<string, unknown> | null> {
|
|
559
|
+
this.assertOpen();
|
|
560
|
+
const json = this.native.engineQuiescenceStatus(this.engine);
|
|
561
|
+
return json ? (JSON.parse(json) as Record<string, unknown>) : null;
|
|
562
|
+
}
|
|
563
|
+
|
|
404
564
|
createNetSyncer(name: string, roomKey: string): NetSyncer {
|
|
405
565
|
this.assertOpen();
|
|
406
566
|
const handle = this.native.netSyncerNew(this.engine, name, roomKey);
|
|
@@ -574,6 +734,16 @@ export class HakoClient {
|
|
|
574
734
|
return new DocumentSnapshot(docId, true, parseDocJson(json), doc);
|
|
575
735
|
}
|
|
576
736
|
|
|
737
|
+
/**
|
|
738
|
+
* P2 fast path (core 0.18+): JSON straight from the pinned bytes, no
|
|
739
|
+
* owned doc handle. Blob links are resolved, so the shape matches get().
|
|
740
|
+
*/
|
|
741
|
+
async getJson(collection: string, docId: string): Promise<HakoDocData | null> {
|
|
742
|
+
this.assertOpen();
|
|
743
|
+
const json = this.native.engineGetJson(this.engine, collection, docId);
|
|
744
|
+
return json ? (parseDocJson(json) as HakoDocData) : null;
|
|
745
|
+
}
|
|
746
|
+
|
|
577
747
|
/**
|
|
578
748
|
* Borrowed point view (v0.8.11+): lazy numeric/bool pulls with no decode
|
|
579
749
|
* and no JSON. Returns null when missing. Free the snapshot when done.
|
|
@@ -733,6 +903,21 @@ export class Transaction {
|
|
|
733
903
|
return new DocumentSnapshot(docId, true, parseDocJson(json));
|
|
734
904
|
}
|
|
735
905
|
|
|
906
|
+
/** Batched read: one snapshot, output aligned with ids; missing ids are null. */
|
|
907
|
+
async getMany(collection: string, ids: string[]): Promise<(HakoDocData | null)[]> {
|
|
908
|
+
this.ensureActive();
|
|
909
|
+
const json = this.native.transactionGetMany(this.engine, this.handle, collection, JSON.stringify(ids));
|
|
910
|
+
if (json === null) throw new Error(`transactionGetMany: ${this.native.lastError()}`);
|
|
911
|
+
return JSON.parse(json) as (HakoDocData | null)[];
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/** Merge-patch a doc inside the transaction (F5). */
|
|
915
|
+
patch(collection: string, docId: string, data: HakoDocData): this {
|
|
916
|
+
this.ensureActive();
|
|
917
|
+
ensureOk(this.native.transactionPatch(this.engine, this.handle, collection, docId, JSON.stringify(data)), this.native, 'transactionPatch');
|
|
918
|
+
return this;
|
|
919
|
+
}
|
|
920
|
+
|
|
736
921
|
set(collection: string, docId: string, data: HakoDocData): this {
|
|
737
922
|
this.ensureActive();
|
|
738
923
|
const doc = toNativeDoc(this.native, data);
|
|
@@ -791,6 +976,28 @@ export class CollectionReference {
|
|
|
791
976
|
return new Query(this.client, this.name).count();
|
|
792
977
|
}
|
|
793
978
|
|
|
979
|
+
whereElemMatch(field: string, filters: ElemFilter[]): Query {
|
|
980
|
+
return new Query(this.client, this.name).whereElemMatch(field, filters);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
whereArrayAllEq(field: string, value: unknown): Query {
|
|
984
|
+
return new Query(this.client, this.name).whereArrayAllEq(field, value);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
whereNear(field: string, vec: number[] | Float32Array): Query {
|
|
988
|
+
return new Query(this.client, this.name).whereNear(field, vec);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
whereTraverse(
|
|
992
|
+
startCol: string,
|
|
993
|
+
startId: string,
|
|
994
|
+
direction: TraverseDirection = 'outgoing',
|
|
995
|
+
edge: string | null = null,
|
|
996
|
+
maxDepth = 3
|
|
997
|
+
): Query {
|
|
998
|
+
return new Query(this.client, this.name).whereTraverse(startCol, startId, direction, edge, maxDepth);
|
|
999
|
+
}
|
|
1000
|
+
|
|
794
1001
|
async createIndex(field: string): Promise<void> {
|
|
795
1002
|
ensureOk(this.client.nativeBindings().createSimpleIndex(this.client.engineHandle(), this.name, field), this.client.nativeBindings(), 'createIndex');
|
|
796
1003
|
}
|
|
@@ -841,6 +1048,72 @@ export class CollectionReference {
|
|
|
841
1048
|
async createCompositeIndex(fields: { field: string; desc?: boolean }[]): Promise<number> {
|
|
842
1049
|
return this.client.createCompositeIndex(this.name, fields);
|
|
843
1050
|
}
|
|
1051
|
+
|
|
1052
|
+
/** Drop indexes (v0.19.6 parity). Composite drops by the id createCompositeIndex returned. */
|
|
1053
|
+
async dropIndex(field: string): Promise<void> {
|
|
1054
|
+
ensureOk(this.client.nativeBindings().dropSimpleIndex(this.client.engineHandle(), this.name, field), this.client.nativeBindings(), 'dropIndex');
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
async dropVectorIndex(field: string): Promise<void> {
|
|
1058
|
+
ensureOk(this.client.nativeBindings().dropVectorIndex(this.client.engineHandle(), this.name, field), this.client.nativeBindings(), 'dropVectorIndex');
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
async dropCompositeIndex(id: number): Promise<void> {
|
|
1062
|
+
ensureOk(this.client.nativeBindings().dropCompositeIndex(this.client.engineHandle(), this.name, id), this.client.nativeBindings(), 'dropCompositeIndex');
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
async dropEdgeIndex(): Promise<void> {
|
|
1066
|
+
ensureOk(this.client.nativeBindings().dropEdgeIndex(this.client.engineHandle(), this.name), this.client.nativeBindings(), 'dropEdgeIndex');
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
async dropFtsIndex(field: string): Promise<void> {
|
|
1070
|
+
ensureOk(this.client.nativeBindings().dropFtsIndex(this.client.engineHandle(), this.name, field), this.client.nativeBindings(), 'dropFtsIndex');
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
async dropTraverseIndex(): Promise<void> {
|
|
1074
|
+
ensureOk(this.client.nativeBindings().dropTraverseIndex(this.client.engineHandle(), this.name), this.client.nativeBindings(), 'dropTraverseIndex');
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/** HNSW-tuned vector index (m = edges per node, efConstruction = build beam, efSearch = query beam; 0 = engine default). */
|
|
1078
|
+
async createVectorIndexV2(field: string, dim: number, metric: VectorMetric = 'cosine', m = 0, efConstruction = 0, efSearch = 0): Promise<void> {
|
|
1079
|
+
ensureOk(this.client.nativeBindings().createVectorIndexV2(this.client.engineHandle(), this.name, field, dim, metric === 'l2' ? 1 : 0, m, efConstruction, efSearch), this.client.nativeBindings(), 'createVectorIndexV2');
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/** Graph BFS with the v0.19 extensions: via-edge hops, node/edge predicates, opt-in path/via projections. */
|
|
1083
|
+
async findPathsFull(id: string, opts: PathOptions = {}): Promise<PathHit[]> {
|
|
1084
|
+
const native = this.client.nativeBindings();
|
|
1085
|
+
const o = resolvePathOptions(opts);
|
|
1086
|
+
const json = native.findPathsFull(this.client.engineHandle(), this.name, id, o.direction, o.edge, o.via, o.maxDepth, o.k, o.includePath, o.includeVia, o.nodeField, o.nodeJSON, o.typeField, o.typeJSON, o.matchField, o.matchJSON);
|
|
1087
|
+
if (json === null) throw new Error(`findPathsFull failed: ${native.lastError()}`);
|
|
1088
|
+
return JSON.parse(json) as PathHit[];
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/** Weighted shortest paths with the same extensions as findPathsFull. */
|
|
1092
|
+
async shortestPathsFull(id: string, via: string | null, opts: PathOptions = {}): Promise<PathHit[]> {
|
|
1093
|
+
const native = this.client.nativeBindings();
|
|
1094
|
+
const o = resolvePathOptions(opts);
|
|
1095
|
+
const json = native.simplePathsFull(this.client.engineHandle(), this.name, id, o.direction, o.edge, via, o.weight ?? null, o.maxDepth, o.k, o.includePath, o.includeVia, o.nodeField, o.nodeJSON, o.typeField, o.typeJSON, o.matchField, o.matchJSON);
|
|
1096
|
+
if (json === null) throw new Error(`shortestPathsFull failed: ${native.lastError()}`);
|
|
1097
|
+
return JSON.parse(json) as PathHit[];
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/** Serialize the collection's ref graph (nodes + edges) as JSON. */
|
|
1101
|
+
async exportGraph(opts: PathOptions = {}): Promise<unknown> {
|
|
1102
|
+
const native = this.client.nativeBindings();
|
|
1103
|
+
const o = resolvePathOptions(opts);
|
|
1104
|
+
const json = native.exportGraph(this.client.engineHandle(), this.name, o.direction, o.edge, o.via, o.nodeField, o.nodeJSON);
|
|
1105
|
+
if (json === null) throw new Error(`exportGraph failed: ${native.lastError()}`);
|
|
1106
|
+
return JSON.parse(json);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/** Whole-graph analysis: "components" | "cycle" | "topo". */
|
|
1110
|
+
async graphAnalysis(op: 'components' | 'cycle' | 'topo', opts: PathOptions = {}): Promise<unknown> {
|
|
1111
|
+
const native = this.client.nativeBindings();
|
|
1112
|
+
const o = resolvePathOptions(opts);
|
|
1113
|
+
const json = native.graphAnalysis(this.client.engineHandle(), this.name, op, o.direction, o.edge, o.via, o.nodeField, o.nodeJSON);
|
|
1114
|
+
if (json === null) throw new Error(`graphAnalysis failed: ${native.lastError()}`);
|
|
1115
|
+
return JSON.parse(json);
|
|
1116
|
+
}
|
|
844
1117
|
}
|
|
845
1118
|
|
|
846
1119
|
export class DocumentReference {
|
|
@@ -882,6 +1155,8 @@ private queryLimit?: number;
|
|
|
882
1155
|
private queryOffset?: number;
|
|
883
1156
|
private projection: string[] = [];
|
|
884
1157
|
private deferBlobsDef = false;
|
|
1158
|
+
private near?: { field: string; vec: Float32Array };
|
|
1159
|
+
private traverse?: { startCol: string; startId: string; direction: number; edge: string | null; maxDepth: number };
|
|
885
1160
|
|
|
886
1161
|
constructor(private readonly client: HakoClient, private readonly collection: string) { }
|
|
887
1162
|
|
|
@@ -946,6 +1221,37 @@ this.deferBlobsDef = defer;
|
|
|
946
1221
|
return this;
|
|
947
1222
|
}
|
|
948
1223
|
|
|
1224
|
+
/** Array-of-objects predicate: every element must match all filters (F3). */
|
|
1225
|
+
whereElemMatch(field: string, filters: ElemFilter[]): Query {
|
|
1226
|
+
this.filters.push({ field, op: 'elemMatch', value: filters });
|
|
1227
|
+
return this;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/** Array predicate: every element equals value (scalar JSON) (F3). */
|
|
1231
|
+
whereArrayAllEq(field: string, value: unknown): Query {
|
|
1232
|
+
this.filters.push({ field, op: 'arrayAllEq', value });
|
|
1233
|
+
return this;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
/** KNN marker; the result cap rides limit() (F3). */
|
|
1237
|
+
whereNear(field: string, vec: number[] | Float32Array): Query {
|
|
1238
|
+
this.near = { field, vec: vec instanceof Float32Array ? vec : Float32Array.from(vec) };
|
|
1239
|
+
return this;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
/** BFS graph marker; edge null = any reference field (F3). */
|
|
1243
|
+
whereTraverse(
|
|
1244
|
+
startCol: string,
|
|
1245
|
+
startId: string,
|
|
1246
|
+
direction: TraverseDirection = 'outgoing',
|
|
1247
|
+
edge: string | null = null,
|
|
1248
|
+
maxDepth = 3
|
|
1249
|
+
): Query {
|
|
1250
|
+
const dir = direction === 'incoming' ? 1 : direction === 'both' ? 2 : 0;
|
|
1251
|
+
this.traverse = { startCol, startId, direction: dir, edge, maxDepth };
|
|
1252
|
+
return this;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
949
1255
|
private prepareNativeQuery(): unknown {
|
|
950
1256
|
const native = this.client.nativeBindings();
|
|
951
1257
|
const handle = native.queryNew(this.collection);
|
|
@@ -1010,6 +1316,12 @@ return this;
|
|
|
1010
1316
|
if (typeof filter.value === 'string') ensureOk(native.queryWhereArrayContainsStr(handle, filter.field, filter.value), native, 'queryWhereArrayContainsStr');
|
|
1011
1317
|
else ensureOk(native.queryWhereArrayContainsInt(handle, filter.field, filter.value), native, 'queryWhereArrayContainsInt');
|
|
1012
1318
|
break;
|
|
1319
|
+
case 'elemMatch':
|
|
1320
|
+
ensureOk(native.queryWhereElemMatch(handle, filter.field, JSON.stringify(filter.value)), native, 'queryWhereElemMatch');
|
|
1321
|
+
break;
|
|
1322
|
+
case 'arrayAllEq':
|
|
1323
|
+
ensureOk(native.queryWhereArrayAllEq(handle, filter.field, JSON.stringify(filter.value)), native, 'queryWhereArrayAllEq');
|
|
1324
|
+
break;
|
|
1013
1325
|
}
|
|
1014
1326
|
}
|
|
1015
1327
|
|
|
@@ -1037,6 +1349,12 @@ return this;
|
|
|
1037
1349
|
ensureOk(native.queryEndBefore(handle, this._endBeforeSnapshot._nativeHandle), native, 'queryEndBefore');
|
|
1038
1350
|
}
|
|
1039
1351
|
|
|
1352
|
+
if (this.near) ensureOk(native.queryWhereNear(handle, this.near.field, this.near.vec), native, 'queryWhereNear');
|
|
1353
|
+
if (this.traverse) {
|
|
1354
|
+
const t = this.traverse;
|
|
1355
|
+
ensureOk(native.queryWhereTraverse(handle, t.startCol, t.startId, t.direction, t.edge, t.maxDepth), native, 'queryWhereTraverse');
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1040
1358
|
if (this.order) ensureOk(native.queryOrderBy(handle, this.order.field, this.order.ascending), native, 'queryOrderBy');
|
|
1041
1359
|
if (this.queryLimit !== undefined) ensureOk(native.queryLimit(handle, this.queryLimit), native, 'queryLimit');
|
|
1042
1360
|
if (this.queryOffset !== undefined) ensureOk(native.queryOffset(handle, this.queryOffset), native, 'queryOffset');
|
|
@@ -1060,6 +1378,32 @@ return this;
|
|
|
1060
1378
|
}
|
|
1061
1379
|
}
|
|
1062
1380
|
|
|
1381
|
+
/**
|
|
1382
|
+
* P2 fast path (core 0.18+): rows serialized from pinned bytes, same
|
|
1383
|
+
* shape as get(). Projections keep the projected executor's shape.
|
|
1384
|
+
*/
|
|
1385
|
+
async getJson(): Promise<HakoDocData[]> {
|
|
1386
|
+
const native = this.client.nativeBindings();
|
|
1387
|
+
const handle = this.prepareNativeQuery();
|
|
1388
|
+
try {
|
|
1389
|
+
return parseQueryRows(native.queryExecuteJson(this.client.engineHandle(), handle));
|
|
1390
|
+
} finally {
|
|
1391
|
+
native.queryFree(handle);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
/** Query plan JSON without executing the scan (F7). */
|
|
1396
|
+
async explain(): Promise<Record<string, unknown> | null> {
|
|
1397
|
+
const native = this.client.nativeBindings();
|
|
1398
|
+
const handle = this.prepareNativeQuery();
|
|
1399
|
+
try {
|
|
1400
|
+
const json = native.queryExplain(this.client.engineHandle(), handle);
|
|
1401
|
+
return json ? (JSON.parse(json) as Record<string, unknown>) : null;
|
|
1402
|
+
} finally {
|
|
1403
|
+
native.queryFree(handle);
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1063
1407
|
/**
|
|
1064
1408
|
* Raw page: no decode, no JSON. Walk it with count/resolve, page with
|
|
1065
1409
|
* startAfterRaw, free when done. Scan-many/touch-few is the shape this
|
|
@@ -1152,6 +1496,32 @@ return this;
|
|
|
1152
1496
|
}
|
|
1153
1497
|
}
|
|
1154
1498
|
|
|
1499
|
+
/** `null` when no matching document has a numeric `field`. */
|
|
1500
|
+
async min(field: string): Promise<number | null> {
|
|
1501
|
+
const native = this.client.nativeBindings();
|
|
1502
|
+
const handle = this.prepareNativeQuery();
|
|
1503
|
+
try {
|
|
1504
|
+
ensureOk(native.queryAggregateMin(handle, field), native, 'queryAggregateMin');
|
|
1505
|
+
const json = native.queryExecuteAggregation(this.client.engineHandle(), handle);
|
|
1506
|
+
return json ? (JSON.parse(json)[`min_${field}`] ?? null) : null;
|
|
1507
|
+
} finally {
|
|
1508
|
+
native.queryFree(handle);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
/** `null` when no matching document has a numeric `field`. */
|
|
1513
|
+
async max(field: string): Promise<number | null> {
|
|
1514
|
+
const native = this.client.nativeBindings();
|
|
1515
|
+
const handle = this.prepareNativeQuery();
|
|
1516
|
+
try {
|
|
1517
|
+
ensureOk(native.queryAggregateMax(handle, field), native, 'queryAggregateMax');
|
|
1518
|
+
const json = native.queryExecuteAggregation(this.client.engineHandle(), handle);
|
|
1519
|
+
return json ? (JSON.parse(json)[`max_${field}`] ?? null) : null;
|
|
1520
|
+
} finally {
|
|
1521
|
+
native.queryFree(handle);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1155
1525
|
onSnapshot(callback: (snapshot: HakoDocData[]) => void): Unsubscribe {
|
|
1156
1526
|
const native = this.client.nativeBindings();
|
|
1157
1527
|
const internalWatcher: WatchCallback = async () => {
|
package/src/native.ts
CHANGED
|
@@ -155,6 +155,8 @@ export interface NativeBindings {
|
|
|
155
155
|
queryAggregateCount(query: Handle): number;
|
|
156
156
|
queryAggregateSum(query: Handle, field: string): number;
|
|
157
157
|
queryAggregateAvg(query: Handle, field: string): number;
|
|
158
|
+
queryAggregateMin(query: Handle, field: string): number;
|
|
159
|
+
queryAggregateMax(query: Handle, field: string): number;
|
|
158
160
|
queryExecuteAggregation(engine: Handle, query: Handle): string | null;
|
|
159
161
|
|
|
160
162
|
engineListCollections(engine: Handle): string | null;
|
|
@@ -195,7 +197,22 @@ export interface NativeBindings {
|
|
|
195
197
|
// (same hit shape, cost-ordered; cost rides each hit).
|
|
196
198
|
createEdgeIndex(engine: Handle, collection: string): number;
|
|
197
199
|
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
|
-
|
|
200
|
+
|
|
201
|
+
// v0.19.6 parity: index drops, full graph/traverse API, JSON writes.
|
|
202
|
+
dropSimpleIndex(engine: Handle, collection: string, field: string): number;
|
|
203
|
+
dropVectorIndex(engine: Handle, collection: string, field: string): number;
|
|
204
|
+
dropCompositeIndex(engine: Handle, collection: string, id: number): number;
|
|
205
|
+
dropEdgeIndex(engine: Handle, collection: string): number;
|
|
206
|
+
dropFtsIndex(engine: Handle, collection: string, field: string): number;
|
|
207
|
+
dropTraverseIndex(engine: Handle, collection: string): number;
|
|
208
|
+
createVectorIndexV2(engine: Handle, collection: string, field: string, dim: number, metric: number, m: number, efConstruction: number, efSearch: number): number;
|
|
209
|
+
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;
|
|
210
|
+
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;
|
|
211
|
+
exportGraph(engine: Handle, collection: string, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null): string | null;
|
|
212
|
+
graphAnalysis(engine: Handle, collection: string, op: string, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null): string | null;
|
|
213
|
+
insertJSON(engine: Handle, collection: string, id: string, json: string): number;
|
|
214
|
+
batchSetJSON(batch: Handle, collection: string, id: string, json: string): number;
|
|
215
|
+
|
|
199
216
|
// Array API
|
|
200
217
|
arrayNew(): Handle;
|
|
201
218
|
arrayFree(array: Handle): void;
|
|
@@ -218,6 +235,78 @@ export interface NativeBindings {
|
|
|
218
235
|
queryEndAt(query: Handle, anchorDoc: Handle): number;
|
|
219
236
|
queryEndBefore(query: Handle, anchorDoc: Handle): number;
|
|
220
237
|
|
|
238
|
+
// Unix-only hk_socket_sync_* is deliberately absent: Windows builds omit
|
|
239
|
+
// the symbol, so binding it unconditionally would break koffi on Windows.
|
|
240
|
+
|
|
241
|
+
// F8: per-collection schemas over the C ABI.
|
|
242
|
+
engineSetSchema(engine: Handle, collection: string, schemaJson: string): number;
|
|
243
|
+
engineGetSchema(engine: Handle, collection: string): string | null;
|
|
244
|
+
engineClearSchema(engine: Handle, collection: string): number;
|
|
245
|
+
engineListSchemas(engine: Handle): string | null;
|
|
246
|
+
|
|
247
|
+
// F5: versioned reads, transaction patch/get_many, retry classification.
|
|
248
|
+
engineGetVersioned(engine: Handle, collection: string, docId: string): { doc: Handle; version: bigint };
|
|
249
|
+
transactionGetMany(engine: Handle, tx: Handle, collection: string, idsJson: string): string | null;
|
|
250
|
+
transactionPatch(engine: Handle, tx: Handle, collection: string, docId: string, updatesJson: string): number;
|
|
251
|
+
errorLastKind(): number;
|
|
252
|
+
errorIsRetryable(): boolean;
|
|
253
|
+
|
|
254
|
+
// F7/F3: explain + array/graph predicates.
|
|
255
|
+
queryExplain(engine: Handle, query: Handle): string | null;
|
|
256
|
+
queryWhereArrayAllEq(query: Handle, field: string, valueJson: string): number;
|
|
257
|
+
queryWhereElemMatch(query: Handle, field: string, filtersJson: string): number;
|
|
258
|
+
queryWhereNear(query: Handle, field: string, vec: Float32Array): number;
|
|
259
|
+
queryWhereTraverse(query: Handle, startCol: string, startId: string, direction: number, edge: string | null, maxDepth: number): number;
|
|
260
|
+
|
|
261
|
+
// F4: aggregation pipeline (raw handle; typed builder is separate work).
|
|
262
|
+
pipelineNew(collection: string): Handle;
|
|
263
|
+
pipelineFree(pipeline: Handle): void;
|
|
264
|
+
pipelineMatch(pipeline: Handle, query: Handle): number;
|
|
265
|
+
pipelineProject(pipeline: Handle, fieldsJson: string): number;
|
|
266
|
+
pipelineSort(pipeline: Handle, field: string, ascending: boolean): number;
|
|
267
|
+
pipelineLimit(pipeline: Handle, limit: number): number;
|
|
268
|
+
pipelineOffset(pipeline: Handle, offset: number): number;
|
|
269
|
+
pipelineUnwind(pipeline: Handle, field: string): number;
|
|
270
|
+
pipelineGroup(pipeline: Handle, key: string, accumsJson: string): number;
|
|
271
|
+
pipelineExecute(engine: Handle, pipeline: Handle): string | null;
|
|
272
|
+
pipelineExecuteToHandles(engine: Handle, pipeline: Handle): Handle;
|
|
273
|
+
|
|
274
|
+
// Config additions (0.12-0.16 core knobs).
|
|
275
|
+
configSetGroupCommitIntervalMs(config: Handle, ms: number | bigint): void;
|
|
276
|
+
configSetPageCacheCapacity(config: Handle, capacity: number): void;
|
|
277
|
+
configSetSyncExcluded(config: Handle, collectionsJson: string): number;
|
|
278
|
+
configSetLazyCollections(config: Handle, collectionsJson: string): number;
|
|
279
|
+
configSetReplicationCollections(config: Handle, collectionsJson: string): number;
|
|
280
|
+
|
|
281
|
+
// Quiescence / diagnostics / logging.
|
|
282
|
+
engineAwaitQuiescent(engine: Handle, timeoutMs: number | bigint): boolean;
|
|
283
|
+
engineQuiescenceStatus(engine: Handle): string | null;
|
|
284
|
+
debugWriteStats(): string | null;
|
|
285
|
+
logEnableStderr(): void;
|
|
286
|
+
logDisableStderr(): void;
|
|
287
|
+
|
|
288
|
+
// Lazy cursor walks: callbacks copy immediately; returning false stops.
|
|
289
|
+
cursorWalk(engine: Handle, query: Handle, callback: (id: string, bytes: Uint8Array) => boolean): number;
|
|
290
|
+
cursorWalkView(engine: Handle, query: Handle, callback: (id: string, view: Handle) => boolean): number;
|
|
291
|
+
|
|
292
|
+
// Borrowed raw/view reads: copied before return (lifetime is the result set/view).
|
|
293
|
+
rawDocBytes(rawDoc: Handle): Uint8Array | null;
|
|
294
|
+
rawDocId(rawDoc: Handle): string | null;
|
|
295
|
+
viewGetStr(view: Handle, key: string): string | null;
|
|
296
|
+
viewGetBytes(view: Handle, key: string): Uint8Array | null;
|
|
297
|
+
|
|
298
|
+
// P2 (core 0.18): JSON read paths + dotted-path view pulls. JSON strings
|
|
299
|
+
// are owned (free happens in the binding); view pulls copy before return.
|
|
300
|
+
engineGetJson(engine: Handle, collection: string, docId: string): string | null;
|
|
301
|
+
queryExecuteJson(engine: Handle, query: Handle): string | null;
|
|
302
|
+
viewToJson(view: Handle): string | null;
|
|
303
|
+
cursorWalkJson(engine: Handle, query: Handle, callback: (id: string, json: Uint8Array) => boolean): number;
|
|
304
|
+
viewGetPathInt(view: Handle, path: string): number | bigint | null;
|
|
305
|
+
viewGetPathFloat(view: Handle, path: string): number | null;
|
|
306
|
+
viewGetPathBool(view: Handle, path: string): boolean | null;
|
|
307
|
+
viewGetPathStr(view: Handle, path: string): string | null;
|
|
308
|
+
viewGetPathBytes(view: Handle, path: string): Uint8Array | null;
|
|
309
|
+
|
|
221
310
|
lastError(): string;
|
|
222
311
|
}
|
|
223
312
|
|
|
@@ -242,7 +331,7 @@ function resolveLibraryPath(explicitPath?: string): string {
|
|
|
242
331
|
|
|
243
332
|
async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
244
333
|
const ffi = await import('bun:ffi');
|
|
245
|
-
const { dlopen, FFIType, CString, JSCallback } = ffi as any;
|
|
334
|
+
const { dlopen, FFIType, CString, JSCallback, toArrayBuffer } = ffi as any;
|
|
246
335
|
|
|
247
336
|
const symbols = dlopen(libPath, {
|
|
248
337
|
hk_engine_open: { args: [FFIType.cstring], returns: FFIType.ptr },
|
|
@@ -308,6 +397,21 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
308
397
|
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
398
|
|
|
310
399
|
hk_batch_new: { args: [], returns: FFIType.ptr },
|
|
400
|
+
|
|
401
|
+
// v0.19.6 parity
|
|
402
|
+
hk_engine_drop_simple_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
403
|
+
hk_engine_drop_vector_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
404
|
+
hk_engine_drop_composite_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32], returns: FFIType.i32 },
|
|
405
|
+
hk_engine_drop_edge_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
406
|
+
hk_engine_drop_fts_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
407
|
+
hk_engine_drop_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
408
|
+
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 },
|
|
409
|
+
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 },
|
|
410
|
+
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 },
|
|
411
|
+
hk_engine_export_graph: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
412
|
+
hk_engine_graph_analysis: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
413
|
+
hk_engine_insert_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
414
|
+
hk_batch_set_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
311
415
|
hk_batch_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
312
416
|
hk_batch_set: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
313
417
|
hk_batch_delete: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
@@ -367,6 +471,8 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
367
471
|
hk_query_aggregate_count: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
368
472
|
hk_query_aggregate_sum: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
369
473
|
hk_query_aggregate_avg: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
474
|
+
hk_query_aggregate_min: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
475
|
+
hk_query_aggregate_max: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
370
476
|
hk_query_execute_aggregation: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
371
477
|
hk_query_where_or_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
372
478
|
hk_query_where_or_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
@@ -399,7 +505,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
399
505
|
|
|
400
506
|
hk_doc_insert_reference: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
401
507
|
|
|
402
|
-
hk_cloud_sync_new: { args: [FFIType.ptr, FFIType.i32, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
508
|
+
hk_cloud_sync_new: { args: [FFIType.ptr, FFIType.i32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
403
509
|
hk_cloud_sync_server_new: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
404
510
|
hk_cloud_sync_client_new: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
405
511
|
hk_cloud_sync_start: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
@@ -407,6 +513,59 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
407
513
|
hk_cloud_sync_stop: { args: [FFIType.ptr], returns: FFIType.void },
|
|
408
514
|
hk_cloud_sync_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
409
515
|
|
|
516
|
+
// 0.16.5 parity: F8 schemas, F5 versioned/tx, F7 explain, F3 predicates,
|
|
517
|
+
// F4 pipelines, config knobs, quiescence, lazy walks and borrowed reads.
|
|
518
|
+
hk_config_set_group_commit_interval_ms: { args: [FFIType.ptr, FFIType.u64], returns: FFIType.void },
|
|
519
|
+
hk_config_set_page_cache_capacity: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.void },
|
|
520
|
+
hk_config_set_sync_excluded: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
521
|
+
hk_config_set_lazy_collections: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
522
|
+
hk_config_set_replication_collections: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
523
|
+
hk_engine_await_quiescent: { args: [FFIType.ptr, FFIType.u64], returns: FFIType.bool },
|
|
524
|
+
hk_engine_quiescence_status: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
525
|
+
hk_engine_get_versioned: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
526
|
+
hk_engine_set_schema: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
527
|
+
hk_engine_get_schema: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
528
|
+
hk_engine_clear_schema: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
529
|
+
hk_engine_list_schemas: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
530
|
+
hk_query_explain: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
531
|
+
hk_query_where_array_all_eq: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
532
|
+
hk_query_where_elem_match: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
533
|
+
hk_query_where_near: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
534
|
+
hk_query_where_traverse: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.usize], returns: FFIType.i32 },
|
|
535
|
+
hk_pipeline_new: { args: [FFIType.cstring], returns: FFIType.ptr },
|
|
536
|
+
hk_pipeline_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
537
|
+
hk_pipeline_match: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
538
|
+
hk_pipeline_project: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
539
|
+
hk_pipeline_sort: { args: [FFIType.ptr, FFIType.cstring, FFIType.bool], returns: FFIType.i32 },
|
|
540
|
+
hk_pipeline_limit: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
541
|
+
hk_pipeline_offset: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
542
|
+
hk_pipeline_unwind: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
543
|
+
hk_pipeline_group: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
544
|
+
hk_pipeline_execute: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
545
|
+
hk_pipeline_execute_to_handles: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
546
|
+
hk_transaction_get_many: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
547
|
+
hk_transaction_patch: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
548
|
+
hk_error_last_kind: { args: [], returns: FFIType.i32 },
|
|
549
|
+
hk_error_is_retryable: { args: [], returns: FFIType.bool },
|
|
550
|
+
hk_debug_write_stats: { args: [], returns: FFIType.ptr },
|
|
551
|
+
hk_log_enable_stderr: { args: [], returns: FFIType.void },
|
|
552
|
+
hk_log_disable_stderr: { args: [], returns: FFIType.void },
|
|
553
|
+
hk_cursor_walk: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
554
|
+
hk_cursor_walk_view: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
555
|
+
hk_rawdoc_bytes: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
556
|
+
hk_rawdoc_id: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
557
|
+
hk_view_get_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
558
|
+
hk_view_get_bytes: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
559
|
+
hk_engine_get_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
560
|
+
hk_query_execute_json: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
561
|
+
hk_cursor_walk_json: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
562
|
+
hk_view_to_json: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
563
|
+
hk_view_get_path_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.bool },
|
|
564
|
+
hk_view_get_path_float: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.bool },
|
|
565
|
+
hk_view_get_path_bool: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
566
|
+
hk_view_get_path_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
567
|
+
hk_view_get_path_bytes: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
568
|
+
|
|
410
569
|
// ================= ERRORS =================
|
|
411
570
|
hk_last_error: { args: [], returns: FFIType.ptr },
|
|
412
571
|
hk_string_free: { args: [FFIType.ptr], returns: FFIType.void }
|
|
@@ -569,6 +728,8 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
569
728
|
queryAggregateCount: (q) => symbols.hk_query_aggregate_count(q),
|
|
570
729
|
queryAggregateSum: (q, f) => symbols.hk_query_aggregate_sum(q, toC(f)),
|
|
571
730
|
queryAggregateAvg: (q, f) => symbols.hk_query_aggregate_avg(q, toC(f)),
|
|
731
|
+
queryAggregateMin: (q, f) => symbols.hk_query_aggregate_min(q, toC(f)),
|
|
732
|
+
queryAggregateMax: (q, f) => symbols.hk_query_aggregate_max(q, toC(f)),
|
|
572
733
|
queryExecuteAggregation: (e, q) => ptrToStringAndFree(symbols.hk_query_execute_aggregation(e, q)),
|
|
573
734
|
engineListCollections: (engine) => ptrToStringAndFree(symbols.hk_engine_list_collections(engine)),
|
|
574
735
|
netSyncerNew: (engine, name, roomKey) => symbols.hk_net_syncer_new(engine, toC(name), toC(roomKey)),
|
|
@@ -600,6 +761,21 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
600
761
|
createEdgeIndex: (engine, collection) => symbols.hk_engine_create_edge_index(engine, toC(collection)),
|
|
601
762
|
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
763
|
|
|
764
|
+
// v0.19.6 parity
|
|
765
|
+
dropSimpleIndex: (engine, collection, field) => symbols.hk_engine_drop_simple_index(engine, toC(collection), toC(field)),
|
|
766
|
+
dropVectorIndex: (engine, collection, field) => symbols.hk_engine_drop_vector_index(engine, toC(collection), toC(field)),
|
|
767
|
+
dropCompositeIndex: (engine, collection, id) => symbols.hk_engine_drop_composite_index(engine, toC(collection), id),
|
|
768
|
+
dropEdgeIndex: (engine, collection) => symbols.hk_engine_drop_edge_index(engine, toC(collection)),
|
|
769
|
+
dropFtsIndex: (engine, collection, field) => symbols.hk_engine_drop_fts_index(engine, toC(collection), toC(field)),
|
|
770
|
+
dropTraverseIndex: (engine, collection) => symbols.hk_engine_drop_traverse_index(engine, toC(collection)),
|
|
771
|
+
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),
|
|
772
|
+
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))),
|
|
773
|
+
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))),
|
|
774
|
+
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))),
|
|
775
|
+
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))),
|
|
776
|
+
insertJSON: (engine, collection, id, json) => symbols.hk_engine_insert_json(engine, toC(collection), toC(id), toC(json)),
|
|
777
|
+
batchSetJSON: (batch, collection, id, json) => symbols.hk_batch_set_json(batch, toC(collection), toC(id), toC(json)),
|
|
778
|
+
|
|
603
779
|
// Array API
|
|
604
780
|
arrayNew: () => symbols.hk_array_new(),
|
|
605
781
|
arrayFree: (arr) => symbols.hk_array_free(arr),
|
|
@@ -622,6 +798,117 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
622
798
|
queryEndAt: (query, anchorDoc) => symbols.hk_query_end_at(query, anchorDoc),
|
|
623
799
|
queryEndBefore: (query, anchorDoc) => symbols.hk_query_end_before(query, anchorDoc),
|
|
624
800
|
|
|
801
|
+
// 0.16.5 parity.
|
|
802
|
+
engineSetSchema: (e, c, json) => symbols.hk_engine_set_schema(e, toC(c), toC(json)),
|
|
803
|
+
engineGetSchema: (e, c) => ptrToStringAndFree(symbols.hk_engine_get_schema(e, toC(c))),
|
|
804
|
+
engineClearSchema: (e, c) => symbols.hk_engine_clear_schema(e, toC(c)),
|
|
805
|
+
engineListSchemas: (e) => ptrToStringAndFree(symbols.hk_engine_list_schemas(e)),
|
|
806
|
+
engineGetVersioned: (e, c, id) => {
|
|
807
|
+
const out = new BigInt64Array(1);
|
|
808
|
+
const doc = symbols.hk_engine_get_versioned(e, toC(c), toC(id), ptrOf(out));
|
|
809
|
+
return { doc, version: out[0] };
|
|
810
|
+
},
|
|
811
|
+
engineAwaitQuiescent: (e, ms) => symbols.hk_engine_await_quiescent(e, BigInt(ms)),
|
|
812
|
+
engineQuiescenceStatus: (e) => ptrToStringAndFree(symbols.hk_engine_quiescence_status(e)),
|
|
813
|
+
transactionGetMany: (e, tx, c, idsJson) => ptrToStringAndFree(symbols.hk_transaction_get_many(e, tx, toC(c), toC(idsJson))),
|
|
814
|
+
transactionPatch: (e, tx, c, id, updatesJson) => symbols.hk_transaction_patch(e, tx, toC(c), toC(id), toC(updatesJson)),
|
|
815
|
+
errorLastKind: () => symbols.hk_error_last_kind(),
|
|
816
|
+
errorIsRetryable: () => symbols.hk_error_is_retryable(),
|
|
817
|
+
debugWriteStats: () => ptrToStringAndFree(symbols.hk_debug_write_stats()),
|
|
818
|
+
logEnableStderr: () => symbols.hk_log_enable_stderr(),
|
|
819
|
+
logDisableStderr: () => symbols.hk_log_disable_stderr(),
|
|
820
|
+
queryExplain: (e, q) => ptrToStringAndFree(symbols.hk_query_explain(e, q)),
|
|
821
|
+
queryWhereArrayAllEq: (q, f, json) => symbols.hk_query_where_array_all_eq(q, toC(f), toC(json)),
|
|
822
|
+
queryWhereElemMatch: (q, f, json) => symbols.hk_query_where_elem_match(q, toC(f), toC(json)),
|
|
823
|
+
queryWhereNear: (q, f, vec) => symbols.hk_query_where_near(q, toC(f), vec, vec.length),
|
|
824
|
+
queryWhereTraverse: (q, sc, sid, dir, edge, depth) => symbols.hk_query_where_traverse(q, toC(sc), toC(sid), dir, edge === null ? null : toC(edge), depth),
|
|
825
|
+
pipelineNew: (c) => symbols.hk_pipeline_new(toC(c)),
|
|
826
|
+
pipelineFree: (p) => symbols.hk_pipeline_free(p),
|
|
827
|
+
pipelineMatch: (p, q) => symbols.hk_pipeline_match(p, q),
|
|
828
|
+
pipelineProject: (p, json) => symbols.hk_pipeline_project(p, toC(json)),
|
|
829
|
+
pipelineSort: (p, f, asc) => symbols.hk_pipeline_sort(p, toC(f), asc),
|
|
830
|
+
pipelineLimit: (p, n) => symbols.hk_pipeline_limit(p, n),
|
|
831
|
+
pipelineOffset: (p, n) => symbols.hk_pipeline_offset(p, n),
|
|
832
|
+
pipelineUnwind: (p, f) => symbols.hk_pipeline_unwind(p, toC(f)),
|
|
833
|
+
pipelineGroup: (p, k, json) => symbols.hk_pipeline_group(p, toC(k), toC(json)),
|
|
834
|
+
pipelineExecute: (e, p) => ptrToStringAndFree(symbols.hk_pipeline_execute(e, p)),
|
|
835
|
+
pipelineExecuteToHandles: (e, p) => symbols.hk_pipeline_execute_to_handles(e, p),
|
|
836
|
+
configSetGroupCommitIntervalMs: (c, ms) => symbols.hk_config_set_group_commit_interval_ms(c, BigInt(ms)),
|
|
837
|
+
configSetPageCacheCapacity: (c, n) => symbols.hk_config_set_page_cache_capacity(c, n),
|
|
838
|
+
configSetSyncExcluded: (c, json) => symbols.hk_config_set_sync_excluded(c, toC(json)),
|
|
839
|
+
configSetLazyCollections: (c, json) => symbols.hk_config_set_lazy_collections(c, toC(json)),
|
|
840
|
+
configSetReplicationCollections: (c, json) => symbols.hk_config_set_replication_collections(c, toC(json)),
|
|
841
|
+
cursorWalk: (e, q, callback) => {
|
|
842
|
+
const cb = new JSCallback((idPtr: any, idLen: number, bytesPtr: any, bytesLen: number) => {
|
|
843
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
844
|
+
const bytes = new Uint8Array(toArrayBuffer(bytesPtr, 0, Number(bytesLen))).slice();
|
|
845
|
+
return callback(id, bytes);
|
|
846
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.usize, FFIType.ptr], returns: FFIType.bool });
|
|
847
|
+
return Number(symbols.hk_cursor_walk(e, q, cb, null));
|
|
848
|
+
},
|
|
849
|
+
cursorWalkView: (e, q, callback) => {
|
|
850
|
+
const cb = new JSCallback((idPtr: any, idLen: number, view: any) => {
|
|
851
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
852
|
+
return callback(id, view);
|
|
853
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.ptr], returns: FFIType.bool });
|
|
854
|
+
return Number(symbols.hk_cursor_walk_view(e, q, cb, null));
|
|
855
|
+
},
|
|
856
|
+
rawDocBytes: (raw) => {
|
|
857
|
+
const len = new BigInt64Array(1);
|
|
858
|
+
const ptr = symbols.hk_rawdoc_bytes(raw, ptrOf(len));
|
|
859
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
860
|
+
},
|
|
861
|
+
rawDocId: (raw) => {
|
|
862
|
+
const len = new BigInt64Array(1);
|
|
863
|
+
const ptr = symbols.hk_rawdoc_id(raw, ptrOf(len));
|
|
864
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
865
|
+
},
|
|
866
|
+
viewGetStr: (view, key) => {
|
|
867
|
+
const len = new BigInt64Array(1);
|
|
868
|
+
const ptr = symbols.hk_view_get_str(view, toC(key), ptrOf(len));
|
|
869
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
870
|
+
},
|
|
871
|
+
viewGetBytes: (view, key) => {
|
|
872
|
+
const len = new BigInt64Array(1);
|
|
873
|
+
const ptr = symbols.hk_view_get_bytes(view, toC(key), ptrOf(len));
|
|
874
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
875
|
+
},
|
|
876
|
+
|
|
877
|
+
// P2 (core 0.18): JSON read paths + dotted-path pulls.
|
|
878
|
+
engineGetJson: (e, c, id) => ptrToStringAndFree(symbols.hk_engine_get_json(e, toC(c), toC(id))),
|
|
879
|
+
queryExecuteJson: (e, q) => ptrToStringAndFree(symbols.hk_query_execute_json(e, q)),
|
|
880
|
+
viewToJson: (view) => ptrToStringAndFree(symbols.hk_view_to_json(view)),
|
|
881
|
+
cursorWalkJson: (e, q, callback) => {
|
|
882
|
+
const cb = new JSCallback((idPtr: any, idLen: number, jsonPtr: any, jsonLen: number) => {
|
|
883
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
884
|
+
const json = new Uint8Array(toArrayBuffer(jsonPtr, 0, Number(jsonLen))).slice();
|
|
885
|
+
return callback(id, json);
|
|
886
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.usize, FFIType.ptr], returns: FFIType.bool });
|
|
887
|
+
return Number(symbols.hk_cursor_walk_json(e, q, cb, null));
|
|
888
|
+
},
|
|
889
|
+
viewGetPathInt: (view, path) => {
|
|
890
|
+
const out = new BigInt64Array(1);
|
|
891
|
+
return symbols.hk_view_get_path_int(view, toC(path), ptrOf(out)) ? out[0] : null;
|
|
892
|
+
},
|
|
893
|
+
viewGetPathFloat: (view, path) => {
|
|
894
|
+
const out = new Float64Array(1);
|
|
895
|
+
return symbols.hk_view_get_path_float(view, toC(path), ptrOf(out)) ? out[0] : null;
|
|
896
|
+
},
|
|
897
|
+
viewGetPathBool: (view, path) => {
|
|
898
|
+
const r = symbols.hk_view_get_path_bool(view, toC(path));
|
|
899
|
+
return r < 0 ? null : r !== 0;
|
|
900
|
+
},
|
|
901
|
+
viewGetPathStr: (view, path) => {
|
|
902
|
+
const len = new BigInt64Array(1);
|
|
903
|
+
const ptr = symbols.hk_view_get_path_str(view, toC(path), ptrOf(len));
|
|
904
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
905
|
+
},
|
|
906
|
+
viewGetPathBytes: (view, path) => {
|
|
907
|
+
const len = new BigInt64Array(1);
|
|
908
|
+
const ptr = symbols.hk_view_get_path_bytes(view, toC(path), ptrOf(len));
|
|
909
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
910
|
+
},
|
|
911
|
+
|
|
625
912
|
lastError: () => {
|
|
626
913
|
const ptr = symbols.hk_last_error();
|
|
627
914
|
return ptr ? new CString(ptr).toString() : 'unknown ffi error';
|
|
@@ -638,7 +925,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
638
925
|
// these EVERY struct-typed decl throws at bindings creation, i.e. the
|
|
639
926
|
// node backend was dead on arrival (bun resolves pointers structurally
|
|
640
927
|
// 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);
|
|
928
|
+
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
929
|
|
|
643
930
|
// ponytail: owned C strings (Rust-allocated) must come back through a
|
|
644
931
|
// DISPOSABLE type wired to hk_string_free — never bare char* (koffi
|
|
@@ -652,6 +939,9 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
652
939
|
// hako.h). Kept as documentation; register() below takes the
|
|
653
940
|
// typedef NAME as a string, not this proto object.
|
|
654
941
|
const OnSnapshotCB = koffi.proto('void HK_OnSnapshotCallback(const char *collection, const char *path, int32_t kind, void *user_data)');
|
|
942
|
+
// ids are length-delimited (not NUL-terminated): take them as raw bytes.
|
|
943
|
+
const WalkCB = koffi.proto('bool HkWalkCallback(const uint8_t *id, size_t id_len, const uint8_t *bytes, size_t bytes_len, void *userdata)');
|
|
944
|
+
const ViewWalkCB = koffi.proto('bool HkViewWalkCallback(const uint8_t *id, size_t id_len, const HK_ViewDoc *view, void *userdata)');
|
|
655
945
|
|
|
656
946
|
const fn = {
|
|
657
947
|
hk_engine_open: lib.func('HK_Engine* hk_engine_open(const char* path)'),
|
|
@@ -720,6 +1010,21 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
720
1010
|
hk_engine_create_edge_index: lib.func('int hk_engine_create_edge_index(HK_Engine* engine, const char* collection)'),
|
|
721
1011
|
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
1012
|
|
|
1013
|
+
// v0.19.6 parity
|
|
1014
|
+
hk_engine_drop_simple_index: lib.func('int hk_engine_drop_simple_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1015
|
+
hk_engine_drop_vector_index: lib.func('int hk_engine_drop_vector_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1016
|
+
hk_engine_drop_composite_index: lib.func('int hk_engine_drop_composite_index(HK_Engine* engine, const char* collection, uint32_t id)'),
|
|
1017
|
+
hk_engine_drop_edge_index: lib.func('int hk_engine_drop_edge_index(HK_Engine* engine, const char* collection)'),
|
|
1018
|
+
hk_engine_drop_fts_index: lib.func('int hk_engine_drop_fts_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1019
|
+
hk_engine_drop_traverse_index: lib.func('int hk_engine_drop_traverse_index(HK_Engine* engine, const char* collection)'),
|
|
1020
|
+
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)'),
|
|
1021
|
+
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)'),
|
|
1022
|
+
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)'),
|
|
1023
|
+
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)'),
|
|
1024
|
+
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)'),
|
|
1025
|
+
hk_engine_insert_json: lib.func('int hk_engine_insert_json(HK_Engine* engine, const char* collection, const char* doc_id, const char* json)'),
|
|
1026
|
+
hk_batch_set_json: lib.func('int hk_batch_set_json(HK_Batch* batch, const char* collection, const char* doc_id, const char* json)'),
|
|
1027
|
+
|
|
723
1028
|
hk_batch_new: lib.func('HK_Batch* hk_batch_new()'),
|
|
724
1029
|
hk_batch_free: lib.func('void hk_batch_free(HK_Batch* batch)'),
|
|
725
1030
|
hk_batch_set: lib.func('int hk_batch_set(HK_Batch* batch, const char* collection, const char* doc_id, const HK_Doc* doc)'),
|
|
@@ -786,6 +1091,8 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
786
1091
|
hk_query_aggregate_count: lib.func('int hk_query_aggregate_count(HK_Query* query)'),
|
|
787
1092
|
hk_query_aggregate_sum: lib.func('int hk_query_aggregate_sum(HK_Query* query, const char* field)'),
|
|
788
1093
|
hk_query_aggregate_avg: lib.func('int hk_query_aggregate_avg(HK_Query* query, const char* field)'),
|
|
1094
|
+
hk_query_aggregate_min: lib.func('int hk_query_aggregate_min(HK_Query* query, const char* field)'),
|
|
1095
|
+
hk_query_aggregate_max: lib.func('int hk_query_aggregate_max(HK_Query* query, const char* field)'),
|
|
789
1096
|
hk_query_execute_aggregation: lib.func('HeapStr hk_query_execute_aggregation(HK_Engine* engine, const HK_Query* query)'),
|
|
790
1097
|
hk_query_where_or_str: lib.func('int hk_query_where_or_str(HK_Query* query, const char* field, const char* value)'),
|
|
791
1098
|
hk_query_where_or_int: lib.func('int hk_query_where_or_int(HK_Query* query, const char* field, int64_t value)'),
|
|
@@ -833,6 +1140,61 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
833
1140
|
hk_cloud_sync_stop: lib.func('void hk_cloud_sync_stop(HK_CloudSync* cloud_sync)'),
|
|
834
1141
|
hk_cloud_sync_free: lib.func('void hk_cloud_sync_free(HK_CloudSync* cloud_sync)'),
|
|
835
1142
|
|
|
1143
|
+
// 0.16.5 parity: F8 schemas, F5 versioned/tx, F7 explain, F3 predicates,
|
|
1144
|
+
// F4 pipelines, config knobs, quiescence, lazy walks and borrowed reads.
|
|
1145
|
+
hk_config_set_group_commit_interval_ms: lib.func('void hk_config_set_group_commit_interval_ms(HK_Config* config, uint64_t ms)'),
|
|
1146
|
+
hk_config_set_page_cache_capacity: lib.func('void hk_config_set_page_cache_capacity(HK_Config* config, size_t capacity)'),
|
|
1147
|
+
hk_config_set_sync_excluded: lib.func('int hk_config_set_sync_excluded(HK_Config* config, const char* collections_json)'),
|
|
1148
|
+
hk_config_set_lazy_collections: lib.func('int hk_config_set_lazy_collections(HK_Config* config, const char* collections_json)'),
|
|
1149
|
+
hk_config_set_replication_collections: lib.func('int hk_config_set_replication_collections(HK_Config* config, const char* collections_json)'),
|
|
1150
|
+
hk_engine_await_quiescent: lib.func('bool hk_engine_await_quiescent(HK_Engine* engine, uint64_t timeout_ms)'),
|
|
1151
|
+
hk_engine_quiescence_status: lib.func('HeapStr hk_engine_quiescence_status(HK_Engine* engine)'),
|
|
1152
|
+
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)'),
|
|
1153
|
+
hk_engine_set_schema: lib.func('int hk_engine_set_schema(HK_Engine* engine, const char* collection, const char* schema_json)'),
|
|
1154
|
+
hk_engine_get_schema: lib.func('HeapStr hk_engine_get_schema(HK_Engine* engine, const char* collection)'),
|
|
1155
|
+
hk_engine_clear_schema: lib.func('int hk_engine_clear_schema(HK_Engine* engine, const char* collection)'),
|
|
1156
|
+
hk_engine_list_schemas: lib.func('HeapStr hk_engine_list_schemas(HK_Engine* engine)'),
|
|
1157
|
+
hk_query_explain: lib.func('HeapStr hk_query_explain(HK_Engine* engine, const HK_Query* query)'),
|
|
1158
|
+
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)'),
|
|
1159
|
+
hk_query_where_elem_match: lib.func('int hk_query_where_elem_match(HK_Query* query, const char* field, const char* filters_json)'),
|
|
1160
|
+
hk_query_where_near: lib.func('int hk_query_where_near(HK_Query* query, const char* field, const float* vec, size_t len)'),
|
|
1161
|
+
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)'),
|
|
1162
|
+
hk_pipeline_new: lib.func('HK_Pipeline* hk_pipeline_new(const char* collection)'),
|
|
1163
|
+
hk_pipeline_free: lib.func('void hk_pipeline_free(HK_Pipeline* pipeline)'),
|
|
1164
|
+
hk_pipeline_match: lib.func('int hk_pipeline_match(HK_Pipeline* pipeline, const HK_Query* query)'),
|
|
1165
|
+
hk_pipeline_project: lib.func('int hk_pipeline_project(HK_Pipeline* pipeline, const char* fields_json)'),
|
|
1166
|
+
hk_pipeline_sort: lib.func('int hk_pipeline_sort(HK_Pipeline* pipeline, const char* field, bool ascending)'),
|
|
1167
|
+
hk_pipeline_limit: lib.func('int hk_pipeline_limit(HK_Pipeline* pipeline, size_t limit)'),
|
|
1168
|
+
hk_pipeline_offset: lib.func('int hk_pipeline_offset(HK_Pipeline* pipeline, size_t offset)'),
|
|
1169
|
+
hk_pipeline_unwind: lib.func('int hk_pipeline_unwind(HK_Pipeline* pipeline, const char* field)'),
|
|
1170
|
+
hk_pipeline_group: lib.func('int hk_pipeline_group(HK_Pipeline* pipeline, const char* key, const char* accums_json)'),
|
|
1171
|
+
hk_pipeline_execute: lib.func('HeapStr hk_pipeline_execute(HK_Engine* engine, const HK_Pipeline* pipeline)'),
|
|
1172
|
+
hk_pipeline_execute_to_handles: lib.func('HK_ResultSet* hk_pipeline_execute_to_handles(HK_Engine* engine, const HK_Pipeline* pipeline)'),
|
|
1173
|
+
hk_transaction_get_many: lib.func('HeapStr hk_transaction_get_many(HK_Engine* engine, HK_Transaction* tx, const char* collection, const char* ids_json)'),
|
|
1174
|
+
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)'),
|
|
1175
|
+
hk_error_last_kind: lib.func('int hk_error_last_kind()'),
|
|
1176
|
+
hk_error_is_retryable: lib.func('bool hk_error_is_retryable()'),
|
|
1177
|
+
hk_debug_write_stats: lib.func('HeapStr hk_debug_write_stats()'),
|
|
1178
|
+
hk_log_enable_stderr: lib.func('void hk_log_enable_stderr()'),
|
|
1179
|
+
hk_log_disable_stderr: lib.func('void hk_log_disable_stderr()'),
|
|
1180
|
+
hk_cursor_walk: lib.func('int64_t hk_cursor_walk(HK_Engine* engine, const HK_Query* query, HkWalkCallback* callback, void* userdata)'),
|
|
1181
|
+
hk_cursor_walk_view: lib.func('int64_t hk_cursor_walk_view(HK_Engine* engine, const HK_Query* query, HkViewWalkCallback* callback, void* userdata)'),
|
|
1182
|
+
hk_rawdoc_bytes: lib.func('const uint8_t* hk_rawdoc_bytes(const HK_RawDoc* doc, _Out_ uintptr_t *len_out)'),
|
|
1183
|
+
// Return as uint8_t* so koffi hands back a pointer; the id is
|
|
1184
|
+
// length-delimited, not NUL-terminated.
|
|
1185
|
+
hk_rawdoc_id: lib.func('const uint8_t* hk_rawdoc_id(const HK_RawDoc* doc, _Out_ uintptr_t *len_out)'),
|
|
1186
|
+
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)'),
|
|
1187
|
+
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)'),
|
|
1188
|
+
hk_engine_get_json: lib.func('HeapStr hk_engine_get_json(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1189
|
+
hk_query_execute_json: lib.func('HeapStr hk_query_execute_json(HK_Engine* engine, const HK_Query* query)'),
|
|
1190
|
+
hk_cursor_walk_json: lib.func('int64_t hk_cursor_walk_json(HK_Engine* engine, const HK_Query* query, HkWalkCallback* callback, void* userdata)'),
|
|
1191
|
+
hk_view_to_json: lib.func('HeapStr hk_view_to_json(const HK_ViewDoc* view)'),
|
|
1192
|
+
hk_view_get_path_int: lib.func('bool hk_view_get_path_int(const HK_ViewDoc* view, const char* path, _Out_ int64_t *out)'),
|
|
1193
|
+
hk_view_get_path_float: lib.func('bool hk_view_get_path_float(const HK_ViewDoc* view, const char* path, _Out_ double *out)'),
|
|
1194
|
+
hk_view_get_path_bool: lib.func('int hk_view_get_path_bool(const HK_ViewDoc* view, const char* path)'),
|
|
1195
|
+
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)'),
|
|
1196
|
+
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)'),
|
|
1197
|
+
|
|
836
1198
|
hk_last_error: lib.func('const char* hk_last_error()'),
|
|
837
1199
|
hk_string_free: lib.func('void hk_string_free(void* value)')
|
|
838
1200
|
};
|
|
@@ -985,6 +1347,8 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
985
1347
|
queryAggregateCount: (q) => fn.hk_query_aggregate_count(q),
|
|
986
1348
|
queryAggregateSum: (q, f) => fn.hk_query_aggregate_sum(q, f),
|
|
987
1349
|
queryAggregateAvg: (q, f) => fn.hk_query_aggregate_avg(q, f),
|
|
1350
|
+
queryAggregateMin: (q, f) => fn.hk_query_aggregate_min(q, f),
|
|
1351
|
+
queryAggregateMax: (q, f) => fn.hk_query_aggregate_max(q, f),
|
|
988
1352
|
queryExecuteAggregation: (e, q) => ptrToStringAndFree(fn.hk_query_execute_aggregation(e, q)),
|
|
989
1353
|
engineListCollections: (engine) => ptrToStringAndFree(fn.hk_engine_list_collections(engine)),
|
|
990
1354
|
netSyncerNew: (engine, name, roomKey) => fn.hk_net_syncer_new(engine, name, roomKey),
|
|
@@ -1016,6 +1380,21 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1016
1380
|
createEdgeIndex: (engine, collection) => fn.hk_engine_create_edge_index(engine, collection),
|
|
1017
1381
|
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
1382
|
|
|
1383
|
+
// v0.19.6 parity (koffi takes null for char* directly)
|
|
1384
|
+
dropSimpleIndex: (engine, collection, field) => fn.hk_engine_drop_simple_index(engine, collection, field),
|
|
1385
|
+
dropVectorIndex: (engine, collection, field) => fn.hk_engine_drop_vector_index(engine, collection, field),
|
|
1386
|
+
dropCompositeIndex: (engine, collection, id) => fn.hk_engine_drop_composite_index(engine, collection, id),
|
|
1387
|
+
dropEdgeIndex: (engine, collection) => fn.hk_engine_drop_edge_index(engine, collection),
|
|
1388
|
+
dropFtsIndex: (engine, collection, field) => fn.hk_engine_drop_fts_index(engine, collection, field),
|
|
1389
|
+
dropTraverseIndex: (engine, collection) => fn.hk_engine_drop_traverse_index(engine, collection),
|
|
1390
|
+
createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch) => fn.hk_engine_create_vector_index_v2(engine, collection, field, dim, metric, m, efConstruction, efSearch),
|
|
1391
|
+
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),
|
|
1392
|
+
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),
|
|
1393
|
+
exportGraph: (engine, collection, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_export_graph(engine, collection, direction, edge, via, nodeField, nodeJSON),
|
|
1394
|
+
graphAnalysis: (engine, collection, op, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_graph_analysis(engine, collection, op, direction, edge, via, nodeField, nodeJSON),
|
|
1395
|
+
insertJSON: (engine, collection, id, json) => fn.hk_engine_insert_json(engine, collection, id, json),
|
|
1396
|
+
batchSetJSON: (batch, collection, id, json) => fn.hk_batch_set_json(batch, collection, id, json),
|
|
1397
|
+
|
|
1019
1398
|
// Array API
|
|
1020
1399
|
arrayNew: () => fn.hk_array_new(),
|
|
1021
1400
|
arrayFree: (arr) => fn.hk_array_free(arr),
|
|
@@ -1038,6 +1417,117 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1038
1417
|
queryEndAt: (query, anchorDoc) => fn.hk_query_end_at(query, anchorDoc),
|
|
1039
1418
|
queryEndBefore: (query, anchorDoc) => fn.hk_query_end_before(query, anchorDoc),
|
|
1040
1419
|
|
|
1420
|
+
// 0.16.5 parity.
|
|
1421
|
+
engineSetSchema: (e, c, json) => fn.hk_engine_set_schema(e, c, json),
|
|
1422
|
+
engineGetSchema: (e, c) => ptrToStringAndFree(fn.hk_engine_get_schema(e, c)),
|
|
1423
|
+
engineClearSchema: (e, c) => fn.hk_engine_clear_schema(e, c),
|
|
1424
|
+
engineListSchemas: (e) => ptrToStringAndFree(fn.hk_engine_list_schemas(e)),
|
|
1425
|
+
engineGetVersioned: (e, c, id) => {
|
|
1426
|
+
const out: bigint[] = [0n];
|
|
1427
|
+
const doc = fn.hk_engine_get_versioned(e, c, id, out);
|
|
1428
|
+
return { doc, version: out[0] };
|
|
1429
|
+
},
|
|
1430
|
+
engineAwaitQuiescent: (e, ms) => fn.hk_engine_await_quiescent(e, ms),
|
|
1431
|
+
engineQuiescenceStatus: (e) => ptrToStringAndFree(fn.hk_engine_quiescence_status(e)),
|
|
1432
|
+
transactionGetMany: (e, tx, c, idsJson) => ptrToStringAndFree(fn.hk_transaction_get_many(e, tx, c, idsJson)),
|
|
1433
|
+
transactionPatch: (e, tx, c, id, updatesJson) => fn.hk_transaction_patch(e, tx, c, id, updatesJson),
|
|
1434
|
+
errorLastKind: () => fn.hk_error_last_kind(),
|
|
1435
|
+
errorIsRetryable: () => fn.hk_error_is_retryable(),
|
|
1436
|
+
debugWriteStats: () => ptrToStringAndFree(fn.hk_debug_write_stats()),
|
|
1437
|
+
logEnableStderr: () => fn.hk_log_enable_stderr(),
|
|
1438
|
+
logDisableStderr: () => fn.hk_log_disable_stderr(),
|
|
1439
|
+
queryExplain: (e, q) => ptrToStringAndFree(fn.hk_query_explain(e, q)),
|
|
1440
|
+
queryWhereArrayAllEq: (q, f, json) => fn.hk_query_where_array_all_eq(q, f, json),
|
|
1441
|
+
queryWhereElemMatch: (q, f, json) => fn.hk_query_where_elem_match(q, f, json),
|
|
1442
|
+
queryWhereNear: (q, f, vec) => fn.hk_query_where_near(q, f, Buffer.from(vec.buffer, vec.byteOffset, vec.byteLength), vec.length),
|
|
1443
|
+
queryWhereTraverse: (q, sc, sid, dir, edge, depth) => fn.hk_query_where_traverse(q, sc, sid, dir, edge, depth),
|
|
1444
|
+
pipelineNew: (c) => fn.hk_pipeline_new(c),
|
|
1445
|
+
pipelineFree: (p) => fn.hk_pipeline_free(p),
|
|
1446
|
+
pipelineMatch: (p, q) => fn.hk_pipeline_match(p, q),
|
|
1447
|
+
pipelineProject: (p, json) => fn.hk_pipeline_project(p, json),
|
|
1448
|
+
pipelineSort: (p, f, asc) => fn.hk_pipeline_sort(p, f, asc),
|
|
1449
|
+
pipelineLimit: (p, n) => fn.hk_pipeline_limit(p, n),
|
|
1450
|
+
pipelineOffset: (p, n) => fn.hk_pipeline_offset(p, n),
|
|
1451
|
+
pipelineUnwind: (p, f) => fn.hk_pipeline_unwind(p, f),
|
|
1452
|
+
pipelineGroup: (p, k, json) => fn.hk_pipeline_group(p, k, json),
|
|
1453
|
+
pipelineExecute: (e, p) => ptrToStringAndFree(fn.hk_pipeline_execute(e, p)),
|
|
1454
|
+
pipelineExecuteToHandles: (e, p) => fn.hk_pipeline_execute_to_handles(e, p),
|
|
1455
|
+
configSetGroupCommitIntervalMs: (c, ms) => fn.hk_config_set_group_commit_interval_ms(c, ms),
|
|
1456
|
+
configSetPageCacheCapacity: (c, n) => fn.hk_config_set_page_cache_capacity(c, n),
|
|
1457
|
+
configSetSyncExcluded: (c, json) => fn.hk_config_set_sync_excluded(c, json),
|
|
1458
|
+
configSetLazyCollections: (c, json) => fn.hk_config_set_lazy_collections(c, json),
|
|
1459
|
+
configSetReplicationCollections: (c, json) => fn.hk_config_set_replication_collections(c, json),
|
|
1460
|
+
cursorWalk: (e, q, callback) => {
|
|
1461
|
+
const wrapper = (id: any, idLen: number, bytes: any, bytesLen: number) => {
|
|
1462
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1463
|
+
const rowBytes = Uint8Array.from(koffi.decode(bytes, 'uint8_t', Number(bytesLen)));
|
|
1464
|
+
return callback(rowId, rowBytes);
|
|
1465
|
+
};
|
|
1466
|
+
return Number(fn.hk_cursor_walk(e, q, koffi.register(wrapper, 'HkWalkCallback *'), null));
|
|
1467
|
+
},
|
|
1468
|
+
cursorWalkView: (e, q, callback) => {
|
|
1469
|
+
const wrapper = (id: any, idLen: number, view: any) => {
|
|
1470
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1471
|
+
return callback(rowId, view);
|
|
1472
|
+
};
|
|
1473
|
+
return Number(fn.hk_cursor_walk_view(e, q, koffi.register(wrapper, 'HkViewWalkCallback *'), null));
|
|
1474
|
+
},
|
|
1475
|
+
rawDocBytes: (raw) => {
|
|
1476
|
+
const len: number[] = [0];
|
|
1477
|
+
const ptr = fn.hk_rawdoc_bytes(raw, len);
|
|
1478
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1479
|
+
},
|
|
1480
|
+
rawDocId: (raw) => {
|
|
1481
|
+
const len: number[] = [0];
|
|
1482
|
+
const ptr = fn.hk_rawdoc_id(raw, len);
|
|
1483
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1484
|
+
},
|
|
1485
|
+
viewGetStr: (view, key) => {
|
|
1486
|
+
const len: number[] = [0];
|
|
1487
|
+
const ptr = fn.hk_view_get_str(view, key, len);
|
|
1488
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1489
|
+
},
|
|
1490
|
+
viewGetBytes: (view, key) => {
|
|
1491
|
+
const len: number[] = [0];
|
|
1492
|
+
const ptr = fn.hk_view_get_bytes(view, key, len);
|
|
1493
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1494
|
+
},
|
|
1495
|
+
|
|
1496
|
+
// P2 (core 0.18): JSON read paths + dotted-path pulls.
|
|
1497
|
+
engineGetJson: (e, c, id) => ptrToStringAndFree(fn.hk_engine_get_json(e, c, id)),
|
|
1498
|
+
queryExecuteJson: (e, q) => ptrToStringAndFree(fn.hk_query_execute_json(e, q)),
|
|
1499
|
+
viewToJson: (view) => ptrToStringAndFree(fn.hk_view_to_json(view)),
|
|
1500
|
+
cursorWalkJson: (e, q, callback) => {
|
|
1501
|
+
const wrapper = (id: any, idLen: number, json: any, jsonLen: number) => {
|
|
1502
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1503
|
+
const rowJson = Uint8Array.from(koffi.decode(json, 'uint8_t', Number(jsonLen)));
|
|
1504
|
+
return callback(rowId, rowJson);
|
|
1505
|
+
};
|
|
1506
|
+
return Number(fn.hk_cursor_walk_json(e, q, koffi.register(wrapper, 'HkWalkCallback *'), null));
|
|
1507
|
+
},
|
|
1508
|
+
viewGetPathInt: (view, path) => {
|
|
1509
|
+
const out: bigint[] = [0n];
|
|
1510
|
+
return fn.hk_view_get_path_int(view, path, out) ? out[0] : null;
|
|
1511
|
+
},
|
|
1512
|
+
viewGetPathFloat: (view, path) => {
|
|
1513
|
+
const out: number[] = [0];
|
|
1514
|
+
return fn.hk_view_get_path_float(view, path, out) ? out[0] : null;
|
|
1515
|
+
},
|
|
1516
|
+
viewGetPathBool: (view, path) => {
|
|
1517
|
+
const r: number = fn.hk_view_get_path_bool(view, path);
|
|
1518
|
+
return r < 0 ? null : r !== 0;
|
|
1519
|
+
},
|
|
1520
|
+
viewGetPathStr: (view, path) => {
|
|
1521
|
+
const len: number[] = [0];
|
|
1522
|
+
const ptr = fn.hk_view_get_path_str(view, path, len);
|
|
1523
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1524
|
+
},
|
|
1525
|
+
viewGetPathBytes: (view, path) => {
|
|
1526
|
+
const len: number[] = [0];
|
|
1527
|
+
const ptr = fn.hk_view_get_path_bytes(view, path, len);
|
|
1528
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1529
|
+
},
|
|
1530
|
+
|
|
1041
1531
|
lastError: () => (fn.hk_last_error() as string) || 'unknown ffi error'
|
|
1042
1532
|
};
|
|
1043
1533
|
}
|