@hookform/resolvers 3.7.0 → 3.8.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 (252) hide show
  1. package/README.md +69 -0
  2. package/ajv/dist/ajv.js.map +1 -1
  3. package/ajv/dist/ajv.modern.mjs.map +1 -1
  4. package/ajv/dist/ajv.module.js.map +1 -1
  5. package/ajv/dist/ajv.umd.js.map +1 -1
  6. package/ajv/dist/types.d.ts +1 -1
  7. package/ajv/src/__tests__/ajv.ts +7 -1
  8. package/ajv/src/ajv.ts +1 -1
  9. package/ajv/src/types.ts +1 -5
  10. package/arktype/dist/arktype.js +1 -1
  11. package/arktype/dist/arktype.js.map +1 -1
  12. package/arktype/dist/arktype.mjs +1 -1
  13. package/arktype/dist/arktype.modern.mjs +1 -1
  14. package/arktype/dist/arktype.modern.mjs.map +1 -1
  15. package/arktype/dist/arktype.module.js +1 -1
  16. package/arktype/dist/arktype.module.js.map +1 -1
  17. package/arktype/dist/arktype.umd.js +1 -1
  18. package/arktype/dist/arktype.umd.js.map +1 -1
  19. package/arktype/dist/types.d.ts +1 -1
  20. package/arktype/package.json +2 -1
  21. package/arktype/src/__tests__/Form-native-validation.tsx +5 -5
  22. package/arktype/src/__tests__/Form.tsx +2 -2
  23. package/arktype/src/__tests__/__fixtures__/data.ts +1 -1
  24. package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +29 -29
  25. package/arktype/src/__tests__/arktype.ts +1 -1
  26. package/arktype/src/arktype.ts +2 -2
  27. package/arktype/src/types.ts +1 -1
  28. package/class-validator/dist/class-validator.js.map +1 -1
  29. package/class-validator/dist/class-validator.modern.mjs.map +1 -1
  30. package/class-validator/dist/class-validator.module.js.map +1 -1
  31. package/class-validator/dist/class-validator.umd.js.map +1 -1
  32. package/class-validator/dist/types.d.ts +2 -2
  33. package/class-validator/src/__tests__/Form-native-validation.tsx +2 -2
  34. package/class-validator/src/__tests__/Form.tsx +2 -2
  35. package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +2 -2
  36. package/class-validator/src/__tests__/class-validator.ts +4 -4
  37. package/class-validator/src/class-validator.ts +2 -2
  38. package/class-validator/src/types.ts +2 -2
  39. package/computed-types/dist/computed-types.js.map +1 -1
  40. package/computed-types/dist/computed-types.modern.mjs.map +1 -1
  41. package/computed-types/dist/computed-types.module.js.map +1 -1
  42. package/computed-types/dist/computed-types.umd.js.map +1 -1
  43. package/computed-types/dist/types.d.ts +1 -1
  44. package/computed-types/src/__tests__/Form-native-validation.tsx +2 -2
  45. package/computed-types/src/__tests__/Form.tsx +2 -2
  46. package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
  47. package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +6 -6
  48. package/computed-types/src/__tests__/computed-types.ts +1 -1
  49. package/computed-types/src/computed-types.ts +2 -2
  50. package/computed-types/src/types.ts +1 -1
  51. package/dist/resolvers.js +1 -1
  52. package/dist/resolvers.js.map +1 -1
  53. package/dist/resolvers.mjs +1 -1
  54. package/dist/resolvers.mjs.map +1 -1
  55. package/dist/resolvers.module.js +1 -1
  56. package/dist/resolvers.module.js.map +1 -1
  57. package/dist/resolvers.umd.js +1 -1
  58. package/dist/resolvers.umd.js.map +1 -1
  59. package/dist/toNestErrors.d.ts +1 -6
  60. package/dist/validateFieldsNatively.d.ts +1 -1
  61. package/effect-ts/dist/effect-ts.js +1 -1
  62. package/effect-ts/dist/effect-ts.js.map +1 -1
  63. package/effect-ts/dist/effect-ts.mjs +1 -1
  64. package/effect-ts/dist/effect-ts.modern.mjs +1 -1
  65. package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
  66. package/effect-ts/dist/effect-ts.module.js +1 -1
  67. package/effect-ts/dist/effect-ts.module.js.map +1 -1
  68. package/effect-ts/dist/effect-ts.umd.js +1 -1
  69. package/effect-ts/dist/effect-ts.umd.js.map +1 -1
  70. package/effect-ts/src/__tests__/Form-native-validation.tsx +2 -2
  71. package/effect-ts/src/__tests__/Form.tsx +2 -2
  72. package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +2 -2
  73. package/effect-ts/src/__tests__/effect-ts.ts +1 -1
  74. package/effect-ts/src/effect-ts.ts +1 -1
  75. package/io-ts/dist/errorsToRecord.d.ts +0 -1
  76. package/io-ts/dist/io-ts.js +1 -1
  77. package/io-ts/dist/io-ts.js.map +1 -1
  78. package/io-ts/dist/io-ts.mjs +1 -1
  79. package/io-ts/dist/io-ts.modern.mjs +1 -1
  80. package/io-ts/dist/io-ts.modern.mjs.map +1 -1
  81. package/io-ts/dist/io-ts.module.js +1 -1
  82. package/io-ts/dist/io-ts.module.js.map +1 -1
  83. package/io-ts/dist/io-ts.umd.js +1 -1
  84. package/io-ts/dist/io-ts.umd.js.map +1 -1
  85. package/io-ts/src/__tests__/Form-native-validation.tsx +2 -2
  86. package/io-ts/src/__tests__/Form.tsx +2 -2
  87. package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +9 -9
  88. package/io-ts/src/__tests__/errorsToRecord.ts +29 -19
  89. package/io-ts/src/__tests__/io-ts.ts +1 -1
  90. package/io-ts/src/errorsToRecord.ts +19 -10
  91. package/io-ts/src/io-ts.ts +1 -1
  92. package/joi/dist/joi.js +1 -1
  93. package/joi/dist/joi.js.map +1 -1
  94. package/joi/dist/joi.mjs +1 -1
  95. package/joi/dist/joi.modern.mjs +1 -1
  96. package/joi/dist/joi.modern.mjs.map +1 -1
  97. package/joi/dist/joi.module.js +1 -1
  98. package/joi/dist/joi.module.js.map +1 -1
  99. package/joi/dist/joi.umd.js +1 -1
  100. package/joi/dist/joi.umd.js.map +1 -1
  101. package/joi/dist/types.d.ts +1 -1
  102. package/joi/src/__tests__/Form-native-validation.tsx +2 -2
  103. package/joi/src/__tests__/Form.tsx +2 -2
  104. package/joi/src/__tests__/__snapshots__/joi.ts.snap +56 -56
  105. package/joi/src/__tests__/joi.ts +1 -1
  106. package/joi/src/joi.ts +1 -1
  107. package/joi/src/types.ts +1 -5
  108. package/nope/dist/nope.js.map +1 -1
  109. package/nope/dist/nope.modern.mjs.map +1 -1
  110. package/nope/dist/nope.module.js.map +1 -1
  111. package/nope/dist/nope.umd.js.map +1 -1
  112. package/nope/dist/types.d.ts +1 -1
  113. package/nope/src/__tests__/Form-native-validation.tsx +2 -2
  114. package/nope/src/__tests__/Form.tsx +2 -2
  115. package/nope/src/__tests__/__fixtures__/data.ts +1 -1
  116. package/nope/src/__tests__/nope.ts +1 -1
  117. package/nope/src/nope.ts +1 -1
  118. package/nope/src/types.ts +2 -2
  119. package/package.json +54 -51
  120. package/superstruct/dist/superstruct.js.map +1 -1
  121. package/superstruct/dist/superstruct.modern.mjs.map +1 -1
  122. package/superstruct/dist/superstruct.module.js.map +1 -1
  123. package/superstruct/dist/superstruct.umd.js.map +1 -1
  124. package/superstruct/dist/types.d.ts +1 -1
  125. package/superstruct/src/__tests__/Form-native-validation.tsx +2 -2
  126. package/superstruct/src/__tests__/Form.tsx +2 -2
  127. package/superstruct/src/__tests__/__fixtures__/data.ts +8 -8
  128. package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +4 -4
  129. package/superstruct/src/__tests__/superstruct.ts +1 -1
  130. package/superstruct/src/superstruct.ts +1 -1
  131. package/superstruct/src/types.ts +1 -1
  132. package/typanion/dist/typanion.js.map +1 -1
  133. package/typanion/dist/typanion.modern.mjs.map +1 -1
  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 +1 -1
  137. package/typanion/src/__tests__/Form-native-validation.tsx +1 -1
  138. package/typanion/src/__tests__/Form.tsx +1 -1
  139. package/typanion/src/__tests__/__fixtures__/data.ts +12 -7
  140. package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +4 -4
  141. package/typanion/src/__tests__/typanion.ts +1 -1
  142. package/typanion/src/typanion.ts +1 -1
  143. package/typanion/src/types.ts +4 -4
  144. package/typebox/dist/typebox.js +1 -1
  145. package/typebox/dist/typebox.js.map +1 -1
  146. package/typebox/dist/typebox.mjs +1 -1
  147. package/typebox/dist/typebox.modern.mjs +1 -1
  148. package/typebox/dist/typebox.modern.mjs.map +1 -1
  149. package/typebox/dist/typebox.module.js +1 -1
  150. package/typebox/dist/typebox.module.js.map +1 -1
  151. package/typebox/dist/typebox.umd.js +1 -1
  152. package/typebox/dist/typebox.umd.js.map +1 -1
  153. package/typebox/dist/types.d.ts +3 -2
  154. package/typebox/src/__tests__/Form-compiler.tsx +57 -0
  155. package/typebox/src/__tests__/Form-native-validation-compiler.tsx +86 -0
  156. package/typebox/src/__tests__/Form-native-validation.tsx +4 -4
  157. package/typebox/src/__tests__/Form.tsx +3 -3
  158. package/typebox/src/__tests__/__fixtures__/data.ts +6 -2
  159. package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +188 -0
  160. package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +13 -13
  161. package/typebox/src/__tests__/typebox-compiler.ts +37 -0
  162. package/typebox/src/__tests__/typebox.ts +1 -1
  163. package/typebox/src/typebox.ts +8 -3
  164. package/typebox/src/types.ts +3 -2
  165. package/typeschema/dist/index.d.ts +2 -0
  166. package/typeschema/dist/types.d.ts +9 -0
  167. package/typeschema/dist/typeschema.d.ts +2 -0
  168. package/typeschema/dist/typeschema.js +2 -0
  169. package/typeschema/dist/typeschema.js.map +1 -0
  170. package/typeschema/dist/typeschema.mjs +2 -0
  171. package/typeschema/dist/typeschema.modern.mjs +2 -0
  172. package/typeschema/dist/typeschema.modern.mjs.map +1 -0
  173. package/typeschema/dist/typeschema.module.js +2 -0
  174. package/typeschema/dist/typeschema.module.js.map +1 -0
  175. package/typeschema/dist/typeschema.umd.js +2 -0
  176. package/typeschema/dist/typeschema.umd.js.map +1 -0
  177. package/typeschema/package.json +18 -0
  178. package/typeschema/src/__tests__/Form-native-validation.tsx +82 -0
  179. package/typeschema/src/__tests__/Form.tsx +53 -0
  180. package/typeschema/src/__tests__/__fixtures__/data.ts +88 -0
  181. package/typeschema/src/__tests__/__snapshots__/typeschema.ts.snap +225 -0
  182. package/typeschema/src/__tests__/typeschema.ts +70 -0
  183. package/typeschema/src/index.ts +2 -0
  184. package/typeschema/src/types.ts +18 -0
  185. package/typeschema/src/typeschema.ts +70 -0
  186. package/valibot/dist/types.d.ts +1 -1
  187. package/valibot/dist/valibot.js +1 -1
  188. package/valibot/dist/valibot.js.map +1 -1
  189. package/valibot/dist/valibot.mjs +1 -1
  190. package/valibot/dist/valibot.modern.mjs +1 -1
  191. package/valibot/dist/valibot.modern.mjs.map +1 -1
  192. package/valibot/dist/valibot.module.js +1 -1
  193. package/valibot/dist/valibot.module.js.map +1 -1
  194. package/valibot/dist/valibot.umd.js +1 -1
  195. package/valibot/dist/valibot.umd.js.map +1 -1
  196. package/valibot/src/__tests__/Form-native-validation.tsx +2 -2
  197. package/valibot/src/__tests__/Form.tsx +1 -1
  198. package/valibot/src/__tests__/valibot.ts +4 -4
  199. package/valibot/src/types.ts +1 -1
  200. package/valibot/src/valibot.ts +12 -6
  201. package/vest/dist/types.d.ts +2 -2
  202. package/vest/dist/vest.js.map +1 -1
  203. package/vest/dist/vest.modern.mjs.map +1 -1
  204. package/vest/dist/vest.module.js.map +1 -1
  205. package/vest/dist/vest.umd.js.map +1 -1
  206. package/vest/src/__tests__/Form-native-validation.tsx +1 -1
  207. package/vest/src/__tests__/Form.tsx +1 -1
  208. package/vest/src/__tests__/__snapshots__/vest.ts.snap +0 -6
  209. package/vest/src/__tests__/vest.ts +14 -8
  210. package/vest/src/types.ts +11 -4
  211. package/vest/src/vest.ts +1 -1
  212. package/vine/dist/types.d.ts +1 -1
  213. package/vine/dist/vine.js +1 -1
  214. package/vine/dist/vine.js.map +1 -1
  215. package/vine/dist/vine.mjs +1 -1
  216. package/vine/dist/vine.modern.mjs +1 -1
  217. package/vine/dist/vine.modern.mjs.map +1 -1
  218. package/vine/dist/vine.module.js +1 -1
  219. package/vine/dist/vine.module.js.map +1 -1
  220. package/vine/dist/vine.umd.js +1 -1
  221. package/vine/dist/vine.umd.js.map +1 -1
  222. package/vine/src/__tests__/Form-native-validation.tsx +9 -5
  223. package/vine/src/__tests__/Form.tsx +9 -5
  224. package/vine/src/__tests__/__fixtures__/data.ts +4 -2
  225. package/vine/src/__tests__/vine.ts +1 -1
  226. package/vine/src/types.ts +1 -1
  227. package/vine/src/vine.ts +10 -8
  228. package/yup/dist/yup.d.ts +1 -1
  229. package/yup/dist/yup.js.map +1 -1
  230. package/yup/dist/yup.modern.mjs.map +1 -1
  231. package/yup/dist/yup.module.js.map +1 -1
  232. package/yup/dist/yup.umd.js.map +1 -1
  233. package/yup/src/__tests__/Form-native-validation.tsx +1 -1
  234. package/yup/src/__tests__/Form.tsx +1 -1
  235. package/yup/src/__tests__/__snapshots__/yup.ts.snap +13 -13
  236. package/yup/src/__tests__/yup.ts +9 -7
  237. package/yup/src/yup.ts +2 -2
  238. package/zod/dist/types.d.ts +1 -1
  239. package/zod/dist/zod.js +1 -1
  240. package/zod/dist/zod.js.map +1 -1
  241. package/zod/dist/zod.mjs +1 -1
  242. package/zod/dist/zod.modern.mjs +1 -1
  243. package/zod/dist/zod.modern.mjs.map +1 -1
  244. package/zod/dist/zod.module.js +1 -1
  245. package/zod/dist/zod.module.js.map +1 -1
  246. package/zod/dist/zod.umd.js +1 -1
  247. package/zod/dist/zod.umd.js.map +1 -1
  248. package/zod/src/__tests__/Form-native-validation.tsx +2 -2
  249. package/zod/src/__tests__/Form.tsx +1 -1
  250. package/zod/src/__tests__/zod.ts +1 -1
  251. package/zod/src/types.ts +1 -1
  252. package/zod/src/zod.ts +4 -3
