@antfly/embedded 0.0.0 → 0.3.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,558 @@
1
+ import { LibraryHandle, KoffiFunc } from 'koffi';
2
+
3
+ /** Where a resolved libantfly path came from, for diagnostics/logging. */
4
+ type LibrarySource = "ANTFLY_LIBRARY" | "ANTFLY_LIB_DIR" | "embedded-package" | "source-tree" | "system";
5
+ interface ResolvedLibrary {
6
+ /** Absolute path to the shared library, or a bare loader name for "system". */
7
+ path: string;
8
+ source: LibrarySource;
9
+ }
10
+ declare class LibraryNotFoundError extends Error {
11
+ constructor(message: string);
12
+ }
13
+ declare class UnsupportedPlatformError extends Error {
14
+ constructor(platform: string);
15
+ }
16
+ /** The libantfly shared library file name for a platform, e.g. "libantfly.dylib". */
17
+ declare function platformLibraryFileName(platform: NodeJS.Platform): string | undefined;
18
+ /** The Apache @antfly/embedded-<platform> package that ships libantfly. */
19
+ declare function embeddedPlatformPackageName(platform: NodeJS.Platform, arch: string): string | undefined;
20
+ interface ResolveLibraryOptions {
21
+ platform?: NodeJS.Platform;
22
+ arch?: string;
23
+ env?: NodeJS.ProcessEnv;
24
+ /** Directory to walk up from when looking for zig/zig-out/lib (a source checkout). Defaults to this package's own directory. */
25
+ startDir?: string;
26
+ existsSync?: (path: string) => boolean;
27
+ /** Like require.resolve; used to locate an installed @antfly/embedded-<platform> package. */
28
+ resolve?: (specifier: string) => string;
29
+ }
30
+ /**
31
+ * Resolves the libantfly shared library to load, in order:
32
+ *
33
+ * 1. `ANTFLY_LIBRARY` env var: an exact file path.
34
+ * 2. `ANTFLY_LIB_DIR` env var: a directory containing the platform library file.
35
+ * 3. The installed `@antfly/embedded-<platform>` package's `lib/` directory.
36
+ * 4. `zig/zig-out/lib/` found by walking up from this package (a source checkout).
37
+ * 5. The bare system loader name, resolved by the OS's shared library search
38
+ * path (LD_LIBRARY_PATH / DYLD_LIBRARY_PATH / PATH / rpath).
39
+ *
40
+ * Throws LibraryNotFoundError if an explicit env var names a path that does
41
+ * not exist, so misconfiguration fails loudly instead of silently falling
42
+ * through to another tier.
43
+ */
44
+ declare function resolveLibrary(options?: ResolveLibraryOptions): ResolvedLibrary;
45
+
46
+ /** How a database is opened (antfly_open_mode_* in antfly.h). */
47
+ declare enum OpenMode {
48
+ Writer = 0,
49
+ Readonly = 1,
50
+ StatusOnly = 2
51
+ }
52
+ /**
53
+ * How a database is stored (antfly_storage_kind_* in antfly.h). The zero
54
+ * value, Lite, is a single-file .aflite database.
55
+ */
56
+ declare enum Storage {
57
+ /** A single-file .aflite database. */
58
+ Lite = 0,
59
+ /** A normal single-node Antfly directory. */
60
+ Directory = 1
61
+ }
62
+ /** The Lite runtime profile (antfly_profile_* in antfly.h). */
63
+ declare enum Profile {
64
+ Native = 0,
65
+ Hosted = 1
66
+ }
67
+ /** Graph edge traversal direction (antfly_graph_direction_* in antfly.h). */
68
+ declare enum GraphDirection {
69
+ Out = 0,
70
+ In = 1,
71
+ Both = 2
72
+ }
73
+ /** Transaction intent lifecycle state (antfly_txn_status in antfly.h). */
74
+ declare enum TxnStatus {
75
+ Pending = 0,
76
+ Committed = 1,
77
+ Aborted = 2
78
+ }
79
+ /** Inference mode strings returned by Lite status and capabilities JSON. */
80
+ declare const InferenceMode: {
81
+ readonly CallerSuppliedOrDisabled: "caller_supplied_or_disabled";
82
+ readonly CallerSuppliedArtifacts: "caller_supplied_artifacts";
83
+ readonly RemoteProvider: "remote_provider";
84
+ readonly LocalEmbedded: "local_embedded";
85
+ readonly ManualMaintenance: "manual_maintenance";
86
+ readonly DisabledDeferred: "disabled_deferred";
87
+ };
88
+ /** The only libantfly threading contract (antfly_threading_mode() return value), like sqlite3_threadsafe(). */
89
+ declare const THREADING_SERIALIZED = 1;
90
+ /** The Antfly C ABI version this binding was written against (antfly_abi_version()). */
91
+ declare const SUPPORTED_ABI_VERSION = 3;
92
+ /** Configures TTL cleanup for a native-profile Lite handle. */
93
+ interface TTLCleanupOptions {
94
+ enabled: boolean;
95
+ leaseOwned: boolean;
96
+ ownerId?: string;
97
+ leaseTtlMs?: Uint64Like;
98
+ intervalMs?: Uint64Like;
99
+ batchSize?: number;
100
+ gracePeriodNs?: Uint64Like;
101
+ }
102
+ /**
103
+ * Configures open/create. See antfly_open_options in antfly.h and
104
+ * zig/LITE.md's "Local Embedded Inference" section for the inference budget
105
+ * fields. All fields are optional; unset numeric budgets mean "automatic".
106
+ */
107
+ interface OpenOptions {
108
+ /** Selects a .aflite file (the default) or a directory. Directory storage is created by opening a missing path; createWithOptions only creates .aflite files. */
109
+ storage?: Storage;
110
+ mode?: OpenMode;
111
+ profile?: Profile;
112
+ noSync?: boolean;
113
+ remoteProviderConfigured?: boolean;
114
+ localRuntimeConfigured?: boolean;
115
+ generatedEnrichmentReplay?: boolean;
116
+ mapSize?: Uint64Like;
117
+ ttlCleanup?: TTLCleanupOptions;
118
+ /** Milliseconds to retry while another writer holds the writer lock (ANTFLY_BUSY), like sqlite3_busy_timeout. 0 (default) fails immediately. */
119
+ busyTimeoutMs?: Uint64Like;
120
+ inferenceHostBudgetMb?: number;
121
+ inferenceBackendBudgetMb?: number;
122
+ inferenceCombinedBudgetMb?: number;
123
+ inferenceKvBudgetMb?: number;
124
+ inferenceScratchBudgetMb?: number;
125
+ inferenceProcessMemoryBudgetMb?: number;
126
+ }
127
+ /** A single key/value write or delete in a batch. */
128
+ interface WriteIntent {
129
+ key: string;
130
+ value?: Uint8Array | Record<string, unknown>;
131
+ delete?: boolean;
132
+ }
133
+ /** Configures restore() and restoreFile(). */
134
+ interface RestoreOptions {
135
+ /** Selects the kind of database created at the destination: a .aflite file (the default) or a directory. */
136
+ storage?: Storage;
137
+ /** Atomically replaces an existing destination. */
138
+ replace?: boolean;
139
+ }
140
+ interface StorageStatus {
141
+ format: string;
142
+ engine: string;
143
+ primary_layout: string;
144
+ replay_layout: string;
145
+ index_layout: string;
146
+ index_namespace?: string;
147
+ format_version?: number;
148
+ page_size?: number;
149
+ active_checkpoint?: number;
150
+ checkpoint_sequence?: number;
151
+ page_count?: number;
152
+ }
153
+ /** Historical snapshot of the local runtime's last denied memory admission. */
154
+ interface MemoryAdmissionStats {
155
+ pressure: string;
156
+ denied_count: number;
157
+ last_denied_ns: number;
158
+ request_count: number;
159
+ requested_host_bytes: number;
160
+ requested_backend_bytes: number;
161
+ requested_kv_bytes: number;
162
+ requested_scratch_bytes: number;
163
+ admitted_host_bytes: number;
164
+ admitted_backend_bytes: number;
165
+ host_limit_bytes: number;
166
+ backend_limit_bytes: number;
167
+ combined_limit_bytes: number;
168
+ available_memory_bytes: number;
169
+ }
170
+ interface InferenceStatus {
171
+ mode: string;
172
+ available_modes: string[];
173
+ configured: boolean;
174
+ remote_provider_configured: boolean;
175
+ local_runtime_configured: boolean;
176
+ local_runtime_available: boolean;
177
+ caller_supplied_artifacts: boolean;
178
+ no_inference_configured_ok: boolean;
179
+ host_budget_mb: number;
180
+ backend_budget_mb: number;
181
+ combined_budget_mb: number;
182
+ kv_budget_mb: number;
183
+ scratch_budget_mb: number;
184
+ process_memory_budget_mb: number;
185
+ process_memory_limit_bytes: number;
186
+ process_memory_limit_source: string;
187
+ memory_admission?: MemoryAdmissionStats;
188
+ }
189
+ interface Capabilities {
190
+ freestanding_build: boolean;
191
+ /** Always "serialized" for the current libantfly (see THREADING_SERIALIZED). */
192
+ threading: string;
193
+ hosted_profile: boolean;
194
+ manual_maintenance: boolean;
195
+ background_enrichment_runtime: boolean;
196
+ ttl_cleanup_runtime: boolean;
197
+ transaction_recovery_runtime: boolean;
198
+ local_template_rendering: boolean;
199
+ remote_template_rendering: boolean;
200
+ remote_template_host_callbacks: boolean;
201
+ inference_mode: string;
202
+ supported_inference_modes: string[];
203
+ available_inference_modes: string[];
204
+ inference_required: boolean;
205
+ no_inference_configured_ok: boolean;
206
+ caller_supplied_artifacts: boolean;
207
+ caller_supplied_embeddings: boolean;
208
+ remote_inference_providers: boolean;
209
+ local_inference_runtime: boolean;
210
+ generated_enrichment_planning: boolean;
211
+ text_search: boolean;
212
+ dense_vector_search: boolean;
213
+ sparse_vector_search: boolean;
214
+ hybrid_search: boolean;
215
+ graph_search: boolean;
216
+ distributed_shard_ownership: boolean;
217
+ raft_replication: boolean;
218
+ cluster_placement: boolean;
219
+ cross_node_joins: boolean;
220
+ remote_shard_fanout: boolean;
221
+ distributed_transaction_coordination: boolean;
222
+ cluster_heartbeat_status_aggregation: boolean;
223
+ server_side_autoscaling: boolean;
224
+ kubernetes_operator: boolean;
225
+ object_storage_primary: boolean;
226
+ }
227
+ interface PendingWorkStatus {
228
+ derived_target_sequence: number;
229
+ has_async_indexes: boolean;
230
+ portable_import_publication_in_progress: boolean;
231
+ portable_import_recovery_required: boolean;
232
+ portable_runtime_activation_pending: boolean;
233
+ enrichment: unknown;
234
+ resolution: unknown;
235
+ promotion: unknown;
236
+ text_merge: unknown;
237
+ replacements?: unknown[];
238
+ }
239
+ interface Status {
240
+ storage: StorageStatus;
241
+ stats: unknown;
242
+ pending_work: PendingWorkStatus;
243
+ inference: InferenceStatus;
244
+ capabilities: Capabilities;
245
+ }
246
+ interface ReplayGeneratedEnrichmentsResult {
247
+ replayed: number;
248
+ }
249
+ interface CheckReport {
250
+ valid: boolean;
251
+ file_size: number;
252
+ valid_prefix_size: number;
253
+ tail_bytes: number;
254
+ record_count: number;
255
+ live_file_count: number;
256
+ live_bytes: number;
257
+ compact_size: number;
258
+ reclaimable_bytes: number;
259
+ issue?: string;
260
+ }
261
+ interface VacuumReport {
262
+ before_size: number;
263
+ after_size: number;
264
+ reclaimed_bytes: number;
265
+ live_file_count: number;
266
+ live_bytes: number;
267
+ }
268
+ interface CompactReport {
269
+ compacted: boolean;
270
+ vacuum: VacuumReport;
271
+ }
272
+ interface StableSnapshotReport {
273
+ source_size: number;
274
+ snapshot_size: number;
275
+ checkpoint_sequence: number;
276
+ page_count: number;
277
+ tail_bytes: number;
278
+ }
279
+ /**
280
+ * Configures Inference.open(). See antfly_inference_options in antfly.h.
281
+ * All fields are optional; unset numeric budgets mean "automatic".
282
+ */
283
+ interface InferenceOptions {
284
+ /** Models directory. Empty (default) uses $ANTFLY_INFERENCE_MODELS_DIR, else ~/.antfly/inference/models. */
285
+ modelsDir?: string;
286
+ hostBudgetMb?: number;
287
+ backendBudgetMb?: number;
288
+ processMemoryBudgetMb?: number;
289
+ combinedBudgetMb?: number;
290
+ kvBudgetMb?: number;
291
+ scratchBudgetMb?: number;
292
+ /** Deadline for each call in milliseconds; 0 (default) means none. */
293
+ callTimeoutMs?: Uint64Like;
294
+ }
295
+ /** One progress report from Inference.pull(), mirroring antfly_inference_pull_progress. */
296
+ interface PullProgress {
297
+ /** The model reference being pulled (one report series per requested variant). */
298
+ model: string;
299
+ file: string;
300
+ bytesDownloaded: bigint;
301
+ /** 0n when unknown. */
302
+ totalBytes: bigint;
303
+ filesDone: bigint;
304
+ filesTotal: bigint;
305
+ /** The file was already present and verified; nothing was downloaded. */
306
+ cached: boolean;
307
+ }
308
+
309
+ interface NativeLibrary {
310
+ handle: LibraryHandle;
311
+ resolved: ResolvedLibrary;
312
+ abiVersion: KoffiFunc<() => number>;
313
+ threadingMode: KoffiFunc<() => number>;
314
+ openOptionsSize: KoffiFunc<() => number>;
315
+ errorCodeName: KoffiFunc<(code: number) => string>;
316
+ errorCodeDescription: KoffiFunc<(code: number) => string>;
317
+ openOptionsInit: KoffiFunc<(options: object) => number>;
318
+ dbOpenWithOptions: KoffiFunc<(path: string, options: object, outHandle: unknown[]) => number>;
319
+ dbCreateWithOptions: KoffiFunc<(path: string, options: object, outHandle: unknown[]) => number>;
320
+ liteOpenHosted: KoffiFunc<(path: string, outHandle: unknown[]) => number>;
321
+ liteCreateHosted: KoffiFunc<(path: string, outHandle: unknown[]) => number>;
322
+ dbClose: KoffiFunc<(handle: unknown) => void>;
323
+ bufferFree: KoffiFunc<(buffer: object) => void>;
324
+ dbSqlJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
325
+ dbOpenTable: KoffiFunc<(handle: unknown, name: object, out: unknown[]) => number>;
326
+ dbCreateTableJson: KoffiFunc<(handle: unknown, name: object, schema: object) => number>;
327
+ dbDropTable: KoffiFunc<(handle: unknown, name: object) => number>;
328
+ dbListTablesJson: KoffiFunc<(handle: unknown, out: object) => number>;
329
+ dbSqlSessionOpen: KoffiFunc<(handle: unknown, out: unknown[]) => number>;
330
+ dbSqlSessionClose: KoffiFunc<(handle: unknown, session: number | bigint) => number>;
331
+ dbSqlOpenCursorJson: KoffiFunc<(handle: unknown, request: object, cursor: unknown[], out: object) => number>;
332
+ dbSqlFetchCursorJson: KoffiFunc<(handle: unknown, cursor: number | bigint, rows: number, out: object) => number>;
333
+ dbSqlCloseCursor: KoffiFunc<(handle: unknown, cursor: number | bigint) => number>;
334
+ dbStatusJson: KoffiFunc<(handle: unknown, out: object) => number>;
335
+ dbCapabilitiesJson: KoffiFunc<(handle: unknown, out: object) => number>;
336
+ dbBackup: KoffiFunc<(handle: unknown, out: object) => number>;
337
+ dbImportBackup: KoffiFunc<(handle: unknown, backup: object) => number>;
338
+ restoreBackupJson: KoffiFunc<(destPath: string, options: object | null, backup: object, replace: boolean, out: object) => number>;
339
+ restoreBackupFileJson: KoffiFunc<(destPath: string, options: object | null, backupPath: string, replace: boolean, out: object) => number>;
340
+ liteCheckJson: KoffiFunc<(handle: unknown, out: object) => number>;
341
+ liteCheckFileJson: KoffiFunc<(path: string, out: object) => number>;
342
+ liteCopyStableSnapshotJson: KoffiFunc<(handle: unknown, destPath: string, replace: boolean, out: object) => number>;
343
+ liteCopyStableSnapshotFileJson: KoffiFunc<(srcPath: string, destPath: string, replace: boolean, out: object) => number>;
344
+ liteCompactJson: KoffiFunc<(handle: unknown, out: object) => number>;
345
+ liteVacuumJson: KoffiFunc<(handle: unknown, out: object) => number>;
346
+ dbRunUntilIdle: KoffiFunc<(handle: unknown) => number>;
347
+ dbRunUntilIdleJson: KoffiFunc<(handle: unknown, out: object) => number>;
348
+ dbReplayGeneratedEnrichmentsJson: KoffiFunc<(handle: unknown, out: object) => number>;
349
+ dbPendingWorkStatsJson: KoffiFunc<(handle: unknown, out: object) => number>;
350
+ dbBatch: KoffiFunc<(handle: unknown, writes: object[] | null, writeCount: number, predicates: object[] | null, predicateCount: number, timestampNs: number | bigint, syncLevel: number) => number>;
351
+ dbBatchJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
352
+ dbBeginTransactionWithId: KoffiFunc<(handle: unknown, txnId: Uint8Array, timestampNs: number | bigint, participants: object[] | null, participantCount: number) => number>;
353
+ dbWriteTransaction: KoffiFunc<(handle: unknown, txnId: Uint8Array, writes: object[] | null, writeCount: number, predicates: object[] | null, predicateCount: number) => number>;
354
+ dbResolveIntents: KoffiFunc<(handle: unknown, txnId: Uint8Array, status: number, commitVersion: number | bigint) => number>;
355
+ dbGetTransactionStatus: KoffiFunc<(handle: unknown, txnId: Uint8Array, outStatus: number[]) => number>;
356
+ dbGetCommitVersion: KoffiFunc<(handle: unknown, txnId: Uint8Array, outVersion: (number | bigint)[]) => number>;
357
+ dbLookupJson: KoffiFunc<(handle: unknown, key: object, out: object) => number>;
358
+ dbGetRaw: KoffiFunc<(handle: unknown, key: object, out: object) => number>;
359
+ dbGetSchemaJson: KoffiFunc<(handle: unknown, out: object) => number>;
360
+ dbSetSchemaJson: KoffiFunc<(handle: unknown, schema: object) => number>;
361
+ dbListIndexesJson: KoffiFunc<(handle: unknown, out: object) => number>;
362
+ dbAddIndexJson: KoffiFunc<(handle: unknown, config: object) => number>;
363
+ dbDeleteIndex: KoffiFunc<(handle: unknown, name: object, outDeleted: boolean[]) => number>;
364
+ dbListEnrichmentsJson: KoffiFunc<(handle: unknown, out: object) => number>;
365
+ dbAddEnrichmentJson: KoffiFunc<(handle: unknown, config: object) => number>;
366
+ dbDeleteEnrichment: KoffiFunc<(handle: unknown, kind: object, name: object, outDeleted: boolean[]) => number>;
367
+ dbScanJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
368
+ dbStatsJson: KoffiFunc<(handle: unknown, out: object) => number>;
369
+ dbSearchJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
370
+ dbSearchDenseWire: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
371
+ dbSearchTextMatchWire: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
372
+ dbSearchTextTermWire: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
373
+ dbSearchTextMatchPhraseWire: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
374
+ dbAggregateHitsJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
375
+ dbLookupArtifactJson: KoffiFunc<(handle: unknown, artifactIdBase64: object, out: object) => number>;
376
+ decodeArtifactIdJson: KoffiFunc<(artifactIdBase64: object, out: object) => number>;
377
+ dbExtractEnrichmentsJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
378
+ dbComputeEnrichmentsJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
379
+ dbGetEdgesJson: KoffiFunc<(handle: unknown, indexName: object, key: object, edgeType: object, direction: number, out: object) => number>;
380
+ dbTraverseEdgesJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
381
+ dbExecuteGraphQueriesJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
382
+ dbGetNeighborsJson: KoffiFunc<(handle: unknown, indexName: object, key: object, edgeType: object, direction: number, out: object) => number>;
383
+ dbFindShortestPathJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
384
+ dbFindKShortestPathsJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
385
+ dbMatchPatternJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
386
+ inferenceOptionsSize: KoffiFunc<() => number>;
387
+ inferenceOptionsInit: KoffiFunc<(options: object) => number>;
388
+ inferenceOpen: KoffiFunc<(options: object | null, outHandle: unknown[]) => number>;
389
+ inferenceClose: KoffiFunc<(handle: unknown) => void>;
390
+ inferenceEmbedJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
391
+ inferenceRerankJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
392
+ inferenceChunkJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
393
+ inferenceGenerateJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
394
+ inferenceGenerateStreamJson: KoffiFunc<(handle: unknown, request: object, onChunk: unknown, chunkContext: unknown, out: object) => number>;
395
+ inferenceGenerateBatchJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
396
+ inferenceRewriteJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
397
+ inferenceDecideJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
398
+ inferenceExtractJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
399
+ inferenceReadJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
400
+ inferenceTranscribeJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
401
+ inferenceListModelsJson: KoffiFunc<(handle: unknown, out: object) => number>;
402
+ inferencePullJson: KoffiFunc<(handle: unknown, request: object, progress: unknown, progressContext: unknown, out: object) => number>;
403
+ }
404
+ /**
405
+ * Native stack for every libantfly call. koffi runs foreign calls on its own
406
+ * stacks (128 KiB for async calls by default), but libantfly needs the
407
+ * minimum documented in zig/CAPI.md "Thread Safety" (ANTFLY_MIN_THREAD_STACK_SIZE
408
+ * in antfly.h): 8 MiB. Smaller stacks crash inside the storage engine.
409
+ */
410
+ declare const NATIVE_STACK_SIZE: number;
411
+
412
+ /** Accepted shapes for a uint64_t argument: plain number (safe up to 2^53) or bigint. */
413
+ type Uint64Like = number | bigint;
414
+ /** Accepted shapes for a JSON request body: an object (JSON.stringify'd), a raw JSON string, or raw bytes. */
415
+ type JsonInput = Record<string, unknown> | unknown[] | string | Uint8Array;
416
+
417
+ /**
418
+ * An embedded Antfly database handle.
419
+ *
420
+ * A Database is safe for concurrent use from any number of in-flight
421
+ * promises: libantfly runs in serialized threading mode (see
422
+ * threadingMode()) -- reads run in parallel, writes on one handle queue
423
+ * behind each other, and schema/index changes wait for in-flight calls (see
424
+ * zig/CAPI.md "Thread Safety"). All handle operations are async and run on
425
+ * koffi's worker thread pool so they never block the event loop; see the
426
+ * package README for a note on koffi's threadpool size.
427
+ *
428
+ * close() waits for every call this binding has dispatched (queued or
429
+ * in-flight) to finish before freeing the native handle, and rejects new
430
+ * calls immediately once close() has started. Node's own async FFI queueing
431
+ * means a call can be queued but not yet "entered" the C library when
432
+ * close() runs; libantfly's own close only drains calls that already entered
433
+ * it, so this extra bookkeeping is required to avoid a use-after-free.
434
+ */
435
+ declare class Database implements AsyncDisposable {
436
+ #private;
437
+ readonly owner?: Database | undefined;
438
+ /** @internal use open()/create()/openHosted()/etc. instead of the constructor. */
439
+ constructor(native: NativeLibrary, handle: unknown, owner?: Database | undefined);
440
+ sqlJson(request: JsonInput): Promise<unknown>;
441
+ createTable(name: string, schema: JsonInput): Promise<void>;
442
+ dropTable(name: string): Promise<void>;
443
+ listTables(): Promise<string[]>;
444
+ openSqlSession(): Promise<Uint64Like>;
445
+ closeSqlSession(id: Uint64Like): Promise<void>;
446
+ openSqlCursor(request: JsonInput): Promise<Uint64Like>;
447
+ fetchSqlCursor(id: Uint64Like, rows?: number): Promise<unknown>;
448
+ closeSqlCursor(id: Uint64Like): Promise<void>;
449
+ /** Idempotent; waits for in-flight calls before freeing the native handle. Calls made after close() rejects with InvalidArgumentError. */
450
+ close(): Promise<void>;
451
+ [Symbol.asyncDispose](): Promise<void>;
452
+ /** Open a table-scoped document/schema/index/enrichment handle. */
453
+ openTable(name: string): Promise<Database>;
454
+ statusRaw(): Promise<Buffer>;
455
+ status(): Promise<Status>;
456
+ capabilitiesRaw(): Promise<Buffer>;
457
+ capabilities(): Promise<Capabilities>;
458
+ checkRaw(): Promise<Buffer>;
459
+ check(): Promise<CheckReport>;
460
+ vacuumRaw(): Promise<Buffer>;
461
+ vacuum(): Promise<VacuumReport>;
462
+ compactRaw(): Promise<Buffer>;
463
+ compact(): Promise<CompactReport>;
464
+ copyStableSnapshotRaw(destPath: string, replace: boolean): Promise<Buffer>;
465
+ copyStableSnapshot(destPath: string, replace: boolean): Promise<StableSnapshotReport>;
466
+ pendingWorkStatsRaw(): Promise<Buffer>;
467
+ pendingWorkStats(): Promise<PendingWorkStatus>;
468
+ /** Drains pending enrichment and index work; returns no result (see runUntilIdleStatus for the post-drain report). */
469
+ runUntilIdle(): Promise<void>;
470
+ runUntilIdleStatusRaw(): Promise<Buffer>;
471
+ runUntilIdleStatus(): Promise<PendingWorkStatus>;
472
+ replayGeneratedEnrichmentsRaw(): Promise<Buffer>;
473
+ replayGeneratedEnrichments(): Promise<ReplayGeneratedEnrichmentsResult>;
474
+ /** Returns a portable Antfly backup archive (.afb) of this database, which restores or imports into either storage kind. */
475
+ backup(): Promise<Buffer>;
476
+ /** Imports a portable Antfly backup archive into this empty database. OutcomeUnknown means the live handle adopted the imported generation, but crash durability could not be confirmed; inspect the handle and do not retry automatically. */
477
+ importBackup(backup: Uint8Array): Promise<void>;
478
+ backupToFile(path: string): Promise<void>;
479
+ batch(writes: WriteIntent[], timestampNs: Uint64Like): Promise<void>;
480
+ batchJsonRaw(request: JsonInput): Promise<Buffer>;
481
+ batchJson(request: JsonInput): Promise<unknown>;
482
+ lookupRaw(key: string | Uint8Array): Promise<Buffer>;
483
+ lookup(key: string | Uint8Array): Promise<unknown>;
484
+ /** Raw stored bytes for key (antfly_db_get_raw), not JSON. */
485
+ getRaw(key: string | Uint8Array): Promise<Buffer>;
486
+ getSchemaRaw(): Promise<Buffer>;
487
+ getSchema(): Promise<unknown>;
488
+ setSchema(schema: JsonInput): Promise<void>;
489
+ listIndexesRaw(): Promise<Buffer>;
490
+ listIndexes(): Promise<unknown>;
491
+ addIndex(config: JsonInput): Promise<void>;
492
+ deleteIndex(name: string): Promise<boolean>;
493
+ listEnrichmentsRaw(): Promise<Buffer>;
494
+ listEnrichments(): Promise<unknown>;
495
+ addEnrichment(config: JsonInput): Promise<void>;
496
+ deleteEnrichment(kind: string, name: string): Promise<boolean>;
497
+ scanRaw(request: JsonInput): Promise<Buffer>;
498
+ scan(request: JsonInput): Promise<unknown>;
499
+ statsRaw(): Promise<Buffer>;
500
+ stats(): Promise<unknown>;
501
+ searchRaw(request: JsonInput): Promise<Buffer>;
502
+ search(request: JsonInput): Promise<unknown>;
503
+ denseSearchWire(request: Uint8Array): Promise<Buffer>;
504
+ textMatchWire(request: Uint8Array): Promise<Buffer>;
505
+ textTermWire(request: Uint8Array): Promise<Buffer>;
506
+ textMatchPhraseWire(request: Uint8Array): Promise<Buffer>;
507
+ aggregateHitsRaw(request: JsonInput): Promise<Buffer>;
508
+ aggregateHits(request: JsonInput): Promise<unknown>;
509
+ lookupArtifactRaw(artifactIdBase64: string): Promise<Buffer>;
510
+ lookupArtifact(artifactIdBase64: string): Promise<unknown>;
511
+ extractEnrichmentsRaw(request: JsonInput): Promise<Buffer>;
512
+ extractEnrichments(request: JsonInput): Promise<unknown>;
513
+ computeEnrichmentsRaw(request: JsonInput): Promise<Buffer>;
514
+ computeEnrichments(request: JsonInput): Promise<unknown>;
515
+ edgesRaw(indexName: string, key: string, edgeType: string, direction: number): Promise<Buffer>;
516
+ edges(indexName: string, key: string, edgeType: string, direction: number): Promise<unknown>;
517
+ neighborsRaw(indexName: string, key: string, edgeType: string, direction: number): Promise<Buffer>;
518
+ neighbors(indexName: string, key: string, edgeType: string, direction: number): Promise<unknown>;
519
+ traverseEdgesRaw(request: JsonInput): Promise<Buffer>;
520
+ traverseEdges(request: JsonInput): Promise<unknown>;
521
+ executeGraphQueriesRaw(request: JsonInput): Promise<Buffer>;
522
+ executeGraphQueries(request: JsonInput): Promise<unknown>;
523
+ findShortestPathRaw(request: JsonInput): Promise<Buffer>;
524
+ findShortestPath(request: JsonInput): Promise<unknown>;
525
+ findKShortestPathsRaw(request: JsonInput): Promise<Buffer>;
526
+ findKShortestPaths(request: JsonInput): Promise<unknown>;
527
+ matchPatternRaw(request: JsonInput): Promise<Buffer>;
528
+ matchPattern(request: JsonInput): Promise<unknown>;
529
+ beginTransaction(txnId: Uint8Array | string, timestampNs: Uint64Like, participants?: string[]): Promise<void>;
530
+ writeTransaction(txnId: Uint8Array | string, writes: WriteIntent[]): Promise<void>;
531
+ resolveTransaction(txnId: Uint8Array | string, status: TxnStatus, commitVersion?: Uint64Like): Promise<void>;
532
+ transactionStatus(txnId: Uint8Array | string): Promise<TxnStatus>;
533
+ commitVersion(txnId: Uint8Array | string): Promise<bigint>;
534
+ }
535
+ /** Opens an existing native Antfly Lite database file for writing. */
536
+ declare function open(path: string): Promise<Database>;
537
+ /** Creates a new native Antfly Lite database file for writing. */
538
+ declare function create(path: string): Promise<Database>;
539
+ /** Opens an existing Antfly Lite database file read-only. */
540
+ declare function openReadonly(path: string): Promise<Database>;
541
+ /** Opens enough of an Antfly Lite database to read status. */
542
+ declare function openStatusOnly(path: string): Promise<Database>;
543
+ /** Opens an Antfly Lite database using explicit C ABI options. */
544
+ declare function openWithOptions(path: string, options?: OpenOptions): Promise<Database>;
545
+ /** Creates an Antfly Lite database using explicit C ABI options. */
546
+ declare function createWithOptions(path: string, options?: OpenOptions): Promise<Database>;
547
+ /**
548
+ * Opens an existing Antfly Lite database in hosted/manual maintenance mode.
549
+ * In this profile callers drive pending work explicitly with runUntilIdle.
550
+ */
551
+ declare function openHosted(path: string): Promise<Database>;
552
+ /**
553
+ * Creates a new Antfly Lite database in hosted/manual maintenance mode. In
554
+ * this profile callers drive pending work explicitly with runUntilIdle.
555
+ */
556
+ declare function createHosted(path: string): Promise<Database>;
557
+
558
+ export { openWithOptions as A, platformLibraryFileName as B, type CheckReport as C, Database as D, resolveLibrary as E, GraphDirection as G, type InferenceOptions as I, type JsonInput as J, LibraryNotFoundError as L, type MemoryAdmissionStats as M, type NativeLibrary as N, OpenMode as O, type PullProgress as P, type RestoreOptions as R, type StableSnapshotReport as S, THREADING_SERIALIZED as T, type Uint64Like as U, type VacuumReport as V, type WriteIntent as W, type Capabilities as a, type CompactReport as b, InferenceMode as c, type InferenceStatus as d, type LibrarySource as e, NATIVE_STACK_SIZE as f, type OpenOptions as g, type PendingWorkStatus as h, Profile as i, type ReplayGeneratedEnrichmentsResult as j, type ResolvedLibrary as k, SUPPORTED_ABI_VERSION as l, type Status as m, Storage as n, type StorageStatus as o, type TTLCleanupOptions as p, TxnStatus as q, UnsupportedPlatformError as r, create as s, createHosted as t, createWithOptions as u, embeddedPlatformPackageName as v, open as w, openHosted as x, openReadonly as y, openStatusOnly as z };