UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

29 lines (28 loc) 1.8 kB
import { Aggregate, BasicExpression, GroupBy, Having, Select } from '../ir.js'; import { NamespacedAndKeyedStream } from '../../types.js'; /** * Processes the GROUP BY clause with optional HAVING and SELECT * Works with the new $selected structure from early SELECT processing */ export declare function processGroupBy(pipeline: NamespacedAndKeyedStream, groupByClause: GroupBy, havingClauses?: Array<Having>, selectClause?: Select, fnHavingClauses?: Array<(row: any) => any>): NamespacedAndKeyedStream; /** * Transforms expressions to replace aggregate functions with references to computed values. * * For aggregate expressions, finds matching aggregates in the SELECT clause and replaces them * with PropRef([resultAlias, alias]) to reference the computed aggregate value. * * Ref expressions (table columns and $selected fields) and value expressions are passed through unchanged. * Function expressions are recursively transformed. * * @param havingExpr - The expression to transform (can be aggregate, ref, func, or val) * @param selectClause - The SELECT clause containing aliases and aggregate definitions * @param resultAlias - The namespace alias for SELECT results (default: '$selected') * @returns A transformed BasicExpression that references computed values instead of raw expressions */ export declare function replaceAggregatesByRefs(havingExpr: BasicExpression | Aggregate, selectClause: Select, resultAlias?: string): BasicExpression; /** * Checks whether an expression contains an aggregate anywhere in its tree. * Returns true for a top-level Aggregate, or a Func whose args (recursively) * contain an Aggregate. Safely returns false for nested Select objects. */ export declare function containsAggregate(expr: BasicExpression | Aggregate | Select): boolean;