package/zod/dist/zod.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestErrors as o}from"@hookform/resolvers";var n=function(e,o){for(var n={};e.length;){var t=e[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u=t.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(r){return r.errors.forEach(function(r){return e.push(r)})}),o){var c=n[a].types,f=c&&c[t.code];n[a]=r(a,o,n,s,f?[].concat(f,t.message):t.message)}e.shift()}return n},t=function(r,t,s){return void 0===s&&(s={}),function(i,a,u){try{return Promise.resolve(function(o,n){try{var a=Promise.resolve(r["sync"===s.mode?"parse":"parseAsync"](i,t)).then(function(r){return u.shouldUseNativeValidation&&e({},u),{errors:{},values:s.raw?i:r}})}catch(r){return n(r)}return a&&a.then?a.then(void 0,n):a}(0,function(r){if(function(r){return Array.isArray(null==r?void 0:r.errors)}(r))return{values:{},errors:o(n(r.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}}};export{t as zodResolver};
1
+ import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";var n=function(r,e){for(var n={};r.length;){var t=r[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u=t.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(e){return e.errors.forEach(function(e){return r.push(e)})}),e){var c=n[a].types,f=c&&c[t.code];n[a]=o(a,e,n,s,f?[].concat(f,t.message):t.message)}r.shift()}return n},t=function(o,t,s){return void 0===s&&(s={}),function(i,a,u){try{return Promise.resolve(function(e,n){try{var a=Promise.resolve(o["sync"===s.mode?"parse":"parseAsync"](i,t)).then(function(e){return u.shouldUseNativeValidation&&r({},u),{errors:{},values:s.raw?i:e}})}catch(r){return n(r)}return a&&a.then?a.then(void 0,n):a}(0,function(r){if(function(r){return Array.isArray(null==r?void 0:r.errors)}(r))return{values:{},errors:e(n(r.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}}};export{t as zodResolver};
2
2
  //# sourceMappingURL=zod.module.js.map
@@ -1,2 +1,2 @@
1
- import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as o,toNestErrors as s}from"@hookform/resolvers";const e=(o,s)=>{const e={};for(;o.length;){const a=o[0],{code:t,message:n,path:i}=a,c=i.join(".");if(!e[c])if("unionErrors"in a){const r=a.unionErrors[0].errors[0];e[c]={message:r.message,type:r.code}}else e[c]={message:n,type:t};if("unionErrors"in a&&a.unionErrors.forEach(r=>r.errors.forEach(r=>o.push(r))),s){const o=e[c].types,n=o&&o[a.code];e[c]=r(c,s,e,t,n?[].concat(n,a.message):a.message)}o.shift()}return e},a=(r,a,t={})=>async(n,i,c)=>{try{const s=await r["sync"===t.mode?"parse":"parseAsync"](n,a);return c.shouldUseNativeValidation&&o({},c),{errors:{},values:t.raw?n:s}}catch(r){if((r=>Array.isArray(null==r?void 0:r.errors))(r))return{values:{},errors:s(e(r.errors,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw r}};export{a as zodResolver};
1
+ import{validateFieldsNatively as r,toNestErrors as o}from"@hookform/resolvers";import{appendErrors as s}from"react-hook-form";const e=(r,o)=>{const e={};for(;r.length;){const a=r[0],{code:t,message:n,path:i}=a,c=i.join(".");if(!e[c])if("unionErrors"in a){const r=a.unionErrors[0].errors[0];e[c]={message:r.message,type:r.code}}else e[c]={message:n,type:t};if("unionErrors"in a&&a.unionErrors.forEach(o=>o.errors.forEach(o=>r.push(o))),o){const r=e[c].types,n=r&&r[a.code];e[c]=s(c,o,e,t,n?[].concat(n,a.message):a.message)}r.shift()}return e},a=(s,a,t={})=>async(n,i,c)=>{try{const o=await s["sync"===t.mode?"parse":"parseAsync"](n,a);return c.shouldUseNativeValidation&&r({},c),{errors:{},values:t.raw?n:o}}catch(r){if((r=>Array.isArray(null==r?void 0:r.errors))(r))return{values:{},errors:o(e(r.errors,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw r}};export{a as zodResolver};
2
2
  //# sourceMappingURL=zod.modern.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod.modern.mjs","sources":["../src/zod.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { z, ZodError } from 'zod';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError => Array.isArray(error?.errors);\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","path","_path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","zodResolver","schema","schemaOptions","resolverOptions","async","values","_","options","data","mode","shouldUseNativeValidation","validateFieldsNatively","raw","Array","isArray","isZodError","toNestErrors","criteriaMode"],"mappings":"8HAKA,MAEMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,CAAA,EAC3C,KAAOF,EAAUG,QAAU,CACzB,MAAMC,EAAQJ,EAAU,IAClBK,KAAEA,EAAIC,QAAEA,EAAOC,KAAEA,GAASH,EAC1BI,EAAQD,EAAKE,KAAK,KAExB,IAAKP,EAAOM,GACV,GAAI,gBAAiBJ,EAAO,CAC1B,MAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOM,GAAS,CACdF,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAEpB,MACCH,EAAOM,GAAS,CAAEF,UAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAASH,GACzBA,EAAWR,OAAOW,QAASC,GAAMd,EAAUe,KAAKD,KAIhDb,EAA0B,CAC5B,MAAMe,EAAQd,EAAOM,GAAOQ,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOM,GAASU,EACdV,EACAP,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAUoB,OACX,CAED,OAAOlB,GAGImB,EACXA,CAACC,EAAQC,EAAeC,EAAkB,KAC1CC,MAAOC,EAAQC,EAAGC,KAChB,IACE,MAAMC,QAAaP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CJ,EAAQH,GAIV,OAFAK,EAAQG,2BAA6BC,EAAuB,CAAE,EAAEJ,GAEzD,CACL1B,OAAQ,CAAA,EACRwB,OAAQF,EAAgBS,IAAMP,EAASG,EAE1C,CAAC,MAAOzB,GACP,GAnEcA,IAAkC8B,MAAMC,QAAQ/B,MAAAA,OAAAA,EAAAA,EAAOF,QAmEjEkC,CAAWhC,GACb,MAAO,CACLsB,OAAQ,GACRxB,OAAQmC,EACNtC,EACEK,EAAMF,QACL0B,EAAQG,2BACkB,QAAzBH,EAAQU,cAEZV,IAKN,MAAMxB,CACP"}
1
+ {"version":3,"file":"zod.modern.mjs","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport { ZodError, z } from 'zod';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError =>\n Array.isArray(error?.errors);\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","path","_path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","zodResolver","schema","schemaOptions","resolverOptions","async","values","_","options","data","mode","shouldUseNativeValidation","validateFieldsNatively","raw","Array","isArray","isZodError","toNestErrors","criteriaMode"],"mappings":"8HAKA,MAGMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,CAAA,EAC3C,KAAOF,EAAUG,QAAU,CACzB,MAAMC,EAAQJ,EAAU,IAClBK,KAAEA,EAAIC,QAAEA,EAAOC,KAAEA,GAASH,EAC1BI,EAAQD,EAAKE,KAAK,KAExB,IAAKP,EAAOM,GACV,GAAI,gBAAiBJ,EAAO,CAC1B,MAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOM,GAAS,CACdF,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAErB,MACEH,EAAOM,GAAS,CAAEF,UAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAASH,GACzBA,EAAWR,OAAOW,QAASC,GAAMd,EAAUe,KAAKD,KAIhDb,EAA0B,CAC5B,MAAMe,EAAQd,EAAOM,GAAOQ,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOM,GAASU,EACdV,EACAP,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAUoB,OACZ,CAEA,OAAOlB,GAGImB,EACXA,CAACC,EAAQC,EAAeC,EAAkB,KAC1CC,MAAOC,EAAQC,EAAGC,KAChB,IACE,MAAMC,QAAaP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CJ,EAAQH,GAIV,OAFAK,EAAQG,2BAA6BC,EAAuB,CAAE,EAAEJ,GAEzD,CACL1B,OAAQ,CAAA,EACRwB,OAAQF,EAAgBS,IAAMP,EAASG,EAE3C,CAAE,MAAOzB,GACP,GApEcA,IAClB8B,MAAMC,QAAQ/B,MAAAA,OAAAA,EAAAA,EAAOF,QAmEbkC,CAAWhC,GACb,MAAO,CACLsB,OAAQ,GACRxB,OAAQmC,EACNtC,EACEK,EAAMF,QACL0B,EAAQG,2BACkB,QAAzBH,EAAQU,cAEZV,IAKN,MAAMxB,CACR"}
@@ -1,2 +1,2 @@
1
- import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestErrors as o}from"@hookform/resolvers";var n=function(e,o){for(var n={};e.length;){var t=e[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u=t.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(r){return r.errors.forEach(function(r){return e.push(r)})}),o){var c=n[a].types,f=c&&c[t.code];n[a]=r(a,o,n,s,f?[].concat(f,t.message):t.message)}e.shift()}return n},t=function(r,t,s){return void 0===s&&(s={}),function(i,a,u){try{return Promise.resolve(function(o,n){try{var a=Promise.resolve(r["sync"===s.mode?"parse":"parseAsync"](i,t)).then(function(r){return u.shouldUseNativeValidation&&e({},u),{errors:{},values:s.raw?i:r}})}catch(r){return n(r)}return a&&a.then?a.then(void 0,n):a}(0,function(r){if(function(r){return Array.isArray(null==r?void 0:r.errors)}(r))return{values:{},errors:o(n(r.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}}};export{t as zodResolver};
1
+ import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";var n=function(r,e){for(var n={};r.length;){var t=r[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u=t.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(e){return e.errors.forEach(function(e){return r.push(e)})}),e){var c=n[a].types,f=c&&c[t.code];n[a]=o(a,e,n,s,f?[].concat(f,t.message):t.message)}r.shift()}return n},t=function(o,t,s){return void 0===s&&(s={}),function(i,a,u){try{return Promise.resolve(function(e,n){try{var a=Promise.resolve(o["sync"===s.mode?"parse":"parseAsync"](i,t)).then(function(e){return u.shouldUseNativeValidation&&r({},u),{errors:{},values:s.raw?i:e}})}catch(r){return n(r)}return a&&a.then?a.then(void 0,n):a}(0,function(r){if(function(r){return Array.isArray(null==r?void 0:r.errors)}(r))return{values:{},errors:e(n(r.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw r}))}catch(r){return Promise.reject(r)}}};export{t as zodResolver};
2
2
  //# sourceMappingURL=zod.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod.module.js","sources":["../src/zod.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { z, ZodError } from 'zod';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError => Array.isArray(error?.errors);\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","_path","path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","zodResolver","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","mode","then","data","shouldUseNativeValidation","validateFieldsNatively","raw","_catch","Array","isArray","isZodError","toNestErrors","criteriaMode","reject"],"mappings":"8HAKA,IAEMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAUG,QAAU,CACzB,IAAMC,EAAQJ,EAAU,GAChBK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,KAAK,KAExB,IAAKP,EAAOK,GACV,GAAI,gBAAiBH,EAAO,CAC1B,IAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOK,GAAS,CACdD,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAEpB,MACCH,EAAOK,GAAS,CAAED,QAAAA,EAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAAQ,SAACH,GAAU,OACnCA,EAAWR,OAAOW,QAAQ,SAACC,GAAM,OAAAd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EACdX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAUoB,OACX,CAED,OAAOlB,CACT,EAEamB,EACX,SAACC,EAAQC,EAAeC,GACjBC,YADgC,IAAfD,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAFlBC,SAAAA,GAMN,OAFAL,EAAQM,2BAA6BC,EAAuB,CAAA,EAAIP,GAEzD,CACLzB,OAAQ,CAAiB,EACzBuB,OAAQD,EAAgBW,IAAMV,EAASO,EACvC,4DAXuBI,CACvB,EAWH,SAAQhC,GACP,GAnEa,SAACA,GAAkC,OAAAiC,MAAMC,QAAa,MAALlC,OAAK,EAALA,EAAOF,OAAO,CAmExEqC,CAAWnC,GACb,MAAO,CACLqB,OAAQ,CAAA,EACRvB,OAAQsC,EACNzC,EACEK,EAAMF,QACLyB,EAAQM,2BACkB,QAAzBN,EAAQc,cAEZd,IAKN,MAAMvB,CACP,GACH,CAAC,MAAAU,GAAA,OAAAc,QAAAc,OAAA5B,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"zod.module.js","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport { ZodError, z } from 'zod';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError =>\n Array.isArray(error?.errors);\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","_path","path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","zodResolver","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","mode","then","data","shouldUseNativeValidation","validateFieldsNatively","raw","_catch","Array","isArray","isZodError","toNestErrors","criteriaMode","reject"],"mappings":"8HAKA,IAGMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAUG,QAAU,CACzB,IAAMC,EAAQJ,EAAU,GAChBK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,KAAK,KAExB,IAAKP,EAAOK,GACV,GAAI,gBAAiBH,EAAO,CAC1B,IAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOK,GAAS,CACdD,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAErB,MACEH,EAAOK,GAAS,CAAED,QAAAA,EAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAAQ,SAACH,GAAU,OACnCA,EAAWR,OAAOW,QAAQ,SAACC,GAAM,OAAAd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EACdX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAUoB,OACZ,CAEA,OAAOlB,CACT,EAEamB,EACX,SAACC,EAAQC,EAAeC,GACjBC,YADgC,IAAfD,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAFlBC,SAAAA,GAMN,OAFAL,EAAQM,2BAA6BC,EAAuB,CAAA,EAAIP,GAEzD,CACLzB,OAAQ,CAAiB,EACzBuB,OAAQD,EAAgBW,IAAMV,EAASO,EACvC,4DAXuBI,CACvB,EAWH,SAAQhC,GACP,GApEa,SAACA,GAClB,OAAAiC,MAAMC,QAAa,MAALlC,OAAK,EAALA,EAAOF,OAAO,CAmEpBqC,CAAWnC,GACb,MAAO,CACLqB,OAAQ,CAAA,EACRvB,OAAQsC,EACNzC,EACEK,EAAMF,QACLyB,EAAQM,2BACkB,QAAzBN,EAAQc,cAEZd,IAKN,MAAMvB,CACR,GACF,CAAC,MAAAU,GAAA,OAAAc,QAAAc,OAAA5B,EAAA,CAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react-hook-form"),require("@hookform/resolvers")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers"],e):e((r||self).hookformResolversZod={},r.ReactHookForm,r.hookformResolvers)}(this,function(r,e,o){var n=function(r,o){for(var n={};r.length;){var s=r[0],t=s.code,i=s.message,a=s.path.join(".");if(!n[a])if("unionErrors"in s){var u=s.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:t};if("unionErrors"in s&&s.unionErrors.forEach(function(e){return e.errors.forEach(function(e){return r.push(e)})}),o){var f=n[a].types,c=f&&f[s.code];n[a]=e.appendErrors(a,o,n,t,c?[].concat(c,s.message):s.message)}r.shift()}return n};r.zodResolver=function(r,e,s){return void 0===s&&(s={}),function(t,i,a){try{return Promise.resolve(function(n,i){try{var u=Promise.resolve(r["sync"===s.mode?"parse":"parseAsync"](t,e)).then(function(r){return a.shouldUseNativeValidation&&o.validateFieldsNatively({},a),{errors:{},values:s.raw?t:r}})}catch(r){return i(r)}return u&&u.then?u.then(void 0,i):u}(0,function(r){if(function(r){return Array.isArray(null==r?void 0:r.errors)}(r))return{values:{},errors:o.toNestErrors(n(r.errors,!a.shouldUseNativeValidation&&"all"===a.criteriaMode),a)};throw r}))}catch(r){return Promise.reject(r)}}}});
1
+ !function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@hookform/resolvers"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form"],e):e((r||self).hookformResolversZod={},r.hookformResolvers,r.ReactHookForm)}(this,function(r,e,o){var n=function(r,e){for(var n={};r.length;){var s=r[0],t=s.code,i=s.message,a=s.path.join(".");if(!n[a])if("unionErrors"in s){var u=s.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code}}else n[a]={message:i,type:t};if("unionErrors"in s&&s.unionErrors.forEach(function(e){return e.errors.forEach(function(e){return r.push(e)})}),e){var f=n[a].types,c=f&&f[s.code];n[a]=o.appendErrors(a,e,n,t,c?[].concat(c,s.message):s.message)}r.shift()}return n};r.zodResolver=function(r,o,s){return void 0===s&&(s={}),function(t,i,a){try{return Promise.resolve(function(n,i){try{var u=Promise.resolve(r["sync"===s.mode?"parse":"parseAsync"](t,o)).then(function(r){return a.shouldUseNativeValidation&&e.validateFieldsNatively({},a),{errors:{},values:s.raw?t:r}})}catch(r){return i(r)}return u&&u.then?u.then(void 0,i):u}(0,function(r){if(function(r){return Array.isArray(null==r?void 0:r.errors)}(r))return{values:{},errors:e.toNestErrors(n(r.errors,!a.shouldUseNativeValidation&&"all"===a.criteriaMode),a)};throw r}))}catch(r){return Promise.reject(r)}}}});
2
2
  //# sourceMappingURL=zod.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod.umd.js","sources":["../src/zod.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { z, ZodError } from 'zod';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError => Array.isArray(error?.errors);\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","_path","path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","mode","then","data","shouldUseNativeValidation","validateFieldsNatively","raw","_catch","Array","isArray","isZodError","toNestErrors","criteriaMode","reject"],"mappings":"wXAKA,IAEMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAUG,QAAU,CACzB,IAAMC,EAAQJ,EAAU,GAChBK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,KAAK,KAExB,IAAKP,EAAOK,GACV,GAAI,gBAAiBH,EAAO,CAC1B,IAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOK,GAAS,CACdD,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAEpB,MACCH,EAAOK,GAAS,CAAED,QAAAA,EAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAAQ,SAACH,GAAU,OACnCA,EAAWR,OAAOW,QAAQ,SAACC,GAAM,OAAAd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EAAAA,aACdX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAUoB,OACX,CAED,OAAOlB,CACT,gBAGE,SAACmB,EAAQC,EAAeC,GACjBC,YADgC,IAAfD,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAFlBC,SAAAA,GAMN,OAFAL,EAAQM,2BAA6BC,yBAAuB,CAAA,EAAIP,GAEzD,CACLxB,OAAQ,CAAiB,EACzBsB,OAAQD,EAAgBW,IAAMV,EAASO,EACvC,4DAXuBI,CACvB,EAWH,SAAQ/B,GACP,GAnEa,SAACA,GAAkC,OAAAgC,MAAMC,QAAa,MAALjC,OAAK,EAALA,EAAOF,OAAO,CAmExEoC,CAAWlC,GACb,MAAO,CACLoB,OAAQ,CAAA,EACRtB,OAAQqC,EAAYA,aAClBxC,EACEK,EAAMF,QACLwB,EAAQM,2BACkB,QAAzBN,EAAQc,cAEZd,IAKN,MAAMtB,CACP,GACH,CAAC,MAAAU,GAAA,OAAAa,QAAAc,OAAA3B,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"zod.umd.js","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport { ZodError, z } from 'zod';\nimport type { Resolver } from './types';\n\nconst isZodError = (error: any): error is ZodError =>\n Array.isArray(error?.errors);\n\nconst parseErrorSchema = (\n zodErrors: z.ZodIssue[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; zodErrors.length; ) {\n const error = zodErrors[0];\n const { code, message, path } = error;\n const _path = path.join('.');\n\n if (!errors[_path]) {\n if ('unionErrors' in error) {\n const unionError = error.unionErrors[0].errors[0];\n\n errors[_path] = {\n message: unionError.message,\n type: unionError.code,\n };\n } else {\n errors[_path] = { message, type: code };\n }\n }\n\n if ('unionErrors' in error) {\n error.unionErrors.forEach((unionError) =>\n unionError.errors.forEach((e) => zodErrors.push(e)),\n );\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.code];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n code,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n zodErrors.shift();\n }\n\n return errors;\n};\n\nexport const zodResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema[\n resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'\n ](values, schemaOptions);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : data,\n };\n } catch (error: any) {\n if (isZodError(error)) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","zodErrors","validateAllFieldCriteria","errors","length","error","code","message","_path","path","join","unionError","unionErrors","type","forEach","e","push","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","mode","then","data","shouldUseNativeValidation","validateFieldsNatively","raw","_catch","Array","isArray","isZodError","toNestErrors","criteriaMode","reject"],"mappings":"wXAKA,IAGMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAUG,QAAU,CACzB,IAAMC,EAAQJ,EAAU,GAChBK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,KAAK,KAExB,IAAKP,EAAOK,GACV,GAAI,gBAAiBH,EAAO,CAC1B,IAAMM,EAAaN,EAAMO,YAAY,GAAGT,OAAO,GAE/CA,EAAOK,GAAS,CACdD,QAASI,EAAWJ,QACpBM,KAAMF,EAAWL,KAErB,MACEH,EAAOK,GAAS,CAAED,QAAAA,EAASM,KAAMP,GAUrC,GANI,gBAAiBD,GACnBA,EAAMO,YAAYE,QAAQ,SAACH,GAAU,OACnCA,EAAWR,OAAOW,QAAQ,SAACC,GAAM,OAAAd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EAAAA,aACdX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAUoB,OACZ,CAEA,OAAOlB,CACT,gBAGE,SAACmB,EAAQC,EAAeC,GACjBC,YADgC,IAAfD,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAFlBC,SAAAA,GAMN,OAFAL,EAAQM,2BAA6BC,yBAAuB,CAAA,EAAIP,GAEzD,CACLxB,OAAQ,CAAiB,EACzBsB,OAAQD,EAAgBW,IAAMV,EAASO,EACvC,4DAXuBI,CACvB,EAWH,SAAQ/B,GACP,GApEa,SAACA,GAClB,OAAAgC,MAAMC,QAAa,MAALjC,OAAK,EAALA,EAAOF,OAAO,CAmEpBoC,CAAWlC,GACb,MAAO,CACLoB,OAAQ,CAAA,EACRtB,OAAQqC,EAAYA,aAClBxC,EACEK,EAAMF,QACLwB,EAAQM,2BACkB,QAAzBN,EAAQc,cAEZd,IAKN,MAAMtB,CACR,GACF,CAAC,MAAAU,GAAA,OAAAa,QAAAc,OAAA3B,EAAA,CAAA,CAAA"}
@@ -1,7 +1,7 @@
1
- import React from 'react';
2
- import { useForm } from 'react-hook-form';
3
1
  import { render, screen } from '@testing-library/react';
4
2
  import user from '@testing-library/user-event';
3
+ import React from 'react';
4
+ import { useForm } from 'react-hook-form';
5
5
  import { z } from 'zod';
6
6
  import { zodResolver } from '..';
7
7
 
@@ -1,6 +1,6 @@
1
- import React from 'react';
2
1
  import { render, screen } from '@testing-library/react';
3
2
  import user from '@testing-library/user-event';
3
+ import React from 'react';
4
4
  import { useForm } from 'react-hook-form';
5
5
  import { z } from 'zod';
6
6
  import { zodResolver } from '..';
@@ -1,5 +1,5 @@
1
1
  import { zodResolver } from '..';
2
- import { schema, validData, invalidData, fields } from './__fixtures__/data';
2
+ import { fields, invalidData, schema, validData } from './__fixtures__/data';
3
3
 
4
4
  const shouldUseNativeValidation = false;
5
5
 
package/zod/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
1
+ import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
2
2
  import { z } from 'zod';
3
3
 
4
4
  export type Resolver = <T extends z.Schema<any, any>>(
package/zod/src/zod.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';
2
- import { z, ZodError } from 'zod';
3
1
  import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
2
+ import { FieldError, FieldErrors, appendErrors } from 'react-hook-form';
3
+ import { ZodError, z } from 'zod';
4
4
  import type { Resolver } from './types';
5
5
 
6
- const isZodError = (error: any): error is ZodError => Array.isArray(error?.errors);
6
+ const isZodError = (error: any): error is ZodError =>
7
+ Array.isArray(error?.errors);
7
8
 
8
9
  const parseErrorSchema = (
9
10
  zodErrors: z.ZodIssue[],