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