@hookform/resolvers 3.7.0 → 3.9.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 +112 -0
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.modern.mjs.map +1 -1
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/types.d.ts +1 -1
- package/ajv/src/__tests__/ajv.ts +7 -1
- package/ajv/src/ajv.ts +1 -1
- package/ajv/src/types.ts +1 -5
- 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 +2 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +5 -5
- package/arktype/src/__tests__/Form.tsx +2 -2
- package/arktype/src/__tests__/__fixtures__/data.ts +1 -1
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +29 -29
- package/arktype/src/__tests__/arktype.ts +1 -1
- package/arktype/src/arktype.ts +2 -2
- package/arktype/src/types.ts +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.modern.mjs.map +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/types.d.ts +2 -2
- package/class-validator/src/__tests__/Form-native-validation.tsx +2 -2
- package/class-validator/src/__tests__/Form.tsx +2 -2
- package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +2 -2
- package/class-validator/src/__tests__/class-validator.ts +4 -4
- package/class-validator/src/class-validator.ts +2 -2
- package/class-validator/src/types.ts +2 -2
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.modern.mjs.map +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/dist/types.d.ts +1 -1
- package/computed-types/src/__tests__/Form-native-validation.tsx +2 -2
- package/computed-types/src/__tests__/Form.tsx +2 -2
- package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +6 -6
- package/computed-types/src/__tests__/computed-types.ts +1 -1
- package/computed-types/src/computed-types.ts +2 -2
- package/computed-types/src/types.ts +1 -1
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +2 -2
- 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/toNestErrors.d.ts +1 -6
- package/dist/validateFieldsNatively.d.ts +1 -1
- package/effect-ts/dist/effect-ts.js +1 -1
- package/effect-ts/dist/effect-ts.js.map +1 -1
- package/effect-ts/dist/effect-ts.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
- package/effect-ts/dist/effect-ts.module.js +1 -1
- package/effect-ts/dist/effect-ts.module.js.map +1 -1
- package/effect-ts/dist/effect-ts.umd.js +1 -1
- package/effect-ts/dist/effect-ts.umd.js.map +1 -1
- package/effect-ts/src/__tests__/Form-native-validation.tsx +2 -2
- package/effect-ts/src/__tests__/Form.tsx +2 -2
- package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +2 -2
- package/effect-ts/src/__tests__/effect-ts.ts +1 -1
- package/effect-ts/src/effect-ts.ts +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.d.ts +4 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.mjs +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js.map +1 -0
- package/fluentvalidation-ts/dist/index.d.ts +1 -0
- package/fluentvalidation-ts/package.json +18 -0
- package/fluentvalidation-ts/src/__tests__/Form-native-validation.tsx +88 -0
- package/fluentvalidation-ts/src/__tests__/Form.tsx +63 -0
- package/fluentvalidation-ts/src/__tests__/__fixtures__/data.ts +121 -0
- package/fluentvalidation-ts/src/__tests__/__snapshots__/fluentvalidation-ts.ts.snap +129 -0
- package/fluentvalidation-ts/src/__tests__/fluentvalidation-ts.ts +113 -0
- package/fluentvalidation-ts/src/fluentvalidation-ts.ts +102 -0
- package/fluentvalidation-ts/src/index.ts +1 -0
- package/io-ts/dist/errorsToRecord.d.ts +0 -1
- 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 +1 -1
- package/io-ts/dist/io-ts.modern.mjs.map +1 -1
- 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/src/__tests__/Form-native-validation.tsx +2 -2
- package/io-ts/src/__tests__/Form.tsx +2 -2
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +9 -9
- package/io-ts/src/__tests__/errorsToRecord.ts +29 -19
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/io-ts/src/errorsToRecord.ts +19 -10
- package/io-ts/src/io-ts.ts +1 -1
- package/joi/dist/joi.js +1 -1
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/joi.mjs +1 -1
- package/joi/dist/joi.modern.mjs +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -1
- package/joi/dist/joi.module.js +1 -1
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/dist/types.d.ts +1 -1
- package/joi/src/__tests__/Form-native-validation.tsx +2 -2
- package/joi/src/__tests__/Form.tsx +2 -2
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +56 -56
- package/joi/src/__tests__/joi.ts +1 -1
- package/joi/src/joi.ts +1 -1
- package/joi/src/types.ts +1 -5
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -1
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/dist/types.d.ts +1 -1
- package/nope/src/__tests__/Form-native-validation.tsx +2 -2
- package/nope/src/__tests__/Form.tsx +2 -2
- package/nope/src/__tests__/__fixtures__/data.ts +1 -1
- package/nope/src/__tests__/nope.ts +1 -1
- package/nope/src/nope.ts +1 -1
- package/nope/src/types.ts +2 -2
- package/package.json +69 -54
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/dist/types.d.ts +1 -1
- package/superstruct/src/__tests__/Form-native-validation.tsx +2 -2
- package/superstruct/src/__tests__/Form.tsx +2 -2
- package/superstruct/src/__tests__/__fixtures__/data.ts +8 -8
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +4 -4
- package/superstruct/src/__tests__/superstruct.ts +1 -1
- package/superstruct/src/superstruct.ts +1 -1
- package/superstruct/src/types.ts +1 -1
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -1
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/dist/types.d.ts +1 -1
- package/typanion/src/__tests__/Form-native-validation.tsx +1 -1
- package/typanion/src/__tests__/Form.tsx +1 -1
- package/typanion/src/__tests__/__fixtures__/data.ts +12 -7
- package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +4 -4
- package/typanion/src/__tests__/typanion.ts +1 -1
- package/typanion/src/typanion.ts +1 -1
- package/typanion/src/types.ts +4 -4
- package/typebox/dist/typebox.js +1 -1
- package/typebox/dist/typebox.js.map +1 -1
- package/typebox/dist/typebox.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs.map +1 -1
- package/typebox/dist/typebox.module.js +1 -1
- package/typebox/dist/typebox.module.js.map +1 -1
- package/typebox/dist/typebox.umd.js +1 -1
- package/typebox/dist/typebox.umd.js.map +1 -1
- package/typebox/dist/types.d.ts +3 -2
- package/typebox/src/__tests__/Form-compiler.tsx +57 -0
- package/typebox/src/__tests__/Form-native-validation-compiler.tsx +86 -0
- package/typebox/src/__tests__/Form-native-validation.tsx +4 -4
- package/typebox/src/__tests__/Form.tsx +3 -3
- package/typebox/src/__tests__/__fixtures__/data.ts +6 -2
- package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +188 -0
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +13 -13
- package/typebox/src/__tests__/typebox-compiler.ts +37 -0
- package/typebox/src/__tests__/typebox.ts +1 -1
- package/typebox/src/typebox.ts +8 -3
- package/typebox/src/types.ts +3 -2
- package/typeschema/dist/index.d.ts +2 -0
- package/typeschema/dist/types.d.ts +9 -0
- package/typeschema/dist/typeschema.d.ts +2 -0
- package/typeschema/dist/typeschema.js +2 -0
- package/typeschema/dist/typeschema.js.map +1 -0
- package/typeschema/dist/typeschema.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs.map +1 -0
- package/typeschema/dist/typeschema.module.js +2 -0
- package/typeschema/dist/typeschema.module.js.map +1 -0
- package/typeschema/dist/typeschema.umd.js +2 -0
- package/typeschema/dist/typeschema.umd.js.map +1 -0
- package/typeschema/package.json +18 -0
- package/typeschema/src/__tests__/Form-native-validation.tsx +82 -0
- package/typeschema/src/__tests__/Form.tsx +53 -0
- package/typeschema/src/__tests__/__fixtures__/data.ts +88 -0
- package/typeschema/src/__tests__/__snapshots__/typeschema.ts.snap +225 -0
- package/typeschema/src/__tests__/typeschema.ts +70 -0
- package/typeschema/src/index.ts +2 -0
- package/typeschema/src/types.ts +18 -0
- package/typeschema/src/typeschema.ts +70 -0
- package/valibot/dist/types.d.ts +1 -1
- 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/src/__tests__/Form-native-validation.tsx +2 -2
- package/valibot/src/__tests__/Form.tsx +1 -1
- package/valibot/src/__tests__/valibot.ts +4 -4
- package/valibot/src/types.ts +1 -1
- package/valibot/src/valibot.ts +12 -6
- package/vest/dist/types.d.ts +2 -2
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -1
- 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 +1 -1
- package/vest/src/__tests__/Form.tsx +1 -1
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +0 -6
- package/vest/src/__tests__/vest.ts +14 -8
- package/vest/src/types.ts +11 -4
- package/vest/src/vest.ts +1 -1
- package/vine/dist/types.d.ts +1 -1
- package/vine/dist/vine.js +1 -1
- package/vine/dist/vine.js.map +1 -1
- package/vine/dist/vine.mjs +1 -1
- package/vine/dist/vine.modern.mjs +1 -1
- package/vine/dist/vine.modern.mjs.map +1 -1
- package/vine/dist/vine.module.js +1 -1
- package/vine/dist/vine.module.js.map +1 -1
- package/vine/dist/vine.umd.js +1 -1
- package/vine/dist/vine.umd.js.map +1 -1
- package/vine/src/__tests__/Form-native-validation.tsx +9 -5
- package/vine/src/__tests__/Form.tsx +9 -5
- package/vine/src/__tests__/__fixtures__/data.ts +4 -2
- package/vine/src/__tests__/vine.ts +1 -1
- package/vine/src/types.ts +1 -1
- package/vine/src/vine.ts +10 -8
- package/yup/dist/yup.d.ts +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/Form-native-validation.tsx +1 -1
- package/yup/src/__tests__/Form.tsx +1 -1
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +13 -13
- package/yup/src/__tests__/yup.ts +9 -7
- package/yup/src/yup.ts +2 -2
- package/zod/dist/types.d.ts +1 -1
- 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/__tests__/Form-native-validation.tsx +2 -2
- package/zod/src/__tests__/Form.tsx +1 -1
- package/zod/src/__tests__/zod.ts +1 -1
- package/zod/src/types.ts +1 -1
- package/zod/src/zod.ts +4 -3
package/arktype/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
1
|
import { Type } from 'arktype';
|
|
2
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
3
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.
|
package/arktype/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useForm } from 'react-hook-form';
|
|
3
1
|
import { render, screen } from '@testing-library/react';
|
|
4
2
|
import user from '@testing-library/user-event';
|
|
5
|
-
import { arktypeResolver } from '..';
|
|
6
3
|
import { type } from 'arktype';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useForm } from 'react-hook-form';
|
|
6
|
+
import { arktypeResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const schema = type({
|
|
9
9
|
username: 'string>1',
|
|
@@ -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 length 1
|
|
60
|
+
'username must be more than length 1',
|
|
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 length 1
|
|
67
|
+
'password must be more than length 1',
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import { type } from 'arktype';
|
|
4
|
+
import React from 'react';
|
|
4
5
|
import { useForm } from 'react-hook-form';
|
|
5
6
|
import { arktypeResolver } from '..';
|
|
6
|
-
import { type } from 'arktype';
|
|
7
7
|
|
|
8
8
|
const schema = type({
|
|
9
9
|
username: 'string>1',
|
|
@@ -104,15 +104,15 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
104
104
|
Symbol(ArkTypeInternalKind): "error",
|
|
105
105
|
},
|
|
106
106
|
"email": ArkError {
|
|
107
|
-
"code": "
|
|
107
|
+
"code": "pattern",
|
|
108
108
|
"data": "",
|
|
109
109
|
"description": "a valid email",
|
|
110
110
|
"flags": "",
|
|
111
111
|
"input": {
|
|
112
|
-
"code": "
|
|
112
|
+
"code": "pattern",
|
|
113
113
|
"description": "a valid email",
|
|
114
114
|
"flags": "",
|
|
115
|
-
"rule": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]
|
|
115
|
+
"rule": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$",
|
|
116
116
|
},
|
|
117
117
|
"nodeConfig": {
|
|
118
118
|
"actual": [Function],
|
|
@@ -127,8 +127,8 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
127
127
|
"ref": {
|
|
128
128
|
"name": "email",
|
|
129
129
|
},
|
|
130
|
-
"rule": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]
|
|
131
|
-
"type": "
|
|
130
|
+
"rule": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$",
|
|
131
|
+
"type": "pattern",
|
|
132
132
|
Symbol(ArkTypeInternalKind): "error",
|
|
133
133
|
},
|
|
134
134
|
"enabled": ArkError {
|
|
@@ -204,12 +204,12 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
204
204
|
},
|
|
205
205
|
"input": {
|
|
206
206
|
"code": "required",
|
|
207
|
-
"missingValueDescription": "a string
|
|
207
|
+
"missingValueDescription": "a string",
|
|
208
208
|
"relativePath": [
|
|
209
209
|
"name",
|
|
210
210
|
],
|
|
211
211
|
},
|
|
212
|
-
"missingValueDescription": "a string
|
|
212
|
+
"missingValueDescription": "a string",
|
|
213
213
|
"nodeConfig": {
|
|
214
214
|
"actual": [Function],
|
|
215
215
|
"description": [Function],
|
|
@@ -236,11 +236,11 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
236
236
|
"data": "___",
|
|
237
237
|
"errors": [
|
|
238
238
|
ArkError {
|
|
239
|
-
"code": "
|
|
239
|
+
"code": "pattern",
|
|
240
240
|
"data": "___",
|
|
241
241
|
"description": "matched by .*[A-Za-z].*",
|
|
242
242
|
"input": {
|
|
243
|
-
"code": "
|
|
243
|
+
"code": "pattern",
|
|
244
244
|
"description": "matched by .*[A-Za-z].*",
|
|
245
245
|
"rule": ".*[A-Za-z].*",
|
|
246
246
|
},
|
|
@@ -258,13 +258,13 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
258
258
|
Symbol(ArkTypeInternalKind): "error",
|
|
259
259
|
},
|
|
260
260
|
ArkError {
|
|
261
|
-
"code": "
|
|
261
|
+
"code": "pattern",
|
|
262
262
|
"data": "___",
|
|
263
|
-
"description": "matched by
|
|
263
|
+
"description": "matched by .*\\d.*",
|
|
264
264
|
"input": {
|
|
265
|
-
"code": "
|
|
266
|
-
"description": "matched by
|
|
267
|
-
"rule": "
|
|
265
|
+
"code": "pattern",
|
|
266
|
+
"description": "matched by .*\\d.*",
|
|
267
|
+
"rule": ".*\\d.*",
|
|
268
268
|
},
|
|
269
269
|
"nodeConfig": {
|
|
270
270
|
"actual": [Function],
|
|
@@ -276,7 +276,7 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
276
276
|
"path": [
|
|
277
277
|
"password",
|
|
278
278
|
],
|
|
279
|
-
"rule": "
|
|
279
|
+
"rule": ".*\\d.*",
|
|
280
280
|
Symbol(ArkTypeInternalKind): "error",
|
|
281
281
|
},
|
|
282
282
|
],
|
|
@@ -284,11 +284,11 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
284
284
|
"code": "union",
|
|
285
285
|
"errors": [
|
|
286
286
|
ArkError {
|
|
287
|
-
"code": "
|
|
287
|
+
"code": "pattern",
|
|
288
288
|
"data": "___",
|
|
289
289
|
"description": "matched by .*[A-Za-z].*",
|
|
290
290
|
"input": {
|
|
291
|
-
"code": "
|
|
291
|
+
"code": "pattern",
|
|
292
292
|
"description": "matched by .*[A-Za-z].*",
|
|
293
293
|
"rule": ".*[A-Za-z].*",
|
|
294
294
|
},
|
|
@@ -306,13 +306,13 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
306
306
|
Symbol(ArkTypeInternalKind): "error",
|
|
307
307
|
},
|
|
308
308
|
ArkError {
|
|
309
|
-
"code": "
|
|
309
|
+
"code": "pattern",
|
|
310
310
|
"data": "___",
|
|
311
|
-
"description": "matched by
|
|
311
|
+
"description": "matched by .*\\d.*",
|
|
312
312
|
"input": {
|
|
313
|
-
"code": "
|
|
314
|
-
"description": "matched by
|
|
315
|
-
"rule": "
|
|
313
|
+
"code": "pattern",
|
|
314
|
+
"description": "matched by .*\\d.*",
|
|
315
|
+
"rule": ".*\\d.*",
|
|
316
316
|
},
|
|
317
317
|
"nodeConfig": {
|
|
318
318
|
"actual": [Function],
|
|
@@ -324,7 +324,7 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
324
324
|
"path": [
|
|
325
325
|
"password",
|
|
326
326
|
],
|
|
327
|
-
"rule": "
|
|
327
|
+
"rule": ".*\\d.*",
|
|
328
328
|
Symbol(ArkTypeInternalKind): "error",
|
|
329
329
|
},
|
|
330
330
|
],
|
|
@@ -360,12 +360,12 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
360
360
|
},
|
|
361
361
|
"input": {
|
|
362
362
|
"code": "required",
|
|
363
|
-
"missingValueDescription": "a string
|
|
363
|
+
"missingValueDescription": "a string",
|
|
364
364
|
"relativePath": [
|
|
365
365
|
"repeatPassword",
|
|
366
366
|
],
|
|
367
367
|
},
|
|
368
|
-
"missingValueDescription": "a string
|
|
368
|
+
"missingValueDescription": "a string",
|
|
369
369
|
"nodeConfig": {
|
|
370
370
|
"actual": [Function],
|
|
371
371
|
"description": [Function],
|
|
@@ -398,12 +398,12 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
398
398
|
},
|
|
399
399
|
"input": {
|
|
400
400
|
"code": "required",
|
|
401
|
-
"missingValueDescription": "
|
|
401
|
+
"missingValueDescription": "an array",
|
|
402
402
|
"relativePath": [
|
|
403
403
|
"tags",
|
|
404
404
|
],
|
|
405
405
|
},
|
|
406
|
-
"missingValueDescription": "
|
|
406
|
+
"missingValueDescription": "an array",
|
|
407
407
|
"nodeConfig": {
|
|
408
408
|
"actual": [Function],
|
|
409
409
|
"description": [Function],
|
|
@@ -436,12 +436,12 @@ exports[`arktypeResolver > should return a single error from arktypeResolver whe
|
|
|
436
436
|
},
|
|
437
437
|
"input": {
|
|
438
438
|
"code": "required",
|
|
439
|
-
"missingValueDescription": "a string
|
|
439
|
+
"missingValueDescription": "a string",
|
|
440
440
|
"relativePath": [
|
|
441
441
|
"username",
|
|
442
442
|
],
|
|
443
443
|
},
|
|
444
|
-
"missingValueDescription": "a string
|
|
444
|
+
"missingValueDescription": "a string",
|
|
445
445
|
"nodeConfig": {
|
|
446
446
|
"actual": [Function],
|
|
447
447
|
"description": [Function],
|
package/arktype/src/arktype.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FieldError, FieldErrors } from 'react-hook-form';
|
|
2
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
|
-
import type { Resolver } from './types';
|
|
4
2
|
import { ArkErrors } from 'arktype';
|
|
3
|
+
import { FieldError, FieldErrors } from 'react-hook-form';
|
|
4
|
+
import type { Resolver } from './types';
|
|
5
5
|
|
|
6
6
|
const parseErrorSchema = (e: ArkErrors): Record<string, FieldError> => {
|
|
7
7
|
// copy code to type to match FieldError shape
|
package/arktype/src/types.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-validator.js","sources":["../src/class-validator.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"class-validator.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { ValidationError, validate, validateSync } from 'class-validator';\nimport { FieldErrors } from 'react-hook-form';\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: toNestErrors(\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 {\n values: resolverOptions.rawValues ? values : data,\n errors: {},\n };\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","toNestErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","rawValues","e","reject"],"mappings":"iGAMMA,EAAc,SAAdA,EACJC,EACAC,EACAC,EACAC,GAEA,gBAHAD,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAH,EAAOI,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAQJ,EAAUA,EAAQG,IAAAA,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,aAErC,CAMA,OAJIH,EAAMY,UAAYZ,EAAMY,SAASC,QACnCpB,EAAYO,EAAMY,SAAUjB,EAA0BI,EAAKE,GAGtDF,CACT,EAAGH,EACL,iCAGE,SAACkB,EAAQC,EAAoBC,GAAoB,YAAxCD,IAAAA,IAAAA,EAAgB,SAAmB,IAAfC,IAAAA,EAAkB,IAAE,SAC1CC,EAAQC,EAAGC,GAAO,IACvB,IAAqBC,EAAcL,EAAdK,UACfC,EAAOC,eAAaR,EAAQG,EADCF,EAA3BQ,aAC+C,OAAAC,QAAAC,SAEL,SAAzBT,EAAgBU,KACrCC,EAAAA,aACAC,EAAQA,UAAEP,EAAMD,IAAUS,KAFxBC,SAAAA,GAIN,OAAIA,EAAUjB,OACL,CACLI,OAAQ,GACRvB,OAAQqC,EAAAA,aACNtC,EACEqC,GACCX,EAAQa,2BACkB,QAAzBb,EAAQc,cAEZd,KAKNA,EAAQa,2BAA6BE,yBAAuB,CAAA,EAAIf,GAEzD,CACLF,OAAQD,EAAgBmB,UAAYlB,EAASI,EAC7C3B,OAAQ,CAAA,GACR,EACJ,CAAC,MAAA0C,GAAA,OAAAZ,QAAAa,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-validator.modern.mjs","sources":["../src/class-validator.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"class-validator.modern.mjs","sources":["../src/class-validator.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { ValidationError, validate, validateSync } from 'class-validator';\nimport { FieldErrors } from 'react-hook-form';\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: toNestErrors(\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 {\n values: resolverOptions.rawValues ? values : data,\n errors: {},\n };\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","toNestErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","rawValues"],"mappings":"6LAMA,MAAMA,EAAcA,CAClBC,EACAC,EACAC,EAA4B,CAAA,EAC5BC,EAAO,KAEAH,EAAOI,OAAO,CAACC,EAAKC,KACzB,MAAMC,EAAQJ,EAAO,GAAGA,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,aAErC,CAMA,OAJIH,EAAMY,UAAYZ,EAAMY,SAASC,QACnCpB,EAAYO,EAAMY,SAAUjB,EAA0BI,EAAKE,GAGtDF,GACNH,GAGQkB,EACXA,CAACC,EAAQC,EAAgB,CAAA,EAAIC,EAAkB,CAAE,IACjDC,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,CAAA,EAAIZ,GAEzD,CACLF,OAAQF,EAAgBiB,UAAYf,EAASK,EAC7C9B,OAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-validator.module.js","sources":["../src/class-validator.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"class-validator.module.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { ValidationError, validate, validateSync } from 'class-validator';\nimport { FieldErrors } from 'react-hook-form';\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: toNestErrors(\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 {\n values: resolverOptions.rawValues ? values : data,\n errors: {},\n };\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","toNestErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","rawValues","e","reject"],"mappings":"6LAMA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,EACAC,GAEA,gBAHAD,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAH,EAAOI,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAQJ,EAAUA,EAAQG,IAAAA,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,aAErC,CAMA,OAJIH,EAAMY,UAAYZ,EAAMY,SAASC,QACnCpB,EAAYO,EAAMY,SAAUjB,EAA0BI,EAAKE,GAGtDF,CACT,EAAGH,EACL,EAEakB,EACX,SAACC,EAAQC,EAAoBC,GAAoB,YAAxCD,IAAAA,IAAAA,EAAgB,SAAmB,IAAfC,IAAAA,EAAkB,IAAE,SAC1CC,EAAQC,EAAGC,GAAO,IACvB,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,CACLF,OAAQD,EAAgBmB,UAAYlB,EAASI,EAC7C5B,OAAQ,CAAA,GACR,EACJ,CAAC,MAAA2C,GAAA,OAAAZ,QAAAa,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-validator.umd.js","sources":["../src/class-validator.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"class-validator.umd.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { ValidationError, validate, validateSync } from 'class-validator';\nimport { FieldErrors } from 'react-hook-form';\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: toNestErrors(\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 {\n values: resolverOptions.rawValues ? values : data,\n errors: {},\n };\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","toNestErrors","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","rawValues","e","reject"],"mappings":"0cAMA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,EACAC,GAEA,gBAHAD,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAH,EAAOI,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAQJ,EAAUA,EAAQG,IAAAA,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,aAErC,CAMA,OAJIH,EAAMY,UAAYZ,EAAMY,SAASC,QACnCpB,EAAYO,EAAMY,SAAUjB,EAA0BI,EAAKE,GAGtDF,CACT,EAAGH,EACL,2BAGE,SAACkB,EAAQC,EAAoBC,GAAoB,YAAxCD,IAAAA,IAAAA,EAAgB,SAAmB,IAAfC,IAAAA,EAAkB,IAAE,SAC1CC,EAAQC,EAAGC,GAAO,IACvB,IAAqBC,EAAcL,EAAdK,UACfC,EAAOC,eAAaR,EAAQG,EADCF,EAA3BQ,aAC+C,OAAAC,QAAAC,SAEL,SAAzBT,EAAgBU,KACrCC,EAAAA,aACAC,EAAQA,UAAEP,EAAMD,IAAUS,KAFxBC,SAAAA,GAIN,OAAIA,EAAUjB,OACL,CACLI,OAAQ,GACRvB,OAAQqC,EAAAA,aACNtC,EACEqC,GACCX,EAAQa,2BACkB,QAAzBb,EAAQc,cAEZd,KAKNA,EAAQa,2BAA6BE,yBAAuB,CAAA,EAAIf,GAEzD,CACLF,OAAQD,EAAgBmB,UAAYlB,EAASI,EAC7C3B,OAAQ,CAAA,GACR,EACJ,CAAC,MAAA0C,GAAA,OAAAZ,QAAAa,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
-
import { ValidatorOptions } from 'class-validator';
|
|
3
1
|
import { ClassConstructor, ClassTransformOptions } from 'class-transformer';
|
|
2
|
+
import { ValidatorOptions } from 'class-validator';
|
|
3
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
4
4
|
export type Resolver = <T extends {
|
|
5
5
|
[_: string]: any;
|
|
6
6
|
}>(schema: ClassConstructor<T>, schemaOptions?: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import { IsNotEmpty } from 'class-validator';
|
|
4
|
+
import React from 'react';
|
|
4
5
|
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
5
6
|
import { classValidatorResolver } from '..';
|
|
6
|
-
import { IsNotEmpty } from 'class-validator';
|
|
7
7
|
|
|
8
8
|
class Schema {
|
|
9
9
|
@IsNotEmpty()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import { IsNotEmpty } from 'class-validator';
|
|
4
|
+
import React from 'react';
|
|
4
5
|
import { SubmitHandler, useForm } from 'react-hook-form';
|
|
5
6
|
import { classValidatorResolver } from '..';
|
|
6
|
-
import { IsNotEmpty } from 'class-validator';
|
|
7
7
|
|
|
8
8
|
class Schema {
|
|
9
9
|
@IsNotEmpty()
|
|
@@ -138,7 +138,7 @@ exports[`classValidatorResolver > should return all the errors from classValidat
|
|
|
138
138
|
"type": "isLength",
|
|
139
139
|
"types": {
|
|
140
140
|
"isLength": "username must be longer than or equal to 3 characters",
|
|
141
|
-
"matches": "username must match
|
|
141
|
+
"matches": "username must match /^\\w+$/ regular expression",
|
|
142
142
|
},
|
|
143
143
|
},
|
|
144
144
|
},
|
|
@@ -198,7 +198,7 @@ exports[`classValidatorResolver > should return all the errors from classValidat
|
|
|
198
198
|
"type": "isLength",
|
|
199
199
|
"types": {
|
|
200
200
|
"isLength": "username must be longer than or equal to 3 characters",
|
|
201
|
-
"matches": "username must match
|
|
201
|
+
"matches": "username must match /^\\w+$/ regular expression",
|
|
202
202
|
},
|
|
203
203
|
},
|
|
204
204
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/* eslint-disable no-console, @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import { classValidatorResolver } from '..';
|
|
3
|
-
import { Schema, validData, fields, invalidData } from './__fixtures__/data';
|
|
4
|
-
import * as classValidator from 'class-validator';
|
|
5
1
|
import { Expose, Type } from 'class-transformer';
|
|
2
|
+
import * as classValidator from 'class-validator';
|
|
6
3
|
import { IsDefined, IsNumber, Max, Min } from 'class-validator';
|
|
4
|
+
/* eslint-disable no-console, @typescript-eslint/ban-ts-comment */
|
|
5
|
+
import { classValidatorResolver } from '..';
|
|
6
|
+
import { Schema, fields, invalidData, validData } from './__fixtures__/data';
|
|
7
7
|
|
|
8
8
|
const shouldUseNativeValidation = false;
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FieldErrors } from 'react-hook-form';
|
|
2
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
2
|
import { plainToClass } from 'class-transformer';
|
|
4
|
-
import { validate, validateSync
|
|
3
|
+
import { ValidationError, validate, validateSync } from 'class-validator';
|
|
4
|
+
import { FieldErrors } from 'react-hook-form';
|
|
5
5
|
import type { Resolver } from './types';
|
|
6
6
|
|
|
7
7
|
const parseErrors = (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
-
import { ValidatorOptions } from 'class-validator';
|
|
3
1
|
import { ClassConstructor, ClassTransformOptions } from 'class-transformer';
|
|
2
|
+
import { ValidatorOptions } from 'class-validator';
|
|
3
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
4
4
|
|
|
5
5
|
export type Resolver = <T extends { [_: string]: any }>(
|
|
6
6
|
schema: ClassConstructor<T>,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed-types.js","sources":["../src/computed-types.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"computed-types.js","sources":["../src/computed-types.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ValidationError } from 'computed-types';\nimport type { FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst isValidationError = (error: any): error is ValidationError =>\n error.errors != null;\n\nconst parseErrorSchema = (computedTypesError: ValidationError) => {\n const parsedErrors: FieldErrors = {};\n return (computedTypesError.errors || []).reduce((acc, error) => {\n acc[error.path.join('.')] = {\n type: error.error.name,\n message: error.error.message,\n };\n\n return acc;\n }, parsedErrors);\n};\n\nexport const computedTypesResolver: Resolver =\n (schema) => async (values, _, options) => {\n try {\n const data = await schema(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: data,\n };\n } catch (error: any) {\n if (isValidationError(error)) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(error), options),\n };\n }\n\n throw error;\n }\n };\n"],"names":["schema","values","_","options","Promise","resolve","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","_catch","error","isValidationError","toNestErrors","computedTypesError","reduce","acc","path","join","type","name","message","e","reject"],"mappings":"mEAqBE,SAACA,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACnCD,QAAAC,QACiBL,EAAOC,IAAOK,KAAA,SAA3BC,GAIN,OAFAJ,EAAQK,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIN,GAEzD,CACLO,OAAQ,CAAE,EACVT,OAAQM,EACR,4DATmCI,CAAA,EAU9BC,SAAAA,GACP,GA3BoB,SAACA,GACzB,OAAgB,MAAhBA,EAAMF,MAAc,CA0BZG,CAAkBD,GACpB,MAAO,CACLX,OAAQ,CAAA,EACRS,OAAQI,EAAAA,cA3BQC,EA2BsBH,GAzBtCG,EAAmBL,QAAU,IAAIM,OAAO,SAACC,EAAKL,GAMpD,OALAK,EAAIL,EAAMM,KAAKC,KAAK,MAAQ,CAC1BC,KAAMR,EAAMA,MAAMS,KAClBC,QAASV,EAAMA,MAAMU,SAGhBL,CACT,EARkC,CAAA,IA0BoBd,IA3B/B,IAACY,EA+BpB,MAAMH,CACR,GACF,CAAC,MAAAW,GAAAnB,OAAAA,QAAAoB,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed-types.modern.mjs","sources":["../src/computed-types.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"computed-types.modern.mjs","sources":["../src/computed-types.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ValidationError } from 'computed-types';\nimport type { FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst isValidationError = (error: any): error is ValidationError =>\n error.errors != null;\n\nconst parseErrorSchema = (computedTypesError: ValidationError) => {\n const parsedErrors: FieldErrors = {};\n return (computedTypesError.errors || []).reduce((acc, error) => {\n acc[error.path.join('.')] = {\n type: error.error.name,\n message: error.error.message,\n };\n\n return acc;\n }, parsedErrors);\n};\n\nexport const computedTypesResolver: Resolver =\n (schema) => async (values, _, options) => {\n try {\n const data = await schema(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: data,\n };\n } catch (error: any) {\n if (isValidationError(error)) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(error), options),\n };\n }\n\n throw error;\n }\n };\n"],"names":["computedTypesResolver","schema","async","values","_","options","data","shouldUseNativeValidation","validateFieldsNatively","errors","error","isValidationError","toNestErrors","computedTypesError","reduce","acc","path","join","type","name","message"],"mappings":"+EAKA,MAeaA,EACVC,GAAWC,MAAOC,EAAQC,EAAGC,KAC5B,IACE,MAAMC,QAAaL,EAAOE,GAI1B,OAFAE,EAAQE,2BAA6BC,EAAuB,CAAE,EAAEH,GAEzD,CACLI,OAAQ,CAAA,EACRN,OAAQG,EAEZ,CAAE,MAAOI,GACP,GA3BqBA,IACT,MAAhBA,EAAMD,OA0BEE,CAAkBD,GACpB,MAAO,CACLP,OAAQ,CAAA,EACRM,OAAQG,GA3BQC,EA2BsBH,GAzBtCG,EAAmBJ,QAAU,IAAIK,OAAO,CAACC,EAAKL,KACpDK,EAAIL,EAAMM,KAAKC,KAAK,MAAQ,CAC1BC,KAAMR,EAAMA,MAAMS,KAClBC,QAASV,EAAMA,MAAMU,SAGhBL,GAPyB,KA0BoBV,IAIlD,MAAMK,CACR,CAhCsBG,KAgCtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed-types.module.js","sources":["../src/computed-types.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"computed-types.module.js","sources":["../src/computed-types.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ValidationError } from 'computed-types';\nimport type { FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst isValidationError = (error: any): error is ValidationError =>\n error.errors != null;\n\nconst parseErrorSchema = (computedTypesError: ValidationError) => {\n const parsedErrors: FieldErrors = {};\n return (computedTypesError.errors || []).reduce((acc, error) => {\n acc[error.path.join('.')] = {\n type: error.error.name,\n message: error.error.message,\n };\n\n return acc;\n }, parsedErrors);\n};\n\nexport const computedTypesResolver: Resolver =\n (schema) => async (values, _, options) => {\n try {\n const data = await schema(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: data,\n };\n } catch (error: any) {\n if (isValidationError(error)) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(error), options),\n };\n }\n\n throw error;\n }\n };\n"],"names":["computedTypesResolver","schema","values","_","options","Promise","resolve","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","_catch","error","isValidationError","toNestErrors","computedTypesError","reduce","acc","path","join","type","name","message","e","reject"],"mappings":"+EAKA,IAeaA,EACX,SAACC,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACnCD,QAAAC,QACiBL,EAAOC,IAAOK,KAAA,SAA3BC,GAIN,OAFAJ,EAAQK,2BAA6BC,EAAuB,CAAA,EAAIN,GAEzD,CACLO,OAAQ,CAAE,EACVT,OAAQM,EACR,4DATmCI,CAAA,EAU9BC,SAAAA,GACP,GA3BoB,SAACA,GACzB,OAAgB,MAAhBA,EAAMF,MAAc,CA0BZG,CAAkBD,GACpB,MAAO,CACLX,OAAQ,CAAA,EACRS,OAAQI,GA3BQC,EA2BsBH,GAzBtCG,EAAmBL,QAAU,IAAIM,OAAO,SAACC,EAAKL,GAMpD,OALAK,EAAIL,EAAMM,KAAKC,KAAK,MAAQ,CAC1BC,KAAMR,EAAMA,MAAMS,KAClBC,QAASV,EAAMA,MAAMU,SAGhBL,CACT,EARkC,CAAA,IA0BoBd,IA3B/B,IAACY,EA+BpB,MAAMH,CACR,GACF,CAAC,MAAAW,GAAAnB,OAAAA,QAAAoB,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed-types.umd.js","sources":["../src/computed-types.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"computed-types.umd.js","sources":["../src/computed-types.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ValidationError } from 'computed-types';\nimport type { FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst isValidationError = (error: any): error is ValidationError =>\n error.errors != null;\n\nconst parseErrorSchema = (computedTypesError: ValidationError) => {\n const parsedErrors: FieldErrors = {};\n return (computedTypesError.errors || []).reduce((acc, error) => {\n acc[error.path.join('.')] = {\n type: error.error.name,\n message: error.error.message,\n };\n\n return acc;\n }, parsedErrors);\n};\n\nexport const computedTypesResolver: Resolver =\n (schema) => async (values, _, options) => {\n try {\n const data = await schema(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: data,\n };\n } catch (error: any) {\n if (isValidationError(error)) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(error), options),\n };\n }\n\n throw error;\n }\n };\n"],"names":["schema","values","_","options","Promise","resolve","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","_catch","error","isValidationError","toNestErrors","computedTypesError","reduce","acc","path","join","type","name","message","e","reject"],"mappings":"2VAqBE,SAACA,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACnCD,QAAAC,QACiBL,EAAOC,IAAOK,KAAA,SAA3BC,GAIN,OAFAJ,EAAQK,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIN,GAEzD,CACLO,OAAQ,CAAE,EACVT,OAAQM,EACR,4DATmCI,CAAA,EAU9BC,SAAAA,GACP,GA3BoB,SAACA,GACzB,OAAgB,MAAhBA,EAAMF,MAAc,CA0BZG,CAAkBD,GACpB,MAAO,CACLX,OAAQ,CAAA,EACRS,OAAQI,EAAAA,cA3BQC,EA2BsBH,GAzBtCG,EAAmBL,QAAU,IAAIM,OAAO,SAACC,EAAKL,GAMpD,OALAK,EAAIL,EAAMM,KAAKC,KAAK,MAAQ,CAC1BC,KAAMR,EAAMA,MAAMS,KAClBC,QAASV,EAAMA,MAAMU,SAGhBL,CACT,EARkC,CAAA,IA0BoBd,IA3B/B,IAACY,EA+BpB,MAAMH,CACR,GACF,CAAC,MAAAW,GAAAnB,OAAAA,QAAAoB,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { FieldValues,
|
|
1
|
+
import type { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
2
|
export type Resolver = (schema: any) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
4
|
-
import { useForm } from 'react-hook-form';
|
|
5
3
|
import Schema, { Type, string } from 'computed-types';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { computedTypesResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
4
|
-
import { useForm } from 'react-hook-form';
|
|
5
3
|
import Schema, { Type, string } from 'computed-types';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { computedTypesResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const schema = Schema({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
1
|
import Schema, { Type, string, number, array, boolean } from 'computed-types';
|
|
2
|
+
import { Field, InternalFieldName } from 'react-hook-form';
|
|
3
3
|
|
|
4
4
|
export const schema = Schema({
|
|
5
5
|
username: string.regexp(/^\w+$/).min(3).max(30),
|
|
@@ -16,7 +16,7 @@ exports[`computedTypesResolver > should return a single error from computedTypes
|
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
"birthYear": {
|
|
19
|
-
"message": "Expect value to be
|
|
19
|
+
"message": "Expect value to be "number"",
|
|
20
20
|
"ref": undefined,
|
|
21
21
|
"type": "ValidationError",
|
|
22
22
|
},
|
|
@@ -28,18 +28,18 @@ exports[`computedTypesResolver > should return a single error from computedTypes
|
|
|
28
28
|
"type": "ValidationError",
|
|
29
29
|
},
|
|
30
30
|
"enabled": {
|
|
31
|
-
"message": "Expect value to be
|
|
31
|
+
"message": "Expect value to be "boolean"",
|
|
32
32
|
"ref": undefined,
|
|
33
33
|
"type": "ValidationError",
|
|
34
34
|
},
|
|
35
35
|
"like": {
|
|
36
36
|
"id": {
|
|
37
|
-
"message": "Expect value to be
|
|
37
|
+
"message": "Expect value to be "number"",
|
|
38
38
|
"ref": undefined,
|
|
39
39
|
"type": "ValidationError",
|
|
40
40
|
},
|
|
41
41
|
"name": {
|
|
42
|
-
"message": "Expect value to be
|
|
42
|
+
"message": "Expect value to be "string"",
|
|
43
43
|
"ref": undefined,
|
|
44
44
|
"type": "ValidationError",
|
|
45
45
|
},
|
|
@@ -52,7 +52,7 @@ exports[`computedTypesResolver > should return a single error from computedTypes
|
|
|
52
52
|
"type": "ValidationError",
|
|
53
53
|
},
|
|
54
54
|
"repeatPassword": {
|
|
55
|
-
"message": "Expect value to be
|
|
55
|
+
"message": "Expect value to be "string"",
|
|
56
56
|
"ref": undefined,
|
|
57
57
|
"type": "ValidationError",
|
|
58
58
|
},
|
|
@@ -62,7 +62,7 @@ exports[`computedTypesResolver > should return a single error from computedTypes
|
|
|
62
62
|
"type": "ValidationError",
|
|
63
63
|
},
|
|
64
64
|
"username": {
|
|
65
|
-
"message": "Expect value to be
|
|
65
|
+
"message": "Expect value to be "string"",
|
|
66
66
|
"ref": {
|
|
67
67
|
"name": "username",
|
|
68
68
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { FieldErrors } from 'react-hook-form';
|
|
2
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
|
-
import type { Resolver } from './types';
|
|
4
2
|
import type { ValidationError } from 'computed-types';
|
|
3
|
+
import type { FieldErrors } from 'react-hook-form';
|
|
4
|
+
import type { Resolver } from './types';
|
|
5
5
|
|
|
6
6
|
const isValidationError = (error: any): error is ValidationError =>
|
|
7
7
|
error.errors != null;
|