@expressots/adapter-express 1.3.0 → 1.5.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 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,61 @@
1
1
 
2
2
 
3
- ## [1.3.0](https://github.com/expressots/adapter-express/compare/1.2.2...1.3.0) (2024-04-26)
3
+ ## [1.5.0](https://github.com/expressots/adapter-express/compare/1.4.0...1.5.0) (2024-06-11)
4
4
 
5
5
 
6
6
  ### Features
7
7
 
8
+ * bump @commitlint/config-conventional from 17.7.0 to 19.2.2 ([c4db260](https://github.com/expressots/adapter-express/commit/c4db260694b492e5744dc7c59ce4edae23053ec8))
9
+ * bump @release-it/conventional-changelog from 7.0.1 to 7.0.2 ([d063fd9](https://github.com/expressots/adapter-express/commit/d063fd9ff2b405eb69197b70cad72334d814b6bf))
10
+ * bump eslint-config-prettier from 9.0.0 to 9.1.0 ([20ca753](https://github.com/expressots/adapter-express/commit/20ca753e4297889506af98e6caa5b1f374aded59))
11
+ * bump husky from 8.0.3 to 9.0.11 ([8cb065e](https://github.com/expressots/adapter-express/commit/8cb065e49e209b2a6ab56d07a712df30596350ca))
12
+ * bump prettier from 3.0.3 to 3.3.1 ([872c7ba](https://github.com/expressots/adapter-express/commit/872c7ba7072c1cfb36a7efe74be0b41f6aea541b))
13
+ * bump prettier from 3.3.1 to 3.3.2 ([5edd349](https://github.com/expressots/adapter-express/commit/5edd3490f1a6fa48a65694a9c146c2ec69a264d3))
14
+ * bump release-it from 16.1.5 to 16.3.0 ([5febf25](https://github.com/expressots/adapter-express/commit/5febf2517dec9857d59ec189829262dafcc63fbd))
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * decorator method case confict fix ([cdf0fbd](https://github.com/expressots/adapter-express/commit/cdf0fbd6c864a0e538372dc102664538112f0e30))
20
+ * init commit ([55359bf](https://github.com/expressots/adapter-express/commit/55359bf31acfdf0186f6916cd0dc1897d1f24cd2))
21
+ * patch issue where not using http decorator shows incorrect code ([975e451](https://github.com/expressots/adapter-express/commit/975e45112181088bcb9d8f1487e8272deb49d3df))
22
+ * remove comments and logs for prod build ([cd0151b](https://github.com/expressots/adapter-express/commit/cd0151be92f1cb73b6040a72db6d4f1268ae6cfc))
23
+ * remove unused method param in find param pattern ([fd40872](https://github.com/expressots/adapter-express/commit/fd4087276672a6b3c34563736892e4065a497bfa))
24
+
25
+
26
+ ### Code Refactoring
27
+
28
+ * without and with decor in the same route conflict ([469f65e](https://github.com/expressots/adapter-express/commit/469f65e9248aefe5db084608684ca211204c2f5b))
29
+
30
+ ## [1.4.0](https://github.com/expressots/adapter-express/compare/1.3.0...1.4.0) (2024-06-07)
31
+
32
+
33
+ ### Features
34
+
35
+ * Add http code decorator ([f0f6e0a](https://github.com/expressots/adapter-express/commit/f0f6e0aa034636d7df67d5f1cef83adb6a3af8bc))
36
+ * add vitest and setup codecov in the ci ([14fd527](https://github.com/expressots/adapter-express/commit/14fd527a097d981778f2b3ba2a68effb68865d8f))
37
+ * adjust doc, update metadata const for http decorator ([773f297](https://github.com/expressots/adapter-express/commit/773f297fee340b5d8de6a134454425328ddbbc03))
38
+ * dev-http decorator changes ([8088f5c](https://github.com/expressots/adapter-express/commit/8088f5c2ef391abbe33d1e8750bef9a6fe34f699))
39
+ * fix issues where decorator does not function properly when used multiple times in same file ([919815f](https://github.com/expressots/adapter-express/commit/919815f4f1232f9a319ed887a99f8c214b40341d))
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * build shield workflow status ([3e5d6c8](https://github.com/expressots/adapter-express/commit/3e5d6c814cb5ed71cfa7a4f5e65f77ad359671f6))
45
+ * code coverage upload path ([aef20eb](https://github.com/expressots/adapter-express/commit/aef20eb2767506e7d9c7773233727c96cb5ca9b7))
46
+ * remove codesee ci config ([043c423](https://github.com/expressots/adapter-express/commit/043c423c52d00c814c6357c1e7f6ed7caed3b2ac))
47
+ * remove the decorator incorrect call in the library due mismatch on tsconfig ([58dbb52](https://github.com/expressots/adapter-express/commit/58dbb5258a7c2155dd34b1841dbfbe15884f4e21))
48
+
49
+
50
+ ### Code Refactoring
51
+
52
+ * readme badges npm, coverage and build added ([d643acd](https://github.com/expressots/adapter-express/commit/d643acde38df4866155a0164f08c2d7f0261c705))
53
+
54
+ ## [1.3.0](https://github.com/expressots/adapter-express/compare/1.2.2...1.3.0) (2024-04-26)
55
+
56
+
57
+ ### Features
58
+
8
59
  * returns httpServer for e2e testing with supertest ([97999fb](https://github.com/expressots/adapter-express/commit/97999fbc7ac977e47caf023d7541e588ef50d548))
9
60
 
10
61
  ## [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,19 @@ 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
+ const statusCodePathMapping = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.httpCode, Reflect) || {};
23
+ for (const key in pathMetadata) {
24
+ if (statusCodeMetadata && statusCodeMetadata[key]) {
25
+ const realPath = pathMetadata[key]["path"] === "/" ? path : `${path}${pathMetadata[key]["path"]}`;
26
+ statusCodePathMapping[`${realPath}/-${pathMetadata[key]["method"].toLowerCase()}`] =
27
+ statusCodeMetadata[key];
28
+ }
29
+ }
30
+ Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.httpCode, statusCodePathMapping, Reflect);
31
+ Reflect.deleteMetadata(constants_1.HTTP_CODE_METADATA.statusCode, Reflect);
32
+ Reflect.deleteMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
20
33
  (0, inversify_1.decorate)((0, inversify_1.injectable)(), target);
21
34
  Reflect.defineMetadata(constants_1.METADATA_KEY.controller, currentMetadata, target);
22
35
  const previousMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controller, Reflect) || [];
@@ -25,6 +38,34 @@ function controller(path, ...middleware) {
25
38
  };
26
39
  }
27
40
  exports.controller = controller;
41
+ /**
42
+ * Http decorator to define the status code for a route
43
+ * @param code
44
+ * @returns MethodDecorator
45
+ * @example
46
+ * ```ts
47
+ * @Http(200)
48
+ * @Get("/")
49
+ * hello() {
50
+ * return "Hello World";
51
+ * }
52
+ * ```
53
+ */
54
+ function Http(code) {
55
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
56
+ return (target, key, descriptor) => {
57
+ let httpCodeMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.statusCode, Reflect);
58
+ if (httpCodeMetadata) {
59
+ httpCodeMetadata[key] = code;
60
+ }
61
+ else {
62
+ httpCodeMetadata = {};
63
+ httpCodeMetadata[key] = code;
64
+ }
65
+ Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.statusCode, httpCodeMetadata, Reflect);
66
+ };
67
+ }
68
+ exports.Http = Http;
28
69
  /**
29
70
  * Decorator to allow accept all HTTP methods
30
71
  * @param path route path, wildcard
@@ -88,6 +129,11 @@ function Delete(path, ...middleware) {
88
129
  return enhancedHttpMethod("delete", path, ...middleware);
89
130
  }
90
131
  exports.Delete = Delete;
132
+ /**
133
+ * Decorator to allow OPTIONS HTTP method
134
+ * @param path route path
135
+ * @param middleware array of middleware to be applied to the route
136
+ */
91
137
  function enhancedHttpMethod(method, path, ...middleware) {
92
138
  return (target, key) => {
93
139
  const metadata = {
@@ -98,6 +144,21 @@ function enhancedHttpMethod(method, path, ...middleware) {
98
144
  target,
99
145
  };
100
146
  let metadataList = [];
147
+ let pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
148
+ if (pathMetadata) {
149
+ pathMetadata[key] = {
150
+ path,
151
+ method,
152
+ };
153
+ }
154
+ else {
155
+ pathMetadata = {};
156
+ pathMetadata[key] = {
157
+ path,
158
+ method,
159
+ };
160
+ }
161
+ Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.path, pathMetadata, Reflect);
101
162
  if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
102
163
  Reflect.defineMetadata(constants_1.METADATA_KEY.controllerMethod, metadataList, target.constructor);
103
164
  }
@@ -118,6 +179,12 @@ function enhancedHttpMethod(method, path, ...middleware) {
118
179
  });
119
180
  };
120
181
  }
182
+ /**
183
+ * Decorator to allow custom HTTP method
184
+ * @param method custom HTTP method
185
+ * @param path route path
186
+ * @param middleware array of middleware to be applied to the route
187
+ */
121
188
  function httpMethod(method, path, ...middleware) {
122
189
  return (target, key) => {
123
190
  const metadata = {
@@ -128,6 +195,21 @@ function httpMethod(method, path, ...middleware) {
128
195
  target,
129
196
  };
130
197
  let metadataList = [];
198
+ let pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
199
+ if (pathMetadata) {
200
+ pathMetadata[key] = {
201
+ path,
202
+ method,
203
+ };
204
+ }
205
+ else {
206
+ pathMetadata = {};
207
+ pathMetadata[key] = {
208
+ path,
209
+ method,
210
+ };
211
+ }
212
+ Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.path, pathMetadata, Reflect);
131
213
  if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
132
214
  Reflect.defineMetadata(constants_1.METADATA_KEY.controllerMethod, metadataList, target.constructor);
133
215
  }
@@ -183,9 +265,17 @@ exports.next = paramDecoratorFactory(constants_1.PARAMETER_TYPE.NEXT);
183
265
  * @returns ParameterDecorator
184
266
  */
185
267
  exports.principal = paramDecoratorFactory(constants_1.PARAMETER_TYPE.PRINCIPAL);
268
+ /**
269
+ * Parameter decorator to inject the request user object
270
+ * @returns ParameterDecorator
271
+ */
186
272
  function paramDecoratorFactory(parameterType) {
187
273
  return (name) => params(parameterType, name);
188
274
  }
275
+ /**
276
+ * Parameter decorator to inject the request object
277
+ * @returns ParameterDecorator
278
+ */
189
279
  function params(type, parameterName) {
190
280
  return (target, methodName, index) => {
191
281
  let metadataList = {};
@@ -211,6 +301,12 @@ function params(type, parameterName) {
211
301
  };
212
302
  }
213
303
  exports.params = params;
304
+ /**
305
+ * Converts a string value to the specified type.
306
+ * @param value The value to convert.
307
+ * @param type The type to convert the value to.
308
+ * @returns The converted value.
309
+ */
214
310
  function convertToType(value, type) {
215
311
  if (type === Number) {
216
312
  return Number(value);
@@ -0,0 +1,79 @@
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
+ const formattedMethod = req.method.toLowerCase();
16
+ if (path === "/" || path === "") {
17
+ path = "/";
18
+ }
19
+ path = `${path}/-${formattedMethod}`;
20
+ const statusCode = statusCodeMapping[path];
21
+ if (statusCode) {
22
+ res.status(statusCode);
23
+ }
24
+ else {
25
+ const patternMatchStatusCode = this.findMatchingParameterPath(path, statusCodeMapping);
26
+ if (patternMatchStatusCode) {
27
+ res.status(patternMatchStatusCode);
28
+ }
29
+ else {
30
+ this.setDefaultStatusCode(req, res);
31
+ }
32
+ }
33
+ next();
34
+ }
35
+ /**
36
+ * Find the matching parameter path.
37
+ * @param path - The path to match.
38
+ * @param mapping - The mapping to check.
39
+ * @param method - The method to check.
40
+ * @returns The status code if found, otherwise null.
41
+ **/
42
+ findMatchingParameterPath(path, mapping) {
43
+ for (const pathCode in mapping) {
44
+ const patternCheck = new RegExp("^" + pathCode.replace(/:[^\s/]+/g, "([^/]+)") + "$");
45
+ if (patternCheck.test(path)) {
46
+ return mapping[pathCode];
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ /**
52
+ * Set the default status code based on the request method.
53
+ * @param req - The request object.
54
+ * @param res - The response object.
55
+ **/
56
+ setDefaultStatusCode(req, res) {
57
+ switch (req.method.toLowerCase()) {
58
+ case "get":
59
+ res.statusCode = 200;
60
+ break;
61
+ case "post":
62
+ res.statusCode = 201;
63
+ break;
64
+ case "put":
65
+ res.statusCode = 204;
66
+ break;
67
+ case "patch":
68
+ res.statusCode = 204;
69
+ break;
70
+ case "delete":
71
+ res.statusCode = 204;
72
+ break;
73
+ default:
74
+ res.statusCode = 200;
75
+ break;
76
+ }
77
+ }
78
+ }
79
+ 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,24 @@
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
+ /**
11
+ * Find the matching parameter path.
12
+ * @param path - The path to match.
13
+ * @param mapping - The mapping to check.
14
+ * @param method - The method to check.
15
+ * @returns The status code if found, otherwise null.
16
+ **/
17
+ private findMatchingParameterPath;
18
+ /**
19
+ * Set the default status code based on the request method.
20
+ * @param req - The request object.
21
+ * @param res - The response object.
22
+ **/
23
+ private setDefaultStatusCode;
24
+ }
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/adapter-express",
3
- "version": "1.3.0",
3
+ "version": "1.5.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
- "test": "jest",
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
- "@commitlint/cli": "^18.0.0",
74
- "@commitlint/config-conventional": "17.7.0",
75
+ "@codecov/vite-plugin": "^0.0.1-beta.6",
76
+ "@commitlint/cli": "18.0.0",
77
+ "@commitlint/config-conventional": "19.2.2",
75
78
  "@expressots/core": "latest",
76
- "@release-it/conventional-changelog": "7.0.1",
79
+ "@release-it/conventional-changelog": "7.0.2",
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
- "eslint-config-prettier": "9.0.0",
84
- "husky": "8.0.3",
85
- "prettier": "3.0.3",
86
- "release-it": "16.1.5",
86
+ "eslint-config-prettier": "9.1.0",
87
+ "husky": "9.0.11",
88
+ "prettier": "3.3.2",
89
+ "release-it": "16.3.0",
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.0",
3
+ "version": "1.5.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
- "test": "jest",
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
- "@commitlint/cli": "^18.0.0",
74
- "@commitlint/config-conventional": "17.7.0",
75
+ "@codecov/vite-plugin": "^0.0.1-beta.6",
76
+ "@commitlint/cli": "18.0.0",
77
+ "@commitlint/config-conventional": "19.2.2",
75
78
  "@expressots/core": "latest",
76
- "@release-it/conventional-changelog": "7.0.1",
79
+ "@release-it/conventional-changelog": "7.0.2",
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
- "eslint-config-prettier": "9.0.0",
84
- "husky": "8.0.3",
85
- "prettier": "3.0.3",
86
- "release-it": "16.1.5",
86
+ "eslint-config-prettier": "9.1.0",
87
+ "husky": "9.0.11",
88
+ "prettier": "3.3.2",
89
+ "release-it": "16.3.0",
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": {