Skip to content

Commit

Permalink
feat: allow the type of app.request (#1444)
Browse files Browse the repository at this point in the history
* feat: allow the type of app.request

* typo
  • Loading branch information
hagishi authored Sep 12, 2023
1 parent f521d30 commit 00af2a5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion deno_dist/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import type { Hono } from '../hono.ts'
import type { Schema } from '../types.ts'
import type { RemoveBlankRecord } from '../utils/types.ts'

type HonoRequest = typeof Hono.prototype['request']

export type ClientRequestOptions = {
headers?: Record<string, string>
fetch?: typeof fetch
fetch?: typeof fetch | HonoRequest
}

type ClientRequest<S extends Schema> = {
Expand Down
2 changes: 1 addition & 1 deletion deno_dist/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class Hono<
}

request = (
input: Request | string | URL,
input: RequestInfo | URL,
requestInit?: RequestInit,
Env?: E['Bindings'] | {},
executionCtx?: ExecutionContext
Expand Down
10 changes: 10 additions & 0 deletions src/client/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,13 @@ describe('Use custom fetch method', () => {
expect(res).toEqual(returnValue)
})
})

describe('Use custom fetch (app.request) method', () => {
it('Should return Response from app request method', async () => {
const app = new Hono().get('/search', (c) => c.jsonT({ ok: true }))
type AppType = typeof app
const client = hc<AppType>('', { fetch: app.request })
const res = await client.search.$get()
expect(res.ok).toBe(true)
})
})
4 changes: 3 additions & 1 deletion src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import type { Hono } from '../hono'
import type { Schema } from '../types'
import type { RemoveBlankRecord } from '../utils/types'

type HonoRequest = typeof Hono.prototype['request']

export type ClientRequestOptions = {
headers?: Record<string, string>
fetch?: typeof fetch
fetch?: typeof fetch | HonoRequest
}

type ClientRequest<S extends Schema> = {
Expand Down
2 changes: 1 addition & 1 deletion src/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class Hono<
}

request = (
input: Request | string | URL,
input: RequestInfo | URL,
requestInit?: RequestInit,
Env?: E['Bindings'] | {},
executionCtx?: ExecutionContext
Expand Down

0 comments on commit 00af2a5

Please sign in to comment.