import { ComparePlan, CompoundPlan, ConstantPlan, ElemMatchPlan, ICondition, IField, IFields, IFieldsVisitor, IFilter, IFilterVisitor, IFilters, IFiltersVisitor, IPagination, IPaginationVisitor, IPlanInterpreter, IQuery, IQueryVisitor, IRelation, IRelationVisitor, IRelations, IRelationsVisitor, ISort, ISortVisitor, ISorts, ISortsVisitor, MatchPlan, ModPlan, NullCheckPlan, OneOfPlan, SizePlan } from "@rapiq/core"; //#region src/types.d.ts export type Predicate = (input: unknown) => boolean; export type Comparator = (a: T, b: T) => number; export type Projector = (input: T) => T; export type Slicer = (data: T[]) => T[]; export type ApplyOutput = { data: T[]; total: number; pagination: { limit?: number; offset?: number; }; }; //#endregion //#region src/parameter/filters/types.d.ts /** * One binding per relation path: the array element (or NULL row) * a condition tree is currently evaluated against. */ export type BindingContext = Map; /** * A compiled condition node, evaluated per binding assignment. * null marks a vanished (empty) compound. */ export type ConditionEval = (ctx: BindingContext, root: unknown) => boolean; export type FilterCompileResult = ConditionEval | null; export type ValueTest = (value: unknown) => boolean; export type FiltersVisitorOptions = { /** * Field keys whose equality (eq/ne/in/nin) and anchored * (startsWith/endsWith/contains) comparisons stay * case-sensitive instead of the case-insensitive default — * e.g. identifier or token columns. Typically forwarded from * a schema's `filters.caseSensitive` list. * * `true` keeps every equality comparison case-sensitive * (byte-exact), for evaluating arbitrary condition trees whose * field keys aren't known upfront. `false` equals the default. */ caseSensitive?: string[] | boolean; }; //#endregion //#region src/parameter/filters/compiler.d.ts /** * Compiles a condition plan into per-binding evaluation functions and * collects the relation paths the tree references. Operator semantics * (complement law, IN decomposition, case-fold policy, pattern * derivation, value validation) are decided by the core lowering — * this interpreter only compiles primitives into value tests. Field * prefixes compose through elemMatch exactly like the SQL adapter, so * conditions sharing a relation path bind to the same array element. */ export declare class FiltersCompiler implements IPlanInterpreter { readonly paths: Set; readonly itself = true; protected bindingPrefix: string; protected scopeSequence: number; constructor(); compound(plan: CompoundPlan): ConditionEval; constant(plan: ConstantPlan): ConditionEval; nullCheck(plan: NullCheckPlan): ConditionEval; compare(plan: ComparePlan): ConditionEval; oneOf(plan: OneOfPlan): ConditionEval; match(plan: MatchPlan): ConditionEval; mod(plan: ModPlan): ConditionEval; size(plan: SizePlan): ConditionEval; elemMatch(plan: ElemMatchPlan): ConditionEval; protected leaf(field: string, test: ValueTest): ConditionEval; protected registerPath(path: string): void; /** * Complement law: the negation wraps OUTSIDE element * quantification, so a negated leaf is the exact complement of * its positive twin — null/missing values match. */ protected negate(test: ValueTest, negated: boolean): ValueTest; /** * Single-value equality: `caseFold` carries the settled policy * verdict (string condition, field not opted out) — string * comparisons then fold on both sides, mirroring the SQL * adapter's lower()-wrapped rendering. * * Folding only ever governs a string *value*: anything else falls * through to plain value equality, which is where a date value * reads a string operand as the instant it denotes. The SQL side * reaches the same place through `isCaseFoldable`, which exempts * non-string columns from the fold. */ protected buildValueEqualTest(input: unknown, caseFold: boolean): ValueTest; protected buildCompareTest(input: unknown, min: number, max: number): ValueTest; } //#endregion //#region src/parameter/filters/module.d.ts export declare class FiltersVisitor implements IFiltersVisitor, IFilterVisitor { protected options: FiltersVisitorOptions; constructor(options?: FiltersVisitorOptions); visitFilters(expr: IFilters): Predicate; visitFilter(expr: IFilter): Predicate; /** * Compile a built-in leaf or group held through {@link ICondition} into a * {@link Predicate}. Dispatch happens in `planCondition`, so callers holding * built-in output abstractly need no cast. A custom condition needs a * consumer that understands its semantics. */ compile(expr: ICondition): Predicate; protected createCompiler(): FiltersCompiler; } //#endregion //#region src/parameter/fields/condition.d.ts /** * Compile the visibility gates carried by the given field nodes into a * single redactor, or `undefined` if no field is gated. * * A gate condition is evaluated against the record the gated property is * read from. For a dotted name (`client.secret`) that is the related * record, so the condition's own field names stay relative to it, matching * how the projector resolves the same path. Every element of a to-many * relation is gated on its own. */ export declare function createFieldConditionRedactor>(fields: IField[], options?: FiltersVisitorOptions): Projector | undefined; //#endregion //#region src/parameter/fields/types.d.ts export type FieldsVisitorOptions = { /** * Included relation paths: an included relation without direct * field picks keeps its whole subtree alongside the selected * fields; direct picks narrow it to the fieldset (#847). */ relations?: string[]; /** * Options for compiling the visibility gate conditions carried * by the fields (`Field.condition`). The same knobs the query's * filters are compiled with. */ filters?: FiltersVisitorOptions; }; //#endregion //#region src/parameter/fields/module.d.ts export declare class FieldsVisitor> implements IFieldsVisitor> { protected options: FieldsVisitorOptions; constructor(options?: FieldsVisitorOptions); visitFields(expr: IFields): Projector; } //#endregion //#region src/parameter/pagination/module.d.ts export declare class PaginationVisitor implements IPaginationVisitor { visitPagination(expr: IPagination): Slicer; } //#endregion //#region src/parameter/relations/module.d.ts export declare class RelationsVisitor implements IRelationsVisitor, IRelationVisitor { visitRelations(expr: IRelations): string[]; visitRelation(expr: IRelation): string; } //#endregion //#region src/parameter/sorts/module.d.ts export declare class SortsVisitor> implements ISortsVisitor>, ISortVisitor> { visitSorts(expr: ISorts): Comparator; visitSort(expr: ISort): Comparator; } //#endregion //#region src/query/types.d.ts export type CompiledQueryContext = { predicate: Predicate; comparator?: Comparator; projector?: Projector; slicer: Slicer; pagination: { limit?: number; offset?: number; }; }; //#endregion //#region src/query/module.d.ts export declare class CompiledQuery> { readonly predicate: Predicate; readonly comparator: Comparator | undefined; readonly projector: Projector | undefined; readonly pagination: { limit?: number; offset?: number; }; protected slicer: Slicer; constructor(ctx: CompiledQueryContext); /** * Evaluate the filters parameter against a single input. */ matches(input: unknown): boolean; /** * Apply the whole query to a collection: * filter, sort, paginate, project. The input array * is never mutated. */ apply(data: T[]): ApplyOutput; } //#endregion //#region src/module.d.ts export type QueryVisitorOptions = { /** * Field keys whose equality (eq/ne/in/nin) and anchored * (startsWith/endsWith/contains) comparisons stay * case-sensitive instead of the case-insensitive default; * `true` opts every field out. Typically forwarded from a * schema's `filters.caseSensitive` list. */ caseSensitive?: string[] | boolean; }; export declare class QueryVisitor> implements IQueryVisitor> { protected options: QueryVisitorOptions; constructor(options?: QueryVisitorOptions); visitQuery(expr: IQuery): CompiledQuery; } export declare function compileQuery>(query: IQuery, options?: QueryVisitorOptions): CompiledQuery; export declare function applyQuery>(query: IQuery, data: T[], options?: QueryVisitorOptions): ApplyOutput; export declare function compileFilters(input: ICondition, options?: FiltersVisitorOptions): Predicate; export declare function compileSorts>(input: ISorts): Comparator; export declare function compileFields>(input: IFields, options?: FieldsVisitorOptions): Projector; export declare function compilePagination(input: IPagination): Slicer; /** * Compile the visibility gates carried by a fields parameter * (`Field.condition`) into a redactor for a single record. * * A gated field is only visible on records satisfying its condition; on a * record that fails it, the key is omitted from the output. The condition * never removes the record itself. Records with nothing to hide are * returned by reference; otherwise a shallow redacted copy is built along * the affected path. The input is never mutated. * * `@rapiq/adapter-memory`'s own projector applies this automatically. It is * exported for `@rapiq/adapter-sql` / `@rapiq/adapter-typeorm` consumers, which project * the column unconditionally (a selection must stay a bare column for * entity hydration) and therefore have to enforce the gates after the * fetch. See {@link applyFieldConditions} for the array form. */ export declare function compileFieldConditions>(input: IFields, options?: FiltersVisitorOptions): Projector; /** * Apply the visibility gates carried by a fields parameter * (`Field.condition`) to already-fetched records. * * Returns a new array; each record is either passed through by reference * (nothing to hide) or replaced by a redacted copy with the failing keys * omitted. No record is ever removed and the input is never mutated. * * ```ts * const entities = await queryBuilder.getMany(); * const output = applyFieldConditions(query.fields, entities); * ``` */ export declare function applyFieldConditions>(input: IFields, data: T[], options?: FiltersVisitorOptions): T[]; //#endregion //# sourceMappingURL=index.d.mts.map