Skip to content
Myr

Merge pull request #4461 from honojs/next

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

Next

authored by Yusuke Wada · committed by GitHub · parents 9ae98c9, 1280661 · Browse files · 10 files+2026 added−221 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+2026 added−221 removed

  • tests:+1387 added−69 removed
  • other:+639 added−152 removed

10 files+2026 added−221 removed

modified:src/client/client.test.ts+106 added
906 unmodified lines
907 type verify = Expect<Equal<Expected, Actual>>908 })909})910911describe('Infer the response types from middlewares', () => {912 const app = new Hono()913 .get(914 '/',915 validator('query', (input, c) => {916 if (!input.page || typeof input.page !== 'string') {917 return c.json({ error: 'Bad request' as const }, 400)918 }919920 return input as { page: string }921 }),922 async (c) => {923 const query = c.req.valid('query')924 return c.json({ data: 'foo', page: query.page }, 200)925 }926 )927 .post(928 '/posts',929 async (c, next) => {930 const auth = c.req.header('authorization')931 if (!auth || !auth.startsWith('Bearer ')) {932 return c.json({ error: 'Unauthorized' as const }, 401)933 }934 return next()935 },936 validator('json', (input, c) => {937 if (!input.title) {938 return c.json({ error: 'Bad request' as const }, 400)939 }940941 return input as { title: string }942 }),943 (c) => {944 const data = c.req.valid('json')945 return c.json(data, 200)946 }947 )948949 type AppType = typeof app950 const client = hc<AppType>('', { fetch: app.request })951952 it('Should infer response type of status 200 correctly', () => {953 const req = client.posts.$post954955 type Actual = InferResponseType<typeof req, 200>956 type Expected = {957 title: string958 }959 type verify = Expect<Equal<Expected, Actual>>960 })961962 it('Should infer response type of status 400 correctly', () => {963 const req = client.posts.$post964965 type Actual = InferResponseType<typeof req, 400>966 type Expected = {967 error: 'Bad request'968 }969 type verify = Expect<Equal<Expected, Actual>>970 })971972 it('Should infer response type of status 401 correctly', () => {973 const req = client.posts.$post974975 type Actual = InferResponseType<typeof req, 401>976 type Expected = {977 error: 'Unauthorized'978 }979 type verify = Expect<Equal<Expected, Actual>>980 })981982 it('Should infer all possible response statuses', async () => {983 const req = await client.posts.$post({984 json: {985 title: 'hello',986 },987 })988989 type Actual = typeof req.status990 type Expected = 200 | 400 | 401991 type verify = Expect<Equal<Expected, Actual>>992 })993994 it('Should properly assign response to corresponding status', async () => {995 const req = await client.posts.$post({996 json: {997 title: 'hello',998 },999 })10001001 if (req.status === 200) {1002 const data = await req.json()10031004 expectTypeOf(data).toEqualTypeOf<{ title: string }>()1005 } else if (req.status === 400) {1006 const data = await req.json()10071008 expectTypeOf(data).toEqualTypeOf<{ error: 'Bad request' }>()1009 } else if (req.status === 401) {1010 const data = await req.json()10111012 expectTypeOf(data).toEqualTypeOf<{ error: 'Unauthorized' }>()1013 }1014 })1015})10161017describe('$url() with a param option', () => {1018 const app = new Hono()1019 .get('/posts/:id/comments', (c) => c.json({ ok: true }))1020 .get('/something/:firstId/:secondId/:version?', (c) => c.json({ ok: true }))
505 unmodified lines
modified:src/helper/factory/index.ts+7 added-6 removed
303 unmodified lines
304 }305 return app306 }307308 createMiddleware = <I extends Input = {}>(309 middleware: MiddlewareHandler<E, P, I>310 ): MiddlewareHandler<E, P, I> => middleware308 createMiddleware = <I extends Input = {}, R extends HandlerResponse<any> = Response>(309 middleware: MiddlewareHandler<E, P, I, R>310 ): MiddlewareHandler<E, P, I, R> => middleware311312 createHandlers: CreateHandlersInterface<E, P> = (...handlers: any) => {313 // @ts-expect-error this should not be typed314 return handlers.filter((handler) => handler !== undefined)
7 unmodified lines
322323export const createMiddleware = <324 E extends Env = any,325 P extends string = string,326 I extends Input = {}326 I extends Input = {},327 R extends HandlerResponse<any> = Response328>(328 middleware: MiddlewareHandler<E, P, I>329): MiddlewareHandler<E, P, I> => middleware329 middleware: MiddlewareHandler<E, P, I, R>330): MiddlewareHandler<E, P, I, R> => middleware
modified:src/helper/ssg/ssg.test.tsx+37 added-3 removed
7 unmodified lines
8 isSSGContext,9 onlySSG,10 ssgParams,11} from './middleware'12import { defaultExtensionMap, fetchRoutesContent, saveContentToFile, toSSG } from './ssg'12import {13 defaultExtensionMap,14 fetchRoutesContent,15 saveContentToFile,16 toSSG,17 defaultPlugin,18} from './ssg'19import type {20 AfterGenerateHook,21 AfterResponseHook,22 BeforeRequestHook,
808 unmodified lines
831 app = new Hono()832 app.get('/', (c) => c.html('<h1>Home</h1>'))833 app.get('/about', (c) => c.html('<h1>About</h1>'))834 app.get('/blog', (c) => c.html('<h1>Blog</h1>'))835 app.get('/created', (c) => c.text('201 Created', 201))836 app.get('/redirect', (c) => c.redirect('/'))837 app.get('/notfound', (c) => c.notFound())838 app.get('/error', (c) => c.text('500 Error', 500))839840 fsMock = {841 writeFile: vi.fn(() => Promise.resolve()),842 mkdir: vi.fn(() => Promise.resolve()),843 }844 })845846 it('should use defaultPlugin when plugins option is omitted', async () => {847 // @ts-expect-error defaultPlugin has afterResponseHook848 const defaultPluginSpy = vi.spyOn(defaultPlugin, 'afterResponseHook')849 await toSSG(app, fsMock, { dir: './static' })850 expect(defaultPluginSpy).toHaveBeenCalled()851 defaultPluginSpy.mockRestore()852 })853854 it('should skip non-200 responses with defaultPlugin', async () => {855 const result = await toSSG(app, fsMock, { plugins: [defaultPlugin], dir: './static' })856 expect(fsMock.writeFile).toHaveBeenCalledWith('static/index.html', '<h1>Home</h1>')857 expect(fsMock.writeFile).toHaveBeenCalledWith('static/about.html', '<h1>About</h1>')858 expect(fsMock.writeFile).toHaveBeenCalledWith('static/blog.html', '<h1>Blog</h1>')859 expect(fsMock.writeFile).not.toHaveBeenCalledWith('static/created.txt', expect.any(String))860 expect(fsMock.writeFile).not.toHaveBeenCalledWith('static/redirect.txt', expect.any(String))861 expect(fsMock.writeFile).not.toHaveBeenCalledWith('static/notfound.txt', expect.any(String))862 expect(fsMock.writeFile).not.toHaveBeenCalledWith('static/error.txt', expect.any(String))863 expect(result.files.some((f) => f.includes('created'))).toBe(false)864 expect(result.files.some((f) => f.includes('redirect'))).toBe(false)865 expect(result.files.some((f) => f.includes('notfound'))).toBe(false)866 expect(result.files.some((f) => f.includes('error'))).toBe(false)867 expect(result.success).toBe(true)868 })869870 it('should correctly apply plugins with beforeRequestHook', async () => {871 const plugin: SSGPlugin = {872 beforeRequestHook: (req) => {873 // Skip requests to the blog page
8 unmodified lines
882 const result = await toSSG(app, fsMock, {883 plugins: [plugin],884 })885852 expect(result.files).toHaveLength(2) // Home and About pages only886 expect(result.files).toHaveLength(6)887 expect(fsMock.writeFile).toHaveBeenCalledWith('static/index.html', '<h1>Home</h1>')888 expect(fsMock.writeFile).toHaveBeenCalledWith('static/about.html', '<h1>About</h1>')889 expect(fsMock.writeFile).not.toHaveBeenCalledWith('static/blog.html', '<h1>Blog</h1>')890 })
58 unmodified lines
949 const result = await toSSG(app, fsMock, {950 plugins: [skipBlogPlugin, prefixPlugin, sitemapPlugin],951 })952919 expect(result.files).toHaveLength(3) // Home, About, and sitemap.xml953 expect(result.files).toHaveLength(7)954 expect(fsMock.writeFile).toHaveBeenCalledWith('static/index.html', '[Prefix] <h1>Home</h1>')955 expect(fsMock.writeFile).toHaveBeenCalledWith('static/about.html', '[Prefix] <h1>About</h1>')956 expect(fsMock.writeFile).not.toHaveBeenCalledWith('static/blog.html', expect.any(String))957 expect(result.files).toContain('sitemap.xml')
73 unmodified lines
modified:src/helper/ssg/ssg.ts+17 added-1 removed
347 unmodified lines
348 (app: Hono<E, S, BasePath>, options?: ToSSGOptions): Promise<ToSSGResult>349}350351/**352 * The default plugin that defines the recommended behavior.353 *354 * @experimental355 * `defaultPlugin` is an experimental feature.356 * The API might be changed.357 */358export const defaultPlugin: SSGPlugin = {359 afterResponseHook: (res) => {360 if (res.status !== 200) {361 return false362 }363 return res364 },365}366367/**368 * @experimental369 * `toSSG` is an experimental feature.370 * The API might be changed.371 */372export const toSSG: ToSSGInterface = async (app, fs, options) => {373 let result: ToSSGResult | undefined374 const getInfoPromises: Promise<unknown>[] = []375 const savePromises: Promise<string | undefined>[] = []360 const plugins = options?.plugins || []376 const plugins = options?.plugins || [defaultPlugin]377 const beforeRequestHooks: BeforeRequestHook[] = []378 const afterResponseHooks: AfterResponseHook[] = []379 const afterGenerateHooks: AfterGenerateHook[] = []380 if (options?.beforeRequestHook) {
94 unmodified lines
modified:src/validator/validator.test.ts+224 added-63 removed
1/* eslint-disable @typescript-eslint/no-unused-vars */2import type { ZodSchema } from 'zod'3import { z } from 'zod'4import type { Context } from '../context'5import { Hono } from '../hono'6import { HTTPException } from '../http-exception'7import { cloneRawRequest } from '../request'8import type {9 ErrorHandler,10 ExtractSchema,11 ExtractSchemaForStatusCode,12 MiddlewareHandler,13 ParsedFormValue,14 TypedResponse,15 ValidationTargets,16} from '../types'13import type { ContentfulStatusCode } from '../utils/http-status'17import type { ContentfulStatusCode, StatusCode } from '../utils/http-status'18import type { Equal, Expect } from '../utils/types'19import type { ValidationFunction } from './validator'20import { validator } from './validator'2122// Helper type to extract the response type from the validation function23// eslint-disable-next-line @typescript-eslint/no-explicit-any24type InferValidatorResponse<VF> = VF extends (value: any, c: any) => infer R25 ? R extends Promise<infer PR>26 ? // eslint-disable-next-line @typescript-eslint/no-explicit-any27 PR extends Response | TypedResponse<any, any, any>28 ? PR29 : never30 : // eslint-disable-next-line @typescript-eslint/no-explicit-any31 R extends Response | TypedResponse<any, any, any>32 ? R33 : never34 : never3536// Reference implementation for only testing37const zodValidator = <38 T extends ZodSchema,39 E extends {},
1 unmodified line
41 Target extends keyof ValidationTargets42>(43 target: Target,44 schema: T27): MiddlewareHandler<28 E,29 P,30 { in: { [K in Target]: z.input<T> }; out: { [K in Target]: z.output<T> } }31> =>32 validator(target, (value, c) => {45) => {46 const validationFunc = (value: unknown, c: Context<E, P>) => {47 const result = schema.safeParse(value)48 if (!result.success) {49 return c.text('Invalid!', 400)50 }37 const data = result.data as z.output<T>38 return data39 })51 return result.data as z.output<T>52 }5354 type ResponseType = InferValidatorResponse<typeof validationFunc>5556 return validator(target, validationFunc) as MiddlewareHandler<57 E,58 P,59 { in: { [K in Target]: z.input<T> }; out: { [K in Target]: z.output<T> } },60 ResponseType61 >62}6364describe('Basic', () => {65 const app = new Hono()6667 const route = app.get(
2 unmodified lines
70 await next()71 },72 validator('query', (value, c) => {73 type verify = Expect<Equal<Record<string, string | string[]>, typeof value>>51 if (!value) {74 if (!value.q) {75 return c.text('Invalid!', 400)76 }77 }),78 (c) => {56 return c.text('Valid!')79 return c.text('Valid!', 200)80 }81 )8283 type Expected = {84 '/search': {85 $get:86 | {87 input: {88 query: {}89 }90 output: 'Invalid!'91 outputFormat: 'text'92 status: 40093 }62 $get: {63 input: {64 query: undefined65 }66 output: 'Valid!'67 outputFormat: 'text'68 status: ContentfulStatusCode69 }94 | {95 input: {96 query: {}97 }98 output: 'Valid!'99 outputFormat: 'text'100 status: 200101 }102 }103 }104105 type Actual = ExtractSchema<typeof route>
6 unmodified lines
112 })113114 it('Should return 400 response', async () => {115 const res = await app.request('http://localhost/search')84 expect(res.status).toBe(200)116 expect(res.status).toBe(400)117 })118})119120const onErrorHandler: ErrorHandler = (e, c) => {
375 unmodified lines
496 })497498 type Expected = {499 '/post': {468 $post: {469 input: {470 json: {471 id: string500 $post:501 | {502 input: {503 json: {504 id: number505 }506 }507 output: {}508 outputFormat: string509 status: StatusCode510 }511 | {512 input: {513 json: {514 id: number515 }473 }474 output: {475 post: {476 id: number516 }517 output: {518 post: {519 id: number520 }521 }522 outputFormat: 'json'523 status: ContentfulStatusCode524 }478 }479 outputFormat: 'json'480 status: ContentfulStatusCode481 }525 }526 }527528 type Actual = ExtractSchema<typeof route>
39 unmodified lines
568 })569570 type Expected = {571 '/post': {572 $post:529 $post: {530 input: {531 json: {532 id: number533 title: string573 | {574 input: {575 json: {576 id: number577 title: string578 }579 }580 output: 'Invalid!'581 outputFormat: 'text'582 status: 400583 }535 }536 output: {537 post: {538 id: number539 title: string584 | {585 input: {586 json: {587 id: number588 title: string589 }590 }591 output: {592 post: {593 id: number594 title: string595 }596 }597 outputFormat: 'json'598 status: ContentfulStatusCode599 }541 }542 outputFormat: 'json'543 status: ContentfulStatusCode544 }600 }601 }602603 type Actual = ExtractSchema<typeof route>
264 unmodified lines
868 type Actual = ExtractSchema<typeof route>869870 type Expected = {871 '/posts': {817 $post: {818 input: {819 query: {820 page: string872 $post:873 | {874 input: {875 query: {876 page: string877 }878 } & {879 form: {880 title: string881 }882 }883 output: 'Invalid!'884 outputFormat: 'text'885 status: 400886 }887 | {888 input: {889 query: {890 page: string891 }822 } & {823 form: {824 title: string892 } & {893 form: {894 title: string895 }896 }897 output: {898 page: number899 title: string900 }901 outputFormat: 'json'902 status: ContentfulStatusCode903 }826 }827 output: {828 page: number829 title: string830 }831 outputFormat: 'json'832 status: ContentfulStatusCode833 }904 }905 }906907 type verify = Expect<Equal<Expected, Actual>>
310 unmodified lines
1218 )1219 }1220 )12211152 expectTypeOf<ExtractSchema<typeof route>>().toEqualTypeOf<{1222 expectTypeOf<ExtractSchemaForStatusCode<typeof route, 201>>().toEqualTypeOf<{1223 '/posts': {1224 $post: {1225 input: {1226 json: {
9 unmodified lines
1236 status: 2011237 }1238 }1239 }>()12401241 expectTypeOf<ExtractSchemaForStatusCode<typeof route, 401>>().toEqualTypeOf<{1242 '/posts': {1243 $post: {1244 input: {1245 json: {1246 type: 'a'1247 name: string1248 age: number1249 }1250 }1251 output: {1252 foo: string1253 }1254 outputFormat: 'json'1255 status: 4011256 }1257 }1258 }>()1259 })1260})12611262describe('Transform', () => {
30 unmodified lines
1293 }12941295 type Actual = ExtractSchema<typeof route>1296 type verify = Expect<Equal<Expected, Actual>>12971298 // Temporary: let's see what the actual type is1299 type TestActual = Actual1300 })1301})13021303describe('Raw Request cloning after validation', () => {1304 it('Should allow the `cloneRawRequest` util to clone the request object after validation', async () => {1305 const app = new Hono()13061307 app.post(1308 '/json-validation',1309 validator('json', (data) => data),1310 async (c) => {1311 const clonedReq = await cloneRawRequest(c.req)1312 const clonedJSON = await clonedReq.json()13131314 return c.json({1315 originalMethod: c.req.raw.method,1316 clonedMethod: clonedReq.method,1317 clonedUrl: clonedReq.url,1318 clonedHeaders: {1319 contentType: clonedReq.headers.get('Content-Type'),1320 customHeader: clonedReq.headers.get('X-Custom-Header'),1321 },1322 originalCache: c.req.raw.cache,1323 clonedCache: clonedReq.cache,1324 originalCredentials: c.req.raw.credentials,1325 clonedCredentials: clonedReq.credentials,1326 originalMode: c.req.raw.mode,1327 clonedMode: clonedReq.mode,1328 originalRedirect: c.req.raw.redirect,1329 clonedRedirect: clonedReq.redirect,1330 originalReferrerPolicy: c.req.raw.referrerPolicy,1331 clonedReferrerPolicy: clonedReq.referrerPolicy,1332 cloned: JSON.stringify(clonedJSON) === JSON.stringify(await c.req.json()),1333 payload: clonedJSON,1334 })1335 }1336 )13371338 const testData = { message: 'test', userId: 123 }1339 const res = await app.request('/json-validation', {1340 method: 'POST',1341 headers: {1342 'Content-Type': 'application/json',1343 'X-Custom-Header': 'test-value',1344 },1345 body: JSON.stringify(testData),1346 cache: 'no-cache',1347 credentials: 'include',1348 mode: 'cors',1349 redirect: 'follow',1350 referrerPolicy: 'origin',1351 })13521353 expect(res.status).toBe(200)13541355 const result = await res.json()13561357 expect(result.originalMethod).toBe('POST')1358 expect(result.clonedMethod).toBe('POST')1359 expect(result.clonedUrl).toBe('http://localhost/json-validation')1360 expect(result.clonedHeaders.contentType).toBe('application/json')1361 expect(result.clonedHeaders.customHeader).toBe('test-value')1362 expect(result.clonedCache).toBe(result.originalCache)1363 expect(result.clonedCredentials).toBe(result.originalCredentials)1364 expect(result.clonedMode).toBe(result.originalMode)1365 expect(result.clonedRedirect).toBe(result.originalRedirect)1366 expect(result.clonedReferrerPolicy).toBe(result.originalReferrerPolicy)1367 expect(result.cloned).toBe(true)1368 expect(result.payload).toMatchObject(testData)1369 })1370})
modified:src/validator/validator.ts+54 added-21 removed
modified:src/request.test.ts+125 added-1 removed
1import { HonoRequest } from './request'1import { HTTPException } from './http-exception'2import { cloneRawRequest, HonoRequest } from './request'3import type { RouterRoute } from './types'45type RecursiveRecord<K extends string, T> = {6 [key in K]: T | RecursiveRecord<K, T>
371 unmodified lines
378 })379 })380 })381})382383describe('cloneRawRequest', () => {384 test('clones unconsumed request object', async () => {385 const req = new HonoRequest(386 new Request('http://localhost', {387 method: 'POST',388 headers: {389 'Content-Type': 'application/json',390 'X-Custom-Header': 'custom-value',391 },392 body: text,393 cache: 'no-cache',394 credentials: 'include',395 integrity: 'sha256-test',396 mode: 'cors',397 redirect: 'follow',398 referrer: 'http://example.com',399 referrerPolicy: 'origin',400 })401 )402403 const clonedReq = await cloneRawRequest(req)404405 expect(clonedReq.method).toBe('POST')406 expect(clonedReq.url).toBe('http://localhost/')407 expect(await clonedReq.text()).toBe(text)408 expect(clonedReq.headers.get('Content-Type')).toBe('application/json')409 expect(clonedReq.headers.get('X-Custom-Header')).toBe('custom-value')410 expect(clonedReq.cache).toBe('no-cache')411 expect(clonedReq.credentials).toBe('include')412 expect(clonedReq.integrity).toBe('sha256-test')413 expect(clonedReq.mode).toBe('cors')414 expect(clonedReq.redirect).toBe('follow')415 expect(clonedReq.referrer).toBe('http://example.com/')416 expect(clonedReq.referrerPolicy).toBe('origin')417 expect(req.raw, 'cloned request should be a different object reference').not.toBe(clonedReq)418 expect(req.raw, 'cloned request should contain the same properties').toMatchObject(clonedReq)419 })420421 test('clones consumed request object', async () => {422 const req = new HonoRequest(423 new Request('http://localhost', {424 method: 'POST',425 headers: {426 Authorization: 'Bearer token123',427 },428 body: text,429 mode: 'same-origin',430 credentials: 'same-origin',431 })432 )433 await req.json()434435 const clonedReq = await cloneRawRequest(req)436437 expect(clonedReq.method).toBe('POST')438 expect(clonedReq.url).toBe('http://localhost/')439 expect(await clonedReq.json()).toEqual(json)440 expect(clonedReq.headers.get('Authorization')).toBe('Bearer token123')441 expect(clonedReq.mode).toBe('same-origin')442 expect(clonedReq.credentials).toBe('same-origin')443 expect(req.raw, 'cloned request should be a different object reference').not.toBe(clonedReq)444 expect(req.raw, 'cloned request should contain the same properties').toMatchObject(clonedReq)445 })446447 test('clones GET request without body', async () => {448 const req = new HonoRequest(449 new Request('http://localhost', {450 method: 'GET',451 headers: {452 'User-Agent': 'test-agent',453 },454 cache: 'default',455 redirect: 'manual',456 referrerPolicy: 'no-referrer',457 })458 )459460 const clonedReq = await cloneRawRequest(req)461462 expect(clonedReq.method).toBe('GET')463 expect(clonedReq.url).toBe('http://localhost/')464 expect(clonedReq.headers.get('User-Agent')).toBe('test-agent')465 expect(clonedReq.cache).toBe('default')466 expect(clonedReq.redirect).toBe('manual')467 expect(clonedReq.referrerPolicy).toBe('no-referrer')468 expect(req.raw, 'cloned request should be a different object reference').not.toBe(clonedReq)469 expect(req.raw, 'cloned request should contain the same properties').toMatchObject(clonedReq)470 })471472 test('clones request when raw body was consumed directly without HonoRequest methods', async () => {473 const req = new HonoRequest(474 new Request('http://localhost', {475 method: 'POST',476 headers: {477 'Content-Type': 'application/json',478 },479 body: text,480 })481 )482483 // Consume the raw request body directly, bypassing HonoRequest methods484 // This means bodyCache will be empty485 await req.raw.text()486487 expect(req.raw.bodyUsed).toBe(true)488 expect(Object.keys(req.bodyCache).length).toBe(0)489490 let error: HTTPException | undefined = undefined491 try {492 await cloneRawRequest(req)493 } catch (e) {494 expect(e).toBeInstanceOf(HTTPException)495 error = e as HTTPException496 }497498 expect(error).not.toBeUndefined()499 expect((error as HTTPException).status).toBe(500)500 expect((error as HTTPException).message).toContain(501 'Cannot clone request: body was already consumed and not cached'502 )503 })504})
modified:src/request.ts+68 added
1/* eslint-disable @typescript-eslint/no-explicit-any */2import { HTTPException } from './http-exception'3import { GET_MATCH_RESULT } from './request/constants'4import type { Result } from './router'5import type {6 Input,
18 unmodified lines
25 formData: FormData26}27type BodyCache = Partial<Body & { parsedBody: BodyData }>2829type OptionalRequestInitProperties = 'window' | 'priority'30type RequiredRequestInit = Required<Omit<RequestInit, OptionalRequestInitProperties>> & {31 [Key in OptionalRequestInitProperties]?: RequestInit[Key]32}3334const tryDecodeURIComponent = (str: string) => tryDecode(str, decodeURIComponent_)3536export class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {37 /**
384 unmodified lines
422 get routePath(): string {423 return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path424 }425}426427/**428 * Clones a HonoRequest's underlying raw Request object.429 *430 * This utility handles both consumed and unconsumed request bodies:431 * - If the request body hasn't been consumed, it uses the native `clone()` method432 * - If the request body has been consumed, it reconstructs a new Request using cached body data433 *434 * This is particularly useful when you need to:435 * - Process the same request body multiple times436 * - Pass requests to external services after validation437 *438 * @param req - The HonoRequest object to clone439 * @returns A Promise that resolves to a new Request object with the same properties440 * @throws {HTTPException} If the request body was consumed directly via `req.raw`441 * without using HonoRequest methods (e.g., `req.json()`, `req.text()`), making it442 * impossible to reconstruct the body from cache443 *444 * @example445 * ```ts446 * // Clone after consuming the body (e.g., after validation)447 * app.post('/forward',448 * validator('json', (data) => data),449 * async (c) => {450 * const validated = c.req.valid('json')451 * // Body has been consumed, but cloneRawRequest still works452 * const clonedReq = await cloneRawRequest(c.req)453 * return fetch('http://backend-service.com', clonedReq)454 * }455 * )456 * ```457 */458export const cloneRawRequest = async (req: HonoRequest): Promise<Request> => {459 if (!req.raw.bodyUsed) {460 return req.raw.clone()461 }462463 const cacheKey = (Object.keys(req.bodyCache) as Array<keyof Body>)[0]464 if (!cacheKey) {465 throw new HTTPException(500, {466 message:467 'Cannot clone request: body was already consumed and not cached. Please use HonoRequest methods (e.g., req.json(), req.text()) instead of consuming req.raw directly.',468 })469 }470471 const requestInit: RequiredRequestInit = {472 body: await req[cacheKey](),473 cache: req.raw.cache,474 credentials: req.raw.credentials,475 headers: req.header(),476 integrity: req.raw.integrity,477 keepalive: req.raw.keepalive,478 method: req.method,479 mode: req.raw.mode,480 redirect: req.raw.redirect,481 referrer: req.raw.referrer,482 referrerPolicy: req.raw.referrerPolicy,483 signal: req.raw.signal,484 }485486 return new Request(req.url, requestInit)487}
modified:src/types.test.ts+895 added-2 removed
1/* eslint-disable @typescript-eslint/no-unused-vars */2import { expectTypeOf } from 'vitest'3import { hc } from './client'4import { Context } from './context'5import { createMiddleware } from './helper/factory'6import { Hono } from './hono'7import { poweredBy } from './middleware/powered-by'
101 unmodified lines
109 const app = new Hono<Env>()110 const middleware: MiddlewareHandler<111 Env,112 '/foo',112 { in: { json: Payload }; out: { json: Payload } }113 { in: { json: Payload }; out: { json: Payload } },114 never115 > = async (_c, next) => {116 await next()117 }118119 test('Context and AppType', () => {120 const route = app.get('/foo', middleware, (c) => {121 type Expected = Context<Env, '/foo', { in: { json: Payload }; out: { json: Payload } }>122 expectTypeOf(c).toEqualTypeOf<Expected>()
24 unmodified lines
147 })148149 describe('With path parameters', () => {150 const app = new Hono<Env>()148 const middleware: MiddlewareHandler<Env, '/post/:id'> = async (_c, next) => {151 const middleware: MiddlewareHandler<Env, '/post/:id', {}, never> = async (_c, next) => {152 await next()153 }154 it('Should have the `param` type', () => {155 const route = app.get('/post/:id', middleware, (c) => {
2245 unmodified lines
2401 type Actual = ExtractSchema<typeof router>['/']['$get']['status']2402 expectTypeOf<Actual>().toEqualTypeOf<204 | 201 | 200>()2403 })2404})24052406describe('RPC supports Middleware responses', () => {2407 describe('Merge responses from multiple handlers, path pattern', () => {2408 test('merge responses from 1 middleware', async () => {2409 const middleware = createMiddleware(async (c) => c.json({ '400': true }, 400))24102411 const app = new Hono().get('/test', middleware, (c) => c.json({ '200': true }, 200))2412 const client = hc<typeof app>('http://localhost', { fetch: app.request })2413 const res = await client.test.$get()24142415 if (res.status === 200) {2416 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2417 }2418 if (res.status === 400) {2419 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2420 }2421 })24222423 test('merge responses from 2 middlewares', async () => {2424 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2425 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))24262427 const app = new Hono().get('/test', middleware1, middleware2, (c) =>2428 c.json({ '200': true }, 200)2429 )2430 const client = hc<typeof app>('http://localhost', { fetch: app.request })2431 const res = await client.test.$get()24322433 if (res.status === 200) {2434 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2435 }2436 if (res.status === 400) {2437 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2438 }2439 if (res.status === 401) {2440 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2441 }2442 })24432444 test('merge responses from 3 middlewares', async () => {2445 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2446 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2447 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))24482449 const app = new Hono().get('/test', middleware1, middleware2, middleware3, (c) =>2450 c.json({ '200': true }, 200)2451 )2452 const client = hc<typeof app>('http://localhost', { fetch: app.request })2453 const res = await client.test.$get()24542455 if (res.status === 200) {2456 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2457 }2458 if (res.status === 400) {2459 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2460 }2461 if (res.status === 401) {2462 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2463 }2464 if (res.status === 403) {2465 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2466 }2467 })24682469 test('merge responses from 4 middlewares', async () => {2470 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2471 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2472 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2473 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))24742475 const app = new Hono().get('/test', middleware1, middleware2, middleware3, middleware4, (c) =>2476 c.json({ '200': true }, 200)2477 )2478 const client = hc<typeof app>('http://localhost', { fetch: app.request })2479 const res = await client.test.$get()24802481 if (res.status === 200) {2482 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2483 }2484 if (res.status === 400) {2485 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2486 }2487 if (res.status === 401) {2488 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2489 }2490 if (res.status === 403) {2491 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2492 }2493 if (res.status === 404) {2494 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2495 }2496 })24972498 test('merge responses from 5 middlewares', async () => {2499 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2500 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2501 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2502 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2503 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))25042505 const app = new Hono().get(2506 '/test',2507 middleware1,2508 middleware2,2509 middleware3,2510 middleware4,2511 middleware5,2512 (c) => c.json({ '200': true }, 200)2513 )2514 const client = hc<typeof app>('http://localhost', { fetch: app.request })2515 const res = await client.test.$get()25162517 if (res.status === 200) {2518 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2519 }2520 if (res.status === 400) {2521 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2522 }2523 if (res.status === 401) {2524 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2525 }2526 if (res.status === 403) {2527 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2528 }2529 if (res.status === 300) {2530 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2531 }2532 })25332534 test('merge responses from 6 middlewares', async () => {2535 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2536 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2537 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2538 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2539 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))2540 const middleware6 = createMiddleware(async (c) => c.json({ '201': true }, 201))25412542 const app = new Hono().get(2543 '/test',2544 middleware1,2545 middleware2,2546 middleware3,2547 middleware4,2548 middleware5,2549 middleware6,2550 (c) => c.json({ '200': true }, 200)2551 )2552 const client = hc<typeof app>('http://localhost', { fetch: app.request })2553 const res = await client.test.$get()25542555 if (res.status === 200) {2556 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2557 }2558 if (res.status === 400) {2559 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2560 }2561 if (res.status === 401) {2562 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2563 }2564 if (res.status === 403) {2565 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2566 }2567 if (res.status === 404) {2568 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2569 }2570 if (res.status === 300) {2571 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2572 }2573 if (res.status === 201) {2574 expectTypeOf(await res.json()).toEqualTypeOf<{ 201: true }>()2575 }2576 })25772578 test('merge responses from 7 middlewares', async () => {2579 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2580 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2581 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2582 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2583 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))2584 const middleware6 = createMiddleware(async (c) => c.json({ '201': true }, 201))2585 const middleware7 = createMiddleware(async (c) => c.json({ '202': true }, 202))25862587 const app = new Hono().get(2588 '/test',2589 middleware1,2590 middleware2,2591 middleware3,2592 middleware4,2593 middleware5,2594 middleware6,2595 middleware7,2596 (c) => c.json({ '200': true }, 200)2597 )2598 const client = hc<typeof app>('http://localhost', { fetch: app.request })2599 const res = await client.test.$get()26002601 if (res.status === 200) {2602 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2603 }2604 if (res.status === 400) {2605 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2606 }2607 if (res.status === 401) {2608 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2609 }2610 if (res.status === 403) {2611 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2612 }2613 if (res.status === 404) {2614 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2615 }2616 if (res.status === 300) {2617 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2618 }2619 if (res.status === 201) {2620 expectTypeOf(await res.json()).toEqualTypeOf<{ 201: true }>()2621 }2622 if (res.status === 202) {2623 expectTypeOf(await res.json()).toEqualTypeOf<{ 202: true }>()2624 }2625 })26262627 test('merge responses from 8 middlewares', async () => {2628 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2629 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2630 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2631 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2632 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))2633 const middleware6 = createMiddleware(async (c) => c.json({ '201': true }, 201))2634 const middleware7 = createMiddleware(async (c) => c.json({ '202': true }, 202))2635 const middleware8 = createMiddleware(async (c) => c.json({ '203': true }, 203))26362637 const app = new Hono().get(2638 '/test',2639 middleware1,2640 middleware2,2641 middleware3,2642 middleware4,2643 middleware5,2644 middleware6,2645 middleware7,2646 middleware8,2647 (c) => c.json({ '200': true }, 200)2648 )2649 const client = hc<typeof app>('http://localhost', { fetch: app.request })2650 const res = await client.test.$get()26512652 if (res.status === 200) {2653 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2654 }2655 if (res.status === 400) {2656 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2657 }2658 if (res.status === 401) {2659 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2660 }2661 if (res.status === 403) {2662 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2663 }2664 if (res.status === 404) {2665 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2666 }2667 if (res.status === 300) {2668 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2669 }2670 if (res.status === 201) {2671 expectTypeOf(await res.json()).toEqualTypeOf<{ 201: true }>()2672 }2673 if (res.status === 202) {2674 expectTypeOf(await res.json()).toEqualTypeOf<{ 202: true }>()2675 }2676 if (res.status === 203) {2677 expectTypeOf(await res.json()).toEqualTypeOf<{ 203: true }>()2678 }2679 })26802681 test('merge responses from 9 middlewares', async () => {2682 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2683 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2684 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2685 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2686 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))2687 const middleware6 = createMiddleware(async (c) => c.json({ '201': true }, 201))2688 const middleware7 = createMiddleware(async (c) => c.json({ '202': true }, 202))2689 const middleware8 = createMiddleware(async (c) => c.json({ '203': true }, 203))2690 const middleware9 = createMiddleware(async (c) => c.json({ '301': true }, 301))26912692 const app = new Hono().get(2693 '/test',2694 middleware1,2695 middleware2,2696 middleware3,2697 middleware4,2698 middleware5,2699 middleware6,2700 middleware7,2701 middleware8,2702 middleware9,2703 (c) => c.json({ '200': true }, 200)2704 )2705 const client = hc<typeof app>('http://localhost', { fetch: app.request })2706 const res = await client.test.$get()27072708 if (res.status === 200) {2709 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2710 }2711 if (res.status === 400) {2712 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2713 }2714 if (res.status === 401) {2715 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2716 }2717 if (res.status === 403) {2718 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2719 }2720 if (res.status === 404) {2721 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2722 }2723 if (res.status === 300) {2724 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2725 }2726 if (res.status === 201) {2727 expectTypeOf(await res.json()).toEqualTypeOf<{ 201: true }>()2728 }2729 if (res.status === 202) {2730 expectTypeOf(await res.json()).toEqualTypeOf<{ 202: true }>()2731 }2732 if (res.status === 203) {2733 expectTypeOf(await res.json()).toEqualTypeOf<{ 203: true }>()2734 }2735 if (res.status === 301) {2736 expectTypeOf(await res.json()).toEqualTypeOf<{ 301: true }>()2737 }2738 })2739 })27402741 describe('Merge responses from multiple handlers, no path pattern', () => {2742 test('merge responses from 1 middleware', async () => {2743 const middleware = createMiddleware(async (c) => c.json({ '400': true }, 400))27442745 const app = new Hono().get(middleware, (c) => c.json({ '200': true }, 200))2746 const client = hc<typeof app>('http://localhost', { fetch: app.request })2747 const res = await client.index.$get()27482749 if (res.status === 200) {2750 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2751 }2752 if (res.status === 400) {2753 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2754 }2755 })27562757 test('merge responses from 2 middlewares', async () => {2758 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2759 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))27602761 const app = new Hono().get(middleware1, middleware2, (c) => c.json({ '200': true }, 200))2762 const client = hc<typeof app>('http://localhost', { fetch: app.request })2763 const res = await client.index.$get()27642765 if (res.status === 200) {2766 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2767 }2768 if (res.status === 400) {2769 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2770 }2771 if (res.status === 401) {2772 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2773 }2774 })27752776 test('merge responses from 3 middlewares', async () => {2777 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2778 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2779 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))27802781 const app = new Hono().get(middleware1, middleware2, middleware3, (c) =>2782 c.json({ '200': true }, 200)2783 )2784 const client = hc<typeof app>('http://localhost', { fetch: app.request })2785 const res = await client.index.$get()27862787 if (res.status === 200) {2788 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2789 }2790 if (res.status === 400) {2791 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2792 }2793 if (res.status === 401) {2794 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2795 }2796 if (res.status === 403) {2797 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2798 }2799 })28002801 test('merge responses from 4 middlewares', async () => {2802 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2803 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2804 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2805 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))28062807 const app = new Hono().get(middleware1, middleware2, middleware3, middleware4, (c) =>2808 c.json({ '200': true }, 200)2809 )2810 const client = hc<typeof app>('http://localhost', { fetch: app.request })2811 const res = await client.index.$get()28122813 if (res.status === 200) {2814 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2815 }2816 if (res.status === 400) {2817 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2818 }2819 if (res.status === 401) {2820 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2821 }2822 if (res.status === 403) {2823 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2824 }2825 if (res.status === 404) {2826 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2827 }2828 })28292830 test('merge responses from 5 middlewares', async () => {2831 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2832 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2833 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2834 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2835 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))28362837 const app = new Hono().get(2838 middleware1,2839 middleware2,2840 middleware3,2841 middleware4,2842 middleware5,2843 (c) => c.json({ '200': true }, 200)2844 )2845 const client = hc<typeof app>('http://localhost', { fetch: app.request })2846 const res = await client.index.$get()28472848 if (res.status === 200) {2849 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2850 }2851 if (res.status === 400) {2852 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2853 }2854 if (res.status === 401) {2855 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2856 }2857 if (res.status === 403) {2858 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2859 }2860 if (res.status === 300) {2861 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2862 }2863 })28642865 test('merge responses from 6 middlewares', async () => {2866 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2867 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2868 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2869 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2870 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))2871 const middleware6 = createMiddleware(async (c) => c.json({ '201': true }, 201))28722873 const app = new Hono().get(2874 middleware1,2875 middleware2,2876 middleware3,2877 middleware4,2878 middleware5,2879 middleware6,2880 (c) => c.json({ '200': true }, 200)2881 )2882 const client = hc<typeof app>('http://localhost', { fetch: app.request })2883 const res = await client.index.$get()28842885 if (res.status === 200) {2886 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2887 }2888 if (res.status === 400) {2889 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2890 }2891 if (res.status === 401) {2892 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2893 }2894 if (res.status === 403) {2895 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2896 }2897 if (res.status === 404) {2898 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2899 }2900 if (res.status === 300) {2901 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2902 }2903 if (res.status === 201) {2904 expectTypeOf(await res.json()).toEqualTypeOf<{ 201: true }>()2905 }2906 })29072908 test('merge responses from 7 middlewares', async () => {2909 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2910 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2911 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2912 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2913 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))2914 const middleware6 = createMiddleware(async (c) => c.json({ '201': true }, 201))2915 const middleware7 = createMiddleware(async (c) => c.json({ '202': true }, 202))29162917 const app = new Hono().get(2918 middleware1,2919 middleware2,2920 middleware3,2921 middleware4,2922 middleware5,2923 middleware6,2924 middleware7,2925 (c) => c.json({ '200': true }, 200)2926 )2927 const client = hc<typeof app>('http://localhost', { fetch: app.request })2928 const res = await client.index.$get()29292930 if (res.status === 200) {2931 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2932 }2933 if (res.status === 400) {2934 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2935 }2936 if (res.status === 401) {2937 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2938 }2939 if (res.status === 403) {2940 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2941 }2942 if (res.status === 404) {2943 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2944 }2945 if (res.status === 300) {2946 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2947 }2948 if (res.status === 201) {2949 expectTypeOf(await res.json()).toEqualTypeOf<{ 201: true }>()2950 }2951 if (res.status === 202) {2952 expectTypeOf(await res.json()).toEqualTypeOf<{ 202: true }>()2953 }2954 })29552956 test('merge responses from 8 middlewares', async () => {2957 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))2958 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))2959 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))2960 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))2961 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))2962 const middleware6 = createMiddleware(async (c) => c.json({ '201': true }, 201))2963 const middleware7 = createMiddleware(async (c) => c.json({ '202': true }, 202))2964 const middleware8 = createMiddleware(async (c) => c.json({ '203': true }, 203))29652966 const app = new Hono().get(2967 middleware1,2968 middleware2,2969 middleware3,2970 middleware4,2971 middleware5,2972 middleware6,2973 middleware7,2974 middleware8,2975 (c) => c.json({ '200': true }, 200)2976 )2977 const client = hc<typeof app>('http://localhost', { fetch: app.request })2978 const res = await client.index.$get()29792980 if (res.status === 200) {2981 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()2982 }2983 if (res.status === 400) {2984 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()2985 }2986 if (res.status === 401) {2987 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()2988 }2989 if (res.status === 403) {2990 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()2991 }2992 if (res.status === 404) {2993 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()2994 }2995 if (res.status === 300) {2996 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()2997 }2998 if (res.status === 201) {2999 expectTypeOf(await res.json()).toEqualTypeOf<{ 201: true }>()3000 }3001 if (res.status === 202) {3002 expectTypeOf(await res.json()).toEqualTypeOf<{ 202: true }>()3003 }3004 if (res.status === 203) {3005 expectTypeOf(await res.json()).toEqualTypeOf<{ 203: true }>()3006 }3007 })30083009 test('merge responses from 9 middlewares', async () => {3010 const middleware1 = createMiddleware(async (c) => c.json({ '400': true }, 400))3011 const middleware2 = createMiddleware(async (c) => c.json({ '401': true }, 401))3012 const middleware3 = createMiddleware(async (c) => c.json({ '403': true }, 403))3013 const middleware4 = createMiddleware(async (c) => c.json({ '404': true }, 404))3014 const middleware5 = createMiddleware(async (c) => c.json({ '300': true }, 300))3015 const middleware6 = createMiddleware(async (c) => c.json({ '201': true }, 201))3016 const middleware7 = createMiddleware(async (c) => c.json({ '202': true }, 202))3017 const middleware8 = createMiddleware(async (c) => c.json({ '203': true }, 203))3018 const middleware9 = createMiddleware(async (c) => c.json({ '301': true }, 301))30193020 const app = new Hono().get(3021 middleware1,3022 middleware2,3023 middleware3,3024 middleware4,3025 middleware5,3026 middleware6,3027 middleware7,3028 middleware8,3029 middleware9,3030 (c) => c.json({ '200': true }, 200)3031 )3032 const client = hc<typeof app>('http://localhost', { fetch: app.request })3033 const res = await client.index.$get()30343035 if (res.status === 200) {3036 expectTypeOf(await res.json()).toEqualTypeOf<{ 200: true }>()3037 }3038 if (res.status === 400) {3039 expectTypeOf(await res.json()).toEqualTypeOf<{ 400: true }>()3040 }3041 if (res.status === 401) {3042 expectTypeOf(await res.json()).toEqualTypeOf<{ 401: true }>()3043 }3044 if (res.status === 403) {3045 expectTypeOf(await res.json()).toEqualTypeOf<{ 403: true }>()3046 }3047 if (res.status === 404) {3048 expectTypeOf(await res.json()).toEqualTypeOf<{ 404: true }>()3049 }3050 if (res.status === 300) {3051 expectTypeOf(await res.json()).toEqualTypeOf<{ 300: true }>()3052 }3053 if (res.status === 201) {3054 expectTypeOf(await res.json()).toEqualTypeOf<{ 201: true }>()3055 }3056 if (res.status === 202) {3057 expectTypeOf(await res.json()).toEqualTypeOf<{ 202: true }>()3058 }3059 if (res.status === 203) {3060 expectTypeOf(await res.json()).toEqualTypeOf<{ 203: true }>()3061 }3062 if (res.status === 301) {3063 expectTypeOf(await res.json()).toEqualTypeOf<{ 301: true }>()3064 }3065 })3066 })30673068 describe('Infers types with multiple middlewares but none returning response', () => {3069 const middleware = createMiddleware(async () => {})3070 const handler = (c: Context) => c.json({ ok: true }, 200)3071 type Expected = {3072 '/': {3073 $get: {3074 input: {}3075 output: {3076 ok: true3077 }3078 outputFormat: 'json'3079 status: 2003080 }3081 }3082 }30833084 test('infer the correct response type with 1 middleware and 1 handler', () => {3085 const routes = new Hono().get('/', middleware, handler)3086 type Actual = ExtractSchema<typeof routes>3087 type verify = Expect<Equal<Expected, Actual>>3088 })30893090 test('infer the correct response type with 1 middleware and 2 handler', () => {3091 const routes = new Hono().get('/', middleware, handler, handler)3092 type Actual = ExtractSchema<typeof routes>3093 type verify = Expect<Equal<Expected, Actual>>3094 })30953096 test('infer the correct response type with 2 middleware and 1 handler', () => {3097 const routes = new Hono().get('/', middleware, middleware, handler)3098 type Actual = ExtractSchema<typeof routes>3099 type verify = Expect<Equal<Expected, Actual>>3100 })31013102 test('infer the correct response type with 3 middleware and 1 handler', () => {3103 const routes = new Hono().get('/', middleware, middleware, middleware, handler)3104 type Actual = ExtractSchema<typeof routes>3105 type verify = Expect<Equal<Expected, Actual>>3106 })31073108 test('infer the correct response type with 4 middleware and 1 handler', () => {3109 const routes = new Hono().get('/', middleware, middleware, middleware, middleware, handler)3110 type Actual = ExtractSchema<typeof routes>3111 type verify = Expect<Equal<Expected, Actual>>3112 })31133114 test('infer the correct response type with 5 middleware and 1 handler', () => {3115 const routes = new Hono().get(3116 '/',3117 middleware,3118 middleware,3119 middleware,3120 middleware,3121 middleware,3122 handler3123 )3124 type Actual = ExtractSchema<typeof routes>3125 type verify = Expect<Equal<Expected, Actual>>3126 })31273128 test('infer the correct response type with 6 middleware and 1 handler', () => {3129 const routes = new Hono().get(3130 '/',3131 middleware,3132 middleware,3133 middleware,3134 middleware,3135 middleware,3136 middleware,3137 handler3138 )3139 type Actual = ExtractSchema<typeof routes>3140 type verify = Expect<Equal<Expected, Actual>>3141 })31423143 test('infer the correct response type with 7 middleware and 1 handler', () => {3144 const routes = new Hono().get(3145 '/',3146 middleware,3147 middleware,3148 middleware,3149 middleware,3150 middleware,3151 middleware,3152 middleware,3153 handler3154 )3155 type Actual = ExtractSchema<typeof routes>3156 type verify = Expect<Equal<Expected, Actual>>3157 })31583159 test('infer the correct response type with 8 middleware and 1 handler', () => {3160 const routes = new Hono().get(3161 '/',3162 middleware,3163 middleware,3164 middleware,3165 middleware,3166 middleware,3167 middleware,3168 middleware,3169 middleware,3170 handler3171 )3172 type Actual = ExtractSchema<typeof routes>3173 type verify = Expect<Equal<Expected, Actual>>3174 })31753176 test('infer the correct response type with 9 middleware and 1 handler', () => {3177 const routes = new Hono().get(3178 '/',3179 middleware,3180 middleware,3181 middleware,3182 middleware,3183 middleware,3184 middleware,3185 middleware,3186 middleware,3187 middleware,3188 handler3189 )3190 type Actual = ExtractSchema<typeof routes>3191 type verify = Expect<Equal<Expected, Actual>>3192 })3193 })31943195 describe('Infers types with multiple middlewares but only some returning response', () => {3196 const handler = (c: Context) => c.json({ ok: true }, 200)31973198 test('infer the correct response type with 2 middleware, only one returning response', () => {3199 const middleware1 = async (c: Context) => {3200 if (Math.random() > 0.5) {3201 return c.json(3202 {3203 q: true,3204 },3205 2003206 )3207 }3208 }3209 const middleware2 = async () => {}32103211 const routes = new Hono().get('/', middleware1, middleware2, handler)3212 type Actual = ExtractSchema<typeof routes>3213 type Expected = {3214 '/': {3215 $get:3216 | {3217 input: {}3218 output: {3219 ok: true3220 }3221 outputFormat: 'json'3222 status: 2003223 }3224 | {3225 input: {}3226 output: {3227 q: true3228 }3229 outputFormat: 'json'3230 status: 2003231 }3232 }3233 }3234 type verify = Expect<Equal<Expected, Actual>>3235 })32363237 test('infer the correct response type with 3 middleware, 2 returning response', () => {3238 const middleware1 = async (c: Context) => {3239 if (Math.random() > 0.5) {3240 return c.json(3241 {3242 q1: true,3243 },3244 2003245 )3246 }3247 }3248 const middleware2 = async (c: Context) => {3249 if (Math.random() > 0.5) {3250 return c.json(3251 {3252 q2: true,3253 },3254 2003255 )3256 }3257 }3258 const middleware3 = async () => {}32593260 const routes = new Hono().get('/', middleware1, middleware2, middleware3, handler)3261 type Actual = ExtractSchema<typeof routes>3262 type Expected = {3263 '/': {3264 $get:3265 | {3266 input: {}3267 output: {3268 ok: true3269 }3270 outputFormat: 'json'3271 status: 2003272 }3273 | {3274 input: {}3275 output: {3276 q1: true3277 }3278 outputFormat: 'json'3279 status: 2003280 }3281 | {3282 input: {}3283 output: {3284 q2: true3285 }3286 outputFormat: 'json'3287 status: 2003288 }3289 }3290 }3291 type verify = Expect<Equal<Expected, Actual>>3292 })3293 })3294})
modified:src/types.ts+493 added-124 removed
78 unmodified lines
7980export type MiddlewareHandler<81 E extends Env = any,82 P extends string = string,83 I extends Input = {}84> = (c: Context<E, P, I>, next: Next) => Promise<Response | void>83 I extends Input = {},84 R extends HandlerResponse<any> = Response85> = (c: Context<E, P, I>, next: Next) => Promise<R | void>8687export type H<88 E extends Env = any,89 P extends string = any,90 I extends Input = BlankInput,91 R extends HandlerResponse<any> = any91> = Handler<E, P, I, R> | MiddlewareHandler<E, P, I>92> = Handler<E, P, I, R> | MiddlewareHandler<E, P, I, R>9394export type NotFoundHandler<E extends Env = any> = (c: Context<E>) => Response | Promise<Response>9596export interface HTTPResponseError extends Error {
32 unmodified lines
129 I extends Input = BlankInput,130 I2 extends Input = I,131 R extends HandlerResponse<any> = any,132 E2 extends Env = E,132 E3 extends Env = IntersectNonAnyTypes<[E, E2]>133 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,134 M1 extends H<E2, P, any> = H<E2, P, any>135 >(134 ...handlers: [H<E2, P, I>, H<E3, P, I2, R>]136 ...handlers: [H<E2, P, I> & M1, H<E3, P, I2, R>]137 ): HonoBase<138 IntersectNonAnyTypes<[E, E2, E3]>,137 S & ToSchema<M, P, I2, MergeTypedResponse<R>>,139 S & ToSchema<M, P, I2, MergeTypedResponse<R> | MergeMiddlewareResponse<M1>>,140 BasePath141 >142143 // app.get(path, handler)
16 unmodified lines
160 I2 extends Input = I,161 I3 extends Input = I & I2,162 E2 extends Env = E,163 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,162 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>164 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,165 // Middleware166 M1 extends H<E2, P, any> = H<E2, P, any>,167 M2 extends H<E3, P, any> = H<E3, P, any>168 >(164 ...handlers: [H<E2, P, I>, H<E3, P, I2>, H<E4, P, I3, R>]169 ...handlers: [H<E2, P, I> & M1, H<E3, P, I2> & M2, H<E4, P, I3, R>]170 ): HonoBase<171 IntersectNonAnyTypes<[E, E2, E3, E4]>,167 S & ToSchema<M, P, I3, MergeTypedResponse<R>>,172 S &173 ToSchema<174 M,175 P,176 I3,177 MergeTypedResponse<R> | MergeMiddlewareResponse<M1> | MergeMiddlewareResponse<M2>178 >,179 BasePath180 >181182 // app.get(path, handler x2)
3 unmodified lines
186 R extends HandlerResponse<any> = any,187 I extends Input = BlankInput,188 I2 extends Input = I,189 E2 extends Env = E,179 E3 extends Env = IntersectNonAnyTypes<[E, E2]>190 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,191 // Middleware192 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>193 >(194 path: P,182 ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2, R>]183 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I2, MergeTypedResponse<R>>, BasePath>195 ...handlers: [H<E2, MergedPath, I> & M1, H<E3, MergedPath, I2, R>]196 ): HonoBase<197 E,198 S &199 ToSchema<M, MergePath<BasePath, P>, I2, MergeTypedResponse<R> | MergeMiddlewareResponse<M1>>,200 BasePath201 >202203 // app.get(handler x 4)204 <205 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,
4 unmodified lines
210 I4 extends Input = I & I2 & I3,211 E2 extends Env = E,212 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,213 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,196 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>214 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,215 // Middleware216 M1 extends H<E2, P, any> = H<E2, P, any>,217 M2 extends H<E3, P, any> = H<E3, P, any>,218 M3 extends H<E4, P, any> = H<E4, P, any>219 >(198 ...handlers: [H<E2, P, I>, H<E3, P, I2>, H<E4, P, I3>, H<E5, P, I4, R>]220 ...handlers: [H<E2, P, I> & M1, H<E3, P, I2> & M2, H<E4, P, I3> & M3, H<E5, P, I4, R>]221 ): HonoBase<222 IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,201 S & ToSchema<M, P, I4, MergeTypedResponse<R>>,223 S &224 ToSchema<225 M,226 P,227 I4,228 | MergeTypedResponse<R>229 | MergeMiddlewareResponse<M1>230 | MergeMiddlewareResponse<M2>231 | MergeMiddlewareResponse<M3>232 >,233 BasePath234 >235236 // app.get(path, handler x3)
5 unmodified lines
242 I2 extends Input = I,243 I3 extends Input = I & I2,244 E2 extends Env = E,245 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,215 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>246 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,247 // Middleware248 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>,249 M2 extends H<E3, MergedPath, any> = H<E3, MergedPath, any>250 >(251 path: P,218 ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2>, H<E4, MergedPath, I3, R>]219 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I3, MergeTypedResponse<R>>, BasePath>252 ...handlers: [H<E2, MergedPath, I> & M1, H<E3, MergedPath, I2> & M2, H<E4, MergedPath, I3, R>]253 ): HonoBase<254 E,255 S &256 ToSchema<257 M,258 MergePath<BasePath, P>,259 I3,260 MergeTypedResponse<R> | MergeMiddlewareResponse<M1> | MergeMiddlewareResponse<M2>261 >,262 BasePath263 >264265 // app.get(handler x 5)266 <267 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,
6 unmodified lines
274 E2 extends Env = E,275 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,276 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,277 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,234 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>278 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,279 // Middleware280 M1 extends H<E2, P, any> = H<E2, P, any>,281 M2 extends H<E3, P, any> = H<E3, P, any>,282 M3 extends H<E4, P, any> = H<E4, P, any>,283 M4 extends H<E5, P, any> = H<E5, P, any>284 >(236 ...handlers: [H<E2, P, I>, H<E3, P, I2>, H<E4, P, I3>, H<E5, P, I4>, H<E6, P, I5, R>]285 ...handlers: [286 H<E2, P, I> & M1,287 H<E3, P, I2> & M2,288 H<E4, P, I3> & M3,289 H<E5, P, I4> & M4,290 H<E6, P, I5, R>291 ]292 ): HonoBase<293 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,239 S & ToSchema<M, P, I5, MergeTypedResponse<R>>,294 S &295 ToSchema<296 M,297 P,298 I5,299 | MergeTypedResponse<R>300 | MergeMiddlewareResponse<M1>301 | MergeMiddlewareResponse<M2>302 | MergeMiddlewareResponse<M3>303 | MergeMiddlewareResponse<M4>304 >,305 BasePath306 >307308 // app.get(path, handler x4)
7 unmodified lines
316 I4 extends Input = I & I2 & I3,317 E2 extends Env = E,318 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,319 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,255 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>320 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,321 // Middleware322 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>,323 M2 extends H<E3, MergedPath, any> = H<E3, MergedPath, any>,324 M3 extends H<E4, MergedPath, any> = H<E4, MergedPath, any>325 >(326 path: P,327 ...handlers: [259 H<E2, MergedPath, I>,260 H<E3, MergedPath, I2>,261 H<E4, MergedPath, I3>,328 H<E2, MergedPath, I> & M1,329 H<E3, MergedPath, I2> & M2,330 H<E4, MergedPath, I3> & M3,331 H<E5, MergedPath, I4, R>332 ]264 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I4, MergeTypedResponse<R>>, BasePath>333 ): HonoBase<334 E,335 S &336 ToSchema<337 M,338 MergePath<BasePath, P>,339 I4,340 | MergeTypedResponse<R>341 | MergeMiddlewareResponse<M1>342 | MergeMiddlewareResponse<M2>343 | MergeMiddlewareResponse<M3>344 >,345 BasePath346 >347348 // app.get(handler x 6)349 <350 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,
8 unmodified lines
359 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,360 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,361 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,362 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,281 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>363 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,364 // Middleware365 M1 extends H<E2, P, any> = H<E2, P, any>,366 M2 extends H<E3, P, any> = H<E3, P, any>,367 M3 extends H<E4, P, any> = H<E4, P, any>,368 M4 extends H<E5, P, any> = H<E5, P, any>,369 M5 extends H<E6, P, any> = H<E6, P, any>370 >(371 ...handlers: [284 H<E2, P, I>,285 H<E3, P, I2>,286 H<E4, P, I3>,287 H<E5, P, I4>,288 H<E6, P, I5>,372 H<E2, P, I> & M1,373 H<E3, P, I2> & M2,374 H<E4, P, I3> & M3,375 H<E5, P, I4> & M4,376 H<E6, P, I5> & M5,377 H<E7, P, I6, R>378 ]379 ): HonoBase<380 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,293 S & ToSchema<M, P, I6, MergeTypedResponse<R>>,381 S &382 ToSchema<383 M,384 P,385 I6,386 | MergeTypedResponse<R>387 | MergeMiddlewareResponse<M1>388 | MergeMiddlewareResponse<M2>389 | MergeMiddlewareResponse<M3>390 | MergeMiddlewareResponse<M4>391 | MergeMiddlewareResponse<M5>392 >,393 BasePath394 >395396 // app.get(path, handler x5)
9 unmodified lines
406 E2 extends Env = E,407 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,408 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,409 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,311 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>410 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,411 // Middleware412 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>,413 M2 extends H<E3, MergedPath, any> = H<E3, MergedPath, any>,414 M3 extends H<E4, MergedPath, any> = H<E4, MergedPath, any>,415 M4 extends H<E5, MergedPath, any> = H<E5, MergedPath, any>416 >(417 path: P,418 ...handlers: [315 H<E2, MergedPath, I>,316 H<E3, MergedPath, I2>,317 H<E4, MergedPath, I3>,318 H<E5, MergedPath, I4>,419 H<E2, MergedPath, I> & M1,420 H<E3, MergedPath, I2> & M2,421 H<E4, MergedPath, I3> & M3,422 H<E5, MergedPath, I4> & M4,423 H<E6, MergedPath, I5, R>424 ]321 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I5, MergeTypedResponse<R>>, BasePath>425 ): HonoBase<426 E,427 S &428 ToSchema<429 M,430 MergePath<BasePath, P>,431 I5,432 | MergeTypedResponse<R>433 | MergeMiddlewareResponse<M1>434 | MergeMiddlewareResponse<M2>435 | MergeMiddlewareResponse<M3>436 | MergeMiddlewareResponse<M4>437 >,438 BasePath439 >440441 // app.get(handler x 7)442 <443 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,
10 unmodified lines
454 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,455 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,456 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,457 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,340 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>458 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,459 // Middleware460 M1 extends H<E2, P, any> = H<E2, P, any>,461 M2 extends H<E3, P, any> = H<E3, P, any>,462 M3 extends H<E4, P, any> = H<E4, P, any>,463 M4 extends H<E5, P, any> = H<E5, P, any>,464 M5 extends H<E6, P, any> = H<E6, P, any>,465 M6 extends H<E7, P, any> = H<E7, P, any>466 >(467 ...handlers: [343 H<E2, P, I>,344 H<E3, P, I2>,345 H<E4, P, I3>,346 H<E5, P, I4>,347 H<E6, P, I5>,348 H<E7, P, I6>,468 H<E2, P, I> & M1,469 H<E3, P, I2> & M2,470 H<E4, P, I3> & M3,471 H<E5, P, I4> & M4,472 H<E6, P, I5> & M5,473 H<E7, P, I6> & M6,474 H<E8, P, I7, R>475 ]476 ): HonoBase<477 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,353 S & ToSchema<M, P, I7, MergeTypedResponse<R>>,478 S &479 ToSchema<480 M,481 P,482 I7,483 | MergeTypedResponse<R>484 | MergeMiddlewareResponse<M1>485 | MergeMiddlewareResponse<M2>486 | MergeMiddlewareResponse<M3>487 | MergeMiddlewareResponse<M4>488 | MergeMiddlewareResponse<M5>489 | MergeMiddlewareResponse<M6>490 >,491 BasePath492 >493494 // app.get(path, handler x6)
11 unmodified lines
506 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,507 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,508 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,509 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,373 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>510 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,511 // Middleware512 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>,513 M2 extends H<E3, MergedPath, any> = H<E3, MergedPath, any>,514 M3 extends H<E4, MergedPath, any> = H<E4, MergedPath, any>,515 M4 extends H<E5, MergedPath, any> = H<E5, MergedPath, any>,516 M5 extends H<E6, MergedPath, any> = H<E6, MergedPath, any>517 >(518 path: P,519 ...handlers: [377 H<E2, MergedPath, I>,378 H<E3, MergedPath, I2>,379 H<E4, MergedPath, I3>,380 H<E5, MergedPath, I4>,381 H<E6, MergedPath, I5>,520 H<E2, MergedPath, I> & M1,521 H<E3, MergedPath, I2> & M2,522 H<E4, MergedPath, I3> & M3,523 H<E5, MergedPath, I4> & M4,524 H<E6, MergedPath, I5> & M5,525 H<E7, MergedPath, I6, R>526 ]384 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I6, MergeTypedResponse<R>>, BasePath>527 ): HonoBase<528 E,529 S &530 ToSchema<531 M,532 MergePath<BasePath, P>,533 I6,534 | MergeTypedResponse<R>535 | MergeMiddlewareResponse<M1>536 | MergeMiddlewareResponse<M2>537 | MergeMiddlewareResponse<M3>538 | MergeMiddlewareResponse<M4>539 | MergeMiddlewareResponse<M5>540 >,541 BasePath542 >543544 // app.get(handler x 8)545 <546 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,
12 unmodified lines
559 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,560 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,561 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,562 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,405 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>563 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,564 // Middleware565 M1 extends H<E2, P, any> = H<E2, P, any>,566 M2 extends H<E3, P, any> = H<E3, P, any>,567 M3 extends H<E4, P, any> = H<E4, P, any>,568 M4 extends H<E5, P, any> = H<E5, P, any>,569 M5 extends H<E6, P, any> = H<E6, P, any>,570 M6 extends H<E7, P, any> = H<E7, P, any>,571 M7 extends H<E8, P, any> = H<E8, P, any>572 >(573 ...handlers: [408 H<E2, P, I>,409 H<E3, P, I2>,410 H<E4, P, I3>,411 H<E5, P, I4>,412 H<E6, P, I5>,413 H<E7, P, I6>,414 H<E8, P, I7>,574 H<E2, P, I> & M1,575 H<E3, P, I2> & M2,576 H<E4, P, I3> & M3,577 H<E5, P, I4> & M4,578 H<E6, P, I5> & M5,579 H<E7, P, I6> & M6,580 H<E8, P, I7> & M7,581 H<E9, P, I8, R>582 ]583 ): HonoBase<584 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,419 S & ToSchema<M, P, I8, MergeTypedResponse<R>>,585 S &586 ToSchema<587 M,588 P,589 I8,590 | MergeTypedResponse<R>591 | MergeMiddlewareResponse<M1>592 | MergeMiddlewareResponse<M2>593 | MergeMiddlewareResponse<M3>594 | MergeMiddlewareResponse<M4>595 | MergeMiddlewareResponse<M5>596 | MergeMiddlewareResponse<M6>597 | MergeMiddlewareResponse<M7>598 >,599 BasePath600 >601602 // app.get(path, handler x7)
13 unmodified lines
616 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,617 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,618 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,619 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,441 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>620 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,621 // Middleware622 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>,623 M2 extends H<E3, MergedPath, any> = H<E3, MergedPath, any>,624 M3 extends H<E4, MergedPath, any> = H<E4, MergedPath, any>,625 M4 extends H<E5, MergedPath, any> = H<E5, MergedPath, any>,626 M5 extends H<E6, MergedPath, any> = H<E6, MergedPath, any>,627 M6 extends H<E7, MergedPath, any> = H<E7, MergedPath, any>628 >(629 path: P,630 ...handlers: [445 H<E2, MergedPath, I>,446 H<E3, MergedPath, I2>,447 H<E4, MergedPath, I3>,448 H<E5, MergedPath, I4>,449 H<E6, MergedPath, I5>,450 H<E7, MergedPath, I6>,631 H<E2, MergedPath, I> & M1,632 H<E3, MergedPath, I2> & M2,633 H<E4, MergedPath, I3> & M3,634 H<E5, MergedPath, I4> & M4,635 H<E6, MergedPath, I5> & M5,636 H<E7, MergedPath, I6> & M6,637 H<E8, MergedPath, I7, R>638 ]453 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I7, MergeTypedResponse<R>>, BasePath>639 ): HonoBase<640 E,641 S &642 ToSchema<643 M,644 MergePath<BasePath, P>,645 I7,646 | MergeTypedResponse<R>647 | MergeMiddlewareResponse<M1>648 | MergeMiddlewareResponse<M2>649 | MergeMiddlewareResponse<M3>650 | MergeMiddlewareResponse<M4>651 | MergeMiddlewareResponse<M5>652 | MergeMiddlewareResponse<M6>653 >,654 BasePath655 >656657 // app.get(handler x 9)658 <659 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,
14 unmodified lines
674 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,675 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,676 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,677 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,476 E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>678 E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,679 // Middleware680 M1 extends H<E2, P, any> = H<E2, P, any>,681 M2 extends H<E3, P, any> = H<E3, P, any>,682 M3 extends H<E4, P, any> = H<E4, P, any>,683 M4 extends H<E5, P, any> = H<E5, P, any>,684 M5 extends H<E6, P, any> = H<E6, P, any>,685 M6 extends H<E7, P, any> = H<E7, P, any>,686 M7 extends H<E8, P, any> = H<E8, P, any>,687 M8 extends H<E9, P, any> = H<E9, P, any>688 >(689 ...handlers: [479 H<E2, P, I>,480 H<E3, P, I2>,481 H<E4, P, I3>,482 H<E5, P, I4>,483 H<E6, P, I5>,484 H<E7, P, I6>,485 H<E8, P, I7>,486 H<E9, P, I8>,690 H<E2, P, I> & M1,691 H<E3, P, I2> & M2,692 H<E4, P, I3> & M3,693 H<E5, P, I4> & M4,694 H<E6, P, I5> & M5,695 H<E7, P, I6> & M6,696 H<E8, P, I7> & M7,697 H<E9, P, I8> & M8,698 H<E10, P, I9, R>699 ]700 ): HonoBase<701 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,491 S & ToSchema<M, P, I9, MergeTypedResponse<R>>,702 S &703 ToSchema<704 M,705 P,706 I9,707 | MergeTypedResponse<R>708 | MergeMiddlewareResponse<M1>709 | MergeMiddlewareResponse<M2>710 | MergeMiddlewareResponse<M3>711 | MergeMiddlewareResponse<M4>712 | MergeMiddlewareResponse<M5>713 | MergeMiddlewareResponse<M6>714 | MergeMiddlewareResponse<M7>715 | MergeMiddlewareResponse<M8>716 >,717 BasePath718 >719720 // app.get(path, handler x8)
15 unmodified lines
736 E5 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4]>,737 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,738 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,739 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,515 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>740 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,741 // Middleware742 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>,743 M2 extends H<E3, MergedPath, any> = H<E3, MergedPath, any>,744 M3 extends H<E4, MergedPath, any> = H<E4, MergedPath, any>,745 M4 extends H<E5, MergedPath, any> = H<E5, MergedPath, any>,746 M5 extends H<E6, MergedPath, any> = H<E6, MergedPath, any>,747 M6 extends H<E7, MergedPath, any> = H<E7, MergedPath, any>,748 M7 extends H<E8, MergedPath, any> = H<E8, MergedPath, any>749 >(750 path: P,751 ...handlers: [519 H<E2, MergedPath, I>,520 H<E3, MergedPath, I2>,521 H<E4, MergedPath, I3>,522 H<E5, MergedPath, I4>,523 H<E6, MergedPath, I5>,524 H<E7, MergedPath, I6>,525 H<E8, MergedPath, I7>,752 H<E2, MergedPath, I> & M1,753 H<E3, MergedPath, I2> & M2,754 H<E4, MergedPath, I3> & M3,755 H<E5, MergedPath, I4> & M4,756 H<E6, MergedPath, I5> & M5,757 H<E7, MergedPath, I6> & M6,758 H<E8, MergedPath, I7> & M7,759 H<E9, MergedPath, I8, R>760 ]528 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I8, MergeTypedResponse<R>>, BasePath>761 ): HonoBase<762 E,763 S &764 ToSchema<765 M,766 MergePath<BasePath, P>,767 I8,768 | MergeTypedResponse<R>769 | MergeMiddlewareResponse<M1>770 | MergeMiddlewareResponse<M2>771 | MergeMiddlewareResponse<M3>772 | MergeMiddlewareResponse<M4>773 | MergeMiddlewareResponse<M5>774 | MergeMiddlewareResponse<M6>775 | MergeMiddlewareResponse<M7>776 >,777 BasePath778 >779780 // app.get(handler x 10)781 <782 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,
16 unmodified lines
799 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,800 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,801 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,802 E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,553 E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>803 E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,804 // Middleware805 M1 extends H<E2, P, any> = H<E2, P, any>,806 M2 extends H<E3, P, any> = H<E3, P, any>,807 M3 extends H<E4, P, any> = H<E4, P, any>,808 M4 extends H<E5, P, any> = H<E5, P, any>,809 M5 extends H<E6, P, any> = H<E6, P, any>,810 M6 extends H<E7, P, any> = H<E7, P, any>,811 M7 extends H<E8, P, any> = H<E8, P, any>,812 M8 extends H<E9, P, any> = H<E9, P, any>,813 M9 extends H<E10, P, any> = H<E10, P, any>814 >(815 ...handlers: [556 H<E2, P, I>,557 H<E3, P, I2>,558 H<E4, P, I3>,559 H<E5, P, I4>,560 H<E6, P, I5>,561 H<E7, P, I6>,562 H<E8, P, I7>,563 H<E9, P, I8>,564 H<E10, P, I9>,816 H<E2, P, I> & M1,817 H<E3, P, I2> & M2,818 H<E4, P, I3> & M3,819 H<E5, P, I4> & M4,820 H<E6, P, I5> & M5,821 H<E7, P, I6> & M6,822 H<E8, P, I7> & M7,823 H<E9, P, I8> & M8,824 H<E10, P, I9> & M9,825 H<E11, P, I10, R>826 ]827 ): HonoBase<828 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>,569 S & ToSchema<M, P, I10, MergeTypedResponse<R>>,829 S &830 ToSchema<831 M,832 P,833 I10,834 | MergeTypedResponse<R>835 | MergeMiddlewareResponse<M1>836 | MergeMiddlewareResponse<M2>837 | MergeMiddlewareResponse<M3>838 | MergeMiddlewareResponse<M4>839 | MergeMiddlewareResponse<M5>840 | MergeMiddlewareResponse<M6>841 | MergeMiddlewareResponse<M7>842 | MergeMiddlewareResponse<M8>843 | MergeMiddlewareResponse<M9>844 >,845 BasePath846 >847848 // app.get(path, handler x9)
17 unmodified lines
866 E6 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,867 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,868 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,869 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,595 E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>870 E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,871 // Middleware872 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>,873 M2 extends H<E3, MergedPath, any> = H<E3, MergedPath, any>,874 M3 extends H<E4, MergedPath, any> = H<E4, MergedPath, any>,875 M4 extends H<E5, MergedPath, any> = H<E5, MergedPath, any>,876 M5 extends H<E6, MergedPath, any> = H<E6, MergedPath, any>,877 M6 extends H<E7, MergedPath, any> = H<E7, MergedPath, any>,878 M7 extends H<E8, MergedPath, any> = H<E8, MergedPath, any>,879 M8 extends H<E9, MergedPath, any> = H<E9, MergedPath, any>880 >(881 path: P,882 ...handlers: [599 H<E2, MergedPath, I>,600 H<E3, MergedPath, I2>,601 H<E4, MergedPath, I3>,602 H<E5, MergedPath, I4>,603 H<E6, MergedPath, I5>,604 H<E7, MergedPath, I6>,605 H<E8, MergedPath, I7>,606 H<E9, MergedPath, I8>,883 H<E2, MergedPath, I> & M1,884 H<E3, MergedPath, I2> & M2,885 H<E4, MergedPath, I3> & M3,886 H<E5, MergedPath, I4> & M4,887 H<E6, MergedPath, I5> & M5,888 H<E7, MergedPath, I6> & M6,889 H<E8, MergedPath, I7> & M7,890 H<E9, MergedPath, I8> & M8,891 H<E10, MergedPath, I9, R>892 ]609 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I9, MergeTypedResponse<R>>, BasePath>893 ): HonoBase<894 E,895 S &896 ToSchema<897 M,898 MergePath<BasePath, P>,899 I9,900 | MergeTypedResponse<R>901 | MergeMiddlewareResponse<M1>902 | MergeMiddlewareResponse<M2>903 | MergeMiddlewareResponse<M3>904 | MergeMiddlewareResponse<M4>905 | MergeMiddlewareResponse<M5>906 | MergeMiddlewareResponse<M6>907 | MergeMiddlewareResponse<M7>908 | MergeMiddlewareResponse<M8>909 >,910 BasePath911 >912913 // app.get(path, handler x10)914 <915 P extends string,
17 unmodified lines
933 E7 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,934 E8 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,935 E9 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,936 E10 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,635 E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>937 E11 extends Env = IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,938 // Middleware939 M1 extends H<E2, MergedPath, any> = H<E2, MergedPath, any>,940 M2 extends H<E3, MergedPath, any> = H<E3, MergedPath, any>,941 M3 extends H<E4, MergedPath, any> = H<E4, MergedPath, any>,942 M4 extends H<E5, MergedPath, any> = H<E5, MergedPath, any>,943 M5 extends H<E6, MergedPath, any> = H<E6, MergedPath, any>,944 M6 extends H<E7, MergedPath, any> = H<E7, MergedPath, any>,945 M7 extends H<E8, MergedPath, any> = H<E8, MergedPath, any>,946 M8 extends H<E9, MergedPath, any> = H<E9, MergedPath, any>,947 M9 extends H<E10, MergedPath, any> = H<E10, MergedPath, any>948 >(949 path: P,950 ...handlers: [639 H<E2, MergedPath, I>,640 H<E3, MergedPath, I2>,641 H<E4, MergedPath, I3>,642 H<E5, MergedPath, I4>,643 H<E6, MergedPath, I5>,644 H<E7, MergedPath, I6>,645 H<E8, MergedPath, I7>,646 H<E9, MergedPath, I8>,647 H<E10, MergedPath, I9>,951 H<E2, MergedPath, I> & M1,952 H<E3, MergedPath, I2> & M2,953 H<E4, MergedPath, I3> & M3,954 H<E5, MergedPath, I4> & M4,955 H<E6, MergedPath, I5> & M5,956 H<E7, MergedPath, I6> & M6,957 H<E8, MergedPath, I7> & M7,958 H<E9, MergedPath, I8> & M8,959 H<E10, MergedPath, I9> & M9,960 H<E11, MergedPath, I10, R>961 ]650 ): HonoBase<E, S & ToSchema<M, MergePath<BasePath, P>, I10, MergeTypedResponse<R>>, BasePath>962 ): HonoBase<963 E,964 S &965 ToSchema<966 M,967 MergePath<BasePath, P>,968 I10,969 | MergeTypedResponse<R>970 | MergeMiddlewareResponse<M1>971 | MergeMiddlewareResponse<M2>972 | MergeMiddlewareResponse<M3>973 | MergeMiddlewareResponse<M4>974 | MergeMiddlewareResponse<M5>975 | MergeMiddlewareResponse<M6>976 | MergeMiddlewareResponse<M7>977 | MergeMiddlewareResponse<M8>978 | MergeMiddlewareResponse<M9>979 >,980 BasePath981 >982983 // app.get(...handlers[])984 <985 P extends string = ExtractStringKey<S> extends never ? BasePath : ExtractStringKey<S>,
47 unmodified lines
10331034 // app.get(path, handler)1035 <P extends string, MergedPath extends MergePath<BasePath, P>, E2 extends Env = E>(1036 path: P,706 handler: MiddlewareHandler<E2, MergedPath>1037 handler: MiddlewareHandler<E2, MergedPath, any, any>1038 ): HonoBase<IntersectNonAnyTypes<[E, E2]>, ChangePathOfSchema<S, MergedPath>, BasePath>10391040 // app.use(handler x3)1041 <
1 unmodified line
1043 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,1044 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,1045 P extends string = MergePath<BasePath, ExtractStringKey<S>>1046 >(716 ...handlers: [MiddlewareHandler<E2, P>, MiddlewareHandler<E3, P>, MiddlewareHandler<E4, P>]1047 ...handlers: [1048 MiddlewareHandler<E2, P, any, any>,1049 MiddlewareHandler<E3, P, any, any>,1050 MiddlewareHandler<E4, P, any, any>1051 ]1052 ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath>10531054 // app.get(path, handler x2)1055 <
1193 unmodified lines
2249 : T extends TypedResponse2250 ? T2251 : TypedResponse22522253type MergeTypedResponseStrict<T> = T extends Promise<infer T2>2254 ? T2 extends TypedResponse2255 ? T22256 : never2257 : T extends TypedResponse2258 ? T2259 : never22602261type MergeMiddlewareResponse<T> = MergeTypedResponseStrict<ExtractHandlerResponse<T>>22622263////////////////////////////////////////2264////// /////2265////// ValidationTargets /////2266////// /////
59 unmodified lines
2326export type ExtractSchema<T> = UnionToIntersection<2327 T extends HonoBase<infer _, infer S, any> ? S : never2328>23292330export type ExtractSchemaForStatusCode<T, Status extends number> = {2331 [Path in keyof ExtractSchema<T>]: {2332 [Method in keyof ExtractSchema<T>[Path]]: Extract<2333 ExtractSchema<T>[Path][Method],2334 { status: Status }2335 >2336 }2337}23382339export type ExtractHandlerResponse<T> = T extends (c: any, next: any) => Promise<infer R>2340 ? Exclude<R, void> extends never2341 ? never // Only void in the type → filter out2342 : Exclude<R, void> extends Response | TypedResponse<any, any, any>2343 ? Exclude<R, void> // Return the response type without void2344 : never // Invalid response type → filter out2345 : T extends (c: any, next: any) => infer R2346 ? R extends Response | TypedResponse<any, any, any>2347 ? R2348 : never2349 : never23502351// Special type to indicate "not specified"2352type NotSpecified = { readonly __notSpecified: unique symbol }23532354type ProcessHead<T> = IfAnyThenEmptyObject<T extends Env ? (Env extends T ? {} : T) : T>2355export type IntersectNonAnyTypes<T extends any[]> = T extends [infer Head, ...infer Rest]2356 ? ProcessHead<Head> & IntersectNonAnyTypes<Rest>2357 : {}
13 unmodified lines