Skip to content

feat(parser): allow parser set event type of handler with middy #2786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 22, 2024

Conversation

am29d
Copy link
Contributor

@am29d am29d commented Jul 19, 2024

Summary

This PR introduces type inference for event type of handler when using parser with middy middleware. Based on the combination of provided inputs (schema, envelope, safeParse) the type can change between a single object, an array (i.e. SqsEnvelope) and safeParse, where we wrap the result into ParsedResult. I have modified the unit tests to use the inference which should have an error, if the type inference breaks.

Changes

  • fixed return types to array for envelopes that return multiple items of provided schema objects
  • added ParseOutput to narrow down the type of the modified event
  • moved DynamoDBStreamEnvelopeResponse to types folder
  • replaced eslit comments with type casts in unit tests as mentioned in our docs

Please provide a summary of what's being changed

Please add the issue number below, if no issue is present the PR might get blocked and not be reviewed

Issue number: closes #2407


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@am29d am29d requested a review from a team July 19, 2024 14:12
@am29d am29d requested a review from a team as a code owner July 19, 2024 14:12
@boring-cyborg boring-cyborg bot added parser This item relates to the Parser Utility tests PRs that add or change tests labels Jul 19, 2024
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Jul 19, 2024
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Jul 19, 2024
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

Great work on these types, just left one minor comment about naming (& a suggestion to fix a typo).

Looking forward to merge it!

@am29d am29d requested a review from dreamorosi July 22, 2024 08:57
Copy link

Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

Thank you for this improvement!

@dreamorosi dreamorosi merged commit 9973f09 into main Jul 22, 2024
11 checks passed
@dreamorosi dreamorosi deleted the parser/type-inference branch July 22, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs that introduce new features or minor changes parser This item relates to the Parser Utility size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: allow parser set event type of handler with middy
2 participants