@hookform/resolvers 3.7.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -0
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.modern.mjs.map +1 -1
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/types.d.ts +1 -1
- package/ajv/src/__tests__/ajv.ts +7 -1
- package/ajv/src/ajv.ts +1 -1
- package/ajv/src/types.ts +1 -5
- package/arktype/dist/arktype.js +1 -1
- package/arktype/dist/arktype.js.map +1 -1
- package/arktype/dist/arktype.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs.map +1 -1
- package/arktype/dist/arktype.module.js +1 -1
- package/arktype/dist/arktype.module.js.map +1 -1
- package/arktype/dist/arktype.umd.js +1 -1
- package/arktype/dist/arktype.umd.js.map +1 -1
- package/arktype/dist/types.d.ts +1 -1
- package/arktype/package.json +2 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +5 -5
- package/arktype/src/__tests__/Form.tsx +2 -2
- package/arktype/src/__tests__/__fixtures__/data.ts +1 -1
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +29 -29
- package/arktype/src/__tests__/arktype.ts +1 -1
- package/arktype/src/arktype.ts +2 -2
- package/arktype/src/types.ts +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.modern.mjs.map +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/types.d.ts +2 -2
- package/class-validator/src/__tests__/Form-native-validation.tsx +2 -2
- package/class-validator/src/__tests__/Form.tsx +2 -2
- package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +2 -2
- package/class-validator/src/__tests__/class-validator.ts +4 -4
- package/class-validator/src/class-validator.ts +2 -2
- package/class-validator/src/types.ts +2 -2
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.modern.mjs.map +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/dist/types.d.ts +1 -1
- package/computed-types/src/__tests__/Form-native-validation.tsx +2 -2
- package/computed-types/src/__tests__/Form.tsx +2 -2
- package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +6 -6
- package/computed-types/src/__tests__/computed-types.ts +1 -1
- package/computed-types/src/computed-types.ts +2 -2
- package/computed-types/src/types.ts +1 -1
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +2 -2
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/dist/toNestErrors.d.ts +1 -6
- package/dist/validateFieldsNatively.d.ts +1 -1
- package/effect-ts/dist/effect-ts.js +1 -1
- package/effect-ts/dist/effect-ts.js.map +1 -1
- package/effect-ts/dist/effect-ts.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
- package/effect-ts/dist/effect-ts.module.js +1 -1
- package/effect-ts/dist/effect-ts.module.js.map +1 -1
- package/effect-ts/dist/effect-ts.umd.js +1 -1
- package/effect-ts/dist/effect-ts.umd.js.map +1 -1
- package/effect-ts/src/__tests__/Form-native-validation.tsx +2 -2
- package/effect-ts/src/__tests__/Form.tsx +2 -2
- package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +2 -2
- package/effect-ts/src/__tests__/effect-ts.ts +1 -1
- package/effect-ts/src/effect-ts.ts +1 -1
- package/fluentvalidation-ts/dist/fluentvalidation-ts.d.ts +4 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.js.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.mjs +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js.map +1 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js +2 -0
- package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js.map +1 -0
- package/fluentvalidation-ts/dist/index.d.ts +1 -0
- package/fluentvalidation-ts/package.json +18 -0
- package/fluentvalidation-ts/src/__tests__/Form-native-validation.tsx +88 -0
- package/fluentvalidation-ts/src/__tests__/Form.tsx +63 -0
- package/fluentvalidation-ts/src/__tests__/__fixtures__/data.ts +121 -0
- package/fluentvalidation-ts/src/__tests__/__snapshots__/fluentvalidation-ts.ts.snap +129 -0
- package/fluentvalidation-ts/src/__tests__/fluentvalidation-ts.ts +113 -0
- package/fluentvalidation-ts/src/fluentvalidation-ts.ts +102 -0
- package/fluentvalidation-ts/src/index.ts +1 -0
- package/io-ts/dist/errorsToRecord.d.ts +0 -1
- package/io-ts/dist/io-ts.js +1 -1
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs.map +1 -1
- package/io-ts/dist/io-ts.module.js +1 -1
- package/io-ts/dist/io-ts.module.js.map +1 -1
- package/io-ts/dist/io-ts.umd.js +1 -1
- package/io-ts/dist/io-ts.umd.js.map +1 -1
- package/io-ts/src/__tests__/Form-native-validation.tsx +2 -2
- package/io-ts/src/__tests__/Form.tsx +2 -2
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +9 -9
- package/io-ts/src/__tests__/errorsToRecord.ts +29 -19
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/io-ts/src/errorsToRecord.ts +19 -10
- package/io-ts/src/io-ts.ts +1 -1
- package/joi/dist/joi.js +1 -1
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/joi.mjs +1 -1
- package/joi/dist/joi.modern.mjs +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -1
- package/joi/dist/joi.module.js +1 -1
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/dist/types.d.ts +1 -1
- package/joi/src/__tests__/Form-native-validation.tsx +2 -2
- package/joi/src/__tests__/Form.tsx +2 -2
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +56 -56
- package/joi/src/__tests__/joi.ts +1 -1
- package/joi/src/joi.ts +1 -1
- package/joi/src/types.ts +1 -5
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -1
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/dist/types.d.ts +1 -1
- package/nope/src/__tests__/Form-native-validation.tsx +2 -2
- package/nope/src/__tests__/Form.tsx +2 -2
- package/nope/src/__tests__/__fixtures__/data.ts +1 -1
- package/nope/src/__tests__/nope.ts +1 -1
- package/nope/src/nope.ts +1 -1
- package/nope/src/types.ts +2 -2
- package/package.json +69 -54
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/dist/types.d.ts +1 -1
- package/superstruct/src/__tests__/Form-native-validation.tsx +2 -2
- package/superstruct/src/__tests__/Form.tsx +2 -2
- package/superstruct/src/__tests__/__fixtures__/data.ts +8 -8
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +4 -4
- package/superstruct/src/__tests__/superstruct.ts +1 -1
- package/superstruct/src/superstruct.ts +1 -1
- package/superstruct/src/types.ts +1 -1
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -1
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/dist/types.d.ts +1 -1
- package/typanion/src/__tests__/Form-native-validation.tsx +1 -1
- package/typanion/src/__tests__/Form.tsx +1 -1
- package/typanion/src/__tests__/__fixtures__/data.ts +12 -7
- package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +4 -4
- package/typanion/src/__tests__/typanion.ts +1 -1
- package/typanion/src/typanion.ts +1 -1
- package/typanion/src/types.ts +4 -4
- package/typebox/dist/typebox.js +1 -1
- package/typebox/dist/typebox.js.map +1 -1
- package/typebox/dist/typebox.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs.map +1 -1
- package/typebox/dist/typebox.module.js +1 -1
- package/typebox/dist/typebox.module.js.map +1 -1
- package/typebox/dist/typebox.umd.js +1 -1
- package/typebox/dist/typebox.umd.js.map +1 -1
- package/typebox/dist/types.d.ts +3 -2
- package/typebox/src/__tests__/Form-compiler.tsx +57 -0
- package/typebox/src/__tests__/Form-native-validation-compiler.tsx +86 -0
- package/typebox/src/__tests__/Form-native-validation.tsx +4 -4
- package/typebox/src/__tests__/Form.tsx +3 -3
- package/typebox/src/__tests__/__fixtures__/data.ts +6 -2
- package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +188 -0
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +13 -13
- package/typebox/src/__tests__/typebox-compiler.ts +37 -0
- package/typebox/src/__tests__/typebox.ts +1 -1
- package/typebox/src/typebox.ts +8 -3
- package/typebox/src/types.ts +3 -2
- package/typeschema/dist/index.d.ts +2 -0
- package/typeschema/dist/types.d.ts +9 -0
- package/typeschema/dist/typeschema.d.ts +2 -0
- package/typeschema/dist/typeschema.js +2 -0
- package/typeschema/dist/typeschema.js.map +1 -0
- package/typeschema/dist/typeschema.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs.map +1 -0
- package/typeschema/dist/typeschema.module.js +2 -0
- package/typeschema/dist/typeschema.module.js.map +1 -0
- package/typeschema/dist/typeschema.umd.js +2 -0
- package/typeschema/dist/typeschema.umd.js.map +1 -0
- package/typeschema/package.json +18 -0
- package/typeschema/src/__tests__/Form-native-validation.tsx +82 -0
- package/typeschema/src/__tests__/Form.tsx +53 -0
- package/typeschema/src/__tests__/__fixtures__/data.ts +88 -0
- package/typeschema/src/__tests__/__snapshots__/typeschema.ts.snap +225 -0
- package/typeschema/src/__tests__/typeschema.ts +70 -0
- package/typeschema/src/index.ts +2 -0
- package/typeschema/src/types.ts +18 -0
- package/typeschema/src/typeschema.ts +70 -0
- package/valibot/dist/types.d.ts +1 -1
- package/valibot/dist/valibot.js +1 -1
- package/valibot/dist/valibot.js.map +1 -1
- package/valibot/dist/valibot.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs.map +1 -1
- package/valibot/dist/valibot.module.js +1 -1
- package/valibot/dist/valibot.module.js.map +1 -1
- package/valibot/dist/valibot.umd.js +1 -1
- package/valibot/dist/valibot.umd.js.map +1 -1
- package/valibot/src/__tests__/Form-native-validation.tsx +2 -2
- package/valibot/src/__tests__/Form.tsx +1 -1
- package/valibot/src/__tests__/valibot.ts +4 -4
- package/valibot/src/types.ts +1 -1
- package/valibot/src/valibot.ts +12 -6
- package/vest/dist/types.d.ts +2 -2
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -1
- package/vest/dist/vest.module.js.map +1 -1
- package/vest/dist/vest.umd.js.map +1 -1
- package/vest/src/__tests__/Form-native-validation.tsx +1 -1
- package/vest/src/__tests__/Form.tsx +1 -1
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +0 -6
- package/vest/src/__tests__/vest.ts +14 -8
- package/vest/src/types.ts +11 -4
- package/vest/src/vest.ts +1 -1
- package/vine/dist/types.d.ts +1 -1
- package/vine/dist/vine.js +1 -1
- package/vine/dist/vine.js.map +1 -1
- package/vine/dist/vine.mjs +1 -1
- package/vine/dist/vine.modern.mjs +1 -1
- package/vine/dist/vine.modern.mjs.map +1 -1
- package/vine/dist/vine.module.js +1 -1
- package/vine/dist/vine.module.js.map +1 -1
- package/vine/dist/vine.umd.js +1 -1
- package/vine/dist/vine.umd.js.map +1 -1
- package/vine/src/__tests__/Form-native-validation.tsx +9 -5
- package/vine/src/__tests__/Form.tsx +9 -5
- package/vine/src/__tests__/__fixtures__/data.ts +4 -2
- package/vine/src/__tests__/vine.ts +1 -1
- package/vine/src/types.ts +1 -1
- package/vine/src/vine.ts +10 -8
- package/yup/dist/yup.d.ts +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/Form-native-validation.tsx +1 -1
- package/yup/src/__tests__/Form.tsx +1 -1
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +13 -13
- package/yup/src/__tests__/yup.ts +9 -7
- package/yup/src/yup.ts +2 -2
- package/zod/dist/types.d.ts +1 -1
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/Form-native-validation.tsx +2 -2
- package/zod/src/__tests__/Form.tsx +1 -1
- package/zod/src/__tests__/zod.ts +1 -1
- package/zod/src/types.ts +1 -1
- package/zod/src/zod.ts +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joi.modern.mjs","sources":["../src/joi.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"joi.modern.mjs","sources":["../src/joi.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n error: ValidationError,\n validateAllFieldCriteria: boolean,\n) =>\n error.details.length\n ? error.details.reduce<Record<string, FieldError>>((previous, error) => {\n const _path = error.path.join('.');\n\n if (!previous[_path]) {\n previous[_path] = { message: error.message, type: error.type };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[_path].types;\n const messages = types && types[error.type!];\n\n previous[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n previous,\n error.type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {})\n : {};\n\nexport const joiResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\n ) =>\n async (values, context, options) => {\n const _schemaOptions = Object.assign({}, schemaOptions, {\n context,\n });\n\n let result: Record<string, any> = {};\n if (resolverOptions.mode === 'sync') {\n result = schema.validate(values, _schemaOptions);\n } else {\n try {\n result.value = await schema.validateAsync(values, _schemaOptions);\n } catch (e) {\n result.error = e;\n }\n }\n\n if (result.error) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.error,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: result.value,\n };\n };\n"],"names":["joiResolver","schema","schemaOptions","abortEarly","resolverOptions","async","values","context","options","_schemaOptions","Object","assign","result","mode","validate","value","validateAsync","e","error","errors","toNestErrors","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","types","messages","appendErrors","concat","validateFieldsNatively","parseErrorSchema"],"mappings":"8HAKA,MA+BaA,EACXA,CACEC,EACAC,EAAgB,CACdC,YAAY,GAEdC,EAAkB,KAEpBC,MAAOC,EAAQC,EAASC,KACtB,MAAMC,EAAiBC,OAAOC,OAAO,CAAA,EAAIT,EAAe,CACtDK,YAGF,IAAIK,EAA8B,CAAA,EAClC,GAA6B,SAAzBR,EAAgBS,KAClBD,EAASX,EAAOa,SAASR,EAAQG,QAEjC,IACEG,EAAOG,YAAcd,EAAOe,cAAcV,EAAQG,EACpD,CAAE,MAAOQ,GACPL,EAAOM,MAAQD,CACjB,CAGF,OAAIL,EAAOM,MACF,CACLZ,OAAQ,CAAE,EACVa,OAAQC,GAzDdF,EA2DUN,EAAOM,MA1DjBG,GA2DWb,EAAQc,2BACkB,QAAzBd,EAAQe,aA1DpBL,EAAMM,QAAQC,OACVP,EAAMM,QAAQE,OAAmC,CAACC,EAAUT,KAC1D,MAAMU,EAAQV,EAAMW,KAAKC,KAAK,KAM9B,GAJKH,EAASC,KACZD,EAASC,GAAS,CAAEG,QAASb,EAAMa,QAASC,KAAMd,EAAMc,OAGtDX,EAA0B,CAC5B,MAAMY,EAAQN,EAASC,GAAOK,MACxBC,EAAWD,GAASA,EAAMf,EAAMc,MAEtCL,EAASC,GAASO,EAChBP,EACAP,EACAM,EACAT,EAAMc,KACNE,EACK,GAAgBE,OAAOF,EAAsBhB,EAAMa,SACpDb,EAAMa,QAEd,CAEA,OAAOJ,GACN,CAAE,GACL,CAAE,GAmCEnB,KAKNA,EAAQc,2BAA6Be,EAAuB,CAAA,EAAI7B,GAEzD,CACLW,OAAQ,CAAA,EACRb,OAAQM,EAAOG,QAzEIuB,IACvBpB,EACAG"}
|
package/joi/dist/joi.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{toNestErrors as e,validateFieldsNatively as r}from"@hookform/resolvers";import{appendErrors as t}from"react-hook-form";var n=function(n,o,a){return void 0===o&&(o={abortEarly:!1}),void 0===a&&(a={}),function(i,s,u){try{var c=function(){return l.error?{values:{},errors:e((n=l.error,o=!u.shouldUseNativeValidation&&"all"===u.criteriaMode,n.details.length?n.details.reduce(function(e,r){var n=r.path.join(".");if(e[n]||(e[n]={message:r.message,type:r.type}),o){var a=e[n].types,i=a&&a[r.type];e[n]=t(n,o,e,r.type,i?[].concat(i,r.message):r.message)}return e},{}):{}),u)}:(u.shouldUseNativeValidation&&r({},u),{errors:{},values:l.value});var n,o},v=Object.assign({},o,{context:s}),l={},f=function(){if("sync"===a.mode)l=n.validate(i,v);else{var e=function(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}(function(){return Promise.resolve(n.validateAsync(i,v)).then(function(e){l.value=e})},function(e){l.error=e});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(f&&f.then?f.then(c):c())}catch(e){return Promise.reject(e)}}};export{n as joiResolver};
|
|
2
2
|
//# sourceMappingURL=joi.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joi.module.js","sources":["../src/joi.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"joi.module.js","sources":["../src/joi.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n error: ValidationError,\n validateAllFieldCriteria: boolean,\n) =>\n error.details.length\n ? error.details.reduce<Record<string, FieldError>>((previous, error) => {\n const _path = error.path.join('.');\n\n if (!previous[_path]) {\n previous[_path] = { message: error.message, type: error.type };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[_path].types;\n const messages = types && types[error.type!];\n\n previous[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n previous,\n error.type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {})\n : {};\n\nexport const joiResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\n ) =>\n async (values, context, options) => {\n const _schemaOptions = Object.assign({}, schemaOptions, {\n context,\n });\n\n let result: Record<string, any> = {};\n if (resolverOptions.mode === 'sync') {\n result = schema.validate(values, _schemaOptions);\n } else {\n try {\n result.value = await schema.validateAsync(values, _schemaOptions);\n } catch (e) {\n result.error = e;\n }\n }\n\n if (result.error) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.error,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: result.value,\n };\n };\n"],"names":["joiResolver","schema","schemaOptions","resolverOptions","abortEarly","values","context","options","_temp3","result","error","errors","toNestErrors","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","types","messages","appendErrors","concat","validateFieldsNatively","value","_schemaOptions","Object","assign","_temp2","mode","validate","_temp","_catch","Promise","resolve","validateAsync","then","_schema$validateAsync","e","reject"],"mappings":"8HAKA,IA+BaA,EACX,SACEC,EACAC,EAGAC,GAAoB,YAHpBD,IAAAA,IAAAA,EAAgB,CACdE,YAAY,SAEdD,IAAAA,IAAAA,EAAkB,CAAE,GAAA,SAEfE,EAAQC,EAASC,GAAW,IAAA,IAAAC,EAAAA,WAgBjC,OAAIC,EAAOC,MACF,CACLL,OAAQ,CAAA,EACRM,OAAQC,GAzDdF,EA2DUD,EAAOC,MA1DjBG,GA2DWN,EAAQO,2BACkB,QAAzBP,EAAQQ,aA1DpBL,EAAMM,QAAQC,OACVP,EAAMM,QAAQE,OAAmC,SAACC,EAAUT,GAC1D,IAAMU,EAAQV,EAAMW,KAAKC,KAAK,KAM9B,GAJKH,EAASC,KACZD,EAASC,GAAS,CAAEG,QAASb,EAAMa,QAASC,KAAMd,EAAMc,OAGtDX,EAA0B,CAC5B,IAAMY,EAAQN,EAASC,GAAOK,MACxBC,EAAWD,GAASA,EAAMf,EAAMc,MAEtCL,EAASC,GAASO,EAChBP,EACAP,EACAM,EACAT,EAAMc,KACNE,EACK,GAAgBE,OAAOF,EAAsBhB,EAAMa,SACpDb,EAAMa,QAEd,CAEA,OAAOJ,CACT,EAAG,CAAA,GACH,CAAE,GAmCEZ,KAKNA,EAAQO,2BAA6Be,EAAuB,GAAItB,GAEzD,CACLI,OAAQ,CAAA,EACRN,OAAQI,EAAOqB,QAzEI,IACvBpB,EACAG,CAwEI,EAlCIkB,EAAiBC,OAAOC,OAAO,CAAA,EAAI/B,EAAe,CACtDI,QAAAA,IAGEG,EAA8B,CAAA,EAAGyB,gBACR,SAAzB/B,EAAgBgC,KAClB1B,EAASR,EAAOmC,SAAS/B,EAAQ0B,OAAgBM,CAAAA,IAAAA,uFAAAC,YAE7CC,OAAAA,QAAAC,QACmBvC,EAAOwC,cAAcpC,EAAQ0B,IAAeW,KAAA,SAAAC,GAAjElC,EAAOqB,MAAKa,CAAsD,EACpE,EAASC,SAAAA,GACPnC,EAAOC,MAAQkC,CACjB,GAACP,GAAAA,GAAAA,EAAAK,YAAAL,EAAAK,KAAA,aAAA,CAAA,IAAA,OAAAH,QAAAC,QAAAN,GAAAA,EAAAQ,KAAAR,EAAAQ,KAAAlC,GAAAA,IAuBL,CAAC,MAAAoC,UAAAL,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
|
package/joi/dist/joi.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form"],r):r((e||self).hookformResolversJoi={},e.hookformResolvers,e.ReactHookForm)}(this,function(e,r,o){e.joiResolver=function(e,t,n){return void 0===t&&(t={abortEarly:!1}),void 0===n&&(n={}),function(i,s,a){try{var u=function(){return f.error?{values:{},errors:r.toNestErrors((e=f.error,t=!a.shouldUseNativeValidation&&"all"===a.criteriaMode,e.details.length?e.details.reduce(function(e,r){var n=r.path.join(".");if(e[n]||(e[n]={message:r.message,type:r.type}),t){var i=e[n].types,s=i&&i[r.type];e[n]=o.appendErrors(n,t,e,r.type,s?[].concat(s,r.message):r.message)}return e},{}):{}),a)}:(a.shouldUseNativeValidation&&r.validateFieldsNatively({},a),{errors:{},values:f.value});var e,t},l=Object.assign({},t,{context:s}),f={},c=function(){if("sync"===n.mode)f=e.validate(i,l);else{var r=function(e,r){try{var o=e()}catch(e){return r(e)}return o&&o.then?o.then(void 0,r):o}(function(){return Promise.resolve(e.validateAsync(i,l)).then(function(e){f.value=e})},function(e){f.error=e});if(r&&r.then)return r.then(function(){})}}();return Promise.resolve(c&&c.then?c.then(u):u())}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=joi.umd.js.map
|
package/joi/dist/joi.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joi.umd.js","sources":["../src/joi.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"joi.umd.js","sources":["../src/joi.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n error: ValidationError,\n validateAllFieldCriteria: boolean,\n) =>\n error.details.length\n ? error.details.reduce<Record<string, FieldError>>((previous, error) => {\n const _path = error.path.join('.');\n\n if (!previous[_path]) {\n previous[_path] = { message: error.message, type: error.type };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[_path].types;\n const messages = types && types[error.type!];\n\n previous[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n previous,\n error.type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {})\n : {};\n\nexport const joiResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\n ) =>\n async (values, context, options) => {\n const _schemaOptions = Object.assign({}, schemaOptions, {\n context,\n });\n\n let result: Record<string, any> = {};\n if (resolverOptions.mode === 'sync') {\n result = schema.validate(values, _schemaOptions);\n } else {\n try {\n result.value = await schema.validateAsync(values, _schemaOptions);\n } catch (e) {\n result.error = e;\n }\n }\n\n if (result.error) {\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n result.error,\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {},\n values: result.value,\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","abortEarly","values","context","options","_temp3","result","error","errors","toNestErrors","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","types","messages","appendErrors","concat","validateFieldsNatively","value","_schemaOptions","Object","assign","_temp2","mode","validate","_temp","_catch","Promise","resolve","validateAsync","then","_schema$validateAsync","e","reject"],"mappings":"sYAqCE,SACEA,EACAC,EAGAC,GAAoB,YAHpBD,IAAAA,IAAAA,EAAgB,CACdE,YAAY,SAEdD,IAAAA,IAAAA,EAAkB,CAAE,GAAA,SAEfE,EAAQC,EAASC,GAAW,IAAA,IAAAC,EAAAA,WAgBjC,OAAIC,EAAOC,MACF,CACLL,OAAQ,CAAA,EACRM,OAAQC,EAAAA,cAzDdF,EA2DUD,EAAOC,MA1DjBG,GA2DWN,EAAQO,2BACkB,QAAzBP,EAAQQ,aA1DpBL,EAAMM,QAAQC,OACVP,EAAMM,QAAQE,OAAmC,SAACC,EAAUT,GAC1D,IAAMU,EAAQV,EAAMW,KAAKC,KAAK,KAM9B,GAJKH,EAASC,KACZD,EAASC,GAAS,CAAEG,QAASb,EAAMa,QAASC,KAAMd,EAAMc,OAGtDX,EAA0B,CAC5B,IAAMY,EAAQN,EAASC,GAAOK,MACxBC,EAAWD,GAASA,EAAMf,EAAMc,MAEtCL,EAASC,GAASO,EAAAA,aAChBP,EACAP,EACAM,EACAT,EAAMc,KACNE,EACK,GAAgBE,OAAOF,EAAsBhB,EAAMa,SACpDb,EAAMa,QAEd,CAEA,OAAOJ,CACT,EAAG,CAAA,GACH,CAAE,GAmCEZ,KAKNA,EAAQO,2BAA6Be,EAAsBA,uBAAC,GAAItB,GAEzD,CACLI,OAAQ,CAAA,EACRN,OAAQI,EAAOqB,QAzEI,IACvBpB,EACAG,CAwEI,EAlCIkB,EAAiBC,OAAOC,OAAO,CAAA,EAAI/B,EAAe,CACtDI,QAAAA,IAGEG,EAA8B,CAAA,EAAGyB,gBACR,SAAzB/B,EAAgBgC,KAClB1B,EAASR,EAAOmC,SAAS/B,EAAQ0B,OAAgBM,CAAAA,IAAAA,uFAAAC,YAE7CC,OAAAA,QAAAC,QACmBvC,EAAOwC,cAAcpC,EAAQ0B,IAAeW,KAAA,SAAAC,GAAjElC,EAAOqB,MAAKa,CAAsD,EACpE,EAASC,SAAAA,GACPnC,EAAOC,MAAQkC,CACjB,GAACP,GAAAA,GAAAA,EAAAK,YAAAL,EAAAK,KAAA,aAAA,CAAA,IAAA,OAAAH,QAAAC,QAAAN,GAAAA,EAAAQ,KAAAR,EAAAQ,KAAAlC,GAAAA,IAuBL,CAAC,MAAAoC,UAAAL,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
|
package/joi/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
1
|
import type { AsyncValidationOptions, Schema } from 'joi';
|
|
2
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
3
3
|
export type Resolver = <T extends Schema>(schema: T, schemaOptions?: AsyncValidationOptions, factoryOptions?: {
|
|
4
4
|
mode?: 'async' | 'sync';
|
|
5
5
|
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
4
|
-
import { useForm } from 'react-hook-form';
|
|
5
3
|
import * as Joi from 'joi';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { joiResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const schema = Joi.object({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
4
|
-
import { useForm } from 'react-hook-form';
|
|
5
3
|
import * as Joi from 'joi';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { joiResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const schema = Joi.object({
|
|
@@ -4,50 +4,50 @@ exports[`joiResolver > should return a single error from joiResolver when valida
|
|
|
4
4
|
{
|
|
5
5
|
"errors": {
|
|
6
6
|
"birthYear": {
|
|
7
|
-
"message": "
|
|
7
|
+
"message": ""birthYear" must be a number",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "number.base",
|
|
10
10
|
},
|
|
11
11
|
"email": {
|
|
12
|
-
"message": "
|
|
12
|
+
"message": ""email" is not allowed to be empty",
|
|
13
13
|
"ref": {
|
|
14
14
|
"name": "email",
|
|
15
15
|
},
|
|
16
16
|
"type": "string.empty",
|
|
17
17
|
},
|
|
18
18
|
"enabled": {
|
|
19
|
-
"message": "
|
|
19
|
+
"message": ""enabled" is required",
|
|
20
20
|
"ref": undefined,
|
|
21
21
|
"type": "any.required",
|
|
22
22
|
},
|
|
23
23
|
"like": [
|
|
24
24
|
{
|
|
25
25
|
"id": {
|
|
26
|
-
"message": "
|
|
26
|
+
"message": ""like[0].id" must be a number",
|
|
27
27
|
"ref": undefined,
|
|
28
28
|
"type": "number.base",
|
|
29
29
|
},
|
|
30
30
|
"name": {
|
|
31
|
-
"message": "
|
|
31
|
+
"message": ""like[0].name" length must be 4 characters long",
|
|
32
32
|
"ref": undefined,
|
|
33
33
|
"type": "string.length",
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
37
|
"password": {
|
|
38
|
-
"message": "
|
|
38
|
+
"message": ""password" with value "___" fails to match the One uppercase character pattern",
|
|
39
39
|
"ref": {
|
|
40
40
|
"name": "password",
|
|
41
41
|
},
|
|
42
42
|
"type": "string.pattern.name",
|
|
43
43
|
},
|
|
44
44
|
"tags": {
|
|
45
|
-
"message": "
|
|
45
|
+
"message": ""tags" is required",
|
|
46
46
|
"ref": undefined,
|
|
47
47
|
"type": "any.required",
|
|
48
48
|
},
|
|
49
49
|
"username": {
|
|
50
|
-
"message": "
|
|
50
|
+
"message": ""username" is required",
|
|
51
51
|
"ref": {
|
|
52
52
|
"name": "username",
|
|
53
53
|
},
|
|
@@ -62,50 +62,50 @@ exports[`joiResolver > should return a single error from joiResolver with \`mode
|
|
|
62
62
|
{
|
|
63
63
|
"errors": {
|
|
64
64
|
"birthYear": {
|
|
65
|
-
"message": "
|
|
65
|
+
"message": ""birthYear" must be a number",
|
|
66
66
|
"ref": undefined,
|
|
67
67
|
"type": "number.base",
|
|
68
68
|
},
|
|
69
69
|
"email": {
|
|
70
|
-
"message": "
|
|
70
|
+
"message": ""email" is not allowed to be empty",
|
|
71
71
|
"ref": {
|
|
72
72
|
"name": "email",
|
|
73
73
|
},
|
|
74
74
|
"type": "string.empty",
|
|
75
75
|
},
|
|
76
76
|
"enabled": {
|
|
77
|
-
"message": "
|
|
77
|
+
"message": ""enabled" is required",
|
|
78
78
|
"ref": undefined,
|
|
79
79
|
"type": "any.required",
|
|
80
80
|
},
|
|
81
81
|
"like": [
|
|
82
82
|
{
|
|
83
83
|
"id": {
|
|
84
|
-
"message": "
|
|
84
|
+
"message": ""like[0].id" must be a number",
|
|
85
85
|
"ref": undefined,
|
|
86
86
|
"type": "number.base",
|
|
87
87
|
},
|
|
88
88
|
"name": {
|
|
89
|
-
"message": "
|
|
89
|
+
"message": ""like[0].name" length must be 4 characters long",
|
|
90
90
|
"ref": undefined,
|
|
91
91
|
"type": "string.length",
|
|
92
92
|
},
|
|
93
93
|
},
|
|
94
94
|
],
|
|
95
95
|
"password": {
|
|
96
|
-
"message": "
|
|
96
|
+
"message": ""password" with value "___" fails to match the One uppercase character pattern",
|
|
97
97
|
"ref": {
|
|
98
98
|
"name": "password",
|
|
99
99
|
},
|
|
100
100
|
"type": "string.pattern.name",
|
|
101
101
|
},
|
|
102
102
|
"tags": {
|
|
103
|
-
"message": "
|
|
103
|
+
"message": ""tags" is required",
|
|
104
104
|
"ref": undefined,
|
|
105
105
|
"type": "any.required",
|
|
106
106
|
},
|
|
107
107
|
"username": {
|
|
108
|
-
"message": "
|
|
108
|
+
"message": ""username" is required",
|
|
109
109
|
"ref": {
|
|
110
110
|
"name": "username",
|
|
111
111
|
},
|
|
@@ -120,83 +120,83 @@ exports[`joiResolver > should return all the errors from joiResolver when valida
|
|
|
120
120
|
{
|
|
121
121
|
"errors": {
|
|
122
122
|
"birthYear": {
|
|
123
|
-
"message": "
|
|
123
|
+
"message": ""birthYear" must be a number",
|
|
124
124
|
"ref": undefined,
|
|
125
125
|
"type": "number.base",
|
|
126
126
|
"types": {
|
|
127
|
-
"number.base": "
|
|
127
|
+
"number.base": ""birthYear" must be a number",
|
|
128
128
|
},
|
|
129
129
|
},
|
|
130
130
|
"email": {
|
|
131
|
-
"message": "
|
|
131
|
+
"message": ""email" is not allowed to be empty",
|
|
132
132
|
"ref": {
|
|
133
133
|
"name": "email",
|
|
134
134
|
},
|
|
135
135
|
"type": "string.empty",
|
|
136
136
|
"types": {
|
|
137
|
-
"string.empty": "
|
|
137
|
+
"string.empty": ""email" is not allowed to be empty",
|
|
138
138
|
},
|
|
139
139
|
},
|
|
140
140
|
"enabled": {
|
|
141
|
-
"message": "
|
|
141
|
+
"message": ""enabled" is required",
|
|
142
142
|
"ref": undefined,
|
|
143
143
|
"type": "any.required",
|
|
144
144
|
"types": {
|
|
145
|
-
"any.required": "
|
|
145
|
+
"any.required": ""enabled" is required",
|
|
146
146
|
},
|
|
147
147
|
},
|
|
148
148
|
"like": [
|
|
149
149
|
{
|
|
150
150
|
"id": {
|
|
151
|
-
"message": "
|
|
151
|
+
"message": ""like[0].id" must be a number",
|
|
152
152
|
"ref": undefined,
|
|
153
153
|
"type": "number.base",
|
|
154
154
|
"types": {
|
|
155
|
-
"number.base": "
|
|
155
|
+
"number.base": ""like[0].id" must be a number",
|
|
156
156
|
},
|
|
157
157
|
},
|
|
158
158
|
"name": {
|
|
159
|
-
"message": "
|
|
159
|
+
"message": ""like[0].name" length must be 4 characters long",
|
|
160
160
|
"ref": undefined,
|
|
161
161
|
"type": "string.length",
|
|
162
162
|
"types": {
|
|
163
|
-
"string.length": "
|
|
164
|
-
"string.pattern.base": "
|
|
163
|
+
"string.length": ""like[0].name" length must be 4 characters long",
|
|
164
|
+
"string.pattern.base": ""like[0].name" with value "r" fails to match the required pattern: /a/",
|
|
165
165
|
},
|
|
166
166
|
},
|
|
167
167
|
},
|
|
168
168
|
],
|
|
169
169
|
"password": {
|
|
170
|
-
"message": "
|
|
170
|
+
"message": ""password" with value "___" fails to match the One uppercase character pattern",
|
|
171
171
|
"ref": {
|
|
172
172
|
"name": "password",
|
|
173
173
|
},
|
|
174
174
|
"type": "string.pattern.name",
|
|
175
175
|
"types": {
|
|
176
|
-
"string.min": "
|
|
176
|
+
"string.min": ""password" length must be at least 8 characters long",
|
|
177
177
|
"string.pattern.name": [
|
|
178
|
-
"
|
|
179
|
-
"
|
|
180
|
-
"
|
|
178
|
+
""password" with value "___" fails to match the One uppercase character pattern",
|
|
179
|
+
""password" with value "___" fails to match the One lowercase character pattern",
|
|
180
|
+
""password" with value "___" fails to match the One number pattern",
|
|
181
181
|
],
|
|
182
182
|
},
|
|
183
183
|
},
|
|
184
184
|
"tags": {
|
|
185
|
-
"message": "
|
|
185
|
+
"message": ""tags" is required",
|
|
186
186
|
"ref": undefined,
|
|
187
187
|
"type": "any.required",
|
|
188
188
|
"types": {
|
|
189
|
-
"any.required": "
|
|
189
|
+
"any.required": ""tags" is required",
|
|
190
190
|
},
|
|
191
191
|
},
|
|
192
192
|
"username": {
|
|
193
|
-
"message": "
|
|
193
|
+
"message": ""username" is required",
|
|
194
194
|
"ref": {
|
|
195
195
|
"name": "username",
|
|
196
196
|
},
|
|
197
197
|
"type": "any.required",
|
|
198
198
|
"types": {
|
|
199
|
-
"any.required": "
|
|
199
|
+
"any.required": ""username" is required",
|
|
200
200
|
},
|
|
201
201
|
},
|
|
202
202
|
},
|
|
@@ -208,83 +208,83 @@ exports[`joiResolver > should return all the errors from joiResolver when valida
|
|
|
208
208
|
{
|
|
209
209
|
"errors": {
|
|
210
210
|
"birthYear": {
|
|
211
|
-
"message": "
|
|
211
|
+
"message": ""birthYear" must be a number",
|
|
212
212
|
"ref": undefined,
|
|
213
213
|
"type": "number.base",
|
|
214
214
|
"types": {
|
|
215
|
-
"number.base": "
|
|
215
|
+
"number.base": ""birthYear" must be a number",
|
|
216
216
|
},
|
|
217
217
|
},
|
|
218
218
|
"email": {
|
|
219
|
-
"message": "
|
|
219
|
+
"message": ""email" is not allowed to be empty",
|
|
220
220
|
"ref": {
|
|
221
221
|
"name": "email",
|
|
222
222
|
},
|
|
223
223
|
"type": "string.empty",
|
|
224
224
|
"types": {
|
|
225
|
-
"string.empty": "
|
|
225
|
+
"string.empty": ""email" is not allowed to be empty",
|
|
226
226
|
},
|
|
227
227
|
},
|
|
228
228
|
"enabled": {
|
|
229
|
-
"message": "
|
|
229
|
+
"message": ""enabled" is required",
|
|
230
230
|
"ref": undefined,
|
|
231
231
|
"type": "any.required",
|
|
232
232
|
"types": {
|
|
233
|
-
"any.required": "
|
|
233
|
+
"any.required": ""enabled" is required",
|
|
234
234
|
},
|
|
235
235
|
},
|
|
236
236
|
"like": [
|
|
237
237
|
{
|
|
238
238
|
"id": {
|
|
239
|
-
"message": "
|
|
239
|
+
"message": ""like[0].id" must be a number",
|
|
240
240
|
"ref": undefined,
|
|
241
241
|
"type": "number.base",
|
|
242
242
|
"types": {
|
|
243
|
-
"number.base": "
|
|
243
|
+
"number.base": ""like[0].id" must be a number",
|
|
244
244
|
},
|
|
245
245
|
},
|
|
246
246
|
"name": {
|
|
247
|
-
"message": "
|
|
247
|
+
"message": ""like[0].name" length must be 4 characters long",
|
|
248
248
|
"ref": undefined,
|
|
249
249
|
"type": "string.length",
|
|
250
250
|
"types": {
|
|
251
|
-
"string.length": "
|
|
252
|
-
"string.pattern.base": "
|
|
251
|
+
"string.length": ""like[0].name" length must be 4 characters long",
|
|
252
|
+
"string.pattern.base": ""like[0].name" with value "r" fails to match the required pattern: /a/",
|
|
253
253
|
},
|
|
254
254
|
},
|
|
255
255
|
},
|
|
256
256
|
],
|
|
257
257
|
"password": {
|
|
258
|
-
"message": "
|
|
258
|
+
"message": ""password" with value "___" fails to match the One uppercase character pattern",
|
|
259
259
|
"ref": {
|
|
260
260
|
"name": "password",
|
|
261
261
|
},
|
|
262
262
|
"type": "string.pattern.name",
|
|
263
263
|
"types": {
|
|
264
|
-
"string.min": "
|
|
264
|
+
"string.min": ""password" length must be at least 8 characters long",
|
|
265
265
|
"string.pattern.name": [
|
|
266
|
-
"
|
|
267
|
-
"
|
|
268
|
-
"
|
|
266
|
+
""password" with value "___" fails to match the One uppercase character pattern",
|
|
267
|
+
""password" with value "___" fails to match the One lowercase character pattern",
|
|
268
|
+
""password" with value "___" fails to match the One number pattern",
|
|
269
269
|
],
|
|
270
270
|
},
|
|
271
271
|
},
|
|
272
272
|
"tags": {
|
|
273
|
-
"message": "
|
|
273
|
+
"message": ""tags" is required",
|
|
274
274
|
"ref": undefined,
|
|
275
275
|
"type": "any.required",
|
|
276
276
|
"types": {
|
|
277
|
-
"any.required": "
|
|
277
|
+
"any.required": ""tags" is required",
|
|
278
278
|
},
|
|
279
279
|
},
|
|
280
280
|
"username": {
|
|
281
|
-
"message": "
|
|
281
|
+
"message": ""username" is required",
|
|
282
282
|
"ref": {
|
|
283
283
|
"name": "username",
|
|
284
284
|
},
|
|
285
285
|
"type": "any.required",
|
|
286
286
|
"types": {
|
|
287
|
-
"any.required": "
|
|
287
|
+
"any.required": ""username" is required",
|
|
288
288
|
},
|
|
289
289
|
},
|
|
290
290
|
},
|
package/joi/src/__tests__/joi.ts
CHANGED
package/joi/src/joi.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { appendErrors, FieldError } from 'react-hook-form';
|
|
2
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
2
|
import type { ValidationError } from 'joi';
|
|
3
|
+
import { FieldError, appendErrors } from 'react-hook-form';
|
|
4
4
|
import { Resolver } from './types';
|
|
5
5
|
|
|
6
6
|
const parseErrorSchema = (
|
package/joi/src/types.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FieldValues,
|
|
3
|
-
ResolverOptions,
|
|
4
|
-
ResolverResult,
|
|
5
|
-
} from 'react-hook-form';
|
|
6
1
|
import type { AsyncValidationOptions, Schema } from 'joi';
|
|
2
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
7
3
|
|
|
8
4
|
export type Resolver = <T extends Schema>(
|
|
9
5
|
schema: T,
|
package/nope/dist/nope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nope.js","sources":["../src/nope.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"nope.js","sources":["../src/nope.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestErrors(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestErrors","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"qCAKMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,EAAI,IAAIK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,CACT,EAAGL,EACL,uBAGE,SACEU,EACAC,GAEC,YAFY,IAAbA,IAAAA,EAAgB,CACdC,YAAY,aAGfC,EAAQC,EAASC,GAChB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAIK,EACK,CAAEH,OAAQ,CAAE,EAAEd,OAAQmB,EAAAA,aAAapB,EAAYkB,GAASD,KAGjEA,EAAQI,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEL,GAEzD,CAAEF,OAAAA,EAAQd,OAAQ,IAC3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nope.modern.mjs","sources":["../src/nope.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"nope.modern.mjs","sources":["../src/nope.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestErrors(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","nopeResolver","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestErrors","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"+EAKA,MAAMA,EAAcA,CAClBC,EACAC,EAA4B,CAAA,EAC5BC,EAAO,KAEAC,OAAOC,KAAKJ,GAAQK,OAAO,CAACC,EAAKC,KACtC,MAAMC,EAAQN,EAAO,GAAGA,KAAQK,IAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,GACNL,GAGQU,EACXA,CACEC,EACAC,EAAgB,CACdC,YAAY,KAGhB,CAACC,EAAQC,EAASC,KAChB,MAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAIK,EACK,CAAEH,OAAQ,CAAE,EAAEf,OAAQoB,EAAarB,EAAYmB,GAASD,KAGjEA,EAAQI,2BAA6BC,EAAuB,GAAIL,GAEzD,CAAEF,SAAQf,OAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nope.module.js","sources":["../src/nope.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"nope.module.js","sources":["../src/nope.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestErrors(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","nopeResolver","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestErrors","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"+EAKA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,EAAI,IAAIK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,CACT,EAAGL,EACL,EAEaU,EACX,SACEC,EACAC,GAEC,YAFY,IAAbA,IAAAA,EAAgB,CACdC,YAAY,aAGfC,EAAQC,EAASC,GAChB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAIK,EACK,CAAEH,OAAQ,CAAE,EAAEf,OAAQoB,EAAarB,EAAYmB,GAASD,KAGjEA,EAAQI,2BAA6BC,EAAuB,CAAE,EAAEL,GAEzD,CAAEF,OAAAA,EAAQf,OAAQ,IAC3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nope.umd.js","sources":["../src/nope.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"nope.umd.js","sources":["../src/nope.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n } as FieldError;\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver =\n (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n ) =>\n (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n if (result) {\n return { values: {}, errors: toNestErrors(parseErrors(result), options) };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return { values, errors: {} };\n };\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestErrors","shouldUseNativeValidation","validateFieldsNatively"],"mappings":"0TAKA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAA4B,CAAE,QAC1B,IAAJC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,EAAI,IAAIK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,CACT,EAAGL,EACL,iBAGE,SACEU,EACAC,GAEC,YAFY,IAAbA,IAAAA,EAAgB,CACdC,YAAY,aAGfC,EAAQC,EAASC,GAChB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAIK,EACK,CAAEH,OAAQ,CAAE,EAAEd,OAAQmB,EAAAA,aAAapB,EAAYkB,GAASD,KAGjEA,EAAQI,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEL,GAEzD,CAAEF,OAAAA,EAAQd,OAAQ,IAC3B,CAAC"}
|
package/nope/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
1
|
import type { NopeObject } from 'nope-validator/lib/cjs/NopeObject';
|
|
2
|
+
import type { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
3
3
|
type ValidateOptions = Parameters<NopeObject['validate']>[2];
|
|
4
4
|
type Context = Parameters<NopeObject['validate']>[1];
|
|
5
5
|
export type Resolver = <T extends NopeObject>(schema: T, schemaOptions?: ValidateOptions, resolverOptions?: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
4
|
-
import { useForm } from 'react-hook-form';
|
|
5
3
|
import Nope from 'nope-validator';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { nopeResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
4
|
-
import { useForm } from 'react-hook-form';
|
|
5
3
|
import Nope from 'nope-validator';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { nopeResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const schema = Nope.object().shape({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
1
|
import Nope from 'nope-validator';
|
|
2
|
+
import { Field, InternalFieldName } from 'react-hook-form';
|
|
3
3
|
|
|
4
4
|
export const schema = Nope.object().shape({
|
|
5
5
|
username: Nope.string().regex(/^\w+$/).min(2).max(30).required(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-console, @typescript-eslint/ban-ts-comment */
|
|
2
2
|
import { nopeResolver } from '..';
|
|
3
|
-
import {
|
|
3
|
+
import { fields, invalidData, schema, validData } from './__fixtures__/data';
|
|
4
4
|
|
|
5
5
|
const shouldUseNativeValidation = false;
|
|
6
6
|
|
package/nope/src/nope.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { FieldError, FieldErrors } from 'react-hook-form';
|
|
2
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
3
2
|
import type { ShapeErrors } from 'nope-validator/lib/cjs/types';
|
|
3
|
+
import type { FieldError, FieldErrors } from 'react-hook-form';
|
|
4
4
|
import type { Resolver } from './types';
|
|
5
5
|
|
|
6
6
|
const parseErrors = (
|
package/nope/src/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { NopeObject } from 'nope-validator/lib/cjs/NopeObject';
|
|
1
2
|
import type {
|
|
2
3
|
FieldValues,
|
|
3
4
|
ResolverOptions,
|
|
4
5
|
ResolverResult,
|
|
5
6
|
} from 'react-hook-form';
|
|
6
|
-
import type { NopeObject } from 'nope-validator/lib/cjs/NopeObject';
|
|
7
7
|
|
|
8
8
|
type ValidateOptions = Parameters<NopeObject['validate']>[2];
|
|
9
9
|
type Context = Parameters<NopeObject['validate']>[1];
|
|
@@ -11,7 +11,7 @@ type Context = Parameters<NopeObject['validate']>[1];
|
|
|
11
11
|
export type Resolver = <T extends NopeObject>(
|
|
12
12
|
schema: T,
|
|
13
13
|
schemaOptions?: ValidateOptions,
|
|
14
|
-
resolverOptions?: { mode?: 'async' | 'sync'
|
|
14
|
+
resolverOptions?: { mode?: 'async' | 'sync'; rawValues?: boolean },
|
|
15
15
|
) => <TFieldValues extends FieldValues, TContext extends Context>(
|
|
16
16
|
values: TFieldValues,
|
|
17
17
|
context: TContext | undefined,
|