import { IncomingMessage, ServerResponse } from 'http'; import { Http2ServerRequest, Http2ServerResponse } from 'http2'; declare function Router( config?: Router.Config ): Router.Instance; declare namespace Router { enum HTTPVersion { V1 = 'http1', V2 = 'http2' } type HTTPMethod = | 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' | 'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' | 'PROPFIND' | 'PROPPATCH' | 'PURGE' | 'PUT' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' | 'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE'; type Req = V extends HTTPVersion.V1 ? IncomingMessage : Http2ServerRequest; type Res = V extends HTTPVersion.V1 ? ServerResponse : Http2ServerResponse; type Handler = ( req: Req, res: Res, params: { [k: string]: string | undefined }, store: any, searchParams: { [k: string]: string } ) => any; type Done = (err: Error | null, result: any) => void; interface ConstraintStrategy { name: string, mustMatchWhenDerived?: boolean, storage() : { get(value: T) : Handler | null, set(value: T, handler: Handler) : void, del?(value: T) : void, empty?() : void }, validate?(value: unknown): void, deriveConstraint(req: Req, ctx?: Context) : T, } type QuerystringParser = (s: string) => unknown; interface Config { ignoreTrailingSlash?: boolean; ignoreDuplicateSlashes?: boolean; allowUnsafeRegex?: boolean; caseSensitive?: boolean; maxParamLength?: number; querystringParser?: QuerystringParser; defaultRoute?( req: Req, res: Res ): void; onBadUrl?( path: string, req: Req, res: Res ): void; constraints? : { [key: string]: ConstraintStrategy } } interface RouteOptions { constraints?: { [key: string]: any } } interface ShortHandRoute { (path: string, handler: Handler): void; (path: string, opts: RouteOptions, handler: Handler): void; (path: string, handler: Handler, store: any): void; (path: string, opts: RouteOptions, handler: Handler, store: any): void; } interface FindResult { handler: Handler; params: { [k: string]: string | undefined }; store: any; searchParams: { [k: string]: string }; } interface FindRouteResult { handler: Handler; store: any; params: string[]; } interface Instance { on( method: HTTPMethod | HTTPMethod[], path: string, handler: Handler ): void; on( method: HTTPMethod | HTTPMethod[], path: string, options: RouteOptions, handler: Handler ): void; on( method: HTTPMethod | HTTPMethod[], path: string, handler: Handler, store: any ): void; on( method: HTTPMethod | HTTPMethod[], path: string, options: RouteOptions, handler: Handler, store: any ): void; off( method: HTTPMethod | HTTPMethod[], path: string, constraints?: { [key: string]: any } ): void; lookup( req: Req, res: Res, ctx?: Context | Done, done?: Done ): any; find( method: HTTPMethod, path: string, constraints?: { [key: string]: any } ): FindResult | null; findRoute( method: HTTPMethod, path: string, constraints?: { [key: string]: any } ): FindRouteResult | null; hasRoute( method: HTTPMethod, path: string, constraints?: { [key: string]: any } ): boolean; reset(): void; prettyPrint(): string; prettyPrint(opts: { method?: HTTPMethod, commonPrefix?: boolean, includeMeta?: boolean | (string | symbol)[] }): string; hasConstraintStrategy(strategyName: string): boolean; addConstraintStrategy(constraintStrategy: ConstraintStrategy): void; all: ShortHandRoute; acl: ShortHandRoute; bind: ShortHandRoute; checkout: ShortHandRoute; connect: ShortHandRoute; copy: ShortHandRoute; delete: ShortHandRoute; get: ShortHandRoute; head: ShortHandRoute; link: ShortHandRoute; lock: ShortHandRoute; 'm-search': ShortHandRoute; merge: ShortHandRoute; mkactivity: ShortHandRoute; mkcalendar: ShortHandRoute; mkcol: ShortHandRoute; move: ShortHandRoute; notify: ShortHandRoute; options: ShortHandRoute; patch: ShortHandRoute; post: ShortHandRoute; propfind: ShortHandRoute; proppatch: ShortHandRoute; purge: ShortHandRoute; put: ShortHandRoute; rebind: ShortHandRoute; report: ShortHandRoute; search: ShortHandRoute; source: ShortHandRoute; subscribe: ShortHandRoute; trace: ShortHandRoute; unbind: ShortHandRoute; unlink: ShortHandRoute; unlock: ShortHandRoute; unsubscribe: ShortHandRoute; } } export = Router;