/** * The journal's tallies of a checkpoint window (journal spec §2.11, T12999): * the rows a stream holds after the segments since a checkpoint, from the * checkpoint's manifest, the window's declared per-transaction deltas and * what this store's inbox says each transaction became (`pending`, `void`, * applied). A vault snapshot of a journal stream checkpoints with them * instead of a synthetic delta segment, and `cleo cloud verify` compares the * store against them instead of the head snapshot's frozen counts. * * @task T12999 * @module cloud/journal-tallies */ import type { DatabaseSync } from 'node:sqlite'; import type { Checkpoint, TxnRef } from '@cleocode/contracts/cloud'; import { type Journal } from './journal.js'; import type { TrustedSigners } from './keys.js'; import { type DeclaredTxn, type SchemaRise } from './manifest-check.js'; /** A window transaction: its ref, declared deltas and stream seq. */ export interface WindowTxn extends DeclaredTxn { /** The stream seq of its segment. */ readonly seq: number; } /** The segments after a checkpoint, as the server declared them. */ export interface JournalWindow { /** Every transaction, in stream order. */ readonly txns: readonly WindowTxn[]; /** Each segment's seq and schemaVersion, in stream order. */ readonly schemaVersions: readonly SchemaRise[]; /** The last seq read (the checkpoint's coversSeq when the window is empty). */ readonly after: number; /** The server's head seq. */ readonly head: number; } /** * Read the segments after `parent` up to `upTo` (inclusive; the head when * omitted), verified by the journal client: each transaction's declared * deltas (`txnDeltas`, or a segment/v2's whole deltas as transaction 0). * * @param journal - The stream's journal client. * @param parent - The checkpoint the window starts after. * @param signers - The account's trusted signers. * @param upTo - The last seq to include. * @returns The window. */ export declare function readJournalWindow(journal: Journal, parent: Pick, signers: TrustedSigners, upTo?: number): Promise; /** A window's accounting (the v3 manifest fields) and the rows it leaves per manifest key. */ export interface JournalTallies { /** Per manifest key: parent rows + applied creates - applied deletes - voided. */ readonly rows: Record; /** Transactions not applied yet (the window's and the parent's still waiting). */ readonly pending: TxnRef[]; /** Effects of applied transactions that did not land. */ readonly voided: DeclaredTxn[]; /** Applied transactions whose effects all count (candidates for {@link settleShortfalls}). */ readonly applied: DeclaredTxn[]; } /** * The window's tallies as this store's inbox resolved it (§2.11 §3, §4). A * window transaction this store never staged (a segment past its pull, or a * vault delta segment) counts as applied; one staged and still open is * pending; a `void` one is voided whole. The parent's pending refs stay * pending until the inbox resolves them. * * @param db - The store (read only), or null for none (every transaction applied). * @param stream - The stream id. * @param parent - The checkpoint the window starts after. * @param window - The window ({@link readJournalWindow}). * @returns The tallies. */ export declare function journalTallies(db: DatabaseSync | null, stream: string, parent: Pick, window: Pick): JournalTallies; /** * Explain the difference between the store's rows and the tallies as voided * effects of applied transactions: fewer rows than tallied voids declared * creates, more rows voids declared deletes, never beyond a transaction's * declared counts (§2.11 §4). What no declared count explains is returned * unexplained, and the checkpoint must not be written. * * shortcut: the applier records no per-op tallies, so a partial void is * attributed by count to the window's applied transactions in order, not to * the exact op; the server rule (counts within each declared transaction) * still holds. Upgrade when the replay records per-op outcomes. * * @param tallies - The window's tallies. * @param local - The store's rows per manifest key. * @param keys - The keys to settle (the journal's tables). * @returns The tallies with the extra voids, and the keys left unexplained. */ export declare function settleShortfalls(tallies: JournalTallies, local: Readonly>, keys: readonly string[]): { tallies: JournalTallies; unexplained: string[]; }; //# sourceMappingURL=journal-tallies.d.ts.map