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.
- package/dist/cjs/context.js +1 -1
- package/dist/cjs/middleware/validator/middleware.js +1 -1
- package/dist/cjs/utils/types.js +2 -0
- package/dist/cjs/{middleware/validator → validator}/rule.js +0 -0
- package/dist/cjs/{middleware/validator → validator}/sanitizer.js +0 -0
- package/dist/cjs/validator/schema.js +2 -0
- package/dist/cjs/{middleware/validator → validator}/validator.js +4 -1
- package/dist/compose.d.ts +3 -2
- package/dist/context.d.ts +10 -9
- package/dist/context.js +1 -1
- package/dist/hono.d.ts +30 -29
- package/dist/index.d.ts +1 -0
- package/dist/middleware/serve-static/module.d.mts +1 -1
- package/dist/middleware/serve-static/serve-static.d.ts +2 -3
- package/dist/middleware/validator/middleware.d.ts +9 -15
- package/dist/middleware/validator/middleware.js +1 -1
- package/dist/request.d.ts +2 -2
- package/dist/utils/types.d.ts +3 -0
- package/dist/utils/types.js +1 -0
- package/dist/{middleware/validator → validator}/rule.d.ts +0 -0
- package/dist/{middleware/validator → validator}/rule.js +0 -0
- package/dist/{middleware/validator → validator}/sanitizer.d.ts +0 -0
- package/dist/{middleware/validator → validator}/sanitizer.js +0 -0
- package/dist/validator/schema.d.ts +7 -0
- package/dist/validator/schema.js +1 -0
- package/dist/{middleware/validator → validator}/validator.d.ts +5 -3
- package/dist/{middleware/validator → validator}/validator.js +4 -1
- package/package.json +1 -1
package/dist/cjs/context.js
CHANGED
|
@@ -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 =
|
|
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("
|
|
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) => {
|
|
File without changes
|
|
File without changes
|
|
@@ -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("
|
|
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:
|
|
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
|
|
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<
|
|
8
|
-
req: Request<
|
|
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:
|
|
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<
|
|
41
|
-
req: Request<
|
|
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<
|
|
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:
|
|
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
|
|
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 =
|
|
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
|
|
13
|
-
export declare type
|
|
14
|
-
export declare type
|
|
15
|
-
export declare type
|
|
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<
|
|
22
|
-
<Path extends string, Data extends
|
|
23
|
-
(...handlers: Handler<string, E>[]): U;
|
|
24
|
-
<Path extends string, Data extends
|
|
25
|
-
(path:
|
|
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,
|
|
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<
|
|
31
|
+
handler: Handler<P, E, S>;
|
|
31
32
|
}
|
|
32
|
-
declare const Hono_base: new <E_1 extends Partial<Environment> = Environment,
|
|
33
|
-
all: HandlerInterface<
|
|
34
|
-
get: HandlerInterface<
|
|
35
|
-
post: HandlerInterface<
|
|
36
|
-
put: HandlerInterface<
|
|
37
|
-
delete: HandlerInterface<
|
|
38
|
-
head: HandlerInterface<
|
|
39
|
-
options: HandlerInterface<
|
|
40
|
-
patch: HandlerInterface<
|
|
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 = '/',
|
|
43
|
-
readonly router: Router<Handler<
|
|
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,
|
|
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<
|
|
52
|
-
use<Path extends string = string, Data extends
|
|
53
|
-
use<Path extends string = string, Data extends
|
|
54
|
-
onError(handler: ErrorHandler<E>):
|
|
55
|
-
notFound(handler: NotFoundHandler<E>):
|
|
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
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ServeStaticOptions } from './serve-static';
|
|
2
|
-
declare const module: (options?: ServeStaticOptions) =>
|
|
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 {
|
|
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) =>
|
|
9
|
+
export declare const serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
|
-
import type { Environment,
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
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<
|
|
17
|
-
declare type ValidationFunction<
|
|
18
|
-
declare
|
|
19
|
-
|
|
20
|
-
|
|
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 {
|
|
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 =
|
|
32
|
+
json<JSONData = unknown>(): Promise<Partial<JSONData>>;
|
|
33
33
|
data: Data;
|
|
34
34
|
valid: {
|
|
35
|
-
(key: string | string[], value:
|
|
35
|
+
(key: string | string[], value: unknown): Data;
|
|
36
36
|
(): Data;
|
|
37
37
|
};
|
|
38
38
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
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 '
|
|
2
|
-
import type { Schema } from './
|
|
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:
|
|
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 '
|
|
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) {
|