import { EventSubscription } from "@mongez/events"; import { LogLevel } from "@mongez/logger"; import { FastifyReply } from "fastify"; import { Route } from "../router"; import { Validator } from "../validator"; import { Request } from "./request"; import { ResponseEvent } from "./types"; export declare class Response { /** * Current route */ protected route: Route; /** * Fastify response object */ baseResponse: FastifyReply; /** * Current status code */ protected currentStatusCode?: number; /** * Current response body */ protected currentBody: any; /** * A flag to determine if response is being sent */ protected isSending: boolean; /** * Request object */ request: Request; /** * Internal events related to this particular response object */ protected events: Map; /** * Get Current response body */ get body(): any; /** * Set response body */ set body(body: any); /** * Add event on sending response */ onSending(callback: any): this; /** * Add event on sent response */ onSent(callback: any): this; /** * Set the Fastify response object */ setResponse(response: FastifyReply): this; /** * Reset the response state */ reset(): void; /** * Set current route */ setRoute(route: Route): this; /** * Get the content type */ get contentType(): any; /** * Set the content type */ setContentType(contentType: string): this; /** * Get the status code */ get statusCode(): any; /** * Check if the response has been sent */ get sent(): any; /** * Add a listener to the response event */ static on(event: ResponseEvent, listener: (...args: any[]) => void): EventSubscription; /** * Trigger the response event */ protected static trigger(event: ResponseEvent, ...args: any[]): Promise; /** * Parse body */ protected parseBody(): Promise; /** * Parse the given value */ protected parse(value: any): Promise; /** * Make a log message */ log(message: string, level?: LogLevel): void; /** * Check if returning response is json */ get isJson(): boolean; /** * Send the response */ send(data?: any, statusCode?: number): Promise; /** * Send html response */ html(data: string, statusCode?: number): Promise; /** * Send xml response */ xml(data: string, statusCode?: number): Promise; /** * Send plain text response */ text(data: string, statusCode?: number): Promise; /** * send stream response * @TODO: check this later as it is not working in some how */ stream(contentType?: string): { send: any; end: () => boolean; }; /** * Stream file */ streamFile(path: string): Promise; /** * Set the status code */ setStatusCode(statusCode: number): this; /** * Redirect the user to another route */ redirect(url: string, statusCode?: number): this; /** * Permanent redirect */ permanentRedirect(url: string): this; /** * Get the response time */ getResponseTime(): any; /** * Remove a specific header */ removeHeader(key: string): this; /** * Get a specific header */ getHeader(key: string): any; /** * Get the response headers */ getHeaders(): any; /** * Set multiple headers */ headers(headers: Record): this; /** * Set the response header */ header(key: string, value: any): this; /** * Alias to header method */ setHeader(key: string, value: any): this; /** * Send an error response with status code 500 */ serverError(data: any): Promise; /** * Send a forbidden response with status code 403 */ forbidden(data: any): Promise; /** * Send an unauthorized response with status code 401 */ unauthorized(data?: any): Promise; /** * Send a not found response with status code 404 */ notFound(data?: any): Promise; /** * Send a bad request response with status code 400 */ badRequest(data: any): Promise; /** * Send a success response with status code 201 */ successCreate(data: any): Promise; /** * Send a success response */ success(data?: any): Promise; /** * Send a file as a response */ sendFile(path: string, cacheTime?: number): this; /** * Send file and cache it * Cache time in seconds * Cache time will be one year */ sendCachedFile(path: string, cacheTime?: number): this; /** * Get content type of the given path */ getFileContentType(path: string): any; /** * Return validation error to response */ validationFailed(validator: Validator): Promise; } //# sourceMappingURL=response.d.ts.map