import type { DbAdminTableSchema, DbAdminMutation } from "../../db-admin/types.js"; /** * The staged-changeset model — the production-grade core of the table editor. * * Edits are NOT committed on blur. Instead every cell edit, new row, and * deletion accumulates here until the user explicitly commits (Cmd/Ctrl+S or * the Commit button), at which point {@link buildMutation} maps the staged * state into a single {@link DbAdminMutation}. Until then the grid renders the * staged values overlaid on the fetched rows, and the user can discard * everything. * * Rows are keyed by a stable primary-key string (the table's PK column values * joined). If a table has no primary key, edits target a full-row `where` * match instead, and the consumer should warn / disable editing. */ /** New rows get a temporary client id so the grid can track them pre-insert. */ export interface NewRow { /** Stable client-only id, e.g. `new:0`. Never sent to the server. */ _localId: string; values: Record; } export interface Changeset { /** rowPkString → { column → newValue }. */ edits: Map>; /** Staged inserts. */ newRows: NewRow[]; /** rowPkString of rows staged for deletion. */ deletedKeys: Set; } export interface UseChangesetResult { edits: Map>; newRows: NewRow[]; deletedKeys: Set; /** Whether editing is possible (requires a primary key on the table). */ canEdit: boolean; /** Stage a single cell edit on an existing row. */ setCell: (pk: string, col: string, value: unknown) => void; /** Stage many cell edits on one existing row at once. */ setCells: (pk: string, values: Record) => void; /** Append a blank new row (optionally seeded) and return its local id. */ addRow: (seed?: Record) => string; /** Patch a staged new row's values. */ setNewRowCell: (localId: string, col: string, value: unknown) => void; /** Remove a staged new row entirely. */ removeNewRow: (localId: string) => void; /** Stage existing rows for deletion (by pk string). Toggles off if re-staged. */ deleteRows: (pks: string[]) => void; /** Un-stage a deletion. */ undeleteRows: (pks: string[]) => void; /** Clear a single staged cell edit (revert to original). */ revertCell: (pk: string, col: string) => void; /** Drop everything. */ discardAll: () => void; /** Whether a given existing-row cell is dirty. */ isCellDirty: (pk: string, col: string) => boolean; /** The staged value for a cell, if any. */ getStagedCell: (pk: string, col: string) => { value: unknown; } | undefined; /** Whether an existing row is staged for deletion. */ isDeleted: (pk: string) => boolean; isDirty: boolean; /** Total count of pending changes (edited rows + new rows + deletions). */ pendingCount: number; /** * Build the mutation payload. `originalRows` maps pk string → the original * fetched row, used to construct the `where` clause for updates/deletes. */ buildMutation: (originalRows: Map>, dryRun?: boolean) => DbAdminMutation; } /** Compute the stable pk string for a row given the schema's primary key. */ export declare function pkStringFor(schema: DbAdminTableSchema | undefined, row: Record): string; export declare function useChangeset(schema: DbAdminTableSchema | undefined): UseChangesetResult; //# sourceMappingURL=changeset.d.ts.map