@hookform/resolvers 3.10.0 → 4.1.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 +108 -6
- package/ajv/dist/ajv.d.ts +20 -0
- package/ajv/dist/ajv.js +1 -1
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.mjs +1 -1
- package/ajv/dist/ajv.modern.mjs +1 -1
- package/ajv/dist/ajv.modern.mjs.map +1 -1
- package/ajv/dist/ajv.module.js +1 -1
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js +1 -1
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/types.d.ts +8 -0
- package/ajv/src/__tests__/__fixtures__/data-errors.ts +216 -0
- package/ajv/src/__tests__/__snapshots__/ajv-errors.ts.snap +462 -0
- package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +6 -6
- package/ajv/src/__tests__/ajv-errors.ts +227 -0
- package/ajv/src/ajv.ts +47 -14
- package/ajv/src/types.ts +8 -0
- package/arktype/dist/arktype.d.ts +20 -2
- 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/index.d.ts +0 -1
- package/arktype/package.json +1 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +3 -3
- package/arktype/src/__tests__/Form.tsx +34 -8
- package/arktype/src/__tests__/__fixtures__/data.ts +2 -2
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +22 -415
- package/arktype/src/arktype.ts +46 -15
- package/arktype/src/index.ts +0 -1
- package/class-validator/dist/class-validator.d.ts +29 -2
- package/class-validator/dist/class-validator.js +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.mjs +1 -1
- package/class-validator/dist/class-validator.modern.mjs +1 -1
- package/class-validator/dist/class-validator.modern.mjs.map +1 -1
- package/class-validator/dist/class-validator.module.js +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/index.d.ts +0 -1
- package/class-validator/src/__tests__/Form.tsx +26 -0
- package/class-validator/src/__tests__/__fixtures__/data.ts +1 -1
- package/class-validator/src/__tests__/class-validator.ts +22 -11
- package/class-validator/src/class-validator.ts +47 -13
- package/class-validator/src/index.ts +0 -1
- package/computed-types/dist/computed-types.d.ts +18 -2
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.mjs +1 -1
- package/computed-types/dist/computed-types.modern.mjs +1 -1
- package/computed-types/dist/computed-types.modern.mjs.map +1 -1
- package/computed-types/dist/computed-types.module.js +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/dist/index.d.ts +0 -1
- package/computed-types/src/__tests__/Form-native-validation.tsx +2 -4
- package/computed-types/src/__tests__/Form.tsx +30 -6
- package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
- package/computed-types/src/__tests__/computed-types.ts +2 -0
- package/computed-types/src/computed-types.ts +24 -7
- package/computed-types/src/index.ts +0 -1
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +1 -1
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/effect-ts/dist/effect-ts.d.ts +19 -2
- 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/dist/index.d.ts +0 -1
- package/effect-ts/src/__tests__/Form.tsx +30 -4
- package/effect-ts/src/__tests__/__fixtures__/data.ts +1 -1
- package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +35 -1
- package/effect-ts/src/__tests__/effect-ts.ts +61 -0
- package/effect-ts/src/effect-ts.ts +60 -13
- package/effect-ts/src/index.ts +0 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.d.ts +21 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js.map +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.mjs +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs.map +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js.map +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js.map +1 -1
- package/fluentvalidation-ts/src/fluentvalidation-ts.ts +24 -3
- package/io-ts/dist/errorsToRecord.d.ts +5 -1
- package/io-ts/dist/index.d.ts +0 -1
- package/io-ts/dist/io-ts.d.ts +19 -2
- package/io-ts/dist/io-ts.js +1 -1
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs +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 +4 -11
- package/io-ts/src/__tests__/Form.tsx +30 -6
- package/io-ts/src/__tests__/__fixtures__/data.ts +2 -19
- package/io-ts/src/errorsToRecord.ts +4 -1
- package/io-ts/src/index.ts +0 -1
- package/io-ts/src/io-ts.ts +47 -25
- package/joi/dist/joi.d.ts +17 -0
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -1
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/src/joi.ts +17 -0
- package/nope/dist/nope.d.ts +17 -0
- package/nope/dist/nope.js +1 -1
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/nope.mjs +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -1
- package/nope/dist/nope.module.js +1 -1
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/src/nope.ts +17 -0
- package/package.json +49 -34
- package/standard-schema/dist/index.d.ts +1 -0
- package/standard-schema/dist/standard-schema.d.ts +25 -0
- package/standard-schema/dist/standard-schema.js +2 -0
- package/standard-schema/dist/standard-schema.js.map +1 -0
- package/standard-schema/dist/standard-schema.mjs +2 -0
- package/standard-schema/dist/standard-schema.modern.mjs +2 -0
- package/standard-schema/dist/standard-schema.modern.mjs.map +1 -0
- package/standard-schema/dist/standard-schema.module.js +2 -0
- package/standard-schema/dist/standard-schema.module.js.map +1 -0
- package/standard-schema/dist/standard-schema.umd.js +2 -0
- package/standard-schema/dist/standard-schema.umd.js.map +1 -0
- package/standard-schema/package.json +18 -0
- package/standard-schema/src/__tests__/Form-native-validation.tsx +82 -0
- package/standard-schema/src/__tests__/Form.tsx +82 -0
- package/standard-schema/src/__tests__/__fixtures__/data.ts +88 -0
- package/standard-schema/src/__tests__/__snapshots__/standard-schema.ts.snap +250 -0
- package/standard-schema/src/__tests__/standard-schema.ts +56 -0
- package/standard-schema/src/index.ts +1 -0
- package/standard-schema/src/standard-schema.ts +88 -0
- package/superstruct/dist/index.d.ts +0 -1
- package/superstruct/dist/superstruct.d.ts +22 -2
- package/superstruct/dist/superstruct.js +1 -1
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.mjs +1 -1
- package/superstruct/dist/superstruct.modern.mjs +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/src/__tests__/Form.tsx +26 -0
- package/superstruct/src/__tests__/__fixtures__/data.ts +1 -1
- package/superstruct/src/index.ts +0 -1
- package/superstruct/src/superstruct.ts +32 -10
- package/typanion/dist/index.d.ts +0 -1
- package/typanion/dist/typanion.d.ts +18 -2
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/typanion.mjs +1 -1
- package/typanion/dist/typanion.modern.mjs +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -1
- package/typanion/dist/typanion.module.js +1 -1
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/src/__tests__/Form-native-validation.tsx +6 -14
- package/typanion/src/__tests__/Form.tsx +32 -8
- package/typanion/src/__tests__/__fixtures__/data.ts +9 -9
- package/typanion/src/__tests__/typanion.ts +3 -3
- package/typanion/src/index.ts +0 -1
- package/typanion/src/typanion.ts +32 -9
- package/typebox/dist/index.d.ts +0 -1
- package/typebox/dist/typebox.d.ts +20 -2
- 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/src/__tests__/Form-compiler.tsx +4 -8
- package/typebox/src/__tests__/Form.tsx +32 -6
- package/typebox/src/__tests__/__fixtures__/data.ts +1 -1
- package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +21 -21
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +21 -21
- package/typebox/src/index.ts +0 -1
- package/typebox/src/typebox.ts +33 -7
- package/typeschema/dist/typeschema.d.ts +17 -0
- package/typeschema/dist/typeschema.js +1 -1
- package/typeschema/dist/typeschema.js.map +1 -1
- package/typeschema/dist/typeschema.mjs +1 -1
- package/typeschema/dist/typeschema.modern.mjs +1 -1
- package/typeschema/dist/typeschema.modern.mjs.map +1 -1
- package/typeschema/dist/typeschema.module.js +1 -1
- package/typeschema/dist/typeschema.module.js.map +1 -1
- package/typeschema/dist/typeschema.umd.js +1 -1
- package/typeschema/dist/typeschema.umd.js.map +1 -1
- package/typeschema/src/typeschema.ts +20 -1
- package/valibot/dist/index.d.ts +0 -1
- package/valibot/dist/valibot.d.ts +31 -2
- 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/package.json +1 -1
- package/valibot/src/__tests__/Form.tsx +26 -0
- package/valibot/src/__tests__/__fixtures__/data.ts +7 -3
- package/valibot/src/__tests__/valibot.ts +1 -1
- package/valibot/src/index.ts +0 -1
- package/valibot/src/valibot.ts +55 -6
- package/vest/dist/vest.d.ts +18 -0
- 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/vest.ts +18 -0
- package/vine/dist/index.d.ts +0 -1
- package/vine/dist/vine.d.ts +25 -2
- 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 +2 -4
- package/vine/src/__tests__/Form.tsx +30 -6
- package/vine/src/__tests__/__fixtures__/data.ts +1 -1
- package/vine/src/index.ts +0 -1
- package/vine/src/vine.ts +38 -10
- package/yup/dist/yup.d.ts +18 -7
- package/yup/dist/yup.js +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.mjs +1 -1
- package/yup/dist/yup.modern.mjs +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/yup.ts +22 -11
- package/zod/dist/index.d.ts +0 -1
- package/zod/dist/zod.d.ts +25 -2
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +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.tsx +30 -6
- package/zod/src/__tests__/__fixtures__/data.ts +3 -3
- package/zod/src/index.ts +0 -1
- package/zod/src/zod.ts +40 -9
- package/arktype/dist/types.d.ts +0 -9
- package/arktype/src/types.ts +0 -18
- package/class-validator/dist/types.d.ts +0 -12
- package/class-validator/src/types.ts +0 -16
- package/computed-types/dist/types.d.ts +0 -2
- package/computed-types/src/types.ts +0 -13
- package/effect-ts/dist/types.d.ts +0 -4
- package/effect-ts/src/types.ts +0 -12
- package/io-ts/dist/types.d.ts +0 -7
- package/io-ts/src/types.ts +0 -18
- package/superstruct/dist/types.d.ts +0 -11
- package/superstruct/src/types.ts +0 -20
- package/typanion/dist/types.d.ts +0 -9
- package/typanion/src/types.ts +0 -20
- package/typebox/dist/types.d.ts +0 -4
- package/typebox/src/types.ts +0 -11
- package/valibot/dist/types.d.ts +0 -13
- package/valibot/src/types.ts +0 -34
- package/vine/dist/types.d.ts +0 -6
- package/vine/src/types.ts +0 -13
- package/zod/dist/types.d.ts +0 -13
- package/zod/src/types.ts +0 -22
package/yup/dist/yup.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as e,toNestErrors as t}from"@hookform/resolvers";import{appendErrors as r}from"react-hook-form";function o(o,n,
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as t}from"@hookform/resolvers";import{appendErrors as r}from"react-hook-form";function o(o,n,s){return void 0===n&&(n={}),void 0===s&&(s={}),function(a,i,c){try{return Promise.resolve(function(t,r){try{var u=(n.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(o["sync"===s.mode?"validateSync":"validate"](a,Object.assign({abortEarly:!1},n,{context:i}))).then(function(t){return c.shouldUseNativeValidation&&e({},c),{values:s.raw?Object.assign({},a):t,errors:{}}}))}catch(e){return r(e)}return u&&u.then?u.then(void 0,r):u}(0,function(e){if(!e.inner)throw e;return{values:{},errors:t((o=e,n=!c.shouldUseNativeValidation&&"all"===c.criteriaMode,(o.inner||[]).reduce(function(e,t){if(e[t.path]||(e[t.path]={message:t.message,type:t.type}),n){var o=e[t.path].types,s=o&&o[t.type];e[t.path]=r(t.path,n,e,t.type,s?[].concat(s,t.message):t.message)}return e},{})),c)};var o,n}))}catch(e){return Promise.reject(e)}}}export{o as yupResolver};
|
|
2
2
|
//# sourceMappingURL=yup.module.js.map
|
package/yup/dist/yup.modern.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as e,toNestErrors as t}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";function
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as t}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";function a(a,r={},s={}){return async(n,c,i)=>{try{r.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead");const t=await a["sync"===s.mode?"validateSync":"validate"](n,Object.assign({abortEarly:!1},r,{context:c}));return i.shouldUseNativeValidation&&e({},i),{values:s.raw?Object.assign({},n):t,errors:{}}}catch(e){if(!e.inner)throw e;return{values:{},errors:t((p=e,l=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,(p.inner||[]).reduce((e,t)=>{if(e[t.path]||(e[t.path]={message:t.message,type:t.type}),l){const a=e[t.path].types,r=a&&a[t.type];e[t.path]=o(t.path,l,e,t.type,r?[].concat(r,t.message):t.message)}return e},{})),i)}}var p,l}}export{a as yupResolver};
|
|
2
2
|
//# sourceMappingURL=yup.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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 */\
|
|
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 */\nfunction 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\n/**\n * Creates a resolver for react-hook-form using Yup schema validation\n * @param {Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>} schema - Yup validation schema\n * @param {Parameters<(typeof schema)['validate']>[1]} schemaOptions - Options to pass to Yup's validate/validateSync\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('async' | 'sync')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values instead of validated results\n * @returns {Resolver<Yup.InferType<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Yup.object({\n * name: Yup.string().required(),\n * age: Yup.number().required(),\n * });\n *\n * useForm({\n * resolver: yupResolver(schema)\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 mode?: 'async' | 'sync';\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 ? Object.assign({}, 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","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"],"mappings":"8HA8DgB,SAAAA,EACdC,EAGAC,EAA4D,CAAE,EAC9DC,EAGI,CAAA,GAEJ,OAAcC,MAAAA,EAAQC,EAASC,KAC7B,IACMJ,EAAcG,SAAoC,gBAAzBE,QAAQC,IAAIC,UAEvCC,QAAQC,KACN,iGAIJ,MAAMC,QAAeX,EACM,SAAzBE,EAAgBU,KAAkB,eAAiB,YAEnDT,EACAU,OAAOC,OAAO,CAAEC,YAAY,GAASd,EAAe,CAAEG,aAKxD,OAFAC,EAAQW,2BAA6BC,EAAuB,CAAA,EAAIZ,GAEzD,CACLF,OAAQD,EAAgBgB,IAAML,OAAOC,OAAO,CAAE,EAAEX,GAAUQ,EAC1DQ,OAAQ,GAEZ,CAAE,MAAOC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLjB,OAAQ,CAAE,EACVgB,OAAQG,GAvFdC,EAyFUH,EAxFVI,GAyFWnB,EAAQW,2BACkB,QAAzBX,EAAQoB,cAxFZF,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,CAAA,IAmEMtB,GAGN,CAjGJ,IACEkB,EACAC,CA+FE,CAEJ"}
|
package/yup/dist/yup.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as e,toNestErrors as t}from"@hookform/resolvers";import{appendErrors as r}from"react-hook-form";function o(o,n,
|
|
1
|
+
import{validateFieldsNatively as e,toNestErrors as t}from"@hookform/resolvers";import{appendErrors as r}from"react-hook-form";function o(o,n,s){return void 0===n&&(n={}),void 0===s&&(s={}),function(a,i,c){try{return Promise.resolve(function(t,r){try{var u=(n.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(o["sync"===s.mode?"validateSync":"validate"](a,Object.assign({abortEarly:!1},n,{context:i}))).then(function(t){return c.shouldUseNativeValidation&&e({},c),{values:s.raw?Object.assign({},a):t,errors:{}}}))}catch(e){return r(e)}return u&&u.then?u.then(void 0,r):u}(0,function(e){if(!e.inner)throw e;return{values:{},errors:t((o=e,n=!c.shouldUseNativeValidation&&"all"===c.criteriaMode,(o.inner||[]).reduce(function(e,t){if(e[t.path]||(e[t.path]={message:t.message,type:t.type}),n){var o=e[t.path].types,s=o&&o[t.type];e[t.path]=r(t.path,n,e,t.type,s?[].concat(s,t.message):t.message)}return e},{})),c)};var o,n}))}catch(e){return Promise.reject(e)}}}export{o as yupResolver};
|
|
2
2
|
//# sourceMappingURL=yup.module.js.map
|
|
@@ -1 +1 @@
|
|
|
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 */\
|
|
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 */\nfunction 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\n/**\n * Creates a resolver for react-hook-form using Yup schema validation\n * @param {Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>} schema - Yup validation schema\n * @param {Parameters<(typeof schema)['validate']>[1]} schemaOptions - Options to pass to Yup's validate/validateSync\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('async' | 'sync')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values instead of validated results\n * @returns {Resolver<Yup.InferType<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Yup.object({\n * name: Yup.string().required(),\n * age: Yup.number().required(),\n * });\n *\n * useForm({\n * resolver: yupResolver(schema)\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 mode?: 'async' | 'sync';\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 ? Object.assign({}, 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":"8HA8DM,SAAUA,EACdC,EAGAC,EACAC,GAKA,YAN4D,IAA5DD,IAAAA,EAA4D,CAAA,YAC5DC,IAAAA,EAGI,CAAE,GAEN,SAAcC,EAAQC,EAASC,GAAO,WAAIC,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,KALKC,SAAAA,GASN,OAFAb,EAAQc,2BAA6BC,EAAuB,CAAE,EAAEf,GAEzD,CACLF,OAAQD,EAAgBmB,IAAMP,OAAOC,OAAO,CAAA,EAAIZ,GAAUe,EAC1DI,OAAQ,CAAA,EACR,6DArBoCC,YAsB/BC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLrB,OAAQ,CAAE,EACVmB,OAAQI,GAvFdC,EAyFUH,EAxFVI,GAyFWvB,EAAQc,2BACkB,QAAzBd,EAAQwB,cAxFZF,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,CAAA,IAmEM1B,IA9FV,IACEsB,EACAC,CA+FE,GACF,CAAC,MAAAJ,GAAA,OAAAlB,QAAAiC,OAAAf,EACH,CAAA,CAAA"}
|
package/yup/dist/yup.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@hookform/resolvers"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form"],o):o((e||self).hookformResolversYup={},e.hookformResolvers,e.ReactHookForm)}(this,function(e,o,t){e.yupResolver=function(e,r,n){return void 0===r&&(r={}),void 0===n&&(n={}),function(s,a,i){try{return Promise.resolve(function(t,u){try{var c=(r.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(e["sync"===n.mode?"validateSync":"validate"](s,Object.assign({abortEarly:!1},r,{context:a}))).then(function(e){return i.shouldUseNativeValidation&&o.validateFieldsNatively({},i),{values:n.raw?s:e,errors:{}}}))}catch(e){return u(e)}return c&&c.then?c.then(void 0,u):c}(0,function(e){if(!e.inner)throw e;return{values:{},errors:o.toNestErrors((r=e,n=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,(r.inner||[]).reduce(function(e,o){if(e[o.path]||(e[o.path]={message:o.message,type:o.type}),n){var r=e[o.path].types,s=r&&r[o.type];e[o.path]=t.appendErrors(o.path,n,e,o.type,s?[].concat(s,o.message):o.message)}return e},{})),i)};var r,n}))}catch(e){return Promise.reject(e)}}}});
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@hookform/resolvers"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form"],o):o((e||self).hookformResolversYup={},e.hookformResolvers,e.ReactHookForm)}(this,function(e,o,t){e.yupResolver=function(e,r,n){return void 0===r&&(r={}),void 0===n&&(n={}),function(s,a,i){try{return Promise.resolve(function(t,u){try{var c=(r.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(e["sync"===n.mode?"validateSync":"validate"](s,Object.assign({abortEarly:!1},r,{context:a}))).then(function(e){return i.shouldUseNativeValidation&&o.validateFieldsNatively({},i),{values:n.raw?Object.assign({},s):e,errors:{}}}))}catch(e){return u(e)}return c&&c.then?c.then(void 0,u):c}(0,function(e){if(!e.inner)throw e;return{values:{},errors:o.toNestErrors((r=e,n=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,(r.inner||[]).reduce(function(e,o){if(e[o.path]||(e[o.path]={message:o.message,type:o.type}),n){var r=e[o.path].types,s=r&&r[o.type];e[o.path]=t.appendErrors(o.path,n,e,o.type,s?[].concat(s,o.message):o.message)}return e},{})),i)};var r,n}))}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=yup.umd.js.map
|
package/yup/dist/yup.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 */\
|
|
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 */\nfunction 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\n/**\n * Creates a resolver for react-hook-form using Yup schema validation\n * @param {Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>} schema - Yup validation schema\n * @param {Parameters<(typeof schema)['validate']>[1]} schemaOptions - Options to pass to Yup's validate/validateSync\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('async' | 'sync')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values instead of validated results\n * @returns {Resolver<Yup.InferType<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Yup.object({\n * name: Yup.string().required(),\n * age: Yup.number().required(),\n * });\n *\n * useForm({\n * resolver: yupResolver(schema)\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 mode?: 'async' | 'sync';\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 ? Object.assign({}, 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":"sYA8DM,SACJA,EAGAC,EACAC,GAKA,YAN4D,IAA5DD,IAAAA,EAA4D,CAAA,YAC5DC,IAAAA,EAGI,CAAE,GAEN,SAAcC,EAAQC,EAASC,GAAO,WAAIC,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,KALKC,SAAAA,GASN,OAFAb,EAAQc,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEf,GAEzD,CACLF,OAAQD,EAAgBmB,IAAMP,OAAOC,OAAO,CAAA,EAAIZ,GAAUe,EAC1DI,OAAQ,CAAA,EACR,6DArBoCC,YAsB/BC,GACP,IAAKA,EAAEC,MACL,MAAMD,EAGR,MAAO,CACLrB,OAAQ,CAAE,EACVmB,OAAQI,EAAAA,cAvFdC,EAyFUH,EAxFVI,GAyFWvB,EAAQc,2BACkB,QAAzBd,EAAQwB,cAxFZF,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,EAAYA,aAClCV,EAAMK,KACNJ,EACAG,EACAJ,EAAMO,KACNE,EACK,GAAgBE,OAAOF,EAAsBT,EAAMM,SACpDN,EAAMM,QAEd,CAEA,OAAOF,CACT,EACA,CAAA,IAmEM1B,IA9FV,IACEsB,EACAC,CA+FE,GACF,CAAC,MAAAJ,GAAA,OAAAlB,QAAAiC,OAAAf,EACH,CAAA,CAAA"}
|
package/yup/src/yup.ts
CHANGED
|
@@ -11,10 +11,10 @@ import * as Yup from 'yup';
|
|
|
11
11
|
* Why `path!` ? because it could be `undefined` in some case
|
|
12
12
|
* https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
function parseErrorSchema(
|
|
15
15
|
error: Yup.ValidationError,
|
|
16
16
|
validateAllFieldCriteria: boolean,
|
|
17
|
-
)
|
|
17
|
+
) {
|
|
18
18
|
return (error.inner || []).reduce<Record<string, FieldError>>(
|
|
19
19
|
(previous, error) => {
|
|
20
20
|
if (!previous[error.path!]) {
|
|
@@ -40,22 +40,33 @@ const parseErrorSchema = (
|
|
|
40
40
|
},
|
|
41
41
|
{},
|
|
42
42
|
);
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Creates a resolver for react-hook-form using Yup schema validation
|
|
47
|
+
* @param {Yup.ObjectSchema<TFieldValues> | ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>} schema - Yup validation schema
|
|
48
|
+
* @param {Parameters<(typeof schema)['validate']>[1]} schemaOptions - Options to pass to Yup's validate/validateSync
|
|
49
|
+
* @param {Object} resolverOptions - Additional resolver configuration
|
|
50
|
+
* @param {('async' | 'sync')} [resolverOptions.mode] - Validation mode
|
|
51
|
+
* @param {boolean} [resolverOptions.raw] - If true, returns raw values instead of validated results
|
|
52
|
+
* @returns {Resolver<Yup.InferType<typeof schema>>} A resolver function compatible with react-hook-form
|
|
53
|
+
* @example
|
|
54
|
+
* const schema = Yup.object({
|
|
55
|
+
* name: Yup.string().required(),
|
|
56
|
+
* age: Yup.number().required(),
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* useForm({
|
|
60
|
+
* resolver: yupResolver(schema)
|
|
61
|
+
* });
|
|
62
|
+
*/
|
|
45
63
|
export function yupResolver<TFieldValues extends FieldValues>(
|
|
46
64
|
schema:
|
|
47
65
|
| Yup.ObjectSchema<TFieldValues>
|
|
48
66
|
| ReturnType<typeof Yup.lazy<Yup.ObjectSchema<TFieldValues>>>,
|
|
49
67
|
schemaOptions: Parameters<(typeof schema)['validate']>[1] = {},
|
|
50
68
|
resolverOptions: {
|
|
51
|
-
/**
|
|
52
|
-
* @default async
|
|
53
|
-
*/
|
|
54
69
|
mode?: 'async' | 'sync';
|
|
55
|
-
/**
|
|
56
|
-
* Return the raw input values rather than the parsed values.
|
|
57
|
-
* @default false
|
|
58
|
-
*/
|
|
59
70
|
raw?: boolean;
|
|
60
71
|
} = {},
|
|
61
72
|
): Resolver<Yup.InferType<typeof schema>> {
|
|
@@ -78,7 +89,7 @@ export function yupResolver<TFieldValues extends FieldValues>(
|
|
|
78
89
|
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
|
|
79
90
|
|
|
80
91
|
return {
|
|
81
|
-
values: resolverOptions.raw ? values : result,
|
|
92
|
+
values: resolverOptions.raw ? Object.assign({}, values) : result,
|
|
82
93
|
errors: {},
|
|
83
94
|
};
|
|
84
95
|
} catch (e: any) {
|
package/zod/dist/index.d.ts
CHANGED
package/zod/dist/zod.d.ts
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { FieldValues, Resolver } from 'react-hook-form';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a resolver function for react-hook-form that validates form data using a Zod schema
|
|
5
|
+
* @param {z.ZodSchema<TFieldValues>} schema - The Zod schema used to validate the form data
|
|
6
|
+
* @param {Partial<z.ParseParams>} [schemaOptions] - Optional configuration options for Zod parsing
|
|
7
|
+
* @param {Object} [resolverOptions] - Optional resolver-specific configuration
|
|
8
|
+
* @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation
|
|
9
|
+
* @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data
|
|
10
|
+
* @returns {Resolver<z.infer<typeof schema>>} A resolver function compatible with react-hook-form
|
|
11
|
+
* @throws {Error} Throws if validation fails with a non-Zod error
|
|
12
|
+
* @example
|
|
13
|
+
* const schema = z.object({
|
|
14
|
+
* name: z.string().min(2),
|
|
15
|
+
* age: z.number().min(18)
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* useForm({
|
|
19
|
+
* resolver: zodResolver(schema)
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
export declare function zodResolver<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues, any, any>, schemaOptions?: Partial<z.ParseParams>, resolverOptions?: {
|
|
23
|
+
mode?: 'async' | 'sync';
|
|
24
|
+
raw?: boolean;
|
|
25
|
+
}): Resolver<z.infer<typeof schema>>;
|
package/zod/dist/zod.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=require("@hookform/resolvers"),e=require("react-hook-form")
|
|
1
|
+
var r=require("@hookform/resolvers"),e=require("react-hook-form");function o(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?Object.assign({},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
|
package/zod/dist/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {
|
|
1
|
+
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport { ZodError, z } from 'zod';\n\nconst isZodError = (error: any): error is ZodError =>\n Array.isArray(error?.errors);\n\nfunction 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\n/**\n * Creates a resolver function for react-hook-form that validates form data using a Zod schema\n * @param {z.ZodSchema<TFieldValues>} schema - The Zod schema used to validate the form data\n * @param {Partial<z.ParseParams>} [schemaOptions] - Optional configuration options for Zod parsing\n * @param {Object} [resolverOptions] - Optional resolver-specific configuration\n * @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation\n * @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data\n * @returns {Resolver<z.infer<typeof schema>>} A resolver function compatible with react-hook-form\n * @throws {Error} Throws if validation fails with a non-Zod error\n * @example\n * const schema = z.object({\n * name: z.string().min(2),\n * age: z.number().min(18)\n * });\n *\n * useForm({\n * resolver: zodResolver(schema)\n * });\n */\nexport function zodResolver<TFieldValues extends FieldValues>(\n schema: z.ZodSchema<TFieldValues, any, any>,\n schemaOptions?: Partial<z.ParseParams>,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw?: boolean;\n } = {},\n): Resolver<z.infer<typeof schema>> {\n return 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 ? Object.assign({}, 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}\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","Object","assign","_catch","Array","isArray","isZodError","toNestErrors","criteriaMode","reject"],"mappings":"kEAaA,SAASA,EACPC,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,GACzB,OAAAA,EAAWR,OAAOW,QAAQ,SAACC,GAAC,OAAKd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EAAYA,aAC1BX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAUoB,OACZ,CAEA,OAAOlB,CACT,qBAqBM,SACJmB,EACAC,EACAC,GAKA,YALAA,IAAAA,IAAAA,EAGI,CAAE,GAEQC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCAC9BD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAFlBC,SAAAA,GAMN,OAFAL,EAAQM,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIP,GAEzD,CACLxB,OAAQ,CAAA,EACRsB,OAAQD,EAAgBW,IAAMC,OAAOC,OAAO,CAAE,EAAEZ,GAAUO,EAC1D,4DAX8BM,CAAA,EAYzBjC,SAAAA,GACP,GA7Fa,SAACA,GAClB,OAAAkC,MAAMC,QAAa,MAALnC,OAAK,EAALA,EAAOF,OAAO,CA4FpBsC,CAAWpC,GACb,MAAO,CACLoB,OAAQ,CAAA,EACRtB,OAAQuC,EAAYA,aAClB1C,EACEK,EAAMF,QACLwB,EAAQM,2BACkB,QAAzBN,EAAQgB,cAEZhB,IAKN,MAAMtB,CACR,GACF,CAAC,MAAAU,GAAAa,OAAAA,QAAAgB,OAAA7B,EACH,CAAA,CAAA"}
|
package/zod/dist/zod.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";
|
|
1
|
+
import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";function n(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 c=n[a].types,f=c&&c[s.code];n[a]=o(a,e,n,t,f?[].concat(f,s.message):s.message)}r.shift()}return n}function s(o,s,t){return void 0===t&&(t={}),function(i,a,u){try{return Promise.resolve(function(e,n){try{var a=Promise.resolve(o["sync"===t.mode?"parse":"parseAsync"](i,s)).then(function(e){return u.shouldUseNativeValidation&&r({},u),{errors:{},values:t.raw?Object.assign({},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{s as zodResolver};
|
|
2
2
|
//# sourceMappingURL=zod.module.js.map
|
package/zod/dist/zod.modern.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as r,toNestErrors as o}from"@hookform/resolvers";import{appendErrors as
|
|
1
|
+
import{validateFieldsNatively as r,toNestErrors as o}from"@hookform/resolvers";import{appendErrors as e}from"react-hook-form";function s(r,o){const s={};for(;r.length;){const n=r[0],{code:t,message:a,path:i}=n,c=i.join(".");if(!s[c])if("unionErrors"in n){const r=n.unionErrors[0].errors[0];s[c]={message:r.message,type:r.code}}else s[c]={message:a,type:t};if("unionErrors"in n&&n.unionErrors.forEach(o=>o.errors.forEach(o=>r.push(o))),o){const r=s[c].types,a=r&&r[n.code];s[c]=e(c,o,s,t,a?[].concat(a,n.message):n.message)}r.shift()}return s}function n(e,n,t={}){return async(a,i,c)=>{try{const o=await e["sync"===t.mode?"parse":"parseAsync"](a,n);return c.shouldUseNativeValidation&&r({},c),{errors:{},values:t.raw?Object.assign({},a):o}}catch(r){if((r=>Array.isArray(null==r?void 0:r.errors))(r))return{values:{},errors:o(s(r.errors,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw r}}}export{n as zodResolver};
|
|
2
2
|
//# sourceMappingURL=zod.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.modern.mjs","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {
|
|
1
|
+
{"version":3,"file":"zod.modern.mjs","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport { ZodError, z } from 'zod';\n\nconst isZodError = (error: any): error is ZodError =>\n Array.isArray(error?.errors);\n\nfunction 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\n/**\n * Creates a resolver function for react-hook-form that validates form data using a Zod schema\n * @param {z.ZodSchema<TFieldValues>} schema - The Zod schema used to validate the form data\n * @param {Partial<z.ParseParams>} [schemaOptions] - Optional configuration options for Zod parsing\n * @param {Object} [resolverOptions] - Optional resolver-specific configuration\n * @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation\n * @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data\n * @returns {Resolver<z.infer<typeof schema>>} A resolver function compatible with react-hook-form\n * @throws {Error} Throws if validation fails with a non-Zod error\n * @example\n * const schema = z.object({\n * name: z.string().min(2),\n * age: z.number().min(18)\n * });\n *\n * useForm({\n * resolver: zodResolver(schema)\n * });\n */\nexport function zodResolver<TFieldValues extends FieldValues>(\n schema: z.ZodSchema<TFieldValues, any, any>,\n schemaOptions?: Partial<z.ParseParams>,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw?: boolean;\n } = {},\n): Resolver<z.infer<typeof schema>> {\n return 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 ? Object.assign({}, 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}\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","data","mode","shouldUseNativeValidation","validateFieldsNatively","raw","Object","assign","Array","isArray","isZodError","toNestErrors","criteriaMode"],"mappings":"8HAaA,SAASA,EACPC,EACAC,GAEA,MAAMC,EAAqC,GAC3C,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,CACT,CAqBgB,SAAAmB,EACdC,EACAC,EACAC,EAGI,IAEJ,OAAcC,MAAAA,EAAQC,EAAGC,KACvB,IACE,MAAMC,QAAaN,EACQ,SAAzBE,EAAgBK,KAAkB,QAAU,cAC5CJ,EAAQF,GAIV,OAFAI,EAAQG,2BAA6BC,EAAuB,GAAIJ,GAEzD,CACLzB,OAAQ,CAAiB,EACzBuB,OAAQD,EAAgBQ,IAAMC,OAAOC,OAAO,CAAE,EAAET,GAAUG,EAE9D,CAAE,MAAOxB,GACP,GA7FcA,IAClB+B,MAAMC,cAAQhC,SAAAA,EAAOF,QA4FbmC,CAAWjC,GACb,MAAO,CACLqB,OAAQ,CAAA,EACRvB,OAAQoC,EACNvC,EACEK,EAAMF,QACLyB,EAAQG,2BACkB,QAAzBH,EAAQY,cAEZZ,IAKN,MAAMvB,CACR,EAEJ"}
|
package/zod/dist/zod.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";
|
|
1
|
+
import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";function n(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 c=n[a].types,f=c&&c[s.code];n[a]=o(a,e,n,t,f?[].concat(f,s.message):s.message)}r.shift()}return n}function s(o,s,t){return void 0===t&&(t={}),function(i,a,u){try{return Promise.resolve(function(e,n){try{var a=Promise.resolve(o["sync"===t.mode?"parse":"parseAsync"](i,s)).then(function(e){return u.shouldUseNativeValidation&&r({},u),{errors:{},values:t.raw?Object.assign({},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{s as zodResolver};
|
|
2
2
|
//# sourceMappingURL=zod.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.module.js","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {
|
|
1
|
+
{"version":3,"file":"zod.module.js","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport { ZodError, z } from 'zod';\n\nconst isZodError = (error: any): error is ZodError =>\n Array.isArray(error?.errors);\n\nfunction 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\n/**\n * Creates a resolver function for react-hook-form that validates form data using a Zod schema\n * @param {z.ZodSchema<TFieldValues>} schema - The Zod schema used to validate the form data\n * @param {Partial<z.ParseParams>} [schemaOptions] - Optional configuration options for Zod parsing\n * @param {Object} [resolverOptions] - Optional resolver-specific configuration\n * @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation\n * @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data\n * @returns {Resolver<z.infer<typeof schema>>} A resolver function compatible with react-hook-form\n * @throws {Error} Throws if validation fails with a non-Zod error\n * @example\n * const schema = z.object({\n * name: z.string().min(2),\n * age: z.number().min(18)\n * });\n *\n * useForm({\n * resolver: zodResolver(schema)\n * });\n */\nexport function zodResolver<TFieldValues extends FieldValues>(\n schema: z.ZodSchema<TFieldValues, any, any>,\n schemaOptions?: Partial<z.ParseParams>,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw?: boolean;\n } = {},\n): Resolver<z.infer<typeof schema>> {\n return 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 ? Object.assign({}, 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}\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","Object","assign","_catch","Array","isArray","isZodError","toNestErrors","criteriaMode","reject"],"mappings":"8HAaA,SAASA,EACPC,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,GACzB,OAAAA,EAAWR,OAAOW,QAAQ,SAACC,GAAC,OAAKd,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,CAqBM,SAAUmB,EACdC,EACAC,EACAC,GAKA,YALAA,IAAAA,IAAAA,EAGI,CAAE,GAEQC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCAC9BD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAFlBC,SAAAA,GAMN,OAFAL,EAAQM,2BAA6BC,EAAuB,CAAA,EAAIP,GAEzD,CACLzB,OAAQ,CAAA,EACRuB,OAAQD,EAAgBW,IAAMC,OAAOC,OAAO,CAAE,EAAEZ,GAAUO,EAC1D,4DAX8BM,CAAA,EAYzBlC,SAAAA,GACP,GA7Fa,SAACA,GAClB,OAAAmC,MAAMC,QAAa,MAALpC,OAAK,EAALA,EAAOF,OAAO,CA4FpBuC,CAAWrC,GACb,MAAO,CACLqB,OAAQ,CAAA,EACRvB,OAAQwC,EACN3C,EACEK,EAAMF,QACLyB,EAAQM,2BACkB,QAAzBN,EAAQgB,cAEZhB,IAKN,MAAMvB,CACR,GACF,CAAC,MAAAU,GAAAc,OAAAA,QAAAgB,OAAA9B,EACH,CAAA,CAAA"}
|
package/zod/dist/zod.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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){
|
|
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){function n(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?Object.assign({},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
|
package/zod/dist/zod.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.umd.js","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {
|
|
1
|
+
{"version":3,"file":"zod.umd.js","sources":["../src/zod.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport { ZodError, z } from 'zod';\n\nconst isZodError = (error: any): error is ZodError =>\n Array.isArray(error?.errors);\n\nfunction 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\n/**\n * Creates a resolver function for react-hook-form that validates form data using a Zod schema\n * @param {z.ZodSchema<TFieldValues>} schema - The Zod schema used to validate the form data\n * @param {Partial<z.ParseParams>} [schemaOptions] - Optional configuration options for Zod parsing\n * @param {Object} [resolverOptions] - Optional resolver-specific configuration\n * @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation\n * @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data\n * @returns {Resolver<z.infer<typeof schema>>} A resolver function compatible with react-hook-form\n * @throws {Error} Throws if validation fails with a non-Zod error\n * @example\n * const schema = z.object({\n * name: z.string().min(2),\n * age: z.number().min(18)\n * });\n *\n * useForm({\n * resolver: zodResolver(schema)\n * });\n */\nexport function zodResolver<TFieldValues extends FieldValues>(\n schema: z.ZodSchema<TFieldValues, any, any>,\n schemaOptions?: Partial<z.ParseParams>,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw?: boolean;\n } = {},\n): Resolver<z.infer<typeof schema>> {\n return 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 ? Object.assign({}, 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}\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","Object","assign","_catch","Array","isArray","isZodError","toNestErrors","criteriaMode","reject"],"mappings":"wXAaA,SAASA,EACPC,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,GACzB,OAAAA,EAAWR,OAAOW,QAAQ,SAACC,GAAC,OAAKd,EAAUe,KAAKD,EAAE,EAAC,GAInDb,EAA0B,CAC5B,IAAMe,EAAQd,EAAOK,GAAOS,MACtBC,EAAWD,GAASA,EAAMZ,EAAMC,MAEtCH,EAAOK,GAASW,EAAYA,aAC1BX,EACAN,EACAC,EACAG,EACAY,EACK,GAAgBE,OAAOF,EAAsBb,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAUoB,OACZ,CAEA,OAAOlB,CACT,eAqBM,SACJmB,EACAC,EACAC,GAKA,YALAA,IAAAA,IAAAA,EAGI,CAAE,GAEQC,SAAAA,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCAC9BD,QAAAC,QACiBP,EACQ,SAAzBE,EAAgBM,KAAkB,QAAU,cAC5CL,EAAQF,IAAcQ,KAFlBC,SAAAA,GAMN,OAFAL,EAAQM,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIP,GAEzD,CACLxB,OAAQ,CAAA,EACRsB,OAAQD,EAAgBW,IAAMC,OAAOC,OAAO,CAAE,EAAEZ,GAAUO,EAC1D,4DAX8BM,CAAA,EAYzBjC,SAAAA,GACP,GA7Fa,SAACA,GAClB,OAAAkC,MAAMC,QAAa,MAALnC,OAAK,EAALA,EAAOF,OAAO,CA4FpBsC,CAAWpC,GACb,MAAO,CACLoB,OAAQ,CAAA,EACRtB,OAAQuC,EAAYA,aAClB1C,EACEK,EAAMF,QACLwB,EAAQM,2BACkB,QAAzBN,EAAQgB,cAEZhB,IAKN,MAAMtB,CACR,GACF,CAAC,MAAAU,GAAAa,OAAAA,QAAAgB,OAAA7B,EACH,CAAA,CAAA"}
|
|
@@ -12,16 +12,14 @@ const schema = z.object({
|
|
|
12
12
|
|
|
13
13
|
type FormData = z.infer<typeof schema> & { unusedProperty: string };
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
onSubmit
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function TestComponent({ onSubmit }: Props) {
|
|
15
|
+
function TestComponent({
|
|
16
|
+
onSubmit,
|
|
17
|
+
}: { onSubmit: (data: z.infer<typeof schema>) => void }) {
|
|
20
18
|
const {
|
|
21
19
|
register,
|
|
22
20
|
handleSubmit,
|
|
23
21
|
formState: { errors },
|
|
24
|
-
} = useForm
|
|
22
|
+
} = useForm({
|
|
25
23
|
resolver: zodResolver(schema), // Useful to check TypeScript regressions
|
|
26
24
|
});
|
|
27
25
|
|
|
@@ -50,3 +48,29 @@ test("form's validation with Zod and TypeScript's integration", async () => {
|
|
|
50
48
|
expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
|
|
51
49
|
expect(handleSubmit).not.toHaveBeenCalled();
|
|
52
50
|
});
|
|
51
|
+
|
|
52
|
+
export function TestComponentManualType({
|
|
53
|
+
onSubmit,
|
|
54
|
+
}: {
|
|
55
|
+
onSubmit: (data: FormData) => void;
|
|
56
|
+
}) {
|
|
57
|
+
const {
|
|
58
|
+
register,
|
|
59
|
+
handleSubmit,
|
|
60
|
+
formState: { errors },
|
|
61
|
+
} = useForm<z.infer<typeof schema>, undefined, FormData>({
|
|
62
|
+
resolver: zodResolver(schema), // Useful to check TypeScript regressions
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
67
|
+
<input {...register('username')} />
|
|
68
|
+
{errors.username && <span role="alert">{errors.username.message}</span>}
|
|
69
|
+
|
|
70
|
+
<input {...register('password')} />
|
|
71
|
+
{errors.password && <span role="alert">{errors.password.message}</span>}
|
|
72
|
+
|
|
73
|
+
<button type="submit">submit</button>
|
|
74
|
+
</form>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -41,7 +41,7 @@ export const schema = z
|
|
|
41
41
|
path: ['confirm'],
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
export const validData
|
|
44
|
+
export const validData = {
|
|
45
45
|
username: 'Doe',
|
|
46
46
|
password: 'Password123_',
|
|
47
47
|
repeatPassword: 'Password123_',
|
|
@@ -58,7 +58,7 @@ export const validData: z.input<typeof schema> = {
|
|
|
58
58
|
},
|
|
59
59
|
],
|
|
60
60
|
dateStr: '2020-01-01',
|
|
61
|
-
}
|
|
61
|
+
} as any as z.infer<typeof schema>;
|
|
62
62
|
|
|
63
63
|
export const invalidData = {
|
|
64
64
|
password: '___',
|
|
@@ -66,7 +66,7 @@ export const invalidData = {
|
|
|
66
66
|
birthYear: 'birthYear',
|
|
67
67
|
like: [{ id: 'z' }],
|
|
68
68
|
url: 'abc',
|
|
69
|
-
}
|
|
69
|
+
} as any as z.infer<typeof schema>;
|
|
70
70
|
|
|
71
71
|
export const fields: Record<InternalFieldName, Field['_f']> = {
|
|
72
72
|
username: {
|
package/zod/src/index.ts
CHANGED
package/zod/src/zod.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
FieldError,
|
|
4
|
+
FieldErrors,
|
|
5
|
+
FieldValues,
|
|
6
|
+
Resolver,
|
|
7
|
+
appendErrors,
|
|
8
|
+
} from 'react-hook-form';
|
|
3
9
|
import { ZodError, z } from 'zod';
|
|
4
|
-
import type { Resolver } from './types';
|
|
5
10
|
|
|
6
11
|
const isZodError = (error: any): error is ZodError =>
|
|
7
12
|
Array.isArray(error?.errors);
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
function parseErrorSchema(
|
|
10
15
|
zodErrors: z.ZodIssue[],
|
|
11
16
|
validateAllFieldCriteria: boolean,
|
|
12
|
-
)
|
|
17
|
+
) {
|
|
13
18
|
const errors: Record<string, FieldError> = {};
|
|
14
19
|
for (; zodErrors.length; ) {
|
|
15
20
|
const error = zodErrors[0];
|
|
@@ -54,11 +59,36 @@ const parseErrorSchema = (
|
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
return errors;
|
|
57
|
-
}
|
|
62
|
+
}
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Creates a resolver function for react-hook-form that validates form data using a Zod schema
|
|
66
|
+
* @param {z.ZodSchema<TFieldValues>} schema - The Zod schema used to validate the form data
|
|
67
|
+
* @param {Partial<z.ParseParams>} [schemaOptions] - Optional configuration options for Zod parsing
|
|
68
|
+
* @param {Object} [resolverOptions] - Optional resolver-specific configuration
|
|
69
|
+
* @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation
|
|
70
|
+
* @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data
|
|
71
|
+
* @returns {Resolver<z.infer<typeof schema>>} A resolver function compatible with react-hook-form
|
|
72
|
+
* @throws {Error} Throws if validation fails with a non-Zod error
|
|
73
|
+
* @example
|
|
74
|
+
* const schema = z.object({
|
|
75
|
+
* name: z.string().min(2),
|
|
76
|
+
* age: z.number().min(18)
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* useForm({
|
|
80
|
+
* resolver: zodResolver(schema)
|
|
81
|
+
* });
|
|
82
|
+
*/
|
|
83
|
+
export function zodResolver<TFieldValues extends FieldValues>(
|
|
84
|
+
schema: z.ZodSchema<TFieldValues, any, any>,
|
|
85
|
+
schemaOptions?: Partial<z.ParseParams>,
|
|
86
|
+
resolverOptions: {
|
|
87
|
+
mode?: 'async' | 'sync';
|
|
88
|
+
raw?: boolean;
|
|
89
|
+
} = {},
|
|
90
|
+
): Resolver<z.infer<typeof schema>> {
|
|
91
|
+
return async (values, _, options) => {
|
|
62
92
|
try {
|
|
63
93
|
const data = await schema[
|
|
64
94
|
resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'
|
|
@@ -68,7 +98,7 @@ export const zodResolver: Resolver =
|
|
|
68
98
|
|
|
69
99
|
return {
|
|
70
100
|
errors: {} as FieldErrors,
|
|
71
|
-
values: resolverOptions.raw ? values : data,
|
|
101
|
+
values: resolverOptions.raw ? Object.assign({}, values) : data,
|
|
72
102
|
};
|
|
73
103
|
} catch (error: any) {
|
|
74
104
|
if (isZodError(error)) {
|
|
@@ -88,3 +118,4 @@ export const zodResolver: Resolver =
|
|
|
88
118
|
throw error;
|
|
89
119
|
}
|
|
90
120
|
};
|
|
121
|
+
}
|
package/arktype/dist/types.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Type } from 'arktype';
|
|
2
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
3
|
-
export type Resolver = <T extends Type<any>>(schema: T, schemaOptions?: undefined, factoryOptions?: {
|
|
4
|
-
/**
|
|
5
|
-
* Return the raw input values rather than the parsed values.
|
|
6
|
-
* @default false
|
|
7
|
-
*/
|
|
8
|
-
raw?: boolean;
|
|
9
|
-
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
|
package/arktype/src/types.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Type } from 'arktype';
|
|
2
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
3
|
-
|
|
4
|
-
export type Resolver = <T extends Type<any>>(
|
|
5
|
-
schema: T,
|
|
6
|
-
schemaOptions?: undefined,
|
|
7
|
-
factoryOptions?: {
|
|
8
|
-
/**
|
|
9
|
-
* Return the raw input values rather than the parsed values.
|
|
10
|
-
* @default false
|
|
11
|
-
*/
|
|
12
|
-
raw?: boolean;
|
|
13
|
-
},
|
|
14
|
-
) => <TFieldValues extends FieldValues, TContext>(
|
|
15
|
-
values: TFieldValues,
|
|
16
|
-
context: TContext | undefined,
|
|
17
|
-
options: ResolverOptions<TFieldValues>,
|
|
18
|
-
) => ResolverResult<TFieldValues>;
|