import { IncomingMessage, ServerResponse } from "@rill/http"; import Request from "./request"; import Response from "./response"; export default class Context { /** The current request. */ req: Request; /** The current response. */ res: Response; /** Local data/state for rendering the request. */ locals: any; /** Allow tools to attach methods/properties. */ [x: string]: any; /** * @description * Creates an incoming message context. * * @example * require('http').createServer((req, res) => { * const ctx = new Context(req, res) * }) * * @param req An rill/http IncomingMessage. * @param res An rill/http ServerResponse. */ constructor(req: IncomingMessage, res: ServerResponse); /** * @description * Throw an http during the current request and update the status and message on the response. * * @example * context.fail(400, 'Password is required') * * @throws {HttpError} * * @param statusCode The http status code to use for the error. * @param statusMessage The http status message to use for the error. * @param metaData An object to merge on to the error. */ fail(statusCode: number, statusMessage?: string, metaData?: any): void; /** * @description * If a value is falsey throw an http during the current request and update the status and message on the response. * * @example * context.assert(password.length > 5, 400, 'Password must be at least 5 characters long') * * @throws {HttpError} * * @param value The value to test for truthyness. * @param statusCode The http status code to use for the error. * @param statusMessage The http status message to use for the error. * @param metaData An object to merge on to the error. */ assert(value: any, statusCode: number, statusMessage?: string, metaData?: any): void; }