Skip to content

Feature request: support for parseAsync in zod parsing #3843

Open
@cbarlow1993

Description

@cbarlow1993

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussingThe issue needs to be discussed, elaborated, or refinedfeature-requestThis item refers to a feature request for an existing or new utilityneed-customer-feedbackRequires more customers feedback before making or revisiting a decisionparserThis item relates to the Parser Utility

    Type

    No type

    Projects

    Status

    Ideas

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions