From 256d8cf76226d68205c308ec79e449510fcffa98 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Sun, 3 Dec 2023 07:24:20 -0800 Subject: [PATCH] refactor!: rename validator to validatorAdapter --- docs/guides/validation.md | 2 +- examples/react/valibot/src/index.tsx | 2 +- examples/react/yup/src/index.tsx | 2 +- examples/react/zod/src/index.tsx | 2 +- examples/solid/valibot/src/index.tsx | 2 +- examples/solid/yup/src/index.tsx | 2 +- examples/solid/zod/src/index.tsx | 2 +- examples/vue/valibot/src/App.vue | 2 +- examples/vue/yup/src/App.vue | 2 +- examples/vue/zod/src/App.vue | 2 +- packages/form-core/src/FieldApi.ts | 18 +++++++++--------- packages/form-core/src/FormApi.ts | 14 +++++++------- .../src/tests/FieldApi.spec.ts | 8 ++++---- .../src/tests/FieldApi.test-d.ts | 10 +++++----- .../src/tests/FormApi.spec.ts | 4 ++-- .../src/tests/FormApi.test-d.ts | 10 +++++----- .../src/tests/FieldApi.spec.ts | 8 ++++---- .../src/tests/FieldApi.test-d.ts | 8 ++++---- .../yup-form-adapter/src/tests/FormApi.spec.ts | 4 ++-- .../src/tests/FormApi.test-d.ts | 8 ++++---- .../src/tests/FieldApi.spec.ts | 8 ++++---- .../src/tests/FieldApi.test-d.ts | 10 +++++----- .../zod-form-adapter/src/tests/FormApi.spec.ts | 4 ++-- .../src/tests/FormApi.test-d.ts | 10 +++++----- 24 files changed, 72 insertions(+), 72 deletions(-) diff --git a/docs/guides/validation.md b/docs/guides/validation.md index 5f60a1a48..eabee0ab0 100644 --- a/docs/guides/validation.md +++ b/docs/guides/validation.md @@ -270,7 +270,7 @@ import { z } from "zod"; const form = useForm({ // Either add the validator here or on `Field` - validator: zodValidator, + validatorAdapter: zodValidator, // ... }); diff --git a/examples/react/valibot/src/index.tsx b/examples/react/valibot/src/index.tsx index 629adf35c..677921b6b 100644 --- a/examples/react/valibot/src/index.tsx +++ b/examples/react/valibot/src/index.tsx @@ -27,7 +27,7 @@ export default function App() { console.log(values); }, // Add a validator to support Valibot usage in Form and Field - validator: valibotValidator, + validatorAdapter: valibotValidator, }); return ( diff --git a/examples/react/yup/src/index.tsx b/examples/react/yup/src/index.tsx index 37b508d9a..5d52edfe1 100644 --- a/examples/react/yup/src/index.tsx +++ b/examples/react/yup/src/index.tsx @@ -27,7 +27,7 @@ export default function App() { console.log(values); }, // Add a validator to support Yup usage in Form and Field - validator: yupValidator, + validatorAdapter: yupValidator, }); return ( diff --git a/examples/react/zod/src/index.tsx b/examples/react/zod/src/index.tsx index 56f4fdaa4..434c1b8b8 100644 --- a/examples/react/zod/src/index.tsx +++ b/examples/react/zod/src/index.tsx @@ -27,7 +27,7 @@ export default function App() { console.log(values); }, // Add a validator to support Zod usage in Form and Field - validator: zodValidator, + validatorAdapter: zodValidator, }); return ( diff --git a/examples/solid/valibot/src/index.tsx b/examples/solid/valibot/src/index.tsx index ae955a41a..70b1698f6 100644 --- a/examples/solid/valibot/src/index.tsx +++ b/examples/solid/valibot/src/index.tsx @@ -31,7 +31,7 @@ function App() { console.log(values) }, // Add a validator to support Valibot usage in Form and Field - validator: valibotValidator, + validatorAdapter: valibotValidator, })) return ( diff --git a/examples/solid/yup/src/index.tsx b/examples/solid/yup/src/index.tsx index 6a3eac838..1fa249087 100644 --- a/examples/solid/yup/src/index.tsx +++ b/examples/solid/yup/src/index.tsx @@ -31,7 +31,7 @@ function App() { console.log(values) }, // Add a validator to support Yup usage in Form and Field - validator: yupValidator, + validatorAdapter: yupValidator, })) return ( diff --git a/examples/solid/zod/src/index.tsx b/examples/solid/zod/src/index.tsx index cba500959..e190c6eb5 100644 --- a/examples/solid/zod/src/index.tsx +++ b/examples/solid/zod/src/index.tsx @@ -31,7 +31,7 @@ function App() { console.log(values) }, // Add a validator to support Zod usage in Form and Field - validator: zodValidator, + validatorAdapter: zodValidator, })) return ( diff --git a/examples/vue/valibot/src/App.vue b/examples/vue/valibot/src/App.vue index c5437ad2b..d207a266d 100644 --- a/examples/vue/valibot/src/App.vue +++ b/examples/vue/valibot/src/App.vue @@ -14,7 +14,7 @@ const form = useForm({ alert(JSON.stringify(values)) }, // Add a validator to support Valibot usage in Form and Field - validator: valibotValidator, + validatorAdapter: valibotValidator, }) form.provideFormContext() diff --git a/examples/vue/yup/src/App.vue b/examples/vue/yup/src/App.vue index 370dc85a7..d4d160c17 100644 --- a/examples/vue/yup/src/App.vue +++ b/examples/vue/yup/src/App.vue @@ -14,7 +14,7 @@ const form = useForm({ alert(JSON.stringify(values)) }, // Add a validator to support Yup usage in Form and Field - validator: yupValidator, + validatorAdapter: yupValidator, }) form.provideFormContext() diff --git a/examples/vue/zod/src/App.vue b/examples/vue/zod/src/App.vue index 998e5c01d..5fef977d6 100644 --- a/examples/vue/zod/src/App.vue +++ b/examples/vue/zod/src/App.vue @@ -14,7 +14,7 @@ const form = useForm({ alert(JSON.stringify(values)) }, // Add a validator to support Zod usage in Form and Field - validator: zodValidator, + validatorAdapter: zodValidator, }) form.provideFormContext() diff --git a/packages/form-core/src/FieldApi.ts b/packages/form-core/src/FieldApi.ts index 8897e4d99..7181494d8 100644 --- a/packages/form-core/src/FieldApi.ts +++ b/packages/form-core/src/FieldApi.ts @@ -120,7 +120,7 @@ export interface FieldOptions< asyncDebounceMs?: number asyncAlways?: boolean preserveValue?: boolean - validator?: ValidatorType + validatorAdapter?: ValidatorType validators?: FieldValidators< TParentData, TName, @@ -373,15 +373,15 @@ export class FieldApi< this.getInfo().validationCount = validationCount const doValidate = (validate: (typeof validates)[number]['validate']) => { - if (this.options.validator && typeof validate !== 'function') { - return (this.options.validator as Validator)().validate( + if (this.options.validatorAdapter && typeof validate !== 'function') { + return (this.options.validatorAdapter as Validator)().validate( value, validate, ) } - if (this.form.options.validator && typeof validate !== 'function') { - return (this.form.options.validator as Validator)().validate( + if (this.form.options.validatorAdapter && typeof validate !== 'function') { + return (this.form.options.validatorAdapter as Validator)().validate( value, validate, ) @@ -508,16 +508,16 @@ export class FieldApi< } const doValidate = () => { - if (this.options.validator && typeof validate !== 'function') { - return (this.options.validator as Validator)().validateAsync( + if (this.options.validatorAdapter && typeof validate !== 'function') { + return (this.options.validatorAdapter as Validator)().validateAsync( value, validate, ) } - if (this.form.options.validator && typeof validate !== 'function') { + if (this.form.options.validatorAdapter && typeof validate !== 'function') { return ( - this.form.options.validator as Validator + this.form.options.validatorAdapter as Validator )().validateAsync(value, validate) } diff --git a/packages/form-core/src/FormApi.ts b/packages/form-core/src/FormApi.ts index e830ed28c..4d0858ec7 100644 --- a/packages/form-core/src/FormApi.ts +++ b/packages/form-core/src/FormApi.ts @@ -39,7 +39,7 @@ export type FormOptions = { defaultState?: Partial> asyncAlways?: boolean asyncDebounceMs?: number - validator?: ValidatorType + validatorAdapter?: ValidatorType validators?: FormValidators onSubmit?: ( values: TData, @@ -188,10 +188,10 @@ export class FormApi { mount = () => { const doValidate = () => { if ( - this.options.validator && + this.options.validatorAdapter && typeof this.options.validators?.onMount !== 'function' ) { - return (this.options.validator as Validator)().validate( + return (this.options.validatorAdapter as Validator)().validate( this.state.values, this.options.validators?.onMount, ) @@ -283,8 +283,8 @@ export class FormApi { const errorMapKey = getErrorMapKey(cause) const doValidate = () => { - if (this.options.validator && typeof validate !== 'function') { - return (this.options.validator as Validator)().validate( + if (this.options.validatorAdapter && typeof validate !== 'function') { + return (this.options.validatorAdapter as Validator)().validate( this.state.values, validate, ) @@ -378,8 +378,8 @@ export class FormApi { if (typeof validate === 'function') { return validate(this.state.values, this) as ValidationError } - if (this.options.validator && typeof validate !== 'function') { - return (this.options.validator as Validator)().validateAsync( + if (this.options.validatorAdapter && typeof validate !== 'function') { + return (this.options.validatorAdapter as Validator)().validateAsync( this.state.values, validate, ) diff --git a/packages/valibot-form-adapter/src/tests/FieldApi.spec.ts b/packages/valibot-form-adapter/src/tests/FieldApi.spec.ts index 58276d26a..cd839c44a 100644 --- a/packages/valibot-form-adapter/src/tests/FieldApi.spec.ts +++ b/packages/valibot-form-adapter/src/tests/FieldApi.spec.ts @@ -15,7 +15,7 @@ describe('valibot field api', () => { const field = new FieldApi({ form, - validator: valibotValidator, + validatorAdapter: valibotValidator, name: 'name', validators: { onChange: string([ @@ -44,7 +44,7 @@ describe('valibot field api', () => { const field = new FieldApi({ form, - validator: valibotValidator, + validatorAdapter: valibotValidator, name: 'name', validators: { onChange: (val) => (val === 'a' ? 'Test' : undefined), @@ -69,7 +69,7 @@ describe('valibot field api', () => { const field = new FieldApi({ form, - validator: valibotValidator, + validatorAdapter: valibotValidator, name: 'name', validators: { onChangeAsync: stringAsync([ @@ -99,7 +99,7 @@ describe('valibot field api', () => { const field = new FieldApi({ form, - validator: valibotValidator, + validatorAdapter: valibotValidator, name: 'name', validators: { onChangeAsync: async (val) => (val === 'a' ? 'Test' : undefined), diff --git a/packages/valibot-form-adapter/src/tests/FieldApi.test-d.ts b/packages/valibot-form-adapter/src/tests/FieldApi.test-d.ts index 988871778..a1ce0bc86 100644 --- a/packages/valibot-form-adapter/src/tests/FieldApi.test-d.ts +++ b/packages/valibot-form-adapter/src/tests/FieldApi.test-d.ts @@ -13,7 +13,7 @@ it('should allow a Valibot validator to be passed in', () => { const field = new FieldApi({ form, name: 'name', - validator: valibotValidator, + validatorAdapter: valibotValidator, } as const) }) @@ -27,7 +27,7 @@ it('should allow a Valibot validator to handle the correct Valibot type', () => const field = new FieldApi({ form, name: 'name', - validator: valibotValidator, + validatorAdapter: valibotValidator, validators: { onChange: string(), }, @@ -44,7 +44,7 @@ it('should allow a Valibot validator to handle the correct Valibot type for an a const field = new FieldApi({ form, name: 'name', - validator: valibotValidator, + validatorAdapter: valibotValidator, validators: { onChangeAsync: string(), }, @@ -61,7 +61,7 @@ it('should allow a functional onChange to be passed when using a validator', () const field = new FieldApi({ form, name: 'name', - validator: valibotValidator, + validatorAdapter: valibotValidator, validators: { onChange: (val) => { assertType<'test'>(val) @@ -97,7 +97,7 @@ it.skip('should allow not a Valibot validator with the wrong Valibot type', () = const field = new FieldApi({ form, name: 'name', - validator: valibotValidator, + validatorAdapter: valibotValidator, validators: { onChange: object({}), }, diff --git a/packages/valibot-form-adapter/src/tests/FormApi.spec.ts b/packages/valibot-form-adapter/src/tests/FormApi.spec.ts index e611d9796..e3495e07a 100644 --- a/packages/valibot-form-adapter/src/tests/FormApi.spec.ts +++ b/packages/valibot-form-adapter/src/tests/FormApi.spec.ts @@ -10,7 +10,7 @@ describe('valibot form api', () => { defaultValues: { name: '', }, - validator: valibotValidator, + validatorAdapter: valibotValidator, }) const field = new FieldApi({ @@ -39,7 +39,7 @@ describe('valibot form api', () => { defaultValues: { name: '', }, - validator: valibotValidator, + validatorAdapter: valibotValidator, }) const field = new FieldApi({ diff --git a/packages/valibot-form-adapter/src/tests/FormApi.test-d.ts b/packages/valibot-form-adapter/src/tests/FormApi.test-d.ts index 205811785..062ff28ad 100644 --- a/packages/valibot-form-adapter/src/tests/FormApi.test-d.ts +++ b/packages/valibot-form-adapter/src/tests/FormApi.test-d.ts @@ -8,7 +8,7 @@ it('should allow a Valibot validator to be passed in', () => { defaultValues: { name: 'test', }, - validator: valibotValidator, + validatorAdapter: valibotValidator, } as const) }) @@ -17,7 +17,7 @@ it('should allow a Valibot validator to handle the correct Valibot type', () => defaultValues: { name: 'test', }, - validator: valibotValidator, + validatorAdapter: valibotValidator, }) const field = new FieldApi({ @@ -34,7 +34,7 @@ it('should allow a Valibot validator to handle the correct Valibot type on async defaultValues: { name: 'test', }, - validator: valibotValidator, + validatorAdapter: valibotValidator, }) const field = new FieldApi({ @@ -51,7 +51,7 @@ it('should allow a functional onChange to be passed when using a validator', () defaultValues: { name: 'test', }, - validator: valibotValidator, + validatorAdapter: valibotValidator, }) const field = new FieldApi({ @@ -92,7 +92,7 @@ it.skip('should allow not a Valibot validator with the wrong Valibot type', () = const field = new FieldApi({ form, name: 'name', - validator: valibotValidator, + validatorAdapter: valibotValidator, validators: { onChange: object({}), }, diff --git a/packages/yup-form-adapter/src/tests/FieldApi.spec.ts b/packages/yup-form-adapter/src/tests/FieldApi.spec.ts index 978c2a2fe..48151cf4e 100644 --- a/packages/yup-form-adapter/src/tests/FieldApi.spec.ts +++ b/packages/yup-form-adapter/src/tests/FieldApi.spec.ts @@ -15,7 +15,7 @@ describe('yup field api', () => { const field = new FieldApi({ form, - validator: yupValidator, + validatorAdapter: yupValidator, name: 'name', validators: { onChange: yup.string().min(3, 'You must have a length of at least 3'), @@ -42,7 +42,7 @@ describe('yup field api', () => { const field = new FieldApi({ form, - validator: yupValidator, + validatorAdapter: yupValidator, name: 'name', validators: { onChange: (val) => (val === 'a' ? 'Test' : undefined), @@ -67,7 +67,7 @@ describe('yup field api', () => { const field = new FieldApi({ form, - validator: yupValidator, + validatorAdapter: yupValidator, name: 'name', validators: { onChangeAsync: yup @@ -99,7 +99,7 @@ describe('yup field api', () => { const field = new FieldApi({ form, - validator: yupValidator, + validatorAdapter: yupValidator, name: 'name', validators: { onChangeAsync: async (val) => (val === 'a' ? 'Test' : undefined), diff --git a/packages/yup-form-adapter/src/tests/FieldApi.test-d.ts b/packages/yup-form-adapter/src/tests/FieldApi.test-d.ts index 201fe4771..cf2814d01 100644 --- a/packages/yup-form-adapter/src/tests/FieldApi.test-d.ts +++ b/packages/yup-form-adapter/src/tests/FieldApi.test-d.ts @@ -13,7 +13,7 @@ it('should allow a Zod validator to be passed in', () => { const field = new FieldApi({ form, name: 'name', - validator: yupValidator, + validatorAdapter: yupValidator, } as const) }) @@ -27,7 +27,7 @@ it('should allow a Zod validator to handle the correct Zod type', () => { const field = new FieldApi({ form, name: 'name', - validator: yupValidator, + validatorAdapter: yupValidator, validators: { onChange: yup.string(), }, @@ -44,7 +44,7 @@ it('should allow a functional onChange to be passed when using a validator', () const field = new FieldApi({ form, name: 'name', - validator: yupValidator, + validatorAdapter: yupValidator, validators: { onChange: (val) => { assertType<'test'>(val) @@ -80,7 +80,7 @@ it.skip('should allow not a Zod validator with the wrong Zod type', () => { const field = new FieldApi({ form, name: 'name', - validator: yupValidator, + validatorAdapter: yupValidator, validators: { onChange: yup.object({}), }, diff --git a/packages/yup-form-adapter/src/tests/FormApi.spec.ts b/packages/yup-form-adapter/src/tests/FormApi.spec.ts index 6b8415ab1..314f1c477 100644 --- a/packages/yup-form-adapter/src/tests/FormApi.spec.ts +++ b/packages/yup-form-adapter/src/tests/FormApi.spec.ts @@ -10,7 +10,7 @@ describe('yup form api', () => { defaultValues: { name: '', }, - validator: yupValidator, + validatorAdapter: yupValidator, }) const field = new FieldApi({ @@ -37,7 +37,7 @@ describe('yup form api', () => { defaultValues: { name: '', }, - validator: yupValidator, + validatorAdapter: yupValidator, }) const field = new FieldApi({ diff --git a/packages/yup-form-adapter/src/tests/FormApi.test-d.ts b/packages/yup-form-adapter/src/tests/FormApi.test-d.ts index 4bbd3bb66..455c438f7 100644 --- a/packages/yup-form-adapter/src/tests/FormApi.test-d.ts +++ b/packages/yup-form-adapter/src/tests/FormApi.test-d.ts @@ -8,7 +8,7 @@ it('should allow a Zod validator to be passed in', () => { defaultValues: { name: 'test', }, - validator: yupValidator, + validatorAdapter: yupValidator, } as const) }) @@ -17,7 +17,7 @@ it('should allow a Zod validator to handle the correct Zod type', () => { defaultValues: { name: 'test', }, - validator: yupValidator, + validatorAdapter: yupValidator, }) const field = new FieldApi({ @@ -34,7 +34,7 @@ it('should allow a functional onChange to be passed when using a validator', () defaultValues: { name: 'test', }, - validator: yupValidator, + validatorAdapter: yupValidator, }) const field = new FieldApi({ @@ -75,7 +75,7 @@ it.skip('should allow not a Zod validator with the wrong Zod type', () => { const field = new FieldApi({ form, name: 'name', - validator: yupValidator, + validatorAdapter: yupValidator, validators: { onChange: yup.object({}), }, diff --git a/packages/zod-form-adapter/src/tests/FieldApi.spec.ts b/packages/zod-form-adapter/src/tests/FieldApi.spec.ts index bcb7ba94b..06e7df2a8 100644 --- a/packages/zod-form-adapter/src/tests/FieldApi.spec.ts +++ b/packages/zod-form-adapter/src/tests/FieldApi.spec.ts @@ -15,7 +15,7 @@ describe('zod field api', () => { const field = new FieldApi({ form, - validator: zodValidator, + validatorAdapter: zodValidator, name: 'name', validators: { onChange: z.string().min(3, 'You must have a length of at least 3'), @@ -42,7 +42,7 @@ describe('zod field api', () => { const field = new FieldApi({ form, - validator: zodValidator, + validatorAdapter: zodValidator, name: 'name', validators: { onChange: (val) => (val === 'a' ? 'Test' : undefined), @@ -67,7 +67,7 @@ describe('zod field api', () => { const field = new FieldApi({ form, - validator: zodValidator, + validatorAdapter: zodValidator, name: 'name', validators: { onChangeAsync: z.string().refine(async (val) => val.length > 3, { @@ -97,7 +97,7 @@ describe('zod field api', () => { const field = new FieldApi({ form, - validator: zodValidator, + validatorAdapter: zodValidator, name: 'name', validators: { onChangeAsync: async (val) => (val === 'a' ? 'Test' : undefined), diff --git a/packages/zod-form-adapter/src/tests/FieldApi.test-d.ts b/packages/zod-form-adapter/src/tests/FieldApi.test-d.ts index 0c9102ddc..9aa639be6 100644 --- a/packages/zod-form-adapter/src/tests/FieldApi.test-d.ts +++ b/packages/zod-form-adapter/src/tests/FieldApi.test-d.ts @@ -13,7 +13,7 @@ it('should allow a Zod validator to be passed in', () => { const field = new FieldApi({ form, name: 'name', - validator: zodValidator, + validatorAdapter: zodValidator, } as const) }) @@ -27,7 +27,7 @@ it('should allow a Zod validator to handle the correct Zod type', () => { const field = new FieldApi({ form, name: 'name', - validator: zodValidator, + validatorAdapter: zodValidator, validators: { onChange: z.string(), }, @@ -44,7 +44,7 @@ it('should allow a Zod validator to handle the correct Zod type for an async met const field = new FieldApi({ form, name: 'name', - validator: zodValidator, + validatorAdapter: zodValidator, validators: { onChangeAsync: z.string(), }, @@ -61,7 +61,7 @@ it('should allow a functional onChange to be passed when using a validator', () const field = new FieldApi({ form, name: 'name', - validator: zodValidator, + validatorAdapter: zodValidator, validators: { onChange: (val) => { assertType<'test'>(val) @@ -97,7 +97,7 @@ it.skip('should allow not a Zod validator with the wrong Zod type', () => { const field = new FieldApi({ form, name: 'name', - validator: zodValidator, + validatorAdapter: zodValidator, validators: { onChange: z.object({}), }, diff --git a/packages/zod-form-adapter/src/tests/FormApi.spec.ts b/packages/zod-form-adapter/src/tests/FormApi.spec.ts index bade276e0..5b689c0d3 100644 --- a/packages/zod-form-adapter/src/tests/FormApi.spec.ts +++ b/packages/zod-form-adapter/src/tests/FormApi.spec.ts @@ -10,7 +10,7 @@ describe('zod form api', () => { defaultValues: { name: '', }, - validator: zodValidator, + validatorAdapter: zodValidator, }) const field = new FieldApi({ @@ -37,7 +37,7 @@ describe('zod form api', () => { defaultValues: { name: '', }, - validator: zodValidator, + validatorAdapter: zodValidator, }) const field = new FieldApi({ diff --git a/packages/zod-form-adapter/src/tests/FormApi.test-d.ts b/packages/zod-form-adapter/src/tests/FormApi.test-d.ts index 220c864f0..f98e82c67 100644 --- a/packages/zod-form-adapter/src/tests/FormApi.test-d.ts +++ b/packages/zod-form-adapter/src/tests/FormApi.test-d.ts @@ -8,7 +8,7 @@ it('should allow a Zod validator to be passed in', () => { defaultValues: { name: 'test', }, - validator: zodValidator, + validatorAdapter: zodValidator, } as const) }) @@ -17,7 +17,7 @@ it('should allow a Zod validator to handle the correct Zod type', () => { defaultValues: { name: 'test', }, - validator: zodValidator, + validatorAdapter: zodValidator, }) const field = new FieldApi({ @@ -34,7 +34,7 @@ it('should allow a Zod validator to handle the correct Zod type on async methods defaultValues: { name: 'test', }, - validator: zodValidator, + validatorAdapter: zodValidator, }) const field = new FieldApi({ @@ -51,7 +51,7 @@ it('should allow a functional onChange to be passed when using a validator', () defaultValues: { name: 'test', }, - validator: zodValidator, + validatorAdapter: zodValidator, }) const field = new FieldApi({ @@ -92,7 +92,7 @@ it.skip('should allow not a Zod validator with the wrong Zod type', () => { const field = new FieldApi({ form, name: 'name', - validator: zodValidator, + validatorAdapter: zodValidator, validators: { onChange: z.object({}), },