@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.
39 lines • 2.73 kB
TypeScript
import type { CursorParams } from './cursor.js';
import type { FilterInput } from './types.js';
/**
* The richer Spatie / JSON:API input shape produced by {@link parseSpatieRequest}.
* A superset of {@link FilterInput}: it adds cursor pagination
* ({@link CursorParams}), JSON:API sparse fieldsets (`select`) and relation
* includes (`include`). Ready to hand to `applyFilter` (offset) or `applyCursor`
* (keyset) — the extra fields are ignored by whichever runner does not use them.
*/
export interface SpatieInput extends FilterInput, CursorParams {
/** JSON:API sparse fieldsets (`fields[resource]=a,b`), flattened + de-duped. */
select?: string[];
/** Relation includes (`include=posts,comments`). */
include?: string[];
}
/**
* Parse a decoded, Spatie-laravel-query-builder / JSON:API-style query object
* into a {@link SpatieInput}. This is the richer, additive counterpart to
* {@link parseFilterRequest}: it understands the same `filter`/`sort`/`search`
* shapes plus JSON:API `include`, sparse `fields[resource]` sets, and cursor
* pagination (`page[after]`/`page[before]`).
*
* | Query string | Decoded input | Mapped to |
* | ------------------------------- | ------------------------------------ | ------------------------------------------ |
* | `filter[name]=Al` | `{ filter: { name: 'Al' } }` | `equals` column filter |
* | `filter[id]=1,2,3` | `{ filter: { id: '1,2,3' } }` | `in` column filter |
* | `filter[age][gte]=18` | `{ filter: { age: { gte: '18' } } }` | operator column filter |
* | `sort=-createdAt,name` | `{ sort: '-createdAt,name' }` | sort items |
* | `distinct=city,tier` | `{ distinct: 'city,tier' }` | `distinct: ['city', 'tier']` |
* | `include=posts,comments` | `{ include: 'posts,comments' }` | `include: ['posts', 'comments']` |
* | `fields[users]=id,name` | `{ fields: { users: 'id,name' } }` | `select: ['id', 'name']` |
* | `page[number]=2&page[size]=10` | `{ page: { number, size } }` | offset (`page`/`size`) |
* | `page[after]=cur&page[size]=10`| `{ page: { after, size } }` | cursor (`after`/`first`) |
*
* A pure reshape — no validation or allow-listing here; that happens downstream
* in `applyFilter` / `applyCursor` against the `FilterConfig`.
*/
export declare function parseSpatieRequest(qs: unknown): SpatieInput;
//# sourceMappingURL=spatie_parser.d.ts.map