@antfly/embedded 0.3.0-rc.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -185,7 +185,7 @@ For decision question types and examples, see the
185
185
  [typed decision guide](../../../docs/reference/decisions.md).
186
186
 
187
187
  - **Calls**: `embed`, `rerank`, `chunk`, `generate`, `generateBatch`,
188
- `rewrite`, `decide`, `extract`, `read` (OCR), `transcribe`, `listModels` -- each with
188
+ `rewrite`, `decide`, `extract`, `read` (documents, images, audio), `listModels` -- each with
189
189
  a bare form (parsed JSON) and a `...Raw` form (raw `Buffer`), following the
190
190
  same convention as `Database`. Binary inputs (images, audio) go inline in
191
191
  the request JSON, as base64 or `data:` URIs. Responses are always
@@ -315,7 +315,8 @@ Every failed call rejects with an `AntflyError` subclass carrying:
315
315
  Subclasses: `InvalidArgumentError` (1), `NotFoundError` (2),
316
316
  `VersionConflictError` (3), `IntentConflictError` (4), `TxnNotFoundError` (5),
317
317
  `BusyError` (6), `OutcomeUnknownError` (7, not safe to retry automatically --
318
- publication may have succeeded but crash durability could not be confirmed),
318
+ the operation may have taken effect, but whether it applied or became durable
319
+ could not be confirmed),
319
320
  `UnsupportedError` (8, not transient), `StalledError` (9, a bounded drain
320
321
  like `runUntilIdle` made no progress and gave up), `CancelledError` (10, the
321
322
  caller returned `false` from an `Inference.pull()` `onProgress` or
@@ -323,6 +324,25 @@ caller returned `false` from an `Inference.pull()` `onProgress` or
323
324
  instead stops the operation the same way, but rejects with the thrown error
324
325
  itself, not `CancelledError`), `InternalError` (255).
325
326
 
327
+ ### Outcome receipts
328
+
329
+ When an autocommit SQL write (`sqlJson`, `Connection` outside a transaction)
330
+ ends with ANTFLY_OUTCOME_UNKNOWN, the rejection (`SqlError`, or
331
+ `OutcomeUnknownError` without a SQL diagnostic) carries `.outcomeReceipt`
332
+ (`undefined` when none was issued). Resolve it on any handle for the same
333
+ database with `db.outcomeReceiptStatus(receipt)`, which resolves to
334
+ `"applied"` or `"not_applied"`, or rejects with `StalledError` while the
335
+ uncertain commit is not reconciled yet (Lite: retry; directory database:
336
+ close the issuing handle and reopen first). Call
337
+ `db.forgetOutcomeReceipt(receipt)` once resolved; afterwards it can no
338
+ longer be resolved.
339
+
340
+ `batch`, `batchJson` and `batchJsonRaw` rejections carry `.outcomeReceipt`
341
+ too: they use `antfly_db_batch_with_receipt` and
342
+ `antfly_db_batch_json_with_receipt`, which return the receipt from the same
343
+ native call (the thread-local `antfly_last_error_outcome_receipt` cannot follow
344
+ an async call to a worker thread).
345
+
326
346
  ## API surface
327
347
 
328
348
  Mirrors `go/pkg/embedded`'s surface idiomatically:
@@ -351,7 +371,7 @@ Mirrors `go/pkg/embedded`'s surface idiomatically:
351
371
  `decodeArtifactId`, `abiVersion`, `threadingMode`, `validateAbi`.
352
372
  - **`Inference`**: `Inference.open(options?)`, `close()`,
353
373
  `[Symbol.asyncDispose]`; `embed`/`rerank`/`chunk`/`generate`/
354
- `generateBatch`/`rewrite`/`extract`/`read`/`transcribe`/`listModels`
374
+ `generateBatch`/`rewrite`/`extract`/`read`/`listModels`
355
375
  (each with a `...Raw` form); `generateStream(request, onChunk)` /
356
376
  `generateStreamRaw`; `pull(request, onProgress?, signal?)`; plus
357
377
  `InferenceOptions`, `PullProgress`, `CancelledError`,
@@ -439,6 +459,11 @@ const people = await sql.selectFrom("people").selectAll().execute();
439
459
  await sql.destroy(); // The caller still owns database.
