@hookform/resolvers 3.2.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/src/ajv.ts +2 -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/src/arktype.ts +2 -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/src/__tests__/class-validator.ts +41 -0
- package/class-validator/src/class-validator.ts +6 -3
- package/computed-types/dist/computed-types.js +1 -1
- 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 +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/src/computed-types.ts +2 -2
- package/dist/index.d.ts +1 -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/dist/toNestErrors.d.ts +2 -0
- 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/io-ts.ts +2 -2
- 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/src/joi.ts +2 -2
- 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 +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 +3 -3
- package/package.json +26 -27
- 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/superstruct.ts +2 -2
- package/typanion/dist/typanion.js +1 -1
- 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 +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/src/typanion.ts +2 -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__/__fixtures__/data.ts +2 -7
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +57 -59
- package/typebox/src/typebox.ts +2 -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/src/__tests__/Form-native-validation.tsx +81 -0
- package/valibot/src/__tests__/Form.tsx +61 -0
- package/valibot/src/__tests__/__fixtures__/data.ts +2 -1
- package/valibot/src/__tests__/__snapshots__/valibot.ts.snap +339 -0
- package/valibot/src/__tests__/valibot.ts +77 -0
- package/valibot/src/valibot.ts +57 -42
- package/vest/dist/types.d.ts +4 -4
- package/vest/dist/vest.js +1 -1
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/vest.mjs +1 -1
- package/vest/dist/vest.modern.mjs +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -1
- package/vest/dist/vest.module.js +1 -1
- package/vest/dist/vest.module.js.map +1 -1
- package/vest/dist/vest.umd.js +1 -1
- package/vest/dist/vest.umd.js.map +1 -1
- package/vest/src/__tests__/vest.ts +13 -0
- package/vest/src/types.ts +10 -7
- package/vest/src/vest.ts +5 -5
- package/yup/dist/yup.d.ts +2 -2
- 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/__tests__/yup.ts +25 -31
- package/yup/src/yup.ts +6 -4
- 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/zod.ts +2 -2
- package/dist/toNestError.d.ts +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestErrors as o}from"@hookform/resolvers";import{Value as s}from"@sinclair/typebox/value";const t=(e,o)=>{const s={};for(;e.length;){const t=e[0],{type:a,message:i,path:n}=t,l=n.substring(1).replace(/\//g,".");if(s[l]||(s[l]={message:i,type:""+a}),o){const e=s[l].types,i=e&&e[""+a];s[l]=r(l,o,s,""+a,i?[].concat(i,t.message):t.message)}e.shift()}return s},a=r=>async(a,i,n)=>{const l=Array.from(s.Errors(r,a));return n.shouldUseNativeValidation&&e({},n),l.length?{values:{},errors:o(t(l,!n.shouldUseNativeValidation&&"all"===n.criteriaMode),n)}:{errors:{},values:a}};export{a as typeboxResolver};
|
|
2
2
|
//# sourceMappingURL=typebox.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.modern.mjs","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport {
|
|
1
|
+
{"version":3,"file":"typebox.modern.mjs","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(Value.Errors(schema, values));\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","path","_path","substring","replace","types","messages","appendErrors","concat","shift","typeboxResolver","schema","async","values","_","options","Array","from","Value","Errors","shouldUseNativeValidation","validateFieldsNatively","toNestErrors","criteriaMode"],"mappings":"8KAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,CAAA,EAC3C,KAAOF,EAAQG,QAAU,CACvB,MAAMC,EAAQJ,EAAQ,IAChBK,KAAEA,EAAIC,QAAEA,EAAOC,KAAEA,GAASH,EAC1BI,EAAQD,EAAKE,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOM,KACVN,EAAOM,GAAS,CAAEF,UAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,MAAMU,EAAQT,EAAOM,GAAOG,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOM,GAASK,EACdL,EACAP,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAQe,OACT,CAED,OAAOb,GAGIc,EACVC,GAAWC,MAAOC,EAAQC,EAAGC,KAC5B,MAAMnB,EAASoB,MAAMC,KAAKC,EAAMC,OAAOR,EAAQE,IAI/C,OAFAE,EAAQK,2BAA6BC,EAAuB,CAAE,EAAEN,GAE3DnB,EAAOC,OAOL,CACLgB,OAAQ,CAAA,EACRjB,OAAQ0B,EACN7B,EACEG,GACCmB,EAAQK,2BAAsD,QAAzBL,EAAQQ,cAEhDR,IAbK,CACLnB,OAAQ,CAAA,EACRiB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestErrors as o}from"@hookform/resolvers";import{Value as t}from"@sinclair/typebox/value";var a=function(e,o){for(var t={};e.length;){var a=e[0],s=a.type,i=a.message,n=a.path.substring(1).replace(/\//g,".");if(t[n]||(t[n]={message:i,type:""+s}),o){var l=t[n].types,m=l&&l[""+s];t[n]=r(n,o,t,""+s,m?[].concat(m,a.message):a.message)}e.shift()}return t},s=function(r){return function(s,i,n){try{var l=Array.from(t.Errors(r,s));return n.shouldUseNativeValidation&&e({},n),Promise.resolve(l.length?{values:{},errors:o(a(l,!n.shouldUseNativeValidation&&"all"===n.criteriaMode),n)}:{errors:{},values:s})}catch(r){return Promise.reject(r)}}};export{s as typeboxResolver};
|
|
2
2
|
//# sourceMappingURL=typebox.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.module.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport {
|
|
1
|
+
{"version":3,"file":"typebox.module.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(Value.Errors(schema, values));\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","typeboxResolver","schema","values","_","options","Array","from","Value","Errors","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"8KAKA,IAAMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EACdN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAQe,OACT,CAED,OAAOb,CACT,EAEac,EACX,SAACC,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAO,IACnC,IAAMlB,EAASmB,MAAMC,KAAKC,EAAMC,OAAOP,EAAQC,IAI/C,OAFAE,EAAQK,2BAA6BC,EAAuB,CAAA,EAAIN,GAShEO,QAAAC,QAPK1B,EAAOC,OAOL,CACLe,OAAQ,CAAE,EACVhB,OAAQ2B,EACN9B,EACEG,GACCkB,EAAQK,2BAAsD,QAAzBL,EAAQU,cAEhDV,IAbK,CACLlB,OAAQ,GACRgB,OAAAA,GAcN,CAAC,MAAAa,GAAAJ,OAAAA,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react-hook-form"),require("@hookform/resolvers"),require("@sinclair/typebox/value")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers","@sinclair/typebox/value"],r):r((e||self).hookformResolversTypebox={},e.ReactHookForm,e.hookformResolvers,e.value)}(this,function(e,r,o,
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react-hook-form"),require("@hookform/resolvers"),require("@sinclair/typebox/value")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers","@sinclair/typebox/value"],r):r((e||self).hookformResolversTypebox={},e.ReactHookForm,e.hookformResolvers,e.value)}(this,function(e,r,o,s){var t=function(e,o){for(var s={};e.length;){var t=e[0],a=t.type,i=t.message,l=t.path.substring(1).replace(/\//g,".");if(s[l]||(s[l]={message:i,type:""+a}),o){var n=s[l].types,f=n&&n[""+a];s[l]=r.appendErrors(l,o,s,""+a,f?[].concat(f,t.message):t.message)}e.shift()}return s};e.typeboxResolver=function(e){return function(r,a,i){try{var l=Array.from(s.Value.Errors(e,r));return i.shouldUseNativeValidation&&o.validateFieldsNatively({},i),Promise.resolve(l.length?{values:{},errors:o.toNestErrors(t(l,!i.shouldUseNativeValidation&&"all"===i.criteriaMode),i)}:{errors:{},values:r})}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=typebox.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.umd.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport {
|
|
1
|
+
{"version":3,"file":"typebox.umd.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(Value.Errors(schema, values));\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","schema","values","_","options","Array","from","Value","Errors","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"mcAKA,IAAMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EAAYA,aAC1BN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAQe,OACT,CAED,OAAOb,CACT,oBAGE,SAACc,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAO,IACnC,IAAMjB,EAASkB,MAAMC,KAAKC,EAAAA,MAAMC,OAAOP,EAAQC,IAI/C,OAFAE,EAAQK,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIN,GAShEO,QAAAC,QAPKzB,EAAOC,OAOL,CACLc,OAAQ,CAAE,EACVf,OAAQ0B,EAAAA,aACN7B,EACEG,GACCiB,EAAQK,2BAAsD,QAAzBL,EAAQU,cAEhDV,IAbK,CACLjB,OAAQ,GACRe,OAAAA,GAcN,CAAC,MAAAa,GAAAJ,OAAAA,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
2
|
import { Static, Type } from '@sinclair/typebox';
|
|
3
|
-
import { TypeSystem } from '@sinclair/typebox/system';
|
|
4
|
-
|
|
5
|
-
TypeSystem.CreateFormat('email', (value: string) => {
|
|
6
|
-
return /^\S+@\S+$/.test(value);
|
|
7
|
-
});
|
|
8
3
|
|
|
9
4
|
export const schema = Type.Object({
|
|
10
5
|
username: Type.String({
|
|
@@ -24,7 +19,7 @@ export const schema = Type.Object({
|
|
|
24
19
|
maximum: 2013,
|
|
25
20
|
}),
|
|
26
21
|
),
|
|
27
|
-
email: Type.Optional(Type.
|
|
22
|
+
email: Type.Optional(Type.RegExp(/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i)),
|
|
28
23
|
tags: Type.Array(Type.String()),
|
|
29
24
|
enabled: Type.Boolean(),
|
|
30
25
|
like: Type.Optional(
|
|
@@ -43,7 +38,7 @@ export const validData: Static<typeof schema> = {
|
|
|
43
38
|
password: 'Password123_',
|
|
44
39
|
repeatPassword: 'Password123_',
|
|
45
40
|
birthYear: 2000,
|
|
46
|
-
email: '
|
|
41
|
+
email: 'google@gmail.com',
|
|
47
42
|
tags: ['tag1', 'tag2'],
|
|
48
43
|
enabled: true,
|
|
49
44
|
accessToken: 'accessToken',
|
|
@@ -4,43 +4,43 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
|
|
|
4
4
|
{
|
|
5
5
|
"errors": {
|
|
6
6
|
"accessToken": {
|
|
7
|
-
"message": "
|
|
7
|
+
"message": "Required property",
|
|
8
8
|
"ref": undefined,
|
|
9
|
-
"type": "
|
|
9
|
+
"type": "45",
|
|
10
10
|
},
|
|
11
11
|
"birthYear": {
|
|
12
12
|
"message": "Expected number",
|
|
13
13
|
"ref": undefined,
|
|
14
|
-
"type": "
|
|
14
|
+
"type": "41",
|
|
15
15
|
},
|
|
16
16
|
"dateStr": {
|
|
17
|
-
"message": "
|
|
17
|
+
"message": "Required property",
|
|
18
18
|
"ref": undefined,
|
|
19
|
-
"type": "
|
|
19
|
+
"type": "45",
|
|
20
20
|
},
|
|
21
21
|
"email": {
|
|
22
|
-
"message": "Expected string to match
|
|
22
|
+
"message": "Expected string to match '^[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\\\\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$'",
|
|
23
23
|
"ref": {
|
|
24
24
|
"name": "email",
|
|
25
25
|
},
|
|
26
|
-
"type": "
|
|
26
|
+
"type": "52",
|
|
27
27
|
},
|
|
28
28
|
"enabled": {
|
|
29
|
-
"message": "
|
|
29
|
+
"message": "Required property",
|
|
30
30
|
"ref": undefined,
|
|
31
|
-
"type": "
|
|
31
|
+
"type": "45",
|
|
32
32
|
},
|
|
33
33
|
"like": [
|
|
34
34
|
{
|
|
35
35
|
"id": {
|
|
36
36
|
"message": "Expected number",
|
|
37
37
|
"ref": undefined,
|
|
38
|
-
"type": "
|
|
38
|
+
"type": "41",
|
|
39
39
|
},
|
|
40
40
|
"name": {
|
|
41
|
-
"message": "
|
|
41
|
+
"message": "Required property",
|
|
42
42
|
"ref": undefined,
|
|
43
|
-
"type": "
|
|
43
|
+
"type": "45",
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
],
|
|
@@ -49,24 +49,24 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
|
|
|
49
49
|
"ref": {
|
|
50
50
|
"name": "password",
|
|
51
51
|
},
|
|
52
|
-
"type": "
|
|
52
|
+
"type": "51",
|
|
53
53
|
},
|
|
54
54
|
"repeatPassword": {
|
|
55
|
-
"message": "
|
|
55
|
+
"message": "Required property",
|
|
56
56
|
"ref": undefined,
|
|
57
|
-
"type": "
|
|
57
|
+
"type": "45",
|
|
58
58
|
},
|
|
59
59
|
"tags": {
|
|
60
|
-
"message": "
|
|
60
|
+
"message": "Required property",
|
|
61
61
|
"ref": undefined,
|
|
62
|
-
"type": "
|
|
62
|
+
"type": "45",
|
|
63
63
|
},
|
|
64
64
|
"username": {
|
|
65
|
-
"message": "
|
|
65
|
+
"message": "Required property",
|
|
66
66
|
"ref": {
|
|
67
67
|
"name": "username",
|
|
68
68
|
},
|
|
69
|
-
"type": "
|
|
69
|
+
"type": "45",
|
|
70
70
|
},
|
|
71
71
|
},
|
|
72
72
|
"values": {},
|
|
@@ -77,50 +77,48 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
|
|
|
77
77
|
{
|
|
78
78
|
"errors": {
|
|
79
79
|
"accessToken": {
|
|
80
|
-
"message": "
|
|
80
|
+
"message": "Required property",
|
|
81
81
|
"ref": undefined,
|
|
82
|
-
"type": "
|
|
82
|
+
"type": "45",
|
|
83
83
|
"types": {
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"43": "Expected string",
|
|
87
|
-
"53": "Expected value of union",
|
|
84
|
+
"45": "Required property",
|
|
85
|
+
"61": "Expected union value",
|
|
88
86
|
},
|
|
89
87
|
},
|
|
90
88
|
"birthYear": {
|
|
91
89
|
"message": "Expected number",
|
|
92
90
|
"ref": undefined,
|
|
93
|
-
"type": "
|
|
91
|
+
"type": "41",
|
|
94
92
|
"types": {
|
|
95
|
-
"
|
|
93
|
+
"41": "Expected number",
|
|
96
94
|
},
|
|
97
95
|
},
|
|
98
96
|
"dateStr": {
|
|
99
|
-
"message": "
|
|
97
|
+
"message": "Required property",
|
|
100
98
|
"ref": undefined,
|
|
101
|
-
"type": "
|
|
99
|
+
"type": "45",
|
|
102
100
|
"types": {
|
|
103
|
-
"
|
|
104
|
-
"
|
|
101
|
+
"20": "Expected Date",
|
|
102
|
+
"45": "Required property",
|
|
105
103
|
},
|
|
106
104
|
},
|
|
107
105
|
"email": {
|
|
108
|
-
"message": "Expected string to match
|
|
106
|
+
"message": "Expected string to match '^[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\\\\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$'",
|
|
109
107
|
"ref": {
|
|
110
108
|
"name": "email",
|
|
111
109
|
},
|
|
112
|
-
"type": "
|
|
110
|
+
"type": "52",
|
|
113
111
|
"types": {
|
|
114
|
-
"
|
|
112
|
+
"52": "Expected string to match '^[a-z0-9!#$%&'*+/=?^_\`{|}~-]+(?:\\\\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$'",
|
|
115
113
|
},
|
|
116
114
|
},
|
|
117
115
|
"enabled": {
|
|
118
|
-
"message": "
|
|
116
|
+
"message": "Required property",
|
|
119
117
|
"ref": undefined,
|
|
120
|
-
"type": "
|
|
118
|
+
"type": "45",
|
|
121
119
|
"types": {
|
|
122
|
-
"
|
|
123
|
-
"
|
|
120
|
+
"14": "Expected boolean",
|
|
121
|
+
"45": "Required property",
|
|
124
122
|
},
|
|
125
123
|
},
|
|
126
124
|
"like": [
|
|
@@ -128,18 +126,18 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
|
|
|
128
126
|
"id": {
|
|
129
127
|
"message": "Expected number",
|
|
130
128
|
"ref": undefined,
|
|
131
|
-
"type": "
|
|
129
|
+
"type": "41",
|
|
132
130
|
"types": {
|
|
133
|
-
"
|
|
131
|
+
"41": "Expected number",
|
|
134
132
|
},
|
|
135
133
|
},
|
|
136
134
|
"name": {
|
|
137
|
-
"message": "
|
|
135
|
+
"message": "Required property",
|
|
138
136
|
"ref": undefined,
|
|
139
|
-
"type": "
|
|
137
|
+
"type": "45",
|
|
140
138
|
"types": {
|
|
141
|
-
"
|
|
142
|
-
"
|
|
139
|
+
"45": "Required property",
|
|
140
|
+
"53": "Expected string",
|
|
143
141
|
},
|
|
144
142
|
},
|
|
145
143
|
},
|
|
@@ -149,39 +147,39 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
|
|
|
149
147
|
"ref": {
|
|
150
148
|
"name": "password",
|
|
151
149
|
},
|
|
152
|
-
"type": "
|
|
150
|
+
"type": "51",
|
|
153
151
|
"types": {
|
|
154
|
-
"
|
|
155
|
-
"
|
|
152
|
+
"51": "Expected string length greater or equal to 8",
|
|
153
|
+
"52": "Expected string to match '^(.*[A-Za-z\\\\d].*)$'",
|
|
156
154
|
},
|
|
157
155
|
},
|
|
158
156
|
"repeatPassword": {
|
|
159
|
-
"message": "
|
|
157
|
+
"message": "Required property",
|
|
160
158
|
"ref": undefined,
|
|
161
|
-
"type": "
|
|
159
|
+
"type": "45",
|
|
162
160
|
"types": {
|
|
163
|
-
"
|
|
164
|
-
"
|
|
161
|
+
"45": "Required property",
|
|
162
|
+
"53": "Expected string",
|
|
165
163
|
},
|
|
166
164
|
},
|
|
167
165
|
"tags": {
|
|
168
|
-
"message": "
|
|
166
|
+
"message": "Required property",
|
|
169
167
|
"ref": undefined,
|
|
170
|
-
"type": "
|
|
168
|
+
"type": "45",
|
|
171
169
|
"types": {
|
|
172
|
-
"
|
|
173
|
-
"
|
|
170
|
+
"45": "Required property",
|
|
171
|
+
"6": "Expected array",
|
|
174
172
|
},
|
|
175
173
|
},
|
|
176
174
|
"username": {
|
|
177
|
-
"message": "
|
|
175
|
+
"message": "Required property",
|
|
178
176
|
"ref": {
|
|
179
177
|
"name": "username",
|
|
180
178
|
},
|
|
181
|
-
"type": "
|
|
179
|
+
"type": "45",
|
|
182
180
|
"types": {
|
|
183
|
-
"
|
|
184
|
-
"
|
|
181
|
+
"45": "Required property",
|
|
182
|
+
"53": "Expected string",
|
|
185
183
|
},
|
|
186
184
|
},
|
|
187
185
|
},
|
package/typebox/src/typebox.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';
|
|
2
|
-
import {
|
|
2
|
+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
3
|
import type { Resolver } from './types';
|
|
4
4
|
import { Value, ValueError } from '@sinclair/typebox/value';
|
|
5
5
|
|
|
@@ -53,7 +53,7 @@ export const typeboxResolver: Resolver =
|
|
|
53
53
|
|
|
54
54
|
return {
|
|
55
55
|
values: {},
|
|
56
|
-
errors:
|
|
56
|
+
errors: toNestErrors(
|
|
57
57
|
parseErrorSchema(
|
|
58
58
|
errors,
|
|
59
59
|
!options.shouldUseNativeValidation && options.criteriaMode === 'all',
|
package/valibot/dist/valibot.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=require("@hookform/resolvers"),e=require("valibot"),t=function(r){var
|
|
1
|
+
var r=require("@hookform/resolvers"),e=require("valibot"),t=require("react-hook-form"),o=function(r,e){for(var o={};r.issues.length;){var a=r.issues[0];if(a.path){var s=a.path.map(function(r){return r.key}).join(".");if(o[s]||(o[s]={message:a.message,type:a.validation}),e){var n=o[s].types,i=n&&n[a.validation];o[s]=t.appendErrors(s,e,o,a.validation,i?[].concat(i,a.message):a.message)}r.issues.shift()}}return o};exports.valibotResolver=function(t,a,s){return void 0===s&&(s={}),function(n,i,u){try{return Promise.resolve(function(r,o){try{var i=function(){function r(r){return{values:s.raw?n:r,errors:{}}}var o=Object.assign({},{abortEarly:!1,abortPipeEarly:!1},a);return"sync"===s.mode?r(e.parse(t,n,o)):Promise.resolve(e.parseAsync(t,n,o)).then(r)}()}catch(r){return o(r)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(t instanceof e.ValiError)return{values:{},errors:r.toNestErrors(o(t,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)};throw t}))}catch(r){return Promise.reject(r)}}};
|
|
2
2
|
//# sourceMappingURL=valibot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.js","sources":["../src/valibot.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"valibot.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport {\n BaseSchema,\n BaseSchemaAsync,\n ValiError,\n parse,\n parseAsync,\n} from 'valibot';\nimport { FieldErrors, FieldError, appendErrors } from 'react-hook-form';\nconst parseErrors = (\n valiErrors: ValiError,\n validateAllFieldCriteria: boolean,\n): FieldErrors => {\n const errors: Record<string, FieldError> = {};\n for (; valiErrors.issues.length; ) {\n const error = valiErrors.issues[0];\n if (!error.path) {\n continue;\n }\n const _path = error.path.map(({ key }) => key).join('.');\n\n if (!errors[_path]) {\n errors[_path] = { message: error.message, type: error.validation };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.validation];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n error.validation,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n valiErrors.issues.shift();\n }\n\n return errors;\n};\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const schemaOpts = Object.assign(\n {},\n {\n abortEarly: false,\n abortPipeEarly: false,\n },\n schemaOptions,\n );\n\n const parsed =\n resolverOptions.mode === 'sync'\n ? parse(schema as BaseSchema, values, schemaOpts)\n : await parseAsync(\n schema as BaseSchema | BaseSchemaAsync,\n values,\n schemaOpts,\n );\n\n return {\n values: resolverOptions.raw ? values : parsed,\n errors: {} as FieldErrors,\n };\n } catch (error) {\n if (error instanceof ValiError) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrors(\n error,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrors","valiErrors","validateAllFieldCriteria","errors","issues","length","error","path","_path","map","_ref","key","join","message","type","validation","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","_temp2","parsed","raw","schemaOpts","Object","assign","abortEarly","abortPipeEarly","mode","parse","parseAsync","then","_catch","ValiError","toNestErrors","shouldUseNativeValidation","criteriaMode","e","reject"],"mappings":"uFAUMA,EAAc,SAClBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAA,EACpCF,EAAWG,OAAOC,QAAU,CACjC,IAAMC,EAAQL,EAAWG,OAAO,GAChC,GAAKE,EAAMC,KAAX,CAGA,IAAMC,EAAQF,EAAMC,KAAKE,IAAI,SAAAC,UAAMA,EAAHC,GAAa,GAAEC,KAAK,KAMpD,GAJKT,EAAOK,KACVL,EAAOK,GAAS,CAAEK,QAASP,EAAMO,QAASC,KAAMR,EAAMS,aAGpDb,EAA0B,CAC5B,IAAMc,EAAQb,EAAOK,GAAOQ,MACtBC,EAAWD,GAASA,EAAMV,EAAMS,YAEtCZ,EAAOK,GAASU,EAAAA,aACdV,EACAN,EACAC,EACAG,EAAMS,WACNE,EACK,GAAgBE,OAAOF,EAAsBX,EAAMO,SACpDP,EAAMO,QAEb,CAEDZ,EAAWG,OAAOgB,OAtBjB,CAuBF,CAED,OAAOjB,CACT,0BAGE,SAACkB,EAAQC,EAAeC,GAAoB,gBAApBA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvB,WAAA,SAAAC,EAUIC,GASN,MAAO,CACLN,OAAQD,EAAgBQ,IAAMP,EAASM,EACvC3B,OAAQ,GACR,CArBF,IAAM6B,EAAaC,OAAOC,OACxB,CAAE,EACF,CACEC,YAAY,EACZC,gBAAgB,GAElBd,GAI+B,MAAN,SAAzBC,EAAgBc,KAAeR,EAC3BS,EAAKA,MAACjB,EAAsBG,EAAQQ,IAAWL,QAAAC,QACzCW,EAAAA,WACJlB,EACAG,EACAQ,IACDQ,KAAAX,EAMR,6DAxB0BY,CACvB,EAuBH,SAAQnC,GACP,GAAIA,aAAiBoC,EAAAA,UACnB,MAAO,CACLlB,OAAQ,GACRrB,OAAQwC,EAAAA,aACN3C,EACEM,GACCoB,EAAQkB,2BACkB,QAAzBlB,EAAQmB,cAEZnB,IAKN,MAAMpB,CACP,GACH,CAAC,MAAAwC,UAAAnB,QAAAoB,OAAAD,EAAA,CAAA,CAAA"}
|
package/valibot/dist/valibot.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{toNestErrors as r}from"@hookform/resolvers";import{parse as e,parseAsync as t,ValiError as o}from"valibot";import{appendErrors as n}from"react-hook-form";var a=function(r,e){for(var t={};r.issues.length;){var o=r.issues[0];if(o.path){var a=o.path.map(function(r){return r.key}).join(".");if(t[a]||(t[a]={message:o.message,type:o.validation}),e){var i=t[a].types,s=i&&i[o.validation];t[a]=n(a,e,t,o.validation,s?[].concat(s,o.message):o.message)}r.issues.shift()}}return t},i=function(n,i,s){return void 0===s&&(s={}),function(u,c,f){try{return Promise.resolve(function(r,o){try{var a=function(){function r(r){return{values:s.raw?u:r,errors:{}}}var o=Object.assign({},{abortEarly:!1,abortPipeEarly:!1},i);return"sync"===s.mode?r(e(n,u,o)):Promise.resolve(t(n,u,o)).then(r)}()}catch(r){return o(r)}return a&&a.then?a.then(void 0,o):a}(0,function(e){if(e instanceof o)return{values:{},errors:r(a(e,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw e}))}catch(r){return Promise.reject(r)}}};export{i as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{toNestErrors as o}from"@hookform/resolvers";import{parse as s,parseAsync as t,ValiError as e}from"valibot";import{appendErrors as a}from"react-hook-form";const r=(o,s)=>{const t={};for(;o.issues.length;){const e=o.issues[0];if(!e.path)continue;const r=e.path.map(({key:o})=>o).join(".");if(t[r]||(t[r]={message:e.message,type:e.validation}),s){const o=t[r].types,i=o&&o[e.validation];t[r]=a(r,s,t,e.validation,i?[].concat(i,e.message):e.message)}o.issues.shift()}return t},i=(a,i,n={})=>async(c,l,m)=>{try{const o=Object.assign({},{abortEarly:!1,abortPipeEarly:!1},i),e="sync"===n.mode?s(a,c,o):await t(a,c,o);return{values:n.raw?c:e,errors:{}}}catch(s){if(s instanceof e)return{values:{},errors:o(r(s,!m.shouldUseNativeValidation&&"all"===m.criteriaMode),m)};throw s}};export{i as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport {\n BaseSchema,\n BaseSchemaAsync,\n ValiError,\n parse,\n parseAsync,\n} from 'valibot';\nimport { FieldErrors, FieldError, appendErrors } from 'react-hook-form';\nconst parseErrors = (\n valiErrors: ValiError,\n validateAllFieldCriteria: boolean,\n): FieldErrors => {\n const errors: Record<string, FieldError> = {};\n for (; valiErrors.issues.length; ) {\n const error = valiErrors.issues[0];\n if (!error.path) {\n continue;\n }\n const _path = error.path.map(({ key }) => key).join('.');\n\n if (!errors[_path]) {\n errors[_path] = { message: error.message, type: error.validation };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.validation];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n error.validation,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n valiErrors.issues.shift();\n }\n\n return errors;\n};\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const schemaOpts = Object.assign(\n {},\n {\n abortEarly: false,\n abortPipeEarly: false,\n },\n schemaOptions,\n );\n\n const parsed =\n resolverOptions.mode === 'sync'\n ? parse(schema as BaseSchema, values, schemaOpts)\n : await parseAsync(\n schema as BaseSchema | BaseSchemaAsync,\n values,\n schemaOpts,\n );\n\n return {\n values: resolverOptions.raw ? values : parsed,\n errors: {} as FieldErrors,\n };\n } catch (error) {\n if (error instanceof ValiError) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrors(\n error,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrors","valiErrors","validateAllFieldCriteria","errors","issues","length","error","path","_path","map","key","join","message","type","validation","types","messages","appendErrors","concat","shift","valibotResolver","schema","schemaOptions","resolverOptions","async","values","_","options","schemaOpts","Object","assign","abortEarly","abortPipeEarly","parsed","mode","parse","parseAsync","raw","ValiError","toNestErrors","shouldUseNativeValidation","criteriaMode"],"mappings":"iKAUA,MAAMA,EAAcA,CAClBC,EACAC,KAEA,MAAMC,EAAqC,CAAE,EAC7C,KAAOF,EAAWG,OAAOC,QAAU,CACjC,MAAMC,EAAQL,EAAWG,OAAO,GAChC,IAAKE,EAAMC,KACT,SAEF,MAAMC,EAAQF,EAAMC,KAAKE,IAAI,EAAGC,SAAUA,GAAKC,KAAK,KAMpD,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAEI,QAASN,EAAMM,QAASC,KAAMP,EAAMQ,aAGpDZ,EAA0B,CAC5B,MAAMa,EAAQZ,EAAOK,GAAOO,MACtBC,EAAWD,GAASA,EAAMT,EAAMQ,YAEtCX,EAAOK,GAASS,EACdT,EACAN,EACAC,EACAG,EAAMQ,WACNE,EACK,GAAgBE,OAAOF,EAAsBV,EAAMM,SACpDN,EAAMM,QAEb,CAEDX,EAAWG,OAAOe,OACnB,CAED,OAAOhB,GAGIiB,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAE,IAC5CC,MAAOC,EAAQC,EAAGC,KAChB,IACE,MAAMC,EAAaC,OAAOC,OACxB,CAAE,EACF,CACEC,YAAY,EACZC,gBAAgB,GAElBV,GAGIW,EACqB,SAAzBV,EAAgBW,KACZC,EAAMd,EAAsBI,EAAQG,SAC9BQ,EACJf,EACAI,EACAG,GAGR,MAAO,CACLH,OAAQF,EAAgBc,IAAMZ,EAASQ,EACvC9B,OAAQ,GAEX,CAAC,MAAOG,GACP,GAAIA,aAAiBgC,EACnB,MAAO,CACLb,OAAQ,CAAE,EACVtB,OAAQoC,EACNvC,EACEM,GACCqB,EAAQa,2BACkB,QAAzBb,EAAQc,cAEZd,IAKN,MAAMrB,CACP"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{toNestErrors as r}from"@hookform/resolvers";import{parse as e,parseAsync as t,ValiError as o}from"valibot";import{appendErrors as n}from"react-hook-form";var a=function(r,e){for(var t={};r.issues.length;){var o=r.issues[0];if(o.path){var a=o.path.map(function(r){return r.key}).join(".");if(t[a]||(t[a]={message:o.message,type:o.validation}),e){var i=t[a].types,s=i&&i[o.validation];t[a]=n(a,e,t,o.validation,s?[].concat(s,o.message):o.message)}r.issues.shift()}}return t},i=function(n,i,s){return void 0===s&&(s={}),function(u,c,f){try{return Promise.resolve(function(r,o){try{var a=function(){function r(r){return{values:s.raw?u:r,errors:{}}}var o=Object.assign({},{abortEarly:!1,abortPipeEarly:!1},i);return"sync"===s.mode?r(e(n,u,o)):Promise.resolve(t(n,u,o)).then(r)}()}catch(r){return o(r)}return a&&a.then?a.then(void 0,o):a}(0,function(e){if(e instanceof o)return{values:{},errors:r(a(e,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw e}))}catch(r){return Promise.reject(r)}}};export{i as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.module.js","sources":["../src/valibot.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"valibot.module.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport {\n BaseSchema,\n BaseSchemaAsync,\n ValiError,\n parse,\n parseAsync,\n} from 'valibot';\nimport { FieldErrors, FieldError, appendErrors } from 'react-hook-form';\nconst parseErrors = (\n valiErrors: ValiError,\n validateAllFieldCriteria: boolean,\n): FieldErrors => {\n const errors: Record<string, FieldError> = {};\n for (; valiErrors.issues.length; ) {\n const error = valiErrors.issues[0];\n if (!error.path) {\n continue;\n }\n const _path = error.path.map(({ key }) => key).join('.');\n\n if (!errors[_path]) {\n errors[_path] = { message: error.message, type: error.validation };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.validation];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n error.validation,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n valiErrors.issues.shift();\n }\n\n return errors;\n};\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const schemaOpts = Object.assign(\n {},\n {\n abortEarly: false,\n abortPipeEarly: false,\n },\n schemaOptions,\n );\n\n const parsed =\n resolverOptions.mode === 'sync'\n ? parse(schema as BaseSchema, values, schemaOpts)\n : await parseAsync(\n schema as BaseSchema | BaseSchemaAsync,\n values,\n schemaOpts,\n );\n\n return {\n values: resolverOptions.raw ? values : parsed,\n errors: {} as FieldErrors,\n };\n } catch (error) {\n if (error instanceof ValiError) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrors(\n error,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrors","valiErrors","validateAllFieldCriteria","errors","issues","length","error","path","_path","map","_ref","key","join","message","type","validation","types","messages","appendErrors","concat","shift","valibotResolver","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","_temp2","parsed","raw","schemaOpts","Object","assign","abortEarly","abortPipeEarly","mode","parse","parseAsync","then","_catch","ValiError","toNestErrors","shouldUseNativeValidation","criteriaMode","e","reject"],"mappings":"iKAUA,IAAMA,EAAc,SAClBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAA,EACpCF,EAAWG,OAAOC,QAAU,CACjC,IAAMC,EAAQL,EAAWG,OAAO,GAChC,GAAKE,EAAMC,KAAX,CAGA,IAAMC,EAAQF,EAAMC,KAAKE,IAAI,SAAAC,UAAMA,EAAHC,GAAa,GAAEC,KAAK,KAMpD,GAJKT,EAAOK,KACVL,EAAOK,GAAS,CAAEK,QAASP,EAAMO,QAASC,KAAMR,EAAMS,aAGpDb,EAA0B,CAC5B,IAAMc,EAAQb,EAAOK,GAAOQ,MACtBC,EAAWD,GAASA,EAAMV,EAAMS,YAEtCZ,EAAOK,GAASU,EACdV,EACAN,EACAC,EACAG,EAAMS,WACNE,EACK,GAAgBE,OAAOF,EAAsBX,EAAMO,SACpDP,EAAMO,QAEb,CAEDZ,EAAWG,OAAOgB,OAtBjB,CAuBF,CAED,OAAOjB,CACT,EAEakB,EACX,SAACC,EAAQC,EAAeC,GAAoB,gBAApBA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvB,WAAA,SAAAC,EAUIC,GASN,MAAO,CACLN,OAAQD,EAAgBQ,IAAMP,EAASM,EACvC5B,OAAQ,GACR,CArBF,IAAM8B,EAAaC,OAAOC,OACxB,CAAE,EACF,CACEC,YAAY,EACZC,gBAAgB,GAElBd,GAI+B,MAAN,SAAzBC,EAAgBc,KAAeR,EAC3BS,EAAMjB,EAAsBG,EAAQQ,IAAWL,QAAAC,QACzCW,EACJlB,EACAG,EACAQ,IACDQ,KAAAX,EAMR,6DAxB0BY,CACvB,EAuBH,SAAQpC,GACP,GAAIA,aAAiBqC,EACnB,MAAO,CACLlB,OAAQ,GACRtB,OAAQyC,EACN5C,EACEM,GACCqB,EAAQkB,2BACkB,QAAzBlB,EAAQmB,cAEZnB,IAKN,MAAMrB,CACP,GACH,CAAC,MAAAyC,UAAAnB,QAAAoB,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("valibot")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","valibot"],r):r((e||self).hookformResolversValibot={},e.hookformResolvers,e.valibot)}(this,function(e,r,o){var
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("valibot"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","valibot","react-hook-form"],r):r((e||self).hookformResolversValibot={},e.hookformResolvers,e.valibot,e.ReactHookForm)}(this,function(e,r,o,t){var s=function(e,r){for(var o={};e.issues.length;){var s=e.issues[0];if(s.path){var i=s.path.map(function(e){return e.key}).join(".");if(o[i]||(o[i]={message:s.message,type:s.validation}),r){var n=o[i].types,a=n&&n[s.validation];o[i]=t.appendErrors(i,r,o,s.validation,a?[].concat(a,s.message):s.message)}e.issues.shift()}}return o};e.valibotResolver=function(e,t,i){return void 0===i&&(i={}),function(n,a,f){try{return Promise.resolve(function(r,s){try{var a=function(){function r(e){return{values:i.raw?n:e,errors:{}}}var s=Object.assign({},{abortEarly:!1,abortPipeEarly:!1},t);return"sync"===i.mode?r(o.parse(e,n,s)):Promise.resolve(o.parseAsync(e,n,s)).then(r)}()}catch(e){return s(e)}return a&&a.then?a.then(void 0,s):a}(0,function(e){if(e instanceof o.ValiError)return{values:{},errors:r.toNestErrors(s(e,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw e}))}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=valibot.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.umd.js","sources":["../src/valibot.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"valibot.umd.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport {\n BaseSchema,\n BaseSchemaAsync,\n ValiError,\n parse,\n parseAsync,\n} from 'valibot';\nimport { FieldErrors, FieldError, appendErrors } from 'react-hook-form';\nconst parseErrors = (\n valiErrors: ValiError,\n validateAllFieldCriteria: boolean,\n): FieldErrors => {\n const errors: Record<string, FieldError> = {};\n for (; valiErrors.issues.length; ) {\n const error = valiErrors.issues[0];\n if (!error.path) {\n continue;\n }\n const _path = error.path.map(({ key }) => key).join('.');\n\n if (!errors[_path]) {\n errors[_path] = { message: error.message, type: error.validation };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[error.validation];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n error.validation,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n valiErrors.issues.shift();\n }\n\n return errors;\n};\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n try {\n const schemaOpts = Object.assign(\n {},\n {\n abortEarly: false,\n abortPipeEarly: false,\n },\n schemaOptions,\n );\n\n const parsed =\n resolverOptions.mode === 'sync'\n ? parse(schema as BaseSchema, values, schemaOpts)\n : await parseAsync(\n schema as BaseSchema | BaseSchemaAsync,\n values,\n schemaOpts,\n );\n\n return {\n values: resolverOptions.raw ? values : parsed,\n errors: {} as FieldErrors,\n };\n } catch (error) {\n if (error instanceof ValiError) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrors(\n error,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n throw error;\n }\n };\n"],"names":["parseErrors","valiErrors","validateAllFieldCriteria","errors","issues","length","error","path","_path","map","_ref","key","join","message","type","validation","types","messages","appendErrors","concat","shift","schema","schemaOptions","resolverOptions","values","_","options","Promise","resolve","_temp2","parsed","raw","schemaOpts","Object","assign","abortEarly","abortPipeEarly","mode","parse","parseAsync","then","_catch","ValiError","toNestErrors","shouldUseNativeValidation","criteriaMode","e","reject"],"mappings":"qaAUA,IAAMA,EAAc,SAClBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAA,EACpCF,EAAWG,OAAOC,QAAU,CACjC,IAAMC,EAAQL,EAAWG,OAAO,GAChC,GAAKE,EAAMC,KAAX,CAGA,IAAMC,EAAQF,EAAMC,KAAKE,IAAI,SAAAC,UAAMA,EAAHC,GAAa,GAAEC,KAAK,KAMpD,GAJKT,EAAOK,KACVL,EAAOK,GAAS,CAAEK,QAASP,EAAMO,QAASC,KAAMR,EAAMS,aAGpDb,EAA0B,CAC5B,IAAMc,EAAQb,EAAOK,GAAOQ,MACtBC,EAAWD,GAASA,EAAMV,EAAMS,YAEtCZ,EAAOK,GAASU,EAAAA,aACdV,EACAN,EACAC,EACAG,EAAMS,WACNE,EACK,GAAgBE,OAAOF,EAAsBX,EAAMO,SACpDP,EAAMO,QAEb,CAEDZ,EAAWG,OAAOgB,OAtBjB,CAuBF,CAED,OAAOjB,CACT,oBAGE,SAACkB,EAAQC,EAAeC,GAAoB,gBAApBA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAW,IAAA,OAAAC,QAAAC,gCACvB,WAAA,SAAAC,EAUIC,GASN,MAAO,CACLN,OAAQD,EAAgBQ,IAAMP,EAASM,EACvC3B,OAAQ,GACR,CArBF,IAAM6B,EAAaC,OAAOC,OACxB,CAAE,EACF,CACEC,YAAY,EACZC,gBAAgB,GAElBd,GAI+B,MAAN,SAAzBC,EAAgBc,KAAeR,EAC3BS,EAAKA,MAACjB,EAAsBG,EAAQQ,IAAWL,QAAAC,QACzCW,EAAAA,WACJlB,EACAG,EACAQ,IACDQ,KAAAX,EAMR,6DAxB0BY,CACvB,EAuBH,SAAQnC,GACP,GAAIA,aAAiBoC,EAAAA,UACnB,MAAO,CACLlB,OAAQ,GACRrB,OAAQwC,EAAAA,aACN3C,EACEM,GACCoB,EAAQkB,2BACkB,QAAzBlB,EAAQmB,cAEZnB,IAKN,MAAMpB,CACP,GACH,CAAC,MAAAwC,UAAAnB,QAAAoB,OAAAD,EAAA,CAAA,CAAA"}
|