-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommandExecutor.js
More file actions
2 lines (2 loc) · 3.37 KB
/
commandExecutor.js
File metadata and controls
2 lines (2 loc) · 3.37 KB
1
2
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _nodeCqrsLib=require("@facetdev/node-cqrs-lib");function _objectSpread(r){for(var e=1;e<arguments.length;e++){var t=null!=arguments[e]?arguments[e]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.forEach(function(e){_defineProperty(r,e,t[e])})}return r}function _objectWithoutProperties(e,r){if(null==e)return{};var t,n,o=_objectWithoutPropertiesLoose(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)t=a[n],0<=r.indexOf(t)||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function _objectWithoutPropertiesLoose(e,r){if(null==e)return{};var t,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)t=a[n],0<=r.indexOf(t)||(o[t]=e[t]);return o}function asyncGeneratorStep(e,r,t,n,o,a,c){try{var s=e[a](c),i=s.value}catch(e){return void t(e)}s.done?r(i):Promise.resolve(i).then(n,o)}function _asyncToGenerator(s){return function(){var e=this,c=arguments;return new Promise(function(r,t){var n=s.apply(e,c);function o(e){asyncGeneratorStep(n,r,t,o,a,"next",e)}function a(e){asyncGeneratorStep(n,r,t,o,a,"throw",e)}o(void 0)})}}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var CommandExecutor=function e(r){var p=this,t=r.name,n=r.handlers,o=r.repository;_classCallCheck(this,e),_defineProperty(this,"execute",function(){var r=_asyncToGenerator(regeneratorRuntime.mark(function e(r){var t,n,o,a,c,s,i,u,f;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.aggregateId,n=r.commandType,o=r.command,a=p.handlers[n]&&p.handlers[n]()){e.next=4;break}throw new _nodeCqrsLib.CommandHandlerError({message:"Unknown command ".concat(n)});case 4:return e.prev=4,e.next=7,p.getAggregate(a,t);case 7:return c=e.sent,e.next=10,a.handle(o,c);case 10:return s=e.sent,u=(i=s||{}).events,f=_objectWithoutProperties(i,["events"]),e.next=14,p.repository.record(u);case 14:return e.abrupt("return",_objectSpread({id:c.id},f));case 17:throw e.prev=17,e.t0=e.catch(4),e.t0.handler=a,e.t0;case 21:case"end":return e.stop()}},e,null,[[4,17]])}));return function(e){return r.apply(this,arguments)}}()),_defineProperty(this,"getAggregate",function(){var t=_asyncToGenerator(regeneratorRuntime.mark(function e(r,t){var n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=4;break}return e.next=3,p.repository.create();case 3:return e.abrupt("return",e.sent);case 4:return e.next=6,p.repository.get(t);case 6:if(e.t0=e.sent,e.t0){e.next=14;break}if(e.t1=r.isCreateHandler,e.t1)return e.next=12,p.repository.create(t);e.next=13;break;case 12:e.t1=e.sent;case 13:e.t0=e.t1;case 14:if(n=e.t0){e.next=17;break}throw new _nodeCqrsLib.CommandHandlerError({message:"".concat(p.name," ").concat(t," not found"),handler:r,aggregate:n});case 17:return e.abrupt("return",n);case 18:case"end":return e.stop()}},e)}));return function(e,r){return t.apply(this,arguments)}}()),this.name=t,this.handlers=n,this.repository=o};exports.default=CommandExecutor;
//# sourceMappingURL=../maps/commandHandling/commandExecutor.js.map