@wabot-dev/framework 0.2.0-beta.6 → 0.2.0-beta.7
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.
|
@@ -4,23 +4,29 @@ function validateModel(value, info) {
|
|
|
4
4
|
}
|
|
5
5
|
let propertiesErrors = {};
|
|
6
6
|
let resultValue = new info.modelConstructor();
|
|
7
|
+
const properties = [];
|
|
8
|
+
const getters = [];
|
|
7
9
|
for (const propertyName in info.properties) {
|
|
8
|
-
const propertyInfo = info.properties[propertyName];
|
|
9
|
-
const propertyValidators = propertyInfo.validators ?? [];
|
|
10
10
|
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(resultValue), propertyName);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (propertyInfo.isOptional && originalValue == null) {
|
|
14
|
-
continue;
|
|
11
|
+
if (descriptor?.get) {
|
|
12
|
+
getters.push(propertyName);
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (!descriptor?.set && !descriptor?.get) {
|
|
15
|
+
properties.push(propertyName);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
for (const propertyName of properties) {
|
|
19
|
+
const propertyInfo = info.properties[propertyName];
|
|
20
|
+
const propertyValidators = propertyInfo.validators ?? [];
|
|
21
|
+
let currentPropValue = propertyInfo.isOptional
|
|
22
|
+
? (value[propertyName] ?? resultValue[propertyName])
|
|
23
|
+
: value[propertyName];
|
|
24
|
+
if (currentPropValue == null && propertyInfo.isOptional) {
|
|
18
25
|
resultValue[propertyName] = undefined;
|
|
19
26
|
continue;
|
|
20
27
|
}
|
|
21
28
|
for (let propertyValidatorInfo of propertyValidators) {
|
|
22
|
-
const propertyValidatorResult = propertyValidatorInfo.validator(
|
|
23
|
-
currentValue = propertyValidatorResult.value;
|
|
29
|
+
const propertyValidatorResult = propertyValidatorInfo.validator(currentPropValue, propertyValidatorInfo.validatorOptions);
|
|
24
30
|
if (propertyValidatorResult.error) {
|
|
25
31
|
let propertyErrors = propertiesErrors[propertyName];
|
|
26
32
|
if (!propertyErrors) {
|
|
@@ -29,9 +35,29 @@ function validateModel(value, info) {
|
|
|
29
35
|
}
|
|
30
36
|
propertyErrors.push(propertyValidatorResult.error.description);
|
|
31
37
|
}
|
|
38
|
+
else {
|
|
39
|
+
currentPropValue = propertyValidatorResult.value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
resultValue[propertyName] = currentPropValue;
|
|
43
|
+
}
|
|
44
|
+
for (const propertyName of getters) {
|
|
45
|
+
const propertyInfo = info.properties[propertyName];
|
|
46
|
+
const propertyValidators = propertyInfo.validators ?? [];
|
|
47
|
+
let propValue = resultValue[propertyName];
|
|
48
|
+
if (propValue == null && propertyInfo.isOptional) {
|
|
49
|
+
continue;
|
|
32
50
|
}
|
|
33
|
-
|
|
34
|
-
|
|
51
|
+
for (let propertyValidatorInfo of propertyValidators) {
|
|
52
|
+
const propertyValidatorResult = propertyValidatorInfo.validator(propValue, propertyValidatorInfo.validatorOptions);
|
|
53
|
+
if (propertyValidatorResult.error) {
|
|
54
|
+
let propertyErrors = propertiesErrors[propertyName];
|
|
55
|
+
if (!propertyErrors) {
|
|
56
|
+
propertyErrors = [];
|
|
57
|
+
propertiesErrors[propertyName] = propertyErrors;
|
|
58
|
+
}
|
|
59
|
+
propertyErrors.push(propertyValidatorResult.error.description);
|
|
60
|
+
}
|
|
35
61
|
}
|
|
36
62
|
}
|
|
37
63
|
if (Object.keys(propertiesErrors).length > 0) {
|