import { FilterAst, FilterOperator, FilterScalar } from "./shared/ast.mjs"; import { FieldSchemas, FilterGrammar, MAX_FILTER_DEPTH, MAX_FILTER_IN_VALUES, MAX_FILTER_NODES, PaginationValidatorOptions, relationFilterSchema } from "./shared/filters.mjs"; import { ConvexValidatorFromZod } from "convex-helpers/server/zod4"; import { z } from "zod"; import { GenericId, GenericValidator } from "convex/values"; //#region src/querying/filters.d.ts /** Shared hard ceilings; the execution engine may impose lower budgets. */ export declare const MAX_PAGE_SIZE = 100; type NativeField = ConvexValidatorFromZod; type ScalarKind = 'id' | 'string' | 'float64' | 'int64' | 'boolean' | 'null' | 'literal'; type SupportedNative = Validator extends { kind: ScalarKind; } ? true : Validator extends { kind: 'union'; members: infer Members extends GenericValidator[]; } ? false extends SupportedNative ? false : true : false; export type ScalarSelection = { [Key in keyof Fields as false extends SupportedNative> ? never : Key]?: true; }; export type ExactScalarSelection = Selection & { [Key in keyof Selection]: Key extends keyof ScalarSelection ? Selection[Key] extends true ? true : never : never; }; type NativeValue = Exclude['type'], undefined>; type FilterInputValue = Value extends GenericId ? string : Value; type FilterValue = Side extends 'input' ? FilterInputValue> : NativeValue; type RangeKind = 'string' | 'float64' | 'int64' | 'literal'; type OrderedNative = Validator extends { kind: RangeKind; } ? Validator['type'] extends string | number | bigint | undefined ? true : false : Validator extends { kind: 'union'; members: infer Members extends GenericValidator[]; } ? false extends OrderedNative ? false : true : false; type OrderedValue = OrderedNative> extends true ? NativeValue : never; export type ScalarPredicate = FilterValue | ({ eq?: FilterValue; in?: FilterValue[]; } & ([OrderedValue] extends [never] ? {} : { gt?: OrderedValue; gte?: OrderedValue; lt?: OrderedValue; lte?: OrderedValue; }) & ('optional' extends NativeField['isOptional'] ? { exists?: boolean; } : {})); type SelectedFieldFilters = { [Key in Extract]?: ScalarPredicate; }; /** Direct shorthand and explicit fields combine with AND. The fields namespace * accepts every selected scalar name, including boolean-control/namespace names. */ type FilterDepth = readonly [1, 1, 1, 1]; type Tail = Depth extends readonly [1, ...infer Rest extends 1[]] ? Rest : []; export type ScalarFilters = Omit, 'and' | 'or' | 'not' | 'fields'> & { fields?: SelectedFieldFilters; } & (Depth extends readonly [] ? {} : { and?: ScalarFilters>[]; or?: ScalarFilters>[]; not?: ScalarFilters>; }); export declare const nativePagination: z.ZodObject<{ cursor: z.ZodUnion; endCursor: z.ZodOptional>; id: z.ZodOptional; onEmptyBudget: z.ZodOptional>; numItems: z.ZodNumber; maximumRowsRead: z.ZodOptional; maximumBytesRead: z.ZodOptional; }, z.core.$strict>; export type NativePagination = z.output; /** Preserve the object boundary so pagination options can be registered directly as query args. */ export type PaginationOptionsSchema = z.ZodObject<(typeof nativePagination)['shape'] & { filters: z.ZodOptional>; order: z.ZodOptional>; }, z.core.$strict>; export type ScalarPaginationSchema = PaginationOptionsSchema, ScalarFilters>; /** Scalar-only schema constructor shared by table and future registry boundaries. * Convex metadata describes stored INPUT, so storage refinements/transforms never run here. */ export declare function scalarPaginationSchema>(validators: Record, selection: ExactScalarSelection, options?: PaginationValidatorOptions): ScalarPaginationSchema; export declare function scalarPredicateSchema(validator: GenericValidator): z.ZodType; export interface QueryIndex { name: string; fields: readonly string[]; } export interface IndexCondition { value: FilterScalar | undefined; index: string; } export interface RangeBound { value: FilterScalar; inclusive: boolean; } export interface FieldRange { lower?: RangeBound; upper?: RangeBound; } export interface NativeRange extends FieldRange { field: string; } export declare const MAX_INDEX_EXPANSION = 8; export interface IndexExpansion { field: string; values: FilterScalar[]; comparator: 'tail' | 'full-index'; } export interface CompiledFilters { expansion: IndexExpansion | null; sets: ReadonlyMap; residual: FilterAst; bindings: ReadonlyMap; ranges: ReadonlyMap; range: NativeRange | null; unsatisfiable: boolean; index: QueryIndex | null; prefix: readonly { field: string; value: FilterScalar; }[]; } type FilterSpec = z.input extends { filters?: infer Spec; } ? Spec : never; export type ServerFilter = ScalarFilters>; /** Validate first; where is independently validated and ANDed with client predicates. * Only guaranteed sets at one consecutive index position may expand. */ export declare function compileFilters(schema: Schema, input: z.input, indexes: readonly QueryIndex[], conditions?: readonly IndexCondition[], where?: FilterSpec): CompiledFilters; /** Internal planner boundary: retain the parsed arguments without parsing them again. */ export declare function parseFilterPlan(schema: Schema, input: z.input, indexes: readonly QueryIndex[], conditions?: readonly IndexCondition[], where?: FilterSpec, ordering?: string): { args: z.infer; compiled: CompiledFilters; }; export declare function withinRange(value: FilterScalar, range: FieldRange): boolean; /** Recompute against the actual stream prefix, including relationship lookup bindings. */ export declare function rangeForIndex(index: QueryIndex, prefix: readonly { field: string; value: FilterScalar; }[], ranges: ReadonlyMap): NativeRange | null; /** Recompute for the actual lookup prefix on direct relationships, too. */ export declare function expansionForIndex(index: QueryIndex, prefix: readonly { field: string; value: FilterScalar; }[], sets: ReadonlyMap, explicit: boolean): IndexExpansion | null; export declare function isQueryFanoutError(error: unknown): boolean; //#endregion export { type FieldSchemas, type FilterAst, type FilterGrammar, type FilterOperator, type FilterScalar, MAX_FILTER_DEPTH, MAX_FILTER_IN_VALUES, MAX_FILTER_NODES, relationFilterSchema }; //# sourceMappingURL=filters.d.mts.map