@wabot-dev/framework 0.2.0-beta.5 → 0.2.0-beta.6
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.
|
@@ -7,16 +7,20 @@ function validateModel(value, info) {
|
|
|
7
7
|
for (const propertyName in info.properties) {
|
|
8
8
|
const propertyInfo = info.properties[propertyName];
|
|
9
9
|
const propertyValidators = propertyInfo.validators ?? [];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(resultValue), propertyName);
|
|
11
|
+
const hasSetterOrWritable = !descriptor || descriptor.set || descriptor.writable;
|
|
12
|
+
const originalValue = value[propertyName];
|
|
13
|
+
if (propertyInfo.isOptional && originalValue == null) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
let currentValue = originalValue;
|
|
13
17
|
if (resultValue[propertyName] == null && propertyInfo.isOptional) {
|
|
14
18
|
resultValue[propertyName] = undefined;
|
|
15
19
|
continue;
|
|
16
20
|
}
|
|
17
21
|
for (let propertyValidatorInfo of propertyValidators) {
|
|
18
|
-
const propertyValidatorResult = propertyValidatorInfo.validator(
|
|
19
|
-
|
|
22
|
+
const propertyValidatorResult = propertyValidatorInfo.validator(currentValue, propertyValidatorInfo.validatorOptions);
|
|
23
|
+
currentValue = propertyValidatorResult.value;
|
|
20
24
|
if (propertyValidatorResult.error) {
|
|
21
25
|
let propertyErrors = propertiesErrors[propertyName];
|
|
22
26
|
if (!propertyErrors) {
|
|
@@ -26,6 +30,9 @@ function validateModel(value, info) {
|
|
|
26
30
|
propertyErrors.push(propertyValidatorResult.error.description);
|
|
27
31
|
}
|
|
28
32
|
}
|
|
33
|
+
if (hasSetterOrWritable) {
|
|
34
|
+
resultValue[propertyName] = currentValue;
|
|
35
|
+
}
|
|
29
36
|
}
|
|
30
37
|
if (Object.keys(propertiesErrors).length > 0) {
|
|
31
38
|
return { error: { description: 'Invalid properties', properties: propertiesErrors } };
|