validno 0.2.2 → 0.2.4
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/ValidnoResult.js +40 -11
- package/dist/dev.js +43 -97
- package/dist/utils/errors.js +6 -2
- package/dist/utils/helpers.js +32 -11
- package/dist/utils/validations.js +42 -16
- package/dist/validate.js +31 -25
- package/package.json +1 -1
- package/.eslintrc.cjs +0 -13
- package/.eslintrc.json +0 -16
- package/jest.config.ts +0 -199
package/dist/ValidnoResult.js
CHANGED
|
@@ -8,26 +8,36 @@ class ValidnoResult {
|
|
|
8
8
|
this.errors = (results === null || results === void 0 ? void 0 : results.errors) || [];
|
|
9
9
|
this.byKeys = (results === null || results === void 0 ? void 0 : results.byKeys) || {};
|
|
10
10
|
this.errorsByKeys = (results === null || results === void 0 ? void 0 : results.errorsByKeys) || {};
|
|
11
|
-
this.byKeys = (results === null || results === void 0 ? void 0 : results.byKeys) || {};
|
|
12
11
|
}
|
|
13
|
-
|
|
12
|
+
setKeyStatus(key, result) {
|
|
14
13
|
this.byKeys[key] = result;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
}
|
|
15
|
+
fixParentByChilds(parentKey, childChecks = []) {
|
|
16
|
+
const isEveryOk = childChecks.every(c => c === true);
|
|
17
|
+
this.setKeyStatus(parentKey, isEveryOk);
|
|
18
|
+
if (isEveryOk === true)
|
|
19
|
+
this.setPassed(parentKey);
|
|
17
20
|
else
|
|
18
|
-
this.
|
|
21
|
+
this.setFailed(parentKey);
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
this.missed.push(key);
|
|
22
|
-
this.fixByKey(key, false);
|
|
23
|
+
setMissing(key, errMsg) {
|
|
23
24
|
const error = errMsg || _errors.getMissingError(key);
|
|
24
|
-
this.
|
|
25
|
+
this.missed.push(key);
|
|
26
|
+
this.setFailed(key, error);
|
|
27
|
+
this.setKeyStatus(key, false);
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
setPassed(key) {
|
|
30
|
+
this.passed.push(key);
|
|
31
|
+
this.setKeyStatus(key, true);
|
|
32
|
+
}
|
|
33
|
+
setFailed(key, msg) {
|
|
27
34
|
if (key in this.errorsByKeys === false) {
|
|
28
35
|
this.errorsByKeys[key] = [];
|
|
29
36
|
}
|
|
30
|
-
this.
|
|
37
|
+
this.failed.push(key);
|
|
38
|
+
this.setKeyStatus(key, false);
|
|
39
|
+
if (!msg)
|
|
40
|
+
return;
|
|
31
41
|
this.errors.push(msg);
|
|
32
42
|
this.errorsByKeys[key].push(msg);
|
|
33
43
|
}
|
|
@@ -50,12 +60,31 @@ class ValidnoResult {
|
|
|
50
60
|
}
|
|
51
61
|
return this;
|
|
52
62
|
}
|
|
63
|
+
clearEmptyErrorsByKeys() {
|
|
64
|
+
for (const key in this.errorsByKeys) {
|
|
65
|
+
if (!this.errorsByKeys[key].length) {
|
|
66
|
+
delete this.errorsByKeys[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
53
70
|
finish() {
|
|
54
71
|
if (this.failed.length)
|
|
55
72
|
this.ok = false;
|
|
56
73
|
else
|
|
57
74
|
this.ok = true;
|
|
75
|
+
this.clearEmptyErrorsByKeys();
|
|
58
76
|
return this;
|
|
59
77
|
}
|
|
78
|
+
data() {
|
|
79
|
+
return {
|
|
80
|
+
ok: this.ok,
|
|
81
|
+
missed: this.missed,
|
|
82
|
+
failed: this.failed,
|
|
83
|
+
passed: this.passed,
|
|
84
|
+
errors: this.errors,
|
|
85
|
+
byKeys: this.byKeys,
|
|
86
|
+
errorsByKeys: this.errorsByKeys,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
60
89
|
}
|
|
61
90
|
export default ValidnoResult;
|
package/dist/dev.js
CHANGED
|
@@ -1,105 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
];
|
|
14
|
-
const str = 'string';
|
|
15
|
-
const date = () => new Date(2025, 0, 1, 0, 0, 0, 0);
|
|
16
|
-
const json = () => {
|
|
17
|
-
return {
|
|
18
|
-
"surname": "Иванов",
|
|
19
|
-
"name": "Иван",
|
|
20
|
-
"patronymic": "Иванович",
|
|
21
|
-
"birthdate": "01.01.1990",
|
|
22
|
-
"birthplace": "Москва",
|
|
23
|
-
"phone": "8 926 766 48 48"
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
console.time('autofill');
|
|
27
|
-
let i = 0;
|
|
28
|
-
while (i < TEST_MAX) {
|
|
29
|
-
if (TYPES.includes('null'))
|
|
30
|
-
listSame.push(null);
|
|
31
|
-
if (TYPES.includes('boolean'))
|
|
32
|
-
listSame.push(true);
|
|
33
|
-
if (TYPES.includes('json'))
|
|
34
|
-
listSame.push(() => json());
|
|
35
|
-
if (TYPES.includes('date'))
|
|
36
|
-
listSame.push(() => date());
|
|
37
|
-
if (TYPES.includes('string'))
|
|
38
|
-
listSame.push(str);
|
|
39
|
-
if (TYPES.includes('number'))
|
|
40
|
-
listSame.push(Math.random());
|
|
41
|
-
if (TYPES.includes('array'))
|
|
42
|
-
listSame.push(() => [{ x: 1, y: { z: 0 } }, { x: 1 }, { x: 1 }]);
|
|
43
|
-
if (TYPES.includes('array'))
|
|
44
|
-
listSame.push(() => [1234451, 5535433, 7839262, 2134573, 10239752]);
|
|
45
|
-
if (TYPES.includes('array'))
|
|
46
|
-
listSame.push(() => [true, true, false, true, false]);
|
|
47
|
-
if (TYPES.includes('array'))
|
|
48
|
-
listSame.push(() => ['true', 'true', 'false', 'true', 'false']);
|
|
49
|
-
i++;
|
|
50
|
-
}
|
|
51
|
-
console.timeEnd('autofill');
|
|
52
|
-
const compareArrs = (v1, v2) => {
|
|
53
|
-
if (v1.length !== v2.length)
|
|
54
|
-
return false;
|
|
55
|
-
return v1.every((el, i) => {
|
|
56
|
-
if (_validations.isObject(el)) {
|
|
57
|
-
return JSON.stringify(el) === JSON.stringify(v2[i]);
|
|
1
|
+
import { Schema } from "./Schema.js";
|
|
2
|
+
const validateConfig = (cfg) => {
|
|
3
|
+
const cfgSchema = new Schema({
|
|
4
|
+
str1: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: true
|
|
7
|
+
},
|
|
8
|
+
str2: {
|
|
9
|
+
deep1: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
}
|
|
58
13
|
}
|
|
59
|
-
return v2[i] === el;
|
|
60
14
|
});
|
|
15
|
+
const res = cfgSchema.validate(cfg);
|
|
16
|
+
console.log(res);
|
|
61
17
|
};
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
const bothArrays = _validations.isArray(value) && _validations.isArray(compareTo);
|
|
67
|
-
if (bothArrays) {
|
|
68
|
-
return compareArrs(value, compareTo);
|
|
69
|
-
}
|
|
70
|
-
const bothObjects = _validations.isObject(value) && _validations.isObject(compareTo);
|
|
71
|
-
if (bothObjects) {
|
|
72
|
-
const valueStr = JSON.stringify(value);
|
|
73
|
-
const compareToStr = JSON.stringify(compareTo);
|
|
74
|
-
return valueStr === compareToStr;
|
|
75
|
-
}
|
|
76
|
-
const bothDates = _validations.isDate(value) && _validations.isDate(compareTo);
|
|
77
|
-
if (bothDates) {
|
|
78
|
-
return value.getTime() === compareTo.getTime();
|
|
79
|
-
}
|
|
80
|
-
return value === compareTo;
|
|
18
|
+
const uniTestService = {
|
|
19
|
+
str1: 'xxxx'
|
|
81
20
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
21
|
+
validateConfig(uniTestService);
|
|
22
|
+
console.log(uniTestService);
|
|
23
|
+
console.log(uniTestService);
|
|
24
|
+
const obj = {
|
|
25
|
+
top: {
|
|
26
|
+
mid1: {
|
|
27
|
+
low1a: false,
|
|
28
|
+
low1b: false
|
|
29
|
+
},
|
|
30
|
+
mid2: {
|
|
31
|
+
low2a: false
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
top2: false
|
|
87
35
|
};
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const v2 = typeof listSame[y] === 'function' ? listSame[y]() : listSame[y];
|
|
94
|
-
const result = func(v1, v2);
|
|
95
|
-
if (result !== true) {
|
|
96
|
-
console.log(v1);
|
|
97
|
-
console.log(v2);
|
|
98
|
-
throw new Error('RESULT != TRUE');
|
|
36
|
+
const setNestedValue = (linkedObj, keysLevels, curLevel, valueToSet) => {
|
|
37
|
+
const lvKey = keysLevels[curLevel];
|
|
38
|
+
if (curLevel < keysLevels.length - 1) {
|
|
39
|
+
if (!linkedObj[lvKey] || typeof linkedObj[lvKey] !== 'object') {
|
|
40
|
+
linkedObj[lvKey] = {};
|
|
99
41
|
}
|
|
100
|
-
|
|
42
|
+
return setNestedValue(linkedObj[lvKey], keysLevels, curLevel + 1, valueToSet);
|
|
101
43
|
}
|
|
102
|
-
|
|
44
|
+
else {
|
|
45
|
+
linkedObj[lvKey] = valueToSet;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const setDeepValue = (obj, keysChain, valueToSet) => {
|
|
49
|
+
const keysLevels = keysChain.split('.');
|
|
50
|
+
setNestedValue(obj, keysLevels, 0, valueToSet);
|
|
103
51
|
};
|
|
104
|
-
doTest(is);
|
|
105
|
-
doTest(is3);
|
package/dist/utils/errors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const _errors = {};
|
|
2
|
-
_errors.getMissingError = (key) =>
|
|
2
|
+
_errors.getMissingError = (key = 'na') => `Отсутствует значение '${key}'`;
|
|
3
3
|
_errors.getErrorDetails = (key, expectedType, receivedValue) => {
|
|
4
4
|
var _a;
|
|
5
5
|
let receivedType = '';
|
|
@@ -9,7 +9,11 @@ _errors.getErrorDetails = (key, expectedType, receivedValue) => {
|
|
|
9
9
|
receivedType = 'null';
|
|
10
10
|
else
|
|
11
11
|
receivedType = ((_a = receivedValue.constructor) === null || _a === void 0 ? void 0 : _a.name) || typeof receivedValue || 'na';
|
|
12
|
-
|
|
12
|
+
const expectedOutput = (expectedType === null || expectedType === void 0 ? void 0 : expectedType.name) || expectedType;
|
|
13
|
+
const receivedOutput = receivedType || 'na';
|
|
14
|
+
if (String(expectedOutput) === String(receivedOutput))
|
|
15
|
+
return '';
|
|
16
|
+
return `Проверьте тип '${key}': ожидался ${expectedOutput}, получен ${receivedOutput}`;
|
|
13
17
|
};
|
|
14
18
|
_errors.joinErrors = (errorsArr, separator = '; ') => {
|
|
15
19
|
return (errorsArr === null || errorsArr === void 0 ? void 0 : errorsArr.join(`${separator}`)) || '';
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defaultSchemaKeys } from "../Schema.js";
|
|
2
|
-
import ValidnoResult from "../ValidnoResult.js";
|
|
3
2
|
import _validations from "./validations.js";
|
|
4
3
|
const _helpers = {};
|
|
5
4
|
_helpers.checkIsNested = (obj) => {
|
|
@@ -13,16 +12,6 @@ _helpers.checkIsNested = (obj) => {
|
|
|
13
12
|
return true;
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
|
-
_helpers.mergeResults = (resultsOld, resultsNew) => {
|
|
17
|
-
const output = new ValidnoResult();
|
|
18
|
-
output.failed = [...resultsOld.failed, ...resultsNew.failed];
|
|
19
|
-
output.errors = [...resultsOld.errors, ...resultsNew.errors];
|
|
20
|
-
output.missed = [...resultsOld.missed, ...resultsNew.missed];
|
|
21
|
-
output.passed = [...resultsOld.passed, ...resultsNew.passed];
|
|
22
|
-
output.byKeys = Object.assign(Object.assign({}, resultsOld.byKeys), resultsNew.byKeys);
|
|
23
|
-
output.errorsByKeys = Object.assign(Object.assign({}, resultsOld.errorsByKeys), resultsNew.errorsByKeys);
|
|
24
|
-
return output;
|
|
25
|
-
};
|
|
26
15
|
_helpers.checkNestedIsMissing = (reqs, data) => {
|
|
27
16
|
const isRequired = reqs.required;
|
|
28
17
|
const isUndef = data === undefined;
|
|
@@ -45,4 +34,36 @@ _helpers.hasMissing = (input) => {
|
|
|
45
34
|
const missingData = (data === undefined || key in data === false || data[key] === undefined);
|
|
46
35
|
return isRequired && missingData;
|
|
47
36
|
};
|
|
37
|
+
_helpers.compareArrs = (v1, v2) => {
|
|
38
|
+
if (v1.length !== v2.length)
|
|
39
|
+
return false;
|
|
40
|
+
return v1.every((el, i) => {
|
|
41
|
+
if (_validations.isObject(el)) {
|
|
42
|
+
return JSON.stringify(el) === JSON.stringify(v2[i]);
|
|
43
|
+
}
|
|
44
|
+
return v2[i] === el;
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
_helpers.compareObjs = (obj1, obj2) => {
|
|
48
|
+
function deepEqual(obj1, obj2) {
|
|
49
|
+
if (obj1 === obj2) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const keys1 = Object.keys(obj1);
|
|
56
|
+
const keys2 = Object.keys(obj2);
|
|
57
|
+
if (keys1.length !== keys2.length) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
for (let key of keys1) {
|
|
61
|
+
if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return deepEqual(obj1, obj2);
|
|
68
|
+
};
|
|
48
69
|
export default _helpers;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _helpers from "./helpers.js";
|
|
1
2
|
const _validations = {};
|
|
2
3
|
_validations.isString = (value) => {
|
|
3
4
|
return typeof value === 'string';
|
|
@@ -73,37 +74,55 @@ _validations.lengthMax = (value, max) => {
|
|
|
73
74
|
_validations.isNumberGte = (value, gte) => {
|
|
74
75
|
return typeof value === 'number' && value >= gte;
|
|
75
76
|
};
|
|
77
|
+
_validations.isNumberGt = (value, gt) => {
|
|
78
|
+
return typeof value === 'number' && value > gt;
|
|
79
|
+
};
|
|
76
80
|
_validations.isNumberLte = (value, lte) => {
|
|
77
81
|
return typeof value === 'number' && value <= lte;
|
|
78
82
|
};
|
|
83
|
+
_validations.isNumberLt = (value, lt) => {
|
|
84
|
+
return typeof value === 'number' && value < lt;
|
|
85
|
+
};
|
|
86
|
+
_validations.isDateGte = (date1, date2) => {
|
|
87
|
+
if (!_validations.isDate(date1) || !_validations.isDate(date2)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return date1 >= date2;
|
|
91
|
+
};
|
|
92
|
+
_validations.isDateGt = (date1, date2) => {
|
|
93
|
+
if (!_validations.isDate(date1) || !_validations.isDate(date2)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return date1 > date2;
|
|
97
|
+
};
|
|
98
|
+
_validations.isDateLte = (date1, date2) => {
|
|
99
|
+
if (!_validations.isDate(date1) || !_validations.isDate(date2)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return date1 <= date2;
|
|
103
|
+
};
|
|
104
|
+
_validations.isDateLt = (date1, date2) => {
|
|
105
|
+
if (!_validations.isDate(date1) || !_validations.isDate(date2)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return date1 < date2;
|
|
109
|
+
};
|
|
79
110
|
_validations.hasKey = (obj, key) => {
|
|
80
111
|
if (_validations.isObject(obj) === false)
|
|
81
112
|
return false;
|
|
82
113
|
return key in obj;
|
|
83
114
|
};
|
|
84
|
-
const compareArrs = (v1, v2) => {
|
|
85
|
-
if (v1.length !== v2.length)
|
|
86
|
-
return false;
|
|
87
|
-
return v1.every((el, i) => {
|
|
88
|
-
if (_validations.isObject(el)) {
|
|
89
|
-
return JSON.stringify(el) === JSON.stringify(v2[i]);
|
|
90
|
-
}
|
|
91
|
-
return v2[i] === el;
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
115
|
_validations.is = (value, compareTo) => {
|
|
95
116
|
if (value === compareTo) {
|
|
96
117
|
return true;
|
|
97
118
|
}
|
|
98
119
|
const bothArrays = _validations.isArray(value) && _validations.isArray(compareTo);
|
|
99
120
|
if (bothArrays) {
|
|
100
|
-
return compareArrs(value, compareTo);
|
|
121
|
+
return _helpers.compareArrs(value, compareTo);
|
|
101
122
|
}
|
|
102
123
|
const bothObjects = _validations.isObject(value) && _validations.isObject(compareTo);
|
|
103
124
|
if (bothObjects) {
|
|
104
|
-
|
|
105
|
-
const compareToStr = JSON.stringify(compareTo);
|
|
106
|
-
return valueStr === compareToStr;
|
|
125
|
+
return _helpers.compareObjs(value, compareTo);
|
|
107
126
|
}
|
|
108
127
|
const bothDates = _validations.isDate(value) && _validations.isDate(compareTo);
|
|
109
128
|
if (bothDates) {
|
|
@@ -114,14 +133,21 @@ _validations.is = (value, compareTo) => {
|
|
|
114
133
|
_validations.not = (value, not) => {
|
|
115
134
|
return !_validations.is(value, not);
|
|
116
135
|
};
|
|
117
|
-
_validations.isNot = _validations.not;
|
|
118
|
-
_validations.ne = _validations.not;
|
|
119
136
|
_validations.regexTested = (value, regexp) => {
|
|
120
137
|
if (!regexp || regexp instanceof RegExp !== true) {
|
|
121
138
|
throw new Error('regexp argument is incorrect');
|
|
122
139
|
}
|
|
123
140
|
return regexp.test(value);
|
|
124
141
|
};
|
|
142
|
+
_validations.gt = _validations.isNumberGt;
|
|
143
|
+
_validations.gte = _validations.isNumberGte;
|
|
144
|
+
_validations.lte = _validations.isNumberLte;
|
|
145
|
+
_validations.lt = _validations.isNumberLt;
|
|
146
|
+
_validations.eq = _validations.is;
|
|
147
|
+
_validations.isNot = _validations.not;
|
|
148
|
+
_validations.ne = _validations.not;
|
|
149
|
+
_validations.neq = _validations.not;
|
|
150
|
+
_validations.regexpTested = _validations.regexpTested;
|
|
125
151
|
_validations.regex = _validations.regexTested;
|
|
126
152
|
_validations.regexp = _validations.regexTested;
|
|
127
153
|
_validations.test = _validations.regexTested;
|
package/dist/validate.js
CHANGED
|
@@ -5,26 +5,25 @@ import _helpers from "./utils/helpers.js";
|
|
|
5
5
|
import { ErrorKeywords } from "./constants/details.js";
|
|
6
6
|
import ValidnoResult from "./ValidnoResult.js";
|
|
7
7
|
function generateMsg(input) {
|
|
8
|
-
let {
|
|
8
|
+
let { key, deepKey, data, reqs } = input;
|
|
9
9
|
const keyForMsg = deepKey || key;
|
|
10
10
|
const keyTitle = 'title' in reqs ? reqs.title : keyForMsg;
|
|
11
|
-
if (reqs.customMessage
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return _errors.getMissingError(keyForMsg);
|
|
11
|
+
if (!reqs.customMessage)
|
|
12
|
+
return _errors.getMissingError(keyForMsg);
|
|
13
|
+
const errMsg = reqs.customMessage({
|
|
14
|
+
keyword: ErrorKeywords.Missing,
|
|
15
|
+
value: data[key],
|
|
16
|
+
key: keyForMsg,
|
|
17
|
+
title: keyTitle,
|
|
18
|
+
reqs: reqs,
|
|
19
|
+
schema: this.schema
|
|
20
|
+
});
|
|
21
|
+
return errMsg;
|
|
23
22
|
}
|
|
24
23
|
function handleDeepKey(input) {
|
|
25
24
|
const { results, key, deepKey, data, reqs } = input;
|
|
26
25
|
const nesctedKeys = Object.keys(reqs);
|
|
27
|
-
|
|
26
|
+
const nestedResults = [];
|
|
28
27
|
let i = 0;
|
|
29
28
|
while (i < nesctedKeys.length) {
|
|
30
29
|
const nestedKey = nesctedKeys[i];
|
|
@@ -35,9 +34,11 @@ function handleDeepKey(input) {
|
|
|
35
34
|
deepKey: `${deepKey}.${nestedKey}`
|
|
36
35
|
};
|
|
37
36
|
const deepResults = handleKey.call(this, deepParams);
|
|
37
|
+
nestedResults.push(deepResults.ok);
|
|
38
38
|
results.merge(deepResults);
|
|
39
39
|
i++;
|
|
40
40
|
}
|
|
41
|
+
results.fixParentByChilds(deepKey, nestedResults);
|
|
41
42
|
return results;
|
|
42
43
|
}
|
|
43
44
|
export function handleKey(input) {
|
|
@@ -52,7 +53,7 @@ export function handleKey(input) {
|
|
|
52
53
|
const typeChecked = [];
|
|
53
54
|
const rulesChecked = [];
|
|
54
55
|
if (_helpers.checkNestedIsMissing(reqs, data)) {
|
|
55
|
-
results.
|
|
56
|
+
results.setMissing(deepKey);
|
|
56
57
|
return results;
|
|
57
58
|
}
|
|
58
59
|
if (hasNested) {
|
|
@@ -61,7 +62,7 @@ export function handleKey(input) {
|
|
|
61
62
|
if (hasMissing) {
|
|
62
63
|
let errMsg = generateMsg.call(this, input);
|
|
63
64
|
missedCheck.push(false);
|
|
64
|
-
results.
|
|
65
|
+
results.setMissing(deepKey, errMsg);
|
|
65
66
|
return results;
|
|
66
67
|
}
|
|
67
68
|
const typeCheck = checkType(key, data[key], reqs, deepKey);
|
|
@@ -82,16 +83,21 @@ export function handleKey(input) {
|
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
85
|
if (missedCheck.length)
|
|
85
|
-
results.
|
|
86
|
+
results.setMissing(deepKey);
|
|
86
87
|
const isPassed = (!typeChecked.length && !rulesChecked.length && !missedCheck.length);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
if (!isPassed) {
|
|
89
|
+
results.setFailed(deepKey);
|
|
90
|
+
results.errorsByKeys[deepKey] = [
|
|
91
|
+
...results.errors
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
results.setPassed(deepKey);
|
|
96
|
+
}
|
|
91
97
|
return results.finish();
|
|
92
98
|
}
|
|
93
99
|
function validate(schema, data, keysToCheck) {
|
|
94
|
-
const
|
|
100
|
+
const output = new ValidnoResult();
|
|
95
101
|
const hasKeysToCheck = _helpers.areKeysLimited(keysToCheck);
|
|
96
102
|
const schemaKeys = Object.entries(schema.schema);
|
|
97
103
|
for (const [key, reqs] of schemaKeys) {
|
|
@@ -99,10 +105,10 @@ function validate(schema, data, keysToCheck) {
|
|
|
99
105
|
if (!toBeValidated)
|
|
100
106
|
continue;
|
|
101
107
|
const keyResult = handleKey.call(this, { key, data, reqs });
|
|
102
|
-
|
|
108
|
+
output.merge(keyResult);
|
|
103
109
|
}
|
|
104
|
-
|
|
105
|
-
return
|
|
110
|
+
output.finish();
|
|
111
|
+
return output;
|
|
106
112
|
}
|
|
107
113
|
;
|
|
108
114
|
export default validate;
|
package/package.json
CHANGED
package/.eslintrc.cjs
DELETED
package/.eslintrc.json
DELETED
package/jest.config.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
-
* https://jestjs.io/docs/configuration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {Config} from 'jest';
|
|
7
|
-
|
|
8
|
-
const config: Config = {
|
|
9
|
-
// All imported modules in your tests should be mocked automatically
|
|
10
|
-
// automock: false,
|
|
11
|
-
|
|
12
|
-
// Stop running tests after `n` failures
|
|
13
|
-
// bail: 0,
|
|
14
|
-
|
|
15
|
-
// The directory where Jest should store its cached dependency information
|
|
16
|
-
// cacheDirectory: "C:\\Users\\lesha\\AppData\\Local\\Temp\\jest",
|
|
17
|
-
|
|
18
|
-
// Automatically clear mock calls, instances, contexts and results before every test
|
|
19
|
-
clearMocks: true,
|
|
20
|
-
|
|
21
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
22
|
-
collectCoverage: false,
|
|
23
|
-
|
|
24
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
25
|
-
// collectCoverageFrom: undefined,
|
|
26
|
-
|
|
27
|
-
// The directory where Jest should output its coverage files
|
|
28
|
-
coverageDirectory: "coverage",
|
|
29
|
-
|
|
30
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
31
|
-
// coveragePathIgnorePatterns: [
|
|
32
|
-
// "\\\\node_modules\\\\"
|
|
33
|
-
// ],
|
|
34
|
-
|
|
35
|
-
// Indicates which provider should be used to instrument code for coverage
|
|
36
|
-
coverageProvider: "v8",
|
|
37
|
-
|
|
38
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
39
|
-
// coverageReporters: [
|
|
40
|
-
// "json",
|
|
41
|
-
// "text",
|
|
42
|
-
// "lcov",
|
|
43
|
-
// "clover"
|
|
44
|
-
// ],
|
|
45
|
-
|
|
46
|
-
// An object that configures minimum threshold enforcement for coverage results
|
|
47
|
-
// coverageThreshold: undefined,
|
|
48
|
-
|
|
49
|
-
// A path to a custom dependency extractor
|
|
50
|
-
// dependencyExtractor: undefined,
|
|
51
|
-
|
|
52
|
-
// Make calling deprecated APIs throw helpful error messages
|
|
53
|
-
// errorOnDeprecated: false,
|
|
54
|
-
|
|
55
|
-
// The default configuration for fake timers
|
|
56
|
-
// fakeTimers: {
|
|
57
|
-
// "enableGlobally": false
|
|
58
|
-
// },
|
|
59
|
-
|
|
60
|
-
// Force coverage collection from ignored files using an array of glob patterns
|
|
61
|
-
// forceCoverageMatch: [],
|
|
62
|
-
|
|
63
|
-
// A path to a module which exports an async function that is triggered once before all test suites
|
|
64
|
-
// globalSetup: undefined,
|
|
65
|
-
|
|
66
|
-
// A path to a module which exports an async function that is triggered once after all test suites
|
|
67
|
-
// globalTeardown: undefined,
|
|
68
|
-
|
|
69
|
-
// A set of global variables that need to be available in all test environments
|
|
70
|
-
// globals: {},
|
|
71
|
-
|
|
72
|
-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
73
|
-
// maxWorkers: "50%",
|
|
74
|
-
|
|
75
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
76
|
-
// moduleDirectories: [
|
|
77
|
-
// "node_modules"
|
|
78
|
-
// ],
|
|
79
|
-
|
|
80
|
-
// An array of file extensions your modules use
|
|
81
|
-
// moduleFileExtensions: [
|
|
82
|
-
// "js",
|
|
83
|
-
// "mjs",
|
|
84
|
-
// "cjs",
|
|
85
|
-
// "jsx",
|
|
86
|
-
// "ts",
|
|
87
|
-
// "tsx",
|
|
88
|
-
// "json",
|
|
89
|
-
// "node"
|
|
90
|
-
// ],
|
|
91
|
-
|
|
92
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
93
|
-
// moduleNameMapper: {},
|
|
94
|
-
|
|
95
|
-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
96
|
-
// modulePathIgnorePatterns: [],
|
|
97
|
-
|
|
98
|
-
// Activates notifications for test results
|
|
99
|
-
// notify: false,
|
|
100
|
-
|
|
101
|
-
// An enum that specifies notification mode. Requires { notify: true }
|
|
102
|
-
// notifyMode: "failure-change",
|
|
103
|
-
|
|
104
|
-
// A preset that is used as a base for Jest's configuration
|
|
105
|
-
// preset: undefined,
|
|
106
|
-
|
|
107
|
-
// Run tests from one or more projects
|
|
108
|
-
// projects: undefined,
|
|
109
|
-
|
|
110
|
-
// Use this configuration option to add custom reporters to Jest
|
|
111
|
-
// reporters: undefined,
|
|
112
|
-
|
|
113
|
-
// Automatically reset mock state before every test
|
|
114
|
-
// resetMocks: false,
|
|
115
|
-
|
|
116
|
-
// Reset the module registry before running each individual test
|
|
117
|
-
// resetModules: false,
|
|
118
|
-
|
|
119
|
-
// A path to a custom resolver
|
|
120
|
-
// resolver: undefined,
|
|
121
|
-
|
|
122
|
-
// Automatically restore mock state and implementation before every test
|
|
123
|
-
// restoreMocks: false,
|
|
124
|
-
|
|
125
|
-
// The root directory that Jest should scan for tests and modules within
|
|
126
|
-
// rootDir: undefined,
|
|
127
|
-
|
|
128
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
129
|
-
// roots: [
|
|
130
|
-
// "<rootDir>"
|
|
131
|
-
// ],
|
|
132
|
-
|
|
133
|
-
// Allows you to use a custom runner instead of Jest's default test runner
|
|
134
|
-
// runner: "jest-runner",
|
|
135
|
-
|
|
136
|
-
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
137
|
-
// setupFiles: [],
|
|
138
|
-
|
|
139
|
-
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
140
|
-
// setupFilesAfterEnv: [],
|
|
141
|
-
|
|
142
|
-
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
143
|
-
// slowTestThreshold: 5,
|
|
144
|
-
|
|
145
|
-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
146
|
-
// snapshotSerializers: [],
|
|
147
|
-
|
|
148
|
-
// The test environment that will be used for testing
|
|
149
|
-
// testEnvironment: "jest-environment-node",
|
|
150
|
-
|
|
151
|
-
// Options that will be passed to the testEnvironment
|
|
152
|
-
// testEnvironmentOptions: {},
|
|
153
|
-
|
|
154
|
-
// Adds a location field to test results
|
|
155
|
-
// testLocationInResults: false,
|
|
156
|
-
|
|
157
|
-
// The glob patterns Jest uses to detect test files
|
|
158
|
-
// testMatch: [
|
|
159
|
-
// "**/__tests__/**/*.[jt]s?(x)",
|
|
160
|
-
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
161
|
-
// ],
|
|
162
|
-
|
|
163
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
164
|
-
// testPathIgnorePatterns: [
|
|
165
|
-
// "\\\\node_modules\\\\"
|
|
166
|
-
// ],
|
|
167
|
-
|
|
168
|
-
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
169
|
-
// testRegex: [],
|
|
170
|
-
|
|
171
|
-
// This option allows the use of a custom results processor
|
|
172
|
-
// testResultsProcessor: undefined,
|
|
173
|
-
|
|
174
|
-
// This option allows use of a custom test runner
|
|
175
|
-
// testRunner: "jest-circus/runner",
|
|
176
|
-
|
|
177
|
-
// A map from regular expressions to paths to transformers
|
|
178
|
-
// transform: undefined,
|
|
179
|
-
|
|
180
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
181
|
-
// transformIgnorePatterns: [
|
|
182
|
-
// "\\\\node_modules\\\\",
|
|
183
|
-
// "\\.pnp\\.[^\\\\]+$"
|
|
184
|
-
// ],
|
|
185
|
-
|
|
186
|
-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
187
|
-
// unmockedModulePathPatterns: undefined,
|
|
188
|
-
|
|
189
|
-
// Indicates whether each individual test should be reported during the run
|
|
190
|
-
// verbose: undefined,
|
|
191
|
-
|
|
192
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
193
|
-
// watchPathIgnorePatterns: [],
|
|
194
|
-
|
|
195
|
-
// Whether to use watchman for file crawling
|
|
196
|
-
// watchman: true,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export default config;
|