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

Feature request: implement parser decorator #1816

Closed
1 of 2 tasks
am29d opened this issue Dec 12, 2023 · 2 comments · Fixed by #1831
Closed
1 of 2 tasks

Feature request: implement parser decorator #1816

am29d opened this issue Dec 12, 2023 · 2 comments · Fixed by #1831
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 Dec 12, 2023

Use case

Similar to middy middleware we want to use build-in schemas and envelopes to parse and extract events using decorators.

Solution/User Experience

Based on the RFC the decorator should take model and envelope as an param object:

const order = z.object({
  id: z.number(),
  description: z.string(),
});

type Order = z.infer<typeof order>;

class Lambda implements LambdaInterface {
  // Decorate your handler class method
  @logger.injectLambdaContext()
  @parser({eventBridgeEnvelope, order})
  public async handler(
    _event: OrderModel,
    _context: Context
  ): Promise<void> {
    logger.info(`Received order model ${_event}`);
  }
}

we should also be able to pass only the model, which can be a custom event or an extension of the built-in schema i.e.

const order = z.object({
  id: z.number(),
  description: z.string(),
});

const customEBschema = EventBridgeSchema.extend({
  detail: order,
});

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 Dec 12, 2023
@am29d am29d added this to the Parser - Beta Release milestone Dec 12, 2023
@am29d am29d self-assigned this Dec 12, 2023
@am29d am29d added parser This item relates to the Parser Utility and removed triage This item has not been triaged by a maintainer, please wait labels Dec 12, 2023
@am29d am29d changed the title Feature request: implement eventParser decorator Feature request: implement parser decorator Dec 21, 2023
@am29d am29d linked a pull request Dec 21, 2023 that will close this issue
9 tasks
@dreamorosi dreamorosi added the completed This item is complete and has been merged/shipped label Dec 22, 2023
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (TypeScript) Dec 22, 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 moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Feb 10, 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