@hookform/resolvers 3.5.0 → 3.7.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 +47 -33
- package/package.json +17 -5
- package/valibot/dist/types.d.ts +2 -2
- package/valibot/dist/valibot.js +1 -1
- package/valibot/dist/valibot.js.map +1 -1
- package/valibot/dist/valibot.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs.map +1 -1
- package/valibot/dist/valibot.module.js +1 -1
- package/valibot/dist/valibot.module.js.map +1 -1
- package/valibot/dist/valibot.umd.js +1 -1
- package/valibot/dist/valibot.umd.js.map +1 -1
- package/valibot/package.json +2 -2
- package/valibot/src/__tests__/Form-native-validation.tsx +14 -14
- package/valibot/src/__tests__/Form.tsx +11 -11
- package/valibot/src/__tests__/__fixtures__/data.ts +43 -53
- package/valibot/src/__tests__/__snapshots__/valibot.ts.snap +50 -50
- package/valibot/src/__tests__/valibot.ts +13 -11
- package/valibot/src/types.ts +15 -3
- package/valibot/src/valibot.ts +55 -77
- package/vine/dist/index.d.ts +2 -0
- package/vine/dist/types.d.ts +6 -0
- package/vine/dist/vine.d.ts +2 -0
- package/vine/dist/vine.js +2 -0
- package/vine/dist/vine.js.map +1 -0
- package/vine/dist/vine.mjs +2 -0
- package/vine/dist/vine.modern.mjs +2 -0
- package/vine/dist/vine.modern.mjs.map +1 -0
- package/vine/dist/vine.module.js +2 -0
- package/vine/dist/vine.module.js.map +1 -0
- package/vine/dist/vine.umd.js +2 -0
- package/vine/dist/vine.umd.js.map +1 -0
- package/vine/package.json +18 -0
- package/vine/src/__tests__/Form-native-validation.tsx +81 -0
- package/vine/src/__tests__/Form.tsx +55 -0
- package/vine/src/__tests__/__fixtures__/data.ts +74 -0
- package/vine/src/__tests__/__snapshots__/vine.ts.snap +180 -0
- package/vine/src/__tests__/vine.ts +53 -0
- package/vine/src/index.ts +2 -0
- package/vine/src/types.ts +13 -0
- package/vine/src/vine.ts +66 -0
- 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 +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- 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/zod.ts +1 -1
|
@@ -4,9 +4,9 @@ exports[`valibotResolver > should return a single error from valibotResolver whe
|
|
|
4
4
|
{
|
|
5
5
|
"errors": {
|
|
6
6
|
"accessToken": {
|
|
7
|
-
"message": "
|
|
7
|
+
"message": "access token is required",
|
|
8
8
|
"ref": undefined,
|
|
9
|
-
"type": "
|
|
9
|
+
"type": "union",
|
|
10
10
|
},
|
|
11
11
|
"birthYear": {
|
|
12
12
|
"message": "Please enter your birth year",
|
|
@@ -21,9 +21,9 @@ exports[`valibotResolver > should return a single error from valibotResolver whe
|
|
|
21
21
|
"type": "email",
|
|
22
22
|
},
|
|
23
23
|
"enabled": {
|
|
24
|
-
"message": "Invalid type",
|
|
24
|
+
"message": "Invalid type: Expected boolean but received undefined",
|
|
25
25
|
"ref": undefined,
|
|
26
|
-
"type": "
|
|
26
|
+
"type": "boolean",
|
|
27
27
|
},
|
|
28
28
|
"like": {
|
|
29
29
|
"id": {
|
|
@@ -32,9 +32,9 @@ exports[`valibotResolver > should return a single error from valibotResolver whe
|
|
|
32
32
|
"type": "number",
|
|
33
33
|
},
|
|
34
34
|
"name": {
|
|
35
|
-
"message": "
|
|
35
|
+
"message": "Like name is required",
|
|
36
36
|
"ref": undefined,
|
|
37
|
-
"type": "
|
|
37
|
+
"type": "string",
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
"password": {
|
|
@@ -45,9 +45,9 @@ exports[`valibotResolver > should return a single error from valibotResolver whe
|
|
|
45
45
|
"type": "regex",
|
|
46
46
|
},
|
|
47
47
|
"repeatPassword": {
|
|
48
|
-
"message": "
|
|
48
|
+
"message": "Repeat Password is required",
|
|
49
49
|
"ref": undefined,
|
|
50
|
-
"type": "
|
|
50
|
+
"type": "string",
|
|
51
51
|
},
|
|
52
52
|
"tags": [
|
|
53
53
|
{
|
|
@@ -67,11 +67,11 @@ exports[`valibotResolver > should return a single error from valibotResolver whe
|
|
|
67
67
|
},
|
|
68
68
|
],
|
|
69
69
|
"username": {
|
|
70
|
-
"message": "Invalid type",
|
|
70
|
+
"message": "Invalid type: Expected string but received undefined",
|
|
71
71
|
"ref": {
|
|
72
72
|
"name": "username",
|
|
73
73
|
},
|
|
74
|
-
"type": "
|
|
74
|
+
"type": "string",
|
|
75
75
|
},
|
|
76
76
|
},
|
|
77
77
|
"values": {},
|
|
@@ -82,9 +82,9 @@ exports[`valibotResolver > should return a single error from valibotResolver wit
|
|
|
82
82
|
{
|
|
83
83
|
"errors": {
|
|
84
84
|
"accessToken": {
|
|
85
|
-
"message": "
|
|
85
|
+
"message": "access token is required",
|
|
86
86
|
"ref": undefined,
|
|
87
|
-
"type": "
|
|
87
|
+
"type": "union",
|
|
88
88
|
},
|
|
89
89
|
"birthYear": {
|
|
90
90
|
"message": "Please enter your birth year",
|
|
@@ -99,9 +99,9 @@ exports[`valibotResolver > should return a single error from valibotResolver wit
|
|
|
99
99
|
"type": "email",
|
|
100
100
|
},
|
|
101
101
|
"enabled": {
|
|
102
|
-
"message": "Invalid type",
|
|
102
|
+
"message": "Invalid type: Expected boolean but received undefined",
|
|
103
103
|
"ref": undefined,
|
|
104
|
-
"type": "
|
|
104
|
+
"type": "boolean",
|
|
105
105
|
},
|
|
106
106
|
"like": {
|
|
107
107
|
"id": {
|
|
@@ -110,9 +110,9 @@ exports[`valibotResolver > should return a single error from valibotResolver wit
|
|
|
110
110
|
"type": "number",
|
|
111
111
|
},
|
|
112
112
|
"name": {
|
|
113
|
-
"message": "
|
|
113
|
+
"message": "Like name is required",
|
|
114
114
|
"ref": undefined,
|
|
115
|
-
"type": "
|
|
115
|
+
"type": "string",
|
|
116
116
|
},
|
|
117
117
|
},
|
|
118
118
|
"password": {
|
|
@@ -123,9 +123,9 @@ exports[`valibotResolver > should return a single error from valibotResolver wit
|
|
|
123
123
|
"type": "regex",
|
|
124
124
|
},
|
|
125
125
|
"repeatPassword": {
|
|
126
|
-
"message": "
|
|
126
|
+
"message": "Repeat Password is required",
|
|
127
127
|
"ref": undefined,
|
|
128
|
-
"type": "
|
|
128
|
+
"type": "string",
|
|
129
129
|
},
|
|
130
130
|
"tags": [
|
|
131
131
|
{
|
|
@@ -145,11 +145,11 @@ exports[`valibotResolver > should return a single error from valibotResolver wit
|
|
|
145
145
|
},
|
|
146
146
|
],
|
|
147
147
|
"username": {
|
|
148
|
-
"message": "Invalid type",
|
|
148
|
+
"message": "Invalid type: Expected string but received undefined",
|
|
149
149
|
"ref": {
|
|
150
150
|
"name": "username",
|
|
151
151
|
},
|
|
152
|
-
"type": "
|
|
152
|
+
"type": "string",
|
|
153
153
|
},
|
|
154
154
|
},
|
|
155
155
|
"values": {},
|
|
@@ -160,11 +160,11 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
160
160
|
{
|
|
161
161
|
"errors": {
|
|
162
162
|
"accessToken": {
|
|
163
|
-
"message": "
|
|
163
|
+
"message": "access token is required",
|
|
164
164
|
"ref": undefined,
|
|
165
|
-
"type": "
|
|
165
|
+
"type": "union",
|
|
166
166
|
"types": {
|
|
167
|
-
"
|
|
167
|
+
"union": "access token is required",
|
|
168
168
|
},
|
|
169
169
|
},
|
|
170
170
|
"birthYear": {
|
|
@@ -186,11 +186,11 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
186
186
|
},
|
|
187
187
|
},
|
|
188
188
|
"enabled": {
|
|
189
|
-
"message": "Invalid type",
|
|
189
|
+
"message": "Invalid type: Expected boolean but received undefined",
|
|
190
190
|
"ref": undefined,
|
|
191
|
-
"type": "
|
|
191
|
+
"type": "boolean",
|
|
192
192
|
"types": {
|
|
193
|
-
"
|
|
193
|
+
"boolean": "Invalid type: Expected boolean but received undefined",
|
|
194
194
|
},
|
|
195
195
|
},
|
|
196
196
|
"like": {
|
|
@@ -203,11 +203,11 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
203
203
|
},
|
|
204
204
|
},
|
|
205
205
|
"name": {
|
|
206
|
-
"message": "
|
|
206
|
+
"message": "Like name is required",
|
|
207
207
|
"ref": undefined,
|
|
208
|
-
"type": "
|
|
208
|
+
"type": "string",
|
|
209
209
|
"types": {
|
|
210
|
-
"
|
|
210
|
+
"string": "Like name is required",
|
|
211
211
|
},
|
|
212
212
|
},
|
|
213
213
|
},
|
|
@@ -227,11 +227,11 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
227
227
|
},
|
|
228
228
|
},
|
|
229
229
|
"repeatPassword": {
|
|
230
|
-
"message": "
|
|
230
|
+
"message": "Repeat Password is required",
|
|
231
231
|
"ref": undefined,
|
|
232
|
-
"type": "
|
|
232
|
+
"type": "string",
|
|
233
233
|
"types": {
|
|
234
|
-
"
|
|
234
|
+
"string": "Repeat Password is required",
|
|
235
235
|
},
|
|
236
236
|
},
|
|
237
237
|
"tags": [
|
|
@@ -261,13 +261,13 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
261
261
|
},
|
|
262
262
|
],
|
|
263
263
|
"username": {
|
|
264
|
-
"message": "Invalid type",
|
|
264
|
+
"message": "Invalid type: Expected string but received undefined",
|
|
265
265
|
"ref": {
|
|
266
266
|
"name": "username",
|
|
267
267
|
},
|
|
268
|
-
"type": "
|
|
268
|
+
"type": "string",
|
|
269
269
|
"types": {
|
|
270
|
-
"
|
|
270
|
+
"string": "Invalid type: Expected string but received undefined",
|
|
271
271
|
},
|
|
272
272
|
},
|
|
273
273
|
},
|
|
@@ -279,11 +279,11 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
279
279
|
{
|
|
280
280
|
"errors": {
|
|
281
281
|
"accessToken": {
|
|
282
|
-
"message": "
|
|
282
|
+
"message": "access token is required",
|
|
283
283
|
"ref": undefined,
|
|
284
|
-
"type": "
|
|
284
|
+
"type": "union",
|
|
285
285
|
"types": {
|
|
286
|
-
"
|
|
286
|
+
"union": "access token is required",
|
|
287
287
|
},
|
|
288
288
|
},
|
|
289
289
|
"birthYear": {
|
|
@@ -305,11 +305,11 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
305
305
|
},
|
|
306
306
|
},
|
|
307
307
|
"enabled": {
|
|
308
|
-
"message": "Invalid type",
|
|
308
|
+
"message": "Invalid type: Expected boolean but received undefined",
|
|
309
309
|
"ref": undefined,
|
|
310
|
-
"type": "
|
|
310
|
+
"type": "boolean",
|
|
311
311
|
"types": {
|
|
312
|
-
"
|
|
312
|
+
"boolean": "Invalid type: Expected boolean but received undefined",
|
|
313
313
|
},
|
|
314
314
|
},
|
|
315
315
|
"like": {
|
|
@@ -322,11 +322,11 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
322
322
|
},
|
|
323
323
|
},
|
|
324
324
|
"name": {
|
|
325
|
-
"message": "
|
|
325
|
+
"message": "Like name is required",
|
|
326
326
|
"ref": undefined,
|
|
327
|
-
"type": "
|
|
327
|
+
"type": "string",
|
|
328
328
|
"types": {
|
|
329
|
-
"
|
|
329
|
+
"string": "Like name is required",
|
|
330
330
|
},
|
|
331
331
|
},
|
|
332
332
|
},
|
|
@@ -346,11 +346,11 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
346
346
|
},
|
|
347
347
|
},
|
|
348
348
|
"repeatPassword": {
|
|
349
|
-
"message": "
|
|
349
|
+
"message": "Repeat Password is required",
|
|
350
350
|
"ref": undefined,
|
|
351
|
-
"type": "
|
|
351
|
+
"type": "string",
|
|
352
352
|
"types": {
|
|
353
|
-
"
|
|
353
|
+
"string": "Repeat Password is required",
|
|
354
354
|
},
|
|
355
355
|
},
|
|
356
356
|
"tags": [
|
|
@@ -380,13 +380,13 @@ exports[`valibotResolver > should return all the errors from valibotResolver whe
|
|
|
380
380
|
},
|
|
381
381
|
],
|
|
382
382
|
"username": {
|
|
383
|
-
"message": "Invalid type",
|
|
383
|
+
"message": "Invalid type: Expected string but received undefined",
|
|
384
384
|
"ref": {
|
|
385
385
|
"name": "username",
|
|
386
386
|
},
|
|
387
|
-
"type": "
|
|
387
|
+
"type": "string",
|
|
388
388
|
"types": {
|
|
389
|
-
"
|
|
389
|
+
"string": "Invalid type: Expected string but received undefined",
|
|
390
390
|
},
|
|
391
391
|
},
|
|
392
392
|
},
|
|
@@ -21,15 +21,13 @@ describe('valibotResolver', () => {
|
|
|
21
21
|
...a,
|
|
22
22
|
};
|
|
23
23
|
});
|
|
24
|
-
const
|
|
25
|
-
const parseAsyncSpy = vi.spyOn(valibot, 'parseAsync');
|
|
24
|
+
const funcSpy = vi.spyOn(valibot, 'safeParseAsync');
|
|
26
25
|
|
|
27
26
|
const result = await valibotResolver(schema, undefined, {
|
|
28
27
|
mode: 'sync',
|
|
29
28
|
})(validData, undefined, { fields, shouldUseNativeValidation });
|
|
30
29
|
|
|
31
|
-
expect(
|
|
32
|
-
expect(parseAsyncSpy).not.toHaveBeenCalled();
|
|
30
|
+
expect(funcSpy).toHaveBeenCalledTimes(1);
|
|
33
31
|
expect(result.errors).toEqual({});
|
|
34
32
|
expect(result).toMatchSnapshot();
|
|
35
33
|
});
|
|
@@ -42,15 +40,13 @@ describe('valibotResolver', () => {
|
|
|
42
40
|
...a,
|
|
43
41
|
};
|
|
44
42
|
});
|
|
45
|
-
const
|
|
46
|
-
const parseAsyncSpy = vi.spyOn(valibot, 'parseAsync');
|
|
43
|
+
const funcSpy = vi.spyOn(valibot, 'safeParseAsync');
|
|
47
44
|
|
|
48
45
|
const result = await valibotResolver(schema, undefined, {
|
|
49
46
|
mode: 'sync',
|
|
50
47
|
})(invalidData, undefined, { fields, shouldUseNativeValidation });
|
|
51
48
|
|
|
52
|
-
expect(
|
|
53
|
-
expect(parseAsyncSpy).not.toHaveBeenCalled();
|
|
49
|
+
expect(funcSpy).toHaveBeenCalledTimes(1);
|
|
54
50
|
expect(result).toMatchSnapshot();
|
|
55
51
|
});
|
|
56
52
|
|
|
@@ -107,7 +103,7 @@ describe('valibotResolver', () => {
|
|
|
107
103
|
expect(result).toMatchSnapshot();
|
|
108
104
|
});
|
|
109
105
|
|
|
110
|
-
it('should be able to validate variants', async () => {
|
|
106
|
+
it('should be able to validate variants without errors', async () => {
|
|
111
107
|
const result = await valibotResolver(schemaError, undefined, {
|
|
112
108
|
mode: 'sync',
|
|
113
109
|
})(validSchemaErrorData, undefined, {
|
|
@@ -123,7 +119,7 @@ describe('valibotResolver', () => {
|
|
|
123
119
|
});
|
|
124
120
|
});
|
|
125
121
|
|
|
126
|
-
it('should
|
|
122
|
+
it('should be able to validate variants with errors', async () => {
|
|
127
123
|
const result = await valibotResolver(schemaError, undefined, {
|
|
128
124
|
mode: 'sync',
|
|
129
125
|
})(invalidSchemaErrorData, undefined, {
|
|
@@ -132,7 +128,13 @@ describe('valibotResolver', () => {
|
|
|
132
128
|
});
|
|
133
129
|
|
|
134
130
|
expect(result).toEqual({
|
|
135
|
-
errors: {
|
|
131
|
+
errors: {
|
|
132
|
+
type: {
|
|
133
|
+
message: 'Invalid type: Expected "a" | "b" but received "c"',
|
|
134
|
+
ref: undefined,
|
|
135
|
+
type: 'variant',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
136
138
|
values: {},
|
|
137
139
|
});
|
|
138
140
|
});
|
package/valibot/src/types.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BaseIssue,
|
|
4
|
+
BaseSchema,
|
|
5
|
+
BaseSchemaAsync,
|
|
6
|
+
Config,
|
|
7
|
+
InferIssue,
|
|
8
|
+
} from 'valibot';
|
|
3
9
|
|
|
4
|
-
export type Resolver = <
|
|
10
|
+
export type Resolver = <
|
|
11
|
+
T extends
|
|
12
|
+
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
|
|
13
|
+
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
|
|
14
|
+
>(
|
|
5
15
|
schema: T,
|
|
6
|
-
schemaOptions?: Partial<
|
|
16
|
+
schemaOptions?: Partial<
|
|
17
|
+
Omit<Config<InferIssue<T>>, 'abortPipeEarly' | 'skipPipe'>
|
|
18
|
+
>,
|
|
7
19
|
resolverOptions?: {
|
|
8
20
|
/**
|
|
9
21
|
* @default async
|
package/valibot/src/valibot.ts
CHANGED
|
@@ -1,89 +1,67 @@
|
|
|
1
1
|
import { toNestErrors } from '@hookform/resolvers';
|
|
2
|
+
import { FieldError, appendErrors, FieldValues } from 'react-hook-form';
|
|
3
|
+
import { getDotPath, safeParseAsync } from 'valibot';
|
|
2
4
|
import type { Resolver } from './types';
|
|
3
|
-
import {
|
|
4
|
-
BaseSchema,
|
|
5
|
-
BaseSchemaAsync,
|
|
6
|
-
ValiError,
|
|
7
|
-
parse,
|
|
8
|
-
parseAsync,
|
|
9
|
-
} from 'valibot';
|
|
10
|
-
import { FieldErrors, FieldError, appendErrors } from 'react-hook-form';
|
|
11
|
-
const parseErrors = (
|
|
12
|
-
valiErrors: ValiError,
|
|
13
|
-
validateAllFieldCriteria: boolean,
|
|
14
|
-
): FieldErrors => {
|
|
15
|
-
const errors: Record<string, FieldError> = {};
|
|
16
|
-
|
|
17
|
-
for (const error of valiErrors.issues) {
|
|
18
|
-
if (!error.path) {
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
const _path = error.path.map(({ key }) => key).join('.');
|
|
22
|
-
|
|
23
|
-
if (!errors[_path]) {
|
|
24
|
-
errors[_path] = { message: error.message, type: error.validation };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (validateAllFieldCriteria) {
|
|
28
|
-
const types = errors[_path].types;
|
|
29
|
-
const messages = types && types[error.validation];
|
|
30
|
-
|
|
31
|
-
errors[_path] = appendErrors(
|
|
32
|
-
_path,
|
|
33
|
-
validateAllFieldCriteria,
|
|
34
|
-
errors,
|
|
35
|
-
error.validation,
|
|
36
|
-
messages
|
|
37
|
-
? ([] as string[]).concat(messages as string[], error.message)
|
|
38
|
-
: error.message,
|
|
39
|
-
) as FieldError;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return errors;
|
|
44
|
-
};
|
|
45
5
|
|
|
46
6
|
export const valibotResolver: Resolver =
|
|
47
7
|
(schema, schemaOptions, resolverOptions = {}) =>
|
|
48
8
|
async (values, _, options) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
abortEarly: false,
|
|
54
|
-
abortPipeEarly: false,
|
|
55
|
-
},
|
|
56
|
-
schemaOptions,
|
|
57
|
-
);
|
|
9
|
+
// Check if we should validate all field criteria
|
|
10
|
+
const validateAllFieldCriteria =
|
|
11
|
+
!options.shouldUseNativeValidation && options.criteriaMode === 'all';
|
|
58
12
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
values,
|
|
65
|
-
schemaOpts,
|
|
66
|
-
);
|
|
13
|
+
// Parse values with Valibot schema
|
|
14
|
+
const result = await safeParseAsync(schema, values, {
|
|
15
|
+
...schemaOptions,
|
|
16
|
+
abortPipeEarly: !validateAllFieldCriteria,
|
|
17
|
+
});
|
|
67
18
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
19
|
+
// If there are issues, return them as errors
|
|
20
|
+
if (result.issues) {
|
|
21
|
+
// Create errors object
|
|
22
|
+
const errors: Record<string, FieldError> = {};
|
|
23
|
+
|
|
24
|
+
// Iterate over issues to add them to errors object
|
|
25
|
+
for (const issue of result.issues) {
|
|
26
|
+
// Create dot path from issue
|
|
27
|
+
const path = getDotPath(issue);
|
|
28
|
+
|
|
29
|
+
if (path) {
|
|
30
|
+
// Add first error of path to errors object
|
|
31
|
+
if (!errors[path]) {
|
|
32
|
+
errors[path] = { message: issue.message, type: issue.type };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// If configured, add all errors of path to errors object
|
|
36
|
+
if (validateAllFieldCriteria) {
|
|
37
|
+
const types = errors[path].types;
|
|
38
|
+
const messages = types && types[issue.type];
|
|
39
|
+
errors[path] = appendErrors(
|
|
40
|
+
path,
|
|
41
|
+
validateAllFieldCriteria,
|
|
42
|
+
errors,
|
|
43
|
+
issue.type,
|
|
44
|
+
messages
|
|
45
|
+
? ([] as string[]).concat(
|
|
46
|
+
messages as string | string[],
|
|
47
|
+
issue.message,
|
|
48
|
+
)
|
|
49
|
+
: issue.message,
|
|
50
|
+
) as FieldError;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
85
53
|
}
|
|
86
54
|
|
|
87
|
-
|
|
55
|
+
// Return resolver result with errors
|
|
56
|
+
return {
|
|
57
|
+
values: {},
|
|
58
|
+
errors: toNestErrors(errors, options),
|
|
59
|
+
} as const;
|
|
88
60
|
}
|
|
61
|
+
|
|
62
|
+
// Otherwise, return resolver result with values
|
|
63
|
+
return {
|
|
64
|
+
values: resolverOptions.raw ? values : (result.output as FieldValues),
|
|
65
|
+
errors: {},
|
|
66
|
+
};
|
|
89
67
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
|
+
import { VineValidator } from '@vinejs/vine';
|
|
3
|
+
import { ValidationOptions } from '@vinejs/vine/build/src/types';
|
|
4
|
+
export type Resolver = <T extends VineValidator<any, any>>(schema: T, schemaOptions?: ValidationOptions<any>, resolverOptions?: {
|
|
5
|
+
raw?: boolean;
|
|
6
|
+
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=require("react-hook-form"),e=require("@hookform/resolvers"),t=require("@vinejs/vine");function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}var o=function(e,t){for(var o,a={},i=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return n(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(r,e):void 0}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(o=i()).done;){var s=o.value,u=s.rule,l=s.message,c=s.field;if(c in a||(a[c]={message:l,type:u}),t){var v=a[c].types,f=v&&v[u];a[c]=r.appendErrors(c,t,a,u,f?[].concat(f,[l]):l)}}return a};exports.vineResolver=function(r,n,a){return void 0===a&&(a={}),function(i,s,u){try{return Promise.resolve(function(t,o){try{var s=Promise.resolve(r.validate(i,n)).then(function(r){return u.shouldUseNativeValidation&&e.validateFieldsNatively({},u),{errors:{},values:a.raw?i:r}})}catch(r){return o(r)}return s&&s.then?s.then(void 0,o):s}(0,function(r){if(r instanceof t.errors.E_VALIDATION_ERROR)return{values:{},errors:e.toNestErrors(o(r.messages,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}}};
|
|
2
|
+
//# sourceMappingURL=vine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vine.js","sources":["../src/vine.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) => {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (const error of vineErrors) {\n const { field, rule, message } = error;\n const path = field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message, type: rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n rule,\n messages ? [...(messages as string[]), message] : message,\n ) as FieldError;\n }\n }\n\n return schemaErrors;\n};\n\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema.validate(values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","_step","schemaErrors","_iterator","_createForOfIteratorHelperLoose","done","error","value","rule","message","path","field","type","types","messages","appendErrors","concat","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"sMAKA,IAAMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAE8BC,EAFxBC,EAA2C,CAAA,EAEjDC,2qBAAAC,CAAoBL,KAAUE,EAAAE,KAAAE,MAAE,CAArB,IAAAC,EAAKL,EAAAM,MACCC,EAAkBF,EAAlBE,KAAMC,EAAYH,EAAZG,QACfC,EAD2BJ,EAAzBK,MAOR,GAJMD,KAAQR,IACZA,EAAaQ,GAAQ,CAAED,QAAAA,EAASG,KAAMJ,IAGpCR,EAA0B,CAC5B,IAAQa,EAAUX,EAAaQ,GAAvBG,MACFC,EAAWD,GAASA,EAAML,GAEhCN,EAAaQ,GAAQK,EAAYA,aAC/BL,EACAV,EACAE,EACAM,EACAM,EAAQE,GAAAA,OAAQF,EAAqB,CAAEL,IAAWA,EAErD,CACF,CAED,OAAOP,CACT,uBAGE,SAACe,EAAQC,EAAeC,eAAAA,IAAAA,IAAAA,EAAkB,aACnCC,EAAQC,EAAGC,OAAWC,OAAAA,QAAAC,gCACvBD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,cAAnDC,GAIN,OAFAL,EAAQM,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIP,GAEzD,CACLQ,OAAQ,CAAA,EACRV,OAAQD,EAAgBY,IAAMX,EAASO,EACvC,4DATuBK,CAAA,WAUlB1B,GACP,GAAIA,aAAiBwB,SAAOG,mBAC1B,MAAO,CACLb,OAAQ,GACRU,OAAQI,EAAAA,aACNpC,EACEQ,EAAMQ,UACLQ,EAAQM,2BACkB,QAAzBN,EAAQa,cAEZb,IAKN,MAAMhB,CACP,GACH,CAAC,MAAA8B,GAAA,OAAAb,QAAAc,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestErrors as t}from"@hookform/resolvers";import{errors as n}from"@vinejs/vine";function o(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}var a=function(e,t){for(var n,a={},i=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return o(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(r,e):void 0}}(r))){t&&(r=t);var n=0;return function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(n=i()).done;){var u=n.value,s=u.rule,l=u.message,c=u.field;if(c in a||(a[c]={message:l,type:s}),t){var f=a[c].types,v=f&&f[s];a[c]=r(c,t,a,s,v?[].concat(v,[l]):l)}}return a},i=function(r,o,i){return void 0===i&&(i={}),function(u,s,l){try{return Promise.resolve(function(t,n){try{var a=Promise.resolve(r.validate(u,o)).then(function(r){return l.shouldUseNativeValidation&&e({},l),{errors:{},values:i.raw?u:r}})}catch(r){return n(r)}return a&&a.then?a.then(void 0,n):a}(0,function(r){if(r instanceof n.E_VALIDATION_ERROR)return{values:{},errors:t(a(r.messages,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)};throw r}))}catch(r){return Promise.reject(r)}}};export{i as vineResolver};
|
|
2
|
+
//# sourceMappingURL=vine.module.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{appendErrors as e}from"react-hook-form";import{validateFieldsNatively as o,toNestErrors as r}from"@hookform/resolvers";import{errors as s}from"@vinejs/vine";const t=(o,r)=>{const s={};for(const t of o){const{field:o,rule:a,message:i}=t,n=o;if(n in s||(s[n]={message:i,type:a}),r){const{types:o}=s[n],t=o&&o[a];s[n]=e(n,r,s,a,t?[...t,i]:i)}}return s},a=(e,a,i={})=>async(n,c,l)=>{try{const r=await e.validate(n,a);return l.shouldUseNativeValidation&&o({},l),{errors:{},values:i.raw?n:r}}catch(e){if(e instanceof s.E_VALIDATION_ERROR)return{values:{},errors:r(t(e.messages,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)};throw e}};export{a as vineResolver};
|
|
2
|
+
//# sourceMappingURL=vine.modern.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vine.modern.mjs","sources":["../src/vine.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) => {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (const error of vineErrors) {\n const { field, rule, message } = error;\n const path = field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message, type: rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n rule,\n messages ? [...(messages as string[]), message] : message,\n ) as FieldError;\n }\n }\n\n return schemaErrors;\n};\n\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema.validate(values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","error","field","rule","message","path","type","types","messages","appendErrors","vineResolver","schema","schemaOptions","resolverOptions","async","values","_","options","data","validate","shouldUseNativeValidation","validateFieldsNatively","errors","raw","E_VALIDATION_ERROR","toNestErrors","criteriaMode"],"mappings":"oKAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAA2C,CAAA,EAEjD,IAAK,MAAMC,KAASH,EAAY,CAC9B,MAAMI,MAAEA,EAAKC,KAAEA,EAAIC,QAAEA,GAAYH,EAC3BI,EAAOH,EAMb,GAJMG,KAAQL,IACZA,EAAaK,GAAQ,CAAED,UAASE,KAAMH,IAGpCJ,EAA0B,CAC5B,MAAMQ,MAAEA,GAAUP,EAAaK,GACzBG,EAAWD,GAASA,EAAMJ,GAEhCH,EAAaK,GAAQI,EACnBJ,EACAN,EACAC,EACAG,EACAK,EAAW,IAAKA,EAAuBJ,GAAWA,EAErD,CACF,CAED,OAAOJ,GAGIU,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAE,IAC5CC,MAAOC,EAAQC,EAAGC,KAChB,IACE,MAAMC,QAAaP,EAAOQ,SAASJ,EAAQH,GAI3C,OAFAK,EAAQG,2BAA6BC,EAAuB,CAAE,EAAEJ,GAEzD,CACLK,OAAQ,CAAiB,EACzBP,OAAQF,EAAgBU,IAAMR,EAASG,EAE1C,CAAC,MAAOjB,GACP,GAAIA,aAAiBqB,EAAOE,mBAC1B,MAAO,CACLT,OAAQ,CAAA,EACRO,OAAQG,EACN5B,EACEI,EAAMO,UACLS,EAAQG,2BACkB,QAAzBH,EAAQS,cAEZT,IAKN,MAAMhB,CACP"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestErrors as t}from"@hookform/resolvers";import{errors as n}from"@vinejs/vine";function o(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}var a=function(e,t){for(var n,a={},i=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return o(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(r,e):void 0}}(r))){t&&(r=t);var n=0;return function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(n=i()).done;){var u=n.value,s=u.rule,l=u.message,c=u.field;if(c in a||(a[c]={message:l,type:s}),t){var f=a[c].types,v=f&&f[s];a[c]=r(c,t,a,s,v?[].concat(v,[l]):l)}}return a},i=function(r,o,i){return void 0===i&&(i={}),function(u,s,l){try{return Promise.resolve(function(t,n){try{var a=Promise.resolve(r.validate(u,o)).then(function(r){return l.shouldUseNativeValidation&&e({},l),{errors:{},values:i.raw?u:r}})}catch(r){return n(r)}return a&&a.then?a.then(void 0,n):a}(0,function(r){if(r instanceof n.E_VALIDATION_ERROR)return{values:{},errors:t(a(r.messages,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)};throw r}))}catch(r){return Promise.reject(r)}}};export{i as vineResolver};
|
|
2
|
+
//# sourceMappingURL=vine.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vine.module.js","sources":["../src/vine.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) => {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (const error of vineErrors) {\n const { field, rule, message } = error;\n const path = field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message, type: rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n rule,\n messages ? [...(messages as string[]), message] : message,\n ) as FieldError;\n }\n }\n\n return schemaErrors;\n};\n\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema.validate(values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","_step","schemaErrors","_iterator","_createForOfIteratorHelperLoose","done","error","value","rule","message","path","field","type","types","messages","appendErrors","concat","vineResolver","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"8QAKA,IAAMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAE8BC,EAFxBC,EAA2C,CAAA,EAEjDC,2qBAAAC,CAAoBL,KAAUE,EAAAE,KAAAE,MAAE,CAArB,IAAAC,EAAKL,EAAAM,MACCC,EAAkBF,EAAlBE,KAAMC,EAAYH,EAAZG,QACfC,EAD2BJ,EAAzBK,MAOR,GAJMD,KAAQR,IACZA,EAAaQ,GAAQ,CAAED,QAAAA,EAASG,KAAMJ,IAGpCR,EAA0B,CAC5B,IAAQa,EAAUX,EAAaQ,GAAvBG,MACFC,EAAWD,GAASA,EAAML,GAEhCN,EAAaQ,GAAQK,EACnBL,EACAV,EACAE,EACAM,EACAM,EAAQE,GAAAA,OAAQF,EAAqB,CAAEL,IAAWA,EAErD,CACF,CAED,OAAOP,CACT,EAEae,EACX,SAACC,EAAQC,EAAeC,eAAAA,IAAAA,IAAAA,EAAkB,aACnCC,EAAQC,EAAGC,OAAWC,OAAAA,QAAAC,gCACvBD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,cAAnDC,GAIN,OAFAL,EAAQM,2BAA6BC,EAAuB,CAAA,EAAIP,GAEzD,CACLQ,OAAQ,CAAA,EACRV,OAAQD,EAAgBY,IAAMX,EAASO,EACvC,4DATuBK,CAAA,WAUlB3B,GACP,GAAIA,aAAiByB,EAAOG,mBAC1B,MAAO,CACLb,OAAQ,GACRU,OAAQI,EACNrC,EACEQ,EAAMQ,UACLS,EAAQM,2BACkB,QAAzBN,EAAQa,cAEZb,IAKN,MAAMjB,CACP,GACH,CAAC,MAAA+B,GAAA,OAAAb,QAAAc,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react-hook-form"),require("@hookform/resolvers"),require("@vinejs/vine")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers","@vinejs/vine"],r):r((e||self).hookformResolversVine={},e.ReactHookForm,e.hookformResolvers,e.vine)}(this,function(e,r,t,o){function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}var i=function(e,t){for(var o,i={},a=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}(e))){t&&(e=t);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(o=a()).done;){var s=o.value,l=s.rule,u=s.message,f=s.field;if(f in i||(i[f]={message:u,type:l}),t){var c=i[f].types,v=c&&c[l];i[f]=r.appendErrors(f,t,i,l,v?[].concat(v,[u]):u)}}return i};e.vineResolver=function(e,r,n){return void 0===n&&(n={}),function(a,s,l){try{return Promise.resolve(function(o,i){try{var s=Promise.resolve(e.validate(a,r)).then(function(e){return l.shouldUseNativeValidation&&t.validateFieldsNatively({},l),{errors:{},values:n.raw?a:e}})}catch(e){return i(e)}return s&&s.then?s.then(void 0,i):s}(0,function(e){if(e instanceof o.errors.E_VALIDATION_ERROR)return{values:{},errors:t.toNestErrors(i(e.messages,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)};throw e}))}catch(e){return Promise.reject(e)}}}});
|
|
2
|
+
//# sourceMappingURL=vine.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vine.umd.js","sources":["../src/vine.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) => {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (const error of vineErrors) {\n const { field, rule, message } = error;\n const path = field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message, type: rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n rule,\n messages ? [...(messages as string[]), message] : message,\n ) as FieldError;\n }\n }\n\n return schemaErrors;\n};\n\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema.validate(values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","_step","schemaErrors","_iterator","_createForOfIteratorHelperLoose","done","error","value","rule","message","path","field","type","types","messages","appendErrors","concat","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"mhBAKA,IAAMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAE8BC,EAFxBC,EAA2C,CAAA,EAEjDC,2qBAAAC,CAAoBL,KAAUE,EAAAE,KAAAE,MAAE,CAArB,IAAAC,EAAKL,EAAAM,MACCC,EAAkBF,EAAlBE,KAAMC,EAAYH,EAAZG,QACfC,EAD2BJ,EAAzBK,MAOR,GAJMD,KAAQR,IACZA,EAAaQ,GAAQ,CAAED,QAAAA,EAASG,KAAMJ,IAGpCR,EAA0B,CAC5B,IAAQa,EAAUX,EAAaQ,GAAvBG,MACFC,EAAWD,GAASA,EAAML,GAEhCN,EAAaQ,GAAQK,EAAYA,aAC/BL,EACAV,EACAE,EACAM,EACAM,EAAQE,GAAAA,OAAQF,EAAqB,CAAEL,IAAWA,EAErD,CACF,CAED,OAAOP,CACT,iBAGE,SAACe,EAAQC,EAAeC,eAAAA,IAAAA,IAAAA,EAAkB,aACnCC,EAAQC,EAAGC,OAAWC,OAAAA,QAAAC,gCACvBD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,cAAnDC,GAIN,OAFAL,EAAQM,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIP,GAEzD,CACLQ,OAAQ,CAAA,EACRV,OAAQD,EAAgBY,IAAMX,EAASO,EACvC,4DATuBK,CAAA,WAUlB1B,GACP,GAAIA,aAAiBwB,SAAOG,mBAC1B,MAAO,CACLb,OAAQ,GACRU,OAAQI,EAAAA,aACNpC,EACEQ,EAAMQ,UACLQ,EAAQM,2BACkB,QAAzBN,EAAQa,cAEZb,IAKN,MAAMhB,CACP,GACH,CAAC,MAAA8B,GAAA,OAAAb,QAAAc,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hookform/resolvers/vine",
|
|
3
|
+
"amdName": "hookformResolversVine",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"description": "React Hook Form validation resolver: vine",
|
|
7
|
+
"main": "dist/vine.js",
|
|
8
|
+
"module": "dist/vine.module.js",
|
|
9
|
+
"umd:main": "dist/vine.umd.js",
|
|
10
|
+
"source": "src/index.ts",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react-hook-form": "^7.0.0",
|
|
15
|
+
"@hookform/resolvers": "^2.0.0",
|
|
16
|
+
"@vinejs/vine": "^2.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|