hono 2.3.1 → 2.3.2

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.
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HonoContext = void 0;
4
4
  const cookie_1 = require("./utils/cookie");
5
5
  class HonoContext {
6
- constructor(req, env = undefined, executionCtx = undefined, notFoundHandler = () => new Response()) {
6
+ constructor(req, env = {}, executionCtx = undefined, notFoundHandler = () => new Response()) {
7
7
  this.error = undefined;
8
8
  this._status = 200;
9
9
  this._pretty = false;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatorMiddleware = void 0;
4
4
  const http_status_1 = require("../../utils/http-status");
5
5
  const object_1 = require("../../utils/object");
6
- const validator_1 = require("./validator");
6
+ const validator_1 = require("../../validator/validator");
7
7
  const validatorMiddleware = (validationFunction, options) => {
8
8
  const v = new validator_1.Validator();
9
9
  const handler = async (c, next) => {
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VBooleanArray = exports.VStringArray = exports.VNumberArray = exports.VBoolean = exports.VNumber = exports.VString = exports.VBase = exports.Validator = exports.VArray = exports.VObject = exports.VObjectBase = void 0;
4
- const json_1 = require("../../utils/json");
4
+ const json_1 = require("./../utils/json");
5
5
  const rule_1 = require("./rule");
6
6
  const sanitizer_1 = require("./sanitizer");
7
7
  class VObjectBase {
@@ -179,6 +179,7 @@ class VBase {
179
179
  const typeResult = this.validateRule(typeRule, value);
180
180
  typeResult.jsonData || (typeResult.jsonData = jsonData);
181
181
  results.unshift(typeResult);
182
+ this.rules.unshift(typeRule);
182
183
  }
183
184
  return results;
184
185
  };
@@ -215,6 +216,8 @@ class VBase {
215
216
  return true;
216
217
  };
217
218
  this.validateValue = (func, value) => {
219
+ if (this._optional && typeof value === 'undefined')
220
+ return true;
218
221
  if (Array.isArray(value)) {
219
222
  // Sanitize
220
223
  for (const sanitizer of this.sanitizers) {
package/dist/compose.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { Environment, NotFoundHandler, ErrorHandler } from './hono';
2
+ import type { Schema } from './validator/schema';
2
3
  interface ComposeContext {
3
4
  finalized: boolean;
4
- res: any;
5
+ res: unknown;
5
6
  }
6
- export declare const compose: <C extends ComposeContext, E extends Partial<Environment> = Environment>(middleware: Function[], onNotFound?: NotFoundHandler<E> | undefined, onError?: ErrorHandler<E> | undefined) => (context: C, next?: Function) => C | Promise<C>;
7
+ export declare const compose: <C extends ComposeContext, P extends string = string, E extends Partial<Environment> = Environment, D extends Partial<Schema> = Schema>(middleware: Function[], onNotFound?: NotFoundHandler<P, E, D> | undefined, onError?: ErrorHandler<P, E, D> | undefined) => (context: C, next?: Function) => C | Promise<C>;
7
8
  export {};
package/dist/context.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  /// <reference types="@cloudflare/workers-types" />
2
- import type { Environment, NotFoundHandler, ContextVariableMap, ValidatedData } from './hono';
2
+ import type { Environment, NotFoundHandler, ContextVariableMap } from './hono';
3
3
  import type { CookieOptions } from './utils/cookie';
4
4
  import type { StatusCode } from './utils/http-status';
5
+ import type { Schema, SchemaToProp } from './validator/schema';
5
6
  declare type Headers = Record<string, string | string[]>;
6
7
  export declare type Data = string | ArrayBuffer | ReadableStream;
7
- export interface Context<RequestParamKeyType extends string = string, E extends Partial<Environment> = any, D extends ValidatedData = ValidatedData> {
8
- req: Request<RequestParamKeyType, D>;
8
+ export interface Context<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> {
9
+ req: Request<P, SchemaToProp<S>>;
9
10
  env: E['Bindings'];
10
11
  event: FetchEvent;
11
12
  executionCtx: ExecutionContext;
@@ -20,7 +21,7 @@ export interface Context<RequestParamKeyType extends string = string, E extends
20
21
  set: {
21
22
  <Key extends keyof ContextVariableMap>(key: Key, value: ContextVariableMap[Key]): void;
22
23
  <Key extends keyof E['Variables']>(key: Key, value: E['Variables'][Key]): void;
23
- (key: string, value: any): void;
24
+ (key: string, value: unknown): void;
24
25
  };
25
26
  get: {
26
27
  <Key extends keyof ContextVariableMap>(key: Key): ContextVariableMap[Key];
@@ -37,8 +38,8 @@ export interface Context<RequestParamKeyType extends string = string, E extends
37
38
  cookie: (name: string, value: string, options?: CookieOptions) => void;
38
39
  notFound: () => Response | Promise<Response>;
39
40
  }
40
- export declare class HonoContext<RequestParamKeyType extends string = string, E extends Partial<Environment> = Environment, D extends ValidatedData = ValidatedData> implements Context<RequestParamKeyType, E, D> {
41
- req: Request<RequestParamKeyType, D>;
41
+ export declare class HonoContext<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> implements Context<P, E, S> {
42
+ req: Request<P, SchemaToProp<S>>;
42
43
  env: E['Bindings'];
43
44
  finalized: boolean;
44
45
  error: Error | undefined;
@@ -50,7 +51,7 @@ export declare class HonoContext<RequestParamKeyType extends string = string, E
50
51
  private _headers;
51
52
  private _res;
52
53
  private notFoundHandler;
53
- constructor(req: Request<RequestParamKeyType>, env?: E['Bindings'] | undefined, executionCtx?: FetchEvent | ExecutionContext | undefined, notFoundHandler?: NotFoundHandler<E>);
54
+ constructor(req: Request<P>, env?: E['Bindings'], executionCtx?: FetchEvent | ExecutionContext | undefined, notFoundHandler?: NotFoundHandler<P, E, S>);
54
55
  get event(): FetchEvent;
55
56
  get executionCtx(): ExecutionContext;
56
57
  get res(): Response;
@@ -61,10 +62,10 @@ export declare class HonoContext<RequestParamKeyType extends string = string, E
61
62
  status(status: StatusCode): void;
62
63
  set<Key extends keyof ContextVariableMap>(key: Key, value: ContextVariableMap[Key]): void;
63
64
  set<Key extends keyof E['Variables']>(key: Key, value: E['Variables'][Key]): void;
64
- set(key: string, value: any): void;
65
+ set(key: string, value: unknown): void;
65
66
  get<Key extends keyof ContextVariableMap>(key: Key): ContextVariableMap[Key];
66
67
  get<Key extends keyof E['Variables']>(key: Key): E['Variables'][Key];
67
- get<T = any>(key: string): T;
68
+ get<T>(key: string): T;
68
69
  pretty(prettyJSON: boolean, space?: number): void;
69
70
  newResponse(data: Data | null, status: StatusCode, headers?: Headers): Response;
70
71
  private _finalizeHeaders;
package/dist/context.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { serialize } from './utils/cookie';
2
2
  export class HonoContext {
3
- constructor(req, env = undefined, executionCtx = undefined, notFoundHandler = () => new Response()) {
3
+ constructor(req, env = {}, executionCtx = undefined, notFoundHandler = () => new Response()) {
4
4
  this.error = undefined;
5
5
  this._status = 200;
6
6
  this._pretty = false;
package/dist/hono.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="@cloudflare/workers-types" />
2
2
  import type { Context } from './context';
3
3
  import type { Router } from './router';
4
+ import type { Schema } from './validator/schema';
4
5
  export interface ContextVariableMap {
5
6
  }
6
7
  export declare type Bindings = Record<string, any>;
@@ -9,50 +10,50 @@ export declare type Environment = {
9
10
  Bindings: Bindings;
10
11
  Variables: Variables;
11
12
  };
12
- export declare type ValidatedData = Record<string, any>;
13
- export declare type Handler<RequestParamKeyType extends string = string, E extends Partial<Environment> = Environment, D extends ValidatedData = ValidatedData> = (c: Context<RequestParamKeyType, E, D>, next: Next) => Response | Promise<Response> | Promise<void> | Promise<Response | undefined | void>;
14
- export declare type MiddlewareHandler = <E extends Partial<Environment> = Environment>(c: Context<string, E>, next: Next) => Promise<void> | Promise<Response | undefined>;
15
- export declare type NotFoundHandler<E extends Partial<Environment> = Environment> = (c: Context<string, E>) => Response | Promise<Response>;
16
- export declare type ErrorHandler<E extends Partial<Environment> = Environment> = (err: Error, c: Context<string, E>) => Response;
13
+ 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>;
14
+ 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>;
15
+ export declare type NotFoundHandler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (c: Context<P, E, S>) => Response | Promise<Response>;
16
+ export declare type ErrorHandler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (err: Error, c: Context<P, E, S>) => Response;
17
17
  export declare type Next = () => Promise<void>;
18
18
  declare type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer _Pattern}` ? Name : NameWithPattern;
19
19
  declare type ParamKey<Component> = Component extends `:${infer NameWithPattern}` ? ParamKeyName<NameWithPattern> : never;
20
20
  declare type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
21
- interface HandlerInterface<T extends string, E extends Partial<Environment>, U = Hono<E, T>> {
22
- <Path extends string, Data extends ValidatedData>(...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): U;
23
- (...handlers: Handler<string, E>[]): U;
24
- <Path extends string, Data extends ValidatedData>(path: Path, ...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): U;
25
- (path: string, ...handlers: Handler<string, E>[]): U;
21
+ interface HandlerInterface<P extends string, E extends Partial<Environment>, S extends Partial<Schema>, U = Hono<E, P, S>> {
22
+ <Path extends string, Data extends Schema>(...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): U;
23
+ (...handlers: Handler<string, E, S>[]): U;
24
+ <Path extends string, Data extends Partial<Schema> = Schema>(path: Path, ...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): U;
25
+ <Path extends string, Data extends Schema>(path: Path, ...handlers: Handler<string, E, Data>[]): U;
26
+ (path: string, ...handlers: Handler<string, E, S>[]): U;
26
27
  }
27
- interface Route<E extends Partial<Environment> = Environment, D extends ValidatedData = ValidatedData> {
28
+ interface Route<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> {
28
29
  path: string;
29
30
  method: string;
30
- handler: Handler<string, E, D>;
31
+ handler: Handler<P, E, S>;
31
32
  }
32
- declare const Hono_base: new <E_1 extends Partial<Environment> = Environment, T extends string = string, U = Hono<E_1, T, ValidatedData>>() => {
33
- all: HandlerInterface<T, E_1, U>;
34
- get: HandlerInterface<T, E_1, U>;
35
- post: HandlerInterface<T, E_1, U>;
36
- put: HandlerInterface<T, E_1, U>;
37
- delete: HandlerInterface<T, E_1, U>;
38
- head: HandlerInterface<T, E_1, U>;
39
- options: HandlerInterface<T, E_1, U>;
40
- patch: HandlerInterface<T, E_1, U>;
33
+ 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>>() => {
34
+ all: HandlerInterface<P_1, E_1, S_1, U>;
35
+ get: HandlerInterface<P_1, E_1, S_1, U>;
36
+ post: HandlerInterface<P_1, E_1, S_1, U>;
37
+ put: HandlerInterface<P_1, E_1, S_1, U>;
38
+ delete: HandlerInterface<P_1, E_1, S_1, U>;
39
+ head: HandlerInterface<P_1, E_1, S_1, U>;
40
+ options: HandlerInterface<P_1, E_1, S_1, U>;
41
+ patch: HandlerInterface<P_1, E_1, S_1, U>;
41
42
  };
42
- export declare class Hono<E extends Partial<Environment> = Environment, P extends string = '/', D extends ValidatedData = ValidatedData> extends Hono_base<E, P, Hono<E, P, D>> {
43
- readonly router: Router<Handler<string, E, D>>;
43
+ 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>> {
44
+ readonly router: Router<Handler<P, E, S>>;
44
45
  readonly strict: boolean;
45
46
  private _tempPath;
46
47
  private path;
47
- routes: Route<E, D>[];
48
+ routes: Route<P, E, S>[];
48
49
  constructor(init?: Partial<Pick<Hono, 'router' | 'strict'>>);
49
50
  private notFoundHandler;
50
51
  private errorHandler;
51
- route(path: string, app?: Hono<any>): Hono<E, P, D>;
52
- use<Path extends string = string, Data extends ValidatedData = D>(...middleware: Handler<Path, E, Data>[]): Hono<E, Path, Data>;
53
- use<Path extends string = string, Data extends ValidatedData = D>(arg1: string, ...middleware: Handler<Path, E, Data>[]): Hono<E, Path, D>;
54
- onError(handler: ErrorHandler<E>): Hono<E, P, D>;
55
- notFound(handler: NotFoundHandler<E>): Hono<E, P, D>;
52
+ route(path: string, app?: Hono<E, P, S>): this;
53
+ use<Path extends string = string, Data extends Partial<Schema> = Schema>(...middleware: Handler<Path, E, Data>[]): Hono<E, Path, S>;
54
+ use<Path extends string = string, Data extends Partial<Schema> = Schema>(arg1: string, ...middleware: Handler<Path, E, Data>[]): Hono<E, Path, S>;
55
+ onError(handler: ErrorHandler<P, E, S>): this;
56
+ notFound(handler: NotFoundHandler<P, E, S>): this;
56
57
  private addRoute;
57
58
  private matchRoute;
58
59
  private handleError;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import { Hono } from './hono';
3
3
  export type { Handler, Next, ContextVariableMap } from './hono';
4
4
  export type { Context } from './context';
5
+ export type { Validator } from './validator/validator';
5
6
  declare module './hono' {
6
7
  interface Hono {
7
8
  fire(): void;
@@ -1,3 +1,3 @@
1
1
  import type { ServeStaticOptions } from './serve-static';
2
- declare const module: (options?: ServeStaticOptions) => (c: import("../..").Context<string, any, import("../../hono").ValidatedData>, next: import("../..").Next) => Promise<Response | undefined>;
2
+ declare const module: (options?: ServeStaticOptions) => import("../../hono").MiddlewareHandler<string, import("../../hono").Environment, import("../../validator/schema").Schema>;
3
3
  export { module as serveStatic };
@@ -1,10 +1,9 @@
1
1
  /// <reference types="@cloudflare/workers-types" />
2
- import type { Context } from '../../context';
3
- import type { Next } from '../../hono';
2
+ import type { MiddlewareHandler } from '../../hono';
4
3
  export declare type ServeStaticOptions = {
5
4
  root?: string;
6
5
  path?: string;
7
6
  manifest?: object | string;
8
7
  namespace?: KVNamespace;
9
8
  };
10
- export declare const serveStatic: (options?: ServeStaticOptions) => (c: Context, next: Next) => Promise<Response | undefined>;
9
+ export declare const serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
@@ -1,22 +1,16 @@
1
1
  import type { Context } from '../../context';
2
- import type { Environment, Next, ValidatedData } from '../../hono';
3
- import { Validator, VObjectBase } from './validator';
4
- import type { VString, VNumber, VBoolean, VObject, VNumberArray, VStringArray, VBooleanArray, ValidateResult, VArray } from './validator';
5
- export declare type Schema = {
6
- [key: string]: VString | VNumber | VBoolean | VStringArray | VNumberArray | VBooleanArray | Schema | VObject<Schema> | VArray<Schema>;
7
- };
8
- declare type SchemaToProp<T> = {
9
- [K in keyof T]: T[K] extends VNumberArray ? number[] : T[K] extends VBooleanArray ? boolean[] : T[K] extends VStringArray ? string[] : T[K] extends VNumber ? number : T[K] extends VBoolean ? boolean : T[K] extends VString ? string : T[K] extends VObjectBase<Schema> ? T[K]['container'] extends VNumber ? number : T[K]['container'] extends VString ? string : T[K]['container'] extends VBoolean ? boolean : T[K] extends VArray<Schema> ? SchemaToProp<ReadonlyArray<T[K]['container']>> : T[K] extends VObject<Schema> ? SchemaToProp<T[K]['container']> : T[K] extends Schema ? SchemaToProp<T[K]> : never : SchemaToProp<T[K]>;
10
- };
2
+ import type { Environment, MiddlewareHandler } from '../../hono';
3
+ import type { Schema } from '../../validator/schema';
4
+ import type { ValidateResult } from '../../validator/validator';
5
+ import { Validator } from '../../validator/validator';
11
6
  declare type ResultSet = {
12
7
  hasError: boolean;
13
8
  messages: string[];
14
9
  results: ValidateResult[];
15
10
  };
16
- declare type Done<Env extends Partial<Environment>> = (resultSet: ResultSet, context: Context<string, Env>) => Response | void;
17
- declare type ValidationFunction<T, Env extends Partial<Environment>> = (v: Validator, c: Context<string, Env>) => T;
18
- declare type MiddlewareHandler<Data extends ValidatedData = ValidatedData, Env extends Partial<Environment> = Environment> = (c: Context<string, Env, Data>, next: Next) => Promise<void> | Promise<Response | undefined>;
19
- export declare const validatorMiddleware: <T extends Schema, Env extends Partial<Environment>>(validationFunction: ValidationFunction<T, Env>, options?: {
20
- done?: Done<Env> | undefined;
21
- } | undefined) => MiddlewareHandler<SchemaToProp<T>, Env>;
11
+ 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?: {
14
+ done?: Done<P, E> | undefined;
15
+ } | undefined) => MiddlewareHandler<string, E, S>;
22
16
  export {};
@@ -1,6 +1,6 @@
1
1
  import { getStatusText } from '../../utils/http-status';
2
2
  import { mergeObjects } from '../../utils/object';
3
- import { VBase, Validator, VObjectBase } from './validator';
3
+ import { Validator, VBase, VObjectBase } from '../../validator/validator';
4
4
  export const validatorMiddleware = (validationFunction, options) => {
5
5
  const v = new Validator();
6
6
  const handler = async (c, next) => {
package/dist/request.d.ts CHANGED
@@ -29,10 +29,10 @@ declare global {
29
29
  bodyData?: BodyData;
30
30
  parseBody<BodyType extends BodyData>(): Promise<BodyType>;
31
31
  jsonData?: any;
32
- json<JSONData = any>(): Promise<JSONData>;
32
+ json<JSONData = unknown>(): Promise<Partial<JSONData>>;
33
33
  data: Data;
34
34
  valid: {
35
- (key: string | string[], value: any): Data;
35
+ (key: string | string[], value: unknown): Data;
36
36
  (): Data;
37
37
  };
38
38
  }
@@ -0,0 +1,3 @@
1
+ export declare type Expect<T extends true> = T;
2
+ export declare type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
3
+ export declare type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1,7 @@
1
+ import type { VString, VNumber, VBoolean, VObject, VNumberArray, VStringArray, VBooleanArray, VArray, VObjectBase } from './validator';
2
+ export declare type Schema = {
3
+ [key: string]: VString | VNumber | VBoolean | VStringArray | VNumberArray | VBooleanArray | Schema | VObject<Schema> | VArray<Schema>;
4
+ };
5
+ export declare type SchemaToProp<T> = {
6
+ [K in keyof T]: T[K] extends VNumberArray ? number[] : T[K] extends VBooleanArray ? boolean[] : T[K] extends VStringArray ? string[] : T[K] extends VNumber ? number : T[K] extends VBoolean ? boolean : T[K] extends VString ? string : T[K] extends VObjectBase<Schema> ? T[K]['container'] extends VNumber ? number : T[K]['container'] extends VString ? string : T[K]['container'] extends VBoolean ? boolean : T[K] extends VArray<Schema> ? SchemaToProp<ReadonlyArray<T[K]['container']>> : T[K] extends VObject<Schema> ? SchemaToProp<T[K]['container']> : T[K] extends Schema ? SchemaToProp<T[K]> : never : SchemaToProp<T[K]>;
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
- import type { JSONObject, JSONPrimitive, JSONArray } from '../../utils/json';
2
- import type { Schema } from './middleware';
1
+ import type { JSONObject, JSONPrimitive, JSONArray } from './../utils/json';
2
+ import type { Schema } from './schema';
3
3
  declare type Target = 'query' | 'header' | 'body' | 'json';
4
4
  declare type Type = JSONPrimitive | JSONObject | JSONArray | File;
5
5
  declare type RuleFunc = (value: Type) => boolean;
@@ -71,7 +71,9 @@ export declare abstract class VBase {
71
71
  asNumber: () => VNumber | VNumberArray;
72
72
  asBoolean: () => VBoolean | VBooleanArray;
73
73
  get(value: string): this;
74
- validate: (req: Request) => Promise<ValidateResult[]>;
74
+ validate: <R extends Request<string, {
75
+ [x: string]: any;
76
+ }>>(req: R) => Promise<ValidateResult[]>;
75
77
  protected getTypeRuleName(): string;
76
78
  private validateRule;
77
79
  private validateType;
@@ -1,4 +1,4 @@
1
- import { JSONPathCopy } from '../../utils/json';
1
+ import { JSONPathCopy } from './../utils/json';
2
2
  import { rule } from './rule';
3
3
  import { sanitizer } from './sanitizer';
4
4
  export class VObjectBase {
@@ -172,6 +172,7 @@ export class VBase {
172
172
  const typeResult = this.validateRule(typeRule, value);
173
173
  typeResult.jsonData || (typeResult.jsonData = jsonData);
174
174
  results.unshift(typeResult);
175
+ this.rules.unshift(typeRule);
175
176
  }
176
177
  return results;
177
178
  };
@@ -208,6 +209,8 @@ export class VBase {
208
209
  return true;
209
210
  };
210
211
  this.validateValue = (func, value) => {
212
+ if (this._optional && typeof value === 'undefined')
213
+ return true;
211
214
  if (Array.isArray(value)) {
212
215
  // Sanitize
213
216
  for (const sanitizer of this.sanitizers) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "Ultrafast web framework for Cloudflare Workers.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",