import type { AggregateKind, Filter } from "./ast.js"; export interface AggregatePlan { kind: AggregateKind; /** Path components leading to the array (relative to document root). */ over: string[]; /** * For `sort_by` / `min_by` / `max_by`: the path components inside each * array element used to extract the sort key. */ keyPath?: string[]; /** * For string-transform aggregates (`split`, `join`, `ltrimstr`, * `rtrimstr`): the literal string argument. */ stringArg?: string; /** Second literal argument for regex replacement pushdown. */ replacementArg?: string; /** For `flatten(N)`: the depth limit. Unset means recursive (jq default). */ depth?: number; } /** * Recognise filters of shape ` | ` where `` is one of * the aggregations Postgres can compute directly: * - zero-arg: length, add, min, max, sort, unique, reverse * - keyed: sort_by(), min_by(), max_by() * Returns null when the filter doesn't match. */ export declare function planAggregate(ast: Filter): AggregatePlan | null; export interface MapObjectPlan { /** Path to the array we'll iterate (empty = document root). */ over: string[]; /** Output keys + path components (relative to each element) for values. */ pairs: Array<{ key: string; valuePath: string[]; }>; } /** * Recognise ` | map({k: , ...})` and (also) bare * `map({...})`. Each value expression must be a pure path so it maps to * `value #> {…}` in SQL. Returns null when the shape doesn't match. */ export declare function planMapObject(ast: Filter): MapObjectPlan | null; export interface SlicePlan { /** Path components leading to the array to slice. */ over: string[]; /** Inclusive 0-based start, or null for "from beginning". */ start: number | null; /** Exclusive 0-based end, or null for "to end". */ end: number | null; } /** * Recognise `[start:end]` (positive bounds only) and return a * slice plan. Negative bounds need length-aware SQL — left to Node for now. */ export declare function planSlice(ast: Filter): SlicePlan | null; /** * Plan a `limit(N; [])` as a streamed slice: fetch the first N * elements of an array and emit each as a separate jq output. Returns null * if the AST doesn't fit this shape. */ export declare function planLimitedIter(ast: Filter): { over: string[]; limit: number; } | null; export interface PushdownPlan { /** SQL/JSON path expression to evaluate against the file's JSONB content. */ path: string; /** * If set, the runner must verify that the value at this path (relative to * the document root) is a JSON array before using the pushdown result. * Empty array `[]` means "check the document root". When the value isn't * an array, the runner falls back to the in-Node evaluator so that jq's * insertion-order semantics for object iteration are preserved. */ arrayCheckPath?: string[]; /** * If non-null, the residual filter to apply in Node against each value * returned by the pushdown query (partial pushdown). When `rest` is null * the pushdown handles the whole filter. */ rest: Filter | null; /** * True when the pushdown query is "path-single": guaranteed to produce * exactly one result per input in jq semantics, so an empty result set * must be post-processed to a single `null`. False for queries that * legitimately produce 0..N results (Iter, filter expressions). */ pathSingle: boolean; /** * When true, the entire pushdown result array is emitted as a single jq * value (used for `map(...)` which collects iter outputs into one array) * rather than streamed element-by-element. */ wrapResult?: boolean; } /** * Plan a Postgres pushdown for the given jq filter AST. * * Returns the longest pushdownable prefix as a `PushdownPlan`. If the * prefix collapses to identity (i.e. nothing useful is being pushed down), * returns null and the caller should evaluate the whole filter in Node. */ export declare function planPushdown(ast: Filter): PushdownPlan | null; /** * Back-compat wrapper kept for the existing pushdown unit tests: returns * just the jsonpath when the entire filter pushes down as a path-single * query, and null otherwise. */ export declare function translateToJsonPath(ast: Filter): string | null; //# sourceMappingURL=pushdown.d.ts.map