@conform-to/yup 0.4.0-pre.3 → 0.4.1
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/index.js +0 -26
- package/module/index.js +0 -26
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -29,10 +29,8 @@ function getFieldsetConstraint(source) {
|
|
|
29
29
|
var description = source.describe();
|
|
30
30
|
return Object.fromEntries(Object.entries(description.fields).map(_ref => {
|
|
31
31
|
var _test$params, _test$params3, _test$params5, _test$params6, _test$params8;
|
|
32
|
-
|
|
33
32
|
var [key, def] = _ref;
|
|
34
33
|
var constraint = {};
|
|
35
|
-
|
|
36
34
|
switch (def.type) {
|
|
37
35
|
case 'string':
|
|
38
36
|
{
|
|
@@ -41,92 +39,69 @@ function getFieldsetConstraint(source) {
|
|
|
41
39
|
case 'required':
|
|
42
40
|
constraint.required = true;
|
|
43
41
|
break;
|
|
44
|
-
|
|
45
42
|
case 'min':
|
|
46
43
|
if (!constraint.minLength || constraint.minLength < Number((_test$params = test.params) === null || _test$params === void 0 ? void 0 : _test$params.min)) {
|
|
47
44
|
var _test$params2;
|
|
48
|
-
|
|
49
45
|
constraint.minLength = Number((_test$params2 = test.params) === null || _test$params2 === void 0 ? void 0 : _test$params2.min);
|
|
50
46
|
}
|
|
51
|
-
|
|
52
47
|
break;
|
|
53
|
-
|
|
54
48
|
case 'max':
|
|
55
49
|
if (!constraint.maxLength || constraint.maxLength > Number((_test$params3 = test.params) === null || _test$params3 === void 0 ? void 0 : _test$params3.max)) {
|
|
56
50
|
var _test$params4;
|
|
57
|
-
|
|
58
51
|
constraint.maxLength = Number((_test$params4 = test.params) === null || _test$params4 === void 0 ? void 0 : _test$params4.max);
|
|
59
52
|
}
|
|
60
|
-
|
|
61
53
|
break;
|
|
62
|
-
|
|
63
54
|
case 'matches':
|
|
64
55
|
if (!constraint.pattern && ((_test$params5 = test.params) === null || _test$params5 === void 0 ? void 0 : _test$params5.regex) instanceof RegExp) {
|
|
65
56
|
constraint.pattern = test.params.regex.source;
|
|
66
57
|
}
|
|
67
|
-
|
|
68
58
|
break;
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
|
-
|
|
72
61
|
if (!constraint.pattern && def.oneOf.length > 0) {
|
|
73
62
|
constraint.pattern = def.oneOf.join('|');
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
break;
|
|
77
65
|
}
|
|
78
|
-
|
|
79
66
|
case 'number':
|
|
80
67
|
for (var _test of def.tests) {
|
|
81
68
|
switch (_test.name) {
|
|
82
69
|
case 'required':
|
|
83
70
|
constraint.required = true;
|
|
84
71
|
break;
|
|
85
|
-
|
|
86
72
|
case 'min':
|
|
87
73
|
if (!constraint.min || constraint.min < Number((_test$params6 = _test.params) === null || _test$params6 === void 0 ? void 0 : _test$params6.min)) {
|
|
88
74
|
var _test$params7;
|
|
89
|
-
|
|
90
75
|
constraint.min = Number((_test$params7 = _test.params) === null || _test$params7 === void 0 ? void 0 : _test$params7.min);
|
|
91
76
|
}
|
|
92
|
-
|
|
93
77
|
break;
|
|
94
|
-
|
|
95
78
|
case 'max':
|
|
96
79
|
if (!constraint.max || constraint.max > Number((_test$params8 = _test.params) === null || _test$params8 === void 0 ? void 0 : _test$params8.max)) {
|
|
97
80
|
var _test$params9;
|
|
98
|
-
|
|
99
81
|
constraint.max = Number((_test$params9 = _test.params) === null || _test$params9 === void 0 ? void 0 : _test$params9.max);
|
|
100
82
|
}
|
|
101
|
-
|
|
102
83
|
break;
|
|
103
84
|
}
|
|
104
85
|
}
|
|
105
|
-
|
|
106
86
|
break;
|
|
107
87
|
}
|
|
108
|
-
|
|
109
88
|
return [key, constraint];
|
|
110
89
|
}));
|
|
111
90
|
}
|
|
112
91
|
function formatError(error) {
|
|
113
92
|
var fallbackMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Oops! Something went wrong.';
|
|
114
|
-
|
|
115
93
|
if (error instanceof yup__namespace.ValidationError) {
|
|
116
94
|
return error.inner.reduce((result, e) => {
|
|
117
95
|
var _e$path;
|
|
118
|
-
|
|
119
96
|
result.push([(_e$path = e.path) !== null && _e$path !== void 0 ? _e$path : '', e.message]);
|
|
120
97
|
return result;
|
|
121
98
|
}, []);
|
|
122
99
|
}
|
|
123
|
-
|
|
124
100
|
return [['', error instanceof Error ? error.message : fallbackMessage]];
|
|
125
101
|
}
|
|
126
102
|
function validate(formData, schema) {
|
|
127
103
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
128
104
|
var submission = dom.parse(formData);
|
|
129
|
-
|
|
130
105
|
try {
|
|
131
106
|
schema.validateSync(submission.value, {
|
|
132
107
|
abortEarly: false
|
|
@@ -134,7 +109,6 @@ function validate(formData, schema) {
|
|
|
134
109
|
} catch (error) {
|
|
135
110
|
submission.error.push(...formatError(error, options.fallbackMessage));
|
|
136
111
|
}
|
|
137
|
-
|
|
138
112
|
return submission;
|
|
139
113
|
}
|
|
140
114
|
|
package/module/index.js
CHANGED
|
@@ -5,10 +5,8 @@ function getFieldsetConstraint(source) {
|
|
|
5
5
|
var description = source.describe();
|
|
6
6
|
return Object.fromEntries(Object.entries(description.fields).map(_ref => {
|
|
7
7
|
var _test$params, _test$params3, _test$params5, _test$params6, _test$params8;
|
|
8
|
-
|
|
9
8
|
var [key, def] = _ref;
|
|
10
9
|
var constraint = {};
|
|
11
|
-
|
|
12
10
|
switch (def.type) {
|
|
13
11
|
case 'string':
|
|
14
12
|
{
|
|
@@ -17,92 +15,69 @@ function getFieldsetConstraint(source) {
|
|
|
17
15
|
case 'required':
|
|
18
16
|
constraint.required = true;
|
|
19
17
|
break;
|
|
20
|
-
|
|
21
18
|
case 'min':
|
|
22
19
|
if (!constraint.minLength || constraint.minLength < Number((_test$params = test.params) === null || _test$params === void 0 ? void 0 : _test$params.min)) {
|
|
23
20
|
var _test$params2;
|
|
24
|
-
|
|
25
21
|
constraint.minLength = Number((_test$params2 = test.params) === null || _test$params2 === void 0 ? void 0 : _test$params2.min);
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
break;
|
|
29
|
-
|
|
30
24
|
case 'max':
|
|
31
25
|
if (!constraint.maxLength || constraint.maxLength > Number((_test$params3 = test.params) === null || _test$params3 === void 0 ? void 0 : _test$params3.max)) {
|
|
32
26
|
var _test$params4;
|
|
33
|
-
|
|
34
27
|
constraint.maxLength = Number((_test$params4 = test.params) === null || _test$params4 === void 0 ? void 0 : _test$params4.max);
|
|
35
28
|
}
|
|
36
|
-
|
|
37
29
|
break;
|
|
38
|
-
|
|
39
30
|
case 'matches':
|
|
40
31
|
if (!constraint.pattern && ((_test$params5 = test.params) === null || _test$params5 === void 0 ? void 0 : _test$params5.regex) instanceof RegExp) {
|
|
41
32
|
constraint.pattern = test.params.regex.source;
|
|
42
33
|
}
|
|
43
|
-
|
|
44
34
|
break;
|
|
45
35
|
}
|
|
46
36
|
}
|
|
47
|
-
|
|
48
37
|
if (!constraint.pattern && def.oneOf.length > 0) {
|
|
49
38
|
constraint.pattern = def.oneOf.join('|');
|
|
50
39
|
}
|
|
51
|
-
|
|
52
40
|
break;
|
|
53
41
|
}
|
|
54
|
-
|
|
55
42
|
case 'number':
|
|
56
43
|
for (var _test of def.tests) {
|
|
57
44
|
switch (_test.name) {
|
|
58
45
|
case 'required':
|
|
59
46
|
constraint.required = true;
|
|
60
47
|
break;
|
|
61
|
-
|
|
62
48
|
case 'min':
|
|
63
49
|
if (!constraint.min || constraint.min < Number((_test$params6 = _test.params) === null || _test$params6 === void 0 ? void 0 : _test$params6.min)) {
|
|
64
50
|
var _test$params7;
|
|
65
|
-
|
|
66
51
|
constraint.min = Number((_test$params7 = _test.params) === null || _test$params7 === void 0 ? void 0 : _test$params7.min);
|
|
67
52
|
}
|
|
68
|
-
|
|
69
53
|
break;
|
|
70
|
-
|
|
71
54
|
case 'max':
|
|
72
55
|
if (!constraint.max || constraint.max > Number((_test$params8 = _test.params) === null || _test$params8 === void 0 ? void 0 : _test$params8.max)) {
|
|
73
56
|
var _test$params9;
|
|
74
|
-
|
|
75
57
|
constraint.max = Number((_test$params9 = _test.params) === null || _test$params9 === void 0 ? void 0 : _test$params9.max);
|
|
76
58
|
}
|
|
77
|
-
|
|
78
59
|
break;
|
|
79
60
|
}
|
|
80
61
|
}
|
|
81
|
-
|
|
82
62
|
break;
|
|
83
63
|
}
|
|
84
|
-
|
|
85
64
|
return [key, constraint];
|
|
86
65
|
}));
|
|
87
66
|
}
|
|
88
67
|
function formatError(error) {
|
|
89
68
|
var fallbackMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Oops! Something went wrong.';
|
|
90
|
-
|
|
91
69
|
if (error instanceof yup.ValidationError) {
|
|
92
70
|
return error.inner.reduce((result, e) => {
|
|
93
71
|
var _e$path;
|
|
94
|
-
|
|
95
72
|
result.push([(_e$path = e.path) !== null && _e$path !== void 0 ? _e$path : '', e.message]);
|
|
96
73
|
return result;
|
|
97
74
|
}, []);
|
|
98
75
|
}
|
|
99
|
-
|
|
100
76
|
return [['', error instanceof Error ? error.message : fallbackMessage]];
|
|
101
77
|
}
|
|
102
78
|
function validate(formData, schema) {
|
|
103
79
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
104
80
|
var submission = parse(formData);
|
|
105
|
-
|
|
106
81
|
try {
|
|
107
82
|
schema.validateSync(submission.value, {
|
|
108
83
|
abortEarly: false
|
|
@@ -110,7 +85,6 @@ function validate(formData, schema) {
|
|
|
110
85
|
} catch (error) {
|
|
111
86
|
submission.error.push(...formatError(error, options.fallbackMessage));
|
|
112
87
|
}
|
|
113
|
-
|
|
114
88
|
return submission;
|
|
115
89
|
}
|
|
116
90
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@conform-to/yup",
|
|
3
3
|
"description": "Conform schema resolver for yup",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.1",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "module/index.js",
|
|
8
8
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "https://github.com/edmundhung/conform/issues"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@conform-to/dom": "0.4.
|
|
17
|
+
"@conform-to/dom": "0.4.1",
|
|
18
18
|
"yup": ">=0.32.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|