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.

26 lines 1.34 kB
import type { FilterFieldKind } from './types.js'; /** Outcome of coercing one filter value against its declared {@link FilterFieldKind}. */ export type CoerceResult = { ok: true; value: unknown; } | { ok: false; reason: string; }; /** * Coerce a raw filter value to its declared column kind, or reject it. * * Why this exists: a filter value arriving over a query string is ALWAYS a string * (`?filter[dayOfWeek][equals]=3` yields `'3'`). Postgres papers over the benign cases with an * implicit cast — `day_of_week = '3'` and `is_recurring = 'false'` both work — so the gap is * invisible until a client sends something that ISN'T castable: `is_recurring = 'xyz'` raises * `invalid input syntax for type boolean` at the database, which surfaces as a 500 on a public * endpoint from pure user input. The allow-list guards which FIELD may be filtered; this guards * what VALUE may reach the column. * * Rejection is not an exception here: the caller maps it onto the spec's existing `throwOnInvalid` * semantics, so a bad value behaves exactly like a disallowed field — dropped by default, or a * loud `InvalidColumnFilterError` (→ 400) when the spec asks for it. */ export declare function coerceFilterValue(value: unknown, kind: FilterFieldKind): CoerceResult; //# sourceMappingURL=coerce_value.d.ts.map