@hookform/resolvers 2.9.11 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -5
- package/ajv/dist/ajv.d.ts +2 -2
- package/ajv/dist/ajv.js +1 -7
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.mjs +1 -7
- package/ajv/dist/ajv.modern.mjs +2 -0
- package/ajv/dist/ajv.modern.mjs.map +1 -0
- package/ajv/dist/ajv.module.js +1 -7
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js +1 -7
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/index.d.ts +2 -2
- package/ajv/dist/types.d.ts +5 -5
- package/ajv/package.json +3 -1
- package/ajv/src/__tests__/Form-native-validation.tsx +5 -9
- package/ajv/src/__tests__/Form.tsx +4 -6
- package/ajv/src/__tests__/__fixtures__/data.ts +3 -4
- package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +83 -83
- package/ajv/src/ajv.ts +28 -24
- package/class-validator/dist/class-validator.d.ts +2 -2
- package/class-validator/dist/class-validator.js +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.mjs +1 -1
- package/class-validator/dist/class-validator.modern.mjs +2 -0
- package/class-validator/dist/class-validator.modern.mjs.map +1 -0
- package/class-validator/dist/class-validator.module.js +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/index.d.ts +2 -2
- package/class-validator/dist/types.d.ts +12 -9
- package/class-validator/src/__tests__/Form-native-validation.tsx +5 -9
- package/class-validator/src/__tests__/Form.tsx +4 -6
- package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +102 -67
- package/class-validator/src/__tests__/class-validator.ts +66 -6
- package/class-validator/src/class-validator.ts +6 -4
- package/class-validator/src/types.ts +7 -8
- package/computed-types/dist/computed-types.d.ts +2 -2
- package/computed-types/dist/computed-types.js +1 -1
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.mjs +1 -1
- package/computed-types/dist/computed-types.modern.mjs +2 -0
- package/computed-types/dist/computed-types.modern.mjs.map +1 -0
- package/computed-types/dist/computed-types.module.js +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/dist/index.d.ts +2 -2
- package/computed-types/dist/types.d.ts +2 -2
- package/computed-types/src/__tests__/Form-native-validation.tsx +5 -9
- package/computed-types/src/__tests__/Form.tsx +4 -6
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +21 -21
- package/computed-types/src/__tests__/computed-types.ts +16 -0
- package/computed-types/src/computed-types.ts +12 -5
- package/dist/index.d.ts +2 -2
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +1 -1
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/dist/toNestError.d.ts +2 -2
- package/dist/validateFieldsNatively.d.ts +2 -2
- package/io-ts/dist/arrayToPath.d.ts +3 -3
- package/io-ts/dist/errorsToRecord.d.ts +5 -5
- package/io-ts/dist/index.d.ts +2 -2
- package/io-ts/dist/io-ts.d.ts +2 -2
- package/io-ts/dist/io-ts.js +1 -1
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs +2 -0
- package/io-ts/dist/io-ts.modern.mjs.map +1 -0
- package/io-ts/dist/io-ts.module.js +1 -1
- package/io-ts/dist/io-ts.module.js.map +1 -1
- package/io-ts/dist/io-ts.umd.js +1 -1
- package/io-ts/dist/io-ts.umd.js.map +1 -1
- package/io-ts/dist/types.d.ts +7 -7
- package/io-ts/src/__tests__/Form-native-validation.tsx +5 -9
- package/io-ts/src/__tests__/Form.tsx +4 -6
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +28 -28
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/joi/dist/index.d.ts +2 -2
- package/joi/dist/joi.d.ts +2 -2
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/{joi.modern.js → joi.modern.mjs} +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -0
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/dist/types.d.ts +5 -5
- package/joi/src/__tests__/Form-native-validation.tsx +5 -9
- package/joi/src/__tests__/Form.tsx +4 -6
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +87 -87
- package/joi/src/__tests__/joi.ts +8 -8
- package/nope/dist/index.d.ts +2 -2
- package/nope/dist/nope.d.ts +2 -2
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/{nope.modern.js → nope.modern.mjs} +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -0
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/dist/types.d.ts +9 -9
- package/nope/src/__tests__/Form-native-validation.tsx +5 -9
- package/nope/src/__tests__/Form.tsx +4 -6
- package/nope/src/__tests__/__snapshots__/nope.ts.snap +15 -15
- package/nope/src/__tests__/nope.ts +1 -1
- package/package.json +74 -44
- package/superstruct/dist/index.d.ts +2 -2
- package/superstruct/dist/superstruct.d.ts +2 -2
- package/superstruct/dist/superstruct.js +1 -1
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.mjs +1 -1
- package/superstruct/dist/superstruct.modern.mjs +2 -0
- package/superstruct/dist/superstruct.modern.mjs.map +1 -0
- package/superstruct/dist/superstruct.module.js +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/dist/types.d.ts +11 -5
- package/superstruct/src/__tests__/Form-native-validation.tsx +5 -9
- package/superstruct/src/__tests__/Form.tsx +4 -6
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +19 -19
- package/superstruct/src/__tests__/superstruct.ts +13 -0
- package/superstruct/src/superstruct.ts +4 -3
- package/superstruct/src/types.ts +8 -5
- package/typanion/dist/index.d.ts +2 -2
- package/typanion/dist/typanion.d.ts +2 -2
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/{typanion.modern.js → typanion.modern.mjs} +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -0
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/dist/types.d.ts +9 -9
- package/typanion/src/__tests__/Form-native-validation.tsx +7 -10
- package/typanion/src/__tests__/Form.tsx +9 -7
- package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +22 -22
- package/typanion/src/__tests__/typanion.ts +11 -7
- package/typanion/src/typanion.ts +1 -1
- package/typebox/dist/index.d.ts +2 -0
- package/typebox/dist/typebox.d.ts +2 -0
- package/typebox/dist/typebox.js +2 -0
- package/typebox/dist/typebox.js.map +1 -0
- package/typebox/dist/typebox.mjs +2 -0
- package/typebox/dist/typebox.modern.mjs +2 -0
- package/typebox/dist/typebox.modern.mjs.map +1 -0
- package/typebox/dist/typebox.module.js +2 -0
- package/typebox/dist/typebox.module.js.map +1 -0
- package/typebox/dist/typebox.umd.js +2 -0
- package/typebox/dist/typebox.umd.js.map +1 -0
- package/typebox/dist/types.d.ts +3 -0
- package/typebox/package.json +18 -0
- package/typebox/src/__tests__/Form-native-validation.tsx +83 -0
- package/typebox/src/__tests__/Form.tsx +54 -0
- package/typebox/src/__tests__/__fixtures__/data.ts +84 -0
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +190 -0
- package/typebox/src/__tests__/typebox.ts +34 -0
- package/typebox/src/index.ts +2 -0
- package/typebox/src/typebox.ts +64 -0
- package/typebox/src/types.ts +10 -0
- package/vest/dist/index.d.ts +2 -2
- package/vest/dist/types.d.ts +8 -8
- package/vest/dist/vest.d.ts +2 -2
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/{vest.modern.js → vest.modern.mjs} +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -0
- package/vest/dist/vest.module.js.map +1 -1
- package/vest/dist/vest.umd.js.map +1 -1
- package/vest/src/__tests__/Form-native-validation.tsx +5 -9
- package/vest/src/__tests__/Form.tsx +6 -10
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +47 -47
- package/yup/dist/index.d.ts +2 -2
- package/yup/dist/types.d.ts +15 -9
- package/yup/dist/yup.d.ts +2 -2
- package/yup/dist/yup.js +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.mjs +1 -1
- package/yup/dist/yup.modern.mjs +2 -0
- package/yup/dist/yup.modern.mjs.map +1 -0
- package/yup/dist/yup.module.js +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/Form-native-validation.tsx +5 -9
- package/yup/src/__tests__/Form.tsx +4 -6
- package/yup/src/__tests__/__fixtures__/data.ts +2 -3
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +100 -87
- package/yup/src/__tests__/yup.ts +49 -18
- package/yup/src/types.ts +14 -11
- package/yup/src/yup.ts +1 -1
- package/zod/dist/index.d.ts +2 -2
- package/zod/dist/types.d.ts +13 -13
- package/zod/dist/zod.d.ts +2 -2
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +2 -0
- package/zod/dist/zod.modern.mjs.map +1 -0
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/Form-native-validation.tsx +5 -9
- package/zod/src/__tests__/Form.tsx +4 -6
- package/zod/src/__tests__/__snapshots__/zod.ts.snap +120 -120
- package/zod/src/__tests__/zod.ts +19 -7
- package/zod/src/types.ts +2 -6
- package/zod/src/zod.ts +27 -27
- package/ajv/dist/ajv.modern.js +0 -8
- package/ajv/dist/ajv.modern.js.map +0 -1
- package/class-validator/dist/class-validator.modern.js +0 -2
- package/class-validator/dist/class-validator.modern.js.map +0 -1
- package/computed-types/dist/computed-types.modern.js +0 -2
- package/computed-types/dist/computed-types.modern.js.map +0 -1
- package/io-ts/dist/io-ts.modern.js +0 -2
- package/io-ts/dist/io-ts.modern.js.map +0 -1
- package/joi/dist/joi.modern.js.map +0 -1
- package/nope/dist/nope.modern.js.map +0 -1
- package/superstruct/dist/superstruct.modern.js +0 -2
- package/superstruct/dist/superstruct.modern.js.map +0 -1
- package/typanion/dist/typanion.modern.js.map +0 -1
- package/vest/dist/vest.modern.js.map +0 -1
- package/yup/dist/yup.modern.js +0 -2
- package/yup/dist/yup.modern.js.map +0 -1
- package/zod/dist/zod.modern.js +0 -2
- package/zod/dist/zod.modern.js.map +0 -1
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`yupResolver should return a single error from yupResolver when validation fails 1`] = `
|
|
4
|
-
|
|
5
|
-
"errors":
|
|
6
|
-
"birthYear":
|
|
3
|
+
exports[`yupResolver > should return a single error from yupResolver when validation fails 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"birthYear": {
|
|
7
7
|
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"birthYear\\"\`).",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "typeError",
|
|
10
10
|
},
|
|
11
|
-
"like":
|
|
12
|
-
|
|
13
|
-
"id":
|
|
11
|
+
"like": [
|
|
12
|
+
{
|
|
13
|
+
"id": {
|
|
14
14
|
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"z\\"\`).",
|
|
15
15
|
"ref": undefined,
|
|
16
16
|
"type": "typeError",
|
|
17
17
|
},
|
|
18
|
-
"name":
|
|
18
|
+
"name": {
|
|
19
19
|
"message": "like[0].name is a required field",
|
|
20
20
|
"ref": undefined,
|
|
21
|
-
"type": "
|
|
21
|
+
"type": "optionality",
|
|
22
22
|
},
|
|
23
23
|
},
|
|
24
24
|
],
|
|
25
|
-
"password":
|
|
25
|
+
"password": {
|
|
26
26
|
"message": "One uppercase character",
|
|
27
|
-
"ref":
|
|
27
|
+
"ref": {
|
|
28
28
|
"name": "password",
|
|
29
29
|
},
|
|
30
30
|
"type": "matches",
|
|
31
31
|
},
|
|
32
|
-
"username":
|
|
32
|
+
"username": {
|
|
33
33
|
"message": "username is a required field",
|
|
34
|
-
"ref":
|
|
34
|
+
"ref": {
|
|
35
35
|
"name": "username",
|
|
36
36
|
},
|
|
37
|
-
"type": "
|
|
37
|
+
"type": "optionality",
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
|
-
"values":
|
|
40
|
+
"values": {},
|
|
41
41
|
}
|
|
42
42
|
`;
|
|
43
43
|
|
|
44
|
-
exports[`yupResolver should return a single error from yupResolver with \`mode: sync\` when validation fails 1`] = `
|
|
45
|
-
|
|
46
|
-
"errors":
|
|
47
|
-
"birthYear":
|
|
44
|
+
exports[`yupResolver > should return a single error from yupResolver with \`mode: sync\` when validation fails 1`] = `
|
|
45
|
+
{
|
|
46
|
+
"errors": {
|
|
47
|
+
"birthYear": {
|
|
48
48
|
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"birthYear\\"\`).",
|
|
49
49
|
"ref": undefined,
|
|
50
50
|
"type": "typeError",
|
|
51
51
|
},
|
|
52
|
-
"like":
|
|
53
|
-
|
|
54
|
-
"id":
|
|
52
|
+
"like": [
|
|
53
|
+
{
|
|
54
|
+
"id": {
|
|
55
55
|
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"z\\"\`).",
|
|
56
56
|
"ref": undefined,
|
|
57
57
|
"type": "typeError",
|
|
58
58
|
},
|
|
59
|
-
"name":
|
|
59
|
+
"name": {
|
|
60
60
|
"message": "like[0].name is a required field",
|
|
61
61
|
"ref": undefined,
|
|
62
|
-
"type": "
|
|
62
|
+
"type": "optionality",
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
|
-
"password":
|
|
66
|
+
"password": {
|
|
67
67
|
"message": "One uppercase character",
|
|
68
|
-
"ref":
|
|
68
|
+
"ref": {
|
|
69
69
|
"name": "password",
|
|
70
70
|
},
|
|
71
71
|
"type": "matches",
|
|
72
72
|
},
|
|
73
|
-
"username":
|
|
73
|
+
"username": {
|
|
74
74
|
"message": "username is a required field",
|
|
75
|
-
"ref":
|
|
75
|
+
"ref": {
|
|
76
76
|
"name": "username",
|
|
77
77
|
},
|
|
78
|
-
"type": "
|
|
78
|
+
"type": "optionality",
|
|
79
79
|
},
|
|
80
80
|
},
|
|
81
|
-
"values":
|
|
81
|
+
"values": {},
|
|
82
82
|
}
|
|
83
83
|
`;
|
|
84
84
|
|
|
85
|
-
exports[`yupResolver should return all the errors from yupResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
86
|
-
|
|
87
|
-
"errors":
|
|
88
|
-
"birthYear":
|
|
85
|
+
exports[`yupResolver > should return all the errors from yupResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
86
|
+
{
|
|
87
|
+
"errors": {
|
|
88
|
+
"birthYear": {
|
|
89
89
|
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"birthYear\\"\`).",
|
|
90
90
|
"ref": undefined,
|
|
91
91
|
"type": "typeError",
|
|
92
|
-
"types":
|
|
92
|
+
"types": {
|
|
93
93
|
"typeError": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"birthYear\\"\`).",
|
|
94
94
|
},
|
|
95
95
|
},
|
|
96
|
-
"like":
|
|
97
|
-
|
|
98
|
-
"id":
|
|
96
|
+
"like": [
|
|
97
|
+
{
|
|
98
|
+
"id": {
|
|
99
99
|
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"z\\"\`).",
|
|
100
100
|
"ref": undefined,
|
|
101
101
|
"type": "typeError",
|
|
102
|
-
"types":
|
|
102
|
+
"types": {
|
|
103
103
|
"typeError": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"z\\"\`).",
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
|
-
"name":
|
|
106
|
+
"name": {
|
|
107
107
|
"message": "like[0].name is a required field",
|
|
108
108
|
"ref": undefined,
|
|
109
|
-
"type": "
|
|
110
|
-
"types":
|
|
111
|
-
"
|
|
109
|
+
"type": "optionality",
|
|
110
|
+
"types": {
|
|
111
|
+
"optionality": "like[0].name is a required field",
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
114
|
},
|
|
115
115
|
],
|
|
116
|
-
"password":
|
|
116
|
+
"password": {
|
|
117
117
|
"message": "One uppercase character",
|
|
118
|
-
"ref":
|
|
118
|
+
"ref": {
|
|
119
119
|
"name": "password",
|
|
120
120
|
},
|
|
121
121
|
"type": "matches",
|
|
122
|
-
"types":
|
|
123
|
-
"matches":
|
|
122
|
+
"types": {
|
|
123
|
+
"matches": [
|
|
124
124
|
"One uppercase character",
|
|
125
125
|
"One lowercase character",
|
|
126
126
|
"One number",
|
|
@@ -128,60 +128,60 @@ Object {
|
|
|
128
128
|
"min": "Must be at least 8 characters in length",
|
|
129
129
|
},
|
|
130
130
|
},
|
|
131
|
-
"username":
|
|
131
|
+
"username": {
|
|
132
132
|
"message": "username is a required field",
|
|
133
|
-
"ref":
|
|
133
|
+
"ref": {
|
|
134
134
|
"name": "username",
|
|
135
135
|
},
|
|
136
|
-
"type": "
|
|
137
|
-
"types":
|
|
138
|
-
"
|
|
136
|
+
"type": "optionality",
|
|
137
|
+
"types": {
|
|
138
|
+
"optionality": "username is a required field",
|
|
139
139
|
},
|
|
140
140
|
},
|
|
141
141
|
},
|
|
142
|
-
"values":
|
|
142
|
+
"values": {},
|
|
143
143
|
}
|
|
144
144
|
`;
|
|
145
145
|
|
|
146
|
-
exports[`yupResolver should return all the errors from yupResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
|
|
147
|
-
|
|
148
|
-
"errors":
|
|
149
|
-
"birthYear":
|
|
146
|
+
exports[`yupResolver > should return all the errors from yupResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
|
|
147
|
+
{
|
|
148
|
+
"errors": {
|
|
149
|
+
"birthYear": {
|
|
150
150
|
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"birthYear\\"\`).",
|
|
151
151
|
"ref": undefined,
|
|
152
152
|
"type": "typeError",
|
|
153
|
-
"types":
|
|
153
|
+
"types": {
|
|
154
154
|
"typeError": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"birthYear\\"\`).",
|
|
155
155
|
},
|
|
156
156
|
},
|
|
157
|
-
"like":
|
|
158
|
-
|
|
159
|
-
"id":
|
|
157
|
+
"like": [
|
|
158
|
+
{
|
|
159
|
+
"id": {
|
|
160
160
|
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"z\\"\`).",
|
|
161
161
|
"ref": undefined,
|
|
162
162
|
"type": "typeError",
|
|
163
|
-
"types":
|
|
163
|
+
"types": {
|
|
164
164
|
"typeError": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"z\\"\`).",
|
|
165
165
|
},
|
|
166
166
|
},
|
|
167
|
-
"name":
|
|
167
|
+
"name": {
|
|
168
168
|
"message": "like[0].name is a required field",
|
|
169
169
|
"ref": undefined,
|
|
170
|
-
"type": "
|
|
171
|
-
"types":
|
|
172
|
-
"
|
|
170
|
+
"type": "optionality",
|
|
171
|
+
"types": {
|
|
172
|
+
"optionality": "like[0].name is a required field",
|
|
173
173
|
},
|
|
174
174
|
},
|
|
175
175
|
},
|
|
176
176
|
],
|
|
177
|
-
"password":
|
|
177
|
+
"password": {
|
|
178
178
|
"message": "One uppercase character",
|
|
179
|
-
"ref":
|
|
179
|
+
"ref": {
|
|
180
180
|
"name": "password",
|
|
181
181
|
},
|
|
182
182
|
"type": "matches",
|
|
183
|
-
"types":
|
|
184
|
-
"matches":
|
|
183
|
+
"types": {
|
|
184
|
+
"matches": [
|
|
185
185
|
"One uppercase character",
|
|
186
186
|
"One lowercase character",
|
|
187
187
|
"One number",
|
|
@@ -189,43 +189,56 @@ Object {
|
|
|
189
189
|
"min": "Must be at least 8 characters in length",
|
|
190
190
|
},
|
|
191
191
|
},
|
|
192
|
-
"username":
|
|
192
|
+
"username": {
|
|
193
193
|
"message": "username is a required field",
|
|
194
|
-
"ref":
|
|
194
|
+
"ref": {
|
|
195
195
|
"name": "username",
|
|
196
196
|
},
|
|
197
|
-
"type": "
|
|
198
|
-
"types":
|
|
199
|
-
"
|
|
197
|
+
"type": "optionality",
|
|
198
|
+
"types": {
|
|
199
|
+
"optionality": "username is a required field",
|
|
200
200
|
},
|
|
201
201
|
},
|
|
202
202
|
},
|
|
203
|
-
"values":
|
|
203
|
+
"values": {},
|
|
204
204
|
}
|
|
205
205
|
`;
|
|
206
206
|
|
|
207
|
-
exports[`yupResolver should return an error from yupResolver when validation fails and pass down the yup context 1`] = `
|
|
208
|
-
|
|
209
|
-
"errors":
|
|
210
|
-
"name":
|
|
207
|
+
exports[`yupResolver > should return an error from yupResolver when validation fails and pass down the yup context 1`] = `
|
|
208
|
+
{
|
|
209
|
+
"errors": {
|
|
210
|
+
"name": {
|
|
211
211
|
"message": "name must be at least 6 characters",
|
|
212
212
|
"ref": undefined,
|
|
213
213
|
"type": "min",
|
|
214
214
|
},
|
|
215
215
|
},
|
|
216
|
-
"values":
|
|
216
|
+
"values": {},
|
|
217
217
|
}
|
|
218
218
|
`;
|
|
219
219
|
|
|
220
|
-
exports[`yupResolver should return correct error message with using yup.test 1`] = `
|
|
221
|
-
|
|
222
|
-
"errors":
|
|
223
|
-
"":
|
|
220
|
+
exports[`yupResolver > should return correct error message with using yup.test 1`] = `
|
|
221
|
+
{
|
|
222
|
+
"errors": {
|
|
223
|
+
"": {
|
|
224
224
|
"message": "Email or name are required",
|
|
225
225
|
"ref": undefined,
|
|
226
226
|
"type": "name",
|
|
227
227
|
},
|
|
228
228
|
},
|
|
229
|
-
"values":
|
|
229
|
+
"values": {},
|
|
230
|
+
}
|
|
231
|
+
`;
|
|
232
|
+
|
|
233
|
+
exports[`yupResolver > should throw an error without inner property 1`] = `
|
|
234
|
+
{
|
|
235
|
+
"errors": {
|
|
236
|
+
"value": {
|
|
237
|
+
"message": "value must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`\\"\\"\`).",
|
|
238
|
+
"ref": undefined,
|
|
239
|
+
"type": "typeError",
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
"values": {},
|
|
230
243
|
}
|
|
231
244
|
`;
|
package/yup/src/__tests__/yup.ts
CHANGED
|
@@ -13,8 +13,8 @@ const shouldUseNativeValidation = false;
|
|
|
13
13
|
|
|
14
14
|
describe('yupResolver', () => {
|
|
15
15
|
it('should return values from yupResolver when validation pass', async () => {
|
|
16
|
-
const schemaSpy =
|
|
17
|
-
const schemaSyncSpy =
|
|
16
|
+
const schemaSpy = vi.spyOn(schema, 'validate');
|
|
17
|
+
const schemaSyncSpy = vi.spyOn(schema, 'validateSync');
|
|
18
18
|
|
|
19
19
|
const result = await yupResolver(schema)(validData, undefined, {
|
|
20
20
|
fields,
|
|
@@ -27,8 +27,8 @@ describe('yupResolver', () => {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
it('should return values from yupResolver with `mode: sync` when validation pass', async () => {
|
|
30
|
-
const validateSyncSpy =
|
|
31
|
-
const validateSpy =
|
|
30
|
+
const validateSyncSpy = vi.spyOn(schema, 'validateSync');
|
|
31
|
+
const validateSpy = vi.spyOn(schema, 'validate');
|
|
32
32
|
|
|
33
33
|
const result = await yupResolver(schema, undefined, {
|
|
34
34
|
mode: 'sync',
|
|
@@ -49,8 +49,8 @@ describe('yupResolver', () => {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
it('should return a single error from yupResolver with `mode: sync` when validation fails', async () => {
|
|
52
|
-
const validateSyncSpy =
|
|
53
|
-
const validateSpy =
|
|
52
|
+
const validateSyncSpy = vi.spyOn(schema, 'validateSync');
|
|
53
|
+
const validateSpy = vi.spyOn(schema, 'validate');
|
|
54
54
|
|
|
55
55
|
const result = await yupResolver(schema, undefined, {
|
|
56
56
|
mode: 'sync',
|
|
@@ -92,12 +92,12 @@ describe('yupResolver', () => {
|
|
|
92
92
|
name: yup
|
|
93
93
|
.string()
|
|
94
94
|
.required()
|
|
95
|
-
.when('$min', (min
|
|
95
|
+
.when('$min', ([min], schema) => {
|
|
96
96
|
return min ? schema.min(6) : schema;
|
|
97
97
|
}),
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
const validateSpy =
|
|
100
|
+
const validateSpy = vi.spyOn(schemaWithContext, 'validate');
|
|
101
101
|
|
|
102
102
|
const result = await yupResolver(schemaWithContext)(data, context, {
|
|
103
103
|
fields,
|
|
@@ -115,7 +115,7 @@ describe('yupResolver', () => {
|
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
it('should show a warning log if yup context is used instead only on dev environment', async () => {
|
|
118
|
-
|
|
118
|
+
vi.spyOn(console, 'warn').mockImplementation(() => vi.fn());
|
|
119
119
|
process.env.NODE_ENV = 'development';
|
|
120
120
|
|
|
121
121
|
await yupResolver(yup.object(), { context: { noContext: true } })(
|
|
@@ -133,7 +133,7 @@ describe('yupResolver', () => {
|
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
it('should not show a warning log if yup context is used instead only on production environment', async () => {
|
|
136
|
-
|
|
136
|
+
vi.spyOn(console, 'warn').mockImplementation(() => vi.fn());
|
|
137
137
|
process.env.NODE_ENV = 'production';
|
|
138
138
|
|
|
139
139
|
await yupResolver(yup.object(), { context: { noContext: true } })(
|
|
@@ -166,7 +166,7 @@ describe('yupResolver', () => {
|
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
it("should merge default yup resolver options with yup's options", async () => {
|
|
169
|
-
const validateSpy =
|
|
169
|
+
const validateSpy = vi.spyOn(schema, 'validate');
|
|
170
170
|
|
|
171
171
|
await yupResolver(schema, { stripUnknown: true })(invalidData, undefined, {
|
|
172
172
|
fields,
|
|
@@ -178,15 +178,46 @@ describe('yupResolver', () => {
|
|
|
178
178
|
);
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
it('should throw an error without inner property', (
|
|
182
|
-
yupResolver(schemaWithWhen)(
|
|
181
|
+
it('should throw an error without inner property', async () => {
|
|
182
|
+
const result = await yupResolver(schemaWithWhen)(
|
|
183
|
+
{ name: 'test', value: '' },
|
|
184
|
+
undefined,
|
|
185
|
+
{
|
|
186
|
+
fields,
|
|
187
|
+
shouldUseNativeValidation,
|
|
188
|
+
},
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect(result).toMatchSnapshot();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should throw any error unrelated to Yup', async () => {
|
|
195
|
+
const schemaWithCustomError = schema.transform(() => {
|
|
196
|
+
throw Error('custom error');
|
|
197
|
+
});
|
|
198
|
+
const promise = yupResolver(schemaWithCustomError)(validData, undefined, {
|
|
183
199
|
fields,
|
|
184
200
|
shouldUseNativeValidation,
|
|
185
|
-
}).catch((e) => {
|
|
186
|
-
expect(e).toMatchInlineSnapshot(
|
|
187
|
-
`[TypeError: You cannot \`concat()\` schema's of different types: string and number]`,
|
|
188
|
-
);
|
|
189
|
-
done();
|
|
190
201
|
});
|
|
202
|
+
|
|
203
|
+
await expect(promise).rejects.toThrow('custom error');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should return values from yupResolver when validation pass & raw=true', async () => {
|
|
207
|
+
const schemaSpy = vi.spyOn(schema, 'validate');
|
|
208
|
+
const schemaSyncSpy = vi.spyOn(schema, 'validateSync');
|
|
209
|
+
|
|
210
|
+
const result = await yupResolver(schema, undefined, { raw: true })(
|
|
211
|
+
validData,
|
|
212
|
+
undefined,
|
|
213
|
+
{
|
|
214
|
+
fields,
|
|
215
|
+
shouldUseNativeValidation,
|
|
216
|
+
},
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
expect(schemaSpy).toHaveBeenCalledTimes(1);
|
|
220
|
+
expect(schemaSyncSpy).not.toHaveBeenCalled();
|
|
221
|
+
expect(result).toEqual({ errors: {}, values: validData });
|
|
191
222
|
});
|
|
192
223
|
});
|
package/yup/src/types.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FieldValues,
|
|
3
|
-
ResolverOptions,
|
|
4
|
-
ResolverResult,
|
|
5
|
-
} from 'react-hook-form';
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
6
2
|
import * as Yup from 'yup';
|
|
7
|
-
import type Lazy from 'yup/lib/Lazy';
|
|
8
3
|
|
|
9
|
-
type Options<T extends Yup.
|
|
10
|
-
T['validate']
|
|
11
|
-
>[1];
|
|
4
|
+
type Options<T extends Yup.ObjectSchema<any>> = Parameters<T['validate']>[1];
|
|
12
5
|
|
|
13
|
-
export type Resolver = <T extends Yup.
|
|
6
|
+
export type Resolver = <T extends Yup.ObjectSchema<any>>(
|
|
14
7
|
schema: T,
|
|
15
8
|
schemaOptions?: Options<T>,
|
|
16
|
-
factoryOptions?: {
|
|
9
|
+
factoryOptions?: {
|
|
10
|
+
/**
|
|
11
|
+
* @default async
|
|
12
|
+
*/
|
|
13
|
+
mode?: 'async' | 'sync';
|
|
14
|
+
/**
|
|
15
|
+
* Return the raw input values rather than the parsed values.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
raw?: boolean;
|
|
19
|
+
},
|
|
17
20
|
) => <TFieldValues extends FieldValues, TContext>(
|
|
18
21
|
values: TFieldValues,
|
|
19
22
|
context: TContext | undefined,
|
package/yup/src/yup.ts
CHANGED
|
@@ -59,7 +59,7 @@ export const yupResolver: Resolver =
|
|
|
59
59
|
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
|
|
60
60
|
|
|
61
61
|
return {
|
|
62
|
-
values: resolverOptions.
|
|
62
|
+
values: resolverOptions.raw ? values : result,
|
|
63
63
|
errors: {},
|
|
64
64
|
};
|
|
65
65
|
} catch (e: any) {
|
package/zod/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './zod';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './zod';
|
|
2
|
+
export * from './types';
|
package/zod/dist/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
export
|
|
4
|
-
/**
|
|
5
|
-
* @default async
|
|
6
|
-
*/
|
|
7
|
-
mode?: 'async' | 'sync';
|
|
8
|
-
/**
|
|
9
|
-
* Return the raw input values rather than the parsed values.
|
|
10
|
-
* @default false
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
1
|
+
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export type Resolver = <T extends z.Schema<any, any>>(schema: T, schemaOptions?: Partial<z.ParseParams>, factoryOptions?: {
|
|
4
|
+
/**
|
|
5
|
+
* @default async
|
|
6
|
+
*/
|
|
7
|
+
mode?: 'async' | 'sync';
|
|
8
|
+
/**
|
|
9
|
+
* Return the raw input values rather than the parsed values.
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
raw?: boolean;
|
|
13
|
+
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
package/zod/dist/zod.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Resolver } from './types';
|
|
2
|
-
export declare const zodResolver: Resolver;
|
|
1
|
+
import type { Resolver } from './types';
|
|
2
|
+
export declare const zodResolver: Resolver;
|
package/zod/dist/zod.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=require("react-hook-form"),e=require("@hookform/resolvers"),o=function(e,o){for(var
|
|
1
|
+
var r=require("react-hook-form"),e=require("@hookform/resolvers"),o=function(e,o){for(var n={};e.length;){var s=e[0],t=s.code,i=s.message,a=s.path.join(".");if(!n[a])if("unionErrors"in s){var u=s.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:t};if("unionErrors"in s&&s.unionErrors.forEach(function(r){return r.errors.forEach(function(r){return e.push(r)})}),o){var c=n[a].types,f=c&&c[s.code];n[a]=r.appendErrors(a,o,n,t,f?[].concat(f,s.message):s.message)}e.shift()}return n};exports.zodResolver=function(r,n,s){return void 0===s&&(s={}),function(t,i,a){try{return Promise.resolve(function(o,i){try{var u=Promise.resolve(r["sync"===s.mode?"parse":"parseAsync"](t,n)).then(function(r){return a.shouldUseNativeValidation&&e.validateFieldsNatively({},a),{errors:{},values:s.raw?t:r}})}catch(r){return i(r)}return u&&u.then?u.then(void 0,i):u}(0,function(r){if(function(r){return null!=r.errors}(r))return{values:{},errors:e.toNestError(o(r.errors,!a.shouldUseNativeValidation&&"all"===a.criteriaMode),a)};throw r}))}catch(r){return Promise.reject(r)}}};
|
|
2
2
|
//# sourceMappingURL=zod.js.map
|
package/zod/dist/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { z, ZodError } from 'zod';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError => error.errors != null;\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","_path","path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","mode","then","data","shouldUseNativeValidation","validateFieldsNatively","raw","_catch","isZodError","toNestError","criteriaMode","reject"],"mappings":"kEAOMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAA,EACpCF,EAAUG,QAAU,CACzB,IAAMC,EAAQJ,EAAU,GAChBK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,KAAK,KAExB,IAAKP,EAAOK,GACV,GAAI,gBAAiBH,EAAO,CAC1B,IAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOK,GAAS,CACdD,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAEpB,MACCH,EAAOK,GAAS,CAAED,QAAAA,EAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAAQ,SAACH,GACzB,OAAAA,EAAWR,OAAOW,QAAQ,SAACC,GAAC,OAAKd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EAAAA,aACdX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAUoB,OACX,CAED,OAAOlB,CACT,sBAGE,SAACmB,EAAQC,EAAeC,GACjBC,YADiBD,IAAAA,IAAAA,EAAkB,IACnCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAAA,SAFlBC,GAMN,OAFAL,EAAQM,2BAA6BC,EAAsBA,uBAAC,GAAIP,GAEzD,CACLxB,OAAQ,CAAA,EACRsB,OAAQD,EAAgBW,IAAMV,EAASO,EACvC,4DAXuBI,CACvB,EAWK/B,SAAAA,GACP,GAnEa,SAACA,GAAkC,OAAgB,MAAhBA,EAAMF,MAAc,CAmEhEkC,CAAWhC,GACb,MAAO,CACLoB,OAAQ,CAAA,EACRtB,OAAQmC,EAAWA,YACjBtC,EACEK,EAAMF,QACLwB,EAAQM,2BACkB,QAAzBN,EAAQY,cAEZZ,IAKN,MAAMtB,CACP,GACH,CAAC,MAAAU,GAAA,OAAAa,QAAAY,OAAAzB,EAAA,CAAA,CAAA"}
|
package/zod/dist/zod.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";var n=function(e,o){for(var n={};e.length;){var
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";var n=function(e,o){for(var n={};e.length;){var t=e[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u=t.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(r){return r.errors.forEach(function(r){return e.push(r)})}),o){var c=n[a].types,f=c&&c[t.code];n[a]=r(a,o,n,s,f?[].concat(f,t.message):t.message)}e.shift()}return n},t=function(r,t,s){return void 0===s&&(s={}),function(i,a,u){try{return Promise.resolve(function(o,n){try{var a=Promise.resolve(r["sync"===s.mode?"parse":"parseAsync"](i,t)).then(function(r){return u.shouldUseNativeValidation&&e({},u),{errors:{},values:s.raw?i:r}})}catch(r){return n(r)}return a&&a.then?a.then(void 0,n):a}(0,function(r){if(function(r){return null!=r.errors}(r))return{values:{},errors:o(n(r.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}}};export{t as zodResolver};
|
|
2
2
|
//# sourceMappingURL=zod.module.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as o,toNestError as e}from"@hookform/resolvers";const s=(o,e)=>{const s={};for(;o.length;){const t=o[0],{code:a,message:n,path:i}=t,c=i.join(".");if(!s[c])if("unionErrors"in t){const r=t.unionErrors[0].errors[0];s[c]={message:r.message,type:r.code}}else s[c]={message:n,type:a};if("unionErrors"in t&&t.unionErrors.forEach(r=>r.errors.forEach(r=>o.push(r))),e){const o=s[c].types,n=o&&o[t.code];s[c]=r(c,e,s,a,n?[].concat(n,t.message):t.message)}o.shift()}return s},t=(r,t,a={})=>async(n,i,c)=>{try{const e=await r["sync"===a.mode?"parse":"parseAsync"](n,t);return c.shouldUseNativeValidation&&o({},c),{errors:{},values:a.raw?n:e}}catch(r){if((r=>null!=r.errors)(r))return{values:{},errors:e(s(r.errors,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw r}};export{t as zodResolver};
|
|
2
|
+
//# sourceMappingURL=zod.modern.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.modern.mjs","sources":["../src/zod.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { z, ZodError } from 'zod';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError => error.errors != null;\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","path","_path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","zodResolver","schema","schemaOptions","resolverOptions","async","values","_","options","data","mode","shouldUseNativeValidation","validateFieldsNatively","raw","isZodError","toNestError","criteriaMode"],"mappings":"6HAKA,MAEMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,CAAE,EAC7C,KAAOF,EAAUG,QAAU,CACzB,MAAMC,EAAQJ,EAAU,IAClBK,KAAEA,EAAIC,QAAEA,EAAOC,KAAEA,GAASH,EAC1BI,EAAQD,EAAKE,KAAK,KAExB,IAAKP,EAAOM,GACV,GAAI,gBAAiBJ,EAAO,CAC1B,MAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOM,GAAS,CACdF,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAEpB,MACCH,EAAOM,GAAS,CAAEF,UAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAASH,GACzBA,EAAWR,OAAOW,QAASC,GAAMd,EAAUe,KAAKD,KAIhDb,EAA0B,CAC5B,MAAMe,EAAQd,EAAOM,GAAOQ,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOM,GAASU,EACdV,EACAP,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAUoB,OACX,CAED,OAAOlB,GAGImB,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAA,IAC1CC,MAAOC,EAAQC,EAAGC,KAChB,IACE,MAAMC,QAAaP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CJ,EAAQH,GAIV,OAFAK,EAAQG,2BAA6BC,EAAuB,CAAA,EAAIJ,GAEzD,CACL1B,OAAQ,GACRwB,OAAQF,EAAgBS,IAAMP,EAASG,EAE1C,CAAC,MAAOzB,GACP,GAnEcA,IAAkD,MAAhBA,EAAMF,OAmElDgC,CAAW9B,GACb,MAAO,CACLsB,OAAQ,CAAA,EACRxB,OAAQiC,EACNpC,EACEK,EAAMF,QACL0B,EAAQG,2BACkB,QAAzBH,EAAQQ,cAEZR,IAKN,MAAMxB,CACP"}
|
package/zod/dist/zod.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";var n=function(e,o){for(var n={};e.length;){var
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";var n=function(e,o){for(var n={};e.length;){var t=e[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u=t.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(r){return r.errors.forEach(function(r){return e.push(r)})}),o){var c=n[a].types,f=c&&c[t.code];n[a]=r(a,o,n,s,f?[].concat(f,t.message):t.message)}e.shift()}return n},t=function(r,t,s){return void 0===s&&(s={}),function(i,a,u){try{return Promise.resolve(function(o,n){try{var a=Promise.resolve(r["sync"===s.mode?"parse":"parseAsync"](i,t)).then(function(r){return u.shouldUseNativeValidation&&e({},u),{errors:{},values:s.raw?i:r}})}catch(r){return n(r)}return a&&a.then?a.then(void 0,n):a}(0,function(r){if(function(r){return null!=r.errors}(r))return{values:{},errors:o(n(r.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}}};export{t as zodResolver};
|
|
2
2
|
//# sourceMappingURL=zod.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.module.js","sources":["../src/zod.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"zod.module.js","sources":["../src/zod.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { z, ZodError } from 'zod';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError => error.errors != null;\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","_path","path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","zodResolver","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","mode","then","data","shouldUseNativeValidation","validateFieldsNatively","raw","_catch","isZodError","toNestError","criteriaMode","reject"],"mappings":"6HAKA,IAEMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAA,EACpCF,EAAUG,QAAU,CACzB,IAAMC,EAAQJ,EAAU,GAChBK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,KAAK,KAExB,IAAKP,EAAOK,GACV,GAAI,gBAAiBH,EAAO,CAC1B,IAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOK,GAAS,CACdD,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAEpB,MACCH,EAAOK,GAAS,CAAED,QAAAA,EAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAAQ,SAACH,GACzB,OAAAA,EAAWR,OAAOW,QAAQ,SAACC,GAAC,OAAKd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EACdX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAUoB,OACX,CAED,OAAOlB,CACT,EAEamB,EACX,SAACC,EAAQC,EAAeC,GACjBC,YADiBD,IAAAA,IAAAA,EAAkB,IACnCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAAA,SAFlBC,GAMN,OAFAL,EAAQM,2BAA6BC,EAAuB,GAAIP,GAEzD,CACLzB,OAAQ,CAAA,EACRuB,OAAQD,EAAgBW,IAAMV,EAASO,EACvC,4DAXuBI,CACvB,EAWKhC,SAAAA,GACP,GAnEa,SAACA,GAAkC,OAAgB,MAAhBA,EAAMF,MAAc,CAmEhEmC,CAAWjC,GACb,MAAO,CACLqB,OAAQ,CAAA,EACRvB,OAAQoC,EACNvC,EACEK,EAAMF,QACLyB,EAAQM,2BACkB,QAAzBN,EAAQY,cAEZZ,IAKN,MAAMvB,CACP,GACH,CAAC,MAAAU,GAAA,OAAAc,QAAAY,OAAA1B,EAAA,CAAA,CAAA"}
|