Skip to content
Myr

fix(rpc): infer path with `route()` and `basePath()` (#1401)

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

* fix(rpc): infer path with `route()` and `basePath()` * denoify

authored by Yusuke Wada · committed by GitHub · parent 4550b31 · Browse files · 3 files+22 added−4 removed
This commit

State

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

Diff stats

3 files+22 added−4 removed

  • tests:+18 added−0 removed
  • other:+4 added−4 removed

3 files+22 added−4 removed

modified:deno_dist/hono-base.ts+2 added-2 removed
145 unmodified lines
146 SubBasePath extends string147 >(148 path: SubPath,149 app: Hono<SubEnv, SubSchema, SubBasePath>150 ): Hono<E, MergeSchemaPath<SubSchema, SubPath> & S, BasePath>150 ): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>151 /** @description152 * Use `basePath` instead of `route` when passing **one** argument, such as `app.route('/api')`.153 * The use of `route` with **one** argument has been removed in v4.154 * However, you can still use `route` with **two** arguments, like `app.route('/api', subApp)`."
6 unmodified lines
161 SubBasePath extends string162 >(163 path: SubPath,164 app?: Hono<SubEnv, SubSchema, SubBasePath>165 ): Hono<E, MergeSchemaPath<SubSchema, SubPath> & S, BasePath> {165 ): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath> {166 const subApp = this.basePath(path)167168 if (!app) {169 // eslint-disable-next-line @typescript-eslint/no-explicit-any
230 unmodified lines
modified:src/client/client.test.ts+18 added
337 unmodified lines
338 ctx.json({339 ok: true,340 })341 )342 }),343 rest.get('http://localhost/v1/book', async (req, res, ctx) => {344 return res(345 ctx.json({346 ok: true,347 })348 )349 })350 )351352 beforeAll(() => server.listen())
27 unmodified lines
380 type verify = Expect<Equal<boolean, typeof data.ok>>381 expect(data.ok).toBe(true)382 })383384 it('Should have correct types - basePath(), route(), get()', async () => {385 const book = new Hono().get('/', (c) => c.jsonT({ ok: true }))386 const app = new Hono().basePath('/v1').route('/book', book)387 type AppType = typeof app388 const client = hc<AppType>('http://localhost')389 const res = await client.v1.book.index.$get()390 const data = await res.json()391 type verify = Expect<Equal<boolean, typeof data.ok>>392 expect(data.ok).toBe(true)393 })394395 it('Should have correct types - with interface', async () => {396 interface Result {397 ok: boolean398 }
70 unmodified lines
modified:src/hono-base.ts+2 added-2 removed
145 unmodified lines
146 SubBasePath extends string147 >(148 path: SubPath,149 app: Hono<SubEnv, SubSchema, SubBasePath>150 ): Hono<E, MergeSchemaPath<SubSchema, SubPath> & S, BasePath>150 ): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath>151 /** @description152 * Use `basePath` instead of `route` when passing **one** argument, such as `app.route('/api')`.153 * The use of `route` with **one** argument has been removed in v4.154 * However, you can still use `route` with **two** arguments, like `app.route('/api', subApp)`."
6 unmodified lines
161 SubBasePath extends string162 >(163 path: SubPath,164 app?: Hono<SubEnv, SubSchema, SubBasePath>165 ): Hono<E, MergeSchemaPath<SubSchema, SubPath> & S, BasePath> {165 ): Hono<E, MergeSchemaPath<SubSchema, MergePath<BasePath, SubPath>> & S, BasePath> {166 const subApp = this.basePath(path)167168 if (!app) {169 // eslint-disable-next-line @typescript-eslint/no-explicit-any
230 unmodified lines