inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
47 lines • 2.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable:prefer-function-over-method
const BaseSingletonDefinition_1 = require("../ioc/objectdefinition/BaseSingletonDefinition");
const MySQLClient_1 = require("./MySQLClient");
const MySQLHealthCheck_1 = require("./MySQLHealthCheck");
class MySQLPlugin {
constructor() {
this.name = 'MySQLPlugin';
}
getName() {
return this.name;
}
willStart(app) {
if (!app.hasConfig('mysql')) {
throw new Error('MysqlPlugin has been registered but could not find config using key "mysql"');
}
const context = app.getContext();
const confs = context.getConfig('mysql');
Object.keys(confs).forEach((key) => {
if (Object.hasOwnProperty.call(confs[key], 'enabled') && (confs[key].enabled === false || confs[key].enabled === 'false')) {
// Skip this definition as it has been specifically disabled
return;
}
const clientSingleton = new BaseSingletonDefinition_1.BaseSingletonDefinition(MySQLClient_1.MySQLClient, key);
const config = Object.assign(Object.assign({}, confs[key]), { name: key });
clientSingleton.constructorParamByValue(config);
context.registerSingletons(clientSingleton);
if (confs[key].master) {
const masterHealthCheck = new BaseSingletonDefinition_1.BaseSingletonDefinition(MySQLHealthCheck_1.MySQLHealthCheck, `HC_${key}_master`);
masterHealthCheck.constructorParamByValue(`mysql.${key}.master`);
masterHealthCheck.constructorParamByValue(false);
masterHealthCheck.setPropertyByRef('mysqlClient', key);
context.registerDefinition(masterHealthCheck);
}
if (confs[key].slave) {
const slaveHealthCheck = new BaseSingletonDefinition_1.BaseSingletonDefinition(MySQLHealthCheck_1.MySQLHealthCheck, `HC_${key}_slave`);
slaveHealthCheck.constructorParamByValue(`mysql.${key}.slave`);
slaveHealthCheck.constructorParamByValue(true);
slaveHealthCheck.setPropertyByRef('mysqlClient', key);
context.registerDefinition(slaveHealthCheck);
}
});
}
}
exports.default = MySQLPlugin;
//# sourceMappingURL=MySQLPlugin.js.map