UNPKG

@bit-js/byte

Version:

A simple, performance-focused web framework that works on Bun, Deno, and browsers.

41 lines (40 loc) 1.55 kB
import type { BaseContext } from '../../core/server'; import decodeURIComponent from './decodeURI'; export type QuerySchemaTypes = 'string' | 'number' | 'bool'; interface TypeMap { string: string | null; number: number; bool: boolean; } export interface QuerySchema extends Record<string, QueryPropertyOptions> { } export type InferQuerySchema<T extends QuerySchema> = { [K in keyof T]: InferQueryPropertyOptions<T[K]> & {}; }; export interface QueryPropertyOptions { type: QuerySchemaTypes; maxItems?: number; } export interface DefaultQueryPropertyOptions extends QueryPropertyOptions { type: 'string'; } export type InferQueryPropertyOptions<T extends QueryPropertyOptions> = undefined extends T['maxItems'] ? TypeMap[T['type']] & {} : T['maxItems'] extends 0 ? null : T['maxItems'] extends 1 ? TypeMap[T['type']] & {} : (TypeMap[T['type']] & {})[]; export declare const query: { /** * Whether query parsers should try to decode value */ decodeValue: boolean; /** * Get values of a key from the query */ get<Options extends QueryPropertyOptions = DefaultQueryPropertyOptions>(name: string, { type, maxItems }?: Options): (ctx: BaseContext) => InferQueryPropertyOptions<Options>; /** * Parse multiple keys */ schema<Schema extends QuerySchema>(schema: Schema): (ctx: BaseContext) => InferQuerySchema<Schema> | null; /** * Try decode URI component. Fallback to the passed value if parsing failed */ decode: typeof decodeURIComponent; }; export {};