UNPKG

lambdaorm-cli

Version:
94 lines 4.23 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Schema = void 0; class Schema { // eslint-disable-next-line no-useless-constructor constructor(service) { this.service = service; } execute(workspace, path, output, url) { return __awaiter(this, void 0, void 0, function* () { if (path === undefined) { console.error('the path argument is required'); return; } const orm = this.service.orm.create({ workspace, url }); try { yield orm.init(); let result = null; if (path === 'schema') { result = yield orm.schema.schema(); } else if (path === 'schema/version') { result = yield orm.schema.version(); } else if (path === 'domain') { result = yield orm.schema.domain(); } else if (path.startsWith('sources/')) { result = yield orm.schema.source(path.replace('sources/', '')); } else if (path === 'entities') { result = yield orm.schema.entities(); } else if (path.startsWith('entities/')) { result = yield orm.schema.entity(path.replace('entities/', '')); } else if (path === 'enums') { result = yield orm.schema.enums(); } else if (path.startsWith('enums/')) { result = yield orm.schema.enum(path.replace('enums/', '')); } else if (path === 'mappings') { result = yield orm.schema.mappings(); } else if (path.startsWith('mappings/') && path.split('/').length === 2) { result = yield orm.schema.mapping(path.replace('mappings/', '')); } else if (path.startsWith('mappings/') && path.split('/').length === 3) { const regex = /mappings\/([^\\/]+)\/([^\\/]+)/; // Hacer coincidir la expresión regular con el string const coincidencias = path.match(regex); // Verificar si hay coincidencias y extraer los valores if (coincidencias) { const mapping = coincidencias[1]; const entity = coincidencias[2]; result = yield orm.schema.entityMapping(mapping, entity); } } else if (path === 'stages') { result = yield orm.schema.stages(); } else if (path.startsWith('stages/')) { result = yield orm.schema.stage(path.replace('stages/', '')); } else if (path === 'views') { result = yield orm.schema.views(); } if (result === undefined) { console.error(`the path ${path} is not valid`); return; } this.service.output.execute(result, output); } catch (error) { console.error(`error: ${error}`); } finally { yield orm.end(); } }); } } exports.Schema = Schema; //# sourceMappingURL=schema.js.map