/** * @module * This module contains some type definitions for the Hono modules. */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ import type { Context } from './context' import type { Hono } from './hono' import type { StatusCode } from './utils/http-status' import type { IfAnyThenEmptyObject, IsAny, JSONValue, RemoveBlankRecord, Simplify, UnionToIntersection, } from './utils/types' //////////////////////////////////////// ////// ////// ////// Values ////// ////// ////// //////////////////////////////////////// export type Bindings = object export type Variables = object export type BlankEnv = {} export type Env = { Bindings?: Bindings Variables?: Variables } export type Next = () => Promise export type ExtractInput = I extends Input ? unknown extends I['in'] ? {} : I['in'] : I export type Input = { in?: {} out?: {} outputFormat?: ResponseFormat } export type BlankSchema = {} export type BlankInput = {} //////////////////////////////////////// ////// ////// ////// Routes ////// ////// ////// //////////////////////////////////////// export interface RouterRoute { path: string method: string handler: H } //////////////////////////////////////// ////// ////// ////// Handlers ////// ////// ////// //////////////////////////////////////// export type HandlerResponse = Response | TypedResponse | Promise> export type Handler< E extends Env = any, P extends string = any, I extends Input = BlankInput, R extends HandlerResponse = any > = (c: Context, next: Next) => R export type MiddlewareHandler< E extends Env = any, P extends string = string, I extends Input = {} > = (c: Context, next: Next) => Promise export type H< E extends Env = any, P extends string = any, I extends Input = BlankInput, R extends HandlerResponse = any > = Handler | MiddlewareHandler export type NotFoundHandler = (c: Context) => Response | Promise export interface HTTPResponseError extends Error { getResponse: () => Response } export type ErrorHandler = ( err: Error | HTTPResponseError, c: Context ) => Response | Promise //////////////////////////////////////// ////// ////// ////// HandlerInterface ////// ////// ////// //////////////////////////////////////// export interface HandlerInterface< E extends Env = Env, M extends string = string, S extends Schema = BlankSchema, BasePath extends string = '/' > { // app.get(handler) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, I extends Input = BlankInput, R extends HandlerResponse = any, E2 extends Env = E >( handler: H ): Hono, S & ToSchema>, BasePath> // app.get(handler x2) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, I extends Input = BlankInput, I2 extends Input = I, R extends HandlerResponse = any, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]> >( ...handlers: [H, H] ): Hono< IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema>, BasePath > // app.get(path, handler) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, E2 extends Env = E >( path: P, handler: H ): Hono, I, MergeTypedResponse>, BasePath> // app.get(handler x 3) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, R extends HandlerResponse = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, E2 extends Env = E, E3 extends Env = E, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]> >( ...handlers: [H, H, H] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4]>, S & ToSchema>, BasePath > // app.get(path, handler x2) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, I2 extends Input = I, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]> >( path: P, ...handlers: [H, H] ): Hono, I2, MergeTypedResponse>, BasePath> // app.get(handler x 4) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]> >( ...handlers: [H, H, H, H] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S & ToSchema>, BasePath > // app.get(path, handler x3) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, E2 extends Env = E, E3 extends Env = E, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]> >( path: P, ...handlers: [H, H, H] ): Hono, I3, MergeTypedResponse>, BasePath> // app.get(handler x 5) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]> >( ...handlers: [H, H, H, H, H] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S & ToSchema>, BasePath > // app.get(path, handler x4) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]> >( path: P, ...handlers: [ H, H, H, H ] ): Hono, I4, MergeTypedResponse>, BasePath> // app.get(handler x 6) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]> >( ...handlers: [ H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S & ToSchema>, BasePath > // app.get(path, handler x5) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]> >( path: P, ...handlers: [ H, H, H, H, H ] ): Hono, I5, MergeTypedResponse>, BasePath> // app.get(handler x 7) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]> >( ...handlers: [ H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S & ToSchema>, BasePath > // app.get(path, handler x6) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]> >( path: P, ...handlers: [ H, H, H, H, H, H ] ): Hono, I6, MergeTypedResponse>, BasePath> // app.get(handler x 8) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]> >( ...handlers: [ H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S & ToSchema>, BasePath > // app.get(path, handler x7) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]> >( path: P, ...handlers: [ H, H, H, H, H, H, H ] ): Hono, I7, MergeTypedResponse>, BasePath> // app.get(handler x 9) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]> >( ...handlers: [ H, H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S & ToSchema>, BasePath > // app.get(path, handler x8) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]> >( path: P, ...handlers: [ H, H, H, H, H, H, H, H ] ): Hono, I8, MergeTypedResponse>, BasePath> // app.get(handler x 10) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = E, E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]> >( ...handlers: [ H, H, H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema>, BasePath > // app.get(path, handler x9) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]> >( path: P, ...handlers: [ H, H, H, H, H, H, H, H, H ] ): Hono, I9, MergeTypedResponse>, BasePath> // app.get(path, handler x10) < P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = E, E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]> >( path: P, ...handlers: [ H, H, H, H, H, H, H, H, H, H ] ): Hono, I10, MergeTypedResponse>, BasePath> // app.get(...handlers[]) < P extends string = ExtractStringKey extends never ? BasePath : ExtractStringKey, I extends Input = BlankInput, R extends HandlerResponse = any >( ...handlers: H[] ): Hono>, BasePath> // app.get(path, ...handlers[])

