/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Optimise in the Calendar (#1409, #1417; `Optimise Spec.md` §5.1, §9.5, R24): * the window in view and its backlog as the run's request — every event kind's * rows in the window and its backlog by slot and by key, as the session holds * them, drafts in place, and every resource kind's rows as context — and the * result landed on the calendar's events as one edit: the diff by key, kind * by kind, recorded as one step (`ScheduleEditing.record`, origin * `optimise`), and the operations the landing draws — an add on the canvas, * a change with a ghost where the event was, a remove — kept until Apply. * * @packageDocumentation */ import { SortedMap, type EastType } from "@elaraai/east"; import { type OptimiseOp } from "../shared/func/optimise-diff.js"; import type { OptimiseCounts } from "../shared/func/use-optimise.js"; import type { ScheduleEditing } from "../shared/schedule/editing.js"; import type { CalendarCommands } from "./actions.js"; import type { CalendarItem, CalendarRange, CalendarValue } from "./model.js"; /** A kind's rows by key, as the request and the result carry them. */ type Rows = SortedMap; /** The run's request: the window, the run's number, each event kind's rows by slot, and each resource kind's. */ export interface CalendarOptimiseRequest { readonly from: Date; readonly to: Date; readonly run: bigint; readonly events: Readonly>; readonly resources: Readonly>; } /** The run's answer: each event kind's rows by slot, complete. */ export interface CalendarOptimiseResult { readonly events: Readonly>; } /** One operation a run left on an event, and the run that made it — its provenance's `run #n`. */ export type CalendarOp = OptimiseOp & { readonly run: string; }; /** * What the runs left on the Calendar's events, until Apply (R17): each * operation by event (`opKey`), a later run's over an earlier's on the same * event, and where a removed or a moved event stood before its run — its * ghost's place. */ export interface CalendarOptimised { /** Each operation, under `opKey(kind, id)`, with the run that made it. */ readonly ops: ReadonlyMap; /** Each changed or removed event as it stood before its run, under `opKey(kind, id)`. */ readonly previous: ReadonlyMap; /** Whether the latest run moved an event into or out of the backlog: the Backlog tab's count flashes. */ readonly backlogChanged: boolean; } /** * The request and result types over the Calendar's kinds: what the bound * optimiser is called with, as the tag held it to. * * @param value - The payload * @returns The request and result East types */ export declare function calendarOptimiseTypes(value: CalendarValue): { request: EastType; result: EastType; }; /** * The run's request (R1, R24, O3, O5): the window, the run's number, every * event kind's rows in the window and its backlog by key, as the session * holds them — base plus every unapplied draft, every row whatever the rail * shows — and every resource kind's rows, read whole. * * @param value - The payload * @param editing - The editing: where each event's row is read, drafts in place * @param range - The window in view * @param items - The window's events, as read * @param backlog - The kinds' backlog, as read * @param run - The run's number * @returns The request */ export declare function calendarOptimiseRequest(value: CalendarValue, editing: ScheduleEditing, range: CalendarRange, items: readonly CalendarItem[], backlog: readonly CalendarItem[], run: number): CalendarOptimiseRequest; /** * The result landed (R7, R8, R10, §12): diffed against the request by key, * kind by kind, and recorded as one step of the history, origin `optimise`. * The operations the landing draws are told by place (§9.5): a backlog row * the result gives a time is an add on the canvas, a scheduled event it takes * back to the backlog a remove, a moved event a change with a ghost at its old * slot. A result that answers no rows for a kind the request asked is * invalid, and nothing is recorded. A result that changes nothing records * nothing and leaves what earlier runs left as it is (R10); one that does * lays its operations over theirs. * * @param value - The payload * @param editing - The editing the step is recorded in * @param request - The request the result answers * @param result - The result * @param label - The step's label — `Elara run #7` * @param items - The window's events as they stood before the run: where a ghost goes * @param backlog - The backlog as it stood before the run * @param runText - The run's number, formatted, for the provenance * @param before - What earlier runs left on the events, still the session's drafts * @returns What the run counted, and what the runs have left on the events — unchanged by a run that changed nothing; `undefined` for an invalid result, or one the session would not take */ export declare function landCalendarOptimise(value: CalendarValue, editing: ScheduleEditing, request: CalendarOptimiseRequest, result: CalendarOptimiseResult, label: string, items: readonly CalendarItem[], backlog: readonly CalendarItem[], runText: string, before: CalendarOptimised | undefined): { counts: OptimiseCounts; optimised: CalendarOptimised | undefined; } | undefined; /** The operation a run left on an event, if any, with the run that made it: what its block draws and its hover says. */ export declare function calendarOpOf(optimised: CalendarOptimised | undefined, item: Pick): CalendarOp | undefined; /** * The commands while a run is out (R2): every gesture refused with the one * reason, the session they read kept — so the views keep drawing their drafts, * and the inspector stays live, while nothing is written. * * @param commands - The commands * @param refusal - Why a gesture is refused — `Elara is optimising Oct 5 – 9` * @returns The commands, locked */ export declare function lockCalendarCommands(commands: CalendarCommands, refusal: string): CalendarCommands; export {}; //# sourceMappingURL=optimise.d.ts.map