@expressots/adapter-express 1.3.0 → 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 +25 -1
- package/lib/README.md +8 -0
- package/lib/cjs/adapter-express/application-express.js +3 -0
- 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/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,10 +1,34 @@
|
|
|
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
4
|
|
|
5
5
|
|
|
6
6
|
### Features
|
|
7
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))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
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))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Code Refactoring
|
|
24
|
+
|
|
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
|
+
|
|
8
32
|
* returns httpServer for e2e testing with supertest ([97999fb](https://github.com/expressots/adapter-express/commit/97999fbc7ac977e47caf023d7541e588ef50d548))
|
|
9
33
|
|
|
10
34
|
## [1.2.2](https://github.com/expressots/adapter-express/compare/1.2.1...1.2.2) (2024-04-25)
|
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
|
|
@@ -16,6 +16,7 @@ const process_1 = __importDefault(require("process"));
|
|
|
16
16
|
const application_express_base_1 = require("./application-express.base");
|
|
17
17
|
const application_express_types_1 = require("./application-express.types");
|
|
18
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
|
|
@@ -97,6 +98,8 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
|
|
|
97
98
|
const sortedMiddlewarePipeline = middleware.getMiddlewarePipeline();
|
|
98
99
|
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
99
100
|
this.middlewares.push(...pipeline);
|
|
101
|
+
/* Apply the status code to the response */
|
|
102
|
+
this.middlewares.unshift(new http_status_middleware_1.HttpStatusCodeMiddleware());
|
|
100
103
|
const expressServer = new inversify_express_server_1.InversifyExpressServer(this.container, null, {
|
|
101
104
|
rootPath: this.globalPrefix,
|
|
102
105
|
});
|
|
@@ -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;
|
|
@@ -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": {
|