UNPKG

@tsed/common

Version:
100 lines (99 loc) 3.48 kB
/// <reference types="node" /> import { InjectorService } from "@tsed/di"; import { IncomingHttpHeaders, IncomingMessage } from "http"; import type { PlatformContext } from "../domain/PlatformContext"; declare global { namespace TsED { interface Request { id: string; $ctx: PlatformContext; } } } /** * Platform Request abstraction layer. * @platform */ export declare class PlatformRequest<T extends { [key: string]: any; } = any> { raw: T; constructor(raw: T); /** * Get the url of the request. * * Is equivalent of `express.response.originalUrl || express.response.url`. */ get url(): any; get headers(): IncomingHttpHeaders; get method(): string; /** * Contains key-value pairs of data submitted in the request body. By default, it is `undefined`, and is populated when you use * `body-parsing` middleware such as `express.json()` or `express.urlencoded()`. */ get body(): any; /** * When using `cookie-parser` middleware, this property is an object that contains cookies sent by the request. * If the request contains no cookies, it defaults to `{}`. */ get cookies(): { [key: string]: any; }; /** * This property is an object containing properties mapped to the named route `parameters`. * For example, if you have the route `/user/:name`, then the `name` property is available as `req.params.name`. * This object defaults to `{}`. */ get params(): { [key: string]: any; }; /** * This property is an object containing a property for each query string parameter in the route. * When query parser is set to disabled, it is an empty object `{}`, otherwise it is the result of the configured query parser. */ get query(): { [key: string]: any; }; /** * This property is an object containing a property for each session attributes set by any code. * It require to install a middleware like express-session to work. */ get session(): { [key: string]: any; }; /** * Create a new instance of PlatformRequest * @param injector * @param req */ static create(injector: InjectorService, req: TsED.Request): PlatformRequest<any>; /** * Returns the HTTP request header specified by field. The match is case-insensitive. * * ```typescript * request.get('Content-Type') // => "text/plain" * ``` * * @param name */ get(name: string): any; /** * Checks if the specified content types are acceptable, based on the request’s Accept HTTP header field. The method returns the best match, or if none of the specified content types is acceptable, returns false (in which case, the application should respond with 406 "Not Acceptable"). * * The type value may be a single MIME type string (such as “application/json”), an extension name such as “json”, a comma-delimited list, or an array. For a list or array, the method returns the best match (if any). * * @param mime */ accepts(mime: string): string | false; accepts(mime: string[]): string[] | false; isAborted(): any; destroy(): void; /** * Return the Framework response object (express, koa, etc...) */ getRequest<Req = T>(): Req; /** * Return the Node.js response object */ getReq(): IncomingMessage; }