Skip to content
Myr

fix(types): replace schema-based path tracking with CurrentPath parameter (#4552)

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

* fix(types): correct types when middleware return Promise<void> * udpate tests * pass tests * support multiple middleware * perf * refactor(types): replace schema-based path tracking with CurrentPath parameter * refactor(types): remove unused ChangePathOfSchema type * fix(types): replace CurrentPath with VoidMiddlewarePath in Hono and Handler interfaces * refactor(types): rename AddSchemaOrPath to AddSchemaIfHasResponse in HandlerInterface * update tests * update tests * Revert "fix(types): replace CurrentPath with VoidMiddlewarePath in Hono and Handler interfaces" This reverts commit ef72a7471708bc11acd6f52c70ba3406491c517f. * update tests * fix(types): simplify AddSchemaIfHasResponse type definition * fix comments * fix(types): update MiddlewareHandlerInterface to use '*' for pathless middlewares * fix(types): use last path as CurrentPath in OnHandlerInterface with multiple paths * fix(types): remove CurrentPath from OnHandlerInterface * fix(types): remove CurrentPath from MiddlewareHandlerInterface --------- Co-authored-by: Yusuke Wada <yusuke@kamawada.com> Fixes #4517

authored by kosei28 · committed by GitHub · parent 6d62638 · Browse files · 4 files+741 added−302 removed
This commit

State

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

Diff stats

4 files+741 added−302 removed

  • tests:+343 added−8 removed
  • other:+398 added−294 removed

4 files+741 added−302 removed

modified:src/helper/factory/index.test.ts+2 added-4 removed
381 unmodified lines
382 })383 })384385 describe('createMiddleware', () => {386 it('Should set the correct type', () => {386 it('Should omit the `*` wildcard from the generated schema', () => {387 const factory = createFactory()388389 const middleware = factory.createMiddleware(async (_, next) => {390 await next()391 })392393 const routes = new Hono().use('*', middleware)394 type Actual = ExtractSchema<typeof routes>395 type Expected = {396 '*': {}397 }395 type Expected = {}396 type verify = Expect<Equal<Expected, Actual>>397 })398399 it('Should default to MiddlewareHandler<E, P, I, Response>', async () => {
35 unmodified lines
modified:src/hono-base.ts+24 added-16 removed
93 unmodified lines
94 optionHandler?: MountOptionHandler95 replaceRequest?: MountReplaceRequest | false96 }9798class Hono<99 E extends Env = Env,100 S extends Schema = {},101 BasePath extends string = '/',102 CurrentPath extends string = BasePath,98class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends string = '/'> {99 get!: HandlerInterface<E, 'get', S, BasePath>100 post!: HandlerInterface<E, 'post', S, BasePath>101 put!: HandlerInterface<E, 'put', S, BasePath>102 delete!: HandlerInterface<E, 'delete', S, BasePath>103 options!: HandlerInterface<E, 'options', S, BasePath>104 patch!: HandlerInterface<E, 'patch', S, BasePath>105 all!: HandlerInterface<E, 'all', S, BasePath>103> {104 get!: HandlerInterface<E, 'get', S, BasePath, CurrentPath>105 post!: HandlerInterface<E, 'post', S, BasePath, CurrentPath>106 put!: HandlerInterface<E, 'put', S, BasePath, CurrentPath>107 delete!: HandlerInterface<E, 'delete', S, BasePath, CurrentPath>108 options!: HandlerInterface<E, 'options', S, BasePath, CurrentPath>109 patch!: HandlerInterface<E, 'patch', S, BasePath, CurrentPath>110 all!: HandlerInterface<E, 'all', S, BasePath, CurrentPath>111 on: OnHandlerInterface<E, S, BasePath>112 use: MiddlewareHandlerInterface<E, S, BasePath>113114 /*
56 unmodified lines
171 Object.assign(this, optionsWithoutStrict)172 this.getPath = (strict ?? true) ? (options.getPath ?? getPath) : getPathNoStrict173 }174170 #clone(): Hono<E, S, BasePath> {171 const clone = new Hono<E, S, BasePath>({175 #clone(): Hono<E, S, BasePath, CurrentPath> {176 const clone = new Hono<E, S, BasePath, CurrentPath>({177 router: this.router,178 getPath: this.getPath,179 })180 clone.errorHandler = this.errorHandler
28 unmodified lines
209 SubPath extends string,210 SubEnv extends Env,211 SubSchema extends Schema,212 SubBasePath extends string,213 SubCurrentPath extends string,214 >(215 path: SubPath,210 app: Hono<SubEnv, SubSchema, SubBasePath>211 ): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> | S, BasePath> {216 app: Hono<SubEnv, SubSchema, SubBasePath, SubCurrentPath>217 ): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> | S, BasePath, CurrentPath> {218 const subApp = this.basePath(path)219 app.routes.map((r) => {220 let handler221 if (app.errorHandler === errorHandler) {
21 unmodified lines
243 * ```ts244 * const api = new Hono().basePath('/api')245 * ```246 */241 basePath<SubPath extends string>(path: SubPath): Hono<E, S, MergePath<BasePath, SubPath>> {247 basePath<SubPath extends string>(248 path: SubPath249 ): Hono<E, S, MergePath<BasePath, SubPath>, MergePath<BasePath, SubPath>> {250 const subApp = this.#clone()251 subApp._basePath = mergePath(this._basePath, path)252 return subApp253 }
13 unmodified lines
267 * return c.text('Custom Error Message', 500)268 * })269 * ```270 */263 onError = (handler: ErrorHandler<E>): Hono<E, S, BasePath> => {271 onError = (handler: ErrorHandler<E>): Hono<E, S, BasePath, CurrentPath> => {272 this.errorHandler = handler273 return this274 }275
11 unmodified lines
287 * return c.text('Custom 404 Message', 404)288 * })289 * ```290 */283 notFound = (handler: NotFoundHandler<E>): Hono<E, S, BasePath> => {291 notFound = (handler: NotFoundHandler<E>): Hono<E, S, BasePath, CurrentPath> => {292 this.#notFoundHandler = handler293 return this294 }295
32 unmodified lines
328 mount(329 path: string,330 applicationHandler: (request: Request, ...args: any) => Response | Promise<Response>,331 options?: MountOptions324 ): Hono<E, S, BasePath> {332 ): Hono<E, S, BasePath, CurrentPath> {333 // handle options334 let replaceRequest: MountReplaceRequest | undefined335 let optionHandler: MountOptionHandler | undefined336 if (options) {
203 unmodified lines
modified:src/types.test.ts+341 added-4 removed
1 unmodified line
2import { expectTypeOf } from 'vitest'3import { hc } from './client'4import { Context } from './context'5import { createMiddleware } from './helper/factory'6import { testClient } from './helper/testing'7import { Hono } from './hono'8import { poweredBy } from './middleware/powered-by'9import type {10 AddParam,
230 unmodified lines
241 }242 }243 type verify = Expect<Equal<Expected, Actual>>244 })245246 it('should use the last registered path for a pathless handler', () => {247 const app = new Hono()248 .get('/foo', (c) => c.text('foo'))249 .get('/bar', (c) => c.text('bar'))250 .post((c) => c.text('baz'))251252 type Actual = ExtractSchema<typeof app>253 type Expected = {254 '/foo': {255 $get: {256 input: {}257 output: 'foo'258 outputFormat: 'text'259 status: ContentfulStatusCode260 }261 }262 } & {263 '/bar': {264 $get: {265 input: {}266 output: 'bar'267 outputFormat: 'text'268 status: ContentfulStatusCode269 }270 }271 } & {272 '/bar': {273 $post: {274 input: {}275 output: 'baz'276 outputFormat: 'text'277 status: ContentfulStatusCode278 }279 }280 }281 type verify = Expect<Equal<Expected, Actual>>282 })283 })284})285286describe('OnHandlerInterface', () => {
39 unmodified lines
326 expectTypeOf(c.var.foo).toEqualTypeOf<string>()327 return c.json({})328 })329 })330331 test('app.on(method, path[], handler).get(pathless handler) - pathless handler should use last path', () => {332 const route = app333 .on('GET', ['/a', '/b'], (c) => {334 return c.json({ first: true })335 })336 .get((c) => {337 return c.json({ second: true })338 })339 type Actual = ExtractSchema<typeof route>340 type Expected = {341 '/a': {342 [x: `$${Lowercase<string>}`]: {343 input: {}344 output: {345 first: true346 }347 outputFormat: 'json'348 status: ContentfulStatusCode349 }350 }351 '/b': {352 [x: `$${Lowercase<string>}`]: {353 input: {}354 output: {355 first: true356 }357 outputFormat: 'json'358 status: ContentfulStatusCode359 }360 }361 } & {362 '/b': {363 $get: {364 input: {}365 output: {366 second: true367 }368 outputFormat: 'json'369 status: ContentfulStatusCode370 }371 }372 }373 type verify = Expect<Equal<Expected, Actual>>374 })375})376377describe('TypedResponse', () => {378 test('unknown', () => {
1998 unmodified lines
2377describe('Returning type from `app.use(path, mw)`', () => {2378 const mw = createMiddleware(async (c, next) => {2379 await next()2380 })2297 it('Should not mark `*` as never', () => {2381 it('Should ignore the `*` wildcard when building the schema', () => {2382 const app = new Hono().use('*', mw)2383 type Actual = ExtractSchema<typeof app>2300 type Expected = {2301 '*': {}2302 }2384 type Expected = {}2385 type verify = Expect<Equal<Expected, Actual>>2386 })2387})2388
984 unmodified lines
3373 type verify = Expect<Equal<Expected, Actual>>3374 })3375 })3376})33773378describe('Handlers returning Promise<void>', () => {3379 it('should not be added to schema when calling await next() with another route', async () => {3380 const app = new Hono()3381 .get('/', async (c, next) => {3382 await next()3383 })3384 .get('/foo', async (c) => c.text('foo'))33853386 const client = testClient(app)33873388 // @ts-expect-error '/' route returns Promise<void>, so it should not be in schema3389 const res = await client.index.$get()3390 })33913392 it('should not be added to schema when only Promise<void> handler exists', async () => {3393 const app = new Hono().get('/', async (c, next) => {3394 await next()3395 })33963397 const client = testClient(app)33983399 // @ts-expect-error '/' route returns Promise<void>, so it should not be in schema3400 const res = await client.index.$get()3401 })34023403 it('should set path from .use() for subsequent handlers without path', () => {3404 const app = new Hono()3405 .use('/:id', async (c, next) => {3406 await next()3407 })3408 .post((c) => {3409 c.req.param('id')3410 return c.text('after')3411 })34123413 type Actual = ExtractSchema<typeof app>3414 type Expected = {3415 '/:id': {3416 $post: {3417 input: {3418 param: {3419 id: string3420 }3421 }3422 output: 'after'3423 outputFormat: 'text'3424 status: ContentfulStatusCode3425 }3426 }3427 }3428 type verify = Expect<Equal<Expected, Actual>>3429 })34303431 it('should preserve existing routes when .use() sets a new path', () => {3432 const app = new Hono()3433 .get((c) => c.text('before'))3434 .use('/:id', async (c, next) => {3435 await next()3436 })3437 .post((c) => {3438 c.req.param('id')3439 return c.text('after')3440 })34413442 type Actual = ExtractSchema<typeof app>3443 type Expected = {3444 '/': {3445 $get: {3446 input: {}3447 output: 'before'3448 outputFormat: 'text'3449 status: ContentfulStatusCode3450 }3451 }3452 } & {3453 '/:id': {3454 $post: {3455 input: {3456 param: {3457 id: string3458 }3459 }3460 output: 'after'3461 outputFormat: 'text'3462 status: ContentfulStatusCode3463 }3464 }3465 }3466 type verify = Expect<Equal<Expected, Actual>>3467 })34683469 it('should work with .get() that returns Promise<void> instead of .use()', () => {3470 const app = new Hono()3471 .get((c) => c.text('before'))3472 .get('/:id', async (c, next) => {3473 await next()3474 })3475 .post((c) => {3476 c.req.param('id')3477 return c.text('after')3478 })34793480 type Actual = ExtractSchema<typeof app>3481 type Expected = {3482 '/': {3483 $get: {3484 input: {}3485 output: 'before'3486 outputFormat: 'text'3487 status: ContentfulStatusCode3488 }3489 }3490 } & {3491 '/:id': {3492 $post: {3493 input: {3494 param: {3495 id: string3496 }3497 }3498 output: 'after'3499 outputFormat: 'text'3500 status: ContentfulStatusCode3501 }3502 }3503 }3504 type verify = Expect<Equal<Expected, Actual>>3505 })35063507 it('should work with .get() that returns Promise<void> instead of .use() - multiple middleware', () => {3508 const app = new Hono()3509 .get((c) => c.text('before'))3510 .get(3511 '/:id',3512 async (c, next) => {3513 await next()3514 },3515 async (c, next) => {3516 await next()3517 }3518 )3519 .post((c) => {3520 c.req.param('id')3521 return c.text('after')3522 })35233524 type Actual = ExtractSchema<typeof app>3525 type Expected = {3526 '/': {3527 $get: {3528 input: {}3529 output: 'before'3530 outputFormat: 'text'3531 status: ContentfulStatusCode3532 }3533 }3534 } & {3535 '/:id': {3536 $post: {3537 input: {3538 param: {3539 id: string3540 }3541 }3542 output: 'after'3543 outputFormat: 'text'3544 status: ContentfulStatusCode3545 }3546 }3547 }3548 type verify = Expect<Equal<Expected, Actual>>3549 })35503551 it('should use the last registered path for a pathless handler with multiple middlewares', () => {3552 const app = new Hono()3553 .get('/foo', async (_c, next) => {3554 await next()3555 })3556 .get('/bar', async (_c, next) => {3557 await next()3558 })3559 .get((c) => c.text('after'))35603561 type Actual = ExtractSchema<typeof app>3562 type Expected = {3563 '/bar': {3564 $get: {3565 input: {}3566 output: 'after'3567 outputFormat: 'text'3568 status: ContentfulStatusCode3569 }3570 }3571 }3572 type verify = Expect<Equal<Expected, Actual>>3573 })35743575 it('should use the last registered path for a pathless handler with mixed handlers and middlewares', () => {3576 const app = new Hono()3577 .get('/void', async (_c, next) => {3578 await next()3579 })3580 .get('/handler', (c) => c.text('handler'))3581 .get((c) => c.text('after'))35823583 type Actual = ExtractSchema<typeof app>3584 type Expected = {3585 '/handler': {3586 $get: {3587 input: {}3588 output: 'handler'3589 outputFormat: 'text'3590 status: ContentfulStatusCode3591 }3592 }3593 } & {3594 '/handler': {3595 $get: {3596 input: {}3597 output: 'after'3598 outputFormat: 'text'3599 status: ContentfulStatusCode3600 }3601 }3602 }3603 type verify = Expect<Equal<Expected, Actual>>3604 })36053606 it('should set path as `*` when .use() is called without path argument', () => {3607 const app = new Hono()3608 .get('/foo', async (_c, next) => {3609 await next()3610 })3611 .use(async (c, next) => {3612 await next()3613 })3614 .post((c) => {3615 return c.text('after')3616 })36173618 type Actual = ExtractSchema<typeof app>3619 type Expected = {3620 '*': {3621 $post: {3622 input: {}3623 output: 'after'3624 outputFormat: 'text'3625 status: ContentfulStatusCode3626 }3627 }3628 }3629 type verify = Expect<Equal<Expected, Actual>>3630 })3631})
modified:src/types.ts+374 added-278 removed
66 unmodified lines
67////// Handlers //////68////// //////69////////////////////////////////////////7071export type HandlerResponse<O> = Response | TypedResponse<O> | Promise<Response | TypedResponse<O>>71export type HandlerResponse<O> =72 | Response73 | TypedResponse<O>74 | Promise<Response | TypedResponse<O>>75 | Promise<void>7677export type Handler<78 E extends Env = any,79 P extends string = any,
49 unmodified lines
129 E extends Env = Env,130 M extends string = string,131 S extends Schema = BlankSchema,132 BasePath extends string = '/',133 CurrentPath extends string = BasePath,134> {135 // app.get(handler)136 <132 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,137 P extends string = CurrentPath,138 I extends Input = BlankInput,139 R extends HandlerResponse<any> = any,140 E2 extends Env = E,141 >(142 handler: H<E2, P, I, R>138 ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S & ToSchema<M, P, I, MergeTypedResponse<R>>, BasePath>143 ): HonoBase<144 IntersectNonAnyTypes<[E, E2]>,145 S & ToSchema<M, P, I, MergeTypedResponse<R>>,146 BasePath,147 CurrentPath148 >149150 // app.get(handler x2)151 <142 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,152 P extends string = CurrentPath,153 I extends Input = BlankInput,154 I2 extends Input = I,155 R extends HandlerResponse<any> = any,156 E2 extends Env = E,
3 unmodified lines
160 ...handlers: [H<E2, P, I> & M1, H<E3, P, I2, R>]161 ): HonoBase<162 IntersectNonAnyTypes<[E, E2, E3]>,163 S & ToSchema<M, P, I2, MergeTypedResponse<R> | MergeMiddlewareResponse<M1>>,154 BasePath164 BasePath,165 CurrentPath166 >167168 // app.get(path, handler)169 <
4 unmodified lines
174 E2 extends Env = E,175 >(176 path: P,177 handler: H<E2, MergedPath, I, R>167 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath>178 ): HonoBase<179 E,180 AddSchemaIfHasResponse<MergeTypedResponse<R>, S, M, P, I, BasePath>,181 BasePath,182 MergePath<BasePath, P>183 >184185 // app.get(handler x 3)186 <171 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,187 P extends string = CurrentPath,188 R extends HandlerResponse<any> = any,189 I extends Input = BlankInput,190 I2 extends Input = I,191 I3 extends Input = I & I2,
13 unmodified lines
205 P,206 I3,207 MergeTypedResponse<R> | MergeMiddlewareResponse<M1> | MergeMiddlewareResponse<M2>208 >,193 BasePath209 BasePath,210 CurrentPath211 >212213 // app.get(path, handler x2)214 <
10 unmodified lines
225 path: P,226 ...handlers: [H<E2, MergedPath, I> & M1, H<E3, MergedPath, I2, R>]227 ): HonoBase<228 E,212 S &213 ToSchema<M, MergePath<BasePath, P>, I2, MergeTypedResponse<R> | MergeMiddlewareResponse<M1>>,214 BasePath229 AddSchemaIfHasResponse<230 MergeTypedResponse<R> | MergeMiddlewareResponse<M1>,231 S,232 M,233 P,234 I2,235 BasePath236 >,237 BasePath,238 MergePath<BasePath, P>239 >240241 // app.get(handler x 4)242 <219 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,243 P extends string = CurrentPath,244 R extends HandlerResponse<any> = any,245 I extends Input = BlankInput,246 I2 extends Input = I,247 I3 extends Input = I & I2,
19 unmodified lines
267 | MergeMiddlewareResponse<M1>268 | MergeMiddlewareResponse<M2>269 | MergeMiddlewareResponse<M3>270 >,247 BasePath271 BasePath,272 CurrentPath273 >274275 // app.get(path, handler x3)276 <
13 unmodified lines
290 path: P,291 ...handlers: [H<E2, MergedPath, I> & M1, H<E3, MergedPath, I2> & M2, H<E4, MergedPath, I3, R>]292 ): HonoBase<293 E,269 S &270 ToSchema<271 M,272 MergePath<BasePath, P>,273 I3,274 MergeTypedResponse<R> | MergeMiddlewareResponse<M1> | MergeMiddlewareResponse<M2>275 >,276 BasePath294 AddSchemaIfHasResponse<295 MergeTypedResponse<R> | MergeMiddlewareResponse<M1> | MergeMiddlewareResponse<M2>,296 S,297 M,298 P,299 I3,300 BasePath301 >,302 BasePath,303 MergePath<BasePath, P>304 >305306 // app.get(handler x 5)307 <281 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,308 P extends string = CurrentPath,309 R extends HandlerResponse<any> = any,310 I extends Input = BlankInput,311 I2 extends Input = I,312 I3 extends Input = I & I2,
29 unmodified lines
342 | MergeMiddlewareResponse<M2>343 | MergeMiddlewareResponse<M3>344 | MergeMiddlewareResponse<M4>345 >,319 BasePath346 BasePath,347 CurrentPath348 >349350 // app.get(path, handler x4)351 <
21 unmodified lines
373 H<E5, MergedPath, I4, R>,374 ]375 ): HonoBase<376 E,349 S &350 ToSchema<351 M,352 MergePath<BasePath, P>,353 I4,354 | MergeTypedResponse<R>355 | MergeMiddlewareResponse<M1>356 | MergeMiddlewareResponse<M2>357 | MergeMiddlewareResponse<M3>358 >,359 BasePath377 AddSchemaIfHasResponse<378 | MergeTypedResponse<R>379 | MergeMiddlewareResponse<M1>380 | MergeMiddlewareResponse<M2>381 | MergeMiddlewareResponse<M3>,382 S,383 M,384 P,385 I4,386 BasePath387 >,388 BasePath,389 MergePath<BasePath, P>390 >391392 // app.get(handler x 6)393 <364 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,394 P extends string = CurrentPath,395 R extends HandlerResponse<any> = any,396 I extends Input = BlankInput,397 I2 extends Input = I,398 I3 extends Input = I & I2,
34 unmodified lines
433 | MergeMiddlewareResponse<M3>434 | MergeMiddlewareResponse<M4>435 | MergeMiddlewareResponse<M5>436 >,407 BasePath437 BasePath,438 CurrentPath439 >440441 // app.get(path, handler x5)442 <
25 unmodified lines
468 H<E6, MergedPath, I5, R>,469 ]470 ): HonoBase<471 E,441 S &442 ToSchema<443 M,444 MergePath<BasePath, P>,445 I5,446 | MergeTypedResponse<R>447 | MergeMiddlewareResponse<M1>448 | MergeMiddlewareResponse<M2>449 | MergeMiddlewareResponse<M3>450 | MergeMiddlewareResponse<M4>451 >,452 BasePath472 AddSchemaIfHasResponse<473 | MergeTypedResponse<R>474 | MergeMiddlewareResponse<M1>475 | MergeMiddlewareResponse<M2>476 | MergeMiddlewareResponse<M3>477 | MergeMiddlewareResponse<M4>,478 S,479 M,480 P,481 I5,482 BasePath483 >,484 BasePath,485 MergePath<BasePath, P>486 >487488 // app.get(handler x 7)489 <457 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,490 P extends string = CurrentPath,491 R extends HandlerResponse<any> = any,492 I extends Input = BlankInput,493 I2 extends Input = I,494 I3 extends Input = I & I2,
39 unmodified lines
534 | MergeMiddlewareResponse<M4>535 | MergeMiddlewareResponse<M5>536 | MergeMiddlewareResponse<M6>537 >,505 BasePath538 BasePath,539 CurrentPath540 >541542 // app.get(path, handler x6)543 <
29 unmodified lines
573 H<E7, MergedPath, I6, R>,574 ]575 ): HonoBase<576 E,543 S &544 ToSchema<545 M,546 MergePath<BasePath, P>,547 I6,548 | MergeTypedResponse<R>549 | MergeMiddlewareResponse<M1>550 | MergeMiddlewareResponse<M2>551 | MergeMiddlewareResponse<M3>552 | MergeMiddlewareResponse<M4>553 | MergeMiddlewareResponse<M5>554 >,555 BasePath577 AddSchemaIfHasResponse<578 | MergeTypedResponse<R>579 | MergeMiddlewareResponse<M1>580 | MergeMiddlewareResponse<M2>581 | MergeMiddlewareResponse<M3>582 | MergeMiddlewareResponse<M4>583 | MergeMiddlewareResponse<M5>,584 S,585 M,586 P,587 I6,588 BasePath589 >,590 BasePath,591 MergePath<BasePath, P>592 >593594 // app.get(handler x 8)595 <560 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,596 P extends string = CurrentPath,597 R extends HandlerResponse<any> = any,598 I extends Input = BlankInput,599 I2 extends Input = I,600 I3 extends Input = I & I2,
44 unmodified lines
645 | MergeMiddlewareResponse<M5>646 | MergeMiddlewareResponse<M6>647 | MergeMiddlewareResponse<M7>648 >,613 BasePath649 BasePath,650 CurrentPath651 >652653 // app.get(path, handler x7)654 <
33 unmodified lines
688 H<E8, MergedPath, I7, R>,689 ]690 ): HonoBase<691 E,655 S &656 ToSchema<657 M,658 MergePath<BasePath, P>,659 I7,660 | MergeTypedResponse<R>661 | MergeMiddlewareResponse<M1>662 | MergeMiddlewareResponse<M2>663 | MergeMiddlewareResponse<M3>664 | MergeMiddlewareResponse<M4>665 | MergeMiddlewareResponse<M5>666 | MergeMiddlewareResponse<M6>667 >,668 BasePath692 AddSchemaIfHasResponse<693 | MergeTypedResponse<R>694 | MergeMiddlewareResponse<M1>695 | MergeMiddlewareResponse<M2>696 | MergeMiddlewareResponse<M3>697 | MergeMiddlewareResponse<M4>698 | MergeMiddlewareResponse<M5>699 | MergeMiddlewareResponse<M6>,700 S,701 M,702 P,703 I7,704 BasePath705 >,706 BasePath,707 MergePath<BasePath, P>708 >709710 // app.get(handler x 9)711 <673 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,712 P extends string = CurrentPath,713 R extends HandlerResponse<any> = any,714 I extends Input = BlankInput,715 I2 extends Input = I,716 I3 extends Input = I & I2,
49 unmodified lines
766 | MergeMiddlewareResponse<M6>767 | MergeMiddlewareResponse<M7>768 | MergeMiddlewareResponse<M8>769 >,731 BasePath770 BasePath,771 CurrentPath772 >773774 // app.get(path, handler x8)775 <
37 unmodified lines
813 H<E9, MergedPath, I8, R>,814 ]815 ): HonoBase<816 E,777 S &778 ToSchema<779 M,780 MergePath<BasePath, P>,781 I8,782 | MergeTypedResponse<R>783 | MergeMiddlewareResponse<M1>784 | MergeMiddlewareResponse<M2>785 | MergeMiddlewareResponse<M3>786 | MergeMiddlewareResponse<M4>787 | MergeMiddlewareResponse<M5>788 | MergeMiddlewareResponse<M6>789 | MergeMiddlewareResponse<M7>790 >,791 BasePath817 AddSchemaIfHasResponse<818 | MergeTypedResponse<R>819 | MergeMiddlewareResponse<M1>820 | MergeMiddlewareResponse<M2>821 | MergeMiddlewareResponse<M3>822 | MergeMiddlewareResponse<M4>823 | MergeMiddlewareResponse<M5>824 | MergeMiddlewareResponse<M6>825 | MergeMiddlewareResponse<M7>,826 S,827 M,828 P,829 I8,830 BasePath831 >,832 BasePath,833 MergePath<BasePath, P>834 >835836 // app.get(handler x 10)837 <796 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,838 P extends string = CurrentPath,839 R extends HandlerResponse<any> = any,840 I extends Input = BlankInput,841 I2 extends Input = I,842 I3 extends Input = I & I2,
54 unmodified lines
897 | MergeMiddlewareResponse<M7>898 | MergeMiddlewareResponse<M8>899 | MergeMiddlewareResponse<M9>900 >,859 BasePath901 BasePath,902 CurrentPath903 >904905 // app.get(path, handler x9)906 <
41 unmodified lines
948 H<E10, MergedPath, I9, R>,949 ]950 ): HonoBase<951 E,909 S &910 ToSchema<911 M,912 MergePath<BasePath, P>,913 I9,914 | MergeTypedResponse<R>915 | MergeMiddlewareResponse<M1>916 | MergeMiddlewareResponse<M2>917 | MergeMiddlewareResponse<M3>918 | MergeMiddlewareResponse<M4>919 | MergeMiddlewareResponse<M5>920 | MergeMiddlewareResponse<M6>921 | MergeMiddlewareResponse<M7>922 | MergeMiddlewareResponse<M8>923 >,924 BasePath952 AddSchemaIfHasResponse<953 | MergeTypedResponse<R>954 | MergeMiddlewareResponse<M1>955 | MergeMiddlewareResponse<M2>956 | MergeMiddlewareResponse<M3>957 | MergeMiddlewareResponse<M4>958 | MergeMiddlewareResponse<M5>959 | MergeMiddlewareResponse<M6>960 | MergeMiddlewareResponse<M7>961 | MergeMiddlewareResponse<M8>,962 S,963 M,964 P,965 I9,966 BasePath967 >,968 BasePath,969 MergePath<BasePath, P>970 >971972 // app.get(path, handler x10)973 <
45 unmodified lines
1019 H<E11, MergedPath, I10, R>,1020 ]1021 ): HonoBase<1022 E,978 S &979 ToSchema<980 M,981 MergePath<BasePath, P>,982 I10,983 | MergeTypedResponse<R>984 | MergeMiddlewareResponse<M1>985 | MergeMiddlewareResponse<M2>986 | MergeMiddlewareResponse<M3>987 | MergeMiddlewareResponse<M4>988 | MergeMiddlewareResponse<M5>989 | MergeMiddlewareResponse<M6>990 | MergeMiddlewareResponse<M7>991 | MergeMiddlewareResponse<M8>992 | MergeMiddlewareResponse<M9>993 >,994 BasePath1023 AddSchemaIfHasResponse<1024 | MergeTypedResponse<R>1025 | MergeMiddlewareResponse<M1>1026 | MergeMiddlewareResponse<M2>1027 | MergeMiddlewareResponse<M3>1028 | MergeMiddlewareResponse<M4>1029 | MergeMiddlewareResponse<M5>1030 | MergeMiddlewareResponse<M6>1031 | MergeMiddlewareResponse<M7>1032 | MergeMiddlewareResponse<M8>1033 | MergeMiddlewareResponse<M9>,1034 S,1035 M,1036 P,1037 I10,1038 BasePath1039 >,1040 BasePath,1041 MergePath<BasePath, P>1042 >10431044 // app.get(...handlers[])1045 <999 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,1046 P extends string = CurrentPath,1047 I extends Input = BlankInput,1048 R extends HandlerResponse<any> = any,1049 >(1050 ...handlers: H<E, P, I, R>[]1004 ): HonoBase<E, S & ToSchema<M, P, I, MergeTypedResponse<R>>, BasePath>1051 ): HonoBase<E, S & ToSchema<M, P, I, MergeTypedResponse<R>>, BasePath, CurrentPath>10521053 // app.get(path, ...handlers[])1054 <P extends string, I extends Input = BlankInput, R extends HandlerResponse<any> = any>(1055 path: P,1009 ...handlers: H<E, MergePath<BasePath, P>, I, R>[]1010 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath>1056 ...handlers: [H<E, MergePath<BasePath, P>, I, R>, ...H<E, MergePath<BasePath, P>, I, R>[]]1057 ): HonoBase<1058 E,1059 S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>,1060 BasePath,1061 MergePath<BasePath, P>1062 >10631064 // app.get(path)1065 <P extends string, R extends HandlerResponse<any> = any, I extends Input = BlankInput>(1066 path: P1015 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath>1067 ): HonoBase<1068 E,1069 S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>,1070 BasePath,1071 MergePath<BasePath, P>1072 >1073}10741075////////////////////////////////////////1076////// //////
7 unmodified lines
1084 BasePath extends string = '/',1085> {1086 //// app.use(...handlers[])1087 <E2 extends Env = E>(1031 ...handlers: MiddlewareHandler<E2, MergePath<BasePath, ExtractStringKey<S>>>[]1032 ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath>1088 ...handlers: MiddlewareHandler<E2, MergePath<BasePath, '*'>>[]1089 ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath, MergePath<BasePath, '*'>>10901091 // app.use(handler)1092 <E2 extends Env = E>(1036 handler: MiddlewareHandler<E2, MergePath<BasePath, ExtractStringKey<S>>>1037 ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath>1093 handler: MiddlewareHandler<E2, MergePath<BasePath, '*'>>1094 ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath, MergePath<BasePath, '*'>>10951096 // app.use(handler x2)1097 <1098 E2 extends Env = E,1099 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,1043 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1100 P extends string = MergePath<BasePath, '*'>,1101 >(1102 ...handlers: [MiddlewareHandler<E2, P>, MiddlewareHandler<E3, P>]1046 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, S, BasePath>1103 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, S, BasePath, P>11041048 // app.get(path, handler)1105 // app.use(path, handler)1106 <P extends string, MergedPath extends MergePath<BasePath, P>, E2 extends Env = E>(1107 path: P,1108 handler: MiddlewareHandler<E2, MergedPath, any, any>1052 ): HonoBase<IntersectNonAnyTypes<[E, E2]>, ChangePathOfSchema<S, MergedPath>, BasePath>1109 ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath, MergedPath>11101111 // app.use(handler x3)1112 <1113 E2 extends Env = E,1114 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,1115 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,1059 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1116 P extends string = MergePath<BasePath, '*'>,1117 >(1118 ...handlers: [1119 MiddlewareHandler<E2, P, any, any>,1120 MiddlewareHandler<E3, P, any, any>,1121 MiddlewareHandler<E4, P, any, any>,1122 ]1066 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath>1123 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath, P>11241068 // app.get(path, handler x2)1125 // app.use(path, handler x2)1126 <1127 P extends string,1128 MergedPath extends MergePath<BasePath, P>,1129 E2 extends Env = E,1130 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,1131 >(1132 path: P,1133 ...handlers: [MiddlewareHandler<E2, P>, MiddlewareHandler<E3, P>]1077 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, ChangePathOfSchema<S, MergedPath>, BasePath>1134 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, S, BasePath, MergedPath>11351136 // app.use(handler x4)1137 <1138 E2 extends Env = E,1139 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,1140 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,1141 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,1085 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1142 P extends string = MergePath<BasePath, '*'>,1143 >(1144 ...handlers: [1145 MiddlewareHandler<E2, P>,1146 MiddlewareHandler<E3, P>,1147 MiddlewareHandler<E4, P>,1148 MiddlewareHandler<E5, P>,1149 ]1093 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S, BasePath>1150 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S, BasePath, P>11511095 // app.get(path, handler x3)1152 // app.use(path, handler x3)1153 <1154 P extends string,1155 MergedPath extends MergePath<BasePath, P>,1156 E2 extends Env = E,
1 unmodified line
1158 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,1159 >(1160 path: P,1161 ...handlers: [MiddlewareHandler<E2, P>, MiddlewareHandler<E3, P>, MiddlewareHandler<E4, P>]1105 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, ChangePathOfSchema<S, MergedPath>, BasePath>1162 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath, MergedPath>11631164 // app.use(handler x5)1165 <1166 E2 extends Env = E,1167 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,1168 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,1169 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,1170 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1114 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1171 P extends string = MergePath<BasePath, '*'>,1172 >(1173 ...handlers: [1174 MiddlewareHandler<E2, P>,1175 MiddlewareHandler<E3, P>,1176 MiddlewareHandler<E4, P>,1177 MiddlewareHandler<E5, P>,1178 MiddlewareHandler<E6, P>,1179 ]1123 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S, BasePath>1180 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S, BasePath, P>11811125 // app.get(path, handler x4)1182 // app.use(path, handler x4)1183 <1184 P extends string,1185 MergedPath extends MergePath<BasePath, P>,1186 E2 extends Env = E,
7 unmodified lines
1194 MiddlewareHandler<E3, P>,1195 MiddlewareHandler<E4, P>,1196 MiddlewareHandler<E5, P>,1197 ]1141 ): HonoBase<1142 IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1143 ChangePathOfSchema<S, MergedPath>,1144 BasePath1145 >1198 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S, BasePath, MergedPath>11991200 // app.use(handler x6)1201 <1202 E2 extends Env = E,
1 unmodified line
1204 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,1205 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,1206 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1207 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1155 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1208 P extends string = MergePath<BasePath, '*'>,1209 >(1210 ...handlers: [1211 MiddlewareHandler<E2, P>,1212 MiddlewareHandler<E3, P>,
1 unmodified line
1214 MiddlewareHandler<E5, P>,1215 MiddlewareHandler<E6, P>,1216 MiddlewareHandler<E7, P>,1217 ]1165 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S, BasePath>1218 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S, BasePath, P>12191167 // app.get(path, handler x5)1220 // app.use(path, handler x5)1221 <1222 P extends string,1223 MergedPath extends MergePath<BasePath, P>,1224 E2 extends Env = E,
9 unmodified lines
1234 MiddlewareHandler<E4, P>,1235 MiddlewareHandler<E5, P>,1236 MiddlewareHandler<E6, P>,1237 ]1185 ): HonoBase<1186 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1187 ChangePathOfSchema<S, MergedPath>,1188 BasePath1189 >1238 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S, BasePath, MergedPath>12391240 // app.use(handler x7)1241 <1242 E2 extends Env = E,
2 unmodified lines
1245 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,1246 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1247 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1248 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1200 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1249 P extends string = MergePath<BasePath, '*'>,1250 >(1251 ...handlers: [1252 MiddlewareHandler<E2, P>,1253 MiddlewareHandler<E3, P>,
2 unmodified lines
1256 MiddlewareHandler<E6, P>,1257 MiddlewareHandler<E7, P>,1258 MiddlewareHandler<E8, P>,1259 ]1211 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S, BasePath>1260 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S, BasePath, P>12611213 // app.get(path, handler x6)1262 // app.use(path, handler x6)1263 <1264 P extends string,1265 MergedPath extends MergePath<BasePath, P>,1266 E2 extends Env = E,
11 unmodified lines
1278 MiddlewareHandler<E5, P>,1279 MiddlewareHandler<E6, P>,1280 MiddlewareHandler<E7, P>,1281 ]1233 ): HonoBase<1234 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1235 ChangePathOfSchema<S, MergedPath>,1236 BasePath1237 >1282 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S, BasePath, MergedPath>12831284 // app.use(handler x8)1285 <1286 E2 extends Env = E,
3 unmodified lines
1290 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1291 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1292 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1293 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,1249 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1294 P extends string = MergePath<BasePath, '*'>,1295 >(1296 ...handlers: [1297 MiddlewareHandler<E2, P>,1298 MiddlewareHandler<E3, P>,
3 unmodified lines
1302 MiddlewareHandler<E7, P>,1303 MiddlewareHandler<E8, P>,1304 MiddlewareHandler<E9, P>,1305 ]1261 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S, BasePath>1306 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S, BasePath, P>13071263 // app.get(path, handler x7)1308 // app.use(path, handler x7)1309 <1310 P extends string,1311 MergedPath extends MergePath<BasePath, P>,1312 E2 extends Env = E,
13 unmodified lines
1326 MiddlewareHandler<E6, P>,1327 MiddlewareHandler<E7, P>,1328 MiddlewareHandler<E8, P>,1329 ]1285 ): HonoBase<1286 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,1287 ChangePathOfSchema<S, MergedPath>,1288 BasePath1289 >1330 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S, BasePath, MergedPath>13311332 // app.use(handler x9)1333 <1334 E2 extends Env = E,
4 unmodified lines
1339 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1340 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1341 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,1342 E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,1302 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1343 P extends string = MergePath<BasePath, '*'>,1344 >(1345 ...handlers: [1346 MiddlewareHandler<E2, P>,1347 MiddlewareHandler<E3, P>,
4 unmodified lines
1352 MiddlewareHandler<E8, P>,1353 MiddlewareHandler<E9, P>,1354 MiddlewareHandler<E10, P>,1355 ]1315 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S, BasePath>1356 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>, S, BasePath, P>13571317 // app.get(path, handler x8)1358 // app.use(path, handler x8)1359 <1360 P extends string,1361 MergedPath extends MergePath<BasePath, P>,1362 E2 extends Env = E,
15 unmodified lines
1378 MiddlewareHandler<E7, P>,1379 MiddlewareHandler<E8, P>,1380 MiddlewareHandler<E9, P>,1381 ]1341 ): HonoBase<1342 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,1343 ChangePathOfSchema<S, MergedPath>,1344 BasePath1345 >1382 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S, BasePath, MergedPath>13831384 // app.use(handler x10)1385 <1386 E2 extends Env = E,
5 unmodified lines
1392 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1393 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,1394 E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,1395 E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,1359 P extends string = MergePath<BasePath, ExtractStringKey<S>>,1396 P extends string = MergePath<BasePath, '*'>,1397 >(1398 ...handlers: [1399 MiddlewareHandler<E2, P>,1400 MiddlewareHandler<E3, P>,
5 unmodified lines
1406 MiddlewareHandler<E9, P>,1407 MiddlewareHandler<E10, P>,1408 MiddlewareHandler<E11, P>,1409 ]1373 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S, BasePath>1410 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>, S, BasePath, P>14111375 // app.get(path, handler x9)1412 // app.use(path, handler x9)1413 <1414 P extends string,1415 MergedPath extends MergePath<BasePath, P>,1416 E2 extends Env = E,
19 unmodified lines
1436 MiddlewareHandler<E10, P>,1437 ]1438 ): HonoBase<1439 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,1403 ChangePathOfSchema<S, MergedPath>,1404 BasePath1440 S,1441 BasePath,1442 MergedPath1443 >14441445 //// app.use(path, ...handlers[])1446 <P extends string, E2 extends Env = E>(1447 path: P,1448 ...handlers: MiddlewareHandler<E2, MergePath<BasePath, P>>[]1411 ): HonoBase<E, S, BasePath>1449 ): HonoBase<E, S, BasePath, MergePath<BasePath, P>>1450}14511452////////////////////////////////////////1453////// //////
20 unmodified lines
1474 handler: H<E2, MergedPath, I, R>1475 ): HonoBase<1476 IntersectNonAnyTypes<[E, E2]>,1477 S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>,1440 BasePath1478 BasePath,1479 MergePath<BasePath, P>1480 >14811482 // app.on(method, path, handler x2)1483 <
11 unmodified lines
1495 ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2, R>]1496 ): HonoBase<1497 IntersectNonAnyTypes<[E, E2, E3]>,1498 S & ToSchema<M, MergePath<BasePath, P>, I2, MergeTypedResponse<R>>,1460 BasePath1499 BasePath,1500 MergePath<BasePath, P>1501 >15021503 // app.on(method, path, handler x3)1504 <
13 unmodified lines
1518 ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2>, H<E4, MergedPath, I3, R>]1519 ): HonoBase<1520 IntersectNonAnyTypes<[E, E2, E3, E4]>,1521 S & ToSchema<M, MergePath<BasePath, P>, I3, MergeTypedResponse<R>>,1482 BasePath1522 BasePath,1523 MergePath<BasePath, P>1524 >15251526 // app.on(method, path, handler x4)1527 <
20 unmodified lines
1548 ]1549 ): HonoBase<1550 IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1551 S & ToSchema<M, MergePath<BasePath, P>, I4, MergeTypedResponse<R>>,1511 BasePath1552 BasePath,1553 MergePath<BasePath, P>1554 >15551556 // app.on(method, path, handler x5)1557 <
23 unmodified lines
1581 ]1582 ): HonoBase<1583 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1584 S & ToSchema<M, MergePath<BasePath, P>, I5, MergeTypedResponse<R>>,1543 BasePath1585 BasePath,1586 MergePath<BasePath, P>1587 >15881589 // app.on(method, path, handler x6)1590 <
26 unmodified lines
1617 ]1618 ): HonoBase<1619 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1620 S & ToSchema<M, MergePath<BasePath, P>, I6, MergeTypedResponse<R>>,1578 BasePath1621 BasePath,1622 MergePath<BasePath, P>1623 >16241625 // app.on(method, path, handler x7)1626 <
29 unmodified lines
1656 ]1657 ): HonoBase<1658 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,1659 S & ToSchema<M, MergePath<BasePath, P>, I7, MergeTypedResponse<R>>,1616 BasePath1660 BasePath,1661 MergePath<BasePath, P>1662 >16631664 // app.on(method, path, handler x8)1665 <
32 unmodified lines
1698 ]1699 ): HonoBase<1700 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,1701 S & ToSchema<M, MergePath<BasePath, P>, I8, MergeTypedResponse<R>>,1657 BasePath1702 BasePath,1703 MergePath<BasePath, P>1704 >17051706 // app.on(method, path, handler x9)1707 <
35 unmodified lines
1743 ]1744 ): HonoBase<1745 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,1746 S & ToSchema<M, MergePath<BasePath, P>, I9, MergeTypedResponse<R>>,1701 BasePath1747 BasePath,1748 MergePath<BasePath, P>1749 >17501751 // app.on(method, path, handler x10)1752 <
38 unmodified lines
1791 ]1792 ): HonoBase<1793 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>,1794 S & ToSchema<M, MergePath<BasePath, P>, I10, MergeTypedResponse<HandlerResponse<any>>>,1748 BasePath1795 BasePath,1796 MergePath<BasePath, P>1797 >17981751 // app.get(method, path, ...handler)1799 // app.on(method, path, ...handler)1800 <1801 M extends string,1802 P extends string,1803 R extends HandlerResponse<any> = any,1804 I extends Input = BlankInput,1805 >(1806 method: M,1807 path: P,1760 ...handlers: H<E, MergePath<BasePath, P>, I, R>[]1761 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath>1808 ...handlers: [H<E, MergePath<BasePath, P>, I, R>, ...H<E, MergePath<BasePath, P>, I, R>[]]1809 ): HonoBase<1810 E,1811 S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>,1812 BasePath,1813 MergePath<BasePath, P>1814 >18151763 // app.get(method[], path, handler)1816 // app.on(method[], path, handler)1817 <1818 Ms extends string[],1819 P extends string,1820 MergedPath extends MergePath<BasePath, P>,
6 unmodified lines
1827 handler: H<E2, MergedPath, I, R>1828 ): HonoBase<1829 IntersectNonAnyTypes<[E, E2]>,1830 S & ToSchema<Ms[number], MergePath<BasePath, P>, I, MergeTypedResponse<R>>,1778 BasePath1831 BasePath,1832 MergePath<BasePath, P>1833 >18341781 // app.get(method[], path, handler x2)1835 // app.on(method[], path, handler x2)1836 <1837 Ms extends string[],1838 P extends string,1839 MergedPath extends MergePath<BasePath, P>,
8 unmodified lines
1848 ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2, R>]1849 ): HonoBase<1850 IntersectNonAnyTypes<[E, E2, E3]>,1851 S & ToSchema<Ms[number], MergePath<BasePath, P>, I2, MergeTypedResponse<R>>,1798 BasePath1852 BasePath,1853 MergePath<BasePath, P>1854 >18551801 // app.get(method[], path, handler x3)1856 // app.on(method[], path, handler x3)1857 <1858 Ms extends string[],1859 P extends string,1860 MergedPath extends MergePath<BasePath, P>,
10 unmodified lines
1871 ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2>, H<E4, MergedPath, I3, R>]1872 ): HonoBase<1873 IntersectNonAnyTypes<[E, E2, E3, E4]>,1874 S & ToSchema<Ms[number], MergePath<BasePath, P>, I3, MergeTypedResponse<R>>,1820 BasePath1875 BasePath,1876 MergePath<BasePath, P>1877 >18781823 // app.get(method[], path, handler x4)1879 // app.on(method[], path, handler x4)1880 <1881 Ms extends string[],1882 P extends string,1883 MergedPath extends MergePath<BasePath, P>,
17 unmodified lines
1901 ]1902 ): HonoBase<1903 IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1904 S & ToSchema<Ms[number], MergePath<BasePath, P>, I4, MergeTypedResponse<R>>,1849 BasePath1905 BasePath,1906 MergePath<BasePath, P>1907 >19081852 // app.get(method[], path, handler x5)1909 // app.on(method[], path, handler x5)1910 <1911 Ms extends string[],1912 P extends string,1913 MergedPath extends MergePath<BasePath, P>,
20 unmodified lines
1934 ]1935 ): HonoBase<1936 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1937 S & ToSchema<Ms[number], MergePath<BasePath, P>, I5, MergeTypedResponse<R>>,1881 BasePath1938 BasePath,1939 MergePath<BasePath, P>1940 >19411884 // app.get(method[], path, handler x6)1942 // app.on(method[], path, handler x6)1943 <1944 Ms extends string[],1945 P extends string,1946 MergedPath extends MergePath<BasePath, P>,
23 unmodified lines
1970 ]1971 ): HonoBase<1972 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1973 S & ToSchema<Ms[number], MergePath<BasePath, P>, I6, MergeTypedResponse<R>>,1916 BasePath1974 BasePath,1975 MergePath<BasePath, P>1976 >19771919 // app.get(method[], path, handler x7)1978 // app.on(method[], path, handler x7)1979 <1980 Ms extends string[],1981 P extends string,1982 MergedPath extends MergePath<BasePath, P>,
26 unmodified lines
2009 ]2010 ): HonoBase<2011 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,2012 S & ToSchema<Ms[number], MergePath<BasePath, P>, I7, MergeTypedResponse<R>>,1954 BasePath2013 BasePath,2014 MergePath<BasePath, P>2015 >20161957 // app.get(method[], path, handler x8)2017 // app.on(method[], path, handler x8)2018 <2019 Ms extends string[],2020 P extends string,2021 MergedPath extends MergePath<BasePath, P>,
29 unmodified lines
2051 ]2052 ): HonoBase<2053 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,2054 S & ToSchema<Ms[number], MergePath<BasePath, P>, I8, MergeTypedResponse<R>>,1995 BasePath2055 BasePath,2056 MergePath<BasePath, P>2057 >20581998 // app.get(method[], path, handler x9)2059 // app.on(method[], path, handler x9)2060 <2061 Ms extends string[],2062 P extends string,2063 MergedPath extends MergePath<BasePath, P>,
32 unmodified lines
2096 ]2097 ): HonoBase<2098 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,2099 S & ToSchema<Ms[number], MergePath<BasePath, P>, I9, MergeTypedResponse<HandlerResponse<any>>>,2039 BasePath2100 BasePath,2101 MergePath<BasePath, P>2102 >21032042 // app.get(method[], path, handler x10)2104 // app.on(method[], path, handler x10)2105 <2106 Ms extends string[],2107 P extends string,2108 MergedPath extends MergePath<BasePath, P>,
35 unmodified lines
2144 ]2145 ): HonoBase<2146 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>,2147 S & ToSchema<Ms[number], MergePath<BasePath, P>, I10, MergeTypedResponse<HandlerResponse<any>>>,2086 BasePath2148 BasePath,2149 MergePath<BasePath, P>2150 >21512152 // app.on(method[], path, ...handler)2153 <P extends string, R extends HandlerResponse<any> = any, I extends Input = BlankInput>(2154 methods: string[],2155 path: P,2093 ...handlers: H<E, MergePath<BasePath, P>, I, R>[]2094 ): HonoBase<E, S & ToSchema<string, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath>2156 ...handlers: [H<E, MergePath<BasePath, P>, I, R>, ...H<E, MergePath<BasePath, P>, I, R>[]]2157 ): HonoBase<2158 E,2159 S & ToSchema<string, MergePath<BasePath, P>, I, MergeTypedResponse<R>>,2160 BasePath,2161 MergePath<BasePath, P>2162 >21632164 // app.on(method | method[], path[], ...handlers[])2097 <I extends Input = BlankInput, R extends HandlerResponse<any> = any, E2 extends Env = E>(2165 <2166 const Ps extends string[],2167 I extends Input = BlankInput,2168 R extends HandlerResponse<any> = any,2169 E2 extends Env = E,2170 >(2171 methods: string | string[],2099 paths: string[],2100 ...handlers: H<E2, any, I, R>[]2101 ): HonoBase<E, S & ToSchema<string, string, I, MergeTypedResponse<R>>, BasePath>2172 paths: Ps,2173 ...handlers: H<E2, MergePath<BasePath, Ps[number]>, I, R>[]2174 ): HonoBase<2175 E,2176 S & ToSchema<string, MergePath<BasePath, Ps[number]>, I, MergeTypedResponse<R>>,2177 BasePath,2178 Ps extends [...string[], infer LastPath extends string] ? MergePath<BasePath, LastPath> : never2179 >2180}21812104type ExtractStringKey<S> = keyof S & string21052182////////////////////////////////////////2183////// //////2184////// ToSchema //////2185////// //////
3 unmodified lines
2189 M extends string,2190 P extends string,2191 I extends Input | Input['in'],2192 RorO, // Response or Output2117> = Simplify<{2118 [K in P]: {2119 [K2 in M as AddDollar<K2>]: Simplify<2120 {2121 input: AddParam<ExtractInput<I>, P>2122 } & (IsAny<RorO> extends true2123 ? {2124 output: {}2125 outputFormat: ResponseFormat2126 status: StatusCode2127 }2128 : RorO extends TypedResponse<infer T, infer U, infer F>2129 ? {2130 output: unknown extends T ? {} : T2131 outputFormat: I extends { outputFormat: string } ? I['outputFormat'] : F2132 status: U2133 }2134 : {2135 output: unknown extends RorO ? {} : RorO2136 outputFormat: unknown extends RorO2137 ? 'json'2138 : I extends { outputFormat: string }2139 ? I['outputFormat']2140 : 'json'2193> =2194 IsAny<RorO> extends true2195 ? Simplify<{2196 [K in P]: {2197 [K2 in M as AddDollar<K2>]: Simplify<2198 {2199 input: AddParam<ExtractInput<I>, P>2200 } & {2201 output: {}2202 outputFormat: ResponseFormat2203 status: StatusCode2142 })2143 >2144 }2145}>2204 }2205 >2206 }2207 }>2208 : [RorO] extends [never]2209 ? {}2210 : [RorO] extends [Promise<void>]2211 ? {}2212 : Simplify<{2213 [K in P]: {2214 [K2 in M as AddDollar<K2>]: Simplify<2215 {2216 input: AddParam<ExtractInput<I>, P>2217 } & (RorO extends TypedResponse<infer T, infer U, infer F>2218 ? {2219 output: unknown extends T ? {} : T2220 outputFormat: I extends { outputFormat: string } ? I['outputFormat'] : F2221 status: U2222 }2223 : {2224 output: unknown extends RorO ? {} : RorO2225 outputFormat: unknown extends RorO2226 ? 'json'2227 : I extends { outputFormat: string }2228 ? I['outputFormat']2229 : 'json'2230 status: StatusCode2231 })2232 >2233 }2234 }>22352236export type Schema = {2237 [Path: string]: {2238 [Method: `$${Lowercase<string>}`]: Endpoint2239 }2240}22412153type ChangePathOfSchema<S extends Schema, Path extends string> = keyof S extends never2154 ? { [K in Path]: {} }2155 : { [K in keyof S as Path]: S[K] }2242type AddSchemaIfHasResponse<2243 Merged,2244 S extends Schema,2245 M extends string,2246 P extends string,2247 I extends Input | Input['in'],2248 BasePath extends string,2249> = [Merged] extends [Promise<void>] ? S : S & ToSchema<M, MergePath<BasePath, P>, I, Merged>22502251export type Endpoint = {2252 input: any2253 output: any
97 unmodified lines
2351 _format: F2352}23532354type MergeTypedResponse<T> =2355 T extends Promise<void>2356 ? T2261 T extends Promise<infer T2>2262 ? T2 extends TypedResponse2263 ? T22264 : TypedResponse2265 : T extends TypedResponse2266 ? T2267 : TypedResponse2357 : T extends Promise<infer T2>2358 ? T2 extends TypedResponse2359 ? T22360 : TypedResponse2361 : T extends TypedResponse2362 ? T2363 : TypedResponse23642365type MergeTypedResponseStrict<T> =2366 T extends Promise<infer T2>2367 ? T2 extends TypedResponse
68 unmodified lines
2436////// //////2437////////////////////////////////////////24382439export type ExtractSchema<T> = UnionToIntersection<2344 T extends HonoBase<infer _, infer S, any> ? S : never2440 T extends HonoBase<infer _, infer S, any, any> ? S : never2441>24422443export type ExtractSchemaForStatusCode<T, Status extends number> = {2444 [Path in keyof ExtractSchema<T>]: {
36 unmodified lines