import { Params, Route, RouteOptions, Router as TRRouter } from "tiny-request-router"; import { Context } from "../context"; import { Middleware, MiddlewareNextFunction, SyncMiddleware } from "../middlewareTypes"; export declare type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS"; export declare type MethodWildcard = "ALL"; /** * A handler function just takes a context, you have to type the generic to use params * in your Handler in a type-checked manner. * * Consider a handler your "final" middleware, usually it's the one that adds the HTML or JSON to the response. * * Example: * ``` * const myHandler: Handler<{}, {username: string}> = (ctx) => { * ctx.response.body = `Hello ${ctx.params.username}!`; * } * ``` */ export declare type Handler, ParamsType = {}, ContextDataType = any> = Middleware | SyncMiddleware; /** * A stronger-typed version of `RouteMatch` in tiny-request-router */ export declare type RouteHandlerMatch = { params: PathParams & Params; matches?: RegExpExecArray; } & Route>>; export declare type SplitRoute = string extends S ? string[] : S extends `${infer Start}/:${infer Param}/${infer Rest}` ? [Param, ...SplitRoute] : S extends `${infer Start}/:${infer Param}+` ? [Param] : S extends `${infer Start}/:${infer Param}` ? [Param] : []; export declare type PathParams = { [P in SplitRoute[number]]: string; } & { [P in SplitRoute[number]]?: string; }; /** * Router wraps the tiny-request-router `Router` with a more strict RouteHandler type and automatic params typings. * * Optionally you can supply a generic type definition for userdata that is shared between all endpoints in this router. */ export declare class Router, InitialContextDataType = {}> { /** * The wrapped tiny-request-router Router. */ readonly internalRouter: TRRouter; constructor(); get(path: S, handler: Handler, InitialContextDataType>, opts?: RouteOptions): this; post(path: S, handler: Handler, InitialContextDataType>, opts?: RouteOptions): this; head(path: S, handler: Handler, InitialContextDataType>, opts?: RouteOptions): this; patch(path: S, handler: Handler, InitialContextDataType>, opts?: RouteOptions): this; put(path: S, handler: Handler, InitialContextDataType>, opts?: RouteOptions): this; delete(path: S, handler: Handler, InitialContextDataType>, opts?: RouteOptions): this; options(path: S, handler: Handler, InitialContextDataType>, opts?: RouteOptions): this; all(path: S, handler: Handler, InitialContextDataType>, opts?: RouteOptions): this; match(method: string, path: S): RouteHandlerMatch | null; readonly middleware: (ctx: Context, next?: MiddlewareNextFunction) => Promise; }