/** * One run's open database, and the transaction a caller can hold. * * Every operation here runs on one connection, one at a time, inside a * transaction. SQLite is reached synchronously but the operations built on it * are not, so the adapter serializes the connection rather than relying on * callers to take turns with it. A standalone append and a caller's * multi-statement transaction reach SQLite through the same insertion routine, * so there is no second write path to keep in agreement with the first. * * ## Enlistment travels with the caller * * `transact()` hands its body a `WorkflowRunTransaction`, and that object — not * the database — is what joins work to the transaction. Work that never * received one cannot enlist by accident, so an append happening elsewhere * waits for its own turn and commits on its own rather than being rolled back * with a failure it had nothing to do with. * * A scope-local marker records which database this scope holds a transaction * on. That is how a nested `transact()` is refused, and how an operation * called from inside a transaction body is refused rather than waiting for a * transaction its own caller is holding open. The marker is structural and the * savepoint that goes with it is a contextual operation; both live in * `transaction.ts`. * * ## Lifetime * * The handle belongs to the scope that opened it. When that scope ends its * lease closes, and every later call answers with a closed-handle failure. The * provider owns the authoritative physical connection for its own scope. */ import type { DatabaseSync } from "node:sqlite"; import { type Operation } from "effection"; import type { WorkflowRunDatabase } from "../storage/api.js"; import { type WorkflowRunRecord } from "../storage/record.js"; import type { RunConnection, WorkflowRunConnections } from "./connections.js"; /** What opening needs from whoever found the file and checked its schema. */ export interface OpenConnection { readonly connection: RunConnection; readonly connections: WorkflowRunConnections; readonly record: WorkflowRunRecord; } /** * Open a scope-owned lease on a run's provider-owned database connection. */ export declare function openWorkflowRunDatabase(connection: OpenConnection): Operation; /** * The run the singleton row describes, for whoever opened the file. * * A database that has already said it is a version-1 workflow run, and then * has no run in it, disagrees with itself. That is damage rather than a file * belonging to somebody else. */ export declare function readRunRow(database: DatabaseSync, path: string): WorkflowRunRecord;