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