= any>( path: P, ...handlers: H, I, R>[] ): Hono, I, MergeTypedResponse>, BasePath> // app.get(path)

= any, I extends Input = BlankInput>( path: P ): Hono, I, MergeTypedResponse>, BasePath> } //////////////////////////////////////// ////// ////// ////// MiddlewareHandlerInterface ////// ////// ////// //////////////////////////////////////// export interface MiddlewareHandlerInterface< E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = '/' > { //// app.use(...handlers[]) ( ...handlers: MiddlewareHandler>>[] ): Hono, S, BasePath> // app.use(handler) ( handler: MiddlewareHandler>> ): Hono, S, BasePath> // app.use(handler x2) < E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]>, P extends string = MergePath> >( ...handlers: [MiddlewareHandler, MiddlewareHandler] ): Hono, S, BasePath> // app.get(path, handler) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E >( path: P, handler: MiddlewareHandler ): Hono, ChangePathOfSchema, BasePath> // app.use(handler x3) < E2 extends Env = E, E3 extends Env = E, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>, P extends string = MergePath> >( ...handlers: [MiddlewareHandler, MiddlewareHandler, MiddlewareHandler] ): Hono, S, BasePath> // app.get(path, handler x2) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]> >( path: P, ...handlers: [MiddlewareHandler, MiddlewareHandler] ): Hono, ChangePathOfSchema, BasePath> // app.use(handler x4) < E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>, P extends string = MergePath> >( ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono, S, BasePath> // app.get(path, handler x3) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E, E3 extends Env = E, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]> >( path: P, ...handlers: [MiddlewareHandler, MiddlewareHandler, MiddlewareHandler] ): Hono, ChangePathOfSchema, BasePath> // app.use(handler x5) < E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, P extends string = MergePath> >( ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono, S, BasePath> // app.get(path, handler x4) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]> >( path: P, ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono, ChangePathOfSchema, BasePath> // app.use(handler x6) < E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, P extends string = MergePath> >( ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono, S, BasePath> // app.get(path, handler x5) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]> >( path: P, ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, ChangePathOfSchema, BasePath > // app.use(handler x7) < E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, P extends string = MergePath> >( ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono, S, BasePath> // app.get(path, handler x6) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]> >( path: P, ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, ChangePathOfSchema, BasePath > // app.use(handler x8) < E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, P extends string = MergePath> >( ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono, S, BasePath> // app.get(path, handler x7) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]> >( path: P, ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, ChangePathOfSchema, BasePath > // app.use(handler x9) < E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, P extends string = MergePath> >( ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono, S, BasePath> // app.get(path, handler x8) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]> >( path: P, ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, ChangePathOfSchema, BasePath > // app.use(handler x10) < E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = E, E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, P extends string = MergePath> >( ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono, S, BasePath> // app.get(path, handler x9) < P extends string, MergedPath extends MergePath = MergePath, E2 extends Env = E, E3 extends Env = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]> >( path: P, ...handlers: [ MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler, MiddlewareHandler ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, ChangePathOfSchema, BasePath > //// app.use(path, ...handlers[])

