-
Notifications
You must be signed in to change notification settings - Fork 154
fix(parser): DynamoDBStream schema & envelope #3482
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR, thanks for the work bringing the unmarschalling into envelope and schema!
Just a minor code duplication we'd need to fix, otherwise ready to go.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful!
Summary
Changes
This PR updates the logic of the
DynamoDBStreamSchema
andDynamoDBStreamEnvelope
built-in schemas so that they automatically handle DynamoDB attribute values for the customer and convert them to JavaScript native objects during the parsing and validation.As part of the PR, I have also improved the error messages in the parser to include the index of the record being processed as well as the full path of the issue when parsing fails. For example, now the error would be something like:
and like this for failed parsing of
Keys
,NewImage
, andOldImage
:Likewise, when parsing an envelope using
safeParse
, the errors can also be combined when multiple records have issues:Note that in all cases the full path of the object is preserved even though we are performing multiple Zod validations under the hood.
While working on this PR, I also brought into the
commons
package an implementation of the unmarshall function inspired by the one in the AWS SDK. This is similar to what Powertools for AWS Lambda (Python) does, and allows us to provide this behavior without forcing an extra dependency. Our implementation also differs from the reference one in a couple minor ways since we don't have to support old Node.js versions.This new behavior is compatible with the
DynamoDBHelper
introduced in the previous release. This is because in order for customers to use the helper they will have to extend & replace the schema, thus bypassing the transform introduced in this PR.Finally, we're treating this change as a fix because this should've been the default behavior all along.
Issue number: fixes #3481
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.