Skip to content

Commit ee37362

Browse files
authored
refactor(Form)!: drop explicit support for zod and valibot (#3618)
1 parent 63b5f2b commit ee37362

File tree

7 files changed

+13
-107
lines changed

7 files changed

+13
-107
lines changed

docs/components/content/examples/FormExampleValibot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function onSubmit(event: FormSubmitEvent<Schema>) {
2121
</script>
2222

2323
<template>
24-
<UForm :schema="v.safeParser(schema)" :state="state" class="space-y-4" @submit="onSubmit">
24+
<UForm :schema="schema" :state="state" class="space-y-4" @submit="onSubmit">
2525
<UFormGroup label="Email" name="email">
2626
<UInput v-model="state.email" />
2727
</UFormGroup>

docs/content/2.components/form.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ It works with the [FormGroup](/components/form-group) component to display error
1414

1515
The form component requires two props:
1616
- `state` - a reactive object holding the form's state.
17-
- `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).
17+
- `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).
1818

1919
::callout{icon="i-heroicons-light-bulb"}
2020
Note that **no validation library is included** by default, so ensure you **install the one you need**.

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"prettier": "^3.5.3",
2525
"ufo": "^1.5.4",
2626
"v-calendar": "^3.1.2",
27-
"valibot": "^0.42.1",
27+
"valibot": "^1.0.0",
2828
"yup": "^1.6.1",
2929
"zod": "^3.24.2"
3030
}

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@
6969
"release-it": "^18.1.2",
7070
"superstruct": "^2.0.2",
7171
"typescript": "^5.6.3",
72-
"valibot": "^0.42.1",
73-
"valibot30": "npm:valibot@0.30.0",
74-
"valibot31": "npm:valibot@0.31.0",
72+
"valibot": "^1.0.0",
7573
"vitest": "^3.0.9",
7674
"vitest-environment-nuxt": "^1.0.1",
7775
"vue-tsc": "^2.1.10",

pnpm-lock.yaml

Lines changed: 7 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

