astuyve / lambda-stream

Implements AWS Lambda Response Streaming in TypeScript for local development and testing
84 stars 10 forks source link

feat: make `event` type generic in RequestHandler #18

Open sgarner opened 1 month ago

sgarner commented 1 month ago

This PR adds generic type arguments to streamifyResponse, so that handlers with different event types can be used (not only APIGatewayProxyEventV2).

The event payload for a Lambda function can have different types depending on how the function is called. When a function is called using the Invoke API, it could be an entirely arbitrary object.

I've also renamed RequestHandler to StreamingHandler. This seems more correct to me since an invocation is not necessarily the same as an HTTP request, and is more in line with the naming of the Handler type in @types/aws-lambda. An exported type alias of RequestHandler = StreamingHandler<APIGatewayProxyEventV2> is provided for backwards compatibility.

Fixes #16