Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feature: Parser Middleware
Example:
Why another package?
This parser package and the validator package are very similar. But, teams already using Zod for other parsing or who don't want to use JSON-schema for validation, might want an alternative. AWS Powertools, for example, is considering separate RFCs for a validator and a parser (aws-powertools/powertools-lambda-typescript#1334). The main thing, though, is providing a more lightweight and intuitive way to do parsing and validation, while getting good type inference. Also, JSON-schema is a completely valid way to solve the problem, hence this parser package is just another option depending on user preference.
Error handling
The error handling in this package differs slightly from the existing validator package. The reason for this is I have run into the need in projects to customize the error: from the status code to the message. The
createErrorFunc
option gives full control over the error creation, so users can make the middleware easily fit their requirements. This also means the package doesn't need to have any responsibility for i18n, since the user can handle that in the error creation.Performance
Based on the benchmark tests, the validator package does seem to be much more performant. Zod has made improvements in performance, but there is still room to improve there. See colinhacks/zod#205
Note:
totally understand if you choose not to accept this package into Middy and prefer to keep as a community package