UEA-Prodem

This commit is contained in:
2026-06-10 12:38:42 -03:00
parent 3f33154e16
commit c41625e542
9352 changed files with 1128292 additions and 14752 deletions
@@ -0,0 +1,2 @@
import { Resolver } from './types';
export declare const ataResolver: Resolver;
+2
View File
@@ -0,0 +1,2 @@
var r=require("@hookform/resolvers"),e=require("ata-validator"),a=require("react-hook-form"),s=function(r,e){for(var s={},t=0;t<r.length;t+=1){var o=r[t],i=("required"===o.keyword?o.instancePath+"/"+o.params.missingProperty:o.instancePath).substring(1).replace(/\//g,".");if(s[i]||(s[i]={message:o.message,type:o.keyword}),e){var n=s[i].types,l=n&&n[o.keyword];s[i]=a.appendErrors(i,e,s,o.keyword,l?[].concat(l,o.message||""):o.message)}}return s};exports.ataResolver=function(a,t,o){void 0===o&&(o={});var i=new e.Validator(a,t);return function(e,a,t){try{var n=i.validate(e);return t.shouldUseNativeValidation&&r.validateFieldsNatively({},t),Promise.resolve(n.valid?{values:o.raw?Object.assign({},e):e,errors:{}}:{values:{},errors:r.toNestErrors(s(n.errors,!t.shouldUseNativeValidation&&"all"===t.criteriaMode),t)})}catch(r){return Promise.reject(r)}}};
//# sourceMappingURL=ata-validator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ata-validator.js","sources":["../src/ata-validator.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { ValidationError, Validator } from 'ata-validator';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n ataErrors: ValidationError[],\n validateAllFieldCriteria: boolean,\n) => {\n const parsedErrors: Record<string, FieldError> = {};\n\n for (let index = 0; index < ataErrors.length; index += 1) {\n const error = ataErrors[index];\n\n const instancePath =\n error.keyword === 'required'\n ? `${error.instancePath}/${error.params.missingProperty}`\n : error.instancePath;\n\n const path = instancePath.substring(1).replace(/\\//g, '.');\n\n if (!parsedErrors[path]) {\n parsedErrors[path] = {\n message: error.message,\n type: error.keyword,\n };\n }\n\n if (validateAllFieldCriteria) {\n const types = parsedErrors[path].types;\n const messages = types && types[error.keyword];\n\n parsedErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n parsedErrors,\n error.keyword,\n messages\n ? ([] as string[]).concat(messages as string[], error.message || '')\n : error.message,\n ) as FieldError;\n }\n }\n\n return parsedErrors;\n};\n\nexport const ataResolver: Resolver = (\n schema,\n schemaOptions,\n resolverOptions = {},\n) => {\n const validator = new Validator(schema, schemaOptions);\n return async (values, _, options) => {\n const result = validator.validate(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return result.valid\n ? {\n values: resolverOptions.raw ? Object.assign({}, values) : values,\n errors: {},\n }\n : {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n};\n"],"names":["parseErrorSchema","ataErrors","validateAllFieldCriteria","parsedErrors","index","length","error","path","keyword","instancePath","params","missingProperty","substring","replace","message","type","types","messages","appendErrors","concat","schema","schemaOptions","resolverOptions","validator","Validator","values","_","options","result","validate","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","valid","raw","Object","assign","errors","toNestErrors","criteriaMode","e","reject"],"mappings":"6FAKMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAE,EAE1CC,EAAQ,EAAGA,EAAQH,EAAUI,OAAQD,GAAS,EAAG,CACxD,IAAME,EAAQL,EAAUG,GAOlBG,GAJc,aAAlBD,EAAME,QACCF,EAAMG,iBAAgBH,EAAMI,OAAOC,gBACtCL,EAAMG,cAEcG,UAAU,GAAGC,QAAQ,MAAO,KAStD,GAPKV,EAAaI,KAChBJ,EAAaI,GAAQ,CACnBO,QAASR,EAAMQ,QACfC,KAAMT,EAAME,UAIZN,EAA0B,CAC5B,IAAMc,EAAQb,EAAaI,GAAMS,MAC3BC,EAAWD,GAASA,EAAMV,EAAME,SAEtCL,EAAaI,GAAQW,EAAAA,aACnBX,EACAL,EACAC,EACAG,EAAME,QACNS,EACK,GAAgBE,OAAOF,EAAsBX,EAAMQ,SAAW,IAC/DR,EAAMQ,QAEd,CACF,CAEA,OAAOX,CACT,sBAEqC,SACnCiB,EACAC,EACAC,QAAe,IAAfA,IAAAA,EAAkB,CAAA,GAElB,IAAMC,EAAY,IAAIC,EAASA,UAACJ,EAAQC,GACxC,OAAA,SAAcI,EAAQC,EAAGC,GAAO,IAC9B,IAAMC,EAASL,EAAUM,SAASJ,GAIlC,OAFAE,EAAQG,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEJ,GAEhEK,QAAAC,QAAOL,EAAOM,MACV,CACET,OAAQH,EAAgBa,IAAMC,OAAOC,OAAO,CAAE,EAAEZ,GAAUA,EAC1Da,OAAQ,IAEV,CACEb,OAAQ,CAAE,EACVa,OAAQC,eACNvC,EACE4B,EAAOU,QACNX,EAAQG,2BACkB,QAAzBH,EAAQa,cAEZb,IAGV,CAAC,MAAAc,UAAAT,QAAAU,OAAAD,IACH"}
@@ -0,0 +1,2 @@
import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{Validator as a}from"ata-validator";import{appendErrors as o}from"react-hook-form";var t=function(r,e){for(var a={},t=0;t<r.length;t+=1){var s=r[t],i=("required"===s.keyword?s.instancePath+"/"+s.params.missingProperty:s.instancePath).substring(1).replace(/\//g,".");if(a[i]||(a[i]={message:s.message,type:s.keyword}),e){var n=a[i].types,m=n&&n[s.keyword];a[i]=o(i,e,a,s.keyword,m?[].concat(m,s.message||""):s.message)}}return a},s=function(o,s,i){void 0===i&&(i={});var n=new a(o,s);return function(a,o,s){try{var m=n.validate(a);return s.shouldUseNativeValidation&&r({},s),Promise.resolve(m.valid?{values:i.raw?Object.assign({},a):a,errors:{}}:{values:{},errors:e(t(m.errors,!s.shouldUseNativeValidation&&"all"===s.criteriaMode),s)})}catch(r){return Promise.reject(r)}}};export{s as ataResolver};
//# sourceMappingURL=ata-validator.module.js.map
@@ -0,0 +1,2 @@
import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import{Validator as o}from"ata-validator";import{appendErrors as s}from"react-hook-form";const t=(e,r)=>{const o={};for(let t=0;t<e.length;t+=1){const a=e[t],i=("required"===a.keyword?`${a.instancePath}/${a.params.missingProperty}`:a.instancePath).substring(1).replace(/\//g,".");if(o[i]||(o[i]={message:a.message,type:a.keyword}),r){const e=o[i].types,t=e&&e[a.keyword];o[i]=s(i,r,o,a.keyword,t?[].concat(t,a.message||""):a.message)}}return o},a=(s,a,i={})=>{const n=new o(s,a);return async(o,s,a)=>{const c=n.validate(o);return a.shouldUseNativeValidation&&e({},a),c.valid?{values:i.raw?Object.assign({},o):o,errors:{}}:{values:{},errors:r(t(c.errors,!a.shouldUseNativeValidation&&"all"===a.criteriaMode),a)}}};export{a as ataResolver};
//# sourceMappingURL=ata-validator.modern.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"ata-validator.modern.mjs","sources":["../src/ata-validator.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { ValidationError, Validator } from 'ata-validator';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n ataErrors: ValidationError[],\n validateAllFieldCriteria: boolean,\n) => {\n const parsedErrors: Record<string, FieldError> = {};\n\n for (let index = 0; index < ataErrors.length; index += 1) {\n const error = ataErrors[index];\n\n const instancePath =\n error.keyword === 'required'\n ? `${error.instancePath}/${error.params.missingProperty}`\n : error.instancePath;\n\n const path = instancePath.substring(1).replace(/\\//g, '.');\n\n if (!parsedErrors[path]) {\n parsedErrors[path] = {\n message: error.message,\n type: error.keyword,\n };\n }\n\n if (validateAllFieldCriteria) {\n const types = parsedErrors[path].types;\n const messages = types && types[error.keyword];\n\n parsedErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n parsedErrors,\n error.keyword,\n messages\n ? ([] as string[]).concat(messages as string[], error.message || '')\n : error.message,\n ) as FieldError;\n }\n }\n\n return parsedErrors;\n};\n\nexport const ataResolver: Resolver = (\n schema,\n schemaOptions,\n resolverOptions = {},\n) => {\n const validator = new Validator(schema, schemaOptions);\n return async (values, _, options) => {\n const result = validator.validate(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return result.valid\n ? {\n values: resolverOptions.raw ? Object.assign({}, values) : values,\n errors: {},\n }\n : {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n};\n"],"names":["parseErrorSchema","ataErrors","validateAllFieldCriteria","parsedErrors","index","length","error","path","keyword","instancePath","params","missingProperty","substring","replace","message","type","types","messages","appendErrors","concat","ataResolver","schema","schemaOptions","resolverOptions","validator","Validator","values","_","options","result","validate","shouldUseNativeValidation","validateFieldsNatively","valid","raw","Object","assign","errors","toNestErrors","criteriaMode"],"mappings":"wKAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAA2C,CAAE,EAEnD,IAAK,IAAIC,EAAQ,EAAGA,EAAQH,EAAUI,OAAQD,GAAS,EAAG,CACxD,MAAME,EAAQL,EAAUG,GAOlBG,GAJc,aAAlBD,EAAME,QACF,GAAGF,EAAMG,gBAAgBH,EAAMI,OAAOC,kBACtCL,EAAMG,cAEcG,UAAU,GAAGC,QAAQ,MAAO,KAStD,GAPKV,EAAaI,KAChBJ,EAAaI,GAAQ,CACnBO,QAASR,EAAMQ,QACfC,KAAMT,EAAME,UAIZN,EAA0B,CAC5B,MAAMc,EAAQb,EAAaI,GAAMS,MAC3BC,EAAWD,GAASA,EAAMV,EAAME,SAEtCL,EAAaI,GAAQW,EACnBX,EACAL,EACAC,EACAG,EAAME,QACNS,EACK,GAAgBE,OAAOF,EAAsBX,EAAMQ,SAAW,IAC/DR,EAAMQ,QAEd,CACF,CAEA,OAAOX,GAGIiB,EAAwBA,CACnCC,EACAC,EACAC,EAAkB,CAAE,KAEpB,MAAMC,EAAY,IAAIC,EAAUJ,EAAQC,GACxC,OAAcI,MAAAA,EAAQC,EAAGC,KACvB,MAAMC,EAASL,EAAUM,SAASJ,GAIlC,OAFAE,EAAQG,2BAA6BC,EAAuB,CAAE,EAAEJ,GAEzDC,EAAOI,MACV,CACEP,OAAQH,EAAgBW,IAAMC,OAAOC,OAAO,CAAE,EAAEV,GAAUA,EAC1DW,OAAQ,CACT,GACD,CACEX,OAAQ,CAAA,EACRW,OAAQC,EACNtC,EACE6B,EAAOQ,QACNT,EAAQG,2BACkB,QAAzBH,EAAQW,cAEZX,IAGV"}
@@ -0,0 +1,2 @@
import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{Validator as a}from"ata-validator";import{appendErrors as o}from"react-hook-form";var t=function(r,e){for(var a={},t=0;t<r.length;t+=1){var s=r[t],i=("required"===s.keyword?s.instancePath+"/"+s.params.missingProperty:s.instancePath).substring(1).replace(/\//g,".");if(a[i]||(a[i]={message:s.message,type:s.keyword}),e){var n=a[i].types,m=n&&n[s.keyword];a[i]=o(i,e,a,s.keyword,m?[].concat(m,s.message||""):s.message)}}return a},s=function(o,s,i){void 0===i&&(i={});var n=new a(o,s);return function(a,o,s){try{var m=n.validate(a);return s.shouldUseNativeValidation&&r({},s),Promise.resolve(m.valid?{values:i.raw?Object.assign({},a):a,errors:{}}:{values:{},errors:e(t(m.errors,!s.shouldUseNativeValidation&&"all"===s.criteriaMode),s)})}catch(r){return Promise.reject(r)}}};export{s as ataResolver};
//# sourceMappingURL=ata-validator.module.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ata-validator.module.js","sources":["../src/ata-validator.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { ValidationError, Validator } from 'ata-validator';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n ataErrors: ValidationError[],\n validateAllFieldCriteria: boolean,\n) => {\n const parsedErrors: Record<string, FieldError> = {};\n\n for (let index = 0; index < ataErrors.length; index += 1) {\n const error = ataErrors[index];\n\n const instancePath =\n error.keyword === 'required'\n ? `${error.instancePath}/${error.params.missingProperty}`\n : error.instancePath;\n\n const path = instancePath.substring(1).replace(/\\//g, '.');\n\n if (!parsedErrors[path]) {\n parsedErrors[path] = {\n message: error.message,\n type: error.keyword,\n };\n }\n\n if (validateAllFieldCriteria) {\n const types = parsedErrors[path].types;\n const messages = types && types[error.keyword];\n\n parsedErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n parsedErrors,\n error.keyword,\n messages\n ? ([] as string[]).concat(messages as string[], error.message || '')\n : error.message,\n ) as FieldError;\n }\n }\n\n return parsedErrors;\n};\n\nexport const ataResolver: Resolver = (\n schema,\n schemaOptions,\n resolverOptions = {},\n) => {\n const validator = new Validator(schema, schemaOptions);\n return async (values, _, options) => {\n const result = validator.validate(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return result.valid\n ? {\n values: resolverOptions.raw ? Object.assign({}, values) : values,\n errors: {},\n }\n : {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n};\n"],"names":["parseErrorSchema","ataErrors","validateAllFieldCriteria","parsedErrors","index","length","error","path","keyword","instancePath","params","missingProperty","substring","replace","message","type","types","messages","appendErrors","concat","ataResolver","schema","schemaOptions","resolverOptions","validator","Validator","values","_","options","result","validate","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","valid","raw","Object","assign","errors","toNestErrors","criteriaMode","e","reject"],"mappings":"wKAKA,IAAMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAE,EAE1CC,EAAQ,EAAGA,EAAQH,EAAUI,OAAQD,GAAS,EAAG,CACxD,IAAME,EAAQL,EAAUG,GAOlBG,GAJc,aAAlBD,EAAME,QACCF,EAAMG,iBAAgBH,EAAMI,OAAOC,gBACtCL,EAAMG,cAEcG,UAAU,GAAGC,QAAQ,MAAO,KAStD,GAPKV,EAAaI,KAChBJ,EAAaI,GAAQ,CACnBO,QAASR,EAAMQ,QACfC,KAAMT,EAAME,UAIZN,EAA0B,CAC5B,IAAMc,EAAQb,EAAaI,GAAMS,MAC3BC,EAAWD,GAASA,EAAMV,EAAME,SAEtCL,EAAaI,GAAQW,EACnBX,EACAL,EACAC,EACAG,EAAME,QACNS,EACK,GAAgBE,OAAOF,EAAsBX,EAAMQ,SAAW,IAC/DR,EAAMQ,QAEd,CACF,CAEA,OAAOX,CACT,EAEaiB,EAAwB,SACnCC,EACAC,EACAC,QAAe,IAAfA,IAAAA,EAAkB,CAAA,GAElB,IAAMC,EAAY,IAAIC,EAAUJ,EAAQC,GACxC,OAAA,SAAcI,EAAQC,EAAGC,GAAO,IAC9B,IAAMC,EAASL,EAAUM,SAASJ,GAIlC,OAFAE,EAAQG,2BAA6BC,EAAuB,CAAE,EAAEJ,GAEhEK,QAAAC,QAAOL,EAAOM,MACV,CACET,OAAQH,EAAgBa,IAAMC,OAAOC,OAAO,CAAE,EAAEZ,GAAUA,EAC1Da,OAAQ,IAEV,CACEb,OAAQ,CAAE,EACVa,OAAQC,EACNxC,EACE6B,EAAOU,QACNX,EAAQG,2BACkB,QAAzBH,EAAQa,cAEZb,IAGV,CAAC,MAAAc,UAAAT,QAAAU,OAAAD,IACH"}
@@ -0,0 +1,2 @@
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("ata-validator"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","ata-validator","react-hook-form"],r):r((e||self).hookformResolversAtaValidator={},e.hookformResolvers,e.ataValidator,e.ReactHookForm)}(this,function(e,r,o,a){var t=function(e,r){for(var o={},t=0;t<e.length;t+=1){var s=e[t],i=("required"===s.keyword?s.instancePath+"/"+s.params.missingProperty:s.instancePath).substring(1).replace(/\//g,".");if(o[i]||(o[i]={message:s.message,type:s.keyword}),r){var n=o[i].types,l=n&&n[s.keyword];o[i]=a.appendErrors(i,r,o,s.keyword,l?[].concat(l,s.message||""):s.message)}}return o};e.ataResolver=function(e,a,s){void 0===s&&(s={});var i=new o.Validator(e,a);return function(e,o,a){try{var n=i.validate(e);return a.shouldUseNativeValidation&&r.validateFieldsNatively({},a),Promise.resolve(n.valid?{values:s.raw?Object.assign({},e):e,errors:{}}:{values:{},errors:r.toNestErrors(t(n.errors,!a.shouldUseNativeValidation&&"all"===a.criteriaMode),a)})}catch(e){return Promise.reject(e)}}}});
//# sourceMappingURL=ata-validator.umd.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ata-validator.umd.js","sources":["../src/ata-validator.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { ValidationError, Validator } from 'ata-validator';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n ataErrors: ValidationError[],\n validateAllFieldCriteria: boolean,\n) => {\n const parsedErrors: Record<string, FieldError> = {};\n\n for (let index = 0; index < ataErrors.length; index += 1) {\n const error = ataErrors[index];\n\n const instancePath =\n error.keyword === 'required'\n ? `${error.instancePath}/${error.params.missingProperty}`\n : error.instancePath;\n\n const path = instancePath.substring(1).replace(/\\//g, '.');\n\n if (!parsedErrors[path]) {\n parsedErrors[path] = {\n message: error.message,\n type: error.keyword,\n };\n }\n\n if (validateAllFieldCriteria) {\n const types = parsedErrors[path].types;\n const messages = types && types[error.keyword];\n\n parsedErrors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n parsedErrors,\n error.keyword,\n messages\n ? ([] as string[]).concat(messages as string[], error.message || '')\n : error.message,\n ) as FieldError;\n }\n }\n\n return parsedErrors;\n};\n\nexport const ataResolver: Resolver = (\n schema,\n schemaOptions,\n resolverOptions = {},\n) => {\n const validator = new Validator(schema, schemaOptions);\n return async (values, _, options) => {\n const result = validator.validate(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return result.valid\n ? {\n values: resolverOptions.raw ? Object.assign({}, values) : values,\n errors: {},\n }\n : {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.errors,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n};\n"],"names":["parseErrorSchema","ataErrors","validateAllFieldCriteria","parsedErrors","index","length","error","path","keyword","instancePath","params","missingProperty","substring","replace","message","type","types","messages","appendErrors","concat","schema","schemaOptions","resolverOptions","validator","Validator","values","_","options","result","validate","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","valid","raw","Object","assign","errors","toNestErrors","criteriaMode","e","reject"],"mappings":"2bAKA,IAAMA,EAAmB,SACvBC,EACAC,GAIA,IAFA,IAAMC,EAA2C,CAAE,EAE1CC,EAAQ,EAAGA,EAAQH,EAAUI,OAAQD,GAAS,EAAG,CACxD,IAAME,EAAQL,EAAUG,GAOlBG,GAJc,aAAlBD,EAAME,QACCF,EAAMG,iBAAgBH,EAAMI,OAAOC,gBACtCL,EAAMG,cAEcG,UAAU,GAAGC,QAAQ,MAAO,KAStD,GAPKV,EAAaI,KAChBJ,EAAaI,GAAQ,CACnBO,QAASR,EAAMQ,QACfC,KAAMT,EAAME,UAIZN,EAA0B,CAC5B,IAAMc,EAAQb,EAAaI,GAAMS,MAC3BC,EAAWD,GAASA,EAAMV,EAAME,SAEtCL,EAAaI,GAAQW,EAAAA,aACnBX,EACAL,EACAC,EACAG,EAAME,QACNS,EACK,GAAgBE,OAAOF,EAAsBX,EAAMQ,SAAW,IAC/DR,EAAMQ,QAEd,CACF,CAEA,OAAOX,CACT,gBAEqC,SACnCiB,EACAC,EACAC,QAAe,IAAfA,IAAAA,EAAkB,CAAA,GAElB,IAAMC,EAAY,IAAIC,EAASA,UAACJ,EAAQC,GACxC,OAAA,SAAcI,EAAQC,EAAGC,GAAO,IAC9B,IAAMC,EAASL,EAAUM,SAASJ,GAIlC,OAFAE,EAAQG,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEJ,GAEhEK,QAAAC,QAAOL,EAAOM,MACV,CACET,OAAQH,EAAgBa,IAAMC,OAAOC,OAAO,CAAE,EAAEZ,GAAUA,EAC1Da,OAAQ,IAEV,CACEb,OAAQ,CAAE,EACVa,OAAQC,eACNvC,EACE4B,EAAOU,QACNX,EAAQG,2BACkB,QAAzBH,EAAQa,cAEZb,IAGV,CAAC,MAAAc,UAAAT,QAAAU,OAAAD,IACH"}
+2
View File
@@ -0,0 +1,2 @@
export * from './ata-validator';
export * from './types';
+6
View File
@@ -0,0 +1,6 @@
import type { ValidationError, ValidatorOptions } from 'ata-validator';
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
export type Resolver = (schema: object, schemaOptions?: ValidatorOptions, resolverOptions?: {
raw?: boolean;
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
export type AtaValidationError = ValidationError;
+18
View File
@@ -0,0 +1,18 @@
{
"name": "@hookform/resolvers/ata-validator",
"amdName": "hookformResolversAtaValidator",
"version": "1.0.0",
"private": true,
"description": "React Hook Form validation resolver: ata-validator",
"main": "dist/ata-validator.js",
"module": "dist/ata-validator.module.js",
"umd:main": "dist/ata-validator.umd.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"license": "MIT",
"peerDependencies": {
"react-hook-form": "^7.55.0",
"@hookform/resolvers": "^2.0.0",
"ata-validator": "^0.7.0"
}
}
@@ -0,0 +1,80 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import React from 'react';
import { useForm } from 'react-hook-form';
import { ataResolver } from '..';
type FormData = { username: string; password: string };
const schema = {
type: 'object',
properties: {
username: {
type: 'string',
minLength: 1,
},
password: {
type: 'string',
minLength: 1,
},
},
required: ['username', 'password'],
additionalProperties: false,
};
interface Props {
onSubmit: (data: FormData) => void;
}
function TestComponent({ onSubmit }: Props) {
const { register, handleSubmit } = useForm<FormData>({
resolver: ataResolver(schema),
shouldUseNativeValidation: true,
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} placeholder="username" />
<input {...register('password')} placeholder="password" />
<button type="submit">submit</button>
</form>
);
}
test("form's native validation with ata-validator", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
let usernameField = screen.getByPlaceholderText(
/username/i,
) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
let passwordField = screen.getByPlaceholderText(
/password/i,
) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
await user.click(screen.getByText(/submit/i));
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(false);
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(false);
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
await user.type(screen.getByPlaceholderText(/password/i), 'password');
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
expect(usernameField.validity.valid).toBe(true);
expect(usernameField.validationMessage).toBe('');
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
expect(passwordField.validity.valid).toBe(true);
expect(passwordField.validationMessage).toBe('');
});
+61
View File
@@ -0,0 +1,61 @@
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import React from 'react';
import { useForm } from 'react-hook-form';
import { ataResolver } from '..';
type FormData = { username: string; password: string };
const schema = {
type: 'object',
properties: {
username: {
type: 'string',
minLength: 1,
},
password: {
type: 'string',
minLength: 1,
},
},
required: ['username', 'password'],
additionalProperties: false,
};
interface Props {
onSubmit: (data: FormData) => void;
}
function TestComponent({ onSubmit }: Props) {
const {
register,
formState: { errors },
handleSubmit,
} = useForm<FormData>({
resolver: ataResolver(schema),
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('username')} />
{errors.username && <span role="alert">{errors.username.message}</span>}
<input {...register('password')} />
{errors.password && <span role="alert">{errors.password.message}</span>}
<button type="submit">submit</button>
</form>
);
}
test("form's validation with ata-validator and TypeScript's integration", async () => {
const handleSubmit = vi.fn();
render(<TestComponent onSubmit={handleSubmit} />);
expect(screen.queryAllByRole('alert')).toHaveLength(0);
await user.click(screen.getByText(/submit/i));
expect(screen.queryAllByRole('alert').length).toBeGreaterThan(0);
expect(handleSubmit).not.toHaveBeenCalled();
});
@@ -0,0 +1,134 @@
import { Field, InternalFieldName } from 'react-hook-form';
interface Data {
username: string;
password: string;
email?: string;
birthday?: number;
tags: string[];
enabled: boolean;
url: string;
like?: { id: number; name: string }[];
deepObject: { data: string; twoLayersDeep: { name: string } };
}
export const schema = {
type: 'object',
properties: {
username: {
type: 'string',
minLength: 3,
maxLength: 30,
pattern: '^\\w+$',
},
password: {
type: 'string',
minLength: 8,
pattern: '.*[A-Z].*',
},
email: {
type: 'string',
format: 'email',
},
birthday: {
type: 'integer',
minimum: 1900,
maximum: 2013,
},
tags: {
type: 'array',
items: { type: 'string' },
},
enabled: {
type: 'boolean',
},
url: {
type: 'string',
format: 'uri',
},
like: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'number' },
name: { type: 'string', minLength: 4, maxLength: 4 },
},
required: ['id', 'name'],
},
},
deepObject: {
type: 'object',
properties: {
data: { type: 'string' },
twoLayersDeep: {
type: 'object',
properties: { name: { type: 'string' } },
additionalProperties: false,
required: ['name'],
},
},
required: ['data', 'twoLayersDeep'],
},
},
required: ['username', 'password', 'tags', 'enabled', 'deepObject'],
additionalProperties: false,
};
export const validData: Data = {
username: 'Doe',
password: 'Password123_',
email: 'john@doe.com',
birthday: 2000,
tags: ['tag1', 'tag2'],
enabled: true,
url: 'https://react-hook-form.com/',
like: [{ id: 1, name: 'name' }],
deepObject: {
data: 'data',
twoLayersDeep: { name: 'deeper' },
},
};
export const invalidData = {
username: '__',
password: 'invalid',
email: '',
birthday: 'birthYear',
like: [{ id: 'z' }],
url: 'abc',
deepObject: {
data: 233,
twoLayersDeep: { name: 123 },
},
};
export const invalidDataWithUndefined = {
username: 'jsun969',
password: undefined,
deepObject: {
twoLayersDeep: {
name: 'deeper',
},
data: undefined,
},
};
export const fields: Record<InternalFieldName, Field['_f']> = {
username: {
ref: { name: 'username' },
name: 'username',
},
password: {
ref: { name: 'password' },
name: 'password',
},
email: {
ref: { name: 'email' },
name: 'email',
},
birthday: {
ref: { name: 'birthday' },
name: 'birthday',
},
};
@@ -0,0 +1,262 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`ataResolver > should return all the error messages from ataResolver when requirement fails 1`] = `
{
"errors": {
"deepObject": {
"message": "must have required property 'deepObject'",
"ref": undefined,
"type": "required",
},
"enabled": {
"message": "must have required property 'enabled'",
"ref": undefined,
"type": "required",
},
"password": {
"message": "must have required property 'password'",
"ref": {
"name": "password",
},
"type": "required",
},
"tags": {
"message": "must have required property 'tags'",
"ref": undefined,
"type": "required",
},
"username": {
"message": "must have required property 'username'",
"ref": {
"name": "username",
},
"type": "required",
},
},
"values": {},
}
`;
exports[`ataResolver > should return all the error messages from ataResolver when some property is undefined 1`] = `
{
"errors": {
"deepObject": {
"data": {
"message": "must have required property 'data'",
"ref": undefined,
"type": "required",
},
},
"enabled": {
"message": "must have required property 'enabled'",
"ref": undefined,
"type": "required",
},
"password": {
"message": "must have required property 'password'",
"ref": {
"name": "password",
},
"type": "required",
},
"tags": {
"message": "must have required property 'tags'",
"ref": undefined,
"type": "required",
},
},
"values": {},
}
`;
exports[`ataResolver > should return all the error messages from ataResolver when validation fails and validateAllFieldCriteria set to true 1`] = `
{
"errors": {
"birthday": {
"message": "must be integer",
"ref": {
"name": "birthday",
},
"type": "type",
"types": {
"type": "must be integer",
},
},
"deepObject": {
"data": {
"message": "must be string",
"ref": undefined,
"type": "type",
"types": {
"type": "must be string",
},
},
"twoLayersDeep": {
"name": {
"message": "must be string",
"ref": undefined,
"type": "type",
"types": {
"type": "must be string",
},
},
},
},
"email": {
"message": "must match format "email"",
"ref": {
"name": "email",
},
"type": "format",
"types": {
"format": "must match format "email"",
},
},
"enabled": {
"message": "must have required property 'enabled'",
"ref": undefined,
"type": "required",
"types": {
"required": "must have required property 'enabled'",
},
},
"like": [
{
"id": {
"message": "must be number",
"ref": undefined,
"type": "type",
"types": {
"type": "must be number",
},
},
"name": {
"message": "must have required property 'name'",
"ref": undefined,
"type": "required",
"types": {
"required": "must have required property 'name'",
},
},
},
],
"password": {
"message": "must NOT have fewer than 8 characters",
"ref": {
"name": "password",
},
"type": "minLength",
"types": {
"minLength": "must NOT have fewer than 8 characters",
"pattern": "must match pattern ".*[A-Z].*"",
},
},
"tags": {
"message": "must have required property 'tags'",
"ref": undefined,
"type": "required",
"types": {
"required": "must have required property 'tags'",
},
},
"url": {
"message": "must match format "uri"",
"ref": undefined,
"type": "format",
"types": {
"format": "must match format "uri"",
},
},
"username": {
"message": "must NOT have fewer than 3 characters",
"ref": {
"name": "username",
},
"type": "minLength",
"types": {
"minLength": "must NOT have fewer than 3 characters",
},
},
},
"values": {},
}
`;
exports[`ataResolver > should return single error message from ataResolver when validation fails and validateAllFieldCriteria set to false 1`] = `
{
"errors": {
"birthday": {
"message": "must be integer",
"ref": {
"name": "birthday",
},
"type": "type",
},
"deepObject": {
"data": {
"message": "must be string",
"ref": undefined,
"type": "type",
},
"twoLayersDeep": {
"name": {
"message": "must be string",
"ref": undefined,
"type": "type",
},
},
},
"email": {
"message": "must match format "email"",
"ref": {
"name": "email",
},
"type": "format",
},
"enabled": {
"message": "must have required property 'enabled'",
"ref": undefined,
"type": "required",
},
"like": [
{
"id": {
"message": "must be number",
"ref": undefined,
"type": "type",
},
"name": {
"message": "must have required property 'name'",
"ref": undefined,
"type": "required",
},
},
],
"password": {
"message": "must NOT have fewer than 8 characters",
"ref": {
"name": "password",
},
"type": "minLength",
},
"tags": {
"message": "must have required property 'tags'",
"ref": undefined,
"type": "required",
},
"url": {
"message": "must match format "uri"",
"ref": undefined,
"type": "format",
},
"username": {
"message": "must NOT have fewer than 3 characters",
"ref": {
"name": "username",
},
"type": "minLength",
},
},
"values": {},
}
`;
@@ -0,0 +1,113 @@
import { ataResolver } from '..';
import {
fields,
invalidData,
invalidDataWithUndefined,
schema,
validData,
} from './__fixtures__/data';
const shouldUseNativeValidation = false;
describe('ataResolver', () => {
it('should return values from ataResolver when validation pass', async () => {
expect(
await ataResolver(schema)(validData, undefined, {
fields,
shouldUseNativeValidation,
}),
).toEqual({
values: validData,
errors: {},
});
});
it('should return values from ataResolver when validation pass & raw=true', async () => {
const result = await ataResolver(schema, undefined, { raw: true })(
validData,
undefined,
{
fields,
shouldUseNativeValidation,
},
);
expect(result).toEqual({ errors: {}, values: validData });
});
it('should return single error message from ataResolver when validation fails and validateAllFieldCriteria set to false', async () => {
expect(
await ataResolver(schema)(invalidData, undefined, {
fields,
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return all the error messages from ataResolver when validation fails and validateAllFieldCriteria set to true', async () => {
expect(
await ataResolver(schema)(
invalidData,
{},
{ fields, criteriaMode: 'all', shouldUseNativeValidation },
),
).toMatchSnapshot();
});
it('should return all the error messages from ataResolver when requirement fails', async () => {
expect(
await ataResolver(schema)({}, undefined, {
fields,
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should return all the error messages from ataResolver when some property is undefined', async () => {
expect(
await ataResolver(schema)(invalidDataWithUndefined, undefined, {
fields,
shouldUseNativeValidation,
}),
).toMatchSnapshot();
});
it('should support coerceTypes option', async () => {
const coerceSchema = {
type: 'object',
properties: {
age: { type: 'integer' },
active: { type: 'boolean' },
},
required: ['age', 'active'],
};
const result = await ataResolver(coerceSchema, { coerceTypes: true })(
{ age: '25', active: 'true' },
undefined,
{ fields, shouldUseNativeValidation },
);
expect(result.errors).toEqual({});
});
it('should support removeAdditional option', async () => {
const strictSchema = {
type: 'object',
properties: {
name: { type: 'string' },
},
required: ['name'],
additionalProperties: false,
};
const result = await ataResolver(strictSchema, {
removeAdditional: true,
})({ name: 'test', extra: 'field' }, undefined, {
fields,
shouldUseNativeValidation,
});
expect(result.errors).toEqual({});
});
});
+76
View File
@@ -0,0 +1,76 @@
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import { ValidationError, Validator } from 'ata-validator';
import { FieldError, appendErrors } from 'react-hook-form';
import { Resolver } from './types';
const parseErrorSchema = (
ataErrors: ValidationError[],
validateAllFieldCriteria: boolean,
) => {
const parsedErrors: Record<string, FieldError> = {};
for (let index = 0; index < ataErrors.length; index += 1) {
const error = ataErrors[index];
const instancePath =
error.keyword === 'required'
? `${error.instancePath}/${error.params.missingProperty}`
: error.instancePath;
const path = instancePath.substring(1).replace(/\//g, '.');
if (!parsedErrors[path]) {
parsedErrors[path] = {
message: error.message,
type: error.keyword,
};
}
if (validateAllFieldCriteria) {
const types = parsedErrors[path].types;
const messages = types && types[error.keyword];
parsedErrors[path] = appendErrors(
path,
validateAllFieldCriteria,
parsedErrors,
error.keyword,
messages
? ([] as string[]).concat(messages as string[], error.message || '')
: error.message,
) as FieldError;
}
}
return parsedErrors;
};
export const ataResolver: Resolver = (
schema,
schemaOptions,
resolverOptions = {},
) => {
const validator = new Validator(schema, schemaOptions);
return async (values, _, options) => {
const result = validator.validate(values);
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return result.valid
? {
values: resolverOptions.raw ? Object.assign({}, values) : values,
errors: {},
}
: {
values: {},
errors: toNestErrors(
parseErrorSchema(
result.errors,
!options.shouldUseNativeValidation &&
options.criteriaMode === 'all',
),
options,
),
};
};
};
+2
View File
@@ -0,0 +1,2 @@
export * from './ata-validator';
export * from './types';
+16
View File
@@ -0,0 +1,16 @@
import type { ValidationError, ValidatorOptions } from 'ata-validator';
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
export type Resolver = (
schema: object,
schemaOptions?: ValidatorOptions,
resolverOptions?: {
raw?: boolean;
},
) => <TFieldValues extends FieldValues, TContext>(
values: TFieldValues,
context: TContext | undefined,
options: ResolverOptions<TFieldValues>,
) => Promise<ResolverResult<TFieldValues>>;
export type AtaValidationError = ValidationError;