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

v3: valibot instead of zod via adapter? #3063

Open
chrisjansky opened this issue Jan 30, 2025 · 2 comments
Open

v3: valibot instead of zod via adapter? #3063

chrisjansky opened this issue Jan 30, 2025 · 2 comments
Labels
enhancement New feature or request v3

Comments

@chrisjansky
Copy link

Hello,

It would be amazing to have the option of defining a custom validator instead of zod only – seems a very opionated assumption that everyone is using zod. We have migrated to valibot as (purely subjective) we deem it better, more lightweight and flexible.

Validators are purely matter of taste, so please consider making the schema property of data collections more generic, perhaps accept an object that can be generated from different sources or introduce an adapter that transforms to the necessary format?

Thank you for considering 🌈

@chrisjansky chrisjansky added the enhancement New feature or request label Jan 30, 2025
@farnabaz farnabaz added the v3 label Jan 31, 2025
@farnabaz
Copy link
Member

Thanks for raising the concern.

Also, changing the validator library is not planned yet, but we are checking for ways to improve the validation in Nuxt Content. We might leverage https://standardschema.dev/ for generic validation, which unlocks the possibility of using different validation libraries.

But still Nuxt Content uses schema for other purposes, like generating database structure and this might be one of the blockers for supporting different libraries.

@chrisjansky
Copy link
Author

Thanks for the reply @farnabaz. Yes, https://standardschema.dev/ sounds like an ideal solution to allow different validators.

We already have an extensive set of complex Typescript types and maintaining a duplicate set of those via zod would be quite the headache.

As a workaround I am casting the query result to a certain type, I suppose that’s the easiest fix for that for now?

const queryPath = `/foo/bar`

// Can be either .json or .md
const { data } = await useAsyncData(queryPath, () => queryCollection("foo").path(queryPath).all())
// Filter .json files
const json = (data.value?.find((c) => c.extension === "json")?.body || {}) as FooType

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

No branches or pull requests

2 participants