lambdaorm-cli
Version:
The lambdaorm command line interface
258 lines • 8.9 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
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.RestOrmService = exports.ClientStageService = exports.ClientSchemaService = void 0;
const client = __importStar(require("lambdaorm-client-node"));
class ClientSchemaService {
// eslint-disable-next-line no-useless-constructor
constructor(schemaService) {
this.schemaService = schemaService;
}
introspect(data, name) {
throw new Error('Method not support in Rest Service.');
}
originalSchema() {
// TODO: Change for Original Schema
return this.schemaService.schema();
}
version() {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.version();
});
}
domain() {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.domain();
});
}
sources() {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.sources();
});
}
source(source) {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.source(source);
});
}
entities() {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.entities();
});
}
entity(entity) {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.entity(entity);
});
}
enums() {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.enums();
});
}
enum(_enum) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.schemaService.enum(_enum);
});
}
mappings() {
return __awaiter(this, void 0, void 0, function* () {
return yield this.schemaService.mappings();
});
}
schema() {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.schema();
});
}
mapping(mapping) {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.mapping(mapping);
});
}
entityMapping(mapping, entity) {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.entityMapping(mapping, entity);
});
}
stages() {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.stages();
});
}
stage(stage) {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.stage(stage);
});
}
views() {
return __awaiter(this, void 0, void 0, function* () {
return this.schemaService.views();
});
}
}
exports.ClientSchemaService = ClientSchemaService;
class ClientStageService {
// eslint-disable-next-line no-useless-constructor
constructor(stageService) {
this.stageService = stageService;
}
exists(stage) {
return __awaiter(this, void 0, void 0, function* () {
return this.stageService.exists(stage);
});
}
export(stage, force) {
return __awaiter(this, void 0, void 0, function* () {
return this.stageService.export(stage);
});
}
import(stage, schemaData) {
return __awaiter(this, void 0, void 0, function* () {
return this.stageService.import(stage, schemaData);
});
}
introspect(data, name, stage) {
throw new Error('Functionality not support by rest client.');
}
incorporate(data, name, stage) {
throw new Error('Functionality not support by rest client.');
}
fetch(stage) {
throw new Error('Functionality not support by rest client.');
}
pull(stage) {
throw new Error('Functionality not support by rest client.');
}
drop(stage, sentence, force) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Functionality not support by rest client.');
});
}
push(stage, sentence, force) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Functionality not support by rest client.');
});
}
}
exports.ClientStageService = ClientStageService;
class RestOrmService {
constructor(url) {
this.url = url;
this.orm = new client.Orm(url);
}
init() {
return __awaiter(this, void 0, void 0, function* () {
yield this.orm.init(this.url);
this._schema = new ClientSchemaService(this.orm.schema);
this._stage = new ClientStageService(this.orm.stage);
return null;
});
}
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;
}
end() {
return __awaiter(this, void 0, void 0, function* () {
return this.orm.end();
});
}
getStageName(stage) {
return __awaiter(this, void 0, void 0, function* () {
const stages = yield this.orm.schema.stages();
if (stages.length === 0) {
throw new Error(`Can't found stages in ${this.url}`);
}
if (stage === undefined) {
return stages[0].name;
}
const _stage = stages.find(s => s.name === stage);
if (_stage === undefined) {
throw new Error(`Can't found stage ${stage} in ${this.url}`);
}
return _stage.name;
});
}
model(query) {
return __awaiter(this, void 0, void 0, function* () {
return this.orm.model(query);
});
}
parameters(query) {
return __awaiter(this, void 0, void 0, function* () {
return this.orm.parameters(query);
});
}
constraints(query) {
return __awaiter(this, void 0, void 0, function* () {
return this.orm.constraints(query);
});
}
metadata(query) {
return __awaiter(this, void 0, void 0, function* () {
return this.orm.metadata(query);
});
}
plan(query, options) {
return __awaiter(this, void 0, void 0, function* () {
return 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.RestOrmService = RestOrmService;
//# sourceMappingURL=rest.js.map