diff --git a/src/adapter/bun/handler.ts b/src/adapter/bun/handler.ts index a3e128dc4..626caa4d2 100644 --- a/src/adapter/bun/handler.ts +++ b/src/adapter/bun/handler.ts @@ -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') diff --git a/src/adapter/web-standard/handler.ts b/src/adapter/web-standard/handler.ts index 0314be75c..aaf29107a 100644 --- a/src/adapter/web-standard/handler.ts +++ b/src/adapter/web-standard/handler.ts @@ -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') diff --git a/test/adapter/web-standard/map-compact-response.test.ts b/test/adapter/web-standard/map-compact-response.test.ts index 9394c8a89..b8567b36c 100644 --- a/test/adapter/web-standard/map-compact-response.test.ts +++ b/test/adapter/web-standard/map-compact-response.test.ts @@ -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) + }) })