Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adapter/bun/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export const mapCompactResponse = (
// @ts-expect-error
if (typeof response?.then === 'function')
// @ts-expect-error
return response.then((x) => mapResponse(x, set)) as any
return response.then((x) => mapCompactResponse(x, request)) as any

// @ts-expect-error
if (typeof response?.toResponse === 'function')
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/web-standard/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export const mapCompactResponse = (
// @ts-expect-error
if (typeof response?.then === 'function')
// @ts-expect-error
return response.then((x) => mapResponse(x, set)) as any
return response.then((x) => mapCompactResponse(x, request)) as any

// @ts-expect-error
if (typeof response?.toResponse === 'function')
Expand Down
23 changes: 23 additions & 0 deletions test/adapter/web-standard/map-compact-response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,27 @@ describe('Web Standard - Map Compact Response', () => {
expect(response.status).toBe(200)
expect(await response.formData()).toBeInstanceOf(FormData)
})

it('map custom thenable', async () => {
// Custom thenable object (e.g., like some ORMs return such as Drizzle)
// Using a class to avoid being caught by the 'Object' case
class CustomThenable {
then(onFulfilled: (value: any) => any) {
const data = { name: 'Shiroko', id: 42 }
return Promise.resolve(data).then(onFulfilled)
}
}

const customThenable = new CustomThenable()
const responsePromise = mapCompactResponse(customThenable)
expect(responsePromise).toBeInstanceOf(Promise)

const response = await responsePromise

expect(response).toBeInstanceOf(Response)
const body = await response.text()
const parsed = JSON.parse(body)
expect(parsed).toEqual({ name: 'Shiroko', id: 42 })
expect(response.status).toBe(200)
})
})
Loading