Skip to content
Myr

fix(types): remove type-errors for routes (#1371)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(types): remove type-errors for routes * denoify * fixed the client and the presets * rename

authored by Yusuke Wada · committed by GitHub · parent f860435 · Browse files · 14 files+182 added−164 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

14 files+182 added−164 removed

  • tests:+4 added−4 removed
  • other:+178 added−160 removed

14 files+182 added−164 removed

modified:deno_dist/client/types.ts+4 added-15 removed
modified:deno_dist/preset/quick.ts+6 added-6 removed
modified:deno_dist/preset/tiny.ts+6 added-6 removed
modified:deno_dist/hono-base.ts+21 added-10 removed
17 unmodified lines
18 TypedResponse,19 MergePath,20 MergeSchemaPath,21 FetchEventLike,22 Schema,23} from './types.ts'24import type { RemoveBlankRecord } from './utils/types.ts'25import { getPath, getPathNoStrict, getQueryStrings, mergePath } from './utils/url.ts'26
5 unmodified lines
32 handler: H33}3435function defineDynamicClass(): {35 new <E extends Env = Env, S = {}, BasePath extends string = '/'>(): {36 new <E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'>(): {37 [M in Methods]: HandlerInterface<E, M, S, BasePath>38 } & {39 on: OnHandlerInterface<E, S, BasePath>40 } & {
15 unmodified lines
56 const message = 'Internal Server Error'57 return c.text(message, 500)58}5959class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends defineDynamicClass()<60 E,61 S,62 BasePath63> {60class Hono<61 E extends Env = Env,62 S extends Schema = {},63 BasePath extends string = '/'64> extends defineDynamicClass()<E, S, BasePath> {65 /*66 This class is like an abstract class and does not have a router.67 To use it, inherit the class and implement router in the constructor.68 */
69 unmodified lines
138139 private notFoundHandler: NotFoundHandler = notFoundHandler140 private errorHandler: ErrorHandler = errorHandler141141 route<SubPath extends string, SubEnv extends Env, SubSchema, SubBasePath extends string>(142 route<143 SubPath extends string,144 SubEnv extends Env,145 SubSchema extends Schema,146 SubBasePath extends string147 >(148 path: SubPath,149 app: Hono<SubEnv, SubSchema, SubBasePath>144 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>, BasePath>150 ): Hono<E, MergeSchemaPath<SubSchema, SubPath> & S, BasePath>151 /** @description152 * Use `basePath` instead of `route` when passing **one** argument, such as `app.route('/api')`.153 * The use of `route` with **one** argument has been removed in v4.154 * However, you can still use `route` with **two** arguments, like `app.route('/api', subApp)`."155 */156 route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>151 route<SubPath extends string, SubEnv extends Env, SubSchema, SubBasePath extends string>(157 route<158 SubPath extends string,159 SubEnv extends Env,160 SubSchema extends Schema,161 SubBasePath extends string162 >(163 path: SubPath,164 app?: Hono<SubEnv, SubSchema, SubBasePath>154 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>, BasePath> {165 ): Hono<E, MergeSchemaPath<SubSchema, SubPath> & S, BasePath> {166 const subApp = this.basePath(path)167168 if (!app) {169 // eslint-disable-next-line @typescript-eslint/no-explicit-any
230 unmodified lines
modified:deno_dist/hono.ts+6 added-6 removed
modified:deno_dist/types.ts+45 added-36 removed
64 unmodified lines
6566export interface HandlerInterface<67 E extends Env = Env,68 M extends string = any,69 S = {},69 S extends Schema = {},70 BasePath extends string = '/'71> {72 //// app.get(...handlers[])73
3 unmodified lines
77 I extends Input = {},78 O = {}79 >(80 ...handlers: [H<E, P, I, O>, H<E, P, I, O>]81 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I['in'], O>>, BasePath>81 ): Hono<E, S & ToSchema<M, P, I['in'], O>, BasePath>8283 // app.get(handler x 3)84 <85 P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>,
2 unmodified lines
88 I2 extends Input = I,89 I3 extends Input = I & I290 >(91 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>]92 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I3['in'], O>>, BasePath>92 ): Hono<E, S & ToSchema<M, P, I3['in'], O>, BasePath>9394 // app.get(handler x 4)95 <96 P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>,
3 unmodified lines
100 I3 extends Input = I & I2,101 I4 extends Input = I & I2 & I3102 >(103 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>]104 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I4['in'], O>>, BasePath>104 ): Hono<E, S & ToSchema<M, P, I4['in'], O>, BasePath>105106 // app.get(handler x 5)107 <108 P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>,
4 unmodified lines
113 I4 extends Input = I2 & I3,114 I5 extends Input = I & I2 & I3 & I4115 >(116 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>, H<E, P, I5, O>]117 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I5['in'], O>>, BasePath>117 ): Hono<E, S & ToSchema<M, P, I5['in'], O>, BasePath>118119 // app.get(...handlers[])120 <121 P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>,122 I extends Input = {},123 O = {}124 >(125 ...handlers: Handler<E, P, I, O>[]126 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I['in'], O>>, BasePath>126 ): Hono<E, S & ToSchema<M, P, I['in'], O>, BasePath>127128 //// app.get(path, ...handlers[])129130 // app.get(path, handler)131 <P extends string, O = {}, I extends Input = {}>(132 path: P,133 handler: H<E, MergePath<BasePath, P>, I, O>134 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>134 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>135136 // app.get(path, handler, handler)137 <P extends string, O = {}, I extends Input = {}>(138 path: P,139 ...handlers: [H<E, MergePath<BasePath, P>, I, O>, H<E, MergePath<BasePath, P>, I, O>]140 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>140 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>141142 // app.get(path, handler x3)143 <P extends string, O = {}, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2>(144 path: P,
1 unmodified line
146 H<E, MergePath<BasePath, P>, I, O>,147 H<E, MergePath<BasePath, P>, I2, O>,148 H<E, MergePath<BasePath, P>, I3, O>149 ]150 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I3['in'], O>>, BasePath>150 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I3['in'], O>, BasePath>151152 // app.get(path, handler x4)153 <154 P extends string,
9 unmodified lines
164 H<E, MergePath<BasePath, P>, I2, O>,165 H<E, MergePath<BasePath, P>, I3, O>,166 H<E, MergePath<BasePath, P>, I4, O>167 ]168 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I4['in'], O>>, BasePath>168 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I4['in'], O>, BasePath>169170 // app.get(path, handler x5)171 <172 P extends string,
11 unmodified lines
184 H<E, MergePath<BasePath, P>, I3, O>,185 H<E, MergePath<BasePath, P>, I4, O>,186 H<E, MergePath<BasePath, P>, I5, O>187 ]188 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I5['in'], O>>, BasePath>188 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I5['in'], O>, BasePath>189190 // app.get(path, ...handlers[])191 <P extends string, I extends Input = {}, O = {}>(192 path: P,193 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]194 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>194 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>195}196197////////////////////////////////////////198////// //////
2 unmodified lines
201////////////////////////////////////////202203export interface MiddlewareHandlerInterface<204 E extends Env = Env,205 S = {},205 S extends Schema = {},206 BasePath extends string = '/'207> {208 //// app.get(...handlers[])209 (...handlers: MiddlewareHandler<E, MergePath<BasePath, ExtractKey<S>>>[]): Hono<E, S, BasePath>
10 unmodified lines
220////// OnHandlerInterface //////221////// //////222////////////////////////////////////////223224export interface OnHandlerInterface<E extends Env = Env, S = {}, BasePath extends string = '/'> {224export interface OnHandlerInterface<225 E extends Env = Env,226 S extends Schema = {},227 BasePath extends string = '/'228> {229 // app.on(method, path, handler, handler)230 <M extends string, P extends string, O = {}, I extends Input = {}>(231 method: M,232 path: P,233 ...handlers: [H<E, MergePath<BasePath, P>, I, O>, H<E, MergePath<BasePath, P>, I, O>]230 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>234 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>235236 // app.get(method, path, handler x3)237 <238 M extends string,
9 unmodified lines
248 H<E, MergePath<BasePath, P>, I, O>,249 H<E, MergePath<BasePath, P>, I2, O>,250 H<E, MergePath<BasePath, P>, I3, O>251 ]248 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I3['in'], O>>, BasePath>252 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I3['in'], O>, BasePath>253254 // app.get(method, path, handler x4)255 <256 M extends string,
11 unmodified lines
268 H<E, MergePath<BasePath, P>, I2, O>,269 H<E, MergePath<BasePath, P>, I3, O>,270 H<E, MergePath<BasePath, P>, I4, O>271 ]268 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I4['in'], O>>, BasePath>272 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I4['in'], O>, BasePath>273274 // app.get(method, path, handler x5)275 <276 M extends string,
13 unmodified lines
290 H<E, MergePath<BasePath, P>, I3, O>,291 H<E, MergePath<BasePath, P>, I4, O>,292 H<E, MergePath<BasePath, P>, I5, O>293 ]290 ): Hono<E, S | Schema<M, MergePath<BasePath, P>, I5['in'], O>, BasePath>294 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I5['in'], O>, BasePath>295296 <M extends string, P extends string, O extends {} = {}, I extends Input = {}>(297 method: M,298 path: P,299 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]296 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>300 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>301302 // app.on(method[], path, ...handler)303 <P extends string, O extends {} = {}, I extends Input = {}>(304 methods: string[],305 path: P,306 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]303 ): Hono<E, RemoveBlankRecord<S | Schema<string, MergePath<BasePath, P>, I['in'], O>>, BasePath>307 ): Hono<E, S & ToSchema<string, MergePath<BasePath, P>, I['in'], O>, BasePath>308}309310type ExtractKey<S> = S extends Record<infer Key, unknown>311 ? Key extends string
2 unmodified lines
314 : string315316////////////////////////////////////////317////// //////314////// Schema //////318////// ToSchema //////319////// //////320////////////////////////////////////////321318export type Schema<M extends string, P extends string, I extends Input['in'], O> = {319 [K in P]: AddDollar<{320 [K2 in M]: {322export type ToSchema<M extends string, P extends string, I extends Input['in'], O> = {323 [K in P]: {324 [K2 in M as AddDollar<string & K2>]: {325 input: unknown extends I ? AddParam<{}, P> : AddParam<I, P>326 output: unknown extends O ? {} : O327 }324 }>328 }329}330331export type Schema = {332 [Path: string]: {333 [Method: `$${Lowercase<string>}`]: {334 input: Partial<ValidationTargets> & {335 param?: Record<string, string>336 }337 output: {}338 }339 }340}341342export type MergeSchemaPath<OrigSchema, SubPath extends string> = {343 [K in keyof OrigSchema as `${SubPath}${K & string}`]: OrigSchema[K]344}345346export type AddParam<I, P extends string> = ParamKeys<P> extends never347 ? I348 : I & { param: UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>> }349331export type AddDollar<T> = T extends Record<infer K, infer R>332 ? K extends string333 ? { [MethodName in `$${Lowercase<K>}`]: R }334 : never335 : never350type AddDollar<T extends string> = `$${Lowercase<T>}`351337export type MergeSchemaPath<S, P extends string> = S extends Record<infer Key, infer T>338 ? Key extends string339 ? Record<MergePath<P, Key>, T>340 : never341 : never342352export type MergePath<A extends string, B extends string> = A extends ''353 ? B354 : A extends '/'355 ? B
102 unmodified lines
modified:src/adapter/aws-lambda/handler.ts+2 added-2 removed
1// @denoify-ignore2import crypto from 'crypto'3import type { Hono } from '../../hono'4import type { Env } from '../../types'4import type { Env, Schema } from '../../types'56import { encodeBase64 } from '../../utils/encode'7import type { ApiGatewayRequestContext, LambdaFunctionUrlRequestContext } from './custom-context'8
48 unmodified lines
5758/**59 * Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)60 */61export const handle = <E extends Env = Env, S = {}, BasePath extends string = '/'>(61export const handle = <E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'>(62 app: Hono<E, S, BasePath>63) => {64 return async (65 event: APIGatewayProxyEvent | APIGatewayProxyEventV2 | LambdaFunctionUrlEvent
104 unmodified lines
modified:src/client/types.ts+4 added-15 removed
1import type { Hono } from '../hono'2import type { ValidationTargets } from '../types'2import type { Schema } from '../types'3import type { RemoveBlankRecord } from '../utils/types'45type MethodName = `$${string}`67type Endpoint = Record<MethodName, Data>89type Data = {10 input: Partial<ValidationTargets> & {11 param?: Record<string, string>12 }13 output: {}14}155export type ClientRequestOptions = {6 headers?: Record<string, string>7 fetch?: typeof fetch8}921type ClientRequest<S extends Data> = {10type ClientRequest<S extends Schema> = {11 [M in keyof S]: S[M] extends { input: infer R; output: infer O }12 ? RemoveBlankRecord<R> extends never13 ? (args?: {}, options?: ClientRequestOptions) => Promise<ClientResponse<O>>14 : (
38 unmodified lines
53 : never5455type PathToChain<56 Path extends string,68 E extends Endpoint,57 E extends Schema,58 Original extends string = ''59> = Path extends `/${infer P}`60 ? PathToChain<P, E, Path>61 : Path extends `${infer P}/${infer R}`
5 unmodified lines
67 }6869// eslint-disable-next-line @typescript-eslint/no-explicit-any70export type Client<T> = T extends Hono<any, infer S, any>82 ? S extends Record<infer K, Endpoint>71 ? S extends Record<infer K, Schema>72 ? K extends string73 ? PathToChain<K, S>74 : never75 : never
13 unmodified lines
modified:src/preset/quick.ts+6 added-6 removed
1import { HonoBase } from '../hono-base'2import { LinearRouter } from '../router/linear-router'3import { SmartRouter } from '../router/smart-router'4import { TrieRouter } from '../router/trie-router'5import type { Env } from '../types'5import type { Env, Schema } from '../types'67export class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends HonoBase<8 E,9 S,10 BasePath11> {7export class Hono<8 E extends Env = Env,9 S extends Schema = {},10 BasePath extends string = '/'11> extends HonoBase<E, S, BasePath> {12 constructor(init: Partial<Pick<Hono, 'getPath'> & { strict: boolean }> = {}) {13 super(init)14 this.router = new SmartRouter({15 routers: [new LinearRouter(), new TrieRouter()],
3 unmodified lines
modified:src/preset/tiny.ts+6 added-6 removed
1import { HonoBase } from '../hono-base'2import { PatternRouter } from '../router/pattern-router'3import type { Env } from '../types'3import type { Env, Schema } from '../types'45export class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends HonoBase<6 E,7 S,8 BasePath9> {5export class Hono<6 E extends Env = Env,7 S extends Schema = {},8 BasePath extends string = '/'9> extends HonoBase<E, S, BasePath> {10 constructor(init: Partial<Pick<Hono, 'getPath'> & { strict: boolean }> = {}) {11 super(init)12 this.router = new PatternRouter()13 }
1 unmodified line
modified:src/hono-base.ts+21 added-10 removed
17 unmodified lines
18 TypedResponse,19 MergePath,20 MergeSchemaPath,21 FetchEventLike,22 Schema,23} from './types'24import type { RemoveBlankRecord } from './utils/types'25import { getPath, getPathNoStrict, getQueryStrings, mergePath } from './utils/url'26
5 unmodified lines
32 handler: H33}3435function defineDynamicClass(): {35 new <E extends Env = Env, S = {}, BasePath extends string = '/'>(): {36 new <E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'>(): {37 [M in Methods]: HandlerInterface<E, M, S, BasePath>38 } & {39 on: OnHandlerInterface<E, S, BasePath>40 } & {
15 unmodified lines
56 const message = 'Internal Server Error'57 return c.text(message, 500)58}5959class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends defineDynamicClass()<60 E,61 S,62 BasePath63> {60class Hono<61 E extends Env = Env,62 S extends Schema = {},63 BasePath extends string = '/'64> extends defineDynamicClass()<E, S, BasePath> {65 /*66 This class is like an abstract class and does not have a router.67 To use it, inherit the class and implement router in the constructor.68 */
69 unmodified lines
138139 private notFoundHandler: NotFoundHandler = notFoundHandler140 private errorHandler: ErrorHandler = errorHandler141141 route<SubPath extends string, SubEnv extends Env, SubSchema, SubBasePath extends string>(142 route<143 SubPath extends string,144 SubEnv extends Env,145 SubSchema extends Schema,146 SubBasePath extends string147 >(148 path: SubPath,149 app: Hono<SubEnv, SubSchema, SubBasePath>144 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>, BasePath>150 ): Hono<E, MergeSchemaPath<SubSchema, SubPath> & S, BasePath>151 /** @description152 * Use `basePath` instead of `route` when passing **one** argument, such as `app.route('/api')`.153 * The use of `route` with **one** argument has been removed in v4.154 * However, you can still use `route` with **two** arguments, like `app.route('/api', subApp)`."155 */156 route<SubPath extends string>(path: SubPath): Hono<E, RemoveBlankRecord<S>, BasePath>151 route<SubPath extends string, SubEnv extends Env, SubSchema, SubBasePath extends string>(157 route<158 SubPath extends string,159 SubEnv extends Env,160 SubSchema extends Schema,161 SubBasePath extends string162 >(163 path: SubPath,164 app?: Hono<SubEnv, SubSchema, SubBasePath>154 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>, BasePath> {165 ): Hono<E, MergeSchemaPath<SubSchema, SubPath> & S, BasePath> {166 const subApp = this.basePath(path)167168 if (!app) {169 // eslint-disable-next-line @typescript-eslint/no-explicit-any
230 unmodified lines
modified:src/hono.ts+6 added-6 removed
1import { HonoBase } from './hono-base'2import { RegExpRouter } from './router/reg-exp-router'3import { SmartRouter } from './router/smart-router'4import { TrieRouter } from './router/trie-router'5import type { Env } from './types'5import type { Env, Schema } from './types'67export class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> extends HonoBase<8 E,9 S,10 BasePath11> {7export class Hono<8 E extends Env = Env,9 S extends Schema = {},10 BasePath extends string = '/'11> extends HonoBase<E, S, BasePath> {12 constructor(init: Partial<Pick<Hono, 'router' | 'getPath'> & { strict: boolean }> = {}) {13 super(init)14 this.router =15 init.router ??
5 unmodified lines
modified:src/types.test.ts+4 added-4 removed
12 unmodified lines
13 MiddlewareHandler,14 ParamKeys,15 ParamKeyToRecord,16 RemoveQuestion,17 Schema,17 ToSchema,18 UndefinedIfHavingQuestion,19} from './types'20import type { Expect, Equal } from './utils/types'21
241 unmodified lines
263describe('Schema', () => {264 test('Schema', () => {265 type AppType = Hono<266 Env,267 Schema<267 ToSchema<268 'post',269 '/api/posts/:id',270 {271 json: {
194 unmodified lines
466 type verify4 = Expect<Equal<'/api', path4>>467 })468469 test('MergeSchemaPath', () => {470 type Sub = Schema<470 type Sub = ToSchema<471 'post',472 '/posts',473 {474 json: {
4 unmodified lines
479 {480 message: string481 }482 > &483 Schema<483 ToSchema<484 'get',485 '/posts',486 {},487 {
32 unmodified lines
modified:src/types.ts+45 added-36 removed
64 unmodified lines
6566export interface HandlerInterface<67 E extends Env = Env,68 M extends string = any,69 S = {},69 S extends Schema = {},70 BasePath extends string = '/'71> {72 //// app.get(...handlers[])73
3 unmodified lines
77 I extends Input = {},78 O = {}79 >(80 ...handlers: [H<E, P, I, O>, H<E, P, I, O>]81 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I['in'], O>>, BasePath>81 ): Hono<E, S & ToSchema<M, P, I['in'], O>, BasePath>8283 // app.get(handler x 3)84 <85 P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>,
2 unmodified lines
88 I2 extends Input = I,89 I3 extends Input = I & I290 >(91 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>]92 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I3['in'], O>>, BasePath>92 ): Hono<E, S & ToSchema<M, P, I3['in'], O>, BasePath>9394 // app.get(handler x 4)95 <96 P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>,
3 unmodified lines
100 I3 extends Input = I & I2,101 I4 extends Input = I & I2 & I3102 >(103 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>]104 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I4['in'], O>>, BasePath>104 ): Hono<E, S & ToSchema<M, P, I4['in'], O>, BasePath>105106 // app.get(handler x 5)107 <108 P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>,
4 unmodified lines
113 I4 extends Input = I2 & I3,114 I5 extends Input = I & I2 & I3 & I4115 >(116 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>, H<E, P, I5, O>]117 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I5['in'], O>>, BasePath>117 ): Hono<E, S & ToSchema<M, P, I5['in'], O>, BasePath>118119 // app.get(...handlers[])120 <121 P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>,122 I extends Input = {},123 O = {}124 >(125 ...handlers: Handler<E, P, I, O>[]126 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I['in'], O>>, BasePath>126 ): Hono<E, S & ToSchema<M, P, I['in'], O>, BasePath>127128 //// app.get(path, ...handlers[])129130 // app.get(path, handler)131 <P extends string, O = {}, I extends Input = {}>(132 path: P,133 handler: H<E, MergePath<BasePath, P>, I, O>134 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>134 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>135136 // app.get(path, handler, handler)137 <P extends string, O = {}, I extends Input = {}>(138 path: P,139 ...handlers: [H<E, MergePath<BasePath, P>, I, O>, H<E, MergePath<BasePath, P>, I, O>]140 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>140 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>141142 // app.get(path, handler x3)143 <P extends string, O = {}, I extends Input = {}, I2 extends Input = I, I3 extends Input = I & I2>(144 path: P,
1 unmodified line
146 H<E, MergePath<BasePath, P>, I, O>,147 H<E, MergePath<BasePath, P>, I2, O>,148 H<E, MergePath<BasePath, P>, I3, O>149 ]150 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I3['in'], O>>, BasePath>150 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I3['in'], O>, BasePath>151152 // app.get(path, handler x4)153 <154 P extends string,
9 unmodified lines
164 H<E, MergePath<BasePath, P>, I2, O>,165 H<E, MergePath<BasePath, P>, I3, O>,166 H<E, MergePath<BasePath, P>, I4, O>167 ]168 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I4['in'], O>>, BasePath>168 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I4['in'], O>, BasePath>169170 // app.get(path, handler x5)171 <172 P extends string,
11 unmodified lines
184 H<E, MergePath<BasePath, P>, I3, O>,185 H<E, MergePath<BasePath, P>, I4, O>,186 H<E, MergePath<BasePath, P>, I5, O>187 ]188 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I5['in'], O>>, BasePath>188 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I5['in'], O>, BasePath>189190 // app.get(path, ...handlers[])191 <P extends string, I extends Input = {}, O = {}>(192 path: P,193 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]194 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>194 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>195}196197////////////////////////////////////////198////// //////
2 unmodified lines
201////////////////////////////////////////202203export interface MiddlewareHandlerInterface<204 E extends Env = Env,205 S = {},205 S extends Schema = {},206 BasePath extends string = '/'207> {208 //// app.get(...handlers[])209 (...handlers: MiddlewareHandler<E, MergePath<BasePath, ExtractKey<S>>>[]): Hono<E, S, BasePath>
10 unmodified lines
220////// OnHandlerInterface //////221////// //////222////////////////////////////////////////223224export interface OnHandlerInterface<E extends Env = Env, S = {}, BasePath extends string = '/'> {224export interface OnHandlerInterface<225 E extends Env = Env,226 S extends Schema = {},227 BasePath extends string = '/'228> {229 // app.on(method, path, handler, handler)230 <M extends string, P extends string, O = {}, I extends Input = {}>(231 method: M,232 path: P,233 ...handlers: [H<E, MergePath<BasePath, P>, I, O>, H<E, MergePath<BasePath, P>, I, O>]230 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>234 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>235236 // app.get(method, path, handler x3)237 <238 M extends string,
9 unmodified lines
248 H<E, MergePath<BasePath, P>, I, O>,249 H<E, MergePath<BasePath, P>, I2, O>,250 H<E, MergePath<BasePath, P>, I3, O>251 ]248 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I3['in'], O>>, BasePath>252 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I3['in'], O>, BasePath>253254 // app.get(method, path, handler x4)255 <256 M extends string,
11 unmodified lines
268 H<E, MergePath<BasePath, P>, I2, O>,269 H<E, MergePath<BasePath, P>, I3, O>,270 H<E, MergePath<BasePath, P>, I4, O>271 ]268 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I4['in'], O>>, BasePath>272 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I4['in'], O>, BasePath>273274 // app.get(method, path, handler x5)275 <276 M extends string,
13 unmodified lines
290 H<E, MergePath<BasePath, P>, I3, O>,291 H<E, MergePath<BasePath, P>, I4, O>,292 H<E, MergePath<BasePath, P>, I5, O>293 ]290 ): Hono<E, S | Schema<M, MergePath<BasePath, P>, I5['in'], O>, BasePath>294 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I5['in'], O>, BasePath>295296 <M extends string, P extends string, O extends {} = {}, I extends Input = {}>(297 method: M,298 path: P,299 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]296 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I['in'], O>>, BasePath>300 ): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], O>, BasePath>301302 // app.on(method[], path, ...handler)303 <P extends string, O extends {} = {}, I extends Input = {}>(304 methods: string[],305 path: P,306 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]303 ): Hono<E, RemoveBlankRecord<S | Schema<string, MergePath<BasePath, P>, I['in'], O>>, BasePath>307 ): Hono<E, S & ToSchema<string, MergePath<BasePath, P>, I['in'], O>, BasePath>308}309310type ExtractKey<S> = S extends Record<infer Key, unknown>311 ? Key extends string
2 unmodified lines
314 : string315316////////////////////////////////////////317////// //////314////// Schema //////318////// ToSchema //////319////// //////320////////////////////////////////////////321318export type Schema<M extends string, P extends string, I extends Input['in'], O> = {319 [K in P]: AddDollar<{320 [K2 in M]: {322export type ToSchema<M extends string, P extends string, I extends Input['in'], O> = {323 [K in P]: {324 [K2 in M as AddDollar<string & K2>]: {325 input: unknown extends I ? AddParam<{}, P> : AddParam<I, P>326 output: unknown extends O ? {} : O327 }324 }>328 }329}330331export type Schema = {332 [Path: string]: {333 [Method: `$${Lowercase<string>}`]: {334 input: Partial<ValidationTargets> & {335 param?: Record<string, string>336 }337 output: {}338 }339 }340}341342export type MergeSchemaPath<OrigSchema, SubPath extends string> = {343 [K in keyof OrigSchema as `${SubPath}${K & string}`]: OrigSchema[K]344}345346export type AddParam<I, P extends string> = ParamKeys<P> extends never347 ? I348 : I & { param: UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>> }349331export type AddDollar<T> = T extends Record<infer K, infer R>332 ? K extends string333 ? { [MethodName in `$${Lowercase<K>}`]: R }334 : never335 : never350type AddDollar<T extends string> = `$${Lowercase<T>}`351337export type MergeSchemaPath<S, P extends string> = S extends Record<infer Key, infer T>338 ? Key extends string339 ? Record<MergePath<P, Key>, T>340 : never341 : never342352export type MergePath<A extends string, B extends string> = A extends ''353 ? B354 : A extends '/'355 ? B
102 unmodified lines