hono 2.5.9 → 2.5.10

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.
@@ -28,8 +28,14 @@ var import_trie = require("./trie");
28
28
  const methodNames = [import_router.METHOD_NAME_ALL, ...import_router.METHODS].map((method) => method.toUpperCase());
29
29
  const emptyParam = {};
30
30
  const nullMatcher = [/^$/, []];
31
+ let wildcardRegExpCache = {};
31
32
  function buildWildcardRegExp(path) {
32
- return new RegExp(path === "*" ? "" : `^${path.replace(/\/\*/, "(?:|/.*)")}$`);
33
+ return wildcardRegExpCache[path] ?? (wildcardRegExpCache[path] = new RegExp(
34
+ path === "*" ? "" : `^${path.replace(/\/\*/, "(?:|/.*)")}$`
35
+ ));
36
+ }
37
+ function clearWildcardRegExpCache() {
38
+ wildcardRegExpCache = {};
33
39
  }
34
40
  function buildMatcherFromPreprocessedRoutes(routes) {
35
41
  const trie = new import_trie.Trie();
@@ -100,20 +106,24 @@ class RegExpRouter {
100
106
  }
101
107
  if (/\*$/.test(path)) {
102
108
  const re = buildWildcardRegExp(path);
103
- (_a = middleware[method])[path] || (_a[path] = findMiddleware(middleware[method], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || []);
109
+ if (method === import_router.METHOD_NAME_ALL) {
110
+ Object.keys(middleware).forEach((m) => {
111
+ var _a2;
112
+ (_a2 = middleware[m])[path] || (_a2[path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || []);
113
+ });
114
+ } else {
115
+ (_a = middleware[method])[path] || (_a[path] = findMiddleware(middleware[method], path) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path) || []);
116
+ }
104
117
  Object.keys(middleware).forEach((m) => {
105
118
  if (method === import_router.METHOD_NAME_ALL || method === m) {
106
119
  Object.keys(middleware[m]).forEach((p) => {
107
- ;
108
- (path === "*" || re.test(p)) && middleware[m][p].push(handler);
120
+ re.test(p) && middleware[m][p].push(handler);
109
121
  });
110
122
  }
111
123
  });
112
124
  Object.keys(routes).forEach((m) => {
113
125
  if (method === import_router.METHOD_NAME_ALL || method === m) {
114
- Object.keys(routes[m]).forEach(
115
- (p) => (path === "*" || re.test(p)) && routes[m][p].push(handler)
116
- );
126
+ Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push(handler));
117
127
  }
118
128
  });
119
129
  return;
@@ -133,6 +143,7 @@ class RegExpRouter {
133
143
  }
134
144
  }
135
145
  match(method, path) {
146
+ clearWildcardRegExpCache();
136
147
  const matchers = this.buildAllMatchers();
137
148
  this.match = (method2, path2) => {
138
149
  const matcher = matchers[method2];
@@ -23,9 +23,13 @@ __export(rule_exports, {
23
23
  module.exports = __toCommonJS(rule_exports);
24
24
  const rule = {
25
25
  isEmpty(value, options = { ignore_whitespace: false }) {
26
+ if (value === void 0)
27
+ return false;
26
28
  return (options.ignore_whitespace ? value.trim().length : value.length) === 0;
27
29
  },
28
30
  isLength: (value, options, arg2) => {
31
+ if (value === void 0)
32
+ return false;
29
33
  let min;
30
34
  let max;
31
35
  if (typeof options === "object") {
@@ -41,15 +45,21 @@ const rule = {
41
45
  return len >= min && (typeof max === "undefined" || len <= max);
42
46
  },
43
47
  isAlpha: (value) => {
48
+ if (value === void 0)
49
+ return false;
44
50
  return /^[A-Z]+$/i.test(value);
45
51
  },
46
52
  isNumeric: (value) => {
53
+ if (value === void 0)
54
+ return false;
47
55
  return /^[0-9]+$/.test(value);
48
56
  },
49
57
  contains: (value, elem, options = {
50
58
  ignoreCase: false,
51
59
  minOccurrences: 1
52
60
  }) => {
61
+ if (value === void 0 || elem === void 0)
62
+ return false;
53
63
  options.ignoreCase || (options.ignoreCase = false);
54
64
  options.minOccurrences || (options.minOccurrences = 1);
55
65
  if (options.ignoreCase) {
@@ -58,6 +68,8 @@ const rule = {
58
68
  return value.split(elem).length > options.minOccurrences;
59
69
  },
60
70
  isIn: (value, options) => {
71
+ if (value === void 0)
72
+ return false;
61
73
  if (typeof options === "object") {
62
74
  for (const elem of options) {
63
75
  if (elem === value)
@@ -67,6 +79,8 @@ const rule = {
67
79
  return false;
68
80
  },
69
81
  match: (value, regExp) => {
82
+ if (value === void 0 || regExp === void 0)
83
+ return false;
70
84
  return regExp.test(value);
71
85
  },
72
86
  isGte: (value, min) => min <= value,
@@ -6,8 +6,14 @@ import { Trie } from "./trie.js";
6
6
  var methodNames = [METHOD_NAME_ALL, ...METHODS].map((method) => method.toUpperCase());
7
7
  var emptyParam = {};
8
8
  var nullMatcher = [/^$/, []];
9
+ var wildcardRegExpCache = {};
9
10
  function buildWildcardRegExp(path) {
10
- return new RegExp(path === "*" ? "" : `^${path.replace(/\/\*/, "(?:|/.*)")}$`);
11
+ return wildcardRegExpCache[path] ?? (wildcardRegExpCache[path] = new RegExp(
12
+ path === "*" ? "" : `^${path.replace(/\/\*/, "(?:|/.*)")}$`
13
+ ));
14
+ }
15
+ function clearWildcardRegExpCache() {
16
+ wildcardRegExpCache = {};
11
17
  }
12
18
  function buildMatcherFromPreprocessedRoutes(routes) {
13
19
  const trie = new Trie();
@@ -78,20 +84,24 @@ var RegExpRouter = class {
78
84
  }
79
85
  if (/\*$/.test(path)) {
80
86
  const re = buildWildcardRegExp(path);
81
- (_a = middleware[method])[path] || (_a[path] = findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || []);
87
+ if (method === METHOD_NAME_ALL) {
88
+ Object.keys(middleware).forEach((m) => {
89
+ var _a2;
90
+ (_a2 = middleware[m])[path] || (_a2[path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || []);
91
+ });
92
+ } else {
93
+ (_a = middleware[method])[path] || (_a[path] = findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || []);
94
+ }
82
95
  Object.keys(middleware).forEach((m) => {
83
96
  if (method === METHOD_NAME_ALL || method === m) {
84
97
  Object.keys(middleware[m]).forEach((p) => {
85
- ;
86
- (path === "*" || re.test(p)) && middleware[m][p].push(handler);
98
+ re.test(p) && middleware[m][p].push(handler);
87
99
  });
88
100
  }
89
101
  });
90
102
  Object.keys(routes).forEach((m) => {
91
103
  if (method === METHOD_NAME_ALL || method === m) {
92
- Object.keys(routes[m]).forEach(
93
- (p) => (path === "*" || re.test(p)) && routes[m][p].push(handler)
94
- );
104
+ Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push(handler));
95
105
  }
96
106
  });
97
107
  return;
@@ -111,6 +121,7 @@ var RegExpRouter = class {
111
121
  }
112
122
  }
113
123
  match(method, path) {
124
+ clearWildcardRegExpCache();
114
125
  const matchers = this.buildAllMatchers();
115
126
  this.match = (method2, path2) => {
116
127
  const matcher = matchers[method2];
@@ -1,9 +1,13 @@
1
1
  // src/validator/rule.ts
2
2
  var rule = {
3
3
  isEmpty(value, options = { ignore_whitespace: false }) {
4
+ if (value === void 0)
5
+ return false;
4
6
  return (options.ignore_whitespace ? value.trim().length : value.length) === 0;
5
7
  },
6
8
  isLength: (value, options, arg2) => {
9
+ if (value === void 0)
10
+ return false;
7
11
  let min;
8
12
  let max;
9
13
  if (typeof options === "object") {
@@ -19,15 +23,21 @@ var rule = {
19
23
  return len >= min && (typeof max === "undefined" || len <= max);
20
24
  },
21
25
  isAlpha: (value) => {
26
+ if (value === void 0)
27
+ return false;
22
28
  return /^[A-Z]+$/i.test(value);
23
29
  },
24
30
  isNumeric: (value) => {
31
+ if (value === void 0)
32
+ return false;
25
33
  return /^[0-9]+$/.test(value);
26
34
  },
27
35
  contains: (value, elem, options = {
28
36
  ignoreCase: false,
29
37
  minOccurrences: 1
30
38
  }) => {
39
+ if (value === void 0 || elem === void 0)
40
+ return false;
31
41
  options.ignoreCase || (options.ignoreCase = false);
32
42
  options.minOccurrences || (options.minOccurrences = 1);
33
43
  if (options.ignoreCase) {
@@ -36,6 +46,8 @@ var rule = {
36
46
  return value.split(elem).length > options.minOccurrences;
37
47
  },
38
48
  isIn: (value, options) => {
49
+ if (value === void 0)
50
+ return false;
39
51
  if (typeof options === "object") {
40
52
  for (const elem of options) {
41
53
  if (elem === value)
@@ -45,6 +57,8 @@ var rule = {
45
57
  return false;
46
58
  },
47
59
  match: (value, regExp) => {
60
+ if (value === void 0 || regExp === void 0)
61
+ return false;
48
62
  return regExp.test(value);
49
63
  },
50
64
  isGte: (value, min) => min <= value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "2.5.9",
3
+ "version": "2.5.10",
4
4
  "description": "Ultrafast web framework for Cloudflare Workers, Deno, and Bun.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",