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
Provenance
- Commit
d194e9b- Tree
8e611da- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
4550b31
3 files changed+22 added−4 removed
modified:deno_dist/hono-base.ts+2 added-2 removed
145 unmodified lines146 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 lines161 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)167 168 if (!app) {169 // eslint-disable-next-line @typescript-eslint/no-explicit-any230 unmodified linesmodified:src/client/client.test.ts+18 added
337 unmodified lines338 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 )351 352 beforeAll(() => server.listen())27 unmodified lines380 type verify = Expect<Equal<boolean, typeof data.ok>>381 expect(data.ok).toBe(true)382 })383 384+ 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+ })394+395 it('Should have correct types - with interface', async () => {396 interface Result {397 ok: boolean398 }70 unmodified linesmodified:src/hono-base.ts+2 added-2 removed
145 unmodified lines146 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 lines161 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)167 168 if (!app) {169 // eslint-disable-next-line @typescript-eslint/no-explicit-any230 unmodified lines