Description
Use case
We currently heavily use zod in our projects. The new Parser (Zod) utility could help us (since we validated most of them manually).
Since we have use a lot of single purpose lambdas, we try to keep our lambda bundle size low. We noticed that zod takes a good part of that, because their api (as great as it is :D) its not well suited for tree shakability (see colinhacks/zod#2596). We made some experiments in the past with alternatives like valibot.
While I can understand why you choose zod (I would have too, in your situation :D), are there any plans to support other Schema Validation Libraries like valibot in this case? Im curious about your plans :)
It feels like the Parser Utility could support multiple schema libraries like the Parameters Utility supports Secrets-Manager and Parameter Sotre.
I am aware of, that you care about bundle size as well, so it seems like a good fit :)
I'm also aware that valibot hasnt reached 1.0 and has most likely a breaking api change (see fabian-hiller/valibot#502)
P.S: If you think that idea is better suited in a discussion, I can close this issue.
Solution/User Experience
I just adapted the example of the readme (it probably doesn't compile, just to get the idea)
import type { Context } from 'aws-lambda';
import { isoTimestamp, object, parse, string, type Output } from "valibot";
import middy from '@middy/core';
const TimestampSchema = object({
timestamp: string([isoTimestamp()]),
});
type Timestamp = Output<typeof TimestampSchema>;
const lambdaHandler = async (
event: Timestamp,
_context: Context
): Promise<void> => {
console.log('Processing event', {event});
};
export const handler = middy(lambdaHandler).use(
parser({ schema: TimestampSchema })
);
Alternative solutions
Alternative parsers:
- https://github.com/hapijs/joi
- https://github.com/ajv-validator/ajv
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status