@@ -448,7 +448,13 @@ export const mapResponse = (
448
448
// @ts -expect-error
449
449
return handleStream ( response as any , set , request )
450
450
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' )
452
458
return mapResponse ( ( response as any ) . toResponse ( ) , set )
453
459
454
460
if ( 'charCodeAt' in ( response as any ) ) {
@@ -588,7 +594,13 @@ export const mapResponse = (
588
594
// @ts -expect-error
589
595
return handleStream ( response as any , set , request )
590
596
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' )
592
604
return mapResponse ( ( response as any ) . toResponse ( ) , set )
593
605
594
606
if ( 'charCodeAt' in ( response as any ) ) {
@@ -832,8 +844,14 @@ export const mapEarlyResponse = (
832
844
// @ts -expect-error
833
845
return handleStream ( response as any , set , request )
834
846
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 )
837
855
838
856
if ( 'charCodeAt' in ( response as any ) ) {
839
857
const code = ( response as any ) . charCodeAt ( 0 )
@@ -966,8 +984,14 @@ export const mapEarlyResponse = (
966
984
// @ts -expect-error
967
985
return handleStream ( response as any , set , request )
968
986
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 )
971
995
972
996
if ( 'charCodeAt' in ( response as any ) ) {
973
997
const code = ( response as any ) . charCodeAt ( 0 )
@@ -1097,8 +1121,14 @@ export const mapCompactResponse = (
1097
1121
// @ts -expect-error
1098
1122
return handleStream ( response as any , undefined , request )
1099
1123
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 )
1102
1132
1103
1133
if ( 'charCodeAt' in ( response as any ) ) {
1104
1134
const code = ( response as any ) . charCodeAt ( 0 )
0 commit comments