/** * Where Clause Processing * * Handles flattening, validation, and relationship JOIN extraction for where clauses. * Converts user-facing operator names to internal $-prefixed format consumed by DB adapters. */ import type { CollectionConfig, Field, RequestContext } from '@momentumcms/core'; import type { WhereClause } from './momentum-api.types'; /** * Maps user-facing where clause operator names to `$`-prefixed internal names * consumed by database adapters. */ export declare const OPERATOR_MAP: Record; /** Maximum number of field conditions allowed in a single where clause (counted globally across main + joins). */ export declare const MAX_WHERE_CONDITIONS = 20; /** Maximum number of relationship JOIN sub-queries allowed per request. */ export declare const MAX_JOINS = 5; /** Maximum nesting depth for and/or logical operators. */ export declare const MAX_WHERE_NESTING_DEPTH = 5; /** Maximum number of results per page. */ export declare const MAX_PAGE_LIMIT = 1000; /** Maximum page number. Prevents offset overflow: page * limit must stay within safe integer range. */ export declare const MAX_PAGE = 1000000; /** All valid user-facing operator names. */ export declare const VALID_OPERATORS: Set; /** Represents a JOIN requirement extracted from a relationship where clause. */ export interface JoinSpec { targetTable: string; localField: string; targetField: string; conditions: Record; /** Raw sub-where clause (before flattening) for access control validation. */ rawWhere: WhereClause; } /** * Recursively count all field conditions in a where clause tree, * including those nested inside and/or arrays. */ export declare function countWhereConditions(where: WhereClause, depth?: number): number; /** * Flattens a structured WhereClause into simple key-value pairs for the adapter. * Converts { field: { equals: value } } to { field: { $eq: value } }. * Guards against excessive conditions and nesting depth. */ export declare function flattenWhereClause(where: WhereClause | undefined): Record; /** * Extracts relationship sub-queries from a where clause, converting them into JOIN specs. * Relationship sub-queries are detected when a relationship field's condition contains * keys that are NOT valid operators (i.e., they reference fields on the related collection). * * Returns cleaned where clause (without relationship sub-queries) and join specs. */ export declare function extractRelationshipJoins(where: WhereClause | undefined, fields: Field[], allCollections: CollectionConfig[]): { cleanedWhere: WhereClause | undefined; joins: JoinSpec[]; allJoins: JoinSpec[]; }; /** * Validate that the user has read access to all fields referenced in the where clause. * Prevents information leakage by blocking queries on restricted fields. */ export declare function validateWhereFields(where: WhereClause | undefined, fields: Field[], req: RequestContext): Promise; /** * Validate that the user has read access to the field used for sorting. * Prevents information inference through result ordering of restricted fields. */ export declare function validateSortField(sort: string | undefined, fields: Field[], req: RequestContext): Promise;