vovk 3.0.0-draft.423 → 3.0.0-draft.424

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/cjs/VovkApp.d.ts CHANGED
@@ -26,4 +26,5 @@ export declare class VovkApp {
26
26
  params: Promise<Record<string, string[]>>;
27
27
  }) => Promise<Response>;
28
28
  respond: (status: HttpStatus, body: unknown, options?: DecoratorOptions) => Response;
29
+ private routeRegexCache;
29
30
  }
package/cjs/VovkApp.js CHANGED
@@ -59,6 +59,7 @@ class VovkApp {
59
59
  isError: true,
60
60
  }, options);
61
61
  };
62
+ routeRegexCache = new Map();
62
63
  #getHandler = ({ handlers, path, params, }) => {
63
64
  let methodParams = {};
64
65
  if (Object.keys(params).length === 0) {
@@ -76,10 +77,15 @@ class VovkApp {
76
77
  const routeSegment = routeSegments[i];
77
78
  const pathSegment = path[i];
78
79
  if (routeSegment.includes('{')) {
79
- const regexPattern = routeSegment
80
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // Escape special chars
81
- .replace(/\\{(\w+)\\}/g, '(?<$1>[^/]+)'); // Replace {var} with named groups
82
- const values = pathSegment.match(new RegExp(`^${regexPattern}$`))?.groups ?? {};
80
+ let regex = this.routeRegexCache.get(routeSegment);
81
+ if (!regex) {
82
+ const regexPattern = routeSegment
83
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
84
+ .replace(/\\{(\w+)\\}/g, '(?<$1>[^/]+)');
85
+ regex = new RegExp(`^${regexPattern}$`);
86
+ this.routeRegexCache.set(routeSegment, regex);
87
+ }
88
+ const values = pathSegment.match(regex)?.groups ?? {};
83
89
  for (const parameter in values) {
84
90
  if (!Object.prototype.hasOwnProperty.call(values, parameter))
85
91
  continue;
package/mjs/VovkApp.d.ts CHANGED
@@ -26,4 +26,5 @@ export declare class VovkApp {
26
26
  params: Promise<Record<string, string[]>>;
27
27
  }) => Promise<Response>;
28
28
  respond: (status: HttpStatus, body: unknown, options?: DecoratorOptions) => Response;
29
+ private routeRegexCache;
29
30
  }
package/mjs/VovkApp.js CHANGED
@@ -59,6 +59,7 @@ class VovkApp {
59
59
  isError: true,
60
60
  }, options);
61
61
  };
62
+ routeRegexCache = new Map();
62
63
  #getHandler = ({ handlers, path, params, }) => {
63
64
  let methodParams = {};
64
65
  if (Object.keys(params).length === 0) {
@@ -76,10 +77,15 @@ class VovkApp {
76
77
  const routeSegment = routeSegments[i];
77
78
  const pathSegment = path[i];
78
79
  if (routeSegment.includes('{')) {
79
- const regexPattern = routeSegment
80
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // Escape special chars
81
- .replace(/\\{(\w+)\\}/g, '(?<$1>[^/]+)'); // Replace {var} with named groups
82
- const values = pathSegment.match(new RegExp(`^${regexPattern}$`))?.groups ?? {};
80
+ let regex = this.routeRegexCache.get(routeSegment);
81
+ if (!regex) {
82
+ const regexPattern = routeSegment
83
+ .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
84
+ .replace(/\\{(\w+)\\}/g, '(?<$1>[^/]+)');
85
+ regex = new RegExp(`^${regexPattern}$`);
86
+ this.routeRegexCache.set(routeSegment, regex);
87
+ }
88
+ const values = pathSegment.match(regex)?.groups ?? {};
83
89
  for (const parameter in values) {
84
90
  if (!Object.prototype.hasOwnProperty.call(values, parameter))
85
91
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vovk",
3
- "version": "3.0.0-draft.423",
3
+ "version": "3.0.0-draft.424",
4
4
  "main": "./cjs/index.js",
5
5
  "module": "./mjs/index.js",
6
6
  "types": "./mjs/index.d.ts",