-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathbody-parser.types.ts
82 lines (80 loc) · 1.97 KB
/
body-parser.types.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type {Options as CoBodyOptions} from 'co-body';
import type * as Koa from 'koa';
/**
* List of supported body types
*/
export const supportedBodyTypes = ['json', 'form', 'text', 'xml'] as const;
export type BodyType = (typeof supportedBodyTypes)[number];
/**
* BodyParser Options
*/
export type BodyParserOptions = {
/**
* declares the HTTP methods where bodies will be parsed.
* @default ['POST', 'PUT', 'PATCH']
*/
parsedMethods?: string[];
/**
* patch request body to Node's 'ctx.req'
* @default false
*/
patchNode?: boolean;
/**
* json detector function, can help to detect request json type based on custom logic
*/
detectJSON?: (ctx: Koa.Context) => boolean;
/**
* error handler, can help to customize the response on error case
*/
onError?: (error: Error, ctx: Koa.Context) => void;
/**
* false to disable the raw request body checking to prevent koa request override
* @default false
*/
enableRawChecking?: boolean;
/**
* co-body parser will only parse when request type hits enableTypes
* @default ['json', 'form']
*/
enableTypes?: BodyType[];
/**
* extend parser types, can help to enhance the base mime types with custom types
*/
extendTypes?: {
[K in BodyType]?: string[];
};
/**
* When set to true, JSON parser will only accept arrays and objects.
* When false will accept anything JSON.parse accepts.
*
* @default true
*/
jsonStrict?: CoBodyOptions['strict'];
/**
* limit of the `json` body
* @default '1mb'
*/
jsonLimit?: CoBodyOptions['limit'];
/**
* limit of the `urlencoded` body
* @default '56kb'
*/
formLimit?: CoBodyOptions['limit'];
/**
* limit of the `text` body
* @default '1mb'
*/
textLimit?: CoBodyOptions['limit'];
/**
* limit of the `xml` body
* @default '1mb'
*/
xmlLimit?: CoBodyOptions['limit'];
} & Pick<
CoBodyOptions,
/**
* requested encoding.
* @default 'utf-8' by 'co-body'.
*/
'encoding'
>;