Rindle

API index and search · Build metadata

Supporting declarations

packages/normalized/src/agg-table.ts. These declarations explain referenced types. Only package-page symbols are package exports.

Exact source

aggTableName

/** The synthetic base-table name for a relationship `count` aggregate — the byte-exact twin
 *  of Rust `agg_table_name` (`normalize.rs` §3.1). A content hash of the aggregate definition
 *  (child table, kind, group key = correlation **child** fields, child `where`); the parent
 *  correlation field is excluded. Same definition ⇒ same name (cross-query sharing); a
 *  different filter ⇒ a different name (no `(table, pk)` collision). */
export declare function aggTableName(csq: CorrelatedSubquery): string;

aggTableSchemas

/** Every synthetic aggregate table `ast` surfaces (recursively, a nested aggregate under a
 *  materialized relationship included), as flat table schemas — the twin of Rust
 *  `agg_table_schemas`. Columns `[childField…, "count"]`; PK = the leading group columns. */
export declare function aggTableSchemas(ast: Ast, isLocal?: (table: string) => boolean): NormalizedTableSchema[];

rewriteAggregates

/** Rewrite an AST for the LOCAL engine: each relationship `count` becomes a precomputed,
 *  source-backed singular relationship over its synthetic table — read the server's count
 *  with a plain join + the same scalar projection (`aggregatePrecomputed`), never a `reduce`
 *  (which would recount the already-aggregated rows). Non-aggregate relationships recurse
 *  (a nested aggregate is rewritten too); the parent's frame is otherwise untouched, so the
 *  view-schema slot order is preserved. Returns a new AST; the input is not mutated.
 *
 *  The `where` tree is rewritten the SAME way (`PARENT-AGGREGATE-FILTER-DESIGN.md` §3): a
 *  `having_count` parent gate lowers to an EXISTS whose subquery CLONES the display `count_as`
 *  and adds a post-aggregation `HAVING`. That is a relationship `count` like any other, so §3's
 *  premise — the client never recomputes a count, it lacks the child rows — applies to it too;
 *  left un-rewritten the gate would reduce over child rows the server (rightly) does not sync
 *  and every parent would fail it. `agg_table_name` hashes neither `alias` nor `having`, so the
 *  gate resolves to the SAME `__agg_*` table the display `count_as` already registers and syncs:
 *  the rewrite costs no extra table, no extra rows, and reads a count the server already sent.
 *  Its counterpart is the server pruning the gate's witnesses from the footprint (Rust
 *  `table_tree`) — that prune is only sound BECAUSE of this rewrite, so ship this side first. */
export declare function rewriteAggregates(ast: Ast, isLocal?: (table: string) => boolean): Ast;