UNPKG

lambdaorm-cli

Version:
245 lines 8.72 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.LibOrmService = exports.LibStageService = exports.LibSchemaService = void 0; const lambdaorm_1 = require("lambdaorm"); class LibSchemaService { // eslint-disable-next-line no-useless-constructor constructor(schemaState) { this.schemaState = schemaState; } introspect(data, name) { return __awaiter(this, void 0, void 0, function* () { this.schemaState.introspect(data, name); }); } sources() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaSources()); }); } source(source) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaSource(source)); }); } version() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaVersion()); }); } schema() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.schema); }); } originalSchema() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.originalSchema); }); } domain() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaDomain()); }); } entities() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaEntities()); }); } entity(entity) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaEntity(entity)); }); } enums() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaEnums()); }); } enum(_enum) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaEnum(_enum)); }); } mappings() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaMappings()); }); } mapping(mapping) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaMapping(mapping)); }); } entityMapping(mapping, entity) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaEntityMapping(mapping, entity)); }); } stages() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaStages()); }); } stage(stage) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaStage(stage)); }); } views() { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.schemaState.getSchemaViews()); }); } } exports.LibSchemaService = LibSchemaService; class LibStageService { // eslint-disable-next-line no-useless-constructor constructor(orm, workspace) { this.orm = orm; this.workspace = workspace; } exists(stage) { return __awaiter(this, void 0, void 0, function* () { return this.orm.stage.exists(stage); }); } fetch(stage) { return __awaiter(this, void 0, void 0, function* () { return this.orm.stage.fetch({ stage }); }); } pull(stage) { return __awaiter(this, void 0, void 0, function* () { return this.orm.stage.pull({ stage }); }); } introspect(data, name, stage) { return __awaiter(this, void 0, void 0, function* () { return this.orm.stage.introspect(data, name, { stage }); }); } incorporate(data, name, stage) { return __awaiter(this, void 0, void 0, function* () { return this.orm.stage.incorporate(data, name, { stage }); }); } export(stage, force) { return __awaiter(this, void 0, void 0, function* () { return this.orm.stage.export({ stage, tryAllCan: force }).execute(); }); } import(stage, schemaData) { return __awaiter(this, void 0, void 0, function* () { return this.orm.stage.import({ stage }).execute(schemaData); }); } drop(stage, sentence, force) { return __awaiter(this, void 0, void 0, function* () { if (sentence) { return yield this.orm.stage.drop({ stage }).sentence(); } else { return yield this.orm.stage.drop({ stage, tryAllCan: force }).execute(); } }); } push(stage, sentence, force) { return __awaiter(this, void 0, void 0, function* () { const schema = yield this.orm.state.load(this.workspace); if (schema === null) { throw new Error(`Can't found schema in ${this.workspace}`); } const _stage = this.orm.state.stage.get(stage); if (sentence) { return yield this.orm.stage.push({ stage: _stage.name }).sentence(); } else { return yield this.orm.stage.push({ stage: _stage.name, tryAllCan: force }).execute(); } }); } } exports.LibStageService = LibStageService; class LibOrmService { constructor(workspace) { this.workspace = workspace; this.orm = new lambdaorm_1.Orm(); this._schema = new LibSchemaService(this.orm.state); this._stage = new LibStageService(this.orm, this.workspace); } init() { return __awaiter(this, void 0, void 0, function* () { return this.orm.init(this.workspace); }); } get schema() { if (!this._schema) { throw new Error('Schema not initialized'); } return this._schema; } get stage() { if (!this._stage) { throw new Error('Stage not initialized'); } return this._stage; } getStageName(stage) { return __awaiter(this, void 0, void 0, function* () { const schema = yield this.orm.state.load(this.workspace); if (schema === null) { throw new Error(`Can't found schema in ${this.workspace}`); } const _stage = this.orm.state.stage.get(stage); return _stage.name; }); } end() { return __awaiter(this, void 0, void 0, function* () { return this.orm.end(); }); } model(query) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.orm.model(query)); }); } parameters(query) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.orm.parameters(query)); }); } constraints(query) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.orm.constraints(query)); }); } metadata(query) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.orm.metadata(query)); }); } plan(query, options) { return __awaiter(this, void 0, void 0, function* () { return Promise.resolve(this.orm.plan(query, options)); }); } execute(query, data, options) { return __awaiter(this, void 0, void 0, function* () { return this.orm.execute(query, data, options); }); } } exports.LibOrmService = LibOrmService; //# sourceMappingURL=lib.js.map