@adonis-agora/filter
Version:
Server-side query filtering/sorting/pagination for AdonisJS — Spatie-style input, a Lucid adapter, and field allow-listing. Part of the Agora ecosystem.
30 lines • 1.73 kB
TypeScript
import type { ColumnFilter } from './operators.js';
import type { SortItem } from './types.js';
/** A declarative field-name remapping: client-facing alias → resolved target column. */
export type FieldAliases = Record<string, string>;
/**
* Resolves a client-supplied field name to its declared `aliases` target, or
* returns `field` unchanged when no alias applies.
*
* This is the single choke point for alias resolution — call it wherever a
* client-supplied field name is about to be resolved against the entity (column
* filters and sort). It must run FIRST, before any validation (allow-listing,
* field-charset checks) — those all evaluate the resolved target, never the
* alias key.
*
* Aliases do not cascade: the returned target is never re-run through the alias
* map, even when it happens to also be a declared alias key itself — this is
* what makes alias cycles structurally impossible.
*/
export declare function resolveFieldAlias(aliases: FieldAliases | undefined, field: string): string;
/**
* Returns a copy of a {@link ColumnFilter} with its own field and every nested
* AND/OR child field resolved through the alias map. Pure — the input tree is
* left untouched.
*/
export declare function remapFilterAliases(filter: ColumnFilter, aliases: FieldAliases): ColumnFilter;
/** Resolves every sort directive's field through the alias map (returns a new array). */
export declare function remapSortAliases(sorts: SortItem[], aliases: FieldAliases): SortItem[];
/** Resolves every distinct field name through the alias map (returns a new array). */
export declare function remapDistinctAliases(fields: string[], aliases: FieldAliases): string[];
//# sourceMappingURL=field_aliases.d.ts.map