Skip to content

Feature request: implement schema envelopes #1791

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

Closed
1 of 2 tasks
am29d opened this issue Nov 14, 2023 · 2 comments · Fixed by #1815
Closed
1 of 2 tasks

Feature request: implement schema envelopes #1791

am29d opened this issue Nov 14, 2023 · 2 comments · Fixed by #1815
Assignees
Labels
completed This item is complete and has been merged/shipped feature-request This item refers to a feature request for an existing or new utility parser This item relates to the Parser Utility

Comments

@am29d
Copy link
Contributor

am29d commented Nov 14, 2023

Use case

Similar to the python implementation we want to have reusable envelopes that we can extend with custom schema.

Solution/User Experience

Envelopes encapsulate the provided custom model in a built-in schema. This means that they parse specific part of the event detail for EventBridge or body for SQS.

const eventBridgeEnvelope = (<T extends ZodSchema>(data: unknown, schema: T) => {
  return schema.parse(EventBridgeSchema.parse(data).detail);
});

This will allow us to bring your own custom schema:

const customSchema = z.object({
  foo: z.string()
})

type CustomSchema = z.infer<typeof customSchema>;

const customEventBridgeEvent: CustomSchema = eventBridgeEnvelope({foo: 'bar'}, customSchema);

While is a one line, it'd be great to provide a bit more debug logs around both calls. It's worth emphasise that envelopes do not return schemas, but the parsed object of the custom schema.

Alternative solutions

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

@am29d am29d added triage This item has not been triaged by a maintainer, please wait feature-request This item refers to a feature request for an existing or new utility labels Nov 14, 2023
@am29d am29d added this to the Parser - Beta Release milestone Nov 14, 2023
@am29d am29d self-assigned this Nov 14, 2023
@am29d am29d added confirmed The scope is clear, ready for implementation parser This item relates to the Parser Utility and removed triage This item has not been triaged by a maintainer, please wait labels Nov 14, 2023
@am29d am29d moved this from Backlog to Working on it in Powertools for AWS Lambda (TypeScript) Dec 7, 2023
@am29d am29d linked a pull request Dec 21, 2023 that will close this issue
21 tasks
@am29d am29d closed this as completed Dec 21, 2023
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (TypeScript) Dec 21, 2023
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@dreamorosi dreamorosi added completed This item is complete and has been merged/shipped and removed confirmed The scope is clear, ready for implementation labels Jan 26, 2024
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Jan 26, 2024
@dreamorosi
Copy link
Contributor

This is now released under v2.1.0 version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed This item is complete and has been merged/shipped feature-request This item refers to a feature request for an existing or new utility parser This item relates to the Parser Utility
Projects
Development

Successfully merging a pull request may close this issue.

2 participants