@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.
Files changed (226) hide show
  1. package/README.md +51 -5
  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__/io-ts.ts +1 -1
  84. package/joi/dist/index.d.ts +2 -2
  85. package/joi/dist/joi.d.ts +2 -2
  86. package/joi/dist/joi.js.map +1 -1
  87. package/joi/dist/{joi.modern.js → joi.modern.mjs} +1 -1
  88. package/joi/dist/joi.modern.mjs.map +1 -0
  89. package/joi/dist/joi.module.js.map +1 -1
  90. package/joi/dist/joi.umd.js.map +1 -1
  91. package/joi/dist/types.d.ts +5 -5
  92. package/joi/src/__tests__/Form-native-validation.tsx +5 -9
  93. package/joi/src/__tests__/Form.tsx +4 -6
  94. package/joi/src/__tests__/__snapshots__/joi.ts.snap +87 -87
  95. package/joi/src/__tests__/joi.ts +8 -8
  96. package/nope/dist/index.d.ts +2 -2
  97. package/nope/dist/nope.d.ts +2 -2
  98. package/nope/dist/nope.js.map +1 -1
  99. package/nope/dist/{nope.modern.js → nope.modern.mjs} +1 -1
  100. package/nope/dist/nope.modern.mjs.map +1 -0
  101. package/nope/dist/nope.module.js.map +1 -1
  102. package/nope/dist/nope.umd.js.map +1 -1
  103. package/nope/dist/types.d.ts +9 -9
  104. package/nope/src/__tests__/Form-native-validation.tsx +5 -9
  105. package/nope/src/__tests__/Form.tsx +4 -6
  106. package/nope/src/__tests__/__snapshots__/nope.ts.snap +15 -15
  107. package/nope/src/__tests__/nope.ts +1 -1
  108. package/package.json +74 -44
  109. package/superstruct/dist/index.d.ts +2 -2
  110. package/superstruct/dist/superstruct.d.ts +2 -2
  111. package/superstruct/dist/superstruct.js +1 -1
  112. package/superstruct/dist/superstruct.js.map +1 -1
  113. package/superstruct/dist/superstruct.mjs +1 -1
  114. package/superstruct/dist/superstruct.modern.mjs +2 -0
  115. package/superstruct/dist/superstruct.modern.mjs.map +1 -0
  116. package/superstruct/dist/superstruct.module.js +1 -1
  117. package/superstruct/dist/superstruct.module.js.map +1 -1
  118. package/superstruct/dist/superstruct.umd.js +1 -1
  119. package/superstruct/dist/superstruct.umd.js.map +1 -1
  120. package/superstruct/dist/types.d.ts +11 -5
  121. package/superstruct/src/__tests__/Form-native-validation.tsx +5 -9
  122. package/superstruct/src/__tests__/Form.tsx +4 -6
  123. package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +19 -19
  124. package/superstruct/src/__tests__/superstruct.ts +13 -0
  125. package/superstruct/src/superstruct.ts +4 -3
  126. package/superstruct/src/types.ts +8 -5
  127. package/typanion/dist/index.d.ts +2 -2
  128. package/typanion/dist/typanion.d.ts +2 -2
  129. package/typanion/dist/typanion.js.map +1 -1
  130. package/typanion/dist/{typanion.modern.js → typanion.modern.mjs} +1 -1
  131. package/typanion/dist/typanion.modern.mjs.map +1 -0
  132. package/typanion/dist/typanion.module.js.map +1 -1
  133. package/typanion/dist/typanion.umd.js.map +1 -1
  134. package/typanion/dist/types.d.ts +9 -9
  135. package/typanion/src/__tests__/Form-native-validation.tsx +7 -10
  136. package/typanion/src/__tests__/Form.tsx +9 -7
  137. package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +22 -22
  138. package/typanion/src/__tests__/typanion.ts +11 -7
  139. package/typanion/src/typanion.ts +1 -1
  140. package/typebox/dist/index.d.ts +2 -0
  141. package/typebox/dist/typebox.d.ts +2 -0
  142. package/typebox/dist/typebox.js +2 -0
  143. package/typebox/dist/typebox.js.map +1 -0
  144. package/typebox/dist/typebox.mjs +2 -0
  145. package/typebox/dist/typebox.modern.mjs +2 -0
  146. package/typebox/dist/typebox.modern.mjs.map +1 -0
  147. package/typebox/dist/typebox.module.js +2 -0
  148. package/typebox/dist/typebox.module.js.map +1 -0
  149. package/typebox/dist/typebox.umd.js +2 -0
  150. package/typebox/dist/typebox.umd.js.map +1 -0
  151. package/typebox/dist/types.d.ts +3 -0
  152. package/typebox/package.json +18 -0
  153. package/typebox/src/__tests__/Form-native-validation.tsx +83 -0
  154. package/typebox/src/__tests__/Form.tsx +54 -0
  155. package/typebox/src/__tests__/__fixtures__/data.ts +84 -0
  156. package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +190 -0
  157. package/typebox/src/__tests__/typebox.ts +34 -0
  158. package/typebox/src/index.ts +2 -0
  159. package/typebox/src/typebox.ts +64 -0
  160. package/typebox/src/types.ts +10 -0
  161. package/vest/dist/index.d.ts +2 -2
  162. package/vest/dist/types.d.ts +8 -8
  163. package/vest/dist/vest.d.ts +2 -2
  164. package/vest/dist/vest.js.map +1 -1
  165. package/vest/dist/{vest.modern.js → vest.modern.mjs} +1 -1
  166. package/vest/dist/vest.modern.mjs.map +1 -0
  167. package/vest/dist/vest.module.js.map +1 -1
  168. package/vest/dist/vest.umd.js.map +1 -1
  169. package/vest/src/__tests__/Form-native-validation.tsx +5 -9
  170. package/vest/src/__tests__/Form.tsx +6 -10
  171. package/vest/src/__tests__/__snapshots__/vest.ts.snap +47 -47
  172. package/yup/dist/index.d.ts +2 -2
  173. package/yup/dist/types.d.ts +15 -9
  174. package/yup/dist/yup.d.ts +2 -2
  175. package/yup/dist/yup.js +1 -1
  176. package/yup/dist/yup.js.map +1 -1
  177. package/yup/dist/yup.mjs +1 -1
  178. package/yup/dist/yup.modern.mjs +2 -0
  179. package/yup/dist/yup.modern.mjs.map +1 -0
  180. package/yup/dist/yup.module.js +1 -1
  181. package/yup/dist/yup.module.js.map +1 -1
  182. package/yup/dist/yup.umd.js +1 -1
  183. package/yup/dist/yup.umd.js.map +1 -1
  184. package/yup/src/__tests__/Form-native-validation.tsx +5 -9
  185. package/yup/src/__tests__/Form.tsx +4 -6
  186. package/yup/src/__tests__/__fixtures__/data.ts +2 -3
  187. package/yup/src/__tests__/__snapshots__/yup.ts.snap +100 -87
  188. package/yup/src/__tests__/yup.ts +49 -18
  189. package/yup/src/types.ts +14 -11
  190. package/yup/src/yup.ts +1 -1
  191. package/zod/dist/index.d.ts +2 -2
  192. package/zod/dist/types.d.ts +13 -13
  193. package/zod/dist/zod.d.ts +2 -2
  194. package/zod/dist/zod.js +1 -1
  195. package/zod/dist/zod.js.map +1 -1
  196. package/zod/dist/zod.mjs +1 -1
  197. package/zod/dist/zod.modern.mjs +2 -0
  198. package/zod/dist/zod.modern.mjs.map +1 -0
  199. package/zod/dist/zod.module.js +1 -1
  200. package/zod/dist/zod.module.js.map +1 -1
  201. package/zod/dist/zod.umd.js +1 -1
  202. package/zod/dist/zod.umd.js.map +1 -1
  203. package/zod/src/__tests__/Form-native-validation.tsx +5 -9
  204. package/zod/src/__tests__/Form.tsx +4 -6
  205. package/zod/src/__tests__/__snapshots__/zod.ts.snap +120 -120
  206. package/zod/src/__tests__/zod.ts +19 -7
  207. package/zod/src/types.ts +2 -6
  208. package/zod/src/zod.ts +27 -27
  209. package/ajv/dist/ajv.modern.js +0 -8
  210. package/ajv/dist/ajv.modern.js.map +0 -1
  211. package/class-validator/dist/class-validator.modern.js +0 -2
  212. package/class-validator/dist/class-validator.modern.js.map +0 -1
  213. package/computed-types/dist/computed-types.modern.js +0 -2
  214. package/computed-types/dist/computed-types.modern.js.map +0 -1
  215. package/io-ts/dist/io-ts.modern.js +0 -2
  216. package/io-ts/dist/io-ts.modern.js.map +0 -1
  217. package/joi/dist/joi.modern.js.map +0 -1
  218. package/nope/dist/nope.modern.js.map +0 -1
  219. package/superstruct/dist/superstruct.modern.js +0 -2
  220. package/superstruct/dist/superstruct.modern.js.map +0 -1
  221. package/typanion/dist/typanion.modern.js.map +0 -1
  222. package/vest/dist/vest.modern.js.map +0 -1
  223. package/yup/dist/yup.modern.js +0 -2
  224. package/yup/dist/yup.modern.js.map +0 -1
  225. package/zod/dist/zod.modern.js +0 -2
  226. package/zod/dist/zod.modern.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"class-validator.umd.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { validate, validateSync, ValidationError } from 'class-validator';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ValidationError[],\n validateAllFieldCriteria: boolean,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return errors.reduce((acc, error) => {\n const _path = path ? `${path}.${error.property}` : error.property;\n\n if (error.constraints) {\n const key = Object.keys(error.constraints)[0];\n acc[_path] = {\n type: key,\n message: error.constraints[key],\n };\n\n if (validateAllFieldCriteria && acc[_path]) {\n Object.assign(acc[_path], { types: error.constraints });\n }\n }\n\n if (error.children && error.children.length) {\n parseErrors(error.children, validateAllFieldCriteria, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const classValidatorResolver: Resolver =\n (schema, schemaOptions = {}, resolverOptions = {}) =>\n async (values, _, options) => {\n const user = plainToClass(schema, values);\n\n const rawErrors = await (resolverOptions.mode === 'sync'\n ? validateSync\n : validate)(user, schemaOptions);\n\n if (rawErrors.length) {\n return {\n values: {},\n errors: toNestError(\n parseErrors(\n rawErrors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","validateAllFieldCriteria","parsedErrors","path","reduce","acc","error","_path","property","constraints","key","Object","keys","type","message","assign","types","children","length","schema","schemaOptions","resolverOptions","values","_","options","user","plainToClass","mode","validateSync","validate","rawErrors","toNestError","shouldUseNativeValidation","criteriaMode","validateFieldsNatively"],"mappings":"0cAMA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,EACAC,GAEA,gBAHAD,IAAAA,EAA4B,aAC5BC,IAAAA,EAAO,IAEAH,EAAOI,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAQJ,EAAUA,MAAQG,EAAME,SAAaF,EAAME,SAEzD,GAAIF,EAAMG,YAAa,CACrB,IAAMC,EAAMC,OAAOC,KAAKN,EAAMG,aAAa,GAC3CJ,EAAIE,GAAS,CACXM,KAAMH,EACNI,QAASR,EAAMG,YAAYC,IAGzBT,GAA4BI,EAAIE,IAClCI,OAAOI,OAAOV,EAAIE,GAAQ,CAAES,MAAOV,EAAMG,cAQ7C,OAJIH,EAAMW,UAAYX,EAAMW,SAASC,QACnCnB,EAAYO,EAAMW,SAAUhB,EAA0BI,EAAKE,GAGtDF,GACNH,6BAIH,SAACiB,EAAQC,EAAoBC,mBAApBD,IAAAA,EAAgB,aAAIC,IAAAA,EAAkB,aACxCC,EAAQC,EAAGC,OAChB,IAAMC,EAAOC,eAAaP,EAAQG,2BAEgB,SAAzBD,EAAgBM,KACrCC,eACAC,YAAUJ,EAAML,kBAFdU,GAIN,OAAIA,EAAUZ,OACL,CACLI,OAAQ,GACRtB,OAAQ+B,cACNhC,EACE+B,GACCN,EAAQQ,2BACkB,QAAzBR,EAAQS,cAEZT,KAKNA,EAAQQ,2BAA6BE,yBAAuB,GAAIV,GAEzD,CAAEF,OAAAA,EAAQtB,OAAQ,OAxB3B"}
