@expressots/adapter-express 1.4.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/lib/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
 
2
2
 
3
+ ## [1.5.0](https://github.com/expressots/adapter-express/compare/1.4.0...1.5.0) (2024-06-11)
4
+
5
+
6
+ ### Features
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
+
3
30
  ## [1.4.0](https://github.com/expressots/adapter-express/compare/1.3.0...1.4.0) (2024-06-07)
4
31
 
5
32
 
@@ -17,16 +17,14 @@ 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
- }
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) || {};
26
23
  for (const key in pathMetadata) {
27
24
  if (statusCodeMetadata && statusCodeMetadata[key]) {
28
- const realPath = pathMetadata[key] === "/" ? path : `${path}${pathMetadata[key]}`;
29
- statusCodePathMapping[realPath] = statusCodeMetadata[key];
25
+ const realPath = pathMetadata[key]["path"] === "/" ? path : `${path}${pathMetadata[key]["path"]}`;
26
+ statusCodePathMapping[`${realPath}/-${pathMetadata[key]["method"].toLowerCase()}`] =
27
+ statusCodeMetadata[key];
30
28
  }
31
29
  }
32
30
  Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.httpCode, statusCodePathMapping, Reflect);
@@ -148,11 +146,17 @@ function enhancedHttpMethod(method, path, ...middleware) {
148
146
  let metadataList = [];
149
147
  let pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
150
148
  if (pathMetadata) {
151
- pathMetadata[key] = path;
149
+ pathMetadata[key] = {
150
+ path,
151
+ method,
152
+ };
152
153
  }
153
154
  else {
154
155
  pathMetadata = {};
155
- pathMetadata[key] = path;
156
+ pathMetadata[key] = {
157
+ path,
158
+ method,
159
+ };
156
160
  }
157
161
  Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.path, pathMetadata, Reflect);
158
162
  if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
@@ -193,11 +197,17 @@ function httpMethod(method, path, ...middleware) {
193
197
  let metadataList = [];
194
198
  let pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
195
199
  if (pathMetadata) {
196
- pathMetadata[key] = path;
200
+ pathMetadata[key] = {
201
+ path,
202
+ method,
203
+ };
197
204
  }
198
205
  else {
199
206
  pathMetadata = {};
200
- pathMetadata[key] = path;
207
+ pathMetadata[key] = {
208
+ path,
209
+ method,
210
+ };
201
211
  }
202
212
  Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.path, pathMetadata, Reflect);
203
213
  if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
@@ -12,18 +12,47 @@ class HttpStatusCodeMiddleware extends core_1.ExpressoMiddleware {
12
12
  use(req, res, next) {
13
13
  const statusCodeMapping = Reflect.getMetadata(constants_1.HTTP_CODE_METADATA.httpCode, Reflect);
14
14
  let path = req.path.endsWith("/") ? req.path.slice(0, -1) : req.path;
15
+ const formattedMethod = req.method.toLowerCase();
15
16
  if (path === "/" || path === "") {
16
17
  path = "/";
17
18
  }
19
+ path = `${path}/-${formattedMethod}`;
18
20
  const statusCode = statusCodeMapping[path];
19
21
  if (statusCode) {
20
22
  res.status(statusCode);
21
23
  }
22
24
  else {
23
- this.setDefaultStatusCode(req, res);
25
+ const patternMatchStatusCode = this.findMatchingParameterPath(path, statusCodeMapping);
26
+ if (patternMatchStatusCode) {
27
+ res.status(patternMatchStatusCode);
28
+ }
29
+ else {
30
+ this.setDefaultStatusCode(req, res);
31
+ }
24
32
  }
25
33
  next();
26
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
+ **/
27
56
  setDefaultStatusCode(req, res) {
28
57
  switch (req.method.toLowerCase()) {
29
58
  case "get":
@@ -35,6 +64,9 @@ class HttpStatusCodeMiddleware extends core_1.ExpressoMiddleware {
35
64
  case "put":
36
65
  res.statusCode = 204;
37
66
  break;
67
+ case "patch":
68
+ res.statusCode = 204;
69
+ break;
38
70
  case "delete":
39
71
  res.statusCode = 204;
40
72
  break;
@@ -7,5 +7,18 @@ import { ExpressoMiddleware } from "@expressots/core";
7
7
  */
8
8
  export declare class HttpStatusCodeMiddleware extends ExpressoMiddleware {
9
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
+ **/
10
23
  private setDefaultStatusCode;
11
24
  }
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/adapter-express",
3
- "version": "1.4.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",
@@ -74,19 +74,19 @@
74
74
  "devDependencies": {
75
75
  "@codecov/vite-plugin": "^0.0.1-beta.6",
76
76
  "@commitlint/cli": "18.0.0",
77
- "@commitlint/config-conventional": "17.7.0",
77
+ "@commitlint/config-conventional": "19.2.2",
78
78
  "@expressots/core": "latest",
79
- "@release-it/conventional-changelog": "7.0.1",
79
+ "@release-it/conventional-changelog": "7.0.2",
80
80
  "@types/express": "4.17.21",
81
81
  "@types/node": "20.4.9",
82
82
  "@typescript-eslint/eslint-plugin": "6.6.0",
83
83
  "@typescript-eslint/parser": "6.6.0",
84
84
  "@vitest/coverage-v8": "^1.4.0",
85
85
  "eslint": "8.48.0",
86
- "eslint-config-prettier": "9.0.0",
87
- "husky": "8.0.3",
88
- "prettier": "3.0.3",
89
- "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",
90
90
  "ts-jest": "29.0.5",
91
91
  "typescript": "5.2.2",
92
92
  "vite": "^5.2.8",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/adapter-express",
3
- "version": "1.4.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",
@@ -74,19 +74,19 @@
74
74
  "devDependencies": {
75
75
  "@codecov/vite-plugin": "^0.0.1-beta.6",
76
76
  "@commitlint/cli": "18.0.0",
77
- "@commitlint/config-conventional": "17.7.0",
77
+ "@commitlint/config-conventional": "19.2.2",
78
78
  "@expressots/core": "latest",
79
- "@release-it/conventional-changelog": "7.0.1",
79
+ "@release-it/conventional-changelog": "7.0.2",
80
80
  "@types/express": "4.17.21",
81
81
  "@types/node": "20.4.9",
82
82
  "@typescript-eslint/eslint-plugin": "6.6.0",
83
83
  "@typescript-eslint/parser": "6.6.0",
84
84
  "@vitest/coverage-v8": "^1.4.0",
85
85
  "eslint": "8.48.0",
86
- "eslint-config-prettier": "9.0.0",
87
- "husky": "8.0.3",
88
- "prettier": "3.0.3",
89
- "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",
90
90
  "ts-jest": "29.0.5",
91
91
  "typescript": "5.2.2",
92
92
  "vite": "^5.2.8",