import type { Expr, AssignExpr, Pipeline, UpdateFilter } from "./ast.ts"; import { type GenerateCtx } from "./codegen.ts"; import { type SubPipelineLowerer, type SlotAllocator } from "./lookup-translation.ts"; export type OutTarget = { kind: "same-db"; coll: string; pos: number; } | { kind: "cross-db"; db: string; coll: string; pos: number; }; /** * Recognise the `$out` LHS shape on an `AssignExpr.target`. Returns the * extracted target on a match, or `null` if the shape isn't even close to * `$out`-like — in which case the caller falls through to its other branches * (replace-root, lookup, regular update op, etc.). * * When the shape *is* `$out`-like but malformed (wrong segment count, * computed bracket), this throws a precise `CodegenError` — that's what we * want, because the user clearly meant to address a collection but the * shape doesn't quite parse as one. */ export declare function detectOutAssign(op: AssignExpr, ctx?: GenerateCtx): OutTarget | null; /** * Walk the RHS chain rooted at `$$` (CollectionRef) and emit the prefix * pipeline stages, left-to-right. Returns the (possibly empty) stage list; * the caller appends the final `$out` stage. * * Supported RHS shapes: * - bare `$$` → [] * - `$$.filter()` → [{ $match: ... }] * - chained stream-methods registry methods * (`.slice`, `.map`, `.toSorted`, `.toReversed`, * `.flatMap`, `.concat`) compose freely → [...] * * Unrecognised methods throw an actionable error naming the * stage-call alternative. */ export declare function lowerOutChain(rhs: Expr, outerCtx: GenerateCtx, lowerBlock: SubPipelineLowerer, allocSlot: SlotAllocator): object[]; /** * Compose RHS-prefix stages with the trailing `{ $out: }`. Returns * the stage list to splice into the surrounding pipeline. The caller is * responsible for flushing any preceding update-op buffer and setting the * "saw $out" flag so subsequent statements throw the trailing-stage error. */ export declare function lowerOut(op: AssignExpr, target: OutTarget, outerCtx: GenerateCtx, lowerBlock: SubPipelineLowerer, allocSlot: SlotAllocator): object[]; /** * Cheap walk: does `node` contain an `$out` assignment? Used by Filter / * `jsmql.expr` mode gates to surface a precise "use Pipeline mode" error. * Recognising only the canonical AssignExpr-target shape (one or two * static accesses on `DatabaseRef`/`ClusterRef`) is enough — anything else * never participates in `$out` lowering anyway. */ export declare function containsOutAssign(node: Expr | Pipeline | UpdateFilter): boolean; //# sourceMappingURL=out-translation.d.ts.map