1 |
|
2 | declare module '@ioc:Adonis/Core/BodyParser' {
|
3 | import { Readable } from 'stream';
|
4 | import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
5 | |
6 |
|
7 |
|
8 | type QueryStringConfig = {
|
9 | depth?: number;
|
10 | allowPrototypes?: boolean;
|
11 | plainObjects?: boolean;
|
12 | parameterLimit?: number;
|
13 | arrayLimit?: number;
|
14 | ignoreQueryPrefix?: boolean;
|
15 | delimiter?: RegExp | string;
|
16 | allowDots?: boolean;
|
17 | charset?: string;
|
18 | charsetSentinel?: boolean;
|
19 | interpretNumericEntities?: boolean;
|
20 | parseArrays?: boolean;
|
21 | comma?: boolean;
|
22 | };
|
23 | |
24 |
|
25 |
|
26 | type BodyParserBaseConfig = {
|
27 | encoding: string;
|
28 | limit: string | number;
|
29 | types: string[];
|
30 | };
|
31 | |
32 |
|
33 |
|
34 | export type BodyParserJSONConfig = BodyParserBaseConfig & {
|
35 | strict: boolean;
|
36 | };
|
37 | |
38 |
|
39 |
|
40 | export type BodyParserFormConfig = BodyParserBaseConfig & {
|
41 | queryString: QueryStringConfig;
|
42 | convertEmptyStringsToNull: boolean;
|
43 | };
|
44 | |
45 |
|
46 |
|
47 | export type BodyParserRawConfig = BodyParserBaseConfig & {
|
48 | queryString: QueryStringConfig;
|
49 | };
|
50 | |
51 |
|
52 |
|
53 | export type BodyParserMultipartConfig = BodyParserBaseConfig & {
|
54 | autoProcess: boolean;
|
55 | maxFields: number;
|
56 | processManually: string[];
|
57 | convertEmptyStringsToNull: boolean;
|
58 | tmpFileName?(): string;
|
59 | };
|
60 | |
61 |
|
62 |
|
63 | export type BodyParserConfig = {
|
64 | whitelistedMethods: string[];
|
65 | json: BodyParserJSONConfig;
|
66 | form: BodyParserFormConfig;
|
67 | raw: BodyParserRawConfig;
|
68 | multipart: BodyParserMultipartConfig;
|
69 | };
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 | |
76 |
|
77 |
|
78 |
|
79 | export type MultipartStream = Readable & {
|
80 | headers: {
|
81 | [key: string]: string;
|
82 | };
|
83 | name: string;
|
84 | filename: string;
|
85 | bytes: number;
|
86 | file: MultipartFileContract;
|
87 | };
|
88 | |
89 |
|
90 |
|
91 | export type PartHandler = (part: MultipartStream, reportChunk: (chunk: Buffer) => void) => Promise<({
|
92 | filePath?: string;
|
93 | tmpPath?: string;
|
94 | } & {
|
95 | [key: string]: any;
|
96 | }) | void>;
|
97 | |
98 |
|
99 |
|
100 |
|
101 | export interface MultipartContract {
|
102 | state: 'idle' | 'processing' | 'error' | 'success';
|
103 | abort(error: any): void;
|
104 | onFile(name: string, options: Partial<FileValidationOptions & {
|
105 | deferValidations: boolean;
|
106 | }>, callback: PartHandler): this;
|
107 | process(config?: Partial<{
|
108 | limit: string | number;
|
109 | maxFields: number;
|
110 | }>): Promise<void>;
|
111 | }
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | |
118 |
|
119 |
|
120 |
|
121 | export type FileValidationOptions = {
|
122 | size: string | number;
|
123 | extnames: string[];
|
124 | };
|
125 | |
126 |
|
127 |
|
128 | export type FileUploadError = {
|
129 | fieldName: string;
|
130 | clientName: string;
|
131 | message: string;
|
132 | type: 'size' | 'extname' | 'fatal';
|
133 | };
|
134 | |
135 |
|
136 |
|
137 | export type FileJSON = {
|
138 | fieldName: string;
|
139 | clientName: string;
|
140 | size: number;
|
141 | filePath?: string;
|
142 | type?: string;
|
143 | extname?: string;
|
144 | subtype?: string;
|
145 | state: 'idle' | 'streaming' | 'consumed' | 'moved';
|
146 | isValid: boolean;
|
147 | validated: boolean;
|
148 | errors: FileUploadError[];
|
149 | meta: any;
|
150 | };
|
151 | |
152 |
|
153 |
|
154 | export interface MultipartFileContract {
|
155 | isMultipartFile: true;
|
156 | fieldName: string;
|
157 | clientName: string;
|
158 | size: number;
|
159 | headers: {
|
160 | [key: string]: string;
|
161 | };
|
162 | tmpPath?: string;
|
163 | filePath?: string;
|
164 | fileName?: string;
|
165 | type?: string;
|
166 | extname?: string;
|
167 | subtype?: string;
|
168 | state: 'idle' | 'streaming' | 'consumed' | 'moved';
|
169 | isValid: boolean;
|
170 | hasErrors: boolean;
|
171 | validated: boolean;
|
172 | errors: FileUploadError[];
|
173 | sizeLimit?: number | string;
|
174 | allowedExtensions?: string[];
|
175 | meta: any;
|
176 | |
177 |
|
178 |
|
179 | validate(): void;
|
180 | |
181 |
|
182 |
|
183 |
|
184 | move(location: string, options?: {
|
185 | name?: string;
|
186 | overwrite?: boolean;
|
187 | }): Promise<void>;
|
188 | |
189 |
|
190 |
|
191 | toJSON(): FileJSON;
|
192 | }
|
193 | |
194 |
|
195 |
|
196 | export interface BodyParserMiddlewareContract {
|
197 | new (config: BodyParserConfig): {
|
198 | handle(ctx: HttpContextContract, next: () => void): any;
|
199 | };
|
200 | }
|
201 | const BodyParserMiddleware: BodyParserMiddlewareContract;
|
202 | export default BodyParserMiddleware;
|
203 | }
|