440
460
  ```
441
461
 
462
+ For typed search relations, migration-table setup, and generated Kysely schema
463
+ interfaces, see the [Kysely reference](../sdk/docs/kysely.md) and
464
+ [`examples/kysely.mjs`](examples/kysely.mjs). The optional shared helpers live in
465
+ `@antfly/sdk/kysely`.
466
+
442
467
  `createTable`, `listTables`, `openTable`, and `dropTable` expose the shared
443
468
  document catalog. Table handles reuse existing schema, index, enrichment,
444
469
  search, and document methods. Close them before dropping their tables;
@@ -453,3 +478,25 @@ backups.
453
478
 
454
479
  See [the native SQL contract](../../../zig/CAPI.md#database-sql) for
455
480
  READ COMMITTED, savepoints, transactional DDL restrictions, and commit outcomes.
481
+
482
+ ## Cypher and SQL graph composition
483
+
484
+ `graphCatalogJson`, `cypherJson`, and `graphWriteStatus` expose durable named graphs, Cypher queries and mutations, and
485
+ transaction receipts through libantfly. Catalog requests use `action` (`put`,
486
+ `get`, `list`, `drop`), a graph `name`, and a `definition` for puts. Replacement
487
+ and drop require the current decimal-string `expected_revision`.
488
+
489
+ Queries use the same request contract as the server: `query`, `parameters` or
490
+ lossless `typed_parameters`, optional limits, and `write_request_id`. Results
491
+ contain tagged graph values; integer values are decimal strings. Native writes
492
+ return a commit receipt. Retain the request ID and resolve an unknown outcome
493
+ through the status method instead of replaying the query. `GraphError` preserves
494
+ the diagnostic code, span, outcome, and transaction ID when available.
495
+
496
+ Local SQL supports `GRAPH_TABLE` over these catalogs, including ordinary-table
497
+ joins and staged SQL rows in an explicit transaction. Graph definitions pin
498
+ local table and graph-index identities across reopen. Raw embedded calls reject
499
+ protected tables; authenticated principal queries use the server API.
500
+
501
+ See [the Cypher contract](../../../zig/CYPHER.md) for grammar, mapping, value,
502
+ mutation, and deployment semantics.
@@ -6,15 +6,21 @@ var __filename = /* @__PURE__ */ getFilename();
6
6
 
7
7
  // src/sql-types.ts
8
8
  var SqlError = class extends Error {
9
- constructor(diagnostic, transactionId) {
9
+ /**
10
+ * @param outcomeReceipt Set when an autocommit write ended with an unknown
11
+ * outcome; resolve it later with `Database.outcomeReceiptStatus()`.
12
+ */
13
+ constructor(diagnostic, transactionId, outcomeReceipt) {
10
14
  super(`${diagnostic.code}: ${diagnostic.message}`);
11
15
  this.diagnostic = diagnostic;
12
16
  this.transactionId = transactionId;
17
+ this.outcomeReceipt = outcomeReceipt;
13
18
  this.name = "SqlError";
14
19
  this.sqlstate = diagnostic.code;
15
20
  }
16
21
  diagnostic;
17
22
  transactionId;
23
+ outcomeReceipt;
18
24
  sqlstate;
19
25
  };
20
26
 
@@ -76,6 +76,11 @@ declare enum TxnStatus {
76
76
  Committed = 1,
77
77
  Aborted = 2
78
78
  }
79
+ /**
80
+ * Resolved outcome of a write that ended with ANTFLY_OUTCOME_UNKNOWN
81
+ * (ANTFLY_OUTCOME_RECEIPT_APPLIED / ANTFLY_OUTCOME_RECEIPT_NOT_APPLIED).
82
+ */
83
+ type OutcomeReceiptStatus = "applied" | "not_applied";
79
84
  /** Inference mode strings returned by Lite status and capabilities JSON. */
80
85
  declare const InferenceMode: {
81
86
  readonly CallerSuppliedOrDisabled: "caller_supplied_or_disabled";
@@ -336,6 +341,9 @@ interface NativeLibrary {
336
341
  dbClose: KoffiFunc<(handle: unknown) => void>;
337
342
  bufferFree: KoffiFunc<(buffer: object) => void>;
338
343
  dbSqlJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
344
+ dbGraphCatalogJson?: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
345
+ dbCypherJson?: KoffiFunc<(handle: unknown, graph: object, request: object, out: object) => number>;
346
+ dbGraphWriteStatusJson?: KoffiFunc<(handle: unknown, transactionId: object, out: object) => number>;
339
347
  dbOpenTable: KoffiFunc<(handle: unknown, name: object, out: unknown[]) => number>;
340
348
  dbCreateTableJson: KoffiFunc<(handle: unknown, name: object, schema: object) => number>;
341
349
  dbDropTable: KoffiFunc<(handle: unknown, name: object) => number>;
@@ -362,7 +370,19 @@ interface NativeLibrary {
362
370
  dbReplayGeneratedEnrichmentsJson: KoffiFunc<(handle: unknown, out: object) => number>;
363
371
  dbPendingWorkStatsJson: KoffiFunc<(handle: unknown, out: object) => number>;
364
372
  dbBatch: KoffiFunc<(handle: unknown, writes: object[] | null, writeCount: number, predicates: object[] | null, predicateCount: number, timestampNs: number | bigint, syncLevel: number) => number>;
373
+ /** Struct batch that returns the outcome receipt in the same call. */
374
+ dbBatchWithReceipt: KoffiFunc<(handle: unknown, writes: object[] | null, writeCount: number, predicates: object[] | null, predicateCount: number, timestampNs: number | bigint, syncLevel: number, receiptOut: object) => number>;
365
375
  dbBatchJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
376
+ /** Batch JSON that returns the outcome receipt in the same call. */
377
+ dbBatchJsonWithReceipt: KoffiFunc<(handle: unknown, request: object, out: object, receiptOut: object) => number>;
378
+ /**
379
+ * Thread-local: valid only on the OS thread that ran the failed call, so
380
+ * it cannot follow an async (worker-thread) call. SQL error bodies carry
381
+ * the same receipt as "outcome_receipt".
382
+ */
383
+ lastErrorOutcomeReceipt: KoffiFunc<(out: object) => number>;
384
+ dbOutcomeReceiptStatus: KoffiFunc<(handle: unknown, receipt: object, outStatus: number[]) => number>;
385
+ dbOutcomeReceiptForget: KoffiFunc<(handle: unknown, receipt: object) => number>;
366
386
  dbBeginTransactionWithId: KoffiFunc<(handle: unknown, txnId: Uint8Array, timestampNs: number | bigint, participants: object[] | null, participantCount: number) => number>;
367
387
  dbWriteTransaction: KoffiFunc<(handle: unknown, txnId: Uint8Array, writes: object[] | null, writeCount: number, predicates: object[] | null, predicateCount: number) => number>;
368
388
  dbResolveIntents: KoffiFunc<(handle: unknown, txnId: Uint8Array, status: number, commitVersion: number | bigint) => number>;
@@ -424,7 +444,6 @@ interface NativeLibrary {
424
444
  inferenceDecideJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
425
445
  inferenceExtractJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
426
446
  inferenceReadJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
427
- inferenceTranscribeJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
428
447
  inferenceListModelsJson: KoffiFunc<(handle: unknown, out: object) => number>;
429
448
  inferencePullJson: KoffiFunc<(handle: unknown, request: object, progress: unknown, progressContext: unknown, out: object) => number>;
430
449
  }
@@ -465,6 +484,9 @@ declare class Database implements AsyncDisposable {
465
484
  /** @internal use open()/create()/openHosted()/etc. instead of the constructor. */
466
485
  constructor(native: NativeLibrary, handle: unknown, owner?: Database | undefined);
467
486
  sqlJson(request: JsonInput): Promise<unknown>;
487
+ graphCatalogJson(request: JsonInput): Promise<unknown>;
488
+ cypherJson(graph: string, request: JsonInput): Promise<unknown>;
489
+ graphWriteStatus(transactionId: string): Promise<unknown>;
468
490
  createTable(name: string, schema: JsonInput): Promise<void>;
469
491
  dropTable(name: string): Promise<void>;
470
492
  listTables(): Promise<string[]>;
@@ -571,6 +593,16 @@ declare class Database implements AsyncDisposable {
571
593
  writeTransaction(txnId: Uint8Array | string, writes: WriteIntent[]): Promise<void>;
572
594
  resolveTransaction(txnId: Uint8Array | string, status: TxnStatus, commitVersion?: Uint64Like): Promise<void>;
573
595
  transactionStatus(txnId: Uint8Array | string): Promise<TxnStatus>;
596
+ /**
597
+ * Resolves an outcome receipt (`SqlError.outcomeReceipt` or
598
+ * `OutcomeUnknownError.outcomeReceipt`) on any handle for the same
599
+ * database. Rejects with `StalledError` while the uncertain commit is not
600
+ * reconciled yet: retry on a Lite database; for a directory database,
601
+ * close the issuing handle and reopen first.
602
+ */
603
+ outcomeReceiptStatus(receipt: string): Promise<OutcomeReceiptStatus>;
604
+ /** Removes a resolved receipt's durable marker; afterwards it cannot be resolved. */
605
+ forgetOutcomeReceipt(receipt: string): Promise<void>;
574
606
  commitVersion(txnId: Uint8Array | string): Promise<bigint>;
575
607
  }
576
608
  /** Opens an existing native Antfly Lite database file for writing. */
@@ -596,4 +628,4 @@ declare function openHosted(path: string): Promise<Database>;
596
628
  */
597
629
  declare function createHosted(path: string): Promise<Database>;
598
630
 
599
- export { openReadonly as A, openStatusOnly as B, type CheckReport as C, Database as D, openWithOptions as E, platformLibraryFileName as F, GraphDirection as G, resolveLibrary as H, 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, type LiveByteAccounting as f, type LiveByteCategory as g, NATIVE_STACK_SIZE as h, type OpenOptions as i, type PendingWorkStatus as j, Profile as k, type ReplayGeneratedEnrichmentsResult as l, type ResolvedLibrary as m, SUPPORTED_ABI_VERSION as n, type Status as o, Storage as p, type StorageStatus as q, type TTLCleanupOptions as r, TxnStatus as s, UnsupportedPlatformError as t, create as u, createHosted as v, createWithOptions as w, embeddedPlatformPackageName as x, open as y, openHosted as z };
631
+ export { openHosted as A, openReadonly as B, type CheckReport as C, Database as D, openStatusOnly as E, openWithOptions as F, GraphDirection as G, platformLibraryFileName as H, type InferenceOptions as I, type JsonInput as J, resolveLibrary as K, 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, type LiveByteAccounting as f, type LiveByteCategory as g, NATIVE_STACK_SIZE as h, type OpenOptions as i, type OutcomeReceiptStatus as j, type PendingWorkStatus as k, Profile as l, type ReplayGeneratedEnrichmentsResult as m, type ResolvedLibrary as n, SUPPORTED_ABI_VERSION as o, type Status as p, Storage as q, type StorageStatus as r, type TTLCleanupOptions as s, TxnStatus as t, UnsupportedPlatformError as u, create as v, createHosted as w, createWithOptions as x, embeddedPlatformPackageName as y, open as z };
@@ -76,6 +76,11 @@ declare enum TxnStatus {
76
76
  Committed = 1,
77
77
  Aborted = 2
78
78
  }
79
+ /**
80
+ * Resolved outcome of a write that ended with ANTFLY_OUTCOME_UNKNOWN
81
+ * (ANTFLY_OUTCOME_RECEIPT_APPLIED / ANTFLY_OUTCOME_RECEIPT_NOT_APPLIED).
82
+ */
83
+ type OutcomeReceiptStatus = "applied" | "not_applied";
79
84
  /** Inference mode strings returned by Lite status and capabilities JSON. */
80
85
  declare const InferenceMode: {
81
86
  readonly CallerSuppliedOrDisabled: "caller_supplied_or_disabled";
@@ -336,6 +341,9 @@ interface NativeLibrary {
336
341
  dbClose: KoffiFunc<(handle: unknown) => void>;
337
342
  bufferFree: KoffiFunc<(buffer: object) => void>;
338
343
  dbSqlJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
344
+ dbGraphCatalogJson?: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
345
+ dbCypherJson?: KoffiFunc<(handle: unknown, graph: object, request: object, out: object) => number>;
346
+ dbGraphWriteStatusJson?: KoffiFunc<(handle: unknown, transactionId: object, out: object) => number>;
339
347
  dbOpenTable: KoffiFunc<(handle: unknown, name: object, out: unknown[]) => number>;
340
348
  dbCreateTableJson: KoffiFunc<(handle: unknown, name: object, schema: object) => number>;
341
349
  dbDropTable: KoffiFunc<(handle: unknown, name: object) => number>;
@@ -362,7 +370,19 @@ interface NativeLibrary {
362
370
  dbReplayGeneratedEnrichmentsJson: KoffiFunc<(handle: unknown, out: object) => number>;
363
371
  dbPendingWorkStatsJson: KoffiFunc<(handle: unknown, out: object) => number>;
364
372
  dbBatch: KoffiFunc<(handle: unknown, writes: object[] | null, writeCount: number, predicates: object[] | null, predicateCount: number, timestampNs: number | bigint, syncLevel: number) => number>;
373
+ /** Struct batch that returns the outcome receipt in the same call. */
374
+ dbBatchWithReceipt: KoffiFunc<(handle: unknown, writes: object[] | null, writeCount: number, predicates: object[] | null, predicateCount: number, timestampNs: number | bigint, syncLevel: number, receiptOut: object) => number>;
365
375
  dbBatchJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
376
+ /** Batch JSON that returns the outcome receipt in the same call. */
377
+ dbBatchJsonWithReceipt: KoffiFunc<(handle: unknown, request: object, out: object, receiptOut: object) => number>;
378
+ /**
379
+ * Thread-local: valid only on the OS thread that ran the failed call, so
380
+ * it cannot follow an async (worker-thread) call. SQL error bodies carry
381
+ * the same receipt as "outcome_receipt".
382
+ */
383
+ lastErrorOutcomeReceipt: KoffiFunc<(out: object) => number>;
384
+ dbOutcomeReceiptStatus: KoffiFunc<(handle: unknown, receipt: object, outStatus: number[]) => number>;
385
+ dbOutcomeReceiptForget: KoffiFunc<(handle: unknown, receipt: object) => number>;
366
386
  dbBeginTransactionWithId: KoffiFunc<(handle: unknown, txnId: Uint8Array, timestampNs: number | bigint, participants: object[] | null, participantCount: number) => number>;
367
387
  dbWriteTransaction: KoffiFunc<(handle: unknown, txnId: Uint8Array, writes: object[] | null, writeCount: number, predicates: object[] | null, predicateCount: number) => number>;
368
388
  dbResolveIntents: KoffiFunc<(handle: unknown, txnId: Uint8Array, status: number, commitVersion: number | bigint) => number>;
@@ -424,7 +444,6 @@ interface NativeLibrary {
424
444
  inferenceDecideJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
425
445
  inferenceExtractJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
426
446
  inferenceReadJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
427
- inferenceTranscribeJson: KoffiFunc<(handle: unknown, request: object, out: object) => number>;
428
447
  inferenceListModelsJson: KoffiFunc<(handle: unknown, out: object) => number>;
429
448
  inferencePullJson: KoffiFunc<(handle: unknown, request: object, progress: unknown, progressContext: unknown, out: object) => number>;
430
449
  }
@@ -465,6 +484,9 @@ declare class Database implements AsyncDisposable {
465
484
  /** @internal use open()/create()/openHosted()/etc. instead of the constructor. */
466
485
  constructor(native: NativeLibrary, handle: unknown, owner?: Database | undefined);
467
486
  sqlJson(request: JsonInput): Promise<unknown>;
487
+ graphCatalogJson(request: JsonInput): Promise<unknown>;
488
+ cypherJson(graph: string, request: JsonInput): Promise<unknown>;
489
+ graphWriteStatus(transactionId: string): Promise<unknown>;
468
490
  createTable(name: string, schema: JsonInput): Promise<void>;
469
491
  dropTable(name: string): Promise<void>;
470
492
  listTables(): Promise<string[]>;
@@ -571,6 +593,16 @@ declare class Database implements AsyncDisposable {
571
593
  writeTransaction(txnId: Uint8Array | string, writes: WriteIntent[]): Promise<void>;
572
594
  resolveTransaction(txnId: Uint8Array | string, status: TxnStatus, commitVersion?: Uint64Like): Promise<void>;
573
595
  transactionStatus(txnId: Uint8Array | string): Promise<TxnStatus>;
596
+ /**
597
+ * Resolves an outcome receipt (`SqlError.outcomeReceipt` or
598
+ * `OutcomeUnknownError.outcomeReceipt`) on any handle for the same
599
+ * database. Rejects with `StalledError` while the uncertain commit is not
600
+ * reconciled yet: retry on a Lite database; for a directory database,
601
+ * close the issuing handle and reopen first.
602
+ */
603
+ outcomeReceiptStatus(receipt: string): Promise<OutcomeReceiptStatus>;
604
+ /** Removes a resolved receipt's durable marker; afterwards it cannot be resolved. */
605
+ forgetOutcomeReceipt(receipt: string): Promise<void>;
574
606
  commitVersion(txnId: Uint8Array | string): Promise<bigint>;
575
607
  }
576
608
  /** Opens an existing native Antfly Lite database file for writing. */
@@ -596,4 +628,4 @@ declare function openHosted(path: string): Promise<Database>;
596
628
  */
597
629
  declare function createHosted(path: string): Promise<Database>;
598
630
 
599
- export { openReadonly as A, openStatusOnly as B, type CheckReport as C, Database as D, openWithOptions as E, platformLibraryFileName as F, GraphDirection as G, resolveLibrary as H, 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, type LiveByteAccounting as f, type LiveByteCategory as g, NATIVE_STACK_SIZE as h, type OpenOptions as i, type PendingWorkStatus as j, Profile as k, type ReplayGeneratedEnrichmentsResult as l, type ResolvedLibrary as m, SUPPORTED_ABI_VERSION as n, type Status as o, Storage as p, type StorageStatus as q, type TTLCleanupOptions as r, TxnStatus as s, UnsupportedPlatformError as t, create as u, createHosted as v, createWithOptions as w, embeddedPlatformPackageName as x, open as y, openHosted as z };
631
+ export { openHosted as A, openReadonly as B, type CheckReport as C, Database as D, openStatusOnly as E, openWithOptions as F, GraphDirection as G, platformLibraryFileName as H, type InferenceOptions as I, type JsonInput as J, resolveLibrary as K, 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, type LiveByteAccounting as f, type LiveByteCategory as g, NATIVE_STACK_SIZE as h, type OpenOptions as i, type OutcomeReceiptStatus as j, type PendingWorkStatus as k, Profile as l, type ReplayGeneratedEnrichmentsResult as m, type ResolvedLibrary as n, SUPPORTED_ABI_VERSION as o, type Status as p, Storage as q, type StorageStatus as r, type TTLCleanupOptions as s, TxnStatus as t, UnsupportedPlatformError as u, create as v, createHosted as w, createWithOptions as x, embeddedPlatformPackageName as y, open as z };
package/dist/index.cjs CHANGED
@@ -38,6 +38,7 @@ __export(index_exports, {
38
38
  Database: () => Database,
39
39
  ErrorCode: () => ErrorCode,
40
40
  GraphDirection: () => GraphDirection,
41
+ GraphError: () => GraphError,
41
42
  Inference: () => Inference,
42
43
  InferenceMode: () => InferenceMode,
43
44
  IntentConflictError: () => IntentConflictError,
@@ -241,7 +242,7 @@ var ERROR_CODE_DESCRIPTIONS = {
241
242
  [4 /* IntentConflict */]: "a transaction intent conflicts with the requested operation",
242
243
  [5 /* TxnNotFound */]: "the requested transaction was not found",
243
244
  [6 /* Busy */]: "the requested resource is temporarily busy or changed during streaming; stabilize it and retry",
244
- [7 /* OutcomeUnknown */]: "the operation was published, but crash durability could not be confirmed; inspect the destination and do not retry automatically",
245
+ [7 /* OutcomeUnknown */]: "the operation may have taken effect, but whether it applied or became durable could not be confirmed; inspect the affected data and do not retry automatically",
245
246
  [8 /* Unsupported */]: "the operation requires a capability that is not supported by this platform or filesystem",
246
247
  [9 /* Stalled */]: "derived work stalled or failed; inspect pending-work diagnostics and repair or reopen the database",
247
248
  [10 /* Cancelled */]: "the caller cancelled the operation",
@@ -315,9 +316,16 @@ var BusyError = class extends AntflyError {
315
316
  }
316
317
  };
317
318
  var OutcomeUnknownError = class extends AntflyError {
318
- constructor(message) {
319
+ /**
320
+ * The receipt the database issued for an autocommit SQL write that ended
321
+ * with an unknown outcome, if any. Resolve it later with
322
+ * `Database.outcomeReceiptStatus()`.
323
+ */
324
+ outcomeReceipt;
325
+ constructor(message, outcomeReceipt) {
319
326
  super(7 /* OutcomeUnknown */, message);
320
327
  this.name = "OutcomeUnknownError";
328
+ if (outcomeReceipt !== void 0) this.outcomeReceipt = outcomeReceipt;
321
329
  Object.setPrototypeOf(this, new.target.prototype);
322
330
  }
323
331
  };
@@ -555,6 +563,31 @@ function buildNative() {
555
563
  configureKoffiStacks();
556
564
  const handle = import_koffi.default.load(resolved.path);
557
565
  const f = handle.func.bind(handle);
566
+ let dbGraphCatalogJson;
567
+ let dbCypherJson;
568
+ let dbGraphWriteStatusJson;
569
+ try {
570
+ dbGraphCatalogJson = f("antfly_db_graph_catalog_json", "uint32_t", [
571
+ PAntflyDb,
572
+ AntflySlice,
573
+ PAntflyBufferOut
574
+ ]);
575
+ dbCypherJson = f("antfly_db_cypher_json", "uint32_t", [
576
+ PAntflyDb,
577
+ AntflySlice,
578
+ AntflySlice,
579
+ PAntflyBufferOut
580
+ ]);
581
+ dbGraphWriteStatusJson = f("antfly_db_graph_write_status_json", "uint32_t", [
582
+ PAntflyDb,
583
+ AntflySlice,
584
+ PAntflyBufferOut
585
+ ]);
586
+ } catch {
587
+ dbGraphCatalogJson = void 0;
588
+ dbCypherJson = void 0;
589
+ dbGraphWriteStatusJson = void 0;
590
+ }
558
591
  return {
559
592
  handle,
560
593
  resolved,
@@ -579,6 +612,9 @@ function buildNative() {
579
612
  dbClose: f("antfly_db_close", "void", [PAntflyDb]),
580
613
  bufferFree: f("antfly_buffer_free", "void", [import_koffi.default.pointer(AntflyBuffer)]),
581
614
  dbSqlJson: f("antfly_db_sql_json", "uint32_t", [PAntflyDb, AntflySlice, PAntflyBufferOut]),
615
+ dbGraphCatalogJson,
616
+ dbCypherJson,
617
+ dbGraphWriteStatusJson,
582
618
  dbOpenTable: f("antfly_db_open_table", "uint32_t", [PAntflyDb, AntflySlice, PAntflyDbOut]),
583
619
  dbCreateTableJson: f("antfly_db_create_table_json", "uint32_t", [
584
620
  PAntflyDb,
@@ -661,7 +697,33 @@ function buildNative() {
661
697
  "uint64_t",
662
698
  "uint8_t"
663
699
  ]),
700
+ dbBatchWithReceipt: f("antfly_db_batch_with_receipt", "uint32_t", [
701
+ PAntflyDb,
702
+ PAntflyWriteIntentArray,
703
+ "size_t",
704
+ PAntflyVersionPredicateArray,
705
+ "size_t",
706
+ "uint64_t",
707
+ "uint8_t",
708
+ PAntflyBufferOut
709
+ ]),
664
710
  dbBatchJson: f("antfly_db_batch_json", "uint32_t", [PAntflyDb, AntflySlice, PAntflyBufferOut]),
711
+ dbBatchJsonWithReceipt: f("antfly_db_batch_json_with_receipt", "uint32_t", [
712
+ PAntflyDb,
713
+ AntflySlice,
714
+ PAntflyBufferOut,
715
+ PAntflyBufferOut
716
+ ]),
717
+ lastErrorOutcomeReceipt: f("antfly_last_error_outcome_receipt", "uint32_t", [PAntflyBufferOut]),
718
+ dbOutcomeReceiptStatus: f("antfly_db_outcome_receipt_status", "uint32_t", [
719
+ PAntflyDb,
720
+ AntflySlice,
721
+ PUint8Out
722
+ ]),
723
+ dbOutcomeReceiptForget: f("antfly_db_outcome_receipt_forget", "uint32_t", [
724
+ PAntflyDb,
725
+ AntflySlice
726
+ ]),
665
727
  dbBeginTransactionWithId: f("antfly_db_begin_transaction_with_id", "uint32_t", [
666
728
  PAntflyDb,
667
729
  "const uint8_t *",
@@ -941,11 +1003,6 @@ function buildNative() {
941
1003
  AntflySlice,
942
1004
  PAntflyBufferOut
943
1005
  ]),
944
- inferenceTranscribeJson: f("antfly_inference_transcribe_json", "uint32_t", [
945
- PAntflyInference,
946
- AntflySlice,
947
- PAntflyBufferOut
948
- ]),
949
1006
  inferenceListModelsJson: f("antfly_inference_list_models_json", "uint32_t", [
950
1007
  PAntflyInference,
951
1008
  PAntflyBufferOut
@@ -1004,6 +1061,18 @@ function validateInferenceAbi() {
1004
1061
  var fsp = __toESM(require("fs/promises"), 1);
1005
1062
  var import_node_path2 = require("path");
1006
1063
 
1064
+ // src/graph-types.ts
1065
+ var GraphError = class extends Error {
1066
+ constructor(diagnostic, nativeCode) {
1067
+ super(diagnostic.message);
1068
+ this.diagnostic = diagnostic;
1069
+ this.nativeCode = nativeCode;
1070
+ this.name = "GraphError";
1071
+ }
1072
+ diagnostic;
1073
+ nativeCode;
1074
+ };
1075
+
1007
1076
  // src/marshal.ts
1008
1077
  var import_node_util = require("util");
1009
1078
  var import_koffi3 = __toESM(require("koffi"), 1);
@@ -1118,19 +1187,27 @@ function parseMemoryJson(buf) {
1118
1187
 
1119
1188
  // src/sql-types.ts
1120
1189
  var SqlError = class extends Error {
1121
- constructor(diagnostic, transactionId) {
1190
+ /**
1191
+ * @param outcomeReceipt Set when an autocommit write ended with an unknown
1192
+ * outcome; resolve it later with `Database.outcomeReceiptStatus()`.
1193
+ */
1194
+ constructor(diagnostic, transactionId, outcomeReceipt) {
1122
1195
  super(`${diagnostic.code}: ${diagnostic.message}`);
1123
1196
  this.diagnostic = diagnostic;
1124
1197
  this.transactionId = transactionId;
1198
+ this.outcomeReceipt = outcomeReceipt;
1125
1199
  this.name = "SqlError";
1126
1200
  this.sqlstate = diagnostic.code;
1127
1201
  }
1128
1202
  diagnostic;
1129
1203
  transactionId;
1204
+ outcomeReceipt;
1130
1205
  sqlstate;
1131
1206
  };
1132
1207
 
1133
1208
  // src/database.ts
1209
+ var OUTCOME_RECEIPT_APPLIED = 1;
1210
+ var OUTCOME_RECEIPT_NOT_APPLIED = 2;
1134
1211
  var OPEN_FLAG_NO_SYNC = 1 << 0;
1135
1212
  var OPEN_FLAG_TTL_CLEANUP = 1 << 1;
1136
1213
  var OPEN_FLAG_REMOTE_PROVIDER_CONFIGURED = 1 << 2;
@@ -1238,7 +1315,12 @@ var Database = class _Database {
1238
1315
  const code = await callAsync(fn, handle, ...args, out);
1239
1316
  const body = takeBuffer(this.#native, out);
1240
1317
  const value = body.length ? JSON.parse(body.toString("utf8")) : void 0;
1241
- if (code && value?.error) throw new SqlError(value.error, value.transaction_id);
1318
+ if (code && value?.error) {
1319
+ throw new SqlError(value.error, value.transaction_id, value.outcome_receipt);
1320
+ }
1321
+ if (code === 7 /* OutcomeUnknown */ && typeof value?.outcome_receipt === "string") {
1322
+ throw new OutcomeUnknownError(void 0, value.outcome_receipt);
1323
+ }
1242
1324
  checkCode(code);
1243
1325
  return value;
1244
1326
  });
@@ -1246,6 +1328,31 @@ var Database = class _Database {
1246
1328
  sqlJson(request2) {
1247
1329
  return this.#invokeSql(this.#native.dbSqlJson, jsonSlice(request2));
1248
1330
  }
1331
+ // biome-ignore lint/suspicious/noExplicitAny: native signatures vary
1332
+ #invokeGraph(fn, ...args) {
1333
+ if (!fn)
1334
+ return Promise.reject(
1335
+ new UnsupportedError("This native library does not expose Cypher graphs")
1336
+ );
1337
+ return this.#run(async (handle) => {
1338
+ const out = newBufferOut();
1339
+ const code = await callAsync(fn, handle, ...args, out);
1340
+ const body = takeBuffer(this.#native, out);
1341
+ const value = body.length ? JSON.parse(body.toString("utf8")) : void 0;
1342
+ if (code && value?.code) throw new GraphError(value, code);
1343
+ checkCode(code);
1344
+ return value;
1345
+ });
1346
+ }
1347
+ graphCatalogJson(request2) {
1348
+ return this.#invokeGraph(this.#native.dbGraphCatalogJson, jsonSlice(request2));
1349
+ }
1350
+ cypherJson(graph, request2) {
1351
+ return this.#invokeGraph(this.#native.dbCypherJson, stringSlice(graph), jsonSlice(request2));
1352
+ }
1353
+ graphWriteStatus(transactionId) {
1354
+ return this.#invokeGraph(this.#native.dbGraphWriteStatusJson, stringSlice(transactionId));
1355
+ }
1249
1356
  createTable(name, schema) {
1250
1357
  return this.#invokeCode(this.#native.dbCreateTableJson, stringSlice(name), jsonSlice(schema));
1251
1358
  }
@@ -1389,21 +1496,44 @@ var Database = class _Database {
1389
1496
  batch(writes, timestampNs) {
1390
1497
  return this.#run(async (handle) => {
1391
1498
  const cWrites = writes.length ? writes.map(toNativeWriteIntent) : null;
1499
+ const receiptOut = newBufferOut();
1392
1500
  const code = await callAsync(
1393
- this.#native.dbBatch,
1501
+ this.#native.dbBatchWithReceipt,
1394
1502
  handle,
1395
1503
  cWrites,
1396
1504
  writes.length,
1397
1505
  null,
1398
1506
  0,
1399
1507
  timestampNs,
1400
- 0
1508
+ 0,
1509
+ receiptOut
1401
1510
  );
1511
+ const receipt = takeBuffer(this.#native, receiptOut);
1512
+ if (code === 7 /* OutcomeUnknown */ && receipt.length) {
1513
+ throw new OutcomeUnknownError(void 0, receipt.toString("utf8"));
1514
+ }
1402
1515
  checkCode(code);
1403
1516
  });
1404
1517
  }
1405
1518
  batchJsonRaw(request2) {
1406
- return this.#invokeBuffer(this.#native.dbBatchJson, jsonSlice(request2));
1519
+ return this.#run(async (handle) => {
1520
+ const out = newBufferOut();
1521
+ const receiptOut = newBufferOut();
1522
+ const code = await callAsync(
1523
+ this.#native.dbBatchJsonWithReceipt,
1524
+ handle,
1525
+ jsonSlice(request2),
1526
+ out,
1527
+ receiptOut
1528
+ );
1529
+ const receipt = takeBuffer(this.#native, receiptOut);
1530
+ if (code === 7 /* OutcomeUnknown */ && receipt.length) {
1531
+ takeBuffer(this.#native, out);
1532
+ throw new OutcomeUnknownError(void 0, receipt.toString("utf8"));
1533
+ }
1534
+ checkCode(code);
1535
+ return takeBuffer(this.#native, out);
1536
+ });
1407
1537
  }
1408
1538
  async batchJson(request2) {
1409
1539
  return parseJson(await this.batchJsonRaw(request2));
@@ -1730,6 +1860,32 @@ var Database = class _Database {
1730
1860
  return out[0];
1731
1861
  });
1732
1862
  }
1863
+ /**
1864
+ * Resolves an outcome receipt (`SqlError.outcomeReceipt` or
1865
+ * `OutcomeUnknownError.outcomeReceipt`) on any handle for the same
1866
+ * database. Rejects with `StalledError` while the uncertain commit is not
1867
+ * reconciled yet: retry on a Lite database; for a directory database,
1868
+ * close the issuing handle and reopen first.
1869
+ */
1870
+ outcomeReceiptStatus(receipt) {
1871
+ return this.#run(async (handle) => {
1872
+ const out = [0];
1873
+ const code = await callAsync(
1874
+ this.#native.dbOutcomeReceiptStatus,
1875
+ handle,
1876
+ stringSlice(receipt),
1877
+ out
1878
+ );
1879
+ checkCode(code);
1880
+ if (out[0] === OUTCOME_RECEIPT_APPLIED) return "applied";
1881
+ if (out[0] === OUTCOME_RECEIPT_NOT_APPLIED) return "not_applied";
1882
+ throw new InternalError(`unexpected outcome receipt status ${out[0]}`);
1883
+ });
1884
+ }
1885
+ /** Removes a resolved receipt's durable marker; afterwards it cannot be resolved. */
1886
+ forgetOutcomeReceipt(receipt) {
1887
+ return this.#invokeCode(this.#native.dbOutcomeReceiptForget, stringSlice(receipt));
1888
+ }
1733
1889
  commitVersion(txnId) {
1734
1890
  return this.#run(async (handle) => {
1735
1891
  const id = txnIdBytes(txnId);
@@ -2162,19 +2318,13 @@ var Inference = class _Inference {
2162
2318
  async extract(request2) {
2163
2319
  return parseJson(await this.extractRaw(request2));
2164
2320
  }
2165
- /** OCR. */
2321
+ /** Read images, documents, or audio. */
2166
2322
  readRaw(request2) {
2167
2323
  return this.#invokeJson(this.#native.inferenceReadJson, request2);
2168
2324
  }
2169
2325
  async read(request2) {
2170
2326
  return parseJson(await this.readRaw(request2));
2171
2327
  }
2172
- transcribeRaw(request2) {
2173
- return this.#invokeJson(this.#native.inferenceTranscribeJson, request2);
2174
- }
2175
- async transcribe(request2) {
2176
- return parseJson(await this.transcribeRaw(request2));
2177
- }
2178
2328
  /** The installed models, as returned by GET /ai/v1/models. */
2179
2329
  listModelsRaw() {
2180
2330
  return this.#run(async (handle) => {
@@ -2451,6 +2601,7 @@ var Connection = class _Connection {
2451
2601
  Database,
2452
2602
  ErrorCode,
2453
2603
  GraphDirection,
2604
+ GraphError,
2454
2605
  Inference,
2455
2606
  InferenceMode,
2456
2607
  IntentConflictError,