@hookform/resolvers 2.9.10 → 3.0.0
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 +33 -2
- 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__/errorsToRecord.ts +47 -0
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/io-ts/src/errorsToRecord.ts +7 -6
- 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 -1
- package/vest/dist/types.d.ts +8 -0
- 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/vest/src/index.ts +1 -0
- 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
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`typeboxResolver > should return a single error from typeboxResolver when validation fails 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"accessToken": {
|
|
7
|
+
"message": "Expected required property",
|
|
8
|
+
"ref": undefined,
|
|
9
|
+
"type": "30",
|
|
10
|
+
},
|
|
11
|
+
"birthYear": {
|
|
12
|
+
"message": "Expected number",
|
|
13
|
+
"ref": undefined,
|
|
14
|
+
"type": "20",
|
|
15
|
+
},
|
|
16
|
+
"dateStr": {
|
|
17
|
+
"message": "Expected required property",
|
|
18
|
+
"ref": undefined,
|
|
19
|
+
"type": "30",
|
|
20
|
+
},
|
|
21
|
+
"email": {
|
|
22
|
+
"message": "Expected string to match format 'email'",
|
|
23
|
+
"ref": {
|
|
24
|
+
"name": "email",
|
|
25
|
+
},
|
|
26
|
+
"type": "39",
|
|
27
|
+
},
|
|
28
|
+
"enabled": {
|
|
29
|
+
"message": "Expected required property",
|
|
30
|
+
"ref": undefined,
|
|
31
|
+
"type": "30",
|
|
32
|
+
},
|
|
33
|
+
"like": [
|
|
34
|
+
{
|
|
35
|
+
"id": {
|
|
36
|
+
"message": "Expected number",
|
|
37
|
+
"ref": undefined,
|
|
38
|
+
"type": "20",
|
|
39
|
+
},
|
|
40
|
+
"name": {
|
|
41
|
+
"message": "Expected required property",
|
|
42
|
+
"ref": undefined,
|
|
43
|
+
"type": "30",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
"password": {
|
|
48
|
+
"message": "Expected string length greater or equal to 8",
|
|
49
|
+
"ref": {
|
|
50
|
+
"name": "password",
|
|
51
|
+
},
|
|
52
|
+
"type": "35",
|
|
53
|
+
},
|
|
54
|
+
"repeatPassword": {
|
|
55
|
+
"message": "Expected required property",
|
|
56
|
+
"ref": undefined,
|
|
57
|
+
"type": "30",
|
|
58
|
+
},
|
|
59
|
+
"tags": {
|
|
60
|
+
"message": "Expected required property",
|
|
61
|
+
"ref": undefined,
|
|
62
|
+
"type": "30",
|
|
63
|
+
},
|
|
64
|
+
"username": {
|
|
65
|
+
"message": "Expected required property",
|
|
66
|
+
"ref": {
|
|
67
|
+
"name": "username",
|
|
68
|
+
},
|
|
69
|
+
"type": "30",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
"values": {},
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
exports[`typeboxResolver > should return all the errors from typeboxResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
77
|
+
{
|
|
78
|
+
"errors": {
|
|
79
|
+
"accessToken": {
|
|
80
|
+
"message": "Expected required property",
|
|
81
|
+
"ref": undefined,
|
|
82
|
+
"type": "30",
|
|
83
|
+
"types": {
|
|
84
|
+
"20": "Expected number",
|
|
85
|
+
"30": "Expected required property",
|
|
86
|
+
"34": "Expected string",
|
|
87
|
+
"43": "Expected value of union",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
"birthYear": {
|
|
91
|
+
"message": "Expected number",
|
|
92
|
+
"ref": undefined,
|
|
93
|
+
"type": "20",
|
|
94
|
+
"types": {
|
|
95
|
+
"20": "Expected number",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
"dateStr": {
|
|
99
|
+
"message": "Expected required property",
|
|
100
|
+
"ref": undefined,
|
|
101
|
+
"type": "30",
|
|
102
|
+
"types": {
|
|
103
|
+
"30": "Expected required property",
|
|
104
|
+
"5": "Expected Date object",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
"email": {
|
|
108
|
+
"message": "Expected string to match format 'email'",
|
|
109
|
+
"ref": {
|
|
110
|
+
"name": "email",
|
|
111
|
+
},
|
|
112
|
+
"type": "39",
|
|
113
|
+
"types": {
|
|
114
|
+
"39": "Expected string to match format 'email'",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
"enabled": {
|
|
118
|
+
"message": "Expected required property",
|
|
119
|
+
"ref": undefined,
|
|
120
|
+
"type": "30",
|
|
121
|
+
"types": {
|
|
122
|
+
"30": "Expected required property",
|
|
123
|
+
"4": "Expected boolean",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
"like": [
|
|
127
|
+
{
|
|
128
|
+
"id": {
|
|
129
|
+
"message": "Expected number",
|
|
130
|
+
"ref": undefined,
|
|
131
|
+
"type": "20",
|
|
132
|
+
"types": {
|
|
133
|
+
"20": "Expected number",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
"name": {
|
|
137
|
+
"message": "Expected required property",
|
|
138
|
+
"ref": undefined,
|
|
139
|
+
"type": "30",
|
|
140
|
+
"types": {
|
|
141
|
+
"30": "Expected required property",
|
|
142
|
+
"34": "Expected string",
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
"password": {
|
|
148
|
+
"message": "Expected string length greater or equal to 8",
|
|
149
|
+
"ref": {
|
|
150
|
+
"name": "password",
|
|
151
|
+
},
|
|
152
|
+
"type": "35",
|
|
153
|
+
"types": {
|
|
154
|
+
"35": "Expected string length greater or equal to 8",
|
|
155
|
+
"37": "Expected string to match pattern ^(.*[A-Za-z\\\\d].*)$",
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
"repeatPassword": {
|
|
159
|
+
"message": "Expected required property",
|
|
160
|
+
"ref": undefined,
|
|
161
|
+
"type": "30",
|
|
162
|
+
"types": {
|
|
163
|
+
"30": "Expected required property",
|
|
164
|
+
"34": "Expected string",
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
"tags": {
|
|
168
|
+
"message": "Expected required property",
|
|
169
|
+
"ref": undefined,
|
|
170
|
+
"type": "30",
|
|
171
|
+
"types": {
|
|
172
|
+
"0": "Expected array",
|
|
173
|
+
"30": "Expected required property",
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
"username": {
|
|
177
|
+
"message": "Expected required property",
|
|
178
|
+
"ref": {
|
|
179
|
+
"name": "username",
|
|
180
|
+
},
|
|
181
|
+
"type": "30",
|
|
182
|
+
"types": {
|
|
183
|
+
"30": "Expected required property",
|
|
184
|
+
"34": "Expected string",
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
"values": {},
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { typeboxResolver } from '..';
|
|
2
|
+
import { schema, validData, invalidData, fields } from './__fixtures__/data';
|
|
3
|
+
|
|
4
|
+
const shouldUseNativeValidation = false;
|
|
5
|
+
|
|
6
|
+
describe('typeboxResolver', () => {
|
|
7
|
+
it('should return a single error from typeboxResolver when validation fails', async () => {
|
|
8
|
+
const result = await typeboxResolver(schema)(invalidData, undefined, {
|
|
9
|
+
fields,
|
|
10
|
+
shouldUseNativeValidation,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
expect(result).toMatchSnapshot();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return all the errors from typeboxResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
|
|
17
|
+
const result = await typeboxResolver(schema)(invalidData, undefined, {
|
|
18
|
+
fields,
|
|
19
|
+
criteriaMode: 'all',
|
|
20
|
+
shouldUseNativeValidation,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(result).toMatchSnapshot();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should validate with success', async () => {
|
|
27
|
+
const result = await typeboxResolver(schema)(validData, undefined, {
|
|
28
|
+
fields,
|
|
29
|
+
shouldUseNativeValidation,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(result).toEqual({ errors: {}, values: validData });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';
|
|
2
|
+
import { toNestError, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
|
+
import type { Resolver } from './types';
|
|
4
|
+
import { Value, ValueError } from '@sinclair/typebox/value';
|
|
5
|
+
|
|
6
|
+
const parseErrorSchema = (
|
|
7
|
+
_errors: ValueError[],
|
|
8
|
+
validateAllFieldCriteria: boolean,
|
|
9
|
+
) => {
|
|
10
|
+
const errors: Record<string, FieldError> = {};
|
|
11
|
+
for (; _errors.length; ) {
|
|
12
|
+
const error = _errors[0];
|
|
13
|
+
const { type, message, path } = error;
|
|
14
|
+
const _path = path.substring(1).replace(/\//g, '.');
|
|
15
|
+
|
|
16
|
+
if (!errors[_path]) {
|
|
17
|
+
errors[_path] = { message, type: '' + type };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (validateAllFieldCriteria) {
|
|
21
|
+
const types = errors[_path].types;
|
|
22
|
+
const messages = types && types['' + type];
|
|
23
|
+
|
|
24
|
+
errors[_path] = appendErrors(
|
|
25
|
+
_path,
|
|
26
|
+
validateAllFieldCriteria,
|
|
27
|
+
errors,
|
|
28
|
+
'' + type,
|
|
29
|
+
messages
|
|
30
|
+
? ([] as string[]).concat(messages as string[], error.message)
|
|
31
|
+
: error.message,
|
|
32
|
+
) as FieldError;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_errors.shift();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return errors;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const typeboxResolver: Resolver =
|
|
42
|
+
(schema) => async (values, _, options) => {
|
|
43
|
+
const errors = [...Value.Errors(schema, values)];
|
|
44
|
+
|
|
45
|
+
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
|
|
46
|
+
|
|
47
|
+
if (!errors.length) {
|
|
48
|
+
return {
|
|
49
|
+
errors: {} as FieldErrors,
|
|
50
|
+
values,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
values: {},
|
|
56
|
+
errors: toNestError(
|
|
57
|
+
parseErrorSchema(
|
|
58
|
+
errors,
|
|
59
|
+
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
|
|
60
|
+
),
|
|
61
|
+
options,
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Type } from '@sinclair/typebox';
|
|
2
|
+
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
export type Resolver = <T extends ReturnType<typeof Type.Object>>(
|
|
5
|
+
schema: T,
|
|
6
|
+
) => <TFieldValues extends FieldValues, TContext>(
|
|
7
|
+
values: TFieldValues,
|
|
8
|
+
context: TContext | undefined,
|
|
9
|
+
options: ResolverOptions<TFieldValues>,
|
|
10
|
+
) => Promise<ResolverResult<TFieldValues>>;
|
package/vest/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './vest';
|
|
1
|
+
export * from './vest';
|
|
2
|
+
export * from './types';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
+
import * as Vest from 'vest';
|
|
3
|
+
export type ICreateResult = ReturnType<typeof Vest.create>;
|
|
4
|
+
export type Resolver = (schema: ICreateResult, schemaOptions?: never, factoryOptions?: {
|
|
5
|
+
mode?: 'async' | 'sync';
|
|
6
|
+
rawValues?: boolean;
|
|
7
|
+
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
8
|
+
export type VestErrors = Record<string, string[]>;
|
package/vest/dist/vest.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Resolver } from './types';
|
|
2
|
-
export declare const vestResolver: Resolver;
|
|
1
|
+
import type { Resolver } from './types';
|
|
2
|
+
export declare const vestResolver: Resolver;
|
package/vest/dist/vest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","_context","options","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","mode","promisify"],"mappings":"6JAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,
|
|
1
|
+
{"version":3,"file":"vest.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","_context","options","_temp2","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","promisify","then","e","reject"],"mappings":"6JAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAA,EAC3C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,uBAGE,SAACQ,EAAQC,EAAGC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAA,GAAE,SACzBC,EAAQC,EAAUC,GAAO,IAAIC,IAAAA,EAAAA,SAC5BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAA,EACRX,OAAQiB,EAAAA,YACNpB,EACEkB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAAA,uBAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQX,OAAQ,CAAA,GAAK,EApBGsB,OAAAA,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,IAAOW,QAAAC,QACRE,EAAS,QAACjB,EAAViB,CAAkBd,IAAOe,KAAAZ,GAmBvC,CAAC,MAAAa,GAAAL,OAAAA,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{toNestError as r,validateFieldsNatively as o}from"@hookform/resolvers";import e from"vest/promisify";const s=(r,o)=>{const e={};for(const s in r)e[s]||(e[s]={message:r[s][0],type:""}),o&&(e[s].types=r[s].reduce((r,o,e)=>(r[e]=o)&&r,{}));return e},t=(t,a,i={})=>async(a,n,l)=>{const c="sync"===i.mode?t(a):await e(t)(a);return c.hasErrors()?{values:{},errors:r(s(c.getErrors(),!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:(l.shouldUseNativeValidation&&o({},l),{values:a,errors:{}})};export{t as vestResolver};
|
|
2
|
-
//# sourceMappingURL=vest.modern.
|
|
2
|
+
//# sourceMappingURL=vest.modern.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vest.modern.mjs","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","async","values","_context","options","result","mode","promisify","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively"],"mappings":"4GAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,CAAE,EAC7C,IAAK,MAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,CAACC,EAAKJ,EAASK,KAAWD,EAAIC,GAASL,IAAYI,EACnD,CAAE,IAIR,OAAON,GAGIQ,EACXA,CAACC,EAAQC,EAAGC,EAAkB,KAC9BC,MAAOC,EAAQC,EAAUC,KACvB,MAAMC,EACqB,SAAzBL,EAAgBM,KACZR,EAAOI,SACDK,EAAUT,EAAVS,CAAkBL,GAE9B,OAAIG,EAAOG,YACF,CACLN,OAAQ,CAAE,EACVb,OAAQoB,EACNvB,EACEmB,EAAOK,aACNN,EAAQO,2BACkB,QAAzBP,EAAQQ,cAEZR,KAKNA,EAAQO,2BAA6BE,EAAuB,CAAA,EAAIT,GAEzD,CAAEF,SAAQb,OAAQ,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.module.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","values","_context","options","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","mode","promisify"],"mappings":"4GAKA,IAAMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,
|
|
1
|
+
{"version":3,"file":"vest.module.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","vestResolver","schema","_","resolverOptions","values","_context","options","_temp2","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","promisify","then","e","reject"],"mappings":"4GAKA,IAAMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAA,EAC3C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,EAEaQ,EACX,SAACC,EAAQC,EAAGC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAA,GAAE,SACzBC,EAAQC,EAAUC,GAAO,IAAIC,IAAAA,EAAAA,SAC5BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAA,EACRZ,OAAQkB,EACNrB,EACEmB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQZ,OAAQ,CAAA,GAAK,EApBGuB,OAAAA,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,IAAOW,QAAAC,QACRE,EAAUjB,EAAViB,CAAkBd,IAAOe,KAAAZ,GAmBvC,CAAC,MAAAa,GAAAL,OAAAA,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vest.umd.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","_context","options","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","mode","promisify"],"mappings":"mdAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,
|
|
1
|
+
{"version":3,"file":"vest.umd.js","sources":["../src/vest.ts"],"sourcesContent":["import { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\nimport promisify from 'vest/promisify';\nimport type { VestErrors, Resolver } from './types';\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (const path in vestError) {\n if (!errors[path]) {\n errors[path] = { message: vestError[path][0], type: '' };\n }\n\n if (validateAllFieldCriteria) {\n errors[path].types = vestError[path].reduce<Record<number, string>>(\n (acc, message, index) => (acc[index] = message) && acc,\n {},\n );\n }\n }\n return errors;\n};\n\nexport const vestResolver: Resolver =\n (schema, _, resolverOptions = {}) =>\n async (values, _context, options) => {\n const result =\n resolverOptions.mode === 'sync'\n ? schema(values)\n : await promisify(schema)(values);\n\n if (result.hasErrors()) {\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n result.getErrors(),\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","errors","path","message","type","types","reduce","acc","index","schema","_","resolverOptions","values","_context","options","_temp2","result","hasErrors","toNestError","getErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","Promise","resolve","mode","promisify","then","e","reject"],"mappings":"mdAKMA,EAAmB,SACvBC,EACAC,GAEA,IAAMC,EAAqC,CAAA,EAC3C,IAAK,IAAMC,KAAQH,EACZE,EAAOC,KACVD,EAAOC,GAAQ,CAAEC,QAASJ,EAAUG,GAAM,GAAIE,KAAM,KAGlDJ,IACFC,EAAOC,GAAMG,MAAQN,EAAUG,GAAMI,OACnC,SAACC,EAAKJ,EAASK,GAAU,OAACD,EAAIC,GAASL,IAAYI,CAAG,EACtD,CAAE,IAIR,OAAON,CACT,iBAGE,SAACQ,EAAQC,EAAGC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAA,GAAE,SACzBC,EAAQC,EAAUC,GAAO,IAAIC,IAAAA,EAAAA,SAC5BC,GAKN,OAAIA,EAAOC,YACF,CACLL,OAAQ,CAAA,EACRX,OAAQiB,EAAAA,YACNpB,EACEkB,EAAOG,aACNL,EAAQM,2BACkB,QAAzBN,EAAQO,cAEZP,KAKNA,EAAQM,2BAA6BE,EAAAA,uBAAuB,CAAA,EAAIR,GAEzD,CAAEF,OAAAA,EAAQX,OAAQ,CAAA,GAAK,EApBGsB,OAAAA,QAAAC,QAAN,SAAzBb,EAAgBc,KAAeV,EAC3BN,EAAOG,IAAOW,QAAAC,QACRE,EAAS,QAACjB,EAAViB,CAAkBd,IAAOe,KAAAZ,GAmBvC,CAAC,MAAAa,GAAAL,OAAAA,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, screen
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import user from '@testing-library/user-event';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import * as vest from 'vest';
|
|
@@ -45,7 +45,7 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
test("form's native validation with Vest", async () => {
|
|
48
|
-
const handleSubmit =
|
|
48
|
+
const handleSubmit = vi.fn();
|
|
49
49
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
50
50
|
|
|
51
51
|
// username
|
|
@@ -62,9 +62,7 @@ test("form's native validation with Vest", async () => {
|
|
|
62
62
|
expect(passwordField.validity.valid).toBe(true);
|
|
63
63
|
expect(passwordField.validationMessage).toBe('');
|
|
64
64
|
|
|
65
|
-
await
|
|
66
|
-
user.click(screen.getByText(/submit/i));
|
|
67
|
-
});
|
|
65
|
+
await user.click(screen.getByText(/submit/i));
|
|
68
66
|
|
|
69
67
|
// username
|
|
70
68
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -76,10 +74,8 @@ test("form's native validation with Vest", async () => {
|
|
|
76
74
|
expect(passwordField.validity.valid).toBe(false);
|
|
77
75
|
expect(passwordField.validationMessage).toBe(PASSWORD_SYMBOL_MESSAGE);
|
|
78
76
|
|
|
79
|
-
await
|
|
80
|
-
|
|
81
|
-
user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
82
|
-
});
|
|
77
|
+
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
|
78
|
+
await user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
83
79
|
|
|
84
80
|
// username
|
|
85
81
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, screen
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import user from '@testing-library/user-event';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import * as vest from 'vest';
|
|
@@ -47,18 +47,14 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
test("form's validation with Vest and TypeScript's integration", async () => {
|
|
50
|
-
const handleSubmit =
|
|
50
|
+
const handleSubmit = vi.fn();
|
|
51
51
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
52
52
|
|
|
53
|
-
expect(screen.queryAllByRole(
|
|
53
|
+
expect(screen.queryAllByRole('alert')).toHaveLength(0);
|
|
54
54
|
|
|
55
|
-
await
|
|
56
|
-
user.click(screen.getByText(/submit/i));
|
|
57
|
-
});
|
|
55
|
+
await user.click(screen.getByText(/submit/i));
|
|
58
56
|
|
|
59
|
-
expect(screen.getByText(/Username is required/i)).
|
|
60
|
-
expect(
|
|
61
|
-
screen.getByText(/Password must contain a symbol/i),
|
|
62
|
-
).toBeInTheDocument();
|
|
57
|
+
expect(screen.getByText(/Username is required/i)).toBeVisible();
|
|
58
|
+
expect(screen.getByText(/Password must contain a symbol/i)).toBeVisible();
|
|
63
59
|
expect(handleSubmit).not.toHaveBeenCalled();
|
|
64
60
|
});
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`vestResolver should return all the error messages from vestResolver when validation fails and validateAllFieldCriteria set to true 1`] = `
|
|
4
|
-
|
|
5
|
-
"errors":
|
|
6
|
-
"deepObject":
|
|
7
|
-
"data":
|
|
3
|
+
exports[`vestResolver > should return all the error messages from vestResolver when validation fails and validateAllFieldCriteria set to true 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"deepObject": {
|
|
7
|
+
"data": {
|
|
8
8
|
"message": "deepObject.data is required",
|
|
9
9
|
"ref": undefined,
|
|
10
10
|
"type": "",
|
|
11
|
-
"types":
|
|
11
|
+
"types": {
|
|
12
12
|
"0": "deepObject.data is required",
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
|
-
"password":
|
|
16
|
+
"password": {
|
|
17
17
|
"message": "Password must be at least 5 chars",
|
|
18
|
-
"ref":
|
|
18
|
+
"ref": {
|
|
19
19
|
"name": "password",
|
|
20
20
|
},
|
|
21
21
|
"type": "",
|
|
22
|
-
"types":
|
|
22
|
+
"types": {
|
|
23
23
|
"0": "Password must be at least 5 chars",
|
|
24
24
|
"1": "Password must contain a digit",
|
|
25
25
|
"2": "Password must contain a symbol",
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
|
-
"username":
|
|
28
|
+
"username": {
|
|
29
29
|
"message": "Username is required",
|
|
30
|
-
"ref":
|
|
30
|
+
"ref": {
|
|
31
31
|
"name": "username",
|
|
32
32
|
},
|
|
33
33
|
"type": "",
|
|
34
|
-
"types":
|
|
34
|
+
"types": {
|
|
35
35
|
"0": "Username is required",
|
|
36
36
|
"1": "Must be longer than 3 chars",
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
|
-
"values":
|
|
40
|
+
"values": {},
|
|
41
41
|
}
|
|
42
42
|
`;
|
|
43
43
|
|
|
44
|
-
exports[`vestResolver should return all the error messages from vestResolver when validation fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
|
|
45
|
-
|
|
46
|
-
"errors":
|
|
47
|
-
"deepObject":
|
|
48
|
-
"data":
|
|
44
|
+
exports[`vestResolver > should return all the error messages from vestResolver when validation fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
|
|
45
|
+
{
|
|
46
|
+
"errors": {
|
|
47
|
+
"deepObject": {
|
|
48
|
+
"data": {
|
|
49
49
|
"message": "deepObject.data is required",
|
|
50
50
|
"ref": undefined,
|
|
51
51
|
"type": "",
|
|
52
|
-
"types":
|
|
52
|
+
"types": {
|
|
53
53
|
"0": "deepObject.data is required",
|
|
54
54
|
},
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
|
-
"password":
|
|
57
|
+
"password": {
|
|
58
58
|
"message": "Password must be at least 5 chars",
|
|
59
|
-
"ref":
|
|
59
|
+
"ref": {
|
|
60
60
|
"name": "password",
|
|
61
61
|
},
|
|
62
62
|
"type": "",
|
|
63
|
-
"types":
|
|
63
|
+
"types": {
|
|
64
64
|
"0": "Password must be at least 5 chars",
|
|
65
65
|
"1": "Password must contain a digit",
|
|
66
66
|
"2": "Password must contain a symbol",
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
|
-
"username":
|
|
69
|
+
"username": {
|
|
70
70
|
"message": "Username is required",
|
|
71
|
-
"ref":
|
|
71
|
+
"ref": {
|
|
72
72
|
"name": "username",
|
|
73
73
|
},
|
|
74
74
|
"type": "",
|
|
75
|
-
"types":
|
|
75
|
+
"types": {
|
|
76
76
|
"0": "Username is required",
|
|
77
77
|
"1": "Must be longer than 3 chars",
|
|
78
78
|
},
|
|
79
79
|
},
|
|
80
80
|
},
|
|
81
|
-
"values":
|
|
81
|
+
"values": {},
|
|
82
82
|
}
|
|
83
83
|
`;
|
|
84
84
|
|
|
85
|
-
exports[`vestResolver should return single error message from vestResolver when validation fails and validateAllFieldCriteria set to false 1`] = `
|
|
86
|
-
|
|
87
|
-
"errors":
|
|
88
|
-
"deepObject":
|
|
89
|
-
"data":
|
|
85
|
+
exports[`vestResolver > should return single error message from vestResolver when validation fails and validateAllFieldCriteria set to false 1`] = `
|
|
86
|
+
{
|
|
87
|
+
"errors": {
|
|
88
|
+
"deepObject": {
|
|
89
|
+
"data": {
|
|
90
90
|
"message": "deepObject.data is required",
|
|
91
91
|
"ref": undefined,
|
|
92
92
|
"type": "",
|
|
93
93
|
},
|
|
94
94
|
},
|
|
95
|
-
"password":
|
|
95
|
+
"password": {
|
|
96
96
|
"message": "Password must be at least 5 chars",
|
|
97
|
-
"ref":
|
|
97
|
+
"ref": {
|
|
98
98
|
"name": "password",
|
|
99
99
|
},
|
|
100
100
|
"type": "",
|
|
101
101
|
},
|
|
102
|
-
"username":
|
|
102
|
+
"username": {
|
|
103
103
|
"message": "Username is required",
|
|
104
|
-
"ref":
|
|
104
|
+
"ref": {
|
|
105
105
|
"name": "username",
|
|
106
106
|
},
|
|
107
107
|
"type": "",
|
|
108
108
|
},
|
|
109
109
|
},
|
|
110
|
-
"values":
|
|
110
|
+
"values": {},
|
|
111
111
|
}
|
|
112
112
|
`;
|
|
113
113
|
|
|
114
|
-
exports[`vestResolver should return single error message from vestResolver when validation fails and validateAllFieldCriteria set to false and \`mode: sync\` 1`] = `
|
|
115
|
-
|
|
116
|
-
"errors":
|
|
117
|
-
"deepObject":
|
|
118
|
-
"data":
|
|
114
|
+
exports[`vestResolver > should return single error message from vestResolver when validation fails and validateAllFieldCriteria set to false and \`mode: sync\` 1`] = `
|
|
115
|
+
{
|
|
116
|
+
"errors": {
|
|
117
|
+
"deepObject": {
|
|
118
|
+
"data": {
|
|
119
119
|
"message": "deepObject.data is required",
|
|
120
120
|
"ref": undefined,
|
|
121
121
|
"type": "",
|
|
122
122
|
},
|
|
123
123
|
},
|
|
124
|
-
"password":
|
|
124
|
+
"password": {
|
|
125
125
|
"message": "Password must be at least 5 chars",
|
|
126
|
-
"ref":
|
|
126
|
+
"ref": {
|
|
127
127
|
"name": "password",
|
|
128
128
|
},
|
|
129
129
|
"type": "",
|
|
130
130
|
},
|
|
131
|
-
"username":
|
|
131
|
+
"username": {
|
|
132
132
|
"message": "Username is required",
|
|
133
|
-
"ref":
|
|
133
|
+
"ref": {
|
|
134
134
|
"name": "username",
|
|
135
135
|
},
|
|
136
136
|
"type": "",
|
|
137
137
|
},
|
|
138
138
|
},
|
|
139
|
-
"values":
|
|
139
|
+
"values": {},
|
|
140
140
|
}
|
|
141
141
|
`;
|
package/vest/src/index.ts
CHANGED