/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * What the builders over the app's own records share (#1372, `Builder * Interfaces Spec.md` §7): the Roster's and the Allocation's. A new row's key, * minted unique among every key the builder holds (§7.6); a window of a * record kept at the revision it was read at, and a row read from it, which a * Save confirms its entries by and a gesture finds a row's original in * (`ScheduleRowRead`); the period's own row, read the same way; a record's * rows as bytes and back; a field of an event's row edited, as the kind writes * it; and Publish: Save first, then the period's status once every record * reads back as saved (§7.3). * * @packageDocumentation */ import { type EastTypeValue, type ValueTypeOf, type option } from "@elaraai/east"; import type { FieldSpecValue } from "@elaraai/east-ui/internal"; import { type ScheduleFieldWriteType, type ScheduleKindType, type SchedulePeriodsKindType } from "@elaraai/e3-ui/internal"; import type { EditHistory, EntryVersion } from "@elaraai/east-ui-components"; import type { ScheduleChange, ScheduleEditingRecord, ScheduleEntryRef, ScheduleRowRead } from "./editing.js"; /** A builder's periods, as the payload carries them. */ export type SchedulePeriodsValue = ValueTypeOf; /** A record's rows, as bytes and back: a period's, a target's, by their row type. */ export interface RowCodec { readonly encode: (row: unknown) => Uint8Array; readonly decode: (bytes: Uint8Array) => unknown; } /** * A record's row codec, made the first time its row type is seen — East * decides which types are the same. * * @param rowType - The row type * @returns Its codec */ export declare function rowCodec(rowType: EastTypeValue): RowCodec; /** One field written: its path, and its value as bytes at the field's type — what a kind's `write` and a record's `set` take. */ export type ScheduleFieldWrite = ValueTypeOf; /** * A field of a form edited, as a record's `set` and an event kind's `write` * take it: its path, and its value as bytes at the field's type — its form's * spec's, else the row's own field's. What every builder's inspector turns a * form's edit into. * * @param specs - The form's specs * @param rowType - The record's row type * @param path - The field's path * @param next - Its new value * @returns The write; `undefined` for a path no field is at */ export declare function fieldWrite(specs: readonly FieldSpecValue[], rowType: EastTypeValue, path: readonly string[], next: unknown): ScheduleFieldWrite | undefined; /** * A key's text written into the field of a row that holds it (#1541, U1), as a kind's `write` takes a field: the * field's own value for it — the key read back from its text at the field's type, a String as it is and any other as * East prints it, and `some` of it where the field is an Option of one. * * @param rowType - The record's row type * @param field - The field * @param text - The key's text * @returns The write; `undefined` for a field the row lacks, and for a text no key of the field's type prints as */ export declare function keyFieldWrite(rowType: EastTypeValue, field: string, text: string): ScheduleFieldWrite | undefined; /** * A lane written into the field a kind's `lane` names (#1541, U1), as its `write` takes a field: a String field's * text, or a variant field's case of that name, which holds no value. * * @param rowType - The record's row type * @param field - The lane's field * @param lane - The lane's key * @returns The write; `undefined` for a field the row lacks, and for a variant with no such case */ export declare function laneFieldWrite(rowType: EastTypeValue, field: string, lane: string): ScheduleFieldWrite | undefined; /** * A field of an event's row edited, as its kind writes it: the inspector's * form's edit of one of the fields no role of the builder's maps * ({@link fieldWrite}). * * @param kind - The event kind: its form's specs and its row type * @param id - The event's key's text * @param path - The field's path * @param next - Its new value * @returns The change; `undefined` for a path that names no field of the row */ export declare function fieldChange(kind: Pick, "key" | "fields" | "editing">, id: string, path: readonly string[], next: unknown): ScheduleChange | undefined; /** * A new key, minted unique among the keys given (a UUID, retried): a record * read whole holds every key, and a key a record read a window at a time holds * unread is its Save's own conflict, never an overwrite. The UUID is * `crypto.randomUUID()`'s, else — a page served over plain HTTP has none — a * version 4 UUID drawn from `crypto.getRandomValues`, which every page has. * * @param taken - Whether a key is held already * @returns The key */ export declare function mintKey(taken: (key: string) => boolean): string; /** * What a builder makes over the app's `values` (#1526) — a new row, or the * period's row it writes first — or `undefined` where they fail as they run, * which the console says: a gesture then records nothing and a probe draws * nothing, and the builder goes on. * * @param builder - The builder, as the console names it: `Roster` * @param what - What it makes, as the console names it: `a new duty` * @param make - Its kind's function over the app's `values`, called * @returns What it makes */ export declare function madeFromValues(builder: string, what: string, make: () => T): T | undefined; /** * An entry's drafted row, when its draft holds one: what a builder decodes a * draft of a record into once. * * @param entry - The entry's version in its session * @returns The row; `undefined` for an entry its draft removes, or one the session holds no version of */ export declare function draftedRow(entry: EntryVersion | undefined): { row: unknown; } | undefined; /** * A window of a record as a builder reads it, kept at the revision it was * read at: every read of a record is pinned to one revision, whose rows stay * as they are however often they are read, so a Save's confirmation, which * reads its entries a batch at a time, reads the window once. Tracked where it * is called: the record moving, or the window's read landing, runs it again. * * @param entries - The record read by key, whose revision the window is kept at; `none` for one read whole, read each time * @param read - The window's read: `none` while it is in flight * @returns The window's read, kept */ export declare function keptAtRevision(entries: ScheduleEditingRecord["entries"], read: () => option): () => option; /** * A row of a window read by key: its bytes where the window holds it; `none` * while the window is read; `undefined` for one it does not hold, which is * read by its key — the record may hold it outside the window. * * @param rows - The window's rows, by key, each its row's bytes * @param key - The row's key's text * @returns The row as the window holds it */ export declare function heldInWindow(rows: option>, key: string): ReturnType; /** * The period's own row as the builder's read of it holds it, by its key's * text: the period's row, or none where the record holds none of it; another * period's is read by its key. * * @param periods - The builder's periods * @param from - The read's start: the period's * @param to - The read's end: the next period's start * @param id - The period's key's text * @returns The read */ export declare function periodRowRead(periods: SchedulePeriodsValue, from: Date, to: Date, id: string): ScheduleRowRead; /** * The rows of every period in a span, as the builder's read of them holds * them, by each one's key's text — the Roster's month, its four to six weeks * (#1406): a period's row, or none where the record holds none of it; a period * outside the span is read by its key. * * @param periods - The builder's periods * @param from - The read's start: the first period's * @param to - The read's end: the period after the last's start * @returns The read */ export declare function periodRowsRead(periods: SchedulePeriodsValue, from: Date, to: Date): ScheduleRowRead; /** * The period's row as Publish writes it: its status the published case, at * the time given — rewritten from the row as the periods' session finds it as * the change is recorded, once the Save has settled: drafted, else as the * record holds it then (`ScheduleChange`'s `rewrite`), so the write changes its * status alone and never puts back what the Save, or another session, wrote * since Publish was pressed; where it finds none, a new one, its own fields * the periods' `values` of its start (#1526) — asked only then * (`ScheduleChange`'s `absent`), and a new row they fail to make records * nothing, so it publishes nothing and the console says why. * * @param periods - The builder's periods * @param record - What a change names the periods' record by * @param id - The period's key's text * @param start - The period's start: its key * @param at - When it is published * @param builder - The builder, as the console names it where the periods' `values` fail * @returns The change */ export declare function periodPublishChange(periods: SchedulePeriodsValue, record: string, id: string, start: Date, at: Date, builder: string): ScheduleChange; /** * Waits until no record's request is in flight or confirming. * * @param history - The history over the records * @returns The history's status then: idle once every record reads back as saved */ export declare function settled(history: EditHistory): Promise["status"]>; /** * Publishes periods (§4.3 rule 4, B7): Save first; once every record's * session reads back as saved, each period's status the published case, and * the periods saved — one period, or several in one request: a Roster * publishing by the day publishes each day of its week not yet published * (#1550). A Save that fails, or drafts that cannot be saved yet, leave each * period a draft with its drafts kept, so a published period never sits over * unsaved rows. * * @param history - The history over the records * @param change - The periods' rows as Publish writes them, worked out once the Save has settled; none publishes nothing * @param record - Records them, as one step * @returns Whether the periods' statuses were written and saved */ export declare function publishPeriod(history: EditHistory, change: () => readonly ScheduleChange[], record: (changes: readonly ScheduleChange[]) => boolean): Promise; //# sourceMappingURL=records.d.ts.map