hono 4.3.0 → 4.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/types/types.d.ts +40 -27
- package/package.json +1 -1
package/dist/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from './context';
|
|
2
2
|
import type { Hono } from './hono';
|
|
3
3
|
import type { StatusCode } from './utils/http-status';
|
|
4
|
-
import type { IfAnyThenEmptyObject, JSONValue, Prettify, RemoveBlankRecord, UnionToIntersection } from './utils/types';
|
|
4
|
+
import type { IfAnyThenEmptyObject, IsAny, JSONValue, Prettify, RemoveBlankRecord, Simplify, UnionToIntersection } from './utils/types';
|
|
5
5
|
export type Bindings = Record<string, unknown>;
|
|
6
6
|
export type Variables = Record<string, unknown>;
|
|
7
7
|
export type Env = {
|
|
@@ -9,6 +9,7 @@ export type Env = {
|
|
|
9
9
|
Variables?: Variables;
|
|
10
10
|
};
|
|
11
11
|
export type Next = () => Promise<void>;
|
|
12
|
+
export type ExtractInput<I extends Input | Input['in']> = I extends Input ? unknown extends I['in'] ? {} : I['in'] : I;
|
|
12
13
|
export type Input = {
|
|
13
14
|
in?: {};
|
|
14
15
|
out?: {};
|
|
@@ -361,16 +362,27 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = {},
|
|
|
361
362
|
<I extends Input = BlankInput, R extends HandlerResponse<any> = any>(methods: string | string[], paths: string[], ...handlers: H<E, any, I, R>[]): Hono<E, S & ToSchema<string, string, I, MergeTypedResponse<R>>, BasePath>;
|
|
362
363
|
}
|
|
363
364
|
type ExtractKey<S> = S extends Record<infer Key, unknown> ? Key extends string ? Key : never : string;
|
|
364
|
-
export type ToSchema<M extends string, P extends string, I extends Input
|
|
365
|
+
export type ToSchema<M extends string, P extends string, I extends Input | Input['in'], RorO> = Prettify<{
|
|
365
366
|
[K in P]: {
|
|
366
|
-
[K2 in M as AddDollar<K2>]:
|
|
367
|
-
input:
|
|
367
|
+
[K2 in M as AddDollar<K2>]: Simplify<{
|
|
368
|
+
input: AddParam<ExtractInput<I>, P>;
|
|
369
|
+
} & (IsAny<RorO> extends true ? {
|
|
370
|
+
output: {};
|
|
371
|
+
outputFormat: ResponseFormat;
|
|
372
|
+
status: StatusCode;
|
|
373
|
+
} : RorO extends TypedResponse<infer T, infer U, infer F> ? {
|
|
368
374
|
output: unknown extends T ? {} : T;
|
|
369
375
|
outputFormat: I extends {
|
|
370
376
|
outputFormat: string;
|
|
371
|
-
} ? I['outputFormat'] :
|
|
377
|
+
} ? I['outputFormat'] : F;
|
|
372
378
|
status: U;
|
|
373
|
-
} :
|
|
379
|
+
} : {
|
|
380
|
+
output: unknown extends RorO ? {} : RorO;
|
|
381
|
+
outputFormat: unknown extends RorO ? 'json' : I extends {
|
|
382
|
+
outputFormat: string;
|
|
383
|
+
} ? I['outputFormat'] : 'json';
|
|
384
|
+
status: StatusCode;
|
|
385
|
+
})>;
|
|
374
386
|
};
|
|
375
387
|
}>;
|
|
376
388
|
export type Schema = {
|
|
@@ -394,29 +406,30 @@ type FlattenIfIntersect<T> = T extends infer O ? {
|
|
|
394
406
|
} : never;
|
|
395
407
|
export type MergeSchemaPath<OrigSchema extends Schema, SubPath extends string> = Prettify<{
|
|
396
408
|
[P in keyof OrigSchema as MergePath<SubPath, P & string>]: {
|
|
397
|
-
[M in keyof OrigSchema[P]]: OrigSchema[P][M]
|
|
398
|
-
input: infer Input;
|
|
399
|
-
output: infer Output;
|
|
400
|
-
outputFormat: infer OutputFormat;
|
|
401
|
-
status: infer Status;
|
|
402
|
-
} ? {
|
|
403
|
-
input: Input extends {
|
|
404
|
-
param: infer _;
|
|
405
|
-
} ? ExtractParams<SubPath> extends never ? Input : FlattenIfIntersect<Input & {
|
|
406
|
-
param: {
|
|
407
|
-
[K in keyof ExtractParams<SubPath> as K extends `${infer Prefix}{${infer _}}` ? Prefix : K]: string;
|
|
408
|
-
};
|
|
409
|
-
}> : RemoveBlankRecord<ExtractParams<SubPath>> extends never ? Input : Input & {
|
|
410
|
-
param: {
|
|
411
|
-
[K in keyof ExtractParams<SubPath> as K extends `${infer Prefix}{${infer _}}` ? Prefix : K]: string;
|
|
412
|
-
};
|
|
413
|
-
};
|
|
414
|
-
output: Output;
|
|
415
|
-
outputFormat: OutputFormat;
|
|
416
|
-
status: Status;
|
|
417
|
-
} : never;
|
|
409
|
+
[M in keyof OrigSchema[P]]: MergeEndpointParamsWithPath<OrigSchema[P][M], SubPath>;
|
|
418
410
|
};
|
|
419
411
|
}>;
|
|
412
|
+
type MergeEndpointParamsWithPath<T, SubPath extends string> = T extends {
|
|
413
|
+
input: infer Input;
|
|
414
|
+
output: infer Output;
|
|
415
|
+
outputFormat: infer OutputFormat;
|
|
416
|
+
status: infer Status;
|
|
417
|
+
} ? {
|
|
418
|
+
input: Input extends {
|
|
419
|
+
param: infer _;
|
|
420
|
+
} ? ExtractParams<SubPath> extends never ? Input : FlattenIfIntersect<Input & {
|
|
421
|
+
param: {
|
|
422
|
+
[K in keyof ExtractParams<SubPath> as K extends `${infer Prefix}{${infer _}}` ? Prefix : K]: string;
|
|
423
|
+
};
|
|
424
|
+
}> : RemoveBlankRecord<ExtractParams<SubPath>> extends never ? Input : Input & {
|
|
425
|
+
param: {
|
|
426
|
+
[K in keyof ExtractParams<SubPath> as K extends `${infer Prefix}{${infer _}}` ? Prefix : K]: string;
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
output: Output;
|
|
430
|
+
outputFormat: OutputFormat;
|
|
431
|
+
status: Status;
|
|
432
|
+
} : never;
|
|
420
433
|
export type AddParam<I, P extends string> = ParamKeys<P> extends never ? I : I extends {
|
|
421
434
|
param: infer _;
|
|
422
435
|
} ? I : I & {
|