Comments (10)
Ok, glad to know that it's in the back of your head for the future! I hope it is doable, as said the alternative is to make a schema standard, so introspection can be made independent of library, and adapters for each library to transform the schema to the library-specific one.
from valibot.
Hey, with Modular Forms, my own form library, I had decided to rely on adapters for schema validation. This makes it theoretically possible to connect any validations library. This approach also has the smallest footprint in bundle size, as only the adapter that is used ends up in the bundle. The adapter basically only maps the errors into a uniform structure for the form library.
For example, here is the code of the valiForm
adapter: https://github.com/fabian-hiller/modular-forms/blob/main/packages/react/src/adapters/valiForm.ts
from valibot.
That looks like the approach that typeschema is taking, which works in the relatively simple case of schema validation - error mapping. But schema introspection, its requirements and specification, goes beyond that. It needs to be supported by the library, since we build the schemas directly in them.
This per-library DSL causes the fragmentation I'm mentioning in the typeschema issue. So either an agnostic schema definition must be used, which can be adapted or directly supported by each library, or a validation library must support introspection according to some specification. I'm hoping for the latter, since the schema definition belongs to the library.
Given the number of JS validation libraries it's obviously quite easy (or maybe fun, challenging, interesting enough) to create one and deploy it into the wild, but it also should assume some responsibility regarding the above. Otherwise, Zod is the only option I have for Superforms.
from valibot.
I haven't quite understood why the approach I use with Modular Forms doesn't work for Superforms. Modular Forms supports Zod and Valibot in this way and allows you to connect any other library. Maybe you can make a code example.
I know that React Hook Form uses resolvers
, which is probably the same as Modular Forms under a different name.
from valibot.
Here you can find a code example with Modular Forms: https://modularforms.dev/react/guides/validate-your-fields#schema-validation
In fact, with Qwik this approach works so well that the same scheme can be used for validation in the browser and on the server, and everything works even if JavaScript is disabled in the browser: https://modularforms.dev/qwik/guides/enhanced-forms
from valibot.
It works, but that's just the validation itself - a rather simple interface that typeschema is unifying for many other libraries as well. But since every validation library also locks consumers into their DSL (the schema definition), the need for introspecting this schema becomes important when you're using it in form validation, for example. This is what I'm discussing here: decs/typeschema#9
Is there any schema introspection available for Valibot that covers these cases?
from valibot.
I have read through your posts and understand what you mean. No, this approach is currently not possible with Valibot. This is due to the fact that a schema in Valibot is composed of different functions and Valibot does not collect validation information about them in advance.
However, I believe it would be technically possible. However, it would increase the bundle size and make the source code more complex. Currently I don't know if this is a functionality I want to support with Valibot. However, I am keeping it in mind as this functionality would also allow serializing a schema in JSON.
from valibot.
Issue is related to: #23
from valibot.
Hey 👋 I think when #211 is merged Valibot will support the functionality you asked for.
from valibot.
v0.21.0 is now available. Presumably not everything is perfect yet. So please let us know if you have any ideas for improvements.
from valibot.
Related Issues (20)
- [Proposal] Considering Biome for formating and linting HOT 1
- Branded schema doesn't provide the type guard thru the `is`. HOT 2
- Add CIDR Schema Type HOT 3
- Reporting of Errors (ValiError Format compared with ZodError Format) HOT 3
- Nullable, how can i do
- isoTimestamp only supports decimal fraction up to 3 digits HOT 8
- Cannot use `brand` with `url` or `email` HOT 1
- Document minimum typescript version HOT 7
- Nextjs build Failed HOT 6
- How can I define a schema so that it can be validated as a function? HOT 1
- getDefaults returns undefined for optional with a default of empty string or false HOT 2
- The validation of the object is not rigorous enough HOT 3
- Optional Objects with Literal Fields and Raw Default Result in "| undefined" Type HOT 1
- union(): Union wrong behavior when type validation pass HOT 2
- A GPT companion for the Zod to Valibot conversion HOT 1
- `union()` of object with overlapping field drops other fields HOT 4
- Supporte Metadata like description
- Support non-string array in `picklist` HOT 4
- customAsync not resolved inside issues? HOT 4
- Change omit() parameter type to `readonly TKeys[]` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from valibot.