renovate.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
"lockFileMaintenance": {
66
"enabled": true
77
},
8-
"ignoreDeps": [
9-
"valibot30",
10-
"valibot31"
11-
],
128
"baseBranches": ["v2", "v3"],
139
"packageRules": [{
1410
"matchBaseBranches": ["v3"],

src/runtime/components/forms/Form.vue

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
<script lang="ts">
88
import { provide, ref, type PropType, defineComponent, onUnmounted, onMounted, readonly } from 'vue'
99
import { useEventBus } from '@vueuse/core'
10-
import type { ZodSchema } from 'zod'
1110
import type { ValidationError as JoiError, Schema as JoiSchema } from 'joi'
1211
import type { ObjectSchema as YupObjectSchema, ValidationError as YupError } from 'yup'
13-
import type { BaseSchema as ValibotSchema30, BaseSchemaAsync as ValibotSchemaAsync30 } from 'valibot30'
14-
import type { GenericSchema as ValibotSchema31, GenericSchemaAsync as ValibotSchemaAsync31, SafeParser as ValibotSafeParser31, SafeParserAsync as ValibotSafeParserAsync31 } from 'valibot31'
15-
import type { GenericSchema as ValibotSchema, GenericSchemaAsync as ValibotSchemaAsync, SafeParser as ValibotSafeParser, SafeParserAsync as ValibotSafeParserAsync } from 'valibot'
1612
import type { StandardSchemaV1 } from '@standard-schema/spec'
1713
import type { Struct } from 'superstruct'
1814
import type { FormError, FormEvent, FormEventType, FormSubmitEvent, FormErrorEvent, Form, ValidateReturnSchema } from '../../types/form'
@@ -26,15 +22,10 @@ class FormException extends Error {
2622
}
2723
}
2824
29-
type Schema = PropType<ZodSchema>
25+
type Schema = PropType<StandardSchemaV1>
3026
| PropType<YupObjectSchema<any>>
27+
| PropType<Struct<any, any>>
3128
| PropType<JoiSchema>
32-
| PropType<ValibotSchema30 | ValibotSchemaAsync30>
33-
| PropType<ValibotSchema31 | ValibotSchemaAsync31>
34-
| PropType<ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any>>
35-
| PropType<ValibotSchema | ValibotSchemaAsync>
36-
| PropType<ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any>> | PropType<Struct<any, any>>
37-
| PropType<StandardSchemaV1>
3829
3930
export default defineComponent({
4031
props: {
@@ -214,14 +205,6 @@ function isJoiError(error: any): error is JoiError {
214205
return error.isJoi === true
215206
}
216207
217-
function isValibotSchema(schema: any): schema is ValibotSchema30 | ValibotSchemaAsync30 | ValibotSchema31 | ValibotSchemaAsync31 | ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any> | ValibotSchema | ValibotSchemaAsync | ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any> {
218-
return '_parse' in schema || '_run' in schema || (typeof schema === 'function' && 'schema' in schema)
219-
}
220-
221-
function isZodSchema(schema: any): schema is ZodSchema {
222-
return schema.parse !== undefined
223-
}
224-
225208
export function isStandardSchema(schema: any): schema is StandardSchemaV1 {
226209
return '~standard' in schema
227210
}
@@ -251,35 +234,6 @@ export async function validateStandardSchema(
251234
}
252235
}
253236
254-
async function validateValibotSchema(
255-
state: any,
256-
schema: ValibotSchema30 | ValibotSchemaAsync30 | ValibotSchema31 | ValibotSchemaAsync31 | ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any> | ValibotSchema | ValibotSchemaAsync | ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any>
257-
): Promise<ValidateReturnSchema<typeof state>> {
258-
const result = await ('_parse' in schema ? schema._parse(state) : '_run' in schema ? schema._run({ typed: false, value: state }, {}) : schema(state))
259-
260-
if (!result.issues || result.issues.length === 0) {
261-
const output = ('output' in result
262-
? result.output
263-
: 'value' in result
264-
? result.value
265-
: null)
266-
return {
267-
errors: null,
268-
result: output
269-
}
270-
}
271-
272-
const errors = result.issues.map(issue => ({
273-
path: issue.path?.map(item => item.key).join('.') || '',
274-
message: issue.message
275-
}))
276-
277-
return {
278-
errors,
279-
result: null
280-
}
281-
}
282-
283237
async function validateJoiSchema(
284238
state: any,
285239
schema: JoiSchema
@@ -307,28 +261,6 @@ async function validateJoiSchema(
307261
}
308262
}
309263
310-
async function validateZodSchema(
311-
state: any,
312-
schema: ZodSchema
313-
): Promise<ValidateReturnSchema<typeof state>> {
314-
const result = await schema.safeParseAsync(state)
315-
if (result.success === false) {
316-
const errors = result.error.issues.map(issue => ({
317-
path: issue.path.join('.'),
318-
message: issue.message
319-
}))
320-
321-
return {
322-
errors,
323-
result: null
324-
}
325-
}
326-
return {
327-
result: result.data,
328-
errors: null
329-
}
330-
}
331-
332264
async function validateSuperstructSchema(state: any, schema: Struct<any, any>): Promise<ValidateReturnSchema<typeof state>> {
333265
const [err, result] = schema.validate(state)
334266
if (err) {
@@ -379,12 +311,8 @@ async function validateYupSchema(
379311
function parseSchema(state: any, schema: Schema): Promise<ValidateReturnSchema<typeof state>> {
380312
if (isStandardSchema(schema)) {
381313
return validateStandardSchema(state, schema)
382-
} else if (isZodSchema(schema)) {
383-
return validateZodSchema(state, schema)
384314
} else if (isJoiSchema(schema)) {
385315
return validateJoiSchema(state, schema)
386-
} else if (isValibotSchema(schema)) {
387-
return validateValibotSchema(state, schema)
388316
} else if (isYupSchema(schema)) {
389317
return validateYupSchema(state, schema)
390318
} else if (isSuperStructSchema(schema)) {

0 commit comments

Comments
 (0)