( path: P, ...handlers: MiddlewareHandler>[] ): Hono } //////////////////////////////////////// ////// ////// ////// OnHandlerInterface ////// ////// ////// //////////////////////////////////////// export interface OnHandlerInterface< E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = '/' > { // app.on(method, path, handler) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, E2 extends Env = E >( method: M, path: P, handler: H ): Hono< IntersectNonAnyTypes<[E, E2]>, S & ToSchema, I, MergeTypedResponse>, BasePath > // app.on(method, path, handler x2) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, I2 extends Input = I, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]> >( method: M, path: P, ...handlers: [H, H] ): Hono< IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema, I2, MergeTypedResponse>, BasePath > // app.on(method, path, handler x3) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, E2 extends Env = E, E3 extends Env = E, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]> >( method: M, path: P, ...handlers: [H, H, H] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4]>, S & ToSchema, I3, MergeTypedResponse>, BasePath > // app.on(method, path, handler x4) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]> >( method: M, path: P, ...handlers: [ H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S & ToSchema, I4, MergeTypedResponse>, BasePath > // app.on(method, path, handler x5) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]> >( method: M, path: P, ...handlers: [ H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S & ToSchema, I5, MergeTypedResponse>, BasePath > // app.on(method, path, handler x6) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]> >( method: M, path: P, ...handlers: [ H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S & ToSchema, I6, MergeTypedResponse>, BasePath > // app.on(method, path, handler x7) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]> >( method: M, path: P, ...handlers: [ H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S & ToSchema, I7, MergeTypedResponse>, BasePath > // app.on(method, path, handler x8) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]> >( method: M, path: P, ...handlers: [ H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S & ToSchema, I8, MergeTypedResponse>, BasePath > // app.on(method, path, handler x9) < M extends string, P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]> >( method: M, path: P, ...handlers: [ H, H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S & ToSchema, I9, MergeTypedResponse>, BasePath > // app.on(method, path, handler x10) < M extends string, P extends string, MergedPath extends MergePath = MergePath, 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = E, E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]> >( method: M, path: P, ...handlers: [ H, H, H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema, I10, MergeTypedResponse>>, BasePath > // app.get(method, path, ...handler) < M extends string, P extends string, R extends HandlerResponse = any, I extends Input = BlankInput >( method: M, path: P, ...handlers: H, I, R>[] ): Hono, I, MergeTypedResponse>, BasePath> // app.get(method[], path, handler) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, E2 extends Env = E >( methods: Ms, path: P, handler: H ): Hono< IntersectNonAnyTypes<[E, E2]>, S & ToSchema, I, MergeTypedResponse>, BasePath > // app.get(method[], path, handler x2) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, I2 extends Input = I, E2 extends Env = E, E3 extends Env = IntersectNonAnyTypes<[E, E2]> >( methods: Ms, path: P, ...handlers: [H, H] ): Hono< IntersectNonAnyTypes<[E, E2, E3]>, S & ToSchema, I2, MergeTypedResponse>, BasePath > // app.get(method[], path, handler x3) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = any, I extends Input = BlankInput, I2 extends Input = I, I3 extends Input = I & I2, E2 extends Env = E, E3 extends Env = E, E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]> >( methods: Ms, path: P, ...handlers: [H, H, H] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4]>, S & ToSchema, I3, MergeTypedResponse>, BasePath > // app.get(method[], path, handler x4) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]> >( methods: Ms, path: P, ...handlers: [ H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S & ToSchema, I4, MergeTypedResponse>, BasePath > // app.get(method[], path, handler x5) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]> >( methods: Ms, path: P, ...handlers: [ H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S & ToSchema, I5, MergeTypedResponse>, BasePath > // app.get(method[], path, handler x6) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]> >( methods: Ms, path: P, ...handlers: [ H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S & ToSchema, I6, MergeTypedResponse>, BasePath > // app.get(method[], path, handler x7) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]> >( methods: Ms, path: P, ...handlers: [ H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S & ToSchema, I7, MergeTypedResponse>, BasePath > // app.get(method[], path, handler x8) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, R extends HandlerResponse = 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]> >( methods: Ms, path: P, ...handlers: [ H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S & ToSchema, I8, MergeTypedResponse>, BasePath > // app.get(method[], path, handler x9) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]> >( methods: Ms, path: P, ...handlers: [ H, H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S & ToSchema, I9, MergeTypedResponse>>, BasePath > // app.get(method[], path, handler x10) < Ms extends string[], P extends string, MergedPath extends MergePath = MergePath, 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 = E, E4 extends Env = E, E5 extends Env = E, E6 extends Env = E, E7 extends Env = E, E8 extends Env = E, E9 extends Env = E, E10 extends Env = E, E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]> >( methods: Ms, path: P, ...handlers: [ H, H, H, H, H, H, H, H, H, H ] ): Hono< IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S & ToSchema, I10, MergeTypedResponse>>, BasePath > // app.on(method[], path, ...handler)

