@vorplex/core 0.0.42 → 0.0.43
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.
|
@@ -58,15 +58,15 @@ export class TsonArray extends TsonSchemaBase {
|
|
|
58
58
|
return this.definition.default;
|
|
59
59
|
if (value != null && !Array.isArray(value))
|
|
60
60
|
throw new TsonError('Array expected', value, this);
|
|
61
|
-
|
|
62
|
-
if (this.definition.min != null &&
|
|
61
|
+
let result = [];
|
|
62
|
+
if (this.definition.min != null && value.length < this.definition.min)
|
|
63
63
|
throw new TsonError(`Array min length of ${this.definition.min} expected`, value, this);
|
|
64
|
-
if (this.definition.max != null &&
|
|
64
|
+
if (this.definition.max != null && value.length > this.definition.max)
|
|
65
65
|
throw new TsonError(`Array max length of ${this.definition.max} expected`, value, this);
|
|
66
66
|
if (this.definition.itemDefinition) {
|
|
67
|
-
for (const [index, item] of
|
|
67
|
+
for (const [index, item] of value.entries()) {
|
|
68
68
|
try {
|
|
69
|
-
|
|
69
|
+
result[index] = $Tson.parse(this.definition.itemDefinition).parse(item);
|
|
70
70
|
}
|
|
71
71
|
catch (error) {
|
|
72
72
|
if (!(error instanceof TsonError))
|
|
@@ -75,6 +75,6 @@ export class TsonArray extends TsonSchemaBase {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
return
|
|
78
|
+
return result;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -55,10 +55,11 @@ export class TsonObject extends TsonSchemaBase {
|
|
|
55
55
|
return this.definition.default;
|
|
56
56
|
if (value != null && typeof value !== 'object')
|
|
57
57
|
throw new TsonError('Object expected', value, this);
|
|
58
|
+
let result = {};
|
|
58
59
|
if (this.definition.property) {
|
|
59
60
|
for (const property in value) {
|
|
60
61
|
try {
|
|
61
|
-
|
|
62
|
+
result[property] = $Tson.parse(this.definition.property).parse(value[property]);
|
|
62
63
|
}
|
|
63
64
|
catch (error) {
|
|
64
65
|
if (error instanceof TsonError) {
|
|
@@ -71,7 +72,7 @@ export class TsonObject extends TsonSchemaBase {
|
|
|
71
72
|
if (this.definition.properties) {
|
|
72
73
|
for (const property in this.definition.properties) {
|
|
73
74
|
try {
|
|
74
|
-
|
|
75
|
+
result[property] = $Tson.parse(this.definition.properties[property]).parse(value[property]);
|
|
75
76
|
}
|
|
76
77
|
catch (error) {
|
|
77
78
|
if (error instanceof TsonError) {
|
|
@@ -82,7 +83,7 @@ export class TsonObject extends TsonSchemaBase {
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
if (this.definition.prototype)
|
|
85
|
-
|
|
86
|
-
return
|
|
86
|
+
Object.setPrototypeOf(result, this.definition.prototype);
|
|
87
|
+
return result;
|
|
87
88
|
}
|
|
88
89
|
}
|