/** * The replay pin of a checkpoint (journal spec §2.11 §7; NEW-9, R5-8, * T12797): what an endorsing device must replay under to recompute the * checkpoint's tallies. * * - `journal`: sha256 over the store's WHOLE ordered migration journal, * `(created_at, name, hash)` per applied migration, in drizzle's order * `(created_at, name)`. A single head is not enough: stamped and drifted * stores differ below it. * - `triggerSetHash`: sha256 over the normalized DDL of the store's OWNED * triggers ({@link OWNED_TRIGGERS}: the guard and side-effect triggers a * replay runs under), sorted by name. Device-local maintenance triggers * (the twin-collapse docs freeze, whose message names the build that froze * that store, and the legacy track triggers) never touch a replayed table, * so they stay out: two devices with the same replay semantics agree * (T13298). Normalization is literal-safe ({@link normalizeTriggerDdl}). * - `transitions`: the schema rise points inside the checkpoint's window; * the caller computes them from the segments it replayed (empty for a * genesis checkpoint, which has no window to replay). * * The server cannot check the two hashes; another device recomputes them * from its own store and requires a match before it endorses. * * @task T12343 * @module store/sync/replay-pin */ import type { DatabaseSync } from 'node:sqlite'; import type { ReplayPin } from '@cleocode/contracts/cloud'; /** * Normalize trigger DDL for hashing, literal-safely (§2.11 §7): comments are * dropped; outside string literals and quoted identifiers, whitespace runs * collapse to one space (and vanish next to punctuation) and words are * lower-cased; a string literal is kept byte for byte (`'Done'` stays * `'Done'`); every quoted identifier (`"x"`, `` `x` ``, `[x]`) is written * `"x"`, and a bare identifier stays bare (SQLite treats both alike for the * names a trigger uses, so the two spellings of one trigger hash alike only * when quoting is unified this way). * * @param sql - The trigger's `CREATE TRIGGER` text. * @returns The normalized text. */ export declare function normalizeTriggerDdl(sql: string): string; /** * sha256 of the store's whole ordered migration journal (§2.11 §7): every * `__drizzle_migrations` row as `[created_at, name, hash]`, ordered by * `(created_at, name)`. A store without the journal hashes an empty list. * * @param db - The store. * @returns The hex digest. */ export declare function migrationJournalHash(db: DatabaseSync): string; /** * sha256 over the normalized DDL of every owned trigger present in the store * ({@link OWNED_TRIGGERS}), sorted by name (§2.11 §7; T13298). Capture * triggers (generated per build) and device-local maintenance triggers are * excluded: they never run in a replay. * * @param db - The store. * @returns The hex digest. */ export declare function triggerSetHash(db: DatabaseSync): string; /** * A checkpoint's replay pin, from the store it snapshots (§2.11 §7). * * @param db - The store (or the snapshot of it the checkpoint carries). * @param transitions - The window's schema rise points (empty for genesis). * @returns The pin. */ export declare function replayPinOf(db: DatabaseSync, transitions?: ReplayPin['transitions']): ReplayPin; //# sourceMappingURL=replay-pin.d.ts.map