Skip to content
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

feat(parser): DynamoDBMarshalled helper to parse DynamoDB data structure #3442

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

arnabrahman
Copy link
Contributor

Summary

When working with Amazon DynamoDB Stream events, the service sends the DynamoDB items in the database-specific format rather than regular JSON objects.

For example, a string might be represented as { "S": "foo" } rather than just foo. This makes parsing the actual changes within an event hard to parse and validate since it requires customers writing a Zod schema with this in mind.

This PR introduces a helper function DynamoDBMarshalled to work this structure

Changes

  • Helper function to unmarshall and validate dynamoDB stream schema
  • New helper function is exported to a subpath
  • Unit test the new helper function
  • Write up the docs for the new helper function

Issue number: #3194


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.

@boring-cyborg boring-cyborg bot added dependencies Changes that touch dependencies, e.g. Dependabot, etc. documentation Improvements or additions to documentation parser This item relates to the Parser Utility tests PRs that add or change tests labels Dec 23, 2024
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Dec 23, 2024
*/
const DynamoDBMarshalled = <T extends ZodTypeAny>(schema: T) =>
z
.record(z.string(), z.custom<AttributeValue>())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would appreciate suggestions on using this type.

Setting the type to unknown causes a TypeScript error. The @aws-sdk/util-dynamodb package has a peer dependency on @aws-sdk/client-dynamodb and we are using the AttributeValue type from @aws-sdk/client-dynamodb. Should we also declare @aws-sdk/client-dynamodb as a peer dependency?

Alternatively, we could set the type to unknown and suppress the TypeScript error using biome-ignore, though I would prefer to avoid this approach.

@arnabrahman arnabrahman marked this pull request as ready for review December 23, 2024 12:23
@arnabrahman arnabrahman requested review from a team as code owners December 23, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Changes that touch dependencies, e.g. Dependabot, etc. documentation Improvements or additions to documentation 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.

1 participant