@hookform/resolvers 3.4.2 → 3.6.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 +9 -8
- package/arktype/dist/arktype.js +1 -1
- package/arktype/dist/arktype.js.map +1 -1
- package/arktype/dist/arktype.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs.map +1 -1
- package/arktype/dist/arktype.module.js +1 -1
- package/arktype/dist/arktype.module.js.map +1 -1
- package/arktype/dist/arktype.umd.js +1 -1
- package/arktype/dist/arktype.umd.js.map +1 -1
- package/arktype/dist/types.d.ts +1 -1
- package/arktype/package.json +1 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +2 -2
- package/arktype/src/__tests__/Form.tsx +2 -2
- package/arktype/src/__tests__/__fixtures__/data.ts +8 -10
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +423 -32
- package/arktype/src/arktype.ts +10 -20
- package/arktype/src/types.ts +1 -1
- package/package.json +3 -3
- package/valibot/dist/types.d.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/package.json +2 -2
- package/valibot/src/__tests__/Form-native-validation.tsx +14 -14
- package/valibot/src/__tests__/Form.tsx +11 -11
- package/valibot/src/__tests__/__fixtures__/data.ts +43 -53
- package/valibot/src/__tests__/__snapshots__/valibot.ts.snap +50 -50
- package/valibot/src/__tests__/valibot.ts +13 -11
- package/valibot/src/types.ts +15 -3
- package/valibot/src/valibot.ts +55 -77
package/valibot/dist/valibot.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=require("@hookform/resolvers"),e=require("
|
|
1
|
+
var r=require("@hookform/resolvers"),e=require("react-hook-form"),t=require("valibot");function o(){return o=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},o.apply(this,arguments)}function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,o=new Array(e);t<e;t++)o[t]=r[t];return o}exports.valibotResolver=function(a,i,s){return void 0===s&&(s={}),function(u,l,c){try{var f=!c.shouldUseNativeValidation&&"all"===c.criteriaMode;return Promise.resolve(t.safeParseAsync(a,u,o({},i,{abortPipeEarly:!f}))).then(function(o){if(o.issues){for(var a,i={},l=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return n(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(r,e):void 0}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(o.issues);!(a=l()).done;){var v=a.value,y=t.getDotPath(v);if(y&&(i[y]||(i[y]={message:v.message,type:v.type}),f)){var p=i[y].types,m=p&&p[v.type];i[y]=e.appendErrors(y,f,i,v.type,m?[].concat(m,v.message):v.message)}}return{values:{},errors:r.toNestErrors(i,c)}}return{values:s.raw?u:o.output,errors:{}}})}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 { toNestErrors } from '@hookform/resolvers';\nimport
|
|
1
|
+
{"version":3,"file":"valibot.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, appendErrors, FieldValues } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(schema, values, {\n ...schemaOptions,\n abortPipeEarly: !validateAllFieldCriteria,\n });\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (const issue of result.issues) {\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","_extends","abortPipeEarly","then","result","issues","_step","errors","_iterator","_createForOfIteratorHelperLoose","done","issue","value","path","getDotPath","message","type","types","messages","appendErrors","concat","toNestErrors","raw","output","e","reject"],"mappings":"6bAME,SAACA,EAAQC,EAAeC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAcA,eAACX,EAAQG,EAAMS,EAAA,CAAA,EAC7CX,EAAa,CAChBY,gBAAiBP,MACjBQ,KAAA,SAHIC,GAMN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAGiCC,EAH3BC,EAAqC,CAAE,EAG7CC,2qBAAAC,CAAoBL,EAAOC,UAAMC,EAAAE,KAAAE,MAAE,KAAxBC,EAAKL,EAAAM,MAERC,EAAOC,EAAUA,WAACH,GAExB,GAAIE,IAEGN,EAAOM,KACVN,EAAOM,GAAQ,CAAEE,QAASJ,EAAMI,QAASC,KAAML,EAAMK,OAInDrB,GAA0B,CAC5B,IAAMsB,EAAQV,EAAOM,GAAMI,MACrBC,EAAWD,GAASA,EAAMN,EAAMK,MACtCT,EAAOM,GAAQM,EAAAA,aACbN,EACAlB,EACAY,EACAI,EAAMK,KACNE,EACK,GAAgBE,OACfF,EACAP,EAAMI,SAERJ,EAAMI,QAEb,CAEJ,CAGD,MAAO,CACLvB,OAAQ,GACRe,OAAQc,EAAAA,aAAad,EAAQb,GAEhC,CAGD,MAAO,CACLF,OAAQD,EAAgB+B,IAAM9B,EAAUY,EAAOmB,OAC/ChB,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAiB,GAAA1B,OAAAA,QAAA2B,OAAAD,EAAA,CAAA,CAAA"}
|
package/valibot/dist/valibot.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as r}from"@hookform/resolvers";import{
|
|
1
|
+
import{toNestErrors as r}from"@hookform/resolvers";import{appendErrors as e}from"react-hook-form";import{safeParseAsync as t,getDotPath as o}from"valibot";function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},n.apply(this,arguments)}function a(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,o=new Array(e);t<e;t++)o[t]=r[t];return o}var i=function(i,s,u){return void 0===u&&(u={}),function(l,c,f){try{var m=!f.shouldUseNativeValidation&&"all"===f.criteriaMode;return Promise.resolve(t(i,l,n({},s,{abortPipeEarly:!m}))).then(function(t){if(t.issues){for(var n,i={},s=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return a(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(r,e):void 0}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t.issues);!(n=s()).done;){var c=n.value,p=o(c);if(p&&(i[p]||(i[p]={message:c.message,type:c.type}),m)){var v=i[p].types,y=v&&v[c.type];i[p]=e(p,m,i,c.type,y?[].concat(y,c.message):c.message)}}return{values:{},errors:r(i,f)}}return{values:u.raw?l:t.output,errors:{}}})}catch(r){return Promise.reject(r)}}};export{i as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as
|
|
1
|
+
import{toNestErrors as r}from"@hookform/resolvers";import{appendErrors as t}from"react-hook-form";import{safeParseAsync as e,getDotPath as o}from"valibot";function s(){return s=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},s.apply(this,arguments)}const a=(a,n,i={})=>async(c,p,f)=>{const l=!f.shouldUseNativeValidation&&"all"===f.criteriaMode,u=await e(a,c,s({},n,{abortPipeEarly:!l}));if(u.issues){const e={};for(const r of u.issues){const s=o(r);if(s&&(e[s]||(e[s]={message:r.message,type:r.type}),l)){const o=e[s].types,a=o&&o[r.type];e[s]=t(s,l,e,r.type,a?[].concat(a,r.message):r.message)}}return{values:{},errors:r(e,f)}}return{values:i.raw?c:u.output,errors:{}}};export{a as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport
|
|
1
|
+
{"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, appendErrors, FieldValues } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(schema, values, {\n ...schemaOptions,\n abortPipeEarly: !validateAllFieldCriteria,\n });\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (const issue of result.issues) {\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["valibotResolver","schema","schemaOptions","resolverOptions","async","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","result","safeParseAsync","_extends","abortPipeEarly","issues","errors","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","toNestErrors","raw","output"],"mappings":"+XAKa,MAAAA,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAE,IAC5CC,MAAOC,EAAQC,EAAGC,KAEhB,MAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAG1CC,QAAeC,EAAeX,EAAQI,EAAMQ,EAAA,GAC7CX,EAAa,CAChBY,gBAAiBN,KAInB,GAAIG,EAAOI,OAAQ,CAEjB,MAAMC,EAAqC,CAAA,EAG3C,IAAK,MAAMC,KAASN,EAAOI,OAAQ,CAEjC,MAAMG,EAAOC,EAAWF,GAExB,GAAIC,IAEGF,EAAOE,KACVF,EAAOE,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDb,GAA0B,CAC5B,MAAMc,EAAQN,EAAOE,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCL,EAAOE,GAAQM,EACbN,EACAV,EACAQ,EACAC,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEb,CAEJ,CAGD,MAAO,CACLf,OAAQ,CAAA,EACRW,OAAQU,EAAaV,EAAQT,GAEhC,CAGD,MAAO,CACLF,OAAQF,EAAgBwB,IAAMtB,EAAUM,EAAOiB,OAC/CZ,OAAQ,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as r}from"@hookform/resolvers";import{
|
|
1
|
+
import{toNestErrors as r}from"@hookform/resolvers";import{appendErrors as e}from"react-hook-form";import{safeParseAsync as t,getDotPath as o}from"valibot";function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},n.apply(this,arguments)}function a(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,o=new Array(e);t<e;t++)o[t]=r[t];return o}var i=function(i,s,u){return void 0===u&&(u={}),function(l,c,f){try{var m=!f.shouldUseNativeValidation&&"all"===f.criteriaMode;return Promise.resolve(t(i,l,n({},s,{abortPipeEarly:!m}))).then(function(t){if(t.issues){for(var n,i={},s=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return a(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(r,e):void 0}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t.issues);!(n=s()).done;){var c=n.value,p=o(c);if(p&&(i[p]||(i[p]={message:c.message,type:c.type}),m)){var v=i[p].types,y=v&&v[c.type];i[p]=e(p,m,i,c.type,y?[].concat(y,c.message):c.message)}}return{values:{},errors:r(i,f)}}return{values:u.raw?l:t.output,errors:{}}})}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 { toNestErrors } from '@hookform/resolvers';\nimport
|
|
1
|
+
{"version":3,"file":"valibot.module.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, appendErrors, FieldValues } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(schema, values, {\n ...schemaOptions,\n abortPipeEarly: !validateAllFieldCriteria,\n });\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (const issue of result.issues) {\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["valibotResolver","schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","_extends","abortPipeEarly","then","result","issues","_step","errors","_iterator","_createForOfIteratorHelperLoose","done","issue","value","path","getDotPath","message","type","types","messages","appendErrors","concat","toNestErrors","raw","output","e","reject"],"mappings":"yeAKa,IAAAA,EACX,SAACC,EAAQC,EAAeC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAeX,EAAQG,EAAMS,EAAA,CAAA,EAC7CX,EAAa,CAChBY,gBAAiBP,MACjBQ,KAAA,SAHIC,GAMN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAGiCC,EAH3BC,EAAqC,CAAE,EAG7CC,2qBAAAC,CAAoBL,EAAOC,UAAMC,EAAAE,KAAAE,MAAE,KAAxBC,EAAKL,EAAAM,MAERC,EAAOC,EAAWH,GAExB,GAAIE,IAEGN,EAAOM,KACVN,EAAOM,GAAQ,CAAEE,QAASJ,EAAMI,QAASC,KAAML,EAAMK,OAInDrB,GAA0B,CAC5B,IAAMsB,EAAQV,EAAOM,GAAMI,MACrBC,EAAWD,GAASA,EAAMN,EAAMK,MACtCT,EAAOM,GAAQM,EACbN,EACAlB,EACAY,EACAI,EAAMK,KACNE,EACK,GAAgBE,OACfF,EACAP,EAAMI,SAERJ,EAAMI,QAEb,CAEJ,CAGD,MAAO,CACLvB,OAAQ,GACRe,OAAQc,EAAad,EAAQb,GAEhC,CAGD,MAAO,CACLF,OAAQD,EAAgB+B,IAAM9B,EAAUY,EAAOmB,OAC/ChB,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAiB,GAAA1B,OAAAA,QAAA2B,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(r
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("react-hook-form"),require("valibot")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form","valibot"],r):r((e||self).hookformResolversValibot={},e.hookformResolvers,e.ReactHookForm,e.valibot)}(this,function(e,r,t,o){function n(){return n=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},n.apply(this,arguments)}function a(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}e.valibotResolver=function(e,i,s){return void 0===s&&(s={}),function(l,u,f){try{var c=!f.shouldUseNativeValidation&&"all"===f.criteriaMode;return Promise.resolve(o.safeParseAsync(e,l,n({},i,{abortPipeEarly:!c}))).then(function(e){if(e.issues){for(var n,i={},u=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return a(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(e,r):void 0}}(e))){t&&(e=t);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.issues);!(n=u()).done;){var v=n.value,p=o.getDotPath(v);if(p&&(i[p]||(i[p]={message:v.message,type:v.type}),c)){var y=i[p].types,d=y&&y[v.type];i[p]=t.appendErrors(p,c,i,v.type,d?[].concat(d,v.message):v.message)}}return{values:{},errors:r.toNestErrors(i,f)}}return{values:s.raw?l:e.output,errors:{}}})}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 { toNestErrors } from '@hookform/resolvers';\nimport
|
|
1
|
+
{"version":3,"file":"valibot.umd.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, appendErrors, FieldValues } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(schema, values, {\n ...schemaOptions,\n abortPipeEarly: !validateAllFieldCriteria,\n });\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (const issue of result.issues) {\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","_extends","abortPipeEarly","then","result","issues","_step","errors","_iterator","_createForOfIteratorHelperLoose","done","issue","value","path","getDotPath","message","type","types","messages","appendErrors","concat","toNestErrors","raw","output","e","reject"],"mappings":"qwBAME,SAACA,EAAQC,EAAeC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAcA,eAACX,EAAQG,EAAMS,EAAA,CAAA,EAC7CX,EAAa,CAChBY,gBAAiBP,MACjBQ,KAAA,SAHIC,GAMN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAGiCC,EAH3BC,EAAqC,CAAE,EAG7CC,2qBAAAC,CAAoBL,EAAOC,UAAMC,EAAAE,KAAAE,MAAE,KAAxBC,EAAKL,EAAAM,MAERC,EAAOC,EAAUA,WAACH,GAExB,GAAIE,IAEGN,EAAOM,KACVN,EAAOM,GAAQ,CAAEE,QAASJ,EAAMI,QAASC,KAAML,EAAMK,OAInDrB,GAA0B,CAC5B,IAAMsB,EAAQV,EAAOM,GAAMI,MACrBC,EAAWD,GAASA,EAAMN,EAAMK,MACtCT,EAAOM,GAAQM,EAAAA,aACbN,EACAlB,EACAY,EACAI,EAAMK,KACNE,EACK,GAAgBE,OACfF,EACAP,EAAMI,SAERJ,EAAMI,QAEb,CAEJ,CAGD,MAAO,CACLvB,OAAQ,GACRe,OAAQc,EAAAA,aAAad,EAAQb,GAEhC,CAGD,MAAO,CACLF,OAAQD,EAAgB+B,IAAM9B,EAAUY,EAAOmB,OAC/ChB,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAiB,GAAA1B,OAAAA,QAAA2B,OAAAD,EAAA,CAAA,CAAA"}
|
package/valibot/package.json
CHANGED
|
@@ -2,22 +2,22 @@ import React from 'react';
|
|
|
2
2
|
import { useForm } from 'react-hook-form';
|
|
3
3
|
import { render, screen } from '@testing-library/react';
|
|
4
4
|
import user from '@testing-library/user-event';
|
|
5
|
-
import
|
|
5
|
+
import * as v from 'valibot';
|
|
6
6
|
import { valibotResolver } from '..';
|
|
7
7
|
|
|
8
|
-
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
|
9
|
-
const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
|
|
10
|
-
|
|
11
|
-
const schema =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
8
|
+
const USERNAME_REQUIRED_MESSAGE = 'username field is v.required';
|
|
9
|
+
const PASSWORD_REQUIRED_MESSAGE = 'password field is v.required';
|
|
10
|
+
|
|
11
|
+
const schema = v.object({
|
|
12
|
+
username: v.pipe(
|
|
13
|
+
v.string(USERNAME_REQUIRED_MESSAGE),
|
|
14
|
+
v.minLength(2, USERNAME_REQUIRED_MESSAGE),
|
|
15
|
+
),
|
|
16
|
+
password: v.pipe(
|
|
17
|
+
v.string(PASSWORD_REQUIRED_MESSAGE),
|
|
18
|
+
v.minLength(2, PASSWORD_REQUIRED_MESSAGE),
|
|
19
|
+
),
|
|
20
|
+
});
|
|
21
21
|
|
|
22
22
|
type FormData = { username: string; password: string };
|
|
23
23
|
|
|
@@ -2,22 +2,22 @@ import React from 'react';
|
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import user from '@testing-library/user-event';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
|
-
import
|
|
5
|
+
import * as v from 'valibot';
|
|
6
6
|
import { valibotResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
|
9
9
|
const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
|
|
10
10
|
|
|
11
|
-
const schema =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
11
|
+
const schema = v.object({
|
|
12
|
+
username: v.pipe(
|
|
13
|
+
v.string(USERNAME_REQUIRED_MESSAGE),
|
|
14
|
+
v.minLength(2, USERNAME_REQUIRED_MESSAGE),
|
|
15
|
+
),
|
|
16
|
+
password: v.pipe(
|
|
17
|
+
v.string(PASSWORD_REQUIRED_MESSAGE),
|
|
18
|
+
v.minLength(2, PASSWORD_REQUIRED_MESSAGE),
|
|
19
|
+
),
|
|
20
|
+
});
|
|
21
21
|
|
|
22
22
|
type FormData = { username: string; password: string };
|
|
23
23
|
|
|
@@ -1,62 +1,52 @@
|
|
|
1
1
|
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
|
-
import
|
|
3
|
-
object,
|
|
4
|
-
string,
|
|
5
|
-
minLength,
|
|
6
|
-
maxLength,
|
|
7
|
-
regex,
|
|
8
|
-
number,
|
|
9
|
-
minValue,
|
|
10
|
-
maxValue,
|
|
11
|
-
email,
|
|
12
|
-
array,
|
|
13
|
-
boolean,
|
|
14
|
-
required,
|
|
15
|
-
union,
|
|
16
|
-
variant,
|
|
17
|
-
literal,
|
|
18
|
-
} from 'valibot';
|
|
2
|
+
import * as v from 'valibot';
|
|
19
3
|
|
|
20
|
-
export const schema =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
[
|
|
36
|
-
string('Access token should be a string'),
|
|
37
|
-
number('Access token should be a number'),
|
|
38
|
-
],
|
|
39
|
-
'access token is required',
|
|
4
|
+
export const schema = v.object({
|
|
5
|
+
username: v.pipe(
|
|
6
|
+
v.string(),
|
|
7
|
+
v.minLength(2),
|
|
8
|
+
v.maxLength(30),
|
|
9
|
+
v.regex(/^\w+$/),
|
|
10
|
+
),
|
|
11
|
+
password: v.pipe(
|
|
12
|
+
v.string('New Password is required'),
|
|
13
|
+
v.regex(new RegExp('.*[A-Z].*'), 'One uppercase character'),
|
|
14
|
+
v.regex(new RegExp('.*[a-z].*'), 'One lowercase character'),
|
|
15
|
+
v.regex(new RegExp('.*\\d.*'), 'One number'),
|
|
16
|
+
v.regex(
|
|
17
|
+
new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
|
|
18
|
+
'One special character',
|
|
40
19
|
),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
20
|
+
v.minLength(8, 'Must be at least 8 characters in length'),
|
|
21
|
+
),
|
|
22
|
+
repeatPassword: v.string('Repeat Password is required'),
|
|
23
|
+
accessToken: v.union(
|
|
24
|
+
[
|
|
25
|
+
v.string('Access token should be a string'),
|
|
26
|
+
v.number('Access token should be a number'),
|
|
27
|
+
],
|
|
28
|
+
'access token is required',
|
|
29
|
+
),
|
|
30
|
+
birthYear: v.pipe(
|
|
31
|
+
v.number('Please enter your birth year'),
|
|
32
|
+
v.minValue(1900),
|
|
33
|
+
v.maxValue(2013),
|
|
34
|
+
),
|
|
35
|
+
email: v.pipe(v.string(), v.email('Invalid email address')),
|
|
36
|
+
tags: v.array(v.string('Tags should be strings')),
|
|
37
|
+
enabled: v.boolean(),
|
|
38
|
+
like: v.object({
|
|
39
|
+
id: v.number('Like id is required'),
|
|
40
|
+
name: v.pipe(
|
|
41
|
+
v.string('Like name is required'),
|
|
42
|
+
v.minLength(4, 'Too short'),
|
|
53
43
|
),
|
|
54
44
|
}),
|
|
55
|
-
);
|
|
45
|
+
});
|
|
56
46
|
|
|
57
|
-
export const schemaError = variant('type', [
|
|
58
|
-
object({ type: literal('a') }),
|
|
59
|
-
object({ type: literal('b') }),
|
|
47
|
+
export const schemaError = v.variant('type', [
|
|
48
|
+
v.object({ type: v.literal('a') }),
|
|
49
|
+
v.object({ type: v.literal('b') }),
|
|
60
50
|
]);
|
|
61
51
|
|
|
62
52
|
export const validSchemaErrorData = { type: 'a' };
|