@expressots/adapter-express 1.2.2 → 1.4.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/README.md +8 -0
- package/lib/CHANGELOG.md +71 -40
- package/lib/README.md +8 -0
- package/lib/cjs/adapter-express/application-express.js +17 -2
- package/lib/cjs/adapter-express/express-utils/constants.js +6 -1
- package/lib/cjs/adapter-express/express-utils/decorators.js +87 -1
- package/lib/cjs/adapter-express/express-utils/http-status-middleware.js +47 -0
- package/lib/cjs/types/adapter-express/application-express.d.ts +7 -0
- package/lib/cjs/types/adapter-express/application-express.interface.d.ts +6 -0
- package/lib/cjs/types/adapter-express/express-utils/constants.d.ts +5 -0
- package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +24 -0
- package/lib/cjs/types/adapter-express/express-utils/http-status-middleware.d.ts +11 -0
- package/lib/package.json +12 -6
- package/package.json +12 -6
package/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- PROJECT SHIELDS -->
|
|
4
4
|
|
|
5
|
+
[![Codecov][codecov-shield]][codecov-url]
|
|
6
|
+
[![NPM][npm-shield]][npm-url]
|
|
7
|
+
![Build][build-shield]
|
|
5
8
|
[![Contributors][contributors-shield]][contributors-url]
|
|
6
9
|
[![Forks][forks-shield]][forks-url]
|
|
7
10
|
[![Stargazers][stars-shield]][stars-url]
|
|
@@ -95,6 +98,11 @@ Distributed under the MIT License. See [`LICENSE.txt`](https://github.com/expres
|
|
|
95
98
|
<!-- MARKDOWN LINKS & IMAGES -->
|
|
96
99
|
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
|
97
100
|
|
|
101
|
+
[codecov-url]: https://codecov.io/gh/expressots/adapter-express
|
|
102
|
+
[codecov-shield]: https://img.shields.io/codecov/c/gh/expressots/adapter-express/main?style=for-the-badge&logo=codecov&labelColor=FB9AD1
|
|
103
|
+
[npm-url]: https://www.npmjs.com/package/@expressots/adapter-express
|
|
104
|
+
[npm-shield]: https://img.shields.io/npm/v/@expressots/adapter-express?style=for-the-badge&logo=npm&color=9B3922
|
|
105
|
+
[build-shield]: https://img.shields.io/github/actions/workflow/status/expressots/adapter-express/build.yaml?branch=main&style=for-the-badge&logo=github
|
|
98
106
|
[contributors-shield]: https://img.shields.io/github/contributors/expressots/adapter-express?style=for-the-badge
|
|
99
107
|
[contributors-url]: https://github.com/expressots/adapter-express/graphs/contributors
|
|
100
108
|
[forks-shield]: https://img.shields.io/github/forks/expressots/adapter-express?style=for-the-badge
|
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,59 +1,90 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
## [1.
|
|
3
|
+
## [1.4.0](https://github.com/expressots/adapter-express/compare/1.3.0...1.4.0) (2024-06-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* Add http code decorator ([f0f6e0a](https://github.com/expressots/adapter-express/commit/f0f6e0aa034636d7df67d5f1cef83adb6a3af8bc))
|
|
9
|
+
* add vitest and setup codecov in the ci ([14fd527](https://github.com/expressots/adapter-express/commit/14fd527a097d981778f2b3ba2a68effb68865d8f))
|
|
10
|
+
* adjust doc, update metadata const for http decorator ([773f297](https://github.com/expressots/adapter-express/commit/773f297fee340b5d8de6a134454425328ddbbc03))
|
|
11
|
+
* dev-http decorator changes ([8088f5c](https://github.com/expressots/adapter-express/commit/8088f5c2ef391abbe33d1e8750bef9a6fe34f699))
|
|
12
|
+
* fix issues where decorator does not function properly when used multiple times in same file ([919815f](https://github.com/expressots/adapter-express/commit/919815f4f1232f9a319ed887a99f8c214b40341d))
|
|
4
13
|
|
|
5
14
|
|
|
6
15
|
### Bug Fixes
|
|
7
16
|
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
* build shield workflow status ([3e5d6c8](https://github.com/expressots/adapter-express/commit/3e5d6c814cb5ed71cfa7a4f5e65f77ad359671f6))
|
|
18
|
+
* code coverage upload path ([aef20eb](https://github.com/expressots/adapter-express/commit/aef20eb2767506e7d9c7773233727c96cb5ca9b7))
|
|
19
|
+
* remove codesee ci config ([043c423](https://github.com/expressots/adapter-express/commit/043c423c52d00c814c6357c1e7f6ed7caed3b2ac))
|
|
20
|
+
* remove the decorator incorrect call in the library due mismatch on tsconfig ([58dbb52](https://github.com/expressots/adapter-express/commit/58dbb5258a7c2155dd34b1841dbfbe15884f4e21))
|
|
11
21
|
|
|
12
22
|
|
|
13
23
|
### Code Refactoring
|
|
14
24
|
|
|
15
|
-
*
|
|
25
|
+
* readme badges npm, coverage and build added ([d643acd](https://github.com/expressots/adapter-express/commit/d643acde38df4866155a0164f08c2d7f0261c705))
|
|
26
|
+
|
|
27
|
+
## [1.3.0](https://github.com/expressots/adapter-express/compare/1.2.2...1.3.0) (2024-04-26)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* returns httpServer for e2e testing with supertest ([97999fb](https://github.com/expressots/adapter-express/commit/97999fbc7ac977e47caf023d7541e588ef50d548))
|
|
33
|
+
|
|
34
|
+
## [1.2.2](https://github.com/expressots/adapter-express/compare/1.2.1...1.2.2) (2024-04-25)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
* validate parameter types in param decorator by default ([b7a8657](https://github.com/expressots/adapter-express/commit/b7a8657598ce51a6fa44c3a388d38106b47ad70d))
|
|
40
|
+
|
|
41
|
+
## [1.2.1](https://github.com/expressots/adapter-express/compare/1.2.0...1.2.1) (2024-04-04)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Code Refactoring
|
|
45
|
+
|
|
46
|
+
* adapter expressto to be used in AppFactory ([239501e](https://github.com/expressots/adapter-express/commit/239501e41bfd98ecc0893a50c34de58dd8914d9e))
|
|
16
47
|
* rename items for standardization and improve doc ([2e691d5](https://github.com/expressots/adapter-express/commit/2e691d50731e8d4d689fe4b4420daab8ba2f5803))
|
|
17
48
|
|
|
18
|
-
## [1.2.0](https://github.com/expressots/adapter-express/compare/1.1.1...1.2.0) (2024-3-5)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### Features
|
|
22
|
-
|
|
23
|
-
* add expressots middleware support ([809f148](https://github.com/expressots/adapter-express/commit/809f148a2b9a6bb0aa41f231595b3a4c394574ee))
|
|
24
|
-
* bump @commitlint/cli from 17.8.1 to 18.0.0 ([15fbb1a](https://github.com/expressots/adapter-express/commit/15fbb1a84c758df25b60f2a893fd44829db3c0dc))
|
|
25
|
-
* fix middleware binding to constructor ([3a6f7dc](https://github.com/expressots/adapter-express/commit/3a6f7dca40889133b09630582c775156392c4fd7))
|
|
49
|
+
## [1.2.0](https://github.com/expressots/adapter-express/compare/1.1.1...1.2.0) (2024-3-5)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Features
|
|
53
|
+
|
|
54
|
+
* add expressots middleware support ([809f148](https://github.com/expressots/adapter-express/commit/809f148a2b9a6bb0aa41f231595b3a4c394574ee))
|
|
55
|
+
* bump @commitlint/cli from 17.8.1 to 18.0.0 ([15fbb1a](https://github.com/expressots/adapter-express/commit/15fbb1a84c758df25b60f2a893fd44829db3c0dc))
|
|
56
|
+
* fix middleware binding to constructor ([3a6f7dc](https://github.com/expressots/adapter-express/commit/3a6f7dca40889133b09630582c775156392c4fd7))
|
|
26
57
|
* fix path call on expresso middleware ([934ae17](https://github.com/expressots/adapter-express/commit/934ae17110489315536e28b71cde24f5f18d88dc))
|
|
27
58
|
|
|
28
|
-
## [1.1.1](https://github.com/expressots/adapter-express/compare/1.1.0...1.1.1) (2023-10-10)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
### Bug Fixes
|
|
32
|
-
|
|
33
|
-
* add global prefix on opinionated ([d9d5a06](https://github.com/expressots/adapter-express/commit/d9d5a0669241ed14541a1452aa0deaa12c1109b4))
|
|
34
|
-
* add global route prefix for both templates ([046fd2c](https://github.com/expressots/adapter-express/commit/046fd2c2e2c5beacf9602f929b223713d48e8b9c))
|
|
35
|
-
* adjust build pipeline ([4f164a2](https://github.com/expressots/adapter-express/commit/4f164a2f6ee5c23512a8e6643b90a74891ec52c4))
|
|
36
|
-
* adjust build script and remove esm build option ([b35af7b](https://github.com/expressots/adapter-express/commit/b35af7b9ea91935572920314eddc8f5258bca4bc))
|
|
59
|
+
## [1.1.1](https://github.com/expressots/adapter-express/compare/1.1.0...1.1.1) (2023-10-10)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Bug Fixes
|
|
63
|
+
|
|
64
|
+
* add global prefix on opinionated ([d9d5a06](https://github.com/expressots/adapter-express/commit/d9d5a0669241ed14541a1452aa0deaa12c1109b4))
|
|
65
|
+
* add global route prefix for both templates ([046fd2c](https://github.com/expressots/adapter-express/commit/046fd2c2e2c5beacf9602f929b223713d48e8b9c))
|
|
66
|
+
* adjust build pipeline ([4f164a2](https://github.com/expressots/adapter-express/commit/4f164a2f6ee5c23512a8e6643b90a74891ec52c4))
|
|
67
|
+
* adjust build script and remove esm build option ([b35af7b](https://github.com/expressots/adapter-express/commit/b35af7b9ea91935572920314eddc8f5258bca4bc))
|
|
37
68
|
* path in codeql analysis report ([035aa16](https://github.com/expressots/adapter-express/commit/035aa16a9d62de8d7e2b39bae052d8d5499799da))
|
|
38
69
|
|
|
39
|
-
## 1.1.0 (2023-09-21)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### Features
|
|
43
|
-
|
|
44
|
-
* add express as an adapter ([2870790](https://github.com/expressots/adapter-express/commit/28707900882422d0f882e5e18c9bf01457e5640d))
|
|
45
|
-
* add expressjs adapter ([263d12d](https://github.com/expressots/adapter-express/commit/263d12dce314cc4125a0f5b14eaa0b5e171f165f))
|
|
46
|
-
* add peer dependency @expressots/core ([7e8ec24](https://github.com/expressots/adapter-express/commit/7e8ec240fe5caf72a0c371ba317c0d0f52898571))
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Bug Fixes
|
|
50
|
-
|
|
51
|
-
* add dev 0 package version ([748b62a](https://github.com/expressots/adapter-express/commit/748b62ad101ed6efe4454f9a9f0d684f1118dec6))
|
|
52
|
-
* add dev version ([31baee3](https://github.com/expressots/adapter-express/commit/31baee3e7dd578e14fbc6e1e11eb88ae939e1d28))
|
|
53
|
-
* consume new middlewareConfig base ([bed7b4a](https://github.com/expressots/adapter-express/commit/bed7b4ae682a8c8d55c705e5d2f9b40b136e2af1))
|
|
54
|
-
* expose controller interface ([468818f](https://github.com/expressots/adapter-express/commit/468818fec78e06392cb6024cb4b257edebfd8d38))
|
|
55
|
-
* signature to [@core-v2](https://github.com/core-v2).2 ([4fb5c58](https://github.com/expressots/adapter-express/commit/4fb5c58aa4f011c3aa97803ebc8a80ae72d5b56d))
|
|
56
|
-
* update [@core](https://github.com/core) dependency to altest ([0138609](https://github.com/expressots/adapter-express/commit/01386093f6116e4731270fd17a1250b564387c56))
|
|
70
|
+
## 1.1.0 (2023-09-21)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### Features
|
|
74
|
+
|
|
75
|
+
* add express as an adapter ([2870790](https://github.com/expressots/adapter-express/commit/28707900882422d0f882e5e18c9bf01457e5640d))
|
|
76
|
+
* add expressjs adapter ([263d12d](https://github.com/expressots/adapter-express/commit/263d12dce314cc4125a0f5b14eaa0b5e171f165f))
|
|
77
|
+
* add peer dependency @expressots/core ([7e8ec24](https://github.com/expressots/adapter-express/commit/7e8ec240fe5caf72a0c371ba317c0d0f52898571))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### Bug Fixes
|
|
81
|
+
|
|
82
|
+
* add dev 0 package version ([748b62a](https://github.com/expressots/adapter-express/commit/748b62ad101ed6efe4454f9a9f0d684f1118dec6))
|
|
83
|
+
* add dev version ([31baee3](https://github.com/expressots/adapter-express/commit/31baee3e7dd578e14fbc6e1e11eb88ae939e1d28))
|
|
84
|
+
* consume new middlewareConfig base ([bed7b4a](https://github.com/expressots/adapter-express/commit/bed7b4ae682a8c8d55c705e5d2f9b40b136e2af1))
|
|
85
|
+
* expose controller interface ([468818f](https://github.com/expressots/adapter-express/commit/468818fec78e06392cb6024cb4b257edebfd8d38))
|
|
86
|
+
* signature to [@core-v2](https://github.com/core-v2).2 ([4fb5c58](https://github.com/expressots/adapter-express/commit/4fb5c58aa4f011c3aa97803ebc8a80ae72d5b56d))
|
|
87
|
+
* update [@core](https://github.com/core) dependency to altest ([0138609](https://github.com/expressots/adapter-express/commit/01386093f6116e4731270fd17a1250b564387c56))
|
|
57
88
|
* update peer dependecy for [@core](https://github.com/core) ([16a01f3](https://github.com/expressots/adapter-express/commit/16a01f353f3285a68a2038ceb40b6498c64c5a34))
|
|
58
89
|
|
|
59
90
|
## 0.0.1 (2023-09-05)
|
package/lib/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- PROJECT SHIELDS -->
|
|
4
4
|
|
|
5
|
+
[![Codecov][codecov-shield]][codecov-url]
|
|
6
|
+
[![NPM][npm-shield]][npm-url]
|
|
7
|
+
![Build][build-shield]
|
|
5
8
|
[![Contributors][contributors-shield]][contributors-url]
|
|
6
9
|
[![Forks][forks-shield]][forks-url]
|
|
7
10
|
[![Stargazers][stars-shield]][stars-url]
|
|
@@ -95,6 +98,11 @@ Distributed under the MIT License. See [`LICENSE.txt`](https://github.com/expres
|
|
|
95
98
|
<!-- MARKDOWN LINKS & IMAGES -->
|
|
96
99
|
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
|
97
100
|
|
|
101
|
+
[codecov-url]: https://codecov.io/gh/expressots/adapter-express
|
|
102
|
+
[codecov-shield]: https://img.shields.io/codecov/c/gh/expressots/adapter-express/main?style=for-the-badge&logo=codecov&labelColor=FB9AD1
|
|
103
|
+
[npm-url]: https://www.npmjs.com/package/@expressots/adapter-express
|
|
104
|
+
[npm-shield]: https://img.shields.io/npm/v/@expressots/adapter-express?style=for-the-badge&logo=npm&color=9B3922
|
|
105
|
+
[build-shield]: https://img.shields.io/github/actions/workflow/status/expressots/adapter-express/build.yaml?branch=main&style=for-the-badge&logo=github
|
|
98
106
|
[contributors-shield]: https://img.shields.io/github/contributors/expressots/adapter-express?style=for-the-badge
|
|
99
107
|
[contributors-url]: https://github.com/expressots/adapter-express/graphs/contributors
|
|
100
108
|
[forks-shield]: https://img.shields.io/github/forks/expressots/adapter-express?style=for-the-badge
|
|
@@ -14,8 +14,9 @@ const core_1 = require("@expressots/core");
|
|
|
14
14
|
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
15
15
|
const process_1 = __importDefault(require("process"));
|
|
16
16
|
const application_express_base_1 = require("./application-express.base");
|
|
17
|
-
const inversify_express_server_1 = require("./express-utils/inversify-express-server");
|
|
18
17
|
const application_express_types_1 = require("./application-express.types");
|
|
18
|
+
const inversify_express_server_1 = require("./express-utils/inversify-express-server");
|
|
19
|
+
const http_status_middleware_1 = require("./express-utils/http-status-middleware");
|
|
19
20
|
/**
|
|
20
21
|
* The AppExpress class provides methods for configuring and running an Express application.
|
|
21
22
|
* @class AppExpress
|
|
@@ -30,6 +31,7 @@ const application_express_types_1 = require("./application-express.types");
|
|
|
30
31
|
let AppExpress = class AppExpress extends application_express_base_1.ApplicationBase {
|
|
31
32
|
constructor() {
|
|
32
33
|
super(...arguments);
|
|
34
|
+
this.logger = new core_1.Logger();
|
|
33
35
|
this.globalPrefix = "/";
|
|
34
36
|
this.middlewares = [];
|
|
35
37
|
}
|
|
@@ -96,6 +98,8 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
|
|
|
96
98
|
const sortedMiddlewarePipeline = middleware.getMiddlewarePipeline();
|
|
97
99
|
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
98
100
|
this.middlewares.push(...pipeline);
|
|
101
|
+
/* Apply the status code to the response */
|
|
102
|
+
this.middlewares.unshift(new http_status_middleware_1.HttpStatusCodeMiddleware());
|
|
99
103
|
const expressServer = new inversify_express_server_1.InversifyExpressServer(this.container, null, {
|
|
100
104
|
rootPath: this.globalPrefix,
|
|
101
105
|
});
|
|
@@ -118,7 +122,7 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
|
|
|
118
122
|
*/
|
|
119
123
|
async listen(port, environment, consoleMessage) {
|
|
120
124
|
await this.init();
|
|
121
|
-
this.port = port;
|
|
125
|
+
this.port = port || 3000;
|
|
122
126
|
this.environment = environment;
|
|
123
127
|
this.app.set("env", environment);
|
|
124
128
|
this.app.listen(this.port, () => {
|
|
@@ -174,6 +178,17 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
|
|
|
174
178
|
.error("isDevelopment() method must be called on `PostServerInitialization`", "application");
|
|
175
179
|
return false;
|
|
176
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Get the underlying HTTP server. (default: Express.js)
|
|
183
|
+
* @returns The underlying HTTP server after initialization.
|
|
184
|
+
*/
|
|
185
|
+
async getHttpServer() {
|
|
186
|
+
if (!this.app) {
|
|
187
|
+
this.logger.error("The method can only be called in `app.provider` or in e2e tests with supertest.", "adapter-express");
|
|
188
|
+
throw new Error("Incorrect usage of `getHttpServer` method");
|
|
189
|
+
}
|
|
190
|
+
return this.app;
|
|
191
|
+
}
|
|
177
192
|
};
|
|
178
193
|
exports.AppExpress = AppExpress;
|
|
179
194
|
exports.AppExpress = AppExpress = __decorate([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_ROUTING_ROOT_PATH = exports.NO_CONTROLLERS_FOUND = exports.DUPLICATED_CONTROLLER_NAME = exports.HTTP_VERBS_ENUM = exports.PARAMETER_TYPE = exports.METADATA_KEY = exports.TYPE = void 0;
|
|
3
|
+
exports.DEFAULT_ROUTING_ROOT_PATH = exports.NO_CONTROLLERS_FOUND = exports.DUPLICATED_CONTROLLER_NAME = exports.HTTP_VERBS_ENUM = exports.PARAMETER_TYPE = exports.HTTP_CODE_METADATA = exports.METADATA_KEY = exports.TYPE = void 0;
|
|
4
4
|
exports.TYPE = {
|
|
5
5
|
AuthProvider: Symbol.for("AuthProvider"),
|
|
6
6
|
Controller: Symbol.for("Controller"),
|
|
@@ -12,6 +12,11 @@ exports.METADATA_KEY = {
|
|
|
12
12
|
controllerParameter: "inversify-express-utils:controller-parameter",
|
|
13
13
|
httpContext: "inversify-express-utils:httpcontext",
|
|
14
14
|
};
|
|
15
|
+
exports.HTTP_CODE_METADATA = {
|
|
16
|
+
httpCode: "inversify-express-utils:httpcode",
|
|
17
|
+
statusCode: "inversify-express-utils:statuscode",
|
|
18
|
+
path: "inversify-express-utils:path",
|
|
19
|
+
};
|
|
15
20
|
var PARAMETER_TYPE;
|
|
16
21
|
(function (PARAMETER_TYPE) {
|
|
17
22
|
PARAMETER_TYPE[PARAMETER_TYPE["REQUEST"] = 0] = "REQUEST";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.params = exports.principal = exports.next = exports.cookies = exports.headers = exports.body = exports.query = exports.param = exports.response = exports.request = exports.httpMethod = exports.Delete = exports.Head = exports.Patch = exports.Put = exports.Post = exports.Get = exports.All = exports.controller = exports.injectHttpContext = void 0;
|
|
3
|
+
exports.params = exports.principal = exports.next = exports.cookies = exports.headers = exports.body = exports.query = exports.param = exports.response = exports.request = exports.httpMethod = exports.Delete = exports.Head = exports.Patch = exports.Put = exports.Post = exports.Get = exports.All = exports.Http = exports.controller = exports.injectHttpContext = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const inversify_1 = require("inversify");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
@@ -17,6 +17,21 @@ function controller(path, ...middleware) {
|
|
|
17
17
|
path,
|
|
18
18
|
target,
|
|
19
19
|
};
|
|
20
|
+
const pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
|
|
21
|
+
const statusCodeMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.statusCode, Reflect);
|
|
22
|
+
let statusCodePathMapping = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.httpCode, Reflect);
|
|
23
|
+
if (!statusCodePathMapping) {
|
|
24
|
+
statusCodePathMapping = {};
|
|
25
|
+
}
|
|
26
|
+
for (const key in pathMetadata) {
|
|
27
|
+
if (statusCodeMetadata && statusCodeMetadata[key]) {
|
|
28
|
+
const realPath = pathMetadata[key] === "/" ? path : `${path}${pathMetadata[key]}`;
|
|
29
|
+
statusCodePathMapping[realPath] = statusCodeMetadata[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.httpCode, statusCodePathMapping, Reflect);
|
|
33
|
+
Reflect.deleteMetadata(constants_1.HTTP_CODE_METADATA.statusCode, Reflect);
|
|
34
|
+
Reflect.deleteMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
|
|
20
35
|
(0, inversify_1.decorate)((0, inversify_1.injectable)(), target);
|
|
21
36
|
Reflect.defineMetadata(constants_1.METADATA_KEY.controller, currentMetadata, target);
|
|
22
37
|
const previousMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controller, Reflect) || [];
|
|
@@ -25,6 +40,34 @@ function controller(path, ...middleware) {
|
|
|
25
40
|
};
|
|
26
41
|
}
|
|
27
42
|
exports.controller = controller;
|
|
43
|
+
/**
|
|
44
|
+
* Http decorator to define the status code for a route
|
|
45
|
+
* @param code
|
|
46
|
+
* @returns MethodDecorator
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* @Http(200)
|
|
50
|
+
* @Get("/")
|
|
51
|
+
* hello() {
|
|
52
|
+
* return "Hello World";
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function Http(code) {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
58
|
+
return (target, key, descriptor) => {
|
|
59
|
+
let httpCodeMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.statusCode, Reflect);
|
|
60
|
+
if (httpCodeMetadata) {
|
|
61
|
+
httpCodeMetadata[key] = code;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
httpCodeMetadata = {};
|
|
65
|
+
httpCodeMetadata[key] = code;
|
|
66
|
+
}
|
|
67
|
+
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.statusCode, httpCodeMetadata, Reflect);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.Http = Http;
|
|
28
71
|
/**
|
|
29
72
|
* Decorator to allow accept all HTTP methods
|
|
30
73
|
* @param path route path, wildcard
|
|
@@ -88,6 +131,11 @@ function Delete(path, ...middleware) {
|
|
|
88
131
|
return enhancedHttpMethod("delete", path, ...middleware);
|
|
89
132
|
}
|
|
90
133
|
exports.Delete = Delete;
|
|
134
|
+
/**
|
|
135
|
+
* Decorator to allow OPTIONS HTTP method
|
|
136
|
+
* @param path route path
|
|
137
|
+
* @param middleware array of middleware to be applied to the route
|
|
138
|
+
*/
|
|
91
139
|
function enhancedHttpMethod(method, path, ...middleware) {
|
|
92
140
|
return (target, key) => {
|
|
93
141
|
const metadata = {
|
|
@@ -98,6 +146,15 @@ function enhancedHttpMethod(method, path, ...middleware) {
|
|
|
98
146
|
target,
|
|
99
147
|
};
|
|
100
148
|
let metadataList = [];
|
|
149
|
+
let pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
|
|
150
|
+
if (pathMetadata) {
|
|
151
|
+
pathMetadata[key] = path;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
pathMetadata = {};
|
|
155
|
+
pathMetadata[key] = path;
|
|
156
|
+
}
|
|
157
|
+
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.path, pathMetadata, Reflect);
|
|
101
158
|
if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
|
|
102
159
|
Reflect.defineMetadata(constants_1.METADATA_KEY.controllerMethod, metadataList, target.constructor);
|
|
103
160
|
}
|
|
@@ -118,6 +175,12 @@ function enhancedHttpMethod(method, path, ...middleware) {
|
|
|
118
175
|
});
|
|
119
176
|
};
|
|
120
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Decorator to allow custom HTTP method
|
|
180
|
+
* @param method custom HTTP method
|
|
181
|
+
* @param path route path
|
|
182
|
+
* @param middleware array of middleware to be applied to the route
|
|
183
|
+
*/
|
|
121
184
|
function httpMethod(method, path, ...middleware) {
|
|
122
185
|
return (target, key) => {
|
|
123
186
|
const metadata = {
|
|
@@ -128,6 +191,15 @@ function httpMethod(method, path, ...middleware) {
|
|
|
128
191
|
target,
|
|
129
192
|
};
|
|
130
193
|
let metadataList = [];
|
|
194
|
+
let pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
|
|
195
|
+
if (pathMetadata) {
|
|
196
|
+
pathMetadata[key] = path;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
pathMetadata = {};
|
|
200
|
+
pathMetadata[key] = path;
|
|
201
|
+
}
|
|
202
|
+
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.path, pathMetadata, Reflect);
|
|
131
203
|
if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
|
|
132
204
|
Reflect.defineMetadata(constants_1.METADATA_KEY.controllerMethod, metadataList, target.constructor);
|
|
133
205
|
}
|
|
@@ -183,9 +255,17 @@ exports.next = paramDecoratorFactory(constants_1.PARAMETER_TYPE.NEXT);
|
|
|
183
255
|
* @returns ParameterDecorator
|
|
184
256
|
*/
|
|
185
257
|
exports.principal = paramDecoratorFactory(constants_1.PARAMETER_TYPE.PRINCIPAL);
|
|
258
|
+
/**
|
|
259
|
+
* Parameter decorator to inject the request user object
|
|
260
|
+
* @returns ParameterDecorator
|
|
261
|
+
*/
|
|
186
262
|
function paramDecoratorFactory(parameterType) {
|
|
187
263
|
return (name) => params(parameterType, name);
|
|
188
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Parameter decorator to inject the request object
|
|
267
|
+
* @returns ParameterDecorator
|
|
268
|
+
*/
|
|
189
269
|
function params(type, parameterName) {
|
|
190
270
|
return (target, methodName, index) => {
|
|
191
271
|
let metadataList = {};
|
|
@@ -211,6 +291,12 @@ function params(type, parameterName) {
|
|
|
211
291
|
};
|
|
212
292
|
}
|
|
213
293
|
exports.params = params;
|
|
294
|
+
/**
|
|
295
|
+
* Converts a string value to the specified type.
|
|
296
|
+
* @param value The value to convert.
|
|
297
|
+
* @param type The type to convert the value to.
|
|
298
|
+
* @returns The converted value.
|
|
299
|
+
*/
|
|
214
300
|
function convertToType(value, type) {
|
|
215
301
|
if (type === Number) {
|
|
216
302
|
return Number(value);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpStatusCodeMiddleware = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const core_1 = require("@expressots/core");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
/**
|
|
8
|
+
* Middleware that applies the status code to the response.
|
|
9
|
+
* @returns express.RequestHandler
|
|
10
|
+
*/
|
|
11
|
+
class HttpStatusCodeMiddleware extends core_1.ExpressoMiddleware {
|
|
12
|
+
use(req, res, next) {
|
|
13
|
+
const statusCodeMapping = Reflect.getMetadata(constants_1.HTTP_CODE_METADATA.httpCode, Reflect);
|
|
14
|
+
let path = req.path.endsWith("/") ? req.path.slice(0, -1) : req.path;
|
|
15
|
+
if (path === "/" || path === "") {
|
|
16
|
+
path = "/";
|
|
17
|
+
}
|
|
18
|
+
const statusCode = statusCodeMapping[path];
|
|
19
|
+
if (statusCode) {
|
|
20
|
+
res.status(statusCode);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.setDefaultStatusCode(req, res);
|
|
24
|
+
}
|
|
25
|
+
next();
|
|
26
|
+
}
|
|
27
|
+
setDefaultStatusCode(req, res) {
|
|
28
|
+
switch (req.method.toLowerCase()) {
|
|
29
|
+
case "get":
|
|
30
|
+
res.statusCode = 200;
|
|
31
|
+
break;
|
|
32
|
+
case "post":
|
|
33
|
+
res.statusCode = 201;
|
|
34
|
+
break;
|
|
35
|
+
case "put":
|
|
36
|
+
res.statusCode = 204;
|
|
37
|
+
break;
|
|
38
|
+
case "delete":
|
|
39
|
+
res.statusCode = 204;
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
res.statusCode = 200;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.HttpStatusCodeMiddleware = HttpStatusCodeMiddleware;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
|
|
2
|
+
import express from "express";
|
|
2
3
|
import { Container } from "inversify";
|
|
3
4
|
import { ApplicationBase } from "./application-express.base";
|
|
4
5
|
import { IWebServer, ServerEnvironment } from "./application-express.types";
|
|
@@ -14,6 +15,7 @@ import { IWebServer, ServerEnvironment } from "./application-express.types";
|
|
|
14
15
|
* @method isDevelopment - Verifies if the current environment is development.
|
|
15
16
|
*/
|
|
16
17
|
declare class AppExpress extends ApplicationBase implements IWebServer {
|
|
18
|
+
private logger;
|
|
17
19
|
private app;
|
|
18
20
|
private port;
|
|
19
21
|
private environment;
|
|
@@ -81,5 +83,10 @@ declare class AppExpress extends ApplicationBase implements IWebServer {
|
|
|
81
83
|
* @returns A boolean value indicating whether the current environment is development or not.
|
|
82
84
|
*/
|
|
83
85
|
protected isDevelopment(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Get the underlying HTTP server. (default: Express.js)
|
|
88
|
+
* @returns The underlying HTTP server after initialization.
|
|
89
|
+
*/
|
|
90
|
+
getHttpServer(): Promise<express.Application>;
|
|
84
91
|
}
|
|
85
92
|
export { AppExpress };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import express from "express";
|
|
1
2
|
import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
|
|
2
3
|
import { ServerEnvironment } from "./application-express.types";
|
|
3
4
|
/**
|
|
@@ -23,4 +24,9 @@ export interface IWebServerPublic {
|
|
|
23
24
|
* This includes the extension name, view path, and the engine function itself.
|
|
24
25
|
*/
|
|
25
26
|
setEngine<T extends RenderTemplateOptions>(options: T): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get the underlying HTTP server. (default: Express.js)
|
|
29
|
+
* @returns The underlying HTTP server after initialization.
|
|
30
|
+
*/
|
|
31
|
+
getHttpServer(): Promise<express.Application>;
|
|
26
32
|
}
|
|
@@ -9,6 +9,11 @@ export declare const METADATA_KEY: {
|
|
|
9
9
|
controllerParameter: string;
|
|
10
10
|
httpContext: string;
|
|
11
11
|
};
|
|
12
|
+
export declare const HTTP_CODE_METADATA: {
|
|
13
|
+
httpCode: string;
|
|
14
|
+
statusCode: string;
|
|
15
|
+
path: string;
|
|
16
|
+
};
|
|
12
17
|
export declare enum PARAMETER_TYPE {
|
|
13
18
|
REQUEST = 0,
|
|
14
19
|
RESPONSE = 1,
|
|
@@ -8,6 +8,20 @@ export declare const injectHttpContext: (target: import("inversify/lib/annotatio
|
|
|
8
8
|
* @param middleware array of middleware to be applied to all routes in the controller
|
|
9
9
|
*/
|
|
10
10
|
export declare function controller(path: string, ...middleware: Array<Middleware>): (target: NewableFunction) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Http decorator to define the status code for a route
|
|
13
|
+
* @param code
|
|
14
|
+
* @returns MethodDecorator
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* @Http(200)
|
|
18
|
+
* @Get("/")
|
|
19
|
+
* hello() {
|
|
20
|
+
* return "Hello World";
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function Http(code: number): (target: object, key: string | symbol, descriptor: TypedPropertyDescriptor<any>) => void;
|
|
11
25
|
/**
|
|
12
26
|
* Decorator to allow accept all HTTP methods
|
|
13
27
|
* @param path route path, wildcard
|
|
@@ -50,6 +64,12 @@ export declare function Head(path: string, ...middleware: Array<Middleware>): Ha
|
|
|
50
64
|
* @param middleware array of middleware to be applied to the route
|
|
51
65
|
*/
|
|
52
66
|
export declare function Delete(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
67
|
+
/**
|
|
68
|
+
* Decorator to allow custom HTTP method
|
|
69
|
+
* @param method custom HTTP method
|
|
70
|
+
* @param path route path
|
|
71
|
+
* @param middleware array of middleware to be applied to the route
|
|
72
|
+
*/
|
|
53
73
|
export declare function httpMethod(method: keyof typeof HTTP_VERBS_ENUM, path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
54
74
|
/**
|
|
55
75
|
* Parameter decorator to inject the request object
|
|
@@ -96,4 +116,8 @@ export declare const next: () => ParameterDecorator;
|
|
|
96
116
|
* @returns ParameterDecorator
|
|
97
117
|
*/
|
|
98
118
|
export declare const principal: () => ParameterDecorator;
|
|
119
|
+
/**
|
|
120
|
+
* Parameter decorator to inject the request object
|
|
121
|
+
* @returns ParameterDecorator
|
|
122
|
+
*/
|
|
99
123
|
export declare function params(type: PARAMETER_TYPE, parameterName?: string): ParameterDecorator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Request, Response, NextFunction } from "express";
|
|
3
|
+
import { ExpressoMiddleware } from "@expressots/core";
|
|
4
|
+
/**
|
|
5
|
+
* Middleware that applies the status code to the response.
|
|
6
|
+
* @returns express.RequestHandler
|
|
7
|
+
*/
|
|
8
|
+
export declare class HttpStatusCodeMiddleware extends ExpressoMiddleware {
|
|
9
|
+
use(req: Request, res: Response, next: NextFunction): void | Promise<void>;
|
|
10
|
+
private setDefaultStatusCode;
|
|
11
|
+
}
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -57,7 +57,10 @@
|
|
|
57
57
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
58
58
|
"release": "release-it",
|
|
59
59
|
"prepublish": "npm run build && npm pack",
|
|
60
|
-
"
|
|
60
|
+
"publish": "npm publish --tag latest",
|
|
61
|
+
"test": "vitest run --reporter default",
|
|
62
|
+
"test:watch": "vitest run --watch",
|
|
63
|
+
"coverage": "vitest run --coverage",
|
|
61
64
|
"format": "prettier --write \"src/**/*.ts\" --cache",
|
|
62
65
|
"lint": "eslint \"src/**/*.ts\"",
|
|
63
66
|
"lint:fix": "eslint \"src/**/*.ts\" --fix"
|
|
@@ -66,26 +69,29 @@
|
|
|
66
69
|
"dotenv": "16.4.5",
|
|
67
70
|
"inversify": "6.0.2",
|
|
68
71
|
"inversify-binding-decorators": "4.0.0",
|
|
69
|
-
"jest": "29.5.0",
|
|
70
72
|
"reflect-metadata": "0.2.2"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
|
-
"@
|
|
75
|
+
"@codecov/vite-plugin": "^0.0.1-beta.6",
|
|
76
|
+
"@commitlint/cli": "18.0.0",
|
|
74
77
|
"@commitlint/config-conventional": "17.7.0",
|
|
75
78
|
"@expressots/core": "latest",
|
|
76
79
|
"@release-it/conventional-changelog": "7.0.1",
|
|
77
80
|
"@types/express": "4.17.21",
|
|
78
|
-
"@types/jest": "29.5.0",
|
|
79
81
|
"@types/node": "20.4.9",
|
|
80
82
|
"@typescript-eslint/eslint-plugin": "6.6.0",
|
|
81
83
|
"@typescript-eslint/parser": "6.6.0",
|
|
84
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
82
85
|
"eslint": "8.48.0",
|
|
83
86
|
"eslint-config-prettier": "9.0.0",
|
|
84
87
|
"husky": "8.0.3",
|
|
85
88
|
"prettier": "3.0.3",
|
|
86
89
|
"release-it": "16.1.5",
|
|
87
90
|
"ts-jest": "29.0.5",
|
|
88
|
-
"typescript": "5.2.2"
|
|
91
|
+
"typescript": "5.2.2",
|
|
92
|
+
"vite": "^5.2.8",
|
|
93
|
+
"vite-tsconfig-paths": "^4.3.2",
|
|
94
|
+
"vitest": "^1.4.0"
|
|
89
95
|
},
|
|
90
96
|
"release-it": {
|
|
91
97
|
"git": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -57,7 +57,10 @@
|
|
|
57
57
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
58
58
|
"release": "release-it",
|
|
59
59
|
"prepublish": "npm run build && npm pack",
|
|
60
|
-
"
|
|
60
|
+
"publish": "npm publish --tag latest",
|
|
61
|
+
"test": "vitest run --reporter default",
|
|
62
|
+
"test:watch": "vitest run --watch",
|
|
63
|
+
"coverage": "vitest run --coverage",
|
|
61
64
|
"format": "prettier --write \"src/**/*.ts\" --cache",
|
|
62
65
|
"lint": "eslint \"src/**/*.ts\"",
|
|
63
66
|
"lint:fix": "eslint \"src/**/*.ts\" --fix"
|
|
@@ -66,26 +69,29 @@
|
|
|
66
69
|
"dotenv": "16.4.5",
|
|
67
70
|
"inversify": "6.0.2",
|
|
68
71
|
"inversify-binding-decorators": "4.0.0",
|
|
69
|
-
"jest": "29.5.0",
|
|
70
72
|
"reflect-metadata": "0.2.2"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
|
-
"@
|
|
75
|
+
"@codecov/vite-plugin": "^0.0.1-beta.6",
|
|
76
|
+
"@commitlint/cli": "18.0.0",
|
|
74
77
|
"@commitlint/config-conventional": "17.7.0",
|
|
75
78
|
"@expressots/core": "latest",
|
|
76
79
|
"@release-it/conventional-changelog": "7.0.1",
|
|
77
80
|
"@types/express": "4.17.21",
|
|
78
|
-
"@types/jest": "29.5.0",
|
|
79
81
|
"@types/node": "20.4.9",
|
|
80
82
|
"@typescript-eslint/eslint-plugin": "6.6.0",
|
|
81
83
|
"@typescript-eslint/parser": "6.6.0",
|
|
84
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
82
85
|
"eslint": "8.48.0",
|
|
83
86
|
"eslint-config-prettier": "9.0.0",
|
|
84
87
|
"husky": "8.0.3",
|
|
85
88
|
"prettier": "3.0.3",
|
|
86
89
|
"release-it": "16.1.5",
|
|
87
90
|
"ts-jest": "29.0.5",
|
|
88
|
-
"typescript": "5.2.2"
|
|
91
|
+
"typescript": "5.2.2",
|
|
92
|
+
"vite": "^5.2.8",
|
|
93
|
+
"vite-tsconfig-paths": "^4.3.2",
|
|
94
|
+
"vitest": "^1.4.0"
|
|
89
95
|
},
|
|
90
96
|
"release-it": {
|
|
91
97
|
"git": {
|