@hookform/resolvers 2.9.11 → 3.0.1
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 +51 -5
- package/ajv/dist/ajv.d.ts +2 -2
- package/ajv/dist/ajv.js +1 -7
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.mjs +1 -7
- package/ajv/dist/ajv.modern.mjs +2 -0
- package/ajv/dist/ajv.modern.mjs.map +1 -0
- package/ajv/dist/ajv.module.js +1 -7
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js +1 -7
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/index.d.ts +2 -2
- package/ajv/dist/types.d.ts +5 -5
- package/ajv/package.json +3 -1
- package/ajv/src/__tests__/Form-native-validation.tsx +5 -9
- package/ajv/src/__tests__/Form.tsx +4 -6
- package/ajv/src/__tests__/__fixtures__/data.ts +3 -4
- package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +83 -83
- package/ajv/src/ajv.ts +28 -24
- package/class-validator/dist/class-validator.d.ts +2 -2
- package/class-validator/dist/class-validator.js +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.mjs +1 -1
- package/class-validator/dist/class-validator.modern.mjs +2 -0
- package/class-validator/dist/class-validator.modern.mjs.map +1 -0
- package/class-validator/dist/class-validator.module.js +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/index.d.ts +2 -2
- package/class-validator/dist/types.d.ts +12 -9
- package/class-validator/src/__tests__/Form-native-validation.tsx +5 -9
- package/class-validator/src/__tests__/Form.tsx +4 -6
- package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +102 -67
- package/class-validator/src/__tests__/class-validator.ts +66 -6
- package/class-validator/src/class-validator.ts +6 -4
- package/class-validator/src/types.ts +7 -8
- package/computed-types/dist/computed-types.d.ts +2 -2
- package/computed-types/dist/computed-types.js +1 -1
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.mjs +1 -1
- package/computed-types/dist/computed-types.modern.mjs +2 -0
- package/computed-types/dist/computed-types.modern.mjs.map +1 -0
- package/computed-types/dist/computed-types.module.js +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/dist/index.d.ts +2 -2
- package/computed-types/dist/types.d.ts +2 -2
- package/computed-types/src/__tests__/Form-native-validation.tsx +5 -9
- package/computed-types/src/__tests__/Form.tsx +4 -6
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +21 -21
- package/computed-types/src/__tests__/computed-types.ts +16 -0
- package/computed-types/src/computed-types.ts +12 -5
- package/dist/index.d.ts +2 -2
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +1 -1
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/dist/toNestError.d.ts +2 -2
- package/dist/validateFieldsNatively.d.ts +2 -2
- package/io-ts/dist/arrayToPath.d.ts +3 -3
- package/io-ts/dist/errorsToRecord.d.ts +5 -5
- package/io-ts/dist/index.d.ts +2 -2
- package/io-ts/dist/io-ts.d.ts +2 -2
- package/io-ts/dist/io-ts.js +1 -1
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs +2 -0
- package/io-ts/dist/io-ts.modern.mjs.map +1 -0
- package/io-ts/dist/io-ts.module.js +1 -1
- package/io-ts/dist/io-ts.module.js.map +1 -1
- package/io-ts/dist/io-ts.umd.js +1 -1
- package/io-ts/dist/io-ts.umd.js.map +1 -1
- package/io-ts/dist/types.d.ts +7 -7
- package/io-ts/src/__tests__/Form-native-validation.tsx +5 -9
- package/io-ts/src/__tests__/Form.tsx +4 -6
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +28 -28
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/joi/dist/index.d.ts +2 -2
- package/joi/dist/joi.d.ts +2 -2
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/{joi.modern.js → joi.modern.mjs} +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -0
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/dist/types.d.ts +5 -5
- package/joi/src/__tests__/Form-native-validation.tsx +5 -9
- package/joi/src/__tests__/Form.tsx +4 -6
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +87 -87
- package/joi/src/__tests__/joi.ts +8 -8
- package/nope/dist/index.d.ts +2 -2
- package/nope/dist/nope.d.ts +2 -2
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/{nope.modern.js → nope.modern.mjs} +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -0
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/dist/types.d.ts +9 -9
- package/nope/src/__tests__/Form-native-validation.tsx +5 -9
- package/nope/src/__tests__/Form.tsx +4 -6
- package/nope/src/__tests__/__snapshots__/nope.ts.snap +15 -15
- package/nope/src/__tests__/nope.ts +1 -1
- package/package.json +74 -44
- package/superstruct/dist/index.d.ts +2 -2
- package/superstruct/dist/superstruct.d.ts +2 -2
- package/superstruct/dist/superstruct.js +1 -1
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.mjs +1 -1
- package/superstruct/dist/superstruct.modern.mjs +2 -0
- package/superstruct/dist/superstruct.modern.mjs.map +1 -0
- package/superstruct/dist/superstruct.module.js +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/dist/types.d.ts +11 -5
- package/superstruct/src/__tests__/Form-native-validation.tsx +5 -9
- package/superstruct/src/__tests__/Form.tsx +4 -6
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +19 -19
- package/superstruct/src/__tests__/superstruct.ts +13 -0
- package/superstruct/src/superstruct.ts +4 -3
- package/superstruct/src/types.ts +8 -5
- package/typanion/dist/index.d.ts +2 -2
- package/typanion/dist/typanion.d.ts +2 -2
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/{typanion.modern.js → typanion.modern.mjs} +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -0
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/dist/types.d.ts +9 -9
- package/typanion/src/__tests__/Form-native-validation.tsx +7 -10
- package/typanion/src/__tests__/Form.tsx +9 -7
- package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +22 -22
- package/typanion/src/__tests__/typanion.ts +11 -7
- package/typanion/src/typanion.ts +1 -1
- package/typebox/dist/index.d.ts +2 -0
- package/typebox/dist/typebox.d.ts +2 -0
- package/typebox/dist/typebox.js +2 -0
- package/typebox/dist/typebox.js.map +1 -0
- package/typebox/dist/typebox.mjs +2 -0
- package/typebox/dist/typebox.modern.mjs +2 -0
- package/typebox/dist/typebox.modern.mjs.map +1 -0
- package/typebox/dist/typebox.module.js +2 -0
- package/typebox/dist/typebox.module.js.map +1 -0
- package/typebox/dist/typebox.umd.js +2 -0
- package/typebox/dist/typebox.umd.js.map +1 -0
- package/typebox/dist/types.d.ts +3 -0
- package/typebox/package.json +18 -0
- package/typebox/src/__tests__/Form-native-validation.tsx +83 -0
- package/typebox/src/__tests__/Form.tsx +54 -0
- package/typebox/src/__tests__/__fixtures__/data.ts +84 -0
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +190 -0
- package/typebox/src/__tests__/typebox.ts +34 -0
- package/typebox/src/index.ts +2 -0
- package/typebox/src/typebox.ts +64 -0
- package/typebox/src/types.ts +10 -0
- package/vest/dist/index.d.ts +2 -2
- package/vest/dist/types.d.ts +8 -8
- package/vest/dist/vest.d.ts +2 -2
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/{vest.modern.js → vest.modern.mjs} +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -0
- package/vest/dist/vest.module.js.map +1 -1
- package/vest/dist/vest.umd.js.map +1 -1
- package/vest/src/__tests__/Form-native-validation.tsx +5 -9
- package/vest/src/__tests__/Form.tsx +6 -10
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +47 -47
- package/yup/dist/index.d.ts +2 -2
- package/yup/dist/types.d.ts +15 -9
- package/yup/dist/yup.d.ts +2 -2
- package/yup/dist/yup.js +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.mjs +1 -1
- package/yup/dist/yup.modern.mjs +2 -0
- package/yup/dist/yup.modern.mjs.map +1 -0
- package/yup/dist/yup.module.js +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/Form-native-validation.tsx +5 -9
- package/yup/src/__tests__/Form.tsx +4 -6
- package/yup/src/__tests__/__fixtures__/data.ts +2 -3
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +100 -87
- package/yup/src/__tests__/yup.ts +49 -18
- package/yup/src/types.ts +14 -11
- package/yup/src/yup.ts +1 -1
- package/zod/dist/index.d.ts +2 -2
- package/zod/dist/types.d.ts +13 -13
- package/zod/dist/zod.d.ts +2 -2
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +2 -0
- package/zod/dist/zod.modern.mjs.map +1 -0
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/Form-native-validation.tsx +5 -9
- package/zod/src/__tests__/Form.tsx +4 -6
- package/zod/src/__tests__/__snapshots__/zod.ts.snap +120 -120
- package/zod/src/__tests__/zod.ts +19 -7
- package/zod/src/types.ts +2 -6
- package/zod/src/zod.ts +27 -27
- package/ajv/dist/ajv.modern.js +0 -8
- package/ajv/dist/ajv.modern.js.map +0 -1
- package/class-validator/dist/class-validator.modern.js +0 -2
- package/class-validator/dist/class-validator.modern.js.map +0 -1
- package/computed-types/dist/computed-types.modern.js +0 -2
- package/computed-types/dist/computed-types.modern.js.map +0 -1
- package/io-ts/dist/io-ts.modern.js +0 -2
- package/io-ts/dist/io-ts.modern.js.map +0 -1
- package/joi/dist/joi.modern.js.map +0 -1
- package/nope/dist/nope.modern.js.map +0 -1
- package/superstruct/dist/superstruct.modern.js +0 -2
- package/superstruct/dist/superstruct.modern.js.map +0 -1
- package/typanion/dist/typanion.modern.js.map +0 -1
- package/vest/dist/vest.modern.js.map +0 -1
- package/yup/dist/yup.modern.js +0 -2
- package/yup/dist/yup.modern.js.map +0 -1
- package/zod/dist/zod.modern.js +0 -2
- package/zod/dist/zod.modern.js.map +0 -1
package/ajv/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './ajv';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './ajv';
|
|
2
|
+
export * from './types';
|
package/ajv/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
-
import * as Ajv from 'ajv';
|
|
3
|
-
export
|
|
4
|
-
mode?: 'async' | 'sync';
|
|
5
|
-
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
+
import * as Ajv from 'ajv';
|
|
3
|
+
export type Resolver = <T>(schema: Ajv.JSONSchemaType<T>, schemaOptions?: Ajv.Options, factoryOptions?: {
|
|
4
|
+
mode?: 'async' | 'sync';
|
|
5
|
+
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
package/ajv/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
2
|
import user from '@testing-library/user-event';
|
|
3
3
|
import { JSONSchemaType } from 'ajv';
|
|
4
4
|
import React from 'react';
|
|
@@ -50,7 +50,7 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
test("form's native validation with Ajv", async () => {
|
|
53
|
-
const handleSubmit =
|
|
53
|
+
const handleSubmit = vi.fn();
|
|
54
54
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
55
55
|
|
|
56
56
|
// username
|
|
@@ -67,9 +67,7 @@ test("form's native validation with Ajv", async () => {
|
|
|
67
67
|
expect(passwordField.validity.valid).toBe(true);
|
|
68
68
|
expect(passwordField.validationMessage).toBe('');
|
|
69
69
|
|
|
70
|
-
await
|
|
71
|
-
user.click(screen.getByText(/submit/i));
|
|
72
|
-
});
|
|
70
|
+
await user.click(screen.getByText(/submit/i));
|
|
73
71
|
|
|
74
72
|
// username
|
|
75
73
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -81,10 +79,8 @@ test("form's native validation with Ajv", async () => {
|
|
|
81
79
|
expect(passwordField.validity.valid).toBe(false);
|
|
82
80
|
expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
|
|
83
81
|
|
|
84
|
-
await
|
|
85
|
-
|
|
86
|
-
user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
87
|
-
});
|
|
82
|
+
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
|
83
|
+
await user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
88
84
|
|
|
89
85
|
// username
|
|
90
86
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
2
|
import user from '@testing-library/user-event';
|
|
3
3
|
import { JSONSchemaType } from 'ajv';
|
|
4
4
|
import React from 'react';
|
|
@@ -52,14 +52,12 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
test("form's validation with Ajv and TypeScript's integration", async () => {
|
|
55
|
-
const handleSubmit =
|
|
55
|
+
const handleSubmit = vi.fn();
|
|
56
56
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
57
57
|
|
|
58
|
-
expect(screen.queryAllByRole(
|
|
58
|
+
expect(screen.queryAllByRole('alert')).toHaveLength(0);
|
|
59
59
|
|
|
60
|
-
await
|
|
61
|
-
user.click(screen.getByText(/submit/i));
|
|
62
|
-
});
|
|
60
|
+
await user.click(screen.getByText(/submit/i));
|
|
63
61
|
|
|
64
62
|
expect(screen.getByText(/username field is required/i)).toBeInTheDocument();
|
|
65
63
|
expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
|
|
@@ -23,7 +23,6 @@ export const schema: JSONSchemaType<Data> = {
|
|
|
23
23
|
},
|
|
24
24
|
deepObject: {
|
|
25
25
|
type: 'object',
|
|
26
|
-
nullable: true,
|
|
27
26
|
properties: {
|
|
28
27
|
data: { type: 'string' },
|
|
29
28
|
twoLayersDeep: {
|
|
@@ -56,7 +55,7 @@ export const invalidData = {
|
|
|
56
55
|
password: 'invalid-password',
|
|
57
56
|
deepObject: {
|
|
58
57
|
data: 233,
|
|
59
|
-
twoLayersDeep: { name: 123 }
|
|
58
|
+
twoLayersDeep: { name: 123 },
|
|
60
59
|
},
|
|
61
60
|
};
|
|
62
61
|
|
|
@@ -68,8 +67,8 @@ export const invalidDataWithUndefined = {
|
|
|
68
67
|
name: 'deeper',
|
|
69
68
|
},
|
|
70
69
|
data: undefined,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
73
72
|
|
|
74
73
|
export const fields: Record<InternalFieldName, Field['_f']> = {
|
|
75
74
|
username: {
|
|
@@ -1,245 +1,245 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`ajvResolver should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true 1`] = `
|
|
4
|
-
|
|
5
|
-
"errors":
|
|
6
|
-
"deepObject":
|
|
3
|
+
exports[`ajvResolver > should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"deepObject": {
|
|
7
7
|
"message": "must have required property 'deepObject'",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "required",
|
|
10
10
|
},
|
|
11
|
-
"password":
|
|
11
|
+
"password": {
|
|
12
12
|
"message": "must have required property 'password'",
|
|
13
|
-
"ref":
|
|
13
|
+
"ref": {
|
|
14
14
|
"name": "password",
|
|
15
15
|
},
|
|
16
16
|
"type": "required",
|
|
17
17
|
},
|
|
18
|
-
"username":
|
|
18
|
+
"username": {
|
|
19
19
|
"message": "must have required property 'username'",
|
|
20
|
-
"ref":
|
|
20
|
+
"ref": {
|
|
21
21
|
"name": "username",
|
|
22
22
|
},
|
|
23
23
|
"type": "required",
|
|
24
24
|
},
|
|
25
25
|
},
|
|
26
|
-
"values":
|
|
26
|
+
"values": {},
|
|
27
27
|
}
|
|
28
28
|
`;
|
|
29
29
|
|
|
30
|
-
exports[`ajvResolver should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
|
|
31
|
-
|
|
32
|
-
"errors":
|
|
33
|
-
"deepObject":
|
|
30
|
+
exports[`ajvResolver > should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
|
|
31
|
+
{
|
|
32
|
+
"errors": {
|
|
33
|
+
"deepObject": {
|
|
34
34
|
"message": "must have required property 'deepObject'",
|
|
35
35
|
"ref": undefined,
|
|
36
36
|
"type": "required",
|
|
37
37
|
},
|
|
38
|
-
"password":
|
|
38
|
+
"password": {
|
|
39
39
|
"message": "must have required property 'password'",
|
|
40
|
-
"ref":
|
|
40
|
+
"ref": {
|
|
41
41
|
"name": "password",
|
|
42
42
|
},
|
|
43
43
|
"type": "required",
|
|
44
44
|
},
|
|
45
|
-
"username":
|
|
45
|
+
"username": {
|
|
46
46
|
"message": "must have required property 'username'",
|
|
47
|
-
"ref":
|
|
47
|
+
"ref": {
|
|
48
48
|
"name": "username",
|
|
49
49
|
},
|
|
50
50
|
"type": "required",
|
|
51
51
|
},
|
|
52
52
|
},
|
|
53
|
-
"values":
|
|
53
|
+
"values": {},
|
|
54
54
|
}
|
|
55
55
|
`;
|
|
56
56
|
|
|
57
|
-
exports[`ajvResolver should return all the error messages from ajvResolver when some property is undefined and result will keep the input data structure 1`] = `
|
|
58
|
-
|
|
59
|
-
"errors":
|
|
60
|
-
"deepObject":
|
|
61
|
-
"data":
|
|
57
|
+
exports[`ajvResolver > should return all the error messages from ajvResolver when some property is undefined and result will keep the input data structure 1`] = `
|
|
58
|
+
{
|
|
59
|
+
"errors": {
|
|
60
|
+
"deepObject": {
|
|
61
|
+
"data": {
|
|
62
62
|
"message": "must have required property 'data'",
|
|
63
63
|
"ref": undefined,
|
|
64
64
|
"type": "required",
|
|
65
65
|
},
|
|
66
66
|
},
|
|
67
|
-
"password":
|
|
67
|
+
"password": {
|
|
68
68
|
"message": "must have required property 'password'",
|
|
69
|
-
"ref":
|
|
69
|
+
"ref": {
|
|
70
70
|
"name": "password",
|
|
71
71
|
},
|
|
72
72
|
"type": "required",
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
|
-
"values":
|
|
75
|
+
"values": {},
|
|
76
76
|
}
|
|
77
77
|
`;
|
|
78
78
|
|
|
79
|
-
exports[`ajvResolver should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true 1`] = `
|
|
80
|
-
|
|
81
|
-
"errors":
|
|
82
|
-
"deepObject":
|
|
83
|
-
"data":
|
|
79
|
+
exports[`ajvResolver > should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true 1`] = `
|
|
80
|
+
{
|
|
81
|
+
"errors": {
|
|
82
|
+
"deepObject": {
|
|
83
|
+
"data": {
|
|
84
84
|
"message": "must be string",
|
|
85
85
|
"ref": undefined,
|
|
86
86
|
"type": "type",
|
|
87
|
-
"types":
|
|
87
|
+
"types": {
|
|
88
88
|
"type": "must be string",
|
|
89
89
|
},
|
|
90
90
|
},
|
|
91
|
-
"twoLayersDeep":
|
|
92
|
-
"name":
|
|
91
|
+
"twoLayersDeep": {
|
|
92
|
+
"name": {
|
|
93
93
|
"message": "must be string",
|
|
94
94
|
"ref": undefined,
|
|
95
95
|
"type": "type",
|
|
96
|
-
"types":
|
|
96
|
+
"types": {
|
|
97
97
|
"type": "must be string",
|
|
98
98
|
},
|
|
99
99
|
},
|
|
100
100
|
},
|
|
101
101
|
},
|
|
102
|
-
"password":
|
|
102
|
+
"password": {
|
|
103
103
|
"message": "One uppercase character",
|
|
104
|
-
"ref":
|
|
104
|
+
"ref": {
|
|
105
105
|
"name": "password",
|
|
106
106
|
},
|
|
107
107
|
"type": "errorMessage",
|
|
108
|
-
"types":
|
|
108
|
+
"types": {
|
|
109
109
|
"errorMessage": "One uppercase character",
|
|
110
110
|
},
|
|
111
111
|
},
|
|
112
|
-
"username":
|
|
112
|
+
"username": {
|
|
113
113
|
"message": "must NOT have fewer than 3 characters",
|
|
114
|
-
"ref":
|
|
114
|
+
"ref": {
|
|
115
115
|
"name": "username",
|
|
116
116
|
},
|
|
117
117
|
"type": "minLength",
|
|
118
|
-
"types":
|
|
118
|
+
"types": {
|
|
119
119
|
"minLength": "must NOT have fewer than 3 characters",
|
|
120
120
|
},
|
|
121
121
|
},
|
|
122
122
|
},
|
|
123
|
-
"values":
|
|
123
|
+
"values": {},
|
|
124
124
|
}
|
|
125
125
|
`;
|
|
126
126
|
|
|
127
|
-
exports[`ajvResolver should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
|
|
128
|
-
|
|
129
|
-
"errors":
|
|
130
|
-
"deepObject":
|
|
131
|
-
"data":
|
|
127
|
+
exports[`ajvResolver > should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
|
|
128
|
+
{
|
|
129
|
+
"errors": {
|
|
130
|
+
"deepObject": {
|
|
131
|
+
"data": {
|
|
132
132
|
"message": "must be string",
|
|
133
133
|
"ref": undefined,
|
|
134
134
|
"type": "type",
|
|
135
|
-
"types":
|
|
135
|
+
"types": {
|
|
136
136
|
"type": "must be string",
|
|
137
137
|
},
|
|
138
138
|
},
|
|
139
|
-
"twoLayersDeep":
|
|
140
|
-
"name":
|
|
139
|
+
"twoLayersDeep": {
|
|
140
|
+
"name": {
|
|
141
141
|
"message": "must be string",
|
|
142
142
|
"ref": undefined,
|
|
143
143
|
"type": "type",
|
|
144
|
-
"types":
|
|
144
|
+
"types": {
|
|
145
145
|
"type": "must be string",
|
|
146
146
|
},
|
|
147
147
|
},
|
|
148
148
|
},
|
|
149
149
|
},
|
|
150
|
-
"password":
|
|
150
|
+
"password": {
|
|
151
151
|
"message": "One uppercase character",
|
|
152
|
-
"ref":
|
|
152
|
+
"ref": {
|
|
153
153
|
"name": "password",
|
|
154
154
|
},
|
|
155
155
|
"type": "errorMessage",
|
|
156
|
-
"types":
|
|
156
|
+
"types": {
|
|
157
157
|
"errorMessage": "One uppercase character",
|
|
158
158
|
},
|
|
159
159
|
},
|
|
160
|
-
"username":
|
|
160
|
+
"username": {
|
|
161
161
|
"message": "must NOT have fewer than 3 characters",
|
|
162
|
-
"ref":
|
|
162
|
+
"ref": {
|
|
163
163
|
"name": "username",
|
|
164
164
|
},
|
|
165
165
|
"type": "minLength",
|
|
166
|
-
"types":
|
|
166
|
+
"types": {
|
|
167
167
|
"minLength": "must NOT have fewer than 3 characters",
|
|
168
168
|
},
|
|
169
169
|
},
|
|
170
170
|
},
|
|
171
|
-
"values":
|
|
171
|
+
"values": {},
|
|
172
172
|
}
|
|
173
173
|
`;
|
|
174
174
|
|
|
175
|
-
exports[`ajvResolver should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false 1`] = `
|
|
176
|
-
|
|
177
|
-
"errors":
|
|
178
|
-
"deepObject":
|
|
179
|
-
"data":
|
|
175
|
+
exports[`ajvResolver > should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false 1`] = `
|
|
176
|
+
{
|
|
177
|
+
"errors": {
|
|
178
|
+
"deepObject": {
|
|
179
|
+
"data": {
|
|
180
180
|
"message": "must be string",
|
|
181
181
|
"ref": undefined,
|
|
182
182
|
"type": "type",
|
|
183
183
|
},
|
|
184
|
-
"twoLayersDeep":
|
|
185
|
-
"name":
|
|
184
|
+
"twoLayersDeep": {
|
|
185
|
+
"name": {
|
|
186
186
|
"message": "must be string",
|
|
187
187
|
"ref": undefined,
|
|
188
188
|
"type": "type",
|
|
189
189
|
},
|
|
190
190
|
},
|
|
191
191
|
},
|
|
192
|
-
"password":
|
|
192
|
+
"password": {
|
|
193
193
|
"message": "One uppercase character",
|
|
194
|
-
"ref":
|
|
194
|
+
"ref": {
|
|
195
195
|
"name": "password",
|
|
196
196
|
},
|
|
197
197
|
"type": "errorMessage",
|
|
198
198
|
},
|
|
199
|
-
"username":
|
|
199
|
+
"username": {
|
|
200
200
|
"message": "must NOT have fewer than 3 characters",
|
|
201
|
-
"ref":
|
|
201
|
+
"ref": {
|
|
202
202
|
"name": "username",
|
|
203
203
|
},
|
|
204
204
|
"type": "minLength",
|
|
205
205
|
},
|
|
206
206
|
},
|
|
207
|
-
"values":
|
|
207
|
+
"values": {},
|
|
208
208
|
}
|
|
209
209
|
`;
|
|
210
210
|
|
|
211
|
-
exports[`ajvResolver should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false and \`mode: sync\` 1`] = `
|
|
212
|
-
|
|
213
|
-
"errors":
|
|
214
|
-
"deepObject":
|
|
215
|
-
"data":
|
|
211
|
+
exports[`ajvResolver > should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false and \`mode: sync\` 1`] = `
|
|
212
|
+
{
|
|
213
|
+
"errors": {
|
|
214
|
+
"deepObject": {
|
|
215
|
+
"data": {
|
|
216
216
|
"message": "must be string",
|
|
217
217
|
"ref": undefined,
|
|
218
218
|
"type": "type",
|
|
219
219
|
},
|
|
220
|
-
"twoLayersDeep":
|
|
221
|
-
"name":
|
|
220
|
+
"twoLayersDeep": {
|
|
221
|
+
"name": {
|
|
222
222
|
"message": "must be string",
|
|
223
223
|
"ref": undefined,
|
|
224
224
|
"type": "type",
|
|
225
225
|
},
|
|
226
226
|
},
|
|
227
227
|
},
|
|
228
|
-
"password":
|
|
228
|
+
"password": {
|
|
229
229
|
"message": "One uppercase character",
|
|
230
|
-
"ref":
|
|
230
|
+
"ref": {
|
|
231
231
|
"name": "password",
|
|
232
232
|
},
|
|
233
233
|
"type": "errorMessage",
|
|
234
234
|
},
|
|
235
|
-
"username":
|
|
235
|
+
"username": {
|
|
236
236
|
"message": "must NOT have fewer than 3 characters",
|
|
237
|
-
"ref":
|
|
237
|
+
"ref": {
|
|
238
238
|
"name": "username",
|
|
239
239
|
},
|
|
240
240
|
"type": "minLength",
|
|
241
241
|
},
|
|
242
242
|
},
|
|
243
|
-
"values":
|
|
243
|
+
"values": {},
|
|
244
244
|
}
|
|
245
245
|
`;
|
package/ajv/src/ajv.ts
CHANGED
|
@@ -48,37 +48,41 @@ const parseErrorSchema = (
|
|
|
48
48
|
export const ajvResolver: Resolver =
|
|
49
49
|
(schema, schemaOptions, resolverOptions = {}) =>
|
|
50
50
|
async (values, _, options) => {
|
|
51
|
-
const ajv = new Ajv(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
const ajv = new Ajv(
|
|
52
|
+
Object.assign(
|
|
53
|
+
{},
|
|
54
|
+
{
|
|
55
|
+
allErrors: true,
|
|
56
|
+
validateSchema: true,
|
|
57
|
+
},
|
|
58
|
+
schemaOptions,
|
|
59
|
+
),
|
|
60
|
+
);
|
|
56
61
|
|
|
57
62
|
ajvErrors(ajv);
|
|
58
63
|
|
|
59
64
|
const validate = ajv.compile(
|
|
60
|
-
Object.assign(
|
|
65
|
+
Object.assign(
|
|
66
|
+
{ $async: resolverOptions && resolverOptions.mode === 'async' },
|
|
67
|
+
schema,
|
|
68
|
+
),
|
|
61
69
|
);
|
|
62
|
-
const valid = validate(values);
|
|
63
70
|
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
values: {},
|
|
67
|
-
errors: toNestError(
|
|
68
|
-
parseErrorSchema(
|
|
69
|
-
validate.errors as DefinedError[],
|
|
70
|
-
!options.shouldUseNativeValidation &&
|
|
71
|
-
options.criteriaMode === 'all',
|
|
72
|
-
),
|
|
73
|
-
options,
|
|
74
|
-
),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
71
|
+
const valid = validate(values);
|
|
77
72
|
|
|
78
73
|
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
|
|
79
74
|
|
|
80
|
-
return
|
|
81
|
-
values,
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
return valid
|
|
76
|
+
? { values, errors: {} }
|
|
77
|
+
: {
|
|
78
|
+
values: {},
|
|
79
|
+
errors: toNestError(
|
|
80
|
+
parseErrorSchema(
|
|
81
|
+
validate.errors as DefinedError[],
|
|
82
|
+
!options.shouldUseNativeValidation &&
|
|
83
|
+
options.criteriaMode === 'all',
|
|
84
|
+
),
|
|
85
|
+
options,
|
|
86
|
+
),
|
|
87
|
+
};
|
|
84
88
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Resolver } from './types';
|
|
2
|
-
export declare const classValidatorResolver: Resolver;
|
|
1
|
+
import type { Resolver } from './types';
|
|
2
|
+
export declare const classValidatorResolver: Resolver;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=require("@hookform/resolvers"),e=require("class-transformer"),t=require("class-validator"),
|
|
1
|
+
var r=require("@hookform/resolvers"),e=require("class-transformer"),t=require("class-validator"),a=function r(e,t,a,s){return void 0===a&&(a={}),void 0===s&&(s=""),e.reduce(function(e,a){var i=s?s+"."+a.property:a.property;if(a.constraints){var o=Object.keys(a.constraints)[0];e[i]={type:o,message:a.constraints[o]};var n=e[i];t&&n&&Object.assign(n,{types:a.constraints})}return a.children&&a.children.length&&r(a.children,t,e,i),e},a)};exports.classValidatorResolver=function(s,i,o){return void 0===i&&(i={}),void 0===o&&(o={}),function(n,l,c){try{var v=i.validator,d=e.plainToClass(s,n,i.transformer);return Promise.resolve(("sync"===o.mode?t.validateSync:t.validate)(d,v)).then(function(e){return e.length?{values:{},errors:r.toNestError(a(e,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)}:(c.shouldUseNativeValidation&&r.validateFieldsNatively({},c),{values:n,errors:{}})})}catch(r){return Promise.reject(r)}}};
|
|
2
2
|
//# sourceMappingURL=class-validator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-validator.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { validate, validateSync, ValidationError } from 'class-validator';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ValidationError[],\n validateAllFieldCriteria: boolean,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return errors.reduce((acc, error) => {\n const _path = path ? `${path}.${error.property}` : error.property;\n\n if (error.constraints) {\n const key = Object.keys(error.constraints)[0];\n acc[_path] = {\n type: key,\n message: error.constraints[key],\n };\n\n if (validateAllFieldCriteria &&
|
|
1
|
+
{"version":3,"file":"class-validator.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { validate, validateSync, ValidationError } from 'class-validator';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ValidationError[],\n validateAllFieldCriteria: boolean,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return errors.reduce((acc, error) => {\n const _path = path ? `${path}.${error.property}` : error.property;\n\n if (error.constraints) {\n const key = Object.keys(error.constraints)[0];\n acc[_path] = {\n type: key,\n message: error.constraints[key],\n };\n\n const _e = acc[_path];\n if (validateAllFieldCriteria && _e) {\n Object.assign(_e, { types: error.constraints });\n }\n }\n\n if (error.children && error.children.length) {\n parseErrors(error.children, validateAllFieldCriteria, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const classValidatorResolver: Resolver =\n (schema, schemaOptions = {}, resolverOptions = {}) =>\n async (values, _, options) => {\n const { transformer, validator } = schemaOptions;\n const data = plainToClass(schema, values, transformer);\n\n const rawErrors = await (resolverOptions.mode === 'sync'\n ? validateSync\n : validate)(data, validator);\n\n if (rawErrors.length) {\n return {\n values: {},\n errors: toNestError(\n parseErrors(\n rawErrors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","validateAllFieldCriteria","parsedErrors","path","reduce","acc","error","_path","property","constraints","key","Object","keys","type","message","_e","assign","types","children","length","schema","schemaOptions","resolverOptions","values","_","options","validator","data","plainToClass","transformer","Promise","resolve","mode","validateSync","validate","then","rawErrors","toNestError","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","e","reject"],"mappings":"iGAMMA,EAAc,SAAdA,EACJC,EACAC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAA,YAC5BC,IAAAA,EAAO,IAEAH,EAAOI,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAQJ,EAAUA,MAAQG,EAAME,SAAaF,EAAME,SAEzD,GAAIF,EAAMG,YAAa,CACrB,IAAMC,EAAMC,OAAOC,KAAKN,EAAMG,aAAa,GAC3CJ,EAAIE,GAAS,CACXM,KAAMH,EACNI,QAASR,EAAMG,YAAYC,IAG7B,IAAMK,EAAKV,EAAIE,GACXN,GAA4Bc,GAC9BJ,OAAOK,OAAOD,EAAI,CAAEE,MAAOX,EAAMG,aAEpC,CAMD,OAJIH,EAAMY,UAAYZ,EAAMY,SAASC,QACnCpB,EAAYO,EAAMY,SAAUjB,EAA0BI,EAAKE,GAGtDF,CACT,EAAGH,EACL,iCAGE,SAACkB,EAAQC,EAAoBC,eAAP,IAAbD,IAAAA,EAAgB,CAAE,QAAEC,IAAAA,IAAAA,EAAkB,CAAE,YAC1CC,EAAQC,EAAGC,GAAW,IAC3B,IAAqBC,EAAcL,EAAdK,UACfC,EAAOC,EAAYA,aAACR,EAAQG,EADCF,EAA3BQ,aAC+C,OAAAC,QAAAC,SAEL,SAAzBT,EAAgBU,KACrCC,eACAC,EAAAA,UAAUP,EAAMD,IAAUS,KAFxBC,SAAAA,GAIN,OAAIA,EAAUjB,OACL,CACLI,OAAQ,GACRvB,OAAQqC,EAAWA,YACjBtC,EACEqC,GACCX,EAAQa,2BACkB,QAAzBb,EAAQc,cAEZd,KAKNA,EAAQa,2BAA6BE,EAAAA,uBAAuB,CAAA,EAAIf,GAEzD,CAAEF,OAAAA,EAAQvB,OAAQ,IAAK,EAChC,CAAC,MAAAyC,GAAA,OAAAX,QAAAY,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{plainToClass as t}from"class-transformer";import{validateSync as o,validate as n}from"class-validator";var s=function r(e,t,o,n){return void 0===o&&(o={}),void 0===n&&(n=""),e.reduce(function(e,o){var s=n?n+"."+o.property:o.property;if(o.constraints){var i=Object.keys(o.constraints)[0];e[s]={type:i,message:o.constraints[i]}
|
|
1
|
+
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{plainToClass as t}from"class-transformer";import{validateSync as o,validate as n}from"class-validator";var s=function r(e,t,o,n){return void 0===o&&(o={}),void 0===n&&(n=""),e.reduce(function(e,o){var s=n?n+"."+o.property:o.property;if(o.constraints){var i=Object.keys(o.constraints)[0];e[s]={type:i,message:o.constraints[i]};var a=e[s];t&&a&&Object.assign(a,{types:o.constraints})}return o.children&&o.children.length&&r(o.children,t,e,s),e},o)},i=function(i,a,c){return void 0===a&&(a={}),void 0===c&&(c={}),function(l,v,d){try{var u=a.validator,m=t(i,l,a.transformer);return Promise.resolve(("sync"===c.mode?o:n)(m,u)).then(function(t){return t.length?{values:{},errors:r(s(t,!d.shouldUseNativeValidation&&"all"===d.criteriaMode),d)}:(d.shouldUseNativeValidation&&e({},d),{values:l,errors:{}})})}catch(r){return Promise.reject(r)}}};export{i as classValidatorResolver};
|
|
2
2
|
//# sourceMappingURL=class-validator.module.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{toNestError as r,validateFieldsNatively as s}from"@hookform/resolvers";import{plainToClass as t}from"class-transformer";import{validateSync as e,validate as o}from"class-validator";const a=(r,s,t={},e="")=>r.reduce((r,t)=>{const o=e?`${e}.${t.property}`:t.property;if(t.constraints){const e=Object.keys(t.constraints)[0];r[o]={type:e,message:t.constraints[e]};const a=r[o];s&&a&&Object.assign(a,{types:t.constraints})}return t.children&&t.children.length&&a(t.children,s,r,o),r},t),n=(n,i={},c={})=>async(l,d,m)=>{const{transformer:p,validator:h}=i,f=t(n,l,p),u=await("sync"===c.mode?e:o)(f,h);return u.length?{values:{},errors:r(a(u,!m.shouldUseNativeValidation&&"all"===m.criteriaMode),m)}:(m.shouldUseNativeValidation&&s({},m),{values:l,errors:{}})};export{n as classValidatorResolver};
|
|
2
|
+
//# sourceMappingURL=class-validator.modern.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-validator.modern.mjs","sources":["../src/class-validator.ts"],"sourcesContent":["import { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { validate, validateSync, ValidationError } from 'class-validator';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ValidationError[],\n validateAllFieldCriteria: boolean,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return errors.reduce((acc, error) => {\n const _path = path ? `${path}.${error.property}` : error.property;\n\n if (error.constraints) {\n const key = Object.keys(error.constraints)[0];\n acc[_path] = {\n type: key,\n message: error.constraints[key],\n };\n\n const _e = acc[_path];\n if (validateAllFieldCriteria && _e) {\n Object.assign(_e, { types: error.constraints });\n }\n }\n\n if (error.children && error.children.length) {\n parseErrors(error.children, validateAllFieldCriteria, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const classValidatorResolver: Resolver =\n (schema, schemaOptions = {}, resolverOptions = {}) =>\n async (values, _, options) => {\n const { transformer, validator } = schemaOptions;\n const data = plainToClass(schema, values, transformer);\n\n const rawErrors = await (resolverOptions.mode === 'sync'\n ? validateSync\n : validate)(data, validator);\n\n if (rawErrors.length) {\n return {\n values: {},\n errors: toNestError(\n parseErrors(\n rawErrors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","validateAllFieldCriteria","parsedErrors","path","reduce","acc","error","_path","property","constraints","key","Object","keys","type","message","_e","assign","types","children","length","classValidatorResolver","schema","schemaOptions","resolverOptions","async","values","_","options","transformer","validator","data","plainToClass","rawErrors","mode","validateSync","validate","toNestError","shouldUseNativeValidation","criteriaMode","validateFieldsNatively"],"mappings":"4LAMA,MAAMA,EAAcA,CAClBC,EACAC,EACAC,EAA4B,CAAA,EAC5BC,EAAO,KAEAH,EAAOI,OAAO,CAACC,EAAKC,KACzB,MAAMC,EAAQJ,KAAUA,KAAQG,EAAME,WAAaF,EAAME,SAEzD,GAAIF,EAAMG,YAAa,CACrB,MAAMC,EAAMC,OAAOC,KAAKN,EAAMG,aAAa,GAC3CJ,EAAIE,GAAS,CACXM,KAAMH,EACNI,QAASR,EAAMG,YAAYC,IAG7B,MAAMK,EAAKV,EAAIE,GACXN,GAA4Bc,GAC9BJ,OAAOK,OAAOD,EAAI,CAAEE,MAAOX,EAAMG,aAEpC,CAMD,OAJIH,EAAMY,UAAYZ,EAAMY,SAASC,QACnCpB,EAAYO,EAAMY,SAAUjB,EAA0BI,EAAKE,GAGtDF,GACNH,GAGQkB,EACXA,CAACC,EAAQC,EAAgB,CAAA,EAAIC,EAAkB,CAAA,IAC/CC,MAAOC,EAAQC,EAAGC,KAChB,MAAMC,YAAEA,EAAWC,UAAEA,GAAcP,EAC7BQ,EAAOC,EAAaV,EAAQI,EAAQG,GAEpCI,QAA4C,SAAzBT,EAAgBU,KACrCC,EACAC,GAAUL,EAAMD,GAEpB,OAAIG,EAAUb,OACL,CACLM,OAAQ,CAAE,EACVzB,OAAQoC,EACNrC,EACEiC,GACCL,EAAQU,2BACkB,QAAzBV,EAAQW,cAEZX,KAKNA,EAAQU,2BAA6BE,EAAuB,CAAE,EAAEZ,GAEzD,CAAEF,SAAQzB,OAAQ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{plainToClass as t}from"class-transformer";import{validateSync as o,validate as n}from"class-validator";var s=function r(e,t,o,n){return void 0===o&&(o={}),void 0===n&&(n=""),e.reduce(function(e,o){var s=n?n+"."+o.property:o.property;if(o.constraints){var i=Object.keys(o.constraints)[0];e[s]={type:i,message:o.constraints[i]}
|
|
1
|
+
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{plainToClass as t}from"class-transformer";import{validateSync as o,validate as n}from"class-validator";var s=function r(e,t,o,n){return void 0===o&&(o={}),void 0===n&&(n=""),e.reduce(function(e,o){var s=n?n+"."+o.property:o.property;if(o.constraints){var i=Object.keys(o.constraints)[0];e[s]={type:i,message:o.constraints[i]};var a=e[s];t&&a&&Object.assign(a,{types:o.constraints})}return o.children&&o.children.length&&r(o.children,t,e,s),e},o)},i=function(i,a,c){return void 0===a&&(a={}),void 0===c&&(c={}),function(l,v,d){try{var u=a.validator,m=t(i,l,a.transformer);return Promise.resolve(("sync"===c.mode?o:n)(m,u)).then(function(t){return t.length?{values:{},errors:r(s(t,!d.shouldUseNativeValidation&&"all"===d.criteriaMode),d)}:(d.shouldUseNativeValidation&&e({},d),{values:l,errors:{}})})}catch(r){return Promise.reject(r)}}};export{i as classValidatorResolver};
|
|
2
2
|
//# sourceMappingURL=class-validator.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-validator.module.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { validate, validateSync, ValidationError } from 'class-validator';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ValidationError[],\n validateAllFieldCriteria: boolean,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return errors.reduce((acc, error) => {\n const _path = path ? `${path}.${error.property}` : error.property;\n\n if (error.constraints) {\n const key = Object.keys(error.constraints)[0];\n acc[_path] = {\n type: key,\n message: error.constraints[key],\n };\n\n if (validateAllFieldCriteria &&
|
|
1
|
+
{"version":3,"file":"class-validator.module.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { validate, validateSync, ValidationError } from 'class-validator';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ValidationError[],\n validateAllFieldCriteria: boolean,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return errors.reduce((acc, error) => {\n const _path = path ? `${path}.${error.property}` : error.property;\n\n if (error.constraints) {\n const key = Object.keys(error.constraints)[0];\n acc[_path] = {\n type: key,\n message: error.constraints[key],\n };\n\n const _e = acc[_path];\n if (validateAllFieldCriteria && _e) {\n Object.assign(_e, { types: error.constraints });\n }\n }\n\n if (error.children && error.children.length) {\n parseErrors(error.children, validateAllFieldCriteria, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const classValidatorResolver: Resolver =\n (schema, schemaOptions = {}, resolverOptions = {}) =>\n async (values, _, options) => {\n const { transformer, validator } = schemaOptions;\n const data = plainToClass(schema, values, transformer);\n\n const rawErrors = await (resolverOptions.mode === 'sync'\n ? validateSync\n : validate)(data, validator);\n\n if (rawErrors.length) {\n return {\n values: {},\n errors: toNestError(\n parseErrors(\n rawErrors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","validateAllFieldCriteria","parsedErrors","path","reduce","acc","error","_path","property","constraints","key","Object","keys","type","message","_e","assign","types","children","length","classValidatorResolver","schema","schemaOptions","resolverOptions","values","_","options","validator","data","plainToClass","transformer","Promise","resolve","mode","validateSync","validate","then","rawErrors","toNestError","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","e","reject"],"mappings":"4LAMA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAA,YAC5BC,IAAAA,EAAO,IAEAH,EAAOI,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAQJ,EAAUA,MAAQG,EAAME,SAAaF,EAAME,SAEzD,GAAIF,EAAMG,YAAa,CACrB,IAAMC,EAAMC,OAAOC,KAAKN,EAAMG,aAAa,GAC3CJ,EAAIE,GAAS,CACXM,KAAMH,EACNI,QAASR,EAAMG,YAAYC,IAG7B,IAAMK,EAAKV,EAAIE,GACXN,GAA4Bc,GAC9BJ,OAAOK,OAAOD,EAAI,CAAEE,MAAOX,EAAMG,aAEpC,CAMD,OAJIH,EAAMY,UAAYZ,EAAMY,SAASC,QACnCpB,EAAYO,EAAMY,SAAUjB,EAA0BI,EAAKE,GAGtDF,CACT,EAAGH,EACL,EAEakB,EACX,SAACC,EAAQC,EAAoBC,eAAP,IAAbD,IAAAA,EAAgB,CAAE,QAAEC,IAAAA,IAAAA,EAAkB,CAAE,YAC1CC,EAAQC,EAAGC,GAAW,IAC3B,IAAqBC,EAAcL,EAAdK,UACfC,EAAOC,EAAaR,EAAQG,EADCF,EAA3BQ,aAC+C,OAAAC,QAAAC,SAEL,SAAzBT,EAAgBU,KACrCC,EACAC,GAAUP,EAAMD,IAAUS,KAFxBC,SAAAA,GAIN,OAAIA,EAAUlB,OACL,CACLK,OAAQ,GACRxB,OAAQsC,EACNvC,EACEsC,GACCX,EAAQa,2BACkB,QAAzBb,EAAQc,cAEZd,KAKNA,EAAQa,2BAA6BE,EAAuB,CAAA,EAAIf,GAEzD,CAAEF,OAAAA,EAAQxB,OAAQ,IAAK,EAChC,CAAC,MAAA0C,GAAA,OAAAX,QAAAY,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("class-transformer"),require("class-validator")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","class-transformer","class-validator"],r):r((e||self).hookformResolversClassValidator={},e.hookformResolvers,e.classTransformer,e.classValidator)}(this,function(e,r,o,s){var t=function e(r,o,s,t){return void 0===s&&(s={}),void 0===t&&(t=""),r.reduce(function(r,s){var a=t?t+"."+s.property:s.property;if(s.constraints){var i=Object.keys(s.constraints)[0];r[a]={type:i,message:s.constraints[i]}
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("class-transformer"),require("class-validator")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","class-transformer","class-validator"],r):r((e||self).hookformResolversClassValidator={},e.hookformResolvers,e.classTransformer,e.classValidator)}(this,function(e,r,o,s){var t=function e(r,o,s,t){return void 0===s&&(s={}),void 0===t&&(t=""),r.reduce(function(r,s){var a=t?t+"."+s.property:s.property;if(s.constraints){var i=Object.keys(s.constraints)[0];r[a]={type:i,message:s.constraints[i]};var n=r[a];o&&n&&Object.assign(n,{types:s.constraints})}return s.children&&s.children.length&&e(s.children,o,r,a),r},s)};e.classValidatorResolver=function(e,a,i){return void 0===a&&(a={}),void 0===i&&(i={}),function(n,l,d){try{var c=a.validator,f=o.plainToClass(e,n,a.transformer);return Promise.resolve(("sync"===i.mode?s.validateSync:s.validate)(f,c)).then(function(e){return e.length?{values:{},errors:r.toNestError(t(e,!d.shouldUseNativeValidation&&"all"===d.criteriaMode),d)}:(d.shouldUseNativeValidation&&r.validateFieldsNatively({},d),{values:n,errors:{}})})}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=class-validator.umd.js.map
|