= any, I extends Input = BlankInput>( methods: string[], path: P, ...handlers: H, I, R>[] ): Hono, I, MergeTypedResponse>, BasePath> // app.on(method | method[], path[], ...handlers[]) = any>( methods: string | string[], paths: string[], ...handlers: H[] ): Hono>, BasePath> } type ExtractStringKey = keyof S & string //////////////////////////////////////// ////// ////// ////// ToSchema ////// ////// ////// //////////////////////////////////////// export type ToSchema< M extends string, P extends string, I extends Input | Input['in'], RorO // Response or Output > = Simplify<{ [K in P]: { [K2 in M as AddDollar]: Simplify< { input: AddParam, P> } & (IsAny extends true ? { output: {} outputFormat: ResponseFormat status: StatusCode } : RorO extends TypedResponse ? { output: unknown extends T ? {} : T outputFormat: I extends { outputFormat: string } ? I['outputFormat'] : F status: U } : { output: unknown extends RorO ? {} : RorO outputFormat: unknown extends RorO ? 'json' : I extends { outputFormat: string } ? I['outputFormat'] : 'json' status: StatusCode }) > } }> export type Schema = { [Path: string]: { [Method: `$${Lowercase}`]: Endpoint } } type ChangePathOfSchema = keyof S extends never ? { [K in Path]: {} } : { [K in keyof S as Path]: S[K] } export type Endpoint = { input: any output: any outputFormat: ResponseFormat status: StatusCode } type ExtractParams = string extends Path ? Record : Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof ExtractParams<`/${Rest}`>]: string } : Path extends `${infer _Start}:${infer Param}` ? { [K in Param]: string } : never type FlattenIfIntersect = T extends infer O ? { [K in keyof O]: O[K] } : never export type MergeSchemaPath = { [P in keyof OrigSchema as MergePath]: [OrigSchema[P]] extends [ Record ] ? { [M in keyof OrigSchema[P]]: MergeEndpointParamsWithPath } : never } type MergeEndpointParamsWithPath = T extends unknown ? { input: T['input'] extends { param: infer _ } ? ExtractParams extends never ? T['input'] : FlattenIfIntersect< T['input'] & { param: { // Maps extracted keys, stripping braces, to a string-typed record. [K in keyof ExtractParams as K extends `${infer Prefix}{${infer _}}` ? Prefix : K]: string } } > : RemoveBlankRecord> extends never ? T['input'] : T['input'] & { // Maps extracted keys, stripping braces, to a string-typed record. param: { [K in keyof ExtractParams as K extends `${infer Prefix}{${infer _}}` ? Prefix : K]: string } } output: T['output'] outputFormat: T['outputFormat'] status: T['status'] } : never export type AddParam = ParamKeys

extends never ? I : I extends { param: infer _ } ? I : I & { param: UnionToIntersection>> } type AddDollar = `$${Lowercase}` export type MergePath = B extends '' ? MergePath : A extends '' ? B : A extends '/' ? B : A extends `${infer P}/` ? B extends `/${infer Q}` ? `${P}/${Q}` : `${P}/${B}` : B extends `/${infer Q}` ? Q extends '' ? A : `${A}/${Q}` : `${A}/${B}` //////////////////////////////////////// ////// ////// ////// TypedResponse ////// ////// ////// //////////////////////////////////////// export type KnownResponseFormat = 'json' | 'text' | 'redirect' export type ResponseFormat = KnownResponseFormat | string export type TypedResponse< T = unknown, U extends StatusCode = StatusCode, F extends ResponseFormat = T extends string ? 'text' : T extends JSONValue ? 'json' : ResponseFormat > = { _data: T _status: U _format: F } type MergeTypedResponse = T extends Promise ? T2 extends TypedResponse ? T2 : TypedResponse : T extends TypedResponse ? T : TypedResponse //////////////////////////////////////// ////// ///// ////// ValidationTargets ///// ////// ///// //////////////////////////////////////// export type FormValue = string | Blob export type ParsedFormValue = string | File export type ValidationTargets = { json: any form: Record query: Record param: Record header: Record cookie: Record } //////////////////////////////////////// ////// ////// ////// Path parameters ////// ////// ////// //////////////////////////////////////// type ParamKeyName = NameWithPattern extends `${infer Name}{${infer Rest}` ? Rest extends `${infer _Pattern}?` ? `${Name}?` : Name : NameWithPattern type ParamKey = Component extends `:${infer NameWithPattern}` ? ParamKeyName : never export type ParamKeys = Path extends `${infer Component}/${infer Rest}` ? ParamKey | ParamKeys : ParamKey export type ParamKeyToRecord = T extends `${infer R}?` ? Record : { [K in T]: string } //////////////////////////////////////// ////// ////// ///// For HonoRequest ////// ////// ////// //////////////////////////////////////// export type InputToDataByTarget< T extends Input['out'], Target extends keyof ValidationTargets > = T extends { [K in Target]: infer R } ? R : never export type RemoveQuestion = T extends `${infer R}?` ? R : T //////////////////////////////////////// ////// ////// ////// Utilities ////// ////// ////// //////////////////////////////////////// export type ExtractSchema = UnionToIntersection< T extends Hono ? S : never > type EnvOrEmpty = T extends Env ? (Env extends T ? {} : T) : T type IntersectNonAnyTypes = T extends [infer Head, ...infer Rest] ? IfAnyThenEmptyObject> & IntersectNonAnyTypes : {} //////////////////////////////////////// ////// ////// ////// FetchEvent ////// ////// ////// //////////////////////////////////////// export abstract class FetchEventLike { abstract readonly request: Request abstract respondWith(promise: Response | Promise): void abstract passThroughOnException(): void abstract waitUntil(promise: Promise): void }