hono 4.11.0 → 4.11.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/README.md +2 -2
- package/dist/cjs/validator/utils.js +16 -0
- package/dist/types/client/types.d.ts +7 -12
- package/dist/types/types.d.ts +39 -40
- package/dist/types/validator/index.d.ts +1 -0
- package/dist/types/validator/utils.d.ts +29 -0
- package/dist/types/validator/validator.d.ts +3 -2
- package/dist/validator/utils.js +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -63,8 +63,8 @@ The migration guide is available on [docs/MIGRATION.md](docs/MIGRATION.md).
|
|
|
63
63
|
Contributions Welcome! You can contribute in the following ways.
|
|
64
64
|
|
|
65
65
|
- Create an Issue - Propose a new feature. Report a bug.
|
|
66
|
-
- Pull Request - Fix a bug
|
|
67
|
-
- Create third-party middleware -
|
|
66
|
+
- Pull Request - Fix a bug or typo. Refactor the code.
|
|
67
|
+
- Create third-party middleware - See instructions below.
|
|
68
68
|
- Share - Share your thoughts on the Blog, X, and others.
|
|
69
69
|
- Make your application - Please try to use Hono.
|
|
70
70
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var utils_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(utils_exports);
|
|
@@ -84,19 +84,14 @@ export interface ClientResponse<T, U extends number = StatusCode, F extends Resp
|
|
|
84
84
|
formData(): Promise<FormData>;
|
|
85
85
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
86
86
|
}
|
|
87
|
-
type
|
|
87
|
+
type BuildSearch<Arg, Key extends 'query'> = Arg extends {
|
|
88
|
+
[K in Key]: infer Query;
|
|
89
|
+
} ? IsEmptyObject<Query> extends true ? '' : `?${string}` : '';
|
|
90
|
+
type BuildPathname<P extends string, Arg> = Arg extends {
|
|
88
91
|
param: infer Param;
|
|
89
|
-
} ?
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
query: infer Query;
|
|
93
|
-
} ? IsEmptyObject<Query> extends true ? TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<P>}`, ''> : TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<P>}`, `?${string}`> : TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<P>}`, ''> : never : ParseHostName<Rest> extends [infer Host extends string, infer Port extends string] ? Arg extends {
|
|
94
|
-
param: infer Param;
|
|
95
|
-
} ? Arg extends {
|
|
96
|
-
query: infer Query;
|
|
97
|
-
} ? IsEmptyObject<Query> extends true ? TypedURL<`${Protocol}:`, Host, Port, `${ApplyParam<TrimStartSlash<Path>, Param>}`, ''> : TypedURL<`${Protocol}:`, Host, Port, `${ApplyParam<TrimStartSlash<Path>, Param>}`, `?${string}`> : TypedURL<`${Protocol}:`, Host, Port, `${ApplyParam<TrimStartSlash<Path>, Param>}`, ''> : Arg extends {
|
|
98
|
-
query: infer Query;
|
|
99
|
-
} ? IsEmptyObject<Query> extends true ? TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<Path>}`, ''> : TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<Path>}`, `?${string}`> : TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<Path>}`, ''> : never : URL : URL;
|
|
92
|
+
} ? `${ApplyParam<TrimStartSlash<P>, Param>}` : `/${TrimStartSlash<P>}`;
|
|
93
|
+
type BuildTypedURL<Protocol extends string, Host extends string, Port extends string, P extends string, Arg> = TypedURL<`${Protocol}:`, Host, Port, BuildPathname<P, Arg>, BuildSearch<Arg, 'query'>>;
|
|
94
|
+
type HonoURL<Prefix extends string, Path extends string, Arg> = IsLiteral<Prefix> extends true ? TrimEndSlash<Prefix> extends `${infer Protocol}://${infer Rest}` ? Rest extends `${infer Hostname}/${infer P}` ? ParseHostName<Hostname> extends [infer Host extends string, infer Port extends string] ? BuildTypedURL<Protocol, Host, Port, P, Arg> : never : ParseHostName<Rest> extends [infer Host extends string, infer Port extends string] ? BuildTypedURL<Protocol, Host, Port, Path, Arg> : never : URL : URL;
|
|
100
95
|
type ParseHostName<T extends string> = T extends `${infer Host}:${infer Port}` ? [Host, Port] : [T, ''];
|
|
101
96
|
type TrimStartSlash<T extends string> = T extends `/${infer R}` ? TrimStartSlash<R> : T;
|
|
102
97
|
type TrimEndSlash<T extends string> = T extends `${infer R}/` ? TrimEndSlash<R> : T;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -376,31 +376,31 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = Blan
|
|
|
376
376
|
H<E11, MergedPath, I10, R>
|
|
377
377
|
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema<M, MergePath<BasePath, P>, I10, MergeTypedResponse<HandlerResponse<any>>>, BasePath, MergePath<BasePath, P>>;
|
|
378
378
|
<M extends string, P extends string, R extends HandlerResponse<any> = any, I extends Input = BlankInput>(method: M, path: P, ...handlers: [H<E, MergePath<BasePath, P>, I, R>, ...H<E, MergePath<BasePath, P>, I, R>[]]): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
379
|
-
<
|
|
380
|
-
<
|
|
381
|
-
<
|
|
382
|
-
<
|
|
379
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, E2 extends Env = E>(methods: M[], path: P, handler: H<E2, MergedPath, I, R>): HonoBase<IntersectNonAnyTypes<[E, E2]>, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
380
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>>(methods: M[], path: P, ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2, R>]): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema<M, MergePath<BasePath, P>, I2, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
381
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>>(methods: M[], path: P, ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2>, H<E4, MergedPath, I3, R>]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, S & ToSchema<M, MergePath<BasePath, P>, I3, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
382
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>>(methods: M[], path: P, ...handlers: [
|
|
383
383
|
H<E2, MergedPath, I>,
|
|
384
384
|
H<E3, MergedPath, I2>,
|
|
385
385
|
H<E4, MergedPath, I3>,
|
|
386
386
|
H<E5, MergedPath, I4, R>
|
|
387
|
-
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S & ToSchema<
|
|
388
|
-
<
|
|
387
|
+
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S & ToSchema<M, MergePath<BasePath, P>, I4, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
388
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>>(methods: M[], path: P, ...handlers: [
|
|
389
389
|
H<E2, MergedPath, I>,
|
|
390
390
|
H<E3, MergedPath, I2>,
|
|
391
391
|
H<E4, MergedPath, I3>,
|
|
392
392
|
H<E5, MergedPath, I4>,
|
|
393
393
|
H<E6, MergedPath, I5, R>
|
|
394
|
-
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S & ToSchema<
|
|
395
|
-
<
|
|
394
|
+
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S & ToSchema<M, MergePath<BasePath, P>, I5, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
395
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>>(methods: M[], path: P, ...handlers: [
|
|
396
396
|
H<E2, MergedPath, I>,
|
|
397
397
|
H<E3, MergedPath, I2>,
|
|
398
398
|
H<E4, MergedPath, I3>,
|
|
399
399
|
H<E5, MergedPath, I4>,
|
|
400
400
|
H<E6, MergedPath, I5>,
|
|
401
401
|
H<E7, MergedPath, I6, R>
|
|
402
|
-
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S & ToSchema<
|
|
403
|
-
<
|
|
402
|
+
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S & ToSchema<M, MergePath<BasePath, P>, I6, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
403
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>>(methods: M[], path: P, ...handlers: [
|
|
404
404
|
H<E2, MergedPath, I>,
|
|
405
405
|
H<E3, MergedPath, I2>,
|
|
406
406
|
H<E4, MergedPath, I3>,
|
|
@@ -408,8 +408,8 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = Blan
|
|
|
408
408
|
H<E6, MergedPath, I5>,
|
|
409
409
|
H<E7, MergedPath, I6>,
|
|
410
410
|
H<E8, MergedPath, I7, R>
|
|
411
|
-
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S & ToSchema<
|
|
412
|
-
<
|
|
411
|
+
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S & ToSchema<M, MergePath<BasePath, P>, I7, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
412
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, I8 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>>(methods: M[], path: P, ...handlers: [
|
|
413
413
|
H<E2, MergedPath, I>,
|
|
414
414
|
H<E3, MergedPath, I2>,
|
|
415
415
|
H<E4, MergedPath, I3>,
|
|
@@ -418,8 +418,8 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = Blan
|
|
|
418
418
|
H<E7, MergedPath, I6>,
|
|
419
419
|
H<E8, MergedPath, I7>,
|
|
420
420
|
H<E9, MergedPath, I8, R>
|
|
421
|
-
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S & ToSchema<
|
|
422
|
-
<
|
|
421
|
+
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S & ToSchema<M, MergePath<BasePath, P>, I8, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
422
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, I8 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7, I9 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7 & I8, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>>(methods: M[], path: P, ...handlers: [
|
|
423
423
|
H<E2, MergedPath, I>,
|
|
424
424
|
H<E3, MergedPath, I2>,
|
|
425
425
|
H<E4, MergedPath, I3>,
|
|
@@ -429,8 +429,8 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = Blan
|
|
|
429
429
|
H<E8, MergedPath, I7>,
|
|
430
430
|
H<E9, MergedPath, I8>,
|
|
431
431
|
H<E10, MergedPath, I9, R>
|
|
432
|
-
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S & ToSchema<
|
|
433
|
-
<
|
|
432
|
+
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S & ToSchema<M, MergePath<BasePath, P>, I9, MergeTypedResponse<HandlerResponse<any>>>, BasePath, MergePath<BasePath, P>>;
|
|
433
|
+
<M extends string, P extends string, MergedPath extends MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, I4 extends Input = I & I2 & I3, I5 extends Input = I & I2 & I3 & I4, I6 extends Input = I & I2 & I3 & I4 & I5, I7 extends Input = I & I2 & I3 & I4 & I5 & I6, I8 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7, I9 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7 & I8, I10 extends Input = I & I2 & I3 & I4 & I5 & I6 & I7 & I8 & I9, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>>(methods: M[], path: P, ...handlers: [
|
|
434
434
|
H<E2, MergedPath, I>,
|
|
435
435
|
H<E3, MergedPath, I2>,
|
|
436
436
|
H<E4, MergedPath, I3>,
|
|
@@ -441,39 +441,39 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = Blan
|
|
|
441
441
|
H<E9, MergedPath, I8>,
|
|
442
442
|
H<E10, MergedPath, I9>,
|
|
443
443
|
H<E11, MergedPath, I10, R>
|
|
444
|
-
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema<
|
|
445
|
-
<P extends string, R extends HandlerResponse<any> = any, I extends Input = BlankInput>(methods:
|
|
446
|
-
<const Ps extends string[], I extends Input = BlankInput, R extends HandlerResponse<any> = any, E2 extends Env = E>(methods:
|
|
444
|
+
]): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema<M, MergePath<BasePath, P>, I10, MergeTypedResponse<HandlerResponse<any>>>, BasePath, MergePath<BasePath, P>>;
|
|
445
|
+
<M extends string, P extends string, R extends HandlerResponse<any> = any, I extends Input = BlankInput>(methods: M[], path: P, ...handlers: [H<E, MergePath<BasePath, P>, I, R>, ...H<E, MergePath<BasePath, P>, I, R>[]]): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath, MergePath<BasePath, P>>;
|
|
446
|
+
<M extends string, const Ps extends string[], I extends Input = BlankInput, R extends HandlerResponse<any> = any, E2 extends Env = E>(methods: M | M[], paths: Ps, ...handlers: H<E2, MergePath<BasePath, Ps[number]>, I, R>[]): HonoBase<E, S & ToSchema<M, MergePath<BasePath, Ps[number]>, I, MergeTypedResponse<R>>, BasePath, Ps extends [...string[], infer LastPath extends string] ? MergePath<BasePath, LastPath> : never>;
|
|
447
447
|
}
|
|
448
|
-
|
|
448
|
+
type ToSchemaOutput<RorO, I extends Input | Input['in']> = RorO extends TypedResponse<infer T, infer U, infer F> ? {
|
|
449
|
+
output: unknown extends T ? {} : T;
|
|
450
|
+
outputFormat: I extends {
|
|
451
|
+
outputFormat: string;
|
|
452
|
+
} ? I['outputFormat'] : F;
|
|
453
|
+
status: U;
|
|
454
|
+
} : {
|
|
455
|
+
output: unknown extends RorO ? {} : RorO;
|
|
456
|
+
outputFormat: unknown extends RorO ? 'json' : I extends {
|
|
457
|
+
outputFormat: string;
|
|
458
|
+
} ? I['outputFormat'] : 'json';
|
|
459
|
+
status: StatusCode;
|
|
460
|
+
};
|
|
461
|
+
export type ToSchema<M extends string, P extends string, I extends Input | Input['in'], RorO> = IsAny<RorO> extends true ? {
|
|
449
462
|
[K in P]: {
|
|
450
|
-
[K2 in M as AddDollar<K2>]:
|
|
463
|
+
[K2 in M as AddDollar<K2>]: {
|
|
451
464
|
input: AddParam<ExtractInput<I>, P>;
|
|
452
|
-
} & {
|
|
453
465
|
output: {};
|
|
454
466
|
outputFormat: ResponseFormat;
|
|
455
467
|
status: StatusCode;
|
|
456
|
-
}
|
|
468
|
+
};
|
|
457
469
|
};
|
|
458
|
-
}
|
|
470
|
+
} : [RorO] extends [never] ? {} : [RorO] extends [Promise<void>] ? {} : {
|
|
459
471
|
[K in P]: {
|
|
460
472
|
[K2 in M as AddDollar<K2>]: Simplify<{
|
|
461
473
|
input: AddParam<ExtractInput<I>, P>;
|
|
462
|
-
} &
|
|
463
|
-
output: unknown extends T ? {} : T;
|
|
464
|
-
outputFormat: I extends {
|
|
465
|
-
outputFormat: string;
|
|
466
|
-
} ? I['outputFormat'] : F;
|
|
467
|
-
status: U;
|
|
468
|
-
} : {
|
|
469
|
-
output: unknown extends RorO ? {} : RorO;
|
|
470
|
-
outputFormat: unknown extends RorO ? 'json' : I extends {
|
|
471
|
-
outputFormat: string;
|
|
472
|
-
} ? I['outputFormat'] : 'json';
|
|
473
|
-
status: StatusCode;
|
|
474
|
-
})>;
|
|
474
|
+
} & ToSchemaOutput<RorO, I>>;
|
|
475
475
|
};
|
|
476
|
-
}
|
|
476
|
+
};
|
|
477
477
|
export type Schema = {
|
|
478
478
|
[Path: string]: {
|
|
479
479
|
[Method: `$${Lowercase<string>}`]: Endpoint;
|
|
@@ -532,8 +532,7 @@ export type TypedResponse<T = unknown, U extends StatusCode = StatusCode, F exte
|
|
|
532
532
|
_format: F;
|
|
533
533
|
};
|
|
534
534
|
type MergeTypedResponse<T> = T extends Promise<void> ? T : T extends Promise<infer T2> ? T2 extends TypedResponse ? T2 : TypedResponse : T extends TypedResponse ? T : TypedResponse;
|
|
535
|
-
type
|
|
536
|
-
type MergeMiddlewareResponse<T> = MergeTypedResponseStrict<ExtractHandlerResponse<T>>;
|
|
535
|
+
type MergeMiddlewareResponse<T> = T extends (c: any, next: any) => Promise<infer R> ? Exclude<R, void> extends never ? never : Exclude<R, void> extends TypedResponse ? Exclude<R, void> : never : T extends (c: any, next: any) => infer R ? R extends TypedResponse ? R : never : never;
|
|
537
536
|
export type FormValue = string | Blob;
|
|
538
537
|
export type ParsedFormValue = string | File;
|
|
539
538
|
export type ValidationTargets<T extends FormValue = ParsedFormValue, P extends string = string> = {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FormValue, ParsedFormValue, ValidationTargets } from '../types';
|
|
2
|
+
import type { UnionToIntersection } from '../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if T is a literal union type (e.g., 'asc' | 'desc')
|
|
5
|
+
* that should be preserved in input types.
|
|
6
|
+
* Returns true for union literals, false for single literals or wide types.
|
|
7
|
+
*/
|
|
8
|
+
export type IsLiteralUnion<T, Base> = [Exclude<T, undefined>] extends [Base] ? [Exclude<T, undefined>] extends [UnionToIntersection<Exclude<T, undefined>>] ? false : true : false;
|
|
9
|
+
type IsOptionalUnion<T> = [unknown] extends [T] ? false : undefined extends T ? true : false;
|
|
10
|
+
type SimplifyDeep<T> = {
|
|
11
|
+
[K in keyof T]: T[K];
|
|
12
|
+
} & {};
|
|
13
|
+
type InferInputInner<Output, Target extends keyof ValidationTargets, T extends FormValue> = SimplifyDeep<{
|
|
14
|
+
[K in keyof Output]: IsLiteralUnion<Output[K], string> extends true ? Output[K] : IsOptionalUnion<Output[K]> extends true ? Output[K] : Target extends 'form' ? T | T[] : Target extends 'query' ? string | string[] : Target extends 'param' ? string : Target extends 'header' ? string : Target extends 'cookie' ? string : unknown;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Utility type to infer input types for validation targets.
|
|
18
|
+
* Preserves literal union types (e.g., 'asc' | 'desc') while using
|
|
19
|
+
* the default ValidationTargets type for other values.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // In @hono/zod-validator or similar:
|
|
24
|
+
* type Input = InferInput<z.input<Schema>, 'query'>
|
|
25
|
+
* // { orderBy: 'asc' | 'desc', page: string | string[] }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type InferInput<Output, Target extends keyof ValidationTargets, T extends FormValue = ParsedFormValue> = [Exclude<Output, undefined>] extends [never] ? {} : [Exclude<Output, undefined>] extends [object] ? undefined extends Output ? SimplifyDeep<InferInputInner<Exclude<Output, undefined>, Target, T>> | undefined : SimplifyDeep<InferInputInner<Output, Target, T>> : {};
|
|
29
|
+
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { Context } from '../context';
|
|
2
2
|
import type { Env, MiddlewareHandler, TypedResponse, ValidationTargets, FormValue } from '../types';
|
|
3
|
+
import type { InferInput } from './utils';
|
|
3
4
|
type ValidationTargetKeysWithBody = 'form' | 'json';
|
|
4
5
|
type ValidationTargetByMethod<M> = M extends 'get' | 'head' ? Exclude<keyof ValidationTargets, ValidationTargetKeysWithBody> : keyof ValidationTargets;
|
|
5
6
|
export type ValidationFunction<InputType, OutputType, E extends Env = {}, P extends string = string> = (value: InputType, c: Context<E, P>) => OutputType | TypedResponse | Promise<OutputType> | Promise<TypedResponse>;
|
|
6
7
|
export type ExtractValidationResponse<VF> = VF extends (value: any, c: any) => infer R ? R extends Promise<infer PR> ? PR extends TypedResponse<infer T, infer S, infer F> ? TypedResponse<T, S, F> : PR extends Response ? PR : PR extends undefined ? never : never : R extends TypedResponse<infer T, infer S, infer F> ? TypedResponse<T, S, F> : R extends Response ? R : R extends undefined ? never : never : never;
|
|
7
8
|
export declare const validator: <InputType, P extends string, M extends string, U extends ValidationTargetByMethod<M>, P2 extends string = P, VF extends (value: unknown extends InputType ? ValidationTargets[U] : InputType, c: Context<any, P2>) => any = (value: unknown extends InputType ? ValidationTargets[U] : InputType, c: Context<any, P2>) => any, V extends {
|
|
8
|
-
in: { [K in U]: K extends "json" ? unknown extends InputType ? ExtractValidatorOutput<VF> : InputType :
|
|
9
|
+
in: { [K in U]: K extends "json" ? unknown extends InputType ? ExtractValidatorOutput<VF> : InputType : InferInput<ExtractValidatorOutput<VF>, K, FormValue>; };
|
|
9
10
|
out: { [K in U]: ExtractValidatorOutput<VF>; };
|
|
10
11
|
} = {
|
|
11
|
-
in: { [K in U]: K extends "json" ? unknown extends InputType ? ExtractValidatorOutput<VF> : InputType :
|
|
12
|
+
in: { [K in U]: K extends "json" ? unknown extends InputType ? ExtractValidatorOutput<VF> : InputType : InferInput<ExtractValidatorOutput<VF>, K, FormValue>; };
|
|
12
13
|
out: { [K in U]: ExtractValidatorOutput<VF>; };
|
|
13
14
|
}, E extends Env = any>(target: U, validationFunc: VF) => MiddlewareHandler<E, P, V, ExtractValidationResponse<VF>>;
|
|
14
15
|
export type ExtractValidatorOutput<VF> = VF extends (value: any, c: any) => infer R ? R extends Promise<infer PR> ? PR extends Response | TypedResponse<any, any, any> ? never : PR : R extends Response | TypedResponse<any, any, any> ? never : R : never;
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.2",
|
|
4
4
|
"description": "Web framework built on Web Standards",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -661,7 +661,7 @@
|
|
|
661
661
|
"@types/glob": "^9.0.0",
|
|
662
662
|
"@types/jsdom": "^21.1.7",
|
|
663
663
|
"@types/node": "^24.3.0",
|
|
664
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
664
|
+
"@typescript/native-preview": "7.0.0-dev.20251220.1",
|
|
665
665
|
"@vitest/coverage-v8": "^3.2.4",
|
|
666
666
|
"arg": "^5.0.2",
|
|
667
667
|
"bun-types": "^1.2.20",
|