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

Add option to skip pipelines when parsing #164

Merged
merged 2 commits into from
Sep 17, 2023

Conversation

jonlambert
Copy link
Contributor

@jonlambert jonlambert commented Sep 16, 2023

Firstly, thanks for Valibot 😊 It's a great library and I'm excited to use it in projects moving forward!

Overview

When validating a value, it would be useful to be able to confirm the type of the object without throwing if the values don't pass formatting checks. Valibot could support that by accepting an option to skip all pipeline checks when parsing.

For example:

const schema = object({
  name: string(),
  email: string([email()]),
});

const initialValues: unknown = { name: '', email: '' };

parse(schema, initialValues); // will throw
parse(schema, initialValues, { skipPipes: true }); // won't throw

This could be really useful in circumstances such as initial form values, where we do care about the type of the values, but want to run formatting checks separately.

If I understand correctly, Valibot's rules for not transforming the data type inside pipelines means that this should work for any schema.

Alternatives

Users could maintain two schemas: one for the type-level checks, one for the formatting. But that would be additional overhead, and cause issues if their Valibot schema is auto-generated.

Notes

Please forgive me if this functionality already exists, or if I've overlooked a caveat here :) Also happy to rename the option too if another name is more appropriate.

@netlify
Copy link

netlify bot commented Sep 16, 2023

Deploy Preview for valibot ready!

Name Link
🔨 Latest commit 844cc85
🔍 Latest deploy log https://app.netlify.com/sites/valibot/deploys/650681fe66a4ec0008b9329b
😎 Deploy Preview https://deploy-preview-164--valibot.netlify.app/404
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@fabian-hiller
Copy link
Owner

Thank you for creating this PR. The idea is good. I'll check your code as soon as I find time and give you feedback then.

@fabian-hiller fabian-hiller self-assigned this Sep 16, 2023
@fabian-hiller fabian-hiller added enhancement New feature or request priority This has priority labels Sep 16, 2023
@fabian-hiller fabian-hiller merged commit f6660fe into fabian-hiller:main Sep 17, 2023
6 checks passed
@jonlambert
Copy link
Contributor Author

Thanks for your swift consideration, @fabian-hiller! Singular skipPipe is much better.

@fabian-hiller
Copy link
Owner

I also find skipPipes suitable. It was only important to me to make it consistent to abortPipeEarly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority This has priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants