@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
|
@@ -1,293 +1,293 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`joiResolver should return a single error from joiResolver when validation fails 1`] = `
|
|
4
|
-
|
|
5
|
-
"errors":
|
|
6
|
-
"birthYear":
|
|
3
|
+
exports[`joiResolver > should return a single error from joiResolver when validation fails 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"birthYear": {
|
|
7
7
|
"message": "\\"birthYear\\" must be a number",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "number.base",
|
|
10
10
|
},
|
|
11
|
-
"email":
|
|
11
|
+
"email": {
|
|
12
12
|
"message": "\\"email\\" is not allowed to be empty",
|
|
13
|
-
"ref":
|
|
13
|
+
"ref": {
|
|
14
14
|
"name": "email",
|
|
15
15
|
},
|
|
16
16
|
"type": "string.empty",
|
|
17
17
|
},
|
|
18
|
-
"enabled":
|
|
18
|
+
"enabled": {
|
|
19
19
|
"message": "\\"enabled\\" is required",
|
|
20
20
|
"ref": undefined,
|
|
21
21
|
"type": "any.required",
|
|
22
22
|
},
|
|
23
|
-
"like":
|
|
24
|
-
|
|
25
|
-
"id":
|
|
23
|
+
"like": [
|
|
24
|
+
{
|
|
25
|
+
"id": {
|
|
26
26
|
"message": "\\"like[0].id\\" must be a number",
|
|
27
27
|
"ref": undefined,
|
|
28
28
|
"type": "number.base",
|
|
29
29
|
},
|
|
30
|
-
"name":
|
|
30
|
+
"name": {
|
|
31
31
|
"message": "\\"like[0].name\\" length must be 4 characters long",
|
|
32
32
|
"ref": undefined,
|
|
33
33
|
"type": "string.length",
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
|
-
"password":
|
|
37
|
+
"password": {
|
|
38
38
|
"message": "\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
39
|
-
"ref":
|
|
39
|
+
"ref": {
|
|
40
40
|
"name": "password",
|
|
41
41
|
},
|
|
42
42
|
"type": "string.pattern.name",
|
|
43
43
|
},
|
|
44
|
-
"tags":
|
|
44
|
+
"tags": {
|
|
45
45
|
"message": "\\"tags\\" is required",
|
|
46
46
|
"ref": undefined,
|
|
47
47
|
"type": "any.required",
|
|
48
48
|
},
|
|
49
|
-
"username":
|
|
49
|
+
"username": {
|
|
50
50
|
"message": "\\"username\\" is required",
|
|
51
|
-
"ref":
|
|
51
|
+
"ref": {
|
|
52
52
|
"name": "username",
|
|
53
53
|
},
|
|
54
54
|
"type": "any.required",
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
|
-
"values":
|
|
57
|
+
"values": {},
|
|
58
58
|
}
|
|
59
59
|
`;
|
|
60
60
|
|
|
61
|
-
exports[`joiResolver should return a single error from joiResolver with \`mode: sync\` when validation fails 1`] = `
|
|
62
|
-
|
|
63
|
-
"errors":
|
|
64
|
-
"birthYear":
|
|
61
|
+
exports[`joiResolver > should return a single error from joiResolver with \`mode: sync\` when validation fails 1`] = `
|
|
62
|
+
{
|
|
63
|
+
"errors": {
|
|
64
|
+
"birthYear": {
|
|
65
65
|
"message": "\\"birthYear\\" must be a number",
|
|
66
66
|
"ref": undefined,
|
|
67
67
|
"type": "number.base",
|
|
68
68
|
},
|
|
69
|
-
"email":
|
|
69
|
+
"email": {
|
|
70
70
|
"message": "\\"email\\" is not allowed to be empty",
|
|
71
|
-
"ref":
|
|
71
|
+
"ref": {
|
|
72
72
|
"name": "email",
|
|
73
73
|
},
|
|
74
74
|
"type": "string.empty",
|
|
75
75
|
},
|
|
76
|
-
"enabled":
|
|
76
|
+
"enabled": {
|
|
77
77
|
"message": "\\"enabled\\" is required",
|
|
78
78
|
"ref": undefined,
|
|
79
79
|
"type": "any.required",
|
|
80
80
|
},
|
|
81
|
-
"like":
|
|
82
|
-
|
|
83
|
-
"id":
|
|
81
|
+
"like": [
|
|
82
|
+
{
|
|
83
|
+
"id": {
|
|
84
84
|
"message": "\\"like[0].id\\" must be a number",
|
|
85
85
|
"ref": undefined,
|
|
86
86
|
"type": "number.base",
|
|
87
87
|
},
|
|
88
|
-
"name":
|
|
88
|
+
"name": {
|
|
89
89
|
"message": "\\"like[0].name\\" length must be 4 characters long",
|
|
90
90
|
"ref": undefined,
|
|
91
91
|
"type": "string.length",
|
|
92
92
|
},
|
|
93
93
|
},
|
|
94
94
|
],
|
|
95
|
-
"password":
|
|
95
|
+
"password": {
|
|
96
96
|
"message": "\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
97
|
-
"ref":
|
|
97
|
+
"ref": {
|
|
98
98
|
"name": "password",
|
|
99
99
|
},
|
|
100
100
|
"type": "string.pattern.name",
|
|
101
101
|
},
|
|
102
|
-
"tags":
|
|
102
|
+
"tags": {
|
|
103
103
|
"message": "\\"tags\\" is required",
|
|
104
104
|
"ref": undefined,
|
|
105
105
|
"type": "any.required",
|
|
106
106
|
},
|
|
107
|
-
"username":
|
|
107
|
+
"username": {
|
|
108
108
|
"message": "\\"username\\" is required",
|
|
109
|
-
"ref":
|
|
109
|
+
"ref": {
|
|
110
110
|
"name": "username",
|
|
111
111
|
},
|
|
112
112
|
"type": "any.required",
|
|
113
113
|
},
|
|
114
114
|
},
|
|
115
|
-
"values":
|
|
115
|
+
"values": {},
|
|
116
116
|
}
|
|
117
117
|
`;
|
|
118
118
|
|
|
119
|
-
exports[`joiResolver should return all the errors from joiResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
120
|
-
|
|
121
|
-
"errors":
|
|
122
|
-
"birthYear":
|
|
119
|
+
exports[`joiResolver > should return all the errors from joiResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
120
|
+
{
|
|
121
|
+
"errors": {
|
|
122
|
+
"birthYear": {
|
|
123
123
|
"message": "\\"birthYear\\" must be a number",
|
|
124
124
|
"ref": undefined,
|
|
125
125
|
"type": "number.base",
|
|
126
|
-
"types":
|
|
126
|
+
"types": {
|
|
127
127
|
"number.base": "\\"birthYear\\" must be a number",
|
|
128
128
|
},
|
|
129
129
|
},
|
|
130
|
-
"email":
|
|
130
|
+
"email": {
|
|
131
131
|
"message": "\\"email\\" is not allowed to be empty",
|
|
132
|
-
"ref":
|
|
132
|
+
"ref": {
|
|
133
133
|
"name": "email",
|
|
134
134
|
},
|
|
135
135
|
"type": "string.empty",
|
|
136
|
-
"types":
|
|
136
|
+
"types": {
|
|
137
137
|
"string.empty": "\\"email\\" is not allowed to be empty",
|
|
138
138
|
},
|
|
139
139
|
},
|
|
140
|
-
"enabled":
|
|
140
|
+
"enabled": {
|
|
141
141
|
"message": "\\"enabled\\" is required",
|
|
142
142
|
"ref": undefined,
|
|
143
143
|
"type": "any.required",
|
|
144
|
-
"types":
|
|
144
|
+
"types": {
|
|
145
145
|
"any.required": "\\"enabled\\" is required",
|
|
146
146
|
},
|
|
147
147
|
},
|
|
148
|
-
"like":
|
|
149
|
-
|
|
150
|
-
"id":
|
|
148
|
+
"like": [
|
|
149
|
+
{
|
|
150
|
+
"id": {
|
|
151
151
|
"message": "\\"like[0].id\\" must be a number",
|
|
152
152
|
"ref": undefined,
|
|
153
153
|
"type": "number.base",
|
|
154
|
-
"types":
|
|
154
|
+
"types": {
|
|
155
155
|
"number.base": "\\"like[0].id\\" must be a number",
|
|
156
156
|
},
|
|
157
157
|
},
|
|
158
|
-
"name":
|
|
158
|
+
"name": {
|
|
159
159
|
"message": "\\"like[0].name\\" length must be 4 characters long",
|
|
160
160
|
"ref": undefined,
|
|
161
161
|
"type": "string.length",
|
|
162
|
-
"types":
|
|
162
|
+
"types": {
|
|
163
163
|
"string.length": "\\"like[0].name\\" length must be 4 characters long",
|
|
164
164
|
"string.pattern.base": "\\"like[0].name\\" with value \\"r\\" fails to match the required pattern: /a/",
|
|
165
165
|
},
|
|
166
166
|
},
|
|
167
167
|
},
|
|
168
168
|
],
|
|
169
|
-
"password":
|
|
169
|
+
"password": {
|
|
170
170
|
"message": "\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
171
|
-
"ref":
|
|
171
|
+
"ref": {
|
|
172
172
|
"name": "password",
|
|
173
173
|
},
|
|
174
174
|
"type": "string.pattern.name",
|
|
175
|
-
"types":
|
|
175
|
+
"types": {
|
|
176
176
|
"string.min": "\\"password\\" length must be at least 8 characters long",
|
|
177
|
-
"string.pattern.name":
|
|
177
|
+
"string.pattern.name": [
|
|
178
178
|
"\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
179
179
|
"\\"password\\" with value \\"___\\" fails to match the One lowercase character pattern",
|
|
180
180
|
"\\"password\\" with value \\"___\\" fails to match the One number pattern",
|
|
181
181
|
],
|
|
182
182
|
},
|
|
183
183
|
},
|
|
184
|
-
"tags":
|
|
184
|
+
"tags": {
|
|
185
185
|
"message": "\\"tags\\" is required",
|
|
186
186
|
"ref": undefined,
|
|
187
187
|
"type": "any.required",
|
|
188
|
-
"types":
|
|
188
|
+
"types": {
|
|
189
189
|
"any.required": "\\"tags\\" is required",
|
|
190
190
|
},
|
|
191
191
|
},
|
|
192
|
-
"username":
|
|
192
|
+
"username": {
|
|
193
193
|
"message": "\\"username\\" is required",
|
|
194
|
-
"ref":
|
|
194
|
+
"ref": {
|
|
195
195
|
"name": "username",
|
|
196
196
|
},
|
|
197
197
|
"type": "any.required",
|
|
198
|
-
"types":
|
|
198
|
+
"types": {
|
|
199
199
|
"any.required": "\\"username\\" is required",
|
|
200
200
|
},
|
|
201
201
|
},
|
|
202
202
|
},
|
|
203
|
-
"values":
|
|
203
|
+
"values": {},
|
|
204
204
|
}
|
|
205
205
|
`;
|
|
206
206
|
|
|
207
|
-
exports[`joiResolver should return all the errors from joiResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
|
|
208
|
-
|
|
209
|
-
"errors":
|
|
210
|
-
"birthYear":
|
|
207
|
+
exports[`joiResolver > should return all the errors from joiResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
|
|
208
|
+
{
|
|
209
|
+
"errors": {
|
|
210
|
+
"birthYear": {
|
|
211
211
|
"message": "\\"birthYear\\" must be a number",
|
|
212
212
|
"ref": undefined,
|
|
213
213
|
"type": "number.base",
|
|
214
|
-
"types":
|
|
214
|
+
"types": {
|
|
215
215
|
"number.base": "\\"birthYear\\" must be a number",
|
|
216
216
|
},
|
|
217
217
|
},
|
|
218
|
-
"email":
|
|
218
|
+
"email": {
|
|
219
219
|
"message": "\\"email\\" is not allowed to be empty",
|
|
220
|
-
"ref":
|
|
220
|
+
"ref": {
|
|
221
221
|
"name": "email",
|
|
222
222
|
},
|
|
223
223
|
"type": "string.empty",
|
|
224
|
-
"types":
|
|
224
|
+
"types": {
|
|
225
225
|
"string.empty": "\\"email\\" is not allowed to be empty",
|
|
226
226
|
},
|
|
227
227
|
},
|
|
228
|
-
"enabled":
|
|
228
|
+
"enabled": {
|
|
229
229
|
"message": "\\"enabled\\" is required",
|
|
230
230
|
"ref": undefined,
|
|
231
231
|
"type": "any.required",
|
|
232
|
-
"types":
|
|
232
|
+
"types": {
|
|
233
233
|
"any.required": "\\"enabled\\" is required",
|
|
234
234
|
},
|
|
235
235
|
},
|
|
236
|
-
"like":
|
|
237
|
-
|
|
238
|
-
"id":
|
|
236
|
+
"like": [
|
|
237
|
+
{
|
|
238
|
+
"id": {
|
|
239
239
|
"message": "\\"like[0].id\\" must be a number",
|
|
240
240
|
"ref": undefined,
|
|
241
241
|
"type": "number.base",
|
|
242
|
-
"types":
|
|
242
|
+
"types": {
|
|
243
243
|
"number.base": "\\"like[0].id\\" must be a number",
|
|
244
244
|
},
|
|
245
245
|
},
|
|
246
|
-
"name":
|
|
246
|
+
"name": {
|
|
247
247
|
"message": "\\"like[0].name\\" length must be 4 characters long",
|
|
248
248
|
"ref": undefined,
|
|
249
249
|
"type": "string.length",
|
|
250
|
-
"types":
|
|
250
|
+
"types": {
|
|
251
251
|
"string.length": "\\"like[0].name\\" length must be 4 characters long",
|
|
252
252
|
"string.pattern.base": "\\"like[0].name\\" with value \\"r\\" fails to match the required pattern: /a/",
|
|
253
253
|
},
|
|
254
254
|
},
|
|
255
255
|
},
|
|
256
256
|
],
|
|
257
|
-
"password":
|
|
257
|
+
"password": {
|
|
258
258
|
"message": "\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
259
|
-
"ref":
|
|
259
|
+
"ref": {
|
|
260
260
|
"name": "password",
|
|
261
261
|
},
|
|
262
262
|
"type": "string.pattern.name",
|
|
263
|
-
"types":
|
|
263
|
+
"types": {
|
|
264
264
|
"string.min": "\\"password\\" length must be at least 8 characters long",
|
|
265
|
-
"string.pattern.name":
|
|
265
|
+
"string.pattern.name": [
|
|
266
266
|
"\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
267
267
|
"\\"password\\" with value \\"___\\" fails to match the One lowercase character pattern",
|
|
268
268
|
"\\"password\\" with value \\"___\\" fails to match the One number pattern",
|
|
269
269
|
],
|
|
270
270
|
},
|
|
271
271
|
},
|
|
272
|
-
"tags":
|
|
272
|
+
"tags": {
|
|
273
273
|
"message": "\\"tags\\" is required",
|
|
274
274
|
"ref": undefined,
|
|
275
275
|
"type": "any.required",
|
|
276
|
-
"types":
|
|
276
|
+
"types": {
|
|
277
277
|
"any.required": "\\"tags\\" is required",
|
|
278
278
|
},
|
|
279
279
|
},
|
|
280
|
-
"username":
|
|
280
|
+
"username": {
|
|
281
281
|
"message": "\\"username\\" is required",
|
|
282
|
-
"ref":
|
|
282
|
+
"ref": {
|
|
283
283
|
"name": "username",
|
|
284
284
|
},
|
|
285
285
|
"type": "any.required",
|
|
286
|
-
"types":
|
|
286
|
+
"types": {
|
|
287
287
|
"any.required": "\\"username\\" is required",
|
|
288
288
|
},
|
|
289
289
|
},
|
|
290
290
|
},
|
|
291
|
-
"values":
|
|
291
|
+
"values": {},
|
|
292
292
|
}
|
|
293
293
|
`;
|
package/joi/src/__tests__/joi.ts
CHANGED
|
@@ -5,8 +5,8 @@ const shouldUseNativeValidation = false;
|
|
|
5
5
|
|
|
6
6
|
describe('joiResolver', () => {
|
|
7
7
|
it('should return values from joiResolver when validation pass', async () => {
|
|
8
|
-
const validateAsyncSpy =
|
|
9
|
-
const validateSpy =
|
|
8
|
+
const validateAsyncSpy = vi.spyOn(schema, 'validateAsync');
|
|
9
|
+
const validateSpy = vi.spyOn(schema, 'validate');
|
|
10
10
|
|
|
11
11
|
const result = await joiResolver(schema)(validData, undefined, {
|
|
12
12
|
fields,
|
|
@@ -19,8 +19,8 @@ describe('joiResolver', () => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('should return values from joiResolver with `mode: sync` when validation pass', async () => {
|
|
22
|
-
const validateAsyncSpy =
|
|
23
|
-
const validateSpy =
|
|
22
|
+
const validateAsyncSpy = vi.spyOn(schema, 'validateAsync');
|
|
23
|
+
const validateSpy = vi.spyOn(schema, 'validate');
|
|
24
24
|
|
|
25
25
|
const result = await joiResolver(schema, undefined, {
|
|
26
26
|
mode: 'sync',
|
|
@@ -41,8 +41,8 @@ describe('joiResolver', () => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it('should return a single error from joiResolver with `mode: sync` when validation fails', async () => {
|
|
44
|
-
const validateAsyncSpy =
|
|
45
|
-
const validateSpy =
|
|
44
|
+
const validateAsyncSpy = vi.spyOn(schema, 'validateAsync');
|
|
45
|
+
const validateSpy = vi.spyOn(schema, 'validate');
|
|
46
46
|
|
|
47
47
|
const result = await joiResolver(schema, undefined, {
|
|
48
48
|
mode: 'sync',
|
|
@@ -79,8 +79,8 @@ describe('joiResolver', () => {
|
|
|
79
79
|
|
|
80
80
|
it('should return values from joiResolver when validation pass and pass down the Joi context', async () => {
|
|
81
81
|
const context = { value: 'context' };
|
|
82
|
-
const validateAsyncSpy =
|
|
83
|
-
const validateSpy =
|
|
82
|
+
const validateAsyncSpy = vi.spyOn(schema, 'validateAsync');
|
|
83
|
+
const validateSpy = vi.spyOn(schema, 'validate');
|
|
84
84
|
|
|
85
85
|
const result = await joiResolver(schema)(validData, context, {
|
|
86
86
|
fields,
|
package/nope/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './nope';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './nope';
|
|
2
|
+
export * from './types';
|
package/nope/dist/nope.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Resolver } from './types';
|
|
2
|
-
export declare const nopeResolver: Resolver;
|
|
1
|
+
import type { Resolver } from './types';
|
|
2
|
+
export declare const nopeResolver: Resolver;
|
package/nope/dist/nope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nope.js","sources":["../src/nope.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestError(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"qCAKMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,
|
|
1
|
+
{"version":3,"file":"nope.js","sources":["../src/nope.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestError(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"qCAKMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,EAAI,IAAIK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,CACT,EAAGL,EACL,uBAGE,SACEU,EACAC,GAEC,YAFY,IAAbA,IAAAA,EAAgB,CACdC,YAAY,aAGfC,EAAQC,EAASC,GAChB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAIK,EACK,CAAEH,OAAQ,CAAE,EAAEd,OAAQmB,EAAAA,YAAYpB,EAAYkB,GAASD,KAGhEA,EAAQI,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEL,GAEzD,CAAEF,OAAAA,EAAQd,OAAQ,IAC3B,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";const o=(r,e={},s="")=>Object.keys(r).reduce((e,t)=>{const a=s?`${s}.${t}`:t,l=r[t];return"string"==typeof l?e[a]={message:l}:o(l,e,a),e},e),s=(s,t={abortEarly:!1})=>(a,l,n)=>{const i=s.validate(a,l,t);return i?{values:{},errors:r(o(i),n)}:(n.shouldUseNativeValidation&&e({},n),{values:a,errors:{}})};export{s as nopeResolver};
|
|
2
|
-
//# sourceMappingURL=nope.modern.
|
|
2
|
+
//# sourceMappingURL=nope.modern.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nope.modern.mjs","sources":["../src/nope.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestError(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","nopeResolver","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"8EAKA,MAAMA,EAAcA,CAClBC,EACAC,EAA4B,CAAA,EAC5BC,EAAO,KAEAC,OAAOC,KAAKJ,GAAQK,OAAO,CAACC,EAAKC,KACtC,MAAMC,EAAQN,EAAO,GAAGA,KAAQK,IAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,GACNL,GAGQU,EACXA,CACEC,EACAC,EAAgB,CACdC,YAAY,KAGhB,CAACC,EAAQC,EAASC,KAChB,MAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAIK,EACK,CAAEH,OAAQ,CAAE,EAAEf,OAAQoB,EAAYrB,EAAYmB,GAASD,KAGhEA,EAAQI,2BAA6BC,EAAuB,GAAIL,GAEzD,CAAEF,SAAQf,OAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nope.module.js","sources":["../src/nope.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestError(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","nopeResolver","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"8EAKA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,
|
|
1
|
+
{"version":3,"file":"nope.module.js","sources":["../src/nope.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestError(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","nopeResolver","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"8EAKA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,EAAI,IAAIK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,CACT,EAAGL,EACL,EAEaU,EACX,SACEC,EACAC,GAEC,YAFY,IAAbA,IAAAA,EAAgB,CACdC,YAAY,aAGfC,EAAQC,EAASC,GAChB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAIK,EACK,CAAEH,OAAQ,CAAE,EAAEf,OAAQoB,EAAYrB,EAAYmB,GAASD,KAGhEA,EAAQI,2BAA6BC,EAAuB,CAAE,EAAEL,GAEzD,CAAEF,OAAAA,EAAQf,OAAQ,IAC3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nope.umd.js","sources":["../src/nope.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestError(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"0TAKA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,
|
|
1
|
+
{"version":3,"file":"nope.umd.js","sources":["../src/nope.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestError(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"0TAKA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,EAAI,IAAIK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,CACT,EAAGL,EACL,iBAGE,SACEU,EACAC,GAEC,YAFY,IAAbA,IAAAA,EAAgB,CACdC,YAAY,aAGfC,EAAQC,EAASC,GAChB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAIK,EACK,CAAEH,OAAQ,CAAE,EAAEd,OAAQmB,EAAAA,YAAYpB,EAAYkB,GAASD,KAGhEA,EAAQI,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEL,GAEzD,CAAEF,OAAAA,EAAQd,OAAQ,IAC3B,CAAC"}
|
package/nope/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
-
import type { NopeObject } from 'nope-validator/lib/cjs/NopeObject';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
mode?: 'async' | 'sync';
|
|
7
|
-
rawValues?: boolean;
|
|
8
|
-
}) => <TFieldValues extends FieldValues, TContext extends Context>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
|
|
9
|
-
export {};
|
|
1
|
+
import type { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
+
import type { NopeObject } from 'nope-validator/lib/cjs/NopeObject';
|
|
3
|
+
type ValidateOptions = Parameters<NopeObject['validate']>[2];
|
|
4
|
+
type Context = Parameters<NopeObject['validate']>[1];
|
|
5
|
+
export type Resolver = <T extends NopeObject>(schema: T, schemaOptions?: ValidateOptions, resolverOptions?: {
|
|
6
|
+
mode?: 'async' | 'sync';
|
|
7
|
+
rawValues?: boolean;
|
|
8
|
+
}) => <TFieldValues extends FieldValues, TContext extends Context>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
|
|
9
|
+
export {};
|
|
@@ -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 Nope from 'nope-validator';
|
|
@@ -41,7 +41,7 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
test("form's native validation with Nope", async () => {
|
|
44
|
-
const handleSubmit =
|
|
44
|
+
const handleSubmit = vi.fn();
|
|
45
45
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
46
46
|
|
|
47
47
|
// username
|
|
@@ -58,9 +58,7 @@ test("form's native validation with Nope", async () => {
|
|
|
58
58
|
expect(passwordField.validity.valid).toBe(true);
|
|
59
59
|
expect(passwordField.validationMessage).toBe('');
|
|
60
60
|
|
|
61
|
-
await
|
|
62
|
-
user.click(screen.getByText(/submit/i));
|
|
63
|
-
});
|
|
61
|
+
await user.click(screen.getByText(/submit/i));
|
|
64
62
|
|
|
65
63
|
// username
|
|
66
64
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -72,10 +70,8 @@ test("form's native validation with Nope", async () => {
|
|
|
72
70
|
expect(passwordField.validity.valid).toBe(false);
|
|
73
71
|
expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
|
|
74
72
|
|
|
75
|
-
await
|
|
76
|
-
|
|
77
|
-
user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
78
|
-
});
|
|
73
|
+
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
|
74
|
+
await user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
79
75
|
|
|
80
76
|
// username
|
|
81
77
|
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 Nope from 'nope-validator';
|
|
@@ -43,14 +43,12 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
test("form's validation with Yup and TypeScript's integration", async () => {
|
|
46
|
-
const handleSubmit =
|
|
46
|
+
const handleSubmit = vi.fn();
|
|
47
47
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
48
48
|
|
|
49
|
-
expect(screen.queryAllByRole(
|
|
49
|
+
expect(screen.queryAllByRole('alert')).toHaveLength(0);
|
|
50
50
|
|
|
51
|
-
await
|
|
52
|
-
user.click(screen.getByText(/submit/i));
|
|
53
|
-
});
|
|
51
|
+
await user.click(screen.getByText(/submit/i));
|
|
54
52
|
|
|
55
53
|
expect(screen.getAllByText(/This field is required/i)).toHaveLength(2);
|
|
56
54
|
expect(handleSubmit).not.toHaveBeenCalled();
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`nopeResolver should return a single error from nopeResolver when validation fails 1`] = `
|
|
4
|
-
|
|
5
|
-
"errors":
|
|
6
|
-
"birthYear":
|
|
3
|
+
exports[`nopeResolver > should return a single error from nopeResolver when validation fails 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"birthYear": {
|
|
7
7
|
"message": "The field is not a valid number",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
},
|
|
10
|
-
"like":
|
|
11
|
-
"id":
|
|
10
|
+
"like": {
|
|
11
|
+
"id": {
|
|
12
12
|
"message": "The field is not a valid number",
|
|
13
13
|
"ref": undefined,
|
|
14
14
|
},
|
|
15
|
-
"name":
|
|
15
|
+
"name": {
|
|
16
16
|
"message": "This field is required",
|
|
17
17
|
"ref": undefined,
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
|
-
"password":
|
|
20
|
+
"password": {
|
|
21
21
|
"message": "One uppercase character",
|
|
22
|
-
"ref":
|
|
22
|
+
"ref": {
|
|
23
23
|
"name": "password",
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
|
-
"repeatPassword":
|
|
26
|
+
"repeatPassword": {
|
|
27
27
|
"message": "This field is required",
|
|
28
28
|
"ref": undefined,
|
|
29
29
|
},
|
|
30
|
-
"tags":
|
|
30
|
+
"tags": {
|
|
31
31
|
"message": "One or more elements are of invalid type",
|
|
32
32
|
"ref": undefined,
|
|
33
33
|
},
|
|
34
|
-
"username":
|
|
34
|
+
"username": {
|
|
35
35
|
"message": "This field is required",
|
|
36
|
-
"ref":
|
|
36
|
+
"ref": {
|
|
37
37
|
"name": "username",
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
|
-
"values":
|
|
41
|
+
"values": {},
|
|
42
42
|
}
|
|
43
43
|
`;
|
|
@@ -6,7 +6,7 @@ const shouldUseNativeValidation = false;
|
|
|
6
6
|
|
|
7
7
|
describe('nopeResolver', () => {
|
|
8
8
|
it('should return values from nopeResolver when validation pass', async () => {
|
|
9
|
-
const schemaSpy =
|
|
9
|
+
const schemaSpy = vi.spyOn(schema, 'validate');
|
|
10
10
|
|
|
11
11
|
const result = await nopeResolver(schema)(validData, undefined, {
|
|
12
12
|
fields,
|