@addapptables/microservice
Version:
addapptables microservice
45 lines • 2.42 kB
JavaScript
;
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.InitializeAdapterBus = void 0;
const ramda_1 = require("ramda");
const interfaces_1 = require("../interfaces");
const exceptions_1 = require("../exceptions");
class InitializeAdapterBus {
constructor(microserviceOptions, module) {
this.microserviceOptions = microserviceOptions;
this.module = module;
}
// TODO: apply design pattern
init(config) {
return __awaiter(this, void 0, void 0, function* () {
const adapterConfig = this.microserviceOptions.adapter;
if ((0, ramda_1.isEmpty)(adapterConfig) || (0, ramda_1.isNil)(adapterConfig)) {
throw new exceptions_1.BusConfigException('The Bus Adapter was not configured.');
}
const AdapterPrototype = adapterConfig.adapterPrototype;
// TODO: validate prototype is IAdapterBus
if ((0, ramda_1.isEmpty)(AdapterPrototype) || (0, ramda_1.isNil)(AdapterPrototype)) {
throw new exceptions_1.BusConfigException('The Bus Adapter Prototype was not configured.');
}
const adapterInstance = yield this.module.resolve(AdapterPrototype, undefined, { strict: false });
if (typeof adapterInstance[interfaces_1.SetOptions] === 'function') {
yield adapterInstance[interfaces_1.SetOptions](config);
}
if (typeof adapterInstance[interfaces_1.OnInit] === 'function') {
yield adapterInstance[interfaces_1.OnInit]();
}
return adapterInstance;
});
}
}
exports.InitializeAdapterBus = InitializeAdapterBus;
//# sourceMappingURL=initialize-adapter-bus.service.js.map