/** * Typed-rule field state that row meta has no place for (T12344; journal spec * §3.6, inventory §3.6.6 `task.status.absorbing`, `task.pipeline-stage.max`). * * - **Leaves.** An absorbing write (a task cancelled or done) overrides a * newer ordinary edit of its column, unless an explicit leave (a reopen …) * newer than it produced the current value; a rank-max restore raises a * floor below which writes are dead. Both are `FieldState.leave`. * - **Frontiers.** A rank-max column keeps its alive candidate writes * (`FieldState.frontier`), so a later restore still finds the next best. * * Every replica must know both, whether applied from the stream or authored * here, so `_sync_field_leave` keeps them per (tbl, uid, col): * - the apply engine records what its merge decided; * - the sealer records a local leave: a sealed U whose `actor.op` is a leave * op of the column's absorbing rule moving it off an absorbing value, or a * restore op of its rank-max rule — the cases in which a receiving * replica's merge records the same leave; * - a delete clears the row's state with its fields. * * @module store/sync/field-leave * @task T12344 */ import type { DatabaseSync } from 'node:sqlite'; import { LedgerWireValue } from '@cleocode/contracts/ledger'; /** Column → encoded HLC of its latest explicit leave. */ export type FieldLeaves = Readonly>; /** A rank-max column's alive candidate writes, oldest first. */ export type FieldFrontier = ReadonlyArray<{ readonly value: LedgerWireValue; readonly hlc: string; }>; /** * The row's recorded leaves. * * @param db - The store (the journal schema applied). * @param tbl - Sync-set table. * @param uid - Row uid. * @returns Column → leave HLC; empty when none. */ export declare function readFieldLeaves(db: DatabaseSync, tbl: string, uid: string): FieldLeaves; /** * Record leaves; a stored leave newer than the incoming one is kept. * * @param db - The store, inside the writer's transaction. * @param tbl - Sync-set table. * @param uid - Row uid. * @param leaves - Column → leave HLC. */ export declare function recordFieldLeaves(db: DatabaseSync, tbl: string, uid: string, leaves: FieldLeaves): void; /** * The row's rank-max frontiers. * * @param db - The store (the journal schema applied). * @param tbl - Sync-set table. * @param uid - Row uid. * @returns Column → frontier; empty when none. */ export declare function readFieldFrontiers(db: DatabaseSync, tbl: string, uid: string): Readonly>; /** * Set rank-max frontiers as the merge left them; `null` clears one (the * current value is the only candidate again). * * @param db - The store, inside the writer's transaction. * @param tbl - Sync-set table. * @param uid - Row uid. * @param frontiers - Column → frontier, or null. */ export declare function setFieldFrontiers(db: DatabaseSync, tbl: string, uid: string, frontiers: Readonly>): void; /** * Forget the row's leaves (its delete). * * @param db - The store, inside the writer's transaction. * @param tbl - Sync-set table. * @param uid - Row uid. */ export declare function clearFieldLeaves(db: DatabaseSync, tbl: string, uid: string): void; /** * The explicit leaves a locally authored U op makes: per absorbing-rule * column, `actorOp` is one of the rule's leave ops and the column moves from * an absorbing value (`b`) to an ordinary one (`a`); per rank-max column the * op writes, `actorOp` is one of the rule's restore ops. * * @param tbl - Sync-set table. * @param op - The sealed op's changed values, before-image and HLC. * @param actorOp - The transaction's `actor.op`, or null. * @returns Column → `op.h` for every leave; empty when none. */ export declare function localLeaves(tbl: string, op: { readonly a?: Readonly>; readonly b?: Readonly>; readonly h: string; }, actorOp: string | null): FieldLeaves; /** * The `op` of a frame or transaction actor (JSON of a `LedgerActor`), or * null when the actor is absent, not JSON (a bare label such as * `fk_orphans`) or names no op. * * @param actor - The stored actor text. * @returns The actor's op, or null. */ export declare function actorOpOf(actor: string | null): string | null; /** * The stored rank-max frontiers a locally authored U op changes (T13232): * the local write joins each frontier the row already has, pruned exactly as * the merge prunes it, so the stored state stays the one every replica * folding the same writes holds. A frontier left with one candidate is * cleared (`null`). Columns without a stored frontier need nothing: the row's * own value is their only candidate. * * @param db - The store, inside the sealer's transaction. * @param tbl - Sync-set table. * @param uid - Row uid. * @param op - The sealed op's changed values and HLC. * @param leaves - The leaves this op records ({@link localLeaves}). * @returns Column → new frontier, or null to clear it. */ export declare function localFrontierUpdates(db: DatabaseSync, tbl: string, uid: string, op: { readonly a?: Readonly>; readonly h: string; }, leaves: FieldLeaves): Record; /** * Move the row's typed-rule state to its new uid on a re-key. * * @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. */ export declare function moveFieldState(db: DatabaseSync, tbl: string, oldUid: string, newUid: string): void; /** A row's typed-rule state as a rebase snapshot keeps it. */ export interface FieldStateSnapshot { readonly leaves: FieldLeaves; readonly frontiers: Readonly>; } /** * Put a row's typed-rule state back exactly as a snapshot holds it (none * when null). A rebase rewind's writer (T13193). * * @param db - The store, inside the rebase frame. * @param tbl - Sync-set table. * @param uid - Row uid. * @param state - The snapshot, or null. */ export declare function restoreFieldState(db: DatabaseSync, tbl: string, uid: string, state: FieldStateSnapshot | null): void; //# sourceMappingURL=field-leave.d.ts.map