@hookform/resolvers 2.3.0 → 2.5.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 +86 -11
- package/computed-types/dist/computed-types.d.ts +2 -0
- package/computed-types/dist/computed-types.js +2 -0
- package/computed-types/dist/computed-types.js.map +1 -0
- package/computed-types/dist/computed-types.mjs +2 -0
- package/computed-types/dist/computed-types.modern.js +2 -0
- package/computed-types/dist/computed-types.modern.js.map +1 -0
- package/computed-types/dist/computed-types.module.js +2 -0
- package/computed-types/dist/computed-types.module.js.map +1 -0
- package/computed-types/dist/computed-types.umd.js +2 -0
- package/computed-types/dist/computed-types.umd.js.map +1 -0
- package/computed-types/dist/index.d.ts +2 -0
- package/computed-types/dist/types.d.ts +2 -0
- package/computed-types/package.json +17 -0
- package/computed-types/src/__tests__/Form.tsx +54 -0
- package/computed-types/src/__tests__/__fixtures__/data.ts +72 -0
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +65 -0
- package/computed-types/src/__tests__/computed-types.ts +20 -0
- package/computed-types/src/computed-types.ts +42 -0
- package/computed-types/src/index.ts +2 -0
- package/computed-types/src/types.ts +14 -0
- package/io-ts/src/__tests__/Form.tsx +65 -0
- package/io-ts/src/__tests__/__fixtures__/data.ts +129 -0
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +89 -0
- package/io-ts/src/__tests__/io-ts.ts +32 -0
- 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.js +1 -1
- package/joi/dist/joi.modern.js.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/src/__tests__/__fixtures__/data.ts +12 -3
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +20 -10
- package/joi/src/joi.ts +6 -1
- package/nope/dist/index.d.ts +2 -0
- package/nope/dist/nope.d.ts +2 -0
- package/nope/dist/nope.js +2 -0
- package/nope/dist/nope.js.map +1 -0
- package/nope/dist/nope.mjs +2 -0
- package/nope/dist/nope.modern.js +2 -0
- package/nope/dist/nope.modern.js.map +1 -0
- package/nope/dist/nope.module.js +2 -0
- package/nope/dist/nope.module.js.map +1 -0
- package/nope/dist/nope.umd.js +2 -0
- package/nope/dist/nope.umd.js.map +1 -0
- package/nope/dist/types.d.ts +6 -0
- package/nope/package.json +18 -0
- package/nope/src/__tests__/Form.tsx +57 -0
- package/nope/src/__tests__/__fixtures__/data.ts +70 -0
- package/nope/src/__tests__/__snapshots__/nope.ts.snap +43 -0
- package/nope/src/__tests__/nope.ts +24 -0
- package/nope/src/index.ts +2 -0
- package/nope/src/nope.ts +40 -0
- package/nope/src/types.ts +19 -0
- package/package.json +51 -32
- package/yup/dist/yup.js +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.mjs +1 -1
- package/yup/dist/yup.modern.js +1 -1
- package/yup/dist/yup.modern.js.map +1 -1
- package/yup/dist/yup.module.js +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/__fixtures__/data.ts +11 -4
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +16 -6
- package/yup/src/yup.ts +6 -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.js +1 -1
- package/zod/dist/zod.modern.js.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__/__fixtures__/data.ts +12 -3
- package/zod/src/__tests__/__snapshots__/zod.ts.snap +24 -8
- package/zod/src/zod.ts +6 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import * as t from 'io-ts';
|
|
2
|
+
import * as tt from 'io-ts-types';
|
|
3
|
+
|
|
4
|
+
import { Field, InternalFieldName } from 'react-hook-form';
|
|
5
|
+
|
|
6
|
+
export const schema = t.intersection([
|
|
7
|
+
t.type({
|
|
8
|
+
username: tt.NonEmptyString,
|
|
9
|
+
password: tt.NonEmptyString,
|
|
10
|
+
accessToken: tt.UUID,
|
|
11
|
+
birthYear: t.number,
|
|
12
|
+
email: t.string,
|
|
13
|
+
tags: t.array(
|
|
14
|
+
t.type({
|
|
15
|
+
name: t.string,
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
luckyNumbers: t.array(t.number),
|
|
19
|
+
enabled: t.boolean,
|
|
20
|
+
animal: t.union([
|
|
21
|
+
t.string,
|
|
22
|
+
t.number,
|
|
23
|
+
t.literal('bird'),
|
|
24
|
+
t.literal('snake'),
|
|
25
|
+
]),
|
|
26
|
+
vehicles: t.array(
|
|
27
|
+
t.union([
|
|
28
|
+
t.type({
|
|
29
|
+
type: t.literal('car'),
|
|
30
|
+
brand: t.string,
|
|
31
|
+
horsepower: t.number,
|
|
32
|
+
}),
|
|
33
|
+
t.type({
|
|
34
|
+
type: t.literal('bike'),
|
|
35
|
+
speed: t.number,
|
|
36
|
+
}),
|
|
37
|
+
]),
|
|
38
|
+
),
|
|
39
|
+
}),
|
|
40
|
+
t.partial({
|
|
41
|
+
like: t.array(
|
|
42
|
+
t.type({
|
|
43
|
+
id: tt.withMessage(
|
|
44
|
+
t.number,
|
|
45
|
+
(i) => `this id is very important but you passed: ${typeof i}(${i})`,
|
|
46
|
+
),
|
|
47
|
+
name: t.string,
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
}),
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
interface Data {
|
|
54
|
+
username: string;
|
|
55
|
+
password: string;
|
|
56
|
+
accessToken: string;
|
|
57
|
+
birthYear?: number;
|
|
58
|
+
luckyNumbers: number[];
|
|
59
|
+
email?: string;
|
|
60
|
+
animal: string | number;
|
|
61
|
+
tags: { name: string }[];
|
|
62
|
+
enabled: boolean;
|
|
63
|
+
like: { id: number; name: string }[];
|
|
64
|
+
vehicles: Array<
|
|
65
|
+
| { type: 'car'; brand: string; horsepower: number }
|
|
66
|
+
| { type: 'bike'; speed: number }
|
|
67
|
+
>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const validData: Data = {
|
|
71
|
+
username: 'Doe',
|
|
72
|
+
password: 'Password123',
|
|
73
|
+
accessToken: 'c2883927-5178-4ad1-bbee-07ba33a5de19',
|
|
74
|
+
birthYear: 2000,
|
|
75
|
+
email: 'john@doe.com',
|
|
76
|
+
tags: [{ name: 'test' }],
|
|
77
|
+
enabled: true,
|
|
78
|
+
luckyNumbers: [17, 5],
|
|
79
|
+
animal: 'cat',
|
|
80
|
+
like: [
|
|
81
|
+
{
|
|
82
|
+
id: 1,
|
|
83
|
+
name: 'name',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
vehicles: [{ type: 'car', brand: 'BMW', horsepower: 150 }],
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const invalidData = {
|
|
90
|
+
username: 'test',
|
|
91
|
+
password: 'Password123',
|
|
92
|
+
repeatPassword: 'Password123',
|
|
93
|
+
birthYear: 2000,
|
|
94
|
+
accessToken: '1015d809-e99d-41ec-b161-981a3c243df8',
|
|
95
|
+
email: 'john@doe.com',
|
|
96
|
+
tags: [{ name: 'test' }],
|
|
97
|
+
enabled: true,
|
|
98
|
+
animal: ['dog'],
|
|
99
|
+
luckyNumbers: [1, 2, '3'],
|
|
100
|
+
like: [
|
|
101
|
+
{
|
|
102
|
+
id: '1',
|
|
103
|
+
name: 'name',
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
vehicles: [
|
|
107
|
+
{ type: 'car', brand: 'BMW', horsepower: 150 },
|
|
108
|
+
{ type: 'car', brand: 'Mercedes' },
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const fields: Record<InternalFieldName, Field['_f']> = {
|
|
113
|
+
username: {
|
|
114
|
+
ref: { name: 'username' },
|
|
115
|
+
name: 'username',
|
|
116
|
+
},
|
|
117
|
+
password: {
|
|
118
|
+
ref: { name: 'password' },
|
|
119
|
+
name: 'password',
|
|
120
|
+
},
|
|
121
|
+
email: {
|
|
122
|
+
ref: { name: 'email' },
|
|
123
|
+
name: 'email',
|
|
124
|
+
},
|
|
125
|
+
birthday: {
|
|
126
|
+
ref: { name: 'birthday' },
|
|
127
|
+
name: 'birthday',
|
|
128
|
+
},
|
|
129
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ioTsResolver should return a single error from ioTsResolver when validation fails 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"errors": Object {
|
|
6
|
+
"animal": Object {
|
|
7
|
+
"message": "expected string but got [\\"dog\\"]",
|
|
8
|
+
"ref": undefined,
|
|
9
|
+
"type": "string",
|
|
10
|
+
},
|
|
11
|
+
"like": Array [
|
|
12
|
+
Object {
|
|
13
|
+
"id": Object {
|
|
14
|
+
"message": "this id is very important but you passed: string(1)",
|
|
15
|
+
"ref": undefined,
|
|
16
|
+
"type": "number",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
"luckyNumbers": Array [
|
|
21
|
+
undefined,
|
|
22
|
+
undefined,
|
|
23
|
+
Object {
|
|
24
|
+
"message": "expected number but got \\"3\\"",
|
|
25
|
+
"ref": undefined,
|
|
26
|
+
"type": "number",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
"vehicles": Array [
|
|
30
|
+
undefined,
|
|
31
|
+
Object {
|
|
32
|
+
"horsepower": Object {
|
|
33
|
+
"message": "expected number but got undefined",
|
|
34
|
+
"ref": undefined,
|
|
35
|
+
"type": "number",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
"values": Object {},
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
exports[`ioTsResolver should return all the errors from ioTsResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
|
|
45
|
+
Object {
|
|
46
|
+
"errors": Object {
|
|
47
|
+
"animal": Object {
|
|
48
|
+
"message": "expected \\"snake\\" but got [\\"dog\\"]",
|
|
49
|
+
"ref": undefined,
|
|
50
|
+
"type": "\\"snake\\"",
|
|
51
|
+
"types": Object {
|
|
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
|
+
},
|
|
57
|
+
},
|
|
58
|
+
"like": Array [
|
|
59
|
+
Object {
|
|
60
|
+
"id": Object {
|
|
61
|
+
"message": "this id is very important but you passed: string(1)",
|
|
62
|
+
"ref": undefined,
|
|
63
|
+
"type": "number",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
"luckyNumbers": Array [
|
|
68
|
+
undefined,
|
|
69
|
+
undefined,
|
|
70
|
+
Object {
|
|
71
|
+
"message": "expected number but got \\"3\\"",
|
|
72
|
+
"ref": undefined,
|
|
73
|
+
"type": "number",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
"vehicles": Array [
|
|
77
|
+
undefined,
|
|
78
|
+
Object {
|
|
79
|
+
"horsepower": Object {
|
|
80
|
+
"message": "expected number but got undefined",
|
|
81
|
+
"ref": undefined,
|
|
82
|
+
"type": "number",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
"values": Object {},
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ioTsResolver } from '..';
|
|
2
|
+
import { schema, validData, fields, invalidData } from './__fixtures__/data';
|
|
3
|
+
|
|
4
|
+
describe('ioTsResolver', () => {
|
|
5
|
+
it('should return values from ioTsResolver when validation pass', async () => {
|
|
6
|
+
const validateSpy = jest.spyOn(schema, 'decode');
|
|
7
|
+
|
|
8
|
+
const result = ioTsResolver(schema)(validData, undefined, {
|
|
9
|
+
fields,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
expect(validateSpy).toHaveBeenCalled();
|
|
13
|
+
expect(result).toEqual({ errors: {}, values: validData });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return a single error from ioTsResolver when validation fails', () => {
|
|
17
|
+
const result = ioTsResolver(schema)(invalidData, undefined, {
|
|
18
|
+
fields,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should return all the errors from ioTsResolver when validation fails with `validateAllFieldCriteria` set to true', () => {
|
|
25
|
+
const result = ioTsResolver(schema)(invalidData, undefined, {
|
|
26
|
+
fields,
|
|
27
|
+
criteriaMode: 'all',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
expect(result).toMatchSnapshot();
|
|
31
|
+
});
|
|
32
|
+
});
|
package/joi/dist/joi.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("react-hook-form"),r=require("@hookform/resolvers");exports.joiResolver=function(t,n,o){return void 0===n&&(n={abortEarly:!1}),void 0===o&&(o={}),function(i,
|
|
1
|
+
var e=require("react-hook-form"),r=require("@hookform/resolvers");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{values:v.error?{}:v.value,errors:v.error?r.toNestError((t=v.error,n="all"===s.criteriaMode,t.details.length?t.details.reduce(function(r,t){var o=t.path.join(".");if(r[o]||(r[o]={message:t.message,type:t.type}),n){var a=r[o].types,i=a&&a[t.type];r[o]=e.appendErrors(o,n,r,t.type,i?[].concat(i,t.message):t.message)}return r},{}):{}),s.fields):{}};var t,n},c=Object.assign({},n,{context:i}),v={},l=function(){if("sync"===o.mode)v=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){v.value=e})},function(e){v.error=e});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(l&&l.then?l.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 { appendErrors, FieldError } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\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 previous[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n previous,\n error.type,\n error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {})\n : {};\n\nexport const joiResolver: Resolver = (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\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 return {\n values: result.error ? {} : result.value,\n errors: result.error\n ? toNestError(\n parseErrorSchema(result.error, options.criteriaMode === 'all'),\n options.fields,\n )\n : {},\n };\n};\n"],"names":["schema","schemaOptions","resolverOptions","abortEarly","values","context","options","result","error","value","errors","toNestError","validateAllFieldCriteria","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","appendErrors","fields","_schemaOptions","Object","assign","mode","validate","validateAsync","e"],"mappings":"
|
|
1
|
+
{"version":3,"file":"joi.js","sources":["../src/joi.ts"],"sourcesContent":["import { appendErrors, FieldError } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\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 schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\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 return {\n values: result.error ? {} : result.value,\n errors: result.error\n ? toNestError(\n parseErrorSchema(result.error, options.criteriaMode === 'all'),\n options.fields,\n )\n : {},\n };\n};\n"],"names":["schema","schemaOptions","resolverOptions","abortEarly","values","context","options","result","error","value","errors","toNestError","validateAllFieldCriteria","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","types","messages","appendErrors","concat","fields","_schemaOptions","Object","assign","mode","validate","validateAsync","e"],"mappings":"sFAoCqC,SACnCA,EACAC,EAGAC,mBAHAD,IAAAA,EAAgB,CACdE,YAAY,aAEdD,IAAAA,EAAkB,aACRE,EAAQC,EAASC,wBAgB3B,MAAO,CACLF,OAAQG,EAAOC,MAAQ,GAAKD,EAAOE,MACnCC,OAAQH,EAAOC,MACXG,eAvDNH,EAwDyBD,EAAOC,MAvDhCI,EAuDgE,QAAzBN,EAAQO,aArD/CL,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,OAGtDV,EAA0B,CAC5B,IAAMW,EAAQN,EAASC,GAAOK,MACxBC,EAAWD,GAASA,EAAMf,EAAMc,MAEtCL,EAASC,GAASO,eAChBP,EACAN,EACAK,EACAT,EAAMc,KACNE,EACK,GAAgBE,OAAOF,EAAsBhB,EAAMa,SACpDb,EAAMa,SAId,OAAOJ,GACN,IACH,IA6BIX,EAAQqB,QAEV,IA5DiB,IACvBnB,EACAI,GAoCMgB,EAAiBC,OAAOC,OAAO,GAAI7B,EAAe,CACtDI,QAAAA,IAGEE,EAA8B,mBACL,SAAzBL,EAAgB6B,KAClBxB,EAASP,EAAOgC,SAAS5B,EAAQwB,sIAGV5B,EAAOiC,cAAc7B,EAAQwB,qBAAlDrB,EAAOE,oBACAyB,GACP3B,EAAOC,MAAQ0B,iGAlBgB"}
|
package/joi/dist/joi.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as
|
|
1
|
+
import{appendErrors as e}from"react-hook-form";import{toNestError as r}from"@hookform/resolvers";var t=function(t,n,o){return void 0===n&&(n={abortEarly:!1}),void 0===o&&(o={}),function(a,i,s){try{var c=function(){return{values:f.error?{}:f.value,errors:f.error?r((t=f.error,n="all"===s.criteriaMode,t.details.length?t.details.reduce(function(r,t){var o=t.path.join(".");if(r[o]||(r[o]={message:t.message,type:t.type}),n){var a=r[o].types,i=a&&a[t.type];r[o]=e(o,n,r,t.type,i?[].concat(i,t.message):t.message)}return r},{}):{}),s.fields):{}};var t,n},u=Object.assign({},n,{context:i}),f={},v=function(){if("sync"===o.mode)f=t.validate(a,u);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,u)).then(function(e){f.value=e})},function(e){f.error=e});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(v&&v.then?v.then(c):c())}catch(e){return Promise.reject(e)}}};export{t as joiResolver};
|
|
2
2
|
//# sourceMappingURL=joi.module.js.map
|
package/joi/dist/joi.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as e}from"react-hook-form";import{toNestError as r}from"@hookform/resolvers";const t=(t,o={abortEarly:!1},a={})=>async(s,l
|
|
1
|
+
import{appendErrors as e}from"react-hook-form";import{toNestError as r}from"@hookform/resolvers";const t=(t,o={abortEarly:!1},a={})=>async(s,c,l)=>{const i=Object.assign({},o,{context:c});let n={};if("sync"===a.mode)n=t.validate(s,i);else try{n.value=await t.validateAsync(s,i)}catch(e){n.error=e}return{values:n.error?{}:n.value,errors:n.error?r((m=n.error,y="all"===l.criteriaMode,m.details.length?m.details.reduce((r,t)=>{const o=t.path.join(".");if(r[o]||(r[o]={message:t.message,type:t.type}),y){const a=r[o].types,s=a&&a[t.type];r[o]=e(o,y,r,t.type,s?[].concat(s,t.message):t.message)}return r},{}):{}),l.fields):{}};var m,y};export{t as joiResolver};
|
|
2
2
|
//# sourceMappingURL=joi.modern.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joi.modern.js","sources":["../src/joi.ts"],"sourcesContent":["import { appendErrors, FieldError } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\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 previous[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n previous,\n error.type,\n error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {})\n : {};\n\nexport const joiResolver: Resolver = (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\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 return {\n values: result.error ? {} : result.value,\n errors: result.error\n ? toNestError(\n parseErrorSchema(result.error, options.criteriaMode === 'all'),\n options.fields,\n )\n : {},\n };\n};\n"],"names":["joiResolver","schema","schemaOptions","abortEarly","resolverOptions","async","values","context","options","_schemaOptions","Object","assign","result","mode","validate","value","validateAsync","e","error","errors","toNestError","validateAllFieldCriteria","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","appendErrors","fields"],"mappings":"iGAKA,
|
|
1
|
+
{"version":3,"file":"joi.modern.js","sources":["../src/joi.ts"],"sourcesContent":["import { appendErrors, FieldError } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\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 schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\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 return {\n values: result.error ? {} : result.value,\n errors: result.error\n ? toNestError(\n parseErrorSchema(result.error, options.criteriaMode === 'all'),\n options.fields,\n )\n : {},\n };\n};\n"],"names":["joiResolver","schema","schemaOptions","abortEarly","resolverOptions","async","values","context","options","_schemaOptions","Object","assign","result","mode","validate","value","validateAsync","e","error","errors","toNestError","validateAllFieldCriteria","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","types","messages","appendErrors","concat","fields"],"mappings":"iGAKA,MA+BaA,EAAwB,CACnCC,EACAC,EAAgB,CACdC,YAAY,GAEdC,EAAkB,KACfC,MAAOC,EAAQC,EAASC,KAC3B,MAAMC,EAAiBC,OAAOC,OAAO,GAAIT,EAAe,CACtDK,QAAAA,IAGF,IAAIK,EAA8B,GAClC,GAA6B,SAAzBR,EAAgBS,KAClBD,EAASX,EAAOa,SAASR,EAAQG,QAEjC,IACEG,EAAOG,YAAcd,EAAOe,cAAcV,EAAQG,GAClD,MAAOQ,GACPL,EAAOM,MAAQD,EAInB,MAAO,CACLX,OAAQM,EAAOM,MAAQ,GAAKN,EAAOG,MACnCI,OAAQP,EAAOM,MACXE,GAvDNF,EAwDyBN,EAAOM,MAvDhCG,EAuDgE,QAAzBb,EAAQc,aArD/CJ,EAAMK,QAAQC,OACVN,EAAMK,QAAQE,OAAmC,CAACC,EAAUR,KAC1D,MAAMS,EAAQT,EAAMU,KAAKC,KAAK,KAM9B,GAJKH,EAASC,KACZD,EAASC,GAAS,CAAEG,QAASZ,EAAMY,QAASC,KAAMb,EAAMa,OAGtDV,EAA0B,CAC5B,MAAMW,EAAQN,EAASC,GAAOK,MACxBC,EAAWD,GAASA,EAAMd,EAAMa,MAEtCL,EAASC,GAASO,EAChBP,EACAN,EACAK,EACAR,EAAMa,KACNE,EACK,GAAgBE,OAAOF,EAAsBf,EAAMY,SACpDZ,EAAMY,SAId,OAAOJ,GACN,IACH,IA6BIlB,EAAQ4B,QAEV,IA5DiB,IACvBlB,EACAG"}
|
package/joi/dist/joi.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as
|
|
1
|
+
import{appendErrors as e}from"react-hook-form";import{toNestError as r}from"@hookform/resolvers";var t=function(t,n,o){return void 0===n&&(n={abortEarly:!1}),void 0===o&&(o={}),function(a,i,s){try{var c=function(){return{values:f.error?{}:f.value,errors:f.error?r((t=f.error,n="all"===s.criteriaMode,t.details.length?t.details.reduce(function(r,t){var o=t.path.join(".");if(r[o]||(r[o]={message:t.message,type:t.type}),n){var a=r[o].types,i=a&&a[t.type];r[o]=e(o,n,r,t.type,i?[].concat(i,t.message):t.message)}return r},{}):{}),s.fields):{}};var t,n},u=Object.assign({},n,{context:i}),f={},v=function(){if("sync"===o.mode)f=t.validate(a,u);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,u)).then(function(e){f.value=e})},function(e){f.error=e});if(e&&e.then)return e.then(function(){})}}();return Promise.resolve(v&&v.then?v.then(c):c())}catch(e){return Promise.reject(e)}}};export{t as joiResolver};
|
|
2
2
|
//# sourceMappingURL=joi.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joi.module.js","sources":["../src/joi.ts"],"sourcesContent":["import { appendErrors, FieldError } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\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 previous[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n previous,\n error.type,\n error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {})\n : {};\n\nexport const joiResolver: Resolver = (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\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 return {\n values: result.error ? {} : result.value,\n errors: result.error\n ? toNestError(\n parseErrorSchema(result.error, options.criteriaMode === 'all'),\n options.fields,\n )\n : {},\n };\n};\n"],"names":["joiResolver","schema","schemaOptions","resolverOptions","abortEarly","values","context","options","result","error","value","errors","toNestError","validateAllFieldCriteria","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","appendErrors","fields","_schemaOptions","Object","assign","mode","validate","validateAsync","e"],"mappings":"iGAKA,
|
|
1
|
+
{"version":3,"file":"joi.module.js","sources":["../src/joi.ts"],"sourcesContent":["import { appendErrors, FieldError } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\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 schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\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 return {\n values: result.error ? {} : result.value,\n errors: result.error\n ? toNestError(\n parseErrorSchema(result.error, options.criteriaMode === 'all'),\n options.fields,\n )\n : {},\n };\n};\n"],"names":["joiResolver","schema","schemaOptions","resolverOptions","abortEarly","values","context","options","result","error","value","errors","toNestError","validateAllFieldCriteria","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","types","messages","appendErrors","concat","fields","_schemaOptions","Object","assign","mode","validate","validateAsync","e"],"mappings":"iGAKA,IA+BaA,EAAwB,SACnCC,EACAC,EAGAC,mBAHAD,IAAAA,EAAgB,CACdE,YAAY,aAEdD,IAAAA,EAAkB,aACRE,EAAQC,EAASC,wBAgB3B,MAAO,CACLF,OAAQG,EAAOC,MAAQ,GAAKD,EAAOE,MACnCC,OAAQH,EAAOC,MACXG,GAvDNH,EAwDyBD,EAAOC,MAvDhCI,EAuDgE,QAAzBN,EAAQO,aArD/CL,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,OAGtDV,EAA0B,CAC5B,IAAMW,EAAQN,EAASC,GAAOK,MACxBC,EAAWD,GAASA,EAAMf,EAAMc,MAEtCL,EAASC,GAASO,EAChBP,EACAN,EACAK,EACAT,EAAMc,KACNE,EACK,GAAgBE,OAAOF,EAAsBhB,EAAMa,SACpDb,EAAMa,SAId,OAAOJ,GACN,IACH,IA6BIX,EAAQqB,QAEV,IA5DiB,IACvBnB,EACAI,GAoCMgB,EAAiBC,OAAOC,OAAO,GAAI7B,EAAe,CACtDI,QAAAA,IAGEE,EAA8B,mBACL,SAAzBL,EAAgB6B,KAClBxB,EAASP,EAAOgC,SAAS5B,EAAQwB,sIAGV5B,EAAOiC,cAAc7B,EAAQwB,qBAAlDrB,EAAOE,oBACAyB,GACP3B,EAAOC,MAAQ0B,iGAlBgB"}
|
package/joi/dist/joi.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react-hook-form"),require("@hookform/resolvers")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers"],r):r((e||self).hookformResolversJoi={},e.reactHookForm,e.hookformResolvers)}(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 f=function(){return{values:c.error?{}:c.value,errors:c.error?o.toNestError((e=c.error,t="all"===a.criteriaMode,e.details.length?e.details.reduce(function(e,o){var n=o.path.join(".");
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react-hook-form"),require("@hookform/resolvers")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers"],r):r((e||self).hookformResolversJoi={},e.reactHookForm,e.hookformResolvers)}(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 f=function(){return{values:c.error?{}:c.value,errors:c.error?o.toNestError((e=c.error,t="all"===a.criteriaMode,e.details.length?e.details.reduce(function(e,o){var n=o.path.join(".");if(e[n]||(e[n]={message:o.message,type:o.type}),t){var i=e[n].types,s=i&&i[o.type];e[n]=r.appendErrors(n,t,e,o.type,s?[].concat(s,o.message):o.message)}return e},{}):{}),a.fields):{}};var e,t},u=Object.assign({},t,{context:s}),c={},l=function(){if("sync"===n.mode)c=e.validate(i,u);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,u)).then(function(e){c.value=e})},function(e){c.error=e});if(r&&r.then)return r.then(function(){})}}();return Promise.resolve(l&&l.then?l.then(f):f())}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 { appendErrors, FieldError } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\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 previous[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n previous,\n error.type,\n error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {})\n : {};\n\nexport const joiResolver: Resolver = (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\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 return {\n values: result.error ? {} : result.value,\n errors: result.error\n ? toNestError(\n parseErrorSchema(result.error, options.criteriaMode === 'all'),\n options.fields,\n )\n : {},\n };\n};\n"],"names":["schema","schemaOptions","resolverOptions","abortEarly","values","context","options","result","error","value","errors","toNestError","validateAllFieldCriteria","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","appendErrors","fields","_schemaOptions","Object","assign","mode","validate","validateAsync","e"],"mappings":"
|
|
1
|
+
{"version":3,"file":"joi.umd.js","sources":["../src/joi.ts"],"sourcesContent":["import { appendErrors, FieldError } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ValidationError } from 'joi';\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 schema,\n schemaOptions = {\n abortEarly: false,\n },\n resolverOptions = {},\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 return {\n values: result.error ? {} : result.value,\n errors: result.error\n ? toNestError(\n parseErrorSchema(result.error, options.criteriaMode === 'all'),\n options.fields,\n )\n : {},\n };\n};\n"],"names":["schema","schemaOptions","resolverOptions","abortEarly","values","context","options","result","error","value","errors","toNestError","validateAllFieldCriteria","criteriaMode","details","length","reduce","previous","_path","path","join","message","type","types","messages","appendErrors","concat","fields","_schemaOptions","Object","assign","mode","validate","validateAsync","e"],"mappings":"sYAoCqC,SACnCA,EACAC,EAGAC,mBAHAD,IAAAA,EAAgB,CACdE,YAAY,aAEdD,IAAAA,EAAkB,aACRE,EAAQC,EAASC,wBAgB3B,MAAO,CACLF,OAAQG,EAAOC,MAAQ,GAAKD,EAAOE,MACnCC,OAAQH,EAAOC,MACXG,eAvDNH,EAwDyBD,EAAOC,MAvDhCI,EAuDgE,QAAzBN,EAAQO,aArD/CL,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,OAGtDV,EAA0B,CAC5B,IAAMW,EAAQN,EAASC,GAAOK,MACxBC,EAAWD,GAASA,EAAMf,EAAMc,MAEtCL,EAASC,GAASO,eAChBP,EACAN,EACAK,EACAT,EAAMc,KACNE,EACK,GAAgBE,OAAOF,EAAsBhB,EAAMa,SACpDb,EAAMa,SAId,OAAOJ,GACN,IACH,IA6BIX,EAAQqB,QAEV,IA5DiB,IACvBnB,EACAI,GAoCMgB,EAAiBC,OAAOC,OAAO,GAAI7B,EAAe,CACtDI,QAAAA,IAGEE,EAA8B,mBACL,SAAzBL,EAAgB6B,KAClBxB,EAASP,EAAOgC,SAAS5B,EAAQwB,sIAGV5B,EAAOiC,cAAc7B,EAAQwB,qBAAlDrB,EAAOE,oBACAyB,GACP3B,EAAOC,MAAQ0B,iGAlBgB"}
|
|
@@ -4,7 +4,16 @@ import { Field, InternalFieldName } from 'react-hook-form';
|
|
|
4
4
|
|
|
5
5
|
export const schema = Joi.object({
|
|
6
6
|
username: Joi.string().alphanum().min(3).max(30).required(),
|
|
7
|
-
password: Joi.string()
|
|
7
|
+
password: Joi.string()
|
|
8
|
+
.pattern(new RegExp('.*[A-Z].*'), 'One uppercase character')
|
|
9
|
+
.pattern(new RegExp('.*[a-z].*'), 'One lowercase character')
|
|
10
|
+
.pattern(new RegExp('.*\\d.*'), 'One number')
|
|
11
|
+
.pattern(
|
|
12
|
+
new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
|
|
13
|
+
'One special character',
|
|
14
|
+
)
|
|
15
|
+
.min(8)
|
|
16
|
+
.required(),
|
|
8
17
|
repeatPassword: Joi.ref('password'),
|
|
9
18
|
accessToken: [Joi.string(), Joi.number()],
|
|
10
19
|
birthYear: Joi.number().integer().min(1900).max(2013),
|
|
@@ -35,8 +44,8 @@ interface Data {
|
|
|
35
44
|
|
|
36
45
|
export const validData: Data = {
|
|
37
46
|
username: 'Doe',
|
|
38
|
-
password: '
|
|
39
|
-
repeatPassword: '
|
|
47
|
+
password: 'Password123_',
|
|
48
|
+
repeatPassword: 'Password123_',
|
|
40
49
|
birthYear: 2000,
|
|
41
50
|
email: 'john@doe.com',
|
|
42
51
|
tags: ['tag1', 'tag2'],
|
|
@@ -35,11 +35,11 @@ Object {
|
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
37
|
"password": Object {
|
|
38
|
-
"message": "\\"password\\" with value \\"___\\" fails to match the
|
|
38
|
+
"message": "\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
39
39
|
"ref": Object {
|
|
40
40
|
"name": "password",
|
|
41
41
|
},
|
|
42
|
-
"type": "string.pattern.
|
|
42
|
+
"type": "string.pattern.name",
|
|
43
43
|
},
|
|
44
44
|
"tags": Object {
|
|
45
45
|
"message": "\\"tags\\" is required",
|
|
@@ -93,11 +93,11 @@ Object {
|
|
|
93
93
|
},
|
|
94
94
|
],
|
|
95
95
|
"password": Object {
|
|
96
|
-
"message": "\\"password\\" with value \\"___\\" fails to match the
|
|
96
|
+
"message": "\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
97
97
|
"ref": Object {
|
|
98
98
|
"name": "password",
|
|
99
99
|
},
|
|
100
|
-
"type": "string.pattern.
|
|
100
|
+
"type": "string.pattern.name",
|
|
101
101
|
},
|
|
102
102
|
"tags": Object {
|
|
103
103
|
"message": "\\"tags\\" is required",
|
|
@@ -167,13 +167,18 @@ Object {
|
|
|
167
167
|
},
|
|
168
168
|
],
|
|
169
169
|
"password": Object {
|
|
170
|
-
"message": "\\"password\\" with value \\"___\\" fails to match the
|
|
170
|
+
"message": "\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
171
171
|
"ref": Object {
|
|
172
172
|
"name": "password",
|
|
173
173
|
},
|
|
174
|
-
"type": "string.pattern.
|
|
174
|
+
"type": "string.pattern.name",
|
|
175
175
|
"types": Object {
|
|
176
|
-
"string.
|
|
176
|
+
"string.min": "\\"password\\" length must be at least 8 characters long",
|
|
177
|
+
"string.pattern.name": Array [
|
|
178
|
+
"\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
179
|
+
"\\"password\\" with value \\"___\\" fails to match the One lowercase character pattern",
|
|
180
|
+
"\\"password\\" with value \\"___\\" fails to match the One number pattern",
|
|
181
|
+
],
|
|
177
182
|
},
|
|
178
183
|
},
|
|
179
184
|
"tags": Object {
|
|
@@ -250,13 +255,18 @@ Object {
|
|
|
250
255
|
},
|
|
251
256
|
],
|
|
252
257
|
"password": Object {
|
|
253
|
-
"message": "\\"password\\" with value \\"___\\" fails to match the
|
|
258
|
+
"message": "\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
254
259
|
"ref": Object {
|
|
255
260
|
"name": "password",
|
|
256
261
|
},
|
|
257
|
-
"type": "string.pattern.
|
|
262
|
+
"type": "string.pattern.name",
|
|
258
263
|
"types": Object {
|
|
259
|
-
"string.
|
|
264
|
+
"string.min": "\\"password\\" length must be at least 8 characters long",
|
|
265
|
+
"string.pattern.name": Array [
|
|
266
|
+
"\\"password\\" with value \\"___\\" fails to match the One uppercase character pattern",
|
|
267
|
+
"\\"password\\" with value \\"___\\" fails to match the One lowercase character pattern",
|
|
268
|
+
"\\"password\\" with value \\"___\\" fails to match the One number pattern",
|
|
269
|
+
],
|
|
260
270
|
},
|
|
261
271
|
},
|
|
262
272
|
"tags": Object {
|
package/joi/src/joi.ts
CHANGED
|
@@ -16,12 +16,17 @@ const parseErrorSchema = (
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
if (validateAllFieldCriteria) {
|
|
19
|
+
const types = previous[_path].types;
|
|
20
|
+
const messages = types && types[error.type!];
|
|
21
|
+
|
|
19
22
|
previous[_path] = appendErrors(
|
|
20
23
|
_path,
|
|
21
24
|
validateAllFieldCriteria,
|
|
22
25
|
previous,
|
|
23
26
|
error.type,
|
|
24
|
-
|
|
27
|
+
messages
|
|
28
|
+
? ([] as string[]).concat(messages as string[], error.message)
|
|
29
|
+
: error.message,
|
|
25
30
|
) as FieldError;
|
|
26
31
|
}
|
|
27
32
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=require("@hookform/resolvers"),e=function r(e,o,t){return void 0===o&&(o={}),void 0===t&&(t=""),Object.keys(e).reduce(function(o,n){var s=t?t+"."+n:n,u=e[n];return"string"==typeof u?o[s]={message:u}:r(u,o,s),o},o)};exports.nopeResolver=function(o,t){return void 0===t&&(t={abortEarly:!1}),function(n,s,u){var i=o.validate(n,s,t);return i?{values:{},errors:r.toNestError(e(i),u.fields)}:{values:n,errors:{}}}};
|
|
2
|
+
//# sourceMappingURL=nope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nope.js","sources":["../src/nope.ts"],"sourcesContent":["import type { FieldErrors } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n };\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver = (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n) => (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n return result\n ? { values: {}, errors: toNestError(parseErrors(result), options.fields) }\n : { values, errors: {} };\n};\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","fields"],"mappings":"qCAKMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,gBAHAD,IAAAA,EAA4B,aAC5BC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,MAAQK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,GACNL,yBAGiC,SACpCU,EACAC,mBAAAA,IAAAA,EAAgB,CACdC,YAAY,aAEVC,EAAQC,EAASC,GACrB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAOK,EACH,CAAEH,OAAQ,GAAId,OAAQmB,cAAYpB,EAAYkB,GAASD,EAAQI,SAC/D,CAAEN,OAAAA,EAAQd,OAAQ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{toNestError as r}from"@hookform/resolvers";var e=function r(e,o,t){return void 0===o&&(o={}),void 0===t&&(t=""),Object.keys(e).reduce(function(o,n){var i=t?t+"."+n:n,s=e[n];return"string"==typeof s?o[i]={message:s}:r(s,o,i),o},o)},o=function(o,t){return void 0===t&&(t={abortEarly:!1}),function(n,i,s){var u=o.validate(n,i,t);return u?{values:{},errors:r(e(u),s.fields)}:{values:n,errors:{}}}};export{o as nopeResolver};
|
|
2
|
+
//# sourceMappingURL=nope.module.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{toNestError as r}from"@hookform/resolvers";const e=(r,o={},s="")=>Object.keys(r).reduce((o,t)=>{const a=s?`${s}.${t}`:t,l=r[t];return"string"==typeof l?o[a]={message:l}:e(l,o,a),o},o),o=(o,s={abortEarly:!1})=>(t,a,l)=>{const n=o.validate(t,a,s);return n?{values:{},errors:r(e(n),l.fields)}:{values:t,errors:{}}};export{o as nopeResolver};
|
|
2
|
+
//# sourceMappingURL=nope.modern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nope.modern.js","sources":["../src/nope.ts"],"sourcesContent":["import type { FieldErrors } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n };\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver = (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n) => (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n return result\n ? { values: {}, errors: toNestError(parseErrors(result), options.fields) }\n : { values, errors: {} };\n};\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","nopeResolver","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","fields"],"mappings":"kDAKA,MAAMA,EAAc,CAClBC,EACAC,EAA4B,GAC5BC,EAAO,KAEAC,OAAOC,KAAKJ,GAAQK,OAAO,CAACC,EAAKC,KACtC,MAAMC,EAAQN,KAAUA,KAAQK,IAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,GACNL,GAGQU,EAAyB,CACpCC,EACAC,EAAgB,CACdC,YAAY,KAEX,CAACC,EAAQC,EAASC,KACrB,MAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAOK,EACH,CAAEH,OAAQ,GAAIf,OAAQoB,EAAYrB,EAAYmB,GAASD,EAAQI,SAC/D,CAAEN,OAAAA,EAAQf,OAAQ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{toNestError as r}from"@hookform/resolvers";var e=function r(e,o,t){return void 0===o&&(o={}),void 0===t&&(t=""),Object.keys(e).reduce(function(o,n){var i=t?t+"."+n:n,s=e[n];return"string"==typeof s?o[i]={message:s}:r(s,o,i),o},o)},o=function(o,t){return void 0===t&&(t={abortEarly:!1}),function(n,i,s){var u=o.validate(n,i,t);return u?{values:{},errors:r(e(u),s.fields)}:{values:n,errors:{}}}};export{o as nopeResolver};
|
|
2
|
+
//# sourceMappingURL=nope.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nope.module.js","sources":["../src/nope.ts"],"sourcesContent":["import type { FieldErrors } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n };\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver = (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n) => (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n return result\n ? { values: {}, errors: toNestError(parseErrors(result), options.fields) }\n : { values, errors: {} };\n};\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","nopeResolver","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","fields"],"mappings":"kDAKA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,gBAHAD,IAAAA,EAA4B,aAC5BC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,MAAQK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,GACNL,IAGQU,EAAyB,SACpCC,EACAC,mBAAAA,IAAAA,EAAgB,CACdC,YAAY,aAEVC,EAAQC,EAASC,GACrB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAOK,EACH,CAAEH,OAAQ,GAAIf,OAAQoB,EAAYrB,EAAYmB,GAASD,EAAQI,SAC/D,CAAEN,OAAAA,EAAQf,OAAQ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@hookform/resolvers")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers"],o):o((e||self).hookformResolversNope={},e.hookformResolvers)}(this,function(e,o){var r=function e(o,r,n){return void 0===r&&(r={}),void 0===n&&(n=""),Object.keys(o).reduce(function(r,t){var s=n?n+"."+t:t,f=o[t];return"string"==typeof f?r[s]={message:f}:e(f,r,s),r},r)};e.nopeResolver=function(e,n){return void 0===n&&(n={abortEarly:!1}),function(t,s,f){var i=e.validate(t,s,n);return i?{values:{},errors:o.toNestError(r(i),f.fields)}:{values:t,errors:{}}}}});
|
|
2
|
+
//# sourceMappingURL=nope.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nope.umd.js","sources":["../src/nope.ts"],"sourcesContent":["import type { FieldErrors } from 'react-hook-form';\nimport { toNestError } from '@hookform/resolvers';\nimport type { ShapeErrors } from 'nope-validator/lib/cjs/types';\nimport type { Resolver } from './types';\n\nconst parseErrors = (\n errors: ShapeErrors,\n parsedErrors: FieldErrors = {},\n path = '',\n) => {\n return Object.keys(errors).reduce((acc, key) => {\n const _path = path ? `${path}.${key}` : key;\n const error = errors[key];\n\n if (typeof error === 'string') {\n acc[_path] = {\n message: error,\n };\n } else {\n parseErrors(error, acc, _path);\n }\n\n return acc;\n }, parsedErrors);\n};\n\nexport const nopeResolver: Resolver = (\n schema,\n schemaOptions = {\n abortEarly: false,\n },\n) => (values, context, options) => {\n const result = schema.validate(values, context, schemaOptions) as\n | ShapeErrors\n | undefined;\n\n return result\n ? { values: {}, errors: toNestError(parseErrors(result), options.fields) }\n : { values, errors: {} };\n};\n"],"names":["parseErrors","errors","parsedErrors","path","Object","keys","reduce","acc","key","_path","error","message","schema","schemaOptions","abortEarly","values","context","options","result","validate","toNestError","fields"],"mappings":"0TAKA,IAAMA,EAAc,SAAdA,EACJC,EACAC,EACAC,GAEA,gBAHAD,IAAAA,EAA4B,aAC5BC,IAAAA,EAAO,IAEAC,OAAOC,KAAKJ,GAAQK,OAAO,SAACC,EAAKC,GACtC,IAAMC,EAAQN,EAAUA,MAAQK,EAAQA,EAClCE,EAAQT,EAAOO,GAUrB,MARqB,iBAAVE,EACTH,EAAIE,GAAS,CACXE,QAASD,GAGXV,EAAYU,EAAOH,EAAKE,GAGnBF,GACNL,mBAGiC,SACpCU,EACAC,mBAAAA,IAAAA,EAAgB,CACdC,YAAY,aAEVC,EAAQC,EAASC,GACrB,IAAMC,EAASN,EAAOO,SAASJ,EAAQC,EAASH,GAIhD,OAAOK,EACH,CAAEH,OAAQ,GAAId,OAAQmB,cAAYpB,EAAYkB,GAASD,EAAQI,SAC/D,CAAEN,OAAAA,EAAQd,OAAQ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FieldValues, ResolverOptions, ResolverResult, UnpackNestedValue } from 'react-hook-form';
|
|
2
|
+
import type { NopeObject } from 'nope-validator/lib/cjs/NopeObject';
|
|
3
|
+
declare type ValidateOptions = Parameters<NopeObject['validate']>[2];
|
|
4
|
+
declare type Context = Parameters<NopeObject['validate']>[1];
|
|
5
|
+
export declare type Resolver = <T extends NopeObject>(schema: T, schemaOptions?: ValidateOptions) => <TFieldValues extends FieldValues, TContext extends Context>(values: UnpackNestedValue<TFieldValues>, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nope",
|
|
3
|
+
"amdName": "hookformResolversNope",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"description": "React Hook Form validation resolver: nope",
|
|
7
|
+
"main": "dist/nope.js",
|
|
8
|
+
"module": "dist/nope.module.js",
|
|
9
|
+
"umd:main": "dist/nope.umd.js",
|
|
10
|
+
"source": "src/index.ts",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react-hook-form": "^7.0.0",
|
|
15
|
+
"@hookform/resolvers": "^2.0.0",
|
|
16
|
+
"nope-validator": "^0.12.0"
|
|
17
|
+
}
|
|
18
|
+
}
|