lambdaorm-client-node
Version:
Client form lambda ORM service
131 lines • 5 kB
JavaScript
"use strict";
/* eslint-disable @typescript-eslint/ban-types */
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.Orm = void 0;
const domain_1 = require("../../domain");
const _3xpr_1 = require("3xpr");
const __1 = require("..");
const api_1 = require("../api");
const QueryApiService_1 = require("./QueryApiService");
const GeneralApiService_1 = require("./GeneralApiService");
const SchemaApiService_1 = require("./SchemaApiService");
const StageApiService_1 = require("./StageApiService");
/**
* Facade through which you can access all the functionalities of the library.
*/
class Orm {
constructor(url = 'http://localhost:9289') {
this.url = url;
}
/**
* Singleton
*/
static get instance() {
if (!this._instance) {
this._instance = new Orm();
}
return this._instance;
}
init(url) {
return __awaiter(this, void 0, void 0, function* () {
if (url) {
this.url = url;
}
new __1.SentenceLibrary(_3xpr_1.expressions).load();
this.configuration = new domain_1.Configuration({ basePath: this.url });
this.queryService = new QueryApiService_1.QueryApiService(new api_1.QueryApi(this.configuration));
this.generalService = new GeneralApiService_1.GeneralApiService(new api_1.GeneralApi(this.configuration));
this.schemaService = new SchemaApiService_1.SchemaApiService(new api_1.SchemaApi(this.configuration));
this.stageService = new StageApiService_1.StageApiService(new api_1.StageApi(this.configuration));
});
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
end() {
return __awaiter(this, void 0, void 0, function* () { });
}
get general() {
if (!this.generalService) {
throw new Error('Orm not initialized');
}
return this.generalService;
}
get schema() {
if (!this.schemaService) {
throw new Error('Orm not initialized');
}
return this.schemaService;
}
get stage() {
if (!this.stageService) {
throw new Error('Orm not initialized');
}
return this.stageService;
}
model(query) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.queryService) {
throw new Error('Orm not initialized');
}
return this.queryService.model(query);
});
}
parameters(query) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.queryService) {
throw new Error('Orm not initialized');
}
return this.queryService.parameters(query);
});
}
constraints(query) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.queryService) {
throw new Error('Orm not initialized');
}
return this.queryService.constraints(query);
});
}
metadata(query) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.queryService) {
throw new Error('Orm not initialized');
}
return this.queryService.metadata(query);
});
}
plan(query, options) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.queryService) {
throw new Error('Orm not initialized');
}
return this.queryService.plan(query, options);
});
}
execute(query_1) {
return __awaiter(this, arguments, void 0, function* (query, data = {}, options = undefined) {
if (!this.queryService) {
throw new Error('Orm not initialized');
}
return this.queryService.execute(query, data, options);
});
}
executeQueued(query_1, topic_1) {
return __awaiter(this, arguments, void 0, function* (query, topic, data = {}, chunk, options = undefined) {
if (!this.queryService) {
throw new Error('Orm not initialized');
}
return this.queryService.executeQueued(query, data, options);
});
}
}
exports.Orm = Orm;
//# sourceMappingURL=orm.js.map