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: Plans for alternative parser implementations #2431

Open
1 of 2 tasks
WtfJoke opened this issue Apr 24, 2024 · 5 comments
Open
1 of 2 tasks

Feature request: Plans for alternative parser implementations #2431

WtfJoke opened this issue Apr 24, 2024 · 5 comments
Labels
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

Comments

@WtfJoke
Copy link

WtfJoke commented Apr 24, 2024

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

Future readers

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

@WtfJoke WtfJoke 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 24, 2024
Copy link

boring-cyborg bot commented Apr 24, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@dreamorosi
Copy link
Contributor

Hi @WtfJoke thank you for taking the time to open an issue and for bringing up this topic.

We have considered the idea during development and like you said, the utility lends itself to a model where you could switch the underlying library. However to be frugal with time and pragmatic with efforts, we decided to go with Zod first.

For this first version we settled on Zod mainly because we thought it'd help a wider audience both as a reflection of its larger user base (8.7M downloads/week vs 142K downloads/week for valibot) and the time/effort investment that customers might have already put in creating schemas for it.

As secondary factors, we also took in account the fact that - like you mentioned - valibot is still not stable, and other AWS projects like Amplify have also adopted Zod.

Overall I think that if valibot becomes stable and Powertools customers ask for it, we could consider adding this capability in a future major version. Since we maintain a collection of schemas and envelopes for AWS events, this would require us doubling the maintenance for each provider we add, however as long as the Parser utility gains traction and there's significant customer demand, I don't think it's out of question.

I think we should leave the issue open so that people can express their interest.

@WtfJoke
Copy link
Author

WtfJoke commented Apr 24, 2024

Thanks for the insights! Totally understandable

@dreamorosi
Copy link
Contributor

As a side note, that doesn't in any way invalidate the ask, I also wanted to surface that Zod appears to be working on a v4 that should improve with tree shaking & bundle size. We are keeping an eye on the development and will consider adopting once it's out.

@dreamorosi dreamorosi added need-customer-feedback Requires more customers feedback before making or revisiting a decision revisit-in-3-months Blocked issues/PRs that need to be revisited and removed triage This item has not been triaged by a maintainer, please wait revisit-in-3-months Blocked issues/PRs that need to be revisited labels Apr 25, 2024
@fabian-hiller
Copy link

I am the creator of Valibot and happy to help and answer questions if you consider supporting Valibot. I expect to release a stable version within the next 2 or 3 months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
Projects
Development

No branches or pull requests

3 participants