/** * Aggregation service for the Summary Row feature. * * A stateless registry of named reducers over a flat array of cell values, plus * the seven built-ins from {@link SummaryAggregation}. Hosts extend it with * their own functions through {@link SummaryConfig.aggregations} or by passing a * {@link SummaryAggregateFn} inline on a cell. * * ### Relationship to `AggregationEngine` * Not to be confused with {@link import('../engines/aggregation/aggregation-engine').AggregationEngine}, * which aggregates a **group tree** bottom-up: that one merges per-node * accumulators so a parent group never re-scans its descendants' leaf rows, and * its contract is tied to `GroupTree`. This one reduces a **flat, already * resolved** value array for one column within one scope, which is the shape a * summary row needs. The two solve different problems over different data * structures and deliberately share no code path. * * ### Performance * Every built-in is a single pass with no intermediate allocation — no * `filter().map()` chains and no `Math.min(...values)` spread (which throws * `RangeError` on large arrays once the argument count exceeds the engine's * stack limit, at roughly 100k values). Value arrays themselves are built once * per `(scope, column)` pair and shared across summary rows by * {@link import('./summary-service').SummaryService}, so N summary rows over the * same column cost one scan, not N. * * @packageDocumentation */ import { SummaryAggregation, type SummaryAggregateFn, type SummaryCellContext } from './summary.types'; /** * Resolves and applies summary aggregations. * * One instance per grid, so a custom aggregation registered on one grid never * leaks into another. * * @example * ```ts * const engine = new SummaryAggregationEngine(); * engine.register('median', ({ values }) => median(values)); * * engine.aggregate('median', context); // custom, by name * engine.aggregate(SummaryAggregation.Sum, ctx); // built-in * engine.aggregate(({ rows }) => rows.length, ctx); // inline * ``` */ export declare class SummaryAggregationEngine { /** * Host-registered functions. Consulted **before** the built-ins, so a host may * redefine `sum` for a grid whose "sum" means something domain-specific * without having to rename every cell that references it. */ private readonly custom; /** * Registers (or replaces) a named aggregation. * * @param name - Name referenced from `aggregate` / `defaultAggregate`. * @param fn - The reducer. Must be pure. */ register(name: string, fn: SummaryAggregateFn): void; /** * Registers every entry of a name → function record. * * @param aggregations - Functions to register; `undefined` is a no-op. */ registerAll(aggregations: Readonly> | undefined): void; /** * Removes a host-registered aggregation. Built-ins cannot be removed; doing * this to a name that shadowed one restores the built-in. * * @param name - Name to unregister. * @returns `true` when a custom function was removed. */ unregister(name: string): boolean; /** * @param name - Aggregation name to test. * @returns `true` when the name resolves to a custom or built-in function. */ has(name: string): boolean; /** @returns Every resolvable aggregation name, custom first. */ getRegisteredNames(): string[]; /** * Resolves an aggregation specification to a callable. * * @param spec - A function (returned as-is), or a name to look up. * @returns The reducer, or `null` when a name resolves to nothing. */ resolve(spec: SummaryAggregation | string | SummaryAggregateFn | undefined): SummaryAggregateFn | null; /** * Resolves and applies an aggregation in one step. * * @param spec - Aggregation function, or the name of one. * @param context - The cell context supplying `values` / `rows`. * @returns The aggregate, or `null` when `spec` resolves to nothing. */ aggregate(spec: SummaryAggregation | string | SummaryAggregateFn | undefined, context: SummaryCellContext): unknown; } //# sourceMappingURL=aggregation-engine.d.ts.map