Skip to content
Myr

feat: Improve route() (#929)

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

* feat: return a sub app cloning itself from route() * feat: Add extra type parameter BasePath. * refactor: The type of hono.basePath may simply be a string. * refactor: first argument of route is required, default value is not required * chore: denoify

authored by Taku Amano · committed by GitHub · parent 86afe03 · Browse files · 10 files+248 added−86 removed
This commit

State

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

Diff stats

10 files+248 added−86 removed

  • tests:+24 added−0 removed
  • other:+224 added−86 removed

10 files+248 added−86 removed

modified:deno_dist/client/client.ts+1 added-1 removed
modified:deno_dist/client/types.ts+1 added-1 removed
modified:deno_dist/hono.ts+33 added-13 removed
16 unmodified lines
17 Next,18 NotFoundHandler,19 OnHandlerInterface,20 TypedResponse,21 MergePath,22 MergeSchemaPath,23 RemoveBlankRecord,24} from './types.ts'25import { getPathFromURL, mergePath } from './utils/url.ts'
6 unmodified lines
32 handler: H33}3435function defineDynamicClass(): {35 new <E extends Env = Env, S = {}>(): {36 [M in Methods]: HandlerInterface<E, M, S>36 new <E extends Env = Env, S = {}, BasePath extends string = ''>(): {37 [M in Methods]: HandlerInterface<E, M, S, BasePath>38 } & {38 on: OnHandlerInterface<E, S>39 on: OnHandlerInterface<E, S, BasePath>40 } & {40 use: MiddlewareHandlerInterface<E, S>41 use: MiddlewareHandlerInterface<E, S, BasePath>42 }43} {44 return class {} as never45}
10 unmodified lines
56 const message = 'Internal Server Error'57 return c.text(message, 500)58}5959export class Hono<E extends Env = Env, S = {}> extends defineDynamicClass()<E, S> {60export class Hono<61 E extends Env = Env,62 S = {},63 BasePath extends string = ''64> extends defineDynamicClass()<E, S, BasePath> {65 readonly router: Router<H> = new SmartRouter({66 routers: [new RegExpRouter(), new TrieRouter()],67 })68 readonly strict: boolean = true // strict routing - default is true64 private _tempPath: string = ''69 private basePath: string = ''70 private path: string = '*'7172 routes: RouterRoute[] = []73
47 unmodified lines
121122 Object.assign(this, init)123 }124125 private clone(): Hono<E, S, BasePath> {126 const clone = new Hono<E, S, BasePath>({127 router: this.router,128 strict: this.strict,129 })130 clone.routes = this.routes131 return clone132 }133134 private notFoundHandler: NotFoundHandler = notFoundHandler135 private errorHandler: ErrorHandler = errorHandler136137 route<SubPath extends string, SubEnv extends Env, SubSchema>(138 path: SubPath,139 app?: Hono<SubEnv, SubSchema>126 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>> {127 this._tempPath = path140 ): Hono<141 E,142 RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>,143 MergePath<BasePath, SubPath>144 > {145 const subApp = this.clone()146 subApp.basePath = mergePath(this.basePath, path)147148 if (app) {149 app.routes.map((r) => {150 const handler =151 app.errorHandler === errorHandler152 ? r.handler153 : async (c: Context, next: Next) =>154 (await compose<Context>([r.handler], app.errorHandler)(c, next)).res135 this.addRoute(r.method, r.path, handler)155 subApp.addRoute(r.method, r.path, handler)156 })137 this._tempPath = ''157 }158159 // eslint-disable-next-line @typescript-eslint/no-explicit-any140 return this as any160 return subApp as any161 }162163 onError(handler: ErrorHandler<E>) {164 this.errorHandler = handler
15 unmodified lines
180 }181182 private addRoute(method: string, path: string, handler: H) {183 method = method.toUpperCase()164 if (this._tempPath) {165 path = mergePath(this._tempPath, path)184 if (this.basePath) {185 path = mergePath(this.basePath, path)186 }187 this.router.add(method, path, handler)188 const r: RouterRoute = { path: path, method: method, handler: handler }189 this.routes.push(r)
106 unmodified lines
modified:deno_dist/types.ts+77 added-28 removed
55 unmodified lines
56////// HandlerInterface //////57////// //////58////////////////////////////////////////5960export interface HandlerInterface<E extends Env = Env, M extends string = any, S = {}> {60export interface HandlerInterface<61 E extends Env = Env,62 M extends string = any,63 S = {},64 BasePath extends string = ''65> {66 //// app.get(...handlers[])6768 // app.get(handler, handler)69 <I = {}, O = {}>(...handlers: [H<E, ExtractKey<S>, I, O>, H<E, ExtractKey<S>, I, O>]): Hono<
37 unmodified lines
107108 // app.get(path, handler, handler)109 <P extends string, O = {}, I = {}>(path: P, ...handlers: [H<E, P, I, O>, H<E, P, I, O>]): Hono<110 E,106 RemoveBlankRecord<S | Schema<M, P, I, O>>111 RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I, O>>112 >113114 // app.get(path, handler x3)115 <P extends string, O = {}, I = {}, I2 = I, I3 = I & I2>(116 path: P,112 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>]117 ...handlers: [118 H<E, MergePath<BasePath, P>, I, O>,119 H<E, MergePath<BasePath, P>, I2, O>,120 H<E, MergePath<BasePath, P>, I3, O>121 ]122 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I3, O>>>123124 // app.get(path, handler x4)125 <P extends string, O = {}, I = {}, I2 = I, I3 = I & I2, I4 = I2 & I3>(126 path: P,118 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>]127 ...handlers: [128 H<E, MergePath<BasePath, P>, I, O>,129 H<E, MergePath<BasePath, P>, I2, O>,130 H<E, MergePath<BasePath, P>, I3, O>,131 H<E, MergePath<BasePath, P>, I4, O>132 ]133 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I4, O>>>134135 // app.get(path, handler x5)136 <P extends string, O = {}, I = {}, I2 = I, I3 = I & I2, I4 = I2 & I3, I5 = I3 & I4>(137 path: P,124 ...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>]138 ...handlers: [139 H<E, MergePath<BasePath, P>, I, O>,140 H<E, MergePath<BasePath, P>, I2, O>,141 H<E, MergePath<BasePath, P>, I3, O>,142 H<E, MergePath<BasePath, P>, I4, O>,143 H<E, MergePath<BasePath, P>, I5, O>144 ]145 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I5, O>>>146147 // app.get(path, ...handlers[])128 <P extends string, I = {}, O = {}>(path: P, ...handlers: H<E, P, I, O>[]): Hono<129 E,130 RemoveBlankRecord<S | Schema<M, P, I, O>>131 >148 <P extends string, I = {}, O = {}>(149 path: P,150 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]151 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I, O>>>152}153154////////////////////////////////////////155////// //////156////// MiddlewareHandlerInterface //////157////// //////158////////////////////////////////////////159140export interface MiddlewareHandlerInterface<E extends Env = Env, S = {}> {160export interface MiddlewareHandlerInterface<161 E extends Env = Env,162 S = {},163 BasePath extends string = ''164> {165 //// app.get(...handlers[])142 (...handlers: MiddlewareHandler<E, ExtractKey<S>>[]): Hono<E, S>166 (...handlers: MiddlewareHandler<E, MergePath<BasePath, ExtractKey<S>>>[]): Hono<E, S, BasePath>167 //// app.get(path, ...handlers[])144 <P extends string>(path: P, ...handlers: MiddlewareHandler<E, P>[]): Hono<E, S>168 <P extends string>(path: P, ...handlers: MiddlewareHandler<E, MergePath<BasePath, P>>[]): Hono<169 E,170 S,171 BasePath172 >173}174175////////////////////////////////////////176////// //////177////// OnHandlerInterface //////178////// //////179////////////////////////////////////////180153export interface OnHandlerInterface<E extends Env = Env, S = {}> {181export interface OnHandlerInterface<E extends Env = Env, S = {}, BasePath extends string = ''> {182 // app.on(method, path, handler, handler)183 <M extends string, P extends string, O = {}, I = {}>(184 method: M,185 path: P,158 ...handlers: [H<E, P, I, O>, H<E, P, I, O>]159 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I, O>>>186 ...handlers: [H<E, MergePath<BasePath, P>, I, O>, H<E, MergePath<BasePath, P>, I, O>]187 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I, O>>, BasePath>188189 // app.get(method, path, handler x3)190 <M extends string, P extends string, O = {}, I = {}, I2 = I, I3 = I & I2>(191 method: M,192 path: P,165 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>]166 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I3, O>>>193 ...handlers: [194 H<E, MergePath<BasePath, P>, I, O>,195 H<E, MergePath<BasePath, P>, I2, O>,196 H<E, MergePath<BasePath, P>, I3, O>197 ]198 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I3, O>>, BasePath>199200 // app.get(method, path, handler x4)201 <M extends string, P extends string, O = {}, I = {}, I2 = I, I3 = I & I2, I4 = I2 & I3>(202 method: M,203 path: P,172 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>]173 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I4, O>>>204 ...handlers: [205 H<E, MergePath<BasePath, P>, I, O>,206 H<E, MergePath<BasePath, P>, I2, O>,207 H<E, MergePath<BasePath, P>, I3, O>,208 H<E, MergePath<BasePath, P>, I4, O>209 ]210 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I4, O>>, BasePath>211212 // app.get(method, path, handler x5)213 <214 M extends string,
6 unmodified lines
221 I5 = I3 & I4222 >(223 method: M,224 path: P,188 ...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>]189 ): Hono<E, S | Schema<M, P, I5, O>>225 ...handlers: [226 H<E, MergePath<BasePath, P>, I, O>,227 H<E, MergePath<BasePath, P>, I2, O>,228 H<E, MergePath<BasePath, P>, I3, O>,229 H<E, MergePath<BasePath, P>, I4, O>,230 H<E, MergePath<BasePath, P>, I5, O>231 ]232 ): Hono<E, S | Schema<M, MergePath<BasePath, P>, I5, O>, BasePath>233234 <M extends string, P extends string, O extends {} = {}, I = {}>(235 method: M,236 path: P,194 ...handlers: H<E, P, I, O>[]195 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I, O>>>237 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]238 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I, O>>, BasePath>239240 // app.on(method[], path, ...handler)241 <P extends string, O extends {} = {}, I = {}>(242 methods: string[],243 path: P,201 ...handlers: H<E, P, I, O>[]202 ): Hono<E, RemoveBlankRecord<S | Schema<string, P, I, O>>>244 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]245 ): Hono<E, RemoveBlankRecord<S | Schema<string, MergePath<BasePath, P>, I, O>>, BasePath>246}247248type ExtractKey<S> = S extends Record<infer Key, unknown>249 ? Key extends string
26 unmodified lines
276 ? Record<MergePath<P, Key>, T>277 : never278 : never279237export type MergePath<A extends string, B extends string> = A extends `${infer P}/`238 ? `${P}${B}`239 : `${A}${B}`280export type MergePath<A extends string, B extends string> = A extends ''281 ? B282 : A extends `${infer P}/`283 ? B extends `/${infer Q}`284 ? `${P}/${Q}`285 : `${P}/${B}`286 : B extends `/${infer Q}`287 ? `${A}/${Q}`288 : `${A}/${B}`289290////////////////////////////////////////291////// //////292////// TypedResponse //////
77 unmodified lines
modified:src/client/client.test.ts+11 added
319 unmodified lines
320 type verify = Expect<Equal<boolean, typeof data.ok>>321 expect(data.ok).toBe(true)322 })323324 it('Should have correct types - route() then get()', async () => {325 const base = new Hono<Env>().route('/api')326 const app = base.get('/search', (c) => c.jsonT({ ok: true }))327 type AppType = typeof app328 const client = hc<AppType>('http://localhost')329 const res = await client.api.search.$get()330 const data = await res.json()331 type verify = Expect<Equal<boolean, typeof data.ok>>332 expect(data.ok).toBe(true)333 })334335 describe('Multiple endpoints', () => {336 const api = new Hono()337 .get('/foo', (c) => c.jsonT({ foo: '' }))338 .post('/bar', (c) => c.jsonT({ bar: 0 }))
44 unmodified lines
modified:src/client/client.ts+1 added-1 removed
99 unmodified lines
100 }101}102103// eslint-disable-next-line @typescript-eslint/no-explicit-any104export const hc = <T extends Hono<any>>(baseUrl: string, options?: RequestOptions) =>104export const hc = <T extends Hono<any, any, any>>(baseUrl: string, options?: RequestOptions) =>105 createProxy(async (opts) => {106 const parts = [...opts.path]107108 let method = ''
17 unmodified lines
modified:src/client/types.ts+1 added-1 removed
50 unmodified lines
51 >52 }5354// eslint-disable-next-line @typescript-eslint/no-explicit-any55export type Client<T> = T extends Hono<any, infer S>55export type Client<T> = T extends Hono<any, infer S, any>56 ? S extends Record<infer K, Endpoint>57 ? K extends string58 ? PathToChain<K, S>59 : never
14 unmodified lines
modified:src/hono.test.ts+13 added
174 unmodified lines
175 const user = app.route('/user')176 user.get('/login', (c) => c.text('get /user/login'))177 user.post('/register', (c) => c.text('post /user/register'))178179 const appForEachUser = user.route(':id')180 appForEachUser.get('/profile', (c) => c.text('get /user/' + c.req.param('id') + '/profile'))181182 app.get('/add-path-after-route-call', (c) => c.text('get /add-path-after-route-call'))183184 let res = await app.request('http://localhost/book', { method: 'GET' })185 expect(res.status).toBe(200)186 expect(await res.text()).toBe('get /book')187
14 unmodified lines
202203 res = await app.request('http://localhost/user/register', { method: 'POST' })204 expect(res.status).toBe(200)205 expect(await res.text()).toBe('post /user/register')206207 res = await app.request('http://localhost/user/123/profile', { method: 'GET' })208 expect(res.status).toBe(200)209 expect(await res.text()).toBe('get /user/123/profile')210211 res = await app.request('http://localhost/add-path-after-route-call', { method: 'GET' })212 expect(res.status).toBe(200)213 expect(await res.text()).toBe('get /add-path-after-route-call')214 })215216 describe('Nested route with middleware', () => {217 const api = new Hono()
1520 unmodified lines
modified:src/hono.ts+33 added-13 removed
16 unmodified lines
17 Next,18 NotFoundHandler,19 OnHandlerInterface,20 TypedResponse,21 MergePath,22 MergeSchemaPath,23 RemoveBlankRecord,24} from './types'25import { getPathFromURL, mergePath } from './utils/url'
6 unmodified lines
32 handler: H33}3435function defineDynamicClass(): {35 new <E extends Env = Env, S = {}>(): {36 [M in Methods]: HandlerInterface<E, M, S>36 new <E extends Env = Env, S = {}, BasePath extends string = ''>(): {37 [M in Methods]: HandlerInterface<E, M, S, BasePath>38 } & {38 on: OnHandlerInterface<E, S>39 on: OnHandlerInterface<E, S, BasePath>40 } & {40 use: MiddlewareHandlerInterface<E, S>41 use: MiddlewareHandlerInterface<E, S, BasePath>42 }43} {44 return class {} as never45}
10 unmodified lines
56 const message = 'Internal Server Error'57 return c.text(message, 500)58}5959export class Hono<E extends Env = Env, S = {}> extends defineDynamicClass()<E, S> {60export class Hono<61 E extends Env = Env,62 S = {},63 BasePath extends string = ''64> extends defineDynamicClass()<E, S, BasePath> {65 readonly router: Router<H> = new SmartRouter({66 routers: [new RegExpRouter(), new TrieRouter()],67 })68 readonly strict: boolean = true // strict routing - default is true64 private _tempPath: string = ''69 private basePath: string = ''70 private path: string = '*'7172 routes: RouterRoute[] = []73
47 unmodified lines
121122 Object.assign(this, init)123 }124125 private clone(): Hono<E, S, BasePath> {126 const clone = new Hono<E, S, BasePath>({127 router: this.router,128 strict: this.strict,129 })130 clone.routes = this.routes131 return clone132 }133134 private notFoundHandler: NotFoundHandler = notFoundHandler135 private errorHandler: ErrorHandler = errorHandler136137 route<SubPath extends string, SubEnv extends Env, SubSchema>(138 path: SubPath,139 app?: Hono<SubEnv, SubSchema>126 ): Hono<E, RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>> {127 this._tempPath = path140 ): Hono<141 E,142 RemoveBlankRecord<MergeSchemaPath<SubSchema, SubPath> | S>,143 MergePath<BasePath, SubPath>144 > {145 const subApp = this.clone()146 subApp.basePath = mergePath(this.basePath, path)147148 if (app) {149 app.routes.map((r) => {150 const handler =151 app.errorHandler === errorHandler152 ? r.handler153 : async (c: Context, next: Next) =>154 (await compose<Context>([r.handler], app.errorHandler)(c, next)).res135 this.addRoute(r.method, r.path, handler)155 subApp.addRoute(r.method, r.path, handler)156 })137 this._tempPath = ''157 }158159 // eslint-disable-next-line @typescript-eslint/no-explicit-any140 return this as any160 return subApp as any161 }162163 onError(handler: ErrorHandler<E>) {164 this.errorHandler = handler
15 unmodified lines
180 }181182 private addRoute(method: string, path: string, handler: H) {183 method = method.toUpperCase()164 if (this._tempPath) {165 path = mergePath(this._tempPath, path)184 if (this.basePath) {185 path = mergePath(this.basePath, path)186 }187 this.router.add(method, path, handler)188 const r: RouterRoute = { path: path, method: method, handler: handler }189 this.routes.push(r)
106 unmodified lines
modified:src/types.ts+77 added-28 removed
55 unmodified lines
56////// HandlerInterface //////57////// //////58////////////////////////////////////////5960export interface HandlerInterface<E extends Env = Env, M extends string = any, S = {}> {60export interface HandlerInterface<61 E extends Env = Env,62 M extends string = any,63 S = {},64 BasePath extends string = ''65> {66 //// app.get(...handlers[])6768 // app.get(handler, handler)69 <I = {}, O = {}>(...handlers: [H<E, ExtractKey<S>, I, O>, H<E, ExtractKey<S>, I, O>]): Hono<
37 unmodified lines
107108 // app.get(path, handler, handler)109 <P extends string, O = {}, I = {}>(path: P, ...handlers: [H<E, P, I, O>, H<E, P, I, O>]): Hono<110 E,106 RemoveBlankRecord<S | Schema<M, P, I, O>>111 RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I, O>>112 >113114 // app.get(path, handler x3)115 <P extends string, O = {}, I = {}, I2 = I, I3 = I & I2>(116 path: P,112 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>]117 ...handlers: [118 H<E, MergePath<BasePath, P>, I, O>,119 H<E, MergePath<BasePath, P>, I2, O>,120 H<E, MergePath<BasePath, P>, I3, O>121 ]122 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I3, O>>>123124 // app.get(path, handler x4)125 <P extends string, O = {}, I = {}, I2 = I, I3 = I & I2, I4 = I2 & I3>(126 path: P,118 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>]127 ...handlers: [128 H<E, MergePath<BasePath, P>, I, O>,129 H<E, MergePath<BasePath, P>, I2, O>,130 H<E, MergePath<BasePath, P>, I3, O>,131 H<E, MergePath<BasePath, P>, I4, O>132 ]133 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I4, O>>>134135 // app.get(path, handler x5)136 <P extends string, O = {}, I = {}, I2 = I, I3 = I & I2, I4 = I2 & I3, I5 = I3 & I4>(137 path: P,124 ...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>]138 ...handlers: [139 H<E, MergePath<BasePath, P>, I, O>,140 H<E, MergePath<BasePath, P>, I2, O>,141 H<E, MergePath<BasePath, P>, I3, O>,142 H<E, MergePath<BasePath, P>, I4, O>,143 H<E, MergePath<BasePath, P>, I5, O>144 ]145 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I5, O>>>146147 // app.get(path, ...handlers[])128 <P extends string, I = {}, O = {}>(path: P, ...handlers: H<E, P, I, O>[]): Hono<129 E,130 RemoveBlankRecord<S | Schema<M, P, I, O>>131 >148 <P extends string, I = {}, O = {}>(149 path: P,150 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]151 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I, O>>>152}153154////////////////////////////////////////155////// //////156////// MiddlewareHandlerInterface //////157////// //////158////////////////////////////////////////159140export interface MiddlewareHandlerInterface<E extends Env = Env, S = {}> {160export interface MiddlewareHandlerInterface<161 E extends Env = Env,162 S = {},163 BasePath extends string = ''164> {165 //// app.get(...handlers[])142 (...handlers: MiddlewareHandler<E, ExtractKey<S>>[]): Hono<E, S>166 (...handlers: MiddlewareHandler<E, MergePath<BasePath, ExtractKey<S>>>[]): Hono<E, S, BasePath>167 //// app.get(path, ...handlers[])144 <P extends string>(path: P, ...handlers: MiddlewareHandler<E, P>[]): Hono<E, S>168 <P extends string>(path: P, ...handlers: MiddlewareHandler<E, MergePath<BasePath, P>>[]): Hono<169 E,170 S,171 BasePath172 >173}174175////////////////////////////////////////176////// //////177////// OnHandlerInterface //////178////// //////179////////////////////////////////////////180153export interface OnHandlerInterface<E extends Env = Env, S = {}> {181export interface OnHandlerInterface<E extends Env = Env, S = {}, BasePath extends string = ''> {182 // app.on(method, path, handler, handler)183 <M extends string, P extends string, O = {}, I = {}>(184 method: M,185 path: P,158 ...handlers: [H<E, P, I, O>, H<E, P, I, O>]159 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I, O>>>186 ...handlers: [H<E, MergePath<BasePath, P>, I, O>, H<E, MergePath<BasePath, P>, I, O>]187 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I, O>>, BasePath>188189 // app.get(method, path, handler x3)190 <M extends string, P extends string, O = {}, I = {}, I2 = I, I3 = I & I2>(191 method: M,192 path: P,165 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>]166 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I3, O>>>193 ...handlers: [194 H<E, MergePath<BasePath, P>, I, O>,195 H<E, MergePath<BasePath, P>, I2, O>,196 H<E, MergePath<BasePath, P>, I3, O>197 ]198 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I3, O>>, BasePath>199200 // app.get(method, path, handler x4)201 <M extends string, P extends string, O = {}, I = {}, I2 = I, I3 = I & I2, I4 = I2 & I3>(202 method: M,203 path: P,172 ...handlers: [H<E, P, I, O>, H<E, P, I2, O>, H<E, P, I3, O>, H<E, P, I4, O>]173 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I4, O>>>204 ...handlers: [205 H<E, MergePath<BasePath, P>, I, O>,206 H<E, MergePath<BasePath, P>, I2, O>,207 H<E, MergePath<BasePath, P>, I3, O>,208 H<E, MergePath<BasePath, P>, I4, O>209 ]210 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I4, O>>, BasePath>211212 // app.get(method, path, handler x5)213 <214 M extends string,
6 unmodified lines
221 I5 = I3 & I4222 >(223 method: M,224 path: P,188 ...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>]189 ): Hono<E, S | Schema<M, P, I5, O>>225 ...handlers: [226 H<E, MergePath<BasePath, P>, I, O>,227 H<E, MergePath<BasePath, P>, I2, O>,228 H<E, MergePath<BasePath, P>, I3, O>,229 H<E, MergePath<BasePath, P>, I4, O>,230 H<E, MergePath<BasePath, P>, I5, O>231 ]232 ): Hono<E, S | Schema<M, MergePath<BasePath, P>, I5, O>, BasePath>233234 <M extends string, P extends string, O extends {} = {}, I = {}>(235 method: M,236 path: P,194 ...handlers: H<E, P, I, O>[]195 ): Hono<E, RemoveBlankRecord<S | Schema<M, P, I, O>>>237 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]238 ): Hono<E, RemoveBlankRecord<S | Schema<M, MergePath<BasePath, P>, I, O>>, BasePath>239240 // app.on(method[], path, ...handler)241 <P extends string, O extends {} = {}, I = {}>(242 methods: string[],243 path: P,201 ...handlers: H<E, P, I, O>[]202 ): Hono<E, RemoveBlankRecord<S | Schema<string, P, I, O>>>244 ...handlers: H<E, MergePath<BasePath, P>, I, O>[]245 ): Hono<E, RemoveBlankRecord<S | Schema<string, MergePath<BasePath, P>, I, O>>, BasePath>246}247248type ExtractKey<S> = S extends Record<infer Key, unknown>249 ? Key extends string
26 unmodified lines
276 ? Record<MergePath<P, Key>, T>277 : never278 : never279237export type MergePath<A extends string, B extends string> = A extends `${infer P}/`238 ? `${P}${B}`239 : `${A}${B}`280export type MergePath<A extends string, B extends string> = A extends ''281 ? B282 : A extends `${infer P}/`283 ? B extends `/${infer Q}`284 ? `${P}/${Q}`285 : `${P}/${B}`286 : B extends `/${infer Q}`287 ? `${A}/${Q}`288 : `${A}/${B}`289290////////////////////////////////////////291////// //////292////// TypedResponse //////
77 unmodified lines