UNPKG

2.77 kBTypeScriptView Raw
1import { RawReplyDefaultExpression, RawServerBase, RawServerDefault, ContextConfigDefault, RawRequestDefaultExpression, ReplyDefault } from './utils'
2import { FastifyContext } from './context'
3import { FastifyLoggerInstance } from './logger'
4import { FastifyRequest } from './request'
5import { RouteGenericInterface } from './route'
6
7export interface ReplyGenericInterface {
8 Reply?: ReplyDefault;
9}
10
11/**
12 * FastifyReply is an instance of the standard http or http2 reply types.
13 * It defaults to http.ServerResponse, and it also extends the relative reply object.
14 */
15export interface FastifyReply<
16 RawServer extends RawServerBase = RawServerDefault,
17 RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
18 RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
19 RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
20 ContextConfig = ContextConfigDefault,
21> {
22 raw: RawReply;
23 context: FastifyContext<ContextConfig>;
24 log: FastifyLoggerInstance;
25 request: FastifyRequest<RouteGeneric, RawServer, RawRequest>;
26 code(statusCode: number): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
27 status(statusCode: number): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
28 statusCode: number;
29 sent: boolean;
30 send<T = RouteGeneric['Reply']>(payload?: T): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
31 header(key: string, value: any): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
32 headers(values: {[key: string]: any}): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
33 getHeader(key: string): string | undefined;
34 getHeaders(): {
35 // Node's `getHeaders()` can return numbers and arrays, so they're included here as possible types.
36 [key: string]: number | string | string[] | undefined;
37 };
38 removeHeader(key: string): void;
39 hasHeader(key: string): boolean;
40 // Note: should consider refactoring the argument order for redirect. statusCode is optional so it should be after the required url param
41 redirect(statusCode: number, url: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
42 redirect(url: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
43 callNotFound(): void;
44 getResponseTime(): number;
45 type(contentType: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
46 serializer(fn: (payload: any) => string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
47 serialize(payload: any): string;
48 then(fullfilled: () => void, rejected: (err: Error) => void): void;
49}