/** * Convex lowering of entity-scoped aggregates — `count(Entity where f == v, …)` * and `sum(Entity where …, of q)` — for reaction params and command * guards/constraints (docs/spec/builtins.md, "Entity-scoped aggregates"). * * The read is chosen from the equality predicates: * - an `id` predicate is a point read (`normalizeId` + `db.get`), never a scan; * - otherwise the declared index (config `indexes`) or single-field index * (`indexed` / reference field) covering the most predicates, in index field * order, drives `withIndex`; * - predicates the index does not cover, soft-delete and tenant scope are * applied as JS filters, mirroring the hardened read surface. */ import type { IR, IREntity, IRExpression } from '../../ir'; import type { ProjectionDiagnostic } from '../interface'; import { type NormalizedOptions } from './generator.js'; type AggregateExpr = Extract; export interface AggregateReadContext { ir: IR; options: NormalizedOptions; /** Renders a predicate value in the caller's scope (null when unresolved). */ renderValue: (value: IRExpression) => string | null; /** Read-side tenant/soft-delete filtering for the scanned entity. */ readFilter: (entity: IREntity) => { hasTenant: boolean; tenantProp: string | undefined; hasSoftDelete: boolean; deletedProp: string; }; /** Emits the handler's tenant binding once; returns the line or null. */ tenantBinding: (tenantProp: string) => string | null; /** Local the tenant binding declares (default `__tenant`). */ tenantVar?: string; /** Diagnostic label, e.g. "reaction X→Y.cmd param 'n'". */ label: string; } export interface AggregateReadResult { lines: string[]; /** Expression holding the count/sum after `lines` run. */ valueVar: string | null; diagnostics: ProjectionDiagnostic[]; } export declare function renderEntityAggregateRead(e: AggregateExpr, varBase: string, ctx: AggregateReadContext): AggregateReadResult; /** Entity-scoped aggregate nodes in `expr` that can be read before it runs. */ export declare function collectEntityAggregates(expr: IRExpression | undefined): AggregateExpr[]; export {}; //# sourceMappingURL=entity-aggregate-read.d.ts.map