From 53ce6ec183500435bcb508e05053abd7b7475e84 Mon Sep 17 00:00:00 2001 From: Abdelrahman Awad Date: Sun, 30 May 2021 21:59:28 +0200 Subject: [PATCH] chore: upgrade zod support to 3.1.x --- packages/zod/package.json | 6 +++--- packages/zod/src/index.ts | 6 +++--- packages/zod/tests/zod.spec.ts | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/zod/package.json b/packages/zod/package.json index 7c3eaf4ee..7f7ee53e6 100644 --- a/packages/zod/package.json +++ b/packages/zod/package.json @@ -24,10 +24,10 @@ "dist/*.d.ts" ], "peerDependencies": { - "vee-validate": "^4.1.18", - "zod": "^2.0.0-beta.29" + "vee-validate": "^4.4.0", + "zod": "^3.1.0" }, "devDependencies": { - "zod": "^2.0.0-beta.29" + "zod": "^3.1.0" } } diff --git a/packages/zod/src/index.ts b/packages/zod/src/index.ts index d86156fb1..681201832 100644 --- a/packages/zod/src/index.ts +++ b/packages/zod/src/index.ts @@ -1,4 +1,4 @@ -import type { ZodObject, ZodType, ZodTypeDef, TypeOf as ZodTypeOf, ZodRawShape } from 'zod'; +import type { ZodObject, ZodType, ZodTypeDef, TypeOf as ZodTypeOf, ZodRawShape, ZodEffects } from 'zod'; import type { BaseSchema, SchemaOf } from 'yup'; import { isIndex } from '../../shared'; @@ -6,7 +6,7 @@ import { isIndex } from '../../shared'; * Transforms a Zod's base type schema to yup's base type schema */ export function toFieldValidator( - zodSchema: ZodType + zodSchema: ZodType | ZodEffects> ): BaseSchema { return { async validate(value: TValue) { @@ -39,7 +39,7 @@ type ToBaseTypes = { export function toFormValidator< TShape extends ZodRawShape, TValues extends Record = ToBaseTypes ->(zodSchema: ZodObject): SchemaOf { +>(zodSchema: ZodObject | ZodEffects>): SchemaOf { return { async validate(value: TValues) { const result = await zodSchema.safeParseAsync(value); diff --git a/packages/zod/tests/zod.spec.ts b/packages/zod/tests/zod.spec.ts index bbe5afe07..feb6215e2 100644 --- a/packages/zod/tests/zod.spec.ts +++ b/packages/zod/tests/zod.spec.ts @@ -100,17 +100,17 @@ test('cross field validation with zod', async () => { const CONFIRM_MSG = "Passwords don't match"; const wrapper = mountWithHoc({ setup() { - const schema = toFormValidator( - zod - .object({ - password: zod.string(), - confirmation: zod.string(), - }) - .refine(data => data.confirmation === data.password, { - message: CONFIRM_MSG, - path: ['confirmation'], - }) - ); + const original = zod + .object({ + password: zod.string(), + confirmation: zod.string(), + }) + .refine(data => data.confirmation === data.password, { + message: CONFIRM_MSG, + path: ['confirmation'], + }); + + const schema = toFormValidator(original); const initialValues = { email: '',