/** * The APIs here are used in app routes to send a response to clients. */ import * as express from 'express'; import { Value } from '@quenk/noni/lib/data/jsonx'; export declare const PRS_VIEW_CONTEXT = "$view.context"; export declare const OK = 200; export declare const ACCEPTED = 202; export declare const NO_CONTENT = 204; export declare const CREATED = 201; export declare const MOVED_PERMANENTLY = 301; export declare const FOUND = 302; export declare const SEE_OTHER = 303; export declare const BAD_REQUEST = 400; export declare const UNAUTHORIZED = 401; export declare const FORBIDDEN = 403; export declare const NOT_FOUND = 404; export declare const CONFLICT = 409; export declare const INTERNAL_SERVER_ERROR = 500; /** * Status type representing an http status code. */ export type Status = number; export type Transport = express.Response; export type BodyValue = Value | object; /** * Response is the parent of all the response classes. * * This class implements the logic for sending the response allowing child * classes to override the status and shape of the body if desired. */ export declare abstract class Response { body?: BodyValue; constructor(body?: BodyValue); /** * status code to send with the response. */ abstract status: Status; getBody(): BodyValue; send(response: Transport): Promise; } /** * Accepted response. */ export declare class Accepted extends Response { status: number; } /** * BadRequest response. */ export declare class BadRequest extends Response { status: number; } /** * Conflict response. */ export declare class Conflict extends Response { status: number; } /** * Created response. */ export declare class Created extends Response { status: number; } /** * NoContent response. */ export declare class NoContent extends Response { status: number; } /** * Forbiddden response. */ export declare class Forbidden extends Response { status: number; } /** * Unauthorized response. */ export declare class Unauthorized extends Response { status: number; } /** * NotFound response. */ export declare class NotFound extends Response { status: number; } /** * Ok action. */ export declare class Ok extends Response { status: number; } /** * Redirect action. */ export declare class Redirect extends Response { url: string; status: Status; constructor(url: string, status: Status); send(response: Transport): Promise; } /** * InternalServerError response. */ export declare class InternalServerError extends Response { status: number; } /** * accepted sends the "ACCEPTED" status to the client with optional body. * @param body - Serializable data to be used as the response body. */ export declare const accepted: (body?: BodyValue) => Accepted; /** * badRequest sends the "BAD REQUEST" status to the client with optional body. * * @param body - Serializable data to be used as the response body. */ export declare const badRequest: (body?: BodyValue) => BadRequest; /** * conflict sends the "CONFLICT" status to the client with optional body. * @param body - Serializable data to be used as the response body. */ export declare const conflict: (body?: BodyValue) => Conflict; /** * created sends the "CREATED" status to the client with optional body. * @param body - Serializable data to be used as the response body. */ export declare const created: (body?: BodyValue) => Created; /** * unauthorized sends the "UNAUTHORIZED" status to the client with optional body. * * @param body - Serializable data to be used as the response body. */ export declare const unauthorized: (body?: BodyValue) => Unauthorized; /** * internalError sends the "INTERNAL SERVER ERROR" status and can optionally log * the error to console. * * @param body - Serializable data to be used as the response body. */ export declare const internalError: (body?: BodyValue) => InternalServerError; export { internalError as error }; /** * forbidden sends the "FORBIDDEN" status to the client with optional body. * * @param body - Serializable data to be used as the response body. */ export declare const forbidden: (body?: BodyValue) => Forbidden; /** * noContent sends the "NO CONTENT" status to the client. */ export declare const noContent: () => NoContent; /** * notFound sends the "NOT FOUND" status to the client with optional body. * @param body - Serializable data to be used as the response body. */ export declare const notFound: (body?: BodyValue) => NotFound; /** * ok sends the "OK" status to the client with optional body. * @param body - Serializable data to be used as the response body. */ export declare const ok: (body?: BodyValue) => Ok; /** * redirect the client to a new resource. * * @param url - The URL to redirect to. * @param code - The HTTP status code to redirect with. * @param abort - Flag indicating whether the response filter chain should * be terminated or not. */ export declare const redirect: (url: string, code?: number) => Redirect;