UNPKG

@moostjs/event-http

Version:
101 lines (94 loc) 6.27 kB
/// <reference types="node" /> import { THook } from '@wooksjs/event-core'; import { TCookieAttributes as TCookieAttributes$1, useSetCookies, WooksHttp, TWooksHttpOptions } from '@wooksjs/event-http'; export { HttpError, TCacheControl, TCookieAttributesInput, TSetCookieData, useHttpContext } from '@wooksjs/event-http'; import * as moost from 'moost'; import { TInterceptorFn, TMoostAdapter, Moost, TConsoleBase, TMoostAdapterOptions } from 'moost'; import * as _prostojs_infact from '@prostojs/infact'; import * as http from 'http'; import { TProstoRouterPathBuilder } from '@prostojs/router'; import { ListenOptions } from 'net'; declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', path?: string): MethodDecorator; declare const All: (path?: string) => MethodDecorator; declare const Get: (path?: string) => MethodDecorator; declare const Post: (path?: string) => MethodDecorator; declare const Put: (path?: string) => MethodDecorator; declare const Delete: (path?: string) => MethodDecorator; declare const Patch: (path?: string) => MethodDecorator; declare const StatusHook: () => ParameterDecorator & PropertyDecorator; declare const HeaderHook: (name: string) => ParameterDecorator & PropertyDecorator; declare const CookieHook: (name: string) => ParameterDecorator & PropertyDecorator; declare const CookieAttrsHook: (name: string) => ParameterDecorator & PropertyDecorator; declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator & PropertyDecorator; declare function Header(name: string): ParameterDecorator & PropertyDecorator; declare function Cookie(name: string): ParameterDecorator & PropertyDecorator; declare function Query(name?: string): ParameterDecorator; declare function Url(): ParameterDecorator & PropertyDecorator; declare function Method(): ParameterDecorator & PropertyDecorator; declare function Req(): ParameterDecorator & PropertyDecorator; declare function Res(opts?: { passthrough: boolean; }): ParameterDecorator & PropertyDecorator; declare function ReqId(): ParameterDecorator & PropertyDecorator; declare function Ip(opts?: { trustProxy: boolean; }): ParameterDecorator & PropertyDecorator; declare function IpList(): ParameterDecorator & PropertyDecorator; declare function Body(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator; declare function RawBody(): ParameterDecorator & PropertyDecorator; type TStatusHook = THook<number>; type THeaderHook = THook; type TCookieAttributes = Partial<TCookieAttributes$1>; type TCookieHook = THook & Partial<THook<TCookieAttributes, 'attrs'>>; declare const setHeaderInterceptor: (name: string, value: string, opts?: { force?: boolean; status?: number; when?: 'always' | 'error' | 'ok'; }) => TInterceptorFn; declare function SetHeader(...args: Parameters<typeof setHeaderInterceptor>): ClassDecorator & MethodDecorator; declare const setCookieInterceptor: (...args: Parameters<ReturnType<typeof useSetCookies>['setCookie']>) => TInterceptorFn; declare function SetCookie(...args: Parameters<typeof setCookieInterceptor>): ClassDecorator & MethodDecorator; declare const setStatusInterceptor: (code: number, opts?: { force?: boolean; }) => TInterceptorFn; declare function SetStatus(...args: Parameters<typeof setStatusInterceptor>): ClassDecorator & MethodDecorator; declare const globalBodySizeLimit: (n: number) => moost.TInterceptorFn; declare const globalCompressedBodySizeLimit: (n: number) => moost.TInterceptorFn; declare const globalBodyReadTimeoutMs: (n: number) => moost.TInterceptorFn; declare const BodySizeLimit: (n: number) => ClassDecorator & MethodDecorator; declare const CompressedBodySizeLimit: (n: number) => ClassDecorator & MethodDecorator; declare const BodyReadTimeoutMs: (n: number) => ClassDecorator & MethodDecorator; interface THttpHandlerMeta { method: string; path: string; } declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> { readonly name = "http"; protected httpApp: WooksHttp; constructor(httpApp?: WooksHttp | TWooksHttpOptions); getHttpApp(): WooksHttp; getServerCb(): (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => void; listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): Promise<void>; listen(port?: number, hostname?: string, listeningListener?: () => void): Promise<void>; listen(port?: number, backlog?: number, listeningListener?: () => void): Promise<void>; listen(port?: number, listeningListener?: () => void): Promise<void>; listen(path: string, backlog?: number, listeningListener?: () => void): Promise<void>; listen(path: string, listeningListener?: () => void): Promise<void>; listen(options: ListenOptions, listeningListener?: () => void): Promise<void>; listen(handle: any, backlog?: number, listeningListener?: () => void): Promise<void>; listen(handle: any, listeningListener?: () => void): Promise<void>; readonly pathBuilders: Record<string, { GET?: TProstoRouterPathBuilder<Record<string, string | string[]>>; PUT?: TProstoRouterPathBuilder<Record<string, string | string[]>>; PATCH?: TProstoRouterPathBuilder<Record<string, string | string[]>>; POST?: TProstoRouterPathBuilder<Record<string, string | string[]>>; DELETE?: TProstoRouterPathBuilder<Record<string, string | string[]>>; }>; onNotFound(): Promise<unknown>; protected moost?: Moost; onInit(moost: Moost): void; getProvideRegistry(): _prostojs_infact.TProvideRegistry; getLogger(): TConsoleBase; bindHandler<T extends object = object>(opts: TMoostAdapterOptions<THttpHandlerMeta, T>): void; } export { All, Authorization, Body, BodyReadTimeoutMs, BodySizeLimit, CompressedBodySizeLimit, Cookie, CookieAttrsHook, CookieHook, Delete, Get, Header, HeaderHook, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, SetStatus, StatusHook, type TCookieAttributes, type TCookieHook, type THeaderHook, type THttpHandlerMeta, type TStatusHook, Url, globalBodyReadTimeoutMs, globalBodySizeLimit, globalCompressedBodySizeLimit };