/** * The one writer of `_sync_row_meta` (journal spec §1.6; T13204). * * Row meta holds a row's replication facts: `hlc` (the newest field HLC), * `fhlc` (only the columns whose HLC is OLDER than `hlc`, so a row whose * fields all share one HLC stores none), the origin replica and actor, the * version, the tombstone flag, the natural key, the content hash and the * birth fingerprint. The sealer writes it for local ops; the apply engine * (T12344) writes it for applied remote ops. Both go through this module, so * the `fhlc` compression can never disagree between them. * * @task T13204 * @module store/sync/row-meta */ import type { DatabaseSync } from 'node:sqlite'; /** A row's stored meta, as the writers read it back. */ export interface RowMetaRow { readonly hlc: string; readonly fhlc: string | null; readonly version: number; readonly deleted: number; readonly key_json: string | null; readonly chash: string | null; readonly bfp: string | null; } /** The columns a row's field HLCs cover: captured, minus identity. */ export interface FieldColumns { readonly columns: readonly string[]; readonly identity: readonly string[]; } /** One row-meta write. */ export interface RowMetaWrite { readonly tbl: string; readonly uid: string; /** The newest field HLC of the row. */ readonly hlc: string; /** Compressed field HLCs ({@link compressFieldHlcs}), or null. */ readonly fhlc: string | null; /** The replica the newest change came from. */ readonly origin: string; readonly actor: string | null; readonly version: number; readonly deleted: boolean; /** The natural key (canonical JSON); kept when null. */ readonly keyJson?: string | null; /** The content hash, or null (recomputed by the sealer later). */ readonly chash?: string | null; /** The birth fingerprint; kept when null. */ readonly bfp?: string | null; } /** The row's stored meta, or undefined. */ export declare function readRowMeta(db: DatabaseSync, tbl: string, uid: string): RowMetaRow | undefined; /** Write one row's meta (insert, or replace its facts; key and bfp are kept when absent). */ export declare function upsertRowMeta(db: DatabaseSync, w: RowMetaWrite): void; /** * Compress a row's full per-field HLC map against its row HLC (§1.6): keep * only the columns whose HLC is older than `rowHlc`. Identity columns carry * no field HLC. * * @returns Canonical JSON of the kept columns, or null when none. */ export declare function compressFieldHlcs(def: FieldColumns, fieldHlc: Readonly>, rowHlc: string): string | null; /** A row's full per-field HLC map from its stored meta (a column absent from `fhlc` is at `hlc`). */ export declare function fieldHlcsOf(def: FieldColumns, prev: RowMetaRow): Record; /** * The `fhlc` after a local op at HLC `h` changed `changed` (the sealer's * rule): changed columns move to `h`, the rest keep theirs. A row with no * meta yet has every field at `h`, so none is stored. A changed column in * `pins` moves to its pinned HLC instead (a copy reconcile's rule-3 op, * §1.5 N7, T13335). */ export declare function nextFhlc(prev: RowMetaRow | undefined, def: FieldColumns, changed: readonly string[], h: string, pins?: Readonly>): string | null; /** A row-meta write fed from a full per-field HLC map (the apply engine). */ export interface RowMetaFromFields { readonly tbl: string; readonly uid: string; /** Field HLCs after the merge (identity columns ignored); partial only when the row has meta. */ readonly fieldHlc: Readonly>; readonly origin: string; readonly actor: string | null; readonly deleted: boolean; readonly keyJson?: string | null; readonly chash?: string | null; readonly bfp?: string | null; } /** * Write a row's meta from its per-field HLC map: `hlc` is the newest field * HLC, `fhlc` holds only the older ones, and the version rises by one. * * The map may be partial when the row already has meta: an absent column * keeps the field HLC it had (never silently advanced to the new row HLC), * and a named column keeps the newer of its stored and incoming HLC (never * moved back, T13207). A write in which no named field wins writes nothing: * the losing op's origin, actor, tombstone and content hash never land. * A row's first write must name every non-identity column. * * @returns The row HLC written. * @throws {Error} When the map is empty, or a first write misses a column. */ export declare function upsertRowMetaFromFields(db: DatabaseSync, def: FieldColumns, w: RowMetaFromFields): string; /** * Move a row's meta to its new uid on a re-key (journal spec §2.5 step 5): * `hlc`, `fhlc`, `version` and `chash` stay; `bfp` takes the new birth * fingerprint when one is given. The caller has checked that no meta row * exists at the new uid. * * @param db - The store, inside the writer's transaction. * @param tbl - Sync-set table. * @param oldUid - The row's uid before the re-key. * @param newUid - Its uid after. * @param bfp - The new birth fingerprint, or null to keep it. */ export declare function moveRowMeta(db: DatabaseSync, tbl: string, oldUid: string, newUid: string, bfp: string | null): void; /** A row's complete stored meta, every column (what a rebase snapshot keeps). */ export interface RowMetaFull { readonly hlc: string; readonly fhlc: string | null; readonly origin: string; readonly actor: string | null; readonly version: number; readonly deleted: number; readonly key_json: string | null; readonly sent: number; readonly fk_excluded: number; readonly held: number; readonly chash: string | null; readonly shash: string | null; readonly bfp: string | null; } /** * The row's complete stored meta, or undefined (T13193: what a rebase * snapshots before a local op, so a rewind restores it exactly). * * @param db - The store. * @param tbl - Sync-set table. * @param uid - Row uid. * @returns Every meta column, or undefined. */ export declare function readRowMetaFull(db: DatabaseSync, tbl: string, uid: string): RowMetaFull | undefined; /** * Put a row's meta back exactly as a snapshot holds it, or remove it when the * snapshot is null (the row had no meta). A rebase rewind's writer. * * @param db - The store, inside the rebase frame. * @param tbl - Sync-set table. * @param uid - Row uid. * @param meta - The snapshot, or null. */ export declare function restoreRowMeta(db: DatabaseSync, tbl: string, uid: string, meta: RowMetaFull | null): void; //# sourceMappingURL=row-meta.d.ts.map