import http, { ServerResponse } from 'http'; import { Readable } from 'stream'; interface ResponseContext { response: ServerResponse; } declare const handle: (context: ResponseContext) => (result: Response) => void; declare class Node { label: number; prefix: string; children: Node[]; kind: number; map: HandlerParamsMap; constructor(prefix?: string, children?: any[], kind?: number, map?: any); append(n: Node): void; find(condition: Function): Node; findChild(label: number, kind: number): Node; findChildByLabel(label: number): Node; findChildByKind(kind: number): Node; addHandler(method: string, handler: any, names: string[]): void; findHandler(method: string): HandlerParams; } declare class Router { tree: Node; constructor(); add(method: string, path: string, handler: Function): void; insert(method: string, path: string, kind: number, names?: string[], handler?: any): void; find(method: string, path: string, cn?: Node, n?: number, result?: [Handler, any[]]): [Handler, any[]]; } declare class Response { body: O; status: number; statusText?: string; headers?: HeadersInit; type?: string; encoding?: string; constructor(body: O, { status, headers }?: { status?: number; headers?: {}; }); static OK(body: O, headers?: {}): { body: O; status: number; headers: {}; }; static Created(body?: BodyInit, headers?: {}): { body: BodyInit; status: number; headers: {}; }; static NotFound(headers?: {}): { body: string; status: number; type: string; headers: {}; }; static Accepted(body?: BodyInit, headers?: {}): { body: BodyInit; status: number; headers: {}; }; static NoContent(headers?: {}): { body: string; status: number; headers: {}; }; static Redirect(url: string, status?: number, headers?: {}): { body: string; status: number; headers: { Location: string; }; }; static BadRequest(body?: BodyInit): { body: BodyInit; status: number; }; static Unauthorized(): { body: string; status: number; }; static Forbidden(body?: BodyInit): { body: BodyInit; status: number; }; static MethodNotAllowed(): { body: string; status: number; }; static NotAcceptable(): { body: string; status: number; }; static Conflict(body?: BodyInit): { body: BodyInit; status: number; }; static InternalServerError(body?: BodyInit, headers?: {}): { body: BodyInit; status: number; headers: {}; }; } declare enum Status { Continue = 100, SwitchingProtocols = 101, Processing = 102, EarlyHints = 103, OK = 200, Created = 201, Accepted = 202, NonAuthoritativeInfo = 203, NoContent = 204, ResetContent = 205, PartialContent = 206, MultiStatus = 207, AlreadyReported = 208, IMUsed = 226, MultipleChoices = 300, MovedPermanently = 301, Found = 302, SeeOther = 303, NotModified = 304, UseProxy = 305, TemporaryRedirect = 307, PermanentRedirect = 308, BadRequest = 400, Unauthorized = 401, PaymentRequired = 402, Forbidden = 403, NotFound = 404, MethodNotAllowed = 405, NotAcceptable = 406, ProxyAuthRequired = 407, RequestTimeout = 408, Conflict = 409, Gone = 410, LengthRequired = 411, PreconditionFailed = 412, RequestEntityTooLarge = 413, RequestURITooLong = 414, UnsupportedMediaType = 415, RequestedRangeNotSatisfiable = 416, ExpectationFailed = 417, Teapot = 418, MisdirectedRequest = 421, UnprocessableEntity = 422, Locked = 423, FailedDependency = 424, TooEarly = 425, UpgradeRequired = 426, PreconditionRequired = 428, TooManyRequests = 429, RequestHeaderFieldsTooLarge = 431, UnavailableForLegalReasons = 451, InternalServerError = 500, NotImplemented = 501, BadGateway = 502, ServiceUnavailable = 503, GatewayTimeout = 504, HTTPVersionNotSupported = 505, VariantAlsoNegotiates = 506, InsufficientStorage = 507, LoopDetected = 508, NotExtended = 510, NetworkAuthenticationRequired = 511 } type response_Response = Response; declare const response_Response: typeof Response; type response_Status = Status; declare const response_Status: typeof Status; declare namespace response { export { response_Response as Response, response_Status as Status, }; } declare const Routing: (router: Router) => Middleware; declare const HTTPMethod: { readonly GET: "GET"; readonly POST: "POST"; readonly PUT: "PUT"; readonly PATH: "PATCH"; readonly HEAD: "HEAD"; readonly OPTIONS: "OPTIONS"; readonly DELETE: "DELETE"; }; type HTTPMethod = typeof HTTPMethod[keyof typeof HTTPMethod]; declare class ServerApp { server: http.Server | undefined; router: Router; middlewares: Array; routes: Routes; routePaths: Object; gracefulTerminationTimeout?: number; stop: () => Promise; handleError: (request: Request) => (error: Error) => void; append: (request: Request) => () => void; custom: (request: http.IncomingMessage, response: http.ServerResponse, next: Function) => void; constructor(routes: Routes, middlewares?: Middleware[], handleError?: ({ response }: { response: any; }) => (error: any) => void, append?: (context: any) => () => void, custom?: (request: any, response: any, next: any) => void, gracefulTerminationTimeout?: number); use(middleware: Middleware): this; add(method: HTTPMethod, path: string, ...fns: [...Middleware[], Handler]): this; setup(): Promise; start(port?: number): Promise>; get port(): number; } type BodyInit = string | object | Readable; type HeadersInit = Record; interface Params { [name: string]: any; } interface AnyValue { [name: string]: any; } interface Request { params: I; headers: { [name: string]: string | string[] | undefined; }; files?: { [name: string]: { name: string; length: number; data: any; encoding: string; mimetype: string; }; }; cookies?: object; user?: unknown; host: string; url: string; method: HTTPMethod; path?: string; format?: string; body: http.IncomingMessage; rawBody?: string; response: http.ServerResponse; context: AnyValue; } type MaybePromise = T | Promise | PromiseLike; type Handler = (request: Request) => MaybePromise>; type Pipeline = [...Middleware[], Handler]; type ReversedPipeline = [Handler, ...Middleware[]]; interface Meta { summary?: string; description?: string; parameters?: Array; responses?: Object; } type Middleware = (handler: Handler) => (request: Request) => MaybePromise; interface RoutePaths { [name: string]: any; } interface RouteOptions { middleware?: Middleware[]; meta?: Meta; } interface RouteParams { GET?: Handler; POST?: Handler; PUT?: Handler; PATCH?: Handler; DELETE?: Handler; middleware?: Middleware[]; meta?: Meta; } type Route = [string, RouteParams, Route?]; type Routes = Route[]; interface Context { request: http.IncomingMessage; response: http.ServerResponse; params: Params; url: string; method: string; headers?: Params; cookies?: Object; format?: string; files?: Object; } interface HandlerParams { handler: Handler; names: string[]; } interface HandlerParamsMap { [method: string]: HandlerParams; } interface KeyValue { name: string; value: string; } export { BodyInit as B, Context as C, Handler as H, KeyValue as K, Middleware as M, Params as P, RouteOptions as R, Status as S, Pipeline as a, HTTPMethod as b, Route as c, Router as d, Response as e, Routing as f, Request as g, handle as h, Routes as i, ServerApp as j, HeadersInit as k, MaybePromise as l, ReversedPipeline as m, Meta as n, RoutePaths as o, HandlerParams as p, HandlerParamsMap as q, response as r };