UNPKG

@tdb/util

Version:
81 lines (70 loc) 1.92 kB
export type RouteMethod = 'GET' | 'PUT' | 'POST' | 'DELETE' | 'PATCH'; export type RouteOptions = { method?: RouteMethod; schema?: IRouteSchemaTypes; title?: IRoute['title']; docs?: IRoute['docs']; description?: IRoute['description']; meta?: IRoute['meta']; /** * See: https://github.com/pillarjs/path-to-regexp#usage */ caseSensitive?: boolean; // When true the regexp will be case sensitive. (default: false) strict?: boolean; end?: boolean; start?: boolean; // Advanced. delimiter?: string; endsWith?: string[]; }; /** * Object interface for a route. */ export type IRoute = { path: string; method: RouteMethod; tokens: Array<string | IRouteToken>; schema: IRouteSchemaTypes; // Documentation. title?: string; description?: string; docs?: string; // URL. meta?: IRouteMeta; }; export type IRouteMeta = { [key: string]: string | number | boolean | null | undefined; }; /** * Represents a single variable-token within a route. */ export type IRouteToken = { name: string | number; prefix: string; delimiter: string; optional: boolean; repeat: boolean; }; /** * Names of the types used by the route for TS => JSON-Schema conversion. */ export type IRouteSchemaTypes = { params?: string; // The parameters within the URL. query?: string; // The parameters within the query-string. data?: string; // The shape of data that may be PUT/POST'ed to the route. response?: string; // The shape of the data that is returned from the route. }; /** * Represents the key/value pairs of a set of parameter embedded within a URL. */ export type RouteParams = { [key: string]: string | number | boolean; }; /** * Represents a query-string. * NB: this record type is derived from NextJS's declaration * for the [ctx.query] type. */ export type RouteQuery = Record< string, string | string[] | number | boolean | undefined >;