/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Optimise in the Roster (#1409, #1421, east-workspace#1622; `Optimise Spec.md` * §5.1, §9.5, R23): the run's request — the period the Roster shows and what * kind it is (the day in Shifts' Day, the week, the month), the run's number * and the rail's narrowing, and no row — and its answer, a patch of the duties' * record, landed on the duties the page holds as one edit: each key the patch * touches, recorded as one step (`ScheduleEditing.record`, origin `optimise`), * and what the landing draws kept until Apply — each duty's operation and its * provenance, on the People view's tiles and the Shifts view's chips alike, * and the people whose hours the latest run changed. While a run is out the * commands are locked (R2): every gesture refused in the one reason, the * drafts kept. * * An optimiser that takes the edges (#1553) is also told which duties its * answer must leave as they are (`fixed`): those the period's window holds — * the period, and the twelve hours either side — whose own period takes no * edit, or that the Roster places in no week it holds. Its answer may change a * duty at an edge, in the weeks either side. * * An answer that would change what a gesture could not is refused whole, * naming the duty, and records nothing (rule 11): a fixed duty changed or * removed, a duty of a period that takes no edit, one put in such a period or * beyond the weeks the Roster holds — and, for an optimiser that does not take * the edges, a duty outside the period it was asked of, as the page holds it * or as the answer leaves it: by its times, or by the week the Roster places it * in, which such a run holds the period's alone — a night shift that starts * before the period and ends in it stands in the week before. A duty the * answer changes that the page does not hold is read by its key first (rule 8). * * @packageDocumentation */ import { DictType, SortedSet, type EastType, type ValueTypeOf, type option } from "@elaraai/east"; import { type RosterOptimiseEdgesRequestType, type RosterOptimiseRequestType } from "@elaraai/e3-ui/internal"; import { type Formatters } from "@elaraai/east-ui-components"; 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 { RosterCommands } from "./actions.js"; import type { RosterEditing } from "./editing.js"; import type { RosterOptimiseWords } from "./messages.js"; import { type Assignment, type DraftedDuty, type RosterDomain, type RosterValue, type StoredDuty } from "./model.js"; /** The period the Roster shows, as a run asks it: its bounds, half open, and which kind it is. */ export interface RosterOptimisePeriod { readonly from: Date; readonly to: Date; readonly period: "day" | "week" | "month"; } /** * The run's request: the period in view and its kind, the run's number and the rail's narrowing — and for an optimiser * that takes the edges (#1553), `fixed`, the keys of the duties in the period's window its answer must leave as they are. */ export type RosterOptimiseRequest = ValueTypeOf | ValueTypeOf; /** The run's answer: the patch of the duties' record. */ export interface RosterOptimiseResult { readonly duties: unknown; } /** * Where the Roster would place a duty's row among the weeks it holds — the span's, and for an optimiser that takes the * edges (#1553) the weeks either side, each with its periods as the session holds them: placed, in the week it falls in, at its place there, and * whether its period takes edits; a row it cannot place, in the week its day falls in, which takes it while every period * of that week does — it lands as that week's issue; or beyond them, `at` its start. */ export type RosterReached = { readonly type: "placed"; readonly start: Date; readonly assignment: Assignment; readonly open: boolean; } | { readonly type: "unplaced"; readonly start: Date; readonly at: Date; readonly open: boolean; } | { readonly type: "beyond"; readonly at: Date; }; /** Where the Roster would place a duty's row, by its key (see {@link RosterReached}). */ export type RosterReach = (row: unknown, key: string) => RosterReached; /** One operation a run left on a duty, until Apply (R17): what it did, the run that made it, and what its hover says. */ export interface RosterDutyOp { readonly op: "add" | "chg" | "del"; /** The run's number, formatted. */ readonly run: string; /** `Added by Elara · run #7`, `Was Mon Early · Inbound · Elara run #7`, or `Removed by Elara · run #7`. */ readonly provenance: string; } /** * What the runs left on the Roster's duties, until Apply (R17): each duty's * operation, a later run's over an earlier's on the same duty — a removed * duty's drawn on its tombstone, struck, for the highlight — and the people * whose week the latest run changed, whose hours and meter flash. */ export interface RosterOptimised { readonly ops: ReadonlyMap; readonly people: ReadonlySet; } /** What the bound optimiser is called with, as the tag held it to, and the duties' record type. */ export interface RosterOptimiseTypes { readonly request: EastType; readonly result: EastType; /** The duties' record type, `Dict`: what the answer's patch is read by. */ readonly record: DictType; } /** * The request and result types over the app's duty row type: what the bound * optimiser is called with, as the tag held it to — the request with `fixed` * where its function takes the edges (#1553). * * @param rowType - The duty kind's row type * @param edges - Whether the optimiser takes the duties at the edges * @returns The request and result East types, and the duties' record type */ export declare function rosterOptimiseTypes(rowType: EastType, edges: boolean): RosterOptimiseTypes; /** * The duties a run's answer must leave as they are (#1553): every duty the period's window holds — the period, and the * twelve hours either side — as the session holds it, a stored one a draft holds in its draft's place and one a draft * removes absent, whose own period takes no edit, or that the Roster places in no week it holds. * * @param args - The window's stored duties, every draft of the session, the period in view, and where a row would stand * @returns Their keys */ export declare function rosterFixed(args: { stored: ReadonlyMap; drafts: ReadonlyMap; period: Pick; reach: RosterReach; }): SortedSet; /** * The run's request (R1, R23, O3; east-workspace#1622, rule 1): the period the Roster shows and its kind, the run's * number and the rail's narrowing — and, for an optimiser that takes the edges, the keys of the duties its answer must * leave as they are (#1553). No row: the function reads the duties, the targets and the staff itself, the Roster's * unsaved edits laid over them. * * @param period - The period in view * @param slice - Each rail source's narrowing now * @param run - The run's number * @param fixed - The duties the answer must leave ({@link rosterFixed}), for an optimiser that takes the edges * @returns The request */ export declare function rosterOptimiseRequest(period: RosterOptimisePeriod, slice: OptimiseSlice, run: number, fixed?: SortedSet): RosterOptimiseRequest; /** * Where a duty stands, as its provenance says it: its day and its shift, its * own times where they differ from the shift's, and its group — or No group, * for a duty in none (#1548), which a run placing it changes alone — `Mon * Early · Inbound`, `Mon Early 07–15 · No group`. * * @param value - The payload: the shifts, the groups and the words * @param format - The app's formatters * @param a - The duty * @param start - The week's first day * @returns The words */ export declare function rosterDutyWords(value: RosterValue, format: Pick, a: Assignment, start: Date): string; /** * A duty as a refusal names it (#1553): whose it is, its day and date, its shift — its own times where they differ — * and its group; one the Roster cannot place, by its start — `N. Ochre · Sat Mar 4 Night · Inbound`, `a duty starting * Mon, Mar 20, 2028`. * * @param value - The payload: the people, the shifts, the groups and the words * @param format - The app's formatters * @param reached - Where the duty stands * @returns The words */ export declare function rosterDutyName(value: RosterValue, format: Pick, reached: RosterReached): string; /** What a landing is made over. */ export interface RosterLanding { readonly value: RosterValue; readonly domain: RosterDomain; /** The duties' record type. */ readonly types: RosterOptimiseTypes; /** The editing the step is recorded in. */ readonly editing: RosterEditing; /** A row as the page holds it, read by its key where it holds none: what the answer lands on. */ readonly held: (kind: string, id: string) => option | undefined; readonly request: RosterOptimiseRequest; readonly result: RosterOptimiseResult; /** The step's label — `Elara run #7`. */ readonly label: string; /** The run's number, formatted, for the provenance. */ readonly runText: string; /** The period's words, which a refusal names. */ readonly period: string; /** The app's formatters, for the provenance's and a refusal's words. */ readonly format: Pick; /** What earlier runs left on the duties, still the session's drafts. */ readonly before: RosterOptimised | undefined; /** Where a row would stand among the weeks the Roster holds, as their periods stand as the result lands. */ readonly reach: RosterReach; /** Whether the optimiser takes the edges (#1553): its answer may change a duty outside the period, in the weeks either side. */ readonly edges: boolean; /** Whether the periods are days: what a refusal names a period. */ readonly days: boolean; readonly m: RosterOptimiseWords; } /** * The result landed (R7, R8, R10, §12; east-workspace#1622, rules 7, 8, 10, * 11): the answer's patch landed key by key on the duties the page holds, and * recorded as one step of the history, origin `optimise`. A duty the answer * adds is an add — Off → shift; one it changes is a change — shift → another, * or its own times; one it drops is a remove — shift → Off, its tombstone * struck for the highlight (§9.5). An answer that changes nothing records * nothing and leaves what earlier runs left as it is (R10); one that does * lays its operations over theirs. One that changes what a gesture could not, * or a duty outside the period it was asked of ({@link refusal}), is refused, * naming the duty, recording nothing; one that touches a duty the page 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 duties — unchanged by a run that changed nothing; * the duties to read first; a refusal's words for an answer the Roster refuses; `undefined` for an answer that does * not fit the duties the page holds, or one the session would not take */ export declare function landRosterOptimise(args: RosterLanding): OptimiseLanded | OptimiseMissing | OptimiseRefused | undefined; /** * The commands while a run is out (R2): every gesture refused with the one * reason — `Elara is optimising W11` — the week's drafts kept, so the views * keep drawing them while nothing is written; Publish off. The reason is * `locked`, so the week's controls stay in place, inert, rather than reading * as a week with no edit. * * @param commands - The commands * @param refusal - Why a gesture is refused * @returns The commands, locked */ export declare function lockRosterCommands(commands: RosterCommands, refusal: string): RosterCommands; //# sourceMappingURL=optimise.d.ts.map