/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The query builder's hooks (#935) — what its surfaces use to resolve the * root, make a one-shot call and summarise a query, and to keep this viewer's * recent runs. A run is `run.ts`'s (#938). * * - **The root** (`useQueryRoot`): each bound data source as a root field — * its name, its dataset's path and its value's type — in the order given. * - **The call** (`useQueryCall`): how a one-shot call is made — against the * `E3Provider`'s server, a run's started and kept as a call of the workspace * (e3-api-client's `oneShotCall`), so it outlives any request and is listed * among the workspace's calls, and a summary's within one request * (`oneShotExecute`); or a host's own ({@link QueryCallProvider}). * - **The split call** (`useQuerySplitCall`, #941): how a split call is made — * e3-api-client's `splitCall` against the `E3Provider`'s server, which * launches it, polls it with backoff and reports its progress; or a host's * own ({@link QuerySplitCallProvider}). And how its pieces are counted when * a run answered before e3 reported them (`useQuerySplitExplain`, #1132): * e3-api-client's `splitCallExplain`, or the host's own beside its split * call. And how a split call's output is opened, when its answer was too * large for one (`useQueryCollection`, #1113): e3-api-client's * `collectionOpen`, which reads it a page at a time. * - **A data source's status** (`useQuerySourceStatus`, #941): what it weighs * and how many rows it holds, which a run reads before it plans — e3's * dataset status, through the query the Datasets tab polls; or a host's own * ({@link QuerySourceStatusProvider}). * - **The plan's options** (`useQueryPlanOptions`, #941): the most a dataset * may weigh and still be read by one call, and what the estimates take of * the server — the memory one call may use and the pieces it runs at once * (#1143) ({@link QueryPlanOptionsProvider}). * - **Summaries** (`useQuerySummaries`): #934's summary programs, run the same * way, kept by prefix and the hashes of what they read. * - **Recent runs** (`useRecentQueries`): this viewer's last ten, kept in the * browser under the builder's key. * * @packageDocumentation */ import { type ReactNode } from "react"; import { type ValueTypeOf } from "@elaraai/east"; import { DataSourceType, SavedQueryType } from "@elaraai/e3-ui/internal"; import { type RemoteCollection, type SplitCallAnswer } from "@elaraai/e3-api-client"; import { type DatasetStatusDetail, type ExecuteResult, type OneShotRequest, type SplitCallPlan, type SplitCallProgress, type SplitCallRequest, type TreePath } from "@elaraai/e3-types"; import { type E3Config } from "../platform/e3-config.js"; import { SummaryCache } from "./model/summaries.js"; import type { QueryWords } from "./model/words.js"; import { type QueryRoot } from "./one-shot.js"; import type { PlanOptions } from "./plan.js"; /** A data source the builder is handed. */ export type DataSource = ValueTypeOf; /** A saved query, or a recent run of one. */ type SavedQuery = ValueTypeOf; /** * The root a builder's queries read: each bound data source as a root field, * in the order given — or why it cannot be queried, in the builder's words. * * @remarks * A `Data.bind` source is its dataset's path, a record `[records, name]`, and a * `Data.bindPaged` source the path its handle was bound with, which the paged * runtime that built it holds. A paged source read through one of a record's * indexes is refused: its rows are the index's, not the record's a query reads. * * @param datasets - The data sources, as the payload holds them * @param words - The words, for a refusal * @returns The root, or the refusal */ export declare function useQueryRoot(datasets: DataSource[], words: QueryWords): QueryRoot | string; /** How a one-shot call is made ({@link QueryCall}): a run's, or a summary's. */ export interface QueryCallOptions { /** * Whether the call is a run's: started and kept by the server as a call of * the workspace, held to no request's deadline and listed among its calls, * rather than made within one request, as a summary's is. Default `false`. */ readonly run?: boolean; /** * Gives the call up: it rejects with the signal's reason, and a run's call * is asked to stop on the server, which ends it `cancelled`. */ readonly signal?: AbortSignal; } /** * Makes a one-shot call: the request, answered by the call's result. * * @param request - The request — a query's or a summary's, platform-free * @param options - Whether it is a run's, and the signal that gives it up * @returns The result * * @remarks * It rejects with e3-api-client's `ApiError` or `AuthError` when the server * refuses the call — `internal` for a run's call someone cancelled, or the * server lost — and with a `TypeError` when the server cannot be reached, as * `fetch` does; and with the signal's reason once it is given up. */ export type QueryCall = (request: OneShotRequest, options?: QueryCallOptions) => Promise; /** Props of {@link QueryCallProvider}. */ export interface QueryCallProviderProps { /** How a one-shot call is made for the subtree. */ call: QueryCall; /** The subtree. */ children?: ReactNode; } /** * Makes the query builder's one-shot calls with a host's own function — a * test's, or a host that reaches e3 another way. * * @param props - The call and the subtree * @returns The provider */ export declare function QueryCallProvider({ call, children }: QueryCallProviderProps): import("react").FunctionComponentElement>; /** * How the builder makes a one-shot call: a {@link QueryCallProvider}'s, else * against the `E3Provider`'s server and workspace, with its token and through * its `fetch`: a run's by e3-api-client's `oneShotCall`, started and kept as a * call of the workspace, polled to its end and stopped once its signal * aborts, so a run takes as long as its limits allow, never a request's * deadline; a summary's by `oneShotExecute`, within one request, and kept by * nothing. * * @returns The call, or `undefined` when there is no server to call */ export declare function useQueryCall(): QueryCall | undefined; /** What a split call is given: the signal that gives it up, and where its progress goes. */ export interface QuerySplitCallOptions { /** * Gives the call up: it stops polling, its job is cancelled, so e3 stops * its units (#1104), and it rejects with the signal's reason. The units * that finished are cached, so a run of the same call again is served them. */ readonly signal: AbortSignal; /** Told the call's progress each time e3 reports it: its stage, and the units of it done of all. */ readonly onProgress: (progress: SplitCallProgress) => void; } /** * Makes a split call: the request, answered once its job ends by the call's * result — read as a one-shot call's is — the hash of its assembled output, * which a re-keyed join's second call reads (#942) and a result too large for * one answer is read a page at a time from (#1113), and how it ran: its * pieces, and the units it ran and the cache served (#1105). * * @param request - The request — a plan's, platform-free (`splitCallRequest`, * `rekeyCallRequests`) * @param options - The signal that gives it up, and where its progress goes * @returns The call's result, its assembled output's hash once its pieces ran * (`null` before), and its report (`null` when the call reports none) * * @remarks * It rejects with e3-api-client's `ApiError` or `AuthError` when the server * refuses the call, with a `TypeError` when the server cannot be reached, as * `fetch` does, and with any other error when e3 could not run it (a job that * ended `failed`); and with the signal's reason once it is given up, its job * cancelled (#1104). */ export type QuerySplitCall = (request: SplitCallRequest, options: QuerySplitCallOptions) => Promise; /** * Plans a split call's pieces without running it: e3's explain, a job that * plans them as the call's run plans them and runs no unit, so the count is * the run's (#1132). * * @param request - The call, as its run sent it * @param options - The signal that abandons it * @returns How many pieces, the argument they are cut over, by its position, * and what that argument weighs in the store * * @remarks * It rejects as a split call does ({@link QuerySplitCall}), and with an * `Error` naming what is wrong when e3 finds the call wrong. */ export type QuerySplitExplain = (request: SplitCallRequest, options: { readonly signal: AbortSignal; }) => Promise; /** Props of {@link QuerySplitCallProvider}. */ export interface QuerySplitCallProviderProps { /** How a split call is made for the subtree. */ call: QuerySplitCall; /** * How the subtree's split calls' pieces are counted when a run answered * before its call reported them (#1132): the in-memory call's `explain`, * say. Without it, such a run's pieces go uncounted. */ explain?: QuerySplitExplain; /** The subtree. */ children?: ReactNode; } /** * Makes the query builder's split calls with a host's own function — a * test's (`createInMemorySplitCall`), or a host that reaches e3 another way — * and counts their pieces with the host's explain, when it gives one. * * @param props - The call, its explain and the subtree * @returns The provider */ export declare function QuerySplitCallProvider({ call, explain, children }: QuerySplitCallProviderProps): import("react").FunctionComponentElement>; /** * How the builder makes a split call: a {@link QuerySplitCallProvider}'s, else * e3-api-client's `splitCall` against the `E3Provider`'s server and workspace, * with its token and through its `fetch`, which launches the call, polls it — * 100 ms apart at first, backing off to a second — reports each progress it * finds, and cancels the job once its signal aborts (#1104). * * @returns The call, or `undefined` when there is no server to call */ export declare function useQuerySplitCall(): QuerySplitCall | undefined; /** * How the builder counts a split call's pieces when its run answered before * e3 reported them (#1132): a {@link QuerySplitCallProvider}'s explain — a * host's split calls are explained by the host, or not at all — else * e3-api-client's `splitCallExplain` against the `E3Provider`'s server and * workspace, with its token and through its `fetch`, which launches the * explain and polls it until it has planned. * * @returns The explain, or `undefined` when there is none to make */ export declare function useQuerySplitExplain(): QuerySplitExplain | undefined; /** * Opens a stored collection by its hash, to read it a window at a time: the * output of a split call whose answer was too large for one (#1113). * * @param hash - The collection's hash: its manifest's, as the call's answer names it * @returns The collection — its type, how many elements it holds, and a * window of them as beast2 * * @remarks * It rejects as e3-api-client's `collectionOpen` does: with an `ApiError` for * a manifest the repository does not hold, and with an `Error` for an object * that is no collection. */ export type QueryCollection = (hash: string) => Promise; /** * How the builder opens a split call's output whose answer was too large for * one (#1113): e3-api-client's `collectionOpen` against the `E3Provider`'s * server, with its token and through its `fetch`, which reads the manifest * once and each window from the segments it overlaps. A host's split calls * (a {@link QuerySplitCallProvider}'s) are not e3's, so their outputs are not * opened: such an answer stays too large. * * @returns The opener, or `undefined` when there is none to open with */ export declare function useQueryCollection(): QueryCollection | undefined; /** What e3's status says of a data source: how many rows it holds, its hash, and what it weighs. */ export interface SourceStatus { /** How many elements a stored list or lookup table holds; `undefined` for a value that is not a collection, or not known. */ readonly rows: number | undefined; /** The hash of its value; `undefined` when it has none, or it is not known. */ readonly hash: string | undefined; /** What its value weighs in the store, in bytes — a collection's segments and its manifest; `undefined` when not known. */ readonly bytes: number | undefined; } /** * Reads a data source's status: what a run weighs before it plans. * * @param path - The dataset's path, as the root holds it * @returns Its status */ export type QuerySourceStatus = (path: TreePath) => Promise; /** Props of {@link QuerySourceStatusProvider}. */ export interface QuerySourceStatusProviderProps { /** How a data source's status is read for the subtree. */ status: QuerySourceStatus; /** The subtree. */ children?: ReactNode; } /** * Reads the data sources' statuses with a host's own function — a test's, or * a host's over datasets in memory (`createInMemorySourceStatus`). * * @param props - The status and the subtree * @returns The provider */ export declare function QuerySourceStatusProvider({ status, children }: QuerySourceStatusProviderProps): import("react").FunctionComponentElement>; /** A data source's status query, as TanStack Query takes it: its key, and its function. */ export interface SourceStatusQuery { /** Its key: the server, the repository, the workspace and the dataset's path. */ readonly queryKey: readonly unknown[]; /** Its function: e3-api-client's `datasetGetStatus`. */ readonly queryFn: () => Promise; } /** * A data source's status query on e3, as TanStack Query takes it: the Datasets * tab polls it, and a run reads it through the same cache before it plans. * * @param config - The server: its token, and the `fetch` its requests go through * @param workspace - The workspace * @param path - The dataset's path * @returns The query's key, and its function: e3-api-client's `datasetGetStatus` */ export declare function sourceStatusQuery(config: E3Config, workspace: string, path: TreePath): SourceStatusQuery; /** * A data source's status, as e3's dataset status gives it. * * @param detail - The dataset's status detail * @returns Its rows, hash and stored bytes */ export declare function sourceStatusOf(detail: DatasetStatusDetail): SourceStatus; /** * How the builder reads a data source's status: a * {@link QuerySourceStatusProvider}'s, else e3's dataset status against the * `E3Provider`'s server and workspace, through the TanStack Query cache the * Datasets tab polls, a status read in the last 5 seconds serving again. * * @returns The status, or `undefined` when there is no server to ask */ export declare function useQuerySourceStatus(): QuerySourceStatus | undefined; /** Props of {@link QueryPlanOptionsProvider}. */ export interface QueryPlanOptionsProviderProps { /** * The most a dataset may weigh, in stored bytes, and still be read by one * call: e3's smallest piece (`PIECE_SIZES.min`, 16 MiB) when omitted. A * host over a server that cuts small pieces (`E3_TEST_PIECE_BYTES`) sets * it small, so its runs split: a run it plans is by weight alone. */ pieceBytes?: number; /** * The memory one call may use, in bytes (#1143): a run whose one call is * estimated to hold more is split. When omitted, a run takes the path * estimated faster. */ memoryBytes?: number; /** How many pieces the server runs at once — its budget's cores (#1143): the planner's assumption when omitted. */ cores?: number; /** The subtree. */ children?: ReactNode; } /** * Sets how the query builder plans its runs for a subtree: the most a dataset * may weigh and still be read by one call, and what the estimates take of the * server (#1143). * * @param props - The options and the subtree * @returns The provider */ export declare function QueryPlanOptionsProvider({ pieceBytes, memoryBytes, cores, children }: QueryPlanOptionsProviderProps): import("react").FunctionComponentElement>; /** * How the builder plans its runs: a {@link QueryPlanOptionsProvider}'s options, * else the defaults. * * @returns The options */ export declare function useQueryPlanOptions(): PlanOptions; /** * The builder's summaries: #934's summary programs, each run as a one-shot * call with small limits when a slot that needs it opens, and kept by prefix * and the hashes of the datasets it read. A summary that fails leaves the * slot's offers without values. * * @param root - The root, or why it cannot be queried * @param call - How a one-shot call is made * @returns The cache, and the latest hash of each data source a run has read */ export declare function useQuerySummaries(root: QueryRoot | string, call: QueryCall | undefined): { cache: SummaryCache; hashes: ReadonlyMap; }; /** How many recent runs a viewer keeps. */ export declare const RECENT_RUNS = 10; /** * This viewer's recent runs, newest first, kept in the browser under the * builder's key — each a saved query's form, printed as East text. A query run * again moves to the front. * * @param key - The builder's recent-runs key (`queryKeys(id).recent`) * @returns The runs, and `remember(run)` */ export declare function useRecentQueries(key: string): { recent: readonly SavedQuery[]; remember: (run: SavedQuery) => void; }; export {}; //# sourceMappingURL=hooks.d.ts.map