import type { DatabaseSync } from "node:sqlite"; export interface StorageMigration { readonly id: string; readonly sql: string; /** Table rebuilds only: run this migration with `foreign_keys=OFF` (the pragma * is a no-op inside a transaction, so the runner toggles it around the step) * and restore enforcement after. Use for dropping/renaming a table that other * tables reference; the SQL must end with `PRAGMA foreign_key_check;`. */ readonly foreignKeysOff?: boolean; } export declare class Database { private readonly connection; readonly path: string; private readonly onPostCommitError; private depth; private savepoint; private closed; private transactionFailure; private unusable; private commitCallbacks; constructor(connection: DatabaseSync, path: string, onPostCommitError?: (error: unknown) => void); /** Notifications/cache changes only; durable delivery belongs in the outbox. * Nested registrations wait for outer commit and are discarded on rollback. * Outside a transaction the preceding write is already committed, so run now. * Observer failures never misreport a committed transaction as rolled back. */ afterCommit(callback: () => void): void; /** File preparation/async services must not run inside an ambient SQL transaction. */ assertOutsideTransaction(): void; private observeCommit; private assertOpen; exec(sql: string): void; run(sql: string, ...params: unknown[]): void; get>(sql: string, ...params: unknown[]): T | undefined; all>(sql: string, ...params: unknown[]): T[]; /** Synchronous only. Nested calls use savepoints. Deferred reads retain a snapshot without a writer lock. */ transaction(fn: (db: Database) => T, mode?: "immediate" | "deferred"): T; close(): void; } /** A consumer can use an initialized context, never initialize one implicitly. */ export declare function getDatabase(): Database; /** Open a connection only. Schema/import/readiness and context binding are explicit. */ export declare function openDatabase(path: string, options?: { onPostCommitError?: (error: unknown) => void; }): Database; /** Synchronous inspection only; no directory creation, schema changes or context binding. */ export declare function inspectDatabase(path: string, inspect: (db: Pick) => T): T; /** SQLite-consistent backup; filesystem publication and durability belong to the caller. */ export declare function backupDatabase(source: string, destination: string): Promise; /** A process-death-safe SQL lock. Never unlink the database carrying the lock. */ export declare function lockDatabase(path: string, mode: "exclusive" | "immediate"): () => void; /** Checkpoint a closed application's WAL before replacing its database file. */ export declare function checkpointDatabase(path: string): { busy: number; } | undefined; /** Only the composition root/test fixture binds the process context. */ export declare function bindDatabase(db: Database): void; /** Applied history must be an exact, checksummed prefix of supported history. */ export declare function validateStorageMigrationHistory(db: Database, migrations: readonly StorageMigration[]): void; /** Ordered, transactional schema steps. Applied SQL cannot silently change. */ export declare function applyStorageMigrations(db: Database, migrations: readonly StorageMigration[]): void; /** Encode an optional boolean for a nullable SQLite integer column. */ export declare function sqliteBoolean(value: boolean | undefined): number | null; //# sourceMappingURL=database.d.ts.map