UNPKG

lambdaorm-base

Version:
68 lines 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoadSchema = void 0; const domain_1 = require("../../domain"); class LoadSchema { // eslint-disable-next-line no-useless-constructor constructor(source, domain, mapping, stage, view, helper) { this.source = source; this.domain = domain; this.mapping = mapping; this.stage = stage; this.view = view; this.helper = helper; } load(source) { const schema = this.helper.utils.solveEnvironmentVars(source); this.domain.entities = schema.domain.entities || []; this.domain.enums = schema.domain.enums || []; if (!schema.infrastructure) { return schema; } if (!schema.infrastructure.views) { schema.infrastructure.views = [{ name: 'default', entities: [] }]; } for (const view of schema.infrastructure.views) { this.view.load(view); } if (schema.infrastructure.mappings) { for (const mapping of schema.infrastructure.mappings) { this.mapping.load(mapping); } } if (schema.infrastructure.sources) { for (const source of schema.infrastructure.sources) { if (this.helper.val.isEmpty(source.connection)) { this.helper.logger.log(`WARNING|source:"${source.name}"|connection is empty`); continue; } if (typeof source.connection === 'string') { if (source.connection.includes('${')) { this.helper.logger.log(`WARNING|source:"${source.name}"|had environment variables unsolved`); } else { const connection = this.helper.utils.tryParse(source.connection); if (connection) { source.connection = connection; } else { throw new domain_1.SchemaError(`Connection "${source.connection}" not serializable`); } } } else if (typeof source.connection !== 'object') { throw new domain_1.SchemaError(`The source "${source.name}" connection to is not defined as an object`); } this.source.load(source); } } if (schema.infrastructure.stages) { for (const stage of schema.infrastructure.stages) { this.stage.load(stage); } } return schema; } } exports.LoadSchema = LoadSchema; //# sourceMappingURL=load.js.map