Skip to content

Feature request: support for parseAsync in zod parsing #3843

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

Open
1 of 2 tasks
cbarlow1993 opened this issue Apr 17, 2025 · 1 comment
Open
1 of 2 tasks

Feature request: support for parseAsync in zod parsing #3843

cbarlow1993 opened this issue Apr 17, 2025 · 1 comment
Labels
discussing The issue needs to be discussed, elaborated, or refined feature-request This item refers to a feature request for an existing or new utility need-customer-feedback Requires more customers feedback before making or revisiting a decision parser This item relates to the Parser Utility

Comments

@cbarlow1993
Copy link

cbarlow1993 commented Apr 17, 2025

Use case

I have several schemas that will attempt to look up values against the database during validation, however these async superRefines are not compatible with this parser as they require parseAsync.

Solution/User Experience

Possibly something along the lines of:

import { asyncParser } from "@aws-lambda-powertools/parser/middleware";
import { APIGatewayProxyEventV2Schema } from "@aws-lambda-powertools/parser/schemas";



const schema =
  APIGatewayProxyEventV2Schema.extend({
    pathParameters: z.obiect({param: z.string()}),
    body: JSONStringified(z.object({ recordId: z.string() }),
  }).superRefine(async (data, ctx) => {
     try {
         const checkRecordExists = await dynamoRead(data.body.recordId)
     } catch (err) {
          ctx.addIssue({
            code: z.ZodIssueCode.custom,
            message:
              "Cannot create data with invalid record type",
          });
     }
}

.use(asyncParser({ schema }))

Alternative solutions

Acknowledgment

Future readers

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

@cbarlow1993 cbarlow1993 added feature-request This item refers to a feature request for an existing or new utility triage This item has not been triaged by a maintainer, please wait labels Apr 17, 2025
@dreamorosi dreamorosi added need-customer-feedback Requires more customers feedback before making or revisiting a decision discussing The issue needs to be discussed, elaborated, or refined parser This item relates to the Parser Utility and removed triage This item has not been triaged by a maintainer, please wait labels Apr 18, 2025
@dreamorosi
Copy link
Contributor

Hi @cbarlow1993, thank you for opening this issue.

Before making a decision on this feature I'd like to finalize our plans for what is discussed in #2431. At the moment we only support Zod as parser library, but with the launch of standard schema we have been considering expanding support to other libraries.

I am unsure whether standard schema supports asynchronous parsing or if it's a Zod-specific feature. It's also still unclear if standard schema will fit our needs, so before making a decision around adding parseAsync from Zod I'd like us to consider these points.

To be completely transparent, this is most likely not something I expect we'll resolve in the next quarter, since we have other items already on our roadmap with more priority.

With that said, I'd encourage anyone stumbling on this issue and who's interested in seeing this added to add a 👍 to the original comment above, so we can continue monitoring demand and potentially adjust our plans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussing The issue needs to be discussed, elaborated, or refined feature-request This item refers to a feature request for an existing or new utility need-customer-feedback Requires more customers feedback before making or revisiting a decision parser This item relates to the Parser Utility
Projects
Development

No branches or pull requests

2 participants