UNPKG

inceptum

Version:

hipages take on the foundational library for enterprise-grade apps written in NodeJS

39 lines 2 kB
"use strict"; 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) => { const clientSingleton = new BaseSingletonDefinition_1.BaseSingletonDefinition(MysqlClient_1.MysqlClient, key); clientSingleton.setPropertyByValue('name', key); clientSingleton.setPropertyByValue('configuration', confs[key]); context.registerSingletons(clientSingleton); 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); 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