import * as v from '../../../../../shared/src/valita.ts';
import type { Database } from '../../../../../zqlite/src/db.ts';
import { StatementRunner } from '../../../db/statements.ts';
import type { LexiVersion } from '../../../types/lexi-version.ts';
import type { LiteRowKey } from '../../../types/lite.ts';
/**
 * The Change Log tracks the last operation (set or delete) for each row in the
 * data base, ordered by state version; in other words, a cross-table
 * index of row changes ordered by version. This facilitates a minimal "diff"
 * of row changes needed to advance a pipeline from one state version to another.
 *
 * The Change Log stores identifiers only, i.e. it does not store contents.
 * A database snapshot at the previous version can be used to query a row's
 * old contents, if any, and the current snapshot can be used to query a row's
 * new contents. (In the common case, the new contents will have just been applied
 * and thus has a high likelihood of being in the SQLite cache.)
 *
 * There are two table-wide operations:
 * - `t` corresponds to the postgres `TRUNCATE` operation
 * - `r` represents any schema (i.e. column) change
 *
 * For both operations, the corresponding row changes are not explicitly included
 * in the change log. The consumer has the option of simulating them be reading
 * from pre- and post- snapshots, or resetting their state entirely with the current
 * snapshot.
 *
 * To achieve the desired ordering semantics when processing tables that have been
 * truncated, reset, and modified, the "rowKey" is set to `null` for resets and
 * the empty string `""` for truncates. This means that resets will be encountered
 * before truncates, which will be processed before any subsequent row changes.
 *
 * This ordering is chosen because resets are currently the more "destructive" op
 * and result in aborting the processing (and starting from scratch); doing this
 * earlier reduces wasted work.
 */
export declare const SET_OP = "s";
export declare const DEL_OP = "d";
export declare const TRUNCATE_OP = "t";
export declare const RESET_OP = "r";
export declare const changeLogEntrySchema: v.Type<{
    rowKey: Readonly<Record<string, import("../../../../../shared/src/bigint-json.ts").JSONValue>> | null;
    stateVersion: string;
    table: string;
    op: "d" | "r" | "s" | "t";
}>;
export type ChangeLogEntry = v.Infer<typeof changeLogEntrySchema>;
export declare function initChangeLog(db: Database): void;
export declare function logSetOp(db: StatementRunner, version: LexiVersion, table: string, row: LiteRowKey): string;
export declare function logDeleteOp(db: StatementRunner, version: LexiVersion, table: string, row: LiteRowKey): string;
export declare function logTruncateOp(db: StatementRunner, version: LexiVersion, table: string): void;
export declare function logResetOp(db: StatementRunner, version: LexiVersion, table: string): void;
//# sourceMappingURL=change-log.d.ts.map