/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type option } from "@elaraai/east"; import { type EditSession } from "@elaraai/east-ui-components"; import { type IndexMaintenances } from "../../platform/indexed-paged.js"; /** * What a drafted row's Save would change in one index, by entry: each an op * of the index's own East patch (`insert`, `update`, `delete`) or a summary * index's `add`, as e3's maintenance gives them, in the index's entry order. */ export type IndexChanges = ReadonlyMap; /** * One drafted row's Save, previewed: what it changes in each index. * * @property key - The row's key * @property state - `previewed`: the changes are e3's for this Save. `reading`: the row is being read at the revision * the builder reads. `stale`: the draft's change does not apply to the row as e3 now holds it — another session * changed the same value — so nothing is previewed. * @property changes - By index, what the Save would change; empty unless `previewed` */ export interface PreviewedRow { readonly key: unknown; readonly state: "previewed" | "reading" | "stale"; readonly changes: ReadonlyMap; } /** * What the part reads of a record's indexed binding (`Data.bindPaged(record, * { indexes })`, as a page holds it): the maintenance it carries, its * revision, and — through the runtime that built it — its rows by key. */ export interface RecordDraftsBinding { /** Each listed nested series and summary index's maintenance for one row, by its name; none where it lists neither. */ readonly maintenance: IndexMaintenances; /** The record's revision the binding reads; none while it resolves. */ revision(): option; } /** * The session the part reads: the record's, its entries the record's rows * whole, keyed by the record's key. A builder that pages a record's rows * without their collections — beside a nested series index — reads a row * whole as its first change is drafted, so the session's original is the row * as e3 holds it. */ export type RecordDraftsSession = Pick, "drafts" | "entryType" | "keyType">; /** * What a spec watches the part by: each run of a row's maintenance. Test use * only. */ export interface RecordDraftsProbe { /** Called for each drafted row whose maintenance runs, with its key. */ readonly ran?: (key: unknown) => void; } /** * Install (or clear) the probe the part's runs are watched by. Test use only. * * @param probe - What watches it; `undefined` clears it */ export declare function setRecordDraftsProbe(probe: RecordDraftsProbe | undefined): void; /** * A record's drafts in what e3 keeps (see the module docs): each drafted * row's Save previewed through a binding's maintenance. Its reads are tracked * where it runs — {@link useRecordDrafts} runs it in a tracked evaluation — so * a row read at a later revision previews once it lands. */ export declare class RecordDrafts { private readonly binding; private readonly session; /** Each drafted row's last preview, by the session's view of it. */ private previews; /** Each drafted row while it is read, by the session's view of it. */ private reads; /** The last answer: the same object while each row's preview is. */ private last; /** A row's change applied to it, as the Save's patch is: the row, or a `ConflictError` thrown where it does not apply. */ private readonly apply; /** A row's change, as the Save sends it: its patch, as an entry present or absent. */ private readonly change; /** A row's patch, where it is present before and after: what the maintenance follows. */ private readonly rowPatch; /** * @param binding - The record's indexed binding * @param session - The record's editing session * @throws {Error} When the session is no keyed source's */ constructor(binding: RecordDraftsBinding, session: RecordDraftsSession); /** * Each drafted row's Save, previewed, by its id: the same object while the * session's drafts, the binding's revision and the rows read at it stand. * * @returns The previewed rows; none where the binding carries no maintenance * @throws {Error} When a drafted row is to be read at a later revision and the binding's runtime reads no rows by key */ preview(): ReadonlyMap; /** Each drafted row's preview, by its id, as {@link RecordDrafts.preview} gives it. */ private answer; /** The answer, as the last one where it holds the same rows: the same object while each row's preview is. */ private kept; /** Every drafted row reading: the revision, or the rows at it, still in flight. */ private reading; /** * One drafted row's Save, previewed over the row as e3 holds it: kept * while its draft, the revision and the row stand. * * @param entry - The session's view of the drafted row * @param revision - The revision e3's row is held at * @param held - The row as e3 holds it there * @param maintain - Each index's maintenance, by its name * @returns The previewed row */ private previewed; } /** * A record's drafts in what e3 keeps (see the module docs), tracked: it reads * again as a draft moves, a row lands or the revision moves. * * @param binding - The record's indexed binding, as the page holds it: its maintenance and its revision, its rows read * by key through the runtime that built it * @param session - The record's editing session: each drafted row, as it began and as drafted * @returns Each drafted row's preview, by its id; none without a binding or a session * @throws {Error} As {@link RecordDrafts} does, through the evaluation's error */ export declare function useRecordDrafts(binding: RecordDraftsBinding | undefined, session: (RecordDraftsSession & Pick, "subscribe" | "getSnapshot">) | undefined): ReadonlyMap; //# sourceMappingURL=drafts.d.ts.map