forked from fastify/fastify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content-type-parser.d.ts
62 lines (54 loc) · 2.75 KB
/
content-type-parser.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
51
52
53
54
55
56
57
58
59
60
61
62
import { RawServerBase, RawServerDefault, RawRequestDefaultExpression } from './utils'
import { FastifyRequest } from './request'
import { RouteGenericInterface } from './route'
type ContentTypeParserDoneFunction = (err: Error | null, body?: any) => void
/**
* Body parser method that operators on request body
*/
export type FastifyBodyParser<
RawBody extends string | Buffer,
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
> = ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, rawBody: RawBody, done: ContentTypeParserDoneFunction) => void)
| ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, rawBody: RawBody) => Promise<any>)
/**
* Content Type Parser method that operates on request content
*/
export type FastifyContentTypeParser<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
> = ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, payload: RawRequest) => Promise<any>)
| ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, payload: RawRequest, done: ContentTypeParserDoneFunction) => void)
/**
* Natively, Fastify only supports 'application/json' and 'text/plain' content types. The default charset is utf-8. If you need to support different content types, you can use the addContentTypeParser API. The default JSON and/or plain text parser can be changed.
*/
export interface AddContentTypeParser<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>
> {
(
contentType: string | string[] | RegExp,
opts: {
bodyLimit?: number;
},
parser: FastifyContentTypeParser<RawServer, RawRequest>
): void;
(contentType: string | string[] | RegExp, parser: FastifyContentTypeParser<RawServer, RawRequest>): void;
<parseAs extends string | Buffer>(
contentType: string | string[] | RegExp,
opts: {
parseAs: parseAs extends Buffer ? 'buffer' : 'string';
bodyLimit?: number;
},
parser: FastifyBodyParser<parseAs, RawServer, RawRequest>
): void;
}
/**
* Checks for a type parser of a content type
*/
export type hasContentTypeParser = (contentType: string | RegExp) => boolean
export type ProtoAction = 'error' | 'remove' | 'ignore'
export type ConstructorAction = 'error' | 'remove' | 'ignore'
export type getDefaultJsonParser = (onProtoPoisoning: ProtoAction, onConstructorPoisoning: ConstructorAction) => FastifyBodyParser<string>