import type { Expr, CallArg, Pipeline, UpdateFilter } from "./ast.ts"; import { type GenerateCtx } from "./codegen.ts"; import { type SubPipelineLowerer } from "./lookup-translation.ts"; export type UnionPushCall = { /** Position of the `$$` receiver token. */ pos: number; /** Position of the `.push(...)` call site (for argument-level errors). */ callPos: number; /** Raw args; lowering re-walks them so each one's pos is preserved for errors. */ args: CallArg[]; }; /** * Recognise a `$$.push(...)` MethodCall — the union entry point. Returns * `null` for anything else, including method calls on `CollectionRef` that * use a method other than `push`. Those other methods (`.filter`, `.map`, * `.slice`, … as well as unknown names) are handled by the bare-statement * stream-chain branch in `pipeline.ts` (`applyStreamMethods`), which lowers * the valid ones and emits an actionable registry error for the rest. */ export declare function detectUnionPush(expr: Expr): UnionPushCall | null; /** * Cheap recursive walk: does `node` (or any sub-tree thereof) contain a * `$$.push(...)` call? Used by mode-gates in `index.ts` to pre-reject the * statement-only union syntax in Filter / `jsmql.expr` / `jsmql.update` * modes with an actionable error. * * Defaults `ctx` to `EMPTY_CTX` for mode-gate call sites without a * meaningful context — the detection doesn't depend on ctx (push doesn't * have any bracket-bound forms today), but the parameter is kept so the * shape mirrors `containsLookupCall` and survives if we add binding-aware * shapes later. */ export declare function containsUnionPush(node: Expr | Pipeline | UpdateFilter, _ctx?: GenerateCtx): boolean; /** * Walk the `$$.push(arg1, arg2, …)` arg list and emit one or more * `$unionWith` stages. Consecutive inline-doc args (`{...}`) batch into a * single `$documents`-form `$unionWith`. Collection-sourced args * (`...$$$.coll[.filter(pred)]`, `$$$.coll.find(pred)`) each emit their own * stage. Source order is preserved across the whole list: e.g. one inline * doc followed by a spread collection followed by another inline doc * produces three stages in that order. * * Rejections (raised on the offending arg's `pos`): * * - `...$$$.coll.find(pred)` — spreading a scalar (JS would TypeError); * "drop the `...`". * - `$$$.coll.filter(pred)` without `...` — pushing an array as one doc * (silent footgun in JS too); "add the `...`". * - Predicate references `$.x` — `$unionWith` has no `let`; move the * local-doc filter to a `$match` before the push. * - Non-document argument (scalar literal, arithmetic expression, etc.) — * collections only hold documents. * - Wrong method on `$$` (anything other than `.push`) — surfaced earlier * by `validateUnionPushShape`. */ export declare function lowerUnionPush(call: UnionPushCall, outerCtx: GenerateCtx, lowerBlock: SubPipelineLowerer): object[]; //# sourceMappingURL=union-translation.d.ts.map