1
+ {"version":3,"file":"class-validator.umd.js","sources":["../src/class-validator.ts"],"sourcesContent":["import { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport { plainToClass } from 'class-transformer';\nimport { validate, validateSync, ValidationError } from 'class-validator';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ValidationError[],\n validateAllFieldCriteria: boolean,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return errors.reduce((acc, error) => {\n const _path = path ? `${path}.${error.property}` : error.property;\n\n if (error.constraints) {\n const key = Object.keys(error.constraints)[0];\n acc[_path] = {\n type: key,\n message: error.constraints[key],\n };\n\n const _e = acc[_path];\n if (validateAllFieldCriteria && _e) {\n Object.assign(_e, { types: error.constraints });\n }\n }\n\n if (error.children && error.children.length) {\n parseErrors(error.children, validateAllFieldCriteria, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const classValidatorResolver: Resolver =\n (schema, schemaOptions = {}, resolverOptions = {}) =>\n async (values, _, options) => {\n const { transformer, validator } = schemaOptions;\n const data = plainToClass(schema, values, transformer);\n\n const rawErrors = await (resolverOptions.mode === 'sync'\n ? validateSync\n : validate)(data, validator);\n\n if (rawErrors.length) {\n return {\n values: {},\n errors: toNestError(\n parseErrors(\n rawErrors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","validateAllFieldCriteria","parsedErrors","path","reduce","acc","error","_path","property","constraints","key","Object","keys","type","message","_e","assign","types","children","length","schema","schemaOptions","resolverOptions","values","_","options","validator","data","plainToClass","transformer","Promise","resolve","mode","validateSync","validate","then","rawErrors","toNestError","shouldUseNativeValidation","criteriaMode","validateFieldsNatively","e","reject"],"mappings":"0cAMA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAA,YAC5BC,IAAAA,EAAO,IAEAH,EAAOI,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAQJ,EAAUA,MAAQG,EAAME,SAAaF,EAAME,SAEzD,GAAIF,EAAMG,YAAa,CACrB,IAAMC,EAAMC,OAAOC,KAAKN,EAAMG,aAAa,GAC3CJ,EAAIE,GAAS,CACXM,KAAMH,EACNI,QAASR,EAAMG,YAAYC,IAG7B,IAAMK,EAAKV,EAAIE,GACXN,GAA4Bc,GAC9BJ,OAAOK,OAAOD,EAAI,CAAEE,MAAOX,EAAMG,aAEpC,CAMD,OAJIH,EAAMY,UAAYZ,EAAMY,SAASC,QACnCpB,EAAYO,EAAMY,SAAUjB,EAA0BI,EAAKE,GAGtDF,CACT,EAAGH,EACL,2BAGE,SAACkB,EAAQC,EAAoBC,eAAP,IAAbD,IAAAA,EAAgB,CAAE,QAAEC,IAAAA,IAAAA,EAAkB,CAAE,YAC1CC,EAAQC,EAAGC,GAAW,IAC3B,IAAqBC,EAAcL,EAAdK,UACfC,EAAOC,EAAYA,aAACR,EAAQG,EADCF,EAA3BQ,aAC+C,OAAAC,QAAAC,SAEL,SAAzBT,EAAgBU,KACrCC,eACAC,EAAAA,UAAUP,EAAMD,IAAUS,KAFxBC,SAAAA,GAIN,OAAIA,EAAUjB,OACL,CACLI,OAAQ,GACRvB,OAAQqC,EAAWA,YACjBtC,EACEqC,GACCX,EAAQa,2BACkB,QAAzBb,EAAQc,cAEZd,KAKNA,EAAQa,2BAA6BE,EAAAA,uBAAuB,CAAA,EAAIf,GAEzD,CAAEF,OAAAA,EAAQvB,OAAQ,IAAK,EAChC,CAAC,MAAAyC,GAAA,OAAAX,QAAAY,OAAAD,EAAA,CAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- export * from './class-validator';
2
- export * from './types';
1
+ export * from './class-validator';
2
+ export * from './types';
@@ -1,9 +1,12 @@
1
- import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
2
- import { ValidatorOptions } from 'class-validator';
3
- import { ClassConstructor } from 'class-transformer';
4
- export declare type Resolver = <T extends {
5
- [_: string]: any;
6
- }>(schema: ClassConstructor<T>, schemaOptions?: ValidatorOptions, resolverOptions?: {
7
- mode?: 'async' | 'sync';
8
- rawValues?: boolean;
9
- }) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
1
+ import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
2
+ import { ValidatorOptions } from 'class-validator';
3
+ import { ClassConstructor, ClassTransformOptions } from 'class-transformer';
4
+ export type Resolver = <T extends {
5
+ [_: string]: any;
6
+ }>(schema: ClassConstructor<T>, schemaOptions?: {
7
+ validator?: ValidatorOptions;
8
+ transformer?: ClassTransformOptions;
9
+ }, resolverOptions?: {
10
+ mode?: 'async' | 'sync';
11
+ rawValues?: boolean;
12
+ }) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
@@ -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 { SubmitHandler, useForm } from 'react-hook-form';
5
5
  import { classValidatorResolver } from '..';
@@ -35,7 +35,7 @@ function TestComponent({ onSubmit }: Props) {
35
35
  }
36
36
 
37
37
  test("form's native validation with Class Validator", async () => {
38
- const handleSubmit = jest.fn();
38
+ const handleSubmit = vi.fn();
39
39
  render(<TestComponent onSubmit={handleSubmit} />);
40
40
 
41
41
  // username
@@ -52,9 +52,7 @@ test("form's native validation with Class Validator", async () => {
52
52
  expect(passwordField.validity.valid).toBe(true);
53
53
  expect(passwordField.validationMessage).toBe('');
54
54
 
55
- await act(async () => {
56
- user.click(screen.getByText(/submit/i));
57
- });
55
+ await user.click(screen.getByText(/submit/i));
58
56
 
59
57
  // username
60
58
  usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
@@ -66,10 +64,8 @@ test("form's native validation with Class Validator", async () => {
66
64
  expect(passwordField.validity.valid).toBe(false);
67
65
  expect(passwordField.validationMessage).toBe('password should not be empty');
68
66
 
69
- await act(async () => {
70
- user.type(screen.getByPlaceholderText(/username/i), 'joe');
71
- user.type(screen.getByPlaceholderText(/password/i), 'password');
72
- });
67
+ await user.type(screen.getByPlaceholderText(/username/i), 'joe');
68
+ await user.type(screen.getByPlaceholderText(/password/i), 'password');
73
69
 
74
70
  // username
75
71
  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 { SubmitHandler, useForm } from 'react-hook-form';
5
5
  import { classValidatorResolver } from '..';
@@ -40,14 +40,12 @@ function TestComponent({ onSubmit }: Props) {
40
40
  }
41
41
 
42
42
  test("form's validation with Class Validator and TypeScript's integration", async () => {
43
- const handleSubmit = jest.fn();
43
+ const handleSubmit = vi.fn();
44
44
  render(<TestComponent onSubmit={handleSubmit} />);
45
45
 
46
- expect(screen.queryAllByRole(/alert/i)).toHaveLength(0);
46
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
47
47
 
48
- await act(async () => {
49
- user.click(screen.getByText(/submit/i));
50
- });
48
+ await user.click(screen.getByText(/submit/i));
51
49
 
52
50
  expect(screen.getByText(/username should not be empty/i)).toBeInTheDocument();
53
51
  expect(screen.getByText(/password should not be empty/i)).toBeInTheDocument();
@@ -1,207 +1,242 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`classValidatorResolver should return a single error from classValidatorResolver when validation fails 1`] = `
4
- Object {
5
- "errors": Object {
6
- "birthYear": Object {
3
+ exports[`classValidatorResolver > should return a single error from classValidatorResolver when validation fails 1`] = `
4
+ {
5
+ "errors": {
6
+ "birthYear": {
7
7
  "message": "birthYear must not be greater than 2013",
8
8
  "ref": undefined,
9
9
  "type": "max",
10
10
  },
11
- "email": Object {
11
+ "email": {
12
12
  "message": "email must be an email",
13
- "ref": Object {
13
+ "ref": {
14
14
  "name": "email",
15
15
  },
16
16
  "type": "isEmail",
17
17
  },
18
- "like": Array [
19
- Object {
20
- "name": Object {
18
+ "like": [
19
+ {
20
+ "name": {
21
21
  "message": "name must be longer than or equal to 4 characters",
22
22
  "ref": undefined,
23
23
  "type": "isLength",
24
24
  },
25
25
  },
26
26
  ],
27
- "password": Object {
27
+ "password": {
28
28
  "message": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
29
- "ref": Object {
29
+ "ref": {
30
30
  "name": "password",
31
31
  },
32
32
  "type": "matches",
33
33
  },
34
- "username": Object {
34
+ "username": {
35
35
  "message": "username must be longer than or equal to 3 characters",
36
- "ref": Object {
36
+ "ref": {
37
37
  "name": "username",
38
38
  },
39
39
  "type": "isLength",
40
40
  },
41
41
  },
42
- "values": Object {},
42
+ "values": {},
43
43
  }
44
44
  `;
45
45
 
46
- exports[`classValidatorResolver should return a single error from classValidatorResolver with \`mode: sync\` when validation fails 1`] = `
47
- Object {
48
- "errors": Object {
49
- "birthYear": Object {
46
+ exports[`classValidatorResolver > should return a single error from classValidatorResolver with \`mode: sync\` when validation fails 1`] = `
47
+ {
48
+ "errors": {
49
+ "birthYear": {
50
50
  "message": "birthYear must not be greater than 2013",
51
51
  "ref": undefined,
52
52
  "type": "max",
53
53
  },
54
- "email": Object {
54
+ "email": {
55
55
  "message": "email must be an email",
56
- "ref": Object {
56
+ "ref": {
57
57
  "name": "email",
58
58
  },
59
59
  "type": "isEmail",
60
60
  },
61
- "like": Array [
62
- Object {
63
- "name": Object {
61
+ "like": [
62
+ {
63
+ "name": {
64
64
  "message": "name must be longer than or equal to 4 characters",
65
65
  "ref": undefined,
66
66
  "type": "isLength",
67
67
  },
68
68
  },
69
69
  ],
70
- "password": Object {
70
+ "password": {
71
71
  "message": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
72
- "ref": Object {
72
+ "ref": {
73
73
  "name": "password",
74
74
  },
75
75
  "type": "matches",
76
76
  },
77
- "username": Object {
77
+ "username": {
78
78
  "message": "username must be longer than or equal to 3 characters",
79
- "ref": Object {
79
+ "ref": {
80
80
  "name": "username",
81
81
  },
82
82
  "type": "isLength",
83
83
  },
84
84
  },
85
- "values": Object {},
85
+ "values": {},
86
86
  }
87
87
  `;
88
88
 
89
- exports[`classValidatorResolver should return all the errors from classValidatorResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
90
- Object {
91
- "errors": Object {
92
- "birthYear": Object {
89
+ exports[`classValidatorResolver > should return all the errors from classValidatorResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
90
+ {
91
+ "errors": {
92
+ "birthYear": {
93
93
  "message": "birthYear must not be greater than 2013",
94
94
  "ref": undefined,
95
95
  "type": "max",
96
- "types": Object {
96
+ "types": {
97
97
  "max": "birthYear must not be greater than 2013",
98
98
  "min": "birthYear must not be less than 1900",
99
99
  },
100
100
  },
101
- "email": Object {
101
+ "email": {
102
102
  "message": "email must be an email",
103
- "ref": Object {
103
+ "ref": {
104
104
  "name": "email",
105
105
  },
106
106
  "type": "isEmail",
107
- "types": Object {
107
+ "types": {
108
108
  "isEmail": "email must be an email",
109
109
  },
110
110
  },
111
- "like": Array [
112
- Object {
113
- "name": Object {
111
+ "like": [
112
+ {
113
+ "name": {
114
114
  "message": "name must be longer than or equal to 4 characters",
115
115
  "ref": undefined,
116
116
  "type": "isLength",
117
- "types": Object {
117
+ "types": {
118
118
  "isLength": "name must be longer than or equal to 4 characters",
119
119
  },
120
120
  },
121
121
  },
122
122
  ],
123
- "password": Object {
123
+ "password": {
124
124
  "message": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
125
- "ref": Object {
125
+ "ref": {
126
126
  "name": "password",
127
127
  },
128
128
  "type": "matches",
129
- "types": Object {
129
+ "types": {
130
130
  "matches": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
131
131
  },
132
132
  },
133
- "username": Object {
133
+ "username": {
134
134
  "message": "username must be longer than or equal to 3 characters",
135
- "ref": Object {
135
+ "ref": {
136
136
  "name": "username",
137
137
  },
138
138
  "type": "isLength",
139
- "types": Object {
139
+ "types": {
140
140
  "isLength": "username must be longer than or equal to 3 characters",
141
141
  "matches": "username must match /^\\\\w+$/ regular expression",
142
142
  },
143
143
  },
144
144
  },
145
- "values": Object {},
145
+ "values": {},
146
146
  }
147
147
  `;
148
148
 
149
- exports[`classValidatorResolver should return all the errors from classValidatorResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
150
- Object {
151
- "errors": Object {
152
- "birthYear": Object {
149
+ exports[`classValidatorResolver > should return all the errors from classValidatorResolver when validation fails with \`validateAllFieldCriteria\` set to true and \`mode: sync\` 1`] = `
150
+ {
151
+ "errors": {
152
+ "birthYear": {
153
153
  "message": "birthYear must not be greater than 2013",
154
154
  "ref": undefined,
155
155
  "type": "max",
156
- "types": Object {
156
+ "types": {
157
157
  "max": "birthYear must not be greater than 2013",
158
158
  "min": "birthYear must not be less than 1900",
159
159
  },
160
160
  },
161
- "email": Object {
161
+ "email": {
162
162
  "message": "email must be an email",
163
- "ref": Object {
163
+ "ref": {
164
164
  "name": "email",
165
165
  },
166
166
  "type": "isEmail",
167
- "types": Object {
167
+ "types": {
168
168
  "isEmail": "email must be an email",
169
169
  },
170
170
  },
171
- "like": Array [
172
- Object {
173
- "name": Object {
171
+ "like": [
172
+ {
173
+ "name": {
174
174
  "message": "name must be longer than or equal to 4 characters",
175
175
  "ref": undefined,
176
176
  "type": "isLength",
177
- "types": Object {
177
+ "types": {
178
178
  "isLength": "name must be longer than or equal to 4 characters",
179
179
  },
180
180
  },
181
181
  },
182
182
  ],
183
- "password": Object {
183
+ "password": {
184
184
  "message": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
185
- "ref": Object {
185
+ "ref": {
186
186
  "name": "password",
187
187
  },
188
188
  "type": "matches",
189
- "types": Object {
189
+ "types": {
190
190
  "matches": "password must match /^[a-zA-Z0-9]{3,30}/ regular expression",
191
191
  },
192
192
  },
193
- "username": Object {
193
+ "username": {
194
194
  "message": "username must be longer than or equal to 3 characters",
195
- "ref": Object {
195
+ "ref": {
196
196
  "name": "username",
197
197
  },
198
198
  "type": "isLength",
199
- "types": Object {
199
+ "types": {
200
200
  "isLength": "username must be longer than or equal to 3 characters",
201
201
  "matches": "username must match /^\\\\w+$/ regular expression",
202
202
  },
203
203
  },
204
204
  },
205
- "values": Object {},
205
+ "values": {},
206
+ }
207
+ `;
208
+
209
+ exports[`validate data with transformer option 1`] = `
210
+ {
211
+ "errors": {
212
+ "random": {
213
+ "message": "All fields must be defined.",
214
+ "ref": undefined,
215
+ "type": "isDefined",
216
+ "types": {
217
+ "isDefined": "All fields must be defined.",
218
+ "isNumber": "Must be a number",
219
+ "max": "Cannot be greater than 255",
220
+ "min": "Cannot be lower than 0",
221
+ },
222
+ },
223
+ },
224
+ "values": {},
225
+ }
226
+ `;
227
+
228
+ exports[`validate data with validator option 1`] = `
229
+ {
230
+ "errors": {
231
+ "random": {
232
+ "message": "All fields must be defined.",
233
+ "ref": undefined,
234
+ "type": "isDefined",
235
+ "types": {
236
+ "isDefined": "All fields must be defined.",
237
+ },
238
+ },
239
+ },
240
+ "values": {},
206
241
  }
207
242
  `;
@@ -2,13 +2,15 @@
2
2
  import { classValidatorResolver } from '..';
3
3
  import { Schema, validData, fields, invalidData } from './__fixtures__/data';
4
4
  import * as classValidator from 'class-validator';
5
+ import { Expose, Type } from 'class-transformer';
6
+ import { IsDefined, IsNumber, Max, Min } from 'class-validator';
5
7
 
6
8
  const shouldUseNativeValidation = false;
7
9
 
8
10
  describe('classValidatorResolver', () => {
9
11
  it('should return values from classValidatorResolver when validation pass', async () => {
10
- const schemaSpy = jest.spyOn(classValidator, 'validate');
11
- const schemaSyncSpy = jest.spyOn(classValidator, 'validateSync');
12
+ const schemaSpy = vi.spyOn(classValidator, 'validate');
13
+ const schemaSyncSpy = vi.spyOn(classValidator, 'validateSync');
12
14
 
13
15
  const result = await classValidatorResolver(Schema)(validData, undefined, {
14
16
  fields,
@@ -21,8 +23,8 @@ describe('classValidatorResolver', () => {
21
23
  });
22
24
 
23
25
  it('should return values from classValidatorResolver with `mode: sync` when validation pass', async () => {
24
- const validateSyncSpy = jest.spyOn(classValidator, 'validateSync');
25
- const validateSpy = jest.spyOn(classValidator, 'validate');
26
+ const validateSyncSpy = vi.spyOn(classValidator, 'validateSync');
27
+ const validateSpy = vi.spyOn(classValidator, 'validate');
26
28
 
27
29
  const result = await classValidatorResolver(Schema, undefined, {
28
30
  mode: 'sync',
@@ -47,8 +49,8 @@ describe('classValidatorResolver', () => {
47
49
  });
48
50
 
49
51
  it('should return a single error from classValidatorResolver with `mode: sync` when validation fails', async () => {
50
- const validateSyncSpy = jest.spyOn(classValidator, 'validateSync');
51
- const validateSpy = jest.spyOn(classValidator, 'validate');
52
+ const validateSyncSpy = vi.spyOn(classValidator, 'validateSync');
53
+ const validateSpy = vi.spyOn(classValidator, 'validate');
52
54
 
53
55
  const result = await classValidatorResolver(Schema, undefined, {
54
56
  mode: 'sync',
@@ -85,3 +87,61 @@ describe('classValidatorResolver', () => {
85
87
  expect(result).toMatchSnapshot();
86
88
  });
87
89
  });
90
+
91
+ it('validate data with transformer option', async () => {
92
+ class SchemaTest {
93
+ @Expose({ groups: ['find', 'create', 'update'] })
94
+ @Type(() => Number)
95
+ @IsDefined({
96
+ message: `All fields must be defined.`,
97
+ groups: ['publish'],
98
+ })
99
+ @IsNumber({}, { message: `Must be a number`, always: true })
100
+ @Min(0, { message: `Cannot be lower than 0`, always: true })
101
+ @Max(255, { message: `Cannot be greater than 255`, always: true })
102
+ random: number;
103
+ }
104
+
105
+ const result = await classValidatorResolver(
106
+ SchemaTest,
107
+ { transformer: { groups: ['update'] } },
108
+ {
109
+ mode: 'sync',
110
+ },
111
+ )(invalidData, undefined, {
112
+ fields,
113
+ criteriaMode: 'all',
114
+ shouldUseNativeValidation,
115
+ });
116
+
117
+ expect(result).toMatchSnapshot();
118
+ });
119
+
120
+ it('validate data with validator option', async () => {
121
+ class SchemaTest {
122
+ @Expose({ groups: ['find', 'create', 'update'] })
123
+ @Type(() => Number)
124
+ @IsDefined({
125
+ message: `All fields must be defined.`,
126
+ groups: ['publish'],
127
+ })
128
+ @IsNumber({}, { message: `Must be a number`, always: true })
129
+ @Min(0, { message: `Cannot be lower than 0`, always: true })
130
+ @Max(255, { message: `Cannot be greater than 255`, always: true })
131
+ random: number;
132
+ }
133
+
134
+ const result = await classValidatorResolver(
135
+ SchemaTest,
136
+ { validator: { stopAtFirstError: true } },
137
+ {
138
+ mode: 'sync',
139
+ },
140
+ )(invalidData, undefined, {
141
+ fields,
142
+ criteriaMode: 'all',
143
+ shouldUseNativeValidation,
144
+ });
145
+
146
+ expect(result).toMatchSnapshot();
147
+ });
@@ -20,8 +20,9 @@ const parseErrors = (
20
20
  message: error.constraints[key],
21
21
  };
22
22
 
23
- if (validateAllFieldCriteria && acc[_path]) {
24
- Object.assign(acc[_path], { types: error.constraints });
23
+ const _e = acc[_path];
24
+ if (validateAllFieldCriteria && _e) {
25
+ Object.assign(_e, { types: error.constraints });
25
26
  }
26
27
  }
27
28
 
@@ -36,11 +37,12 @@ const parseErrors = (
36
37
  export const classValidatorResolver: Resolver =
37
38
  (schema, schemaOptions = {}, resolverOptions = {}) =>
38
39
  async (values, _, options) => {
39
- const user = plainToClass(schema, values);
40
+ const { transformer, validator } = schemaOptions;
41
+ const data = plainToClass(schema, values, transformer);
40
42
 
41
43
  const rawErrors = await (resolverOptions.mode === 'sync'
42
44
  ? validateSync
43
- : validate)(user, schemaOptions);
45
+ : validate)(data, validator);
44
46
 
45
47
  if (rawErrors.length) {
46
48
  return {
@@ -1,15 +1,14 @@
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 { ValidatorOptions } from 'class-validator';
7
- import { ClassConstructor } from 'class-transformer';
3
+ import { ClassConstructor, ClassTransformOptions } from 'class-transformer';
8
4
 
9
5
  export type Resolver = <T extends { [_: string]: any }>(
10
6
  schema: ClassConstructor<T>,
11
- schemaOptions?: ValidatorOptions,
12
- resolverOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; },
7
+ schemaOptions?: {
8
+ validator?: ValidatorOptions;
9
+ transformer?: ClassTransformOptions;
10
+ },
11
+ resolverOptions?: { mode?: 'async' | 'sync'; rawValues?: boolean },
13
12
  ) => <TFieldValues extends FieldValues, TContext>(
14
13
  values: TFieldValues,
15
14
  context: TContext | undefined,
@@ -1,2 +1,2 @@
1
- import type { Resolver } from './types';
2
- export declare const computedTypesResolver: Resolver;
1
+ import type { Resolver } from './types';
2
+ export declare const computedTypesResolver: Resolver;
@@ -1,2 +1,2 @@
1
- var r=require("@hookform/resolvers");exports.computedTypesResolver=function(e){return function(t,o,n){try{return Promise.resolve(function(o,s){try{var u=Promise.resolve(e(t)).then(function(e){return n.shouldUseNativeValidation&&r.validateFieldsNatively({},n),{errors:{},values:e}})}catch(r){return s(r)}return u&&u.then?u.then(void 0,s):u}(0,function(e){return{values:{},errors:r.toNestError((t=e,(t.errors||[]).reduce(function(r,e){return r[e.path.join(".")]={type:e.error.name,message:e.error.message},r},{})),n)};var t}))}catch(r){return Promise.reject(r)}}};
1
+ var r=require("@hookform/resolvers");exports.computedTypesResolver=function(e){return function(t,o,n){try{return Promise.resolve(function(o,s){try{var u=Promise.resolve(e(t)).then(function(e){return n.shouldUseNativeValidation&&r.validateFieldsNatively({},n),{errors:{},values:e}})}catch(r){return s(r)}return u&&u.then?u.then(void 0,s):u}(0,function(e){if(function(r){return null!=r.errors}(e))return{values:{},errors:r.toNestError((t=e,(t.errors||[]).reduce(function(r,e){return r[e.path.join(".")]={type:e.error.name,message:e.error.message},r},{})),n)};var t;throw e}))}catch(r){return Promise.reject(r)}}};
2
2
  //# sourceMappingURL=computed-types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"computed-types.js","sources":["../src/computed-types.ts"],"sourcesContent":["import type { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ValidationError } from 'computed-types';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (computedTypesError: ValidationError) => {\n const parsedErrors: FieldErrors = {};\n return (computedTypesError.errors || []).reduce((acc, error) => {\n acc[error.path.join('.')] = {\n type: error.error.name,\n message: error.error.message,\n };\n\n return acc;\n }, parsedErrors);\n};\n\nexport const computedTypesResolver: Resolver =\n (schema) => async (values, _, options) => {\n try {\n const data = await schema(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: data,\n };\n } catch (error: any) {\n return {\n values: {},\n errors: toNestError(parseErrorSchema(error), options),\n };\n }\n };\n"],"names":["schema","values","_","options","data","shouldUseNativeValidation","validateFieldsNatively","errors","error","toNestError","computedTypesError","reduce","acc","path","join","type","name","message"],"mappings":"mEAkBE,SAACA,mBAAkBC,EAAQC,EAAGC,sEAEPH,EAAOC,kBAApBG,GAIN,OAFAD,EAAQE,2BAA6BC,yBAAuB,GAAIH,GAEzD,CACLI,OAAQ,GACRN,OAAQG,0EAEHI,GACP,MAAO,CACLP,OAAQ,GACRM,OAAQE,eA1BUC,EA0BmBF,GAxBnCE,EAAmBH,QAAU,IAAII,OAAO,SAACC,EAAKJ,GAMpD,OALAI,EAAIJ,EAAMK,KAAKC,KAAK,MAAQ,CAC1BC,KAAMP,EAAMA,MAAMQ,KAClBC,QAAST,EAAMA,MAAMS,SAGhBL,GAPyB,KAyBiBT,IA1B5B,IAACO,KAaxB"}
1
+ {"version":3,"file":"computed-types.js","sources":["../src/computed-types.ts"],"sourcesContent":["import type { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport type { ValidationError } from 'computed-types';\n\nconst isValidationError = (error: any): error is ValidationError =>\n error.errors != null;\n\nconst parseErrorSchema = (computedTypesError: ValidationError) => {\n const parsedErrors: FieldErrors = {};\n return (computedTypesError.errors || []).reduce((acc, error) => {\n acc[error.path.join('.')] = {\n type: error.error.name,\n message: error.error.message,\n };\n\n return acc;\n }, parsedErrors);\n};\n\nexport const computedTypesResolver: Resolver =\n (schema) => async (values, _, options) => {\n try {\n const data = await schema(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: data,\n };\n } catch (error: any) {\n if (isValidationError(error)) {\n return {\n values: {},\n errors: toNestError(parseErrorSchema(error), options),\n };\n }\n\n throw error;\n }\n };\n"],"names":["schema","values","_","options","Promise","resolve","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","_catch","error","isValidationError","toNestError","computedTypesError","reduce","acc","path","join","type","name","message","e","reject"],"mappings":"mEAqBE,SAACA,GAAM,OAAA,SAAYC,EAAQC,EAAGC,GAAO,IAAIC,OAAAA,QAAAC,gCACnCD,QAAAC,QACiBL,EAAOC,IAAOK,KAA3BC,SAAAA,GAIN,OAFAJ,EAAQK,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIN,GAEzD,CACLO,OAAQ,CAAE,EACVT,OAAQM,EACR,4DATmCI,CACnC,EASH,SAAQC,GACP,GA3BoB,SAACA,GAAU,OACnB,MAAhBA,EAAMF,MAAc,CA0BZG,CAAkBD,GACpB,MAAO,CACLX,OAAQ,CAAA,EACRS,OAAQI,EAAAA,aA3BQC,EA2BqBH,GAzBrCG,EAAmBL,QAAU,IAAIM,OAAO,SAACC,EAAKL,GAMpD,OALAK,EAAIL,EAAMM,KAAKC,KAAK,MAAQ,CAC1BC,KAAMR,EAAMA,MAAMS,KAClBC,QAASV,EAAMA,MAAMU,SAGhBL,CACT,EARkC,CAAA,IA0BmBd,IA3B9B,IAACY,EA+BpB,MAAMH,CACP,GACH,CAAC,MAAAW,GAAAnB,OAAAA,QAAAoB,OAAAD,EAAA,CAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- import{validateFieldsNatively as r,toNestError as e}from"@hookform/resolvers";var t=function(t){return function(o,n,s){try{return Promise.resolve(function(e,n){try{var u=Promise.resolve(t(o)).then(function(e){return s.shouldUseNativeValidation&&r({},s),{errors:{},values:e}})}catch(r){return n(r)}return u&&u.then?u.then(void 0,n):u}(0,function(r){return{values:{},errors:e((t=r,(t.errors||[]).reduce(function(r,e){return r[e.path.join(".")]={type:e.error.name,message:e.error.message},r},{})),s)};var t}))}catch(r){return Promise.reject(r)}}};export{t as computedTypesResolver};
1
+ import{validateFieldsNatively as r,toNestError as e}from"@hookform/resolvers";var t=function(t){return function(n,o,u){try{return Promise.resolve(function(e,o){try{var s=Promise.resolve(t(n)).then(function(e){return u.shouldUseNativeValidation&&r({},u),{errors:{},values:e}})}catch(r){return o(r)}return s&&s.then?s.then(void 0,o):s}(0,function(r){if(function(r){return null!=r.errors}(r))return{values:{},errors:e((t=r,(t.errors||[]).reduce(function(r,e){return r[e.path.join(".")]={type:e.error.name,message:e.error.message},r},{})),u)};var t;throw r}))}catch(r){return Promise.reject(r)}}};export{t as computedTypesResolver};
2
2
  //# sourceMappingURL=computed-types.module.js.map
@@ -0,0 +1,2 @@
1
+ import{validateFieldsNatively as r,toNestError as e}from"@hookform/resolvers";const o=o=>async(s,a,t)=>{try{const e=await o(s);return t.shouldUseNativeValidation&&r({},t),{errors:{},values:e}}catch(r){if((r=>null!=r.errors)(r))return{values:{},errors:e((n=r,(n.errors||[]).reduce((r,e)=>(r[e.path.join(".")]={type:e.error.name,message:e.error.message},r),{})),t)};throw r}var n};export{o as computedTypesResolver};
2
+ //# sourceMappingURL=computed-types.modern.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computed-types.modern.mjs","sources":["../src/computed-types.ts"],"sourcesContent":["import type { FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport type { ValidationError } from 'computed-types';\n\nconst isValidationError = (error: any): error is ValidationError =>\n error.errors != null;\n\nconst parseErrorSchema = (computedTypesError: ValidationError) => {\n const parsedErrors: FieldErrors = {};\n return (computedTypesError.errors || []).reduce((acc, error) => {\n acc[error.path.join('.')] = {\n type: error.error.name,\n message: error.error.message,\n };\n\n return acc;\n }, parsedErrors);\n};\n\nexport const computedTypesResolver: Resolver =\n (schema) => async (values, _, options) => {\n try {\n const data = await schema(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: data,\n };\n } catch (error: any) {\n if (isValidationError(error)) {\n return {\n values: {},\n errors: toNestError(parseErrorSchema(error), options),\n };\n }\n\n throw error;\n }\n };\n"],"names":["computedTypesResolver","schema","async","values","_","options","data","shouldUseNativeValidation","validateFieldsNatively","errors","error","isValidationError","toNestError","computedTypesError","reduce","acc","path","join","type","name","message"],"mappings":"8EAKA,MAeaA,EACVC,GAAWC,MAAOC,EAAQC,EAAGC,KAC5B,IACE,MAAMC,QAAaL,EAAOE,GAI1B,OAFAE,EAAQE,2BAA6BC,EAAuB,CAAE,EAAEH,GAEzD,CACLI,OAAQ,CAAA,EACRN,OAAQG,EAEX,CAAC,MAAOI,GACP,GA3BqBA,IACT,MAAhBA,EAAMD,OA0BEE,CAAkBD,GACpB,MAAO,CACLP,OAAQ,CAAA,EACRM,OAAQG,GA3BQC,EA2BqBH,GAzBrCG,EAAmBJ,QAAU,IAAIK,OAAO,CAACC,EAAKL,KACpDK,EAAIL,EAAMM,KAAKC,KAAK,MAAQ,CAC1BC,KAAMR,EAAMA,MAAMS,KAClBC,QAASV,EAAMA,MAAMU,SAGhBL,GAPyB,KA0BmBV,IAIjD,MAAMK,CACP,CAhCqBG,KAgCrB"}
@@ -1,2 +1,2 @@
1
- import{validateFieldsNatively as r,toNestError as e}from"@hookform/resolvers";var t=function(t){return function(o,n,s){try{return Promise.resolve(function(e,n){try{var u=Promise.resolve(t(o)).then(function(e){return s.shouldUseNativeValidation&&r({},s),{errors:{},values:e}})}catch(r){return n(r)}return u&&u.then?u.then(void 0,n):u}(0,function(r){return{values:{},errors:e((t=r,(t.errors||[]).reduce(function(r,e){return r[e.path.join(".")]={type:e.error.name,message:e.error.message},r},{})),s)};var t}))}catch(r){return Promise.reject(r)}}};export{t as computedTypesResolver};
1
+ import{validateFieldsNatively as r,toNestError as e}from"@hookform/resolvers";var t=function(t){return function(n,o,u){try{return Promise.resolve(function(e,o){try{var s=Promise.resolve(t(n)).then(function(e){return u.shouldUseNativeValidation&&r({},u),{errors:{},values:e}})}catch(r){return o(r)}return s&&s.then?s.then(void 0,o):s}(0,function(r){if(function(r){return null!=r.errors}(r))return{values:{},errors:e((t=r,(t.errors||[]).reduce(function(r,e){return r[e.path.join(".")]={type:e.error.name,message:e.error.message},r},{})),u)};var t;throw r}))}catch(r){return Promise.reject(r)}}};export{t as computedTypesResolver};
2
2
  //# sourceMappingURL=computed-types.module.js.map