1 |
|
2 |
|
3 |
|
4 | var ValidationError = (function () {
|
5 | function ValidationError() {
|
6 | }
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | ValidationError.prototype.toString = function (shouldDecorate, hasParent, parentPath) {
|
14 | var _this = this;
|
15 | if (shouldDecorate === void 0) { shouldDecorate = false; }
|
16 | if (hasParent === void 0) { hasParent = false; }
|
17 | if (parentPath === void 0) { parentPath = ""; }
|
18 | var boldStart = shouldDecorate ? "\u001B[1m" : "";
|
19 | var boldEnd = shouldDecorate ? "\u001B[22m" : "";
|
20 | var propConstraintFailed = function (propertyName) {
|
21 | return " - property ".concat(boldStart).concat(parentPath).concat(propertyName).concat(boldEnd, " has failed the following constraints: ").concat(boldStart).concat(Object.keys(_this.constraints).join(", ")).concat(boldEnd, " \n");
|
22 | };
|
23 | if (!hasParent) {
|
24 | return ("An instance of ".concat(boldStart).concat(this.target ? this.target.constructor.name : 'an object').concat(boldEnd, " has failed the validation:\n") +
|
25 | (this.constraints ? propConstraintFailed(this.property) : "") +
|
26 | (this.children
|
27 | ? this.children.map(function (childError) { return childError.toString(shouldDecorate, true, _this.property); }).join("")
|
28 | : ""));
|
29 | }
|
30 | else {
|
31 |
|
32 | var formattedProperty_1 = Number.isInteger(+this.property)
|
33 | ? "[".concat(this.property, "]")
|
34 | : "".concat(parentPath ? "." : "").concat(this.property);
|
35 | if (this.constraints) {
|
36 | return propConstraintFailed(formattedProperty_1);
|
37 | }
|
38 | else {
|
39 | return this.children
|
40 | ? this.children
|
41 | .map(function (childError) { return childError.toString(shouldDecorate, true, "".concat(parentPath).concat(formattedProperty_1)); })
|
42 | .join("")
|
43 | : "";
|
44 | }
|
45 | }
|
46 | };
|
47 | return ValidationError;
|
48 | }());
|
49 | export { ValidationError };
|
50 |
|
\ | No newline at end of file |