/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Summaries (#934): what the rows at a step hold, for a slot's offers and a * field's summary (`Query Editor Spec.md` ยง4.5). A summary is #875's summary * program (`summaryProgram`) after the program up to the step, which the * builder runs as a one-shot call (#935); this module gives the program and * keeps the answers. Nothing here reads data: a summary is fetched only when * a slot that needs it opens, never on an edit. * * @packageDocumentation */ import { SummaryType, type EastType, type ValueTypeOf } from "@elaraai/east"; import type { StepField } from "../steps/fields.js"; import type { Shape } from "../steps/shape.js"; import { type StepQuery } from "../steps/values.js"; import type { SlotKind } from "./messages.js"; import { type SummaryLeaf } from "./words.js"; /** A summary of rows: how many, and each leaf path's summary. */ export type Summary = ValueTypeOf; /** The limits a summary's run takes: one output, and five seconds. */ export declare const SUMMARY_LIMITS: { readonly maxOutputs: 1; readonly timeoutMs: 5000; }; /** A summary to fetch: the rows at a step, and the program that summarises them. */ export interface SummaryRequest { /** The canonical program of the steps before: what the summary is of, and its cache key. */ readonly prefix: string; /** The program to run: the prefix, then the summary. */ readonly program: string; /** The shape of the rows it summarises. */ readonly shape: Shape; /** The data sources it reads, by name: the source, and each Look up's. */ readonly reads: readonly string[]; } /** * The summary of the rows a step takes. * * @param query - the query * @param stepIndex - the step; the query's length for the rows it gives * @param root - the root's type: a struct of the data sources * @returns the request, or `undefined` when the rows are not known there: a step before has a problem, or the stage is not rows */ export declare function summaryAt(query: StepQuery, stepIndex: number, root: EastType): SummaryRequest | undefined; /** * A field's leaf of a summary. * * @param summary - the summary of the rows the field is read in * @param field - the field * @param list - the list field the field is an item's field of, for an inner condition * @returns the leaf, or `undefined` when the summary has none for it */ export declare function leafOf(summary: Summary | undefined, field: StepField, list?: StepField): SummaryLeaf | undefined; /** * Whether a slot's offers come from a summary: a condition's field and * value, a field to show, group by, total or sort by, and an input's value. * * @param slot - the slot's kind * @returns whether opening it fetches the summary */ export declare function summaryNeeded(slot: SlotKind): boolean; /** What a summary's run gave: the summary, and the hash of each data source it read. */ export interface SummaryResult { /** The summary. */ readonly summary: Summary; /** Each data source read, by name, with the hash the run read. */ readonly hashes: ReadonlyMap; } /** * Runs a summary's program: the builder's one-shot call (#935). * * @param request - the summary to fetch * @returns what it gave, or `undefined` when it failed: the popover then lists no values */ export type SummaryRun = (request: SummaryRequest) => Promise; /** * The summaries a builder has fetched, while it is mounted: one per prefix, * kept with the hashes of the data sources the run read, so a newer dataset * misses. * * @example * ```ts * const cache = new SummaryCache(request => runOneShot(request.program, SUMMARY_LIMITS)); * const request = summaryAt(query, 2, root); * if (request !== undefined && summaryNeeded("value")) await cache.ensure(request, hashes); * const summary = request === undefined ? undefined : cache.get(request, hashes); * ``` */ export declare class SummaryCache { private readonly run; private readonly entries; private readonly pending; /** * @param run - runs a summary's program */ constructor(run: SummaryRun); /** * The summary of a request, when the cache holds it for the data sources as they are. * * @param request - the request * @param hashes - each data source's current hash, by name; a source not listed is taken as unchanged * @returns the summary, or `undefined` when it has not been fetched, or a source it read has changed since */ get(request: SummaryRequest, hashes: ReadonlyMap): Summary | undefined; /** * Fetches a request's summary unless the cache holds it: once per prefix * and hashes, however often it is asked for while the run is in flight. * * @param request - the request * @param hashes - each data source's current hash, by name * @returns the summary, or `undefined` when the run failed */ ensure(request: SummaryRequest, hashes: ReadonlyMap): Promise; } //# sourceMappingURL=summaries.d.ts.map