@lucaspaganini/value-objects
Version:
TypeScript first validation and class creation library
156 lines • 5.58 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogicError = exports.UnknownError = exports.RawTypeError = exports.PatternError = exports.NotIntegerError = exports.NotInSetError = exports.MinSizeError = exports.MinLengthError = exports.MaxSizeError = exports.MaxLengthError = exports.VOError = void 0;
var utils_1 = require("../utils");
var VO_ERROR_TAG = {};
var VOError = /** @class */ (function (_super) {
__extends(VOError, _super);
function VOError(message, path) {
if (path === void 0) { path = new utils_1.ObjectPath([]); }
var _this = _super.call(this, message) || this;
_this.path = path;
_this._tag = VO_ERROR_TAG;
return _this;
}
VOError.is = function (err) {
return err._tag === VO_ERROR_TAG;
};
return VOError;
}(Error));
exports.VOError = VOError;
var MaxLengthError = /** @class */ (function (_super) {
__extends(MaxLengthError, _super);
function MaxLengthError(maxLength, length) {
var _this = _super.call(this) || this;
_this.maxLength = maxLength;
_this.length = length;
_this.message = 'Too long';
return _this;
}
return MaxLengthError;
}(VOError));
exports.MaxLengthError = MaxLengthError;
var MaxSizeError = /** @class */ (function (_super) {
__extends(MaxSizeError, _super);
function MaxSizeError(max, valueSize) {
var _this = _super.call(this) || this;
_this.max = max;
_this.valueSize = valueSize;
_this.message = 'Too big';
return _this;
}
return MaxSizeError;
}(VOError));
exports.MaxSizeError = MaxSizeError;
var MinLengthError = /** @class */ (function (_super) {
__extends(MinLengthError, _super);
function MinLengthError(minLength, length) {
var _this = _super.call(this) || this;
_this.minLength = minLength;
_this.length = length;
_this.message = 'Too short';
return _this;
}
return MinLengthError;
}(VOError));
exports.MinLengthError = MinLengthError;
var MinSizeError = /** @class */ (function (_super) {
__extends(MinSizeError, _super);
function MinSizeError(min, valueSize) {
var _this = _super.call(this) || this;
_this.min = min;
_this.valueSize = valueSize;
_this.message = 'Too small';
return _this;
}
return MinSizeError;
}(VOError));
exports.MinSizeError = MinSizeError;
var NotInSetError = /** @class */ (function (_super) {
__extends(NotInSetError, _super);
function NotInSetError(set, value, prop) {
var _this = _super.call(this) || this;
_this.set = set;
_this.value = value;
_this.prop = prop;
_this.message = 'Value not found in set';
return _this;
}
return NotInSetError;
}(VOError));
exports.NotInSetError = NotInSetError;
var NotIntegerError = /** @class */ (function (_super) {
__extends(NotIntegerError, _super);
function NotIntegerError(value, prop) {
var _this = _super.call(this) || this;
_this.value = value;
_this.prop = prop;
_this.message = 'Not an integer';
return _this;
}
return NotIntegerError;
}(VOError));
exports.NotIntegerError = NotIntegerError;
var PatternError = /** @class */ (function (_super) {
__extends(PatternError, _super);
function PatternError() {
var _this = _super.call(this) || this;
_this.message = "Value doesn't match pattern";
return _this;
}
return PatternError;
}(VOError));
exports.PatternError = PatternError;
var RawTypeError = /** @class */ (function (_super) {
__extends(RawTypeError, _super);
function RawTypeError(expected, actual, prop) {
var _this = _super.call(this) || this;
_this.expected = expected;
_this.actual = actual;
_this.prop = prop;
_this.message = 'Wrong raw value type';
return _this;
}
RawTypeError.is = function (err) {
return err.message === 'Wrong raw value type';
};
return RawTypeError;
}(TypeError));
exports.RawTypeError = RawTypeError;
var UnknownError = /** @class */ (function (_super) {
__extends(UnknownError, _super);
function UnknownError() {
var _this = _super.call(this) || this;
_this.message = 'Unknown error';
return _this;
}
return UnknownError;
}(VOError));
exports.UnknownError = UnknownError;
var LogicError = /** @class */ (function (_super) {
__extends(LogicError, _super);
function LogicError(expected) {
var _this = _super.call(this) || this;
_this.expected = expected;
_this.message = 'Invalid logic';
return _this;
}
return LogicError;
}(VOError));
exports.LogicError = LogicError;
//# sourceMappingURL=errors.js.map