@hookform/resolvers 1.3.4 → 1.3.8
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 +13 -5
- package/dist/convertArrayToPathName.d.ts +1 -0
- package/dist/ie11/joi/index.d.ts +1 -0
- package/dist/ie11/{joi.d.ts → joi/joi.d.ts} +0 -0
- package/dist/ie11/joi/joi.js +2 -0
- package/dist/ie11/joi/joi.js.map +1 -0
- package/dist/ie11/superstruct/index.d.ts +1 -0
- package/dist/ie11/{superstruct.d.ts → superstruct/superstruct.d.ts} +0 -0
- package/dist/ie11/superstruct/superstruct.js +2 -0
- package/dist/ie11/superstruct/superstruct.js.map +1 -0
- package/dist/ie11/vest/index.d.ts +1 -0
- package/dist/ie11/{vest.d.ts → vest/vest.d.ts} +0 -0
- package/dist/ie11/vest/vest.js +2 -0
- package/dist/ie11/vest/vest.js.map +1 -0
- package/dist/ie11/yup/index.d.ts +1 -0
- package/dist/{yup.d.ts → ie11/yup/yup.d.ts} +6 -5
- package/dist/ie11/yup/yup.js +2 -0
- package/dist/ie11/yup/yup.js.map +1 -0
- package/dist/ie11/zod/index.d.ts +1 -0
- package/dist/ie11/{zod.d.ts → zod/zod.d.ts} +0 -0
- package/dist/ie11/zod/zod.js +2 -0
- package/dist/ie11/zod/zod.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/resolvers.js +2 -0
- package/dist/resolvers.js.map +1 -0
- package/dist/resolvers.mjs +2 -0
- package/dist/resolvers.modern.js +2 -0
- package/dist/resolvers.modern.js.map +1 -0
- package/dist/resolvers.module.js +2 -0
- package/dist/resolvers.module.js.map +1 -0
- package/dist/resolvers.umd.js +2 -0
- package/dist/resolvers.umd.js.map +1 -0
- package/joi/dist/index.d.ts +1 -0
- package/{dist → joi/dist}/joi.d.ts +3 -3
- package/joi/dist/joi.js +2 -0
- package/joi/dist/joi.js.map +1 -0
- package/joi/dist/joi.mjs +2 -0
- package/joi/dist/joi.modern.js +2 -0
- package/joi/dist/joi.modern.js.map +1 -0
- package/joi/dist/joi.module.js +2 -0
- package/joi/dist/joi.module.js.map +1 -0
- package/joi/dist/joi.umd.js +2 -0
- package/joi/dist/joi.umd.js.map +1 -0
- package/joi/package.json +17 -0
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +13 -0
- package/joi/src/__tests__/joi.ts +49 -0
- package/joi/src/index.ts +1 -0
- package/joi/src/joi.ts +76 -0
- package/package.json +83 -39
- package/superstruct/dist/index.d.ts +1 -0
- package/{dist → superstruct/dist}/superstruct.d.ts +5 -5
- package/superstruct/dist/superstruct.js +2 -0
- package/superstruct/dist/superstruct.js.map +1 -0
- package/superstruct/dist/superstruct.mjs +2 -0
- package/superstruct/dist/superstruct.modern.js +2 -0
- package/superstruct/dist/superstruct.modern.js.map +1 -0
- package/superstruct/dist/superstruct.module.js +2 -0
- package/superstruct/dist/superstruct.module.js.map +1 -0
- package/superstruct/dist/superstruct.umd.js +2 -0
- package/superstruct/dist/superstruct.umd.js.map +1 -0
- package/superstruct/package.json +17 -0
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +33 -0
- package/superstruct/src/__tests__/superstruct.ts +45 -0
- package/superstruct/src/index.ts +1 -0
- package/superstruct/src/superstruct.ts +68 -0
- package/vest/dist/index.d.ts +1 -0
- package/{dist → vest/dist}/vest.d.ts +5 -5
- package/vest/dist/vest.js +2 -0
- package/vest/dist/vest.js.map +1 -0
- package/vest/dist/vest.mjs +2 -0
- package/vest/dist/vest.modern.js +2 -0
- package/vest/dist/vest.modern.js.map +1 -0
- package/vest/dist/vest.module.js +2 -0
- package/vest/dist/vest.module.js.map +1 -0
- package/vest/dist/vest.umd.js +2 -0
- package/vest/dist/vest.umd.js.map +1 -0
- package/vest/package.json +17 -0
- package/vest/src/__tests__/vest.ts +120 -0
- package/vest/src/index.ts +1 -0
- package/vest/src/vest.ts +59 -0
- package/yup/dist/index.d.ts +1 -0
- package/{dist/ie11 → yup/dist}/yup.d.ts +2 -1
- package/yup/dist/yup.js +2 -0
- package/yup/dist/yup.js.map +1 -0
- package/yup/dist/yup.mjs +2 -0
- package/yup/dist/yup.modern.js +2 -0
- package/yup/dist/yup.modern.js.map +1 -0
- package/yup/dist/yup.module.js +2 -0
- package/yup/dist/yup.module.js.map +1 -0
- package/yup/dist/yup.umd.js +2 -0
- package/yup/dist/yup.umd.js.map +1 -0
- package/yup/package.json +17 -0
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +119 -0
- package/yup/src/__tests__/yup.ts +311 -0
- package/yup/src/index.ts +1 -0
- package/yup/src/yup.ts +96 -0
- package/zod/dist/index.d.ts +1 -0
- package/{dist → zod/dist}/zod.d.ts +4 -4
- package/zod/dist/zod.js +2 -0
- package/zod/dist/zod.js.map +1 -0
- package/zod/dist/zod.mjs +2 -0
- package/zod/dist/zod.modern.js +2 -0
- package/zod/dist/zod.modern.js.map +1 -0
- package/zod/dist/zod.module.js +2 -0
- package/zod/dist/zod.module.js.map +1 -0
- package/zod/dist/zod.umd.js +2 -0
- package/zod/dist/zod.umd.js.map +1 -0
- package/zod/package.json +17 -0
- package/zod/src/__tests__/__snapshots__/zod.ts.snap +194 -0
- package/zod/src/__tests__/zod.ts +131 -0
- package/zod/src/index.ts +1 -0
- package/zod/src/zod.ts +84 -0
- package/CHANGELOG.md +0 -7
- package/dist/ie11/_virtual/_tslib.js +0 -2
- package/dist/ie11/_virtual/_tslib.js.map +0 -1
- package/dist/ie11/joi.js +0 -2
- package/dist/ie11/joi.js.map +0 -1
- package/dist/ie11/superstruct.js +0 -2
- package/dist/ie11/superstruct.js.map +0 -1
- package/dist/ie11/utils/convertArrayToPathName.d.ts +0 -2
- package/dist/ie11/utils/convertArrayToPathName.js +0 -2
- package/dist/ie11/utils/convertArrayToPathName.js.map +0 -1
- package/dist/ie11/vest.js +0 -2
- package/dist/ie11/vest.js.map +0 -1
- package/dist/ie11/yup.js +0 -2
- package/dist/ie11/yup.js.map +0 -1
- package/dist/ie11/zod.js +0 -2
- package/dist/ie11/zod.js.map +0 -1
- package/dist/joi.js +0 -38
- package/dist/joi.js.map +0 -1
- package/dist/superstruct.js +0 -36
- package/dist/superstruct.js.map +0 -1
- package/dist/umd/index.js +0 -2
- package/dist/umd/index.js.map +0 -1
- package/dist/utils/convertArrayToPathName.d.ts +0 -2
- package/dist/utils/convertArrayToPathName.js +0 -6
- package/dist/utils/convertArrayToPathName.js.map +0 -1
- package/dist/vest.js +0 -26
- package/dist/vest.js.map +0 -1
- package/dist/yup.js +0 -59
- package/dist/yup.js.map +0 -1
- package/dist/zod.js +0 -44
- package/dist/zod.js.map +0 -1
- package/joi.d.ts +0 -1
- package/joi.js +0 -1
- package/superstruct.d.ts +0 -1
- package/superstruct.js +0 -1
- package/vest.d.ts +0 -1
- package/vest.js +0 -1
- package/yup.d.ts +0 -1
- package/yup.js +0 -1
- package/zod.d.ts +0 -1
- package/zod.js +0 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`zodResolver should get errors with zod error map 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"errors": Object {
|
|
6
|
+
"author": Object {
|
|
7
|
+
"id": Object {
|
|
8
|
+
"message": "Expected number, received string",
|
|
9
|
+
"type": "invalid_type",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
"count": Object {
|
|
13
|
+
"message": "Value should be greater than 0",
|
|
14
|
+
"type": "too_small",
|
|
15
|
+
},
|
|
16
|
+
"date": Object {
|
|
17
|
+
"message": "Expected date, received string",
|
|
18
|
+
"type": "invalid_type",
|
|
19
|
+
},
|
|
20
|
+
"id": Object {
|
|
21
|
+
"message": "Expected number, received string",
|
|
22
|
+
"type": "invalid_type",
|
|
23
|
+
},
|
|
24
|
+
"password": Object {
|
|
25
|
+
"message": "Should be at least 8 characters",
|
|
26
|
+
"type": "too_small",
|
|
27
|
+
},
|
|
28
|
+
"tags": Array [
|
|
29
|
+
Object {
|
|
30
|
+
"message": "This ain't a string!",
|
|
31
|
+
"type": "invalid_type",
|
|
32
|
+
},
|
|
33
|
+
Object {
|
|
34
|
+
"message": "This ain't a string!",
|
|
35
|
+
"type": "invalid_type",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
"title": Object {
|
|
39
|
+
"message": "This ain't a string!",
|
|
40
|
+
"type": "invalid_type",
|
|
41
|
+
},
|
|
42
|
+
"url": Object {
|
|
43
|
+
"message": "This ain't a string!",
|
|
44
|
+
"type": "invalid_type",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
"values": Object {},
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
exports[`zodResolver should get errors without validate all criteria fields 1`] = `
|
|
52
|
+
Object {
|
|
53
|
+
"errors": Object {
|
|
54
|
+
"": Object {
|
|
55
|
+
"message": "Unrecognized key(s) in object: 'unknownProperty'",
|
|
56
|
+
"type": "unrecognized_keys",
|
|
57
|
+
},
|
|
58
|
+
"author": Object {
|
|
59
|
+
"id": Object {
|
|
60
|
+
"message": "Expected number, received string",
|
|
61
|
+
"type": "invalid_type",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
"confirm": Object {
|
|
65
|
+
"message": "Passwords don't match",
|
|
66
|
+
"type": "custom_error",
|
|
67
|
+
},
|
|
68
|
+
"date": Object {
|
|
69
|
+
"message": "Expected date, received string",
|
|
70
|
+
"type": "invalid_type",
|
|
71
|
+
},
|
|
72
|
+
"id": Object {
|
|
73
|
+
"message": "Expected number, received string",
|
|
74
|
+
"type": "invalid_type",
|
|
75
|
+
},
|
|
76
|
+
"password": Object {
|
|
77
|
+
"message": "Should be at least 8 characters",
|
|
78
|
+
"type": "too_small",
|
|
79
|
+
},
|
|
80
|
+
"tags": Array [
|
|
81
|
+
Object {
|
|
82
|
+
"message": "Expected string, received number",
|
|
83
|
+
"type": "invalid_type",
|
|
84
|
+
},
|
|
85
|
+
Object {
|
|
86
|
+
"message": "Expected string, received boolean",
|
|
87
|
+
"type": "invalid_type",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
"title": Object {
|
|
91
|
+
"message": "Required",
|
|
92
|
+
"type": "invalid_type",
|
|
93
|
+
},
|
|
94
|
+
"url": Object {
|
|
95
|
+
"message": "Required",
|
|
96
|
+
"type": "invalid_type",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
"values": Object {},
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
exports[`zodResolver should get errors without validate all criteria fields 2`] = `
|
|
104
|
+
Object {
|
|
105
|
+
"errors": Object {
|
|
106
|
+
"author": Object {
|
|
107
|
+
"id": Object {
|
|
108
|
+
"message": "Expected number, received string",
|
|
109
|
+
"type": "invalid_type",
|
|
110
|
+
"types": Object {
|
|
111
|
+
"invalid_type": "Expected number, received string",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
"count": Object {
|
|
116
|
+
"message": "Value should be greater than 0",
|
|
117
|
+
"type": "too_small",
|
|
118
|
+
"types": Object {
|
|
119
|
+
"too_small": "Value should be greater than 0",
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
"date": Object {
|
|
123
|
+
"message": "Expected date, received string",
|
|
124
|
+
"type": "invalid_type",
|
|
125
|
+
"types": Object {
|
|
126
|
+
"invalid_type": "Expected date, received string",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
"id": Object {
|
|
130
|
+
"message": "Expected number, received string",
|
|
131
|
+
"type": "invalid_type",
|
|
132
|
+
"types": Object {
|
|
133
|
+
"invalid_type": "Expected number, received string",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
"likedUsers": Object {
|
|
137
|
+
"0": Object {
|
|
138
|
+
"id": Object {
|
|
139
|
+
"message": "Expected number, received string",
|
|
140
|
+
"type": "invalid_type",
|
|
141
|
+
"types": Object {
|
|
142
|
+
"invalid_type": "Expected number, received string",
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
"message": "Invalid input",
|
|
147
|
+
"type": "invalid_union",
|
|
148
|
+
"types": Object {
|
|
149
|
+
"invalid_type": "Expected undefined, received array",
|
|
150
|
+
"invalid_union": "Invalid input",
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
"password": Object {
|
|
154
|
+
"message": "Should be at least 8 characters",
|
|
155
|
+
"type": "too_small",
|
|
156
|
+
"types": Object {
|
|
157
|
+
"invalid_string": "Invalid",
|
|
158
|
+
"too_small": "Should be at least 8 characters",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
"tags": Array [
|
|
162
|
+
Object {
|
|
163
|
+
"message": "Expected string, received number",
|
|
164
|
+
"type": "invalid_type",
|
|
165
|
+
"types": Object {
|
|
166
|
+
"invalid_type": "Expected string, received number",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
Object {
|
|
170
|
+
"message": "Expected string, received boolean",
|
|
171
|
+
"type": "invalid_type",
|
|
172
|
+
"types": Object {
|
|
173
|
+
"invalid_type": "Expected string, received boolean",
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
"title": Object {
|
|
178
|
+
"message": "Required",
|
|
179
|
+
"type": "invalid_type",
|
|
180
|
+
"types": Object {
|
|
181
|
+
"invalid_type": "Required",
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
"url": Object {
|
|
185
|
+
"message": "Required",
|
|
186
|
+
"type": "invalid_type",
|
|
187
|
+
"types": Object {
|
|
188
|
+
"invalid_type": "Required",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
"values": Object {},
|
|
193
|
+
}
|
|
194
|
+
`;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { zodResolver } from '..';
|
|
3
|
+
|
|
4
|
+
const schema = z
|
|
5
|
+
.object({
|
|
6
|
+
id: z.number(),
|
|
7
|
+
title: z.string(),
|
|
8
|
+
isPublished: z.boolean().optional(),
|
|
9
|
+
tags: z.array(z.string()),
|
|
10
|
+
author: z.object({
|
|
11
|
+
id: z.number(),
|
|
12
|
+
}),
|
|
13
|
+
likedUsers: z
|
|
14
|
+
.array(
|
|
15
|
+
z.object({
|
|
16
|
+
id: z.number(),
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
.optional(),
|
|
20
|
+
count: z.number().positive().int(),
|
|
21
|
+
date: z.date(),
|
|
22
|
+
url: z.string().url(),
|
|
23
|
+
password: z
|
|
24
|
+
.string()
|
|
25
|
+
.min(8)
|
|
26
|
+
.regex(RegExp('(.*[a-z].*)'))
|
|
27
|
+
.regex(RegExp('(.*[A-Z].*)'))
|
|
28
|
+
.regex(RegExp('(.*\\d.*)'))
|
|
29
|
+
.regex(RegExp('[!@#$%^&*(),.?":{}|<>]')),
|
|
30
|
+
confirm: z.string(),
|
|
31
|
+
})
|
|
32
|
+
.refine((data) => data.password === data.confirm, {
|
|
33
|
+
message: "Passwords don't match",
|
|
34
|
+
path: ['confirm'], // set path of error
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('zodResolver', () => {
|
|
38
|
+
it('should get values', async () => {
|
|
39
|
+
const data = {
|
|
40
|
+
id: 2,
|
|
41
|
+
title: 'test',
|
|
42
|
+
tags: ['news', 'features'],
|
|
43
|
+
author: {
|
|
44
|
+
id: 1,
|
|
45
|
+
},
|
|
46
|
+
likedUsers: [{ id: 1 }],
|
|
47
|
+
count: 4,
|
|
48
|
+
date: new Date(),
|
|
49
|
+
url: 'https://github.com/react-hook-form/resolvers',
|
|
50
|
+
password: '[}tehk6Uor',
|
|
51
|
+
confirm: '[}tehk6Uor',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
expect(await zodResolver(schema)(data)).toEqual({
|
|
55
|
+
values: data,
|
|
56
|
+
errors: {},
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should get errors without validate all criteria fields', async () => {
|
|
61
|
+
const data: any = {
|
|
62
|
+
id: '2',
|
|
63
|
+
tags: [2, true],
|
|
64
|
+
author: {
|
|
65
|
+
id: '1',
|
|
66
|
+
},
|
|
67
|
+
count: 1,
|
|
68
|
+
date: 'date',
|
|
69
|
+
password: 'R',
|
|
70
|
+
confirm: 'A',
|
|
71
|
+
unknownProperty: '',
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
expect(await zodResolver(schema)(data)).toMatchSnapshot();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should get errors without validate all criteria fields', async () => {
|
|
78
|
+
const data: any = {
|
|
79
|
+
id: '2',
|
|
80
|
+
tags: [2, true],
|
|
81
|
+
author: {
|
|
82
|
+
id: '1',
|
|
83
|
+
},
|
|
84
|
+
likedUsers: [{ id: '1' }],
|
|
85
|
+
count: -5,
|
|
86
|
+
date: 'date',
|
|
87
|
+
password: 'R',
|
|
88
|
+
confirm: 'R',
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
expect(await zodResolver(schema)(data, undefined, true)).toMatchSnapshot();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should get errors with zod error map', async () => {
|
|
95
|
+
const data: any = {
|
|
96
|
+
id: '2',
|
|
97
|
+
tags: [2, true],
|
|
98
|
+
author: {
|
|
99
|
+
id: '1',
|
|
100
|
+
},
|
|
101
|
+
count: -5,
|
|
102
|
+
date: 'date',
|
|
103
|
+
password: 'R',
|
|
104
|
+
confirm: 'R',
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const errorMap: z.ZodErrorMap = (error, ctx) => {
|
|
108
|
+
if (error.message) {
|
|
109
|
+
return { message: error.message };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
switch (error.code) {
|
|
113
|
+
case z.ZodErrorCode.invalid_type:
|
|
114
|
+
if (error.expected === 'string') {
|
|
115
|
+
return { message: `This ain't a string!` };
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case z.ZodErrorCode.custom_error:
|
|
119
|
+
const params = error.params || {};
|
|
120
|
+
if (params.myField) {
|
|
121
|
+
return { message: `Bad input: ${params.myField}` };
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { message: ctx.defaultError };
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
expect(await zodResolver(schema, { errorMap })(data)).toMatchSnapshot();
|
|
130
|
+
});
|
|
131
|
+
});
|
package/zod/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './zod';
|
package/zod/src/zod.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendErrors,
|
|
3
|
+
Resolver,
|
|
4
|
+
ResolverError,
|
|
5
|
+
ResolverSuccess,
|
|
6
|
+
transformToNestObject,
|
|
7
|
+
} from 'react-hook-form';
|
|
8
|
+
import * as z from 'zod';
|
|
9
|
+
import { ParseParams } from 'zod/lib/src/parser';
|
|
10
|
+
import { convertArrayToPathName } from '@hookform/resolvers';
|
|
11
|
+
|
|
12
|
+
const parseErrorSchema = (
|
|
13
|
+
zodError: z.ZodError,
|
|
14
|
+
validateAllFieldCriteria: boolean,
|
|
15
|
+
) => {
|
|
16
|
+
if (zodError.isEmpty) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const errors = [...zodError.errors];
|
|
21
|
+
let previous: Record<string, any> = {};
|
|
22
|
+
|
|
23
|
+
for (const error of errors) {
|
|
24
|
+
const { path, message, code: type } = error;
|
|
25
|
+
const currentPath = convertArrayToPathName(path);
|
|
26
|
+
|
|
27
|
+
if ('unionErrors' in error) {
|
|
28
|
+
for (const subErrors of error.unionErrors.map((e) => e.errors)) {
|
|
29
|
+
errors.push(...subErrors);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
previous = {
|
|
34
|
+
...previous,
|
|
35
|
+
...(path
|
|
36
|
+
? previous[currentPath] && validateAllFieldCriteria
|
|
37
|
+
? {
|
|
38
|
+
[currentPath]: appendErrors(
|
|
39
|
+
currentPath,
|
|
40
|
+
validateAllFieldCriteria,
|
|
41
|
+
previous,
|
|
42
|
+
type,
|
|
43
|
+
message,
|
|
44
|
+
),
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
[currentPath]: previous[currentPath] || {
|
|
48
|
+
message,
|
|
49
|
+
type,
|
|
50
|
+
...(validateAllFieldCriteria
|
|
51
|
+
? {
|
|
52
|
+
types: { [type]: message || true },
|
|
53
|
+
}
|
|
54
|
+
: {}),
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
: {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return previous;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const zodResolver = <T extends z.ZodSchema<any, any>>(
|
|
65
|
+
schema: T,
|
|
66
|
+
options?: ParseParams,
|
|
67
|
+
): Resolver<z.infer<T>> => async (
|
|
68
|
+
values,
|
|
69
|
+
_,
|
|
70
|
+
validateAllFieldCriteria = false,
|
|
71
|
+
) => {
|
|
72
|
+
const result = schema.safeParse(values, options);
|
|
73
|
+
|
|
74
|
+
if (result.success) {
|
|
75
|
+
return { values: result.data, errors: {} } as ResolverSuccess<z.infer<T>>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
values: {},
|
|
80
|
+
errors: transformToNestObject(
|
|
81
|
+
parseErrorSchema(result.error, validateAllFieldCriteria),
|
|
82
|
+
),
|
|
83
|
+
} as ResolverError<z.infer<T>>;
|
|
84
|
+
};
|
package/CHANGELOG.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# @hookform/resolvers
|
|
2
|
-
|
|
3
|
-
## 1.3.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [`a7beb92`](https://github.com/react-hook-form/resolvers/commit/a7beb924686eb286e6c29dd766ddb56d0422d661) [#95](https://github.com/react-hook-form/resolvers/pull/95) Thanks [@benallfree](https://github.com/benallfree)! - esm support to fix bundler incompatibility
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";function e(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,a=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(o)throw o.error}}return i}Object.defineProperty(exports,"__esModule",{value:!0}),exports.__assign=function(){return exports.__assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},exports.__assign.apply(this,arguments)},exports.__awaiter=function(e,t,r,n){return new(r||(r=Promise))((function(o,a){function i(e){try{u(n.next(e))}catch(e){a(e)}}function l(e){try{u(n.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,l)}u((n=n.apply(e,t||[])).next())}))},exports.__generator=function(e,t){var r,n,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(a){return function(l){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}},exports.__read=e,exports.__spread=function(){for(var t=[],r=0;r<arguments.length;r++)t=t.concat(e(arguments[r]));return t},exports.__values=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};
|
|
2
|
-
//# sourceMappingURL=_tslib.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_tslib.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/ie11/joi.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_tslib.js"),r=require("react-hook-form/dist/index.ie11"),t=require("./utils/convertArrayToPathName.js"),s=function(s,a){return Array.isArray(s.details)?s.details.reduce((function(s,i){var n,o,u,c=i.path,_=i.message,d=void 0===_?"":_,v=i.type,l=t.default(c);return e.__assign(e.__assign({},s),c?s[l]&&a?((n={})[l]=r.appendErrors(l,a,s,v,d),n):((o={})[l]=s[l]||e.__assign({message:d,type:v},a?{types:(u={},u[v]=d||!0,u)}:{}),o):{})}),{}):[]};exports.joiResolver=function(t,a){return void 0===a&&(a={abortEarly:!1}),function(i,n,o){return void 0===o&&(o=!1),e.__awaiter(void 0,void 0,void 0,(function(){var u,c;return e.__generator(this,(function(_){switch(_.label){case 0:return _.trys.push([0,2,,3]),c={},[4,t.validateAsync(i,e.__assign(e.__assign({},a),{context:n}))];case 1:return[2,(c.values=_.sent(),c.errors={},c)];case 2:return u=_.sent(),[2,{values:{},errors:r.transformToNestObject(s(u,o))}];case 3:return[2]}}))}))}};
|
|
2
|
-
//# sourceMappingURL=joi.js.map
|
package/dist/ie11/joi.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"joi.js","sources":["../../src/joi.ts"],"sourcesContent":["import {\n appendErrors,\n transformToNestObject,\n Resolver,\n FieldValues,\n} from 'react-hook-form';\nimport * as Joi from 'joi';\nimport convertArrayToPathName from './utils/convertArrayToPathName';\n\nconst parseErrorSchema = (\n error: Joi.ValidationError,\n validateAllFieldCriteria: boolean,\n) =>\n Array.isArray(error.details)\n ? error.details.reduce(\n (previous: Record<string, any>, { path, message = '', type }) => {\n const currentPath = convertArrayToPathName(path);\n\n return {\n ...previous,\n ...(path\n ? previous[currentPath] && validateAllFieldCriteria\n ? {\n [currentPath]: appendErrors(\n currentPath,\n validateAllFieldCriteria,\n previous,\n type,\n message,\n ),\n }\n : {\n [currentPath]: previous[currentPath] || {\n message,\n type,\n ...(validateAllFieldCriteria\n ? {\n types: { [type]: message || true },\n }\n : {}),\n },\n }\n : {}),\n };\n },\n {},\n )\n : [];\n\nexport const joiResolver = <TFieldValues extends FieldValues>(\n schema: Joi.Schema,\n options: Joi.AsyncValidationOptions = {\n abortEarly: false,\n },\n): Resolver<TFieldValues> => async (\n values,\n context,\n validateAllFieldCriteria = false,\n) => {\n try {\n return {\n values: await schema.validateAsync(values, {\n ...options,\n context,\n }),\n errors: {},\n };\n } catch (e) {\n return {\n values: {},\n errors: transformToNestObject(\n parseErrorSchema(e, validateAllFieldCriteria),\n ),\n };\n }\n};\n"],"names":["parseErrorSchema","error","validateAllFieldCriteria","Array","isArray","details","reduce","previous","_a","path","_e","message","type","currentPath","convertArrayToPathName","appendErrors","types","_d","schema","options","abortEarly","values","context","validateAsync","_b","errors","transformToNestObject","e_1"],"mappings":"sMASMA,EAAmB,SACvBC,EACAC,GAEA,OAAAC,MAAMC,QAAQH,EAAMI,SAChBJ,EAAMI,QAAQC,QACZ,SAACC,EAA+BC,aAAEC,SAAMC,YAAAC,aAAU,KAAIC,SAC9CC,EAAcC,UAAuBL,GAE3C,gCACKF,GACCE,EACAF,EAASM,IAAgBX,UAEpBW,GAAcE,eACbF,EACAX,EACAK,EACAK,EACAD,cAIDE,GAAcN,EAASM,gBACtBF,UACAC,QACIV,EACA,CACEc,YAASC,EAACL,GAAOD,IAAW,MAE9B,OAGV,MAGR,IAEF,wBAEqB,SACzBO,EACAC,GAG2B,oBAH3BA,GACEC,YAAY,IAEa,SAC3BC,EACAC,EACApB,uBAAAA,yHAIY,qCAAMgB,EAAOK,cAAcF,2BAC9BF,IACHG,qBAHJ,UACEd,SAAQgB,SAIRhB,SAAQ,cAGV,qBAAO,CACLa,OAAQ,GACRI,OAAQC,wBACN1B,EAAiB2B,EAAGzB"}
|
package/dist/ie11/superstruct.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_tslib.js"),r=require("react-hook-form/dist/index.ie11"),s=require("./utils/convertArrayToPathName.js"),t=require("superstruct"),u=function(t,u){return t.failures().reduce((function(t,a){var i,n,o,l=a.path,c=a.message,v=void 0===c?"":c,_=a.type,d=s.default(l);return e.__assign(e.__assign({},t),l?t[d]&&u?((i={})[d]=r.appendErrors(d,u,t,_||"",v),i):((n={})[d]=t[d]||e.__assign({message:v,type:_},u?{types:(o={},o[_||""]=v||!0,o)}:{}),n):{})}),{})};exports.superstructResolver=function(s,a){return function(i,n,o){void 0===o&&(o=!1);var l=e.__read(t.validate(i,s,a),2),c=l[0],v=l[1];return null!=c?{values:{},errors:r.transformToNestObject(u(c,o))}:{values:v,errors:{}}}};
|
|
2
|
-
//# sourceMappingURL=superstruct.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.js","sources":["../../src/superstruct.ts"],"sourcesContent":["import {\n appendErrors,\n transformToNestObject,\n Resolver,\n ResolverSuccess,\n ResolverError,\n} from 'react-hook-form';\nimport { StructError, validate, Struct, Infer } from 'superstruct';\nimport convertArrayToPathName from './utils/convertArrayToPathName';\n\nconst parseErrorSchema = (\n error: StructError,\n validateAllFieldCriteria: boolean,\n) =>\n error\n .failures()\n .reduce((previous: Record<string, any>, { path, message = '', type }) => {\n const currentPath = convertArrayToPathName(path);\n return {\n ...previous,\n ...(path\n ? previous[currentPath] && validateAllFieldCriteria\n ? {\n [currentPath]: appendErrors(\n currentPath,\n validateAllFieldCriteria,\n previous,\n type || '',\n message,\n ),\n }\n : {\n [currentPath]: previous[currentPath] || {\n message,\n type,\n ...(validateAllFieldCriteria\n ? {\n types: { [type || '']: message || true },\n }\n : {}),\n },\n }\n : {}),\n };\n }, {});\n\ntype Options = Parameters<typeof validate>[2];\n\nexport const superstructResolver = <T extends Struct<any, any>>(\n schema: T,\n options?: Options,\n): Resolver<Infer<T>> => (values, _, validateAllFieldCriteria = false) => {\n const [errors, result] = validate(values, schema, options);\n\n if (errors != null) {\n return {\n values: {},\n errors: transformToNestObject(\n parseErrorSchema(errors, validateAllFieldCriteria),\n ),\n } as ResolverError<Infer<T>>;\n }\n\n return {\n values: result,\n errors: {},\n } as ResolverSuccess<Infer<T>>;\n};\n"],"names":["parseErrorSchema","error","validateAllFieldCriteria","failures","reduce","previous","_a","path","_e","message","type","currentPath","convertArrayToPathName","appendErrors","types","_d","schema","options","values","_","__read","validate","errors","result","transformToNestObject"],"mappings":"+NAUMA,EAAmB,SACvBC,EACAC,GAEA,OAAAD,EACGE,WACAC,QAAO,SAACC,EAA+BC,aAAEC,SAAMC,YAAAC,aAAU,KAAIC,SACtDC,EAAcC,UAAuBL,GAC3C,gCACKF,GACCE,EACAF,EAASM,IAAgBT,UAEpBS,GAAcE,eACbF,EACAT,EACAG,EACAK,GAAQ,GACRD,cAIDE,GAAcN,EAASM,gBACtBF,UACAC,QACIR,EACA,CACEY,YAASC,EAACL,GAAQ,IAAKD,IAAW,MAEpC,OAGV,MAEL,iCAI4B,SACjCO,EACAC,GACuB,OAAA,SAACC,EAAQC,EAAGjB,gBAAAA,MAC7B,IAAAI,EAAAc,SAAmBC,WAASH,EAAQF,EAAQC,MAA3CK,OAAQC,OAEf,OAAc,MAAVD,EACK,CACLJ,OAAQ,GACRI,OAAQE,wBACNxB,EAAiBsB,EAAQpB,KAKxB,CACLgB,OAAQK,EACRD,OAAQ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertArrayToPathName.js","sources":["../../../src/utils/convertArrayToPathName.ts"],"sourcesContent":["export default (paths: (string | number)[]): string =>\n paths\n .reduce(\n (previous, path: string | number, index): string =>\n `${previous}${\n typeof path === 'string'\n ? `${index > 0 ? '.' : ''}${path}`\n : `[${path}]`\n }`,\n '',\n )\n .toString();\n"],"names":["paths","reduce","previous","path","index","toString"],"mappings":"6FAAgBA,GACd,OAAAA,EACGC,QACC,SAACC,EAAUC,EAAuBC,GAChC,OAAGF,GACe,iBAATC,GACAC,EAAQ,EAAI,IAAM,IAAKD,EAC1B,IAAIA,SAEZ,IAEDE"}
|
package/dist/ie11/vest.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("./_virtual/_tslib.js"),e=require("react-hook-form/dist/index.ie11"),t=function(e,t){return Object.entries(e).reduce((function(e,n){var s,i=r.__read(n,2),o=i[0],u=i[1];return r.__assign(r.__assign({},e),((s={})[o]=r.__assign({type:"",message:u[0]},t?{types:u.reduce((function(e,t,n){var s;return r.__assign(r.__assign({},e),((s={})[n]=t,s))}),{})}:{}),s))}),{})};exports.vestResolver=function(n,s,i){return void 0===i&&(i=!1),function(s){return r.__awaiter(void 0,void 0,void 0,(function(){var o,u;return r.__generator(this,(function(a){switch(a.label){case 0:return _=n,[4,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new Promise((function(t){return _.apply(void 0,r.__spread(e)).done(t)}))}(s)];case 1:return o=a.sent(),u=o.getErrors(),o.hasErrors()?[2,{values:{},errors:e.transformToNestObject(t(u,i))}]:[2,{values:s,errors:{}}]}var _}))}))}};
|
|
2
|
-
//# sourceMappingURL=vest.js.map
|
package/dist/ie11/vest.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vest.js","sources":["../../src/vest.ts"],"sourcesContent":["import { FieldValues, Resolver, transformToNestObject } from 'react-hook-form';\nimport * as Vest from 'vest';\n\ntype VestErrors = Record<string, string[]>;\n\ntype ICreateResult = ReturnType<typeof Vest.create>;\n\ntype Promisify = <T extends ICreateResult, K>(\n fn: T,\n) => (args: K) => Promise<Vest.IVestResult>;\n\nconst promisify: Promisify = (validatorFn) => (...args) =>\n new Promise((resolve) => validatorFn(...args).done(resolve as Vest.DoneCB));\n\nconst parseErrorSchema = (\n vestError: VestErrors,\n validateAllFieldCriteria: boolean,\n) => {\n return Object.entries(vestError).reduce((prev, [key, value]) => {\n return {\n ...prev,\n [key]: {\n type: '',\n message: value[0],\n ...(validateAllFieldCriteria\n ? {\n types: value.reduce((prev, message, index) => {\n return {\n ...prev,\n [index]: message,\n };\n }, {}),\n }\n : {}),\n },\n };\n }, {});\n};\n\nexport const vestResolver = <TFieldValues extends FieldValues>(\n schema: ICreateResult,\n _: any = {},\n validateAllFieldCriteria = false,\n): Resolver<TFieldValues> => async (values) => {\n const validateSchema = promisify(schema);\n const result = await validateSchema(values);\n const errors = result.getErrors();\n\n if (!result.hasErrors()) {\n return { values: values as any, errors: {} };\n }\n\n return {\n values: {},\n errors: transformToNestObject(\n parseErrorSchema(errors, validateAllFieldCriteria),\n ),\n };\n};\n"],"names":["parseErrorSchema","vestError","validateAllFieldCriteria","Object","entries","reduce","prev","_a","_c","__read","key","value","type","message","types","index","schema","_","values","validatorFn","_i","args","Promise","resolve","done","validateSchema","result","errors","getErrors","hasErrors","transformToNestObject"],"mappings":"uJAcMA,EAAmB,SACvBC,EACAC,GAEA,OAAOC,OAAOC,QAAQH,GAAWI,QAAO,SAACC,EAAMC,SAAAC,EAAAC,cAACC,OAAKC,OACnD,gCACKL,WACFI,eACCE,KAAM,GACNC,QAASF,EAAM,IACXT,EACA,CACEY,MAAOH,EAAMN,QAAO,SAACC,EAAMO,EAASE,SAClC,gCACKT,WACFS,GAAQF,QAEV,KAEL,UAGP,0BAGuB,SAC1BG,EACAC,EACAf,GAC2B,oBAD3BA,MAC2B,SAAOgB,6HAEnB,OAlCaC,EAiCKH,KAjCW,eAAC,aAAAI,mBAAAA,IAAAC,kBAC7C,OAAA,IAAIC,SAAQ,SAACC,GAAY,OAAAJ,0BAAeE,IAAMG,KAAKD,MAiC9BE,CAAeP,WAGpC,OAHMQ,EAASnB,SACToB,EAASD,EAAOE,YAEjBF,EAAOG,eAIL,CACLX,OAAQ,GACRS,OAAQG,wBACN9B,EAAiB2B,EAAQzB,SANpB,CAAEgB,OAAQA,EAAeS,OAAQ,KAtCf,IAACR"}
|
package/dist/ie11/yup.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_tslib.js"),r=require("react-hook-form/dist/index.ie11");exports.yupResolver=function(s,t){return void 0===t&&(t={abortEarly:!1}),function(n,a,i){return void 0===i&&(i=!1),e.__awaiter(void 0,void 0,void 0,(function(){var o,_,u;return e.__generator(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),t.context&&process.env.NODE_ENV,u={},[4,s.validate(n,e.__assign(e.__assign({},t),{context:a}))];case 1:return[2,(u.values=c.sent(),u.errors={},u)];case 2:return o=c.sent(),_=function(r,s){var t;return Array.isArray(r.inner)&&r.inner.length?r.inner.reduce((function(r,t){var n,a,i=t.path,o=t.message,_=t.type,u=r[i]&&r[i].types||{},c=i||_;return e.__assign(e.__assign({},r),c?((n={})[c]=e.__assign(e.__assign({},r[c]||{message:o,type:_}),s?{types:e.__assign(e.__assign({},u),(a={},a[_]=u[_]?e.__spread([].concat(u[_]),[o]):o,a))}:{}),n):{})}),{}):((t={})[r.path]={message:r.message,type:r.type},t)}(o,i),[2,{values:{},errors:r.transformToNestObject(_)}];case 3:return[2]}}))}))}};
|
|
2
|
-
//# sourceMappingURL=yup.js.map
|
package/dist/ie11/yup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"yup.js","sources":["../../src/yup.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { Resolver, transformToNestObject, FieldValues } from 'react-hook-form';\nimport Yup from 'yup';\n\n/**\n * From 0.32.0, Yup add TypeScript support and `path` typing is optional that's why we have `@ts-expect-error`\n * FYI: `path`: a string, indicating where there error was thrown. `path` is empty at the root level.\n * react-hook-form's values are object so path is defined\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) => {\n return Array.isArray(error.inner) && error.inner.length\n ? error.inner.reduce(\n (previous: Record<string, any>, { path, message, type }) => {\n // @ts-expect-error\n const previousTypes = (previous[path] && previous[path].types) || {};\n const key = path || type;\n\n return {\n ...previous,\n ...(key\n ? {\n [key]: {\n ...(previous[key] || {\n message,\n type,\n }),\n ...(validateAllFieldCriteria\n ? {\n types: {\n ...previousTypes,\n // @ts-expect-error\n [type]: previousTypes[type]\n ? // @ts-expect-error\n [...[].concat(previousTypes[type]), message]\n : message,\n },\n }\n : {}),\n },\n }\n : {}),\n };\n },\n {},\n )\n : {\n // @ts-expect-error\n [error.path]: { message: error.message, type: error.type },\n };\n};\n\ntype ValidateOptions<T extends Yup.AnyObjectSchema> = Parameters<\n T['validate']\n>[1];\n\nexport const yupResolver = <TFieldValues extends FieldValues>(\n schema: Yup.AnyObjectSchema,\n options: ValidateOptions<Yup.AnyObjectSchema> = {\n abortEarly: false,\n },\n): Resolver<TFieldValues> => async (\n values,\n context,\n validateAllFieldCriteria = false,\n) => {\n try {\n if (options.context && process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n return {\n values: await schema.validate(values, {\n ...options,\n context,\n }),\n errors: {},\n };\n } catch (e) {\n const parsedErrors = parseErrorSchema(e, validateAllFieldCriteria);\n return {\n values: {},\n errors: transformToNestObject(parsedErrors),\n };\n }\n};\n"],"names":["schema","options","abortEarly","values","context","validateAllFieldCriteria","process","env","NODE_ENV","validate","_a","_b","parsedErrors","error","Array","isArray","inner","length","reduce","previous","path","message","type","previousTypes","types","key","concat","parseErrorSchema","e_1","errors","transformToNestObject"],"mappings":"2KA2D2B,SACzBA,EACAC,GAG2B,oBAH3BA,GACEC,YAAY,IAEa,SAC3BC,EACAC,EACAC,uBAAAA,2HAUY,6BAPNJ,EAAQG,SAAWE,QAAQC,IAAIC,iBAOnBR,EAAOS,SAASN,2BACzBF,IACHG,qBAHJ,UACEM,SAAQC,SAIRD,SAAQ,cAIV,kBADME,EA1Ee,SACvBC,EACAR,SAEA,OAAOS,MAAMC,QAAQF,EAAMG,QAAUH,EAAMG,MAAMC,OAC7CJ,EAAMG,MAAME,QACV,SAACC,EAA+BT,WAAEU,SAAMC,YAASC,SAEzCC,EAAiBJ,EAASC,IAASD,EAASC,GAAMI,OAAU,GAC5DC,EAAML,GAAQE,EAEpB,gCACKH,GACCM,UAEGA,4BACKN,EAASM,IAAQ,CACnBJ,UACAC,SAEEjB,EACA,CACEmB,+BACKD,WAEFD,GAAOC,EAAcD,cAEd,GAAGI,OAAOH,EAAcD,KAAQD,IACpCA,OAGR,OAGR,MAGR,YAICR,EAAMO,MAAO,CAAEC,QAASR,EAAMQ,QAASC,KAAMT,EAAMS,SAiCnCK,CAAiBC,EAAGvB,MAClC,CACLF,OAAQ,GACR0B,OAAQC,wBAAsBlB"}
|
package/dist/ie11/zod.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("./_virtual/_tslib.js"),e=require("react-hook-form/dist/index.ie11"),t=require("./utils/convertArrayToPathName.js"),a=function(a,o){var n,s,i,u,l,v,_;if(a.isEmpty)return{};var f=r.__spread(a.errors),c={};try{for(var d=r.__values(f),p=d.next();!p.done;p=d.next()){var y=p.value,h=y.path,m=y.message,x=y.code,g=t.default(h);if("unionErrors"in y)try{for(var j=(i=void 0,r.__values(y.unionErrors.map((function(r){return r.errors})))),E=j.next();!E.done;E=j.next()){var b=E.value;f.push.apply(f,r.__spread(b))}}catch(r){i={error:r}}finally{try{E&&!E.done&&(u=j.return)&&u.call(j)}finally{if(i)throw i.error}}c=r.__assign(r.__assign({},c),h?c[g]&&o?((l={})[g]=e.appendErrors(g,o,c,x,m),l):((v={})[g]=c[g]||r.__assign({message:m,type:x},o?{types:(_={},_[x]=m||!0,_)}:{}),v):{})}}catch(r){n={error:r}}finally{try{p&&!p.done&&(s=d.return)&&s.call(d)}finally{if(n)throw n.error}}return c};exports.zodResolver=function(t,o){return function(n,s,i){return void 0===i&&(i=!1),r.__awaiter(void 0,void 0,void 0,(function(){var s;return r.__generator(this,(function(r){return(s=t.safeParse(n,o)).success?[2,{values:s.data,errors:{}}]:[2,{values:{},errors:e.transformToNestObject(a(s.error,i))}]}))}))}};
|
|
2
|
-
//# sourceMappingURL=zod.js.map
|
package/dist/ie11/zod.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sources":["../../src/zod.ts"],"sourcesContent":["import {\n appendErrors,\n Resolver,\n ResolverError,\n ResolverSuccess,\n transformToNestObject,\n} from 'react-hook-form';\nimport * as z from 'zod';\nimport { ParseParams } from 'zod/lib/src/parser';\nimport convertArrayToPathName from './utils/convertArrayToPathName';\n\nconst parseErrorSchema = (\n zodError: z.ZodError,\n validateAllFieldCriteria: boolean,\n) => {\n if (zodError.isEmpty) {\n return {};\n }\n\n const errors = [...zodError.errors];\n let previous: Record<string, any> = {};\n\n for (const error of errors) {\n const { path, message, code: type } = error;\n const currentPath = convertArrayToPathName(path);\n\n if ('unionErrors' in error) {\n for (const subErrors of error.unionErrors.map((e) => e.errors)) {\n errors.push(...subErrors);\n }\n }\n\n previous = {\n ...previous,\n ...(path\n ? previous[currentPath] && validateAllFieldCriteria\n ? {\n [currentPath]: appendErrors(\n currentPath,\n validateAllFieldCriteria,\n previous,\n type,\n message,\n ),\n }\n : {\n [currentPath]: previous[currentPath] || {\n message,\n type,\n ...(validateAllFieldCriteria\n ? {\n types: { [type]: message || true },\n }\n : {}),\n },\n }\n : {}),\n };\n }\n\n return previous;\n};\n\nexport const zodResolver = <T extends z.ZodSchema<any, any>>(\n schema: T,\n options?: ParseParams,\n): Resolver<z.infer<T>> => async (\n values,\n _,\n validateAllFieldCriteria = false,\n) => {\n const result = schema.safeParse(values, options);\n\n if (result.success) {\n return { values: result.data, errors: {} } as ResolverSuccess<z.infer<T>>;\n }\n\n return {\n values: {},\n errors: transformToNestObject(\n parseErrorSchema(result.error, validateAllFieldCriteria),\n ),\n } as ResolverError<z.infer<T>>;\n};\n"],"names":["parseErrorSchema","zodError","validateAllFieldCriteria","isEmpty","errors","previous","errors_1","__values","error","path","message","type","currentPath","convertArrayToPathName","_f","unionErrors","map","e","subErrors","push","appendErrors","types","_e","schema","options","values","_","result","safeParse","success","data","transformToNestObject"],"mappings":"sMAWMA,EAAmB,SACvBC,EACAC,qBAEA,GAAID,EAASE,QACX,MAAO,GAGT,IAAMC,aAAaH,EAASG,QACxBC,EAAgC,OAEpC,IAAoB,IAAAC,EAAAC,WAAAH,iCAAQ,CAAvB,IAAMI,UACDC,EAA8BD,OAAxBE,EAAwBF,UAATG,EAASH,OAChCI,EAAcC,UAAuBJ,GAE3C,GAAI,gBAAiBD,MACnB,IAAwB,IAAAM,YAAAP,WAAAC,EAAMO,YAAYC,KAAI,SAACC,GAAM,OAAAA,EAAEb,0CAAS,CAA3D,IAAMc,UACTd,EAAOe,WAAPf,aAAec,sGAInBb,2BACKA,GACCI,EACAJ,EAASO,IAAgBV,UAEpBU,GAAcQ,eACbR,EACAV,EACAG,EACAM,EACAD,cAIDE,GAAcP,EAASO,gBACtBF,UACAC,QACIT,EACA,CACEmB,YAASC,EAACX,GAAOD,IAAW,MAE9B,OAGV,sGAIR,OAAOL,uBAGkB,SACzBkB,EACAC,GACyB,OAAA,SACzBC,EACAC,EACAxB,uBAAAA,gGAIA,OAFMyB,EAASJ,EAAOK,UAAUH,EAAQD,IAE7BK,WACF,CAAEJ,OAAQE,EAAOG,KAAM1B,OAAQ,QAGjC,CACLqB,OAAQ,GACRrB,OAAQ2B,wBACN/B,EAAiB2B,EAAOnB,MAAON"}
|
package/dist/joi.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { appendErrors, transformToNestObject, } from 'react-hook-form';
|
|
2
|
-
import convertArrayToPathName from './utils/convertArrayToPathName';
|
|
3
|
-
const parseErrorSchema = (error, validateAllFieldCriteria) => Array.isArray(error.details)
|
|
4
|
-
? error.details.reduce((previous, { path, message = '', type }) => {
|
|
5
|
-
const currentPath = convertArrayToPathName(path);
|
|
6
|
-
return Object.assign(Object.assign({}, previous), (path
|
|
7
|
-
? previous[currentPath] && validateAllFieldCriteria
|
|
8
|
-
? {
|
|
9
|
-
[currentPath]: appendErrors(currentPath, validateAllFieldCriteria, previous, type, message),
|
|
10
|
-
}
|
|
11
|
-
: {
|
|
12
|
-
[currentPath]: previous[currentPath] || Object.assign({ message,
|
|
13
|
-
type }, (validateAllFieldCriteria
|
|
14
|
-
? {
|
|
15
|
-
types: { [type]: message || true },
|
|
16
|
-
}
|
|
17
|
-
: {})),
|
|
18
|
-
}
|
|
19
|
-
: {}));
|
|
20
|
-
}, {})
|
|
21
|
-
: [];
|
|
22
|
-
export const joiResolver = (schema, options = {
|
|
23
|
-
abortEarly: false,
|
|
24
|
-
}) => async (values, context, validateAllFieldCriteria = false) => {
|
|
25
|
-
try {
|
|
26
|
-
return {
|
|
27
|
-
values: await schema.validateAsync(values, Object.assign(Object.assign({}, options), { context })),
|
|
28
|
-
errors: {},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
return {
|
|
33
|
-
values: {},
|
|
34
|
-
errors: transformToNestObject(parseErrorSchema(e, validateAllFieldCriteria)),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=joi.js.map
|
package/dist/joi.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"joi.js","sourceRoot":"","sources":["../src/joi.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,qBAAqB,GAGtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,sBAAsB,MAAM,gCAAgC,CAAC;AAEpE,MAAM,gBAAgB,GAAG,CACvB,KAA0B,EAC1B,wBAAiC,EACjC,EAAE,CACF,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;IAC1B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAClB,CAAC,QAA6B,EAAE,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QAC9D,MAAM,WAAW,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAEjD,uCACK,QAAQ,GACR,CAAC,IAAI;YACN,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,wBAAwB;gBACjD,CAAC,CAAC;oBACE,CAAC,WAAW,CAAC,EAAE,YAAY,CACzB,WAAW,EACX,wBAAwB,EACxB,QAAQ,EACR,IAAI,EACJ,OAAO,CACR;iBACF;gBACH,CAAC,CAAC;oBACE,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,oBAClC,OAAO;wBACP,IAAI,IACD,CAAC,wBAAwB;wBAC1B,CAAC,CAAC;4BACE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,IAAI,IAAI,EAAE;yBACnC;wBACH,CAAC,CAAC,EAAE,CAAC,CACR;iBACF;YACL,CAAC,CAAC,EAAE,CAAC,EACP;IACJ,CAAC,EACD,EAAE,CACH;IACH,CAAC,CAAC,EAAE,CAAC;AAET,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAAkB,EAClB,UAAsC;IACpC,UAAU,EAAE,KAAK;CAClB,EACuB,EAAE,CAAC,KAAK,EAChC,MAAM,EACN,OAAO,EACP,wBAAwB,GAAG,KAAK,EAChC,EAAE;IACF,IAAI;QACF,OAAO;YACL,MAAM,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,kCACpC,OAAO,KACV,OAAO,IACP;YACF,MAAM,EAAE,EAAE;SACX,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,OAAO;YACL,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,qBAAqB,CAC3B,gBAAgB,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAC9C;SACF,CAAC;KACH;AACH,CAAC,CAAC"}
|
package/dist/superstruct.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { appendErrors, transformToNestObject, } from 'react-hook-form';
|
|
2
|
-
import { validate } from 'superstruct';
|
|
3
|
-
import convertArrayToPathName from './utils/convertArrayToPathName';
|
|
4
|
-
const parseErrorSchema = (error, validateAllFieldCriteria) => error
|
|
5
|
-
.failures()
|
|
6
|
-
.reduce((previous, { path, message = '', type }) => {
|
|
7
|
-
const currentPath = convertArrayToPathName(path);
|
|
8
|
-
return Object.assign(Object.assign({}, previous), (path
|
|
9
|
-
? previous[currentPath] && validateAllFieldCriteria
|
|
10
|
-
? {
|
|
11
|
-
[currentPath]: appendErrors(currentPath, validateAllFieldCriteria, previous, type || '', message),
|
|
12
|
-
}
|
|
13
|
-
: {
|
|
14
|
-
[currentPath]: previous[currentPath] || Object.assign({ message,
|
|
15
|
-
type }, (validateAllFieldCriteria
|
|
16
|
-
? {
|
|
17
|
-
types: { [type || '']: message || true },
|
|
18
|
-
}
|
|
19
|
-
: {})),
|
|
20
|
-
}
|
|
21
|
-
: {}));
|
|
22
|
-
}, {});
|
|
23
|
-
export const superstructResolver = (schema, options) => (values, _, validateAllFieldCriteria = false) => {
|
|
24
|
-
const [errors, result] = validate(values, schema, options);
|
|
25
|
-
if (errors != null) {
|
|
26
|
-
return {
|
|
27
|
-
values: {},
|
|
28
|
-
errors: transformToNestObject(parseErrorSchema(errors, validateAllFieldCriteria)),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
values: result,
|
|
33
|
-
errors: {},
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=superstruct.js.map
|
package/dist/superstruct.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,qBAAqB,GAItB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,QAAQ,EAAiB,MAAM,aAAa,CAAC;AACnE,OAAO,sBAAsB,MAAM,gCAAgC,CAAC;AAEpE,MAAM,gBAAgB,GAAG,CACvB,KAAkB,EAClB,wBAAiC,EACjC,EAAE,CACF,KAAK;KACF,QAAQ,EAAE;KACV,MAAM,CAAC,CAAC,QAA6B,EAAE,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;IACtE,MAAM,WAAW,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACjD,uCACK,QAAQ,GACR,CAAC,IAAI;QACN,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,wBAAwB;YACjD,CAAC,CAAC;gBACE,CAAC,WAAW,CAAC,EAAE,YAAY,CACzB,WAAW,EACX,wBAAwB,EACxB,QAAQ,EACR,IAAI,IAAI,EAAE,EACV,OAAO,CACR;aACF;YACH,CAAC,CAAC;gBACE,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,oBAClC,OAAO;oBACP,IAAI,IACD,CAAC,wBAAwB;oBAC1B,CAAC,CAAC;wBACE,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,OAAO,IAAI,IAAI,EAAE;qBACzC;oBACH,CAAC,CAAC,EAAE,CAAC,CACR;aACF;QACL,CAAC,CAAC,EAAE,CAAC,EACP;AACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AAIX,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAS,EACT,OAAiB,EACG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,wBAAwB,GAAG,KAAK,EAAE,EAAE;IACvE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAE3D,IAAI,MAAM,IAAI,IAAI,EAAE;QAClB,OAAO;YACL,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,qBAAqB,CAC3B,gBAAgB,CAAC,MAAM,EAAE,wBAAwB,CAAC,CACnD;SACyB,CAAC;KAC9B;IAED,OAAO;QACL,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,EAAE;KACkB,CAAC;AACjC,CAAC,CAAC"}
|
package/dist/umd/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","react-hook-form"],s):s((e="undefined"!=typeof globalThis?globalThis:e||self).ReactHookFormResolvers={},e.ReactHookForm)}(this,(function(e,s){"use strict";class r extends TypeError{constructor(e,s){let r;const{message:t,...o}=e,{path:n}=e;super(0===n.length?t:"At path: "+n.join(".")+" -- "+t),Object.assign(this,o),this.name=this.constructor.name,this.failures=()=>{var t;return null!=(t=r)?t:r=[e,...s()]}}}function*t(e,s,r={}){const{path:o=[],branch:n=[e],coerce:a=!1}=r,c={path:o,branch:n};a&&(e=s.coercer(e,c));let i=!0;for(const r of s.validator(e,c))i=!1,yield[r,void 0];if(i)for(const r of s.refiner(e,c))i=!1,yield[r,void 0];for(let[r,l,f]of s.entries(e,c)){const s=t(l,f,{path:void 0===r?o:[...o,r],branch:void 0===r?n:[...n,l],coerce:a});for(const t of s)t[0]?(i=!1,yield[t[0],void 0]):a&&(l=t[1],void 0===r?e=l:e instanceof Map?e.set(r,l):e instanceof Set?e.add(l):"object"==typeof(u=e)&&null!=u&&(e[r]=l))}var u;i&&(yield[void 0,e])}function o(e,s,o={}){const n=t(e,s,o),a=function(e){const{done:s,value:r}=e.next();return s?void 0:r}(n);if(a[0]){return[new r(a[0],(function*(){for(const e of n)e[0]&&(yield e[0])})),void 0]}return[void 0,a[1]]}var n=e=>e.reduce(((e,s,r)=>`${e}${"string"==typeof s?`${r>0?".":""}${s}`:`[${s}]`}`),"").toString();const a=(e,r)=>e.failures().reduce(((e,{path:t,message:o="",type:a})=>{const c=n(t);return Object.assign(Object.assign({},e),t?e[c]&&r?{[c]:s.appendErrors(c,r,e,a||"",o)}:{[c]:e[c]||Object.assign({message:o,type:a},r?{types:{[a||""]:o||!0}}:{})}:{})}),{}),c=(e,r)=>Array.isArray(e.details)?e.details.reduce(((e,{path:t,message:o="",type:a})=>{const c=n(t);return Object.assign(Object.assign({},e),t?e[c]&&r?{[c]:s.appendErrors(c,r,e,a,o)}:{[c]:e[c]||Object.assign({message:o,type:a},r?{types:{[a]:o||!0}}:{})}:{})}),{}):[],i=(e,r)=>{if(e.isEmpty)return{};const t=[...e.errors];let o={};for(const e of t){const{path:a,message:c,code:i}=e,u=n(a);if("unionErrors"in e)for(const s of e.unionErrors.map((e=>e.errors)))t.push(...s);o=Object.assign(Object.assign({},o),a?o[u]&&r?{[u]:s.appendErrors(u,r,o,i,c)}:{[u]:o[u]||Object.assign({message:c,type:i},r?{types:{[i]:c||!0}}:{})}:{})}return o},u=(e,s)=>Object.entries(e).reduce(((e,[r,t])=>Object.assign(Object.assign({},e),{[r]:Object.assign({type:"",message:t[0]},s?{types:t.reduce(((e,s,r)=>Object.assign(Object.assign({},e),{[r]:s})),{})}:{})})),{});e.joiResolver=(e,r={abortEarly:!1})=>async(t,o,n=!1)=>{try{return{values:await e.validateAsync(t,Object.assign(Object.assign({},r),{context:o})),errors:{}}}catch(e){return{values:{},errors:s.transformToNestObject(c(e,n))}}},e.superstructResolver=(e,r)=>(t,n,c=!1)=>{const[i,u]=o(t,e,r);return null!=i?{values:{},errors:s.transformToNestObject(a(i,c))}:{values:u,errors:{}}},e.vestResolver=(e,r={},t=!1)=>async r=>{const o=(n=e,(...e)=>new Promise((s=>n(...e).done(s))));var n;const a=await o(r),c=a.getErrors();return a.hasErrors()?{values:{},errors:s.transformToNestObject(u(c,t))}:{values:r,errors:{}}},e.yupResolver=(e,r={abortEarly:!1})=>async(t,o,n=!1)=>{try{return r.context&&process.env.NODE_ENV,{values:await e.validate(t,Object.assign(Object.assign({},r),{context:o})),errors:{}}}catch(e){const r=((e,s)=>Array.isArray(e.inner)&&e.inner.length?e.inner.reduce(((e,{path:r,message:t,type:o})=>{const n=e[r]&&e[r].types||{},a=r||o;return Object.assign(Object.assign({},e),a?{[a]:Object.assign(Object.assign({},e[a]||{message:t,type:o}),s?{types:Object.assign(Object.assign({},n),{[o]:n[o]?[...[].concat(n[o]),t]:t})}:{})}:{})}),{}):{[e.path]:{message:e.message,type:e.type}})(e,n);return{values:{},errors:s.transformToNestObject(r)}}},e.zodResolver=(e,r)=>async(t,o,n=!1)=>{const a=e.safeParse(t,r);return a.success?{values:a.data,errors:{}}:{values:{},errors:s.transformToNestObject(i(a.error,n))}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
-
//# sourceMappingURL=index.js.map
|