@hookform/resolvers 2.9.0 → 2.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ajv/dist/ajv.js +1 -1
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.mjs +1 -1
- package/ajv/dist/ajv.modern.js +1 -1
- package/ajv/dist/ajv.modern.js.map +1 -1
- package/ajv/dist/ajv.module.js +1 -1
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js +1 -1
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/types.d.ts +2 -2
- package/ajv/src/__tests__/__fixtures__/data.ts +12 -2
- package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +34 -0
- package/ajv/src/ajv.ts +1 -1
- package/ajv/src/types.ts +1 -2
- package/class-validator/dist/types.d.ts +2 -2
- package/class-validator/src/types.ts +1 -2
- package/computed-types/dist/types.d.ts +2 -2
- package/computed-types/src/types.ts +1 -2
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/dist/toNestError.d.ts +2 -2
- package/dist/validateFieldsNatively.d.ts +2 -2
- 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.js +1 -1
- package/io-ts/dist/io-ts.modern.js.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/dist/types.d.ts +2 -2
- package/io-ts/src/io-ts.ts +1 -1
- package/io-ts/src/types.ts +1 -2
- package/joi/dist/types.d.ts +2 -2
- package/joi/src/types.ts +1 -2
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/nope.modern.js.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 +2 -2
- package/nope/src/nope.ts +2 -2
- package/nope/src/types.ts +1 -2
- package/package.json +2 -2
- package/superstruct/dist/types.d.ts +2 -2
- package/superstruct/src/types.ts +2 -3
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/typanion.modern.js.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 +2 -2
- package/typanion/src/typanion.ts +2 -2
- package/typanion/src/types.ts +1 -2
- package/vest/src/types.ts +1 -2
- package/yup/dist/types.d.ts +2 -2
- package/yup/src/types.ts +1 -2
- package/zod/dist/types.d.ts +2 -2
- package/zod/src/types.ts +1 -2
package/ajv/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldValues, ResolverOptions, ResolverResult
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
2
|
import * as Ajv from 'ajv';
|
|
3
3
|
export declare type Resolver = <T>(schema: Ajv.JSONSchemaType<T>, schemaOptions?: Ajv.Options, factoryOptions?: {
|
|
4
4
|
mode?: 'async' | 'sync';
|
|
5
|
-
}) => <TFieldValues extends FieldValues, TContext>(values:
|
|
5
|
+
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
@@ -4,7 +4,7 @@ import { Field, InternalFieldName } from 'react-hook-form';
|
|
|
4
4
|
interface Data {
|
|
5
5
|
username: string;
|
|
6
6
|
password: string;
|
|
7
|
-
deepObject: { data: string };
|
|
7
|
+
deepObject: { data: string; twoLayersDeep: { name: string } };
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const schema: JSONSchemaType<Data> = {
|
|
@@ -26,8 +26,14 @@ export const schema: JSONSchemaType<Data> = {
|
|
|
26
26
|
nullable: true,
|
|
27
27
|
properties: {
|
|
28
28
|
data: { type: 'string' },
|
|
29
|
+
twoLayersDeep: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: { name: { type: 'string' } },
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
required: ['name'],
|
|
34
|
+
},
|
|
29
35
|
},
|
|
30
|
-
required: ['data'],
|
|
36
|
+
required: ['data', 'twoLayersDeep'],
|
|
31
37
|
},
|
|
32
38
|
},
|
|
33
39
|
required: ['username', 'password', 'deepObject'],
|
|
@@ -38,6 +44,9 @@ export const validData: Data = {
|
|
|
38
44
|
username: 'jsun969',
|
|
39
45
|
password: 'validPassword',
|
|
40
46
|
deepObject: {
|
|
47
|
+
twoLayersDeep: {
|
|
48
|
+
name: 'deeper',
|
|
49
|
+
},
|
|
41
50
|
data: 'data',
|
|
42
51
|
},
|
|
43
52
|
};
|
|
@@ -47,6 +56,7 @@ export const invalidData = {
|
|
|
47
56
|
password: 'invalid-password',
|
|
48
57
|
deepObject: {
|
|
49
58
|
data: 233,
|
|
59
|
+
twoLayersDeep: { name: 123 }
|
|
50
60
|
},
|
|
51
61
|
};
|
|
52
62
|
|
|
@@ -66,6 +66,16 @@ Object {
|
|
|
66
66
|
"type": "must be string",
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
|
+
"twoLayersDeep": Object {
|
|
70
|
+
"name": Object {
|
|
71
|
+
"message": "must be string",
|
|
72
|
+
"ref": undefined,
|
|
73
|
+
"type": "type",
|
|
74
|
+
"types": Object {
|
|
75
|
+
"type": "must be string",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
69
79
|
},
|
|
70
80
|
"password": Object {
|
|
71
81
|
"message": "One uppercase character",
|
|
@@ -104,6 +114,16 @@ Object {
|
|
|
104
114
|
"type": "must be string",
|
|
105
115
|
},
|
|
106
116
|
},
|
|
117
|
+
"twoLayersDeep": Object {
|
|
118
|
+
"name": Object {
|
|
119
|
+
"message": "must be string",
|
|
120
|
+
"ref": undefined,
|
|
121
|
+
"type": "type",
|
|
122
|
+
"types": Object {
|
|
123
|
+
"type": "must be string",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
107
127
|
},
|
|
108
128
|
"password": Object {
|
|
109
129
|
"message": "One uppercase character",
|
|
@@ -139,6 +159,13 @@ Object {
|
|
|
139
159
|
"ref": undefined,
|
|
140
160
|
"type": "type",
|
|
141
161
|
},
|
|
162
|
+
"twoLayersDeep": Object {
|
|
163
|
+
"name": Object {
|
|
164
|
+
"message": "must be string",
|
|
165
|
+
"ref": undefined,
|
|
166
|
+
"type": "type",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
142
169
|
},
|
|
143
170
|
"password": Object {
|
|
144
171
|
"message": "One uppercase character",
|
|
@@ -168,6 +195,13 @@ Object {
|
|
|
168
195
|
"ref": undefined,
|
|
169
196
|
"type": "type",
|
|
170
197
|
},
|
|
198
|
+
"twoLayersDeep": Object {
|
|
199
|
+
"name": Object {
|
|
200
|
+
"message": "must be string",
|
|
201
|
+
"ref": undefined,
|
|
202
|
+
"type": "type",
|
|
203
|
+
},
|
|
204
|
+
},
|
|
171
205
|
},
|
|
172
206
|
"password": Object {
|
|
173
207
|
"message": "One uppercase character",
|
package/ajv/src/ajv.ts
CHANGED
|
@@ -17,7 +17,7 @@ const parseErrorSchema = (
|
|
|
17
17
|
|
|
18
18
|
return ajvErrors.reduce<Record<string, FieldError>>((previous, error) => {
|
|
19
19
|
// `/deepObject/data` -> `deepObject.data`
|
|
20
|
-
const path = error.instancePath.substring(1).replace(
|
|
20
|
+
const path = error.instancePath.substring(1).replace(/\//g, '.');
|
|
21
21
|
|
|
22
22
|
if (!previous[path]) {
|
|
23
23
|
previous[path] = {
|
package/ajv/src/types.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
FieldValues,
|
|
3
3
|
ResolverOptions,
|
|
4
4
|
ResolverResult,
|
|
5
|
-
UnpackNestedValue,
|
|
6
5
|
} from 'react-hook-form';
|
|
7
6
|
import * as Ajv from 'ajv';
|
|
8
7
|
|
|
@@ -11,7 +10,7 @@ export type Resolver = <T>(
|
|
|
11
10
|
schemaOptions?: Ajv.Options,
|
|
12
11
|
factoryOptions?: { mode?: 'async' | 'sync' },
|
|
13
12
|
) => <TFieldValues extends FieldValues, TContext>(
|
|
14
|
-
values:
|
|
13
|
+
values: TFieldValues,
|
|
15
14
|
context: TContext | undefined,
|
|
16
15
|
options: ResolverOptions<TFieldValues>,
|
|
17
16
|
) => Promise<ResolverResult<TFieldValues>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldValues, ResolverOptions, ResolverResult
|
|
1
|
+
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
2
|
import { ValidatorOptions } from 'class-validator';
|
|
3
3
|
import { ClassConstructor } from 'class-transformer';
|
|
4
4
|
export declare type Resolver = <T extends {
|
|
@@ -6,4 +6,4 @@ export declare type Resolver = <T extends {
|
|
|
6
6
|
}>(schema: ClassConstructor<T>, schemaOptions?: ValidatorOptions, resolverOptions?: {
|
|
7
7
|
mode?: 'async' | 'sync';
|
|
8
8
|
rawValues?: boolean;
|
|
9
|
-
}) => <TFieldValues extends FieldValues, TContext>(values:
|
|
9
|
+
}) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
FieldValues,
|
|
3
3
|
ResolverOptions,
|
|
4
4
|
ResolverResult,
|
|
5
|
-
UnpackNestedValue,
|
|
6
5
|
} from 'react-hook-form';
|
|
7
6
|
import { ValidatorOptions } from 'class-validator';
|
|
8
7
|
import { ClassConstructor } from 'class-transformer';
|
|
@@ -12,7 +11,7 @@ export type Resolver = <T extends { [_: string]: any }>(
|
|
|
12
11
|
schemaOptions?: ValidatorOptions,
|
|
13
12
|
resolverOptions?: { mode?: 'async' | 'sync', rawValues?: boolean; },
|
|
14
13
|
) => <TFieldValues extends FieldValues, TContext>(
|
|
15
|
-
values:
|
|
14
|
+
values: TFieldValues,
|
|
16
15
|
context: TContext | undefined,
|
|
17
16
|
options: ResolverOptions<TFieldValues>,
|
|
18
17
|
) => Promise<ResolverResult<TFieldValues>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { FieldValues, ResolverResult,
|
|
2
|
-
export declare type Resolver = (schema: any) => <TFieldValues extends FieldValues, TContext>(values:
|
|
1
|
+
import type { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
|
+
export declare type Resolver = (schema: any) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
FieldValues,
|
|
3
3
|
ResolverResult,
|
|
4
|
-
UnpackNestedValue,
|
|
5
4
|
ResolverOptions,
|
|
6
5
|
} from 'react-hook-form';
|
|
7
6
|
|
|
8
7
|
export type Resolver = (
|
|
9
8
|
schema: any,
|
|
10
9
|
) => <TFieldValues extends FieldValues, TContext>(
|
|
11
|
-
values:
|
|
10
|
+
values: TFieldValues,
|
|
12
11
|
context: TContext | undefined,
|
|
13
12
|
options: ResolverOptions<TFieldValues>,
|
|
14
13
|
) => Promise<ResolverResult<TFieldValues>>;
|
package/dist/resolvers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvers.js","sources":["../src/validateFieldsNatively.ts","../src/toNestError.ts"],"sourcesContent":["import {\n get, FieldError, ResolverOptions, Ref\n} from 'react-hook-form';\n\nconst setCustomValidity = (ref: Ref, fieldPath: string, errors:
|
|
1
|
+
{"version":3,"file":"resolvers.js","sources":["../src/validateFieldsNatively.ts","../src/toNestError.ts"],"sourcesContent":["import {\n get, FieldError, ResolverOptions, Ref, FieldErrors\n} from 'react-hook-form';\n\nconst setCustomValidity = (ref: Ref, fieldPath: string, errors: FieldErrors) => {\n if (ref && 'reportValidity' in ref) {\n const error = get(errors, fieldPath) as FieldError | undefined;\n ref.setCustomValidity((error && error.message) || '');\n\n ref.reportValidity();\n }\n};\n\n// Native validation (web only)\nexport const validateFieldsNatively = <TFieldValues>(\n errors: FieldErrors,\n options: ResolverOptions<TFieldValues>,\n): void => {\n\n\n for (const fieldPath in options.fields) {\n const field = options.fields[fieldPath];\n if (field && field.ref && 'reportValidity' in field.ref) {\n setCustomValidity(field.ref, fieldPath, errors)\n } else if (field.refs) {\n field.refs.forEach((ref: HTMLInputElement) => setCustomValidity(ref, fieldPath, errors))\n }\n }\n};\n","import {\n set,\n get,\n FieldErrors,\n Field,\n ResolverOptions,\n} from 'react-hook-form';\nimport { validateFieldsNatively } from './validateFieldsNatively';\n\nexport const toNestError = <TFieldValues>(\n errors: FieldErrors,\n options: ResolverOptions<TFieldValues>,\n): FieldErrors<TFieldValues> => {\n options.shouldUseNativeValidation && validateFieldsNatively(errors, options);\n\n const fieldErrors = {} as FieldErrors<TFieldValues>;\n for (const path in errors) {\n const field = get(options.fields, path) as Field['_f'] | undefined;\n\n set(\n fieldErrors,\n path,\n Object.assign(errors[path], { ref: field && field.ref }),\n );\n }\n\n return fieldErrors;\n};\n"],"names":["setCustomValidity","ref","fieldPath","errors","error","get","message","reportValidity","validateFieldsNatively","options","field","fields","refs","forEach","shouldUseNativeValidation","fieldErrors","path","set","Object","assign"],"mappings":"iCAIMA,EAAoB,SAACC,EAAUC,EAAmBC,GACtD,GAAIF,GAAO,mBAAoBA,EAAK,CAClC,IAAMG,EAAQC,MAAIF,EAAQD,GAC1BD,EAAID,kBAAmBI,GAASA,EAAME,SAAY,IAElDL,EAAIM,mBAKKC,EAAyB,SACpCL,EACAM,kBAIWP,GACT,IAAMQ,EAAQD,EAAQE,OAAOT,GACzBQ,GAASA,EAAMT,KAAO,mBAAoBS,EAAMT,IAClDD,EAAkBU,EAAMT,IAAKC,EAAWC,GAC/BO,EAAME,MACfF,EAAME,KAAKC,QAAQ,SAACZ,UAA0BD,EAAkBC,EAAKC,EAAWC,MALpF,IAAK,IAAMD,KAAaO,EAAQE,SAArBT,wBCXc,SACzBC,EACAM,GAEAA,EAAQK,2BAA6BN,EAAuBL,EAAQM,GAEpE,IAAMM,EAAc,GACpB,IAAK,IAAMC,KAAQb,EAAQ,CACzB,IAAMO,EAAQL,MAAII,EAAQE,OAAQK,GAElCC,MACEF,EACAC,EACAE,OAAOC,OAAOhB,EAAOa,GAAO,CAAEf,IAAKS,GAASA,EAAMT,OAItD,OAAOc"}
|
package/dist/resolvers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvers.mjs","sources":["../src/validateFieldsNatively.ts","../src/toNestError.ts"],"sourcesContent":["import {\n get, FieldError, ResolverOptions, Ref\n} from 'react-hook-form';\n\nconst setCustomValidity = (ref: Ref, fieldPath: string, errors:
|
|
1
|
+
{"version":3,"file":"resolvers.mjs","sources":["../src/validateFieldsNatively.ts","../src/toNestError.ts"],"sourcesContent":["import {\n get, FieldError, ResolverOptions, Ref, FieldErrors\n} from 'react-hook-form';\n\nconst setCustomValidity = (ref: Ref, fieldPath: string, errors: FieldErrors) => {\n if (ref && 'reportValidity' in ref) {\n const error = get(errors, fieldPath) as FieldError | undefined;\n ref.setCustomValidity((error && error.message) || '');\n\n ref.reportValidity();\n }\n};\n\n// Native validation (web only)\nexport const validateFieldsNatively = <TFieldValues>(\n errors: FieldErrors,\n options: ResolverOptions<TFieldValues>,\n): void => {\n\n\n for (const fieldPath in options.fields) {\n const field = options.fields[fieldPath];\n if (field && field.ref && 'reportValidity' in field.ref) {\n setCustomValidity(field.ref, fieldPath, errors)\n } else if (field.refs) {\n field.refs.forEach((ref: HTMLInputElement) => setCustomValidity(ref, fieldPath, errors))\n }\n }\n};\n","import {\n set,\n get,\n FieldErrors,\n Field,\n ResolverOptions,\n} from 'react-hook-form';\nimport { validateFieldsNatively } from './validateFieldsNatively';\n\nexport const toNestError = <TFieldValues>(\n errors: FieldErrors,\n options: ResolverOptions<TFieldValues>,\n): FieldErrors<TFieldValues> => {\n options.shouldUseNativeValidation && validateFieldsNatively(errors, options);\n\n const fieldErrors = {} as FieldErrors<TFieldValues>;\n for (const path in errors) {\n const field = get(options.fields, path) as Field['_f'] | undefined;\n\n set(\n fieldErrors,\n path,\n Object.assign(errors[path], { ref: field && field.ref }),\n );\n }\n\n return fieldErrors;\n};\n"],"names":["setCustomValidity","ref","fieldPath","errors","error","get","message","reportValidity","validateFieldsNatively","options","fields","field","refs","forEach","toNestError","shouldUseNativeValidation","fieldErrors","path","set","Object","assign"],"mappings":"+CAIA,MAAMA,EAAoB,CAACC,EAAUC,EAAmBC,KACtD,GAAIF,GAAO,mBAAoBA,EAAK,CAClC,MAAMG,EAAQC,EAAIF,EAAQD,GAC1BD,EAAID,kBAAmBI,GAASA,EAAME,SAAY,IAElDL,EAAIM,mBAKKC,EAAyB,CACpCL,EACAM,KAIA,IAAK,MAAMP,KAAaO,EAAQC,OAAQ,CACtC,MAAMC,EAAQF,EAAQC,OAAOR,GACzBS,GAASA,EAAMV,KAAO,mBAAoBU,EAAMV,IAClDD,EAAkBW,EAAMV,IAAKC,EAAWC,GAC/BQ,EAAMC,MACfD,EAAMC,KAAKC,QAASZ,GAA0BD,EAAkBC,EAAKC,EAAWC,MChBzEW,EAAc,CACzBX,EACAM,KAEAA,EAAQM,2BAA6BP,EAAuBL,EAAQM,GAEpE,MAAMO,EAAc,GACpB,IAAK,MAAMC,KAAQd,EAAQ,CACzB,MAAMQ,EAAQN,EAAII,EAAQC,OAAQO,GAElCC,EACEF,EACAC,EACAE,OAAOC,OAAOjB,EAAOc,GAAO,CAAEhB,IAAKU,GAASA,EAAMV,OAItD,OAAOe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvers.module.js","sources":["../src/validateFieldsNatively.ts","../src/toNestError.ts"],"sourcesContent":["import {\n get, FieldError, ResolverOptions, Ref\n} from 'react-hook-form';\n\nconst setCustomValidity = (ref: Ref, fieldPath: string, errors:
|
|
1
|
+
{"version":3,"file":"resolvers.module.js","sources":["../src/validateFieldsNatively.ts","../src/toNestError.ts"],"sourcesContent":["import {\n get, FieldError, ResolverOptions, Ref, FieldErrors\n} from 'react-hook-form';\n\nconst setCustomValidity = (ref: Ref, fieldPath: string, errors: FieldErrors) => {\n if (ref && 'reportValidity' in ref) {\n const error = get(errors, fieldPath) as FieldError | undefined;\n ref.setCustomValidity((error && error.message) || '');\n\n ref.reportValidity();\n }\n};\n\n// Native validation (web only)\nexport const validateFieldsNatively = <TFieldValues>(\n errors: FieldErrors,\n options: ResolverOptions<TFieldValues>,\n): void => {\n\n\n for (const fieldPath in options.fields) {\n const field = options.fields[fieldPath];\n if (field && field.ref && 'reportValidity' in field.ref) {\n setCustomValidity(field.ref, fieldPath, errors)\n } else if (field.refs) {\n field.refs.forEach((ref: HTMLInputElement) => setCustomValidity(ref, fieldPath, errors))\n }\n }\n};\n","import {\n set,\n get,\n FieldErrors,\n Field,\n ResolverOptions,\n} from 'react-hook-form';\nimport { validateFieldsNatively } from './validateFieldsNatively';\n\nexport const toNestError = <TFieldValues>(\n errors: FieldErrors,\n options: ResolverOptions<TFieldValues>,\n): FieldErrors<TFieldValues> => {\n options.shouldUseNativeValidation && validateFieldsNatively(errors, options);\n\n const fieldErrors = {} as FieldErrors<TFieldValues>;\n for (const path in errors) {\n const field = get(options.fields, path) as Field['_f'] | undefined;\n\n set(\n fieldErrors,\n path,\n Object.assign(errors[path], { ref: field && field.ref }),\n );\n }\n\n return fieldErrors;\n};\n"],"names":["setCustomValidity","ref","fieldPath","errors","error","get","message","reportValidity","validateFieldsNatively","options","field","fields","refs","forEach","toNestError","shouldUseNativeValidation","fieldErrors","path","set","Object","assign"],"mappings":"+CAIA,IAAMA,EAAoB,SAACC,EAAUC,EAAmBC,GACtD,GAAIF,GAAO,mBAAoBA,EAAK,CAClC,IAAMG,EAAQC,EAAIF,EAAQD,GAC1BD,EAAID,kBAAmBI,GAASA,EAAME,SAAY,IAElDL,EAAIM,mBAKKC,EAAyB,SACpCL,EACAM,kBAIWP,GACT,IAAMQ,EAAQD,EAAQE,OAAOT,GACzBQ,GAASA,EAAMT,KAAO,mBAAoBS,EAAMT,IAClDD,EAAkBU,EAAMT,IAAKC,EAAWC,GAC/BO,EAAME,MACfF,EAAME,KAAKC,QAAQ,SAACZ,UAA0BD,EAAkBC,EAAKC,EAAWC,MALpF,IAAK,IAAMD,KAAaO,EAAQE,SAArBT,ICXAY,EAAc,SACzBX,EACAM,GAEAA,EAAQM,2BAA6BP,EAAuBL,EAAQM,GAEpE,IAAMO,EAAc,GACpB,IAAK,IAAMC,KAAQd,EAAQ,CACzB,IAAMO,EAAQL,EAAII,EAAQE,OAAQM,GAElCC,EACEF,EACAC,EACAE,OAAOC,OAAOjB,EAAOc,GAAO,CAAEhB,IAAKS,GAASA,EAAMT,OAItD,OAAOe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvers.umd.js","sources":["../src/validateFieldsNatively.ts","../src/toNestError.ts"],"sourcesContent":["import {\n get, FieldError, ResolverOptions, Ref\n} from 'react-hook-form';\n\nconst setCustomValidity = (ref: Ref, fieldPath: string, errors:
|
|
1
|
+
{"version":3,"file":"resolvers.umd.js","sources":["../src/validateFieldsNatively.ts","../src/toNestError.ts"],"sourcesContent":["import {\n get, FieldError, ResolverOptions, Ref, FieldErrors\n} from 'react-hook-form';\n\nconst setCustomValidity = (ref: Ref, fieldPath: string, errors: FieldErrors) => {\n if (ref && 'reportValidity' in ref) {\n const error = get(errors, fieldPath) as FieldError | undefined;\n ref.setCustomValidity((error && error.message) || '');\n\n ref.reportValidity();\n }\n};\n\n// Native validation (web only)\nexport const validateFieldsNatively = <TFieldValues>(\n errors: FieldErrors,\n options: ResolverOptions<TFieldValues>,\n): void => {\n\n\n for (const fieldPath in options.fields) {\n const field = options.fields[fieldPath];\n if (field && field.ref && 'reportValidity' in field.ref) {\n setCustomValidity(field.ref, fieldPath, errors)\n } else if (field.refs) {\n field.refs.forEach((ref: HTMLInputElement) => setCustomValidity(ref, fieldPath, errors))\n }\n }\n};\n","import {\n set,\n get,\n FieldErrors,\n Field,\n ResolverOptions,\n} from 'react-hook-form';\nimport { validateFieldsNatively } from './validateFieldsNatively';\n\nexport const toNestError = <TFieldValues>(\n errors: FieldErrors,\n options: ResolverOptions<TFieldValues>,\n): FieldErrors<TFieldValues> => {\n options.shouldUseNativeValidation && validateFieldsNatively(errors, options);\n\n const fieldErrors = {} as FieldErrors<TFieldValues>;\n for (const path in errors) {\n const field = get(options.fields, path) as Field['_f'] | undefined;\n\n set(\n fieldErrors,\n path,\n Object.assign(errors[path], { ref: field && field.ref }),\n );\n }\n\n return fieldErrors;\n};\n"],"names":["setCustomValidity","ref","fieldPath","errors","error","get","message","reportValidity","validateFieldsNatively","options","field","fields","refs","forEach","shouldUseNativeValidation","fieldErrors","path","set","Object","assign"],"mappings":"0SAIA,IAAMA,EAAoB,SAACC,EAAUC,EAAmBC,GACtD,GAAIF,GAAO,mBAAoBA,EAAK,CAClC,IAAMG,EAAQC,MAAIF,EAAQD,GAC1BD,EAAID,kBAAmBI,GAASA,EAAME,SAAY,IAElDL,EAAIM,mBAKKC,EAAyB,SACpCL,EACAM,kBAIWP,GACT,IAAMQ,EAAQD,EAAQE,OAAOT,GACzBQ,GAASA,EAAMT,KAAO,mBAAoBS,EAAMT,IAClDD,EAAkBU,EAAMT,IAAKC,EAAWC,GAC/BO,EAAME,MACfF,EAAME,KAAKC,QAAQ,SAACZ,UAA0BD,EAAkBC,EAAKC,EAAWC,MALpF,IAAK,IAAMD,KAAaO,EAAQE,SAArBT,kBCXc,SACzBC,EACAM,GAEAA,EAAQK,2BAA6BN,EAAuBL,EAAQM,GAEpE,IAAMM,EAAc,GACpB,IAAK,IAAMC,KAAQb,EAAQ,CACzB,IAAMO,EAAQL,MAAII,EAAQE,OAAQK,GAElCC,MACEF,EACAC,EACAE,OAAOC,OAAOhB,EAAOa,GAAO,CAAEf,IAAKS,GAASA,EAAMT,OAItD,OAAOc"}
|
package/dist/toNestError.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const toNestError: <TFieldValues>(errors:
|
|
1
|
+
import { FieldErrors, ResolverOptions } from 'react-hook-form';
|
|
2
|
+
export declare const toNestError: <TFieldValues>(errors: FieldErrors, options: ResolverOptions<TFieldValues>) => FieldErrors<TFieldValues>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const validateFieldsNatively: <TFieldValues>(errors:
|
|
1
|
+
import { ResolverOptions, FieldErrors } from 'react-hook-form';
|
|
2
|
+
export declare const validateFieldsNatively: <TFieldValues>(errors: FieldErrors, options: ResolverOptions<TFieldValues>) => void;
|
package/io-ts/dist/io-ts.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("fp-ts/
|
|
1
|
+
var e=require("fp-ts/Either"),t=require("fp-ts/function"),r=require("@hookform/resolvers"),n=require("io-ts"),o=require("fp-ts/ReadonlyArray"),u=require("fp-ts/Option"),i=require("fp-ts/Semigroup"),a=require("fp-ts/ReadonlyRecord");function f(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var p=/*#__PURE__*/f(e),c=/*#__PURE__*/f(o),s=/*#__PURE__*/f(u),l=/*#__PURE__*/f(i),d=/*#__PURE__*/f(a);function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var m=function(e){return e.reduce(function(e,r,n){return t.pipe(r,p.fold(function(e){return(n>0?".":"")+e},function(e){return"["+e+"]"}),function(t){return""+e+t})},"")},v=["path"],g=function(e){var r,o=t.pipe(r=e.context,c.filterMapWithIndex(function(e,t){var o=e-1;return void 0===r[o]||r[o].type instanceof n.TaggedUnionType||r[o].type instanceof n.UnionType||r[o].type instanceof n.IntersectionType?s.none:s.some(t)}),c.map(function(e){return e.key}),c.map(function(e){return t.pipe(e,function(e){return parseInt(e,10)},p.fromPredicate(t.not(Number.isNaN),function(){return e}))}),c.toArray,m);return{message:t.pipe(e.message,p.fromNullable(e.context),p.mapLeft(t.flow(c.last,s.map(function(e){return"expected "+e.type.name+" but got "+JSON.stringify(e.actual)}),s.getOrElseW(function(){return t.absurd("Error context is missing name")}))),p.getOrElseW(t.identity)),type:t.pipe(e.context,c.last,s.map(function(e){return e.type.name}),s.getOrElse(function(){return"unknown"})),path:o}},O=function(e){return t.pipe(e,c.map(function(e){var t;return(t={})[e.path]={type:e.type,message:e.message},t}),function(e){return l.fold({concat:function(e,t){return Object.assign({},t,e)}})({},e)})},b={concat:function(e,t){var r;return y({},t,{types:y({},e.types,(r={},r[e.type]=e.message,r[t.type]=t.message,r))})}},h=function(e){return t.pipe(d.fromFoldableMap(b,c.Foldable)(e,function(e){return[e.path,e]}),d.map(function(e){return function(e,t){if(null==e)return{};var r,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)t.indexOf(r=u[n])>=0||(o[r]=e[r]);return o}(e,v)}))};exports.ioTsResolver=function(e){return function(n,o,u){return t.pipe(n,e.decode,p.mapLeft((i=!u.shouldUseNativeValidation&&"all"===u.criteriaMode,function(e){var r=i?h:O;return t.pipe(e,c.map(g),r)})),p.mapLeft(function(e){return r.toNestError(e,u)}),p.fold(function(e){return{values:{},errors:e}},function(e){return u.shouldUseNativeValidation&&r.validateFieldsNatively({},u),{values:e,errors:{}}}));var i}};
|
|
2
2
|
//# sourceMappingURL=io-ts.js.map
|
package/io-ts/dist/io-ts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io-ts.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 t from 'io-ts';\nimport {\n IntersectionType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as Option from 'fp-ts/Option';\nimport * as Either from 'fp-ts/Either';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport arrayToPath from './arrayToPath';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n\n const shouldBeFiltered =\n context[previousIndex] === undefined ||\n context[previousIndex].type instanceof TaggedUnionType ||\n context[previousIndex].type instanceof UnionType ||\n context[previousIndex].type instanceof IntersectionType;\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 * as Either from 'fp-ts/
|
|
1
|
+
{"version":3,"file":"io-ts.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 t from 'io-ts';\nimport {\n IntersectionType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as Option from 'fp-ts/Option';\nimport * as Either from 'fp-ts/Either';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport arrayToPath from './arrayToPath';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n\n const shouldBeFiltered =\n context[previousIndex] === undefined ||\n context[previousIndex].type instanceof TaggedUnionType ||\n context[previousIndex].type instanceof UnionType ||\n context[previousIndex].type instanceof IntersectionType;\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 * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\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) => toNestError(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","formatError","e","context","ReadonlyArray","filterMapWithIndex","contextEntry","previousIndex","undefined","type","TaggedUnionType","UnionType","IntersectionType","Option","none","some","map","k","parseInt","fromPredicate","not","Number","isNaN","toArray","message","fromNullable","mapLeft","flow","last","name","JSON","stringify","actual","getOrElseW","absurd","identity","getOrElse","concatToSingleError","errors","error","SemiGroup","concat","first","second","Object","assign","appendSeveralErrors","a","b","types","concatToMultipleErrors","ReadonlyRecord","fromFoldableMap","Foldable","errorWithPath","codec","values","_context","options","decode","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","validationErrors","toNestError","validateFieldsNatively"],"mappings":"6yBAGA,IAAMA,EAAc,SAACC,UACnBA,EAAMC,OACJ,SAACC,EAAUC,EAAMC,UACfC,OACEF,EACAG,EAAOC,KACL,SAACC,UAAWJ,EAAQ,EAAI,IAAM,IAAKI,GACnC,SAACA,aAAYA,QAEf,SAACL,YAAYD,EAAWC,KAE5B,gBC4BEM,EAAc,SAACC,GACnB,IA3BuBC,EA2BjBR,EA1BNE,OADuBM,EA2BMD,EAAEC,QAxB7BC,EAAcC,mBAAmB,SAACT,EAAOU,GACvC,IAAMC,EAAgBX,EAAQ,EAQ9B,YAL6BY,IAA3BL,EAAQI,IACRJ,EAAQI,GAAeE,gBAAgBC,mBACvCP,EAAQI,GAAeE,gBAAgBE,aACvCR,EAAQI,GAAeE,gBAAgBG,mBAEfC,EAAOC,KAAOD,EAAOE,KAAKT,KAEtDF,EAAcY,IAAI,qBAAGhB,MACrBI,EAAcY,IAAI,SAAChB,UACjBH,OACEG,EACA,SAACiB,UAAMC,SAASD,EAAG,KACnBnB,EAAOqB,cAAcC,MAAYC,OAAOC,OAAQ,kBAAMtB,OAG1DI,EAAcmB,QACdhC,GAiCF,MAAO,CAAEiC,QA3BO3B,OACdK,EAAEsB,QACF1B,EAAO2B,aAAavB,EAAEC,SACtBL,EAAO4B,QACLC,OACEvB,EAAcwB,KACdf,EAAOG,IACL,SAACV,qBACaA,EAAaG,KAAKoB,iBAAgBC,KAAKC,UACjDzB,EAAa0B,UAGnBnB,EAAOoB,WAAW,kBAChBC,SAAe,qCAIrBpC,EAAOmC,WAAWE,aAUF1B,KAPLZ,OACXK,EAAEC,QACFC,EAAcwB,KACdf,EAAOG,IAAI,SAACV,UAAiBA,EAAaG,KAAKoB,OAC/ChB,EAAOuB,UAAU,iBAAM,aAGDzC,KAAAA,IAWpB0C,EAAsB,SAC1BC,UAEAzC,OACEyC,EACAlC,EAAcY,IAAI,SAACuB,sBAChBA,EAAM5C,MAAO,CACZc,KAAM8B,EAAM9B,KACZe,QAASe,EAAMf,aAGnB,SAACc,UAAWE,EAAUzC,KAfM,CAC9B0C,OAAQ,SAACC,EAAOC,UAAWC,OAAOC,OAAO,GAAIF,EAAQD,KAcvCF,CAAkD,GAAIF,MAGhEQ,EAA+D,CACnEL,OAAQ,SAACM,EAAGC,qBACPA,GACHC,WAAYF,EAAEE,cAAQF,EAAEtC,MAAOsC,EAAEvB,UAAUwB,EAAEvC,MAAOuC,EAAExB,gBAIpD0B,EAAyB,SAC7BZ,UAEAzC,OACEsD,EAAeC,gBAAgBN,EAAqB1C,EAAciD,SAAlEF,CACEb,EACA,SAACC,SAAU,CAACA,EAAM5C,KAAM4C,KAE1BY,EAAenC,IAAI,SAACsC,GAIlB,0IAF2BA,8BC5GK,SAACC,mBAAWC,EAAQC,EAAUC,UAClE7D,OACE2D,EACAD,EAAMI,OACN7D,EAAO4B,SD+GRkC,GC7GMF,EAAQG,2BAAsD,QAAzBH,EAAQI,sBD8GnDC,GACC,IAAMtB,EAASmB,EACXV,EACAb,EAEJ,OAAOxC,OAAKkE,EAAkB3D,EAAcY,IAAIf,GAAcwC,MChH9D3C,EAAO4B,QAAQ,SAACY,UAAW0B,cAAY1B,EAAQoB,KAC/C5D,EAAOC,KACL,SAACuC,SAAY,CACXkB,OAAQ,GACRlB,OAAAA,IAEF,SAACkB,GAIC,OAHAE,EAAQG,2BACNI,yBAAuB,GAAIP,GAEtB,CACLF,OAAAA,EACAlB,OAAQ,OD8FhB,IAACsB"}
|
package/io-ts/dist/io-ts.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as t from"fp-ts/
|
|
1
|
+
import*as t from"fp-ts/Either";import{pipe as n,not as r,flow as e,absurd as o,identity as u}from"fp-ts/function";import{toNestError as a,validateFieldsNatively as i}from"@hookform/resolvers";import{TaggedUnionType as f,UnionType as s,IntersectionType as c}from"io-ts";import*as p from"fp-ts/ReadonlyArray";import*as m from"fp-ts/Option";import*as l from"fp-ts/Semigroup";import*as y from"fp-ts/ReadonlyRecord";function d(){return(d=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t}).apply(this,arguments)}var g=function(r){return r.reduce(function(r,e,o){return n(e,t.fold(function(t){return(o>0?".":"")+t},function(t){return"["+t+"]"}),function(t){return""+r+t})},"")},v=["path"],h=function(a){var i,l=n(i=a.context,p.filterMapWithIndex(function(t,n){var r=t-1;return void 0===i[r]||i[r].type instanceof f||i[r].type instanceof s||i[r].type instanceof c?m.none:m.some(n)}),p.map(function(t){return t.key}),p.map(function(e){return n(e,function(t){return parseInt(t,10)},t.fromPredicate(r(Number.isNaN),function(){return e}))}),p.toArray,g);return{message:n(a.message,t.fromNullable(a.context),t.mapLeft(e(p.last,m.map(function(t){return"expected "+t.type.name+" but got "+JSON.stringify(t.actual)}),m.getOrElseW(function(){return o("Error context is missing name")}))),t.getOrElseW(u)),type:n(a.context,p.last,m.map(function(t){return t.type.name}),m.getOrElse(function(){return"unknown"})),path:l}},O=function(t){return n(t,p.map(function(t){var n;return(n={})[t.path]={type:t.type,message:t.message},n}),function(t){return l.fold({concat:function(t,n){return Object.assign({},n,t)}})({},t)})},b={concat:function(t,n){var r;return d({},n,{types:d({},t.types,(r={},r[t.type]=t.message,r[n.type]=n.message,r))})}},x=function(t){return n(y.fromFoldableMap(b,p.Foldable)(t,function(t){return[t.path,t]}),y.map(function(t){return function(t,n){if(null==t)return{};var r,e,o={},u=Object.keys(t);for(e=0;e<u.length;e++)n.indexOf(r=u[e])>=0||(o[r]=t[r]);return o}(t,v)}))},N=function(r){return function(e,o,u){return n(e,r.decode,t.mapLeft((f=!u.shouldUseNativeValidation&&"all"===u.criteriaMode,function(t){var r=f?x:O;return n(t,p.map(h),r)})),t.mapLeft(function(t){return a(t,u)}),t.fold(function(t){return{values:{},errors:t}},function(t){return u.shouldUseNativeValidation&&i({},u),{values:t,errors:{}}}));var f}};export{N as ioTsResolver};
|
|
2
2
|
//# sourceMappingURL=io-ts.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as e from"fp-ts/
|
|
1
|
+
import*as e from"fp-ts/Either";import{pipe as t,not as r,flow as o,absurd as a,identity as s}from"fp-ts/function";import{toNestError as n,validateFieldsNatively as p}from"@hookform/resolvers";import{TaggedUnionType as i,UnionType as m,IntersectionType as f}from"io-ts";import*as l from"fp-ts/ReadonlyArray";import*as c from"fp-ts/Option";import*as u from"fp-ts/Semigroup";import*as y from"fp-ts/ReadonlyRecord";function d(){return(d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}const g=r=>r.reduce((r,o,a)=>t(o,e.fold(e=>`${a>0?".":""}${e}`,e=>`[${e}]`),e=>`${r}${e}`),""),h=["path"],v=n=>{const p=t(u=n.context,l.filterMapWithIndex((e,t)=>{const r=e-1;return void 0===u[r]||u[r].type instanceof i||u[r].type instanceof m||u[r].type instanceof f?c.none:c.some(t)}),l.map(({key:e})=>e),l.map(o=>t(o,e=>parseInt(e,10),e.fromPredicate(r(Number.isNaN),()=>o))),l.toArray,g);var u;return{message:t(n.message,e.fromNullable(n.context),e.mapLeft(o(l.last,c.map(e=>`expected ${e.type.name} but got ${JSON.stringify(e.actual)}`),c.getOrElseW(()=>a("Error context is missing name")))),e.getOrElseW(s)),type:t(n.context,l.last,c.map(e=>e.type.name),c.getOrElse(()=>"unknown")),path:p}},O=e=>t(e,l.map(e=>({[e.path]:{type:e.type,message:e.message}})),e=>u.fold({concat:(e,t)=>Object.assign({},t,e)})({},e)),b={concat:(e,t)=>d({},t,{types:d({},e.types,{[e.type]:e.message,[t.type]:t.message})})},x=e=>t(y.fromFoldableMap(b,l.Foldable)(e,e=>[e.path,e]),y.map(e=>function(e,t){if(null==e)return{};var r,o,a={},s=Object.keys(e);for(o=0;o<s.length;o++)t.indexOf(r=s[o])>=0||(a[r]=e[r]);return a}(e,h))),N=r=>(o,a,s)=>{return t(o,r.decode,e.mapLeft((i=!s.shouldUseNativeValidation&&"all"===s.criteriaMode,e=>{const r=i?x:O;return t(e,l.map(v),r)})),e.mapLeft(e=>n(e,s)),e.fold(e=>({values:{},errors:e}),e=>(s.shouldUseNativeValidation&&p({},s),{values:e,errors:{}})));var i};export{N as ioTsResolver};
|
|
2
2
|
//# sourceMappingURL=io-ts.modern.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io-ts.modern.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 t from 'io-ts';\nimport {\n IntersectionType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as Option from 'fp-ts/Option';\nimport * as Either from 'fp-ts/Either';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport arrayToPath from './arrayToPath';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n\n const shouldBeFiltered =\n context[previousIndex] === undefined ||\n context[previousIndex].type instanceof TaggedUnionType ||\n context[previousIndex].type instanceof UnionType ||\n context[previousIndex].type instanceof IntersectionType;\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 * as Either from 'fp-ts/
|
|
1
|
+
{"version":3,"file":"io-ts.modern.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 t from 'io-ts';\nimport {\n IntersectionType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as Option from 'fp-ts/Option';\nimport * as Either from 'fp-ts/Either';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport arrayToPath from './arrayToPath';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n\n const shouldBeFiltered =\n context[previousIndex] === undefined ||\n context[previousIndex].type instanceof TaggedUnionType ||\n context[previousIndex].type instanceof UnionType ||\n context[previousIndex].type instanceof IntersectionType;\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 * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\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) => toNestError(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","formatError","e","context","ReadonlyArray","filterMapWithIndex","contextEntry","previousIndex","undefined","type","TaggedUnionType","UnionType","IntersectionType","Option","none","some","map","k","parseInt","fromPredicate","not","Number","isNaN","toArray","message","fromNullable","mapLeft","flow","last","name","JSON","stringify","actual","getOrElseW","absurd","identity","getOrElse","concatToSingleError","errors","error","SemiGroup","concat","first","second","Object","assign","appendSeveralErrors","a","b","types","concatToMultipleErrors","ReadonlyRecord","fromFoldableMap","Foldable","errorWithPath","ioTsResolver","codec","values","_context","options","decode","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","validationErrors","toNestError","validateFieldsNatively"],"mappings":"0mBAGA,MAAMA,EAAeC,GACnBA,EAAMC,OACJ,CAACC,EAAUC,EAAMC,IACfC,EACEF,EACAG,EAAOC,KACJC,MAAWJ,EAAQ,EAAI,IAAM,KAAKI,IAClCA,OAAYA,MAEdL,MAAYD,IAAWC,KAE5B,eC4BEM,EAAeC,IACnB,MAAMP,EA1BNE,EADuBM,EA2BMD,EAAEC,QAxB7BC,EAAcC,mBAAmB,CAACT,EAAOU,KACvC,MAAMC,EAAgBX,EAAQ,EAQ9B,YAL6BY,IAA3BL,EAAQI,IACRJ,EAAQI,GAAeE,gBAAgBC,GACvCP,EAAQI,GAAeE,gBAAgBE,GACvCR,EAAQI,GAAeE,gBAAgBG,EAEfC,EAAOC,KAAOD,EAAOE,KAAKT,KAEtDF,EAAcY,IAAI,EAAGhB,IAAAA,KAAUA,GAC/BI,EAAcY,IAAKhB,GACjBH,EACEG,EACCiB,GAAMC,SAASD,EAAG,IACnBnB,EAAOqB,cAAcC,EAAYC,OAAOC,OAAQ,IAAMtB,KAG1DI,EAAcmB,QACdhC,GAvBqBY,IAAAA,EAwDvB,MAAO,CAAEqB,QA3BO3B,EACdK,EAAEsB,QACF1B,EAAO2B,aAAavB,EAAEC,SACtBL,EAAO4B,QACLC,EACEvB,EAAcwB,KACdf,EAAOG,IACJV,eACaA,EAAaG,KAAKoB,gBAAgBC,KAAKC,UACjDzB,EAAa0B,WAGnBnB,EAAOoB,WAAW,IAChBC,EAAe,oCAIrBpC,EAAOmC,WAAWE,IAUF1B,KAPLZ,EACXK,EAAEC,QACFC,EAAcwB,KACdf,EAAOG,IAAKV,GAAiBA,EAAaG,KAAKoB,MAC/ChB,EAAOuB,UAAU,IAAM,YAGDzC,KAAAA,IAWpB0C,EACJC,GAEAzC,EACEyC,EACAlC,EAAcY,IAAKuB,KACjB,CAACA,EAAM5C,MAAO,CACZc,KAAM8B,EAAM9B,KACZe,QAASe,EAAMf,YAGlBc,GAAWE,EAAUzC,MAdxB0C,OAAQ,CAACC,EAAOC,IAAWC,OAAOC,OAAO,GAAIF,EAAQD,IAcvCF,CAAkD,GAAIF,IAGhEQ,EAA+D,CACnEL,OAAQ,CAACM,EAAGC,SACPA,GACHC,WAAYF,EAAEE,OAAO,CAACF,EAAEtC,MAAOsC,EAAEvB,QAAS,CAACwB,EAAEvC,MAAOuC,EAAExB,aAIpD0B,EACJZ,GAEAzC,EACEsD,EAAeC,gBAAgBN,EAAqB1C,EAAciD,SAAlEF,CACEb,EACCC,GAAU,CAACA,EAAM5C,KAAM4C,IAE1BY,EAAenC,IAAKsC,sIAESA,OC5GpBC,EAA0BC,GAAU,CAACC,EAAQC,EAAUC,KAClE9D,OAAAA,EACE4D,EACAD,EAAMI,OACN9D,EAAO4B,SD+GRmC,GC7GMF,EAAQG,2BAAsD,QAAzBH,EAAQI,aD8GnDC,IACC,MAAMvB,EAASoB,EACXX,EACAb,EAEJ,OAAOxC,EAAKmE,EAAkB5D,EAAcY,IAAIf,GAAcwC,MChH9D3C,EAAO4B,QAASY,GAAW2B,EAAY3B,EAAQqB,IAC/C7D,EAAOC,KACJuC,KACCmB,OAAQ,GACRnB,OAAAA,IAEDmB,IACCE,EAAQG,2BACNI,EAAuB,GAAIP,GAEtB,CACLF,OAAAA,EACAnB,OAAQ,OD8FfuB,IAAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as t from"fp-ts/
|
|
1
|
+
import*as t from"fp-ts/Either";import{pipe as n,not as r,flow as e,absurd as o,identity as u}from"fp-ts/function";import{toNestError as a,validateFieldsNatively as i}from"@hookform/resolvers";import{TaggedUnionType as f,UnionType as s,IntersectionType as c}from"io-ts";import*as p from"fp-ts/ReadonlyArray";import*as m from"fp-ts/Option";import*as l from"fp-ts/Semigroup";import*as y from"fp-ts/ReadonlyRecord";function d(){return(d=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t}).apply(this,arguments)}var g=function(r){return r.reduce(function(r,e,o){return n(e,t.fold(function(t){return(o>0?".":"")+t},function(t){return"["+t+"]"}),function(t){return""+r+t})},"")},v=["path"],h=function(a){var i,l=n(i=a.context,p.filterMapWithIndex(function(t,n){var r=t-1;return void 0===i[r]||i[r].type instanceof f||i[r].type instanceof s||i[r].type instanceof c?m.none:m.some(n)}),p.map(function(t){return t.key}),p.map(function(e){return n(e,function(t){return parseInt(t,10)},t.fromPredicate(r(Number.isNaN),function(){return e}))}),p.toArray,g);return{message:n(a.message,t.fromNullable(a.context),t.mapLeft(e(p.last,m.map(function(t){return"expected "+t.type.name+" but got "+JSON.stringify(t.actual)}),m.getOrElseW(function(){return o("Error context is missing name")}))),t.getOrElseW(u)),type:n(a.context,p.last,m.map(function(t){return t.type.name}),m.getOrElse(function(){return"unknown"})),path:l}},O=function(t){return n(t,p.map(function(t){var n;return(n={})[t.path]={type:t.type,message:t.message},n}),function(t){return l.fold({concat:function(t,n){return Object.assign({},n,t)}})({},t)})},b={concat:function(t,n){var r;return d({},n,{types:d({},t.types,(r={},r[t.type]=t.message,r[n.type]=n.message,r))})}},x=function(t){return n(y.fromFoldableMap(b,p.Foldable)(t,function(t){return[t.path,t]}),y.map(function(t){return function(t,n){if(null==t)return{};var r,e,o={},u=Object.keys(t);for(e=0;e<u.length;e++)n.indexOf(r=u[e])>=0||(o[r]=t[r]);return o}(t,v)}))},N=function(r){return function(e,o,u){return n(e,r.decode,t.mapLeft((f=!u.shouldUseNativeValidation&&"all"===u.criteriaMode,function(t){var r=f?x:O;return n(t,p.map(h),r)})),t.mapLeft(function(t){return a(t,u)}),t.fold(function(t){return{values:{},errors:t}},function(t){return u.shouldUseNativeValidation&&i({},u),{values:t,errors:{}}}));var f}};export{N 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 t from 'io-ts';\nimport {\n IntersectionType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as Option from 'fp-ts/Option';\nimport * as Either from 'fp-ts/Either';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport arrayToPath from './arrayToPath';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n\n const shouldBeFiltered =\n context[previousIndex] === undefined ||\n context[previousIndex].type instanceof TaggedUnionType ||\n context[previousIndex].type instanceof UnionType ||\n context[previousIndex].type instanceof IntersectionType;\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 * as Either from 'fp-ts/
|
|
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 t from 'io-ts';\nimport {\n IntersectionType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as Option from 'fp-ts/Option';\nimport * as Either from 'fp-ts/Either';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport arrayToPath from './arrayToPath';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n\n const shouldBeFiltered =\n context[previousIndex] === undefined ||\n context[previousIndex].type instanceof TaggedUnionType ||\n context[previousIndex].type instanceof UnionType ||\n context[previousIndex].type instanceof IntersectionType;\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 * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\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) => toNestError(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","formatError","e","context","ReadonlyArray","filterMapWithIndex","contextEntry","previousIndex","undefined","type","TaggedUnionType","UnionType","IntersectionType","Option","none","some","map","k","parseInt","fromPredicate","not","Number","isNaN","toArray","message","fromNullable","mapLeft","flow","last","name","JSON","stringify","actual","getOrElseW","absurd","identity","getOrElse","concatToSingleError","errors","error","SemiGroup","concat","first","second","Object","assign","appendSeveralErrors","a","b","types","concatToMultipleErrors","ReadonlyRecord","fromFoldableMap","Foldable","errorWithPath","ioTsResolver","codec","values","_context","options","decode","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","validationErrors","toNestError","validateFieldsNatively"],"mappings":"0mBAGA,IAAMA,EAAc,SAACC,UACnBA,EAAMC,OACJ,SAACC,EAAUC,EAAMC,UACfC,EACEF,EACAG,EAAOC,KACL,SAACC,UAAWJ,EAAQ,EAAI,IAAM,IAAKI,GACnC,SAACA,aAAYA,QAEf,SAACL,YAAYD,EAAWC,KAE5B,gBC4BEM,EAAc,SAACC,GACnB,IA3BuBC,EA2BjBR,EA1BNE,EADuBM,EA2BMD,EAAEC,QAxB7BC,EAAcC,mBAAmB,SAACT,EAAOU,GACvC,IAAMC,EAAgBX,EAAQ,EAQ9B,YAL6BY,IAA3BL,EAAQI,IACRJ,EAAQI,GAAeE,gBAAgBC,GACvCP,EAAQI,GAAeE,gBAAgBE,GACvCR,EAAQI,GAAeE,gBAAgBG,EAEfC,EAAOC,KAAOD,EAAOE,KAAKT,KAEtDF,EAAcY,IAAI,qBAAGhB,MACrBI,EAAcY,IAAI,SAAChB,UACjBH,EACEG,EACA,SAACiB,UAAMC,SAASD,EAAG,KACnBnB,EAAOqB,cAAcC,EAAYC,OAAOC,OAAQ,kBAAMtB,OAG1DI,EAAcmB,QACdhC,GAiCF,MAAO,CAAEiC,QA3BO3B,EACdK,EAAEsB,QACF1B,EAAO2B,aAAavB,EAAEC,SACtBL,EAAO4B,QACLC,EACEvB,EAAcwB,KACdf,EAAOG,IACL,SAACV,qBACaA,EAAaG,KAAKoB,iBAAgBC,KAAKC,UACjDzB,EAAa0B,UAGnBnB,EAAOoB,WAAW,kBAChBC,EAAe,qCAIrBpC,EAAOmC,WAAWE,IAUF1B,KAPLZ,EACXK,EAAEC,QACFC,EAAcwB,KACdf,EAAOG,IAAI,SAACV,UAAiBA,EAAaG,KAAKoB,OAC/ChB,EAAOuB,UAAU,iBAAM,aAGDzC,KAAAA,IAWpB0C,EAAsB,SAC1BC,UAEAzC,EACEyC,EACAlC,EAAcY,IAAI,SAACuB,sBAChBA,EAAM5C,MAAO,CACZc,KAAM8B,EAAM9B,KACZe,QAASe,EAAMf,aAGnB,SAACc,UAAWE,EAAUzC,KAfM,CAC9B0C,OAAQ,SAACC,EAAOC,UAAWC,OAAOC,OAAO,GAAIF,EAAQD,KAcvCF,CAAkD,GAAIF,MAGhEQ,EAA+D,CACnEL,OAAQ,SAACM,EAAGC,qBACPA,GACHC,WAAYF,EAAEE,cAAQF,EAAEtC,MAAOsC,EAAEvB,UAAUwB,EAAEvC,MAAOuC,EAAExB,gBAIpD0B,EAAyB,SAC7BZ,UAEAzC,EACEsD,EAAeC,gBAAgBN,EAAqB1C,EAAciD,SAAlEF,CACEb,EACA,SAACC,SAAU,CAACA,EAAM5C,KAAM4C,KAE1BY,EAAenC,IAAI,SAACsC,GAIlB,0IAF2BA,SC5GpBC,EAAyB,SAACC,mBAAWC,EAAQC,EAAUC,UAClE9D,EACE4D,EACAD,EAAMI,OACN9D,EAAO4B,SD+GRmC,GC7GMF,EAAQG,2BAAsD,QAAzBH,EAAQI,sBD8GnDC,GACC,IAAMvB,EAASoB,EACXX,EACAb,EAEJ,OAAOxC,EAAKmE,EAAkB5D,EAAcY,IAAIf,GAAcwC,MChH9D3C,EAAO4B,QAAQ,SAACY,UAAW2B,EAAY3B,EAAQqB,KAC/C7D,EAAOC,KACL,SAACuC,SAAY,CACXmB,OAAQ,GACRnB,OAAAA,IAEF,SAACmB,GAIC,OAHAE,EAAQG,2BACNI,EAAuB,GAAIP,GAEtB,CACLF,OAAAA,EACAnB,OAAQ,OD8FhB,IAACuB"}
|
package/io-ts/dist/io-ts.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fp-ts/
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fp-ts/Either"),require("fp-ts/function"),require("@hookform/resolvers"),require("io-ts"),require("fp-ts/ReadonlyArray"),require("fp-ts/Option"),require("fp-ts/Semigroup"),require("fp-ts/ReadonlyRecord")):"function"==typeof define&&define.amd?define(["exports","fp-ts/Either","fp-ts/function","@hookform/resolvers","io-ts","fp-ts/ReadonlyArray","fp-ts/Option","fp-ts/Semigroup","fp-ts/ReadonlyRecord"],t):t((e||self).hookformResolversIoTs={},e.Either,e._function,e.hookformResolvers,e.ioTs,e.ReadonlyArray,e.Option,e.SemiGroup,e.ReadonlyRecord)}(this,function(e,t,n,r,o,i,u,f,a){function p(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var s=/*#__PURE__*/p(t),c=/*#__PURE__*/p(i),l=/*#__PURE__*/p(u),d=/*#__PURE__*/p(f),y=/*#__PURE__*/p(a);function m(){return(m=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var v=function(e){return e.reduce(function(e,t,r){return n.pipe(t,s.fold(function(e){return(r>0?".":"")+e},function(e){return"["+e+"]"}),function(t){return""+e+t})},"")},g=["path"],h=function(e){var t,r=n.pipe(t=e.context,c.filterMapWithIndex(function(e,n){var r=e-1;return void 0===t[r]||t[r].type instanceof o.TaggedUnionType||t[r].type instanceof o.UnionType||t[r].type instanceof o.IntersectionType?l.none:l.some(n)}),c.map(function(e){return e.key}),c.map(function(e){return n.pipe(e,function(e){return parseInt(e,10)},s.fromPredicate(n.not(Number.isNaN),function(){return e}))}),c.toArray,v);return{message:n.pipe(e.message,s.fromNullable(e.context),s.mapLeft(n.flow(c.last,l.map(function(e){return"expected "+e.type.name+" but got "+JSON.stringify(e.actual)}),l.getOrElseW(function(){return n.absurd("Error context is missing name")}))),s.getOrElseW(n.identity)),type:n.pipe(e.context,c.last,l.map(function(e){return e.type.name}),l.getOrElse(function(){return"unknown"})),path:r}},b=function(e){return n.pipe(e,c.map(function(e){var t;return(t={})[e.path]={type:e.type,message:e.message},t}),function(e){return d.fold({concat:function(e,t){return Object.assign({},t,e)}})({},e)})},O={concat:function(e,t){var n;return m({},t,{types:m({},e.types,(n={},n[e.type]=e.message,n[t.type]=t.message,n))})}},R=function(e){return n.pipe(y.fromFoldableMap(O,c.Foldable)(e,function(e){return[e.path,e]}),y.map(function(e){return function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])>=0||(o[n]=e[n]);return o}(e,g)}))};e.ioTsResolver=function(e){return function(t,o,i){return n.pipe(t,e.decode,s.mapLeft((u=!i.shouldUseNativeValidation&&"all"===i.criteriaMode,function(e){var t=u?R:b;return n.pipe(e,c.map(h),t)})),s.mapLeft(function(e){return r.toNestError(e,i)}),s.fold(function(e){return{values:{},errors:e}},function(e){return i.shouldUseNativeValidation&&r.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 t from 'io-ts';\nimport {\n IntersectionType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as Option from 'fp-ts/Option';\nimport * as Either from 'fp-ts/Either';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport arrayToPath from './arrayToPath';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n\n const shouldBeFiltered =\n context[previousIndex] === undefined ||\n context[previousIndex].type instanceof TaggedUnionType ||\n context[previousIndex].type instanceof UnionType ||\n context[previousIndex].type instanceof IntersectionType;\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 * as Either from 'fp-ts/
|
|
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 t from 'io-ts';\nimport {\n IntersectionType,\n TaggedUnionType,\n UnionType,\n ValidationError,\n} from 'io-ts';\nimport { absurd, flow, identity, not, pipe } from 'fp-ts/function';\nimport * as ReadonlyArray from 'fp-ts/ReadonlyArray';\nimport * as Option from 'fp-ts/Option';\nimport * as Either from 'fp-ts/Either';\nimport * as SemiGroup from 'fp-ts/Semigroup';\nimport arrayToPath from './arrayToPath';\nimport * as ReadonlyRecord from 'fp-ts/ReadonlyRecord';\nimport { ErrorObject, FieldErrorWithPath } from './types';\n\nconst formatErrorPath = (context: t.Context): string =>\n pipe(\n context,\n ReadonlyArray.filterMapWithIndex((index, contextEntry) => {\n const previousIndex = index - 1;\n\n const shouldBeFiltered =\n context[previousIndex] === undefined ||\n context[previousIndex].type instanceof TaggedUnionType ||\n context[previousIndex].type instanceof UnionType ||\n context[previousIndex].type instanceof IntersectionType;\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 * as Either from 'fp-ts/Either';\nimport { pipe } from 'fp-ts/function';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\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) => toNestError(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","formatError","e","context","ReadonlyArray","filterMapWithIndex","contextEntry","previousIndex","undefined","type","TaggedUnionType","UnionType","IntersectionType","Option","none","some","map","k","parseInt","fromPredicate","not","Number","isNaN","toArray","message","fromNullable","mapLeft","flow","last","name","JSON","stringify","actual","getOrElseW","absurd","identity","getOrElse","concatToSingleError","errors","error","SemiGroup","concat","first","second","Object","assign","appendSeveralErrors","a","b","types","concatToMultipleErrors","ReadonlyRecord","fromFoldableMap","Foldable","errorWithPath","codec","values","_context","options","decode","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","validationErrors","toNestError","validateFieldsNatively"],"mappings":"0wCAGA,IAAMA,EAAc,SAACC,UACnBA,EAAMC,OACJ,SAACC,EAAUC,EAAMC,UACfC,OACEF,EACAG,EAAOC,KACL,SAACC,UAAWJ,EAAQ,EAAI,IAAM,IAAKI,GACnC,SAACA,aAAYA,QAEf,SAACL,YAAYD,EAAWC,KAE5B,gBC4BEM,EAAc,SAACC,GACnB,IA3BuBC,EA2BjBR,EA1BNE,OADuBM,EA2BMD,EAAEC,QAxB7BC,EAAcC,mBAAmB,SAACT,EAAOU,GACvC,IAAMC,EAAgBX,EAAQ,EAQ9B,YAL6BY,IAA3BL,EAAQI,IACRJ,EAAQI,GAAeE,gBAAgBC,mBACvCP,EAAQI,GAAeE,gBAAgBE,aACvCR,EAAQI,GAAeE,gBAAgBG,mBAEfC,EAAOC,KAAOD,EAAOE,KAAKT,KAEtDF,EAAcY,IAAI,qBAAGhB,MACrBI,EAAcY,IAAI,SAAChB,UACjBH,OACEG,EACA,SAACiB,UAAMC,SAASD,EAAG,KACnBnB,EAAOqB,cAAcC,MAAYC,OAAOC,OAAQ,kBAAMtB,OAG1DI,EAAcmB,QACdhC,GAiCF,MAAO,CAAEiC,QA3BO3B,OACdK,EAAEsB,QACF1B,EAAO2B,aAAavB,EAAEC,SACtBL,EAAO4B,QACLC,OACEvB,EAAcwB,KACdf,EAAOG,IACL,SAACV,qBACaA,EAAaG,KAAKoB,iBAAgBC,KAAKC,UACjDzB,EAAa0B,UAGnBnB,EAAOoB,WAAW,kBAChBC,SAAe,qCAIrBpC,EAAOmC,WAAWE,aAUF1B,KAPLZ,OACXK,EAAEC,QACFC,EAAcwB,KACdf,EAAOG,IAAI,SAACV,UAAiBA,EAAaG,KAAKoB,OAC/ChB,EAAOuB,UAAU,iBAAM,aAGDzC,KAAAA,IAWpB0C,EAAsB,SAC1BC,UAEAzC,OACEyC,EACAlC,EAAcY,IAAI,SAACuB,sBAChBA,EAAM5C,MAAO,CACZc,KAAM8B,EAAM9B,KACZe,QAASe,EAAMf,aAGnB,SAACc,UAAWE,EAAUzC,KAfM,CAC9B0C,OAAQ,SAACC,EAAOC,UAAWC,OAAOC,OAAO,GAAIF,EAAQD,KAcvCF,CAAkD,GAAIF,MAGhEQ,EAA+D,CACnEL,OAAQ,SAACM,EAAGC,qBACPA,GACHC,WAAYF,EAAEE,cAAQF,EAAEtC,MAAOsC,EAAEvB,UAAUwB,EAAEvC,MAAOuC,EAAExB,gBAIpD0B,EAAyB,SAC7BZ,UAEAzC,OACEsD,EAAeC,gBAAgBN,EAAqB1C,EAAciD,SAAlEF,CACEb,EACA,SAACC,SAAU,CAACA,EAAM5C,KAAM4C,KAE1BY,EAAenC,IAAI,SAACsC,GAIlB,0IAF2BA,wBC5GK,SAACC,mBAAWC,EAAQC,EAAUC,UAClE7D,OACE2D,EACAD,EAAMI,OACN7D,EAAO4B,SD+GRkC,GC7GMF,EAAQG,2BAAsD,QAAzBH,EAAQI,sBD8GnDC,GACC,IAAMtB,EAASmB,EACXV,EACAb,EAEJ,OAAOxC,OAAKkE,EAAkB3D,EAAcY,IAAIf,GAAcwC,MChH9D3C,EAAO4B,QAAQ,SAACY,UAAW0B,cAAY1B,EAAQoB,KAC/C5D,EAAOC,KACL,SAACuC,SAAY,CACXkB,OAAQ,GACRlB,OAAAA,IAEF,SAACkB,GAIC,OAHAE,EAAQG,2BACNI,yBAAuB,GAAIP,GAEtB,CACLF,OAAAA,EACAlB,OAAQ,OD8FhB,IAACsB"}
|
package/io-ts/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as t from 'io-ts';
|
|
2
|
-
import { FieldError, FieldValues, ResolverOptions, ResolverResult
|
|
3
|
-
export declare type Resolver = <T, TFieldValues, TContext>(codec: t.Decoder<FieldValues, T>) => (values:
|
|
2
|
+
import { FieldError, FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
3
|
+
export declare type Resolver = <T, TFieldValues, TContext>(codec: t.Decoder<FieldValues, T>) => (values: TFieldValues, _context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
|
|
4
4
|
export declare type ErrorObject = Record<string, FieldError>;
|
|
5
5
|
export declare type FieldErrorWithPath = FieldError & {
|
|
6
6
|
path: string;
|
package/io-ts/src/io-ts.ts
CHANGED