@hookform/resolvers 2.9.10 → 3.0.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.
Files changed (229) hide show
  1. package/README.md +33 -2
  2. package/ajv/dist/ajv.d.ts +2 -2
  3. package/ajv/dist/ajv.js +1 -7
  4. package/ajv/dist/ajv.js.map +1 -1
  5. package/ajv/dist/ajv.mjs +1 -7
  6. package/ajv/dist/ajv.modern.mjs +2 -0
  7. package/ajv/dist/ajv.modern.mjs.map +1 -0
  8. package/ajv/dist/ajv.module.js +1 -7
  9. package/ajv/dist/ajv.module.js.map +1 -1
  10. package/ajv/dist/ajv.umd.js +1 -7
  11. package/ajv/dist/ajv.umd.js.map +1 -1
  12. package/ajv/dist/index.d.ts +2 -2
  13. package/ajv/dist/types.d.ts +5 -5
  14. package/ajv/package.json +3 -1
  15. package/ajv/src/__tests__/Form-native-validation.tsx +5 -9
  16. package/ajv/src/__tests__/Form.tsx +4 -6
  17. package/ajv/src/__tests__/__fixtures__/data.ts +3 -4
  18. package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +83 -83
  19. package/ajv/src/ajv.ts +28 -24
  20. package/class-validator/dist/class-validator.d.ts +2 -2
  21. package/class-validator/dist/class-validator.js +1 -1
  22. package/class-validator/dist/class-validator.js.map +1 -1
  23. package/class-validator/dist/class-validator.mjs +1 -1
  24. package/class-validator/dist/class-validator.modern.mjs +2 -0
  25. package/class-validator/dist/class-validator.modern.mjs.map +1 -0
  26. package/class-validator/dist/class-validator.module.js +1 -1
  27. package/class-validator/dist/class-validator.module.js.map +1 -1
  28. package/class-validator/dist/class-validator.umd.js +1 -1
  29. package/class-validator/dist/class-validator.umd.js.map +1 -1
  30. package/class-validator/dist/index.d.ts +2 -2
  31. package/class-validator/dist/types.d.ts +12 -9
  32. package/class-validator/src/__tests__/Form-native-validation.tsx +5 -9
  33. package/class-validator/src/__tests__/Form.tsx +4 -6
  34. package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +102 -67
  35. package/class-validator/src/__tests__/class-validator.ts +66 -6
  36. package/class-validator/src/class-validator.ts +6 -4
  37. package/class-validator/src/types.ts +7 -8
  38. package/computed-types/dist/computed-types.d.ts +2 -2
  39. package/computed-types/dist/computed-types.js +1 -1
  40. package/computed-types/dist/computed-types.js.map +1 -1
  41. package/computed-types/dist/computed-types.mjs +1 -1
  42. package/computed-types/dist/computed-types.modern.mjs +2 -0
  43. package/computed-types/dist/computed-types.modern.mjs.map +1 -0
  44. package/computed-types/dist/computed-types.module.js +1 -1
  45. package/computed-types/dist/computed-types.module.js.map +1 -1
  46. package/computed-types/dist/computed-types.umd.js +1 -1
  47. package/computed-types/dist/computed-types.umd.js.map +1 -1
  48. package/computed-types/dist/index.d.ts +2 -2
  49. package/computed-types/dist/types.d.ts +2 -2
  50. package/computed-types/src/__tests__/Form-native-validation.tsx +5 -9
  51. package/computed-types/src/__tests__/Form.tsx +4 -6
  52. package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +21 -21
  53. package/computed-types/src/__tests__/computed-types.ts +16 -0
  54. package/computed-types/src/computed-types.ts +12 -5
  55. package/dist/index.d.ts +2 -2
  56. package/dist/resolvers.js +1 -1
  57. package/dist/resolvers.js.map +1 -1
  58. package/dist/resolvers.mjs +1 -1
  59. package/dist/resolvers.mjs.map +1 -1
  60. package/dist/resolvers.module.js +1 -1
  61. package/dist/resolvers.module.js.map +1 -1
  62. package/dist/resolvers.umd.js +1 -1
  63. package/dist/resolvers.umd.js.map +1 -1
  64. package/dist/toNestError.d.ts +2 -2
  65. package/dist/validateFieldsNatively.d.ts +2 -2
  66. package/io-ts/dist/arrayToPath.d.ts +3 -3
  67. package/io-ts/dist/errorsToRecord.d.ts +5 -5
  68. package/io-ts/dist/index.d.ts +2 -2
  69. package/io-ts/dist/io-ts.d.ts +2 -2
  70. package/io-ts/dist/io-ts.js +1 -1
  71. package/io-ts/dist/io-ts.js.map +1 -1
  72. package/io-ts/dist/io-ts.mjs +1 -1
  73. package/io-ts/dist/io-ts.modern.mjs +2 -0
  74. package/io-ts/dist/io-ts.modern.mjs.map +1 -0
  75. package/io-ts/dist/io-ts.module.js +1 -1
  76. package/io-ts/dist/io-ts.module.js.map +1 -1
  77. package/io-ts/dist/io-ts.umd.js +1 -1
  78. package/io-ts/dist/io-ts.umd.js.map +1 -1
  79. package/io-ts/dist/types.d.ts +7 -7
  80. package/io-ts/src/__tests__/Form-native-validation.tsx +5 -9
  81. package/io-ts/src/__tests__/Form.tsx +4 -6
  82. package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +28 -28
  83. package/io-ts/src/__tests__/errorsToRecord.ts +47 -0
  84. package/io-ts/src/__tests__/io-ts.ts +1 -1
  85. package/io-ts/src/errorsToRecord.ts +7 -6
  86. package/joi/dist/index.d.ts +2 -2
  87. package/joi/dist/joi.d.ts +2 -2
  88. package/joi/dist/joi.js.map +1 -1
  89. package/joi/dist/{joi.modern.js → joi.modern.mjs} +1 -1
  90. package/joi/dist/joi.modern.mjs.map +1 -0
  91. package/joi/dist/joi.module.js.map +1 -1
  92. package/joi/dist/joi.umd.js.map +1 -1
  93. package/joi/dist/types.d.ts +5 -5
  94. package/joi/src/__tests__/Form-native-validation.tsx +5 -9
  95. package/joi/src/__tests__/Form.tsx +4 -6
  96. package/joi/src/__tests__/__snapshots__/joi.ts.snap +87 -87
  97. package/joi/src/__tests__/joi.ts +8 -8
  98. package/nope/dist/index.d.ts +2 -2
  99. package/nope/dist/nope.d.ts +2 -2
  100. package/nope/dist/nope.js.map +1 -1
  101. package/nope/dist/{nope.modern.js → nope.modern.mjs} +1 -1
  102. package/nope/dist/nope.modern.mjs.map +1 -0
  103. package/nope/dist/nope.module.js.map +1 -1
  104. package/nope/dist/nope.umd.js.map +1 -1
  105. package/nope/dist/types.d.ts +9 -9
  106. package/nope/src/__tests__/Form-native-validation.tsx +5 -9
  107. package/nope/src/__tests__/Form.tsx +4 -6
  108. package/nope/src/__tests__/__snapshots__/nope.ts.snap +15 -15
  109. package/nope/src/__tests__/nope.ts +1 -1
  110. package/package.json +74 -44
  111. package/superstruct/dist/index.d.ts +2 -2
  112. package/superstruct/dist/superstruct.d.ts +2 -2
  113. package/superstruct/dist/superstruct.js +1 -1
  114. package/superstruct/dist/superstruct.js.map +1 -1
  115. package/superstruct/dist/superstruct.mjs +1 -1
  116. package/superstruct/dist/superstruct.modern.mjs +2 -0
  117. package/superstruct/dist/superstruct.modern.mjs.map +1 -0
  118. package/superstruct/dist/superstruct.module.js +1 -1
  119. package/superstruct/dist/superstruct.module.js.map +1 -1
  120. package/superstruct/dist/superstruct.umd.js +1 -1
  121. package/superstruct/dist/superstruct.umd.js.map +1 -1
  122. package/superstruct/dist/types.d.ts +11 -5
  123. package/superstruct/src/__tests__/Form-native-validation.tsx +5 -9
  124. package/superstruct/src/__tests__/Form.tsx +4 -6
  125. package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +19 -19
  126. package/superstruct/src/__tests__/superstruct.ts +13 -0
  127. package/superstruct/src/superstruct.ts +4 -3
  128. package/superstruct/src/types.ts +8 -5
  129. package/typanion/dist/index.d.ts +2 -2
  130. package/typanion/dist/typanion.d.ts +2 -2
  131. package/typanion/dist/typanion.js.map +1 -1
  132. package/typanion/dist/{typanion.modern.js → typanion.modern.mjs} +1 -1
  133. package/typanion/dist/typanion.modern.mjs.map +1 -0
  134. package/typanion/dist/typanion.module.js.map +1 -1
  135. package/typanion/dist/typanion.umd.js.map +1 -1
  136. package/typanion/dist/types.d.ts +9 -9
  137. package/typanion/src/__tests__/Form-native-validation.tsx +7 -10
  138. package/typanion/src/__tests__/Form.tsx +9 -7
  139. package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +22 -22
  140. package/typanion/src/__tests__/typanion.ts +11 -7
  141. package/typanion/src/typanion.ts +1 -1
  142. package/typebox/dist/index.d.ts +2 -0
  143. package/typebox/dist/typebox.d.ts +2 -0
  144. package/typebox/dist/typebox.js +2 -0
  145. package/typebox/dist/typebox.js.map +1 -0
  146. package/typebox/dist/typebox.mjs +2 -0
  147. package/typebox/dist/typebox.modern.mjs +2 -0
  148. package/typebox/dist/typebox.modern.mjs.map +1 -0
  149. package/typebox/dist/typebox.module.js +2 -0
  150. package/typebox/dist/typebox.module.js.map +1 -0
  151. package/typebox/dist/typebox.umd.js +2 -0
  152. package/typebox/dist/typebox.umd.js.map +1 -0
  153. package/typebox/dist/types.d.ts +3 -0
  154. package/typebox/package.json +18 -0
  155. package/typebox/src/__tests__/Form-native-validation.tsx +83 -0
  156. package/typebox/src/__tests__/Form.tsx +54 -0
  157. package/typebox/src/__tests__/__fixtures__/data.ts +84 -0
  158. package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +190 -0
  159. package/typebox/src/__tests__/typebox.ts +34 -0
  160. package/typebox/src/index.ts +2 -0
  161. package/typebox/src/typebox.ts +64 -0
  162. package/typebox/src/types.ts +10 -0
  163. package/vest/dist/index.d.ts +2 -1
  164. package/vest/dist/types.d.ts +8 -0
  165. package/vest/dist/vest.d.ts +2 -2
  166. package/vest/dist/vest.js.map +1 -1
  167. package/vest/dist/{vest.modern.js → vest.modern.mjs} +1 -1
  168. package/vest/dist/vest.modern.mjs.map +1 -0
  169. package/vest/dist/vest.module.js.map +1 -1
  170. package/vest/dist/vest.umd.js.map +1 -1
  171. package/vest/src/__tests__/Form-native-validation.tsx +5 -9
  172. package/vest/src/__tests__/Form.tsx +6 -10
  173. package/vest/src/__tests__/__snapshots__/vest.ts.snap +47 -47
  174. package/vest/src/index.ts +1 -0
  175. package/yup/dist/index.d.ts +2 -2
  176. package/yup/dist/types.d.ts +15 -9
  177. package/yup/dist/yup.d.ts +2 -2
  178. package/yup/dist/yup.js +1 -1
  179. package/yup/dist/yup.js.map +1 -1
  180. package/yup/dist/yup.mjs +1 -1
  181. package/yup/dist/yup.modern.mjs +2 -0
  182. package/yup/dist/yup.modern.mjs.map +1 -0
  183. package/yup/dist/yup.module.js +1 -1
  184. package/yup/dist/yup.module.js.map +1 -1
  185. package/yup/dist/yup.umd.js +1 -1
  186. package/yup/dist/yup.umd.js.map +1 -1
  187. package/yup/src/__tests__/Form-native-validation.tsx +5 -9
  188. package/yup/src/__tests__/Form.tsx +4 -6
  189. package/yup/src/__tests__/__fixtures__/data.ts +2 -3
  190. package/yup/src/__tests__/__snapshots__/yup.ts.snap +100 -87
  191. package/yup/src/__tests__/yup.ts +49 -18
  192. package/yup/src/types.ts +14 -11
  193. package/yup/src/yup.ts +1 -1
  194. package/zod/dist/index.d.ts +2 -2
  195. package/zod/dist/types.d.ts +13 -13
  196. package/zod/dist/zod.d.ts +2 -2
  197. package/zod/dist/zod.js +1 -1
  198. package/zod/dist/zod.js.map +1 -1
  199. package/zod/dist/zod.mjs +1 -1
  200. package/zod/dist/zod.modern.mjs +2 -0
  201. package/zod/dist/zod.modern.mjs.map +1 -0
  202. package/zod/dist/zod.module.js +1 -1
  203. package/zod/dist/zod.module.js.map +1 -1
  204. package/zod/dist/zod.umd.js +1 -1
  205. package/zod/dist/zod.umd.js.map +1 -1
  206. package/zod/src/__tests__/Form-native-validation.tsx +5 -9
  207. package/zod/src/__tests__/Form.tsx +4 -6
  208. package/zod/src/__tests__/__snapshots__/zod.ts.snap +120 -120
  209. package/zod/src/__tests__/zod.ts +19 -7
  210. package/zod/src/types.ts +2 -6
  211. package/zod/src/zod.ts +27 -27
  212. package/ajv/dist/ajv.modern.js +0 -8
  213. package/ajv/dist/ajv.modern.js.map +0 -1
  214. package/class-validator/dist/class-validator.modern.js +0 -2
  215. package/class-validator/dist/class-validator.modern.js.map +0 -1
  216. package/computed-types/dist/computed-types.modern.js +0 -2
  217. package/computed-types/dist/computed-types.modern.js.map +0 -1
  218. package/io-ts/dist/io-ts.modern.js +0 -2
  219. package/io-ts/dist/io-ts.modern.js.map +0 -1
  220. package/joi/dist/joi.modern.js.map +0 -1
  221. package/nope/dist/nope.modern.js.map +0 -1
  222. package/superstruct/dist/superstruct.modern.js +0 -2
  223. package/superstruct/dist/superstruct.modern.js.map +0 -1
  224. package/typanion/dist/typanion.modern.js.map +0 -1
  225. package/vest/dist/vest.modern.js.map +0 -1
  226. package/yup/dist/yup.modern.js +0 -2
  227. package/yup/dist/yup.modern.js.map +0 -1
  228. package/zod/dist/zod.modern.js +0 -2
  229. 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": "2.9.10",
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.0",
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": "jest",
133
- "test:watch": "yarn test --watchAll --coverage --runInBand",
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
- "@testing-library/jest-dom": "^5.16.1",
167
- "@testing-library/react": "^12.1.2",
168
- "@testing-library/user-event": "^13.5.0",
169
- "@types/jest": "^27.4.0",
170
- "@types/react": "^17.0.38",
171
- "@typescript-eslint/eslint-plugin": "^5.10.0",
172
- "@typescript-eslint/parser": "^5.10.0",
173
- "ajv": "^8.11.0",
189
+ "@sinclair/typebox": "^0.25.24",
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.3",
195
+ "@types/react": "^18.0.28",
196
+ "@types/testing-library__jest-dom": "^5.14.5",
197
+ "@typescript-eslint/eslint-plugin": "^5.55.0",
198
+ "@typescript-eslint/parser": "^5.55.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.2.0",
202
+ "check-export-map": "^1.3.0",
176
203
  "class-transformer": "^0.5.1",
