@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/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hookform/resolvers",
|
|
3
3
|
"amdName": "hookformResolvers",
|
|
4
|
-
"version": "
|
|
5
|
-
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types and Typanion",
|
|
4
|
+
"version": "3.0.1",
|
|
5
|
+
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox and Typanion",
|
|
6
6
|
"main": "dist/resolvers.js",
|
|
7
7
|
"module": "dist/resolvers.module.js",
|
|
8
8
|
"umd:main": "dist/resolvers.umd.js",
|
|
@@ -10,61 +10,79 @@
|
|
|
10
10
|
"types": "dist/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
13
14
|
"umd": "./dist/resolvers.umd.js",
|
|
14
15
|
"import": "./dist/resolvers.mjs",
|
|
15
16
|
"require": "./dist/resolvers.js"
|
|
16
17
|
},
|
|
17
18
|
"./zod": {
|
|
19
|
+
"types": "./zod/dist/index.d.ts",
|
|
18
20
|
"umd": "./zod/dist/zod.umd.js",
|
|
19
21
|
"import": "./zod/dist/zod.mjs",
|
|
20
22
|
"require": "./zod/dist/zod.js"
|
|
21
23
|
},
|
|
24
|
+
"./typebox": {
|
|
25
|
+
"types": "./typebox/dist/index.d.ts",
|
|
26
|
+
"umd": "./typebox/dist/typebox.umd.js",
|
|
27
|
+
"import": "./typebox/dist/typebox.mjs",
|
|
28
|
+
"require": "./typebox/dist/typebox.js"
|
|
29
|
+
},
|
|
22
30
|
"./yup": {
|
|
31
|
+
"types": "./yup/dist/index.d.ts",
|
|
23
32
|
"umd": "./yup/dist/yup.umd.js",
|
|
24
33
|
"import": "./yup/dist/yup.mjs",
|
|
25
34
|
"require": "./yup/dist/yup.js"
|
|
26
35
|
},
|
|
27
36
|
"./joi": {
|
|
37
|
+
"types": "./joi/dist/index.d.ts",
|
|
28
38
|
"umd": "./joi/dist/joi.umd.js",
|
|
29
39
|
"import": "./joi/dist/joi.mjs",
|
|
30
40
|
"require": "./joi/dist/joi.js"
|
|
31
41
|
},
|
|
32
42
|
"./vest": {
|
|
43
|
+
"types": "./vest/dist/index.d.ts",
|
|
33
44
|
"umd": "./vest/dist/vest.umd.js",
|
|
34
45
|
"import": "./vest/dist/vest.mjs",
|
|
35
46
|
"require": "./vest/dist/vest.js"
|
|
36
47
|
},
|
|
37
48
|
"./superstruct": {
|
|
49
|
+
"types": "./superstruct/dist/index.d.ts",
|
|
38
50
|
"umd": "./superstruct/dist/superstruct.umd.js",
|
|
39
51
|
"import": "./superstruct/dist/superstruct.mjs",
|
|
40
52
|
"require": "./superstruct/dist/superstruct.js"
|
|
41
53
|
},
|
|
42
54
|
"./class-validator": {
|
|
55
|
+
"types": "./class-validator/dist/index.d.ts",
|
|
43
56
|
"umd": "./class-validator/dist/class-validator.umd.js",
|
|
44
57
|
"import": "./class-validator/dist/class-validator.mjs",
|
|
45
58
|
"require": "./class-validator/dist/class-validator.js"
|
|
46
59
|
},
|
|
47
60
|
"./io-ts": {
|
|
61
|
+
"types": "./io-ts/dist/index.d.ts",
|
|
48
62
|
"umd": "./io-ts/dist/io-ts.umd.js",
|
|
49
63
|
"import": "./io-ts/dist/io-ts.mjs",
|
|
50
64
|
"require": "./io-ts/dist/io-ts.js"
|
|
51
65
|
},
|
|
52
66
|
"./nope": {
|
|
67
|
+
"types": "./nope/dist/index.d.ts",
|
|
53
68
|
"umd": "./nope/dist/nope.umd.js",
|
|
54
69
|
"import": "./nope/dist/nope.mjs",
|
|
55
70
|
"require": "./nope/dist/nope.js"
|
|
56
71
|
},
|
|
57
72
|
"./computed-types": {
|
|
73
|
+
"types": "./computed-types/dist/index.d.ts",
|
|
58
74
|
"umd": "./computed-types/dist/computed-types.umd.js",
|
|
59
75
|
"import": "./computed-types/dist/computed-types.mjs",
|
|
60
76
|
"require": "./computed-types/dist/computed-types.js"
|
|
61
77
|
},
|
|
62
78
|
"./typanion": {
|
|
79
|
+
"types": "./typanion/dist/index.d.ts",
|
|
63
80
|
"umd": "./typanion/dist/typanion.umd.js",
|
|
64
81
|
"import": "./typanion/dist/typanion.mjs",
|
|
65
82
|
"require": "./typanion/dist/typanion.js"
|
|
66
83
|
},
|
|
67
84
|
"./ajv": {
|
|
85
|
+
"types": "./ajv/dist/index.d.ts",
|
|
68
86
|
"umd": "./ajv/dist/ajv.umd.js",
|
|
69
87
|
"import": "./ajv/dist/ajv.mjs",
|
|
70
88
|
"require": "./ajv/dist/ajv.js"
|
|
@@ -106,31 +124,35 @@
|
|
|
106
124
|
"typanion/dist",
|
|
107
125
|
"ajv/package.json",
|
|
108
126
|
"ajv/src",
|
|
109
|
-
"ajv/dist"
|
|
127
|
+
"ajv/dist",
|
|
128
|
+
"typebox/package.json",
|
|
129
|
+
"typebox/src",
|
|
130
|
+
"typebox/dist"
|
|
110
131
|
],
|
|
111
132
|
"publishConfig": {
|
|
112
133
|
"access": "public"
|
|
113
134
|
},
|
|
114
135
|
"scripts": {
|
|
115
136
|
"prepare": "run-s build:src build && check-export-map && husky install",
|
|
116
|
-
"build": "npm-run-all --parallel build:*",
|
|
137
|
+
"build": "cross-env npm-run-all --parallel 'build:*'",
|
|
117
138
|
"build:src": "microbundle build --globals react-hook-form=ReactHookForm",
|
|
118
139
|
"build:zod": "microbundle --cwd zod --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
119
140
|
"build:yup": "microbundle --cwd yup --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
120
141
|
"build:joi": "microbundle --cwd joi --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
121
142
|
"build:superstruct": "microbundle --cwd superstruct --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
122
|
-
"build:io-ts": "microbundle --cwd io-ts --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
123
|
-
"build:vest": "microbundle --cwd vest --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
143
|
+
"build:io-ts": "microbundle --cwd io-ts --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,fp-ts/Either=Either,fp-ts/function=_function,fp-ts/Option=Option,fp-ts/ReadonlyArray=ReadonlyArray,fp-ts/Semigroup=Semigroup,fp-ts/ReadonlyRecord=ReadonlyRecord",
|
|
144
|
+
"build:vest": "microbundle --cwd vest --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,vest/promisify=promisify",
|
|
124
145
|
"build:class-validator": "microbundle --cwd class-validator --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
125
146
|
"build:nope": "microbundle --cwd nope --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
126
147
|
"build:computed-types": "microbundle --cwd computed-types --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
127
148
|
"build:typanion": "microbundle --cwd typanion --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
128
149
|
"build:ajv": "microbundle --cwd ajv --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
150
|
+
"build:typebox": "microbundle --cwd typebox --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@sinclair/typebox/value=value",
|
|
129
151
|
"postbuild": "node ./config/node-13-exports.js",
|
|
130
152
|
"lint": "eslint . --ext .ts,.js --ignore-path .gitignore",
|
|
131
153
|
"lint:types": "tsc",
|
|
132
|
-
"test": "
|
|
133
|
-
"test:watch": "
|
|
154
|
+
"test": "vitest run",
|
|
155
|
+
"test:watch": "vitest watch",
|
|
134
156
|
"check:all": "npm-run-all --parallel lint:* test"
|
|
135
157
|
},
|
|
136
158
|
"keywords": [
|
|
@@ -150,7 +172,8 @@
|
|
|
150
172
|
"nope",
|
|
151
173
|
"computed-types",
|
|
152
174
|
"typanion",
|
|
153
|
-
"ajv"
|
|
175
|
+
"ajv",
|
|
176
|
+
"TypeBox"
|
|
154
177
|
],
|
|
155
178
|
"repository": {
|
|
156
179
|
"type": "git",
|
|
@@ -163,52 +186,59 @@
|
|
|
163
186
|
},
|
|
164
187
|
"homepage": "https://react-hook-form.com",
|
|
165
188
|
"devDependencies": {
|
|
166
|
-
"@
|
|
167
|
-
"@testing-library/
|
|
168
|
-
"@testing-library/
|
|
169
|
-
"@
|
|
170
|
-
"@
|
|
171
|
-
"@
|
|
172
|
-
"@
|
|
173
|
-
"
|
|
189
|
+
"@sinclair/typebox": "^0.26.3",
|
|
190
|
+
"@testing-library/dom": "^9.0.1",
|
|
191
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
192
|
+
"@testing-library/react": "^14.0.0",
|
|
193
|
+
"@testing-library/user-event": "^14.4.3",
|
|
194
|
+
"@types/node": "^18.15.7",
|
|
195
|
+
"@types/react": "^18.0.28",
|
|
196
|
+
"@types/testing-library__jest-dom": "^5.14.5",
|
|
197
|
+
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
|
198
|
+
"@typescript-eslint/parser": "^5.56.0",
|
|
199
|
+
"@vitejs/plugin-react": "^3.1.0",
|
|
200
|
+
"ajv": "^8.12.0",
|
|
174
201
|
"ajv-errors": "^3.0.0",
|
|
175
|
-
"check-export-map": "^1.
|
|
202
|
+
"check-export-map": "^1.3.0",
|
|
176
203
|
"class-transformer": "^0.5.1",
|
|
177
|
-
"class-validator": "^0.
|
|
178
|
-
"computed-types": "^1.11.
|
|
179
|
-
"
|
|
180
|
-
"eslint
|
|
181
|
-
"
|
|
182
|
-
"
|
|
183
|
-
"
|
|
184
|
-
"io-ts
|
|
185
|
-
"
|
|
186
|
-
"joi": "^17.
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"
|
|
204
|
+
"class-validator": "^0.14.0",
|
|
205
|
+
"computed-types": "^1.11.2",
|
|
206
|
+
"cross-env": "^7.0.3",
|
|
207
|
+
"eslint": "^8.36.0",
|
|
208
|
+
"eslint-config-prettier": "^8.8.0",
|
|
209
|
+
"fp-ts": "^2.13.1",
|
|
210
|
+
"husky": "^8.0.3",
|
|
211
|
+
"io-ts": "^2.2.20",
|
|
212
|
+
"io-ts-types": "^0.5.19",
|
|
213
|
+
"joi": "^17.9.1",
|
|
214
|
+
"jsdom": "^21.1.1",
|
|
215
|
+
"lint-staged": "^13.2.0",
|
|
216
|
+
"microbundle": "^0.15.1",
|
|
217
|
+
"monocle-ts": "^2.3.13",
|
|
190
218
|
"newtype-ts": "^0.3.5",
|
|
191
|
-
"nope-validator": "^1.0.
|
|
219
|
+
"nope-validator": "^1.0.4",
|
|
192
220
|
"npm-run-all": "^4.1.5",
|
|
193
|
-
"prettier": "^2.
|
|
194
|
-
"react": "^
|
|
195
|
-
"react-dom": "^
|
|
196
|
-
"react-hook-form": "^7.
|
|
221
|
+
"prettier": "^2.8.7",
|
|
222
|
+
"react": "^18.2.0",
|
|
223
|
+
"react-dom": "^18.2.0",
|
|
224
|
+
"react-hook-form": "^7.43.7",
|
|
197
225
|
"reflect-metadata": "^0.1.13",
|
|
198
|
-
"superstruct": "^0.
|
|
199
|
-
"
|
|
200
|
-
"
|
|
201
|
-
"
|
|
202
|
-
"
|
|
203
|
-
"
|
|
204
|
-
"
|
|
226
|
+
"superstruct": "^1.0.3",
|
|
227
|
+
"typanion": "^3.12.1",
|
|
228
|
+
"typescript": "^5.0.2",
|
|
229
|
+
"vest": "^4.6.9",
|
|
230
|
+
"vite": "^4.2.1",
|
|
231
|
+
"vite-tsconfig-paths": "^4.0.7",
|
|
232
|
+
"vitest": "^0.29.7",
|
|
233
|
+
"yup": "^1.0.2",
|
|
234
|
+
"zod": "^3.21.4"
|
|
205
235
|
},
|
|
206
236
|
"peerDependencies": {
|
|
207
237
|
"react-hook-form": "^7.0.0"
|
|
208
238
|
},
|
|
209
239
|
"lint-staged": {
|
|
210
240
|
"*.{js,ts}": [
|
|
211
|
-
"
|
|
241
|
+
"pnpm lint --fix"
|
|
212
242
|
],
|
|
213
243
|
"*.{md,json,yml}": [
|
|
214
244
|
"prettier --write"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './superstruct';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './superstruct';
|
|
2
|
+
export * from './types';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Resolver } from './types';
|
|
2
|
-
export declare const superstructResolver: Resolver;
|
|
1
|
+
import { Resolver } from './types';
|
|
2
|
+
export declare const superstructResolver: Resolver;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("@hookform/resolvers"),r=require("superstruct");exports.superstructResolver=function(s,t){return function(u,
|
|
1
|
+
var e=require("@hookform/resolvers"),r=require("superstruct");exports.superstructResolver=function(s,t,a){return void 0===a&&(a={}),function(o,u,i){var l,n=r.validate(o,s,t);return n[0]?{values:{},errors:e.toNestError((l=n[0],l.failures().reduce(function(e,r){return(e[r.path.join(".")]={message:r.message,type:r.type})&&e},{})),i)}:(i.shouldUseNativeValidation&&e.validateFieldsNatively({},i),{values:a.raw?o:n[1],errors:{}})}};
|
|
2
2
|
//# sourceMappingURL=superstruct.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { FieldError } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, resolverOptions)
|
|
1
|
+
{"version":3,"file":"superstruct.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { FieldError } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const result = validate(values, schema, schemaOptions);\n\n if (result[0]) {\n return {\n values: {},\n errors: toNestError(parseErrorSchema(result[0]), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result[1],\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","error","result","validate","errors","toNestError","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"0FAiBE,SAACA,EAAQC,EAAeC,mBAAAA,IAAAA,EAAkB,CAAA,GACzCC,SAAAA,EAAQC,EAAGC,GACV,IAbsBC,EAahBC,EAASC,EAAQA,SAACL,EAAQH,EAAQC,GAExC,OAAIM,EAAO,GACF,CACLJ,OAAQ,CAAE,EACVM,OAAQC,EAAAA,aAlBUJ,EAkBmBC,EAAO,GAjBlDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,UACRO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,CAAQ,EAChB,CAAA,IAWqDR,KAIrDA,EAAQa,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEd,GAEzD,CACLF,OAAQD,EAAgBkB,IAAMjB,EAASI,EAAO,GAC9CE,OAAQ,CAAA,GAEZ,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{validate as o}from"superstruct";var t=function(t,s){return
|
|
1
|
+
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{validate as o}from"superstruct";var t=function(t,s,u){return void 0===u&&(u={}),function(a,i,n){var f,m=o(a,t,s);return m[0]?{values:{},errors:r((f=m[0],f.failures().reduce(function(r,e){return(r[e.path.join(".")]={message:e.message,type:e.type})&&r},{})),n)}:(n.shouldUseNativeValidation&&e({},n),{values:u.raw?a:m[1],errors:{}})}};export{t as superstructResolver};
|
|
2
2
|
//# sourceMappingURL=superstruct.module.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{validate as s}from"superstruct";const o=(o,t,a={})=>(u,i,m)=>{const p=s(u,o,t);return p[0]?{values:{},errors:r((l=p[0],l.failures().reduce((r,e)=>(r[e.path.join(".")]={message:e.message,type:e.type})&&r,{})),m)}:(m.shouldUseNativeValidation&&e({},m),{values:a.raw?u:p[1],errors:{}});var l};export{o as superstructResolver};
|
|
2
|
+
//# sourceMappingURL=superstruct.modern.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"superstruct.modern.mjs","sources":["../src/superstruct.ts"],"sourcesContent":["import { FieldError } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const result = validate(values, schema, schemaOptions);\n\n if (result[0]) {\n return {\n values: {},\n errors: toNestError(parseErrorSchema(result[0]), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result[1],\n errors: {},\n };\n };\n"],"names":["superstructResolver","schema","schemaOptions","resolverOptions","values","_","options","result","validate","errors","toNestError","error","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"qHAMA,MAUaA,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAE,IAC5C,CAACC,EAAQC,EAAGC,KACV,MAAMC,EAASC,EAASJ,EAAQH,EAAQC,GAExC,OAAIK,EAAO,GACF,CACLH,OAAQ,CAAA,EACRK,OAAQC,GAlBUC,EAkBmBJ,EAAO,GAjBlDI,EAAMC,WAAWC,OACf,CAACC,EAAUH,KACRG,EAASH,EAAMI,KAAKC,KAAK,MAAQ,CAChCC,QAASN,EAAMM,QACfC,KAAMP,EAAMO,QACRJ,EACR,CAAA,IAWqDR,KAIrDA,EAAQa,2BAA6BC,EAAuB,CAAE,EAAEd,GAEzD,CACLF,OAAQD,EAAgBkB,IAAMjB,EAASG,EAAO,GAC9CE,OAAQ,KA1BYE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{validate as o}from"superstruct";var t=function(t,s){return
|
|
1
|
+
import{toNestError as r,validateFieldsNatively as e}from"@hookform/resolvers";import{validate as o}from"superstruct";var t=function(t,s,u){return void 0===u&&(u={}),function(a,i,n){var f,m=o(a,t,s);return m[0]?{values:{},errors:r((f=m[0],f.failures().reduce(function(r,e){return(r[e.path.join(".")]={message:e.message,type:e.type})&&r},{})),n)}:(n.shouldUseNativeValidation&&e({},n),{values:u.raw?a:m[1],errors:{}})}};export{t as superstructResolver};
|
|
2
2
|
//# sourceMappingURL=superstruct.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.module.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { FieldError } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, resolverOptions)
|
|
1
|
+
{"version":3,"file":"superstruct.module.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { FieldError } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const result = validate(values, schema, schemaOptions);\n\n if (result[0]) {\n return {\n values: {},\n errors: toNestError(parseErrorSchema(result[0]), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result[1],\n errors: {},\n };\n };\n"],"names":["superstructResolver","schema","schemaOptions","resolverOptions","values","_","options","error","result","validate","errors","toNestError","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"qHAMA,IAUaA,EACX,SAACC,EAAQC,EAAeC,mBAAAA,IAAAA,EAAkB,CAAA,GACzCC,SAAAA,EAAQC,EAAGC,GACV,IAbsBC,EAahBC,EAASC,EAASL,EAAQH,EAAQC,GAExC,OAAIM,EAAO,GACF,CACLJ,OAAQ,CAAE,EACVM,OAAQC,GAlBUJ,EAkBmBC,EAAO,GAjBlDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,UACRO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,CAAQ,EAChB,CAAA,IAWqDR,KAIrDA,EAAQa,2BAA6BC,EAAuB,CAAE,EAAEd,GAEzD,CACLF,OAAQD,EAAgBkB,IAAMjB,EAASI,EAAO,GAC9CE,OAAQ,CAAA,GAEZ,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("superstruct")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","superstruct"],r):r((e||self).hookformResolversSuperstruct={},e.hookformResolvers,e.superstruct)}(this,function(e,r,o){e.superstructResolver=function(e,s){return
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("superstruct")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","superstruct"],r):r((e||self).hookformResolversSuperstruct={},e.hookformResolvers,e.superstruct)}(this,function(e,r,o){e.superstructResolver=function(e,s,t){return void 0===t&&(t={}),function(u,i,n){var f,l=o.validate(u,e,s);return l[0]?{values:{},errors:r.toNestError((f=l[0],f.failures().reduce(function(e,r){return(e[r.path.join(".")]={message:r.message,type:r.type})&&e},{})),n)}:(n.shouldUseNativeValidation&&r.validateFieldsNatively({},n),{values:t.raw?u:l[1],errors:{}})}}});
|
|
2
2
|
//# sourceMappingURL=superstruct.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.umd.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { FieldError } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, resolverOptions)
|
|
1
|
+
{"version":3,"file":"superstruct.umd.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { FieldError } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const result = validate(values, schema, schemaOptions);\n\n if (result[0]) {\n return {\n values: {},\n errors: toNestError(parseErrorSchema(result[0]), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result[1],\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","error","result","validate","errors","toNestError","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"4YAiBE,SAACA,EAAQC,EAAeC,mBAAAA,IAAAA,EAAkB,CAAA,GACzCC,SAAAA,EAAQC,EAAGC,GACV,IAbsBC,EAahBC,EAASC,EAAQA,SAACL,EAAQH,EAAQC,GAExC,OAAIM,EAAO,GACF,CACLJ,OAAQ,CAAE,EACVM,OAAQC,EAAAA,aAlBUJ,EAkBmBC,EAAO,GAjBlDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,UACRO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,CAAQ,EAChB,CAAA,IAWqDR,KAIrDA,EAAQa,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEd,GAEzD,CACLF,OAAQD,EAAgBkB,IAAMjB,EAASI,EAAO,GAC9CE,OAAQ,CAAA,GAEZ,CAAC"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
-
import { validate, Struct } from 'superstruct';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
+
import { validate, Struct } from 'superstruct';
|
|
3
|
+
type Options = Parameters<typeof validate>[2];
|
|
4
|
+
export type Resolver = <T extends Struct<any, any>>(schema: T, options?: Options, factoryOptions?: {
|
|
5
|
+
/**
|
|
6
|
+
* Return the raw input values rather than the parsed values.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
raw?: boolean;
|
|
10
|
+
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
|
|
11
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, screen
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import user from '@testing-library/user-event';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import { object, string, Infer, size } from 'superstruct';
|
|
@@ -34,7 +34,7 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
test("form's native validation with Superstruct", async () => {
|
|
37
|
-
const handleSubmit =
|
|
37
|
+
const handleSubmit = vi.fn();
|
|
38
38
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
39
39
|
|
|
40
40
|
// username
|
|
@@ -51,9 +51,7 @@ test("form's native validation with Superstruct", async () => {
|
|
|
51
51
|
expect(passwordField.validity.valid).toBe(true);
|
|
52
52
|
expect(passwordField.validationMessage).toBe('');
|
|
53
53
|
|
|
54
|
-
await
|
|
55
|
-
user.click(screen.getByText(/submit/i));
|
|
56
|
-
});
|
|
54
|
+
await user.click(screen.getByText(/submit/i));
|
|
57
55
|
|
|
58
56
|
// username
|
|
59
57
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -69,10 +67,8 @@ test("form's native validation with Superstruct", async () => {
|
|
|
69
67
|
'Expected a string with a length of `6` but received one with a length of `0`',
|
|
70
68
|
);
|
|
71
69
|
|
|
72
|
-
await
|
|
73
|
-
|
|
74
|
-
user.type(screen.getByPlaceholderText(/password/i), 'passwo');
|
|
75
|
-
});
|
|
70
|
+
await user.type(screen.getByPlaceholderText(/username/i), 'jo');
|
|
71
|
+
await user.type(screen.getByPlaceholderText(/password/i), 'passwo');
|
|
76
72
|
|
|
77
73
|
// username
|
|
78
74
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, screen
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import user from '@testing-library/user-event';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import { object, string, Infer, size } from 'superstruct';
|
|
@@ -39,14 +39,12 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
test("form's validation with Superstruct and TypeScript's integration", async () => {
|
|
42
|
-
const handleSubmit =
|
|
42
|
+
const handleSubmit = vi.fn();
|
|
43
43
|
render(<TestComponent onSubmit={handleSubmit} />);
|
|
44
44
|
|
|
45
|
-
expect(screen.queryAllByRole(
|
|
45
|
+
expect(screen.queryAllByRole('alert')).toHaveLength(0);
|
|
46
46
|
|
|
47
|
-
await
|
|
48
|
-
user.click(screen.getByText(/submit/i));
|
|
49
|
-
});
|
|
47
|
+
await user.click(screen.getByText(/submit/i));
|
|
50
48
|
|
|
51
49
|
expect(
|
|
52
50
|
screen.getByText(
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`superstructResolver should return a single error from superstructResolver when validation fails 1`] = `
|
|
4
|
-
|
|
5
|
-
"errors":
|
|
6
|
-
"birthYear":
|
|
3
|
+
exports[`superstructResolver > should return a single error from superstructResolver when validation fails 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"errors": {
|
|
6
|
+
"birthYear": {
|
|
7
7
|
"message": "Expected a number, but received: \\"birthYear\\"",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "number",
|
|
10
10
|
},
|
|
11
|
-
"email":
|
|
11
|
+
"email": {
|
|
12
12
|
"message": "Expected a string matching \`/^[\\\\w-\\\\.]+@([\\\\w-]+\\\\.)+[\\\\w-]{2,4}$/\` but received \\"\\"",
|
|
13
|
-
"ref":
|
|
13
|
+
"ref": {
|
|
14
14
|
"name": "email",
|
|
15
15
|
},
|
|
16
16
|
"type": "string",
|
|
17
17
|
},
|
|
18
|
-
"enabled":
|
|
18
|
+
"enabled": {
|
|
19
19
|
"message": "Expected a value of type \`boolean\`, but received: \`undefined\`",
|
|
20
20
|
"ref": undefined,
|
|
21
21
|
"type": "boolean",
|
|
22
22
|
},
|
|
23
|
-
"like":
|
|
24
|
-
|
|
25
|
-
"id":
|
|
23
|
+
"like": [
|
|
24
|
+
{
|
|
25
|
+
"id": {
|
|
26
26
|
"message": "Expected a number, but received: \\"z\\"",
|
|
27
27
|
"ref": undefined,
|
|
28
28
|
"type": "number",
|
|
29
29
|
},
|
|
30
|
-
"name":
|
|
30
|
+
"name": {
|
|
31
31
|
"message": "Expected a string, but received: undefined",
|
|
32
32
|
"ref": undefined,
|
|
33
33
|
"type": "string",
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
|
-
"password":
|
|
37
|
+
"password": {
|
|
38
38
|
"message": "Expected a string matching \`/^[a-zA-Z0-9]{3,30}/\` but received \\"___\\"",
|
|
39
|
-
"ref":
|
|
39
|
+
"ref": {
|
|
40
40
|
"name": "password",
|
|
41
41
|
},
|
|
42
42
|
"type": "string",
|
|
43
43
|
},
|
|
44
|
-
"repeatPassword":
|
|
44
|
+
"repeatPassword": {
|
|
45
45
|
"message": "Expected a value of type \`Password\`, but received: \`undefined\`",
|
|
46
46
|
"ref": undefined,
|
|
47
47
|
"type": "Password",
|
|
48
48
|
},
|
|
49
|
-
"tags":
|
|
49
|
+
"tags": {
|
|
50
50
|
"message": "Expected an array value, but received: undefined",
|
|
51
51
|
"ref": undefined,
|
|
52
52
|
"type": "array",
|
|
53
53
|
},
|
|
54
|
-
"username":
|
|
54
|
+
"username": {
|
|
55
55
|
"message": "Expected a string, but received: undefined",
|
|
56
|
-
"ref":
|
|
56
|
+
"ref": {
|
|
57
57
|
"name": "username",
|
|
58
58
|
},
|
|
59
59
|
"type": "string",
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
|
-
"values":
|
|
62
|
+
"values": {},
|
|
63
63
|
}
|
|
64
64
|
`;
|
|
@@ -21,4 +21,17 @@ describe('superstructResolver', () => {
|
|
|
21
21
|
|
|
22
22
|
expect(result).toMatchSnapshot();
|
|
23
23
|
});
|
|
24
|
+
|
|
25
|
+
it('should return values from superstructResolver when validation pass & raw=true', async () => {
|
|
26
|
+
const result = await superstructResolver(schema, undefined, { raw: true })(
|
|
27
|
+
validData,
|
|
28
|
+
undefined,
|
|
29
|
+
{
|
|
30
|
+
fields,
|
|
31
|
+
shouldUseNativeValidation,
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(result).toEqual({ errors: {}, values: validData });
|
|
36
|
+
});
|
|
24
37
|
});
|
|
@@ -15,8 +15,9 @@ const parseErrorSchema = (error: StructError) =>
|
|
|
15
15
|
);
|
|
16
16
|
|
|
17
17
|
export const superstructResolver: Resolver =
|
|
18
|
-
(schema, resolverOptions
|
|
19
|
-
|
|
18
|
+
(schema, schemaOptions, resolverOptions = {}) =>
|
|
19
|
+
(values, _, options) => {
|
|
20
|
+
const result = validate(values, schema, schemaOptions);
|
|
20
21
|
|
|
21
22
|
if (result[0]) {
|
|
22
23
|
return {
|
|
@@ -28,7 +29,7 @@ export const superstructResolver: Resolver =
|
|
|
28
29
|
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
|
|
29
30
|
|
|
30
31
|
return {
|
|
31
|
-
values: result[1],
|
|
32
|
+
values: resolverOptions.raw ? values : result[1],
|
|
32
33
|
errors: {},
|
|
33
34
|
};
|
|
34
35
|
};
|
package/superstruct/src/types.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FieldValues,
|
|
3
|
-
ResolverOptions,
|
|
4
|
-
ResolverResult,
|
|
5
|
-
} from 'react-hook-form';
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
6
2
|
import { validate, Struct } from 'superstruct';
|
|
7
3
|
|
|
8
4
|
type Options = Parameters<typeof validate>[2];
|
|
@@ -10,6 +6,13 @@ type Options = Parameters<typeof validate>[2];
|
|
|
10
6
|
export type Resolver = <T extends Struct<any, any>>(
|
|
11
7
|
schema: T,
|
|
12
8
|
options?: Options,
|
|
9
|
+
factoryOptions?: {
|
|
10
|
+
/**
|
|
11
|
+
* Return the raw input values rather than the parsed values.
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
raw?: boolean;
|
|
15
|
+
},
|
|
13
16
|
) => <TFieldValues extends FieldValues, TContext>(
|
|
14
17
|
values: TFieldValues,
|
|
15
18
|
context: TContext | undefined,
|
package/typanion/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './typanion';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './typanion';
|
|
2
|
+
export * from './types';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Resolver } from './types';
|
|
2
|
-
export declare const typanionResolver: Resolver;
|
|
1
|
+
import type { Resolver } from './types';
|
|
2
|
+
export declare const typanionResolver: Resolver;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typanion.js","sources":["../src/typanion.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const e = error.split(':');\n\n acc[e[0].slice(1)] = {\n message: e[1].trim(),\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestError(parsedErrors, options) };\n };\n"],"names":["validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","reduce","acc","error","e","split","slice","message","trim","parseErrors","shouldUseNativeValidation","validateFieldsNatively","toNestError"],"mappings":"8DAiBE,SAACA,EAAWC,
|
|
1
|
+
{"version":3,"file":"typanion.js","sources":["../src/typanion.ts"],"sourcesContent":["import type { FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const e = error.split(':');\n\n acc[e[0].slice(1)] = {\n message: e[1].trim(),\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestError(parsedErrors, options) };\n };\n"],"names":["validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","reduce","acc","error","e","split","slice","message","trim","parseErrors","shouldUseNativeValidation","validateFieldsNatively","toNestError"],"mappings":"8DAiBE,SAACA,EAAWC,GAAqB,gBAArBA,IAAAA,EAAmB,CAAA,YAC9BC,EAAQC,EAAGC,GACV,IAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,CAAA,EACA,CACEC,OAAQJ,GAEVJ,IAGES,EA1BU,SAACD,EAAkBC,GACrC,YADqCA,IAAAA,IAAAA,EAA4B,CAAE,GAC5DD,EAAOE,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAID,EAAME,MAAM,KAMtB,OAJAH,EAAIE,EAAE,GAAGE,MAAM,IAAM,CACnBC,QAASH,EAAE,GAAGI,QAGTN,CACT,EAAGF,EACL,CAgByBS,CAAYd,GAEjC,OAAIC,GACFF,EAAQgB,2BACNC,EAAsBA,uBAACX,EAAcN,GAEhC,CAAEF,OAAAA,EAAQO,OAAQ,KAGpB,CAAEP,OAAQ,CAAA,EAAIO,OAAQa,cAAYZ,EAAcN,GACzD,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{validateFieldsNatively as r,toNestError as e}from"@hookform/resolvers";const s=(s,o={})=>(t,i,a)=>{const l=[],n=s(t,Object.assign({},{errors:l},o)),c=((r,e={})=>r.reduce((r,e)=>{const s=e.split(":");return r[s[0].slice(1)]={message:s[1].trim()},r},e))(l);return n?(a.shouldUseNativeValidation&&r(c,a),{values:t,errors:{}}):{values:{},errors:e(c,a)}};export{s as typanionResolver};
|
|
2
|
-
//# sourceMappingURL=typanion.modern.
|
|
2
|
+
//# sourceMappingURL=typanion.modern.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typanion.modern.mjs","sources":["../src/typanion.ts"],"sourcesContent":["import type { FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const e = error.split(':');\n\n acc[e[0].slice(1)] = {\n message: e[1].trim(),\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestError(parsedErrors, options) };\n };\n"],"names":["typanionResolver","validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","parseErrors","reduce","acc","error","e","split","slice","message","trim","shouldUseNativeValidation","validateFieldsNatively","toNestError"],"mappings":"8EAIA,MAYaA,EACXA,CAACC,EAAWC,EAAmB,CAAA,IAC/B,CAACC,EAAQC,EAAGC,KACV,MAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,CAAE,EACF,CACEC,OAAQJ,GAEVJ,IAGES,EA1BUC,EAACF,EAAkBC,EAA4B,CAAA,IAC1DD,EAAOG,OAAO,CAACC,EAAKC,KACzB,MAAMC,EAAID,EAAME,MAAM,KAMtB,OAJAH,EAAIE,EAAE,GAAGE,MAAM,IAAM,CACnBC,QAASH,EAAE,GAAGI,QAGTN,GACNH,GAiBoBC,CAAYN,GAEjC,OAAIC,GACFF,EAAQgB,2BACNC,EAAuBX,EAAcN,GAEhC,CAAEF,SAAQO,OAAQ,CAAA,IAGpB,CAAEP,OAAQ,CAAE,EAAEO,OAAQa,EAAYZ,EAAcN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typanion.module.js","sources":["../src/typanion.ts"],"sourcesContent":["import type {FieldError, FieldErrors} from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const e = error.split(':');\n\n acc[e[0].slice(1)] = {\n message: e[1].trim(),\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestError(parsedErrors, options) };\n };\n"],"names":["typanionResolver","validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","reduce","acc","error","e","split","slice","message","trim","parseErrors","shouldUseNativeValidation","validateFieldsNatively","toNestError"],"mappings":"8EAIA,IAYaA,EACX,SAACC,EAAWC,
|
|
1
|
+
{"version":3,"file":"typanion.module.js","sources":["../src/typanion.ts"],"sourcesContent":["import type { FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const e = error.split(':');\n\n acc[e[0].slice(1)] = {\n message: e[1].trim(),\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestError(parsedErrors, options) };\n };\n"],"names":["typanionResolver","validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","reduce","acc","error","e","split","slice","message","trim","parseErrors","shouldUseNativeValidation","validateFieldsNatively","toNestError"],"mappings":"8EAIA,IAYaA,EACX,SAACC,EAAWC,GAAqB,gBAArBA,IAAAA,EAAmB,CAAA,YAC9BC,EAAQC,EAAGC,GACV,IAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,CAAA,EACA,CACEC,OAAQJ,GAEVJ,IAGES,EA1BU,SAACD,EAAkBC,GACrC,YADqCA,IAAAA,IAAAA,EAA4B,CAAE,GAC5DD,EAAOE,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAID,EAAME,MAAM,KAMtB,OAJAH,EAAIE,EAAE,GAAGE,MAAM,IAAM,CACnBC,QAASH,EAAE,GAAGI,QAGTN,CACT,EAAGF,EACL,CAgByBS,CAAYd,GAEjC,OAAIC,GACFF,EAAQgB,2BACNC,EAAuBX,EAAcN,GAEhC,CAAEF,OAAAA,EAAQO,OAAQ,KAGpB,CAAEP,OAAQ,CAAA,EAAIO,OAAQa,EAAYZ,EAAcN,GACzD,CAAC"}
|