hono 2.5.9 → 2.6.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.
@@ -27,6 +27,7 @@ var import_validator = require("../../validator/validator");
27
27
  const validatorMiddleware = (validationFunction, options) => {
28
28
  const v = new import_validator.Validator();
29
29
  const handler = async (c, next) => {
30
+ var _a;
30
31
  const resultSet = {
31
32
  hasError: false,
32
33
  messages: [],
@@ -75,14 +76,16 @@ const validatorMiddleware = (validationFunction, options) => {
75
76
  const dst = data;
76
77
  data = (0, import_object.mergeObjects)(dst, jsonData);
77
78
  } else {
78
- c.req.valid(keys, value);
79
+ let tmp = data;
80
+ for (let i = 0; i < keys.length - 1; i++) {
81
+ tmp = tmp[_a = keys[i]] || (tmp[_a] = {});
82
+ }
83
+ tmp[keys[keys.length - 1]] = value;
79
84
  }
80
85
  }
81
86
  }
82
87
  if (!resultSet.hasError) {
83
- Object.keys(data).map((key) => {
84
- c.req.valid(key, data[key]);
85
- });
88
+ c.req.valid(data);
86
89
  }
87
90
  if (options && options.done) {
88
91
  const res = options.done(resultSet, c);
@@ -113,20 +113,12 @@ function extendRequestPrototype() {
113
113
  }
114
114
  return jsonData;
115
115
  };
116
- Request.prototype.valid = function(keys, value) {
117
- var _a;
116
+ Request.prototype.valid = function(data) {
118
117
  if (!this.data) {
119
118
  this.data = {};
120
119
  }
121
- if (keys !== void 0) {
122
- if (typeof keys === "string") {
123
- keys = [keys];
124
- }
125
- let data = this.data;
126
- for (let i = 0; i < keys.length - 1; i++) {
127
- data = data[_a = keys[i]] || (data[_a] = {});
128
- }
129
- data[keys[keys.length - 1]] = value;
120
+ if (data) {
121
+ this.data = data;
130
122
  }
131
123
  return this.data;
132
124
  };
@@ -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,
package/dist/context.d.ts CHANGED
@@ -6,7 +6,7 @@ import type { Schema, SchemaToProp } from './validator/schema';
6
6
  declare type Headers = Record<string, string | string[]>;
7
7
  declare type Runtime = 'node' | 'deno' | 'bun' | 'cloudflare' | 'fastly' | 'vercel' | 'other';
8
8
  export declare type Data = string | ArrayBuffer | ReadableStream;
9
- export declare class Context<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> {
9
+ export declare class Context<P extends string = string, E extends Partial<Environment> = Environment, S = any> {
10
10
  req: Request<unknown, P, S extends Schema ? SchemaToProp<S> : S>;
11
11
  env: E['Bindings'];
12
12
  finalized: boolean;
package/dist/hono.d.ts CHANGED
@@ -1,20 +1,19 @@
1
1
  import type { Router } from './router';
2
2
  import type { ExecutionContext } from './types';
3
3
  import type { Handler, Environment, ParamKeys, ErrorHandler, NotFoundHandler } from './types';
4
- import type { Schema } from './validator/schema';
5
- interface HandlerInterface<P extends string, E extends Partial<Environment>, S extends Partial<Schema>, U = Hono<E, P, S>> {
6
- <Path extends string, Data extends Schema>(...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): U;
7
- (...handlers: Handler<string, E, S>[]): U;
8
- <Path extends string, Data extends Partial<Schema> = Schema>(path: Path, ...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): U;
9
- <Path extends string, Data extends Schema>(path: Path, ...handlers: Handler<string, E, Data>[]): U;
10
- (path: string, ...handlers: Handler<string, E, S>[]): U;
4
+ interface HandlerInterface<P extends string, E extends Partial<Environment> = Environment, S = unknown, U = Hono<E, P, S>> {
5
+ <Path extends string, Data = S>(...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): Hono<E, Path, Data & S>;
6
+ (...handlers: Handler<P, E, S>[]): U;
7
+ <Path extends string, Data = S>(path: Path, ...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): Hono<E, Path, Data & S>;
8
+ <Path extends string, Data = S>(path: Path, ...handlers: Handler<string, E, Data>[]): Hono<E, string, Data & S>;
9
+ (path: string, ...handlers: Handler<P, E, S>[]): U;
11
10
  }
12
- interface Route<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> {
11
+ interface Route<P extends string = string, E extends Partial<Environment> = Environment, S = unknown> {
13
12
  path: string;
14
13
  method: string;
15
14
  handler: Handler<P, E, S>;
16
15
  }
17
- declare const Hono_base: new <E_1 extends Partial<Environment> = Environment, P_1 extends string = string, S_1 extends Partial<Schema> = Schema, U = Hono<E_1, P_1, S_1>>() => {
16
+ declare const Hono_base: new <E_1 extends Partial<Environment> = Environment, P_1 extends string = string, S_1 = unknown, U = Hono<E_1, P_1, S_1>>() => {
18
17
  get: HandlerInterface<P_1, E_1, S_1, U>;
19
18
  all: HandlerInterface<P_1, E_1, S_1, U>;
20
19
  post: HandlerInterface<P_1, E_1, S_1, U>;
@@ -24,7 +23,7 @@ declare const Hono_base: new <E_1 extends Partial<Environment> = Environment, P_
24
23
  options: HandlerInterface<P_1, E_1, S_1, U>;
25
24
  patch: HandlerInterface<P_1, E_1, S_1, U>;
26
25
  };
27
- export declare class Hono<E extends Partial<Environment> = Environment, P extends string = '/', S extends Partial<Schema> = Schema> extends Hono_base<E, P, S, Hono<E, P, S>> {
26
+ export declare class Hono<E extends Partial<Environment> = Environment, P extends string = '/', S = unknown> extends Hono_base<E, P, S, Hono<E, P, S>> {
28
27
  readonly router: Router<Handler<P, E, S>>;
29
28
  readonly strict: boolean;
30
29
  private _tempPath;
@@ -34,8 +33,8 @@ export declare class Hono<E extends Partial<Environment> = Environment, P extend
34
33
  private notFoundHandler;
35
34
  private errorHandler;
36
35
  route(path: string, app?: Hono<any>): this;
37
- use<Path extends string = string, Data extends Partial<Schema> = Schema>(...middleware: Handler<Path, E, Data>[]): Hono<E, P, S>;
38
- use<Path extends string = string, Data extends Partial<Schema> = Schema>(arg1: string, ...middleware: Handler<Path, E, Data>[]): Hono<E, P, S>;
36
+ use<Path extends string = string, Data = unknown>(...middleware: Handler<Path, E, Data>[]): Hono<E, P, S>;
37
+ use<Path extends string = string, Data = unknown>(arg1: string, ...middleware: Handler<Path, E, Data>[]): Hono<E, P, S>;
39
38
  on(method: string, path: string, ...handlers: Handler<P, E, S>[]): this;
40
39
  onError(handler: ErrorHandler<E>): this;
41
40
  notFound(handler: NotFoundHandler<E>): this;
@@ -1,3 +1,3 @@
1
1
  import type { ServeStaticOptions } from './serve-static';
2
- declare const module: (options?: ServeStaticOptions) => import("../..").MiddlewareHandler<string, import("../../types").Environment, import("../../validator/schema").Schema>;
2
+ declare const module: (options?: ServeStaticOptions) => import("../..").MiddlewareHandler<string, import("../../types").Environment, unknown>;
3
3
  export { module as serveStatic };
@@ -1,6 +1,5 @@
1
1
  import type { Context } from '../../context';
2
2
  import type { Environment, MiddlewareHandler } from '../../types';
3
- import type { Schema } from '../../validator/schema';
4
3
  import type { ValidateResult } from '../../validator/validator';
5
4
  import { Validator } from '../../validator/validator';
6
5
  declare type ResultSet = {
@@ -9,8 +8,8 @@ declare type ResultSet = {
9
8
  results: ValidateResult[];
10
9
  };
11
10
  declare type Done<P extends string, E extends Partial<Environment> = Environment> = (resultSet: ResultSet, c: Context<P, E>) => Response | void;
12
- declare type ValidationFunction<P extends string, E extends Partial<Environment> = Environment, S extends Schema = Schema> = (v: Validator, c: Context<P, E>) => S;
13
- export declare const validatorMiddleware: <P extends string, E extends Partial<Environment> = Environment, S extends Schema = Schema>(validationFunction: ValidationFunction<P, E, S>, options?: {
11
+ declare type ValidationFunction<P extends string, E extends Partial<Environment> = Environment, S = unknown> = (v: Validator, c: Context<P, E>) => S;
12
+ export declare const validatorMiddleware: <P extends string, E extends Partial<Environment> = Environment, S = unknown>(validationFunction: ValidationFunction<P, E, S>, options?: {
14
13
  done?: Done<P, E> | undefined;
15
14
  } | undefined) => MiddlewareHandler<string, E, S>;
16
15
  export {};
@@ -5,6 +5,7 @@ import { Validator, VBase, VObjectBase } from "../../validator/validator.js";
5
5
  var validatorMiddleware = (validationFunction, options) => {
6
6
  const v = new Validator();
7
7
  const handler = async (c, next) => {
8
+ var _a;
8
9
  const resultSet = {
9
10
  hasError: false,
10
11
  messages: [],
@@ -53,14 +54,16 @@ var validatorMiddleware = (validationFunction, options) => {
53
54
  const dst = data;
54
55
  data = mergeObjects(dst, jsonData);
55
56
  } else {
56
- c.req.valid(keys, value);
57
+ let tmp = data;
58
+ for (let i = 0; i < keys.length - 1; i++) {
59
+ tmp = tmp[_a = keys[i]] || (tmp[_a] = {});
60
+ }
61
+ tmp[keys[keys.length - 1]] = value;
57
62
  }
58
63
  }
59
64
  }
60
65
  if (!resultSet.hasError) {
61
- Object.keys(data).map((key) => {
62
- c.req.valid(key, data[key]);
63
- });
66
+ c.req.valid(data);
64
67
  }
65
68
  if (options && options.done) {
66
69
  const res = options.done(resultSet, c);
package/dist/request.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import type { BodyData } from './utils/body';
2
2
  import type { Cookie } from './utils/cookie';
3
- declare type ValidatedData = Record<string, unknown>;
4
3
  declare global {
5
- interface Request<CfHostMetadata = unknown, ParamKeyType extends string = string, Data extends ValidatedData = ValidatedData> {
4
+ interface Request<CfHostMetadata = unknown, ParamKeyType extends string = string, Data = any> {
6
5
  paramData?: Record<ParamKeyType, string>;
7
6
  param: {
8
7
  (key: ParamKeyType): string;
@@ -23,7 +22,7 @@ declare global {
23
22
  (): Record<string, string>;
24
23
  };
25
24
  cookie: {
26
- (name: string): string;
25
+ (name: string): string | undefined;
27
26
  (): Cookie;
28
27
  };
29
28
  bodyData?: BodyData;
@@ -32,10 +31,9 @@ declare global {
32
31
  json<T>(): Promise<T>;
33
32
  data: Data;
34
33
  valid: {
35
- (key: string | string[], value: unknown): Data;
34
+ (data: Data): Data;
36
35
  (): Data;
37
36
  };
38
37
  }
39
38
  }
40
39
  export declare function extendRequestPrototype(): void;
41
- export {};
package/dist/request.js CHANGED
@@ -91,20 +91,12 @@ function extendRequestPrototype() {
91
91
  }
92
92
  return jsonData;
93
93
  };
94
- Request.prototype.valid = function(keys, value) {
95
- var _a;
94
+ Request.prototype.valid = function(data) {
96
95
  if (!this.data) {
97
96
  this.data = {};
98
97
  }
99
- if (keys !== void 0) {
100
- if (typeof keys === "string") {
101
- keys = [keys];
102
- }
103
- let data = this.data;
104
- for (let i = 0; i < keys.length - 1; i++) {
105
- data = data[_a = keys[i]] || (data[_a] = {});
106
- }
107
- data[keys[keys.length - 1]] = value;
98
+ if (data) {
99
+ this.data = data;
108
100
  }
109
101
  return this.data;
110
102
  };
@@ -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];
package/dist/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { Context } from './context';
2
- import type { Schema } from './validator/schema';
3
2
  export interface ContextVariableMap {
4
3
  }
5
4
  export declare type Bindings = Record<string, any>;
@@ -8,16 +7,16 @@ export declare type Environment = {
8
7
  Bindings: Bindings;
9
8
  Variables: Variables;
10
9
  };
11
- export declare type Handler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (c: Context<P, E, S>, next: Next) => Response | Promise<Response | undefined | void>;
12
- export declare type MiddlewareHandler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (c: Context<P, E, S>, next: Next) => Promise<Response | undefined | void>;
10
+ export declare type Handler<P extends string = string, E extends Partial<Environment> = Environment, S = unknown> = (c: Context<P, E, S>, next: Next) => Response | Promise<Response | undefined | void>;
11
+ export declare type MiddlewareHandler<P extends string = string, E extends Partial<Environment> = Environment, S = unknown> = (c: Context<P, E, S>, next: Next) => Promise<Response | undefined | void>;
13
12
  export declare type NotFoundHandler<E extends Partial<Environment> = Environment> = (c: Context<string, E>) => Response | Promise<Response>;
14
13
  export declare type ErrorHandler<E extends Partial<Environment> = Environment> = (err: Error, c: Context<string, E>) => Response;
15
14
  export declare type Next = () => Promise<void>;
16
15
  declare type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer _Pattern}` ? Name : NameWithPattern;
17
16
  declare type ParamKey<Component> = Component extends `:${infer NameWithPattern}` ? ParamKeyName<NameWithPattern> : never;
18
17
  export declare type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
19
- export interface CustomHandler<P extends string | Partial<Environment> | Schema = string, E = Partial<Environment> | Partial<Schema>, S = Partial<Schema>> {
20
- (c: Context<P extends string ? P : P extends Partial<Environment> ? string : P extends Partial<Schema> ? string : never, P extends Partial<Environment> ? P : P extends Partial<Schema> ? Partial<Environment> : E extends Partial<Environment> ? E extends Partial<Schema> ? Environment : E : E extends Partial<Schema> ? Partial<Environment> : Environment, S extends Schema ? S : P extends Schema ? P : E extends Schema ? E : any>, next: Next): Response | Promise<Response | undefined | void>;
18
+ export interface CustomHandler<P = string, E = Partial<Environment>, S = any> {
19
+ (c: Context<P extends string ? P : string, P extends Partial<Environment> ? P : E extends Partial<Environment> ? E : never, P extends string ? E extends Partial<Environment> ? S : P extends Partial<Environment> ? E : never : P extends Partial<Environment> ? E extends Partial<Environment> ? S : E : P>, next: Next): Response | Promise<Response | undefined | void>;
21
20
  }
22
21
  export interface ExecutionContext {
23
22
  waitUntil(promise: Promise<void>): void;
@@ -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,
@@ -73,9 +73,7 @@ export declare abstract class VBase {
73
73
  asNumber: () => VNumber | VNumberArray;
74
74
  asBoolean: () => VBoolean | VBooleanArray;
75
75
  get(value: string): this;
76
- validate: <R extends Request<unknown, string, {
77
- [x: string]: unknown;
78
- }>>(req: R) => Promise<ValidateResult[]>;
76
+ validate: <R extends Request<unknown, string, any>>(req: R) => Promise<ValidateResult[]>;
79
77
  protected getTypeRuleName(): string;
80
78
  private sanitizeValue;
81
79
  private validateRule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "2.5.9",
3
+ "version": "2.6.0",
4
4
  "description": "Ultrafast web framework for Cloudflare Workers, Deno, and Bun.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",