UNPKG

lex-model-validator

Version:
72 lines (71 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _1 = require("./"); exports.runValidation = function (json, validator) { validator.run(json); if (validator.childrenCount > 0) { validator.runChildren(json); } }; var LexModelValidator = /** @class */ (function () { function LexModelValidator(validatorConstructors) { if (validatorConstructors === void 0) { validatorConstructors = [ _1.MetaDataValidator, _1.ResourceValidator, _1.IntentValidator, _1.SlotTypeValidator ]; } this.collectedErrors = []; this.$validators = []; this.use.apply(this, validatorConstructors); } LexModelValidator.prototype.use = function () { var validatorConstructors = []; for (var _i = 0; _i < arguments.length; _i++) { validatorConstructors[_i] = arguments[_i]; } this.addValidators.apply(this, validatorConstructors); }; LexModelValidator.prototype.validator = function (name) { return this.$validators.find(function (validator) { return validator.name === name; }); }; LexModelValidator.prototype.validateJson = function (json) { return this.validate(json); }; LexModelValidator.prototype.validate = function (json) { this.collectedErrors = []; this.$validators.forEach(exports.runValidation.bind(this, json)); var output = ''; this.collectedErrors.forEach(function (error) { output += error.message + '\n'; }); if (output === '') { _1.Log.success('The given model should have no errors and there should be no problems while importing in Amazon Lex.'); } else { _1.Log.warning(output); } return this.collectedErrors; }; LexModelValidator.prototype.addValidator = function (validatorConstructor) { if (!this.$validators.some(function (validator) { return validator.name === validatorConstructor.name; })) { this.$validators.push(new validatorConstructor(this)); } }; LexModelValidator.prototype.addValidators = function () { var _this = this; var validatorConstructors = []; for (var _i = 0; _i < arguments.length; _i++) { validatorConstructors[_i] = arguments[_i]; } validatorConstructors.forEach(function (constructor) { _this.addValidator(constructor); }); }; return LexModelValidator; }()); exports.LexModelValidator = LexModelValidator;