/** * The persisted HLC clock (journal spec §1.4). * * `_sync_clock(replica_id, phys, ctr)` is local-only. It is read and written * only inside the caller's `BEGIN IMMEDIATE` transaction (every seal and every * apply), so two processes serialize on the SQLite write lock and no clock * state lives in process memory across transactions. * * @task T12342 * @module store/sync/clock-store */ import type { DatabaseSync } from 'node:sqlite'; import { type Hlc } from './hlc.js'; /** * Journal tables whose `hlc` column can hold this replica's timestamps. The * clock heals to their maximum on open, which covers a store restored from a * copy taken between a seal and its clock write. They arrive with the sealer * (S3); a missing table is skipped. */ export declare const CLOCK_HEAL_SOURCES: ReadonlyArray<{ table: string; column: string; }>; /** * `_sync_meta` key: the server's clock as push last observed it (§1.3), JSON * `{offsetMs, atMs}` — `offsetMs` is the server's date minus this device's * clock, `atMs` this device's clock when it was observed. */ export declare const SERVER_CLOCK_KEY = "sync.server_clock"; /** How long an observed server date bounds sealing (§1.3: "a server date from the last 24 h"). */ export declare const SERVER_CLOCK_TTL_MS: number; /** * The highest physical candidate a seal may use now (journal spec §1.3, local * clock ahead): the server's date, estimated from the last observed offset, * plus `MAX_DRIFT`. Null when no server date from the last 24 h is known, the * record is unreadable, or this clock was set back since the observation (a * corrected clock: the offset no longer holds): sealing is then unclamped. * Read-only. * * @param db - The store. * @param nowMs - This device's clock. * @param maxDriftMs - The bound; defaults to {@link MAX_DRIFT_MS}. */ export declare function sealWallCeiling(db: DatabaseSync, nowMs: number, maxDriftMs?: number): number | null; /** * The stored clock of a replica, or its genesis when none is stored. */ export declare function loadClock(db: DatabaseSync, replica: string): Hlc; /** Store a clock value. Caller holds the transaction. */ export declare function storeClock(db: DatabaseSync, h: Hlc): void; /** * Issue the next local HLC and persist the clock. Caller holds the * transaction. * * @param wallMs - The physical candidate (§1.2). * @returns The issued timestamp, encoded. */ export declare function tickClock(db: DatabaseSync, replica: string, wallMs: number): string; /** * Merge a received HLC into the persisted clock, unless it is beyond the skew * bound: then nothing is written and the caller must hold the transaction * (see `SkewHold`). Caller holds the transaction. * * @returns `{ held: false, clock }` after a merge, `{ held: true }` otherwise. */ export declare function receiveClock(db: DatabaseSync, replica: string, remote: string, nowMs: number, maxDriftMs?: number): { held: false; clock: string; } | { held: true; }; /** * Heal a replica's clock to the largest HLC it is known to have issued: the * stored clock, or the maximum of {@link CLOCK_HEAL_SOURCES}. Caller holds * the transaction. * * @returns The healed clock. */ export declare function healClock(db: DatabaseSync, replica: string, sources?: ReadonlyArray<{ table: string; column: string; }>): Hlc; /** * Run `fn` inside `BEGIN IMMEDIATE`, committing on return and rolling back * on a throw. The clock primitives above require such a transaction. */ export declare function withImmediateTransaction(db: DatabaseSync, fn: () => T): T; //# sourceMappingURL=clock-store.d.ts.map