hono 2.5.10 → 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.
- package/dist/cjs/middleware/validator/middleware.js +7 -4
- package/dist/cjs/request.js +3 -11
- package/dist/context.d.ts +1 -1
- package/dist/hono.d.ts +11 -12
- package/dist/middleware/serve-static/module.d.ts +1 -1
- package/dist/middleware/validator/middleware.d.ts +2 -3
- package/dist/middleware/validator/middleware.js +7 -4
- package/dist/request.d.ts +3 -5
- package/dist/request.js +3 -11
- package/dist/types.d.ts +4 -5
- package/dist/validator/validator.d.ts +1 -3
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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);
|
package/dist/cjs/request.js
CHANGED
|
@@ -113,20 +113,12 @@ function extendRequestPrototype() {
|
|
|
113
113
|
}
|
|
114
114
|
return jsonData;
|
|
115
115
|
};
|
|
116
|
-
Request.prototype.valid = function(
|
|
117
|
-
var _a;
|
|
116
|
+
Request.prototype.valid = function(data) {
|
|
118
117
|
if (!this.data) {
|
|
119
118
|
this.data = {};
|
|
120
119
|
}
|
|
121
|
-
if (
|
|
122
|
-
|
|
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
|
};
|
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
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(...handlers: Handler<string
|
|
8
|
-
<Path extends string, Data
|
|
9
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
38
|
-
use<Path extends string = string, Data
|
|
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,
|
|
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
|
|
13
|
-
export declare const validatorMiddleware: <P extends string, E extends Partial<Environment> = Environment, S
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
(
|
|
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(
|
|
95
|
-
var _a;
|
|
94
|
+
Request.prototype.valid = function(data) {
|
|
96
95
|
if (!this.data) {
|
|
97
96
|
this.data = {};
|
|
98
97
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
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
|
};
|
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
|
|
12
|
-
export declare type MiddlewareHandler<P extends string = string, E extends Partial<Environment> = Environment, S
|
|
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
|
|
20
|
-
(c: Context<P extends string ? P : P extends Partial<Environment> ?
|
|
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;
|
|
@@ -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;
|