/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type CheckJqResult, type EastType, type option } from "@elaraai/east"; import type { SplitCallProgress, SplitCallReport } from "@elaraai/e3-types"; import type { QueryCall, QueryCollection, QuerySourceStatus, QuerySplitCall, QuerySplitExplain } from "./hooks.js"; import { type QueryResult, type QueryRoot } from "./one-shot.js"; import { type PagedResult } from "./paged-result.js"; import { type PlanOptions, type QueryPlan } from "./plan.js"; import type { QueryHeader } from "./session.js"; import type { CheckedSteps } from "./steps/check.js"; import { type Shape } from "./steps/shape.js"; import type { StepQuery } from "./steps/values.js"; import type { QueryView } from "./toolbar.js"; /** The most rows a visual run returns; the counting program counts them all. */ export declare const RUN_MAX_ROWS = 1000; /** * A program's canonical text: printed in the pipeline layout when it parses, * as written when it does not — what a result is fresh against. * * @param program - the program's text * @returns its canonical text */ export declare function canonicalProgram(program: string): string; /** What a run sends as a split call, and what reading its answer needs. */ export interface SplitRun { /** * The program: in the visual view the query, a rows result followed by * `{counts: [length], result: .[:1000]}` — the rows joined, and that run * once after them; in the jq view, the jq. */ readonly program: string; /** What each of its counts is of — the last counted stage, for a visual run of rows; `undefined` when it answers the result alone. */ readonly counted: readonly string[] | undefined; /** The data source whose stored row count is the source's count — a visual run's, when its source counts; `undefined` otherwise. */ readonly source: string | undefined; } /** What a run sends, and what reading its answer needs. */ export interface RunPlan { /** The program a one-shot call runs: the counting program, or the jq. */ readonly program: string; /** The query's own program, canonical: what its result is fresh against, and what its plan splits and explains. */ readonly canonical: string; /** What each of the counting program's counts is of — `undefined` for a jq run. */ readonly counted: readonly string[] | undefined; /** What a split call runs instead. */ readonly split: SplitRun; /** The shape the query gives, as the editor knew it when it ran: what its rows are called. */ readonly shape: Shape | undefined; /** The query's name and description when it ran: what its recent query is called. */ readonly name: string; readonly description: option; } /** What planning a run needs of the open query. */ export interface RunEditor { /** The view shown. */ readonly view: QueryView; /** The header: its jq, when the program is not steps. */ readonly header: QueryHeader; /** The steps. */ readonly query: StepQuery; /** The steps' check; `undefined` while the program is jq. */ readonly checked: CheckedSteps | undefined; /** The jq as typed, in the jq view. */ readonly jqText: string; /** The jq view's check of it. */ readonly jqChecked: CheckJqResult | undefined; } /** * What a run of the open query sends. * * @param editor - the open query, as the editor holds it * @param root - the root * @returns the plan: in the visual view the counting program, or for a split * call the query, a rows result wrapped to count its rows; in the jq view the jq */ export declare function planRun(editor: RunEditor, root: QueryRoot): RunPlan; /** What a run that answered gave: the query's result, and what the counting program counted. */ export interface RunOutput { /** The result's type: `T`, `Option` or `Array` by the query's multiplicity. */ readonly type: EastType; /** The result; `undefined` for one read a page at a time, whose rows are its pages'. */ readonly value: unknown; /** The rows each stage gave, by step id (`SOURCE_COUNT` for the source's): a visual run's. */ readonly counts: ReadonlyMap | undefined; /** The rows the query gives in all, when the run returned fewer: the counting program's last count. */ readonly total: number | undefined; /** Whether the answer was cut at the call's most outputs, its total unknown: a jq run's. */ readonly truncated: boolean; /** * A result too large for one answer, read a page at a time (#1113): the * output of a split call with no final step, opened by its hash; * `undefined` for a result in hand. */ readonly paged: PagedResult | undefined; } /** * Reads a run's answer. * * @param program - what the run's program counts: a {@link RunPlan}'s * counting program, or a {@link SplitRun}'s * @param result - what the call answered * @param known - counts known before the run answered, by step id: a split * run's source's stored rows * @returns the result and its counts; `undefined` for a run that gave no result * @throws {Error} When a counting run's answer does not hold one count per counted stage. */ export declare function runOutput(program: { readonly counted: readonly string[] | undefined; }, result: QueryResult, known?: ReadonlyMap): RunOutput | undefined; /** Where the builder's run stands. */ export type RunState = { readonly status: "idle"; } /** * A run going: its number, its plan, the data sources it reads; how it * reads them, once planned; and a split call's progress, and how many * pieces it cut, once e3 says. */ | { readonly status: "running"; readonly n: number; readonly plan: RunPlan; readonly reads: readonly string[]; readonly planned: QueryPlan | undefined; readonly progress: SplitCallProgress | undefined; readonly pieces: number | undefined; } /** * A run answered — a result, or the checker's, the runner's or e3's * refusal — how it read its data; how many pieces it cut, once e3 says — * its report, or for a host's split call that reports none, its explain, * after the answer (#1132); and how its split call ran, as e3 reports it, * for a call that gave its output: the units it ran and the cache served * (#1105) — the join call's, for a re-keyed join. */ | { readonly status: "done"; readonly n: number; readonly plan: RunPlan; readonly result: QueryResult; readonly output: RunOutput | undefined; readonly at: Date; readonly ms: number; readonly planned: QueryPlan | undefined; readonly pieces: number | undefined; readonly report: SplitCallReport | undefined; } /** A call that never answered: unreachable, or refused by the server — and how it was to read its data. */ | { readonly status: "failed"; readonly n: number; readonly plan: RunPlan; readonly reason: "unreachable" | "refused"; readonly message: string; readonly at: Date; readonly planned: QueryPlan | undefined; }; /** What a run reaches e3 through, and how it plans. */ export interface QueryRunSeams { /** How a one-shot call is made; `undefined` when there is no server. */ readonly call: QueryCall | undefined; /** How a split call is made; `undefined` when there is no server. */ readonly split: QuerySplitCall | undefined; /** How a split call's pieces are counted when its answer reported none (a host's); `undefined` when there is none to ask, and they go uncounted. */ readonly explain: QuerySplitExplain | undefined; /** How a split call's output is opened, when its answer was too large for one (#1113); `undefined` when there is none to open, and the answer stays too large. */ readonly collection: QueryCollection | undefined; /** How a data source's status is read; `undefined` when there is none to read, and every dataset's weight is unknown. */ readonly status: QuerySourceStatus | undefined; /** How the run plans: the most a dataset may weigh and still be read by one call. */ readonly options: PlanOptions; } /** * Runs the open query: each run planned in the browser and sent as one * one-shot call, or as a split call over the dataset it works through; one * run in flight at a time, a new run abandoning the old. * * @param root - The root, or why it cannot be queried * @param seams - How a one-shot call, a split call and a data source's status * are made, and how the run plans * @param onRan - Told each run that answered, with its result, for the recent queries * @returns The run's state, and `run(plan)` * * @remarks * A run checks and splits the query (`draftPlan`); reads the status of the * datasets whose weights decide its path, when it would cut one; plans the * call by what they weigh (`weighPlan`); and makes it — a re-keyed join's two * calls one after the other, the second over the first's output (#942). A * split call's progress is the run's as e3 reports it, and how many pieces it * cut is the partition's units — the join call's, for a re-keyed join. A * split visual run counts the source from its dataset's stored rows, and a * rows result's rows from the call; nothing between. * * Once a split call answers, its report says how it ran (#1105): its pieces — * which a call that ended between two polls, or one the cache served whole, * never said as it went — and the units it ran and the cache served. A host's * split call that reports none, and answered before it said its pieces, has * them counted once it has answered, by its explain, which plans them as the * run did and runs no unit (#1132): the answer shows at once, and the count * lands after it. An explain is work in proportion to the dataset, so a call * whose progress or report named its pieces is never explained. An explain * that fails leaves the count unknown; a new run gives it up with the run. * * A split call with no final step whose answer was too large for one has its * output — the hash the answer names — opened (`collection`), and the run's * result is read a page at a time (#1113). An output that can't be opened * leaves the answer too large. A one call's answer too large for one names no * output: a run whose estimates chose one call, and whose split call has no * final step, goes on as that split call (`weighPlan`'s `tooLarge`), so its * result is read a page at a time too. * * A one call is a run's (`QueryCall`'s `run`): e3 starts and keeps it as a call * of the workspace, listed among its calls, so it runs as long as its limits * allow, never a request's deadline. A new run gives the one before up by its * signal, and so does the builder going — unmounted, or hidden: its one call * is asked to stop, and its split call stops polling and its job is * cancelled, so e3 stops its units (#1104); and its answer is dropped when it * lands. The builder's coming back starts that run again, under its number: * React's development check of a component's effects, which mounts it, * unmounts it and mounts it again, would otherwise fail the run a saved query * starts as it opens, with the given-up call's "signal is aborted"; the units * the cancelled job finished are cached, and serve the run started again. */ export declare function useQueryRun(root: QueryRoot | string, seams: QueryRunSeams, onRan?: (result: QueryResult, plan: RunPlan) => void): { state: RunState; run: (plan: RunPlan) => void; }; //# sourceMappingURL=run.d.ts.map