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