@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.
46 lines • 2.64 kB
TypeScript
import { BaseModelFilter } from './base_model_filter.js';
import { type FilterSpec } from './filter_spec.js';
/**
* A filter class as the container hands it back: constructible, extending {@link BaseModelFilter}
* — and carrying that base's static declarations (`filterable`, `sortable`, `blacklist`, …).
*
* Spelled as an intersection with `typeof BaseModelFilter` rather than an index signature: a
* concrete `class UserFilter extends BaseModelFilter` has no index signature, so
* `Record<string, unknown>` here would make every real filter class *unassignable* to this type —
* `static $filter = () => UserFilter` on a model would not compile.
*/
export type FilterClass = new (...args: any[]) => BaseModelFilter;
/**
* Is this a filter class (as opposed to a `defineFilter` spec)? Checked structurally — a class
* that extends {@link BaseModelFilter} — so the two forms can share one entry point.
*/
export declare function isFilterClass(value: unknown): value is FilterClass;
/**
* The request keys a class owns with a method of its own, walking the prototype chain up to (but
* not including) {@link BaseModelFilter} — so a shared abstract filter's methods are inherited
* like any other. `setup`, the constructor, `$`-prefixed members and anything on the class's
* `blacklist` are excluded.
*
* Memoized per class: the shape of a class does not change between requests.
*/
export declare function dispatchKeys(cls: FilterClass): ReadonlySet<string>;
/**
* Compile a filter class's static declarations into the {@link FilterSpec} the runner consumes —
* the same object `defineFilter` produces, so a class and a spec take the identical code path
* through allow-listing, search, sort and pagination.
*
* A class that declares no `filterable` is method-only: nothing reaches SQL except through the
* methods it wrote, which is the tightest allow-list there is.
*
* Memoized per class — the declaration is static, so it is compiled once per process.
*/
export declare function specFromFilterClass(cls: FilterClass): FilterSpec;
/**
* Find the method a request key maps to, honouring the class's `camelCase` (a `snake_case` key
* matches a camelCase method — on by default) and `dropId` (`companyId` matches `company`) knobs.
* Returns the method name, or `undefined` when the class does not own the key.
*/
export declare function methodForKey(cls: FilterClass, key: string): string | undefined;
/** Is this key one the wire format owns (so it is never dispatched to a method)? */
export declare function isReservedKey(key: string): boolean;
//# sourceMappingURL=filter_class.d.ts.map