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