@hakodb/client 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci-quick.yml +31 -31
- package/.github/workflows/publish.yml +36 -0
- package/README.md +27 -37
- package/examples/bun/index.ts +85 -85
- package/examples/bun/package.json +10 -10
- package/examples/node/index.ts +111 -111
- package/examples/node/package-lock.json +533 -533
- package/examples/node/package.json +13 -13
- package/examples/node/softdel.ts +70 -70
- package/package.json +38 -34
- package/src/bun-ffi.d.ts +6 -6
- package/src/client.ts +1653 -1627
- package/src/index.ts +37 -37
- package/src/native.ts +1620 -1605
- package/sync-native.ps1 +55 -55
- package/tsconfig.json +12 -12
package/src/native.ts
CHANGED
|
@@ -1,1605 +1,1620 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
type Handle = any;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* matches HK_OnSnapshotCallback in hako.h
|
|
7
|
-
*/
|
|
8
|
-
export type WatchCallback = (collection: string, path: string, kind: number) => void;
|
|
9
|
-
|
|
10
|
-
export interface NativeBindings {
|
|
11
|
-
engineOpen(path: string): Handle;
|
|
12
|
-
engineIsIndexesReady(engine: Handle): boolean;
|
|
13
|
-
engineOpenWithConfig(path: string, config: Handle): Handle;
|
|
14
|
-
engineFree(engine: Handle): void;
|
|
15
|
-
engineBackup(engine: Handle, path: string): number; // Added
|
|
16
|
-
engineCompact(engine: Handle): number;
|
|
17
|
-
engineGetStats(engine: Handle): string | null;
|
|
18
|
-
engineGetAuditLog(engine: Handle): string | null;
|
|
19
|
-
engineSnapshotIndices(engine: Handle): number;
|
|
20
|
-
engineListIndexes(engine: Handle, collection: string | null): string | null;
|
|
21
|
-
|
|
22
|
-
// Configuration Builder
|
|
23
|
-
configNew(): Handle;
|
|
24
|
-
configFree(config: Handle): void;
|
|
25
|
-
configSetDurability(config: Handle, mode: number): void;
|
|
26
|
-
configSetEncryptionKey(config: Handle, key: string | null): void;
|
|
27
|
-
configSetEncryptedCollections(config: Handle, collectionsJson: string | null): number;
|
|
28
|
-
configSetAuditLog(config: Handle, enabled: boolean, path: string | null): void;
|
|
29
|
-
configSetQueryWorkers(config: Handle, count: number): void;
|
|
30
|
-
configSetMemoryLimits(config: Handle, mmap: number, maxInlined: number): void;
|
|
31
|
-
configSetStorageTuning(
|
|
32
|
-
config: Handle,
|
|
33
|
-
pageSize: number,
|
|
34
|
-
threshold: number,
|
|
35
|
-
groupCommit: number
|
|
36
|
-
): void;
|
|
37
|
-
configSetBlobThreshold(config: Handle, thresholdBytes: number): void;
|
|
38
|
-
configSetCompression(config: Handle, enabled: boolean, level: number): void;
|
|
39
|
-
configSetBackgroundMaintenance(config: Handle, enabled: boolean): void;
|
|
40
|
-
|
|
41
|
-
// Real-time Watch
|
|
42
|
-
engineWatch(engine: Handle, collection: string, callback: WatchCallback): Handle;
|
|
43
|
-
watchFree(watch: Handle): void;
|
|
44
|
-
|
|
45
|
-
// Document Builder
|
|
46
|
-
docNew(): Handle;
|
|
47
|
-
docFree(doc: Handle): void;
|
|
48
|
-
docInsertStr(doc: Handle, key: string, value: string): number;
|
|
49
|
-
docInsertInt(doc: Handle, key: string, value: number | bigint): number;
|
|
50
|
-
docInsertFloat(doc: Handle, key: string, value: number): number;
|
|
51
|
-
docInsertBool(doc: Handle, key: string, value: boolean): number;
|
|
52
|
-
docInsertNull(doc: Handle, key: string): number;
|
|
53
|
-
docInsertBin(doc: Handle, key: string, bytes: Uint8Array): number;
|
|
54
|
-
docInsertTimestamp(doc: Handle, key: string, micros: bigint): number; // Added
|
|
55
|
-
docInsertServerTimestamp(doc: Handle, key: string): number; // Added
|
|
56
|
-
docInsertReference(doc: Handle, key: string, targetCollection: string, targetId: string): number;
|
|
57
|
-
docToJson(doc: Handle): string | null;
|
|
58
|
-
|
|
59
|
-
// Engine CRUD
|
|
60
|
-
engineInsert(engine: Handle, collection: string, docId: string, doc: Handle): number;
|
|
61
|
-
engineGet(engine: Handle, collection: string, docId: string): Handle;
|
|
62
|
-
engineDelete(engine: Handle, collection: string, docId: string): number;
|
|
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;
|
|
69
|
-
engineSetCollectionLocal(engine: Handle, collection: string, local: number): number;
|
|
70
|
-
engineReplicateKey(engine: Handle, collection: string, docId: string): number;
|
|
71
|
-
engineReplicateCollection(engine: Handle, collection: string): number;
|
|
72
|
-
engineVacuumCollection(engine: Handle, collection: string): number;
|
|
73
|
-
engineRelocateDocs(engine: Handle, src: string, dst: string, idsJson: string): string | null;
|
|
74
|
-
engineLoadCollection(engine: Handle, collection: string): number;
|
|
75
|
-
engineUnloadCollection(engine: Handle, collection: string): number;
|
|
76
|
-
engineUnloadedCollections(engine: Handle): string | null;
|
|
77
|
-
enginePatch(engine: Handle, collection: string, docId: string, updates: Handle): number;
|
|
78
|
-
engineInsertSubDoc(engine: Handle, col: string, id: string, subCol: string, subId: string, doc: Handle): number;
|
|
79
|
-
engineGetByRef(engine: Handle, doc: Handle, fieldKey: string): Handle;
|
|
80
|
-
engineCreateIndex(engine: Handle, collection: string, fieldsJson: string): number;
|
|
81
|
-
|
|
82
|
-
// Atomic Batch
|
|
83
|
-
batchNew(): Handle;
|
|
84
|
-
batchFree(batch: Handle): void;
|
|
85
|
-
batchSet(batch: Handle, collection: string, docId: string, doc: Handle): number;
|
|
86
|
-
batchDelete(batch: Handle, collection: string, docId: string): number;
|
|
87
|
-
batchDeleteEx(batch: Handle, collection: string, docId: string, force: boolean): number;
|
|
88
|
-
batchCommit(engine: Handle, batch: Handle): number;
|
|
89
|
-
|
|
90
|
-
// Serializable Transactions
|
|
91
|
-
transactionBegin(engine: Handle): Handle;
|
|
92
|
-
transactionGet(engine: Handle, tx: Handle, collection: string, docId: string): Handle;
|
|
93
|
-
transactionSet(tx: Handle, collection: string, docId: string, doc: Handle): number;
|
|
94
|
-
transactionCommit(engine: Handle, tx: Handle): number;
|
|
95
|
-
transactionFree(tx: Handle): void;
|
|
96
|
-
|
|
97
|
-
// Query API
|
|
98
|
-
queryNew(collection: string): Handle;
|
|
99
|
-
queryFree(query: Handle): void;
|
|
100
|
-
queryWhereEqStr(query: Handle, field: string, value: string): number;
|
|
101
|
-
queryWhereEqBool(query: Handle, field: string, value: boolean): number;
|
|
102
|
-
queryWhereEqInt(query: Handle, field: string, value: number | bigint): number;
|
|
103
|
-
queryWhereNeStr(query: Handle, field: string, value: string): number;
|
|
104
|
-
queryWhereNeInt(query: Handle, field: string, value: number | bigint): number;
|
|
105
|
-
queryWhereGtStr(query: Handle, field: string, value: string): number;
|
|
106
|
-
queryWhereGtInt(query: Handle, field: string, value: number | bigint): number;
|
|
107
|
-
queryWhereGteStr(query: Handle, field: string, value: string): number;
|
|
108
|
-
queryWhereGteInt(query: Handle, field: string, value: number | bigint): number;
|
|
109
|
-
queryWhereLtStr(query: Handle, field: string, value: string): number;
|
|
110
|
-
queryWhereLtInt(query: Handle, field: string, value: number | bigint): number;
|
|
111
|
-
queryWhereLteStr(query: Handle, field: string, value: string): number;
|
|
112
|
-
queryWhereLteInt(query: Handle, field: string, value: number | bigint): number;
|
|
113
|
-
queryOrderBy(query: Handle, field: string, ascending: boolean): number;
|
|
114
|
-
queryLimit(query: Handle, limit: number): number;
|
|
115
|
-
queryOffset(query: Handle, offset: number): number;
|
|
116
|
-
querySelectField(query: Handle, field: string): number;
|
|
117
|
-
queryExecute(engine: Handle, query: Handle): string | null;
|
|
118
|
-
queryDelete(engine: Handle, query: Handle): number;
|
|
119
|
-
queryDeleteLocal(engine: Handle, query: Handle): number;
|
|
120
|
-
queryPatch(engine: Handle, query: Handle, patchDoc: Handle): number;
|
|
121
|
-
queryExecuteToHandles(engine: Handle, query: Handle): Handle;
|
|
122
|
-
resultSetCount(results: Handle): number;
|
|
123
|
-
resultSetGetDoc(results: Handle, index: number): Handle;
|
|
124
|
-
resultSetFree(results: Handle): void;
|
|
125
|
-
resultSetToJson(results: Handle): string | null;
|
|
126
|
-
// Raw result sets (v0.8.3): pinned bytes, not decoded docs. Rows are
|
|
127
|
-
// resolved selectively via rawDocToDoc (decode only what you touch);
|
|
128
|
-
// page with queryStartAfterRaw (no decode at all). rawDocBytes/Id need
|
|
129
|
-
// backend memory reads — use resolve-then-read instead (see client.ts).
|
|
130
|
-
queryExecuteRaw(engine: Handle, query: Handle): Handle;
|
|
131
|
-
rawResultCount(results: Handle): number;
|
|
132
|
-
rawResultGet(results: Handle, index: number): Handle;
|
|
133
|
-
rawResultFree(results: Handle): void;
|
|
134
|
-
rawDocToDoc(engine: Handle, rawDoc: Handle, collection: string): Handle;
|
|
135
|
-
queryStartAfterRaw(query: Handle, anchorRawDoc: Handle): number;
|
|
136
|
-
// Borrowed views (v0.8.11): lazy typed pulls, no owned construction.
|
|
137
|
-
// Numeric/bool getters cross by value (no memory reads); strings and
|
|
138
|
-
// walks stay on resolve/raw paths (documented in client.ts).
|
|
139
|
-
viewGet(engine: Handle, collection: string, docId: string): Handle;
|
|
140
|
-
viewFree(view: Handle): void;
|
|
141
|
-
viewFieldCount(view: Handle): number;
|
|
142
|
-
viewHasField(view: Handle, key: string): boolean;
|
|
143
|
-
viewGetInt(view: Handle, key: string): number | bigint | null;
|
|
144
|
-
viewGetFloat(view: Handle, key: string): number | null;
|
|
145
|
-
viewGetBool(view: Handle, key: string): boolean | null;
|
|
146
|
-
viewToDoc(view: Handle, docId: string): Handle;
|
|
147
|
-
queryDeferBlobs(query: Handle, defer: boolean): number;
|
|
148
|
-
docResolveBlobs(engine: Handle, collection: string, doc: Handle): number;
|
|
149
|
-
engineInsertTake(engine: Handle, collection: string, docId: string, doc: Handle): number;
|
|
150
|
-
configSetWalReserveBytes(c: Handle, bytes: number | bigint): void;
|
|
151
|
-
|
|
152
|
-
// Full-Text Search Queries (Added)
|
|
153
|
-
queryWhereMatch(query: Handle, field: string, value: string): number;
|
|
154
|
-
queryWhereMatchPrefix(query: Handle, field: string, value: string): number;
|
|
155
|
-
queryWhereContains(query: Handle, field: string, value: string): number;
|
|
156
|
-
queryWhereStartsWith(query: Handle, field: string, value: string): number;
|
|
157
|
-
queryWhereOrStr(query: Handle, field: string, value: string): number;
|
|
158
|
-
queryWhereOrInt(query: Handle, field: string, value: number | bigint): number;
|
|
159
|
-
|
|
160
|
-
// Aggregation API
|
|
161
|
-
queryAggregateCount(query: Handle): number;
|
|
162
|
-
queryAggregateSum(query: Handle, field: string): number;
|
|
163
|
-
queryAggregateAvg(query: Handle, field: string): number;
|
|
164
|
-
queryAggregateMin(query: Handle, field: string): number;
|
|
165
|
-
queryAggregateMax(query: Handle, field: string): number;
|
|
166
|
-
queryExecuteAggregation(engine: Handle, query: Handle): string | null;
|
|
167
|
-
|
|
168
|
-
engineListCollections(engine: Handle): string | null;
|
|
169
|
-
|
|
170
|
-
// Net Sync
|
|
171
|
-
netSyncerNew(engine: Handle, name: string, roomKey: string): Handle;
|
|
172
|
-
netSyncerStart(syncer: Handle, port: number): number;
|
|
173
|
-
netSyncerSetDiscovery(syncer: Handle, mode: number): number;
|
|
174
|
-
netSyncerStatus(syncer: Handle): string | null;
|
|
175
|
-
netSyncerFree(syncer: Handle): void;
|
|
176
|
-
|
|
177
|
-
// Cloud Sync (bi-directional WebSocket replication)
|
|
178
|
-
cloudSyncNew(engine: Handle, mode: number, clientId: string | null, roomName: string | null, roomKey: string | null, authToken: string | null): Handle;
|
|
179
|
-
cloudSyncServerNew(engine: Handle, serverId: string | null, authToken: string | null, roomName: string | null, roomKey: string | null): Handle;
|
|
180
|
-
cloudSyncClientNew(engine: Handle, clientId: string | null, roomName: string | null, roomKey: string | null, authToken: string | null): Handle;
|
|
181
|
-
cloudSyncStart(cloudSync: Handle, address: string): number;
|
|
182
|
-
cloudSyncStatus(cloudSync: Handle): string | null;
|
|
183
|
-
cloudSyncStop(cloudSync: Handle): void;
|
|
184
|
-
cloudSyncFree(cloudSync: Handle): void;
|
|
185
|
-
|
|
186
|
-
// v0.5.9
|
|
187
|
-
createFtsIndex(engine: Handle, collection: string, field: string): number;
|
|
188
|
-
createSimpleIndex(engine: Handle, collection: string, field: string): number;
|
|
189
|
-
|
|
190
|
-
// Vector KNN (core >=0.13.3): one-shot search returns owned JSON
|
|
191
|
-
// [{id, score, doc}] (null = hard error, e.g. dim mismatch — read
|
|
192
|
-
// lastError); unindexed field returns "[]".
|
|
193
|
-
createVectorIndex(engine: Handle, collection: string, field: string, dim: number, metric: number): number;
|
|
194
|
-
engineFindNear(engine: Handle, collection: string, field: string, vec: Float32Array, k: number): string | null;
|
|
195
|
-
|
|
196
|
-
// Graph traversal (core >=0.14.0): one-shot BFS returns owned JSON
|
|
197
|
-
// [{collection, id, depth, doc}] (null = hard error, e.g. incoming
|
|
198
|
-
// into untracked — read lastError); missing anchor returns "[]".
|
|
199
|
-
// direction 0/1/2 = outgoing/incoming/both; edge null = any ref field.
|
|
200
|
-
createTraverseIndex(engine: Handle, collection: string): number;
|
|
201
|
-
engineFindPaths(engine: Handle, collection: string, id: string, direction: number, edge: string | null, maxDepth: number, k: number): string | null;
|
|
202
|
-
// Phase B (core >=0.15.0): edge registration + weighted Dijkstra
|
|
203
|
-
// (same hit shape, cost-ordered; cost rides each hit).
|
|
204
|
-
createEdgeIndex(engine: Handle, collection: string): number;
|
|
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;
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
//
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
return
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
//
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
const
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
const
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
const
|
|
947
|
-
return
|
|
948
|
-
},
|
|
949
|
-
|
|
950
|
-
const
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
//
|
|
977
|
-
//
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
//
|
|
983
|
-
//
|
|
984
|
-
|
|
985
|
-
//
|
|
986
|
-
|
|
987
|
-
const
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
//
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
//
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
const
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
return
|
|
1544
|
-
},
|
|
1545
|
-
|
|
1546
|
-
const len: number[] = [0];
|
|
1547
|
-
const ptr = fn.
|
|
1548
|
-
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1549
|
-
},
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
const
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
type Handle = any;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* matches HK_OnSnapshotCallback in hako.h
|
|
7
|
+
*/
|
|
8
|
+
export type WatchCallback = (collection: string, path: string, kind: number) => void;
|
|
9
|
+
|
|
10
|
+
export interface NativeBindings {
|
|
11
|
+
engineOpen(path: string): Handle;
|
|
12
|
+
engineIsIndexesReady(engine: Handle): boolean;
|
|
13
|
+
engineOpenWithConfig(path: string, config: Handle): Handle;
|
|
14
|
+
engineFree(engine: Handle): void;
|
|
15
|
+
engineBackup(engine: Handle, path: string): number; // Added
|
|
16
|
+
engineCompact(engine: Handle): number;
|
|
17
|
+
engineGetStats(engine: Handle): string | null;
|
|
18
|
+
engineGetAuditLog(engine: Handle): string | null;
|
|
19
|
+
engineSnapshotIndices(engine: Handle): number;
|
|
20
|
+
engineListIndexes(engine: Handle, collection: string | null): string | null;
|
|
21
|
+
|
|
22
|
+
// Configuration Builder
|
|
23
|
+
configNew(): Handle;
|
|
24
|
+
configFree(config: Handle): void;
|
|
25
|
+
configSetDurability(config: Handle, mode: number): void;
|
|
26
|
+
configSetEncryptionKey(config: Handle, key: string | null): void;
|
|
27
|
+
configSetEncryptedCollections(config: Handle, collectionsJson: string | null): number;
|
|
28
|
+
configSetAuditLog(config: Handle, enabled: boolean, path: string | null): void;
|
|
29
|
+
configSetQueryWorkers(config: Handle, count: number): void;
|
|
30
|
+
configSetMemoryLimits(config: Handle, mmap: number, maxInlined: number): void;
|
|
31
|
+
configSetStorageTuning(
|
|
32
|
+
config: Handle,
|
|
33
|
+
pageSize: number,
|
|
34
|
+
threshold: number,
|
|
35
|
+
groupCommit: number
|
|
36
|
+
): void;
|
|
37
|
+
configSetBlobThreshold(config: Handle, thresholdBytes: number): void;
|
|
38
|
+
configSetCompression(config: Handle, enabled: boolean, level: number): void;
|
|
39
|
+
configSetBackgroundMaintenance(config: Handle, enabled: boolean): void;
|
|
40
|
+
|
|
41
|
+
// Real-time Watch
|
|
42
|
+
engineWatch(engine: Handle, collection: string, callback: WatchCallback): Handle;
|
|
43
|
+
watchFree(watch: Handle): void;
|
|
44
|
+
|
|
45
|
+
// Document Builder
|
|
46
|
+
docNew(): Handle;
|
|
47
|
+
docFree(doc: Handle): void;
|
|
48
|
+
docInsertStr(doc: Handle, key: string, value: string): number;
|
|
49
|
+
docInsertInt(doc: Handle, key: string, value: number | bigint): number;
|
|
50
|
+
docInsertFloat(doc: Handle, key: string, value: number): number;
|
|
51
|
+
docInsertBool(doc: Handle, key: string, value: boolean): number;
|
|
52
|
+
docInsertNull(doc: Handle, key: string): number;
|
|
53
|
+
docInsertBin(doc: Handle, key: string, bytes: Uint8Array): number;
|
|
54
|
+
docInsertTimestamp(doc: Handle, key: string, micros: bigint): number; // Added
|
|
55
|
+
docInsertServerTimestamp(doc: Handle, key: string): number; // Added
|
|
56
|
+
docInsertReference(doc: Handle, key: string, targetCollection: string, targetId: string): number;
|
|
57
|
+
docToJson(doc: Handle): string | null;
|
|
58
|
+
|
|
59
|
+
// Engine CRUD
|
|
60
|
+
engineInsert(engine: Handle, collection: string, docId: string, doc: Handle): number;
|
|
61
|
+
engineGet(engine: Handle, collection: string, docId: string): Handle;
|
|
62
|
+
engineDelete(engine: Handle, collection: string, docId: string): number;
|
|
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;
|
|
69
|
+
engineSetCollectionLocal(engine: Handle, collection: string, local: number): number;
|
|
70
|
+
engineReplicateKey(engine: Handle, collection: string, docId: string): number;
|
|
71
|
+
engineReplicateCollection(engine: Handle, collection: string): number;
|
|
72
|
+
engineVacuumCollection(engine: Handle, collection: string): number;
|
|
73
|
+
engineRelocateDocs(engine: Handle, src: string, dst: string, idsJson: string): string | null;
|
|
74
|
+
engineLoadCollection(engine: Handle, collection: string): number;
|
|
75
|
+
engineUnloadCollection(engine: Handle, collection: string): number;
|
|
76
|
+
engineUnloadedCollections(engine: Handle): string | null;
|
|
77
|
+
enginePatch(engine: Handle, collection: string, docId: string, updates: Handle): number;
|
|
78
|
+
engineInsertSubDoc(engine: Handle, col: string, id: string, subCol: string, subId: string, doc: Handle): number;
|
|
79
|
+
engineGetByRef(engine: Handle, doc: Handle, fieldKey: string): Handle;
|
|
80
|
+
engineCreateIndex(engine: Handle, collection: string, fieldsJson: string): number;
|
|
81
|
+
|
|
82
|
+
// Atomic Batch
|
|
83
|
+
batchNew(): Handle;
|
|
84
|
+
batchFree(batch: Handle): void;
|
|
85
|
+
batchSet(batch: Handle, collection: string, docId: string, doc: Handle): number;
|
|
86
|
+
batchDelete(batch: Handle, collection: string, docId: string): number;
|
|
87
|
+
batchDeleteEx(batch: Handle, collection: string, docId: string, force: boolean): number;
|
|
88
|
+
batchCommit(engine: Handle, batch: Handle): number;
|
|
89
|
+
|
|
90
|
+
// Serializable Transactions
|
|
91
|
+
transactionBegin(engine: Handle): Handle;
|
|
92
|
+
transactionGet(engine: Handle, tx: Handle, collection: string, docId: string): Handle;
|
|
93
|
+
transactionSet(tx: Handle, collection: string, docId: string, doc: Handle): number;
|
|
94
|
+
transactionCommit(engine: Handle, tx: Handle): number;
|
|
95
|
+
transactionFree(tx: Handle): void;
|
|
96
|
+
|
|
97
|
+
// Query API
|
|
98
|
+
queryNew(collection: string): Handle;
|
|
99
|
+
queryFree(query: Handle): void;
|
|
100
|
+
queryWhereEqStr(query: Handle, field: string, value: string): number;
|
|
101
|
+
queryWhereEqBool(query: Handle, field: string, value: boolean): number;
|
|
102
|
+
queryWhereEqInt(query: Handle, field: string, value: number | bigint): number;
|
|
103
|
+
queryWhereNeStr(query: Handle, field: string, value: string): number;
|
|
104
|
+
queryWhereNeInt(query: Handle, field: string, value: number | bigint): number;
|
|
105
|
+
queryWhereGtStr(query: Handle, field: string, value: string): number;
|
|
106
|
+
queryWhereGtInt(query: Handle, field: string, value: number | bigint): number;
|
|
107
|
+
queryWhereGteStr(query: Handle, field: string, value: string): number;
|
|
108
|
+
queryWhereGteInt(query: Handle, field: string, value: number | bigint): number;
|
|
109
|
+
queryWhereLtStr(query: Handle, field: string, value: string): number;
|
|
110
|
+
queryWhereLtInt(query: Handle, field: string, value: number | bigint): number;
|
|
111
|
+
queryWhereLteStr(query: Handle, field: string, value: string): number;
|
|
112
|
+
queryWhereLteInt(query: Handle, field: string, value: number | bigint): number;
|
|
113
|
+
queryOrderBy(query: Handle, field: string, ascending: boolean): number;
|
|
114
|
+
queryLimit(query: Handle, limit: number): number;
|
|
115
|
+
queryOffset(query: Handle, offset: number): number;
|
|
116
|
+
querySelectField(query: Handle, field: string): number;
|
|
117
|
+
queryExecute(engine: Handle, query: Handle): string | null;
|
|
118
|
+
queryDelete(engine: Handle, query: Handle): number;
|
|
119
|
+
queryDeleteLocal(engine: Handle, query: Handle): number;
|
|
120
|
+
queryPatch(engine: Handle, query: Handle, patchDoc: Handle): number;
|
|
121
|
+
queryExecuteToHandles(engine: Handle, query: Handle): Handle;
|
|
122
|
+
resultSetCount(results: Handle): number;
|
|
123
|
+
resultSetGetDoc(results: Handle, index: number): Handle;
|
|
124
|
+
resultSetFree(results: Handle): void;
|
|
125
|
+
resultSetToJson(results: Handle): string | null;
|
|
126
|
+
// Raw result sets (v0.8.3): pinned bytes, not decoded docs. Rows are
|
|
127
|
+
// resolved selectively via rawDocToDoc (decode only what you touch);
|
|
128
|
+
// page with queryStartAfterRaw (no decode at all). rawDocBytes/Id need
|
|
129
|
+
// backend memory reads — use resolve-then-read instead (see client.ts).
|
|
130
|
+
queryExecuteRaw(engine: Handle, query: Handle): Handle;
|
|
131
|
+
rawResultCount(results: Handle): number;
|
|
132
|
+
rawResultGet(results: Handle, index: number): Handle;
|
|
133
|
+
rawResultFree(results: Handle): void;
|
|
134
|
+
rawDocToDoc(engine: Handle, rawDoc: Handle, collection: string): Handle;
|
|
135
|
+
queryStartAfterRaw(query: Handle, anchorRawDoc: Handle): number;
|
|
136
|
+
// Borrowed views (v0.8.11): lazy typed pulls, no owned construction.
|
|
137
|
+
// Numeric/bool getters cross by value (no memory reads); strings and
|
|
138
|
+
// walks stay on resolve/raw paths (documented in client.ts).
|
|
139
|
+
viewGet(engine: Handle, collection: string, docId: string): Handle;
|
|
140
|
+
viewFree(view: Handle): void;
|
|
141
|
+
viewFieldCount(view: Handle): number;
|
|
142
|
+
viewHasField(view: Handle, key: string): boolean;
|
|
143
|
+
viewGetInt(view: Handle, key: string): number | bigint | null;
|
|
144
|
+
viewGetFloat(view: Handle, key: string): number | null;
|
|
145
|
+
viewGetBool(view: Handle, key: string): boolean | null;
|
|
146
|
+
viewToDoc(view: Handle, docId: string): Handle;
|
|
147
|
+
queryDeferBlobs(query: Handle, defer: boolean): number;
|
|
148
|
+
docResolveBlobs(engine: Handle, collection: string, doc: Handle): number;
|
|
149
|
+
engineInsertTake(engine: Handle, collection: string, docId: string, doc: Handle): number;
|
|
150
|
+
configSetWalReserveBytes(c: Handle, bytes: number | bigint): void;
|
|
151
|
+
|
|
152
|
+
// Full-Text Search Queries (Added)
|
|
153
|
+
queryWhereMatch(query: Handle, field: string, value: string): number;
|
|
154
|
+
queryWhereMatchPrefix(query: Handle, field: string, value: string): number;
|
|
155
|
+
queryWhereContains(query: Handle, field: string, value: string): number;
|
|
156
|
+
queryWhereStartsWith(query: Handle, field: string, value: string): number;
|
|
157
|
+
queryWhereOrStr(query: Handle, field: string, value: string): number;
|
|
158
|
+
queryWhereOrInt(query: Handle, field: string, value: number | bigint): number;
|
|
159
|
+
|
|
160
|
+
// Aggregation API
|
|
161
|
+
queryAggregateCount(query: Handle): number;
|
|
162
|
+
queryAggregateSum(query: Handle, field: string): number;
|
|
163
|
+
queryAggregateAvg(query: Handle, field: string): number;
|
|
164
|
+
queryAggregateMin(query: Handle, field: string): number;
|
|
165
|
+
queryAggregateMax(query: Handle, field: string): number;
|
|
166
|
+
queryExecuteAggregation(engine: Handle, query: Handle): string | null;
|
|
167
|
+
|
|
168
|
+
engineListCollections(engine: Handle): string | null;
|
|
169
|
+
|
|
170
|
+
// Net Sync
|
|
171
|
+
netSyncerNew(engine: Handle, name: string, roomKey: string): Handle;
|
|
172
|
+
netSyncerStart(syncer: Handle, port: number): number;
|
|
173
|
+
netSyncerSetDiscovery(syncer: Handle, mode: number): number;
|
|
174
|
+
netSyncerStatus(syncer: Handle): string | null;
|
|
175
|
+
netSyncerFree(syncer: Handle): void;
|
|
176
|
+
|
|
177
|
+
// Cloud Sync (bi-directional WebSocket replication)
|
|
178
|
+
cloudSyncNew(engine: Handle, mode: number, clientId: string | null, roomName: string | null, roomKey: string | null, authToken: string | null): Handle;
|
|
179
|
+
cloudSyncServerNew(engine: Handle, serverId: string | null, authToken: string | null, roomName: string | null, roomKey: string | null): Handle;
|
|
180
|
+
cloudSyncClientNew(engine: Handle, clientId: string | null, roomName: string | null, roomKey: string | null, authToken: string | null): Handle;
|
|
181
|
+
cloudSyncStart(cloudSync: Handle, address: string): number;
|
|
182
|
+
cloudSyncStatus(cloudSync: Handle): string | null;
|
|
183
|
+
cloudSyncStop(cloudSync: Handle): void;
|
|
184
|
+
cloudSyncFree(cloudSync: Handle): void;
|
|
185
|
+
|
|
186
|
+
// v0.5.9
|
|
187
|
+
createFtsIndex(engine: Handle, collection: string, field: string): number;
|
|
188
|
+
createSimpleIndex(engine: Handle, collection: string, field: string): number;
|
|
189
|
+
|
|
190
|
+
// Vector KNN (core >=0.13.3): one-shot search returns owned JSON
|
|
191
|
+
// [{id, score, doc}] (null = hard error, e.g. dim mismatch — read
|
|
192
|
+
// lastError); unindexed field returns "[]".
|
|
193
|
+
createVectorIndex(engine: Handle, collection: string, field: string, dim: number, metric: number): number;
|
|
194
|
+
engineFindNear(engine: Handle, collection: string, field: string, vec: Float32Array, k: number): string | null;
|
|
195
|
+
|
|
196
|
+
// Graph traversal (core >=0.14.0): one-shot BFS returns owned JSON
|
|
197
|
+
// [{collection, id, depth, doc}] (null = hard error, e.g. incoming
|
|
198
|
+
// into untracked — read lastError); missing anchor returns "[]".
|
|
199
|
+
// direction 0/1/2 = outgoing/incoming/both; edge null = any ref field.
|
|
200
|
+
createTraverseIndex(engine: Handle, collection: string): number;
|
|
201
|
+
engineFindPaths(engine: Handle, collection: string, id: string, direction: number, edge: string | null, maxDepth: number, k: number): string | null;
|
|
202
|
+
// Phase B (core >=0.15.0): edge registration + weighted Dijkstra
|
|
203
|
+
// (same hit shape, cost-ordered; cost rides each hit).
|
|
204
|
+
createEdgeIndex(engine: Handle, collection: string): number;
|
|
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;
|
|
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, binaryStage1: 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
|
+
graphPagerank(engine: Handle, collection: string, seeds: string | null, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null, damping: number, top: number): string | null;
|
|
220
|
+
subgraph(engine: Handle, collection: string, seedId: string, maxDepth: number, direction: number, edge: string | null, via: string | null, nodeField: string | null, nodeJSON: string | null, nodeCap: number): string | null;
|
|
221
|
+
hybridSearch(engine: Handle, collection: string, textField: string, textQuery: string, vecField: string, vec: Float32Array, k: number, rrfK: number): string | null;
|
|
222
|
+
insertJSON(engine: Handle, collection: string, id: string, json: string): number;
|
|
223
|
+
batchSetJSON(batch: Handle, collection: string, id: string, json: string): number;
|
|
224
|
+
|
|
225
|
+
// Array API
|
|
226
|
+
arrayNew(): Handle;
|
|
227
|
+
arrayFree(array: Handle): void;
|
|
228
|
+
arrayAppendStr(array: Handle, value: string): number;
|
|
229
|
+
arrayAppendInt(array: Handle, value: number | bigint): number;
|
|
230
|
+
arrayAppendDoc(array: Handle, doc: Handle): number;
|
|
231
|
+
|
|
232
|
+
// Nested structures
|
|
233
|
+
docInsertDoc(parent: Handle, key: string, child: Handle): number;
|
|
234
|
+
docInsertArray(parent: Handle, key: string, array: Handle): number;
|
|
235
|
+
|
|
236
|
+
// Query extensions
|
|
237
|
+
queryWhereIn(query: Handle, field: string, array: Handle): number;
|
|
238
|
+
queryWhereNotIn(query: Handle, field: string, array: Handle): number;
|
|
239
|
+
queryWhereArrayContainsAny(query: Handle, field: string, array: Handle): number;
|
|
240
|
+
queryWhereArrayContainsStr(query: Handle, field: string, value: string): number;
|
|
241
|
+
queryWhereArrayContainsInt(query: Handle, field: string, value: number | bigint): number;
|
|
242
|
+
queryStartAfter(query: Handle, anchorDoc: Handle): number;
|
|
243
|
+
queryStartAt(query: Handle, anchorDoc: Handle): number;
|
|
244
|
+
queryEndAt(query: Handle, anchorDoc: Handle): number;
|
|
245
|
+
queryEndBefore(query: Handle, anchorDoc: Handle): number;
|
|
246
|
+
|
|
247
|
+
// Unix-only hk_socket_sync_* is deliberately absent: Windows builds omit
|
|
248
|
+
// the symbol, so binding it unconditionally would break koffi on Windows.
|
|
249
|
+
|
|
250
|
+
// F8: per-collection schemas over the C ABI.
|
|
251
|
+
engineSetSchema(engine: Handle, collection: string, schemaJson: string): number;
|
|
252
|
+
engineGetSchema(engine: Handle, collection: string): string | null;
|
|
253
|
+
engineClearSchema(engine: Handle, collection: string): number;
|
|
254
|
+
engineListSchemas(engine: Handle): string | null;
|
|
255
|
+
|
|
256
|
+
// F5: versioned reads, transaction patch/get_many, retry classification.
|
|
257
|
+
engineGetVersioned(engine: Handle, collection: string, docId: string): { doc: Handle; version: bigint };
|
|
258
|
+
transactionGetMany(engine: Handle, tx: Handle, collection: string, idsJson: string): string | null;
|
|
259
|
+
transactionPatch(engine: Handle, tx: Handle, collection: string, docId: string, updatesJson: string): number;
|
|
260
|
+
errorLastKind(): number;
|
|
261
|
+
errorIsRetryable(): boolean;
|
|
262
|
+
|
|
263
|
+
// F7/F3: explain + array/graph predicates.
|
|
264
|
+
queryExplain(engine: Handle, query: Handle): string | null;
|
|
265
|
+
queryWhereArrayAllEq(query: Handle, field: string, valueJson: string): number;
|
|
266
|
+
queryWhereElemMatch(query: Handle, field: string, filtersJson: string): number;
|
|
267
|
+
queryWhereNear(query: Handle, field: string, vec: Float32Array): number;
|
|
268
|
+
queryWhereTraverse(query: Handle, startCol: string, startId: string, direction: number, edge: string | null, maxDepth: number): number;
|
|
269
|
+
|
|
270
|
+
// F4: aggregation pipeline (raw handle; typed builder is separate work).
|
|
271
|
+
pipelineNew(collection: string): Handle;
|
|
272
|
+
pipelineFree(pipeline: Handle): void;
|
|
273
|
+
pipelineMatch(pipeline: Handle, query: Handle): number;
|
|
274
|
+
pipelineProject(pipeline: Handle, fieldsJson: string): number;
|
|
275
|
+
pipelineSort(pipeline: Handle, field: string, ascending: boolean): number;
|
|
276
|
+
pipelineLimit(pipeline: Handle, limit: number): number;
|
|
277
|
+
pipelineOffset(pipeline: Handle, offset: number): number;
|
|
278
|
+
pipelineUnwind(pipeline: Handle, field: string): number;
|
|
279
|
+
pipelineGroup(pipeline: Handle, key: string, accumsJson: string): number;
|
|
280
|
+
pipelineExecute(engine: Handle, pipeline: Handle): string | null;
|
|
281
|
+
pipelineExecuteToHandles(engine: Handle, pipeline: Handle): Handle;
|
|
282
|
+
|
|
283
|
+
// Config additions (0.12-0.16 core knobs).
|
|
284
|
+
configSetGroupCommitIntervalMs(config: Handle, ms: number | bigint): void;
|
|
285
|
+
configSetPageCacheCapacity(config: Handle, capacity: number): void;
|
|
286
|
+
configSetSyncExcluded(config: Handle, collectionsJson: string): number;
|
|
287
|
+
configSetLazyCollections(config: Handle, collectionsJson: string): number;
|
|
288
|
+
configSetReplicationCollections(config: Handle, collectionsJson: string): number;
|
|
289
|
+
|
|
290
|
+
// Quiescence / diagnostics / logging.
|
|
291
|
+
engineAwaitQuiescent(engine: Handle, timeoutMs: number | bigint): boolean;
|
|
292
|
+
engineQuiescenceStatus(engine: Handle): string | null;
|
|
293
|
+
debugWriteStats(): string | null;
|
|
294
|
+
logEnableStderr(): void;
|
|
295
|
+
logDisableStderr(): void;
|
|
296
|
+
|
|
297
|
+
// Lazy cursor walks: callbacks copy immediately; returning false stops.
|
|
298
|
+
cursorWalk(engine: Handle, query: Handle, callback: (id: string, bytes: Uint8Array) => boolean): number;
|
|
299
|
+
cursorWalkView(engine: Handle, query: Handle, callback: (id: string, view: Handle) => boolean): number;
|
|
300
|
+
|
|
301
|
+
// Borrowed raw/view reads: copied before return (lifetime is the result set/view).
|
|
302
|
+
rawDocBytes(rawDoc: Handle): Uint8Array | null;
|
|
303
|
+
rawDocId(rawDoc: Handle): string | null;
|
|
304
|
+
viewGetStr(view: Handle, key: string): string | null;
|
|
305
|
+
viewGetBytes(view: Handle, key: string): Uint8Array | null;
|
|
306
|
+
|
|
307
|
+
// P2 (core 0.18): JSON read paths + dotted-path view pulls. JSON strings
|
|
308
|
+
// are owned (free happens in the binding); view pulls copy before return.
|
|
309
|
+
engineGetJson(engine: Handle, collection: string, docId: string): string | null;
|
|
310
|
+
queryExecuteJson(engine: Handle, query: Handle): string | null;
|
|
311
|
+
viewToJson(view: Handle): string | null;
|
|
312
|
+
cursorWalkJson(engine: Handle, query: Handle, callback: (id: string, json: Uint8Array) => boolean): number;
|
|
313
|
+
viewGetPathInt(view: Handle, path: string): number | bigint | null;
|
|
314
|
+
viewGetPathFloat(view: Handle, path: string): number | null;
|
|
315
|
+
viewGetPathBool(view: Handle, path: string): boolean | null;
|
|
316
|
+
viewGetPathStr(view: Handle, path: string): string | null;
|
|
317
|
+
viewGetPathBytes(view: Handle, path: string): Uint8Array | null;
|
|
318
|
+
|
|
319
|
+
lastError(): string;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function isBunRuntime(): boolean {
|
|
323
|
+
return typeof (globalThis as any).Bun !== 'undefined';
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function defaultLibraryPath(): string {
|
|
327
|
+
const libName = process.platform === 'win32' ? 'hakodb.dll' :
|
|
328
|
+
process.platform === 'darwin' ? 'libhakodb.dylib' : 'libhakodb.so';
|
|
329
|
+
// Explicit path wins (loadNativeBindings(path)); otherwise the binary
|
|
330
|
+
// shipped under ./native/ (populated by sync-native.* from a core
|
|
331
|
+
// checkout or release asset). HAKODB_LIB_PATH overrides both.
|
|
332
|
+
const override = typeof process !== 'undefined' ? process.env.HAKODB_LIB_PATH : undefined;
|
|
333
|
+
if (override) return override;
|
|
334
|
+
return `./native/${libName}`;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function resolveLibraryPath(explicitPath?: string): string {
|
|
338
|
+
return explicitPath ?? defaultLibraryPath();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
342
|
+
const ffi = await import('bun:ffi');
|
|
343
|
+
const { dlopen, FFIType, CString, JSCallback, toArrayBuffer } = ffi as any;
|
|
344
|
+
|
|
345
|
+
// Watch trampolines must outlive their native watch: the engine invokes
|
|
346
|
+
// them from its watch thread, and a GC'd JSCallback would leave that
|
|
347
|
+
// thread calling freed memory (issue #21). Closed in watchFree after
|
|
348
|
+
// the native join.
|
|
349
|
+
const watchTrampolines = new Map<unknown, { close(): void }>();
|
|
350
|
+
|
|
351
|
+
const symbols = dlopen(libPath, {
|
|
352
|
+
hk_engine_open: { args: [FFIType.cstring], returns: FFIType.ptr },
|
|
353
|
+
hk_engine_is_indexes_ready: { args: [FFIType.ptr], returns: FFIType.bool },
|
|
354
|
+
hk_engine_open_with_config: { args: [FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
355
|
+
hk_engine_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
356
|
+
hk_engine_backup: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
357
|
+
hk_engine_compact: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
358
|
+
hk_engine_get_stats: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
359
|
+
hk_engine_get_audit_log: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
360
|
+
hk_engine_snapshot_indices: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
361
|
+
hk_engine_list_indexes: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
362
|
+
|
|
363
|
+
hk_config_new: { args: [], returns: FFIType.ptr },
|
|
364
|
+
hk_config_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
365
|
+
hk_config_set_durability: { args: [FFIType.ptr, FFIType.i32], returns: FFIType.void },
|
|
366
|
+
hk_config_set_encryption_key: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.void },
|
|
367
|
+
hk_config_set_encrypted_collections: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
368
|
+
hk_config_set_audit_log: { args: [FFIType.ptr, FFIType.bool, FFIType.cstring], returns: FFIType.void },
|
|
369
|
+
hk_config_set_query_workers: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.void },
|
|
370
|
+
hk_config_set_memory_limits: { args: [FFIType.ptr, FFIType.usize, FFIType.usize], returns: FFIType.void },
|
|
371
|
+
hk_config_set_storage_tuning: { args: [FFIType.ptr, FFIType.usize, FFIType.usize, FFIType.usize], returns: FFIType.void },
|
|
372
|
+
hk_config_set_blob_threshold: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.void },
|
|
373
|
+
hk_config_set_compression: { args: [FFIType.ptr, FFIType.bool, FFIType.i32], returns: FFIType.void },
|
|
374
|
+
hk_config_set_background_maintenance: { args: [FFIType.ptr, FFIType.bool], returns: FFIType.void },
|
|
375
|
+
|
|
376
|
+
hk_engine_watch: { args: [FFIType.ptr, FFIType.cstring, FFIType.function, FFIType.ptr], returns: FFIType.ptr },
|
|
377
|
+
hk_watch_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
378
|
+
|
|
379
|
+
hk_doc_new: { args: [], returns: FFIType.ptr },
|
|
380
|
+
hk_doc_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
381
|
+
hk_doc_insert_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
382
|
+
hk_doc_insert_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
383
|
+
hk_doc_insert_float: { args: [FFIType.ptr, FFIType.cstring, FFIType.f64], returns: FFIType.i32 },
|
|
384
|
+
hk_doc_insert_bool: { args: [FFIType.ptr, FFIType.cstring, FFIType.bool], returns: FFIType.i32 },
|
|
385
|
+
hk_doc_insert_null: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
386
|
+
hk_doc_insert_bin: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
387
|
+
hk_doc_insert_timestamp: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
388
|
+
hk_doc_insert_server_timestamp: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
389
|
+
hk_doc_to_json: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
390
|
+
|
|
391
|
+
hk_engine_insert: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
392
|
+
hk_engine_get: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
393
|
+
hk_engine_delete: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
394
|
+
hk_engine_delete_local: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
395
|
+
hk_engine_delete_ext: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.i32], returns: FFIType.i32 },
|
|
396
|
+
hk_engine_restore: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
397
|
+
hk_engine_restore_available: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
398
|
+
hk_engine_delete_queue: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
399
|
+
hk_engine_sweep_now: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
400
|
+
hk_net_syncer_new: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
401
|
+
hk_net_syncer_start: { args: [FFIType.ptr, FFIType.u16], returns: FFIType.i32 },
|
|
402
|
+
hk_net_syncer_set_discovery: { args: [FFIType.ptr, FFIType.i32], returns: FFIType.i32 },
|
|
403
|
+
hk_net_syncer_status: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
404
|
+
hk_net_syncer_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
405
|
+
hk_engine_set_collection_local: { args: [FFIType.ptr, FFIType.cstring, FFIType.i32], returns: FFIType.i32 },
|
|
406
|
+
hk_engine_replicate_key: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
407
|
+
hk_engine_replicate_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
408
|
+
hk_engine_vacuum_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
409
|
+
hk_engine_relocate_docs: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
410
|
+
hk_engine_load_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
411
|
+
hk_engine_unload_collection: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
412
|
+
hk_engine_unloaded_collections: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
413
|
+
hk_engine_patch: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
414
|
+
hk_engine_insert_subdoc: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
415
|
+
hk_engine_get_by_ref: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
416
|
+
hk_engine_create_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.u32 },
|
|
417
|
+
hk_engine_create_vector_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32], returns: FFIType.i32 },
|
|
418
|
+
hk_engine_find_near: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
|
|
419
|
+
hk_engine_create_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
420
|
+
hk_engine_find_paths: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
|
|
421
|
+
hk_engine_create_edge_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
422
|
+
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 },
|
|
423
|
+
|
|
424
|
+
hk_batch_new: { args: [], returns: FFIType.ptr },
|
|
425
|
+
|
|
426
|
+
// v0.19.6 parity
|
|
427
|
+
hk_engine_drop_simple_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
428
|
+
hk_engine_drop_vector_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
429
|
+
hk_engine_drop_composite_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32], returns: FFIType.i32 },
|
|
430
|
+
hk_engine_drop_edge_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
431
|
+
hk_engine_drop_fts_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
432
|
+
hk_engine_drop_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
433
|
+
hk_engine_create_vector_index_v2: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32, FFIType.usize, FFIType.usize, FFIType.usize, FFIType.u32], returns: FFIType.i32 },
|
|
434
|
+
hk_engine_graph_pagerank: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.f64, FFIType.usize], returns: FFIType.ptr },
|
|
435
|
+
hk_engine_subgraph: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.usize], returns: FFIType.ptr },
|
|
436
|
+
hk_engine_hybrid_search: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
|
|
437
|
+
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 },
|
|
438
|
+
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 },
|
|
439
|
+
hk_engine_export_graph: { args: [FFIType.ptr, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
440
|
+
hk_engine_graph_analysis: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
441
|
+
hk_engine_insert_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
442
|
+
hk_batch_set_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
443
|
+
hk_batch_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
444
|
+
hk_batch_set: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
445
|
+
hk_batch_delete: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
446
|
+
hk_batch_delete_ext: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.i32], returns: FFIType.i32 },
|
|
447
|
+
hk_batch_commit: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
448
|
+
|
|
449
|
+
hk_transaction_begin: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
450
|
+
hk_transaction_get: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
451
|
+
hk_transaction_set: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
452
|
+
hk_transaction_commit: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
453
|
+
hk_transaction_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
454
|
+
|
|
455
|
+
hk_query_new: { args: [FFIType.cstring], returns: FFIType.ptr },
|
|
456
|
+
hk_query_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
457
|
+
hk_query_where_eq_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
458
|
+
hk_query_where_eq_bool: { args: [FFIType.ptr, FFIType.cstring, FFIType.bool], returns: FFIType.i32 },
|
|
459
|
+
hk_query_where_eq_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
460
|
+
hk_query_where_ne_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
461
|
+
hk_query_where_ne_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
462
|
+
hk_query_where_gt_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
463
|
+
hk_query_where_gt_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
464
|
+
hk_query_where_gte_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
465
|
+
hk_query_where_gte_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
466
|
+
hk_query_where_lt_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
467
|
+
hk_query_where_lt_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
468
|
+
hk_query_where_lte_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
469
|
+
hk_query_where_lte_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
470
|
+
hk_query_where_match: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
471
|
+
hk_query_where_match_prefix: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
472
|
+
hk_query_where_contains: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
473
|
+
hk_query_where_starts_with: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
474
|
+
hk_query_order_by: { args: [FFIType.ptr, FFIType.cstring, FFIType.bool], returns: FFIType.i32 },
|
|
475
|
+
hk_query_limit: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
476
|
+
hk_query_offset: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
477
|
+
hk_query_select_field: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
478
|
+
hk_query_execute: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
479
|
+
hk_query_delete: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
480
|
+
hk_query_delete_local: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
481
|
+
hk_query_patch: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
482
|
+
hk_query_execute_to_handles: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
483
|
+
hk_result_set_count: { args: [FFIType.ptr], returns: FFIType.usize },
|
|
484
|
+
hk_result_set_get_doc: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.ptr },
|
|
485
|
+
hk_result_set_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
486
|
+
hk_result_set_to_json: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
487
|
+
// Raw result sets (v0.8.3). All crossings are handles/strings/ints —
|
|
488
|
+
// no (ptr,len) memory reads needed (anchor + resolve by handle).
|
|
489
|
+
hk_query_execute_raw: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
490
|
+
hk_rawresult_count: { args: [FFIType.ptr], returns: FFIType.usize },
|
|
491
|
+
hk_rawresult_get: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.ptr },
|
|
492
|
+
hk_rawresult_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
493
|
+
hk_query_start_after_raw: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
494
|
+
hk_rawdoc_to_doc: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
495
|
+
hk_query_defer_blobs: { args: [FFIType.ptr, FFIType.i32], returns: FFIType.i32 },
|
|
496
|
+
hk_doc_resolve_blobs: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
497
|
+
hk_engine_insert_take: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
498
|
+
hk_config_set_wal_reserve_bytes: { args: [FFIType.ptr, FFIType.u64], returns: FFIType.void },
|
|
499
|
+
|
|
500
|
+
hk_query_aggregate_count: { args: [FFIType.ptr], returns: FFIType.i32 },
|
|
501
|
+
hk_query_aggregate_sum: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
502
|
+
hk_query_aggregate_avg: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
503
|
+
hk_query_aggregate_min: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
504
|
+
hk_query_aggregate_max: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
505
|
+
hk_query_execute_aggregation: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
506
|
+
hk_query_where_or_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
507
|
+
hk_query_where_or_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.i64], returns: FFIType.i32 },
|
|
508
|
+
|
|
509
|
+
// v0.5.9
|
|
510
|
+
// Indexing
|
|
511
|
+
hk_engine_create_fts_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
512
|
+
hk_engine_create_simple_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
513
|
+
|
|
514
|
+
// Array API
|
|
515
|
+
hk_array_new: { args: [], returns: FFIType.ptr },
|
|
516
|
+
hk_array_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
517
|
+
hk_array_append_str: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
518
|
+
hk_array_append_int: { args: [FFIType.ptr, FFIType.i64], returns: FFIType.i32 },
|
|
519
|
+
hk_array_append_doc: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
520
|
+
|
|
521
|
+
// Nested structures
|
|
522
|
+
hk_doc_insert_doc: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
523
|
+
hk_doc_insert_array: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
524
|
+
|
|
525
|
+
// Query extensions
|
|
526
|
+
hk_query_where_in: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
527
|
+
hk_query_where_not_in: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
528
|
+
hk_query_where_array_contains_any: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
529
|
+
hk_query_where_array_contains: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
530
|
+
hk_query_start_after: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
531
|
+
hk_query_start_at: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
532
|
+
hk_query_end_at: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
533
|
+
hk_query_end_before: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
534
|
+
|
|
535
|
+
hk_doc_insert_reference: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
536
|
+
|
|
537
|
+
hk_cloud_sync_new: { args: [FFIType.ptr, FFIType.i32, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
538
|
+
hk_cloud_sync_server_new: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
539
|
+
hk_cloud_sync_client_new: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
540
|
+
hk_cloud_sync_start: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
541
|
+
hk_cloud_sync_status: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
542
|
+
hk_cloud_sync_stop: { args: [FFIType.ptr], returns: FFIType.void },
|
|
543
|
+
hk_cloud_sync_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
544
|
+
|
|
545
|
+
// 0.16.5 parity: F8 schemas, F5 versioned/tx, F7 explain, F3 predicates,
|
|
546
|
+
// F4 pipelines, config knobs, quiescence, lazy walks and borrowed reads.
|
|
547
|
+
hk_config_set_group_commit_interval_ms: { args: [FFIType.ptr, FFIType.u64], returns: FFIType.void },
|
|
548
|
+
hk_config_set_page_cache_capacity: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.void },
|
|
549
|
+
hk_config_set_sync_excluded: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
550
|
+
hk_config_set_lazy_collections: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
551
|
+
hk_config_set_replication_collections: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
552
|
+
hk_engine_await_quiescent: { args: [FFIType.ptr, FFIType.u64], returns: FFIType.bool },
|
|
553
|
+
hk_engine_quiescence_status: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
554
|
+
hk_engine_get_versioned: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
555
|
+
hk_engine_set_schema: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
556
|
+
hk_engine_get_schema: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
557
|
+
hk_engine_clear_schema: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
558
|
+
hk_engine_list_schemas: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
559
|
+
hk_query_explain: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
560
|
+
hk_query_where_array_all_eq: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
561
|
+
hk_query_where_elem_match: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
562
|
+
hk_query_where_near: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
563
|
+
hk_query_where_traverse: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.cstring, FFIType.usize], returns: FFIType.i32 },
|
|
564
|
+
hk_pipeline_new: { args: [FFIType.cstring], returns: FFIType.ptr },
|
|
565
|
+
hk_pipeline_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
566
|
+
hk_pipeline_match: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.i32 },
|
|
567
|
+
hk_pipeline_project: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
568
|
+
hk_pipeline_sort: { args: [FFIType.ptr, FFIType.cstring, FFIType.bool], returns: FFIType.i32 },
|
|
569
|
+
hk_pipeline_limit: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
570
|
+
hk_pipeline_offset: { args: [FFIType.ptr, FFIType.usize], returns: FFIType.i32 },
|
|
571
|
+
hk_pipeline_unwind: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
572
|
+
hk_pipeline_group: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
573
|
+
hk_pipeline_execute: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
574
|
+
hk_pipeline_execute_to_handles: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
575
|
+
hk_transaction_get_many: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
576
|
+
hk_transaction_patch: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.i32 },
|
|
577
|
+
hk_error_last_kind: { args: [], returns: FFIType.i32 },
|
|
578
|
+
hk_error_is_retryable: { args: [], returns: FFIType.bool },
|
|
579
|
+
hk_debug_write_stats: { args: [], returns: FFIType.ptr },
|
|
580
|
+
hk_log_enable_stderr: { args: [], returns: FFIType.void },
|
|
581
|
+
hk_log_disable_stderr: { args: [], returns: FFIType.void },
|
|
582
|
+
hk_cursor_walk: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
583
|
+
hk_cursor_walk_view: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
584
|
+
hk_rawdoc_bytes: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
585
|
+
hk_rawdoc_id: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
586
|
+
hk_view_get_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
587
|
+
hk_view_get_bytes: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
588
|
+
hk_engine_get_json: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
589
|
+
hk_query_execute_json: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
|
|
590
|
+
hk_cursor_walk_json: { args: [FFIType.ptr, FFIType.ptr, FFIType.function, FFIType.ptr], returns: FFIType.i64 },
|
|
591
|
+
hk_view_to_json: { args: [FFIType.ptr], returns: FFIType.ptr },
|
|
592
|
+
hk_view_get_path_int: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.bool },
|
|
593
|
+
hk_view_get_path_float: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.bool },
|
|
594
|
+
hk_view_get_path_bool: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
595
|
+
hk_view_get_path_str: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
596
|
+
hk_view_get_path_bytes: { args: [FFIType.ptr, FFIType.cstring, FFIType.ptr], returns: FFIType.ptr },
|
|
597
|
+
|
|
598
|
+
// ================= ERRORS =================
|
|
599
|
+
hk_last_error: { args: [], returns: FFIType.ptr },
|
|
600
|
+
hk_string_free: { args: [FFIType.ptr], returns: FFIType.void }
|
|
601
|
+
|
|
602
|
+
}).symbols;
|
|
603
|
+
|
|
604
|
+
const toC = (s: string | null) => s ? Buffer.from(s + '\0') : null;
|
|
605
|
+
// ponytail: typed-array pointer for FFI out-params (i64/double reads).
|
|
606
|
+
// Guarded: only view getters use it, and they throw a clear error on
|
|
607
|
+
// ancient runtimes instead of a cryptic TypeError.
|
|
608
|
+
const bunPtr = (ffi as any).ptr;
|
|
609
|
+
const ptrOf = (arr: BigInt64Array | Float64Array): any => {
|
|
610
|
+
if (!bunPtr) throw new Error('bun:ffi ptr() unavailable — upgrade Bun');
|
|
611
|
+
return bunPtr(arr);
|
|
612
|
+
};
|
|
613
|
+
const ptrToStringAndFree = (ptr: any): string | null => {
|
|
614
|
+
if (!ptr) return null;
|
|
615
|
+
const text = new CString(ptr).toString();
|
|
616
|
+
symbols.hk_string_free(ptr);
|
|
617
|
+
return text;
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
return {
|
|
621
|
+
engineOpen: (path) => symbols.hk_engine_open(toC(path)),
|
|
622
|
+
engineIsIndexesReady: (engine) => symbols.hk_engine_is_indexes_ready(engine),
|
|
623
|
+
engineOpenWithConfig: (path, config) => symbols.hk_engine_open_with_config(toC(path), config),
|
|
624
|
+
engineFree: (engine) => symbols.hk_engine_free(engine),
|
|
625
|
+
engineBackup: (e, p) => symbols.hk_engine_backup(e, toC(p)),
|
|
626
|
+
engineCompact: (e) => symbols.hk_engine_compact(e),
|
|
627
|
+
engineGetStats: (e) => ptrToStringAndFree(symbols.hk_engine_get_stats(e)),
|
|
628
|
+
engineGetAuditLog: (e) => ptrToStringAndFree(symbols.hk_engine_get_audit_log(e)),
|
|
629
|
+
engineSnapshotIndices: (e) => symbols.hk_engine_snapshot_indices(e),
|
|
630
|
+
engineListIndexes: (e, c) => ptrToStringAndFree(symbols.hk_engine_list_indexes(e, toC(c))),
|
|
631
|
+
|
|
632
|
+
configNew: () => symbols.hk_config_new(),
|
|
633
|
+
configFree: (c) => symbols.hk_config_free(c),
|
|
634
|
+
configSetDurability: (c, m) => symbols.hk_config_set_durability(c, m),
|
|
635
|
+
configSetEncryptionKey: (c, k) => symbols.hk_config_set_encryption_key(c, toC(k)),
|
|
636
|
+
configSetEncryptedCollections: (c, json) => symbols.hk_config_set_encrypted_collections(c, toC(json)),
|
|
637
|
+
configSetAuditLog: (c, e, p) => symbols.hk_config_set_audit_log(c, e, toC(p)),
|
|
638
|
+
configSetQueryWorkers: (c, count) => symbols.hk_config_set_query_workers(c, count),
|
|
639
|
+
configSetMemoryLimits: (c, m, mi) => symbols.hk_config_set_memory_limits(c, m, mi),
|
|
640
|
+
configSetStorageTuning: (c, ps, th, gc) => symbols.hk_config_set_storage_tuning(c, ps, th, gc),
|
|
641
|
+
configSetBlobThreshold: (c, t) => symbols.hk_config_set_blob_threshold(c, t),
|
|
642
|
+
configSetCompression: (c, e, l) => symbols.hk_config_set_compression(c, e, l),
|
|
643
|
+
configSetBackgroundMaintenance: (c, e) => symbols.hk_config_set_background_maintenance(c, e),
|
|
644
|
+
|
|
645
|
+
engineWatch: (engine, collection, callback) => {
|
|
646
|
+
// The engine calls the snapshot callback from its native watch
|
|
647
|
+
// thread — bun requires a threadsafe trampoline for that (marshaled
|
|
648
|
+
// onto the JS thread; issue #21).
|
|
649
|
+
const cb = new JSCallback((c: any, p: any, kind: number) => {
|
|
650
|
+
callback(new CString(c).toString(), new CString(p).toString(), kind);
|
|
651
|
+
}, { args: [FFIType.ptr, FFIType.ptr, FFIType.i32], returns: FFIType.void, threadsafe: true });
|
|
652
|
+
const watch = symbols.hk_engine_watch(engine, toC(collection), cb, null);
|
|
653
|
+
watchTrampolines.set(watch, cb);
|
|
654
|
+
return watch;
|
|
655
|
+
},
|
|
656
|
+
watchFree: (watch) => {
|
|
657
|
+
// hk_watch_free joins the watch thread — no invocation can follow,
|
|
658
|
+
// so the trampoline is dead and can be closed + dropped.
|
|
659
|
+
symbols.hk_watch_free(watch);
|
|
660
|
+
const cb = watchTrampolines.get(watch);
|
|
661
|
+
if (cb) {
|
|
662
|
+
cb.close();
|
|
663
|
+
watchTrampolines.delete(watch);
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
|
|
667
|
+
docNew: () => symbols.hk_doc_new(),
|
|
668
|
+
docFree: (doc) => symbols.hk_doc_free(doc),
|
|
669
|
+
docInsertStr: (doc, key, value) => symbols.hk_doc_insert_str(doc, toC(key), toC(value)),
|
|
670
|
+
docInsertInt: (doc, key, value) => symbols.hk_doc_insert_int(doc, toC(key), BigInt(value)),
|
|
671
|
+
docInsertFloat: (doc, key, value) => symbols.hk_doc_insert_float(doc, toC(key), value),
|
|
672
|
+
docInsertBool: (doc, key, value) => symbols.hk_doc_insert_bool(doc, toC(key), value),
|
|
673
|
+
docInsertNull: (doc, key) => symbols.hk_doc_insert_null(doc, toC(key)),
|
|
674
|
+
docInsertBin: (doc, key, bytes) => symbols.hk_doc_insert_bin(doc, toC(key), bytes, bytes.byteLength),
|
|
675
|
+
docInsertTimestamp: (doc, key, micros) => symbols.hk_doc_insert_timestamp(doc, toC(key), micros),
|
|
676
|
+
docInsertServerTimestamp: (doc, key) => symbols.hk_doc_insert_server_timestamp(doc, toC(key)),
|
|
677
|
+
docInsertReference: (doc, key, tc, tid) => symbols.hk_doc_insert_reference(doc, toC(key), toC(tc), toC(tid)),
|
|
678
|
+
docToJson: (doc) => ptrToStringAndFree(symbols.hk_doc_to_json(doc)),
|
|
679
|
+
|
|
680
|
+
engineInsert: (engine, collection, docId, doc) => symbols.hk_engine_insert(engine, toC(collection), toC(docId), doc),
|
|
681
|
+
engineGet: (engine, collection, docId) => symbols.hk_engine_get(engine, toC(collection), toC(docId)),
|
|
682
|
+
engineDelete: (engine, collection, docId) => symbols.hk_engine_delete(engine, toC(collection), toC(docId)),
|
|
683
|
+
engineDeleteLocal: (engine, collection, docId) => symbols.hk_engine_delete_local(engine, toC(collection), toC(docId)),
|
|
684
|
+
engineDeleteEx: (engine, collection, docId, force) => symbols.hk_engine_delete_ext(engine, toC(collection), toC(docId), force ? 1 : 0),
|
|
685
|
+
engineRestore: (engine, collection, docId) => symbols.hk_engine_restore(engine, toC(collection), toC(docId)),
|
|
686
|
+
engineRestoreAvailable: (engine, collection) => ptrToStringAndFree(symbols.hk_engine_restore_available(engine, (collection ? toC(collection) : null) as unknown as string)),
|
|
687
|
+
engineDeleteQueue: (engine, collection) => ptrToStringAndFree(symbols.hk_engine_delete_queue(engine, (collection ? toC(collection) : null) as unknown as string)),
|
|
688
|
+
engineSweepNow: (engine) => symbols.hk_engine_sweep_now(engine),
|
|
689
|
+
engineSetCollectionLocal: (engine, collection, local) => symbols.hk_engine_set_collection_local(engine, toC(collection), local),
|
|
690
|
+
engineReplicateKey: (engine, collection, docId) => symbols.hk_engine_replicate_key(engine, toC(collection), toC(docId)),
|
|
691
|
+
engineReplicateCollection: (engine, collection) => symbols.hk_engine_replicate_collection(engine, toC(collection)),
|
|
692
|
+
engineVacuumCollection: (engine, collection) => symbols.hk_engine_vacuum_collection(engine, toC(collection)),
|
|
693
|
+
engineRelocateDocs: (engine, src, dst, idsJson) => ptrToStringAndFree(symbols.hk_engine_relocate_docs(engine, toC(src), toC(dst), toC(idsJson))),
|
|
694
|
+
engineLoadCollection: (engine, collection) => symbols.hk_engine_load_collection(engine, toC(collection)),
|
|
695
|
+
engineUnloadCollection: (engine, collection) => symbols.hk_engine_unload_collection(engine, toC(collection)),
|
|
696
|
+
engineUnloadedCollections: (engine) => ptrToStringAndFree(symbols.hk_engine_unloaded_collections(engine)),
|
|
697
|
+
enginePatch: (engine, collection, docId, updates) => symbols.hk_engine_patch(engine, toC(collection), toC(docId), updates),
|
|
698
|
+
engineInsertSubDoc: (engine, col, id, subCol, subId, doc) => symbols.hk_engine_insert_subdoc(engine, toC(col), toC(id), toC(subCol), toC(subId), doc),
|
|
699
|
+
engineGetByRef: (engine, doc, fieldKey) => symbols.hk_engine_get_by_ref(engine, doc, toC(fieldKey)),
|
|
700
|
+
engineCreateIndex: (engine, collection, fieldsJson) => symbols.hk_engine_create_index(engine, toC(collection), toC(fieldsJson)),
|
|
701
|
+
|
|
702
|
+
batchNew: () => symbols.hk_batch_new(),
|
|
703
|
+
batchFree: (batch) => symbols.hk_batch_free(batch),
|
|
704
|
+
batchSet: (batch, collection, docId, doc) => symbols.hk_batch_set(batch, toC(collection), toC(docId), doc),
|
|
705
|
+
batchDelete: (batch, collection, docId) => symbols.hk_batch_delete(batch, toC(collection), toC(docId)),
|
|
706
|
+
batchDeleteEx: (batch, collection, docId, force) => symbols.hk_batch_delete_ext(batch, toC(collection), toC(docId), force ? 1 : 0),
|
|
707
|
+
batchCommit: (engine, batch) => symbols.hk_batch_commit(engine, batch),
|
|
708
|
+
|
|
709
|
+
transactionBegin: (engine) => symbols.hk_transaction_begin(engine),
|
|
710
|
+
transactionGet: (engine, tx, collection, docId) => symbols.hk_transaction_get(engine, tx, toC(collection), toC(docId)),
|
|
711
|
+
transactionSet: (tx, collection, docId, doc) => symbols.hk_transaction_set(tx, toC(collection), toC(docId), doc),
|
|
712
|
+
transactionCommit: (engine, tx) => symbols.hk_transaction_commit(engine, tx),
|
|
713
|
+
transactionFree: (tx) => symbols.hk_transaction_free(tx),
|
|
714
|
+
|
|
715
|
+
queryNew: (collection) => symbols.hk_query_new(toC(collection)),
|
|
716
|
+
queryFree: (query) => symbols.hk_query_free(query),
|
|
717
|
+
queryWhereEqStr: (query, field, value) => symbols.hk_query_where_eq_str(query, toC(field), toC(value)),
|
|
718
|
+
queryWhereEqBool: (query, field, value) => symbols.hk_query_where_eq_bool(query, toC(field), value),
|
|
719
|
+
queryWhereEqInt: (query, field, value) => symbols.hk_query_where_eq_int(query, toC(field), BigInt(value)),
|
|
720
|
+
queryWhereNeStr: (query, field, value) => symbols.hk_query_where_ne_str(query, toC(field), toC(value)),
|
|
721
|
+
queryWhereNeInt: (query, field, value) => symbols.hk_query_where_ne_int(query, toC(field), BigInt(value)),
|
|
722
|
+
queryWhereGtStr: (query, field, value) => symbols.hk_query_where_gt_str(query, toC(field), toC(value)),
|
|
723
|
+
queryWhereGtInt: (query, field, value) => symbols.hk_query_where_gt_int(query, toC(field), BigInt(value)),
|
|
724
|
+
queryWhereGteStr: (query, field, value) => symbols.hk_query_where_gte_str(query, toC(field), toC(value)),
|
|
725
|
+
queryWhereGteInt: (query, field, value) => symbols.hk_query_where_gte_int(query, toC(field), BigInt(value)),
|
|
726
|
+
queryWhereLtStr: (query, field, value) => symbols.hk_query_where_lt_str(query, toC(field), toC(value)),
|
|
727
|
+
queryWhereLtInt: (query, field, value) => symbols.hk_query_where_lt_int(query, toC(field), BigInt(value)),
|
|
728
|
+
queryWhereLteStr: (query, field, value) => symbols.hk_query_where_lte_str(query, toC(field), toC(value)),
|
|
729
|
+
queryWhereLteInt: (query, field, value) => symbols.hk_query_where_lte_int(query, toC(field), BigInt(value)),
|
|
730
|
+
queryWhereMatch: (query, field, value) => symbols.hk_query_where_match(query, toC(field), toC(value)),
|
|
731
|
+
queryWhereMatchPrefix: (query, field, value) => symbols.hk_query_where_match_prefix(query, toC(field), toC(value)),
|
|
732
|
+
queryWhereContains: (query, field, value) => symbols.hk_query_where_contains(query, toC(field), toC(value)),
|
|
733
|
+
queryWhereStartsWith: (query, field, value) => symbols.hk_query_where_starts_with(query, toC(field), toC(value)),
|
|
734
|
+
queryWhereOrStr: (query, field, value) => symbols.hk_query_where_or_str(query, toC(field), toC(value)),
|
|
735
|
+
queryWhereOrInt: (query, field, value) => symbols.hk_query_where_or_int(query, toC(field), BigInt(value)),
|
|
736
|
+
queryOrderBy: (query, field, asc) => symbols.hk_query_order_by(query, toC(field), asc),
|
|
737
|
+
queryLimit: (query, limit) => symbols.hk_query_limit(query, limit),
|
|
738
|
+
queryOffset: (query, offset) => symbols.hk_query_offset(query, offset),
|
|
739
|
+
querySelectField: (query, field) => symbols.hk_query_select_field(query, toC(field)),
|
|
740
|
+
queryExecute: (engine, query) => ptrToStringAndFree(symbols.hk_query_execute(engine, query)),
|
|
741
|
+
queryDelete: (engine, query) => symbols.hk_query_delete(engine, query),
|
|
742
|
+
queryDeleteLocal: (engine, query) => symbols.hk_query_delete_local(engine, query),
|
|
743
|
+
queryPatch: (engine, query, patchDoc) => symbols.hk_query_patch(engine, query, patchDoc),
|
|
744
|
+
queryExecuteToHandles: (engine, query) => symbols.hk_query_execute_to_handles(engine, query),
|
|
745
|
+
resultSetCount: (results) => symbols.hk_result_set_count(results),
|
|
746
|
+
resultSetGetDoc: (results, index) => symbols.hk_result_set_get_doc(results, index),
|
|
747
|
+
resultSetFree: (results) => symbols.hk_result_set_free(results),
|
|
748
|
+
resultSetToJson: (results) => ptrToStringAndFree(symbols.hk_result_set_to_json(results)),
|
|
749
|
+
queryExecuteRaw: (engine, query) => symbols.hk_query_execute_raw(engine, query),
|
|
750
|
+
rawResultCount: (results) => symbols.hk_rawresult_count(results),
|
|
751
|
+
rawResultGet: (results, index) => symbols.hk_rawresult_get(results, index),
|
|
752
|
+
rawResultFree: (results) => symbols.hk_rawresult_free(results),
|
|
753
|
+
queryStartAfterRaw: (query, anchorRawDoc) => symbols.hk_query_start_after_raw(query, anchorRawDoc),
|
|
754
|
+
rawDocToDoc: (engine, rawDoc, collection) => symbols.hk_rawdoc_to_doc(engine, rawDoc, toC(collection)),
|
|
755
|
+
viewGet: (engine, collection, docId) => symbols.hk_view_get(engine, toC(collection), toC(docId)),
|
|
756
|
+
viewFree: (view) => symbols.hk_view_free(view),
|
|
757
|
+
viewFieldCount: (view) => symbols.hk_view_field_count(view),
|
|
758
|
+
viewHasField: (view, key) => symbols.hk_view_has_field(view, toC(key)),
|
|
759
|
+
viewGetInt: (view, key) => {
|
|
760
|
+
const out = new BigInt64Array(1);
|
|
761
|
+
return symbols.hk_view_get_int(view, toC(key), ptrOf(out)) ? out[0] : null;
|
|
762
|
+
},
|
|
763
|
+
viewGetFloat: (view, key) => {
|
|
764
|
+
const out = new Float64Array(1);
|
|
765
|
+
return symbols.hk_view_get_float(view, toC(key), ptrOf(out)) ? out[0] : null;
|
|
766
|
+
},
|
|
767
|
+
viewGetBool: (view, key) => {
|
|
768
|
+
const r = symbols.hk_view_get_bool(view, toC(key));
|
|
769
|
+
return r < 0 ? null : r !== 0;
|
|
770
|
+
},
|
|
771
|
+
viewToDoc: (view, docId) => symbols.hk_view_to_doc(view, toC(docId)),
|
|
772
|
+
queryDeferBlobs: (query, defer) => symbols.hk_query_defer_blobs(query, defer ? 1 : 0),
|
|
773
|
+
docResolveBlobs: (engine, collection, doc) => symbols.hk_doc_resolve_blobs(engine, toC(collection), doc),
|
|
774
|
+
engineInsertTake: (engine, collection, docId, doc) => symbols.hk_engine_insert_take(engine, toC(collection), toC(docId), doc),
|
|
775
|
+
configSetWalReserveBytes: (c, bytes) => symbols.hk_config_set_wal_reserve_bytes(c, bytes),
|
|
776
|
+
|
|
777
|
+
queryAggregateCount: (q) => symbols.hk_query_aggregate_count(q),
|
|
778
|
+
queryAggregateSum: (q, f) => symbols.hk_query_aggregate_sum(q, toC(f)),
|
|
779
|
+
queryAggregateAvg: (q, f) => symbols.hk_query_aggregate_avg(q, toC(f)),
|
|
780
|
+
queryAggregateMin: (q, f) => symbols.hk_query_aggregate_min(q, toC(f)),
|
|
781
|
+
queryAggregateMax: (q, f) => symbols.hk_query_aggregate_max(q, toC(f)),
|
|
782
|
+
queryExecuteAggregation: (e, q) => ptrToStringAndFree(symbols.hk_query_execute_aggregation(e, q)),
|
|
783
|
+
engineListCollections: (engine) => ptrToStringAndFree(symbols.hk_engine_list_collections(engine)),
|
|
784
|
+
netSyncerNew: (engine, name, roomKey) => symbols.hk_net_syncer_new(engine, toC(name), toC(roomKey)),
|
|
785
|
+
netSyncerStart: (syncer, port) => symbols.hk_net_syncer_start(syncer, port),
|
|
786
|
+
netSyncerSetDiscovery: (syncer, mode) => symbols.hk_net_syncer_set_discovery(syncer, mode),
|
|
787
|
+
netSyncerStatus: (syncer) => ptrToStringAndFree(symbols.hk_net_syncer_status(syncer)),
|
|
788
|
+
netSyncerFree: (syncer) => symbols.hk_net_syncer_free(syncer),
|
|
789
|
+
|
|
790
|
+
cloudSyncNew: (engine, mode, clientId, roomName, roomKey, authToken) => symbols.hk_cloud_sync_new(engine, mode, toC(clientId), toC(roomName), toC(roomKey), toC(authToken)),
|
|
791
|
+
cloudSyncServerNew: (engine, serverId, authToken, roomName, roomKey) => symbols.hk_cloud_sync_server_new(engine, toC(serverId), toC(authToken), toC(roomName), toC(roomKey)),
|
|
792
|
+
cloudSyncClientNew: (engine, clientId, roomName, roomKey, authToken) => symbols.hk_cloud_sync_client_new(engine, toC(clientId), toC(roomName), toC(roomKey), toC(authToken)),
|
|
793
|
+
cloudSyncStart: (cs, address) => symbols.hk_cloud_sync_start(cs, toC(address)),
|
|
794
|
+
cloudSyncStatus: (cs) => ptrToStringAndFree(symbols.hk_cloud_sync_status(cs)),
|
|
795
|
+
cloudSyncStop: (cs) => symbols.hk_cloud_sync_stop(cs),
|
|
796
|
+
cloudSyncFree: (cs) => symbols.hk_cloud_sync_free(cs),
|
|
797
|
+
|
|
798
|
+
// ================= v0.5.9 =================
|
|
799
|
+
|
|
800
|
+
// Indexing
|
|
801
|
+
createFtsIndex: (engine, collection, field) => symbols.hk_engine_create_fts_index(engine, toC(collection), toC(field)),
|
|
802
|
+
createSimpleIndex: (engine, collection, field) => symbols.hk_engine_create_simple_index(engine, toC(collection), toC(field)),
|
|
803
|
+
createVectorIndex: (engine, collection, field, dim, metric) => symbols.hk_engine_create_vector_index(engine, toC(collection), toC(field), dim, metric),
|
|
804
|
+
// Float32Array crosses as its LE-f32 bytes (bun:ffi takes the typed
|
|
805
|
+
// array as ptr, like docInsertBin takes bytes).
|
|
806
|
+
engineFindNear: (engine, collection, field, vec, k) => ptrToStringAndFree(symbols.hk_engine_find_near(engine, toC(collection), toC(field), vec, vec.length, k)),
|
|
807
|
+
createTraverseIndex: (engine, collection) => symbols.hk_engine_create_traverse_index(engine, toC(collection)),
|
|
808
|
+
// Null edge crosses as NULL (any ref field); bun:ffi takes null for ptr/cstring.
|
|
809
|
+
engineFindPaths: (engine, collection, id, direction, edge, maxDepth, k) => ptrToStringAndFree(symbols.hk_engine_find_paths(engine, toC(collection), toC(id), direction, edge === null ? null : toC(edge), maxDepth, k)),
|
|
810
|
+
createEdgeIndex: (engine, collection) => symbols.hk_engine_create_edge_index(engine, toC(collection)),
|
|
811
|
+
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)),
|
|
812
|
+
|
|
813
|
+
// v0.19.6 parity
|
|
814
|
+
dropSimpleIndex: (engine, collection, field) => symbols.hk_engine_drop_simple_index(engine, toC(collection), toC(field)),
|
|
815
|
+
dropVectorIndex: (engine, collection, field) => symbols.hk_engine_drop_vector_index(engine, toC(collection), toC(field)),
|
|
816
|
+
dropCompositeIndex: (engine, collection, id) => symbols.hk_engine_drop_composite_index(engine, toC(collection), id),
|
|
817
|
+
dropEdgeIndex: (engine, collection) => symbols.hk_engine_drop_edge_index(engine, toC(collection)),
|
|
818
|
+
dropFtsIndex: (engine, collection, field) => symbols.hk_engine_drop_fts_index(engine, toC(collection), toC(field)),
|
|
819
|
+
dropTraverseIndex: (engine, collection) => symbols.hk_engine_drop_traverse_index(engine, toC(collection)),
|
|
820
|
+
createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1) => symbols.hk_engine_create_vector_index_v2(engine, toC(collection), toC(field), dim, metric, m, efConstruction, efSearch, binaryStage1),
|
|
821
|
+
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))),
|
|
822
|
+
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))),
|
|
823
|
+
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))),
|
|
824
|
+
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))),
|
|
825
|
+
graphPagerank: (engine, collection, seeds, direction, edge, via, nodeField, nodeJSON, damping, top) => ptrToStringAndFree(symbols.hk_engine_graph_pagerank(engine, toC(collection), seeds === null ? null : toC(seeds), direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), damping, top)),
|
|
826
|
+
subgraph: (engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap) => ptrToStringAndFree(symbols.hk_engine_subgraph(engine, toC(collection), toC(seedId), maxDepth, direction, edge === null ? null : toC(edge), via === null ? null : toC(via), nodeField === null ? null : toC(nodeField), nodeJSON === null ? null : toC(nodeJSON), nodeCap)),
|
|
827
|
+
hybridSearch: (engine, collection, textField, textQuery, vecField, vec, k, rrfK) => ptrToStringAndFree(symbols.hk_engine_hybrid_search(engine, toC(collection), toC(textField), toC(textQuery), toC(vecField), vec, vec.length, k, rrfK)),
|
|
828
|
+
insertJSON: (engine, collection, id, json) => symbols.hk_engine_insert_json(engine, toC(collection), toC(id), toC(json)),
|
|
829
|
+
batchSetJSON: (batch, collection, id, json) => symbols.hk_batch_set_json(batch, toC(collection), toC(id), toC(json)),
|
|
830
|
+
|
|
831
|
+
// Array API
|
|
832
|
+
arrayNew: () => symbols.hk_array_new(),
|
|
833
|
+
arrayFree: (arr) => symbols.hk_array_free(arr),
|
|
834
|
+
arrayAppendStr: (arr, value) => symbols.hk_array_append_str(arr, toC(value)),
|
|
835
|
+
arrayAppendInt: (arr, value) => symbols.hk_array_append_int(arr, BigInt(value)),
|
|
836
|
+
arrayAppendDoc: (arr, doc) => symbols.hk_array_append_doc(arr, doc),
|
|
837
|
+
|
|
838
|
+
// Nested
|
|
839
|
+
docInsertDoc: (parent, key, child) => symbols.hk_doc_insert_doc(parent, toC(key), child),
|
|
840
|
+
docInsertArray: (parent, key, arr) => symbols.hk_doc_insert_array(parent, toC(key), arr),
|
|
841
|
+
|
|
842
|
+
// Query extensions
|
|
843
|
+
queryWhereIn: (query, field, arr) => symbols.hk_query_where_in(query, toC(field), arr),
|
|
844
|
+
queryWhereNotIn: (query, field, arr) => symbols.hk_query_where_not_in(query, toC(field), arr),
|
|
845
|
+
queryWhereArrayContainsAny: (query, field, arr) => symbols.hk_query_where_array_contains_any(query, toC(field), arr),
|
|
846
|
+
queryWhereArrayContainsStr: (query, field, value) => symbols.hk_query_where_array_contains(query, toC(field), toC(String(value))),
|
|
847
|
+
queryWhereArrayContainsInt: (query, field, value) => symbols.hk_query_where_array_contains(query, toC(field), toC(String(value))),
|
|
848
|
+
queryStartAfter: (query, anchorDoc) => symbols.hk_query_start_after(query, anchorDoc),
|
|
849
|
+
queryStartAt: (query, anchorDoc) => symbols.hk_query_start_at(query, anchorDoc),
|
|
850
|
+
queryEndAt: (query, anchorDoc) => symbols.hk_query_end_at(query, anchorDoc),
|
|
851
|
+
queryEndBefore: (query, anchorDoc) => symbols.hk_query_end_before(query, anchorDoc),
|
|
852
|
+
|
|
853
|
+
// 0.16.5 parity.
|
|
854
|
+
engineSetSchema: (e, c, json) => symbols.hk_engine_set_schema(e, toC(c), toC(json)),
|
|
855
|
+
engineGetSchema: (e, c) => ptrToStringAndFree(symbols.hk_engine_get_schema(e, toC(c))),
|
|
856
|
+
engineClearSchema: (e, c) => symbols.hk_engine_clear_schema(e, toC(c)),
|
|
857
|
+
engineListSchemas: (e) => ptrToStringAndFree(symbols.hk_engine_list_schemas(e)),
|
|
858
|
+
engineGetVersioned: (e, c, id) => {
|
|
859
|
+
const out = new BigInt64Array(1);
|
|
860
|
+
const doc = symbols.hk_engine_get_versioned(e, toC(c), toC(id), ptrOf(out));
|
|
861
|
+
return { doc, version: out[0] };
|
|
862
|
+
},
|
|
863
|
+
engineAwaitQuiescent: (e, ms) => symbols.hk_engine_await_quiescent(e, BigInt(ms)),
|
|
864
|
+
engineQuiescenceStatus: (e) => ptrToStringAndFree(symbols.hk_engine_quiescence_status(e)),
|
|
865
|
+
transactionGetMany: (e, tx, c, idsJson) => ptrToStringAndFree(symbols.hk_transaction_get_many(e, tx, toC(c), toC(idsJson))),
|
|
866
|
+
transactionPatch: (e, tx, c, id, updatesJson) => symbols.hk_transaction_patch(e, tx, toC(c), toC(id), toC(updatesJson)),
|
|
867
|
+
errorLastKind: () => symbols.hk_error_last_kind(),
|
|
868
|
+
errorIsRetryable: () => symbols.hk_error_is_retryable(),
|
|
869
|
+
debugWriteStats: () => ptrToStringAndFree(symbols.hk_debug_write_stats()),
|
|
870
|
+
logEnableStderr: () => symbols.hk_log_enable_stderr(),
|
|
871
|
+
logDisableStderr: () => symbols.hk_log_disable_stderr(),
|
|
872
|
+
queryExplain: (e, q) => ptrToStringAndFree(symbols.hk_query_explain(e, q)),
|
|
873
|
+
queryWhereArrayAllEq: (q, f, json) => symbols.hk_query_where_array_all_eq(q, toC(f), toC(json)),
|
|
874
|
+
queryWhereElemMatch: (q, f, json) => symbols.hk_query_where_elem_match(q, toC(f), toC(json)),
|
|
875
|
+
queryWhereNear: (q, f, vec) => symbols.hk_query_where_near(q, toC(f), vec, vec.length),
|
|
876
|
+
queryWhereTraverse: (q, sc, sid, dir, edge, depth) => symbols.hk_query_where_traverse(q, toC(sc), toC(sid), dir, edge === null ? null : toC(edge), depth),
|
|
877
|
+
pipelineNew: (c) => symbols.hk_pipeline_new(toC(c)),
|
|
878
|
+
pipelineFree: (p) => symbols.hk_pipeline_free(p),
|
|
879
|
+
pipelineMatch: (p, q) => symbols.hk_pipeline_match(p, q),
|
|
880
|
+
pipelineProject: (p, json) => symbols.hk_pipeline_project(p, toC(json)),
|
|
881
|
+
pipelineSort: (p, f, asc) => symbols.hk_pipeline_sort(p, toC(f), asc),
|
|
882
|
+
pipelineLimit: (p, n) => symbols.hk_pipeline_limit(p, n),
|
|
883
|
+
pipelineOffset: (p, n) => symbols.hk_pipeline_offset(p, n),
|
|
884
|
+
pipelineUnwind: (p, f) => symbols.hk_pipeline_unwind(p, toC(f)),
|
|
885
|
+
pipelineGroup: (p, k, json) => symbols.hk_pipeline_group(p, toC(k), toC(json)),
|
|
886
|
+
pipelineExecute: (e, p) => ptrToStringAndFree(symbols.hk_pipeline_execute(e, p)),
|
|
887
|
+
pipelineExecuteToHandles: (e, p) => symbols.hk_pipeline_execute_to_handles(e, p),
|
|
888
|
+
configSetGroupCommitIntervalMs: (c, ms) => symbols.hk_config_set_group_commit_interval_ms(c, BigInt(ms)),
|
|
889
|
+
configSetPageCacheCapacity: (c, n) => symbols.hk_config_set_page_cache_capacity(c, n),
|
|
890
|
+
configSetSyncExcluded: (c, json) => symbols.hk_config_set_sync_excluded(c, toC(json)),
|
|
891
|
+
configSetLazyCollections: (c, json) => symbols.hk_config_set_lazy_collections(c, toC(json)),
|
|
892
|
+
configSetReplicationCollections: (c, json) => symbols.hk_config_set_replication_collections(c, toC(json)),
|
|
893
|
+
cursorWalk: (e, q, callback) => {
|
|
894
|
+
const cb = new JSCallback((idPtr: any, idLen: number, bytesPtr: any, bytesLen: number) => {
|
|
895
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
896
|
+
const bytes = new Uint8Array(toArrayBuffer(bytesPtr, 0, Number(bytesLen))).slice();
|
|
897
|
+
return callback(id, bytes);
|
|
898
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.usize, FFIType.ptr], returns: FFIType.bool });
|
|
899
|
+
return Number(symbols.hk_cursor_walk(e, q, cb, null));
|
|
900
|
+
},
|
|
901
|
+
cursorWalkView: (e, q, callback) => {
|
|
902
|
+
const cb = new JSCallback((idPtr: any, idLen: number, view: any) => {
|
|
903
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
904
|
+
return callback(id, view);
|
|
905
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.ptr], returns: FFIType.bool });
|
|
906
|
+
return Number(symbols.hk_cursor_walk_view(e, q, cb, null));
|
|
907
|
+
},
|
|
908
|
+
rawDocBytes: (raw) => {
|
|
909
|
+
const len = new BigInt64Array(1);
|
|
910
|
+
const ptr = symbols.hk_rawdoc_bytes(raw, ptrOf(len));
|
|
911
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
912
|
+
},
|
|
913
|
+
rawDocId: (raw) => {
|
|
914
|
+
const len = new BigInt64Array(1);
|
|
915
|
+
const ptr = symbols.hk_rawdoc_id(raw, ptrOf(len));
|
|
916
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
917
|
+
},
|
|
918
|
+
viewGetStr: (view, key) => {
|
|
919
|
+
const len = new BigInt64Array(1);
|
|
920
|
+
const ptr = symbols.hk_view_get_str(view, toC(key), ptrOf(len));
|
|
921
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
922
|
+
},
|
|
923
|
+
viewGetBytes: (view, key) => {
|
|
924
|
+
const len = new BigInt64Array(1);
|
|
925
|
+
const ptr = symbols.hk_view_get_bytes(view, toC(key), ptrOf(len));
|
|
926
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
927
|
+
},
|
|
928
|
+
|
|
929
|
+
// P2 (core 0.18): JSON read paths + dotted-path pulls.
|
|
930
|
+
engineGetJson: (e, c, id) => ptrToStringAndFree(symbols.hk_engine_get_json(e, toC(c), toC(id))),
|
|
931
|
+
queryExecuteJson: (e, q) => ptrToStringAndFree(symbols.hk_query_execute_json(e, q)),
|
|
932
|
+
viewToJson: (view) => ptrToStringAndFree(symbols.hk_view_to_json(view)),
|
|
933
|
+
cursorWalkJson: (e, q, callback) => {
|
|
934
|
+
const cb = new JSCallback((idPtr: any, idLen: number, jsonPtr: any, jsonLen: number) => {
|
|
935
|
+
const id = new TextDecoder().decode(new Uint8Array(toArrayBuffer(idPtr, 0, Number(idLen))).slice());
|
|
936
|
+
const json = new Uint8Array(toArrayBuffer(jsonPtr, 0, Number(jsonLen))).slice();
|
|
937
|
+
return callback(id, json);
|
|
938
|
+
}, { args: [FFIType.ptr, FFIType.usize, FFIType.ptr, FFIType.usize, FFIType.ptr], returns: FFIType.bool });
|
|
939
|
+
return Number(symbols.hk_cursor_walk_json(e, q, cb, null));
|
|
940
|
+
},
|
|
941
|
+
viewGetPathInt: (view, path) => {
|
|
942
|
+
const out = new BigInt64Array(1);
|
|
943
|
+
return symbols.hk_view_get_path_int(view, toC(path), ptrOf(out)) ? out[0] : null;
|
|
944
|
+
},
|
|
945
|
+
viewGetPathFloat: (view, path) => {
|
|
946
|
+
const out = new Float64Array(1);
|
|
947
|
+
return symbols.hk_view_get_path_float(view, toC(path), ptrOf(out)) ? out[0] : null;
|
|
948
|
+
},
|
|
949
|
+
viewGetPathBool: (view, path) => {
|
|
950
|
+
const r = symbols.hk_view_get_path_bool(view, toC(path));
|
|
951
|
+
return r < 0 ? null : r !== 0;
|
|
952
|
+
},
|
|
953
|
+
viewGetPathStr: (view, path) => {
|
|
954
|
+
const len = new BigInt64Array(1);
|
|
955
|
+
const ptr = symbols.hk_view_get_path_str(view, toC(path), ptrOf(len));
|
|
956
|
+
return ptr ? new TextDecoder().decode(new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice()) : null;
|
|
957
|
+
},
|
|
958
|
+
viewGetPathBytes: (view, path) => {
|
|
959
|
+
const len = new BigInt64Array(1);
|
|
960
|
+
const ptr = symbols.hk_view_get_path_bytes(view, toC(path), ptrOf(len));
|
|
961
|
+
return ptr ? new Uint8Array(toArrayBuffer(ptr, 0, Number(len[0]))).slice() : null;
|
|
962
|
+
},
|
|
963
|
+
|
|
964
|
+
lastError: () => {
|
|
965
|
+
const ptr = symbols.hk_last_error();
|
|
966
|
+
return ptr ? new CString(ptr).toString() : 'unknown ffi error';
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
972
|
+
const koffiModule = await import('koffi');
|
|
973
|
+
const koffi: any = (koffiModule as any).default ?? koffiModule;
|
|
974
|
+
const lib = koffi.load(libPath);
|
|
975
|
+
|
|
976
|
+
// ponytail: koffi needs opaque struct declarations up front — without
|
|
977
|
+
// these EVERY struct-typed decl throws at bindings creation, i.e. the
|
|
978
|
+
// node backend was dead on arrival (bun resolves pointers structurally
|
|
979
|
+
// and never noticed). Declared once here for all present and future fns.
|
|
980
|
+
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);
|
|
981
|
+
|
|
982
|
+
// ponytail: owned C strings (Rust-allocated) must come back through a
|
|
983
|
+
// DISPOSABLE type wired to hk_string_free — never bare char* (koffi
|
|
984
|
+
// auto-decodes to a JS string and the native buffer leaks) and never
|
|
985
|
+
// default koffi.free (wrong allocator: Rust memory freed by C free is
|
|
986
|
+
// UB). Declared before the table; the closure runs post-init.
|
|
987
|
+
const flStringFreeRaw = lib.func('void hk_string_free(void* value)');
|
|
988
|
+
const HeapStr = koffi.disposable('HeapStr', 'str', (ptr: any) => { flStringFreeRaw(ptr); });
|
|
989
|
+
|
|
990
|
+
// Canonical callback signature (matches HK_OnSnapshotCallback in
|
|
991
|
+
// hako.h). Kept as documentation; register() below takes the
|
|
992
|
+
// typedef NAME as a string, not this proto object.
|
|
993
|
+
const OnSnapshotCB = koffi.proto('void HK_OnSnapshotCallback(const char *collection, const char *path, int32_t kind, void *user_data)');
|
|
994
|
+
// ids are length-delimited (not NUL-terminated): take them as raw bytes.
|
|
995
|
+
const WalkCB = koffi.proto('bool HkWalkCallback(const uint8_t *id, size_t id_len, const uint8_t *bytes, size_t bytes_len, void *userdata)');
|
|
996
|
+
const ViewWalkCB = koffi.proto('bool HkViewWalkCallback(const uint8_t *id, size_t id_len, const HK_ViewDoc *view, void *userdata)');
|
|
997
|
+
|
|
998
|
+
const fn = {
|
|
999
|
+
hk_engine_open: lib.func('HK_Engine* hk_engine_open(const char* path)'),
|
|
1000
|
+
hk_engine_is_indexes_ready: lib.func('bool hk_engine_is_indexes_ready(HK_Engine* engine)'),
|
|
1001
|
+
hk_engine_open_with_config: lib.func('HK_Engine* hk_engine_open_with_config(const char* path, HK_Config* config)'),
|
|
1002
|
+
hk_engine_free: lib.func('void hk_engine_free(HK_Engine* engine)'),
|
|
1003
|
+
hk_engine_backup: lib.func('int hk_engine_backup(HK_Engine* engine, const char* path)'),
|
|
1004
|
+
hk_engine_compact: lib.func('int hk_engine_compact(HK_Engine* engine)'),
|
|
1005
|
+
// ponytail: owned-string returns are HeapStr (auto-freed via
|
|
1006
|
+
// hk_string_free by the disposable — never bare char*, which leaks,
|
|
1007
|
+
// and never default koffi.free (wrong allocator for Rust memory).
|
|
1008
|
+
// hk_last_error stays char* (TLS, never freed).
|
|
1009
|
+
hk_engine_get_stats: lib.func('HeapStr hk_engine_get_stats(HK_Engine* engine)'),
|
|
1010
|
+
hk_engine_get_audit_log: lib.func('HeapStr hk_engine_get_audit_log(HK_Engine* engine)'),
|
|
1011
|
+
hk_engine_snapshot_indices: lib.func('int hk_engine_snapshot_indices(HK_Engine* engine)'),
|
|
1012
|
+
hk_engine_list_indexes: lib.func('HeapStr hk_engine_list_indexes(HK_Engine* engine, const char* collection)'),
|
|
1013
|
+
|
|
1014
|
+
hk_config_new: lib.func('HK_Config* hk_config_new()'),
|
|
1015
|
+
hk_config_free: lib.func('void hk_config_free(HK_Config* config)'),
|
|
1016
|
+
hk_config_set_durability: lib.func('void hk_config_set_durability(HK_Config* config, int32_t mode)'),
|
|
1017
|
+
hk_config_set_encryption_key: lib.func('void hk_config_set_encryption_key(HK_Config* config, const char* key)'),
|
|
1018
|
+
hk_config_set_encrypted_collections: lib.func('int hk_config_set_encrypted_collections(HK_Config* config, const char* collections_json)'),
|
|
1019
|
+
hk_config_set_audit_log: lib.func('void hk_config_set_audit_log(HK_Config* config, bool enabled, const char* path)'),
|
|
1020
|
+
hk_config_set_query_workers: lib.func('void hk_config_set_query_workers(HK_Config* config, size_t count)'),
|
|
1021
|
+
hk_config_set_memory_limits: lib.func('void hk_config_set_memory_limits(HK_Config* config, size_t mmap_size, size_t max_inlined_bytes)'),
|
|
1022
|
+
hk_config_set_storage_tuning: lib.func('void hk_config_set_storage_tuning(HK_Config* config, size_t page_size, size_t compaction_threshold, size_t group_commit_max_ops)'),
|
|
1023
|
+
hk_config_set_blob_threshold: lib.func('void hk_config_set_blob_threshold(HK_Config* config, size_t threshold_bytes)'),
|
|
1024
|
+
hk_config_set_compression: lib.func('void hk_config_set_compression(HK_Config* config, bool enabled, int32_t level)'),
|
|
1025
|
+
hk_config_set_background_maintenance: lib.func('void hk_config_set_background_maintenance(HK_Config* config, bool enabled)'),
|
|
1026
|
+
|
|
1027
|
+
hk_engine_watch: lib.func('HK_Watch* hk_engine_watch(HK_Engine* engine, const char* collection, HK_OnSnapshotCallback* callback, void* user_data)'),
|
|
1028
|
+
hk_watch_free: lib.func('void hk_watch_free(HK_Watch* watch)'),
|
|
1029
|
+
|
|
1030
|
+
hk_doc_new: lib.func('HK_Doc* hk_doc_new()'),
|
|
1031
|
+
hk_doc_free: lib.func('void hk_doc_free(HK_Doc* doc)'),
|
|
1032
|
+
hk_doc_insert_str: lib.func('int hk_doc_insert_str(HK_Doc* doc, const char* key, const char* value)'),
|
|
1033
|
+
hk_doc_insert_int: lib.func('int hk_doc_insert_int(HK_Doc* doc, const char* key, int64_t value)'),
|
|
1034
|
+
hk_doc_insert_float: lib.func('int hk_doc_insert_float(HK_Doc* doc, const char* key, double value)'),
|
|
1035
|
+
hk_doc_insert_bool: lib.func('int hk_doc_insert_bool(HK_Doc* doc, const char* key, bool value)'),
|
|
1036
|
+
hk_doc_insert_null: lib.func('int hk_doc_insert_null(HK_Doc* doc, const char* key)'),
|
|
1037
|
+
hk_doc_insert_bin: lib.func('int hk_doc_insert_bin(HK_Doc* doc, const char* key, const uint8_t* data, size_t len)'),
|
|
1038
|
+
hk_doc_insert_timestamp: lib.func('int hk_doc_insert_timestamp(HK_Doc* doc, const char* key, int64_t micros)'),
|
|
1039
|
+
hk_doc_insert_server_timestamp: lib.func('int hk_doc_insert_server_timestamp(HK_Doc* doc, const char* key)'),
|
|
1040
|
+
hk_doc_to_json: lib.func('HeapStr hk_doc_to_json(const HK_Doc* doc)'),
|
|
1041
|
+
|
|
1042
|
+
hk_engine_insert: lib.func('int hk_engine_insert(HK_Engine* engine, const char* collection, const char* doc_id, const HK_Doc* doc)'),
|
|
1043
|
+
hk_engine_get: lib.func('HK_Doc* hk_engine_get(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1044
|
+
hk_engine_delete: lib.func('int hk_engine_delete(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1045
|
+
hk_engine_delete_local: lib.func('int hk_engine_delete_local(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1046
|
+
hk_engine_delete_ext: lib.func('int hk_engine_delete_ext(HK_Engine* engine, const char* collection, const char* doc_id, int32_t mode)'),
|
|
1047
|
+
hk_engine_restore: lib.func('int hk_engine_restore(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1048
|
+
hk_engine_restore_available: lib.func('HeapStr hk_engine_restore_available(HK_Engine* engine, const char* collection)'),
|
|
1049
|
+
hk_engine_delete_queue: lib.func('HeapStr hk_engine_delete_queue(HK_Engine* engine, const char* collection)'),
|
|
1050
|
+
hk_engine_sweep_now: lib.func('int hk_engine_sweep_now(HK_Engine* engine)'),
|
|
1051
|
+
hk_engine_set_collection_local: lib.func('int hk_engine_set_collection_local(HK_Engine* engine, const char* collection, int local)'),
|
|
1052
|
+
hk_engine_replicate_key: lib.func('int hk_engine_replicate_key(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1053
|
+
hk_engine_replicate_collection: lib.func('int hk_engine_replicate_collection(HK_Engine* engine, const char* collection)'),
|
|
1054
|
+
hk_engine_vacuum_collection: lib.func('int hk_engine_vacuum_collection(HK_Engine* engine, const char* collection)'),
|
|
1055
|
+
hk_engine_relocate_docs: lib.func('HeapStr hk_engine_relocate_docs(HK_Engine* engine, const char* src, const char* dst, const char* ids_json)'),
|
|
1056
|
+
hk_engine_load_collection: lib.func('int hk_engine_load_collection(HK_Engine* engine, const char* collection)'),
|
|
1057
|
+
hk_engine_unload_collection: lib.func('int hk_engine_unload_collection(HK_Engine* engine, const char* collection)'),
|
|
1058
|
+
hk_engine_unloaded_collections: lib.func('HeapStr hk_engine_unloaded_collections(HK_Engine* engine)'),
|
|
1059
|
+
hk_engine_patch: lib.func('int hk_engine_patch(HK_Engine* engine, const char* collection, const char* doc_id, const HK_Doc* updates)'),
|
|
1060
|
+
hk_engine_insert_subdoc: lib.func('int hk_engine_insert_subdoc(HK_Engine* engine, const char* col, const char* id, const char* sub_col, const char* sub_id, const HK_Doc* doc)'),
|
|
1061
|
+
hk_engine_get_by_ref: lib.func('HK_Doc* hk_engine_get_by_ref(HK_Engine* engine, const HK_Doc* doc, const char* field_key)'),
|
|
1062
|
+
hk_engine_create_index: lib.func('uint32_t hk_engine_create_index(HK_Engine* engine, const char* collection, const char* fields_json)'),
|
|
1063
|
+
hk_engine_create_vector_index: lib.func('int hk_engine_create_vector_index(HK_Engine* engine, const char* collection, const char* field, uint32_t dim, uint32_t metric)'),
|
|
1064
|
+
hk_engine_find_near: lib.func('HeapStr hk_engine_find_near(HK_Engine* engine, const char* collection, const char* field, const float* vec, size_t len, size_t k)'),
|
|
1065
|
+
hk_engine_create_traverse_index: lib.func('int hk_engine_create_traverse_index(HK_Engine* engine, const char* collection)'),
|
|
1066
|
+
hk_engine_find_paths: lib.func('HeapStr hk_engine_find_paths(HK_Engine* engine, const char* collection, const char* doc_id, uint32_t direction, const char* edge, size_t max_depth, size_t k)'),
|
|
1067
|
+
hk_engine_create_edge_index: lib.func('int hk_engine_create_edge_index(HK_Engine* engine, const char* collection)'),
|
|
1068
|
+
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)'),
|
|
1069
|
+
|
|
1070
|
+
// v0.19.6 parity
|
|
1071
|
+
hk_engine_drop_simple_index: lib.func('int hk_engine_drop_simple_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1072
|
+
hk_engine_drop_vector_index: lib.func('int hk_engine_drop_vector_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1073
|
+
hk_engine_drop_composite_index: lib.func('int hk_engine_drop_composite_index(HK_Engine* engine, const char* collection, uint32_t id)'),
|
|
1074
|
+
hk_engine_drop_edge_index: lib.func('int hk_engine_drop_edge_index(HK_Engine* engine, const char* collection)'),
|
|
1075
|
+
hk_engine_drop_fts_index: lib.func('int hk_engine_drop_fts_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1076
|
+
hk_engine_drop_traverse_index: lib.func('int hk_engine_drop_traverse_index(HK_Engine* engine, const char* collection)'),
|
|
1077
|
+
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, uint32_t binary_stage1)'),
|
|
1078
|
+
hk_engine_graph_pagerank: lib.func('HeapStr hk_engine_graph_pagerank(HK_Engine* engine, const char* collection, const char* seeds_json, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json, double damping, size_t top)'),
|
|
1079
|
+
hk_engine_subgraph: lib.func('HeapStr hk_engine_subgraph(HK_Engine* engine, const char* collection, const char* seed_id, uint32_t max_depth, uint32_t direction, const char* edge, const char* via, const char* filter_field, const char* filter_json, size_t node_cap)'),
|
|
1080
|
+
hk_engine_hybrid_search: lib.func('HeapStr hk_engine_hybrid_search(HK_Engine* engine, const char* collection, const char* text_field, const char* text_query, const char* vec_field, const float* vec, size_t vec_len, size_t k, size_t rrf_k)'),
|
|
1081
|
+
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)'),
|
|
1082
|
+
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)'),
|
|
1083
|
+
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)'),
|
|
1084
|
+
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)'),
|
|
1085
|
+
hk_engine_insert_json: lib.func('int hk_engine_insert_json(HK_Engine* engine, const char* collection, const char* doc_id, const char* json)'),
|
|
1086
|
+
hk_batch_set_json: lib.func('int hk_batch_set_json(HK_Batch* batch, const char* collection, const char* doc_id, const char* json)'),
|
|
1087
|
+
|
|
1088
|
+
hk_batch_new: lib.func('HK_Batch* hk_batch_new()'),
|
|
1089
|
+
hk_batch_free: lib.func('void hk_batch_free(HK_Batch* batch)'),
|
|
1090
|
+
hk_batch_set: lib.func('int hk_batch_set(HK_Batch* batch, const char* collection, const char* doc_id, const HK_Doc* doc)'),
|
|
1091
|
+
hk_batch_delete: lib.func('int hk_batch_delete(HK_Batch* batch, const char* collection, const char* doc_id)'),
|
|
1092
|
+
hk_batch_delete_ext: lib.func('int hk_batch_delete_ext(HK_Batch* batch, const char* collection, const char* doc_id, int32_t mode)'),
|
|
1093
|
+
hk_batch_commit: lib.func('int hk_batch_commit(HK_Engine* engine, HK_Batch* batch)'),
|
|
1094
|
+
|
|
1095
|
+
hk_transaction_begin: lib.func('HK_Transaction* hk_transaction_begin(HK_Engine* engine)'),
|
|
1096
|
+
hk_transaction_get: lib.func('HK_Doc* hk_transaction_get(HK_Engine* engine, HK_Transaction* tx, const char* collection, const char* doc_id)'),
|
|
1097
|
+
hk_transaction_set: lib.func('int hk_transaction_set(HK_Transaction* tx, const char* collection, const char* doc_id, const HK_Doc* doc)'),
|
|
1098
|
+
hk_transaction_commit: lib.func('int hk_transaction_commit(HK_Engine* engine, HK_Transaction* tx)'),
|
|
1099
|
+
hk_transaction_free: lib.func('void hk_transaction_free(HK_Transaction* tx)'),
|
|
1100
|
+
|
|
1101
|
+
hk_query_new: lib.func('HK_Query* hk_query_new(const char* collection)'),
|
|
1102
|
+
hk_query_free: lib.func('void hk_query_free(HK_Query* query)'),
|
|
1103
|
+
hk_query_where_eq_str: lib.func('int hk_query_where_eq_str(HK_Query* query, const char* field, const char* value)'),
|
|
1104
|
+
hk_query_where_eq_bool: lib.func('int hk_query_where_eq_bool(HK_Query* query, const char* field, bool value)'),
|
|
1105
|
+
hk_query_where_eq_int: lib.func('int hk_query_where_eq_int(HK_Query* query, const char* field, int64_t value)'),
|
|
1106
|
+
hk_query_where_ne_str: lib.func('int hk_query_where_ne_str(HK_Query* query, const char* field, const char* value)'),
|
|
1107
|
+
hk_query_where_ne_int: lib.func('int hk_query_where_ne_int(HK_Query* query, const char* field, int64_t value)'),
|
|
1108
|
+
hk_query_where_gt_str: lib.func('int hk_query_where_gt_str(HK_Query* query, const char* field, const char* value)'),
|
|
1109
|
+
hk_query_where_gt_int: lib.func('int hk_query_where_gt_int(HK_Query* query, const char* field, int64_t value)'),
|
|
1110
|
+
hk_query_where_gte_str: lib.func('int hk_query_where_gte_str(HK_Query* query, const char* field, const char* value)'),
|
|
1111
|
+
hk_query_where_gte_int: lib.func('int hk_query_where_gte_int(HK_Query* query, const char* field, int64_t value)'),
|
|
1112
|
+
hk_query_where_lt_str: lib.func('int hk_query_where_lt_str(HK_Query* query, const char* field, const char* value)'),
|
|
1113
|
+
hk_query_where_lt_int: lib.func('int hk_query_where_lt_int(HK_Query* query, const char* field, int64_t value)'),
|
|
1114
|
+
hk_query_where_lte_str: lib.func('int hk_query_where_lte_str(HK_Query* query, const char* field, const char* value)'),
|
|
1115
|
+
hk_query_where_lte_int: lib.func('int hk_query_where_lte_int(HK_Query* query, const char* field, int64_t value)'),
|
|
1116
|
+
hk_query_where_match: lib.func('int hk_query_where_match(HK_Query* query, const char* field, const char* value)'),
|
|
1117
|
+
hk_query_where_match_prefix: lib.func('int hk_query_where_match_prefix(HK_Query* query, const char* field, const char* value)'),
|
|
1118
|
+
hk_query_where_contains: lib.func('int hk_query_where_contains(HK_Query* query, const char* field, const char* value)'),
|
|
1119
|
+
hk_query_where_starts_with: lib.func('int hk_query_where_starts_with(HK_Query* query, const char* field, const char* value)'),
|
|
1120
|
+
hk_query_order_by: lib.func('int hk_query_order_by(HK_Query* query, const char* field, bool ascending)'),
|
|
1121
|
+
hk_query_limit: lib.func('int hk_query_limit(HK_Query* query, size_t limit)'),
|
|
1122
|
+
hk_query_offset: lib.func('int hk_query_offset(HK_Query* query, size_t offset)'),
|
|
1123
|
+
hk_query_select_field: lib.func('int hk_query_select_field(HK_Query* query, const char* field)'),
|
|
1124
|
+
hk_query_execute: lib.func('HeapStr hk_query_execute(HK_Engine* engine, const HK_Query* query)'),
|
|
1125
|
+
hk_query_delete: lib.func('int hk_query_delete(HK_Engine* engine, HK_Query* query)'),
|
|
1126
|
+
hk_query_delete_local: lib.func('int hk_query_delete_local(HK_Engine* engine, HK_Query* query)'),
|
|
1127
|
+
hk_query_patch: lib.func('int hk_query_patch(HK_Engine* engine, HK_Query* query, const HK_Doc* patch_doc)'),
|
|
1128
|
+
hk_query_execute_to_handles: lib.func('HK_ResultSet* hk_query_execute_to_handles(HK_Engine* engine, const HK_Query* query)'),
|
|
1129
|
+
hk_result_set_count: lib.func('size_t hk_result_set_count(HK_ResultSet* results)'),
|
|
1130
|
+
hk_result_set_get_doc: lib.func('HK_Doc* hk_result_set_get_doc(HK_ResultSet* results, size_t index)'),
|
|
1131
|
+
hk_result_set_free: lib.func('void hk_result_set_free(HK_ResultSet* results)'),
|
|
1132
|
+
hk_result_set_to_json: lib.func('HeapStr hk_result_set_to_json(HK_ResultSet* results)'),
|
|
1133
|
+
hk_query_execute_raw: lib.func('HK_RawResultSet* hk_query_execute_raw(HK_Engine* engine, const HK_Query* query)'),
|
|
1134
|
+
hk_rawresult_count: lib.func('size_t hk_rawresult_count(HK_RawResultSet* results)'),
|
|
1135
|
+
hk_rawresult_get: lib.func('HK_RawDoc* hk_rawresult_get(HK_RawResultSet* results, size_t index)'),
|
|
1136
|
+
hk_rawresult_free: lib.func('void hk_rawresult_free(HK_RawResultSet* results)'),
|
|
1137
|
+
hk_query_start_after_raw: lib.func('int hk_query_start_after_raw(HK_Query* query, const HK_RawDoc* anchor_doc)'),
|
|
1138
|
+
hk_rawdoc_to_doc: lib.func('HK_Doc* hk_rawdoc_to_doc(HK_Engine* engine, const HK_RawDoc* raw_doc, const char* collection)'),
|
|
1139
|
+
hk_view_get: lib.func('HK_ViewDoc* hk_view_get(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1140
|
+
hk_view_free: lib.func('void hk_view_free(HK_ViewDoc* view)'),
|
|
1141
|
+
hk_view_field_count: lib.func('size_t hk_view_field_count(const HK_ViewDoc* view)'),
|
|
1142
|
+
hk_view_has_field: lib.func('bool hk_view_has_field(const HK_ViewDoc* view, const char* key)'),
|
|
1143
|
+
hk_view_get_int: lib.func('bool hk_view_get_int(const HK_ViewDoc* view, const char* key, _Out_ int64_t *out)'),
|
|
1144
|
+
hk_view_get_float: lib.func('bool hk_view_get_float(const HK_ViewDoc* view, const char* key, _Out_ double *out)'),
|
|
1145
|
+
hk_view_get_bool: lib.func('int hk_view_get_bool(const HK_ViewDoc* view, const char* key)'),
|
|
1146
|
+
hk_view_to_doc: lib.func('HK_Doc* hk_view_to_doc(const HK_ViewDoc* view, const char* doc_id)'),
|
|
1147
|
+
hk_query_defer_blobs: lib.func('int hk_query_defer_blobs(HK_Query* query, int defer)'),
|
|
1148
|
+
hk_doc_resolve_blobs: lib.func('int hk_doc_resolve_blobs(HK_Engine* engine, const char* collection, HK_Doc* doc)'),
|
|
1149
|
+
hk_engine_insert_take: lib.func('int hk_engine_insert_take(HK_Engine* engine, const char* collection, const char* doc_id, HK_Doc* doc)'),
|
|
1150
|
+
hk_config_set_wal_reserve_bytes: lib.func('void hk_config_set_wal_reserve_bytes(HK_Config* config, uint64_t bytes)'),
|
|
1151
|
+
|
|
1152
|
+
hk_query_aggregate_count: lib.func('int hk_query_aggregate_count(HK_Query* query)'),
|
|
1153
|
+
hk_query_aggregate_sum: lib.func('int hk_query_aggregate_sum(HK_Query* query, const char* field)'),
|
|
1154
|
+
hk_query_aggregate_avg: lib.func('int hk_query_aggregate_avg(HK_Query* query, const char* field)'),
|
|
1155
|
+
hk_query_aggregate_min: lib.func('int hk_query_aggregate_min(HK_Query* query, const char* field)'),
|
|
1156
|
+
hk_query_aggregate_max: lib.func('int hk_query_aggregate_max(HK_Query* query, const char* field)'),
|
|
1157
|
+
hk_query_execute_aggregation: lib.func('HeapStr hk_query_execute_aggregation(HK_Engine* engine, const HK_Query* query)'),
|
|
1158
|
+
hk_query_where_or_str: lib.func('int hk_query_where_or_str(HK_Query* query, const char* field, const char* value)'),
|
|
1159
|
+
hk_query_where_or_int: lib.func('int hk_query_where_or_int(HK_Query* query, const char* field, int64_t value)'),
|
|
1160
|
+
|
|
1161
|
+
hk_engine_list_collections: lib.func('HeapStr hk_engine_list_collections(HK_Engine* engine)'),
|
|
1162
|
+
hk_net_syncer_new: lib.func('HK_NetSyncer* hk_net_syncer_new(HK_Engine* engine, const char* name, const char* room_key)'),
|
|
1163
|
+
hk_net_syncer_start: lib.func('int hk_net_syncer_start(HK_NetSyncer* syncer, uint16_t port)'),
|
|
1164
|
+
hk_net_syncer_set_discovery: lib.func('int hk_net_syncer_set_discovery(HK_NetSyncer* syncer, int mode)'),
|
|
1165
|
+
hk_net_syncer_status: lib.func('HeapStr hk_net_syncer_status(HK_NetSyncer* syncer)'),
|
|
1166
|
+
hk_net_syncer_free: lib.func('void hk_net_syncer_free(HK_NetSyncer* syncer)'),
|
|
1167
|
+
|
|
1168
|
+
// v0.5.9
|
|
1169
|
+
// Indexing
|
|
1170
|
+
hk_engine_create_fts_index: lib.func('int hk_engine_create_fts_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1171
|
+
hk_engine_create_simple_index: lib.func('int hk_engine_create_simple_index(HK_Engine* engine, const char* collection, const char* field)'),
|
|
1172
|
+
|
|
1173
|
+
// Array API
|
|
1174
|
+
hk_array_new: lib.func('HK_Array* hk_array_new()'),
|
|
1175
|
+
hk_array_free: lib.func('void hk_array_free(HK_Array* arr)'),
|
|
1176
|
+
hk_array_append_str: lib.func('int hk_array_append_str(HK_Array* arr, const char* value)'),
|
|
1177
|
+
hk_array_append_int: lib.func('int hk_array_append_int(HK_Array* arr, int64_t value)'),
|
|
1178
|
+
hk_array_append_doc: lib.func('int hk_array_append_doc(HK_Array* arr, const HK_Doc* doc)'),
|
|
1179
|
+
|
|
1180
|
+
// Nested
|
|
1181
|
+
hk_doc_insert_doc: lib.func('int hk_doc_insert_doc(HK_Doc* parent, const char* key, HK_Doc* child)'),
|
|
1182
|
+
hk_doc_insert_array: lib.func('int hk_doc_insert_array(HK_Doc* parent, const char* key, HK_Array* arr)'),
|
|
1183
|
+
|
|
1184
|
+
// Query extensions
|
|
1185
|
+
hk_query_where_in: lib.func('int hk_query_where_in(HK_Query* query, const char* field, HK_Array* arr)'),
|
|
1186
|
+
hk_query_where_not_in: lib.func('int hk_query_where_not_in(HK_Query* query, const char* field, HK_Array* arr)'),
|
|
1187
|
+
hk_query_where_array_contains_any: lib.func('int hk_query_where_array_contains_any(HK_Query* query, const char* field, HK_Array* arr)'),
|
|
1188
|
+
hk_query_where_array_contains: lib.func('int hk_query_where_array_contains(HK_Query* query, const char* field, const char* value)'),
|
|
1189
|
+
hk_query_start_after: lib.func('int hk_query_start_after(HK_Query* query, HK_Doc* anchor)'),
|
|
1190
|
+
hk_query_start_at: lib.func('int hk_query_start_at(HK_Query* query, const HK_Doc* anchor)'),
|
|
1191
|
+
hk_query_end_at: lib.func('int hk_query_end_at(HK_Query* query, const HK_Doc* anchor)'),
|
|
1192
|
+
hk_query_end_before: lib.func('int hk_query_end_before(HK_Query* query, const HK_Doc* anchor)'),
|
|
1193
|
+
|
|
1194
|
+
hk_doc_insert_reference: lib.func('int hk_doc_insert_reference(HK_Doc* doc, const char* key, const char* target_collection, const char* target_id)'),
|
|
1195
|
+
|
|
1196
|
+
hk_cloud_sync_new: lib.func('HK_CloudSync* hk_cloud_sync_new(HK_Engine* engine, int32_t mode, const char* client_id, const char* room_name, const char* room_key, const char* auth_token)'),
|
|
1197
|
+
hk_cloud_sync_server_new: lib.func('HK_CloudSync* hk_cloud_sync_server_new(HK_Engine* engine, const char* server_id, const char* auth_token, const char* room_name, const char* room_key)'),
|
|
1198
|
+
hk_cloud_sync_client_new: lib.func('HK_CloudSync* hk_cloud_sync_client_new(HK_Engine* engine, const char* client_id, const char* room_name, const char* room_key, const char* auth_token)'),
|
|
1199
|
+
hk_cloud_sync_start: lib.func('int hk_cloud_sync_start(HK_CloudSync* cloud_sync, const char* address)'),
|
|
1200
|
+
hk_cloud_sync_status: lib.func('HeapStr hk_cloud_sync_status(HK_CloudSync* cloud_sync)'),
|
|
1201
|
+
hk_cloud_sync_stop: lib.func('void hk_cloud_sync_stop(HK_CloudSync* cloud_sync)'),
|
|
1202
|
+
hk_cloud_sync_free: lib.func('void hk_cloud_sync_free(HK_CloudSync* cloud_sync)'),
|
|
1203
|
+
|
|
1204
|
+
// 0.16.5 parity: F8 schemas, F5 versioned/tx, F7 explain, F3 predicates,
|
|
1205
|
+
// F4 pipelines, config knobs, quiescence, lazy walks and borrowed reads.
|
|
1206
|
+
hk_config_set_group_commit_interval_ms: lib.func('void hk_config_set_group_commit_interval_ms(HK_Config* config, uint64_t ms)'),
|
|
1207
|
+
hk_config_set_page_cache_capacity: lib.func('void hk_config_set_page_cache_capacity(HK_Config* config, size_t capacity)'),
|
|
1208
|
+
hk_config_set_sync_excluded: lib.func('int hk_config_set_sync_excluded(HK_Config* config, const char* collections_json)'),
|
|
1209
|
+
hk_config_set_lazy_collections: lib.func('int hk_config_set_lazy_collections(HK_Config* config, const char* collections_json)'),
|
|
1210
|
+
hk_config_set_replication_collections: lib.func('int hk_config_set_replication_collections(HK_Config* config, const char* collections_json)'),
|
|
1211
|
+
hk_engine_await_quiescent: lib.func('bool hk_engine_await_quiescent(HK_Engine* engine, uint64_t timeout_ms)'),
|
|
1212
|
+
hk_engine_quiescence_status: lib.func('HeapStr hk_engine_quiescence_status(HK_Engine* engine)'),
|
|
1213
|
+
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)'),
|
|
1214
|
+
hk_engine_set_schema: lib.func('int hk_engine_set_schema(HK_Engine* engine, const char* collection, const char* schema_json)'),
|
|
1215
|
+
hk_engine_get_schema: lib.func('HeapStr hk_engine_get_schema(HK_Engine* engine, const char* collection)'),
|
|
1216
|
+
hk_engine_clear_schema: lib.func('int hk_engine_clear_schema(HK_Engine* engine, const char* collection)'),
|
|
1217
|
+
hk_engine_list_schemas: lib.func('HeapStr hk_engine_list_schemas(HK_Engine* engine)'),
|
|
1218
|
+
hk_query_explain: lib.func('HeapStr hk_query_explain(HK_Engine* engine, const HK_Query* query)'),
|
|
1219
|
+
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)'),
|
|
1220
|
+
hk_query_where_elem_match: lib.func('int hk_query_where_elem_match(HK_Query* query, const char* field, const char* filters_json)'),
|
|
1221
|
+
hk_query_where_near: lib.func('int hk_query_where_near(HK_Query* query, const char* field, const float* vec, size_t len)'),
|
|
1222
|
+
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)'),
|
|
1223
|
+
hk_pipeline_new: lib.func('HK_Pipeline* hk_pipeline_new(const char* collection)'),
|
|
1224
|
+
hk_pipeline_free: lib.func('void hk_pipeline_free(HK_Pipeline* pipeline)'),
|
|
1225
|
+
hk_pipeline_match: lib.func('int hk_pipeline_match(HK_Pipeline* pipeline, const HK_Query* query)'),
|
|
1226
|
+
hk_pipeline_project: lib.func('int hk_pipeline_project(HK_Pipeline* pipeline, const char* fields_json)'),
|
|
1227
|
+
hk_pipeline_sort: lib.func('int hk_pipeline_sort(HK_Pipeline* pipeline, const char* field, bool ascending)'),
|
|
1228
|
+
hk_pipeline_limit: lib.func('int hk_pipeline_limit(HK_Pipeline* pipeline, size_t limit)'),
|
|
1229
|
+
hk_pipeline_offset: lib.func('int hk_pipeline_offset(HK_Pipeline* pipeline, size_t offset)'),
|
|
1230
|
+
hk_pipeline_unwind: lib.func('int hk_pipeline_unwind(HK_Pipeline* pipeline, const char* field)'),
|
|
1231
|
+
hk_pipeline_group: lib.func('int hk_pipeline_group(HK_Pipeline* pipeline, const char* key, const char* accums_json)'),
|
|
1232
|
+
hk_pipeline_execute: lib.func('HeapStr hk_pipeline_execute(HK_Engine* engine, const HK_Pipeline* pipeline)'),
|
|
1233
|
+
hk_pipeline_execute_to_handles: lib.func('HK_ResultSet* hk_pipeline_execute_to_handles(HK_Engine* engine, const HK_Pipeline* pipeline)'),
|
|
1234
|
+
hk_transaction_get_many: lib.func('HeapStr hk_transaction_get_many(HK_Engine* engine, HK_Transaction* tx, const char* collection, const char* ids_json)'),
|
|
1235
|
+
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)'),
|
|
1236
|
+
hk_error_last_kind: lib.func('int hk_error_last_kind()'),
|
|
1237
|
+
hk_error_is_retryable: lib.func('bool hk_error_is_retryable()'),
|
|
1238
|
+
hk_debug_write_stats: lib.func('HeapStr hk_debug_write_stats()'),
|
|
1239
|
+
hk_log_enable_stderr: lib.func('void hk_log_enable_stderr()'),
|
|
1240
|
+
hk_log_disable_stderr: lib.func('void hk_log_disable_stderr()'),
|
|
1241
|
+
hk_cursor_walk: lib.func('int64_t hk_cursor_walk(HK_Engine* engine, const HK_Query* query, HkWalkCallback* callback, void* userdata)'),
|
|
1242
|
+
hk_cursor_walk_view: lib.func('int64_t hk_cursor_walk_view(HK_Engine* engine, const HK_Query* query, HkViewWalkCallback* callback, void* userdata)'),
|
|
1243
|
+
hk_rawdoc_bytes: lib.func('const uint8_t* hk_rawdoc_bytes(const HK_RawDoc* doc, _Out_ uintptr_t *len_out)'),
|
|
1244
|
+
// Return as uint8_t* so koffi hands back a pointer; the id is
|
|
1245
|
+
// length-delimited, not NUL-terminated.
|
|
1246
|
+
hk_rawdoc_id: lib.func('const uint8_t* hk_rawdoc_id(const HK_RawDoc* doc, _Out_ uintptr_t *len_out)'),
|
|
1247
|
+
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)'),
|
|
1248
|
+
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)'),
|
|
1249
|
+
hk_engine_get_json: lib.func('HeapStr hk_engine_get_json(HK_Engine* engine, const char* collection, const char* doc_id)'),
|
|
1250
|
+
hk_query_execute_json: lib.func('HeapStr hk_query_execute_json(HK_Engine* engine, const HK_Query* query)'),
|
|
1251
|
+
hk_cursor_walk_json: lib.func('int64_t hk_cursor_walk_json(HK_Engine* engine, const HK_Query* query, HkWalkCallback* callback, void* userdata)'),
|
|
1252
|
+
hk_view_to_json: lib.func('HeapStr hk_view_to_json(const HK_ViewDoc* view)'),
|
|
1253
|
+
hk_view_get_path_int: lib.func('bool hk_view_get_path_int(const HK_ViewDoc* view, const char* path, _Out_ int64_t *out)'),
|
|
1254
|
+
hk_view_get_path_float: lib.func('bool hk_view_get_path_float(const HK_ViewDoc* view, const char* path, _Out_ double *out)'),
|
|
1255
|
+
hk_view_get_path_bool: lib.func('int hk_view_get_path_bool(const HK_ViewDoc* view, const char* path)'),
|
|
1256
|
+
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)'),
|
|
1257
|
+
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)'),
|
|
1258
|
+
|
|
1259
|
+
hk_last_error: lib.func('const char* hk_last_error()'),
|
|
1260
|
+
hk_string_free: lib.func('void hk_string_free(void* value)')
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
// ponytail: HeapStr returns arrive as JS strings, ALREADY freed via
|
|
1264
|
+
// hk_string_free by the disposable — no decode, no manual free (both
|
|
1265
|
+
// crash or leak: decode on externals segfaults, freeing a copy leaks).
|
|
1266
|
+
const ptrToStringAndFree = (s: any): string | null => {
|
|
1267
|
+
if (!s) return null;
|
|
1268
|
+
return s as string;
|
|
1269
|
+
};
|
|
1270
|
+
|
|
1271
|
+
return {
|
|
1272
|
+
engineOpen: (path) => fn.hk_engine_open(path),
|
|
1273
|
+
engineIsIndexesReady: (engine) => fn.hk_engine_is_indexes_ready(engine),
|
|
1274
|
+
engineOpenWithConfig: (path, config) => fn.hk_engine_open_with_config(path, config),
|
|
1275
|
+
engineFree: (engine) => fn.hk_engine_free(engine),
|
|
1276
|
+
engineBackup: (e, p) => fn.hk_engine_backup(e, p),
|
|
1277
|
+
engineCompact: (e) => fn.hk_engine_compact(e),
|
|
1278
|
+
engineGetStats: (e) => ptrToStringAndFree(fn.hk_engine_get_stats(e)),
|
|
1279
|
+
engineGetAuditLog: (e) => ptrToStringAndFree(fn.hk_engine_get_audit_log(e)),
|
|
1280
|
+
engineSnapshotIndices: (e) => fn.hk_engine_snapshot_indices(e),
|
|
1281
|
+
engineListIndexes: (e, c) => ptrToStringAndFree(fn.hk_engine_list_indexes(e, c ?? null)),
|
|
1282
|
+
|
|
1283
|
+
configNew: () => fn.hk_config_new(),
|
|
1284
|
+
configFree: (c) => fn.hk_config_free(c),
|
|
1285
|
+
configSetDurability: (c, m) => fn.hk_config_set_durability(c, m),
|
|
1286
|
+
configSetEncryptionKey: (c, k) => fn.hk_config_set_encryption_key(c, k),
|
|
1287
|
+
configSetEncryptedCollections: (c, json) => fn.hk_config_set_encrypted_collections(c, json),
|
|
1288
|
+
configSetAuditLog: (c, e, p) => fn.hk_config_set_audit_log(c, e, p),
|
|
1289
|
+
configSetQueryWorkers: (c, count) => fn.hk_config_set_query_workers(c, count),
|
|
1290
|
+
configSetMemoryLimits: (c, m, mi) => fn.hk_config_set_memory_limits(c, m, mi),
|
|
1291
|
+
configSetStorageTuning: (c, ps, th, gc) => fn.hk_config_set_storage_tuning(c, ps, th, gc),
|
|
1292
|
+
configSetBlobThreshold: (c, t) => fn.hk_config_set_blob_threshold(c, t),
|
|
1293
|
+
configSetCompression: (c, e, l) => fn.hk_config_set_compression(c, e, l),
|
|
1294
|
+
configSetBackgroundMaintenance: (c, e) => fn.hk_config_set_background_maintenance(c, e),
|
|
1295
|
+
|
|
1296
|
+
engineWatch: (engine, collection, callback) => {
|
|
1297
|
+
const wrapper = (c: string, p: string, kind: number, _user: any) => callback(c, p, kind);
|
|
1298
|
+
// ponytail: koffi.register takes the typedef NAME as a string here —
|
|
1299
|
+
// passing the proto object itself throws "Unexpected ... type".
|
|
1300
|
+
return fn.hk_engine_watch(engine, collection, koffi.register(wrapper, 'HK_OnSnapshotCallback *'), null);
|
|
1301
|
+
},
|
|
1302
|
+
watchFree: (watch) => fn.hk_watch_free(watch),
|
|
1303
|
+
|
|
1304
|
+
docNew: () => fn.hk_doc_new(),
|
|
1305
|
+
docFree: (doc) => fn.hk_doc_free(doc),
|
|
1306
|
+
docInsertStr: (doc, key, value) => fn.hk_doc_insert_str(doc, key, value),
|
|
1307
|
+
docInsertInt: (doc, key, value) => fn.hk_doc_insert_int(doc, key, value),
|
|
1308
|
+
docInsertFloat: (doc, key, value) => fn.hk_doc_insert_float(doc, key, value),
|
|
1309
|
+
docInsertBool: (doc, key, value) => fn.hk_doc_insert_bool(doc, key, value),
|
|
1310
|
+
docInsertNull: (doc, key) => fn.hk_doc_insert_null(doc, key),
|
|
1311
|
+
docInsertBin: (doc, key, bytes) => fn.hk_doc_insert_bin(doc, key, Buffer.from(bytes), bytes.byteLength),
|
|
1312
|
+
docInsertTimestamp: (doc, key, micros) => fn.hk_doc_insert_timestamp(doc, key, micros),
|
|
1313
|
+
docInsertServerTimestamp: (doc, key) => fn.hk_doc_insert_server_timestamp(doc, key),
|
|
1314
|
+
docInsertReference: (doc, key, tc, tid) => fn.hk_doc_insert_reference(doc, key, tc, tid),
|
|
1315
|
+
docToJson: (doc) => ptrToStringAndFree(fn.hk_doc_to_json(doc)),
|
|
1316
|
+
|
|
1317
|
+
engineInsert: (engine, collection, docId, doc) => fn.hk_engine_insert(engine, collection, docId, doc),
|
|
1318
|
+
engineGet: (engine, collection, docId) => fn.hk_engine_get(engine, collection, docId),
|
|
1319
|
+
engineDelete: (engine, collection, docId) => fn.hk_engine_delete(engine, collection, docId),
|
|
1320
|
+
engineDeleteLocal: (engine, collection, docId) => fn.hk_engine_delete_local(engine, collection, docId),
|
|
1321
|
+
engineDeleteEx: (engine, collection, docId, force) => fn.hk_engine_delete_ext(engine, collection, docId, force ? 1 : 0),
|
|
1322
|
+
engineRestore: (engine, collection, docId) => fn.hk_engine_restore(engine, collection, docId),
|
|
1323
|
+
engineRestoreAvailable: (engine, collection) => ptrToStringAndFree(fn.hk_engine_restore_available(engine, collection as unknown as string)),
|
|
1324
|
+
engineDeleteQueue: (engine, collection) => ptrToStringAndFree(fn.hk_engine_delete_queue(engine, collection as unknown as string)),
|
|
1325
|
+
engineSweepNow: (engine) => fn.hk_engine_sweep_now(engine),
|
|
1326
|
+
engineSetCollectionLocal: (engine, collection, local) => fn.hk_engine_set_collection_local(engine, collection, local),
|
|
1327
|
+
engineReplicateKey: (engine, collection, docId) => fn.hk_engine_replicate_key(engine, collection, docId),
|
|
1328
|
+
engineReplicateCollection: (engine, collection) => fn.hk_engine_replicate_collection(engine, collection),
|
|
1329
|
+
engineVacuumCollection: (engine, collection) => fn.hk_engine_vacuum_collection(engine, collection),
|
|
1330
|
+
engineRelocateDocs: (engine, src, dst, idsJson) => ptrToStringAndFree(fn.hk_engine_relocate_docs(engine, src, dst, idsJson)),
|
|
1331
|
+
engineLoadCollection: (engine, collection) => fn.hk_engine_load_collection(engine, collection),
|
|
1332
|
+
engineUnloadCollection: (engine, collection) => fn.hk_engine_unload_collection(engine, collection),
|
|
1333
|
+
engineUnloadedCollections: (engine) => ptrToStringAndFree(fn.hk_engine_unloaded_collections(engine)),
|
|
1334
|
+
enginePatch: (engine, collection, docId, updates) => fn.hk_engine_patch(engine, collection, docId, updates),
|
|
1335
|
+
engineInsertSubDoc: (engine, col, id, subCol, subId, doc) => fn.hk_engine_insert_subdoc(engine, col, id, subCol, subId, doc),
|
|
1336
|
+
engineGetByRef: (engine, doc, fieldKey) => fn.hk_engine_get_by_ref(engine, doc, fieldKey),
|
|
1337
|
+
engineCreateIndex: (engine, collection, fieldsJson) => fn.hk_engine_create_index(engine, collection, fieldsJson),
|
|
1338
|
+
|
|
1339
|
+
batchNew: () => fn.hk_batch_new(),
|
|
1340
|
+
batchFree: (batch) => fn.hk_batch_free(batch),
|
|
1341
|
+
batchSet: (batch, collection, docId, doc) => fn.hk_batch_set(batch, collection, docId, doc),
|
|
1342
|
+
batchDelete: (batch, collection, docId) => fn.hk_batch_delete(batch, collection, docId),
|
|
1343
|
+
batchDeleteEx: (batch, collection, docId, force) => fn.hk_batch_delete_ext(batch, collection, docId, force ? 1 : 0),
|
|
1344
|
+
batchCommit: (engine, batch) => fn.hk_batch_commit(engine, batch),
|
|
1345
|
+
|
|
1346
|
+
transactionBegin: (engine) => fn.hk_transaction_begin(engine),
|
|
1347
|
+
transactionGet: (engine, tx, collection, docId) => fn.hk_transaction_get(engine, tx, collection, docId),
|
|
1348
|
+
transactionSet: (tx, collection, docId, doc) => fn.hk_transaction_set(tx, collection, docId, doc),
|
|
1349
|
+
transactionCommit: (engine, tx) => fn.hk_transaction_commit(engine, tx),
|
|
1350
|
+
transactionFree: (tx) => fn.hk_transaction_free(tx),
|
|
1351
|
+
|
|
1352
|
+
queryNew: (collection) => fn.hk_query_new(collection),
|
|
1353
|
+
queryFree: (query) => fn.hk_query_free(query),
|
|
1354
|
+
queryWhereEqStr: (query, field, value) => fn.hk_query_where_eq_str(query, field, value),
|
|
1355
|
+
queryWhereEqBool: (query, field, value) => fn.hk_query_where_eq_bool(query, field, value),
|
|
1356
|
+
queryWhereEqInt: (query, field, value) => fn.hk_query_where_eq_int(query, field, value),
|
|
1357
|
+
queryWhereNeStr: (query, field, value) => fn.hk_query_where_ne_str(query, field, value),
|
|
1358
|
+
queryWhereNeInt: (query, field, value) => fn.hk_query_where_ne_int(query, field, value),
|
|
1359
|
+
queryWhereGtStr: (query, field, value) => fn.hk_query_where_gt_str(query, field, value),
|
|
1360
|
+
queryWhereGtInt: (query, field, value) => fn.hk_query_where_gt_int(query, field, value),
|
|
1361
|
+
queryWhereGteStr: (query, field, value) => fn.hk_query_where_gte_str(query, field, value),
|
|
1362
|
+
queryWhereGteInt: (query, field, value) => fn.hk_query_where_gte_int(query, field, value),
|
|
1363
|
+
queryWhereLtStr: (query, field, value) => fn.hk_query_where_lt_str(query, field, value),
|
|
1364
|
+
queryWhereLtInt: (query, field, value) => fn.hk_query_where_lt_int(query, field, value),
|
|
1365
|
+
queryWhereLteStr: (query, field, value) => fn.hk_query_where_lte_str(query, field, value),
|
|
1366
|
+
queryWhereLteInt: (query, field, value) => fn.hk_query_where_lte_int(query, field, value),
|
|
1367
|
+
queryWhereMatch: (query, field, value) => fn.hk_query_where_match(query, field, value),
|
|
1368
|
+
queryWhereMatchPrefix: (query, field, value) => fn.hk_query_where_match_prefix(query, field, value),
|
|
1369
|
+
queryWhereContains: (query, field, value) => fn.hk_query_where_contains(query, field, value),
|
|
1370
|
+
queryWhereStartsWith: (query, field, value) => fn.hk_query_where_starts_with(query, field, value),
|
|
1371
|
+
queryWhereOrStr: (query, field, value) => fn.hk_query_where_or_str(query, field, value),
|
|
1372
|
+
queryWhereOrInt: (query, field, value) => fn.hk_query_where_or_int(query, field, value),
|
|
1373
|
+
queryOrderBy: (query, field, asc) => fn.hk_query_order_by(query, field, asc),
|
|
1374
|
+
queryLimit: (query, limit) => fn.hk_query_limit(query, limit),
|
|
1375
|
+
queryOffset: (query, offset) => fn.hk_query_offset(query, offset),
|
|
1376
|
+
querySelectField: (query, field) => fn.hk_query_select_field(query, field),
|
|
1377
|
+
queryExecute: (engine, query) => ptrToStringAndFree(fn.hk_query_execute(engine, query)),
|
|
1378
|
+
queryDelete: (engine, query) => fn.hk_query_delete(engine, query),
|
|
1379
|
+
queryDeleteLocal: (engine, query) => fn.hk_query_delete_local(engine, query),
|
|
1380
|
+
queryPatch: (engine, query, patchDoc) => fn.hk_query_patch(engine, query, patchDoc),
|
|
1381
|
+
queryExecuteToHandles: (engine, query) => fn.hk_query_execute_to_handles(engine, query),
|
|
1382
|
+
resultSetCount: (results) => fn.hk_result_set_count(results),
|
|
1383
|
+
resultSetGetDoc: (results, index) => fn.hk_result_set_get_doc(results, index),
|
|
1384
|
+
resultSetFree: (results) => fn.hk_result_set_free(results),
|
|
1385
|
+
resultSetToJson: (results) => ptrToStringAndFree(fn.hk_result_set_to_json(results)),
|
|
1386
|
+
queryExecuteRaw: (engine, query) => fn.hk_query_execute_raw(engine, query),
|
|
1387
|
+
rawResultCount: (results) => fn.hk_rawresult_count(results),
|
|
1388
|
+
rawResultGet: (results, index) => fn.hk_rawresult_get(results, index),
|
|
1389
|
+
rawResultFree: (results) => fn.hk_rawresult_free(results),
|
|
1390
|
+
queryStartAfterRaw: (query, anchorRawDoc) => fn.hk_query_start_after_raw(query, anchorRawDoc),
|
|
1391
|
+
rawDocToDoc: (engine, rawDoc, collection) => fn.hk_rawdoc_to_doc(engine, rawDoc, collection),
|
|
1392
|
+
viewGet: (engine, collection, docId) => fn.hk_view_get(engine, collection, docId),
|
|
1393
|
+
viewFree: (view) => fn.hk_view_free(view),
|
|
1394
|
+
viewFieldCount: (view) => fn.hk_view_field_count(view),
|
|
1395
|
+
viewHasField: (view, key) => fn.hk_view_has_field(view, key),
|
|
1396
|
+
viewGetInt: (view, key) => {
|
|
1397
|
+
const out: bigint[] = [0n];
|
|
1398
|
+
return fn.hk_view_get_int(view, key, out) ? out[0] : null;
|
|
1399
|
+
},
|
|
1400
|
+
viewGetFloat: (view, key) => {
|
|
1401
|
+
const out: number[] = [0];
|
|
1402
|
+
return fn.hk_view_get_float(view, key, out) ? out[0] : null;
|
|
1403
|
+
},
|
|
1404
|
+
viewGetBool: (view, key) => {
|
|
1405
|
+
const r: number = fn.hk_view_get_bool(view, key);
|
|
1406
|
+
return r < 0 ? null : r !== 0;
|
|
1407
|
+
},
|
|
1408
|
+
viewToDoc: (view, docId) => fn.hk_view_to_doc(view, docId),
|
|
1409
|
+
queryDeferBlobs: (query, defer) => fn.hk_query_defer_blobs(query, defer ? 1 : 0),
|
|
1410
|
+
docResolveBlobs: (engine, collection, doc) => fn.hk_doc_resolve_blobs(engine, collection, doc),
|
|
1411
|
+
engineInsertTake: (engine, collection, docId, doc) => fn.hk_engine_insert_take(engine, collection, docId, doc),
|
|
1412
|
+
configSetWalReserveBytes: (c, bytes) => fn.hk_config_set_wal_reserve_bytes(c, bytes),
|
|
1413
|
+
|
|
1414
|
+
queryAggregateCount: (q) => fn.hk_query_aggregate_count(q),
|
|
1415
|
+
queryAggregateSum: (q, f) => fn.hk_query_aggregate_sum(q, f),
|
|
1416
|
+
queryAggregateAvg: (q, f) => fn.hk_query_aggregate_avg(q, f),
|
|
1417
|
+
queryAggregateMin: (q, f) => fn.hk_query_aggregate_min(q, f),
|
|
1418
|
+
queryAggregateMax: (q, f) => fn.hk_query_aggregate_max(q, f),
|
|
1419
|
+
queryExecuteAggregation: (e, q) => ptrToStringAndFree(fn.hk_query_execute_aggregation(e, q)),
|
|
1420
|
+
engineListCollections: (engine) => ptrToStringAndFree(fn.hk_engine_list_collections(engine)),
|
|
1421
|
+
netSyncerNew: (engine, name, roomKey) => fn.hk_net_syncer_new(engine, name, roomKey),
|
|
1422
|
+
netSyncerStart: (syncer, port) => fn.hk_net_syncer_start(syncer, port),
|
|
1423
|
+
netSyncerSetDiscovery: (syncer, mode) => fn.hk_net_syncer_set_discovery(syncer, mode),
|
|
1424
|
+
netSyncerStatus: (syncer) => ptrToStringAndFree(fn.hk_net_syncer_status(syncer)),
|
|
1425
|
+
netSyncerFree: (syncer) => fn.hk_net_syncer_free(syncer),
|
|
1426
|
+
|
|
1427
|
+
cloudSyncNew: (engine, mode, clientId, roomName, roomKey, authToken) => fn.hk_cloud_sync_new(engine, mode, clientId, roomName, roomKey, authToken),
|
|
1428
|
+
cloudSyncServerNew: (engine, serverId, authToken, roomName, roomKey) => fn.hk_cloud_sync_server_new(engine, serverId, authToken, roomName, roomKey),
|
|
1429
|
+
cloudSyncClientNew: (engine, clientId, roomName, roomKey, authToken) => fn.hk_cloud_sync_client_new(engine, clientId, roomName, roomKey, authToken),
|
|
1430
|
+
cloudSyncStart: (cs, address) => fn.hk_cloud_sync_start(cs, address),
|
|
1431
|
+
cloudSyncStatus: (cs) => ptrToStringAndFree(fn.hk_cloud_sync_status(cs)),
|
|
1432
|
+
cloudSyncStop: (cs) => fn.hk_cloud_sync_stop(cs),
|
|
1433
|
+
cloudSyncFree: (cs) => fn.hk_cloud_sync_free(cs),
|
|
1434
|
+
|
|
1435
|
+
// ================= v0.5.9 =================
|
|
1436
|
+
|
|
1437
|
+
// Indexing
|
|
1438
|
+
createFtsIndex: (engine, collection, field) => fn.hk_engine_create_fts_index(engine, collection, field),
|
|
1439
|
+
createSimpleIndex: (engine, collection, field) => fn.hk_engine_create_simple_index(engine, collection, field),
|
|
1440
|
+
createVectorIndex: (engine, collection, field, dim, metric) => fn.hk_engine_create_vector_index(engine, collection, field, dim, metric),
|
|
1441
|
+
// LE-f32 bytes via Buffer over the Float32Array (koffi takes Buffer
|
|
1442
|
+
// for float*, same as docInsertBin takes Buffer for uint8_t*).
|
|
1443
|
+
engineFindNear: (engine, collection, field, vec, k) => fn.hk_engine_find_near(engine, collection, field, Buffer.from(vec.buffer, vec.byteOffset, vec.byteLength), vec.length, k),
|
|
1444
|
+
createTraverseIndex: (engine, collection) => fn.hk_engine_create_traverse_index(engine, collection),
|
|
1445
|
+
// Null edge crosses as NULL (koffi takes null for char*).
|
|
1446
|
+
engineFindPaths: (engine, collection, id, direction, edge, maxDepth, k) => fn.hk_engine_find_paths(engine, collection, id, direction, edge, maxDepth, k),
|
|
1447
|
+
createEdgeIndex: (engine, collection) => fn.hk_engine_create_edge_index(engine, collection),
|
|
1448
|
+
engineShortestPaths: (engine, collection, id, direction, edge, via, weight, maxDepth, k) => fn.hk_engine_shortest_paths(engine, collection, id, direction, edge, via, weight, maxDepth, k),
|
|
1449
|
+
|
|
1450
|
+
// v0.19.6 parity (koffi takes null for char* directly)
|
|
1451
|
+
dropSimpleIndex: (engine, collection, field) => fn.hk_engine_drop_simple_index(engine, collection, field),
|
|
1452
|
+
dropVectorIndex: (engine, collection, field) => fn.hk_engine_drop_vector_index(engine, collection, field),
|
|
1453
|
+
dropCompositeIndex: (engine, collection, id) => fn.hk_engine_drop_composite_index(engine, collection, id),
|
|
1454
|
+
dropEdgeIndex: (engine, collection) => fn.hk_engine_drop_edge_index(engine, collection),
|
|
1455
|
+
dropFtsIndex: (engine, collection, field) => fn.hk_engine_drop_fts_index(engine, collection, field),
|
|
1456
|
+
dropTraverseIndex: (engine, collection) => fn.hk_engine_drop_traverse_index(engine, collection),
|
|
1457
|
+
createVectorIndexV2: (engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1) => fn.hk_engine_create_vector_index_v2(engine, collection, field, dim, metric, m, efConstruction, efSearch, binaryStage1),
|
|
1458
|
+
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),
|
|
1459
|
+
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),
|
|
1460
|
+
exportGraph: (engine, collection, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_export_graph(engine, collection, direction, edge, via, nodeField, nodeJSON),
|
|
1461
|
+
graphAnalysis: (engine, collection, op, direction, edge, via, nodeField, nodeJSON) => fn.hk_engine_graph_analysis(engine, collection, op, direction, edge, via, nodeField, nodeJSON),
|
|
1462
|
+
graphPagerank: (engine, collection, seeds, direction, edge, via, nodeField, nodeJSON, damping, top) => fn.hk_engine_graph_pagerank(engine, collection, seeds, direction, edge, via, nodeField, nodeJSON, damping, top),
|
|
1463
|
+
subgraph: (engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap) => fn.hk_engine_subgraph(engine, collection, seedId, maxDepth, direction, edge, via, nodeField, nodeJSON, nodeCap),
|
|
1464
|
+
hybridSearch: (engine, collection, textField, textQuery, vecField, vec, k, rrfK) => fn.hk_engine_hybrid_search(engine, collection, textField, textQuery, vecField, vec, k, rrfK),
|
|
1465
|
+
insertJSON: (engine, collection, id, json) => fn.hk_engine_insert_json(engine, collection, id, json),
|
|
1466
|
+
batchSetJSON: (batch, collection, id, json) => fn.hk_batch_set_json(batch, collection, id, json),
|
|
1467
|
+
|
|
1468
|
+
// Array API
|
|
1469
|
+
arrayNew: () => fn.hk_array_new(),
|
|
1470
|
+
arrayFree: (arr) => fn.hk_array_free(arr),
|
|
1471
|
+
arrayAppendStr: (arr, value) => fn.hk_array_append_str(arr, value),
|
|
1472
|
+
arrayAppendInt: (arr, value) => fn.hk_array_append_int(arr, value),
|
|
1473
|
+
arrayAppendDoc: (arr, doc) => fn.hk_array_append_doc(arr, doc),
|
|
1474
|
+
|
|
1475
|
+
// Nested
|
|
1476
|
+
docInsertDoc: (parent, key, child) => fn.hk_doc_insert_doc(parent, key, child),
|
|
1477
|
+
docInsertArray: (parent, key, arr) => fn.hk_doc_insert_array(parent, key, arr),
|
|
1478
|
+
|
|
1479
|
+
// Query extensions
|
|
1480
|
+
queryWhereIn: (query, field, arr) => fn.hk_query_where_in(query, field, arr),
|
|
1481
|
+
queryWhereNotIn: (query, field, arr) => fn.hk_query_where_not_in(query, field, arr),
|
|
1482
|
+
queryWhereArrayContainsAny: (query, field, arr) => fn.hk_query_where_array_contains_any(query, field, arr),
|
|
1483
|
+
queryWhereArrayContainsStr: (query, field, value) => fn.hk_query_where_array_contains(query, field, String(value)),
|
|
1484
|
+
queryWhereArrayContainsInt: (query, field, value) => fn.hk_query_where_array_contains(query, field, String(value)),
|
|
1485
|
+
queryStartAfter: (query, anchorDoc) => fn.hk_query_start_after(query, anchorDoc),
|
|
1486
|
+
queryStartAt: (query, anchorDoc) => fn.hk_query_start_at(query, anchorDoc),
|
|
1487
|
+
queryEndAt: (query, anchorDoc) => fn.hk_query_end_at(query, anchorDoc),
|
|
1488
|
+
queryEndBefore: (query, anchorDoc) => fn.hk_query_end_before(query, anchorDoc),
|
|
1489
|
+
|
|
1490
|
+
// 0.16.5 parity.
|
|
1491
|
+
engineSetSchema: (e, c, json) => fn.hk_engine_set_schema(e, c, json),
|
|
1492
|
+
engineGetSchema: (e, c) => ptrToStringAndFree(fn.hk_engine_get_schema(e, c)),
|
|
1493
|
+
engineClearSchema: (e, c) => fn.hk_engine_clear_schema(e, c),
|
|
1494
|
+
engineListSchemas: (e) => ptrToStringAndFree(fn.hk_engine_list_schemas(e)),
|
|
1495
|
+
engineGetVersioned: (e, c, id) => {
|
|
1496
|
+
const out: bigint[] = [0n];
|
|
1497
|
+
const doc = fn.hk_engine_get_versioned(e, c, id, out);
|
|
1498
|
+
return { doc, version: out[0] };
|
|
1499
|
+
},
|
|
1500
|
+
engineAwaitQuiescent: (e, ms) => fn.hk_engine_await_quiescent(e, ms),
|
|
1501
|
+
engineQuiescenceStatus: (e) => ptrToStringAndFree(fn.hk_engine_quiescence_status(e)),
|
|
1502
|
+
transactionGetMany: (e, tx, c, idsJson) => ptrToStringAndFree(fn.hk_transaction_get_many(e, tx, c, idsJson)),
|
|
1503
|
+
transactionPatch: (e, tx, c, id, updatesJson) => fn.hk_transaction_patch(e, tx, c, id, updatesJson),
|
|
1504
|
+
errorLastKind: () => fn.hk_error_last_kind(),
|
|
1505
|
+
errorIsRetryable: () => fn.hk_error_is_retryable(),
|
|
1506
|
+
debugWriteStats: () => ptrToStringAndFree(fn.hk_debug_write_stats()),
|
|
1507
|
+
logEnableStderr: () => fn.hk_log_enable_stderr(),
|
|
1508
|
+
logDisableStderr: () => fn.hk_log_disable_stderr(),
|
|
1509
|
+
queryExplain: (e, q) => ptrToStringAndFree(fn.hk_query_explain(e, q)),
|
|
1510
|
+
queryWhereArrayAllEq: (q, f, json) => fn.hk_query_where_array_all_eq(q, f, json),
|
|
1511
|
+
queryWhereElemMatch: (q, f, json) => fn.hk_query_where_elem_match(q, f, json),
|
|
1512
|
+
queryWhereNear: (q, f, vec) => fn.hk_query_where_near(q, f, Buffer.from(vec.buffer, vec.byteOffset, vec.byteLength), vec.length),
|
|
1513
|
+
queryWhereTraverse: (q, sc, sid, dir, edge, depth) => fn.hk_query_where_traverse(q, sc, sid, dir, edge, depth),
|
|
1514
|
+
pipelineNew: (c) => fn.hk_pipeline_new(c),
|
|
1515
|
+
pipelineFree: (p) => fn.hk_pipeline_free(p),
|
|
1516
|
+
pipelineMatch: (p, q) => fn.hk_pipeline_match(p, q),
|
|
1517
|
+
pipelineProject: (p, json) => fn.hk_pipeline_project(p, json),
|
|
1518
|
+
pipelineSort: (p, f, asc) => fn.hk_pipeline_sort(p, f, asc),
|
|
1519
|
+
pipelineLimit: (p, n) => fn.hk_pipeline_limit(p, n),
|
|
1520
|
+
pipelineOffset: (p, n) => fn.hk_pipeline_offset(p, n),
|
|
1521
|
+
pipelineUnwind: (p, f) => fn.hk_pipeline_unwind(p, f),
|
|
1522
|
+
pipelineGroup: (p, k, json) => fn.hk_pipeline_group(p, k, json),
|
|
1523
|
+
pipelineExecute: (e, p) => ptrToStringAndFree(fn.hk_pipeline_execute(e, p)),
|
|
1524
|
+
pipelineExecuteToHandles: (e, p) => fn.hk_pipeline_execute_to_handles(e, p),
|
|
1525
|
+
configSetGroupCommitIntervalMs: (c, ms) => fn.hk_config_set_group_commit_interval_ms(c, ms),
|
|
1526
|
+
configSetPageCacheCapacity: (c, n) => fn.hk_config_set_page_cache_capacity(c, n),
|
|
1527
|
+
configSetSyncExcluded: (c, json) => fn.hk_config_set_sync_excluded(c, json),
|
|
1528
|
+
configSetLazyCollections: (c, json) => fn.hk_config_set_lazy_collections(c, json),
|
|
1529
|
+
configSetReplicationCollections: (c, json) => fn.hk_config_set_replication_collections(c, json),
|
|
1530
|
+
cursorWalk: (e, q, callback) => {
|
|
1531
|
+
const wrapper = (id: any, idLen: number, bytes: any, bytesLen: number) => {
|
|
1532
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1533
|
+
const rowBytes = Uint8Array.from(koffi.decode(bytes, 'uint8_t', Number(bytesLen)));
|
|
1534
|
+
return callback(rowId, rowBytes);
|
|
1535
|
+
};
|
|
1536
|
+
return Number(fn.hk_cursor_walk(e, q, koffi.register(wrapper, 'HkWalkCallback *'), null));
|
|
1537
|
+
},
|
|
1538
|
+
cursorWalkView: (e, q, callback) => {
|
|
1539
|
+
const wrapper = (id: any, idLen: number, view: any) => {
|
|
1540
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1541
|
+
return callback(rowId, view);
|
|
1542
|
+
};
|
|
1543
|
+
return Number(fn.hk_cursor_walk_view(e, q, koffi.register(wrapper, 'HkViewWalkCallback *'), null));
|
|
1544
|
+
},
|
|
1545
|
+
rawDocBytes: (raw) => {
|
|
1546
|
+
const len: number[] = [0];
|
|
1547
|
+
const ptr = fn.hk_rawdoc_bytes(raw, len);
|
|
1548
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1549
|
+
},
|
|
1550
|
+
rawDocId: (raw) => {
|
|
1551
|
+
const len: number[] = [0];
|
|
1552
|
+
const ptr = fn.hk_rawdoc_id(raw, len);
|
|
1553
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1554
|
+
},
|
|
1555
|
+
viewGetStr: (view, key) => {
|
|
1556
|
+
const len: number[] = [0];
|
|
1557
|
+
const ptr = fn.hk_view_get_str(view, key, len);
|
|
1558
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1559
|
+
},
|
|
1560
|
+
viewGetBytes: (view, key) => {
|
|
1561
|
+
const len: number[] = [0];
|
|
1562
|
+
const ptr = fn.hk_view_get_bytes(view, key, len);
|
|
1563
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1564
|
+
},
|
|
1565
|
+
|
|
1566
|
+
// P2 (core 0.18): JSON read paths + dotted-path pulls.
|
|
1567
|
+
engineGetJson: (e, c, id) => ptrToStringAndFree(fn.hk_engine_get_json(e, c, id)),
|
|
1568
|
+
queryExecuteJson: (e, q) => ptrToStringAndFree(fn.hk_query_execute_json(e, q)),
|
|
1569
|
+
viewToJson: (view) => ptrToStringAndFree(fn.hk_view_to_json(view)),
|
|
1570
|
+
cursorWalkJson: (e, q, callback) => {
|
|
1571
|
+
const wrapper = (id: any, idLen: number, json: any, jsonLen: number) => {
|
|
1572
|
+
const rowId = new TextDecoder().decode(Uint8Array.from(koffi.decode(id, 'uint8_t', Number(idLen))));
|
|
1573
|
+
const rowJson = Uint8Array.from(koffi.decode(json, 'uint8_t', Number(jsonLen)));
|
|
1574
|
+
return callback(rowId, rowJson);
|
|
1575
|
+
};
|
|
1576
|
+
return Number(fn.hk_cursor_walk_json(e, q, koffi.register(wrapper, 'HkWalkCallback *'), null));
|
|
1577
|
+
},
|
|
1578
|
+
viewGetPathInt: (view, path) => {
|
|
1579
|
+
const out: bigint[] = [0n];
|
|
1580
|
+
return fn.hk_view_get_path_int(view, path, out) ? out[0] : null;
|
|
1581
|
+
},
|
|
1582
|
+
viewGetPathFloat: (view, path) => {
|
|
1583
|
+
const out: number[] = [0];
|
|
1584
|
+
return fn.hk_view_get_path_float(view, path, out) ? out[0] : null;
|
|
1585
|
+
},
|
|
1586
|
+
viewGetPathBool: (view, path) => {
|
|
1587
|
+
const r: number = fn.hk_view_get_path_bool(view, path);
|
|
1588
|
+
return r < 0 ? null : r !== 0;
|
|
1589
|
+
},
|
|
1590
|
+
viewGetPathStr: (view, path) => {
|
|
1591
|
+
const len: number[] = [0];
|
|
1592
|
+
const ptr = fn.hk_view_get_path_str(view, path, len);
|
|
1593
|
+
return ptr ? new TextDecoder().decode(Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0])))) : null;
|
|
1594
|
+
},
|
|
1595
|
+
viewGetPathBytes: (view, path) => {
|
|
1596
|
+
const len: number[] = [0];
|
|
1597
|
+
const ptr = fn.hk_view_get_path_bytes(view, path, len);
|
|
1598
|
+
return ptr ? Uint8Array.from(koffi.decode(ptr, 'uint8_t', Number(len[0]))) : null;
|
|
1599
|
+
},
|
|
1600
|
+
|
|
1601
|
+
lastError: () => (fn.hk_last_error() as string) || 'unknown ffi error'
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
export async function loadNativeBindings(explicitPath?: string): Promise<NativeBindings> {
|
|
1606
|
+
const libPath = resolveLibraryPath(explicitPath);
|
|
1607
|
+
// return isBunRuntime() ? createBunBindings(libPath) : createNodeBindings(libPath);
|
|
1608
|
+
|
|
1609
|
+
// 1. Check for Bun
|
|
1610
|
+
if (typeof (globalThis as any).Bun !== 'undefined') {
|
|
1611
|
+
return createBunBindings(libPath);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// 2. Check for Node.js (via process)
|
|
1615
|
+
if (typeof process !== 'undefined' && process.versions && process.versions.node) {
|
|
1616
|
+
return createNodeBindings(libPath);
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
throw new Error("HakoDB Native Bindings are only supported in Node.js or Bun environments. For browsers, use the Tauri Gateway.");
|
|
1620
|
+
}
|