-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Allow for different validator libraries #120
Comments
Hi, this question has come up a couple of times, and it's hard to find a library with the requirements needed for Superforms to work properly. The biggest issue with most other libraries is that you cannot introspect the schema nowhere near Zod's level. For example, I'm able to extract at runtime every little aspect of the schema, generating constraints based on min/max values, regexps, nullable/optional, etc. Also, the default values must be extractable, so correct types can be generated for empty schemas.
Because of side effects in schemas (refine/superRefine that sets a custom path), per-field validation is not an issue anymore. The whole schema must always be validated to know the final result. I've searched around plenty to be able to make an informed decision about this, and haven't been able to find a library except for Zod that satisfies these requirements. So this won't happen for the upcoming 1.0 release, but maybe 2.0 could do it, if there is some clever way of doing "progressive enhancement" for the data returned from |
For V2, I guess the starting point would be to define the Fortunately, I am in early stages with my @effect/schema impl, so I might just use Zod. |
I'd like to use https://github.com/typestack/class-validator (huntabyte/shadcn-svelte#497) and not be tied to zod. This is preventing me from using this library :(. |
Good thing then that v2 is underway: https://blog.encodeart.dev/superforms-v2-supporting-all-validation-libraries Also, being able to export the validators from the library as JSON Schema is pretty much required, otherwise you'll have to do the heavy lifting with default values and constraints yourself. |
Will the work in V2 also make it easier to define dynamically-optional fields, without requiring separate schemas for each permutation of a complex form? That's still a concern for some of us with this lib. |
Dynamic behavior is a bit tricky with a compile time-defined schema. You can already now swap the schema for any other, it's just that typescript will complain about the schema type that you defined in the first call to |
I'm talking about what was discussed in issue #282. Maintaining separate schemas for geometric permutations of a single form that can have different valid fields based on the values of other fields is just painful, and not necessary with other libraries. Regardless of how difficult that is to handle the way Superforms is architected, libs architected differently (though they don't hook specifically into SK) are superior in this case. |
Superforms v2 will at least have union support, but since I don't know the details about your case, I can't say more than that. Good thing there are superior solutions out there, at least. |
My case is basically any case where user input can modify field validations in a way that may be easily specified in a single schema (which is usually accomplished using a |
What can I say. With OSS, you pay with your time. Superforms doesn't force you to go fully type-safe, since any schema can be used to validate the data, it's just typescript that will complain. The validation will work either way. But it looks like v2 will handle unions properly. |
That project doesn't seem like it is actively maintained. |
I'm sure anyone ("someone else") can contribute with maintenance. |
This one is ready for testing, migration guide at: https://superforms.rocks/migration-v2/ |
Finally time to close this. Arktype, Joi, TypeBox, Valibot, Yup and Zod are all working. |
Thanks for opening up the library for additional validation libs ! |
There's a problem with the moduleResolution for it: ianstormtaylor/superstruct#1200 |
Is your feature request related to a problem? Please describe.
Many parts of the web ecosystem allow for different pluggable technologies.
For example, Prisma, tRPC and Felte allow for different, 'typesafe' validator implementations
I have a couple of projects using superstruct, and a couple using Zod, and am starting one with @effect/schema.
I've used Felte a bit, and it's reasonable, however I really like the look of Superforms.
Describe the solution you'd like
Allow for use of other validators (eg, yup, superstruct, joi, validator.js, @effect/schema) etc
Describe alternatives you've considered
The alternatives are
The text was updated successfully, but these errors were encountered: