Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return __awaiter(this, void 0, void 0, function* () {
const env = di_1.Container.get("ENVIRONMENT");
this.nodeId = env.nodeId;
this.eventEmitter = new eventemitter2_1.EventEmitter2(this.CONFIG.eventEmitter);
this.dbClient = di_1.Container.get(db_1.DbAppClient);
yield this.finishInitialisation();
// set listeners that were cached during booting, clean cache afterwards
Object.values(this.listenersCache).forEach((eventListeners) => {
Object.values(eventListeners).forEach((listener) => {
this._on(listener.eventName, listener.options, listener.callback);
});
});
this.listenersCache = {};
// fire events that were cached during booting, clean cache afterwards
Object.entries(this.emittersCache).forEach((emitterEntry) => {
const eventName = emitterEntry[0];
const eventEmitters = emitterEntry[1];
Object.values(eventEmitters).forEach((emitter) => {
this._emit(eventName, emitter.nodeId, ...emitter.args);
});
});
return __awaiter(this, void 0, void 0, function* () {
// get DB pgClient from DI container
const dbClient = di_1.Container.get(db_1.DbAppClient).pgClient;
// check latest version migrated
let latestVersion = 0;
try {
const dbInitVersion = (yield dbClient.query(`SELECT value FROM _meta.info WHERE key = 'version';`)).rows[0];
if (dbInitVersion != null && dbInitVersion.value != null) {
latestVersion = parseInt(dbInitVersion.value, 10);
this.logger.debug('migration.db.init.version.detected', latestVersion);
}
}
catch (err) {
this.logger.info('migration.db.init.not.found');
}
// find init scripts to ignore (version lower than the current one)
const initSqlFolders = [];
// run through all registered packages
this.initSqlPaths.map((initSqlPath) => {
return __awaiter(this, void 0, void 0, function* () {
// get DB pgClient from DI container
const dbAppClient = di_1.Container.get(db_1.DbAppClient);
const dbClient = dbAppClient.pgClient;
// check latest version migrated
let latestVersion = 0;
try {
const dbInitVersion = (yield dbClient.query("SELECT value FROM _meta.info WHERE key = 'version';")).rows[0];
if (dbInitVersion != null && dbInitVersion.value != null) {
latestVersion = parseInt(dbInitVersion.value, 10);
this.logger.debug("migration.db.init.version.detected", latestVersion);
}
}
catch (err) {
this.logger.info("migration.db.init.not.found");
}
// find init scripts to ignore (version lower than the current one)
const initSqlFolders = [];
// run through all registered packages
__param(4, di_1.Inject((type) => db_1.DbAppClient)),
__metadata("design:paramtypes", [logger_1.LoggerFactory,
__param(3, di_1.Inject((type) => db_1.DbAppClient)),
__param(4, di_1.Inject((type) => db_1.DbGeneralPool)),
for (const sql of Object.values(bootSqlStatements)) {
this.logger.trace("migration.boot.sql.statement", sql);
yield dbClient.query(sql);
}
});
}
};
DbSchemaBuilder = __decorate([
di_1.Service(),
__param(0, di_1.Inject((type) => boot_loader_1.BootLoader)),
__param(1, di_1.Inject((type) => config_1.Config)),
__param(2, di_1.Inject((type) => logger_1.LoggerFactory)),
__param(3, di_1.Inject((type) => db_1.DbAppClient)),
__metadata("design:paramtypes", [Object, config_1.Config,
logger_1.LoggerFactory,
db_1.DbAppClient])
], DbSchemaBuilder);
exports.DbSchemaBuilder = DbSchemaBuilder;
__param(0, di_1.Inject((type) => db_1.DbAppClient)),
__metadata("design:paramtypes", [Object])
__param(2, di_1.Inject(type => db_1.DbAppClient)),
__metadata("design:paramtypes", [config_1.Config,