hono 2.6.0 → 2.6.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 +6 -1
- package/dist/cjs/hono.js +1 -1
- package/dist/cjs/request.js +5 -2
- package/dist/cjs/validator/validator.js +21 -12
- package/dist/context.js +6 -1
- package/dist/hono.d.ts +2 -2
- package/dist/hono.js +1 -1
- package/dist/middleware/serve-static/module.d.ts +1 -1
- package/dist/request.js +5 -2
- package/dist/types.d.ts +2 -2
- package/dist/validator/schema.d.ts +7 -4
- package/dist/validator/validator.d.ts +8 -2
- package/dist/validator/validator.js +21 -12
- package/package.json +1 -1
package/dist/cjs/context.js
CHANGED
|
@@ -131,7 +131,12 @@ class Context {
|
|
|
131
131
|
body(data, status = this._status, headers = {}) {
|
|
132
132
|
return this.newResponse(data, status, headers);
|
|
133
133
|
}
|
|
134
|
-
text(text, status
|
|
134
|
+
text(text, status, headers) {
|
|
135
|
+
if (!headers && !status && !this._res && !this._headers) {
|
|
136
|
+
return new Response(text);
|
|
137
|
+
}
|
|
138
|
+
status || (status = this._status);
|
|
139
|
+
headers || (headers = {});
|
|
135
140
|
headers["content-type"] = "text/plain; charset=UTF-8";
|
|
136
141
|
return this.newResponse(text, status, headers);
|
|
137
142
|
}
|
package/dist/cjs/hono.js
CHANGED
|
@@ -48,7 +48,7 @@ class Hono extends defineDynamicClass() {
|
|
|
48
48
|
return c.text("404 Not Found", 404);
|
|
49
49
|
};
|
|
50
50
|
this.errorHandler = (err, c) => {
|
|
51
|
-
console.trace(err
|
|
51
|
+
console.trace(err);
|
|
52
52
|
const message = "Internal Server Error";
|
|
53
53
|
return c.text(message, 500);
|
|
54
54
|
};
|
package/dist/cjs/request.js
CHANGED
|
@@ -31,11 +31,14 @@ function extendRequestPrototype() {
|
|
|
31
31
|
Request.prototype.param = function(key) {
|
|
32
32
|
if (this.paramData) {
|
|
33
33
|
if (key) {
|
|
34
|
-
|
|
34
|
+
const param = this.paramData[key];
|
|
35
|
+
return param ? decodeURIComponent(param) : void 0;
|
|
35
36
|
} else {
|
|
36
37
|
const decoded = {};
|
|
37
38
|
for (const [key2, value] of Object.entries(this.paramData)) {
|
|
38
|
-
|
|
39
|
+
if (value) {
|
|
40
|
+
decoded[key2] = decodeURIComponent(value);
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
return decoded;
|
|
41
44
|
}
|
|
@@ -139,16 +139,10 @@ class VBase {
|
|
|
139
139
|
});
|
|
140
140
|
};
|
|
141
141
|
this.asNumber = () => {
|
|
142
|
-
|
|
143
|
-
if (this.isArray)
|
|
144
|
-
return newVNumber.asArray();
|
|
145
|
-
return newVNumber;
|
|
142
|
+
return new VNumber({ ...this, type: "number" });
|
|
146
143
|
};
|
|
147
144
|
this.asBoolean = () => {
|
|
148
|
-
|
|
149
|
-
if (this.isArray)
|
|
150
|
-
return newVBoolean.asArray();
|
|
151
|
-
return newVBoolean;
|
|
145
|
+
return new VBoolean({ ...this, type: "boolean" });
|
|
152
146
|
};
|
|
153
147
|
this.validate = async (req) => {
|
|
154
148
|
let value = void 0;
|
|
@@ -201,10 +195,7 @@ class VBase {
|
|
|
201
195
|
}
|
|
202
196
|
return results;
|
|
203
197
|
};
|
|
204
|
-
this.sanitizeValue = (value) => this.sanitizers.reduce(
|
|
205
|
-
(acc, sanitizer2) => sanitizer2(acc),
|
|
206
|
-
value
|
|
207
|
-
);
|
|
198
|
+
this.sanitizeValue = (value) => this.sanitizers.reduce((acc, sanitizer2) => sanitizer2(acc), value);
|
|
208
199
|
this.validateType = (value) => {
|
|
209
200
|
if (this.isArray) {
|
|
210
201
|
if (!Array.isArray(value)) {
|
|
@@ -398,6 +389,12 @@ class VBoolean extends VBase {
|
|
|
398
389
|
class VNumberArray extends VNumber {
|
|
399
390
|
constructor(options) {
|
|
400
391
|
super(options);
|
|
392
|
+
this.asNumber = () => {
|
|
393
|
+
return new VNumberArray({ ...this, type: "number" });
|
|
394
|
+
};
|
|
395
|
+
this.asBoolean = () => {
|
|
396
|
+
return new VBooleanArray({ ...this, type: "boolean" });
|
|
397
|
+
};
|
|
401
398
|
this.isArray = true;
|
|
402
399
|
this.rules[0].name = this.getTypeRuleName();
|
|
403
400
|
}
|
|
@@ -405,6 +402,12 @@ class VNumberArray extends VNumber {
|
|
|
405
402
|
class VStringArray extends VString {
|
|
406
403
|
constructor(options) {
|
|
407
404
|
super(options);
|
|
405
|
+
this.asNumber = () => {
|
|
406
|
+
return new VNumberArray({ ...this, type: "number" });
|
|
407
|
+
};
|
|
408
|
+
this.asBoolean = () => {
|
|
409
|
+
return new VBooleanArray({ ...this, type: "boolean" });
|
|
410
|
+
};
|
|
408
411
|
this.isArray = true;
|
|
409
412
|
this.rules[0].name = this.getTypeRuleName();
|
|
410
413
|
}
|
|
@@ -412,6 +415,12 @@ class VStringArray extends VString {
|
|
|
412
415
|
class VBooleanArray extends VBoolean {
|
|
413
416
|
constructor(options) {
|
|
414
417
|
super(options);
|
|
418
|
+
this.asNumber = () => {
|
|
419
|
+
return new VNumberArray({ ...this, type: "number" });
|
|
420
|
+
};
|
|
421
|
+
this.asBoolean = () => {
|
|
422
|
+
return new VBooleanArray({ ...this, type: "boolean" });
|
|
423
|
+
};
|
|
415
424
|
this.isArray = true;
|
|
416
425
|
this.rules[0].name = this.getTypeRuleName();
|
|
417
426
|
}
|
package/dist/context.js
CHANGED
|
@@ -109,7 +109,12 @@ var Context = class {
|
|
|
109
109
|
body(data, status = this._status, headers = {}) {
|
|
110
110
|
return this.newResponse(data, status, headers);
|
|
111
111
|
}
|
|
112
|
-
text(text, status
|
|
112
|
+
text(text, status, headers) {
|
|
113
|
+
if (!headers && !status && !this._res && !this._headers) {
|
|
114
|
+
return new Response(text);
|
|
115
|
+
}
|
|
116
|
+
status || (status = this._status);
|
|
117
|
+
headers || (headers = {});
|
|
113
118
|
headers["content-type"] = "text/plain; charset=UTF-8";
|
|
114
119
|
return this.newResponse(text, status, headers);
|
|
115
120
|
}
|
package/dist/hono.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ interface Route<P extends string = string, E extends Partial<Environment> = Envi
|
|
|
14
14
|
handler: Handler<P, E, S>;
|
|
15
15
|
}
|
|
16
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>>() => {
|
|
17
|
-
get: HandlerInterface<P_1, E_1, S_1, U>;
|
|
18
17
|
all: HandlerInterface<P_1, E_1, S_1, U>;
|
|
18
|
+
get: HandlerInterface<P_1, E_1, S_1, U>;
|
|
19
19
|
post: HandlerInterface<P_1, E_1, S_1, U>;
|
|
20
20
|
put: HandlerInterface<P_1, E_1, S_1, U>;
|
|
21
21
|
delete: HandlerInterface<P_1, E_1, S_1, U>;
|
|
@@ -23,7 +23,7 @@ declare const Hono_base: new <E_1 extends Partial<Environment> = Environment, P_
|
|
|
23
23
|
options: HandlerInterface<P_1, E_1, S_1, U>;
|
|
24
24
|
patch: HandlerInterface<P_1, E_1, S_1, U>;
|
|
25
25
|
};
|
|
26
|
-
export declare class Hono<E extends Partial<Environment> = Environment, P extends string =
|
|
26
|
+
export declare class Hono<E extends Partial<Environment> = Environment, P extends string = string, S = unknown> extends Hono_base<E, P, S, Hono<E, P, S>> {
|
|
27
27
|
readonly router: Router<Handler<P, E, S>>;
|
|
28
28
|
readonly strict: boolean;
|
|
29
29
|
private _tempPath;
|
package/dist/hono.js
CHANGED
|
@@ -26,7 +26,7 @@ var Hono = class extends defineDynamicClass() {
|
|
|
26
26
|
return c.text("404 Not Found", 404);
|
|
27
27
|
};
|
|
28
28
|
this.errorHandler = (err, c) => {
|
|
29
|
-
console.trace(err
|
|
29
|
+
console.trace(err);
|
|
30
30
|
const message = "Internal Server Error";
|
|
31
31
|
return c.text(message, 500);
|
|
32
32
|
};
|
|
@@ -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, any>;
|
|
3
3
|
export { module as serveStatic };
|
package/dist/request.js
CHANGED
|
@@ -9,11 +9,14 @@ function extendRequestPrototype() {
|
|
|
9
9
|
Request.prototype.param = function(key) {
|
|
10
10
|
if (this.paramData) {
|
|
11
11
|
if (key) {
|
|
12
|
-
|
|
12
|
+
const param = this.paramData[key];
|
|
13
|
+
return param ? decodeURIComponent(param) : void 0;
|
|
13
14
|
} else {
|
|
14
15
|
const decoded = {};
|
|
15
16
|
for (const [key2, value] of Object.entries(this.paramData)) {
|
|
16
|
-
|
|
17
|
+
if (value) {
|
|
18
|
+
decoded[key2] = decodeURIComponent(value);
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
21
|
return decoded;
|
|
19
22
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare type Environment = {
|
|
|
7
7
|
Bindings: Bindings;
|
|
8
8
|
Variables: Variables;
|
|
9
9
|
};
|
|
10
|
-
export declare type Handler<P extends string = string, E extends Partial<Environment> = Environment, S =
|
|
11
|
-
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 = any> = (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 = any> = (c: Context<P, E, S>, next: Next) => Promise<Response | undefined | void>;
|
|
12
12
|
export declare type NotFoundHandler<E extends Partial<Environment> = Environment> = (c: Context<string, E>) => Response | Promise<Response>;
|
|
13
13
|
export declare type ErrorHandler<E extends Partial<Environment> = Environment> = (err: Error, c: Context<string, E>) => Response;
|
|
14
14
|
export declare type Next = () => Promise<void>;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type { VString, VNumber, VBoolean, VObject, VNumberArray, VStringArray, VBooleanArray,
|
|
1
|
+
import type { VString, VNumber, VBoolean, VObject, VArray, VNumberArray, VStringArray, VBooleanArray, VBase } from './validator';
|
|
2
2
|
export declare type Schema = {
|
|
3
|
-
[key: string]: VString | VNumber | VBoolean |
|
|
3
|
+
[key: string]: VString | VNumber | VBoolean | Schema | VObject<Schema> | VArray<Schema>;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
declare type Primitive<T> = T extends VNumberArray ? number[] : T extends VNumber ? number : T extends VStringArray ? string[] : T extends VString ? string : T extends VBooleanArray ? boolean[] : T extends VBoolean ? boolean : T;
|
|
6
|
+
declare type P<T> = T extends VArray<infer R> ? P<R>[] : T extends VObject<infer R> ? P<R> : {
|
|
7
|
+
[K in keyof T]: T[K] extends VBase ? Primitive<T[K]> : T[K] extends VArray<infer R> ? P<R>[] : T[K] extends VObject<infer R> ? P<R> : T[K] extends Schema ? P<T[K]> : never;
|
|
7
8
|
};
|
|
9
|
+
export declare type SchemaToProp<T> = P<T>;
|
|
10
|
+
export {};
|
|
@@ -70,8 +70,8 @@ export declare abstract class VBase {
|
|
|
70
70
|
isRequired: () => this;
|
|
71
71
|
isOptional: () => this;
|
|
72
72
|
isEqual: (comparison: unknown) => this;
|
|
73
|
-
asNumber: () => VNumber
|
|
74
|
-
asBoolean: () => VBoolean
|
|
73
|
+
asNumber: () => VNumber;
|
|
74
|
+
asBoolean: () => VBoolean;
|
|
75
75
|
get(value: string): this;
|
|
76
76
|
validate: <R extends Request<unknown, string, any>>(req: R) => Promise<ValidateResult[]>;
|
|
77
77
|
protected getTypeRuleName(): string;
|
|
@@ -116,13 +116,19 @@ export declare class VBoolean extends VBase {
|
|
|
116
116
|
export declare class VNumberArray extends VNumber {
|
|
117
117
|
isArray: true;
|
|
118
118
|
constructor(options: VOptions);
|
|
119
|
+
asNumber: () => VNumberArray;
|
|
120
|
+
asBoolean: () => VBooleanArray;
|
|
119
121
|
}
|
|
120
122
|
export declare class VStringArray extends VString {
|
|
121
123
|
isArray: true;
|
|
122
124
|
constructor(options: VOptions);
|
|
125
|
+
asNumber: () => VNumberArray;
|
|
126
|
+
asBoolean: () => VBooleanArray;
|
|
123
127
|
}
|
|
124
128
|
export declare class VBooleanArray extends VBoolean {
|
|
125
129
|
isArray: true;
|
|
126
130
|
constructor(options: VOptions);
|
|
131
|
+
asNumber: () => VNumberArray;
|
|
132
|
+
asBoolean: () => VBooleanArray;
|
|
127
133
|
}
|
|
128
134
|
export {};
|
|
@@ -107,16 +107,10 @@ var VBase = class {
|
|
|
107
107
|
});
|
|
108
108
|
};
|
|
109
109
|
this.asNumber = () => {
|
|
110
|
-
|
|
111
|
-
if (this.isArray)
|
|
112
|
-
return newVNumber.asArray();
|
|
113
|
-
return newVNumber;
|
|
110
|
+
return new VNumber({ ...this, type: "number" });
|
|
114
111
|
};
|
|
115
112
|
this.asBoolean = () => {
|
|
116
|
-
|
|
117
|
-
if (this.isArray)
|
|
118
|
-
return newVBoolean.asArray();
|
|
119
|
-
return newVBoolean;
|
|
113
|
+
return new VBoolean({ ...this, type: "boolean" });
|
|
120
114
|
};
|
|
121
115
|
this.validate = async (req) => {
|
|
122
116
|
let value = void 0;
|
|
@@ -169,10 +163,7 @@ var VBase = class {
|
|
|
169
163
|
}
|
|
170
164
|
return results;
|
|
171
165
|
};
|
|
172
|
-
this.sanitizeValue = (value) => this.sanitizers.reduce(
|
|
173
|
-
(acc, sanitizer2) => sanitizer2(acc),
|
|
174
|
-
value
|
|
175
|
-
);
|
|
166
|
+
this.sanitizeValue = (value) => this.sanitizers.reduce((acc, sanitizer2) => sanitizer2(acc), value);
|
|
176
167
|
this.validateType = (value) => {
|
|
177
168
|
if (this.isArray) {
|
|
178
169
|
if (!Array.isArray(value)) {
|
|
@@ -366,6 +357,12 @@ var VBoolean = class extends VBase {
|
|
|
366
357
|
var VNumberArray = class extends VNumber {
|
|
367
358
|
constructor(options) {
|
|
368
359
|
super(options);
|
|
360
|
+
this.asNumber = () => {
|
|
361
|
+
return new VNumberArray({ ...this, type: "number" });
|
|
362
|
+
};
|
|
363
|
+
this.asBoolean = () => {
|
|
364
|
+
return new VBooleanArray({ ...this, type: "boolean" });
|
|
365
|
+
};
|
|
369
366
|
this.isArray = true;
|
|
370
367
|
this.rules[0].name = this.getTypeRuleName();
|
|
371
368
|
}
|
|
@@ -373,6 +370,12 @@ var VNumberArray = class extends VNumber {
|
|
|
373
370
|
var VStringArray = class extends VString {
|
|
374
371
|
constructor(options) {
|
|
375
372
|
super(options);
|
|
373
|
+
this.asNumber = () => {
|
|
374
|
+
return new VNumberArray({ ...this, type: "number" });
|
|
375
|
+
};
|
|
376
|
+
this.asBoolean = () => {
|
|
377
|
+
return new VBooleanArray({ ...this, type: "boolean" });
|
|
378
|
+
};
|
|
376
379
|
this.isArray = true;
|
|
377
380
|
this.rules[0].name = this.getTypeRuleName();
|
|
378
381
|
}
|
|
@@ -380,6 +383,12 @@ var VStringArray = class extends VString {
|
|
|
380
383
|
var VBooleanArray = class extends VBoolean {
|
|
381
384
|
constructor(options) {
|
|
382
385
|
super(options);
|
|
386
|
+
this.asNumber = () => {
|
|
387
|
+
return new VNumberArray({ ...this, type: "number" });
|
|
388
|
+
};
|
|
389
|
+
this.asBoolean = () => {
|
|
390
|
+
return new VBooleanArray({ ...this, type: "boolean" });
|
|
391
|
+
};
|
|
383
392
|
this.isArray = true;
|
|
384
393
|
this.rules[0].name = this.getTypeRuleName();
|
|
385
394
|
}
|