@hookform/resolvers 3.7.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -0
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.modern.mjs.map +1 -1
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/types.d.ts +1 -1
- package/ajv/src/__tests__/ajv.ts +7 -1
- package/ajv/src/ajv.ts +1 -1
- package/ajv/src/types.ts +1 -5
- package/arktype/dist/arktype.js +1 -1
- package/arktype/dist/arktype.js.map +1 -1
- package/arktype/dist/arktype.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs.map +1 -1
- package/arktype/dist/arktype.module.js +1 -1
- package/arktype/dist/arktype.module.js.map +1 -1
- package/arktype/dist/arktype.umd.js +1 -1
- package/arktype/dist/arktype.umd.js.map +1 -1
- package/arktype/dist/types.d.ts +1 -1
- package/arktype/package.json +2 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +5 -5
- package/arktype/src/__tests__/Form.tsx +2 -2
- package/arktype/src/__tests__/__fixtures__/data.ts +1 -1
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +29 -29
- package/arktype/src/__tests__/arktype.ts +1 -1
- package/arktype/src/arktype.ts +2 -2
- package/arktype/src/types.ts +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.modern.mjs.map +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/types.d.ts +2 -2
- package/class-validator/src/__tests__/Form-native-validation.tsx +2 -2
- package/class-validator/src/__tests__/Form.tsx +2 -2
- package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +2 -2
- package/class-validator/src/__tests__/class-validator.ts +4 -4
- package/class-validator/src/class-validator.ts +2 -2
- package/class-validator/src/types.ts +2 -2
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.modern.mjs.map +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/dist/types.d.ts +1 -1
- package/computed-types/src/__tests__/Form-native-validation.tsx +2 -2
- package/computed-types/src/__tests__/Form.tsx +2 -2
- package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +6 -6
- package/computed-types/src/__tests__/computed-types.ts +1 -1
- package/computed-types/src/computed-types.ts +2 -2
- package/computed-types/src/types.ts +1 -1
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +2 -2
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/dist/toNestErrors.d.ts +1 -6
- package/dist/validateFieldsNatively.d.ts +1 -1
- package/effect-ts/dist/effect-ts.js +1 -1
- package/effect-ts/dist/effect-ts.js.map +1 -1
- package/effect-ts/dist/effect-ts.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
- package/effect-ts/dist/effect-ts.module.js +1 -1
- package/effect-ts/dist/effect-ts.module.js.map +1 -1
- package/effect-ts/dist/effect-ts.umd.js +1 -1
- package/effect-ts/dist/effect-ts.umd.js.map +1 -1
- package/effect-ts/src/__tests__/Form-native-validation.tsx +2 -2
- package/effect-ts/src/__tests__/Form.tsx +2 -2
- package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +2 -2
- package/effect-ts/src/__tests__/effect-ts.ts +1 -1
- package/effect-ts/src/effect-ts.ts +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.d.ts +4 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.mjs +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js.map +1 -0
- package/fluentvalidation-ts/dist/index.d.ts +1 -0
- package/fluentvalidation-ts/package.json +18 -0
- package/fluentvalidation-ts/src/__tests__/Form-native-validation.tsx +88 -0
- package/fluentvalidation-ts/src/__tests__/Form.tsx +63 -0
- package/fluentvalidation-ts/src/__tests__/__fixtures__/data.ts +121 -0
- package/fluentvalidation-ts/src/__tests__/__snapshots__/fluentvalidation-ts.ts.snap +129 -0
- package/fluentvalidation-ts/src/__tests__/fluentvalidation-ts.ts +113 -0
- package/fluentvalidation-ts/src/fluentvalidation-ts.ts +102 -0
- package/fluentvalidation-ts/src/index.ts +1 -0
- package/io-ts/dist/errorsToRecord.d.ts +0 -1
- package/io-ts/dist/io-ts.js +1 -1
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs.map +1 -1
- package/io-ts/dist/io-ts.module.js +1 -1
- package/io-ts/dist/io-ts.module.js.map +1 -1
- package/io-ts/dist/io-ts.umd.js +1 -1
- package/io-ts/dist/io-ts.umd.js.map +1 -1
- package/io-ts/src/__tests__/Form-native-validation.tsx +2 -2
- package/io-ts/src/__tests__/Form.tsx +2 -2
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +9 -9
- package/io-ts/src/__tests__/errorsToRecord.ts +29 -19
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/io-ts/src/errorsToRecord.ts +19 -10
- package/io-ts/src/io-ts.ts +1 -1
- package/joi/dist/joi.js +1 -1
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/joi.mjs +1 -1
- package/joi/dist/joi.modern.mjs +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -1
- package/joi/dist/joi.module.js +1 -1
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/dist/types.d.ts +1 -1
- package/joi/src/__tests__/Form-native-validation.tsx +2 -2
- package/joi/src/__tests__/Form.tsx +2 -2
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +56 -56
- package/joi/src/__tests__/joi.ts +1 -1
- package/joi/src/joi.ts +1 -1
- package/joi/src/types.ts +1 -5
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -1
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/dist/types.d.ts +1 -1
- package/nope/src/__tests__/Form-native-validation.tsx +2 -2
- package/nope/src/__tests__/Form.tsx +2 -2
- package/nope/src/__tests__/__fixtures__/data.ts +1 -1
- package/nope/src/__tests__/nope.ts +1 -1
- package/nope/src/nope.ts +1 -1
- package/nope/src/types.ts +2 -2
- package/package.json +69 -54
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/dist/types.d.ts +1 -1
- package/superstruct/src/__tests__/Form-native-validation.tsx +2 -2
- package/superstruct/src/__tests__/Form.tsx +2 -2
- package/superstruct/src/__tests__/__fixtures__/data.ts +8 -8
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +4 -4
- package/superstruct/src/__tests__/superstruct.ts +1 -1
- package/superstruct/src/superstruct.ts +1 -1
- package/superstruct/src/types.ts +1 -1
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -1
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/dist/types.d.ts +1 -1
- package/typanion/src/__tests__/Form-native-validation.tsx +1 -1
- package/typanion/src/__tests__/Form.tsx +1 -1
- package/typanion/src/__tests__/__fixtures__/data.ts +12 -7
- package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +4 -4
- package/typanion/src/__tests__/typanion.ts +1 -1
- package/typanion/src/typanion.ts +1 -1
- package/typanion/src/types.ts +4 -4
- package/typebox/dist/typebox.js +1 -1
- package/typebox/dist/typebox.js.map +1 -1
- package/typebox/dist/typebox.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs.map +1 -1
- package/typebox/dist/typebox.module.js +1 -1
- package/typebox/dist/typebox.module.js.map +1 -1
- package/typebox/dist/typebox.umd.js +1 -1
- package/typebox/dist/typebox.umd.js.map +1 -1
- package/typebox/dist/types.d.ts +3 -2
- package/typebox/src/__tests__/Form-compiler.tsx +57 -0
- package/typebox/src/__tests__/Form-native-validation-compiler.tsx +86 -0
- package/typebox/src/__tests__/Form-native-validation.tsx +4 -4
- package/typebox/src/__tests__/Form.tsx +3 -3
- package/typebox/src/__tests__/__fixtures__/data.ts +6 -2
- package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +188 -0
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +13 -13
- package/typebox/src/__tests__/typebox-compiler.ts +37 -0
- package/typebox/src/__tests__/typebox.ts +1 -1
- package/typebox/src/typebox.ts +8 -3
- package/typebox/src/types.ts +3 -2
- package/typeschema/dist/index.d.ts +2 -0
- package/typeschema/dist/types.d.ts +9 -0
- package/typeschema/dist/typeschema.d.ts +2 -0
- package/typeschema/dist/typeschema.js +2 -0
- package/typeschema/dist/typeschema.js.map +1 -0
- package/typeschema/dist/typeschema.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs.map +1 -0
- package/typeschema/dist/typeschema.module.js +2 -0
- package/typeschema/dist/typeschema.module.js.map +1 -0
- package/typeschema/dist/typeschema.umd.js +2 -0
- package/typeschema/dist/typeschema.umd.js.map +1 -0
- package/typeschema/package.json +18 -0
- package/typeschema/src/__tests__/Form-native-validation.tsx +82 -0
- package/typeschema/src/__tests__/Form.tsx +53 -0
- package/typeschema/src/__tests__/__fixtures__/data.ts +88 -0
- package/typeschema/src/__tests__/__snapshots__/typeschema.ts.snap +225 -0
- package/typeschema/src/__tests__/typeschema.ts +70 -0
- package/typeschema/src/index.ts +2 -0
- package/typeschema/src/types.ts +18 -0
- package/typeschema/src/typeschema.ts +70 -0
- package/valibot/dist/types.d.ts +1 -1
- package/valibot/dist/valibot.js +1 -1
- package/valibot/dist/valibot.js.map +1 -1
- package/valibot/dist/valibot.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs.map +1 -1
- package/valibot/dist/valibot.module.js +1 -1
- package/valibot/dist/valibot.module.js.map +1 -1
- package/valibot/dist/valibot.umd.js +1 -1
- package/valibot/dist/valibot.umd.js.map +1 -1
- package/valibot/src/__tests__/Form-native-validation.tsx +2 -2
- package/valibot/src/__tests__/Form.tsx +1 -1
- package/valibot/src/__tests__/valibot.ts +4 -4
- package/valibot/src/types.ts +1 -1
- package/valibot/src/valibot.ts +12 -6
- package/vest/dist/types.d.ts +2 -2
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -1
- package/vest/dist/vest.module.js.map +1 -1
- package/vest/dist/vest.umd.js.map +1 -1
- package/vest/src/__tests__/Form-native-validation.tsx +1 -1
- package/vest/src/__tests__/Form.tsx +1 -1
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +0 -6
- package/vest/src/__tests__/vest.ts +14 -8
- package/vest/src/types.ts +11 -4
- package/vest/src/vest.ts +1 -1
- package/vine/dist/types.d.ts +1 -1
- package/vine/dist/vine.js +1 -1
- package/vine/dist/vine.js.map +1 -1
- package/vine/dist/vine.mjs +1 -1
- package/vine/dist/vine.modern.mjs +1 -1
- package/vine/dist/vine.modern.mjs.map +1 -1
- package/vine/dist/vine.module.js +1 -1
- package/vine/dist/vine.module.js.map +1 -1
- package/vine/dist/vine.umd.js +1 -1
- package/vine/dist/vine.umd.js.map +1 -1
- package/vine/src/__tests__/Form-native-validation.tsx +9 -5
- package/vine/src/__tests__/Form.tsx +9 -5
- package/vine/src/__tests__/__fixtures__/data.ts +4 -2
- package/vine/src/__tests__/vine.ts +1 -1
- package/vine/src/types.ts +1 -1
- package/vine/src/vine.ts +10 -8
- package/yup/dist/yup.d.ts +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/Form-native-validation.tsx +1 -1
- package/yup/src/__tests__/Form.tsx +1 -1
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +13 -13
- package/yup/src/__tests__/yup.ts +9 -7
- package/yup/src/yup.ts +2 -2
- package/zod/dist/types.d.ts +1 -1
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/Form-native-validation.tsx +2 -2
- package/zod/src/__tests__/Form.tsx +1 -1
- package/zod/src/__tests__/zod.ts +1 -1
- package/zod/src/types.ts +1 -1
- package/zod/src/zod.ts +4 -3
package/vine/dist/vine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vine.js","sources":["../src/vine.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"vine.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) => {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (; vineErrors.length; ) {\n const error = vineErrors[0];\n const path = error.field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message: error.message, type: error.rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[error.rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n error.rule,\n messages ? [...(messages as string[]), error.message] : error.message,\n ) as FieldError;\n }\n\n vineErrors.shift();\n }\n\n return schemaErrors;\n};\n\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema.validate(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 (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","length","error","path","field","message","type","rule","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"4FAKMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAA,EAE1CF,EAAWG,QAAU,CAC1B,IAAMC,EAAQJ,EAAW,GACnBK,EAAOD,EAAME,MAMnB,GAJMD,KAAQH,IACZA,EAAaG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMK,OAGzDR,EAA0B,CAC5B,IAAQS,EAAUR,EAAaG,GAAvBK,MACFC,EAAWD,GAASA,EAAMN,EAAMK,MAEtCP,EAAaG,GAAQO,eACnBP,EACAJ,EACAC,EACAE,EAAMK,KACNE,EAAQ,GAAAE,OAAQF,EAAuBP,CAAAA,EAAMG,UAAWH,EAAMG,QAElE,CAEAP,EAAWc,OACb,CAEA,OAAOZ,CACT,uBAGE,SAACa,EAAQC,EAAeC,GACjBC,YADiBD,IAAAA,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,KAAnDC,SAAAA,GAIN,OAFAL,EAAQM,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEP,GAEzD,CACLQ,OAAQ,GACRV,OAAQD,EAAgBY,IAAMX,EAASO,EACvC,4DATuBK,GAU1B,SAAQ1B,GACP,GAAIA,aAAiBwB,EAAMA,OAACG,mBAC1B,MAAO,CACLb,OAAQ,CAAA,EACRU,OAAQI,EAAYA,aAClBjC,EACEK,EAAMO,UACLS,EAAQM,2BACkB,QAAzBN,EAAQa,cAEZb,IAKN,MAAMhB,CACR,GACF,CAAC,MAAA8B,GAAA,OAAAb,QAAAc,OAAAD,EAAA,CAAA,CAAA"}
|
package/vine/dist/vine.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as t}from"@vinejs/vine";import{appendErrors as o}from"react-hook-form";var n=function(e,r){for(var t={};e.length;){var n=e[0],i=n.field;if(i in t||(t[i]={message:n.message,type:n.rule}),r){var s=t[i].types,a=s&&s[n.rule];t[i]=o(i,r,t,n.rule,a?[].concat(a,[n.message]):n.message)}e.shift()}return t},i=function(o,i,s){return void 0===s&&(s={}),function(a,u,f){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(o.validate(a,i)).then(function(r){return f.shouldUseNativeValidation&&e({},f),{errors:{},values:s.raw?a:r}})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){if(e instanceof t.E_VALIDATION_ERROR)return{values:{},errors:r(n(e.messages,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw e}))}catch(e){return Promise.reject(e)}}};export{i as vineResolver};
|
|
2
2
|
//# sourceMappingURL=vine.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as s}from"@vinejs/vine";import{appendErrors as o}from"react-hook-form";const t=(e,r)=>{const s={};for(;e.length;){const t=e[0],a=t.field;if(a in s||(s[a]={message:t.message,type:t.rule}),r){const{types:e}=s[a],i=e&&e[t.rule];s[a]=o(a,r,s,t.rule,i?[...i,t.message]:t.message)}e.shift()}return s},a=(o,a,i={})=>async(n,l,m)=>{try{const r=await o.validate(n,a);return m.shouldUseNativeValidation&&e({},m),{errors:{},values:i.raw?n:r}}catch(e){if(e instanceof s.E_VALIDATION_ERROR)return{values:{},errors:r(t(e.messages,!m.shouldUseNativeValidation&&"all"===m.criteriaMode),m)};throw e}};export{a as vineResolver};
|
|
2
2
|
//# sourceMappingURL=vine.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vine.modern.mjs","sources":["../src/vine.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"vine.modern.mjs","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) => {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (; vineErrors.length; ) {\n const error = vineErrors[0];\n const path = error.field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message: error.message, type: error.rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[error.rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n error.rule,\n messages ? [...(messages as string[]), error.message] : error.message,\n ) as FieldError;\n }\n\n vineErrors.shift();\n }\n\n return schemaErrors;\n};\n\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema.validate(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 (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","length","error","path","field","message","type","rule","types","messages","appendErrors","shift","vineResolver","schema","schemaOptions","resolverOptions","async","values","_","options","data","validate","shouldUseNativeValidation","validateFieldsNatively","errors","raw","E_VALIDATION_ERROR","toNestErrors","criteriaMode"],"mappings":"oKAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAA2C,CAAE,EAEnD,KAAOF,EAAWG,QAAU,CAC1B,MAAMC,EAAQJ,EAAW,GACnBK,EAAOD,EAAME,MAMnB,GAJMD,KAAQH,IACZA,EAAaG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMK,OAGzDR,EAA0B,CAC5B,MAAMS,MAAEA,GAAUR,EAAaG,GACzBM,EAAWD,GAASA,EAAMN,EAAMK,MAEtCP,EAAaG,GAAQO,EACnBP,EACAJ,EACAC,EACAE,EAAMK,KACNE,EAAW,IAAKA,EAAuBP,EAAMG,SAAWH,EAAMG,QAElE,CAEAP,EAAWa,OACb,CAEA,OAAOX,GAGIY,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAE,IAC5CC,MAAOC,EAAQC,EAAGC,KAChB,IACE,MAAMC,QAAaP,EAAOQ,SAASJ,EAAQH,GAI3C,OAFAK,EAAQG,2BAA6BC,EAAuB,CAAA,EAAIJ,GAEzD,CACLK,OAAQ,GACRP,OAAQF,EAAgBU,IAAMR,EAASG,EAE3C,CAAE,MAAOlB,GACP,GAAIA,aAAiBsB,EAAOE,mBAC1B,MAAO,CACLT,OAAQ,CAAA,EACRO,OAAQG,EACN9B,EACEK,EAAMO,UACLU,EAAQG,2BACkB,QAAzBH,EAAQS,cAEZT,IAKN,MAAMjB,CACR"}
|
package/vine/dist/vine.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{errors as t}from"@vinejs/vine";import{appendErrors as o}from"react-hook-form";var n=function(e,r){for(var t={};e.length;){var n=e[0],i=n.field;if(i in t||(t[i]={message:n.message,type:n.rule}),r){var s=t[i].types,a=s&&s[n.rule];t[i]=o(i,r,t,n.rule,a?[].concat(a,[n.message]):n.message)}e.shift()}return t},i=function(o,i,s){return void 0===s&&(s={}),function(a,u,f){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(o.validate(a,i)).then(function(r){return f.shouldUseNativeValidation&&e({},f),{errors:{},values:s.raw?a:r}})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){if(e instanceof t.E_VALIDATION_ERROR)return{values:{},errors:r(n(e.messages,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw e}))}catch(e){return Promise.reject(e)}}};export{i as vineResolver};
|
|
2
2
|
//# sourceMappingURL=vine.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vine.module.js","sources":["../src/vine.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"vine.module.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) => {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (; vineErrors.length; ) {\n const error = vineErrors[0];\n const path = error.field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message: error.message, type: error.rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[error.rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n error.rule,\n messages ? [...(messages as string[]), error.message] : error.message,\n ) as FieldError;\n }\n\n vineErrors.shift();\n }\n\n return schemaErrors;\n};\n\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema.validate(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 (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","length","error","path","field","message","type","rule","types","messages","appendErrors","concat","shift","vineResolver","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"oKAKA,IAAMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAA,EAE1CF,EAAWG,QAAU,CAC1B,IAAMC,EAAQJ,EAAW,GACnBK,EAAOD,EAAME,MAMnB,GAJMD,KAAQH,IACZA,EAAaG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMK,OAGzDR,EAA0B,CAC5B,IAAQS,EAAUR,EAAaG,GAAvBK,MACFC,EAAWD,GAASA,EAAMN,EAAMK,MAEtCP,EAAaG,GAAQO,EACnBP,EACAJ,EACAC,EACAE,EAAMK,KACNE,EAAQ,GAAAE,OAAQF,EAAuBP,CAAAA,EAAMG,UAAWH,EAAMG,QAElE,CAEAP,EAAWc,OACb,CAEA,OAAOZ,CACT,EAEaa,EACX,SAACC,EAAQC,EAAeC,GACjBC,YADiBD,IAAAA,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,KAAnDC,SAAAA,GAIN,OAFAL,EAAQM,2BAA6BC,EAAuB,CAAE,EAAEP,GAEzD,CACLQ,OAAQ,GACRV,OAAQD,EAAgBY,IAAMX,EAASO,EACvC,4DATuBK,GAU1B,SAAQ3B,GACP,GAAIA,aAAiByB,EAAOG,mBAC1B,MAAO,CACLb,OAAQ,CAAA,EACRU,OAAQI,EACNlC,EACEK,EAAMO,UACLU,EAAQM,2BACkB,QAAzBN,EAAQa,cAEZb,IAKN,MAAMjB,CACR,GACF,CAAC,MAAA+B,GAAA,OAAAb,QAAAc,OAAAD,EAAA,CAAA,CAAA"}
|
package/vine/dist/vine.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("@vinejs/vine"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","@vinejs/vine","react-hook-form"],r):r((e||self).hookformResolversVine={},e.hookformResolvers,e.vine,e.ReactHookForm)}(this,function(e,r,o,t){var n=function(e,r){for(var o={};e.length;){var n=e[0],i=n.field;if(i in o||(o[i]={message:n.message,type:n.rule}),r){var s=o[i].types,a=s&&s[n.rule];o[i]=t.appendErrors(i,r,o,n.rule,a?[].concat(a,[n.message]):n.message)}e.shift()}return o};e.vineResolver=function(e,t,i){return void 0===i&&(i={}),function(s,a,f){try{return Promise.resolve(function(o,n){try{var a=Promise.resolve(e.validate(s,t)).then(function(e){return f.shouldUseNativeValidation&&r.validateFieldsNatively({},f),{errors:{},values:i.raw?s:e}})}catch(e){return n(e)}return a&&a.then?a.then(void 0,n):a}(0,function(e){if(e instanceof o.errors.E_VALIDATION_ERROR)return{values:{},errors:r.toNestErrors(n(e.messages,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw e}))}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=vine.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vine.umd.js","sources":["../src/vine.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"vine.umd.js","sources":["../src/vine.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { SimpleErrorReporter, errors } from '@vinejs/vine';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n vineErrors: SimpleErrorReporter['errors'],\n validateAllFieldCriteria: boolean,\n) => {\n const schemaErrors: Record<string, FieldError> = {};\n\n for (; vineErrors.length; ) {\n const error = vineErrors[0];\n const path = error.field;\n\n if (!(path in schemaErrors)) {\n schemaErrors[path] = { message: error.message, type: error.rule };\n }\n\n if (validateAllFieldCriteria) {\n const { types } = schemaErrors[path];\n const messages = types && types[error.rule];\n\n schemaErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n schemaErrors,\n error.rule,\n messages ? [...(messages as string[]), error.message] : error.message,\n ) as FieldError;\n }\n\n vineErrors.shift();\n }\n\n return schemaErrors;\n};\n\nexport const vineResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const data = await schema.validate(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 (error instanceof errors.E_VALIDATION_ERROR) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n error.messages,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrorSchema","vineErrors","validateAllFieldCriteria","schemaErrors","length","error","path","field","message","type","rule","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","validate","then","data","shouldUseNativeValidation","validateFieldsNatively","errors","raw","_catch","E_VALIDATION_ERROR","toNestErrors","criteriaMode","e","reject"],"mappings":"yaAKA,IAAMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAA,EAE1CF,EAAWG,QAAU,CAC1B,IAAMC,EAAQJ,EAAW,GACnBK,EAAOD,EAAME,MAMnB,GAJMD,KAAQH,IACZA,EAAaG,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMK,OAGzDR,EAA0B,CAC5B,IAAQS,EAAUR,EAAaG,GAAvBK,MACFC,EAAWD,GAASA,EAAMN,EAAMK,MAEtCP,EAAaG,GAAQO,eACnBP,EACAJ,EACAC,EACAE,EAAMK,KACNE,EAAQ,GAAAE,OAAQF,EAAuBP,CAAAA,EAAMG,UAAWH,EAAMG,QAElE,CAEAP,EAAWc,OACb,CAEA,OAAOZ,CACT,iBAGE,SAACa,EAAQC,EAAeC,GACjBC,YADiBD,IAAAA,IAAAA,EAAkB,CAAE,GACrCC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvBD,QAAAC,QACiBP,EAAOQ,SAASL,EAAQF,IAAcQ,KAAnDC,SAAAA,GAIN,OAFAL,EAAQM,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEP,GAEzD,CACLQ,OAAQ,GACRV,OAAQD,EAAgBY,IAAMX,EAASO,EACvC,4DATuBK,GAU1B,SAAQ1B,GACP,GAAIA,aAAiBwB,EAAMA,OAACG,mBAC1B,MAAO,CACLb,OAAQ,CAAA,EACRU,OAAQI,EAAYA,aAClBjC,EACEK,EAAMO,UACLS,EAAQM,2BACkB,QAAzBN,EAAQa,cAEZb,IAKN,MAAMhB,CACR,GACF,CAAC,MAAA8B,GAAA,OAAAb,QAAAc,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useForm } from 'react-hook-form';
|
|
3
1
|
import { render, screen } from '@testing-library/react';
|
|
4
2
|
import user from '@testing-library/user-event';
|
|
5
|
-
import { vineResolver } from '..';
|
|
6
3
|
import vine from '@vinejs/vine';
|
|
7
4
|
import { Infer } from '@vinejs/vine/build/src/types';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useForm } from 'react-hook-form';
|
|
7
|
+
import { vineResolver } from '..';
|
|
8
8
|
|
|
9
9
|
const schema = vine.compile(
|
|
10
10
|
vine.object({
|
|
@@ -59,12 +59,16 @@ test("form's native validation with Zod", async () => {
|
|
|
59
59
|
// username
|
|
60
60
|
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
|
61
61
|
expect(usernameField.validity.valid).toBe(false);
|
|
62
|
-
expect(usernameField.validationMessage).toBe(
|
|
62
|
+
expect(usernameField.validationMessage).toBe(
|
|
63
|
+
'The username field must have at least 1 characters',
|
|
64
|
+
);
|
|
63
65
|
|
|
64
66
|
// password
|
|
65
67
|
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
|
|
66
68
|
expect(passwordField.validity.valid).toBe(false);
|
|
67
|
-
expect(passwordField.validationMessage).toBe(
|
|
69
|
+
expect(passwordField.validationMessage).toBe(
|
|
70
|
+
'The password field must have at least 1 characters',
|
|
71
|
+
);
|
|
68
72
|
|
|
69
73
|
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
|
70
74
|
await user.type(screen.getByPlaceholderText(/password/i), 'password');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
4
|
-
import { useForm } from 'react-hook-form';
|
|
5
|
-
import { vineResolver } from '..';
|
|
6
3
|
import vine from '@vinejs/vine';
|
|
7
4
|
import { Infer } from '@vinejs/vine/build/src/types';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useForm } from 'react-hook-form';
|
|
7
|
+
import { vineResolver } from '..';
|
|
8
8
|
|
|
9
9
|
const schema = vine.compile(
|
|
10
10
|
vine.object({
|
|
@@ -49,7 +49,11 @@ test("form's validation with Vine and TypeScript's integration", async () => {
|
|
|
49
49
|
|
|
50
50
|
await user.click(screen.getByText(/submit/i));
|
|
51
51
|
|
|
52
|
-
expect(
|
|
53
|
-
|
|
52
|
+
expect(
|
|
53
|
+
screen.getByText(/The username field must have at least 1 characters/i),
|
|
54
|
+
).toBeInTheDocument();
|
|
55
|
+
expect(
|
|
56
|
+
screen.getByText(/The password field must have at least 1 characters/i),
|
|
57
|
+
).toBeInTheDocument();
|
|
54
58
|
expect(handleSubmit).not.toHaveBeenCalled();
|
|
55
59
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
1
|
import vine from '@vinejs/vine';
|
|
3
2
|
import { Infer } from '@vinejs/vine/build/src/types';
|
|
3
|
+
import { Field, InternalFieldName } from 'react-hook-form';
|
|
4
4
|
|
|
5
5
|
export const schema = vine.compile(
|
|
6
6
|
vine.object({
|
|
@@ -25,7 +25,9 @@ export const schema = vine.compile(
|
|
|
25
25
|
name: vine.string().fixedLength(4),
|
|
26
26
|
}),
|
|
27
27
|
),
|
|
28
|
-
dateStr: vine
|
|
28
|
+
dateStr: vine
|
|
29
|
+
.string()
|
|
30
|
+
.transform((value: string) => new Date(value).toISOString()),
|
|
29
31
|
}),
|
|
30
32
|
);
|
|
31
33
|
|
package/vine/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
1
|
import { VineValidator } from '@vinejs/vine';
|
|
3
2
|
import { ValidationOptions } from '@vinejs/vine/build/src/types';
|
|
3
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
4
4
|
|
|
5
5
|
export type Resolver = <T extends VineValidator<any, any>>(
|
|
6
6
|
schema: T,
|
package/vine/src/vine.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';
|
|
2
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
2
|
import { SimpleErrorReporter, errors } from '@vinejs/vine';
|
|
3
|
+
import { FieldError, FieldErrors, appendErrors } from 'react-hook-form';
|
|
4
4
|
import type { Resolver } from './types';
|
|
5
5
|
|
|
6
6
|
const parseErrorSchema = (
|
|
@@ -9,26 +9,28 @@ const parseErrorSchema = (
|
|
|
9
9
|
) => {
|
|
10
10
|
const schemaErrors: Record<string, FieldError> = {};
|
|
11
11
|
|
|
12
|
-
for (
|
|
13
|
-
const
|
|
14
|
-
const path = field;
|
|
12
|
+
for (; vineErrors.length; ) {
|
|
13
|
+
const error = vineErrors[0];
|
|
14
|
+
const path = error.field;
|
|
15
15
|
|
|
16
16
|
if (!(path in schemaErrors)) {
|
|
17
|
-
schemaErrors[path] = { message, type: rule };
|
|
17
|
+
schemaErrors[path] = { message: error.message, type: error.rule };
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
if (validateAllFieldCriteria) {
|
|
21
21
|
const { types } = schemaErrors[path];
|
|
22
|
-
const messages = types && types[rule];
|
|
22
|
+
const messages = types && types[error.rule];
|
|
23
23
|
|
|
24
24
|
schemaErrors[path] = appendErrors(
|
|
25
25
|
path,
|
|
26
26
|
validateAllFieldCriteria,
|
|
27
27
|
schemaErrors,
|
|
28
|
-
rule,
|
|
29
|
-
messages ? [...(messages as string[]), message] : message,
|
|
28
|
+
error.rule,
|
|
29
|
+
messages ? [...(messages as string[]), error.message] : error.message,
|
|
30
30
|
) as FieldError;
|
|
31
31
|
}
|
|
32
|
+
|
|
33
|
+
vineErrors.shift();
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
return schemaErrors;
|
package/yup/dist/yup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as Yup from 'yup';
|
|
2
1
|
import { FieldValues, Resolver } from 'react-hook-form';
|
|
2
|
+
import * as Yup from 'yup';
|
|
3
3
|
export declare function yupResolver<TFieldValues extends FieldValues>(schema: Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>, schemaOptions?: Parameters<(typeof schema)['validate']>[1], resolverOptions?: {
|
|
4
4
|
/**
|
|
5
5
|
* @default async
|
package/yup/dist/yup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.js","sources":["../src/yup.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"yup.js","sources":["../src/yup.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n },\n {},\n );\n};\n\nexport function yupResolver<TFieldValues extends FieldValues>(\n schema:\n | Yup.ObjectSchema<TFieldValues>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>,\n schemaOptions: Parameters<(typeof schema)['validate']>[1] = {},\n resolverOptions: {\n /**\n * @default async\n */\n mode?: 'async' | 'sync';\n /**\n * Return the raw input values rather than the parsed values.\n * @default false\n */\n raw?: boolean;\n } = {},\n): Resolver<Yup.InferType<typeof schema>> {\n return async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n values,\n Object.assign({ abortEarly: false }, schemaOptions, { context }),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result,\n errors: {},\n };\n } catch (e: any) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n e,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n };\n}\n"],"names":["schema","schemaOptions","resolverOptions","values","context","options","Promise","resolve","process","env","NODE_ENV","console","warn","mode","Object","assign","abortEarly","then","result","shouldUseNativeValidation","validateFieldsNatively","raw","errors","_catch","e","inner","toNestErrors","error","validateAllFieldCriteria","criteriaMode","reduce","previous","path","message","type","types","messages","appendErrors","concat","reject"],"mappings":"sFA4CgB,SACdA,EAGAC,EACAC,GAYA,YAbAD,IAAAA,IAAAA,EAA4D,CAAE,QAC9DC,IAAAA,IAAAA,EAUI,IAEUC,SAAAA,EAAQC,EAASC,GAAW,IAAA,OAAAC,QAAAC,iCAElCN,EAAcG,SAAoC,gBAAzBI,QAAQC,IAAIC,UAEvCC,QAAQC,KACN,iGAEHN,QAAAC,QAEoBP,EACM,SAAzBE,EAAgBW,KAAkB,eAAiB,YAEnDV,EACAW,OAAOC,OAAO,CAAEC,YAAY,GAASf,EAAe,CAAEG,QAAAA,MACvDa,cALKC,GASN,OAFAb,EAAQc,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEf,GAEzD,CACLF,OAAQD,EAAgBmB,IAAMlB,EAASe,EACvCI,OAAQ,CAAA,EACR,6DArBoCC,CAAA,WAsB/BC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLrB,OAAQ,CAAE,EACVmB,OAAQI,EAAAA,cA5EdC,EA8EUH,EA7EVI,GA8EWvB,EAAQc,2BACkB,QAAzBd,EAAQwB,cA7EZF,EAAMF,OAAS,IAAIK,OACzB,SAACC,EAAUJ,GAKT,GAJKI,EAASJ,EAAMK,QAClBD,EAASJ,EAAMK,MAAS,CAAEC,QAASN,EAAMM,QAASC,KAAMP,EAAMO,OAG5DN,EAA0B,CAC5B,IAAMO,EAAQJ,EAASJ,EAAMK,MAAOG,MAC9BC,EAAWD,GAASA,EAAMR,EAAMO,MAEtCH,EAASJ,EAAMK,MAASK,EAAAA,aACtBV,EAAMK,KACNJ,EACAG,EACAJ,EAAMO,KACNE,EACK,GAAgBE,OAAOF,EAAsBT,EAAMM,SACpDN,EAAMM,QAEd,CAEA,OAAOF,CACT,EACA,KAwDM1B,IAnFe,IACvBsB,EACAC,CAoFE,GACF,CAAC,MAAAJ,GAAA,OAAAlB,QAAAiC,OAAAf,EACH,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.modern.mjs","sources":["../src/yup.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"yup.modern.mjs","sources":["../src/yup.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n },\n {},\n );\n};\n\nexport function yupResolver<TFieldValues extends FieldValues>(\n schema:\n | Yup.ObjectSchema<TFieldValues>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>,\n schemaOptions: Parameters<(typeof schema)['validate']>[1] = {},\n resolverOptions: {\n /**\n * @default async\n */\n mode?: 'async' | 'sync';\n /**\n * Return the raw input values rather than the parsed values.\n * @default false\n */\n raw?: boolean;\n } = {},\n): Resolver<Yup.InferType<typeof schema>> {\n return async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n values,\n Object.assign({ abortEarly: false }, schemaOptions, { context }),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result,\n errors: {},\n };\n } catch (e: any) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n e,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n };\n}\n"],"names":["yupResolver","schema","schemaOptions","resolverOptions","async","values","context","options","process","env","NODE_ENV","console","warn","result","mode","Object","assign","abortEarly","shouldUseNativeValidation","validateFieldsNatively","raw","errors","e","inner","toNestErrors","error","validateAllFieldCriteria","criteriaMode","reduce","previous","path","message","type","types","messages","appendErrors","concat","parseErrorSchema"],"mappings":"uIA4CgBA,EACdC,EAGAC,EAA4D,CAAE,EAC9DC,EAUI,CAAA,GAEJ,OAAOC,MAAOC,EAAQC,EAASC,KAC7B,IACML,EAAcI,SAAoC,gBAAzBE,QAAQC,IAAIC,UAEvCC,QAAQC,KACN,iGAIJ,MAAMC,QAAeZ,EACM,SAAzBE,EAAgBW,KAAkB,eAAiB,YAEnDT,EACAU,OAAOC,OAAO,CAAEC,YAAY,GAASf,EAAe,CAAEI,aAKxD,OAFAC,EAAQW,2BAA6BC,EAAuB,CAAA,EAAIZ,GAEzD,CACLF,OAAQF,EAAgBiB,IAAMf,EAASQ,EACvCQ,OAAQ,GAEZ,CAAE,MAAOC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLjB,OAAQ,CAAE,EACVgB,OAAQG,GA5EdC,EA8EUH,EA7EVI,GA8EWnB,EAAQW,2BACkB,QAAzBX,EAAQoB,cA7EZF,EAAMF,OAAS,IAAIK,OACzB,CAACC,EAAUJ,KAKT,GAJKI,EAASJ,EAAMK,QAClBD,EAASJ,EAAMK,MAAS,CAAEC,QAASN,EAAMM,QAASC,KAAMP,EAAMO,OAG5DN,EAA0B,CAC5B,MAAMO,EAAQJ,EAASJ,EAAMK,MAAOG,MAC9BC,EAAWD,GAASA,EAAMR,EAAMO,MAEtCH,EAASJ,EAAMK,MAASK,EACtBV,EAAMK,KACNJ,EACAG,EACAJ,EAAMO,KACNE,EACK,GAAgBE,OAAOF,EAAsBT,EAAMM,SACpDN,EAAMM,QAEd,CAEA,OAAOF,GAET,CAAE,IAwDItB,GAGN,CAtFqB8B,IACvBZ,EACAC,CAoFE,CAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.module.js","sources":["../src/yup.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"yup.module.js","sources":["../src/yup.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n },\n {},\n );\n};\n\nexport function yupResolver<TFieldValues extends FieldValues>(\n schema:\n | Yup.ObjectSchema<TFieldValues>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>,\n schemaOptions: Parameters<(typeof schema)['validate']>[1] = {},\n resolverOptions: {\n /**\n * @default async\n */\n mode?: 'async' | 'sync';\n /**\n * Return the raw input values rather than the parsed values.\n * @default false\n */\n raw?: boolean;\n } = {},\n): Resolver<Yup.InferType<typeof schema>> {\n return async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n values,\n Object.assign({ abortEarly: false }, schemaOptions, { context }),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result,\n errors: {},\n };\n } catch (e: any) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n e,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n };\n}\n"],"names":["yupResolver","schema","schemaOptions","resolverOptions","values","context","options","Promise","resolve","process","env","NODE_ENV","console","warn","mode","Object","assign","abortEarly","then","result","shouldUseNativeValidation","validateFieldsNatively","raw","errors","_catch","e","inner","toNestErrors","error","validateAllFieldCriteria","criteriaMode","reduce","previous","path","message","type","types","messages","appendErrors","concat","reject"],"mappings":"8HA4CgB,SAAAA,EACdC,EAGAC,EACAC,GAYA,YAbAD,IAAAA,IAAAA,EAA4D,CAAE,QAC9DC,IAAAA,IAAAA,EAUI,IAEUC,SAAAA,EAAQC,EAASC,GAAW,IAAA,OAAAC,QAAAC,iCAElCN,EAAcG,SAAoC,gBAAzBI,QAAQC,IAAIC,UAEvCC,QAAQC,KACN,iGAEHN,QAAAC,QAEoBP,EACM,SAAzBE,EAAgBW,KAAkB,eAAiB,YAEnDV,EACAW,OAAOC,OAAO,CAAEC,YAAY,GAASf,EAAe,CAAEG,QAAAA,MACvDa,cALKC,GASN,OAFAb,EAAQc,2BAA6BC,EAAuB,CAAE,EAAEf,GAEzD,CACLF,OAAQD,EAAgBmB,IAAMlB,EAASe,EACvCI,OAAQ,CAAA,EACR,6DArBoCC,CAAA,WAsB/BC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLrB,OAAQ,CAAE,EACVmB,OAAQI,GA5EdC,EA8EUH,EA7EVI,GA8EWvB,EAAQc,2BACkB,QAAzBd,EAAQwB,cA7EZF,EAAMF,OAAS,IAAIK,OACzB,SAACC,EAAUJ,GAKT,GAJKI,EAASJ,EAAMK,QAClBD,EAASJ,EAAMK,MAAS,CAAEC,QAASN,EAAMM,QAASC,KAAMP,EAAMO,OAG5DN,EAA0B,CAC5B,IAAMO,EAAQJ,EAASJ,EAAMK,MAAOG,MAC9BC,EAAWD,GAASA,EAAMR,EAAMO,MAEtCH,EAASJ,EAAMK,MAASK,EACtBV,EAAMK,KACNJ,EACAG,EACAJ,EAAMO,KACNE,EACK,GAAgBE,OAAOF,EAAsBT,EAAMM,SACpDN,EAAMM,QAEd,CAEA,OAAOF,CACT,EACA,KAwDM1B,IAnFe,IACvBsB,EACAC,CAoFE,GACF,CAAC,MAAAJ,GAAA,OAAAlB,QAAAiC,OAAAf,EACH,CAAA,CAAA"}
|
package/yup/dist/yup.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yup.umd.js","sources":["../src/yup.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"yup.umd.js","sources":["../src/yup.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean,\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n },\n {},\n );\n};\n\nexport function yupResolver<TFieldValues extends FieldValues>(\n schema:\n | Yup.ObjectSchema<TFieldValues>\n | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>,\n schemaOptions: Parameters<(typeof schema)['validate']>[1] = {},\n resolverOptions: {\n /**\n * @default async\n */\n mode?: 'async' | 'sync';\n /**\n * Return the raw input values rather than the parsed values.\n * @default false\n */\n raw?: boolean;\n } = {},\n): Resolver<Yup.InferType<typeof schema>> {\n return async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\",\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n values,\n Object.assign({ abortEarly: false }, schemaOptions, { context }),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result,\n errors: {},\n };\n } catch (e: any) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n e,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n };\n}\n"],"names":["schema","schemaOptions","resolverOptions","values","context","options","Promise","resolve","process","env","NODE_ENV","console","warn","mode","Object","assign","abortEarly","then","result","shouldUseNativeValidation","validateFieldsNatively","raw","errors","_catch","e","inner","toNestErrors","error","validateAllFieldCriteria","criteriaMode","reduce","previous","path","message","type","types","messages","appendErrors","concat","reject"],"mappings":"sYA4CgB,SACdA,EAGAC,EACAC,GAYA,YAbAD,IAAAA,IAAAA,EAA4D,CAAE,QAC9DC,IAAAA,IAAAA,EAUI,IAEUC,SAAAA,EAAQC,EAASC,GAAW,IAAA,OAAAC,QAAAC,iCAElCN,EAAcG,SAAoC,gBAAzBI,QAAQC,IAAIC,UAEvCC,QAAQC,KACN,iGAEHN,QAAAC,QAEoBP,EACM,SAAzBE,EAAgBW,KAAkB,eAAiB,YAEnDV,EACAW,OAAOC,OAAO,CAAEC,YAAY,GAASf,EAAe,CAAEG,QAAAA,MACvDa,cALKC,GASN,OAFAb,EAAQc,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEf,GAEzD,CACLF,OAAQD,EAAgBmB,IAAMlB,EAASe,EACvCI,OAAQ,CAAA,EACR,6DArBoCC,CAAA,WAsB/BC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLrB,OAAQ,CAAE,EACVmB,OAAQI,EAAAA,cA5EdC,EA8EUH,EA7EVI,GA8EWvB,EAAQc,2BACkB,QAAzBd,EAAQwB,cA7EZF,EAAMF,OAAS,IAAIK,OACzB,SAACC,EAAUJ,GAKT,GAJKI,EAASJ,EAAMK,QAClBD,EAASJ,EAAMK,MAAS,CAAEC,QAASN,EAAMM,QAASC,KAAMP,EAAMO,OAG5DN,EAA0B,CAC5B,IAAMO,EAAQJ,EAASJ,EAAMK,MAAOG,MAC9BC,EAAWD,GAASA,EAAMR,EAAMO,MAEtCH,EAASJ,EAAMK,MAASK,EAAAA,aACtBV,EAAMK,KACNJ,EACAG,EACAJ,EAAMO,KACNE,EACK,GAAgBE,OAAOF,EAAsBT,EAAMM,SACpDN,EAAMM,QAEd,CAEA,OAAOF,CACT,EACA,KAwDM1B,IAnFe,IACvBsB,EACAC,CAoFE,GACF,CAAC,MAAAJ,GAAA,OAAAlB,QAAAiC,OAAAf,EACH,CAAA,CAAA"}
|
|
@@ -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 * as Yup from 'yup';
|
|
6
6
|
import { yupResolver } from '..';
|
|
@@ -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 { SubmitHandler, useForm } from 'react-hook-form';
|
|
5
5
|
import * as Yup from 'yup';
|
|
6
6
|
import { yupResolver } from '..';
|
|
@@ -4,14 +4,14 @@ exports[`yupResolver > should return a single error from yupResolver when valida
|
|
|
4
4
|
{
|
|
5
5
|
"errors": {
|
|
6
6
|
"birthYear": {
|
|
7
|
-
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
7
|
+
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"birthYear"\`).",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "typeError",
|
|
10
10
|
},
|
|
11
11
|
"like": [
|
|
12
12
|
{
|
|
13
13
|
"id": {
|
|
14
|
-
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
14
|
+
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"z"\`).",
|
|
15
15
|
"ref": undefined,
|
|
16
16
|
"type": "typeError",
|
|
17
17
|
},
|
|
@@ -45,14 +45,14 @@ exports[`yupResolver > should return a single error from yupResolver with \`mode
|
|
|
45
45
|
{
|
|
46
46
|
"errors": {
|
|
47
47
|
"birthYear": {
|
|
48
|
-
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
48
|
+
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"birthYear"\`).",
|
|
49
49
|
"ref": undefined,
|
|
50
50
|
"type": "typeError",
|
|
51
51
|
},
|
|
52
52
|
"like": [
|
|
53
53
|
{
|
|
54
54
|
"id": {
|
|
55
|
-
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
55
|
+
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"z"\`).",
|
|
56
56
|
"ref": undefined,
|
|
57
57
|
"type": "typeError",
|
|
58
58
|
},
|
|
@@ -86,21 +86,21 @@ exports[`yupResolver > should return all the errors from yupResolver when valida
|
|
|
86
86
|
{
|
|
87
87
|
"errors": {
|
|
88
88
|
"birthYear": {
|
|
89
|
-
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
89
|
+
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"birthYear"\`).",
|
|
90
90
|
"ref": undefined,
|
|
91
91
|
"type": "typeError",
|
|
92
92
|
"types": {
|
|
93
|
-
"typeError": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
93
|
+
"typeError": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"birthYear"\`).",
|
|
94
94
|
},
|
|
95
95
|
},
|
|
96
96
|
"like": [
|
|
97
97
|
{
|
|
98
98
|
"id": {
|
|
99
|
-
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
99
|
+
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"z"\`).",
|
|
100
100
|
"ref": undefined,
|
|
101
101
|
"type": "typeError",
|
|
102
102
|
"types": {
|
|
103
|
-
"typeError": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
103
|
+
"typeError": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"z"\`).",
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
106
|
"name": {
|
|
@@ -147,21 +147,21 @@ exports[`yupResolver > should return all the errors from yupResolver when valida
|
|
|
147
147
|
{
|
|
148
148
|
"errors": {
|
|
149
149
|
"birthYear": {
|
|
150
|
-
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
150
|
+
"message": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"birthYear"\`).",
|
|
151
151
|
"ref": undefined,
|
|
152
152
|
"type": "typeError",
|
|
153
153
|
"types": {
|
|
154
|
-
"typeError": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
154
|
+
"typeError": "birthYear must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"birthYear"\`).",
|
|
155
155
|
},
|
|
156
156
|
},
|
|
157
157
|
"like": [
|
|
158
158
|
{
|
|
159
159
|
"id": {
|
|
160
|
-
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
160
|
+
"message": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"z"\`).",
|
|
161
161
|
"ref": undefined,
|
|
162
162
|
"type": "typeError",
|
|
163
163
|
"types": {
|
|
164
|
-
"typeError": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
164
|
+
"typeError": "like[0].id must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`"z"\`).",
|
|
165
165
|
},
|
|
166
166
|
},
|
|
167
167
|
"name": {
|
|
@@ -234,7 +234,7 @@ exports[`yupResolver > should throw an error without inner property 1`] = `
|
|
|
234
234
|
{
|
|
235
235
|
"errors": {
|
|
236
236
|
"value": {
|
|
237
|
-
"message": "value must be a \`number\` type, but the final value was: \`NaN\` (cast from the value
|
|
237
|
+
"message": "value must be a \`number\` type, but the final value was: \`NaN\` (cast from the value \`""\`).",
|
|
238
238
|
"ref": undefined,
|
|
239
239
|
"type": "typeError",
|
|
240
240
|
},
|
package/yup/src/__tests__/yup.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import * as yup from 'yup';
|
|
3
3
|
import { yupResolver } from '..';
|
|
4
4
|
import {
|
|
5
|
-
schema,
|
|
6
|
-
validData,
|
|
7
5
|
fields,
|
|
8
6
|
invalidData,
|
|
7
|
+
schema,
|
|
9
8
|
schemaWithWhen,
|
|
9
|
+
validData,
|
|
10
10
|
} from './__fixtures__/data';
|
|
11
11
|
|
|
12
12
|
const shouldUseNativeValidation = false;
|
|
@@ -191,20 +191,22 @@ describe('yupResolver', () => {
|
|
|
191
191
|
});
|
|
192
192
|
|
|
193
193
|
it('shoud validate a lazy schema with success', async () => {
|
|
194
|
-
const lazySchema = yup.lazy(() =>
|
|
194
|
+
const lazySchema = yup.lazy(() =>
|
|
195
|
+
yup.object().shape({ firstName: yup.string().optional() }),
|
|
196
|
+
);
|
|
195
197
|
|
|
196
198
|
const schemaSpy = vi.spyOn(lazySchema, 'validate');
|
|
197
199
|
const schemaSyncSpy = vi.spyOn(lazySchema, 'validateSync');
|
|
198
200
|
|
|
199
|
-
const result = await yupResolver(lazySchema, undefined
|
|
200
|
-
{ firstName:
|
|
201
|
+
const result = await yupResolver(lazySchema, undefined)(
|
|
202
|
+
{ firstName: 'resolver' },
|
|
201
203
|
undefined,
|
|
202
204
|
{
|
|
203
205
|
fields: {
|
|
204
206
|
firstName: {
|
|
205
207
|
ref: { name: 'firstName' },
|
|
206
208
|
name: 'firstName',
|
|
207
|
-
}
|
|
209
|
+
},
|
|
208
210
|
},
|
|
209
211
|
shouldUseNativeValidation,
|
|
210
212
|
},
|
|
@@ -212,6 +214,6 @@ describe('yupResolver', () => {
|
|
|
212
214
|
|
|
213
215
|
expect(schemaSpy).toHaveBeenCalledTimes(1);
|
|
214
216
|
expect(schemaSyncSpy).not.toHaveBeenCalled();
|
|
215
|
-
expect(result).toEqual({ errors: {}, values: { firstName:
|
|
217
|
+
expect(result).toEqual({ errors: {}, values: { firstName: 'resolver' } });
|
|
216
218
|
});
|
|
217
219
|
});
|
package/yup/src/yup.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as Yup from 'yup';
|
|
2
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
2
|
import {
|
|
4
|
-
appendErrors,
|
|
5
3
|
FieldError,
|
|
6
4
|
FieldValues,
|
|
7
5
|
Resolver,
|
|
6
|
+
appendErrors,
|
|
8
7
|
} from 'react-hook-form';
|
|
8
|
+
import * as Yup from 'yup';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Why `path!` ? because it could be `undefined` in some case
|
package/zod/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldValues,
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
export type Resolver = <T extends z.Schema<any, any>>(schema: T, schemaOptions?: Partial<z.ParseParams>, factoryOptions?: {
|
|
4
4
|
/**
|
package/zod/dist/zod.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=require("
|
|
1
|
+
var r=require("@hookform/resolvers"),e=require("react-hook-form"),o=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 c=n[a].types,f=c&&c[s.code];n[a]=e.appendErrors(a,o,n,t,f?[].concat(f,s.message):s.message)}r.shift()}return n};exports.zodResolver=function(e,n,s){return void 0===s&&(s={}),function(t,i,a){try{return Promise.resolve(function(o,i){try{var u=Promise.resolve(e["sync"===s.mode?"parse":"parseAsync"](t,n)).then(function(e){return a.shouldUseNativeValidation&&r.validateFieldsNatively({},a),{errors:{},values:s.raw?t:e}})}catch(r){return i(r)}return u&&u.then?u.then(void 0,i):u}(0,function(e){if(function(r){return Array.isArray(null==r?void 0:r.errors)}(e))return{values:{},errors:r.toNestErrors(o(e.errors,!a.shouldUseNativeValidation&&"all"===a.criteriaMode),a)};throw e}))}catch(r){return Promise.reject(r)}}};
|
|
2
2
|
//# sourceMappingURL=zod.js.map
|