/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * A run's result as a Table (#938, `Query Editor Spec.md` §4.11): the rows a * result gives and their columns, the words a cell shows where the Table * words a value rather than shows it — a list by its size, a record by its * first fields, a case with its payload, a missing value as "—" — and the * value east-ui-components' Table renderer shows, built here, in the browser, * from the decoded result. * * The Table and the CSV download read the same rows ({@link resultRows}) and * word a cell through the same {@link cellText}, so the two never differ. A * result too large for one answer is the Table's paged source, read a window * at a time ({@link pagedResultTable}, #1113). * * @packageDocumentation */ import { type EastType } from "@elaraai/east"; import type { TableRootValue } from "@elaraai/east-ui-components"; import { type QueryWords } from "./model/words.js"; /** * A run's result, decoded: its East type and its value. * * @remarks * The type is the one the run's self-describing beast2 answer carries: `T` * for a query giving one value, `Option` for none or one, `Array` for * many. * * @property type - The result's East type * @property value - The decoded value, of that type */ export interface DecodedResult { /** The result's East type: `T`, `Option` or `Array`, as the run gave it. */ readonly type: EastType; /** The decoded value, of that type. */ readonly value: unknown; } /** * A column of a result's rows. * * @property key - The key each row holds the column's value under * @property type - The column's East type * @property field - The field the column reads; `undefined` for the one column of a result that is not records */ export interface ResultColumn { /** The key each row holds the column's value under: a record's field name, or `value`. */ readonly key: string; /** The column's East type: the field's, or the type of the values a result that is not records gives. */ readonly type: EastType; /** * The field the column reads, whose name names a list's items in it * (`3 lines`); `undefined` for the one `value` column of a result that is * not records, whose lists' items are `items`. */ readonly field: string | undefined; } /** * A result's rows, as the Table shows them and the CSV writes them. * * @property columns - The columns, in order * @property rows - The rows, each a struct value keyed by column key */ export interface ResultRows { /** The columns, in order: a record's fields, in declared order, or the one `value` column. */ readonly columns: readonly ResultColumn[]; /** The rows, each a struct value keyed by column key: a record itself, or `{ value }`. */ readonly rows: readonly unknown[]; } /** * A result's rows and columns, as the Table shows them (`Query Editor * Spec.md` §4.11). * * @param result - the decoded result: its type, and its value * @returns the columns, in order, and the rows, each a struct value keyed by * column key * * @remarks * - **Records.** An array or a set of records — a recursive element read as * its node — is one row per element and one column per field, in declared * order; a record is one row. * - **An option.** `none` is no rows, with the columns its payload would * give; `some` is its payload's rows. * - **Anything else.** An array, a set or a vector of other values is one * row per value — a vector's numbers or booleans, as East reads them out of * it — and any other value one row, in one `value` column: each row is * `{ value }`. * * @example * ```ts * const { columns, rows } = resultRows({ type: ArrayType(Order), value: orders }); * // columns: customer_id, discount, id, lines, status, total — one row per order * * resultRows({ type: IntegerType, value: 40n }); * // columns: value — rows: [{ value: 40n }] * ``` */ export declare function resultRows(result: DecodedResult): ResultRows; /** * The words a result's cell shows for a value the Table words rather than * shows as itself (`Query Editor Spec.md` §4.11): a nested value summarised, * and a missing one. * * @param type - the value's East type * @param value - the value * @param words - the words * @param field - the field the value sits in, whose name names a list's * items: a column's `field`; `undefined` for the one `value` column, whose * lists' items are `items` * @returns the words; `undefined` for a primitive value — Null, Boolean, * Integer, Float, String, DateTime, Blob, under any options — which a cell * holds as itself * * @remarks * - **Missing.** An option's `none` is the missing word, "—"; its `some` is * its payload's words. A recursive value is its node's. * - **A list** (an array, a set, a vector) is its size and its items, named * after its field: "1 line", "3 lines"; "3 items" where no field names * them. **A lookup table** is "1 entry", "8 entries"; **a grid** its shape, * "3 × 4". * - **A record** is up to its first three fields that are neither a * collection nor a record, missing ones left out, joined " · ". * - **A case** is its name; with a payload, "{case} · {payload}" — a record * payload's every field, missing ones left out; a Null payload, the case * alone. **A calculation** is "function". * - **Inside a summary**, a number prints in the viewer's language through * the words' formatters, exactly: an ID field's as written, a whole number * grouped, any other with every digit (§9 — never rounded); a DateTime as * its date and time, and a Boolean, a Null and a Blob as East prints them. * * @example * ```ts * cellText(ArrayType(Line), lines, words, "lines"); // "3 lines" * cellText(Status, variant("shipped", { date }), words, "status"); // "shipped · Jun 1, 2026, 14:00" * cellText(OptionType(FloatType), none, words, "discount"); // "—" * cellText(FloatType, 1234.5, words, "total"); // undefined: the cell holds 1234.5 * ``` */ export declare function cellText(type: EastType, value: unknown, words: QueryWords, field: string | undefined): string | undefined; /** * A result's rows read a window at a time (#1113): what * {@link pagedResultTable} serves the Table from. * * @property id - The result's identity: its collection's hash * @property total - How many rows it holds * @property rows - Its rows in a window, or `undefined` while they are read */ export interface ResultWindows { /** The result's identity, the same rows for as long as it is shown: its collection's hash. */ readonly id: string; /** How many rows it holds. */ readonly total: number; /** * Its rows `[offset, offset + limit)`, fewer at its end, each as * {@link resultRows} gives a row. * * @param offset - The first row * @param limit - The most rows * @returns The rows; `undefined` while they are being read * @throws {Error} When they cannot be read. */ rows(offset: number, limit: number): readonly unknown[] | undefined; } /** * A run's result as the value east-ui-components' Table renderer shows * (`EastChakraTable`, `Query Editor Spec.md` §4.11): its rows inline, * virtualised, under a sticky header, filling the height of the box it is * placed in. * * @param result - the decoded result: its type, and its value * @param words - the words: the message table, and the viewer's formatters * @returns the Table's value * * @remarks * - **Rows and columns** are {@link resultRows}': one column per field of a * record, headed by its name as a person reads it (`customer ID`), or one * `value` column, headed by the message table's word. * - **A cell** holds a primitive value as itself, under its own tag — Null, * Boolean, Integer, Float, String, DateTime, Blob; an option's present * value is its payload. Every other value is a String cell of its words * ({@link cellText}): "—" where it is missing, "3 lines" where it is nested. * - **Printing** is the renderer's: no column declares a format, so a number * prints every digit, never grouped — an ID as written, a total exact * (§9) — and a column whose present values are numbers is a number column, * right-aligned in tabular mono, its missing "—" with them. * * @example * ```tsx * const { type, value } = decodeBeast2(result.outcome.value.result); * const table = resultTable({ type: fromEastTypeValue(type), value }, queryWords(useFormatters())); * return ; * ``` */ export declare function resultTable(result: DecodedResult, words: QueryWords): TableRootValue; /** * A result too large for one answer as the Table's value (#1113): its rows a * window at a time, east-ui's paged row source, which the Table walks from the * first row, a window at a time, and reads `none` for while a window is read; * otherwise as {@link resultTable}'s. * * @param type - The result's type: an Array or a Set of the rows * @param windows - Its rows a window at a time * @param words - The words: the message table, and the viewer's formatters * @returns The Table's value */ export declare function pagedResultTable(type: EastType, windows: ResultWindows, words: QueryWords): TableRootValue; //# sourceMappingURL=results-table.d.ts.map