177
- "class-validator": "^0.13.2",
178
- "computed-types": "^1.11.1",
179
- "eslint": "^7.27.0",
180
- "eslint-config-prettier": "^8.3.0",
181
- "fp-ts": "^2.11.8",
182
- "husky": "^7.0.4",
183
- "io-ts": "^2.0.0",
184
- "io-ts-types": "^0.5.16",
185
- "jest": "^27.4.7",
186
- "joi": "^17.5.0",
187
- "lint-staged": "^12.1.7",
188
- "microbundle": "^0.14.2",
189
- "monocle-ts": "^2.3.12",
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.7.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.8.4",
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.0",
219
+ "nope-validator": "^1.0.4",
192
220
  "npm-run-all": "^4.1.5",
193
- "prettier": "^2.5.1",
194
- "react": "^17.0.2",
195
- "react-dom": "^17.0.2",
196
- "react-hook-form": "^7.33.0",
221
+ "prettier": "^2.8.4",
222
+ "react": "^18.2.0",
223
+ "react-dom": "^18.2.0",
224
+ "react-hook-form": "^7.43.6",
197
225
  "reflect-metadata": "^0.1.13",
198
- "superstruct": "^0.15.3",
199
- "ts-jest": "^27.1.3",
200
- "typanion": "^3.7.1",
201
- "typescript": "^4.5.4",
202
- "vest": "^4.0.3",
203
- "yup": "^0.32.11",
204
- "zod": "^3.11.6"
226
+ "superstruct": "^1.0.3",
227
+ "typanion": "^3.12.1",
228
+ "typescript": "^5.0.2",
229
+ "vest": "^4.6.9",
230
+ "vite": "^4.2.0",
231
+ "vite-tsconfig-paths": "^4.0.7",
232
+ "vitest": "^0.29.3",
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
- "yarn lint --fix"
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,a,o){var i,l=r.validate(u,s,t);return l[0]?{values:{},errors:e.toNestError((i=l[0],i.failures().reduce(function(e,r){return(e[r.path.join(".")]={message:r.message,type:r.type})&&e},{})),o)}:(o.shouldUseNativeValidation&&e.validateFieldsNatively({},o),{values:l[1],errors:{}})}};
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) => (values, _, options) => {\n const result = validate(values, schema, resolverOptions);\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: result[1],\n errors: {},\n };\n };\n"],"names":["schema","resolverOptions","values","_","options","error","result","validate","errors","toNestError","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"0FAiBE,SAACA,EAAQC,mBAAqBC,EAAQC,EAAGC,GACvC,IAZsBC,EAYhBC,EAASC,WAASL,EAAQF,EAAQC,GAExC,OAAIK,EAAO,GACF,CACLJ,OAAQ,GACRM,OAAQC,eAjBUJ,EAiBmBC,EAAO,GAhBlDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,UACRO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,GACR,KAUqDR,KAIrDA,EAAQa,2BAA6BC,yBAAuB,GAAId,GAEzD,CACLF,OAAQI,EAAO,GACfE,OAAQ"}
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 function(u,a,n){var i,f=o(u,t,s);return f[0]?{values:{},errors:r((i=f[0],i.failures().reduce(function(r,e){return(r[e.path.join(".")]={message:e.message,type:e.type})&&r},{})),n)}:(n.shouldUseNativeValidation&&e({},n),{values:f[1],errors:{}})}};export{t as superstructResolver};
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 function(u,a,n){var i,f=o(u,t,s);return f[0]?{values:{},errors:r((i=f[0],i.failures().reduce(function(r,e){return(r[e.path.join(".")]={message:e.message,type:e.type})&&r},{})),n)}:(n.shouldUseNativeValidation&&e({},n),{values:f[1],errors:{}})}};export{t as superstructResolver};
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) => (values, _, options) => {\n const result = validate(values, schema, resolverOptions);\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: result[1],\n errors: {},\n };\n };\n"],"names":["superstructResolver","schema","resolverOptions","values","_","options","error","result","validate","errors","toNestError","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"qHAMA,IAUaA,EACX,SAACC,EAAQC,mBAAqBC,EAAQC,EAAGC,GACvC,IAZsBC,EAYhBC,EAASC,EAASL,EAAQF,EAAQC,GAExC,OAAIK,EAAO,GACF,CACLJ,OAAQ,GACRM,OAAQC,GAjBUJ,EAiBmBC,EAAO,GAhBlDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,UACRO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,GACR,KAUqDR,KAIrDA,EAAQa,2BAA6BC,EAAuB,GAAId,GAEzD,CACLF,OAAQI,EAAO,GACfE,OAAQ"}
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 function(t,u,i){var n,f=o.validate(t,e,s);return f[0]?{values:{},errors:r.toNestError((n=f[0],n.failures().reduce(function(e,r){return(e[r.path.join(".")]={message:r.message,type:r.type})&&e},{})),i)}:(i.shouldUseNativeValidation&&r.validateFieldsNatively({},i),{values:f[1],errors:{}})}}});
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) => (values, _, options) => {\n const result = validate(values, schema, resolverOptions);\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: result[1],\n errors: {},\n };\n };\n"],"names":["schema","resolverOptions","values","_","options","error","result","validate","errors","toNestError","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"4YAiBE,SAACA,EAAQC,mBAAqBC,EAAQC,EAAGC,GACvC,IAZsBC,EAYhBC,EAASC,WAASL,EAAQF,EAAQC,GAExC,OAAIK,EAAO,GACF,CACLJ,OAAQ,GACRM,OAAQC,eAjBUJ,EAiBmBC,EAAO,GAhBlDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,UACRO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,GACR,KAUqDR,KAIrDA,EAAQa,2BAA6BC,yBAAuB,GAAId,GAEzD,CACLF,OAAQI,EAAO,GACfE,OAAQ"}
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
- declare type Options = Parameters<typeof validate>[2];
4
- export declare type Resolver = <T extends Struct<any, any>>(schema: T, options?: Options) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
5
- export {};
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, act } from '@testing-library/react';
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 = jest.fn();
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 act(async () => {
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 act(async () => {
73
- user.type(screen.getByPlaceholderText(/username/i), 'jo');
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, act } from '@testing-library/react';
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 = jest.fn();
42
+ const handleSubmit = vi.fn();
43
43
  render(<TestComponent onSubmit={handleSubmit} />);
44
44
 
45
- expect(screen.queryAllByRole(/alert/i)).toHaveLength(0);
45
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
46
46
 
47
- await act(async () => {
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
- // Jest Snapshot v1, https://goo.gl/fbAQLP
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
- Object {
5
- "errors": Object {
6
- "birthYear": Object {
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": Object {
11
+ "email": {
12
12
  "message": "Expected a string matching \`/^[\\\\w-\\\\.]+@([\\\\w-]+\\\\.)+[\\\\w-]{2,4}$/\` but received \\"\\"",
13
- "ref": Object {
13
+ "ref": {
14
14
  "name": "email",
15
15
  },
16
16
  "type": "string",
17
17
  },
18
- "enabled": Object {
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": Array [
24
- Object {
25
- "id": Object {
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": Object {
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": Object {
37
+ "password": {
38
38
  "message": "Expected a string matching \`/^[a-zA-Z0-9]{3,30}/\` but received \\"___\\"",
39
- "ref": Object {
39
+ "ref": {
40
40
  "name": "password",
41
41
  },
42
42
  "type": "string",
43
43
  },
44
- "repeatPassword": Object {
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": Object {
49
+ "tags": {
50
50
  "message": "Expected an array value, but received: undefined",
51
51
  "ref": undefined,
52
52
  "type": "array",
53
53
  },
54
- "username": Object {
54
+ "username": {
55
55
  "message": "Expected a string, but received: undefined",
56
- "ref": Object {
56
+ "ref": {
57
57
  "name": "username",
58
58
  },
59
59
  "type": "string",
60
60
  },
61
61
  },
62
- "values": Object {},
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) => (values, _, options) => {
19
- const result = validate(values, schema, resolverOptions);
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
  };
@@ -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,
@@ -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,mBAAAA,IAAAA,EAAmB,aAC9BC,EAAQC,EAAGC,GACV,IAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,GACA,CACEC,OAAQJ,GAEVJ,IAGES,EA1BU,SAACD,EAAkBC,GACrC,gBADqCA,IAAAA,EAA4B,IAC1DD,EAAOE,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAID,EAAME,MAAM,KAMtB,OAJAH,EAAIE,EAAE,GAAGE,MAAM,IAAM,CACnBC,QAASH,EAAE,GAAGI,QAGTN,GACNF,GAiBoBS,CAAYd,GAEjC,OAAIC,GACFF,EAAQgB,2BACNC,yBAAuBX,EAAcN,GAEhC,CAAEF,OAAAA,EAAQO,OAAQ,KAGpB,CAAEP,OAAQ,GAAIO,OAAQa,cAAYZ,EAAcN"}
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.js.map
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,mBAAAA,IAAAA,EAAmB,aAC9BC,EAAQC,EAAGC,GACV,IAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,GACA,CACEC,OAAQJ,GAEVJ,IAGES,EA1BU,SAACD,EAAkBC,GACrC,gBADqCA,IAAAA,EAA4B,IAC1DD,EAAOE,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAID,EAAME,MAAM,KAMtB,OAJAH,EAAIE,EAAE,GAAGE,MAAM,IAAM,CACnBC,QAASH,EAAE,GAAGI,QAGTN,GACNF,GAiBoBS,CAAYd,GAEjC,OAAIC,GACFF,EAAQgB,2BACNC,EAAuBX,EAAcN,GAEhC,CAAEF,OAAAA,EAAQO,OAAQ,KAGpB,CAAEP,OAAQ,GAAIO,OAAQa,EAAYZ,EAAcN"}
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"}