@hookform/resolvers 3.4.2 → 3.5.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/arktype/dist/arktype.js +1 -1
- package/arktype/dist/arktype.js.map +1 -1
- package/arktype/dist/arktype.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs.map +1 -1
- package/arktype/dist/arktype.module.js +1 -1
- package/arktype/dist/arktype.module.js.map +1 -1
- package/arktype/dist/arktype.umd.js +1 -1
- package/arktype/dist/arktype.umd.js.map +1 -1
- package/arktype/dist/types.d.ts +1 -1
- package/arktype/package.json +1 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +2 -2
- package/arktype/src/__tests__/Form.tsx +2 -2
- package/arktype/src/__tests__/__fixtures__/data.ts +8 -10
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +423 -32
- package/arktype/src/arktype.ts +10 -20
- package/arktype/src/types.ts +1 -1
- package/package.json +2 -2
package/arktype/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
2
|
import { Type } from 'arktype';
|
|
3
|
-
export type Resolver = <T extends Type<any>>(schema: T, schemaOptions?:
|
|
3
|
+
export type Resolver = <T extends Type<any>>(schema: T, schemaOptions?: undefined, factoryOptions?: {
|
|
4
4
|
/**
|
|
5
5
|
* Return the raw input values rather than the parsed values.
|
|
6
6
|
* @default false
|
package/arktype/package.json
CHANGED
|
@@ -57,14 +57,14 @@ test("form's native validation with Zod", async () => {
|
|
|
57
57
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
58
58
|
expect(usernameField.validity.valid).toBe(false);
|
|
59
59
|
expect(usernameField.validationMessage).toBe(
|
|
60
|
-
'username must be more than 1
|
|
60
|
+
'username must be more than length 1 (was 0)',
|
|
61
61
|
);
|
|
62
62
|
|
|
63
63
|
// password
|
|
64
64
|
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
|
|
65
65
|
expect(passwordField.validity.valid).toBe(false);
|
|
66
66
|
expect(passwordField.validationMessage).toBe(
|
|
67
|
-
'password must be more than 1
|
|
67
|
+
'password must be more than length 1 (was 0)',
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
|
@@ -47,10 +47,10 @@ test("form's validation with arkType and TypeScript's integration", async () =>
|
|
|
47
47
|
await user.click(screen.getByText(/submit/i));
|
|
48
48
|
|
|
49
49
|
expect(
|
|
50
|
-
screen.getByText('username must be more than 1
|
|
50
|
+
screen.getByText('username must be more than length 1 (was 0)'),
|
|
51
51
|
).toBeInTheDocument();
|
|
52
52
|
expect(
|
|
53
|
-
screen.getByText('password must be more than 1
|
|
53
|
+
screen.getByText('password must be more than length 1 (was 0)'),
|
|
54
54
|
).toBeInTheDocument();
|
|
55
55
|
expect(handleSubmit).not.toHaveBeenCalled();
|
|
56
56
|
});
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
|
-
import { type
|
|
2
|
+
import { type } from 'arktype';
|
|
3
3
|
|
|
4
4
|
export const schema = type({
|
|
5
5
|
username: 'string>2',
|
|
6
|
-
password:
|
|
6
|
+
password: '/.*[A-Za-z].*/>8|/.*\\d.*/',
|
|
7
7
|
repeatPassword: 'string>1',
|
|
8
|
-
accessToken:
|
|
8
|
+
accessToken: 'string|number',
|
|
9
9
|
birthYear: '1900<number<2013',
|
|
10
10
|
email: 'email',
|
|
11
|
-
tags:
|
|
11
|
+
tags: 'string[]',
|
|
12
12
|
enabled: 'boolean',
|
|
13
13
|
url: 'string>1',
|
|
14
|
-
'like?':
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}),
|
|
19
|
-
),
|
|
14
|
+
'like?': type({
|
|
15
|
+
id: 'number',
|
|
16
|
+
name: 'string>3',
|
|
17
|
+
}).array(),
|
|
20
18
|
dateStr: 'Date',
|
|
21
19
|
});
|
|
22
20
|
|
|
@@ -3,72 +3,463 @@
|
|
|
3
3
|
exports[`arktypeResolver > should return a single error from arktypeResolver when validation fails 1`] = `
|
|
4
4
|
{
|
|
5
5
|
"errors": {
|
|
6
|
-
"accessToken": {
|
|
7
|
-
"
|
|
6
|
+
"accessToken": ArkError {
|
|
7
|
+
"code": "required",
|
|
8
|
+
"data": {
|
|
9
|
+
"birthYear": "birthYear",
|
|
10
|
+
"email": "",
|
|
11
|
+
"like": [
|
|
12
|
+
{
|
|
13
|
+
"id": "z",
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
"password": "___",
|
|
17
|
+
"url": "abc",
|
|
18
|
+
},
|
|
19
|
+
"input": {
|
|
20
|
+
"code": "required",
|
|
21
|
+
"missingValueDescription": "a number or a string",
|
|
22
|
+
"relativePath": [
|
|
23
|
+
"accessToken",
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
"missingValueDescription": "a number or a string",
|
|
27
|
+
"nodeConfig": {
|
|
28
|
+
"actual": [Function],
|
|
29
|
+
"description": [Function],
|
|
30
|
+
"expected": [Function],
|
|
31
|
+
"message": [Function],
|
|
32
|
+
"problem": [Function],
|
|
33
|
+
},
|
|
34
|
+
"path": [
|
|
35
|
+
"accessToken",
|
|
36
|
+
],
|
|
8
37
|
"ref": undefined,
|
|
9
|
-
"
|
|
38
|
+
"relativePath": [
|
|
39
|
+
"accessToken",
|
|
40
|
+
],
|
|
41
|
+
"type": "required",
|
|
42
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
10
43
|
},
|
|
11
|
-
"birthYear": {
|
|
12
|
-
"
|
|
44
|
+
"birthYear": ArkError {
|
|
45
|
+
"code": "domain",
|
|
46
|
+
"data": "birthYear",
|
|
47
|
+
"description": "a number",
|
|
48
|
+
"domain": "number",
|
|
49
|
+
"input": {
|
|
50
|
+
"code": "domain",
|
|
51
|
+
"description": "a number",
|
|
52
|
+
"domain": "number",
|
|
53
|
+
},
|
|
54
|
+
"nodeConfig": {
|
|
55
|
+
"actual": [Function],
|
|
56
|
+
"description": [Function],
|
|
57
|
+
"expected": [Function],
|
|
58
|
+
"message": [Function],
|
|
59
|
+
"problem": [Function],
|
|
60
|
+
},
|
|
61
|
+
"path": [
|
|
62
|
+
"birthYear",
|
|
63
|
+
],
|
|
13
64
|
"ref": undefined,
|
|
14
65
|
"type": "domain",
|
|
66
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
15
67
|
},
|
|
16
|
-
"dateStr": {
|
|
17
|
-
"
|
|
68
|
+
"dateStr": ArkError {
|
|
69
|
+
"code": "required",
|
|
70
|
+
"data": {
|
|
71
|
+
"birthYear": "birthYear",
|
|
72
|
+
"email": "",
|
|
73
|
+
"like": [
|
|
74
|
+
{
|
|
75
|
+
"id": "z",
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
"password": "___",
|
|
79
|
+
"url": "abc",
|
|
80
|
+
},
|
|
81
|
+
"input": {
|
|
82
|
+
"code": "required",
|
|
83
|
+
"missingValueDescription": "a Date",
|
|
84
|
+
"relativePath": [
|
|
85
|
+
"dateStr",
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
"missingValueDescription": "a Date",
|
|
89
|
+
"nodeConfig": {
|
|
90
|
+
"actual": [Function],
|
|
91
|
+
"description": [Function],
|
|
92
|
+
"expected": [Function],
|
|
93
|
+
"message": [Function],
|
|
94
|
+
"problem": [Function],
|
|
95
|
+
},
|
|
96
|
+
"path": [
|
|
97
|
+
"dateStr",
|
|
98
|
+
],
|
|
18
99
|
"ref": undefined,
|
|
19
|
-
"
|
|
100
|
+
"relativePath": [
|
|
101
|
+
"dateStr",
|
|
102
|
+
],
|
|
103
|
+
"type": "required",
|
|
104
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
20
105
|
},
|
|
21
|
-
"email": {
|
|
22
|
-
"
|
|
106
|
+
"email": ArkError {
|
|
107
|
+
"code": "regex",
|
|
108
|
+
"data": "",
|
|
109
|
+
"description": "a valid email",
|
|
110
|
+
"flags": "",
|
|
111
|
+
"input": {
|
|
112
|
+
"code": "regex",
|
|
113
|
+
"description": "a valid email",
|
|
114
|
+
"flags": "",
|
|
115
|
+
"rule": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,}$",
|
|
116
|
+
},
|
|
117
|
+
"nodeConfig": {
|
|
118
|
+
"actual": [Function],
|
|
119
|
+
"description": [Function],
|
|
120
|
+
"expected": [Function],
|
|
121
|
+
"message": [Function],
|
|
122
|
+
"problem": [Function],
|
|
123
|
+
},
|
|
124
|
+
"path": [
|
|
125
|
+
"email",
|
|
126
|
+
],
|
|
23
127
|
"ref": {
|
|
24
128
|
"name": "email",
|
|
25
129
|
},
|
|
130
|
+
"rule": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,}$",
|
|
26
131
|
"type": "regex",
|
|
132
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
27
133
|
},
|
|
28
|
-
"enabled": {
|
|
29
|
-
"
|
|
134
|
+
"enabled": ArkError {
|
|
135
|
+
"code": "required",
|
|
136
|
+
"data": {
|
|
137
|
+
"birthYear": "birthYear",
|
|
138
|
+
"email": "",
|
|
139
|
+
"like": [
|
|
140
|
+
{
|
|
141
|
+
"id": "z",
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
"password": "___",
|
|
145
|
+
"url": "abc",
|
|
146
|
+
},
|
|
147
|
+
"input": {
|
|
148
|
+
"code": "required",
|
|
149
|
+
"missingValueDescription": "boolean",
|
|
150
|
+
"relativePath": [
|
|
151
|
+
"enabled",
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
"missingValueDescription": "boolean",
|
|
155
|
+
"nodeConfig": {
|
|
156
|
+
"actual": [Function],
|
|
157
|
+
"description": [Function],
|
|
158
|
+
"expected": [Function],
|
|
159
|
+
"message": [Function],
|
|
160
|
+
"problem": [Function],
|
|
161
|
+
},
|
|
162
|
+
"path": [
|
|
163
|
+
"enabled",
|
|
164
|
+
],
|
|
30
165
|
"ref": undefined,
|
|
31
|
-
"
|
|
166
|
+
"relativePath": [
|
|
167
|
+
"enabled",
|
|
168
|
+
],
|
|
169
|
+
"type": "required",
|
|
170
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
32
171
|
},
|
|
33
172
|
"like": [
|
|
34
173
|
{
|
|
35
|
-
"id": {
|
|
36
|
-
"
|
|
174
|
+
"id": ArkError {
|
|
175
|
+
"code": "domain",
|
|
176
|
+
"data": "z",
|
|
177
|
+
"description": "a number",
|
|
178
|
+
"domain": "number",
|
|
179
|
+
"input": {
|
|
180
|
+
"code": "domain",
|
|
181
|
+
"description": "a number",
|
|
182
|
+
"domain": "number",
|
|
183
|
+
},
|
|
184
|
+
"nodeConfig": {
|
|
185
|
+
"actual": [Function],
|
|
186
|
+
"description": [Function],
|
|
187
|
+
"expected": [Function],
|
|
188
|
+
"message": [Function],
|
|
189
|
+
"problem": [Function],
|
|
190
|
+
},
|
|
191
|
+
"path": [
|
|
192
|
+
"like",
|
|
193
|
+
0,
|
|
194
|
+
"id",
|
|
195
|
+
],
|
|
37
196
|
"ref": undefined,
|
|
38
197
|
"type": "domain",
|
|
198
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
39
199
|
},
|
|
40
|
-
"name": {
|
|
41
|
-
"
|
|
200
|
+
"name": ArkError {
|
|
201
|
+
"code": "required",
|
|
202
|
+
"data": {
|
|
203
|
+
"id": "z",
|
|
204
|
+
},
|
|
205
|
+
"input": {
|
|
206
|
+
"code": "required",
|
|
207
|
+
"missingValueDescription": "a string and more than length 3",
|
|
208
|
+
"relativePath": [
|
|
209
|
+
"name",
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
"missingValueDescription": "a string and more than length 3",
|
|
213
|
+
"nodeConfig": {
|
|
214
|
+
"actual": [Function],
|
|
215
|
+
"description": [Function],
|
|
216
|
+
"expected": [Function],
|
|
217
|
+
"message": [Function],
|
|
218
|
+
"problem": [Function],
|
|
219
|
+
},
|
|
220
|
+
"path": [
|
|
221
|
+
"like",
|
|
222
|
+
0,
|
|
223
|
+
"name",
|
|
224
|
+
],
|
|
42
225
|
"ref": undefined,
|
|
43
|
-
"
|
|
226
|
+
"relativePath": [
|
|
227
|
+
"name",
|
|
228
|
+
],
|
|
229
|
+
"type": "required",
|
|
230
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
44
231
|
},
|
|
45
232
|
},
|
|
46
233
|
],
|
|
47
|
-
"password": {
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
234
|
+
"password": ArkError {
|
|
235
|
+
"code": "union",
|
|
236
|
+
"data": "___",
|
|
237
|
+
"errors": [
|
|
238
|
+
ArkError {
|
|
239
|
+
"code": "regex",
|
|
240
|
+
"data": "___",
|
|
241
|
+
"description": "matched by .*[A-Za-z].*",
|
|
242
|
+
"input": {
|
|
243
|
+
"code": "regex",
|
|
244
|
+
"description": "matched by .*[A-Za-z].*",
|
|
245
|
+
"rule": ".*[A-Za-z].*",
|
|
246
|
+
},
|
|
247
|
+
"nodeConfig": {
|
|
248
|
+
"actual": [Function],
|
|
249
|
+
"description": [Function],
|
|
250
|
+
"expected": [Function],
|
|
251
|
+
"message": [Function],
|
|
252
|
+
"problem": [Function],
|
|
253
|
+
},
|
|
254
|
+
"path": [
|
|
255
|
+
"password",
|
|
256
|
+
],
|
|
257
|
+
"rule": ".*[A-Za-z].*",
|
|
258
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
259
|
+
},
|
|
260
|
+
ArkError {
|
|
261
|
+
"code": "regex",
|
|
262
|
+
"data": "___",
|
|
263
|
+
"description": "matched by .*\\\\d.*",
|
|
264
|
+
"input": {
|
|
265
|
+
"code": "regex",
|
|
266
|
+
"description": "matched by .*\\\\d.*",
|
|
267
|
+
"rule": ".*\\\\d.*",
|
|
268
|
+
},
|
|
269
|
+
"nodeConfig": {
|
|
270
|
+
"actual": [Function],
|
|
271
|
+
"description": [Function],
|
|
272
|
+
"expected": [Function],
|
|
273
|
+
"message": [Function],
|
|
274
|
+
"problem": [Function],
|
|
275
|
+
},
|
|
276
|
+
"path": [
|
|
277
|
+
"password",
|
|
278
|
+
],
|
|
279
|
+
"rule": ".*\\\\d.*",
|
|
280
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
"input": {
|
|
284
|
+
"code": "union",
|
|
285
|
+
"errors": [
|
|
286
|
+
ArkError {
|
|
287
|
+
"code": "regex",
|
|
288
|
+
"data": "___",
|
|
289
|
+
"description": "matched by .*[A-Za-z].*",
|
|
290
|
+
"input": {
|
|
291
|
+
"code": "regex",
|
|
292
|
+
"description": "matched by .*[A-Za-z].*",
|
|
293
|
+
"rule": ".*[A-Za-z].*",
|
|
294
|
+
},
|
|
295
|
+
"nodeConfig": {
|
|
296
|
+
"actual": [Function],
|
|
297
|
+
"description": [Function],
|
|
298
|
+
"expected": [Function],
|
|
299
|
+
"message": [Function],
|
|
300
|
+
"problem": [Function],
|
|
301
|
+
},
|
|
302
|
+
"path": [
|
|
303
|
+
"password",
|
|
304
|
+
],
|
|
305
|
+
"rule": ".*[A-Za-z].*",
|
|
306
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
307
|
+
},
|
|
308
|
+
ArkError {
|
|
309
|
+
"code": "regex",
|
|
310
|
+
"data": "___",
|
|
311
|
+
"description": "matched by .*\\\\d.*",
|
|
312
|
+
"input": {
|
|
313
|
+
"code": "regex",
|
|
314
|
+
"description": "matched by .*\\\\d.*",
|
|
315
|
+
"rule": ".*\\\\d.*",
|
|
316
|
+
},
|
|
317
|
+
"nodeConfig": {
|
|
318
|
+
"actual": [Function],
|
|
319
|
+
"description": [Function],
|
|
320
|
+
"expected": [Function],
|
|
321
|
+
"message": [Function],
|
|
322
|
+
"problem": [Function],
|
|
323
|
+
},
|
|
324
|
+
"path": [
|
|
325
|
+
"password",
|
|
326
|
+
],
|
|
327
|
+
"rule": ".*\\\\d.*",
|
|
328
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
},
|
|
332
|
+
"nodeConfig": {
|
|
333
|
+
"actual": [Function],
|
|
334
|
+
"description": [Function],
|
|
335
|
+
"expected": [Function],
|
|
336
|
+
"message": [Function],
|
|
337
|
+
"problem": [Function],
|
|
338
|
+
},
|
|
339
|
+
"path": [
|
|
340
|
+
"password",
|
|
341
|
+
],
|
|
51
342
|
"ref": {
|
|
52
343
|
"name": "password",
|
|
53
344
|
},
|
|
54
|
-
"type": "
|
|
345
|
+
"type": "union",
|
|
346
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
55
347
|
},
|
|
56
|
-
"repeatPassword": {
|
|
57
|
-
"
|
|
348
|
+
"repeatPassword": ArkError {
|
|
349
|
+
"code": "required",
|
|
350
|
+
"data": {
|
|
351
|
+
"birthYear": "birthYear",
|
|
352
|
+
"email": "",
|
|
353
|
+
"like": [
|
|
354
|
+
{
|
|
355
|
+
"id": "z",
|
|
356
|
+
},
|
|
357
|
+
],
|
|
358
|
+
"password": "___",
|
|
359
|
+
"url": "abc",
|
|
360
|
+
},
|
|
361
|
+
"input": {
|
|
362
|
+
"code": "required",
|
|
363
|
+
"missingValueDescription": "a string and more than length 1",
|
|
364
|
+
"relativePath": [
|
|
365
|
+
"repeatPassword",
|
|
366
|
+
],
|
|
367
|
+
},
|
|
368
|
+
"missingValueDescription": "a string and more than length 1",
|
|
369
|
+
"nodeConfig": {
|
|
370
|
+
"actual": [Function],
|
|
371
|
+
"description": [Function],
|
|
372
|
+
"expected": [Function],
|
|
373
|
+
"message": [Function],
|
|
374
|
+
"problem": [Function],
|
|
375
|
+
},
|
|
376
|
+
"path": [
|
|
377
|
+
"repeatPassword",
|
|
378
|
+
],
|
|
58
379
|
"ref": undefined,
|
|
59
|
-
"
|
|
380
|
+
"relativePath": [
|
|
381
|
+
"repeatPassword",
|
|
382
|
+
],
|
|
383
|
+
"type": "required",
|
|
384
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
60
385
|
},
|
|
61
|
-
"tags": {
|
|
62
|
-
"
|
|
386
|
+
"tags": ArkError {
|
|
387
|
+
"code": "required",
|
|
388
|
+
"data": {
|
|
389
|
+
"birthYear": "birthYear",
|
|
390
|
+
"email": "",
|
|
391
|
+
"like": [
|
|
392
|
+
{
|
|
393
|
+
"id": "z",
|
|
394
|
+
},
|
|
395
|
+
],
|
|
396
|
+
"password": "___",
|
|
397
|
+
"url": "abc",
|
|
398
|
+
},
|
|
399
|
+
"input": {
|
|
400
|
+
"code": "required",
|
|
401
|
+
"missingValueDescription": "string[]",
|
|
402
|
+
"relativePath": [
|
|
403
|
+
"tags",
|
|
404
|
+
],
|
|
405
|
+
},
|
|
406
|
+
"missingValueDescription": "string[]",
|
|
407
|
+
"nodeConfig": {
|
|
408
|
+
"actual": [Function],
|
|
409
|
+
"description": [Function],
|
|
410
|
+
"expected": [Function],
|
|
411
|
+
"message": [Function],
|
|
412
|
+
"problem": [Function],
|
|
413
|
+
},
|
|
414
|
+
"path": [
|
|
415
|
+
"tags",
|
|
416
|
+
],
|
|
63
417
|
"ref": undefined,
|
|
64
|
-
"
|
|
418
|
+
"relativePath": [
|
|
419
|
+
"tags",
|
|
420
|
+
],
|
|
421
|
+
"type": "required",
|
|
422
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
65
423
|
},
|
|
66
|
-
"username": {
|
|
67
|
-
"
|
|
424
|
+
"username": ArkError {
|
|
425
|
+
"code": "required",
|
|
426
|
+
"data": {
|
|
427
|
+
"birthYear": "birthYear",
|
|
428
|
+
"email": "",
|
|
429
|
+
"like": [
|
|
430
|
+
{
|
|
431
|
+
"id": "z",
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
"password": "___",
|
|
435
|
+
"url": "abc",
|
|
436
|
+
},
|
|
437
|
+
"input": {
|
|
438
|
+
"code": "required",
|
|
439
|
+
"missingValueDescription": "a string and more than length 2",
|
|
440
|
+
"relativePath": [
|
|
441
|
+
"username",
|
|
442
|
+
],
|
|
443
|
+
},
|
|
444
|
+
"missingValueDescription": "a string and more than length 2",
|
|
445
|
+
"nodeConfig": {
|
|
446
|
+
"actual": [Function],
|
|
447
|
+
"description": [Function],
|
|
448
|
+
"expected": [Function],
|
|
449
|
+
"message": [Function],
|
|
450
|
+
"problem": [Function],
|
|
451
|
+
},
|
|
452
|
+
"path": [
|
|
453
|
+
"username",
|
|
454
|
+
],
|
|
68
455
|
"ref": {
|
|
69
456
|
"name": "username",
|
|
70
457
|
},
|
|
71
|
-
"
|
|
458
|
+
"relativePath": [
|
|
459
|
+
"username",
|
|
460
|
+
],
|
|
461
|
+
"type": "required",
|
|
462
|
+
Symbol(ArkTypeInternalKind): "error",
|
|
72
463
|
},
|
|
73
464
|
},
|
|
74
465
|
"values": {},
|
package/arktype/src/arktype.ts
CHANGED
|
@@ -1,34 +1,24 @@
|
|
|
1
1
|
import { FieldError, FieldErrors } from 'react-hook-form';
|
|
2
2
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
3
|
import type { Resolver } from './types';
|
|
4
|
-
import {
|
|
4
|
+
import { ArkErrors } from 'arktype';
|
|
5
5
|
|
|
6
|
-
const parseErrorSchema = (e:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!errors[_path]) {
|
|
13
|
-
errors[_path] = { message: error.message, type: error.code };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// @ts-expect-error - false positive Property 'shift' does not exist on type 'Problems'.
|
|
17
|
-
e.shift();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return errors;
|
|
6
|
+
const parseErrorSchema = (e: ArkErrors): Record<string, FieldError> => {
|
|
7
|
+
// copy code to type to match FieldError shape
|
|
8
|
+
e.forEach((e) => Object.assign(e, { type: e.code }));
|
|
9
|
+
// need to cast here because TS doesn't understand we added the type field
|
|
10
|
+
return e.byPath as never;
|
|
21
11
|
};
|
|
22
12
|
|
|
23
13
|
export const arktypeResolver: Resolver =
|
|
24
14
|
(schema, _schemaOptions, resolverOptions = {}) =>
|
|
25
15
|
(values, _, options) => {
|
|
26
|
-
const
|
|
16
|
+
const out = schema(values);
|
|
27
17
|
|
|
28
|
-
if (
|
|
18
|
+
if (out instanceof ArkErrors) {
|
|
29
19
|
return {
|
|
30
20
|
values: {},
|
|
31
|
-
errors: toNestErrors(parseErrorSchema(
|
|
21
|
+
errors: toNestErrors(parseErrorSchema(out), options),
|
|
32
22
|
};
|
|
33
23
|
}
|
|
34
24
|
|
|
@@ -36,6 +26,6 @@ export const arktypeResolver: Resolver =
|
|
|
36
26
|
|
|
37
27
|
return {
|
|
38
28
|
errors: {} as FieldErrors,
|
|
39
|
-
values: resolverOptions.raw ? values :
|
|
29
|
+
values: resolverOptions.raw ? values : out,
|
|
40
30
|
};
|
|
41
31
|
};
|
package/arktype/src/types.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hookform/resolvers",
|
|
3
3
|
"amdName": "hookformResolvers",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.5.0",
|
|
5
5
|
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion and Effect-TS",
|
|
6
6
|
"main": "dist/resolvers.js",
|
|
7
7
|
"module": "dist/resolvers.module.js",
|
|
@@ -233,7 +233,7 @@
|
|
|
233
233
|
"@vitejs/plugin-react": "^4.0.4",
|
|
234
234
|
"ajv": "^8.12.0",
|
|
235
235
|
"ajv-errors": "^3.0.0",
|
|
236
|
-
"arktype": "
|
|
236
|
+
"arktype": "2.0.0-dev.14",
|
|
237
237
|
"check-export-map": "^1.3.0",
|
|
238
238
|
"class-transformer": "^0.5.1",
|
|
239
239
|
"class-validator": "^0.14.0",
|