UNPKG

@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.

33 lines 1.37 kB
/** * The class-authoring form of a filter over ANY backend — the generic base behind * {@link import('./base_model_filter.js').BaseModelFilter} (Lucid) and custom backends * (in-memory stores, engine clients, predicate bags) alike: **one style that does everything**. * * A method's name IS the key it owns, `setup()` runs on every call before anything the request * asked for, and the class is resolved through the IoC container so an `@inject()`ed constructor * works — exactly the shape AdonisJS developers know from `adonis-lucid-filter`. What differs per * backend is only what `$query` IS: a Lucid builder for models, a draft the methods narrow for * anything else. * * ```ts * export class RunFilter extends BaseFilter<RunQueryDraft> { * declare $query: RunQueryDraft; * * status(value: unknown, operator: string) { * const values = (Array.isArray(value) ? value : [value]).map(String); * this.$query.narrow(values.length === 1 ? { status: values[0] } : { statuses: values }); * } * } * * const draft = new RunQueryDraft(); * await applyCustomFilter(draft, RunFilter, ctx); * ``` */ export class BaseFilter { input(key, fallback) { if (key === undefined) return this.$input; return Object.hasOwn(this.$input, key) ? this.$input[key] : fallback; } } //# sourceMappingURL=base_filter.js.map