8000 refactor(Form)!: drop explicit support for `zod` and `valibot` by romhml Β· Pull Request #3618 Β· nuxt/ui Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor(Form)!: drop explicit support for zod and valibot #3618

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

Merged
merged 3 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/components/content/examples/FormExampleValibot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function onSubmit(event: FormSubmitEvent<Schema>) {
</script>

<template>
<UForm :schema="v.safeParser(schema)" :state="state" class="space-y-4" @submit="onSubmit">
<UForm :schema="schema" :state="state" class="space-y-4" @submit="onSubmit">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" /& 8000 gt;
</UFormGroup>
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.components/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It works with the [FormGroup](/components/form-group) component to display error

The form component requires two props:
- `state` - a reactive object holding the form's state.
- `schema` - a schema object from a validation library like [Yup](https://github.com/jquense/yup), [Zod](https://github.com/colinhacks/zod), [Joi](https://github.com/hapijs/joi), [Valibot](https://github.com/fabian-hiller/valibot) or [Superstruct](https://github.com/ianstormtaylor/superstruct).
- `schema` - any [Standard Schema](https://standardschema.dev/) or a schema from [Yup](https://github.com/jquense/yup), [Joi](https://github.com/hapijs/joi) or [Superstruct](https://github.com/ianstormtaylor/superstruct).

::callout{icon="i-heroicons-light-bulb"}
Note that **no validation library is included** by default, so ensure you **install the one you need**.
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"prettier": "^3.5.3",
"ufo": "^1.5.4",
"v-calendar": "^3.1.2",
"valibot": "^0.42.1",
"valibot": "^1.0.0",
"yup": "^1.6.1",
"zod": "^3.24.2"
}
Expand Down
4 changes: 1 addition & 3 deletions package.json
@@ -69,9 +69,7 @@
Original file line number Diff line number Diff line change
Expand Up
"release-it": "^18.1.2",
"superstruct": "^2.0.2",
"typescript": "^5.6.3",
"valibot": "^0.42.1",
"valibot30": "npm:valibot@0.30.0",
"valibot31": "npm:valibot@0.31.0",
"valibot": "^1.0.0",
"vitest": "^3.0.9",
"vitest-environment-nuxt": "^1.0.1",
"vue-tsc": "^2.1.10",
Expand Down
30 changes: 7 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
"lockFileMaintenance": {
"enabled": true
},
"ignoreDeps": [
"valibot30",
"valibot31"
],
"baseBranches": ["v2", "v3"],
"packageRules": [{
"matchBaseBranches": ["v3"],
Expand Down
76 changes: 2 additions & 74 deletions src/runtime/components/forms/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
<script lang="ts">
import { provide, ref, type PropType, defineComponent, onUnmounted, onMounted, readonly } from 'vue'
import { useEventBus } from '@vueuse/core'
import type { ZodSchema } from 'zod'
import type { ValidationError as JoiError, Schema as JoiSchema } from 'joi'
import type { ObjectSchema as YupObjectSchema, ValidationError as YupError } from 'yup'
import type { BaseSchema as ValibotSchema30, BaseSchemaAsync as ValibotSchemaAsync30 } from 'valibot30'
import type { GenericSchema as ValibotSchema31, GenericSchemaAsync as ValibotSchemaAsync31, SafeParser as ValibotSafeParser31, SafeParserAsync as ValibotSafeParserAsync31 } from 'valibot31'
import type { GenericSchema as ValibotSchema, GenericSchemaAsync as ValibotSchemaAsync, SafeParser as ValibotSafeParser, SafeParserAsync as ValibotSafeParserAsync } from 'valibot'
import type { StandardSchemaV1 } from '@standard-schema/spec'
import type { Struct } from 'superstruct'
import type { FormError, FormEvent, FormEventType, FormSubmitEvent, FormErrorEvent, Form, ValidateReturnSchema } from '../../types/form'
Expand All @@ -26,15 +22,10 @@ class FormException extends Error {
}
}

type Schema = PropType<ZodSchema>
type Schema = PropType<StandardSchemaV1>
| PropType<YupObjectSchema<any>>
| PropType<Struct<any, any>>
| PropType<JoiSchema>
| PropType<ValibotSchema30 | ValibotSchemaAsync30>
| PropType<ValibotSchema31 | ValibotSchemaAsync31>
| PropType<ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any>>
| PropType<ValibotSchema | ValibotSchemaAsync>
| PropType<ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any>> | PropType<Struct<any, any>>
| PropType<StandardSchemaV1>

export default defineComponent({
props: {
Expand Down Expand Up @@ -214,14 +205,6 @@ function isJoiError(error: any): error is JoiError {
return error.isJoi === true
}

function isValibotSchema(schema: any): schema is ValibotSchema30 | ValibotSchemaAsync30 | ValibotSchema31 | ValibotSchemaAsync31 | ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any> | ValibotSchema | ValibotSchemaAsync | ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any> {
return '_parse' in schema || '_run' in schema || (typeof schema === 'function' && 'schema' in schema)
}

function isZodSchema(schema: any): schema is ZodSchema {
return schema.parse !== undefined
}

export function isStandardSchema(schema: any): schema is StandardSchemaV1 {
return '~standard' in schema
}
Expand Down Expand Up @@ -251,35 +234,6 @@ export async function validateStandardSchema(
}
}

async function validateValibotSchema(
state: any,
schema: ValibotSchema30 | ValibotSchemaAsync30 | 6D40 ValibotSchema31 | ValibotSchemaAsync31 | ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any> | ValibotSchema | ValibotSchemaAsync | ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any>
): Promise<ValidateReturnSchema<typeof state>> {
const result = await ('_parse' in schema ? schema._parse(state) : '_run' in schema ? schema._run({ typed: false, value: state }, {}) : schema(state))

if (!result.issues || result.issues.length === 0) {
const output = ('output' in result
? result.output
: 'value' in result
? result.value
: null)
return {
errors: null,
result: output
}
}

const errors = result.issues.map(issue => ({
path: issue.path?.map(item => item.key).join('.') || '',
message: issue.message
}))

return {
errors,
result: null
}
}

async function validateJoiSchema(
state: any,
schema: JoiSchema
Expand Down Expand Up @@ -307,28 +261,6 @@ async function validateJoiSchema(
}
}

async function validateZodSchema(
state: any,
schema: ZodSchema
): Promise<ValidateReturnSchema<typeof state>> {
const result = await schema.safeParseAsync(state)
if (result.success === false) {
const errors = result.error.issues.map(issue => ({
path: issue.path.join('.'),
message: issue.message
}))

return {
errors,
result: null
}
}
return {
result: result.data,
errors: null
}
}

async function validateSuperstructSchema(state: any, schema: Struct<any, any>): Promise<ValidateReturnSchema<typeof state>> {
const [err, result] = schema.validate(state)
if (err) {
Expand Down Expand Up @@ -379,12 +311,8 @@ async function validateYupSchema(
function parseSchema(state: any, schema: Schema): Promise<ValidateReturnSchema<typeof state>> {
if (isStandardSchema(schema)) {
return validateStandardSchema(state, schema)
} else if (isZodSchema(schema)) {
return validateZodSchema(state, schema)
} else if (isJoiSchema(schema)) {
return validateJoiSchema(state, schema)
} else if (isValibotSchema(schema)) {
return validateValibotSchema(state, schema)
} else if (isYupSchema(schema)) {
return validateYupSchema(state, schema)
} else if (isSuperStructSchema(schema)) {
Expand Down
Loading
0