/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The query builder's plain words (#934): what a step, a field, a kind, a * shape, a count, a summary and a problem are called in the visual view * (`Query Editor Spec.md` §4.3–§4.6), the sentence a saved query shows when * its author wrote none (§4.13), and a run's plan, its path, stages and * pruning (#941). Every string comes from the message table; every number * from the locale's formatters. * * @packageDocumentation */ import { type EastType, type SummaryLeafType, type ValueTypeOf } from "@elaraai/east"; import type { SplitCallProgress, SplitCallReport } from "@elaraai/e3-types"; import type { Formatters } from "@elaraai/east-ui-components"; import type { PlanExplanation, QueryPlan } from "../plan.js"; import { type CheckedSteps, type StepDiagnostic, type StepFix } from "../steps/check.js"; import { type StepField } from "../steps/fields.js"; import { type Shape } from "../steps/shape.js"; import type { StepParseError } from "../steps/parse.js"; import { type Condition, type Step, type StepKind, type StepQuery, type StepValue } from "../steps/values.js"; import { type QueryMessages } from "./messages.js"; /** A summary leaf: what a summary says about one path of the rows. */ export type SummaryLeaf = ValueTypeOf; /** The words the model says, and how it prints numbers and dates. */ export interface QueryWords { /** The message table. */ readonly messages: QueryMessages; /** The locale's formatters. */ readonly formatters: Formatters; } /** * The words of a locale. * * @param formatters - the locale's formatters (`useFormatters()` in a renderer) * @param messages - the message table; English by default * @returns the words */ export declare function queryWords(formatters: Formatters, messages?: QueryMessages): QueryWords; /** Each step's icon (Font Awesome's names, `Query Editor Spec.md` §4.4). */ export declare const STEP_ICON: Readonly>; /** * A field's name as a person reads it: underscores as spaces, and `id` and * `sku` in capitals — `customer_id` is `customer ID`. * * @param name - the name * @returns the label */ export declare function human(name: string): string; /** * The plural of a noun, as English mostly forms it: `order` → `orders`, * `category` → `categories`, `status` → `statuses`; a noun already plural is * itself. * * @param word - the noun * @returns its plural */ export declare function plural(word: string): string; /** * A field's label: its name as a person reads it, and a payload's field * with its case — `shipped date`. * * @param field - the field * @returns the label */ export declare function fieldLabel(field: StepField): string; /** * The label of the field a step names: its field's in the shape, or the * last part of the name when the shape has none. * * @param shape - the rows it is read in * @param ref - how the step names it * @returns the label */ export declare function refLabel(shape: Shape, ref: string): string; /** * Whether a field holds IDs, which print as written: `id`, a name ending * `_id`, or `order`. * * @param name - the field's name * @returns whether it is an ID */ export declare function isIdName(name: string): boolean; /** * A kind of value in plain words (`Query Editor Spec.md` §4.4): `text`, * `whole number`, `number, sometimes missing`, `one of gold, standard`, `list * of lines`, `lookup table`, `calculation`, `record`, `tree of boms`. * * @param type - the type * @param words - the words * @param items - what a list's or a tree's items are called, already plural: a field's or a data source's name * @returns the kind */ export declare function plainKind(type: EastType, words: QueryWords, items?: string): string; /** * A field's kind in plain words, its items named after it. * * @param field - the field * @param words - the words * @returns the kind */ export declare function fieldKind(field: StepField, words: QueryWords): string; /** * The case a shape's rows are narrowed to, as an adjective: `shipped`. * * @param shape - the shape * @returns the first narrowed case, or `""` */ export declare function adjectiveOf(shape: Shape): string; /** * A shape's rows in words, in the number a count gives: `shipped orders`, * `shipped order`. * * @param shape - the shape * @param words - the words * @param n - how many, for the noun's number; plural when omitted * @param adjective - an adjective in place of the shape's own * @returns the rows */ export declare function rowsWords(shape: Shape, words: QueryWords, n?: number, adjective?: string): string; /** * A shape in plain words (`Query Editor Spec.md` §4.3): `Many shipped * orders`, `Up to 10 orders`, `One whole number`, `One bom tree`. * * @param shape - the shape * @param words - the words * @returns the words */ export declare function shapeWords(shape: Shape, words: QueryWords): string; /** * A shape counted: `16 shipped orders`; one value is its shape. * * @param shape - the shape * @param n - how many rows a run counted * @param words - the words * @returns the words */ export declare function countWords(shape: Shape, n: number, words: QueryWords): string; /** * The fields of a shape's rows as a person reads them, payloads aside. * * @param shape - the shape * @returns the labels */ export declare function fieldLabels(shape: Shape): string[]; /** * A number from the data as a summary prints it: an ID as written, a whole * number grouped, any other with two decimals. * * @param n - the number * @param field - the field it belongs to * @param words - the words * @returns the text */ export declare function dataNumber(n: number, field: StepField, words: QueryWords): string; /** * A value a step holds, as its slot shows it: text as written, a number as * data — every digit, never grouped. * * @param value - the value * @param words - the words * @returns the text */ export declare function valueWords(value: StepValue, words: QueryWords): string; /** * The jq path from a row a summary keys a field's leaf by: `.total`, * `.status.type`, `.status.value.date`; an item's field under its list — * `.lines[].sku`. * * @param field - the field * @param list - the list field the field is an item's field of, if any * @returns the path */ export declare function leafPath(field: StepField, list?: StepField): string; /** * What a summary says of a field, as a slot's offer shows it * (`Query Editor Spec.md` §4.5): `8 values`, `0.85 – 3,646.84`, `3 cases`, * `1–4 each`, `· 12 missing`. * * @param field - the field * @param leaf - its leaf of the summary * @param words - the words * @returns the words, or `""` when the summary says nothing worth showing */ export declare function fieldSummaryWords(field: StepField, leaf: SummaryLeaf | undefined, words: QueryWords): string; /** A problem in plain words, and its fixes' labels. */ export interface ProblemWords { /** The sentence. */ readonly text: string; /** Each fix, with its label in plain words. */ readonly fixes: readonly { readonly fix: StepFix; readonly label: string; }[]; } /** * A problem of the steps in plain words (`Query Editor Spec.md` §4.6), with * its fixes' labels; a problem the words have no sentence for keeps the * checker's. * * @param d - the diagnostic, as `checkSteps` placed it * @param query - the query * @param root - the root's type: a struct of the data sources * @param checked - the query's check * @param words - the words * @returns the sentence and the fixes */ export declare function problemWords(d: StepDiagnostic, query: StepQuery, root: EastType, checked: CheckedSteps, words: QueryWords): ProblemWords; /** * A problem that keeps a program from being steps, in plain words * (`Query Editor Spec.md` §4.6, "the program"); one the words have no * sentence for keeps the parser's or the checker's. * * @param error - the problem `parseSteps` gave * @param words - the words * @returns the sentence */ export declare function parseErrorWords(error: StepParseError, words: QueryWords): string; /** The most a generated description holds (`Query Editor Spec.md` §4.13). */ export declare const DESCRIPTION_MAX = 140; /** * A condition in a sentence: `status is shipped`, `lines has any where SKU * is BRK-100`; a group in brackets. * * @param condition - the condition * @param shape - the rows it tests * @param words - the words * @returns the words, or `""` for a condition not finished */ export declare function conditionWords(condition: Condition, shape: Shape, words: QueryWords): string; /** * How a field's order is said: dates newest or oldest first, text A to Z, * anything else highest or lowest first. * * @param field - the field sorted by, if known * @returns the kind of order */ export declare function orderKind(field: StepField | undefined): "date" | "text" | "number"; /** * A step in words, from its own values: what an outline line says * (`Query Editor Spec.md` §5) — `status is shipped and total is at least * 100`, `name and region from customers by customer ID`, `revenue and orders * per region`, `by total, highest first`. * * @param step - the step * @param before - the rows it takes * @param words - the words * @returns the words; a jq step's text as written */ export declare function stepWords(step: Step, before: Shape, words: QueryWords): string; /** * The sentence a saved query shows when its author wrote none * (`Query Editor Spec.md` §4.13): one sentence from the finished steps, at * most {@link DESCRIPTION_MAX} characters, cut at a word. * * @param query - the query * @param checked - its check, for each step's rows * @param words - the words * @returns the sentence, or `""` when no step is finished */ export declare function describeQuery(query: StepQuery, checked: CheckedSteps, words: QueryWords): string; /** * A size in bytes, in words — `1.4 MB`, `16 MB`, `512 B`: in the largest unit * it holds one of, to GB. * * @param bytes - the size * @param words - the words * @param figures - the significant figures to round an estimate to (#1143) — * `300 MB` rather than `300.394 MB`; every one when not given * @returns the size */ export declare function byteWords(bytes: number | bigint, words: QueryWords, figures?: number): string; /** * An estimated duration in words (#1143), to two figures — `430 ms`, `2.9 s`, * `17 s`, `4.9 min`: in milliseconds under a second, in seconds under two * minutes, and in minutes after. * * @param seconds - the duration, in seconds * @param words - the words * @returns the duration */ export declare function durationWords(seconds: number, words: QueryWords): string; /** A line of a plan's explanation: a sentence, and the jq it is about. */ export interface PlanLine { /** * What it says: the path and why; both paths' estimates and what they * assumed (#1143); a re-key and its stage (#942); what each piece runs, * what it reads cut at the same keys (#942), how the pieces combine, a * total, what runs once; what every piece reads whole; the pieces; how the * call's units ran, once it answered (#1105); a read that prunes. */ readonly kind: "path" | "estimate" | "rekey" | "piece" | "copartitioned" | "combine" | "total" | "then" | "broadcast" | "pieces" | "units" | "pruning"; /** Its sentence: one that ends with a colon has its jq after it. */ readonly text: string; /** The jq it is about, as the query writes it; `undefined` when it is about none. */ readonly code: string | undefined; } /** What a run knows of its plan as it goes: a split call's progress, how many pieces it cut, and how its units ran. */ export interface PlanRun { /** A split call's progress, while it goes. */ readonly progress?: SplitCallProgress | undefined; /** How many pieces it cut, once e3 says. */ readonly pieces?: number | undefined; /** How a split call ran, once it answered (#1105): the units it ran, and those the cache served. */ readonly report?: SplitCallReport | undefined; } /** * How a split call's units ran, in words, once it answered (#1105) — `The * cache served 11 of its 14 units, and 3 ran.`; a call the cache served whole * consulted no unit, and says so. * * @param report - how it ran, as e3 reports it * @param words - the words * @returns the words */ export declare function planUnitsWords(report: SplitCallReport, words: QueryWords): string; /** * How far a split run has got, in words — `3 of 12 pieces done`, `1 of 1 * merges done`. * * @param progress - its progress, as e3 reports it * @param words - the words * @returns the words */ export declare function planProgressWords(progress: SplitCallProgress, words: QueryWords): string; /** * A plan's explanation in words: one line per sentence, each with the jq it * is about. * * @param explanation - the plan's explanation (`plan.ts`) * @param words - the words * @param run - what the run knows of its plan: a split call's progress while * it goes, how many pieces it cut once e3 says, and how its units ran once * it answered * @returns the lines, in order * * @remarks * - **The path**, first: a split call over a dataset, estimated faster than * one call or one call holding more memory than it may use (#1143), or the * one a run went on as when its one call's answer was too large for one * (#1113), or, its rows not known, what it weighs, more than one piece — or what the * heaviest dataset cut with it weighs; or one call — estimated faster, * within one piece, a weight not known, a split call that could not be * made, or the reason the query runs as one unit, with the jq the reason is * about. * - **The estimates** beside it, when the path was chosen by them (#1143): * one call's time and what it holds, and the memory it may use; the split * call's time, its pieces and how many run at once, and what each holds; * and what they assumed — the rows, those a stream's first rows stop both * paths after, what each costs in one call and in a piece, and what one call * holding every row holds of each. A re-keyed * join says so next, and its re-key stage with the join key and what the * re-keyed rows are estimated to weigh (#942). * - **A split's stages**: what each piece runs; the data sources cut at the * same keys with it (#942); how their outputs combine — rows joined; * totals, each by its rule; grouped by a key, each group's totals combined * or its rows collected; the distinct rows; the first row of each key; a * reduce's updates by key, added or the last kept; the first rows of a sort * (#942); what runs once after them; the data sources every piece reads * whole; and the pieces — how far the run has got while it goes, then how * many and about what each weighs, and how the call's units ran: how many * the cache served, or that it served the whole call (#1105). * - **The reads that prune**, last: a count from a dataset's index, a key * seek, a stream that stops. */ export declare function planWords(explanation: PlanExplanation, words: QueryWords, run?: PlanRun): PlanLine[]; /** * A plan's read-out, beside a run's: `One call`; `Split call`, with how far it * has got while it goes — `Split call · 3 of 12 pieces done` — and how many * pieces it cut once e3 says — `Split call · 12 pieces`; and a re-keyed join's * two calls the same way — `Re-keyed join · 12 pieces`, the join call's * pieces (#942). Once the call answered, the units the cache served follow — * `Split call · 12 pieces · 11 units cached`, `Split call · 12 pieces · all * cached` for a call it served whole (#1105). * * @param planned - the run's plan * @param words - the words * @param run - what the run knows of its plan * @returns the read-out */ export declare function planBadge(planned: QueryPlan, words: QueryWords, run?: PlanRun): string; //# sourceMappingURL=words.d.ts.map