import type { RunFence } from '@mastra/core/storage'; import type { SqlCondition, SqlQueryOptions } from '../sql-builder.js'; import type { D1DB } from './index.js'; /** A write's fence, and the table holding the run's current claim to check it against. */ export interface RunFenceCheck { claimsTable: string; fence: RunFence; operation: string; } /** * Epoch milliseconds on the database clock. `julianday('now')` rather than * `unixepoch('subsec')`, which needs SQLite 3.42. */ export declare const DB_NOW_MS = "CAST(ROUND((julianday('now') - 2440587.5) * 86400000) AS INTEGER)"; /** * The condition a fenced statement writes under: the check's fence is the * run's current claim. D1 has no interactive transactions, so a fenced write * can't check the claim first and write second; each of its statements * carries this condition instead, and SQLite evaluates it atomically with the * write. */ export declare function runFenceGuard(check: RunFenceCheck | undefined): SqlCondition | undefined; /** Throws `RunFenceConflictError` unless the check's fence is the run's current claim. */ export declare function assertRunFence(db: D1DB, { claimsTable, fence, operation }: RunFenceCheck): Promise; /** * Runs one statement of a fenced write. With a check, `statement` must carry * `runFenceGuard(check)`. A guarded statement that changes no row either * found no target or was refused by its guard; re-reading the claim tells * which, and a refusal throws `RunFenceConflictError`. * * A write made of several statements stops at the first refused one, so a * takeover that lands between them leaves the earlier statements applied. * None of the refused writer's statements land after the takeover. */ export declare function executeFenced(db: D1DB, check: RunFenceCheck | undefined, { sql, params }: SqlQueryOptions): Promise; //# sourceMappingURL=run-fencing.d.ts.map