@expressots/core 2.9.1 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CHANGELOG.md +145 -89
- package/lib/cjs/application/{app-container.js → application-container.js} +95 -94
- package/lib/cjs/application/application-factory.js +39 -74
- package/lib/cjs/application/index.js +7 -7
- package/lib/cjs/common/{color-service.provider.js → color-codes.js} +46 -47
- package/lib/cjs/common/index.js +2 -2
- package/lib/cjs/common/{package-resolver.provider.js → package-resolver.js} +35 -35
- package/lib/cjs/common/{project-config.provider.js → project-config.js} +2 -2
- package/lib/cjs/console/console.js +60 -61
- package/lib/cjs/console/index.js +5 -5
- package/lib/cjs/container-module/container-module.js +111 -111
- package/lib/cjs/container-module/index.js +6 -6
- package/lib/cjs/controller/base-controller.js +74 -75
- package/lib/cjs/controller/index.js +5 -5
- package/lib/cjs/decorator/index.js +17 -17
- package/lib/cjs/decorator/scope-binding.js +44 -44
- package/lib/cjs/error/app-error.js +26 -26
- package/lib/cjs/error/error-handler-middleware.js +28 -28
- package/lib/cjs/error/index.js +9 -9
- package/lib/cjs/error/report.js +53 -54
- package/lib/cjs/error/status-code.js +89 -89
- package/lib/cjs/index.js +26 -26
- package/lib/cjs/middleware/index.js +32 -32
- package/lib/cjs/middleware/interfaces/body-parser.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/compression.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/cookie-parser.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/cookie-session/cookie-session.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/cookie-session/keygrip.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/cors.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/express-rate-limit.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/express-session.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/helmet.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/morgan.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/multer.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/serve-favicon.interface.js +2 -2
- package/lib/cjs/middleware/interfaces/serve-static.interface.js +2 -2
- package/lib/cjs/middleware/middleware-resolver.js +72 -72
- package/lib/cjs/middleware/middleware-service.js +480 -481
- package/lib/cjs/provider/db-in-memory/db-in-memory.provider.js +82 -82
- package/lib/cjs/provider/dto-validator/dto-validator.provider.js +53 -53
- package/lib/cjs/provider/environment/env-validator.provider.js +98 -98
- package/lib/cjs/provider/index.js +13 -13
- package/lib/cjs/provider/logger/logger.provider.js +117 -117
- package/lib/cjs/provider/provider-manager.js +49 -50
- package/lib/cjs/render/handlebars.interface.js +2 -2
- package/lib/cjs/render/index.js +2 -2
- package/lib/cjs/render/render.type.js +2 -2
- package/lib/cjs/types/application/{app-container.d.ts → application-container.d.ts} +64 -62
- package/lib/cjs/types/application/application-factory.d.ts +19 -34
- package/lib/cjs/types/application/index.d.ts +2 -2
- package/lib/cjs/types/common/{color-service.provider.d.ts → color-codes.d.ts} +29 -29
- package/lib/cjs/types/common/index.d.ts +1 -1
- package/lib/cjs/types/common/{package-resolver.provider.d.ts → package-resolver.d.ts} +8 -8
- package/lib/cjs/types/common/{project-config.provider.d.ts → project-config.d.ts} +56 -56
- package/lib/cjs/types/console/console.d.ts +27 -27
- package/lib/cjs/types/console/index.d.ts +1 -1
- package/lib/cjs/types/container-module/container-module.d.ts +28 -28
- package/lib/cjs/types/container-module/index.d.ts +1 -1
- package/lib/cjs/types/controller/base-controller.d.ts +48 -48
- package/lib/cjs/types/controller/index.d.ts +1 -1
- package/lib/cjs/types/decorator/index.d.ts +1 -1
- package/lib/cjs/types/decorator/scope-binding.d.ts +33 -33
- package/lib/cjs/types/error/app-error.d.ts +29 -29
- package/lib/cjs/types/error/error-handler-middleware.d.ts +11 -11
- package/lib/cjs/types/error/index.d.ts +3 -3
- package/lib/cjs/types/error/report.d.ts +25 -25
- package/lib/cjs/types/error/status-code.d.ts +136 -136
- package/lib/cjs/types/index.d.ts +10 -10
- package/lib/cjs/types/middleware/index.d.ts +13 -13
- package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts +33 -33
- package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts +98 -98
- package/lib/cjs/types/middleware/interfaces/cookie-parser.interface.d.ts +9 -9
- package/lib/cjs/types/middleware/interfaces/cookie-session/cookie-session.interface.d.ts +57 -57
- package/lib/cjs/types/middleware/interfaces/cookie-session/keygrip.interface.d.ts +27 -27
- package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts +57 -57
- package/lib/cjs/types/middleware/interfaces/express-rate-limit.interface.d.ts +292 -292
- package/lib/cjs/types/middleware/interfaces/express-session.interface.d.ts +207 -207
- package/lib/cjs/types/middleware/interfaces/helmet.interface.d.ts +210 -210
- package/lib/cjs/types/middleware/interfaces/morgan.interface.d.ts +40 -40
- package/lib/cjs/types/middleware/interfaces/multer.interface.d.ts +255 -255
- package/lib/cjs/types/middleware/interfaces/serve-favicon.interface.d.ts +11 -11
- package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts +70 -70
- package/lib/cjs/types/middleware/middleware-resolver.d.ts +11 -11
- package/lib/cjs/types/middleware/middleware-service.d.ts +368 -368
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.provider.d.ts +43 -43
- package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts +11 -11
- package/lib/cjs/types/provider/environment/env-validator.provider.d.ts +35 -35
- package/lib/cjs/types/provider/index.d.ts +5 -5
- package/lib/cjs/types/provider/logger/logger.provider.d.ts +54 -54
- package/lib/cjs/types/provider/provider-manager.d.ts +16 -16
- package/lib/cjs/types/render/handlebars.interface.d.ts +46 -46
- package/lib/cjs/types/render/index.d.ts +2 -2
- package/lib/cjs/types/render/render.type.d.ts +12 -12
- package/lib/package.json +16 -17
- package/package.json +16 -17
|
@@ -1,255 +1,255 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { RequestHandler } from "express";
|
|
4
|
-
import { Readable } from "stream";
|
|
5
|
-
declare global {
|
|
6
|
-
namespace Express {
|
|
7
|
-
namespace Multer {
|
|
8
|
-
/** Object containing file metadata and access information. */
|
|
9
|
-
interface File {
|
|
10
|
-
/** Name of the form field associated with this file. */
|
|
11
|
-
fieldname: string;
|
|
12
|
-
/** Name of the file on the uploader's computer. */
|
|
13
|
-
originalname: string;
|
|
14
|
-
/**
|
|
15
|
-
* Value of the `Content-Transfer-Encoding` header for this file.
|
|
16
|
-
* @deprecated since July 2015
|
|
17
|
-
* @see RFC 7578, Section 4.7
|
|
18
|
-
*/
|
|
19
|
-
encoding: string;
|
|
20
|
-
/** Value of the `Content-Type` header for this file. */
|
|
21
|
-
mimetype: string;
|
|
22
|
-
/** Size of the file in bytes. */
|
|
23
|
-
size: number;
|
|
24
|
-
/**
|
|
25
|
-
* A readable stream of this file. Only available to the `_handleFile`
|
|
26
|
-
* callback for custom `StorageEngine`s.
|
|
27
|
-
*/
|
|
28
|
-
stream: Readable;
|
|
29
|
-
/** `DiskStorage` only: Directory to which this file has been uploaded. */
|
|
30
|
-
destination: string;
|
|
31
|
-
/** `DiskStorage` only: Name of this file within `destination`. */
|
|
32
|
-
filename: string;
|
|
33
|
-
/** `DiskStorage` only: Full path to the uploaded file. */
|
|
34
|
-
path: string;
|
|
35
|
-
/** `MemoryStorage` only: A Buffer containing the entire file. */
|
|
36
|
-
buffer: Buffer;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
interface Request {
|
|
40
|
-
/** `Multer.File` object populated by `single()` middleware. */
|
|
41
|
-
file?: Multer.File | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Array or dictionary of `Multer.File` object populated by `array()`,
|
|
44
|
-
* `fields()`, and `any()` middleware.
|
|
45
|
-
*/
|
|
46
|
-
files?: {
|
|
47
|
-
[fieldname: string]: Multer.File[];
|
|
48
|
-
} | Multer.File[] | undefined;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export declare namespace multer {
|
|
53
|
-
/**
|
|
54
|
-
* @see {@link https://github.com/expressjs/multer#api}
|
|
55
|
-
*/
|
|
56
|
-
interface Multer {
|
|
57
|
-
/**
|
|
58
|
-
* Returns middleware that processes a single file associated with the
|
|
59
|
-
* given form field.
|
|
60
|
-
*
|
|
61
|
-
* The `Request` object will be populated with a `file` object containing
|
|
62
|
-
* information about the processed file.
|
|
63
|
-
*
|
|
64
|
-
* @param fieldName Name of the multipart form field to process.
|
|
65
|
-
*/
|
|
66
|
-
single(fieldName: string): RequestHandler;
|
|
67
|
-
/**
|
|
68
|
-
* Returns middleware that processes multiple files sharing the same field
|
|
69
|
-
* name.
|
|
70
|
-
*
|
|
71
|
-
* The `Request` object will be populated with a `files` array containing
|
|
72
|
-
* an information object for each processed file.
|
|
73
|
-
*
|
|
74
|
-
* @param fieldName Shared name of the multipart form fields to process.
|
|
75
|
-
* @param maxCount Optional. Maximum number of files to process. (default: Infinity)
|
|
76
|
-
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName`
|
|
77
|
-
*/
|
|
78
|
-
array(fieldName: string, maxCount?: number): RequestHandler;
|
|
79
|
-
/**
|
|
80
|
-
* Returns middleware that processes multiple files associated with the
|
|
81
|
-
* given form fields.
|
|
82
|
-
*
|
|
83
|
-
* The `Request` object will be populated with a `files` object which
|
|
84
|
-
* maps each field name to an array of the associated file information
|
|
85
|
-
* objects.
|
|
86
|
-
*
|
|
87
|
-
* @param fields Array of `Field` objects describing multipart form fields to process.
|
|
88
|
-
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName` for any field.
|
|
89
|
-
*/
|
|
90
|
-
fields(fields: ReadonlyArray<Field>): RequestHandler;
|
|
91
|
-
/**
|
|
92
|
-
* Returns middleware that processes all files contained in the multipart
|
|
93
|
-
* request.
|
|
94
|
-
*
|
|
95
|
-
* The `Request` object will be populated with a `files` array containing
|
|
96
|
-
* an information object for each processed file.
|
|
97
|
-
*/
|
|
98
|
-
any(): RequestHandler;
|
|
99
|
-
/**
|
|
100
|
-
* Returns middleware that accepts only non-file multipart form fields.
|
|
101
|
-
*
|
|
102
|
-
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if any file is encountered.
|
|
103
|
-
*/
|
|
104
|
-
none(): RequestHandler;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Returns a `StorageEngine` implementation configured to store files on
|
|
108
|
-
* the local file system.
|
|
109
|
-
*
|
|
110
|
-
* A string or function may be specified to determine the destination
|
|
111
|
-
* directory, and a function to determine filenames. If no options are set,
|
|
112
|
-
* files will be stored in the system's temporary directory with random 32
|
|
113
|
-
* character filenames.
|
|
114
|
-
*/
|
|
115
|
-
function diskStorage(options: DiskStorageOptions): StorageEngine;
|
|
116
|
-
/**
|
|
117
|
-
* Returns a `StorageEngine` implementation configured to store files in
|
|
118
|
-
* memory as `Buffer` objects.
|
|
119
|
-
*/
|
|
120
|
-
function memoryStorage(): StorageEngine;
|
|
121
|
-
type ErrorCode = "LIMIT_PART_COUNT" | "LIMIT_FILE_SIZE" | "LIMIT_FILE_COUNT" | "LIMIT_FIELD_KEY" | "LIMIT_FIELD_VALUE" | "LIMIT_FIELD_COUNT" | "LIMIT_UNEXPECTED_FILE";
|
|
122
|
-
class MulterError extends Error {
|
|
123
|
-
constructor(code: ErrorCode, field?: string);
|
|
124
|
-
/** Name of the MulterError constructor. */
|
|
125
|
-
name: string;
|
|
126
|
-
/** Identifying error code. */
|
|
127
|
-
code: ErrorCode;
|
|
128
|
-
/** Descriptive error message. */
|
|
129
|
-
message: string;
|
|
130
|
-
/** Name of the multipart form field associated with this error. */
|
|
131
|
-
field?: string | undefined;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* a function to control which files should be uploaded and which should be skipped
|
|
135
|
-
* pass a boolean to indicate if the file should be accepted
|
|
136
|
-
* pass an error if something goes wrong
|
|
137
|
-
*/
|
|
138
|
-
interface FileFilterCallback {
|
|
139
|
-
(error: Error): void;
|
|
140
|
-
(error: null, acceptFile: boolean): void;
|
|
141
|
-
}
|
|
142
|
-
/** Options for initializing a Multer instance. */
|
|
143
|
-
interface Options {
|
|
144
|
-
/**
|
|
145
|
-
* A `StorageEngine` responsible for processing files uploaded via Multer.
|
|
146
|
-
* Takes precedence over `dest`.
|
|
147
|
-
*/
|
|
148
|
-
storage?: StorageEngine | undefined;
|
|
149
|
-
/**
|
|
150
|
-
* The destination directory for uploaded files. If `storage` is not set
|
|
151
|
-
* and `dest` is, Multer will create a `DiskStorage` instance configured
|
|
152
|
-
* to store files at `dest` with random filenames.
|
|
153
|
-
*
|
|
154
|
-
* Ignored if `storage` is set.
|
|
155
|
-
*/
|
|
156
|
-
dest?: string | undefined;
|
|
157
|
-
/**
|
|
158
|
-
* An object specifying various limits on incoming data. This object is
|
|
159
|
-
* passed to Busboy directly, and the details of properties can be found
|
|
160
|
-
* at https://github.com/mscdex/busboy#busboy-methods.
|
|
161
|
-
*/
|
|
162
|
-
limits?: {
|
|
163
|
-
/** Maximum size of each form field name in bytes. (Default: 100) */
|
|
164
|
-
fieldNameSize?: number | undefined;
|
|
165
|
-
/** Maximum size of each form field value in bytes. (Default: 1048576) */
|
|
166
|
-
fieldSize?: number | undefined;
|
|
167
|
-
/** Maximum number of non-file form fields. (Default: Infinity) */
|
|
168
|
-
fields?: number | undefined;
|
|
169
|
-
/** Maximum size of each file in bytes. (Default: Infinity) */
|
|
170
|
-
fileSize?: number | undefined;
|
|
171
|
-
/** Maximum number of file fields. (Default: Infinity) */
|
|
172
|
-
files?: number | undefined;
|
|
173
|
-
/** Maximum number of parts (non-file fields + files). (Default: Infinity) */
|
|
174
|
-
parts?: number | undefined;
|
|
175
|
-
/** Maximum number of headers. (Default: 2000) */
|
|
176
|
-
headerPairs?: number | undefined;
|
|
177
|
-
} | undefined;
|
|
178
|
-
/** Preserve the full path of the original filename rather than the basename. (Default: false) */
|
|
179
|
-
preservePath?: boolean | undefined;
|
|
180
|
-
/**
|
|
181
|
-
* Optional function to control which files are uploaded. This is called
|
|
182
|
-
* for every file that is processed.
|
|
183
|
-
*
|
|
184
|
-
* @param req The Express `Request` object.
|
|
185
|
-
* @param file Object containing information about the processed file.
|
|
186
|
-
* @param callback a function to control which files should be uploaded and which should be skipped.
|
|
187
|
-
*/
|
|
188
|
-
fileFilter?(req: Request, file: File, callback: FileFilterCallback): void;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Implementations of this interface are responsible for storing files
|
|
192
|
-
* encountered by Multer and returning information on how to access them
|
|
193
|
-
* once stored. Implementations must also provide a method for removing
|
|
194
|
-
* files in the event that an error occurs.
|
|
195
|
-
*/
|
|
196
|
-
interface StorageEngine {
|
|
197
|
-
/**
|
|
198
|
-
* Store the file described by `file`, then invoke the callback with
|
|
199
|
-
* information about the stored file.
|
|
200
|
-
*
|
|
201
|
-
* File contents are available as a stream via `file.stream`. Information
|
|
202
|
-
* passed to the callback will be merged with `file` for subsequent
|
|
203
|
-
* middleware.
|
|
204
|
-
*
|
|
205
|
-
* @param req The Express `Request` object.
|
|
206
|
-
* @param file Object with `stream`, `fieldname`, `originalname`, `encoding`, and `mimetype` defined.
|
|
207
|
-
* @param callback Callback to specify file information.
|
|
208
|
-
*/
|
|
209
|
-
_handleFile(req: Request, file: File, callback: (error?: any, info?: Partial<File>) => void): void;
|
|
210
|
-
/**
|
|
211
|
-
* Remove the file described by `file`, then invoke the callback with.
|
|
212
|
-
*
|
|
213
|
-
* `file` contains all the properties available to `_handleFile`, as
|
|
214
|
-
* well as those returned by `_handleFile`.
|
|
215
|
-
*
|
|
216
|
-
* @param req The Express `Request` object.
|
|
217
|
-
* @param file Object containing information about the processed file.
|
|
218
|
-
* @param callback Callback to indicate completion.
|
|
219
|
-
*/
|
|
220
|
-
_removeFile(req: Request, file: Express.Multer.File, callback: (error: Error | null) => void): void;
|
|
221
|
-
}
|
|
222
|
-
interface DiskStorageOptions {
|
|
223
|
-
/**
|
|
224
|
-
* A string or function that determines the destination path for uploaded
|
|
225
|
-
* files. If a string is passed and the directory does not exist, Multer
|
|
226
|
-
* attempts to create it recursively. If neither a string or a function
|
|
227
|
-
* is passed, the destination defaults to `os.tmpdir()`.
|
|
228
|
-
*
|
|
229
|
-
* @param req The Express `Request` object.
|
|
230
|
-
* @param file Object containing information about the processed file.
|
|
231
|
-
* @param callback Callback to determine the destination path.
|
|
232
|
-
*/
|
|
233
|
-
destination?: string | ((req: Request, file: Express.Multer.File, callback: (error: Error | null, destination: string) => void) => void) | undefined;
|
|
234
|
-
/**
|
|
235
|
-
* A function that determines the name of the uploaded file. If nothing
|
|
236
|
-
* is passed, Multer will generate a 32 character pseudorandom hex string
|
|
237
|
-
* with no extension.
|
|
238
|
-
*
|
|
239
|
-
* @param req The Express `Request` object.
|
|
240
|
-
* @param file Object containing information about the processed file.
|
|
241
|
-
* @param callback Callback to determine the name of the uploaded file.
|
|
242
|
-
*/
|
|
243
|
-
filename?(req: Request, file: Express.Multer.File, callback: (error: Error | null, filename: string) => void): void;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* An object describing a field name and the maximum number of files with
|
|
247
|
-
* that field name to accept.
|
|
248
|
-
*/
|
|
249
|
-
interface Field {
|
|
250
|
-
/** The field name. */
|
|
251
|
-
name: string;
|
|
252
|
-
/** Optional maximum number of files per field to accept. (Default: Infinity) */
|
|
253
|
-
maxCount?: number | undefined;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { RequestHandler } from "express";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
declare global {
|
|
6
|
+
namespace Express {
|
|
7
|
+
namespace Multer {
|
|
8
|
+
/** Object containing file metadata and access information. */
|
|
9
|
+
interface File {
|
|
10
|
+
/** Name of the form field associated with this file. */
|
|
11
|
+
fieldname: string;
|
|
12
|
+
/** Name of the file on the uploader's computer. */
|
|
13
|
+
originalname: string;
|
|
14
|
+
/**
|
|
15
|
+
* Value of the `Content-Transfer-Encoding` header for this file.
|
|
16
|
+
* @deprecated since July 2015
|
|
17
|
+
* @see RFC 7578, Section 4.7
|
|
18
|
+
*/
|
|
19
|
+
encoding: string;
|
|
20
|
+
/** Value of the `Content-Type` header for this file. */
|
|
21
|
+
mimetype: string;
|
|
22
|
+
/** Size of the file in bytes. */
|
|
23
|
+
size: number;
|
|
24
|
+
/**
|
|
25
|
+
* A readable stream of this file. Only available to the `_handleFile`
|
|
26
|
+
* callback for custom `StorageEngine`s.
|
|
27
|
+
*/
|
|
28
|
+
stream: Readable;
|
|
29
|
+
/** `DiskStorage` only: Directory to which this file has been uploaded. */
|
|
30
|
+
destination: string;
|
|
31
|
+
/** `DiskStorage` only: Name of this file within `destination`. */
|
|
32
|
+
filename: string;
|
|
33
|
+
/** `DiskStorage` only: Full path to the uploaded file. */
|
|
34
|
+
path: string;
|
|
35
|
+
/** `MemoryStorage` only: A Buffer containing the entire file. */
|
|
36
|
+
buffer: Buffer;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
interface Request {
|
|
40
|
+
/** `Multer.File` object populated by `single()` middleware. */
|
|
41
|
+
file?: Multer.File | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Array or dictionary of `Multer.File` object populated by `array()`,
|
|
44
|
+
* `fields()`, and `any()` middleware.
|
|
45
|
+
*/
|
|
46
|
+
files?: {
|
|
47
|
+
[fieldname: string]: Multer.File[];
|
|
48
|
+
} | Multer.File[] | undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export declare namespace multer {
|
|
53
|
+
/**
|
|
54
|
+
* @see {@link https://github.com/expressjs/multer#api}
|
|
55
|
+
*/
|
|
56
|
+
interface Multer {
|
|
57
|
+
/**
|
|
58
|
+
* Returns middleware that processes a single file associated with the
|
|
59
|
+
* given form field.
|
|
60
|
+
*
|
|
61
|
+
* The `Request` object will be populated with a `file` object containing
|
|
62
|
+
* information about the processed file.
|
|
63
|
+
*
|
|
64
|
+
* @param fieldName Name of the multipart form field to process.
|
|
65
|
+
*/
|
|
66
|
+
single(fieldName: string): RequestHandler;
|
|
67
|
+
/**
|
|
68
|
+
* Returns middleware that processes multiple files sharing the same field
|
|
69
|
+
* name.
|
|
70
|
+
*
|
|
71
|
+
* The `Request` object will be populated with a `files` array containing
|
|
72
|
+
* an information object for each processed file.
|
|
73
|
+
*
|
|
74
|
+
* @param fieldName Shared name of the multipart form fields to process.
|
|
75
|
+
* @param maxCount Optional. Maximum number of files to process. (default: Infinity)
|
|
76
|
+
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName`
|
|
77
|
+
*/
|
|
78
|
+
array(fieldName: string, maxCount?: number): RequestHandler;
|
|
79
|
+
/**
|
|
80
|
+
* Returns middleware that processes multiple files associated with the
|
|
81
|
+
* given form fields.
|
|
82
|
+
*
|
|
83
|
+
* The `Request` object will be populated with a `files` object which
|
|
84
|
+
* maps each field name to an array of the associated file information
|
|
85
|
+
* objects.
|
|
86
|
+
*
|
|
87
|
+
* @param fields Array of `Field` objects describing multipart form fields to process.
|
|
88
|
+
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName` for any field.
|
|
89
|
+
*/
|
|
90
|
+
fields(fields: ReadonlyArray<Field>): RequestHandler;
|
|
91
|
+
/**
|
|
92
|
+
* Returns middleware that processes all files contained in the multipart
|
|
93
|
+
* request.
|
|
94
|
+
*
|
|
95
|
+
* The `Request` object will be populated with a `files` array containing
|
|
96
|
+
* an information object for each processed file.
|
|
97
|
+
*/
|
|
98
|
+
any(): RequestHandler;
|
|
99
|
+
/**
|
|
100
|
+
* Returns middleware that accepts only non-file multipart form fields.
|
|
101
|
+
*
|
|
102
|
+
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if any file is encountered.
|
|
103
|
+
*/
|
|
104
|
+
none(): RequestHandler;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns a `StorageEngine` implementation configured to store files on
|
|
108
|
+
* the local file system.
|
|
109
|
+
*
|
|
110
|
+
* A string or function may be specified to determine the destination
|
|
111
|
+
* directory, and a function to determine filenames. If no options are set,
|
|
112
|
+
* files will be stored in the system's temporary directory with random 32
|
|
113
|
+
* character filenames.
|
|
114
|
+
*/
|
|
115
|
+
function diskStorage(options: DiskStorageOptions): StorageEngine;
|
|
116
|
+
/**
|
|
117
|
+
* Returns a `StorageEngine` implementation configured to store files in
|
|
118
|
+
* memory as `Buffer` objects.
|
|
119
|
+
*/
|
|
120
|
+
function memoryStorage(): StorageEngine;
|
|
121
|
+
type ErrorCode = "LIMIT_PART_COUNT" | "LIMIT_FILE_SIZE" | "LIMIT_FILE_COUNT" | "LIMIT_FIELD_KEY" | "LIMIT_FIELD_VALUE" | "LIMIT_FIELD_COUNT" | "LIMIT_UNEXPECTED_FILE";
|
|
122
|
+
class MulterError extends Error {
|
|
123
|
+
constructor(code: ErrorCode, field?: string);
|
|
124
|
+
/** Name of the MulterError constructor. */
|
|
125
|
+
name: string;
|
|
126
|
+
/** Identifying error code. */
|
|
127
|
+
code: ErrorCode;
|
|
128
|
+
/** Descriptive error message. */
|
|
129
|
+
message: string;
|
|
130
|
+
/** Name of the multipart form field associated with this error. */
|
|
131
|
+
field?: string | undefined;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* a function to control which files should be uploaded and which should be skipped
|
|
135
|
+
* pass a boolean to indicate if the file should be accepted
|
|
136
|
+
* pass an error if something goes wrong
|
|
137
|
+
*/
|
|
138
|
+
interface FileFilterCallback {
|
|
139
|
+
(error: Error): void;
|
|
140
|
+
(error: null, acceptFile: boolean): void;
|
|
141
|
+
}
|
|
142
|
+
/** Options for initializing a Multer instance. */
|
|
143
|
+
interface Options {
|
|
144
|
+
/**
|
|
145
|
+
* A `StorageEngine` responsible for processing files uploaded via Multer.
|
|
146
|
+
* Takes precedence over `dest`.
|
|
147
|
+
*/
|
|
148
|
+
storage?: StorageEngine | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* The destination directory for uploaded files. If `storage` is not set
|
|
151
|
+
* and `dest` is, Multer will create a `DiskStorage` instance configured
|
|
152
|
+
* to store files at `dest` with random filenames.
|
|
153
|
+
*
|
|
154
|
+
* Ignored if `storage` is set.
|
|
155
|
+
*/
|
|
156
|
+
dest?: string | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* An object specifying various limits on incoming data. This object is
|
|
159
|
+
* passed to Busboy directly, and the details of properties can be found
|
|
160
|
+
* at https://github.com/mscdex/busboy#busboy-methods.
|
|
161
|
+
*/
|
|
162
|
+
limits?: {
|
|
163
|
+
/** Maximum size of each form field name in bytes. (Default: 100) */
|
|
164
|
+
fieldNameSize?: number | undefined;
|
|
165
|
+
/** Maximum size of each form field value in bytes. (Default: 1048576) */
|
|
166
|
+
fieldSize?: number | undefined;
|
|
167
|
+
/** Maximum number of non-file form fields. (Default: Infinity) */
|
|
168
|
+
fields?: number | undefined;
|
|
169
|
+
/** Maximum size of each file in bytes. (Default: Infinity) */
|
|
170
|
+
fileSize?: number | undefined;
|
|
171
|
+
/** Maximum number of file fields. (Default: Infinity) */
|
|
172
|
+
files?: number | undefined;
|
|
173
|
+
/** Maximum number of parts (non-file fields + files). (Default: Infinity) */
|
|
174
|
+
parts?: number | undefined;
|
|
175
|
+
/** Maximum number of headers. (Default: 2000) */
|
|
176
|
+
headerPairs?: number | undefined;
|
|
177
|
+
} | undefined;
|
|
178
|
+
/** Preserve the full path of the original filename rather than the basename. (Default: false) */
|
|
179
|
+
preservePath?: boolean | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Optional function to control which files are uploaded. This is called
|
|
182
|
+
* for every file that is processed.
|
|
183
|
+
*
|
|
184
|
+
* @param req The Express `Request` object.
|
|
185
|
+
* @param file Object containing information about the processed file.
|
|
186
|
+
* @param callback a function to control which files should be uploaded and which should be skipped.
|
|
187
|
+
*/
|
|
188
|
+
fileFilter?(req: Request, file: File, callback: FileFilterCallback): void;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Implementations of this interface are responsible for storing files
|
|
192
|
+
* encountered by Multer and returning information on how to access them
|
|
193
|
+
* once stored. Implementations must also provide a method for removing
|
|
194
|
+
* files in the event that an error occurs.
|
|
195
|
+
*/
|
|
196
|
+
interface StorageEngine {
|
|
197
|
+
/**
|
|
198
|
+
* Store the file described by `file`, then invoke the callback with
|
|
199
|
+
* information about the stored file.
|
|
200
|
+
*
|
|
201
|
+
* File contents are available as a stream via `file.stream`. Information
|
|
202
|
+
* passed to the callback will be merged with `file` for subsequent
|
|
203
|
+
* middleware.
|
|
204
|
+
*
|
|
205
|
+
* @param req The Express `Request` object.
|
|
206
|
+
* @param file Object with `stream`, `fieldname`, `originalname`, `encoding`, and `mimetype` defined.
|
|
207
|
+
* @param callback Callback to specify file information.
|
|
208
|
+
*/
|
|
209
|
+
_handleFile(req: Request, file: File, callback: (error?: any, info?: Partial<File>) => void): void;
|
|
210
|
+
/**
|
|
211
|
+
* Remove the file described by `file`, then invoke the callback with.
|
|
212
|
+
*
|
|
213
|
+
* `file` contains all the properties available to `_handleFile`, as
|
|
214
|
+
* well as those returned by `_handleFile`.
|
|
215
|
+
*
|
|
216
|
+
* @param req The Express `Request` object.
|
|
217
|
+
* @param file Object containing information about the processed file.
|
|
218
|
+
* @param callback Callback to indicate completion.
|
|
219
|
+
*/
|
|
220
|
+
_removeFile(req: Request, file: Express.Multer.File, callback: (error: Error | null) => void): void;
|
|
221
|
+
}
|
|
222
|
+
interface DiskStorageOptions {
|
|
223
|
+
/**
|
|
224
|
+
* A string or function that determines the destination path for uploaded
|
|
225
|
+
* files. If a string is passed and the directory does not exist, Multer
|
|
226
|
+
* attempts to create it recursively. If neither a string or a function
|
|
227
|
+
* is passed, the destination defaults to `os.tmpdir()`.
|
|
228
|
+
*
|
|
229
|
+
* @param req The Express `Request` object.
|
|
230
|
+
* @param file Object containing information about the processed file.
|
|
231
|
+
* @param callback Callback to determine the destination path.
|
|
232
|
+
*/
|
|
233
|
+
destination?: string | ((req: Request, file: Express.Multer.File, callback: (error: Error | null, destination: string) => void) => void) | undefined;
|
|
234
|
+
/**
|
|
235
|
+
* A function that determines the name of the uploaded file. If nothing
|
|
236
|
+
* is passed, Multer will generate a 32 character pseudorandom hex string
|
|
237
|
+
* with no extension.
|
|
238
|
+
*
|
|
239
|
+
* @param req The Express `Request` object.
|
|
240
|
+
* @param file Object containing information about the processed file.
|
|
241
|
+
* @param callback Callback to determine the name of the uploaded file.
|
|
242
|
+
*/
|
|
243
|
+
filename?(req: Request, file: Express.Multer.File, callback: (error: Error | null, filename: string) => void): void;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* An object describing a field name and the maximum number of files with
|
|
247
|
+
* that field name to accept.
|
|
248
|
+
*/
|
|
249
|
+
interface Field {
|
|
250
|
+
/** The field name. */
|
|
251
|
+
name: string;
|
|
252
|
+
/** Optional maximum number of files per field to accept. (Default: Infinity) */
|
|
253
|
+
maxCount?: number | undefined;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ServeFaviconOptions defines the available options for configuring the serve-favicon middleware.
|
|
3
|
-
*/
|
|
4
|
-
interface ServeFaviconOptions {
|
|
5
|
-
/**
|
|
6
|
-
* The cache-control max-age directive in ms, defaulting to 1 year.
|
|
7
|
-
* This can also be a string accepted by the `ms` module.
|
|
8
|
-
*/
|
|
9
|
-
maxAge?: number | string | undefined;
|
|
10
|
-
}
|
|
11
|
-
export { ServeFaviconOptions };
|
|
1
|
+
/**
|
|
2
|
+
* ServeFaviconOptions defines the available options for configuring the serve-favicon middleware.
|
|
3
|
+
*/
|
|
4
|
+
interface ServeFaviconOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The cache-control max-age directive in ms, defaulting to 1 year.
|
|
7
|
+
* This can also be a string accepted by the `ms` module.
|
|
8
|
+
*/
|
|
9
|
+
maxAge?: number | string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export { ServeFaviconOptions };
|