vest 4.4.2 → 4.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/dist/cjs/classnames.development.js +16 -90
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +5 -58
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +8 -51
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +5 -57
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +15 -89
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +2 -26
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +197 -452
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +14 -88
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -54
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +2 -45
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +1 -53
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +14 -88
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +1 -25
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +131 -387
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +27 -56
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +111 -94
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +185 -168
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +134 -117
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +27 -56
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/vest.development.js +398 -386
- package/dist/umd/vest.production.js +1 -1
- package/package.json +4 -3
- package/testUtils/__tests__/partition.test.ts +21 -0
- package/testUtils/mockThrowError.ts +2 -1
- package/testUtils/partition.ts +13 -0
- package/testUtils/suiteDummy.ts +1 -1
- package/types/enforce/compose.d.ts +17 -32
- package/types/enforce/compounds.d.ts +17 -32
- package/types/enforce/schema.d.ts +17 -32
- package/types/parser.d.ts +8 -7
- package/types/promisify.d.ts +20 -35
- package/types/vest.d.ts +45 -60
|
@@ -1,109 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function optionalFunctionValue(value) {
|
|
8
|
-
var args = [];
|
|
9
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
10
|
-
args[_i - 1] = arguments[_i];
|
|
11
|
-
}
|
|
12
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function defaultTo(value, defaultValue) {
|
|
16
|
-
var _a;
|
|
17
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A safe hasOwnProperty access
|
|
22
|
-
*/
|
|
23
|
-
function hasOwnProperty(obj, key) {
|
|
24
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function invariant(condition,
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
29
|
-
message) {
|
|
30
|
-
if (condition) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
// If message is a string object (rather than string literal)
|
|
34
|
-
// Throw the value directly as a string
|
|
35
|
-
// Alternatively, throw an error with the message
|
|
36
|
-
throw message instanceof String
|
|
37
|
-
? message.valueOf()
|
|
38
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function isNumeric(value) {
|
|
42
|
-
var str = String(value);
|
|
43
|
-
var num = Number(value);
|
|
44
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
45
|
-
return Boolean(result);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function greaterThan(value, gt) {
|
|
49
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isPositive(value) {
|
|
53
|
-
return greaterThan(value, 0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
var Severity;
|
|
57
|
-
(function (Severity) {
|
|
58
|
-
Severity["WARNINGS"] = "warnings";
|
|
59
|
-
Severity["ERRORS"] = "errors";
|
|
60
|
-
})(Severity || (Severity = {}));
|
|
61
|
-
var SeverityCount;
|
|
62
|
-
(function (SeverityCount) {
|
|
63
|
-
SeverityCount["ERROR_COUNT"] = "errorCount";
|
|
64
|
-
SeverityCount["WARN_COUNT"] = "warnCount";
|
|
65
|
-
})(SeverityCount || (SeverityCount = {}));
|
|
3
|
+
var vestUtils = require('vest-utils');
|
|
4
|
+
var vest = require('vest');
|
|
66
5
|
|
|
67
|
-
// eslint-disable-next-line max-
|
|
68
|
-
function parse(
|
|
69
|
-
invariant(
|
|
6
|
+
// eslint-disable-next-line max-statements
|
|
7
|
+
function parse(summary) {
|
|
8
|
+
vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
|
|
9
|
+
var sel = vest.suiteSelectors(summary);
|
|
70
10
|
var testedStorage = {};
|
|
71
11
|
var selectors = {
|
|
72
|
-
invalid: hasErrors,
|
|
12
|
+
invalid: sel.hasErrors,
|
|
73
13
|
tested: isTested,
|
|
74
14
|
untested: isUntested,
|
|
75
|
-
valid: isValid,
|
|
76
|
-
warning: hasWarnings
|
|
15
|
+
valid: sel.isValid,
|
|
16
|
+
warning: sel.hasWarnings
|
|
77
17
|
};
|
|
78
18
|
return selectors;
|
|
19
|
+
// Booleans
|
|
79
20
|
function isTested(fieldName) {
|
|
80
21
|
if (!fieldName) {
|
|
81
|
-
return isPositive(
|
|
22
|
+
return vestUtils.isPositive(summary.testCount);
|
|
82
23
|
}
|
|
83
|
-
if (hasOwnProperty(testedStorage, fieldName))
|
|
24
|
+
if (vestUtils.hasOwnProperty(testedStorage, fieldName))
|
|
84
25
|
return testedStorage[fieldName];
|
|
85
26
|
testedStorage[fieldName] =
|
|
86
|
-
hasOwnProperty(
|
|
87
|
-
isPositive(
|
|
27
|
+
vestUtils.hasOwnProperty(summary.tests, fieldName) &&
|
|
28
|
+
vestUtils.isPositive(summary.tests[fieldName].testCount);
|
|
88
29
|
return selectors.tested(fieldName);
|
|
89
30
|
}
|
|
90
31
|
function isUntested(fieldName) {
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
|
-
function isValid(fieldName) {
|
|
94
|
-
var _a;
|
|
95
|
-
return fieldName ? Boolean((_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : res.valid;
|
|
96
|
-
}
|
|
97
|
-
function hasWarnings(fieldName) {
|
|
98
|
-
return hasFailures(SeverityCount.WARN_COUNT, fieldName);
|
|
99
|
-
}
|
|
100
|
-
function hasErrors(fieldName) {
|
|
101
|
-
return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
|
|
102
|
-
}
|
|
103
|
-
function hasFailures(countKey, fieldName) {
|
|
104
|
-
var _a;
|
|
105
|
-
var failureCount = defaultTo(fieldName ? (_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey] : res[countKey], 0);
|
|
106
|
-
return isPositive(failureCount);
|
|
32
|
+
return !(vestUtils.isPositive(summary.testCount) && selectors.tested(fieldName));
|
|
107
33
|
}
|
|
108
34
|
}
|
|
109
35
|
|
|
@@ -117,7 +43,7 @@ function classnames(res, classes) {
|
|
|
117
43
|
var classesArray = [];
|
|
118
44
|
for (var selector in classes) {
|
|
119
45
|
var sel = selector;
|
|
120
|
-
if (isFunction(selectors[sel]) && selectors[sel](key)) {
|
|
46
|
+
if (vestUtils.isFunction(selectors[sel]) && selectors[sel](key)) {
|
|
121
47
|
classesArray.push(classes[sel]);
|
|
122
48
|
}
|
|
123
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";var t=require("vest-utils"),e=require("vest");module.exports=function(s,r){void 0===r&&(r={});var i=function(s){t.invariant(s&&t.hasOwnProperty(s,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var r=e.suiteSelectors(s),i={},n={invalid:r.hasErrors,tested:function(e){return e?t.hasOwnProperty(i,e)?i[e]:(i[e]=t.hasOwnProperty(s.tests,e)&&t.isPositive(s.tests[e].testCount),n.tested(e)):t.isPositive(s.testCount)},untested:function(e){return!(t.isPositive(s.testCount)&&n.tested(e))},valid:r.isValid,warning:r.hasWarnings};return n}(s);return function(e){var s,n=[];for(s in r){var o=s;t.isFunction(i[o])&&i[o](e)&&n.push(r[o])}return n.join(" ")}};
|
|
@@ -1,61 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var vestUtils = require('vest-utils');
|
|
3
4
|
var n4s = require('n4s');
|
|
4
5
|
|
|
5
|
-
var assign = Object.assign;
|
|
6
|
-
|
|
7
|
-
function isFunction(value) {
|
|
8
|
-
return typeof value === 'function';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function optionalFunctionValue(value) {
|
|
12
|
-
var args = [];
|
|
13
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
14
|
-
args[_i - 1] = arguments[_i];
|
|
15
|
-
}
|
|
16
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function invariant(condition,
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
21
|
-
message) {
|
|
22
|
-
if (condition) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
// If message is a string object (rather than string literal)
|
|
26
|
-
// Throw the value directly as a string
|
|
27
|
-
// Alternatively, throw an error with the message
|
|
28
|
-
throw message instanceof String
|
|
29
|
-
? message.valueOf()
|
|
30
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
31
|
-
}
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
33
|
-
function StringObject(value) {
|
|
34
|
-
return new String(optionalFunctionValue(value));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function mapFirst(array, callback) {
|
|
38
|
-
var broke = false;
|
|
39
|
-
var breakoutValue = null;
|
|
40
|
-
for (var i = 0; i < array.length; i++) {
|
|
41
|
-
callback(array[i], breakout, i);
|
|
42
|
-
if (broke) {
|
|
43
|
-
return breakoutValue;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function breakout(conditional, value) {
|
|
47
|
-
if (conditional) {
|
|
48
|
-
broke = true;
|
|
49
|
-
breakoutValue = value;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function defaultTo(value, defaultValue) {
|
|
55
|
-
var _a;
|
|
56
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
6
|
function ruleReturn(pass, message) {
|
|
60
7
|
var output = { pass: pass };
|
|
61
8
|
if (message) {
|
|
@@ -70,7 +17,7 @@ function passing() {
|
|
|
70
17
|
return ruleReturn(true);
|
|
71
18
|
}
|
|
72
19
|
function defaultToPassing(callback) {
|
|
73
|
-
return defaultTo(callback, passing());
|
|
20
|
+
return vestUtils.defaultTo(callback, passing());
|
|
74
21
|
}
|
|
75
22
|
|
|
76
23
|
function runLazyRule(lazyRule, currentValue) {
|
|
@@ -88,16 +35,16 @@ function compose() {
|
|
|
88
35
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
89
36
|
composites[_i] = arguments[_i];
|
|
90
37
|
}
|
|
91
|
-
return assign(function (value) {
|
|
38
|
+
return vestUtils.assign(function (value) {
|
|
92
39
|
var res = run(value);
|
|
93
|
-
invariant(res.pass, StringObject(res.message));
|
|
40
|
+
vestUtils.invariant(res.pass, vestUtils.StringObject(res.message));
|
|
94
41
|
}, {
|
|
95
42
|
run: run,
|
|
96
43
|
test: function (value) { return run(value).pass; }
|
|
97
44
|
});
|
|
98
45
|
function run(value) {
|
|
99
46
|
return n4s.ctx.run({ value: value }, function () {
|
|
100
|
-
return defaultToPassing(mapFirst(composites, function (composite, breakout) {
|
|
47
|
+
return defaultToPassing(vestUtils.mapFirst(composites, function (composite, breakout) {
|
|
101
48
|
/* HACK: Just a small white lie. ~~HELP WANTED~~.
|
|
102
49
|
The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
|
|
103
50
|
The problem is that lazy rules can't really be passed to this function due to some generic hell
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=require("
|
|
1
|
+
"use strict";var n=require("vest-utils"),t=require("n4s");function r(n,t){return n={pass:n},t&&(n.message=t),n}function u(t){return n.defaultTo(t,r(!0))}function e(n,t){try{return n.run(t)}catch(n){return r(!1)}}module.exports=function(){function r(r){return t.ctx.run({value:r},(function(){return u(n.mapFirst(s,(function(n,t){t(!(n=e(n,r)).pass,n)})))}))}for(var s=[],i=0;i<arguments.length;i++)s[i]=arguments[i];return n.assign((function(t){t=r(t),n.invariant(t.pass,n.StringObject(t.message))}),{run:r,test:function(n){return r(n).pass}})};
|
|
@@ -1,41 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var vestUtils = require('vest-utils');
|
|
3
4
|
var n4s = require('n4s');
|
|
4
5
|
|
|
5
|
-
function mapFirst(array, callback) {
|
|
6
|
-
var broke = false;
|
|
7
|
-
var breakoutValue = null;
|
|
8
|
-
for (var i = 0; i < array.length; i++) {
|
|
9
|
-
callback(array[i], breakout, i);
|
|
10
|
-
if (broke) {
|
|
11
|
-
return breakoutValue;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function breakout(conditional, value) {
|
|
15
|
-
if (conditional) {
|
|
16
|
-
broke = true;
|
|
17
|
-
breakoutValue = value;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function isFunction(value) {
|
|
23
|
-
return typeof value === 'function';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function optionalFunctionValue(value) {
|
|
27
|
-
var args = [];
|
|
28
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
29
|
-
args[_i - 1] = arguments[_i];
|
|
30
|
-
}
|
|
31
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function defaultTo(value, defaultValue) {
|
|
35
|
-
var _a;
|
|
36
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
6
|
function ruleReturn(pass, message) {
|
|
40
7
|
var output = { pass: pass };
|
|
41
8
|
if (message) {
|
|
@@ -50,10 +17,10 @@ function passing() {
|
|
|
50
17
|
return ruleReturn(true);
|
|
51
18
|
}
|
|
52
19
|
function defaultToFailing(callback) {
|
|
53
|
-
return defaultTo(callback, failing());
|
|
20
|
+
return vestUtils.defaultTo(callback, failing());
|
|
54
21
|
}
|
|
55
22
|
function defaultToPassing(callback) {
|
|
56
|
-
return defaultTo(callback, passing());
|
|
23
|
+
return vestUtils.defaultTo(callback, passing());
|
|
57
24
|
}
|
|
58
25
|
|
|
59
26
|
function runLazyRule(lazyRule, currentValue) {
|
|
@@ -70,7 +37,7 @@ function allOf(value) {
|
|
|
70
37
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
71
38
|
rules[_i - 1] = arguments[_i];
|
|
72
39
|
}
|
|
73
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
40
|
+
return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
|
|
74
41
|
var res = runLazyRule(rule, value);
|
|
75
42
|
breakout(!res.pass, res);
|
|
76
43
|
}));
|
|
@@ -81,7 +48,7 @@ function anyOf(value) {
|
|
|
81
48
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
82
49
|
rules[_i - 1] = arguments[_i];
|
|
83
50
|
}
|
|
84
|
-
return defaultToFailing(mapFirst(rules, function (rule, breakout) {
|
|
51
|
+
return defaultToFailing(vestUtils.mapFirst(rules, function (rule, breakout) {
|
|
85
52
|
var res = runLazyRule(rule, value);
|
|
86
53
|
breakout(res.pass, res);
|
|
87
54
|
}));
|
|
@@ -92,7 +59,7 @@ function noneOf(value) {
|
|
|
92
59
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
93
60
|
rules[_i - 1] = arguments[_i];
|
|
94
61
|
}
|
|
95
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
62
|
+
return defaultToPassing(vestUtils.mapFirst(rules, function (rule, breakout) {
|
|
96
63
|
var res = runLazyRule(rule, value);
|
|
97
64
|
breakout(res.pass, failing());
|
|
98
65
|
}));
|
|
@@ -101,17 +68,7 @@ function noneOf(value) {
|
|
|
101
68
|
function equals(value, arg1) {
|
|
102
69
|
return value === arg1;
|
|
103
70
|
}
|
|
104
|
-
|
|
105
|
-
function isNumeric(value) {
|
|
106
|
-
var str = String(value);
|
|
107
|
-
var num = Number(value);
|
|
108
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
109
|
-
return Boolean(result);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function greaterThan(value, gt) {
|
|
113
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
114
|
-
}
|
|
71
|
+
vestUtils.bindNot(equals);
|
|
115
72
|
|
|
116
73
|
var REQUIRED_COUNT = 1;
|
|
117
74
|
function oneOf(value) {
|
|
@@ -125,7 +82,7 @@ function oneOf(value) {
|
|
|
125
82
|
if (res.pass) {
|
|
126
83
|
passingCount++;
|
|
127
84
|
}
|
|
128
|
-
if (greaterThan(passingCount, REQUIRED_COUNT)) {
|
|
85
|
+
if (vestUtils.greaterThan(passingCount, REQUIRED_COUNT)) {
|
|
129
86
|
return false;
|
|
130
87
|
}
|
|
131
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=require("
|
|
1
|
+
"use strict";var n=require("vest-utils"),r=require("n4s");function t(n,r){return n={pass:n},r&&(n.message=r),n}function e(){return t(!1)}function u(r){return n.defaultTo(r,e())}function f(r){return n.defaultTo(r,t(!0))}function o(n,r){try{return n.run(r)}catch(n){return e()}}function i(n,r){return n===r}n.bindNot(i);r.enforce.extend({allOf:function(r){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return f(n.mapFirst(t,(function(n,t){t(!(n=o(n,r)).pass,n)})))},anyOf:function(r){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return u(n.mapFirst(t,(function(n,t){t((n=o(n,r)).pass,n)})))},noneOf:function(r){for(var t=[],u=1;u<arguments.length;u++)t[u-1]=arguments[u];return f(n.mapFirst(t,(function(n,t){t((n=o(n,r)).pass,e())})))},oneOf:function(r){for(var e=[],u=1;u<arguments.length;u++)e[u-1]=arguments[u];var f=0;return e.some((function(t){if(o(t,r).pass&&f++,n.greaterThan(f,1))return!1})),t(i(f,1))}});
|
|
@@ -2,42 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var vestUtils = require('vest-utils');
|
|
5
6
|
var n4s = require('n4s');
|
|
6
7
|
|
|
7
|
-
function mapFirst(array, callback) {
|
|
8
|
-
var broke = false;
|
|
9
|
-
var breakoutValue = null;
|
|
10
|
-
for (var i = 0; i < array.length; i++) {
|
|
11
|
-
callback(array[i], breakout, i);
|
|
12
|
-
if (broke) {
|
|
13
|
-
return breakoutValue;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function breakout(conditional, value) {
|
|
17
|
-
if (conditional) {
|
|
18
|
-
broke = true;
|
|
19
|
-
breakoutValue = value;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function isFunction(value) {
|
|
25
|
-
return typeof value === 'function';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function optionalFunctionValue(value) {
|
|
29
|
-
var args = [];
|
|
30
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
31
|
-
args[_i - 1] = arguments[_i];
|
|
32
|
-
}
|
|
33
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function defaultTo(value, defaultValue) {
|
|
37
|
-
var _a;
|
|
38
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
8
|
function ruleReturn(pass, message) {
|
|
42
9
|
var output = { pass: pass };
|
|
43
10
|
if (message) {
|
|
@@ -52,7 +19,7 @@ function passing() {
|
|
|
52
19
|
return ruleReturn(true);
|
|
53
20
|
}
|
|
54
21
|
function defaultToPassing(callback) {
|
|
55
|
-
return defaultTo(callback, passing());
|
|
22
|
+
return vestUtils.defaultTo(callback, passing());
|
|
56
23
|
}
|
|
57
24
|
|
|
58
25
|
function runLazyRule(lazyRule, currentValue) {
|
|
@@ -65,7 +32,7 @@ function runLazyRule(lazyRule, currentValue) {
|
|
|
65
32
|
}
|
|
66
33
|
|
|
67
34
|
function isArrayOf(inputArray, currentRule) {
|
|
68
|
-
return defaultToPassing(mapFirst(inputArray, function (currentValue, breakout, index) {
|
|
35
|
+
return defaultToPassing(vestUtils.mapFirst(inputArray, function (currentValue, breakout, index) {
|
|
69
36
|
var res = n4s.ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
|
|
70
37
|
breakout(!res.pass, res);
|
|
71
38
|
}));
|
|
@@ -90,39 +57,20 @@ function loose(inputObject, shapeObject) {
|
|
|
90
57
|
return passing();
|
|
91
58
|
}
|
|
92
59
|
|
|
93
|
-
function isNull(value) {
|
|
94
|
-
return value === null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function isUndefined(value) {
|
|
98
|
-
return value === undefined;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function isNullish(value) {
|
|
102
|
-
return isNull(value) || isUndefined(value);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
60
|
function optional(value, ruleChain) {
|
|
106
|
-
if (isNullish(value)) {
|
|
61
|
+
if (vestUtils.isNullish(value)) {
|
|
107
62
|
return passing();
|
|
108
63
|
}
|
|
109
64
|
return runLazyRule(ruleChain, value);
|
|
110
65
|
}
|
|
111
66
|
|
|
112
|
-
/**
|
|
113
|
-
* A safe hasOwnProperty access
|
|
114
|
-
*/
|
|
115
|
-
function hasOwnProperty(obj, key) {
|
|
116
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
67
|
function shape(inputObject, shapeObject) {
|
|
120
68
|
var baseRes = loose(inputObject, shapeObject);
|
|
121
69
|
if (!baseRes.pass) {
|
|
122
70
|
return baseRes;
|
|
123
71
|
}
|
|
124
72
|
for (var key in inputObject) {
|
|
125
|
-
if (!hasOwnProperty(shapeObject, key)) {
|
|
73
|
+
if (!vestUtils.hasOwnProperty(shapeObject, key)) {
|
|
126
74
|
return failing();
|
|
127
75
|
}
|
|
128
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("vest-utils"),n=require("n4s");function e(r,n){return r={pass:r},n&&(r.message=n),r}function t(){return e(!1)}function u(){return e(!0)}function i(r,n){try{return r.run(n)}catch(r){return t()}}function o(r,e){var t,o=function(t){var u=r[t],o=e[t];if(!(t=n.ctx.run({value:u,set:!0,meta:{key:t}},(function(){return i(o,u)}))).pass)return{value:t}};for(t in e){var a=o(t);if("object"==typeof a)return a.value}return u()}n.enforce.extend({isArrayOf:function(e,t){return function(n){return r.defaultTo(n,u())}(r.mapFirst(e,(function(r,e,u){e(!(u=n.ctx.run({value:r,set:!0,meta:{index:u}},(function(){return i(t,r)}))).pass,u)})))},loose:o,optional:function(n,e){return r.isNullish(n)?u():i(e,n)},shape:function(n,e){var i=o(n,e);if(!i.pass)return i;for(var a in n)if(!r.hasOwnProperty(e,a))return t();return u()}}),exports.partial=function(r){var e,t={};for(e in r)t[e]=n.enforce.optional(r[e]);return t};
|
|
@@ -2,110 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function optionalFunctionValue(value) {
|
|
10
|
-
var args = [];
|
|
11
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
12
|
-
args[_i - 1] = arguments[_i];
|
|
13
|
-
}
|
|
14
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function defaultTo(value, defaultValue) {
|
|
18
|
-
var _a;
|
|
19
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A safe hasOwnProperty access
|
|
24
|
-
*/
|
|
25
|
-
function hasOwnProperty(obj, key) {
|
|
26
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function invariant(condition,
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
31
|
-
message) {
|
|
32
|
-
if (condition) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
// If message is a string object (rather than string literal)
|
|
36
|
-
// Throw the value directly as a string
|
|
37
|
-
// Alternatively, throw an error with the message
|
|
38
|
-
throw message instanceof String
|
|
39
|
-
? message.valueOf()
|
|
40
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
41
|
-
}
|
|
5
|
+
var vest = require('vest');
|
|
6
|
+
var vestUtils = require('vest-utils');
|
|
42
7
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var
|
|
47
|
-
return Boolean(result);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function greaterThan(value, gt) {
|
|
51
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function isPositive(value) {
|
|
55
|
-
return greaterThan(value, 0);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
var Severity;
|
|
59
|
-
(function (Severity) {
|
|
60
|
-
Severity["WARNINGS"] = "warnings";
|
|
61
|
-
Severity["ERRORS"] = "errors";
|
|
62
|
-
})(Severity || (Severity = {}));
|
|
63
|
-
var SeverityCount;
|
|
64
|
-
(function (SeverityCount) {
|
|
65
|
-
SeverityCount["ERROR_COUNT"] = "errorCount";
|
|
66
|
-
SeverityCount["WARN_COUNT"] = "warnCount";
|
|
67
|
-
})(SeverityCount || (SeverityCount = {}));
|
|
68
|
-
|
|
69
|
-
// eslint-disable-next-line max-lines-per-function
|
|
70
|
-
function parse(res) {
|
|
71
|
-
invariant(res && hasOwnProperty(res, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
|
|
8
|
+
// eslint-disable-next-line max-statements
|
|
9
|
+
function parse(summary) {
|
|
10
|
+
vestUtils.invariant(summary && vestUtils.hasOwnProperty(summary, 'valid'), "Vest parser: expected argument at position 0 to be Vest's result object.");
|
|
11
|
+
var sel = vest.suiteSelectors(summary);
|
|
72
12
|
var testedStorage = {};
|
|
73
13
|
var selectors = {
|
|
74
|
-
invalid: hasErrors,
|
|
14
|
+
invalid: sel.hasErrors,
|
|
75
15
|
tested: isTested,
|
|
76
16
|
untested: isUntested,
|
|
77
|
-
valid: isValid,
|
|
78
|
-
warning: hasWarnings
|
|
17
|
+
valid: sel.isValid,
|
|
18
|
+
warning: sel.hasWarnings
|
|
79
19
|
};
|
|
80
20
|
return selectors;
|
|
21
|
+
// Booleans
|
|
81
22
|
function isTested(fieldName) {
|
|
82
23
|
if (!fieldName) {
|
|
83
|
-
return isPositive(
|
|
24
|
+
return vestUtils.isPositive(summary.testCount);
|
|
84
25
|
}
|
|
85
|
-
if (hasOwnProperty(testedStorage, fieldName))
|
|
26
|
+
if (vestUtils.hasOwnProperty(testedStorage, fieldName))
|
|
86
27
|
return testedStorage[fieldName];
|
|
87
28
|
testedStorage[fieldName] =
|
|
88
|
-
hasOwnProperty(
|
|
89
|
-
isPositive(
|
|
29
|
+
vestUtils.hasOwnProperty(summary.tests, fieldName) &&
|
|
30
|
+
vestUtils.isPositive(summary.tests[fieldName].testCount);
|
|
90
31
|
return selectors.tested(fieldName);
|
|
91
32
|
}
|
|
92
33
|
function isUntested(fieldName) {
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
function isValid(fieldName) {
|
|
96
|
-
var _a;
|
|
97
|
-
return fieldName ? Boolean((_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a.valid) : res.valid;
|
|
98
|
-
}
|
|
99
|
-
function hasWarnings(fieldName) {
|
|
100
|
-
return hasFailures(SeverityCount.WARN_COUNT, fieldName);
|
|
101
|
-
}
|
|
102
|
-
function hasErrors(fieldName) {
|
|
103
|
-
return hasFailures(SeverityCount.ERROR_COUNT, fieldName);
|
|
104
|
-
}
|
|
105
|
-
function hasFailures(countKey, fieldName) {
|
|
106
|
-
var _a;
|
|
107
|
-
var failureCount = defaultTo(fieldName ? (_a = res.tests[fieldName]) === null || _a === void 0 ? void 0 : _a[countKey] : res[countKey], 0);
|
|
108
|
-
return isPositive(failureCount);
|
|
34
|
+
return !(vestUtils.isPositive(summary.testCount) && selectors.tested(fieldName));
|
|
109
35
|
}
|
|
110
36
|
}
|
|
111
37
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("vest"),e=require("vest-utils");exports.parse=function(s){e.invariant(s&&e.hasOwnProperty(s,"valid"),"Vest parser: expected argument at position 0 to be Vest's result object.");var r=t.suiteSelectors(s),i={},n={invalid:r.hasErrors,tested:function(t){return t?e.hasOwnProperty(i,t)?i[t]:(i[t]=e.hasOwnProperty(s.tests,t)&&e.isPositive(s.tests[t].testCount),n.tested(t)):e.isPositive(s.testCount)},untested:function(t){return!(e.isPositive(s.testCount)&&n.tested(t))},valid:r.isValid,warning:r.hasWarnings};return n};
|
|
@@ -1,30 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
return typeof value === 'function';
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function optionalFunctionValue(value) {
|
|
8
|
-
var args = [];
|
|
9
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
10
|
-
args[_i - 1] = arguments[_i];
|
|
11
|
-
}
|
|
12
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function invariant(condition,
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
17
|
-
message) {
|
|
18
|
-
if (condition) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
// If message is a string object (rather than string literal)
|
|
22
|
-
// Throw the value directly as a string
|
|
23
|
-
// Alternatively, throw an error with the message
|
|
24
|
-
throw message instanceof String
|
|
25
|
-
? message.valueOf()
|
|
26
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
27
|
-
}
|
|
3
|
+
var vestUtils = require('vest-utils');
|
|
28
4
|
|
|
29
5
|
var promisify = function (validatorFn) {
|
|
30
6
|
return function () {
|
|
@@ -32,7 +8,7 @@ var promisify = function (validatorFn) {
|
|
|
32
8
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
33
9
|
args[_i] = arguments[_i];
|
|
34
10
|
}
|
|
35
|
-
invariant(isFunction(validatorFn), 'promisify: Expected validatorFn to be a function.');
|
|
11
|
+
vestUtils.invariant(vestUtils.isFunction(validatorFn), 'promisify: Expected validatorFn to be a function.');
|
|
36
12
|
return new Promise(function (resolve) { return validatorFn.apply(void 0, args).done(resolve); });
|
|
37
13
|
};
|
|
38
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";var n=require("vest-utils");module.exports=function(t){return function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return n.invariant(n.isFunction(t),"promisify: Expected validatorFn to be a function."),new Promise((function(n){return t.apply(void 0,r).done(n)}))}};
|