@@ -5,15 +5,11 @@ import express from 'express'
5
5
import type { LambdaEvent } from 'lambda-local'
6
6
7
7
import { chalk , logPadded , NETLIFYDEVERR } from '../../utils/command-helpers.js'
8
- import { isStream as baseIsReadableStream } from '../../utils/is-stream.js'
9
8
import renderErrorTemplate from '../render-error-template.js'
10
9
11
10
import { detectAwsSdkError } from './utils.js'
12
11
import type { InvocationError } from './netlify-function.js'
13
-
14
- // Annoyingly, `isReadableStream` refines to the `Readable` interface rather than the
15
- // `ReadableStream` class. Refining to the class makes further refinements work as expected.
16
- const isReadableStream = ( value : unknown ) : value is NodeJS . ReadableStream => baseIsReadableStream ( value )
12
+ import { isReadable } from 'stream'
17
13
18
14
const addHeaders = ( headers : undefined | Record < string , string | string [ ] > , response : express . Response ) : void => {
19
15
if ( ! headers ) {
@@ -89,13 +85,12 @@ export const handleSynchronousFunction = async function ({
89
85
}
90
86
91
87
if ( result . body ) {
92
- if ( isReadableStream ( result . body ) ) {
93
- result . body . pipe ( response )
88
+ if ( isReadable ( result . body as NodeJS . ReadableStream ) ) {
89
+ ( result . body as NodeJS . ReadableStream ) . pipe ( response )
94
90
95
91
return
96
92
}
97
-
98
- response . write ( result . isBase64Encoded ? Buffer . from ( result . body , 'base64' ) : result . body )
93
+ response . write ( result . isBase64Encoded ? Buffer . from ( result . body as string , 'base64' ) : result . body )
99
94
}
100
95
response . end ( )
101
96
}
@@ -182,7 +177,7 @@ const validateLambdaResponse = (lambdaResponse: undefined | null | LambdaEvent):
182
177
error : `Your function response must have a numerical statusCode. You gave: ${ inspect ( lambdaResponse . statusCode ) } ` ,
183
178
}
184
179
}
185
- if ( lambdaResponse . body && typeof lambdaResponse . body !== 'string' && ! isReadableStream ( lambdaResponse . body ) ) {
180
+ if ( lambdaResponse . body && typeof lambdaResponse . body !== 'string' && ! isReadable ( lambdaResponse . body ) ) {
186
181
return {
187
182
error : `Your function response must have a string or a stream body. You gave: ${ inspect ( lambdaResponse . body ) } ` ,
188
183
}
0 commit comments