@hookform/resolvers 3.6.0 → 3.8.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 +107 -25
- 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 +1 -1
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/dist/toNestErrors.d.ts +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/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/package.json +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/index.d.ts +2 -0
- package/vine/dist/types.d.ts +6 -0
- package/vine/dist/vine.d.ts +2 -0
- package/vine/dist/vine.js +2 -0
- package/vine/dist/vine.js.map +1 -0
- package/vine/dist/vine.mjs +2 -0
- package/vine/dist/vine.modern.mjs +2 -0
- package/vine/dist/vine.modern.mjs.map +1 -0
- package/vine/dist/vine.module.js +2 -0
- package/vine/dist/vine.module.js.map +1 -0
- package/vine/dist/vine.umd.js +2 -0
- package/vine/dist/vine.umd.js.map +1 -0
- package/vine/package.json +18 -0
- package/vine/src/__tests__/Form-native-validation.tsx +85 -0
- package/vine/src/__tests__/Form.tsx +59 -0
- package/vine/src/__tests__/__fixtures__/data.ts +76 -0
- package/vine/src/__tests__/__snapshots__/vine.ts.snap +180 -0
- package/vine/src/__tests__/vine.ts +53 -0
- package/vine/src/index.ts +2 -0
- package/vine/src/types.ts +13 -0
- package/vine/src/vine.ts +68 -0
- 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,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{toNestErrors as n,validateFieldsNatively as t}from"@hookform/resolvers";import*as r from"fp-ts/Either";import{pipe as e,flow as o,absurd as u,identity as a,not as i}from"fp-ts/function";import*as f from"fp-ts/Option";import*as s from"fp-ts/ReadonlyArray";import*as c from"fp-ts/ReadonlyRecord";import*as p from"fp-ts/Semigroup";import{TaggedUnionType as m,UnionType as l,IntersectionType as d,ExactType as v,RefinementType as y}from"io-ts";function g(){return g=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)({}).hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n},g.apply(null,arguments)}var h=function(n){return n.reduce(function(n,t,o){return e(t,r.fold(function(n){return(o>0?".":"")+n},function(n){return"["+n+"]"}),function(t){return""+n+t})},"")},O=["path"],b=[m,l,d,v,y],x=function(n){var t,c=e(t=n.context,s.filterMapWithIndex(function(n,r){var e=n-1,o=-1===e?void 0:t[e];return void 0===o||b.some(function(n){return o.type instanceof n})?f.none:f.some(r)}),s.map(function(n){return n.key}),s.map(function(n){return e(n,function(n){return parseInt(n,10)},r.fromPredicate(i(Number.isNaN),function(){return n}))}),s.toArray,h);return{message:e(n.message,r.fromNullable(n.context),r.mapLeft(o(s.last,f.map(function(n){return"expected "+n.type.name+" but got "+JSON.stringify(n.actual)}),f.getOrElseW(function(){return u("Error context is missing name")}))),r.getOrElseW(a)),type:e(n.context,s.last,f.map(function(n){return n.type.name}),f.getOrElse(function(){return"unknown"})),path:c}},N=function(n){return e(n,s.map(function(n){var t;return(t={})[n.path]={type:n.type,message:n.message},t}),function(n){return p.fold({concat:function(n,t){return Object.assign({},t,n)}})({},n)})},E={concat:function(n,t){var r;return g({},t,{types:g({},n.types,(r={},r[n.type]=n.message,r[t.type]=t.message,r))})}},j=function(n){return e(c.fromFoldableMap(E,s.Foldable)(n,function(n){return[n.path,n]}),c.map(function(n){return function(n,t){if(null==n)return{};var r={};for(var e in n)if({}.hasOwnProperty.call(n,e)){if(t.indexOf(e)>=0)continue;r[e]=n[e]}return r}(n,O)}))},k=function(o){return function(u,a,i){return e(u,o.decode,r.mapLeft((f=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,function(n){var t=f?j:N;return e(n,s.map(x),t)})),r.mapLeft(function(t){return n(t,i)}),r.fold(function(n){return{values:{},errors:n}},function(n){return i.shouldUseNativeValidation&&t({},i),{values:n,errors:{}}}));var f}};export{k as ioTsResolver};
|
|
2
2
|
//# sourceMappingURL=io-ts.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io-ts.module.js","sources":["../src/arrayToPath.ts","../src/errorsToRecord.ts","../src/io-ts.ts"],"sourcesContent":["import * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\n\nconst arrayToPath = (paths: Either.Either<string, number>[]): string =>\n paths.reduce(\n (previous, path, index) =>\n pipe(\n path,\n Either.fold(\n (key) => `${index > 0 ? '.' : ''}${key}`,\n (key) => `[${key}]`,\n ),\n (path) => `${previous}${path}`,\n ),\n '',\n );\n\nexport default arrayToPath;\n","import * as
|
|
1
|
+
{"version":3,"file":"io-ts.module.js","sources":["../src/arrayToPath.ts","../src/errorsToRecord.ts","../src/io-ts.ts"],"sourcesContent":["import * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\n\nconst arrayToPath = (paths: Either.Either<string, number>[]): string =>\n paths.reduce(\n (previous, path, index) =>\n pipe(\n path,\n Either.fold(\n (key) => `${index > 0 ? '.' : ''}${key}`,\n (key) => `[${key}]`,\n ),\n (path) => `${previous}${path}`,\n ),\n '',\n );\n\nexport default arrayToPath;\n","import * as Either from 'fp-ts/Either';\nimport * as Option from 'fp-ts/Option';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as t from 'io-ts';\nimport {\n ExactType,\n IntersectionType,\n RefinementType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport arrayToPath from './arrayToPath';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst INSTANCE_TYPES_TO_FILTER = [\n TaggedUnionType,\n UnionType,\n IntersectionType,\n ExactType,\n RefinementType,\n];\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n const previousContextEntry =\n previousIndex === -1 ? undefined : context[previousIndex];\n const shouldBeFiltered =\n previousContextEntry === undefined ||\n INSTANCE_TYPES_TO_FILTER.some(\n (type) => previousContextEntry.type instanceof type,\n );\n\n return shouldBeFiltered ? Option.none : Option.some(contextEntry);\n }),\n ReadonlyArray.map(({ key }) => key),\n ReadonlyArray.map((key) =>\n pipe(\n key,\n (k) => parseInt(k, 10),\n Either.fromPredicate(not<number>(Number.isNaN), () => key),\n ),\n ),\n ReadonlyArray.toArray,\n arrayToPath,\n );\n\nconst formatError = (e: t.ValidationError): FieldErrorWithPath => {\n const path = formatErrorPath(e.context);\n\n const message = pipe(\n e.message,\n Either.fromNullable(e.context),\n Either.mapLeft(\n flow(\n ReadonlyArray.last,\n Option.map(\n (contextEntry) =>\n `expected ${contextEntry.type.name} but got ${JSON.stringify(\n contextEntry.actual,\n )}`,\n ),\n Option.getOrElseW(() =>\n absurd<string>('Error context is missing name' as never),\n ),\n ),\n ),\n Either.getOrElseW(identity),\n );\n\n const type = pipe(\n e.context,\n ReadonlyArray.last,\n Option.map((contextEntry) => contextEntry.type.name),\n Option.getOrElse(() => 'unknown'),\n );\n\n return { message, type, path };\n};\n\n// this is almost the same function like Semigroup.getObjectSemigroup but reversed\n// in order to get the first error\nconst getObjectSemigroup = <\n A extends Record<string, unknown> = never,\n>(): SemiGroup.Semigroup<A> => ({\n concat: (first, second) => Object.assign({}, second, first),\n});\n\nconst concatToSingleError = (\n errors: ReadonlyArray<FieldErrorWithPath>,\n): ErrorObject =>\n pipe(\n errors,\n ReadonlyArray.map((error) => ({\n [error.path]: {\n type: error.type,\n message: error.message,\n },\n })),\n (errors) => SemiGroup.fold(getObjectSemigroup<ErrorObject>())({}, errors),\n );\n\nconst appendSeveralErrors: SemiGroup.Semigroup<FieldErrorWithPath> = {\n concat: (a, b) => ({\n ...b,\n types: { ...a.types, [a.type]: a.message, [b.type]: b.message },\n }),\n};\n\nconst concatToMultipleErrors = (\n errors: ReadonlyArray<FieldErrorWithPath>,\n): ErrorObject =>\n pipe(\n ReadonlyRecord.fromFoldableMap(appendSeveralErrors, ReadonlyArray.Foldable)(\n errors,\n (error) => [error.path, error],\n ),\n ReadonlyRecord.map((errorWithPath) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { path, ...error } = errorWithPath;\n\n return error;\n }),\n );\n\nconst errorsToRecord =\n (validateAllFieldCriteria: boolean) =>\n (validationErrors: ReadonlyArray<ValidationError>): ErrorObject => {\n const concat = validateAllFieldCriteria\n ? concatToMultipleErrors\n : concatToSingleError;\n\n return pipe(validationErrors, ReadonlyArray.map(formatError), concat);\n };\n\nexport default errorsToRecord;\n","import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\nimport errorsToRecord from './errorsToRecord';\nimport { Resolver } from './types';\n\nexport const ioTsResolver: Resolver = (codec) => (values, _context, options) =>\n pipe(\n values,\n codec.decode,\n Either.mapLeft(\n errorsToRecord(\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n ),\n Either.mapLeft((errors) => toNestErrors(errors, options)),\n Either.fold(\n (errors) => ({\n values: {},\n errors,\n }),\n (values) => {\n options.shouldUseNativeValidation &&\n validateFieldsNatively({}, options);\n\n return {\n values,\n errors: {},\n } as any;\n },\n ),\n );\n"],"names":["arrayToPath","paths","reduce","previous","path","index","pipe","Either","fold","key","_excluded","INSTANCE_TYPES_TO_FILTER","TaggedUnionType","UnionType","IntersectionType","ExactType","RefinementType","formatError","e","context","ReadonlyArray","filterMapWithIndex","contextEntry","previousIndex","previousContextEntry","undefined","some","type","Option","none","map","_ref","k","parseInt","fromPredicate","not","Number","isNaN","toArray","message","fromNullable","mapLeft","flow","last","name","JSON","stringify","actual","getOrElseW","absurd","identity","getOrElse","concatToSingleError","errors","error","_ref2","SemiGroup","concat","first","second","Object","assign","appendSeveralErrors","a","b","_extends2","_extends","types","concatToMultipleErrors","ReadonlyRecord","fromFoldableMap","Foldable","errorWithPath","_objectWithoutPropertiesLoose","ioTsResolver","codec","values","_context","options","decode","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","validationErrors","toNestErrors","validateFieldsNatively"],"mappings":"upBAGA,IAAMA,EAAc,SAACC,UACnBA,EAAMC,OACJ,SAACC,EAAUC,EAAMC,GAAK,OACpBC,EACEF,EACAG,EAAOC,KACL,SAACC,GAAG,OAAQJ,EAAQ,EAAI,IAAM,IAAKI,CAAG,EACtC,SAACA,GAAYA,MAAAA,IAAAA,QAEf,SAACL,YAAYD,EAAWC,C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ts.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@hookform/resolvers"),require("fp-ts/Either"),require("fp-ts/function"),require("fp-ts/Option"),require("fp-ts/ReadonlyArray"),require("fp-ts/ReadonlyRecord"),require("fp-ts/Semigroup"),require("io-ts")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","fp-ts/Either","fp-ts/function","fp-ts/Option","fp-ts/ReadonlyArray","fp-ts/ReadonlyRecord","fp-ts/Semigroup","io-ts"],n):n((e||self).hookformResolversIoTs={},e.hookformResolvers,e.Either,e._function,e.Option,e.ReadonlyArray,e.ReadonlyRecord,e.Semigroup,e.ioTs)}(this,function(e,n,t,r,o,i,u,a,f){function s(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}}),n.default=e,n}var p=/*#__PURE__*/s(t),c=/*#__PURE__*/s(o),l=/*#__PURE__*/s(i),d=/*#__PURE__*/s(u),y=/*#__PURE__*/s(a);function m(){return m=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},m.apply(null,arguments)}var v=function(e){return e.reduce(function(e,n,t){return r.pipe(n,p.fold(function(e){return(t>0?".":"")+e},function(e){return"["+e+"]"}),function(n){return""+e+n})},"")},g=["path"],h=[f.TaggedUnionType,f.UnionType,f.IntersectionType,f.ExactType,f.RefinementType],b=function(e){var n,t=r.pipe(n=e.context,l.filterMapWithIndex(function(e,t){var r=e-1,o=-1===r?void 0:n[r];return void 0===o||h.some(function(e){return o.type instanceof e})?c.none:c.some(t)}),l.map(function(e){return e.key}),l.map(function(e){return r.pipe(e,function(e){return parseInt(e,10)},p.fromPredicate(r.not(Number.isNaN),function(){return e}))}),l.toArray,v);return{message:r.pipe(e.message,p.fromNullable(e.context),p.mapLeft(r.flow(l.last,c.map(function(e){return"expected "+e.type.name+" but got "+JSON.stringify(e.actual)}),c.getOrElseW(function(){return r.absurd("Error context is missing name")}))),p.getOrElseW(r.identity)),type:r.pipe(e.context,l.last,c.map(function(e){return e.type.name}),c.getOrElse(function(){return"unknown"})),path:t}},O=function(e){return r.pipe(e,l.map(function(e){var n;return(n={})[e.path]={type:e.type,message:e.message},n}),function(e){return y.fold({concat:function(e,n){return Object.assign({},n,e)}})({},e)})},R={concat:function(e,n){var t;return m({},n,{types:m({},e.types,(t={},t[e.type]=e.message,t[n.type]=n.message,t))})}},x=function(e){return r.pipe(d.fromFoldableMap(R,l.Foldable)(e,function(e){return[e.path,e]}),d.map(function(e){return function(e,n){if(null==e)return{};var t={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(n.indexOf(r)>=0)continue;t[r]=e[r]}return t}(e,g)}))};e.ioTsResolver=function(e){return function(t,o,i){return r.pipe(t,e.decode,p.mapLeft((u=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,function(e){var n=u?x:O;return r.pipe(e,l.map(b),n)})),p.mapLeft(function(e){return n.toNestErrors(e,i)}),p.fold(function(e){return{values:{},errors:e}},function(e){return i.shouldUseNativeValidation&&n.validateFieldsNatively({},i),{values:e,errors:{}}}));var u}}});
|
|
2
2
|
//# sourceMappingURL=io-ts.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io-ts.umd.js","sources":["../src/arrayToPath.ts","../src/errorsToRecord.ts","../src/io-ts.ts"],"sourcesContent":["import * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\n\nconst arrayToPath = (paths: Either.Either<string, number>[]): string =>\n paths.reduce(\n (previous, path, index) =>\n pipe(\n path,\n Either.fold(\n (key) => `${index > 0 ? '.' : ''}${key}`,\n (key) => `[${key}]`,\n ),\n (path) => `${previous}${path}`,\n ),\n '',\n );\n\nexport default arrayToPath;\n","import * as
|
|
1
|
+
{"version":3,"file":"io-ts.umd.js","sources":["../src/arrayToPath.ts","../src/errorsToRecord.ts","../src/io-ts.ts"],"sourcesContent":["import * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\n\nconst arrayToPath = (paths: Either.Either<string, number>[]): string =>\n paths.reduce(\n (previous, path, index) =>\n pipe(\n path,\n Either.fold(\n (key) => `${index > 0 ? '.' : ''}${key}`,\n (key) => `[${key}]`,\n ),\n (path) => `${previous}${path}`,\n ),\n '',\n );\n\nexport default arrayToPath;\n","import * as Either from 'fp-ts/Either';\nimport * as Option from 'fp-ts/Option';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as t from 'io-ts';\nimport {\n ExactType,\n IntersectionType,\n RefinementType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport arrayToPath from './arrayToPath';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst INSTANCE_TYPES_TO_FILTER = [\n TaggedUnionType,\n UnionType,\n IntersectionType,\n ExactType,\n RefinementType,\n];\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n const previousContextEntry =\n previousIndex === -1 ? undefined : context[previousIndex];\n const shouldBeFiltered =\n previousContextEntry === undefined ||\n INSTANCE_TYPES_TO_FILTER.some(\n (type) => previousContextEntry.type instanceof type,\n );\n\n return shouldBeFiltered ? Option.none : Option.some(contextEntry);\n }),\n ReadonlyArray.map(({ key }) => key),\n ReadonlyArray.map((key) =>\n pipe(\n key,\n (k) => parseInt(k, 10),\n Either.fromPredicate(not<number>(Number.isNaN), () => key),\n ),\n ),\n ReadonlyArray.toArray,\n arrayToPath,\n );\n\nconst formatError = (e: t.ValidationError): FieldErrorWithPath => {\n const path = formatErrorPath(e.context);\n\n const message = pipe(\n e.message,\n Either.fromNullable(e.context),\n Either.mapLeft(\n flow(\n ReadonlyArray.last,\n Option.map(\n (contextEntry) =>\n `expected ${contextEntry.type.name} but got ${JSON.stringify(\n contextEntry.actual,\n )}`,\n ),\n Option.getOrElseW(() =>\n absurd<string>('Error context is missing name' as never),\n ),\n ),\n ),\n Either.getOrElseW(identity),\n );\n\n const type = pipe(\n e.context,\n ReadonlyArray.last,\n Option.map((contextEntry) => contextEntry.type.name),\n Option.getOrElse(() => 'unknown'),\n );\n\n return { message, type, path };\n};\n\n// this is almost the same function like Semigroup.getObjectSemigroup but reversed\n// in order to get the first error\nconst getObjectSemigroup = <\n A extends Record<string, unknown> = never,\n>(): SemiGroup.Semigroup<A> => ({\n concat: (first, second) => Object.assign({}, second, first),\n});\n\nconst concatToSingleError = (\n errors: ReadonlyArray<FieldErrorWithPath>,\n): ErrorObject =>\n pipe(\n errors,\n ReadonlyArray.map((error) => ({\n [error.path]: {\n type: error.type,\n message: error.message,\n },\n })),\n (errors) => SemiGroup.fold(getObjectSemigroup<ErrorObject>())({}, errors),\n );\n\nconst appendSeveralErrors: SemiGroup.Semigroup<FieldErrorWithPath> = {\n concat: (a, b) => ({\n ...b,\n types: { ...a.types, [a.type]: a.message, [b.type]: b.message },\n }),\n};\n\nconst concatToMultipleErrors = (\n errors: ReadonlyArray<FieldErrorWithPath>,\n): ErrorObject =>\n pipe(\n ReadonlyRecord.fromFoldableMap(appendSeveralErrors, ReadonlyArray.Foldable)(\n errors,\n (error) => [error.path, error],\n ),\n ReadonlyRecord.map((errorWithPath) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { path, ...error } = errorWithPath;\n\n return error;\n }),\n );\n\nconst errorsToRecord =\n (validateAllFieldCriteria: boolean) =>\n (validationErrors: ReadonlyArray<ValidationError>): ErrorObject => {\n const concat = validateAllFieldCriteria\n ? concatToMultipleErrors\n : concatToSingleError;\n\n return pipe(validationErrors, ReadonlyArray.map(formatError), concat);\n };\n\nexport default errorsToRecord;\n","import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\nimport errorsToRecord from './errorsToRecord';\nimport { Resolver } from './types';\n\nexport const ioTsResolver: Resolver = (codec) => (values, _context, options) =>\n pipe(\n values,\n codec.decode,\n Either.mapLeft(\n errorsToRecord(\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n ),\n Either.mapLeft((errors) => toNestErrors(errors, options)),\n Either.fold(\n (errors) => ({\n values: {},\n errors,\n }),\n (values) => {\n options.shouldUseNativeValidation &&\n validateFieldsNatively({}, options);\n\n return {\n values,\n errors: {},\n } as any;\n },\n ),\n );\n"],"names":["arrayToPath","paths","reduce","previous","path","index","pipe","Either","fold","key","_excluded","INSTANCE_TYPES_TO_FILTER","TaggedUnionType","UnionType","IntersectionType","ExactType","RefinementType","formatError","e","context","ReadonlyArray","filterMapWithIndex","contextEntry","previousIndex","previousContextEntry","undefined","some","type","Option","none","map","_ref","k","parseInt","fromPredicate","not","Number","isNaN","toArray","message","fromNullable","mapLeft","flow","last","name","JSON","stringify","actual","getOrElseW","absurd","identity","getOrElse","concatToSingleError","errors","error","_ref2","SemiGroup","concat","first","second","Object","assign","appendSeveralErrors","a","b","_extends2","_extends","types","concatToMultipleErrors","ReadonlyRecord","fromFoldableMap","Foldable","errorWithPath","_objectWithoutPropertiesLoose","codec","values","_context","options","decode","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","validationErrors","toNestErrors","validateFieldsNatively"],"mappings":"mxCAGA,IAAMA,EAAc,SAACC,UACnBA,EAAMC,OACJ,SAACC,EAAUC,EAAMC,GAAK,OACpBC,EAAAA,KACEF,EACAG,EAAOC,KACL,SAACC,GAAG,OAAQJ,EAAQ,EAAI,IAAM,IAAKI,CAAG,EACtC,SAACA,GAAYA,MAAAA,IAA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QG,2BACNI,yBAAuB,CAAA,EAAIP,GAEtB,CACLF,OAAAA,EACAtB,OAAQ,CAAA,EAEZ,IDsGJ,IAAC0B,CCpGA,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
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 t from 'io-ts';
|
|
6
4
|
import * as tt from 'io-ts-types';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useForm } from 'react-hook-form';
|
|
7
7
|
import { ioTsResolver } from '..';
|
|
8
8
|
|
|
9
9
|
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
|
@@ -1,9 +1,9 @@
|
|
|
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 t from 'io-ts';
|
|
6
4
|
import * as tt from 'io-ts-types';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useForm } from 'react-hook-form';
|
|
7
7
|
import { ioTsResolver } from '..';
|
|
8
8
|
|
|
9
9
|
const schema = t.type({
|
|
@@ -4,7 +4,7 @@ exports[`ioTsResolver > should return a single error from ioTsResolver when vali
|
|
|
4
4
|
{
|
|
5
5
|
"errors": {
|
|
6
6
|
"animal": {
|
|
7
|
-
"message": "expected string but got [
|
|
7
|
+
"message": "expected string but got ["dog"]",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "string",
|
|
10
10
|
},
|
|
@@ -21,7 +21,7 @@ exports[`ioTsResolver > should return a single error from ioTsResolver when vali
|
|
|
21
21
|
,
|
|
22
22
|
,
|
|
23
23
|
{
|
|
24
|
-
"message": "expected number but got
|
|
24
|
+
"message": "expected number but got "3"",
|
|
25
25
|
"ref": undefined,
|
|
26
26
|
"type": "number",
|
|
27
27
|
},
|
|
@@ -45,14 +45,14 @@ exports[`ioTsResolver > should return all the errors from ioTsResolver when vali
|
|
|
45
45
|
{
|
|
46
46
|
"errors": {
|
|
47
47
|
"animal": {
|
|
48
|
-
"message": "expected
|
|
48
|
+
"message": "expected "snake" but got ["dog"]",
|
|
49
49
|
"ref": undefined,
|
|
50
|
-
"type": "
|
|
50
|
+
"type": ""snake"",
|
|
51
51
|
"types": {
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"number": "expected number but got [
|
|
55
|
-
"string": "expected string but got [
|
|
52
|
+
""bird"": "expected "bird" but got ["dog"]",
|
|
53
|
+
""snake"": "expected "snake" but got ["dog"]",
|
|
54
|
+
"number": "expected number but got ["dog"]",
|
|
55
|
+
"string": "expected string but got ["dog"]",
|
|
56
56
|
},
|
|
57
57
|
},
|
|
58
58
|
"like": [
|
|
@@ -68,7 +68,7 @@ exports[`ioTsResolver > should return all the errors from ioTsResolver when vali
|
|
|
68
68
|
,
|
|
69
69
|
,
|
|
70
70
|
{
|
|
71
|
-
"message": "expected number but got
|
|
71
|
+
"message": "expected number but got "3"",
|
|
72
72
|
"ref": undefined,
|
|
73
73
|
"type": "number",
|
|
74
74
|
},
|
|
@@ -1,47 +1,57 @@
|
|
|
1
|
-
import * as t from 'io-ts';
|
|
2
1
|
import { isLeft } from 'fp-ts/Either';
|
|
2
|
+
import * as t from 'io-ts';
|
|
3
3
|
import errorsToRecord from '../errorsToRecord';
|
|
4
4
|
|
|
5
5
|
const assertLeft = <T>(result: t.Validation<T>) => {
|
|
6
6
|
expect(isLeft(result)).toBe(true);
|
|
7
|
-
if (!isLeft(result)) {
|
|
7
|
+
if (!isLeft(result)) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
'panic! error is not of the "left" type, should be unreachable',
|
|
10
|
+
);
|
|
11
|
+
}
|
|
8
12
|
return result.left;
|
|
9
13
|
};
|
|
10
14
|
|
|
11
15
|
const FIRST_NAME_FIELD_PATH = 'firstName' as const;
|
|
12
|
-
const FIRST_NAME_ERROR_SHAPE = {
|
|
16
|
+
const FIRST_NAME_ERROR_SHAPE = {
|
|
17
|
+
message: 'expected string but got undefined',
|
|
18
|
+
type: 'string',
|
|
19
|
+
};
|
|
13
20
|
describe('errorsToRecord', () => {
|
|
14
21
|
it('should return a correct error for an exact intersection type error object', () => {
|
|
15
22
|
// a recommended pattern from https://github.com/gcanti/io-ts/blob/master/index.md#mixing-required-and-optional-props
|
|
16
|
-
const schema = t.exact(
|
|
17
|
-
t.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const schema = t.exact(
|
|
24
|
+
t.intersection([
|
|
25
|
+
t.type({
|
|
26
|
+
[FIRST_NAME_FIELD_PATH]: t.string,
|
|
27
|
+
}),
|
|
28
|
+
t.partial({
|
|
29
|
+
lastName: t.string,
|
|
30
|
+
}),
|
|
31
|
+
]),
|
|
32
|
+
);
|
|
24
33
|
const error = assertLeft(schema.decode({}));
|
|
25
34
|
const record = errorsToRecord(false)(error);
|
|
26
35
|
expect(record[FIRST_NAME_FIELD_PATH]).toMatchObject(FIRST_NAME_ERROR_SHAPE);
|
|
27
36
|
});
|
|
28
37
|
it('should return a correct error for a branded intersection', () => {
|
|
29
38
|
interface Brand {
|
|
30
|
-
readonly Brand: unique symbol
|
|
39
|
+
readonly Brand: unique symbol;
|
|
31
40
|
}
|
|
32
|
-
const schema = t.brand(
|
|
41
|
+
const schema = t.brand(
|
|
42
|
+
t.intersection([
|
|
33
43
|
t.type({
|
|
34
|
-
[FIRST_NAME_FIELD_PATH]: t.string
|
|
44
|
+
[FIRST_NAME_FIELD_PATH]: t.string,
|
|
35
45
|
}),
|
|
36
46
|
t.type({
|
|
37
|
-
lastName: t.string
|
|
38
|
-
})
|
|
47
|
+
lastName: t.string,
|
|
48
|
+
}),
|
|
39
49
|
]),
|
|
40
50
|
(_x): _x is t.Branded<typeof _x, Brand> => true,
|
|
41
|
-
'Brand'
|
|
51
|
+
'Brand',
|
|
42
52
|
);
|
|
43
53
|
const error = assertLeft(schema.decode({}));
|
|
44
54
|
const record = errorsToRecord(false)(error);
|
|
45
55
|
expect(record[FIRST_NAME_FIELD_PATH]).toMatchObject(FIRST_NAME_ERROR_SHAPE);
|
|
46
|
-
})
|
|
47
|
-
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import * as Either from 'fp-ts/Either';
|
|
2
|
+
import * as Option from 'fp-ts/Option';
|
|
3
|
+
import * as ReadonlyArray from 'fp-ts/ReadonlyArray';
|
|
4
|
+
import * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';
|
|
5
|
+
import * as SemiGroup from 'fp-ts/Semigroup';
|
|
6
|
+
import { absurd, flow, identity, not, pipe } from 'fp-ts/function';
|
|
1
7
|
import * as t from 'io-ts';
|
|
2
8
|
import {
|
|
3
9
|
ExactType,
|
|
@@ -5,27 +11,30 @@ import {
|
|
|
5
11
|
RefinementType,
|
|
6
12
|
TaggedUnionType,
|
|
7
13
|
UnionType,
|
|
8
|
-
ValidationError
|
|
14
|
+
ValidationError,
|
|
9
15
|
} from 'io-ts';
|
|
10
|
-
import { absurd, flow, identity, not, pipe } from 'fp-ts/function';
|
|
11
|
-
import * as ReadonlyArray from 'fp-ts/ReadonlyArray';
|
|
12
|
-
import * as Option from 'fp-ts/Option';
|
|
13
|
-
import * as Either from 'fp-ts/Either';
|
|
14
|
-
import * as SemiGroup from 'fp-ts/Semigroup';
|
|
15
16
|
import arrayToPath from './arrayToPath';
|
|
16
|
-
import * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';
|
|
17
17
|
import { ErrorObject, FieldErrorWithPath } from './types';
|
|
18
18
|
|
|
19
|
-
const INSTANCE_TYPES_TO_FILTER = [
|
|
19
|
+
const INSTANCE_TYPES_TO_FILTER = [
|
|
20
|
+
TaggedUnionType,
|
|
21
|
+
UnionType,
|
|
22
|
+
IntersectionType,
|
|
23
|
+
ExactType,
|
|
24
|
+
RefinementType,
|
|
25
|
+
];
|
|
20
26
|
const formatErrorPath = (context: t.Context): string =>
|
|
21
27
|
pipe(
|
|
22
28
|
context,
|
|
23
29
|
ReadonlyArray.filterMapWithIndex((index, contextEntry) => {
|
|
24
30
|
const previousIndex = index - 1;
|
|
25
|
-
const previousContextEntry =
|
|
31
|
+
const previousContextEntry =
|
|
32
|
+
previousIndex === -1 ? undefined : context[previousIndex];
|
|
26
33
|
const shouldBeFiltered =
|
|
27
34
|
previousContextEntry === undefined ||
|
|
28
|
-
INSTANCE_TYPES_TO_FILTER.some(
|
|
35
|
+
INSTANCE_TYPES_TO_FILTER.some(
|
|
36
|
+
(type) => previousContextEntry.type instanceof type,
|
|
37
|
+
);
|
|
29
38
|
|
|
30
39
|
return shouldBeFiltered ? Option.none : Option.some(contextEntry);
|
|
31
40
|
}),
|
package/io-ts/src/io-ts.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
1
2
|
import * as Either from 'fp-ts/Either';
|
|
2
3
|
import { pipe } from 'fp-ts/function';
|
|
3
|
-
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
4
4
|
import errorsToRecord from './errorsToRecord';
|
|
5
5
|
import { Resolver } from './types';
|
|
6
6
|
|
package/joi/dist/joi.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("
|
|
1
|
+
var e=require("@hookform/resolvers"),r=require("react-hook-form");exports.joiResolver=function(t,n,o){return void 0===n&&(n={abortEarly:!1}),void 0===o&&(o={}),function(a,i,s){try{var u=function(){return l.error?{values:{},errors:e.toNestErrors((t=l.error,n=!s.shouldUseNativeValidation&&"all"===s.criteriaMode,t.details.length?t.details.reduce(function(e,t){var o=t.path.join(".");if(e[o]||(e[o]={message:t.message,type:t.type}),n){var a=e[o].types,i=a&&a[t.type];e[o]=r.appendErrors(o,n,e,t.type,i?[].concat(i,t.message):t.message)}return e},{}):{}),s)}:(s.shouldUseNativeValidation&&e.validateFieldsNatively({},s),{errors:{},values:l.value});var t,n},c=Object.assign({},n,{context:i}),l={},v=function(){if("sync"===o.mode)l=t.validate(a,c);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(t.validateAsync(a,c)).then(function(e){l.value=e})},function(e){l.error=e});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(v&&v.then?v.then(u):u())}catch(e){return Promise.reject(e)}}};
|
|
2
2
|
//# sourceMappingURL=joi.js.map
|
package/joi/dist/joi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joi.js","sources":["../src/joi.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"joi.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":"sFAqCE,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/joi.mjs
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
|
package/joi/dist/joi.modern.mjs
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";const a=(a,o={abortEarly:!1},s={})=>async(i,l,c)=>{const n=Object.assign({},o,{context:l});let d={};if("sync"===s.mode)d=a.validate(i,n);else try{d.value=await a.validateAsync(i,n)}catch(e){d.error=e}return d.error?{values:{},errors:e((m=d.error,v=!c.shouldUseNativeValidation&&"all"===c.criteriaMode,m.details.length?m.details.reduce((e,r)=>{const a=r.path.join(".");if(e[a]||(e[a]={message:r.message,type:r.type}),v){const o=e[a].types,s=o&&o[r.type];e[a]=t(a,v,e,r.type,s?[].concat(s,r.message):r.message)}return e},{}):{}),c)}:(c.shouldUseNativeValidation&&r({},c),{errors:{},values:d.value});var m,v};export{a as joiResolver};
|
|
2
2
|
//# sourceMappingURL=joi.modern.mjs.map
|
|
@@ -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({
|