/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Counting a query's rows (#933): the program a run uses when the builder * wants each shape line's count — the query, with the number of rows bound * after each stage whose shape is rows, and the counts and a bounded result * as its output — so one run gives every count (`Query Editor Spec.md` §4.11). * * @packageDocumentation */ import { ArrayType, IntegerType, type EastType, type ValueTypeOf } from "@elaraai/east"; import type { StepQuery } from "./values.js"; /** The id a count of the data source's rows is given, beside the steps' ids. */ export declare const SOURCE_COUNT = "$source"; /** How many rows a counting run returns, by default. */ export declare const DEFAULT_MAX_ROWS = 1000; /** The counts a counting program gives: one per counted stage. */ declare const CountsType: ArrayType; /** A counting program, and what its counts count. */ export interface CountingProgram { /** The program's text. */ readonly text: string; /** What each count is of, in order: {@link SOURCE_COUNT}, or a step's id. */ readonly counted: readonly string[]; } /** * The program that runs a query and counts each stage's rows. * * @param query - the query * @param root - the root's type: a struct of the data sources * @param options - `maxRows`, how many rows of a rows result to return (1 000 by default) * @returns the program, and what its counts are of * * @remarks * After the data source and each step whose shape is rows, the program binds * `length as $nK`; it ends `{counts: [$n0, …], result: …}`, the result * `.[:maxRows]` when the query gives rows and `.` otherwise. It checks against * the root as the query does. */ export declare function countingProgram(query: StepQuery, root: EastType, options?: { maxRows?: number; }): CountingProgram; /** * Reads a counting run's output. * * @param output - what the counting program gave: its counts and its result * @param counted - what each count is of, as {@link countingProgram} gave it * @returns each count, by {@link SOURCE_COUNT} or step id, and the result * @throws {Error} When the counts are not one whole number per counted stage. */ export declare function readCounts(output: { readonly counts: ValueTypeOf; readonly result: T; }, counted: readonly string[]): { counts: ReadonlyMap; value: T; }; export {}; //# sourceMappingURL=count.d.ts.map