/** * Uid aliases the applier follows (T13397; T12341 §6.4 step 1, journal spec * §2.6 "K ops"). * * A held uid collision (T13394) settles when the loser's origin re-keys its * row and publishes the K. A receiver where the winner owns the uid never * placed the loser, so it records the K as an alias only * ({@link recordUidAlias}). Every staged transaction then reads through the * aliases ({@link followUidAliases}) before it is planned: * * - **the loser's own ops**: an op naming (uid, birth fingerprint) of a * re-keyed row takes the new uid. The winner keeps the uid with another * fingerprint, so it is never matched; * - **references**: a reference to the old uid written by a replica that * had placed the loser, before that replica's K, meant the loser, so it * takes the new uid. The origin's K draws that boundary for the origin. * Any other replica that placed the loser first (a third replica the * origin's insert reached before the winner's) announces the re-key under * its own name once it applies the origin's K (T13399, * store/sync/collision-settle `announcePlacedRekeys`): an alias-only K * that draws its own boundary. A reference written after the writer's * boundary, or by a replica that never placed the loser, means the winner * and is left alone. * * The aliases are local-only: each replica derives them from the K ops it * applied. {@link recordUidAlias} writes them; {@link markAliasPlaced} and * {@link markAliasAnnounced} track the announcement this replica owes. * * @module store/sync/uid-alias * @task T13397 */ import type { DatabaseSync } from 'node:sqlite'; import type { CaptureTableDef } from './capture.js'; import type { StagedTxn } from './inbox.js'; import { UID_ALIAS_JOURNAL_TABLE, UID_REF_ALIAS_JOURNAL_TABLE } from './schema.js'; export { UID_ALIAS_JOURNAL_TABLE, UID_REF_ALIAS_JOURNAL_TABLE }; /** One re-keyed row, as a K op names it. */ export interface UidAlias { readonly table: string; readonly oldUid: string; /** The row's birth fingerprint before the re-key (the K's `obfp`). */ readonly oldBfp: string; readonly newUid: string; /** The replica that wrote the K. */ readonly origin: string; /** The K's HLC. */ readonly hlc: string; } /** * Record a re-key as an alias. The first record of a (table, uid, * fingerprint) wins: a re-delivered K changes nothing. * * @param db - The store, inside the apply frame's transaction. * @param alias - The re-keyed row. * @param nowIso - The time. */ export declare function recordUidAlias(db: DatabaseSync, alias: UidAlias, nowIso: string): void; /** * Applying a K moved a loser this replica had placed, and another replica * wrote the K (T13399): this replica owes the re-key's announcement, since * its own earlier references to the old uid meant the loser. * * @param db - The store, inside the apply frame's transaction. * @param table - The re-keyed row's table. * @param oldUid - Its uid before the K. * @param oldBfp - Its birth fingerprint. */ export declare function markAliasPlaced(db: DatabaseSync, table: string, oldUid: string, oldBfp: string): void; /** One announcement this replica owes ({@link markAliasPlaced}). */ export interface OwedAnnouncement { readonly table: string; readonly oldUid: string; readonly oldBfp: string; readonly newUid: string; } /** * The re-key announcements this replica owes, oldest first. * * @param db - The store. */ export declare function owedAnnouncements(db: DatabaseSync): OwedAnnouncement[]; /** * The announcement of `a` was captured (T13399). * * @param db - The store, inside the announcing transaction. * @param a - The announced re-key. * @param nowIso - The time. */ export declare function markAliasAnnounced(db: DatabaseSync, a: OwedAnnouncement, nowIso: string): void; /** * A staged transaction read through the uid aliases (module doc). Unchanged, * and the same object, when nothing is aliased. * * @param db - The store. * @param st - The staged transaction. * @param defs - Capture definitions by table (for reference columns). * @returns The transaction its planning and apply see. */ export declare function followUidAliases(db: DatabaseSync, st: StagedTxn, defs: (table: string) => CaptureTableDef | null): StagedTxn; //# sourceMappingURL=uid-alias.d.ts.map