import * as z from 'zod'; import { QueryComposer } from '../core/query-composer'; import type { QueryBuilderOptions } from '../core/types'; /** * Extract column names from a Zod object schema */ export type InferColumns = T extends z.ZodObject ? keyof Shape & string : never; /** * Infer the TypeScript type from a Zod schema */ export type InferZodType = z.infer; /** * Operator suffixes for typed where */ type OperatorSuffix = '' | '__exact' | '__notexact' | '__gt' | '__gte' | '__lt' | '__lte' | '__contains' | '__icontains' | '__startswith' | '__istartswith' | '__endswith' | '__iendswith' | '__in' | '__notin' | '__between' | '__isnull' | '__isnotnull'; /** * Generate typed where filter interface * * Allows both exact matches and operator-based filters */ export type TypedWhere = T extends z.ZodObject ? { [K in keyof Shape as K extends string ? K : never]?: z.infer; } & { [K in keyof Shape as K extends string ? `${K}${OperatorSuffix}` : never]?: unknown; } : Record; /** * Typed select fields */ export type TypedSelect = InferColumns[]; /** * Typed order by fields (with optional - prefix for DESC) */ export type TypedOrderBy = T extends z.ZodObject ? (keyof Shape extends string ? keyof Shape | `-${keyof Shape & string}` : string)[] : string[]; /** * Type-safe QueryComposer wrapper * * Provides compile-time type checking for: * - Column names in where(), select(), orderBy() * - Operator syntax validation * - Result type inference */ export declare class TypedQueryComposer extends QueryComposer { private typeSchema; constructor(schema: T, table: string, options?: QueryBuilderOptions); /** * Type-safe where with typed filter object */ where(filters: TypedWhere): this; /** * Type-safe select with typed column array */ select(fields: TypedSelect): this; /** * Type-safe orderBy with typed field names */ orderBy(...fields: string[]): this; /** * Type-safe or with typed filter groups */ or(filterGroups: Array>): this; /** * Type-safe not with typed filter object */ not(filters: TypedWhere): this; /** * Type-safe conditional with typed callback */ when(condition: boolean | (() => boolean) | unknown, callback: (qc: QueryComposer) => QueryComposer): this; /** * Type-safe unless with typed callback */ unless(condition: boolean | (() => boolean) | unknown, callback: (qc: QueryComposer) => QueryComposer): this; /** * Clone with preserved types */ clone(): TypedQueryComposer; /** * Get the typed schema */ getSchema(): T; /** * Get options for cloning */ private getOptions; } /** * Create a type-safe query composer * * @param schema - Zod schema for the table * @param table - Table name * @param options - Query builder options * @returns TypedQueryComposer with full type safety * * @example * ```typescript * const UserSchema = z.object({ * id: z.string(), * name: z.string(), * age: z.number(), * status: z.enum(['active', 'inactive']), * }); * * const qc = createTypedComposer(UserSchema, 'users') * .where({ status: 'active' }) // Type-safe! * .where({ age__gte: 18 }) // Operators work too * .select(['id', 'name']) // Only valid columns * .orderBy('-created_at'); // With optional - prefix * ``` */ export declare function createTypedComposer(schema: T, table: string, options?: QueryBuilderOptions): TypedQueryComposer; /** * Infer result type based on select fields * * If no select is specified, returns full type. * Otherwise returns pick of selected fields. * * `& keyof InferZodType` is load-bearing: while `T` is still an unresolved * generic, zod v4 collapses `keyof output` to `never`, so a bare * `Selected[number]` fails `Pick`'s constraint (TS2344) at the declaration site * — breaking the library's own build on v4 and every consumer compiling the * shipped `.d.ts` with `skipLibCheck: false`. */ export type InferResult[] | undefined = undefined> = Selected extends InferColumns[] ? Pick, Selected[number] & keyof InferZodType> : InferZodType; /** * Type helper for building typed filters */ export declare function typedFilter(_schema: T, filter: TypedWhere): TypedWhere; export {}; //# sourceMappingURL=infer.d.ts.map