Skip to content

Commit 243f8b5

Browse files
committed
🔧 fix: handle .then
1 parent 22b79ce commit 243f8b5

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.1.23 - 22 Oct 2024
2+
Bug fix:
3+
- Handle object with `.then` even if it's not promise (looking at you, Drizzle)
4+
15
# 1.1.22 - 13 Oct 2024
26
Bug fix:
37
- Fix `set-cookie` to resent if value is accessed even without set

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Ergonomic Framework for Human",
4-
"version": "1.1.22",
4+
"version": "1.1.23",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

src/handler.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,13 @@ export const mapResponse = (
448448
// @ts-expect-error
449449
return handleStream(response as any, set, request)
450450

451-
if ('toResponse' in (response as any))
451+
// @ts-expect-error
452+
if (typeof response?.then === 'function')
453+
// @ts-expect-error
454+
return response.then((x) => mapResponse(x, set)) as any
455+
456+
// @ts-expect-error
457+
if (typeof response?.toResponse === 'function')
452458
return mapResponse((response as any).toResponse(), set)
453459

454460
if ('charCodeAt' in (response as any)) {
@@ -588,7 +594,13 @@ export const mapResponse = (
588594
// @ts-expect-error
589595
return handleStream(response as any, set, request)
590596

591-
if ('toResponse' in (response as any))
597+
// @ts-expect-error
598+
if (typeof response?.then === 'function')
599+
// @ts-expect-error
600+
return response.then((x) => mapResponse(x, set)) as any
601+
602+
// @ts-expect-error
603+
if (typeof response?.toResponse === 'function')
592604
return mapResponse((response as any).toResponse(), set)
593605

594606
if ('charCodeAt' in (response as any)) {
@@ -832,8 +844,14 @@ export const mapEarlyResponse = (
832844
// @ts-expect-error
833845
return handleStream(response as any, set, request)
834846

835-
if ('toResponse' in (response as any))
836-
return mapEarlyResponse((response as any).toResponse(), set)
847+
// @ts-expect-error
848+
if (typeof response?.then === 'function')
849+
// @ts-expect-error
850+
return response.then((x) => mapResponse(x, set)) as any
851+
852+
// @ts-expect-error
853+
if (typeof response?.toResponse === 'function')
854+
return mapResponse((response as any).toResponse(), set)
837855

838856
if ('charCodeAt' in (response as any)) {
839857
const code = (response as any).charCodeAt(0)
@@ -966,8 +984,14 @@ export const mapEarlyResponse = (
966984
// @ts-expect-error
967985
return handleStream(response as any, set, request)
968986

969-
if ('toResponse' in (response as any))
970-
return mapEarlyResponse((response as any).toResponse(), set)
987+
// @ts-expect-error
988+
if (typeof response?.then === 'function')
989+
// @ts-expect-error
990+
return response.then((x) => mapResponse(x, set)) as any
991+
992+
// @ts-expect-error
993+
if (typeof response?.toResponse === 'function')
994+
return mapResponse((response as any).toResponse(), set)
971995

972996
if ('charCodeAt' in (response as any)) {
973997
const code = (response as any).charCodeAt(0)
@@ -1097,8 +1121,14 @@ export const mapCompactResponse = (
10971121
// @ts-expect-error
10981122
return handleStream(response as any, undefined, request)
10991123

1100-
if ('toResponse' in (response as any))
1101-
return mapCompactResponse((response as any).toResponse())
1124+
// @ts-expect-error
1125+
if (typeof response?.then === 'function')
1126+
// @ts-expect-error
1127+
return response.then((x) => mapResponse(x, set)) as any
1128+
1129+
// @ts-expect-error
1130+
if (typeof response?.toResponse === 'function')
1131+
return mapResponse((response as any).toResponse(), set)
11021132

11031133
if ('charCodeAt' in (response as any)) {
11041134
const code = (response as any).charCodeAt(0)

0 commit comments

Comments
 (0)