validno 0.4.0 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/details.d.ts +3 -2
- package/dist/constants/details.d.ts.map +1 -1
- package/dist/constants/details.js +2 -1
- package/dist/dev.js +74 -52
- package/dist/engine/methods/handleNestedKey.js +1 -1
- package/dist/engine/methods/validate.d.ts.map +1 -1
- package/dist/engine/methods/validate.js +7 -0
- package/dist/engine/methods/validateType.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/ValidnoResult.js +0 -102
- package/dist/checkType.js +0 -1
- package/dist/validate/index.js +0 -1
- package/dist/validate/validate.js +0 -151
- package/dist/validate.js +0 -151
- package/dist/validateEngine/ValidateEngine.js +0 -44
- package/dist/validateEngine/index.js +0 -2
- package/dist/validateEngine/methods/ValidateEngine.js +0 -139
- package/dist/validateEngine/methods/checkRulesForKey.js +0 -15
- package/dist/validateEngine/methods/checkValueType.js +0 -134
- package/dist/validateEngine/methods/finalizeValidation.js +0 -15
- package/dist/validateEngine/methods/finishValidation.js +0 -15
- package/dist/validateEngine/methods/handleKey.js +0 -43
- package/dist/validateEngine/methods/handleMissingKey.js +0 -19
- package/dist/validateEngine/methods/handleMissingKeyValidation.js +0 -9
- package/dist/validateEngine/methods/handleNestedKey.js +0 -19
- package/dist/validateEngine/methods/validate.js +0 -14
- package/dist/validateEngine/methods/validateKey.js +0 -31
- package/dist/validateEngine/methods/validateKeyDetails.js +0 -13
- package/dist/validateEngine/methods/validateKeyValue.js +0 -13
- package/dist/validateEngine/methods/validateNestedKey.js +0 -19
- package/dist/validateEngine/methods/validateType.js +0 -134
- package/dist/validateEngine/validate.js +0 -14
- package/dist/validateRules.js +0 -159
- package/dist/validateSchema/ValidateEngine.js +0 -147
- package/dist/validateSchema/index.js +0 -6
- package/dist/validateSchema/validate.js +0 -151
- package/dist/validateSchema.js +0 -6
- package/dist/validateType.js +0 -124
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import ValidnoResult from "../ValidnoResult.js";
|
|
2
|
-
import validate from "./methods/validate.js";
|
|
3
|
-
import handleMissingKey from "./methods/handleMissingKey.js";
|
|
4
|
-
import handleNestedKey from "./methods/handleNestedKey.js";
|
|
5
|
-
import handleKey from "./methods/handleKey.js";
|
|
6
|
-
import handleMissingKeyValidation from "./methods/handleMissingKeyValidation.js";
|
|
7
|
-
import checkRulesForKey from "./methods/checkRulesForKey.js";
|
|
8
|
-
import finishValidation from "./methods/finishValidation.js";
|
|
9
|
-
import validateType from "./methods/validateType.js";
|
|
10
|
-
class ValidateEngine {
|
|
11
|
-
constructor(definition) {
|
|
12
|
-
this.definition = definition;
|
|
13
|
-
this.result = new ValidnoResult();
|
|
14
|
-
}
|
|
15
|
-
validate(data, validationKeys) {
|
|
16
|
-
return validate.call(this, data, validationKeys);
|
|
17
|
-
}
|
|
18
|
-
handleKey(input) {
|
|
19
|
-
return handleKey.call(this, input);
|
|
20
|
-
}
|
|
21
|
-
handleNestedKey(input) {
|
|
22
|
-
return handleNestedKey.call(this, input);
|
|
23
|
-
}
|
|
24
|
-
handleMissingKey(schema, input) {
|
|
25
|
-
return handleMissingKey(schema, input);
|
|
26
|
-
}
|
|
27
|
-
handleMissingNestedKey(nestedKey, results) {
|
|
28
|
-
results.setMissing(nestedKey);
|
|
29
|
-
return results;
|
|
30
|
-
}
|
|
31
|
-
handleMissingKeyValidation(params) {
|
|
32
|
-
return handleMissingKeyValidation.call(this, params);
|
|
33
|
-
}
|
|
34
|
-
validateType(input) {
|
|
35
|
-
return validateType(input);
|
|
36
|
-
}
|
|
37
|
-
checkRulesForKey(input) {
|
|
38
|
-
return checkRulesForKey.call(this, input);
|
|
39
|
-
}
|
|
40
|
-
finishValidation(checks) {
|
|
41
|
-
return finishValidation(checks);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export default ValidateEngine;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import validateType from "../../validateType.js";
|
|
2
|
-
import validateRules from "../../validateRules.js";
|
|
3
|
-
import { ValidationIds } from "../../constants/details.js";
|
|
4
|
-
import ValidnoResult from "../../ValidnoResult.js";
|
|
5
|
-
import _errors from "../../utils/errors.js";
|
|
6
|
-
import _helpers from "../../utils/helpers.js";
|
|
7
|
-
import validate from "../validate.js";
|
|
8
|
-
class ValidateEngine {
|
|
9
|
-
constructor(definition) {
|
|
10
|
-
this.definition = definition;
|
|
11
|
-
this.result = new ValidnoResult();
|
|
12
|
-
}
|
|
13
|
-
validate(data, validationKeys) {
|
|
14
|
-
return validate.call(this, data, validationKeys);
|
|
15
|
-
}
|
|
16
|
-
handleMissingKey(schema, input) {
|
|
17
|
-
const { key, nestedKey, data, reqs } = input;
|
|
18
|
-
const messageKey = nestedKey || key;
|
|
19
|
-
const messageTitle = reqs.title || messageKey;
|
|
20
|
-
if (!reqs.customMessage) {
|
|
21
|
-
return _errors.getMissingError(messageKey);
|
|
22
|
-
}
|
|
23
|
-
const errorMessage = reqs.customMessage({
|
|
24
|
-
keyword: ValidationIds.Missing,
|
|
25
|
-
value: data[key],
|
|
26
|
-
key: messageKey,
|
|
27
|
-
title: messageTitle,
|
|
28
|
-
reqs,
|
|
29
|
-
schema,
|
|
30
|
-
});
|
|
31
|
-
return errorMessage;
|
|
32
|
-
}
|
|
33
|
-
validateNestedKey(input) {
|
|
34
|
-
const { results, key, nestedKey, data, reqs } = input;
|
|
35
|
-
const nestedKeys = Object.keys(reqs);
|
|
36
|
-
const nestedResults = [];
|
|
37
|
-
for (const itemKey of nestedKeys) {
|
|
38
|
-
const deepParams = {
|
|
39
|
-
key: itemKey,
|
|
40
|
-
data: data[key],
|
|
41
|
-
reqs: reqs[itemKey],
|
|
42
|
-
nestedKey: `${nestedKey}.${itemKey}`
|
|
43
|
-
};
|
|
44
|
-
const deepResults = this.validateKey(deepParams);
|
|
45
|
-
nestedResults.push(deepResults.ok);
|
|
46
|
-
results.merge(deepResults);
|
|
47
|
-
}
|
|
48
|
-
results.fixParentByChilds(nestedKey, nestedResults);
|
|
49
|
-
return results;
|
|
50
|
-
}
|
|
51
|
-
validateKey(input) {
|
|
52
|
-
let { results, key, nestedKey, data, reqs } = input;
|
|
53
|
-
if (data === undefined) {
|
|
54
|
-
const noDataResult = new ValidnoResult();
|
|
55
|
-
noDataResult.setNoData();
|
|
56
|
-
noDataResult.finish();
|
|
57
|
-
return noDataResult;
|
|
58
|
-
}
|
|
59
|
-
if (!results)
|
|
60
|
-
results = new ValidnoResult();
|
|
61
|
-
if (!nestedKey)
|
|
62
|
-
nestedKey = key;
|
|
63
|
-
const hasMissing = _helpers.hasMissing(input);
|
|
64
|
-
if (_helpers.checkNestedIsMissing(reqs, data)) {
|
|
65
|
-
return this.handleMissingNestedKey(results, nestedKey);
|
|
66
|
-
}
|
|
67
|
-
if (_helpers.checkIsNested(reqs)) {
|
|
68
|
-
return this.validateNestedKey({ results, key, data, reqs, nestedKey });
|
|
69
|
-
}
|
|
70
|
-
return this.validateKeyDetails({
|
|
71
|
-
results,
|
|
72
|
-
key,
|
|
73
|
-
nestedKey,
|
|
74
|
-
data,
|
|
75
|
-
reqs,
|
|
76
|
-
hasMissing,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
handleMissingNestedKey(results, nestedKey) {
|
|
80
|
-
results.setMissing(nestedKey);
|
|
81
|
-
return results;
|
|
82
|
-
}
|
|
83
|
-
validateKeyDetails(params) {
|
|
84
|
-
const { results, key, nestedKey, data, reqs, hasMissing } = params;
|
|
85
|
-
const missedCheck = [];
|
|
86
|
-
const typeChecked = [];
|
|
87
|
-
const rulesChecked = [];
|
|
88
|
-
if (hasMissing) {
|
|
89
|
-
return this.handleMissingKeyValidation({ results, key, nestedKey, data, reqs }, missedCheck);
|
|
90
|
-
}
|
|
91
|
-
this.checkValueType(results, key, data[key], reqs, nestedKey, typeChecked);
|
|
92
|
-
this.checkRulesForKey(results, nestedKey, data[key], reqs, data, rulesChecked);
|
|
93
|
-
return this.finalizeValidation({ results, nestedKey, missedCheck, typeChecked, rulesChecked });
|
|
94
|
-
}
|
|
95
|
-
handleMissingKeyValidation(params, missedCheck) {
|
|
96
|
-
const schema = this.definition;
|
|
97
|
-
const { results, key, nestedKey, data, reqs } = params;
|
|
98
|
-
const errMsg = this.handleMissingKey(schema, { key, nestedKey, data, reqs });
|
|
99
|
-
missedCheck.push(false);
|
|
100
|
-
results.setMissing(nestedKey, errMsg);
|
|
101
|
-
return results;
|
|
102
|
-
}
|
|
103
|
-
checkValueType(results, key, value, reqs, nestedKey, typeChecked) {
|
|
104
|
-
const typeCheck = validateType(key, value, reqs, nestedKey);
|
|
105
|
-
typeCheck.forEach((res) => {
|
|
106
|
-
if (!res.passed) {
|
|
107
|
-
typeChecked.push(false);
|
|
108
|
-
results.errors.push(res.details || '');
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
checkRulesForKey(results, nestedKey, value, reqs, data, rulesChecked) {
|
|
113
|
-
const ruleCheck = validateRules.call(this, nestedKey, value, reqs, data);
|
|
114
|
-
if (!ruleCheck.ok) {
|
|
115
|
-
rulesChecked.push(false);
|
|
116
|
-
ruleCheck.details.forEach((el) => {
|
|
117
|
-
if (!(nestedKey in results.errorsByKeys))
|
|
118
|
-
results.errorsByKeys[nestedKey] = [];
|
|
119
|
-
results.errors.push(el);
|
|
120
|
-
results.errorsByKeys[nestedKey] = ['1'];
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
finalizeValidation(checks) {
|
|
125
|
-
const { results, nestedKey, missedCheck, typeChecked, rulesChecked } = checks;
|
|
126
|
-
if (missedCheck.length)
|
|
127
|
-
results.setMissing(nestedKey);
|
|
128
|
-
const isPassed = !typeChecked.length && !rulesChecked.length && !missedCheck.length;
|
|
129
|
-
if (!isPassed) {
|
|
130
|
-
results.setFailed(nestedKey);
|
|
131
|
-
results.errorsByKeys[nestedKey] = [...results.errors];
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
results.setPassed(nestedKey);
|
|
135
|
-
}
|
|
136
|
-
return results.finish();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
export default ValidateEngine;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import validateRules from "../../validateRules.js";
|
|
2
|
-
function checkRulesForKey(input) {
|
|
3
|
-
const { results, nestedKey, value, reqs, data, rulesChecked } = input;
|
|
4
|
-
const ruleCheck = validateRules.call(this, nestedKey, value, reqs, data);
|
|
5
|
-
if (!ruleCheck.ok) {
|
|
6
|
-
rulesChecked.push(false);
|
|
7
|
-
ruleCheck.details.forEach((el) => {
|
|
8
|
-
if (!(nestedKey in results.errorsByKeys))
|
|
9
|
-
results.errorsByKeys[nestedKey] = [];
|
|
10
|
-
results.errors.push(el);
|
|
11
|
-
results.errorsByKeys[nestedKey] = ['1'];
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export default checkRulesForKey;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { ValidationDetails, ValidationIds } from "../../constants/details.js";
|
|
2
|
-
import _validations from "../../utils/validations.js";
|
|
3
|
-
import _errors from "../../utils/errors.js";
|
|
4
|
-
import _validateType from "../../utils/validateType.js";
|
|
5
|
-
const validateUnionType = (key, value, requirements, keyName = key) => {
|
|
6
|
-
const typeList = Array.isArray(requirements.type)
|
|
7
|
-
? requirements.type.map((el) => String((el === null || el === void 0 ? void 0 : el.name) || el))
|
|
8
|
-
: [];
|
|
9
|
-
const results = [];
|
|
10
|
-
for (let i = 0; i < typeList.length; i++) {
|
|
11
|
-
const requirementsRe = Object.assign(Object.assign({}, requirements), { type: requirements.type[i] });
|
|
12
|
-
const result = validateType(key, value, requirementsRe);
|
|
13
|
-
results.push(result[0].passed);
|
|
14
|
-
if (results[i] === true)
|
|
15
|
-
return _validateType.getResult(keyName, true);
|
|
16
|
-
}
|
|
17
|
-
const isPassed = results.some((r) => r === true);
|
|
18
|
-
const result = _validateType.getResult(keyName, isPassed, isPassed ? null : _errors.getErrorDetails(keyName, typeList.join('/'), value));
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
const validateType = (key, value, requirements, keyName = key) => {
|
|
22
|
-
var _a;
|
|
23
|
-
const isNotNull = value !== null;
|
|
24
|
-
const keyTitle = 'title' in requirements ? requirements.title : keyName;
|
|
25
|
-
const hasCustomMessage = requirements.customMessage && typeof requirements.customMessage === 'function';
|
|
26
|
-
if (value === undefined && requirements.required) {
|
|
27
|
-
return [_validateType.getResult(keyName, false, _errors.getMissingError(keyName))];
|
|
28
|
-
}
|
|
29
|
-
if (Array.isArray(requirements.type)) {
|
|
30
|
-
return [validateUnionType(key, value, requirements)];
|
|
31
|
-
}
|
|
32
|
-
if (value === undefined && requirements.required !== true) {
|
|
33
|
-
return [_validateType.getResult(keyName, true)];
|
|
34
|
-
}
|
|
35
|
-
const customErrDetails = hasCustomMessage ?
|
|
36
|
-
requirements.customMessage({
|
|
37
|
-
keyword: ValidationIds.Type,
|
|
38
|
-
value: value,
|
|
39
|
-
key: keyName,
|
|
40
|
-
title: keyTitle,
|
|
41
|
-
reqs: requirements,
|
|
42
|
-
schema: null
|
|
43
|
-
}) :
|
|
44
|
-
null;
|
|
45
|
-
const baseErrDetails = _errors.getErrorDetails(keyName, requirements.type, value);
|
|
46
|
-
const getDetails = (isOK, errorText) => isOK ?
|
|
47
|
-
ValidationDetails.OK :
|
|
48
|
-
errorText || customErrDetails || baseErrDetails;
|
|
49
|
-
const typeBySchema = requirements.type;
|
|
50
|
-
const result = [];
|
|
51
|
-
switch (typeBySchema) {
|
|
52
|
-
case 'any': {
|
|
53
|
-
result.push(_validateType.getResult(keyName, true, getDetails(true)));
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case Number: {
|
|
57
|
-
const isNumber = isNotNull && value.constructor === Number;
|
|
58
|
-
result.push(_validateType.getResult(keyName, isNumber, getDetails(isNumber)));
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
case String: {
|
|
62
|
-
const isString = isNotNull && value.constructor === String;
|
|
63
|
-
result.push(_validateType.getResult(keyName, isString, getDetails(isString)));
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case Date: {
|
|
67
|
-
const isDate = isNotNull && value.constructor === Date;
|
|
68
|
-
const isValid = isDate && !isNaN(value.getTime());
|
|
69
|
-
const isValidDate = isDate && isValid;
|
|
70
|
-
result.push(_validateType.getResult(keyName, isValidDate, getDetails(isValidDate, ValidationDetails.INVALID_DATE)));
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case Boolean: {
|
|
74
|
-
const isBoolean = isNotNull && value.constructor === Boolean;
|
|
75
|
-
result.push(_validateType.getResult(keyName, isBoolean, getDetails(isBoolean)));
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case Array: {
|
|
79
|
-
const isArray = isNotNull && value.constructor === Array;
|
|
80
|
-
if (!isArray) {
|
|
81
|
-
result.push(_validateType.getResult(keyName, false, getDetails(isArray)));
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
let isEachChecked = { passed: true, details: "" };
|
|
85
|
-
if ('eachType' in requirements) {
|
|
86
|
-
for (const el of value) {
|
|
87
|
-
const result = validateType('each of ' + key, el, { type: requirements.eachType, required: true });
|
|
88
|
-
if (!result[0].passed) {
|
|
89
|
-
isEachChecked.passed = false;
|
|
90
|
-
isEachChecked.details = result[0].details || '';
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const isOk = isArray && isEachChecked.passed;
|
|
96
|
-
const details = !isEachChecked.passed ? isEachChecked.details : getDetails(isOk);
|
|
97
|
-
result.push(_validateType.getResult(keyName, isOk, details));
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
case Object: {
|
|
101
|
-
const isObject = _validations.isObject(value) && value.constructor === Object;
|
|
102
|
-
result.push(_validateType.getResult(keyName, isObject, getDetails(isObject)));
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
case RegExp: {
|
|
106
|
-
const isRegex = _validations.isRegex(value);
|
|
107
|
-
result.push(_validateType.getResult(keyName, isRegex, getDetails(isRegex)));
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
case null: {
|
|
111
|
-
const isNull = value === null;
|
|
112
|
-
result.push(_validateType.getResult(keyName, isNull, getDetails(isNull)));
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
default: {
|
|
116
|
-
const isInstanceOf = typeof typeBySchema === 'function' && value instanceof typeBySchema;
|
|
117
|
-
const isConstructorSame = typeof typeBySchema === 'function' && ((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.name) === (typeBySchema === null || typeBySchema === void 0 ? void 0 : typeBySchema.name);
|
|
118
|
-
const isOK = isInstanceOf && isConstructorSame;
|
|
119
|
-
result.push(_validateType.getResult(keyName, isOK, getDetails(isOK)));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
};
|
|
124
|
-
function checkValueType(input) {
|
|
125
|
-
const { results, key, value, reqs, nestedKey, typeChecked } = input;
|
|
126
|
-
const typeCheck = validateType(key, value, reqs, nestedKey);
|
|
127
|
-
typeCheck.forEach((res) => {
|
|
128
|
-
if (!res.passed) {
|
|
129
|
-
typeChecked.push(false);
|
|
130
|
-
results.errors.push(res.details || '');
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
export default checkValueType;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
function finalizeValidation(checks) {
|
|
2
|
-
const { results, nestedKey, missedCheck, typeChecked, rulesChecked } = checks;
|
|
3
|
-
if (missedCheck.length)
|
|
4
|
-
results.setMissing(nestedKey);
|
|
5
|
-
const isPassed = !typeChecked.length && !rulesChecked.length && !missedCheck.length;
|
|
6
|
-
if (!isPassed) {
|
|
7
|
-
results.setFailed(nestedKey);
|
|
8
|
-
results.errorsByKeys[nestedKey] = [...results.errors];
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
results.setPassed(nestedKey);
|
|
12
|
-
}
|
|
13
|
-
return results.finish();
|
|
14
|
-
}
|
|
15
|
-
export default finalizeValidation;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
function finishValidation(checks) {
|
|
2
|
-
const { results, nestedKey, missedCheck, typeChecked, rulesChecked } = checks;
|
|
3
|
-
if (missedCheck.length)
|
|
4
|
-
results.setMissing(nestedKey);
|
|
5
|
-
const isPassed = !typeChecked.length && !rulesChecked.length && !missedCheck.length;
|
|
6
|
-
if (!isPassed) {
|
|
7
|
-
results.setFailed(nestedKey);
|
|
8
|
-
results.errorsByKeys[nestedKey] = [...results.errors];
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
results.setPassed(nestedKey);
|
|
12
|
-
}
|
|
13
|
-
return results.finish();
|
|
14
|
-
}
|
|
15
|
-
export default finishValidation;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import _helpers from "../../utils/helpers.js";
|
|
2
|
-
import ValidnoResult from "../../ValidnoResult.js";
|
|
3
|
-
function validateKeyValue(params) {
|
|
4
|
-
const { results, key, nestedKey, data, reqs, hasMissing } = params;
|
|
5
|
-
const missedCheck = [];
|
|
6
|
-
const typeChecked = [];
|
|
7
|
-
const rulesChecked = [];
|
|
8
|
-
if (hasMissing) {
|
|
9
|
-
return this.handleMissingKeyValidation({ results, key, nestedKey, data, reqs, missedCheck });
|
|
10
|
-
}
|
|
11
|
-
this.validateType({ results, key, value: data[key], reqs, nestedKey, typeChecked });
|
|
12
|
-
this.checkRulesForKey({ results, nestedKey, value: data[key], reqs, data, rulesChecked });
|
|
13
|
-
return this.finishValidation({ results, nestedKey, missedCheck, typeChecked, rulesChecked });
|
|
14
|
-
}
|
|
15
|
-
function validateKey(input) {
|
|
16
|
-
let { results, key, nestedKey, data, reqs } = input;
|
|
17
|
-
if (data === undefined) {
|
|
18
|
-
const noDataResult = new ValidnoResult();
|
|
19
|
-
noDataResult.setNoData();
|
|
20
|
-
noDataResult.finish();
|
|
21
|
-
return noDataResult;
|
|
22
|
-
}
|
|
23
|
-
if (!results)
|
|
24
|
-
results = new ValidnoResult();
|
|
25
|
-
if (!nestedKey)
|
|
26
|
-
nestedKey = key;
|
|
27
|
-
const hasMissing = _helpers.hasMissing(input);
|
|
28
|
-
if (_helpers.checkNestedIsMissing(reqs, data)) {
|
|
29
|
-
return this.handleMissingNestedKey(nestedKey, results);
|
|
30
|
-
}
|
|
31
|
-
if (_helpers.checkIsNested(reqs)) {
|
|
32
|
-
return this.handleNestedKey({ results, key, data, reqs, nestedKey });
|
|
33
|
-
}
|
|
34
|
-
return validateKeyValue.call(this, {
|
|
35
|
-
results,
|
|
36
|
-
key,
|
|
37
|
-
nestedKey,
|
|
38
|
-
data,
|
|
39
|
-
reqs,
|
|
40
|
-
hasMissing,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
export default validateKey;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ValidationIds } from "../../constants/details.js";
|
|
2
|
-
import _errors from "../../utils/errors.js";
|
|
3
|
-
function handleMissingKey(schema, input) {
|
|
4
|
-
const { key, nestedKey, data, reqs } = input;
|
|
5
|
-
const messageKey = nestedKey || key;
|
|
6
|
-
const messageTitle = reqs.title || messageKey;
|
|
7
|
-
if (!reqs.customMessage)
|
|
8
|
-
return _errors.getMissingError(messageKey);
|
|
9
|
-
const errorMessage = reqs.customMessage({
|
|
10
|
-
keyword: ValidationIds.Missing,
|
|
11
|
-
value: data[key],
|
|
12
|
-
key: messageKey,
|
|
13
|
-
title: messageTitle,
|
|
14
|
-
reqs,
|
|
15
|
-
schema,
|
|
16
|
-
});
|
|
17
|
-
return errorMessage;
|
|
18
|
-
}
|
|
19
|
-
export default handleMissingKey;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
function handleMissingKeyValidation(params) {
|
|
2
|
-
const schema = this.definition;
|
|
3
|
-
const { results, key, nestedKey, data, reqs, missedCheck } = params;
|
|
4
|
-
const errMsg = this.handleMissingKey(schema, { key, nestedKey, data, reqs });
|
|
5
|
-
missedCheck.push(false);
|
|
6
|
-
results.setMissing(nestedKey, errMsg);
|
|
7
|
-
return results;
|
|
8
|
-
}
|
|
9
|
-
export default handleMissingKeyValidation;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
function handleNestedKey(input) {
|
|
2
|
-
const { results, key, nestedKey, data, reqs } = input;
|
|
3
|
-
const nestedKeys = Object.keys(reqs);
|
|
4
|
-
const nestedResults = [];
|
|
5
|
-
for (const itemKey of nestedKeys) {
|
|
6
|
-
const deepParams = {
|
|
7
|
-
key: itemKey,
|
|
8
|
-
data: data[key],
|
|
9
|
-
reqs: reqs[itemKey],
|
|
10
|
-
nestedKey: `${nestedKey}.${itemKey}`
|
|
11
|
-
};
|
|
12
|
-
const deepResults = this.handleKey(deepParams);
|
|
13
|
-
nestedResults.push(deepResults.ok);
|
|
14
|
-
results.merge(deepResults);
|
|
15
|
-
}
|
|
16
|
-
results.fixParentByChilds(nestedKey, nestedResults);
|
|
17
|
-
return results;
|
|
18
|
-
}
|
|
19
|
-
export default handleNestedKey;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import _helpers from "../../utils/helpers.js";
|
|
2
|
-
function validate(data, validationKeys) {
|
|
3
|
-
const hasKeysToCheck = _helpers.areKeysLimited(validationKeys);
|
|
4
|
-
const schemaKeys = Object.entries(this.definition);
|
|
5
|
-
for (const [key, reqs] of schemaKeys) {
|
|
6
|
-
const toBeValidated = _helpers.needValidation(key, hasKeysToCheck, validationKeys);
|
|
7
|
-
if (!toBeValidated)
|
|
8
|
-
continue;
|
|
9
|
-
const keyResult = this.handleKey({ key, data, reqs });
|
|
10
|
-
this.result.merge(keyResult);
|
|
11
|
-
}
|
|
12
|
-
return this.result.finish();
|
|
13
|
-
}
|
|
14
|
-
export default validate;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import _helpers from "../../utils/helpers.js";
|
|
2
|
-
import ValidnoResult from "../../ValidnoResult.js";
|
|
3
|
-
function validateKey(input) {
|
|
4
|
-
let { results, key, nestedKey, data, reqs } = input;
|
|
5
|
-
if (data === undefined) {
|
|
6
|
-
const noDataResult = new ValidnoResult();
|
|
7
|
-
noDataResult.setNoData();
|
|
8
|
-
noDataResult.finish();
|
|
9
|
-
return noDataResult;
|
|
10
|
-
}
|
|
11
|
-
if (!results)
|
|
12
|
-
results = new ValidnoResult();
|
|
13
|
-
if (!nestedKey)
|
|
14
|
-
nestedKey = key;
|
|
15
|
-
const hasMissing = _helpers.hasMissing(input);
|
|
16
|
-
if (_helpers.checkNestedIsMissing(reqs, data)) {
|
|
17
|
-
return this.handleMissingNestedKey(nestedKey, results);
|
|
18
|
-
}
|
|
19
|
-
if (_helpers.checkIsNested(reqs)) {
|
|
20
|
-
return this.validateNestedKey({ results, key, data, reqs, nestedKey });
|
|
21
|
-
}
|
|
22
|
-
return this.validateKeyDetails({
|
|
23
|
-
results,
|
|
24
|
-
key,
|
|
25
|
-
nestedKey,
|
|
26
|
-
data,
|
|
27
|
-
reqs,
|
|
28
|
-
hasMissing,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
export default validateKey;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
function validateKeyDetails(params) {
|
|
2
|
-
const { results, key, nestedKey, data, reqs, hasMissing } = params;
|
|
3
|
-
const missedCheck = [];
|
|
4
|
-
const typeChecked = [];
|
|
5
|
-
const rulesChecked = [];
|
|
6
|
-
if (hasMissing) {
|
|
7
|
-
return this.handleMissingKeyValidation({ results, key, nestedKey, data, reqs, missedCheck });
|
|
8
|
-
}
|
|
9
|
-
this.checkValueType({ results, key, value: data[key], reqs, nestedKey, typeChecked });
|
|
10
|
-
this.checkRulesForKey({ results, nestedKey, value: data[key], reqs, data, rulesChecked });
|
|
11
|
-
return this.finalizeValidation({ results, nestedKey, missedCheck, typeChecked, rulesChecked });
|
|
12
|
-
}
|
|
13
|
-
export default validateKeyDetails;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
function validateKeyValue(params) {
|
|
2
|
-
const { results, key, nestedKey, data, reqs, hasMissing } = params;
|
|
3
|
-
const missedCheck = [];
|
|
4
|
-
const typeChecked = [];
|
|
5
|
-
const rulesChecked = [];
|
|
6
|
-
if (hasMissing) {
|
|
7
|
-
return this.handleMissingKeyValidation({ results, key, nestedKey, data, reqs, missedCheck });
|
|
8
|
-
}
|
|
9
|
-
this.checkValueType({ results, key, value: data[key], reqs, nestedKey, typeChecked });
|
|
10
|
-
this.checkRulesForKey({ results, nestedKey, value: data[key], reqs, data, rulesChecked });
|
|
11
|
-
return this.finalizeValidation({ results, nestedKey, missedCheck, typeChecked, rulesChecked });
|
|
12
|
-
}
|
|
13
|
-
export default validateKeyValue;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
function validateNestedKey(input) {
|
|
2
|
-
const { results, key, nestedKey, data, reqs } = input;
|
|
3
|
-
const nestedKeys = Object.keys(reqs);
|
|
4
|
-
const nestedResults = [];
|
|
5
|
-
for (const itemKey of nestedKeys) {
|
|
6
|
-
const deepParams = {
|
|
7
|
-
key: itemKey,
|
|
8
|
-
data: data[key],
|
|
9
|
-
reqs: reqs[itemKey],
|
|
10
|
-
nestedKey: `${nestedKey}.${itemKey}`
|
|
11
|
-
};
|
|
12
|
-
const deepResults = this.handleKey(deepParams);
|
|
13
|
-
nestedResults.push(deepResults.ok);
|
|
14
|
-
results.merge(deepResults);
|
|
15
|
-
}
|
|
16
|
-
results.fixParentByChilds(nestedKey, nestedResults);
|
|
17
|
-
return results;
|
|
18
|
-
}
|
|
19
|
-
export default validateNestedKey;
|