/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Optimise in the Sheet (#1409, #1418, east-workspace#1622; `Optimise Spec.md` * §5.1, §9.5, R25): the run's request — the run's number and the rail's * narrowing, and over one entry's rows the entry's key; no row: the function * reads the rows the sheet saves to, its unsaved edits laid over them — and * its answer, a patch of the rows the sheet's Save reaches, landed on the rows * the sheet holds as one edit: each key the patch touches recorded as one step * of the session (`session.record`, origin `optimise`), each row answered * lifted into its draft and projected to the wire row the source would show * for it (`editing.project`), and the operations the landing draws per cell — * a blank given a value an add, a value changed a change, a value cleared a * remove — kept until Apply. A row the answer changes that the sheet does not * hold is read by its key first (rule 8); one whose own edit is still * incomplete — a field missing, text that could not be read — refuses the * answer whole, naming the row (rule 11): the function read it as saved. * * @packageDocumentation */ import { DictType, type EastType, type ValueTypeOf, type option } from "@elaraai/east"; import { type SheetEntryOptimiseRequestType, type SheetOptimiseBindingType, type SheetOptimiseRequestType } from "@elaraai/e3-ui/internal"; import { type OptimiseLanded } from "../shared/func/optimise-diff.js"; import type { OptimiseSlice } from "../shared/func/optimise-slice.js"; import type { OptimiseMissing, OptimiseRefused } from "../shared/func/use-optimise.js"; import type { EntryUpdate, EntryVersion, Origin } from "./transactions.js"; import type { SheetCellValue, SheetNounValue, SheetRootValue } from "./values.js"; import type { SheetWords } from "./words.js"; /** A sheet's optimiser as its payload carries it: the function's binding, the record, the rows' type and the entry's key. */ export type SheetOptimiseBound = ValueTypeOf; /** * The run's request, as the form the sheet's optimiser takes types it: the run's number and the rail's narrowing — and, * over one entry's rows, the entry's key. */ export type SheetOptimiseRequest = ValueTypeOf | ValueTypeOf>; /** The run's answer: the patch of the rows the sheet's Save reaches. */ export interface SheetOptimiseResult { readonly rows: unknown; } /** What a run did to one cell (R25): a blank given a value, a value changed, or a value cleared. */ export type SheetCellOp = "add" | "chg" | "del"; /** What a run left on one row — an entry's own cells, a band's, or a line's — until Apply, and the run that did it. */ export interface SheetRowOps { /** The row's own operation: a row the run added, or one it changed. */ readonly op: "add" | "chg"; /** Each cell the run changed, by column key. */ readonly cells: ReadonlyMap; /** Each changed cell as it stood before the run, by column key: the provenance's `Was …`. */ readonly previous: ReadonlyMap; /** The run's number, formatted: the provenance's `run #n`. */ readonly run: string; } /** A row's marks as its row draws them. */ export type SheetRowMarks = SheetRowOps; /** * What the runs left on the sheet's rows (R17): each row's operations by its * id — an entry's or a band's under the entry's id, a line's under * `lineId(group, key)` — a later run's over an earlier's on the same row. */ export interface SheetOptimised { readonly rows: ReadonlyMap; } /** The sheet's optimiser's types: the request and the result over the rows its Save reaches, and the entry's key. */ export interface SheetOptimiseTypes { readonly request: EastType; readonly result: EastType; /** The rows the Save reaches, `Dict`: what the answer's patch is read by. */ readonly rows: DictType; /** * Over one entry's rows, the entry's key, which a request carries, and the key as East prints it — what names the * run's scope, so a run out stops as the entry does; `undefined` over the record's own entries. */ readonly entry: { readonly key: ValueTypeOf; readonly printed: string; } | undefined; } /** * The request and result types over the rows the sheet's Save reaches: what * the bound optimiser is called with, as the tag held it to — the request * with `entry` over one entry's rows. * * @param bound - The sheet's optimiser, as its payload carries it; `undefined` for a sheet with none * @returns The types, and the entry's key */ export declare function sheetOptimiseTypes(bound: SheetOptimiseBound | undefined): SheetOptimiseTypes; /** * The run's scope, as the eye, the footer line and the banner name it (§10): * the tab's rows counted in the sheet's own words — `8 work orders`, a * grouped sheet's `3 plans`. * * @param n - How many rows the tab holds * @param noun - A grouped sheet's word for a group; `undefined` on a flat sheet * @param rowsNoun - What the rail counts a flat sheet's rows in — `work orders`, else `rows` * @param words - The sheet's words * @returns The scope's label */ export declare function sheetOptimisePeriod(n: number, noun: SheetNounValue | undefined, rowsNoun: string, words: SheetWords): string; /** * The run's request (R1, R25, O3; east-workspace#1622, rule 1): the run's * number and the rail's narrowing — and, over one entry's rows, the entry's * key. No row: the function reads the rows the sheet saves to, the sheet's * unsaved edits laid over them. * * @param types - The optimiser's types: the entry's key, over one entry's rows * @param slice - Each rail source's narrowing now * @param run - The run's number * @returns The request */ export declare function sheetOptimiseRequest(types: Pick, slice: OptimiseSlice, run: number): SheetOptimiseRequest; /** What a landing is made over. */ export interface SheetLanding { /** The sheet's editing declaration: its row projection. */ readonly editing: Pick; readonly types: SheetOptimiseTypes; /** The entries' draft type. */ readonly draftType: EastType; /** Whether the source is keyed: a new row takes its key's place; else it lands at the end. */ readonly keyed: boolean; readonly result: SheetOptimiseResult; /** The step's label — `Elara run #7`. */ readonly label: string; /** The run's number, formatted, for the provenance. */ readonly runText: string; /** An entry's version as it stands: the session's, else the source's — absent for a row the sheet does not hold. */ readonly versionOf: (id: string) => EntryVersion; /** * A row as the sheet holds it, for the answer to land on: its draft where it has one, whole; `none` for a key no * row stands under — the record holds none, or the drafts removed it; `undefined` for one the sheet does not hold, * or is still reading by its key. */ readonly held: (id: string) => option | undefined; /** Whether the sheet's edit of a row is still incomplete — a field missing, text that could not be read. */ readonly incomplete: (id: string) => boolean; /** A row as a refusal names it: its row's words, else its key. */ readonly nameOf: (id: string) => string; /** Records the versions as one transaction of the session; answers whether it did. */ readonly record: (updates: readonly EntryUpdate[], origin: Origin, label: string) => boolean; /** What earlier runs left on the rows, still the session's drafts. */ readonly before?: SheetOptimised | undefined; } /** * The result landed (R7, R8, R10, R25, §12; east-workspace#1622, rules 7, 8, * 10, 11): the answer's patch landed key by key on the rows the sheet holds, * and recorded as one step of the session, origin `optimise` — each row * answered lifted into its draft, its wire row the source's projection of it; * a row the answer deletes, removed; a new row placed at its key's place on a * keyed source, else at the end. An answer that changes nothing records * nothing and leaves what earlier runs left as it is (R10); one that changes * rows lays its marks over theirs. One that changes a row whose own edit is * still incomplete is refused whole, naming the row; one that touches a row * the sheet does not hold names it, to be read by its key. * * @param args - What the landing is made over * @returns What the run counted, and what the runs have left on the rows — unchanged by a run that changed nothing; * the rows to read first; a refusal, naming the row; `undefined` for an answer that does not fit the rows the sheet * holds, or one the session would not take */ export declare function landSheetOptimise(args: SheetLanding): OptimiseLanded | OptimiseMissing | OptimiseRefused | undefined; //# sourceMappingURL=optimise.d.ts.map