Skip to content

Commit

Permalink
chore: upgrade zod support to 3.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed May 30, 2021
1 parent 83ba405 commit 53ce6ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/zod/package.json
Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions packages/zod/src/index.ts
@@ -1,12 +1,12 @@
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';

/**
* Transforms a Zod's base type schema to yup's base type schema
*/
export function toFieldValidator<TValue = unknown, TDef extends ZodTypeDef = ZodTypeDef, TInput = TValue>(
zodSchema: ZodType<TValue, TDef, TInput>
zodSchema: ZodType<TValue, TDef, TInput> | ZodEffects<ZodType<TValue, TDef, TInput>>
): BaseSchema<TValue> {
return {
async validate(value: TValue) {
Expand Down Expand Up @@ -39,7 +39,7 @@ type ToBaseTypes<TShape extends ZodRawShape> = {
export function toFormValidator<
TShape extends ZodRawShape,
TValues extends Record<string, unknown> = ToBaseTypes<TShape>
>(zodSchema: ZodObject<TShape>): SchemaOf<TValues> {
>(zodSchema: ZodObject<TShape> | ZodEffects<ZodObject<TShape>>): SchemaOf<TValues> {
return {
async validate(value: TValues) {
const result = await zodSchema.safeParseAsync(value);
Expand Down
22 changes: 11 additions & 11 deletions packages/zod/tests/zod.spec.ts
Expand Up @@ -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: '',
Expand Down

0 comments on commit 53ce6ec

Please sign in to comment.