import { type DatabaseSync } from 'node:sqlite'; /** * A copy whose effects cannot be recovered must abort the source transaction. * @remarks The migration caller retains its staging journal for explicit recovery. */ export declare class ExodusRecoveryError extends Error { } /** * The SQL image of a row identity as copy receipts record it (`identity_json`), * over arbitrary SQL value expressions: a caller comparing other rows with * recorded identities builds them the same way (T13309). * * @param expressions - One SQL expression per key column, in key order. * @returns A SQL expression evaluating to the identity image. */ export declare function identityImageSql(expressions: readonly string[]): string; /** The table holding copy receipts in an Exodus target. */ export declare const EXODUS_RECEIPTS_TABLE = "_exodus_recovery_rows"; /** * Inspect durable ownership for an existing staging operation. * * @param db - Exact target database connection. * @param operation - Existing Exodus staging-directory identity. * @returns Whether this target records the operation. * @remarks A staging journal alone cannot prove ownership of target rows. * @example * ```ts * hasExodusRecovery(db, stagingDirectory); * ``` */ export declare function hasExodusRecovery(db: DatabaseSync, operation: string): boolean; /** * Register the staging operation on the exact target before copying. * * @param db - Exact target database connection. * @param operation - Existing Exodus staging-directory identity. * @param schema - Target schema containing the receipt tables. * @remarks Call within the source transaction so operation ownership commits with its rows. * @example * ```ts * prepareExodusRecovery(db, stagingDirectory, 'main'); * ``` */ export declare function prepareExodusRecovery(db: DatabaseSync, operation: string, schema?: string): void; /** * Insert rows with transactional ownership and effect receipts. * * @param db - Target connection inside the source transaction. * @param schema - Target schema receiving rows. * @param table - Target table with a stable declared primary key. * @param insertSql - Migration INSERT statement whose effects are assessed. * @param operation - Existing Exodus staging-directory identity. * @param sourceDb - Source database identity recorded as provenance. * @param sourceTable - Original source table name. * @returns Number of directly inserted rows. * @remarks Rows and receipts share a savepoint. Ignored rows have no receipt. Read-only guard triggers and recorded handoff mirrors are supported; other effects are refused. * @example * ```ts * insertWithExodusReceipts(db, 'main', 'tasks_tasks', insertSql, stagingDirectory, sourcePath, 'tasks'); * ``` */ export declare function insertWithExodusReceipts(db: DatabaseSync, schema: string, table: string, insertSql: string, operation: string, sourceDb: string, sourceTable: string): number; /** * Recover unchanged resources owned by one staging operation. * * @param db - Exact target database connection. * @param operation - Existing Exodus staging-directory identity. * @returns Number of reverted inserted rows and mirror effects. * @remarks All owned resources are checked before any mutation. Conflicts refuse the whole target scope; unrelated resources remain intact. Separate database files are not one atomic transaction. * @example * ```ts * rollbackExodusReceipts(db, stagingDirectory); * ``` */ export declare function rollbackExodusReceipts(db: DatabaseSync, operation: string): number; /** * Commit a fresh cutover token before publishing its marker. * * @param db - Exact target database connection after migration verification. * @returns Persisted token identifying this verified cutover. * @remarks The marker and target token must agree; replacing or restoring the file invalidates an old marker. * @example * ```ts * const token = sealExodusDatabase(db); * ``` */ export declare function sealExodusDatabase(db: DatabaseSync): string; /** * Check a marker against the current database cutover identity. * * @param db - Existing caller connection to the target database. * @param token - Cutover token read from the completion marker. * @returns Whether the current database stores the expected cutover token. * @remarks This read never creates missing identity state and does not trust a pathname alone. * @example * ```ts * hasExodusDatabaseIdentity(db, marker.databaseIdentity); * ``` */ export declare function hasExodusDatabaseIdentity(db: DatabaseSync, token: string): boolean; /** The table recording each legacy value a copy mapped to another (T12711). */ export declare const EXODUS_VALUE_MAP_TABLE = "_exodus_recovery_value_map"; /** One mapped column of an Exodus copy, for {@link recordExodusValueMap}. */ export interface ExodusValueMapping { /** Recovery operation of the copy; its rollback removes these records. */ readonly operation: string; /** Logical source name (`LegacyDbDescriptor.name`). */ readonly sourceDb: string; /** Source table, as attached. */ readonly sourceTable: string; /** Target table the rows landed in. */ readonly targetTable: string; /** The mapped column. */ readonly column: string; /** SQL expression of the legacy value, over `fromSql`. */ readonly legacyExpr: string; /** SQL expression of the value the copy wrote, over `fromSql`. */ readonly mappedExpr: string; /** The target table's key columns, in key order. */ readonly keyColumns: readonly string[]; /** SQL expressions of the target row's key, in `keyColumns` order, over `fromSql`. */ readonly keyExprs: readonly string[]; /** The `FROM` clause naming the attached source table. */ readonly fromSql: string; } /** * Record, in the Exodus target, every source row whose value in one column the * copy mapped to a different value and which the target now holds (T12711): * the legacy value, what it became, and the target row's key. The record is lineage, local to the store like the * copy receipts; a re-run keeps the first record per row and column. * * @param db - The target connection, inside the copy's transaction. * @param schema - Schema the target lives in (`main` or an attach alias). * @param mapping - The mapped column and its expressions. * @returns Records written. */ export declare function recordExodusValueMap(db: DatabaseSync, schema: string, mapping: ExodusValueMapping): number; //# sourceMappingURL=recovery.d.ts.map