1 |
|
2 |
|
3 | import { Readable } from 'node:stream';
|
4 | import type { MultipartFile } from './multipart/file.js';
|
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?: 'utf-8' | 'iso-8859-1' | undefined;
|
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 | convertEmptyStringsToNull: 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 |
|
50 |
|
51 |
|
52 | export type BodyParserMultipartConfig = BodyParserBaseConfig & {
|
53 | autoProcess: boolean | string[];
|
54 | maxFields: number;
|
55 | processManually: string[];
|
56 | convertEmptyStringsToNull: boolean;
|
57 | fieldsLimit?: number | string;
|
58 | tmpFileName?(): string;
|
59 | };
|
60 |
|
61 |
|
62 |
|
63 | export type BodyParserConfig = {
|
64 | allowedMethods: string[];
|
65 | json: BodyParserJSONConfig;
|
66 | form: BodyParserFormConfig;
|
67 | raw: BodyParserRawConfig;
|
68 | multipart: BodyParserMultipartConfig;
|
69 | };
|
70 |
|
71 |
|
72 |
|
73 | export type BodyParserOptionalConfig = {
|
74 | allowedMethods?: string[];
|
75 | json?: Partial<BodyParserJSONConfig>;
|
76 | form?: Partial<BodyParserFormConfig>;
|
77 | raw?: Partial<BodyParserRawConfig>;
|
78 | multipart?: Partial<BodyParserMultipartConfig>;
|
79 | };
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | export type MultipartStream = Readable & {
|
90 | headers: {
|
91 | [key: string]: string;
|
92 | };
|
93 | name: string;
|
94 | filename: string;
|
95 | bytes: number;
|
96 | file: MultipartFile;
|
97 | };
|
98 |
|
99 |
|
100 |
|
101 | export type PartHandler = (part: MultipartStream, reportChunk: (chunk: Buffer) => void) => Promise<({
|
102 | filePath?: string;
|
103 | tmpPath?: string;
|
104 | } & {
|
105 | [key: string]: any;
|
106 | }) | void>;
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | export type FileValidationOptions = {
|
117 | size: string | number;
|
118 | extnames: string[];
|
119 | };
|
120 |
|
121 |
|
122 |
|
123 | export type FileUploadError = {
|
124 | fieldName: string;
|
125 | clientName: string;
|
126 | message: string;
|
127 | type: 'size' | 'extname' | 'fatal';
|
128 | };
|
129 |
|
130 |
|
131 |
|
132 | export type FileJSON = {
|
133 | fieldName: string;
|
134 | clientName: string;
|
135 | size: number;
|
136 | filePath?: string;
|
137 | fileName?: string;
|
138 | type?: string;
|
139 | extname?: string;
|
140 | subtype?: string;
|
141 | state: 'idle' | 'streaming' | 'consumed' | 'moved';
|
142 | isValid: boolean;
|
143 | validated: boolean;
|
144 | errors: FileUploadError[];
|
145 | meta: any;
|
146 | };
|
147 | export { MultipartFile };
|