Skip to content

Comments

feat: make event type generic in RequestHandler#18

Merged
astuyve merged 7 commits intoastuyve:mainfrom
sgarner:arbitrary-event
Mar 26, 2025
Merged

feat: make event type generic in RequestHandler#18
astuyve merged 7 commits intoastuyve:mainfrom
sgarner:arbitrary-event

Conversation

@sgarner
Copy link
Contributor

@sgarner sgarner commented Oct 10, 2024

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

@jm42
Copy link

jm42 commented Mar 26, 2025

This is nice.

@sgarner
Copy link
Contributor Author

sgarner commented Mar 26, 2025

Looks like I forgot to mention @astuyve to request review!

src/index.ts Outdated
Comment on lines 16 to 17
TEvent = APIGatewayProxyEventV2,
TResult = void
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TEvent = APIGatewayProxyEventV2,
TResult = void
TEvent = LambdaFunctionURLEvent,
TResult = LambdaFunctionURLResult

@astuyve
Copy link
Owner

astuyve commented Mar 26, 2025

Thanks for the PR @sgarner – I think @jm42 is right and we should switch the event/result types here to use FURLs but that's a discussion I think you two can decide.

Just let me know and I'll merge and release it

@sgarner
Copy link
Contributor Author

sgarner commented Mar 26, 2025

Yes, fair enough. Note I had to update @types/aws-lambda to bring in the new type alias.

Ready for review again @astuyve

@astuyve
Copy link
Owner

astuyve commented Mar 26, 2025

LGTM, thanks!

@astuyve astuyve merged commit 4af7689 into astuyve:main Mar 26, 2025
@sgarner sgarner deleted the arbitrary-event branch March 26, 2025 20:49
@astuyve
Copy link
Owner

astuyve commented Mar 26, 2025

Released in 0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

event should support IAM authorized API Gateway event

3 participants