/** * Filters for extracting query strings * @packageDocumentation */ import { Filter } from "../filter"; import { IsInstanceOf } from "../types"; /** * Schema for query string validation and extraction */ export declare type QuerySchema = { [key: string]: typeof String | typeof Number | typeof Boolean | { optional: true; type: typeof String | typeof Number; }; }; /** * Converts a [[`QuerySchema`]] to the type it represents */ declare type QueryMap = { [K in keyof S]: true extends IsInstanceOf ? string : true extends IsInstanceOf ? number : true extends IsInstanceOf ? boolean : S[K] extends { optional: true; type: infer T; } ? true extends IsInstanceOf ? string | undefined : true extends IsInstanceOf ? number | undefined : never : never; }; /** * Validates and extracts the query string following the provided schema * * ```ts * // Will match ?limit=50&strip * // Generic type annotation not required, only present for clarity's sake * const query: Filter<[ * { limit: number; skip?: number; strip: boolean } * ]> = query({ * limit: Number, * skip: { optional: true, type: Number }, * strip: Boolean, * }); * ``` * * @param schema - Schema * @param extra - Whether to include extra fields not diescribed in the schema in the extracted object */ export declare function query(schema: T, extra?: boolean): Filter<[QueryMap]>; /** * Extracts the query string */ export declare const any: Filter<[URLSearchParams]>; /** * Extracts the raw query string */ export declare const raw: Filter<[string]>; export {};