UNPKG

@geek-fun/serverlessinsight

Version:

Full life cycle cross providers serverless application management for your fast-growing business.

47 lines (46 loc) 1.74 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateYaml = void 0; const ajv_1 = __importDefault(require("ajv")); const common_1 = require("../common"); const rootSchema_1 = require("./rootSchema"); const databaseSchema_1 = require("./databaseSchema"); const eventSchema_1 = require("./eventSchema"); const functionSchema_1 = require("./functionSchema"); const bucketSchema_1 = require("./bucketSchema"); const tableschema_1 = require("./tableschema"); class IacSchemaErrors extends Error { constructor(errors) { super(`Invalid yaml`); this.schemaErrors = errors.map((error) => ({ instancePath: error.instancePath, schemaPath: error.schemaPath, message: error.message, allowedValues: error.params?.allowedValues, type: error.keyword, })); } get errors() { return this.schemaErrors; } } const ajv = new ajv_1.default({ allowUnionTypes: true, strict: false, allErrors: true }); const validate = ajv .addSchema(functionSchema_1.functionSchema) .addSchema(eventSchema_1.eventSchema) .addSchema(databaseSchema_1.databaseSchema) .addSchema(tableschema_1.tableSchema) .addSchema(bucketSchema_1.bucketSchema) .compile(rootSchema_1.rootSchema); const validateYaml = (iacJson) => { const valid = validate(iacJson); if (!valid) { common_1.logger.debug(`Invalid yaml: ${JSON.stringify(validate.errors)}`); throw new IacSchemaErrors(validate.errors); } return true; }; exports.validateYaml = validateYaml;