/** * Uid remaps propagate to everything still pending (journal spec §3.3 G; * T12779). * * A capture records a reference as `[enc(local key), target uid]`, with the * target's uid read when the write happened. When that uid is later replaced * without the stream ever learning the old one (a re-key netted into the * row's own insert, a refill), every pending capture and every sealed but * unsegmented op that still names the old uid would send a reference to a * row no replica has. {@link remapPending} rewrites them, in the remap's own * transaction: reference uids, the remapped row's own uid, and its birth * fingerprint when that changed too. * * Segmented transactions are never rewritten: what a segment carries is * history. * * @task T12779 * @module store/sync/remap */ import type { DatabaseSync } from 'node:sqlite'; import type { TableScope } from '@cleocode/contracts'; /** `enc()` of a text value, as the capture triggers write it (`quote()`). */ export declare function encText(value: string): string; /** One remap: `oldUid` became `newUid` (the same uid when only `bfp` changed). */ export interface UidRemap { readonly table: string; readonly oldUid: string; readonly newUid: string; /** The row's new birth fingerprint, or null when it is unchanged. */ readonly newBfp: string | null; } /** A capture's remappable fields. */ export interface RemappableCapture { readonly tbl: string; readonly op: 'I' | 'U' | 'D' | 'K'; readonly uid: string | null; readonly img: string; } /** * A capture with `remap` applied: its reference pairs, and, when it is the * remapped row's own I or D capture, its uid and birth fingerprint. A K's * own (old, new) pair holds `enc()` texts, never a bare uid, so it is never * mistaken for a reference and keeps recording the remap itself. Returns the * same object when nothing changed. */ export declare function remapCapture(c: C, remap: UidRemap): C; /** A sealed op body with `remap` applied (reference values are plain uids there). */ export declare function remapOpBody(body: Record, remap: UidRemap): Record; /** What {@link remapPending} rewrote. */ export interface RemapReport { readonly captures: number; readonly ops: number; } /** * Apply a uid remap to every live capture and every op of a sealed, * unsegmented transaction (§3.3 G), in the caller's transaction. * * @param db - The store, inside the remap's transaction. * @param remap - What changed. * @returns How many captures and ops were rewritten. */ export declare function remapPending(db: DatabaseSync, remap: UidRemap): RemapReport; /** * After a refill re-derived birth fingerprints (§12.1, before any uid has * synced), point every pending capture and unsegmented op of a minted row at * the row's current `birth_fp` (§3.3 G; T12779). Uids are unchanged by a * refill. A row that no longer exists is left alone. * * @returns How many captures and ops were rewritten. */ export declare function refreshPendingBirthFps(db: DatabaseSync, scope: TableScope): RemapReport; //# sourceMappingURL=remap.d.ts.map