Merge pull request #4574 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 6efc564, 3e12de6 · Browse files · 21 files·+1256 added−343 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
21 files+1256 added−343 removed
- tests:+626 added−18 removed
- other:+630 added−325 removed
Provenance
- Commit
0d739b6- Tree
de8386c- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent 1
6efc564- Parent 2
3e12de6
21 files changed+1256 added−343 removed
modified:src/client/client.test.ts+78 added
1521 unmodified lines1522 client.index.$ws({ query })1523 expect(webSocketMock).toHaveBeenCalledWith(expectedUrl, undefined)1524 })1525 })1526+1527+describe('Custom buildSearchParams', () => {1528+ const app = new Hono()1529+ const route = app.get(1530+ '/search',1531+ validator('query', () => {1532+ return {} as { q: string; tags: string[] }1533+ }),1534+ (c) => {1535+ return c.json({1536+ message: 'success',1537+ queryString: '',1538+ })1539+ }1540+ )1541+1542+ type AppType = typeof route1543+1544+ const server = setupServer(1545+ http.get('http://localhost/search', ({ request }) => {1546+ const url = new URL(request.url)1547+ return HttpResponse.json({1548+ message: 'success',1549+ queryString: url.search,1550+ })1551+ })1552+ )1553+1554+ beforeAll(() => server.listen())1555+ afterEach(() => server.resetHandlers())1556+ afterAll(() => server.close())1557+1558+ // Custom buildSearchParams that uses bracket notation for arrays (key[]=value)1559+ const customBuildSearchParams = (query: Record<string, string | string[]>) => {1560+ const searchParams = new URLSearchParams()1561+ for (const [k, v] of Object.entries(query)) {1562+ if (v === undefined) continue1563+ if (Array.isArray(v)) {1564+ v.forEach((item) => searchParams.append(`${k}[]`, item))1565+ } else {1566+ searchParams.set(k, v)1567+ }1568+ }1569+ return searchParams1570+ }1571+1572+ it('Should use custom buildSearchParams for query serialization', async () => {1573+ const client = hc<AppType>('http://localhost', { buildSearchParams: customBuildSearchParams })1574+ const res = await client.search.$get({ query: { q: 'test', tags: ['tag1', 'tag2', 'tag3'] } })1575+ const data = await res.json()1576+1577+ expect(res.status).toBe(200)1578+ expect(data.queryString).toBe('?q=test&tags%5B%5D=tag1&tags%5B%5D=tag2&tags%5B%5D=tag3')1579+ })1580+1581+ it('Should use default buildSearchParams when custom one is not provided', async () => {1582+ const client = hc<AppType>('http://localhost')1583+ const res = await client.search.$get({ query: { q: 'test', tags: ['tag1', 'tag2'] } })1584+ const data = await res.json()1585+1586+ expect(res.status).toBe(200)1587+ expect(data.queryString).toBe('?q=test&tags=tag1&tags=tag2')1588+ })1589+1590+ it('Should use custom buildSearchParams in $url() method', () => {1591+ const client = hc<AppType>('http://localhost', { buildSearchParams: customBuildSearchParams })1592+ const url = client.search.$url({ query: { q: 'test', tags: ['tag1', 'tag2'] } })1593+1594+ expect(url.href).toBe('http://localhost/search?q=test&tags%5B%5D=tag1&tags%5B%5D=tag2')1595+ })1596+1597+ it('Should use default buildSearchParams in $url() when custom one is not provided', () => {1598+ const client = hc<AppType>('http://localhost')1599+ const url = client.search.$url({ query: { q: 'test', tags: ['tag1', 'tag2'] } })1600+1601+ expect(url.href).toBe('http://localhost/search?q=test&tags=tag1&tags=tag2')1602+ })1603+})modified:src/client/client.ts+19 added-8 removed
1 import type { Hono } from '../hono'2 import type { FormValue, ValidationTargets } from '../types'3 import { serialize } from '../utils/cookie'4 import type { UnionToIntersection } from '../utils/types'5-import type { Callback, Client, ClientRequestOptions } from './types'5+import type { BuildSearchParamsFn, Callback, Client, ClientRequestOptions } from './types'6 import {7 buildSearchParams,8 deepMerge,9 mergePath,22 unmodified lines32 33 class ClientRequestImpl {34 private url: string35 private method: string36+ private buildSearchParams: BuildSearchParamsFn37 private queryParams: URLSearchParams | undefined = undefined38 private pathParams: Record<string, string> = {}39 private rBody: BodyInit | undefined40 private cType: string | undefined = undefined41 41- constructor(url: string, method: string) {42+ constructor(43+ url: string,44+ method: string,45+ options: {46+ buildSearchParams: BuildSearchParamsFn47+ }48+ ) {49 this.url = url50 this.method = method51+ this.buildSearchParams = options.buildSearchParams52 }53 fetch = async (54 args?: ValidationTargets<FormValue> & {55 param?: Record<string, string>1 unmodified line57 opt?: ClientRequestOptions58 ) => {59 if (args) {60 if (args.query) {53- this.queryParams = buildSearchParams(args.query)61+ this.queryParams = this.buildSearchParams(args.query)62 }63 64 if (args.form) {65 const form = new FormData()60 unmodified lines126 }127 }128 129 // eslint-disable-next-line @typescript-eslint/no-explicit-any122-export const hc = <T extends Hono<any, any, any>>(123- baseUrl: string,130+export const hc = <T extends Hono<any, any, any>, Prefix extends string = string>(131+ baseUrl: Prefix,132 options?: ClientRequestOptions133 ) =>134 createProxy(function proxyCallback(opts) {135+ const buildSearchParamsOption = options?.buildSearchParams ?? buildSearchParams136 const parts = [...opts.path]137 const lastParts = parts.slice(-3).reverse()138 139 // allow calling .toString() and .valueOf() on the proxy31 unmodified lines171 if (opts.args[0].param) {172 result = replaceUrlParam(url, opts.args[0].param)173 }174 if (opts.args[0].query) {166- result = result + '?' + buildSearchParams(opts.args[0].query).toString()175+ result = result + '?' + buildSearchParamsOption(opts.args[0].query).toString()176 }177 }178 result = removeIndexString(result)179 return new URL(result)24 unmodified lines204 205 return establishWebSocket(targetUrl.toString())206 }207 199- const req = new ClientRequestImpl(url, method)208+ const req = new ClientRequestImpl(url, method, {209+ buildSearchParams: buildSearchParamsOption,210+ })211 if (method) {212 options ??= {}213 const args = deepMerge<ClientRequestOptions>(options, { ...opts.args[1] })214 return req.fetch(opts.args[0], args)215 }216 return req206- }, []) as UnionToIntersection<Client<T>>217+ }, []) as UnionToIntersection<Client<T, Prefix>>modified:src/client/types.test.ts+20 added-1 removed
12345678920 unmodified lines30313233333435363738394041424344454647484950515253545556575859606162636415 unmodified lines/* eslint-disable @typescript-eslint/no-unused-vars */import { expectTypeOf } from 'vitest'import { Hono } from '..'import { upgradeWebSocket } from '../adapter/deno/websocket'import type { TypedURL } from './types'import { hc } from '.'
describe('WebSockets', () => { const app = new Hono()20 unmodified lines const app = new Hono() .get('foo', (c) => c.json({})) .get('foo/bar', (c) => c.json({})) .get('foo/:id/baz', (c) => c.json({})) const client = hc<typeof app>('') const client = hc<typeof app, 'http://localhost'>('http://localhost') it('`foo` should have `$get`', () => { expectTypeOf(client.foo).toHaveProperty('$get') expectTypeOf(client.foo.$url()).toEqualTypeOf<TypedURL<'http:', 'localhost', '', '/foo', ''>>() }) it('`foo.bar` should not have `$get`', () => { expectTypeOf(client.foo.bar).toHaveProperty('$get') expectTypeOf(client.foo.bar.$url()).toEqualTypeOf< TypedURL<'http:', 'localhost', '', '/foo/bar', ''> >() }) it('`foo[":id"].baz` should have `$get`', () => { expectTypeOf(client.foo[':id'].baz).toHaveProperty('$get') expectTypeOf(client.foo[':id'].baz.$url()).toEqualTypeOf< TypedURL<'http:', 'localhost', '', '/foo/:id/baz', ''> >() expectTypeOf( client.foo[':id'].baz.$url({ param: { id: '123' }, }) ).toEqualTypeOf<TypedURL<'http:', 'localhost', '', '/foo/123/baz', ''>>() expectTypeOf( client.foo[':id'].baz.$url({ param: { id: '123' }, query: { q: 'hono' }, }) ).toEqualTypeOf<TypedURL<'http:', 'localhost', '', '/foo/123/baz', `?${string}`>>() })})
describe('with the leading slash', () => {15 unmodified linesmodified:src/client/types.ts+146 added-16 removed
4 unmodified lines5 import type { HasRequiredKeys } from '../utils/types'6 7 type HonoRequest = (typeof Hono.prototype)['request']8 9+export type BuildSearchParamsFn = (query: Record<string, string | string[]>) => URLSearchParams10+11 export type ClientRequestOptions<T = unknown> = {12 fetch?: typeof fetch | HonoRequest13 webSocket?: (...args: ConstructorParameters<typeof WebSocket>) => WebSocket14 /**2 unmodified lines17 *18 * If you want to add some headers, use in `headers` instead of `init`19 */20 init?: RequestInit21+ /**22+ * Custom function to serialize query parameters into URLSearchParams.23+ * By default, arrays are serialized as multiple parameters with the same key (e.g., `key=a&key=b`).24+ * You can provide a custom function to change this behavior, for example to use bracket notation (e.g., `key[]=a&key[]=b`).25+ *26+ * @example27+ * ```ts28+ * const client = hc('http://localhost', {29+ * buildSearchParams: (query) => {30+ * return new URLSearchParams(qs.stringify(query))31+ * }32+ * })33+ * ```34+ */35+ buildSearchParams?: BuildSearchParamsFn36 } & (keyof T extends never37 ? {38 headers?:39 | Record<string, string>2 unmodified lines42 : {43 headers: T | (() => T | Promise<T>)44 })45 29-export type ClientRequest<S extends Schema> = {46+export type ClientRequest<Prefix extends string, Path extends string, S extends Schema> = {47 [M in keyof S]: S[M] extends Endpoint & { input: infer R }48 ? R extends object49 ? HasRequiredKeys<R> extends true50 ? (args: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<S[M]>>51 : (args?: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<S[M]>>52 : never53 : never54 } & {55+ $url: <38- $url: (39- arg?: S[keyof S] extends { input: infer R }40- ? R extends { param: infer P }41- ? R extends { query: infer Q }42- ? { param: P; query: Q }43- : { param: P }44- : R extends { query: infer Q }45- ? { query: Q }46- : {}47- : {}48- ) => URL56+ const Arg extends57+ | (S[keyof S] extends { input: infer R }58+ ? R extends { param: infer P }59+ ? R extends { query: infer Q }60+ ? { param: P; query: Q }61+ : { param: P }62+ : R extends { query: infer Q }63+ ? { query: Q }64+ : {}65+ : {})66+ | undefined = undefined,67+ >(68+ arg?: Arg69+ ) => HonoURL<Prefix, Path, Arg>70 } & (S['$get'] extends { outputFormat: 'ws' }71 ? S['$get'] extends { input: infer I }72 ? {73 $ws: (args?: I) => WebSocket34 unmodified lines108 formData(): Promise<FormData>109 arrayBuffer(): Promise<ArrayBuffer>110 }111 112+type HonoURL<Prefix extends string, Path extends string, Arg> =113+ IsLiteral<Prefix> extends true114+ ? TrimEndSlash<Prefix> extends `${infer Protocol}://${infer Rest}`115+ ? Rest extends `${infer Hostname}/${infer P}`116+ ? ParseHostName<Hostname> extends [infer Host extends string, infer Port extends string]117+ ? Arg extends { param: infer Param }118+ ? Arg extends { query: infer Query }119+ ? IsEmptyObject<Query> extends true120+ ? TypedURL<121+ `${Protocol}:`,122+ Host,123+ Port,124+ `${ApplyParam<TrimStartSlash<P>, Param>}`,125+ ''126+ >127+ : TypedURL<128+ `${Protocol}:`,129+ Host,130+ Port,131+ `${ApplyParam<TrimStartSlash<P>, Param>}`,132+ `?${string}`133+ >134+ : TypedURL<`${Protocol}:`, Host, Port, `${ApplyParam<TrimStartSlash<P>, Param>}`, ''>135+ : Arg extends { query: infer Query }136+ ? IsEmptyObject<Query> extends true137+ ? TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<P>}`, ''>138+ : TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<P>}`, `?${string}`>139+ : TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<P>}`, ''>140+ : never141+ : ParseHostName<Rest> extends [infer Host extends string, infer Port extends string]142+ ? Arg extends { param: infer Param }143+ ? Arg extends { query: infer Query }144+ ? IsEmptyObject<Query> extends true145+ ? TypedURL<146+ `${Protocol}:`,147+ Host,148+ Port,149+ `${ApplyParam<TrimStartSlash<Path>, Param>}`,150+ ''151+ >152+ : TypedURL<153+ `${Protocol}:`,154+ Host,155+ Port,156+ `${ApplyParam<TrimStartSlash<Path>, Param>}`,157+ `?${string}`158+ >159+ : TypedURL<160+ `${Protocol}:`,161+ Host,162+ Port,163+ `${ApplyParam<TrimStartSlash<Path>, Param>}`,164+ ''165+ >166+ : Arg extends { query: infer Query }167+ ? IsEmptyObject<Query> extends true168+ ? TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<Path>}`, ''>169+ : TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<Path>}`, `?${string}`>170+ : TypedURL<`${Protocol}:`, Host, Port, `/${TrimStartSlash<Path>}`, ''>171+ : never172+ : URL173+ : URL174+type ParseHostName<T extends string> = T extends `${infer Host}:${infer Port}`175+ ? [Host, Port]176+ : [T, '']177+type TrimStartSlash<T extends string> = T extends `/${infer R}` ? TrimStartSlash<R> : T178+type TrimEndSlash<T extends string> = T extends `${infer R}/` ? TrimEndSlash<R> : T179+type IsLiteral<T extends string> = [T] extends [never] ? false : string extends T ? false : true180+type ApplyParam<181+ Path extends string,182+ P,183+ Result extends string = '',184+> = Path extends `${infer Head}/${infer Rest}`185+ ? Head extends `:${infer Param}`186+ ? P extends Record<Param, infer Value extends string>187+ ? IsLiteral<Value> extends true188+ ? ApplyParam<Rest, P, `${Result}/${Value & string}`>189+ : ApplyParam<Rest, P, `${Result}/${Head}`>190+ : ApplyParam<Rest, P, `${Result}/${Head}`>191+ : ApplyParam<Rest, P, `${Result}/${Head}`>192+ : Path extends `:${infer Param}`193+ ? P extends Record<Param, infer Value extends string>194+ ? IsLiteral<Value> extends true195+ ? `${Result}/${Value & string}`196+ : `${Result}/${Path}`197+ : `${Result}/${Path}`198+ : `${Result}/${Path}`199+type IsEmptyObject<T> = keyof T extends never ? true : false200+201+export interface TypedURL<202+ Protocol extends string,203+ Hostname extends string,204+ Port extends string,205+ Pathname extends string,206+ Search extends string,207+> extends URL {208+ protocol: Protocol209+ hostname: Hostname210+ port: Port211+ host: Port extends '' ? Hostname : `${Hostname}:${Port}`212+ origin: `${Protocol}//${Hostname}${Port extends '' ? '' : `:${Port}`}`213+ pathname: Pathname214+ search: Search215+ href: `${Protocol}//${Hostname}${Port extends '' ? '' : `:${Port}`}${Pathname}${Search}`216+}217+218 export interface Response extends ClientResponse<unknown> {}219 220 export type Fetch<T> = (221 args?: InferRequestType<T>,55 unmodified lines277 : never278 : never279 280 type PathToChain<281+ Prefix extends string,282 Path extends string,283 E extends Schema,284 Original extends string = Path,285 > = Path extends `/${infer P}`158- ? PathToChain<P, E, Path>286+ ? PathToChain<Prefix, P, E, Path>287 : Path extends `${infer P}/${infer R}`160- ? { [K in P]: PathToChain<R, E, Original> }288+ ? { [K in P]: PathToChain<Prefix, R, E, Original> }289 : {290 [K in Path extends '' ? 'index' : Path]: ClientRequest<291+ Prefix,292+ Original,293 E extends Record<string, unknown> ? E[Original] : never294 >295 }296 167-export type Client<T> =297+export type Client<T, Prefix extends string> =298 T extends HonoBase<any, infer S, any>299 ? S extends Record<infer K, Schema>300 ? K extends string171- ? PathToChain<K, S>301+ ? PathToChain<Prefix, K, S>302 : never303 : never304 : never305 11 unmodified linesmodified:src/helper/factory/index.test.ts+13 added-11 removed
108 unmodified lines109 110 it('Should return correct path types - /a', () => {111 const client = hc<typeof routesA>('/')112 expectTypeOf(client).toEqualTypeOf<{113+ a: ClientRequest<114+ string,115+ '/a',113- a: ClientRequest<{114- $get: {115- input: {}116- output: 'A'117- outputFormat: 'text'118- status: ContentfulStatusCode116+ {117+ $get: {118+ input: {}119+ output: 'A'120+ outputFormat: 'text'121+ status: ContentfulStatusCode122+ }123 }120- }>124+ >125 }>()126 })127 })128 253 unmodified lines382 })383 })384 385 describe('createMiddleware', () => {382- it('Should set the correct type', () => {386+ it('Should omit the `*` wildcard from the generated schema', () => {387 const factory = createFactory()388 389 const middleware = factory.createMiddleware(async (_, next) => {390 await next()391 })392 393 const routes = new Hono().use('*', middleware)394 type Actual = ExtractSchema<typeof routes>391- type Expected = {392- '*': {}393- }395+ type Expected = {}396 type verify = Expect<Equal<Expected, Actual>>397 })398 399 it('Should default to MiddlewareHandler<E, P, I, Response>', async () => {35 unmodified linesmodified:src/helper/testing/index.ts+2 added-2 removed
16 unmodified lines1718192021212223242526262716 unmodified lines app: T, Env?: ExtractEnv<T>['Bindings'] | {}, executionCtx?: ExecutionContext, options?: Omit<ClientRequestOptions, 'fetch'>): UnionToIntersection<Client<T>> => {): UnionToIntersection<Client<T, 'http://localhost'>> => { const customFetch = (input: RequestInfo | URL, init?: RequestInit) => { return app.request(input, init, Env, executionCtx) }
return hc<typeof app>('http://localhost', { ...options, fetch: customFetch }) return hc<typeof app, 'http://localhost'>('http://localhost', { ...options, fetch: customFetch })}modified:src/middleware/context-storage/index.test.ts+14 added-1 removed
122345610 unmodified lines171819202122232425262728293031323334353637383940414243import { Hono } from '../../hono'import { contextStorage, getContext } from '.'import { contextStorage, getContext, tryGetContext } from '.'
describe('Context Storage Middleware', () => { type Env = { Variables: {10 unmodified lines }) app.get('/', (c) => { return c.text(getMessage()) }) app.get('/optional', (c) => { const optionalContext = tryGetContext<Env>() return c.text(optionalContext?.var.message ?? 'no context') })
const getMessage = () => { return getContext<Env>().var.message }
it('Should get context', async () => { const res = await app.request('/') expect(await res.text()).toBe('Hono is hot!!') })
it('Should return undefined when context is missing', () => { expect(tryGetContext<Env>()).toBeUndefined() })
it('Should get context when available via tryGetContext', async () => { const res = await app.request('/optional') expect(await res.text()).toBe('Hono is hot!!') })})modified:src/middleware/context-storage/index.ts+5 added-1 removed
44 unmodified lines4546474849505152535054555657585944 unmodified lines await asyncLocalStorage.run(c, next) }}
export const tryGetContext = <E extends Env = Env>(): Context<E> | undefined => { return asyncLocalStorage.getStore() as Context<E> | undefined}
export const getContext = <E extends Env = Env>(): Context<E> => { const context = asyncLocalStorage.getStore() const context = tryGetContext<E>() if (!context) { throw new Error('Context is not available') } return context}modified:src/middleware/pretty-json/index.test.ts+18 added
53 unmodified lines54 }`)55 const nonPrettyText = await (await app.request('?pretty')).text()56 expect(nonPrettyText).toBe('{"message":"Hono!"}')57 })58+59+ it('Should force pretty JSON output when force option is true', async () => {60+ const app = new Hono()61+ app.use('*', prettyJSON({ force: true }))62+ app.get('/', (c) => {63+ return c.json({ message: 'Hono!' })64+ })65+66+ const resWithoutQuery = await (await app.request('http://localhost/')).text()67+ expect(resWithoutQuery).toBe(`{68+ "message": "Hono!"69+}`)70+71+ const resWithQuery = await (await app.request('http://localhost/?pretty')).text()72+ expect(resWithQuery).toBe(`{73+ "message": "Hono!"74+}`)75+ })76 })modified:src/middleware/pretty-json/index.ts+7 added-1 removed
15 unmodified lines16 * Query conditions for when to Pretty.17 * @default 'pretty'18 */19 query?: string20+21+ /**22+ * Force prettification of JSON responses regardless of query parameters.23+ * @default false24+ */25+ force?: boolean26 }27 28 /**29 * Pretty JSON Middleware for Hono.15 unmodified lines45 */46 export const prettyJSON = (options?: PrettyOptions): MiddlewareHandler => {47 const targetQuery = options?.query ?? 'pretty'48 return async function prettyJSON(c, next) {43- const pretty = c.req.query(targetQuery) || c.req.query(targetQuery) === ''49+ const pretty = options?.force || c.req.query(targetQuery) || c.req.query(targetQuery) === ''50 await next()51 if (pretty && c.res.headers.get('Content-Type')?.startsWith('application/json')) {52 const obj = await c.res.json()53 c.res = new Response(JSON.stringify(obj, null, options?.space ?? 2), c.res)3 unmodified linesmodified:src/middleware/secure-headers/index.test.ts+110 added
478 unmodified lines479 expect(csp).toMatch("style-src 'self' 'nonce-styleSrc'")480 expect(await res.text()).toEqual('script: scriptSrc, style: styleSrc')481 })482 })483+484+ // OUR NEW REPORT-URI TESTS485+ describe('CSP report-uri directive', () => {486+ it('should set report-uri with single endpoint', async () => {487+ const app = new Hono()488+ app.use(489+ '/test',490+ secureHeaders({491+ contentSecurityPolicy: {492+ defaultSrc: ["'self'"],493+ reportUri: '/csp-report',494+ },495+ })496+ )497+498+ const res = await app.request('/test')499+ expect(res.headers.get('Content-Security-Policy')).toEqual(500+ "default-src 'self'; report-uri /csp-report"501+ )502+ })503+504+ it('should set report-uri with multiple endpoints', async () => {505+ const app = new Hono()506+ app.use(507+ '/test',508+ secureHeaders({509+ contentSecurityPolicy: {510+ defaultSrc: ["'self'"],511+ reportUri: ['/endpoint1', '/endpoint2'],512+ },513+ })514+ )515+516+ const res = await app.request('/test')517+ expect(res.headers.get('Content-Security-Policy')).toEqual(518+ "default-src 'self'; report-uri /endpoint1 /endpoint2"519+ )520+ })521+522+ it('should work with report-to and report-uri together', async () => {523+ const app = new Hono()524+ app.use(525+ '/test',526+ secureHeaders({527+ contentSecurityPolicy: {528+ defaultSrc: ["'self'"],529+ reportTo: 'endpoint-1',530+ reportUri: '/legacy-report',531+ },532+ })533+ )534+535+ const res = await app.request('/test')536+ expect(res.headers.get('Content-Security-Policy')).toEqual(537+ "default-src 'self'; report-to endpoint-1; report-uri /legacy-report"538+ )539+ })540+541+ it('should work with Content-Security-Policy-Report-Only', async () => {542+ const app = new Hono()543+ app.use(544+ '/test',545+ secureHeaders({546+ contentSecurityPolicyReportOnly: {547+ defaultSrc: ["'self'"],548+ reportUri: '/csp-report-only',549+ },550+ })551+ )552+553+ const res = await app.request('/test')554+ expect(res.headers.get('Content-Security-Policy-Report-Only')).toEqual(555+ "default-src 'self'; report-uri /csp-report-only"556+ )557+ })558+559+ // ADDED MISSING TEST CASE for Report-Only:560+561+ it('should not output report-uri when reportUri is not set', async () => {562+ const app = new Hono()563+ app.use(564+ '/test',565+ secureHeaders({566+ contentSecurityPolicy: {567+ defaultSrc: ["'self'"],568+ },569+ })570+ )571+572+ const res = await app.request('/test')573+ const header = res.headers.get('Content-Security-Policy') || ''574+ expect(header.includes('report-uri')).toBe(false)575+ })576+577+ it('should not output report-uri in Report-Only when reportUri is not set', async () => {578+ const app = new Hono()579+ app.use(580+ '/test',581+ secureHeaders({582+ contentSecurityPolicyReportOnly: {583+ defaultSrc: ["'self'"],584+ },585+ })586+ )587+588+ const res = await app.request('/test')589+ const header = res.headers.get('Content-Security-Policy-Report-Only') || ''590+ expect(header.includes('report-uri')).toBe(false)591+ })592+ })593 })modified:src/middleware/secure-headers/secure-headers.ts+1 added
27 unmodified lines28 manifestSrc?: ContentSecurityPolicyOptionValue29 mediaSrc?: ContentSecurityPolicyOptionValue30 objectSrc?: ContentSecurityPolicyOptionValue31 reportTo?: string32+ reportUri?: string | string[]33 sandbox?: ContentSecurityPolicyOptionValue34 scriptSrc?: ContentSecurityPolicyOptionValue35 scriptSrcAttr?: ContentSecurityPolicyOptionValue36 scriptSrcElem?: ContentSecurityPolicyOptionValue298 unmodified linesmodified:src/middleware/timing/index.test.ts+32 added-1 removed
1 import { Hono } from '../../hono'2-import { endTime, setMetric, startTime, timing } from '.'2+import { endTime, setMetric, startTime, timing, wrapTime } from '.'3 4 describe('Server-Timing API', () => {5 const app = new Hono()6 15 unmodified lines22 endTime(c, name)23 24 return c.text('api!')25 })26+ app.get('/api-wrap', async (c) => {27+ await wrapTime(c, name, new Promise((r) => setTimeout(r, 30)))28+29+ return c.text('api!')30+ })31+ app.get('/api-wrap-throw', async (c) => {32+ try {33+ await wrapTime(c, name, new Promise((_, r) => setTimeout(r, 30)))34+ } catch (e) {35+ return c.text(`error :( ${e}`, 500)36+ }37+38+ return c.text('api!')39+ })40 app.get('/cache', async (c) => {41 setMetric(c, region, regionDesc)42 43 return c.text('cache!')20 unmodified lines64 expect(res.headers.get('server-timing')?.includes(`${name};dur=`)).toBeTruthy()65 expect(res.headers.get('server-timing')?.includes(name)).toBeTruthy()66 })67 68+ it('Should contain value metrics, wrapped', async () => {69+ const res = await app.request('http://localhost/api-wrap')70+ expect(res).not.toBeNull()71+ expect(res.headers.has('server-timing')).toBeTruthy()72+ expect(res.headers.get('server-timing')?.includes(`${name};dur=`)).toBeTruthy()73+ expect(res.headers.get('server-timing')?.includes(name)).toBeTruthy()74+ })75+76+ it('Should contain value metrics, wrapped throw', async () => {77+ const res = await app.request('http://localhost/api-wrap-throw')78+ expect(res).not.toBeNull()79+ expect(res.headers.has('server-timing')).toBeTruthy()80+ expect(res.status).toBeGreaterThanOrEqual(500)81+ expect(res.headers.get('server-timing')?.includes(`${name};dur=`)).toBeTruthy()82+ expect(res.headers.get('server-timing')?.includes(name)).toBeTruthy()83+ })84+85 it('Should contain value-less metrics', async () => {86 const res = await app.request('http://localhost/cache')87 expect(res).not.toBeNull()88 expect(res.headers.has('server-timing')).toBeTruthy()102 unmodified linesmodified:src/middleware/timing/index.ts+2 added-1 removed
1 import type { TimingVariables } from './timing'2+3 export { TimingVariables }3-export { timing, setMetric, startTime, endTime } from './timing'4+export { timing, setMetric, startTime, endTime, wrapTime } from './timing'5 6 declare module '../..' {7 interface ContextVariableMap extends TimingVariables {}8 }modified:src/middleware/timing/timing.ts+32 added
219 unmodified lines220 221 setMetric(c, name, duration, description, precision)222 metrics.timers.delete(name)223 }224+225+/**226+ * Wrap a Promise to capture its duration.227+ * @param {Context} c - The context of the request.228+ * @param {string} name - The name of the timer.229+ * @param {Promise<T>} callable - The Promise to time.230+ * @param {string} [description] - The description of the timer.231+ * @param {number} [precision] - The precision of the timer value.232+ *233+ * @example234+ * ```ts235+ * // Instead of this:236+ * const data = await db.findMany(...);237+ *238+ * // do this:239+ * const data = await wrapTime(c, 'query', db.findMany(...));240+ * ```241+ * */242+export async function wrapTime<T>(243+ c: Context,244+ name: string,245+ callable: Promise<T>,246+ description?: string,247+ precision?: number248+): Promise<T> {249+ startTime(c, name, description)250+ try {251+ return await callable252+ } finally {253+ endTime(c, name, precision)254+ }255+}modified:src/context.ts+1 added-1 removed
761 unmodified lines762 * return c.notFound()763 * })764 * ```765 */766- notFound = (): Response | Promise<Response> => {766+ notFound = (): ReturnType<NotFoundHandler> => {767 this.#notFoundHandler ??= () => new Response()768 return this.#notFoundHandler(this)769 }770 }modified:src/hono-base.ts+24 added-16 removed
93 unmodified lines94 optionHandler?: MountOptionHandler95 replaceRequest?: MountReplaceRequest | false96 }97 98+class Hono<99+ E extends Env = Env,100+ S extends Schema = {},101+ BasePath extends string = '/',102+ CurrentPath extends string = BasePath,98-class 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>113 114 /*56 unmodified lines171 Object.assign(this, optionsWithoutStrict)172 this.getPath = (strict ?? true) ? (options.getPath ?? getPath) : getPathNoStrict173 }174 170- #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.errorHandler28 unmodified lines209 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 lines243 * ```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 lines267 * 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 lines287 * 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 lines328 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 linesmodified:src/index.ts+1 added
23 unmodified lines24 ErrorHandler,25 Handler,26 MiddlewareHandler,27 Next,28+ NotFoundResponse,29 NotFoundHandler,30 ValidationTargets,31 Input,32 Schema,20 unmodified linesmodified:src/types.test.ts+341 added-4 removed
1 unmodified line2 import { expectTypeOf } from 'vitest'3 import { hc } from './client'4 import { Context } from './context'5 import { createMiddleware } from './helper/factory'6+import { testClient } from './helper/testing'7 import { Hono } from './hono'8 import { poweredBy } from './middleware/powered-by'9 import type {10 AddParam,230 unmodified lines241 }242 }243 type verify = Expect<Equal<Expected, Actual>>244 })245+246+ 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'))251+252+ 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 })285 286 describe('OnHandlerInterface', () => {39 unmodified lines326 expectTypeOf(c.var.foo).toEqualTypeOf<string>()327 return c.json({})328 })329 })330+331+ 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 })376 377 describe('TypedResponse', () => {378 test('unknown', () => {1998 unmodified lines2377 describe('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 lines3373 type verify = Expect<Equal<Expected, Actual>>3374 })3375 })3376 })3377+3378+describe('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'))3385+3386+ const client = testClient(app)3387+3388+ // @ts-expect-error '/' route returns Promise<void>, so it should not be in schema3389+ const res = await client.index.$get()3390+ })3391+3392+ 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+ })3396+3397+ const client = testClient(app)3398+3399+ // @ts-expect-error '/' route returns Promise<void>, so it should not be in schema3400+ const res = await client.index.$get()3401+ })3402+3403+ 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+ })3412+3413+ 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+ })3430+3431+ 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+ })3441+3442+ 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+ })3468+3469+ 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+ })3479+3480+ 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+ })3506+3507+ 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+ })3523+3524+ 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+ })3550+3551+ 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'))3560+3561+ 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+ })3574+3575+ 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'))3582+3583+ 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+ })3605+3606+ 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+ })3617+3618+ 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+389 added-279 removed
66 unmodified lines67 ////// Handlers //////68 ////// //////69 ////////////////////////////////////////70 71-export type HandlerResponse<O> = Response | TypedResponse<O> | Promise<Response | TypedResponse<O>>71+export type HandlerResponse<O> =72+ | Response73+ | TypedResponse<O>74+ | Promise<Response | TypedResponse<O>>75+ | Promise<void>76 77 export type Handler<78 E extends Env = any,79 P extends string = any,14 unmodified lines94 I extends Input = BlankInput,95 R extends HandlerResponse<any> = any,96 > = Handler<E, P, I, R> | MiddlewareHandler<E, P, I, R>97 94-export type NotFoundHandler<E extends Env = any> = (c: Context<E>) => Response | Promise<Response>98+/**99+ * You can extend this interface to define a custom `c.notFound()` Response type.100+ *101+ * @example102+ * declare module 'hono' {103+ * interface NotFoundResponse extends Response, TypedResponse<string, 404, 'text'> {}104+ * }105+ */106+export interface NotFoundResponse {}107 108+export type NotFoundHandler<E extends Env = any> = (109+ c: Context<E>110+) => NotFoundResponse extends Response111+ ? NotFoundResponse | Promise<NotFoundResponse>112+ : Response | Promise<Response>113+114 export interface HTTPResponseError extends Error {115 getResponse: () => Response116 }117 export type ErrorHandler<E extends Env = any> = (11 unmodified lines129 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 <118- 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>124- ): 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+ >149 150 // app.get(handler x2)151 <128- 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 lines160 ...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>>,140- BasePath164+ BasePath,165+ CurrentPath166 >167 168 // app.get(path, handler)169 <4 unmodified lines174 E2 extends Env = E,175 >(176 path: P,177 handler: H<E2, MergedPath, I, R>153- ): 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+ >184 185 // app.get(handler x 3)186 <157- 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 lines205 P,206 I3,207 MergeTypedResponse<R> | MergeMiddlewareResponse<M1> | MergeMiddlewareResponse<M2>208 >,179- BasePath209+ BasePath,210+ CurrentPath211 >212 213 // app.get(path, handler x2)214 <10 unmodified lines225 path: P,226 ...handlers: [H<E2, MergedPath, I> & M1, H<E3, MergedPath, I2, R>]227 ): HonoBase<228 E,198- S &199- ToSchema<M, MergePath<BasePath, P>, I2, MergeTypedResponse<R> | MergeMiddlewareResponse<M1>>,200- BasePath229+ AddSchemaIfHasResponse<230+ MergeTypedResponse<R> | MergeMiddlewareResponse<M1>,231+ S,232+ M,233+ P,234+ I2,235+ BasePath236+ >,237+ BasePath,238+ MergePath<BasePath, P>239 >240 241 // app.get(handler x 4)242 <205- 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 lines267 | MergeMiddlewareResponse<M1>268 | MergeMiddlewareResponse<M2>269 | MergeMiddlewareResponse<M3>270 >,233- BasePath271+ BasePath,272+ CurrentPath273 >274 275 // app.get(path, handler x3)276 <13 unmodified lines290 path: P,291 ...handlers: [H<E2, MergedPath, I> & M1, H<E3, MergedPath, I2> & M2, H<E4, MergedPath, I3, R>]292 ): HonoBase<293 E,255- S &256- ToSchema<257- M,258- MergePath<BasePath, P>,259- I3,260- MergeTypedResponse<R> | MergeMiddlewareResponse<M1> | MergeMiddlewareResponse<M2>261- >,262- 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 >305 306 // app.get(handler x 5)307 <267- 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 lines342 | MergeMiddlewareResponse<M2>343 | MergeMiddlewareResponse<M3>344 | MergeMiddlewareResponse<M4>345 >,305- BasePath346+ BasePath,347+ CurrentPath348 >349 350 // app.get(path, handler x4)351 <21 unmodified lines373 H<E5, MergedPath, I4, R>,374 ]375 ): HonoBase<376 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- 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 >391 392 // app.get(handler x 6)393 <350- 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 lines433 | MergeMiddlewareResponse<M3>434 | MergeMiddlewareResponse<M4>435 | MergeMiddlewareResponse<M5>436 >,393- BasePath437+ BasePath,438+ CurrentPath439 >440 441 // app.get(path, handler x5)442 <25 unmodified lines468 H<E6, MergedPath, I5, R>,469 ]470 ): HonoBase<471 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- 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 >487 488 // app.get(handler x 7)489 <443- 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 lines534 | MergeMiddlewareResponse<M4>535 | MergeMiddlewareResponse<M5>536 | MergeMiddlewareResponse<M6>537 >,491- BasePath538+ BasePath,539+ CurrentPath540 >541 542 // app.get(path, handler x6)543 <29 unmodified lines573 H<E7, MergedPath, I6, R>,574 ]575 ): HonoBase<576 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- 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 >593 594 // app.get(handler x 8)595 <546- 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 lines645 | MergeMiddlewareResponse<M5>646 | MergeMiddlewareResponse<M6>647 | MergeMiddlewareResponse<M7>648 >,599- BasePath649+ BasePath,650+ CurrentPath651 >652 653 // app.get(path, handler x7)654 <33 unmodified lines688 H<E8, MergedPath, I7, R>,689 ]690 ): HonoBase<691 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- 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 >709 710 // app.get(handler x 9)711 <659- 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 lines766 | MergeMiddlewareResponse<M6>767 | MergeMiddlewareResponse<M7>768 | MergeMiddlewareResponse<M8>769 >,717- BasePath770+ BasePath,771+ CurrentPath772 >773 774 // app.get(path, handler x8)775 <37 unmodified lines813 H<E9, MergedPath, I8, R>,814 ]815 ): HonoBase<816 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- 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 >835 836 // app.get(handler x 10)837 <782- 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 lines897 | MergeMiddlewareResponse<M7>898 | MergeMiddlewareResponse<M8>899 | MergeMiddlewareResponse<M9>900 >,845- BasePath901+ BasePath,902+ CurrentPath903 >904 905 // app.get(path, handler x9)906 <41 unmodified lines948 H<E10, MergedPath, I9, R>,949 ]950 ): HonoBase<951 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- 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 >971 972 // app.get(path, handler x10)973 <45 unmodified lines1019 H<E11, MergedPath, I10, R>,1020 ]1021 ): HonoBase<1022 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- 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 >1043 1044 // app.get(...handlers[])1045 <985- 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>[]990- ): HonoBase<E, S & ToSchema<M, P, I, MergeTypedResponse<R>>, BasePath>1051+ ): HonoBase<E, S & ToSchema<M, P, I, MergeTypedResponse<R>>, BasePath, CurrentPath>1052 1053 // app.get(path, ...handlers[])1054 <P extends string, I extends Input = BlankInput, R extends HandlerResponse<any> = any>(1055 path: P,995- ...handlers: H<E, MergePath<BasePath, P>, I, R>[]996- ): 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+ >1063 1064 // app.get(path)1065 <P extends string, R extends HandlerResponse<any> = any, I extends Input = BlankInput>(1066 path: P1001- ): 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 }1074 1075 ////////////////////////////////////////1076 ////// //////7 unmodified lines1084 BasePath extends string = '/',1085 > {1086 //// app.use(...handlers[])1087 <E2 extends Env = E>(1017- ...handlers: MiddlewareHandler<E2, MergePath<BasePath, ExtractStringKey<S>>>[]1018- ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath>1088+ ...handlers: MiddlewareHandler<E2, MergePath<BasePath, '*'>>[]1089+ ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath, MergePath<BasePath, '*'>>1090 1091 // app.use(handler)1092 <E2 extends Env = E>(1022- handler: MiddlewareHandler<E2, MergePath<BasePath, ExtractStringKey<S>>>1023- ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath>1093+ handler: MiddlewareHandler<E2, MergePath<BasePath, '*'>>1094+ ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath, MergePath<BasePath, '*'>>1095 1096 // app.use(handler x2)1097 <1098 E2 extends Env = E,1099 E3 extends Env = IntersectNonAnyTypes<[E, E2]>,1029- P extends string = MergePath<BasePath, ExtractStringKey<S>>,1100+ P extends string = MergePath<BasePath, '*'>,1101 >(1102 ...handlers: [MiddlewareHandler<E2, P>, MiddlewareHandler<E3, P>]1032- ): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, S, BasePath>1103+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, S, BasePath, P>1104 1034- // 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>1038- ): HonoBase<IntersectNonAnyTypes<[E, E2]>, ChangePathOfSchema<S, MergedPath>, BasePath>1109+ ): HonoBase<IntersectNonAnyTypes<[E, E2]>, S, BasePath, MergedPath>1110 1111 // 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]>,1045- 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 ]1052- ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath>1123+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath, P>1124 1054- // 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>]1063- ): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, ChangePathOfSchema<S, MergedPath>, BasePath>1134+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3]>, S, BasePath, MergedPath>1135 1136 // 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]>,1071- 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 ]1079- ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S, BasePath>1150+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S, BasePath, P>1151 1081- // 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 line1158 E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,1159 >(1160 path: P,1161 ...handlers: [MiddlewareHandler<E2, P>, MiddlewareHandler<E3, P>, MiddlewareHandler<E4, P>]1091- ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, ChangePathOfSchema<S, MergedPath>, BasePath>1162+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4]>, S, BasePath, MergedPath>1163 1164 // 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]>,1100- 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 ]1109- ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S, BasePath>1180+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S, BasePath, P>1181 1111- // 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 lines1194 MiddlewareHandler<E3, P>,1195 MiddlewareHandler<E4, P>,1196 MiddlewareHandler<E5, P>,1197 ]1127- ): HonoBase<1128- IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1129- ChangePathOfSchema<S, MergedPath>,1130- BasePath1131- >1198+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5]>, S, BasePath, MergedPath>1199 1200 // app.use(handler x6)1201 <1202 E2 extends Env = E,1 unmodified line1204 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]>,1141- 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 line1214 MiddlewareHandler<E5, P>,1215 MiddlewareHandler<E6, P>,1216 MiddlewareHandler<E7, P>,1217 ]1151- ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S, BasePath>1218+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S, BasePath, P>1219 1153- // 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 lines1234 MiddlewareHandler<E4, P>,1235 MiddlewareHandler<E5, P>,1236 MiddlewareHandler<E6, P>,1237 ]1171- ): HonoBase<1172- IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1173- ChangePathOfSchema<S, MergedPath>,1174- BasePath1175- >1238+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>, S, BasePath, MergedPath>1239 1240 // app.use(handler x7)1241 <1242 E2 extends Env = E,2 unmodified lines1245 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]>,1186- 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 lines1256 MiddlewareHandler<E6, P>,1257 MiddlewareHandler<E7, P>,1258 MiddlewareHandler<E8, P>,1259 ]1197- ): 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>1261 1199- // 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 lines1278 MiddlewareHandler<E5, P>,1279 MiddlewareHandler<E6, P>,1280 MiddlewareHandler<E7, P>,1281 ]1219- ): HonoBase<1220- IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1221- ChangePathOfSchema<S, MergedPath>,1222- BasePath1223- >1282+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>, S, BasePath, MergedPath>1283 1284 // app.use(handler x8)1285 <1286 E2 extends Env = E,3 unmodified lines1290 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]>,1235- 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 lines1302 MiddlewareHandler<E7, P>,1303 MiddlewareHandler<E8, P>,1304 MiddlewareHandler<E9, P>,1305 ]1247- ): 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>1307 1249- // 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 lines1326 MiddlewareHandler<E6, P>,1327 MiddlewareHandler<E7, P>,1328 MiddlewareHandler<E8, P>,1329 ]1271- ): HonoBase<1272- IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,1273- ChangePathOfSchema<S, MergedPath>,1274- BasePath1275- >1330+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>, S, BasePath, MergedPath>1331 1332 // app.use(handler x9)1333 <1334 E2 extends Env = E,4 unmodified lines1339 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]>,1288- 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 lines1352 MiddlewareHandler<E8, P>,1353 MiddlewareHandler<E9, P>,1354 MiddlewareHandler<E10, P>,1355 ]1301- ): 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>1357 1303- // 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 lines1378 MiddlewareHandler<E7, P>,1379 MiddlewareHandler<E8, P>,1380 MiddlewareHandler<E9, P>,1381 ]1327- ): HonoBase<1328- IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,1329- ChangePathOfSchema<S, MergedPath>,1330- BasePath1331- >1382+ ): HonoBase<IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>, S, BasePath, MergedPath>1383 1384 // app.use(handler x10)1385 <1386 E2 extends Env = E,5 unmodified lines1392 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]>,1345- 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 lines1406 MiddlewareHandler<E9, P>,1407 MiddlewareHandler<E10, P>,1408 MiddlewareHandler<E11, P>,1409 ]1359- ): 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>1411 1361- // 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 lines1436 MiddlewareHandler<E10, P>,1437 ]1438 ): HonoBase<1439 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,1389- ChangePathOfSchema<S, MergedPath>,1390- BasePath1440+ S,1441+ BasePath,1442+ MergedPath1443 >1444 1445 //// app.use(path, ...handlers[])1446 <P extends string, E2 extends Env = E>(1447 path: P,1448 ...handlers: MiddlewareHandler<E2, MergePath<BasePath, P>>[]1397- ): HonoBase<E, S, BasePath>1449+ ): HonoBase<E, S, BasePath, MergePath<BasePath, P>>1450 }1451 1452 ////////////////////////////////////////1453 ////// //////20 unmodified lines1474 handler: H<E2, MergedPath, I, R>1475 ): HonoBase<1476 IntersectNonAnyTypes<[E, E2]>,1477 S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>,1426- BasePath1478+ BasePath,1479+ MergePath<BasePath, P>1480 >1481 1482 // app.on(method, path, handler x2)1483 <11 unmodified lines1495 ...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>>,1446- BasePath1499+ BasePath,1500+ MergePath<BasePath, P>1501 >1502 1503 // app.on(method, path, handler x3)1504 <13 unmodified lines1518 ...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>>,1468- BasePath1522+ BasePath,1523+ MergePath<BasePath, P>1524 >1525 1526 // app.on(method, path, handler x4)1527 <20 unmodified lines1548 ]1549 ): HonoBase<1550 IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1551 S & ToSchema<M, MergePath<BasePath, P>, I4, MergeTypedResponse<R>>,1497- BasePath1552+ BasePath,1553+ MergePath<BasePath, P>1554 >1555 1556 // app.on(method, path, handler x5)1557 <23 unmodified lines1581 ]1582 ): HonoBase<1583 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1584 S & ToSchema<M, MergePath<BasePath, P>, I5, MergeTypedResponse<R>>,1529- BasePath1585+ BasePath,1586+ MergePath<BasePath, P>1587 >1588 1589 // app.on(method, path, handler x6)1590 <26 unmodified lines1617 ]1618 ): HonoBase<1619 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1620 S & ToSchema<M, MergePath<BasePath, P>, I6, MergeTypedResponse<R>>,1564- BasePath1621+ BasePath,1622+ MergePath<BasePath, P>1623 >1624 1625 // app.on(method, path, handler x7)1626 <29 unmodified lines1656 ]1657 ): HonoBase<1658 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,1659 S & ToSchema<M, MergePath<BasePath, P>, I7, MergeTypedResponse<R>>,1602- BasePath1660+ BasePath,1661+ MergePath<BasePath, P>1662 >1663 1664 // app.on(method, path, handler x8)1665 <32 unmodified lines1698 ]1699 ): HonoBase<1700 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,1701 S & ToSchema<M, MergePath<BasePath, P>, I8, MergeTypedResponse<R>>,1643- BasePath1702+ BasePath,1703+ MergePath<BasePath, P>1704 >1705 1706 // app.on(method, path, handler x9)1707 <35 unmodified lines1743 ]1744 ): HonoBase<1745 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,1746 S & ToSchema<M, MergePath<BasePath, P>, I9, MergeTypedResponse<R>>,1687- BasePath1747+ BasePath,1748+ MergePath<BasePath, P>1749 >1750 1751 // app.on(method, path, handler x10)1752 <38 unmodified lines1791 ]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>>>,1734- BasePath1795+ BasePath,1796+ MergePath<BasePath, P>1797 >1798 1737- // 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,1746- ...handlers: H<E, MergePath<BasePath, P>, I, R>[]1747- ): 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+ >1815 1749- // 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 lines1827 handler: H<E2, MergedPath, I, R>1828 ): HonoBase<1829 IntersectNonAnyTypes<[E, E2]>,1830 S & ToSchema<Ms[number], MergePath<BasePath, P>, I, MergeTypedResponse<R>>,1764- BasePath1831+ BasePath,1832+ MergePath<BasePath, P>1833 >1834 1767- // 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 lines1848 ...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>>,1784- BasePath1852+ BasePath,1853+ MergePath<BasePath, P>1854 >1855 1787- // 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 lines1871 ...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>>,1806- BasePath1875+ BasePath,1876+ MergePath<BasePath, P>1877 >1878 1809- // 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 lines1901 ]1902 ): HonoBase<1903 IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,1904 S & ToSchema<Ms[number], MergePath<BasePath, P>, I4, MergeTypedResponse<R>>,1835- BasePath1905+ BasePath,1906+ MergePath<BasePath, P>1907 >1908 1838- // 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 lines1934 ]1935 ): HonoBase<1936 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,1937 S & ToSchema<Ms[number], MergePath<BasePath, P>, I5, MergeTypedResponse<R>>,1867- BasePath1938+ BasePath,1939+ MergePath<BasePath, P>1940 >1941 1870- // 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 lines1970 ]1971 ): HonoBase<1972 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,1973 S & ToSchema<Ms[number], MergePath<BasePath, P>, I6, MergeTypedResponse<R>>,1902- BasePath1974+ BasePath,1975+ MergePath<BasePath, P>1976 >1977 1905- // 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 lines2009 ]2010 ): HonoBase<2011 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,2012 S & ToSchema<Ms[number], MergePath<BasePath, P>, I7, MergeTypedResponse<R>>,1940- BasePath2013+ BasePath,2014+ MergePath<BasePath, P>2015 >2016 1943- // 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 lines2051 ]2052 ): HonoBase<2053 IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,2054 S & ToSchema<Ms[number], MergePath<BasePath, P>, I8, MergeTypedResponse<R>>,1981- BasePath2055+ BasePath,2056+ MergePath<BasePath, P>2057 >2058 1984- // 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 lines2096 ]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>>>,2025- BasePath2100+ BasePath,2101+ MergePath<BasePath, P>2102 >2103 2028- // 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 lines2144 ]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>>>,2072- BasePath2148+ BasePath,2149+ MergePath<BasePath, P>2150 >2151 2152 // app.on(method[], path, ...handler)2153 <P extends string, R extends HandlerResponse<any> = any, I extends Input = BlankInput>(2154 methods: string[],2155 path: P,2079- ...handlers: H<E, MergePath<BasePath, P>, I, R>[]2080- ): 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+ >2163 2164 // app.on(method | method[], path[], ...handlers[])2083- <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[],2085- paths: string[],2086- ...handlers: H<E2, any, I, R>[]2087- ): 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 }2181 2090-type ExtractStringKey<S> = keyof S & string2091-2182 ////////////////////////////////////////2183 ////// //////2184 ////// ToSchema //////2185 ////// //////3 unmodified lines2189 M extends string,2190 P extends string,2191 I extends Input | Input['in'],2192 RorO, // Response or Output2103-> = Simplify<{2104- [K in P]: {2105- [K2 in M as AddDollar<K2>]: Simplify<2106- {2107- input: AddParam<ExtractInput<I>, P>2108- } & (IsAny<RorO> extends true2109- ? {2110- output: {}2111- outputFormat: ResponseFormat2112- status: StatusCode2113- }2114- : RorO extends TypedResponse<infer T, infer U, infer F>2115- ? {2116- output: unknown extends T ? {} : T2117- outputFormat: I extends { outputFormat: string } ? I['outputFormat'] : F2118- status: U2119- }2120- : {2121- output: unknown extends RorO ? {} : RorO2122- outputFormat: unknown extends RorO2123- ? 'json'2124- : I extends { outputFormat: string }2125- ? I['outputFormat']2126- : '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: StatusCode2128- })2129- >2130- }2131-}>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+ }>2235 2236 export type Schema = {2237 [Path: string]: {2238 [Method: `$${Lowercase<string>}`]: Endpoint2239 }2240 }2241 2139-type ChangePathOfSchema<S extends Schema, Path extends string> = keyof S extends never2140- ? { [K in Path]: {} }2141- : { [K in keyof S as Path]: S[K] }2242+type 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>2250 2251 export type Endpoint = {2252 input: any2253 output: any97 unmodified lines2351 _format: F2352 }2353 2354 type MergeTypedResponse<T> =2355+ T extends Promise<void>2356+ ? T2247- T extends Promise<infer T2>2248- ? T2 extends TypedResponse2249- ? T22250- : TypedResponse2251- : T extends TypedResponse2252- ? T2253- : TypedResponse2357+ : T extends Promise<infer T2>2358+ ? T2 extends TypedResponse2359+ ? T22360+ : TypedResponse2361+ : T extends TypedResponse2362+ ? T2363+ : TypedResponse2364 2365 type MergeTypedResponseStrict<T> =2366 T extends Promise<infer T2>2367 ? T2 extends TypedResponse68 unmodified lines2436 ////// //////2437 ////////////////////////////////////////2438 2439 export type ExtractSchema<T> = UnionToIntersection<2330- T extends HonoBase<infer _, infer S, any> ? S : never2440+ T extends HonoBase<infer _, infer S, any, any> ? S : never2441 >2442 2443 export type ExtractSchemaForStatusCode<T, Status extends number> = {2444 [Path in keyof ExtractSchema<T>]: {36 unmodified linesmodified:bun.lock+1 added
1 {2 "lockfileVersion": 1,3+ "configVersion": 0,4 "workspaces": {5 "": {6 "name": "hono",7 "devDependencies": {2352 unmodified lines