@adv-ui/boros-tcf
Version:
Adevinta GDPR - Transparency and Consent Framework - API
118 lines (96 loc) • 2.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UseCaseAdapterFactory = void 0;
var _ioc = require("../../core/ioc/ioc");
var _DomainEventBus = require("../../domain/service/DomainEventBus");
var _constants = require("../../core/constants");
var UseCaseAdapterFactory = /*#__PURE__*/function () {
function UseCaseAdapterFactory(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$domainEventBus = _ref.domainEventBus,
domainEventBus = _ref$domainEventBus === void 0 ? (0, _ioc.inject)(_DomainEventBus.DomainEventBus) : _ref$domainEventBus;
this._domainEventBus = domainEventBus;
}
var _proto = UseCaseAdapterFactory.prototype;
_proto.createSync = function createSync(_ref2) {
var _this = this;
var instance = _ref2.instance,
key = _ref2.key;
return {
execute: function execute(params) {
try {
var result = instance.execute(params);
_this._raiseCalled({
key: key,
params: params,
result: result
});
return result;
} catch (error) {
_this._raiseError({
key: key,
params: params,
error: error
});
throw error;
}
}
};
};
_proto.createAsync = function createAsync(_ref3) {
var _this2 = this;
var instance = _ref3.instance,
key = _ref3.key;
return {
execute: function execute(params) {
return Promise.resolve().then(function () {
return instance.execute(params);
}).then(function (result) {
_this2._raiseCalled({
key: key,
params: params,
result: result
});
return result;
})["catch"](function (error) {
_this2._raiseError({
key: key,
params: params,
error: error
});
throw error;
});
}
};
};
_proto._raiseCalled = function _raiseCalled(_ref4) {
var key = _ref4.key,
params = _ref4.params,
result = _ref4.result;
this._domainEventBus.raise({
eventName: _constants.EVENT_USE_CASE_CALLED,
payload: {
useCase: key.ID,
params: params,
result: result
}
});
};
_proto._raiseError = function _raiseError(_ref5) {
var key = _ref5.key,
params = _ref5.params,
error = _ref5.error;
this._domainEventBus.raise({
eventName: _constants.EVENT_USE_CASE_ERROR,
payload: {
useCase: key.ID,
params: params,
error: error
}
});
};
return UseCaseAdapterFactory;
}();
exports.UseCaseAdapterFactory = UseCaseAdapterFactory;