import { FunctionInputError } from "./parser.ts"; export { FunctionInputError }; export type ValidationError = { message: string; pos: number; code: "SYNTAX_ERROR" | "CODEGEN_ERROR"; }; export type ValidationResult = { valid: boolean; errors: ValidationError[]; }; export declare class JsmqlInterpolationError extends Error { readonly slot: number; readonly key?: string; constructor(message: string, slot: number, key?: string); } export type JsmqlOps = Record<`$${string}`, (...args: any[]) => any>; type JsmqlFn = ($: any, ops: JsmqlOps) => unknown; export type JsmqlInput = string | JsmqlFn; type JsmqlCompileFn
= (params: P, $: any, ops: JsmqlOps) => unknown;
export type JsmqlOutput = object | object[];
declare function jsmqlDispatch(input: JsmqlInput): JsmqlOutput;
declare function jsmqlDispatch(strings: TemplateStringsArray, ...values: unknown[]): JsmqlOutput;
/**
* `jsmql.expr(input)` — compile a partial / "unfinished" expression in
* aggregation-expression form, the shape used inside Pipeline stage bodies
* (`$project`, `$addFields`, `$group`, …) and as the second argument to
* `db.coll.updateOne(filter, update)` when the update is a update op.
*
* Differs from `jsmql()` only in the no-`;` bare-expression branch: instead of
* Filter dispatch (`{ $expr: ... }` wrap for non-predicates), the expression
* lowers directly to its aggregation-expression form. `;`-separated input is
* still a Pipeline, update op chains still produce `$set`/`$unset`, and array-
* literal Pipelines still pass through — the three other branches are shared
* with `jsmql()` via `lowerProgram`. Same three input shapes as `jsmql()`.
*/
declare function exprDispatch(input: JsmqlInput): JsmqlOutput;
declare function exprDispatch(strings: TemplateStringsArray, ...values: unknown[]): JsmqlOutput;
/**
* `jsmql.filter(input)` — compile to a Filter document only.
*
* Same three input shapes as `jsmql()` (string / arrow / template tag), but
* rejects any input that would lower to a Pipeline. Use this when the call
* site is `db.coll.find(filter)` (or `deleteOne` / `countDocuments` / etc.)
* and you want a compile-time guarantee that you won't accidentally hand the
* driver a stage array. `jsmql()` is the polymorphic counterpart — call it
* when the same source string might legitimately produce either shape.
*
* Pipeline-shaped inputs that throw here: `;`-separated statements, update-op
* chains (`$.x = …`, `delete $.x`), top-level stage calls (`$match(...)`),
* single-key stage-object literals (`{ $match: ... }`), and array-literal
* Pipelines (`[{ $stage: ... }, ...]`). Each error names the shape it found
* and suggests the right call (`jsmql.pipeline()`, `jsmql.update()`,
* `jsmql()`).
*/
declare function filterDispatch(input: JsmqlInput): object;
declare function filterDispatch(strings: TemplateStringsArray, ...values: unknown[]): object;
/**
* `jsmql.pipeline(input)` — compile to a Pipeline (stage array) only.
*
* Same three input shapes as `jsmql()`, but rejects any bare expression that
* would lower to a Filter document. Use this when the call site is
* `db.coll.aggregate(pipeline)` and you want a compile-time guarantee that
* you won't accidentally hand the driver a single document where it expects
* a stage array. Accepts every shape that already produces a Pipeline through
* `jsmql()`:
*
* - `;`-separated statements
* - a single top-level stage call (`$match(...)`) — auto-wraps to one stage
* - a single stage-object literal (`{ $match: ... }`) — auto-wraps too
* - update-op chains (`$.x = …`) — compile to `$set` / `$unset` stages
* - array-literal Pipelines (`[{ $stage: ... }, ...]`)
*
* A bare expression like `$.age > 18` throws — the error suggests `jsmql.filter()`
* if you wanted a Filter, or wrapping in `$match(...)` to make it a Pipeline.
*/
declare function pipelineDispatch(input: JsmqlInput): object[];
declare function pipelineDispatch(strings: TemplateStringsArray, ...values: unknown[]): object[];
/**
* `jsmql.update(input)` — compile to an aggregation-pipeline update (the
* second argument to `db.coll.updateOne(filter, update)` /
* `db.coll.updateMany(filter, update)` in its array form, called an
* `UpdateFilter` in the Node.js MongoDB driver's typings).
*
* The shorter public name (`update` rather than `updateFilter`) avoids the
* trap where developers read "filter" as the *query* document — the first
* argument to `updateOne(filter, update)` — and reach for this when they
* meant `jsmql.filter()`. The MongoDB driver type stays `UpdateFilter >(fn: JsmqlCompileFn ): (params: P) => JsmqlOutput;
declare function compileFunction(src: string): (params: Record >(fn: JsmqlCompileFn ): ValidationResult;
declare function validateInput(input: JsmqlInput): ValidationResult;
declare function validateInput(strings: TemplateStringsArray, ...values: unknown[]): ValidationResult;
type Jsmql = typeof jsmqlDispatch & {
compile: typeof compileFunction;
validate: typeof validateInput;
expr: typeof exprDispatch;
filter: typeof filterDispatch;
pipeline: typeof pipelineDispatch;
update: typeof updateDispatch;
};
export declare const jsmql: Jsmql;
//# sourceMappingURL=index.d.ts.map