@expressots/core 2.6.0 → 2.8.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 +49 -0
- package/lib/cjs/middleware/index.js +4 -1
- package/lib/cjs/middleware/interfaces/multer.interface.js +2 -0
- package/lib/cjs/middleware/middleware-resolver.js +1 -0
- package/lib/cjs/middleware/middleware-service.js +220 -41
- package/lib/cjs/provider/db-in-memory/db-in-memory.provider.js +75 -0
- package/lib/cjs/provider/index.js +3 -1
- package/lib/cjs/types/middleware/index.d.ts +2 -1
- package/lib/cjs/types/middleware/interfaces/express-session.interface.d.ts +0 -1
- package/lib/cjs/types/middleware/interfaces/multer.interface.d.ts +255 -0
- package/lib/cjs/types/middleware/middleware-resolver.d.ts +2 -2
- package/lib/cjs/types/middleware/middleware-service.d.ts +111 -18
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.provider.d.ts +38 -0
- package/lib/cjs/types/provider/index.d.ts +1 -0
- package/lib/package.json +7 -7
- package/package.json +7 -7
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [2.8.0](https://github.com/expressots/expressots/compare/2.7.0...2.8.0) (2024-3-5)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add middleware handler, config and expresso ([df60183](https://github.com/expressots/expressots/commit/df601837a771662723f25f185622de8c912f6721))
|
|
9
|
+
* add provide annotation to abstract class ExpressMiddleware ([49e762e](https://github.com/expressots/expressots/commit/49e762e035053d67a977d54d9f448334e931134b))
|
|
10
|
+
* Added it into options wiring ([58e58c1](https://github.com/expressots/expressots/commit/58e58c11693d8dfc8e235bbc5b8d62aa35493ec9))
|
|
11
|
+
* Added multer middleware for expressots ([522db5d](https://github.com/expressots/expressots/commit/522db5d58dd4521fd03528cf4178cbbc951a0537))
|
|
12
|
+
* bump @commitlint/cli from 17.8.1 to 18.0.0 ([4ddcbd4](https://github.com/expressots/expressots/commit/4ddcbd49ffe65cfa7a15b253515bb7f3446046ee))
|
|
13
|
+
* bump @commitlint/config-conventional from 17.8.1 to 18.0.0 ([91e1237](https://github.com/expressots/expressots/commit/91e12370f9736188805df20d4f7da378720ac43b))
|
|
14
|
+
* bump husky from 8.0.3 to 9.0.11 ([#170](https://github.com/expressots/expressots/issues/170)) ([342983f](https://github.com/expressots/expressots/commit/342983fe59d6ccc409f887f7a1c8f65c9469a8d7))
|
|
15
|
+
* bump prettier from 3.0.3 to 3.1.1 ([#145](https://github.com/expressots/expressots/issues/145)) ([2e7b812](https://github.com/expressots/expressots/commit/2e7b81226c65468edacae51407ce56c78c66a85b))
|
|
16
|
+
* bump prettier from 3.1.1 to 3.2.5 ([#166](https://github.com/expressots/expressots/issues/166)) ([49c148c](https://github.com/expressots/expressots/commit/49c148c2fae6b4e0260650fbbcf559c69075d9bc))
|
|
17
|
+
* bump reflect-metadata from 0.1.14 to 0.2.1 ([#148](https://github.com/expressots/expressots/issues/148)) ([f444982](https://github.com/expressots/expressots/commit/f444982ccbedb75f3c26b982a2a5d5d336857aae))
|
|
18
|
+
* bump vite from 4.4.11 to 4.5.0 ([344161c](https://github.com/expressots/expressots/commit/344161cdf0cd7f54ffaa069023241aaea04d7c5d))
|
|
19
|
+
* comments addressed ([8c3f55a](https://github.com/expressots/expressots/commit/8c3f55a901874c1e9c33d415157fa0a2beab9c56))
|
|
20
|
+
* correct expresso middleware path ([0879c10](https://github.com/expressots/expressots/commit/0879c104810256f5143dcb2206579debaf0e6a97))
|
|
21
|
+
* Include multer as resolver ([056d4d9](https://github.com/expressots/expressots/commit/056d4d99801f9f4af2932bcee333a1fa652b45a8))
|
|
22
|
+
* remove getmiddleware pipeline from interface ([0577527](https://github.com/expressots/expressots/commit/057752754e257552eddebf031cf977f663b093ed))
|
|
23
|
+
* Remove multer dependency / Added dynamic multer usage behavior ([6a4530b](https://github.com/expressots/expressots/commit/6a4530be243c961e5bfe50340d2c41742332e186))
|
|
24
|
+
* Remove multer dependency with interface defined ([5a0acd2](https://github.com/expressots/expressots/commit/5a0acd228166efc2de8f4be7078c21ed6fd34634))
|
|
25
|
+
* Remove multer dependency with interface defined ([8133621](https://github.com/expressots/expressots/commit/8133621108bb7f2017088d59ae6145da8606ebf7))
|
|
26
|
+
* update reflect metadata on templates ([#152](https://github.com/expressots/expressots/issues/152)) ([75a3312](https://github.com/expressots/expressots/commit/75a33122e0f468b9e28040b8e7eb6747252e4c6b))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* interface types and middleware return multer ([b5223fd](https://github.com/expressots/expressots/commit/b5223fdc22eaaf1cb9b315b2aa77ad0e615e8ed3))
|
|
32
|
+
* remove codesee build ([#177](https://github.com/expressots/expressots/issues/177)) ([812e06d](https://github.com/expressots/expressots/commit/812e06da1b91cc7a4b0685ec70b0f0de1bd4517b))
|
|
33
|
+
|
|
34
|
+
## [2.7.0](https://github.com/expressots/expressots/compare/2.6.0...2.7.0) (2023-10-17)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
* add db in memory as provider ([b656f22](https://github.com/expressots/expressots/commit/b656f2297e0e985dd5184c611f795edddf6c5b2d))
|
|
40
|
+
* modify IMemoryDB interface name ([fd1d440](https://github.com/expressots/expressots/commit/fd1d440eb947f377955bfc2a969d3e7ca4ffaa3e))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Bug Fixes
|
|
44
|
+
|
|
45
|
+
* remove db in memory from template opinionated ([0516c8c](https://github.com/expressots/expressots/commit/0516c8c4e9c0e1a4b8aae3fab5842136a0565a39))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Tests
|
|
49
|
+
|
|
50
|
+
* improve collocation and fix console tests ([52bdf98](https://github.com/expressots/expressots/commit/52bdf98cfcbbffc58841b1b67c6ce2a1f6fe308b))
|
|
51
|
+
|
|
3
52
|
## [2.6.0](https://github.com/expressots/expressots/compare/2.5.0...2.6.0) (2023-10-09)
|
|
4
53
|
|
|
5
54
|
|
|
@@ -23,7 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.IMorgan = exports.Middleware = void 0;
|
|
26
|
+
exports.IMorgan = exports.multer = exports.ExpressoMiddleware = exports.Middleware = void 0;
|
|
27
27
|
var middleware_service_1 = require("./middleware-service");
|
|
28
28
|
Object.defineProperty(exports, "Middleware", { enumerable: true, get: function () { return middleware_service_1.Middleware; } });
|
|
29
|
+
Object.defineProperty(exports, "ExpressoMiddleware", { enumerable: true, get: function () { return middleware_service_1.ExpressoMiddleware; } });
|
|
30
|
+
var multer_interface_1 = require("./interfaces/multer.interface");
|
|
31
|
+
Object.defineProperty(exports, "multer", { enumerable: true, get: function () { return multer_interface_1.multer; } });
|
|
29
32
|
exports.IMorgan = __importStar(require("./interfaces/morgan.interface"));
|
|
@@ -8,14 +8,42 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
|
-
var Middleware_1;
|
|
11
|
+
var ExpressoMiddleware_1, Middleware_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.Middleware = void 0;
|
|
13
|
+
exports.Middleware = exports.ExpressoMiddleware = void 0;
|
|
14
14
|
const express_1 = __importDefault(require("express"));
|
|
15
15
|
const index_1 = require("../decorator/index");
|
|
16
16
|
const error_handler_middleware_1 = __importDefault(require("../error/error-handler-middleware"));
|
|
17
17
|
const logger_service_1 = require("../provider/logger/logger-service");
|
|
18
18
|
const middleware_resolver_1 = require("./middleware-resolver");
|
|
19
|
+
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
20
|
+
/**
|
|
21
|
+
* Abstract class for creating custom Expresso middleware.
|
|
22
|
+
* Custom middleware classes should extend this class and implement the use method.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
let ExpressoMiddleware = exports.ExpressoMiddleware = ExpressoMiddleware_1 = class ExpressoMiddleware {
|
|
26
|
+
get name() {
|
|
27
|
+
return this.constructor.name;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.ExpressoMiddleware = ExpressoMiddleware = ExpressoMiddleware_1 = __decorate([
|
|
31
|
+
(0, inversify_binding_decorators_1.provide)(ExpressoMiddleware_1)
|
|
32
|
+
], ExpressoMiddleware);
|
|
33
|
+
/**
|
|
34
|
+
* MiddlewareType Enum
|
|
35
|
+
*
|
|
36
|
+
* The MiddlewareType enum represents the various types of middleware that can be added to the middleware collection.
|
|
37
|
+
* - Config: Middleware configuration object.
|
|
38
|
+
* - ExpressHandler: Express request handler function.
|
|
39
|
+
* - IExpressoMiddleware: Custom Expresso middleware.
|
|
40
|
+
*/
|
|
41
|
+
var MiddlewareType;
|
|
42
|
+
(function (MiddlewareType) {
|
|
43
|
+
MiddlewareType[MiddlewareType["Config"] = 0] = "Config";
|
|
44
|
+
MiddlewareType[MiddlewareType["ExpressHandler"] = 1] = "ExpressHandler";
|
|
45
|
+
MiddlewareType[MiddlewareType["IExpressoMiddleware"] = 2] = "IExpressoMiddleware";
|
|
46
|
+
})(MiddlewareType || (MiddlewareType = {}));
|
|
19
47
|
/**
|
|
20
48
|
* Singleton class that implements the IConfigure interface.
|
|
21
49
|
* Manages the middleware configuration for the application,
|
|
@@ -27,6 +55,25 @@ let Middleware = Middleware_1 = class Middleware {
|
|
|
27
55
|
middlewarePipeline = [];
|
|
28
56
|
errorHandler;
|
|
29
57
|
logger = new logger_service_1.Logger();
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves the type of the middleware.
|
|
60
|
+
*
|
|
61
|
+
* @param middleware - The middleware to be checked.
|
|
62
|
+
*
|
|
63
|
+
* @returns The type of the middleware.
|
|
64
|
+
*/
|
|
65
|
+
getMiddlewareType(middleware) {
|
|
66
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
67
|
+
if (middleware?.hasOwnProperty("path")) {
|
|
68
|
+
return MiddlewareType.Config;
|
|
69
|
+
}
|
|
70
|
+
else if (middleware instanceof Function) {
|
|
71
|
+
return MiddlewareType.ExpressHandler;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return MiddlewareType.IExpressoMiddleware;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
30
77
|
/**
|
|
31
78
|
* Checks if a middleware with the given name exists in the middleware collection.
|
|
32
79
|
*
|
|
@@ -35,10 +82,15 @@ let Middleware = Middleware_1 = class Middleware {
|
|
|
35
82
|
* @returns A boolean value indicating whether the middleware exists or not.
|
|
36
83
|
*/
|
|
37
84
|
middlewareExists(middlewareName) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
85
|
+
return this.middlewarePipeline.some((m) => {
|
|
86
|
+
if (m.middleware instanceof Function) {
|
|
87
|
+
return m.middleware.name === middlewareName;
|
|
88
|
+
}
|
|
89
|
+
else if (m.middleware instanceof Object) {
|
|
90
|
+
return m.middleware.path === middlewareName;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
});
|
|
42
94
|
}
|
|
43
95
|
addRateLimiter(options) {
|
|
44
96
|
const middleware = (0, middleware_resolver_1.middlewareResolver)("rateLimit", options);
|
|
@@ -161,6 +213,14 @@ let Middleware = Middleware_1 = class Middleware {
|
|
|
161
213
|
});
|
|
162
214
|
}
|
|
163
215
|
}
|
|
216
|
+
setupMulter(options) {
|
|
217
|
+
const multerMiddleware = (0, middleware_resolver_1.middlewareResolver)("multer", options);
|
|
218
|
+
const middlewareExist = this.middlewareExists("multer");
|
|
219
|
+
if (multerMiddleware && !middlewareExist) {
|
|
220
|
+
return multerMiddleware;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
164
224
|
/**
|
|
165
225
|
* Adds a middleware to enhance security by setting various HTTP headers.
|
|
166
226
|
*
|
|
@@ -226,55 +286,141 @@ let Middleware = Middleware_1 = class Middleware {
|
|
|
226
286
|
}
|
|
227
287
|
}
|
|
228
288
|
/**
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* @
|
|
232
|
-
*
|
|
289
|
+
* Helper method to add middleware configuration objects to the middleware collection.
|
|
290
|
+
* @param middleware - The middleware configuration object to be added to the middleware collection.
|
|
291
|
+
* @returns void
|
|
233
292
|
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
};
|
|
293
|
+
addConfigMiddleware(middleware) {
|
|
294
|
+
// eslint-disable-next-line no-case-declarations
|
|
295
|
+
const config = middleware;
|
|
296
|
+
let routeExists = false;
|
|
297
|
+
if (config.middlewares.length === 0) {
|
|
298
|
+
this.logger.warn(`No middlewares in the route [${config.path}]. Skipping...`, "configure-service");
|
|
299
|
+
return;
|
|
242
300
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
};
|
|
301
|
+
if (this.middlewarePipeline.length === 0) {
|
|
302
|
+
this.middlewarePipeline.push({
|
|
303
|
+
timestamp: new Date(),
|
|
304
|
+
middleware: config,
|
|
305
|
+
});
|
|
248
306
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
307
|
+
else {
|
|
308
|
+
this.middlewarePipeline.forEach((m) => {
|
|
309
|
+
if (m.middleware.path === config.path) {
|
|
310
|
+
this.logger.warn(`[${config.path}] route already exists. Skipping...`, "configure-service");
|
|
311
|
+
routeExists = true;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
if (!routeExists) {
|
|
256
315
|
this.middlewarePipeline.push({
|
|
257
316
|
timestamp: new Date(),
|
|
258
317
|
middleware: config,
|
|
259
318
|
});
|
|
260
319
|
}
|
|
261
320
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Helper method to add express request handler functions to the middleware collection.
|
|
324
|
+
* @param middleware - The express request handler function to be added to the middleware collection.
|
|
325
|
+
* @returns void
|
|
326
|
+
*/
|
|
327
|
+
addExpressHandlerMiddleware(middleware) {
|
|
328
|
+
let middlewareExists = false;
|
|
329
|
+
if (this.middlewarePipeline.length === 0) {
|
|
330
|
+
this.middlewarePipeline.push({
|
|
331
|
+
timestamp: new Date(),
|
|
332
|
+
middleware,
|
|
333
|
+
});
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
this.middlewarePipeline.forEach((m) => {
|
|
337
|
+
const mType = this.getMiddlewareType(m.middleware);
|
|
338
|
+
if (mType === MiddlewareType.ExpressHandler) {
|
|
339
|
+
if (m.middleware?.name === middleware?.name) {
|
|
340
|
+
this.logger.warn(`[${middleware?.name}] already exists. Skipping...`, "configure-service");
|
|
341
|
+
middlewareExists = true;
|
|
342
|
+
return;
|
|
268
343
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
if (!middlewareExists) {
|
|
347
|
+
this.middlewarePipeline.push({
|
|
348
|
+
timestamp: new Date(),
|
|
349
|
+
middleware,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Helper method to add custom Expresso middleware to the middleware collection.
|
|
355
|
+
* @param middleware - The custom Expresso middleware to be added to the middleware collection.
|
|
356
|
+
* @returns void
|
|
357
|
+
*/
|
|
358
|
+
addIExpressoMiddleware(middleware) {
|
|
359
|
+
let middlewareExists = false;
|
|
360
|
+
if (this.middlewarePipeline.length === 0) {
|
|
361
|
+
this.middlewarePipeline.push({
|
|
362
|
+
timestamp: new Date(),
|
|
363
|
+
middleware,
|
|
364
|
+
});
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
this.middlewarePipeline.forEach((m) => {
|
|
368
|
+
const mType = this.getMiddlewareType(m.middleware);
|
|
369
|
+
if (mType === MiddlewareType.IExpressoMiddleware) {
|
|
370
|
+
if (m.middleware.constructor.name ===
|
|
371
|
+
middleware.constructor.name) {
|
|
372
|
+
this.logger.warn(`[${middleware.constructor.name}] already exists. Skipping...`, "configure-service");
|
|
373
|
+
middlewareExists = true;
|
|
374
|
+
return;
|
|
274
375
|
}
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
if (!middlewareExists) {
|
|
379
|
+
this.middlewarePipeline.push({
|
|
380
|
+
timestamp: new Date(),
|
|
381
|
+
middleware,
|
|
275
382
|
});
|
|
276
383
|
}
|
|
277
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Adds a middleware to the middleware collection.
|
|
387
|
+
*
|
|
388
|
+
* @param options - The Express request handler function to be added to the middleware collection, or a middleware configuration object
|
|
389
|
+
* that is composed by a route and an expressjs handler, or a custom Expresso middleware.
|
|
390
|
+
*
|
|
391
|
+
* @example Express Handler
|
|
392
|
+
* const middleware = (req, res, next) => {
|
|
393
|
+
* // Your middleware logic here
|
|
394
|
+
* next();
|
|
395
|
+
* }
|
|
396
|
+
*
|
|
397
|
+
* @example Middleware Configuration Object
|
|
398
|
+
* const middleware = {
|
|
399
|
+
* path: "/",
|
|
400
|
+
* middlewares: [] // Array of Express Handlers
|
|
401
|
+
* }
|
|
402
|
+
*
|
|
403
|
+
* @example Expresso Middleware
|
|
404
|
+
* class CustomMiddleware implements IExpressoMiddleware {
|
|
405
|
+
* use(req: Request, res: Response, next: NextFunction): Promise<void> | void {
|
|
406
|
+
* // Your middleware logic here
|
|
407
|
+
* next();
|
|
408
|
+
* }
|
|
409
|
+
* }
|
|
410
|
+
*/
|
|
411
|
+
addMiddleware(options) {
|
|
412
|
+
switch (this.getMiddlewareType(options)) {
|
|
413
|
+
case MiddlewareType.Config:
|
|
414
|
+
this.addConfigMiddleware(options);
|
|
415
|
+
break;
|
|
416
|
+
case MiddlewareType.ExpressHandler:
|
|
417
|
+
this.addExpressHandlerMiddleware(options);
|
|
418
|
+
break;
|
|
419
|
+
case MiddlewareType.IExpressoMiddleware:
|
|
420
|
+
this.addIExpressoMiddleware(options);
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
278
424
|
/**
|
|
279
425
|
* Retrieves middleware pipeline in the order they were added.
|
|
280
426
|
*
|
|
@@ -285,6 +431,39 @@ let Middleware = Middleware_1 = class Middleware {
|
|
|
285
431
|
return a.timestamp.getTime() - b.timestamp.getTime();
|
|
286
432
|
});
|
|
287
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* View middleware pipeline formatted.
|
|
436
|
+
* @returns void
|
|
437
|
+
*/
|
|
438
|
+
viewMiddlewarePipeline() {
|
|
439
|
+
const sortedMiddlewarePipeline = this.getMiddlewarePipeline();
|
|
440
|
+
const formattedPipeline = sortedMiddlewarePipeline.map((m) => {
|
|
441
|
+
const middlewareType = this.getMiddlewareType(m.middleware);
|
|
442
|
+
if (middlewareType === MiddlewareType.Config) {
|
|
443
|
+
const middlewareNames = m.middleware.middlewares.map((mw) => mw?.name || "Anonymous");
|
|
444
|
+
return {
|
|
445
|
+
timestamp: m.timestamp.toISOString(),
|
|
446
|
+
path: m.middleware.path,
|
|
447
|
+
middleware: `[${middlewareNames.join(", ")}]`,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
else if (middlewareType === MiddlewareType.IExpressoMiddleware) {
|
|
451
|
+
return {
|
|
452
|
+
timestamp: m.timestamp.toISOString(),
|
|
453
|
+
path: m.middleware.path ?? "Global",
|
|
454
|
+
middleware: m.middleware.constructor.name,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
return {
|
|
459
|
+
timestamp: m.timestamp.toISOString(),
|
|
460
|
+
path: "Global",
|
|
461
|
+
middleware: m.middleware?.name,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
console.table(formattedPipeline);
|
|
466
|
+
}
|
|
288
467
|
/**
|
|
289
468
|
* Gets the configured error handler middleware.
|
|
290
469
|
*
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var InMemoryDB_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.InMemoryDB = void 0;
|
|
11
|
+
const decorator_1 = require("../../decorator");
|
|
12
|
+
/**
|
|
13
|
+
* InMemoryDB Class
|
|
14
|
+
*
|
|
15
|
+
* This class and its methods offer functionalities to simulate an in-memory database.
|
|
16
|
+
* It is particularly useful for developers starting with ExpressoTS without any database connection.
|
|
17
|
+
*
|
|
18
|
+
* @decorator @provideSingleton(InMemoryDB)
|
|
19
|
+
*/
|
|
20
|
+
let InMemoryDB = exports.InMemoryDB = InMemoryDB_1 = class InMemoryDB {
|
|
21
|
+
tables = {};
|
|
22
|
+
/**
|
|
23
|
+
* getTable Method
|
|
24
|
+
*
|
|
25
|
+
* Retrieves a table by its name from the in-memory database.
|
|
26
|
+
*
|
|
27
|
+
* @param tableName - The name of the table to retrieve.
|
|
28
|
+
* @returns {IEntity[]} - An array of entities.
|
|
29
|
+
*/
|
|
30
|
+
getTable(tableName) {
|
|
31
|
+
if (!this.tables[tableName]) {
|
|
32
|
+
this.tables[tableName] = [];
|
|
33
|
+
}
|
|
34
|
+
return this.tables[tableName];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* showTables Method
|
|
38
|
+
*
|
|
39
|
+
* Prints a list of all tables in the in-memory database to the standard output.
|
|
40
|
+
*/
|
|
41
|
+
showTables() {
|
|
42
|
+
if (!this.tables) {
|
|
43
|
+
process.stdout.write("No tables exist.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
process.stdout.write("List of tables:");
|
|
47
|
+
for (const tableName in this.tables) {
|
|
48
|
+
process.stdout.write(`\n- ${tableName}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* printTable Method
|
|
53
|
+
*
|
|
54
|
+
* Prints all records in a specific table to the console.
|
|
55
|
+
* If the table doesn't exist or is empty, it notifies the user.
|
|
56
|
+
*
|
|
57
|
+
* @param tableName - The name of the table to print.
|
|
58
|
+
*/
|
|
59
|
+
printTable(tableName) {
|
|
60
|
+
if (!this.tables) {
|
|
61
|
+
process.stdout.write("No tables exist.");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const table = this.getTable(tableName);
|
|
65
|
+
if (table.length === 0) {
|
|
66
|
+
process.stdout.write(`Table '${tableName}' is empty.`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
process.stdout.write(`\nRecords in table '${tableName}':\n`);
|
|
70
|
+
console.table(table);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
exports.InMemoryDB = InMemoryDB = InMemoryDB_1 = __decorate([
|
|
74
|
+
(0, decorator_1.provideSingleton)(InMemoryDB_1)
|
|
75
|
+
], InMemoryDB);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidateDTO = exports.Env = exports.Logger = exports.Provider = void 0;
|
|
3
|
+
exports.InMemoryDB = exports.ValidateDTO = exports.Env = exports.Logger = exports.Provider = void 0;
|
|
4
4
|
var provider_service_1 = require("./provider-service");
|
|
5
5
|
Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return provider_service_1.Provider; } });
|
|
6
6
|
var logger_service_1 = require("./logger/logger-service");
|
|
@@ -9,3 +9,5 @@ var env_validator_provider_1 = require("./environment/env-validator.provider");
|
|
|
9
9
|
Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return env_validator_provider_1.EnvValidatorProvider; } });
|
|
10
10
|
var dto_validator_provider_1 = require("./dto-validator/dto-validator.provider");
|
|
11
11
|
Object.defineProperty(exports, "ValidateDTO", { enumerable: true, get: function () { return dto_validator_provider_1.ValidateDTO; } });
|
|
12
|
+
var db_in_memory_provider_1 = require("./db-in-memory/db-in-memory.provider");
|
|
13
|
+
Object.defineProperty(exports, "InMemoryDB", { enumerable: true, get: function () { return db_in_memory_provider_1.InMemoryDB; } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { IMiddleware, Middleware } from "./middleware-service";
|
|
1
|
+
export { IMiddleware, Middleware, ExpressHandler, ExpressoMiddleware, MiddlewareOptions, } from "./middleware-service";
|
|
2
2
|
export { OptionsJson } from "./interfaces/body-parser.interface";
|
|
3
3
|
export { CorsOptions } from "./interfaces/cors.interface";
|
|
4
4
|
export { CompressionOptions } from "./interfaces/compression.interface";
|
|
@@ -9,4 +9,5 @@ export { Keygrip } from "./interfaces/cookie-session/keygrip.interface";
|
|
|
9
9
|
export { CookieParserOptions } from "./interfaces/cookie-parser.interface";
|
|
10
10
|
export { ServeFaviconOptions } from "./interfaces/serve-favicon.interface";
|
|
11
11
|
export { RateLimitOptions } from "./interfaces/express-rate-limit.interface";
|
|
12
|
+
export { multer } from "./interfaces/multer.interface";
|
|
12
13
|
export * as IMorgan from "./interfaces/morgan.interface";
|
|
@@ -0,0 +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,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExpressHandler } from "./middleware-service";
|
|
2
2
|
/**
|
|
3
3
|
* A utility function that wraps the creation and retrieval of middleware.
|
|
4
4
|
* It creates a new instance of MiddlewareResolver and calls the getMiddleware method.
|
|
@@ -7,5 +7,5 @@ import express from "express";
|
|
|
7
7
|
* @param {...any} options - Optional arguments to configure the middleware.
|
|
8
8
|
* @returns {express.RequestHandler | null} - Returns the configured middleware or null if not found or not installed.
|
|
9
9
|
*/
|
|
10
|
-
declare function middlewareResolver(middleware: string, ...options: any):
|
|
10
|
+
declare function middlewareResolver(middleware: string, ...options: any): ExpressHandler | null;
|
|
11
11
|
export { middlewareResolver };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import express from "express";
|
|
2
|
+
import express, { Request, Response, NextFunction } from "express";
|
|
3
3
|
import { OptionsJson } from "./interfaces/body-parser.interface";
|
|
4
4
|
import { CompressionOptions } from "./interfaces/compression.interface";
|
|
5
5
|
import { CorsOptions } from "./interfaces/cors.interface";
|
|
@@ -10,6 +10,7 @@ import { ServeFaviconOptions } from "./interfaces/serve-favicon.interface";
|
|
|
10
10
|
import { FormatFn, OptionsMorgan } from "./interfaces/morgan.interface";
|
|
11
11
|
import { RateLimitOptions } from "./interfaces/express-rate-limit.interface";
|
|
12
12
|
import { OptionsHelmet } from "./interfaces/helmet.interface";
|
|
13
|
+
import { multer } from "./interfaces/multer.interface";
|
|
13
14
|
import { SessionOptions } from "./interfaces/express-session.interface";
|
|
14
15
|
/**
|
|
15
16
|
* ExpressHandler Type
|
|
@@ -21,14 +22,29 @@ import { SessionOptions } from "./interfaces/express-session.interface";
|
|
|
21
22
|
* - express.RequestHandler: General request handler.
|
|
22
23
|
* - undefined: Represents the absence of a handler.
|
|
23
24
|
*/
|
|
24
|
-
type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
|
|
25
|
+
export type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
|
|
25
26
|
/**
|
|
26
|
-
*
|
|
27
|
+
* Expresso middleware interface.
|
|
28
|
+
*/
|
|
29
|
+
interface IExpressoMiddleware {
|
|
30
|
+
use(req: Request, res: Response, next: NextFunction): Promise<void> | void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Abstract class for creating custom Expresso middleware.
|
|
34
|
+
* Custom middleware classes should extend this class and implement the use method.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
export declare abstract class ExpressoMiddleware implements IExpressoMiddleware {
|
|
38
|
+
get name(): string;
|
|
39
|
+
abstract use(req: Request, res: Response, next: NextFunction): Promise<void> | void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* MiddlewareOptions Type
|
|
27
43
|
*
|
|
28
|
-
* The
|
|
29
|
-
* It can either be a
|
|
44
|
+
* The MiddlewareOptions type represents arguments that can be passed to a middleware function.
|
|
45
|
+
* It can either be a expressjs request handler function, a middleware configuration object that is composed by a route and an expressjs handler or
|
|
30
46
|
*/
|
|
31
|
-
type
|
|
47
|
+
export type MiddlewareOptions = ExpressHandler | MiddlewareConfig | IExpressoMiddleware;
|
|
32
48
|
/**
|
|
33
49
|
* MiddlewareConfig Interface
|
|
34
50
|
*
|
|
@@ -38,7 +54,7 @@ type MiddlewareArgs = string | ExpressHandler;
|
|
|
38
54
|
*/
|
|
39
55
|
type MiddlewareConfig = {
|
|
40
56
|
path?: string;
|
|
41
|
-
middlewares: Array<ExpressHandler>;
|
|
57
|
+
middlewares: Array<ExpressHandler | IExpressoMiddleware>;
|
|
42
58
|
};
|
|
43
59
|
/**
|
|
44
60
|
* MiddlewarePipeline Interface
|
|
@@ -49,7 +65,7 @@ type MiddlewareConfig = {
|
|
|
49
65
|
*/
|
|
50
66
|
interface MiddlewarePipeline {
|
|
51
67
|
timestamp: Date;
|
|
52
|
-
middleware: ExpressHandler | MiddlewareConfig;
|
|
68
|
+
middleware: ExpressHandler | MiddlewareConfig | IExpressoMiddleware;
|
|
53
69
|
}
|
|
54
70
|
/**
|
|
55
71
|
* Interface for configuring and managing middlewares in the application.
|
|
@@ -134,16 +150,35 @@ interface IMiddleware {
|
|
|
134
150
|
/**
|
|
135
151
|
* Adds a middleware to the middleware collection.
|
|
136
152
|
*
|
|
137
|
-
* @param
|
|
138
|
-
*
|
|
153
|
+
* @param options - The Express request handler function to be added to the middleware collection, or a middleware configuration object
|
|
154
|
+
* that is composed by a route and an expressjs handler, or a custom Expresso middleware.
|
|
155
|
+
*
|
|
156
|
+
* @example Express Handler
|
|
157
|
+
* const middleware = (req, res, next) => {
|
|
158
|
+
* // Your middleware logic here
|
|
159
|
+
* next();
|
|
160
|
+
* }
|
|
161
|
+
*
|
|
162
|
+
* @example Middleware Configuration Object
|
|
163
|
+
* const middleware = {
|
|
164
|
+
* path: "/",
|
|
165
|
+
* middlewares: [] // Array of Express Handlers
|
|
166
|
+
* }
|
|
167
|
+
*
|
|
168
|
+
* @example Expresso Middleware
|
|
169
|
+
* class CustomMiddleware implements IExpressoMiddleware {
|
|
170
|
+
* use(req: Request, res: Response, next: NextFunction): Promise<void> | void {
|
|
171
|
+
* // Your middleware logic here
|
|
172
|
+
* next();
|
|
173
|
+
* }
|
|
174
|
+
* }
|
|
139
175
|
*/
|
|
140
|
-
addMiddleware(
|
|
176
|
+
addMiddleware(options: MiddlewareOptions): void;
|
|
141
177
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* @returns An array of Express request handlers representing the middlewares.
|
|
178
|
+
* View middleware pipeline formatted.
|
|
179
|
+
* @returns void
|
|
145
180
|
*/
|
|
146
|
-
|
|
181
|
+
viewMiddlewarePipeline(): void;
|
|
147
182
|
/**
|
|
148
183
|
* Gets the configured error handler middleware.
|
|
149
184
|
*
|
|
@@ -157,6 +192,12 @@ interface IMiddleware {
|
|
|
157
192
|
* @returns The configuration options for Helmet middleware.
|
|
158
193
|
*/
|
|
159
194
|
addHelmet(options?: OptionsHelmet): void;
|
|
195
|
+
/**
|
|
196
|
+
* Adds Multer middleware for handling multipart/form-data, typically used for file uploads.
|
|
197
|
+
*
|
|
198
|
+
* @param options - Optional configuration options for Multer.
|
|
199
|
+
*/
|
|
200
|
+
setupMulter(options?: multer.Options): multer.Multer;
|
|
160
201
|
}
|
|
161
202
|
/**
|
|
162
203
|
* Singleton class that implements the IConfigure interface.
|
|
@@ -169,6 +210,14 @@ declare class Middleware implements IMiddleware {
|
|
|
169
210
|
private middlewarePipeline;
|
|
170
211
|
private errorHandler;
|
|
171
212
|
private logger;
|
|
213
|
+
/**
|
|
214
|
+
* Retrieves the type of the middleware.
|
|
215
|
+
*
|
|
216
|
+
* @param middleware - The middleware to be checked.
|
|
217
|
+
*
|
|
218
|
+
* @returns The type of the middleware.
|
|
219
|
+
*/
|
|
220
|
+
private getMiddlewareType;
|
|
172
221
|
/**
|
|
173
222
|
* Checks if a middleware with the given name exists in the middleware collection.
|
|
174
223
|
*
|
|
@@ -224,6 +273,7 @@ declare class Middleware implements IMiddleware {
|
|
|
224
273
|
* @param options - Optional configuration options for serving the favicon. Defines the behavior of the favicon middleware like cache control, custom headers, etc.
|
|
225
274
|
*/
|
|
226
275
|
addServeFavicon(path: string | Buffer, options?: ServeFaviconOptions): void;
|
|
276
|
+
setupMulter(options?: multer.Options): multer.Multer;
|
|
227
277
|
/**
|
|
228
278
|
* Adds a middleware to enhance security by setting various HTTP headers.
|
|
229
279
|
*
|
|
@@ -252,19 +302,62 @@ declare class Middleware implements IMiddleware {
|
|
|
252
302
|
* @param options - Optional configuration options for serving static files. Defines behavior like cache control, custom headers, etc.
|
|
253
303
|
*/
|
|
254
304
|
serveStatic(root: string, options?: ServeStaticOptions): void;
|
|
305
|
+
/**
|
|
306
|
+
* Helper method to add middleware configuration objects to the middleware collection.
|
|
307
|
+
* @param middleware - The middleware configuration object to be added to the middleware collection.
|
|
308
|
+
* @returns void
|
|
309
|
+
*/
|
|
310
|
+
private addConfigMiddleware;
|
|
311
|
+
/**
|
|
312
|
+
* Helper method to add express request handler functions to the middleware collection.
|
|
313
|
+
* @param middleware - The express request handler function to be added to the middleware collection.
|
|
314
|
+
* @returns void
|
|
315
|
+
*/
|
|
316
|
+
private addExpressHandlerMiddleware;
|
|
317
|
+
/**
|
|
318
|
+
* Helper method to add custom Expresso middleware to the middleware collection.
|
|
319
|
+
* @param middleware - The custom Expresso middleware to be added to the middleware collection.
|
|
320
|
+
* @returns void
|
|
321
|
+
*/
|
|
322
|
+
private addIExpressoMiddleware;
|
|
255
323
|
/**
|
|
256
324
|
* Adds a middleware to the middleware collection.
|
|
257
325
|
*
|
|
258
|
-
* @param
|
|
259
|
-
*
|
|
326
|
+
* @param options - The Express request handler function to be added to the middleware collection, or a middleware configuration object
|
|
327
|
+
* that is composed by a route and an expressjs handler, or a custom Expresso middleware.
|
|
328
|
+
*
|
|
329
|
+
* @example Express Handler
|
|
330
|
+
* const middleware = (req, res, next) => {
|
|
331
|
+
* // Your middleware logic here
|
|
332
|
+
* next();
|
|
333
|
+
* }
|
|
334
|
+
*
|
|
335
|
+
* @example Middleware Configuration Object
|
|
336
|
+
* const middleware = {
|
|
337
|
+
* path: "/",
|
|
338
|
+
* middlewares: [] // Array of Express Handlers
|
|
339
|
+
* }
|
|
340
|
+
*
|
|
341
|
+
* @example Expresso Middleware
|
|
342
|
+
* class CustomMiddleware implements IExpressoMiddleware {
|
|
343
|
+
* use(req: Request, res: Response, next: NextFunction): Promise<void> | void {
|
|
344
|
+
* // Your middleware logic here
|
|
345
|
+
* next();
|
|
346
|
+
* }
|
|
347
|
+
* }
|
|
260
348
|
*/
|
|
261
|
-
addMiddleware(
|
|
349
|
+
addMiddleware(options: MiddlewareOptions): void;
|
|
262
350
|
/**
|
|
263
351
|
* Retrieves middleware pipeline in the order they were added.
|
|
264
352
|
*
|
|
265
353
|
* @returns An array of Express request handlers representing the middlewares.
|
|
266
354
|
*/
|
|
267
355
|
getMiddlewarePipeline(): Array<MiddlewarePipeline>;
|
|
356
|
+
/**
|
|
357
|
+
* View middleware pipeline formatted.
|
|
358
|
+
* @returns void
|
|
359
|
+
*/
|
|
360
|
+
viewMiddlewarePipeline(): void;
|
|
268
361
|
/**
|
|
269
362
|
* Gets the configured error handler middleware.
|
|
270
363
|
*
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface IMemoryDBEntity {
|
|
2
|
+
id: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* InMemoryDB Class
|
|
6
|
+
*
|
|
7
|
+
* This class and its methods offer functionalities to simulate an in-memory database.
|
|
8
|
+
* It is particularly useful for developers starting with ExpressoTS without any database connection.
|
|
9
|
+
*
|
|
10
|
+
* @decorator @provideSingleton(InMemoryDB)
|
|
11
|
+
*/
|
|
12
|
+
export declare class InMemoryDB {
|
|
13
|
+
private tables;
|
|
14
|
+
/**
|
|
15
|
+
* getTable Method
|
|
16
|
+
*
|
|
17
|
+
* Retrieves a table by its name from the in-memory database.
|
|
18
|
+
*
|
|
19
|
+
* @param tableName - The name of the table to retrieve.
|
|
20
|
+
* @returns {IEntity[]} - An array of entities.
|
|
21
|
+
*/
|
|
22
|
+
getTable(tableName: string): Array<IMemoryDBEntity>;
|
|
23
|
+
/**
|
|
24
|
+
* showTables Method
|
|
25
|
+
*
|
|
26
|
+
* Prints a list of all tables in the in-memory database to the standard output.
|
|
27
|
+
*/
|
|
28
|
+
showTables(): void;
|
|
29
|
+
/**
|
|
30
|
+
* printTable Method
|
|
31
|
+
*
|
|
32
|
+
* Prints all records in a specific table to the console.
|
|
33
|
+
* If the table doesn't exist or is empty, it notifies the user.
|
|
34
|
+
*
|
|
35
|
+
* @param tableName - The name of the table to print.
|
|
36
|
+
*/
|
|
37
|
+
printTable(tableName: string): void;
|
|
38
|
+
}
|
|
@@ -2,3 +2,4 @@ export { Provider, IProvider } from "./provider-service";
|
|
|
2
2
|
export { Logger } from "./logger/logger-service";
|
|
3
3
|
export { EnvValidatorProvider as Env } from "./environment/env-validator.provider";
|
|
4
4
|
export { ValidateDTO } from "./dto-validator/dto-validator.provider";
|
|
5
|
+
export { InMemoryDB, IMemoryDBEntity, } from "./db-in-memory/db-in-memory.provider";
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -69,11 +69,11 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"inversify": "^6.0.1",
|
|
71
71
|
"inversify-binding-decorators": "^4.0.0",
|
|
72
|
-
"reflect-metadata": "^0.1
|
|
72
|
+
"reflect-metadata": "^0.2.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@commitlint/cli": "^
|
|
76
|
-
"@commitlint/config-conventional": "^
|
|
75
|
+
"@commitlint/cli": "^18.0.0",
|
|
76
|
+
"@commitlint/config-conventional": "^18.0.0",
|
|
77
77
|
"@expressots/adapter-express": "latest",
|
|
78
78
|
"@release-it/conventional-changelog": "^7.0.1",
|
|
79
79
|
"@types/express": "^4.17.17",
|
|
@@ -83,12 +83,12 @@
|
|
|
83
83
|
"@vitest/coverage-v8": "^0.34.6",
|
|
84
84
|
"eslint": "^8.48.0",
|
|
85
85
|
"eslint-config-prettier": "^9.0.0",
|
|
86
|
-
"husky": "^
|
|
87
|
-
"prettier": "3.
|
|
86
|
+
"husky": "^9.0.11",
|
|
87
|
+
"prettier": "3.2.5",
|
|
88
88
|
"release-it": "^16.1.5",
|
|
89
89
|
"ts-jest": "^29.0.5",
|
|
90
90
|
"typescript": "^5.0.3",
|
|
91
|
-
"vite": "4.
|
|
91
|
+
"vite": "4.5.0",
|
|
92
92
|
"vitest": "0.34.6"
|
|
93
93
|
},
|
|
94
94
|
"release-it": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -69,11 +69,11 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"inversify": "^6.0.1",
|
|
71
71
|
"inversify-binding-decorators": "^4.0.0",
|
|
72
|
-
"reflect-metadata": "^0.1
|
|
72
|
+
"reflect-metadata": "^0.2.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@commitlint/cli": "^
|
|
76
|
-
"@commitlint/config-conventional": "^
|
|
75
|
+
"@commitlint/cli": "^18.0.0",
|
|
76
|
+
"@commitlint/config-conventional": "^18.0.0",
|
|
77
77
|
"@expressots/adapter-express": "latest",
|
|
78
78
|
"@release-it/conventional-changelog": "^7.0.1",
|
|
79
79
|
"@types/express": "^4.17.17",
|
|
@@ -83,12 +83,12 @@
|
|
|
83
83
|
"@vitest/coverage-v8": "^0.34.6",
|
|
84
84
|
"eslint": "^8.48.0",
|
|
85
85
|
"eslint-config-prettier": "^9.0.0",
|
|
86
|
-
"husky": "^
|
|
87
|
-
"prettier": "3.
|
|
86
|
+
"husky": "^9.0.11",
|
|
87
|
+
"prettier": "3.2.5",
|
|
88
88
|
"release-it": "^16.1.5",
|
|
89
89
|
"ts-jest": "^29.0.5",
|
|
90
90
|
"typescript": "^5.0.3",
|
|
91
|
-
"vite": "4.
|
|
91
|
+
"vite": "4.5.0",
|
|
92
92
|
"vitest": "0.34.6"
|
|
93
93
|
},
|
|
94
94
|
"release-it": {
|