UNPKG

sws-frontend

Version:

sws frontend project

67 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var helpers_1 = require("./helpers"); exports.aggregateValidationsArray = function (array) { var globalValidation; array.map(function (cAuth, idx) { return globalValidation = exports.aggregateIssues(cAuth.getValidation(), globalValidation); }); return globalValidation; }; exports.aggregateIssues = function (a, b) { if (!a || !b) return a || b; var error; if (a.level == 'error') { error = a; } // if b is error merge with a if (b.level == 'error') { error = { level: 'error', message: (error && error.message) ? error.message + "\n" + (b.message ? b.message : 'Generic error') : b.message }; } // TODO WARNING return error ? error : { level: 'success', message: '' }; }; exports.IssueTypes = ['success', 'warning', 'error']; exports.resolveIssueType = function (type) { switch (type) { case 'success': return 'success'; case 'warning': return 'warning'; case 'error': return 'error'; } }; var ValidationResult = (function () { function ValidationResult(validations) { var _this = this; validations && Object.keys(validations).map(function (validation) { if (validation != '_validation') { _this[validation] = validations[validation]; _this._validation = exports.aggregateIssues(_this._validation, validations[validation]); } }); } ValidationResult.prototype.setValidation = function (i) { this._validation = i && i; }; ValidationResult.prototype.getValidation = function () { return this._validation; }; ValidationResult.prototype.isValid = function () { return this.getValidation().level != 'error'; }; return ValidationResult; }()); exports.ValidationResult = ValidationResult; var given = function (issue) { return { isValid: function () { return issue.level != 'error'; } }; }; exports.IssueApi = { given: given }; exports.buildValidation = function (defaults, overrides) { return new ValidationResult(overrides ? helpers_1.merge(defaults, overrides) : defaults); }; //# sourceMappingURL=validation.js.map