import { type Column, type SQL } from "drizzle-orm";
import type { AllowedFilters, Filter } from "./filters.js";
/**
* Per-field column map. Mirrors the shape of `AllowedFilters`: every field
* declared in `allowed` must have a matching `Column` in `columns`. Authors
* write the map once and the helper handles operator dispatch internally.
*
* Type guarantees:
* - **Key presence** is compile-time enforced — omit a declared field and
* the call site fails to typecheck.
* - **Data-type alignment** between an `AllowedFilter.type` and the
* column's underlying type is NOT compile-time enforced (the `Column`
* generic is intentionally loose). Mismatches are caught at validation
* time by `checkFilter` and at runtime by `applyDrizzleFilters` as
* defence in depth.
*
* The TODO at `matchOp` tracks tightening this end of the contract.
*/
export type FilterColumns = {
[K in keyof A]: Column;
};
/**
* Drizzle helper. Use this from a carte entry's `query` function to turn
* an array of validated `Filter`s into Drizzle `SQL` conditions ready to spread
* into `.where(and(...))`.
*
* The `columns` map mirrors `allowed` one-for-one: each declared filter field
* gets a Drizzle column reference. The LLM never sees column names — only the
* filter `field` strings you authored.
*
* const conditions = applyDrizzleFilters(
* { jobType: jobs.type, retryCount: jobs.retryCount, failedAt: jobs.failedAt },
* params.filters ?? [],
* allowedFilters,
* );
* await db.select().from(jobs).where(and(eq(jobs.status, 'failed'), ...conditions));
*
* Throws on any field/operator/value mismatch — defence in depth even though
* `validatePlan` already gated the plan. If `validatePlan` ran and accepted,
* this helper will not throw at runtime.
*
* Skip this helper entirely if you're using a different ORM; the validation
* still works (your `query` function just builds whatever conditions it
* needs from the raw `params.filters`).
*/
export declare function applyDrizzleFilters(columns: FilterColumns, filters: ReadonlyArray, allowed: A): SQL[];
//# sourceMappingURL=drizzle-filters.d.ts.map