validateConfig.js 949 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.validateConfig = void 0;
  7. const validators_1 = __importDefault(require("./generated/validators"));
  8. const validateConfig = (schemaId, config) => {
  9. const validate = validators_1.default[schemaId];
  10. if (!validate(config) && validate.errors) {
  11. const errors = validate.errors.map((error) => {
  12. return {
  13. message: error.message,
  14. params: error.params,
  15. schemaPath: error.schemaPath,
  16. };
  17. });
  18. /* eslint-disable no-console */
  19. console.log('config', config);
  20. console.log('errors', errors);
  21. /* eslint-enable no-console */
  22. throw new Error('Invalid config.');
  23. }
  24. };
  25. exports.validateConfig = validateConfig;