UNPKG

eventric

Version:

Build JavaScript applications with Behaviour-driven Domain Design. Based on DDD, BDD, CQRS and EventSourcing.

2 lines 84.4 kB
!function(){"use strict";var e="undefined"==typeof window?global:window;if("function"!=typeof e.require){var n={},t={_load:function(e,r){var i=t._resolveFilename(e,r),a=n[i];if(!a)throw new Error('Cannot find module "'+i+'" from "'+r+'"');if(t._cache[i])return t._cache[i].exports;var u=o(i),c={id:i,exports:{}};return t._cache[i]=c,a.call(c.exports,c.exports,u,c),c.exports},_cache:{},_resolveFilename:function(e,t){var r=i(a(t),e);return n.hasOwnProperty(r)?r:(r=i(r,"./index"),n.hasOwnProperty(r)?r:e)}},r=function(e,n){return t._load(e,n)},i=function(){var e=/^\.\.?(\/|$)/;return function(n,t){var r,i,o=[];r=(e.test(t)?n+"/"+t:t).split("/");for(var a=0,u=r.length;u>a;a++)i=r[a],".."===i?o.pop():"."!==i&&""!==i&&o.push(i);return o.join("/")}}(),o=function(n){return function(t){return e.require(t,n)}},a=function(e){return e?e.split("/").slice(0,-1).join("/"):""};r.register=r.define=function(e,t){if("object"==typeof e)for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r]);else n[e]=t},r.list=function(){var e=[];for(var t in n)n.hasOwnProperty(t)&&e.push(t);return e},e.require=r,r.define("module",function(e,n,r){r.exports=t})}}(),require.register("eventric/index",function(e,n,t){t.exports=n("./src")}),require.register("es6-promise",function(){!function(){var e,n,t,r;!function(){var i={},o={};e=function(e,n,t){i[e]={deps:n,callback:t}},r=t=n=function(e){function t(n){if("."!==n.charAt(0))return n;for(var t=n.split("/"),r=e.split("/").slice(0,-1),i=0,o=t.length;o>i;i++){var a=t[i];if(".."===a)r.pop();else{if("."===a)continue;r.push(a)}}return r.join("/")}if(r._eak_seen=i,o[e])return o[e];if(o[e]={},!i[e])throw new Error("Could not find module "+e);for(var a,u=i[e],c=u.deps,s=u.callback,l=[],d=0,m=c.length;m>d;d++)l.push("exports"===c[d]?a={}:n(t(c[d])));var p=s.apply(this,l);return o[e]=a||p}}(),e("promise/all",["./utils","exports"],function(e,n){"use strict";function t(e){var n=this;if(!r(e))throw new TypeError("You must pass an array to all.");return new n(function(n,t){function r(e){return function(n){o(e,n)}}function o(e,t){u[e]=t,0===--c&&n(u)}var a,u=[],c=e.length;0===c&&n([]);for(var s=0;s<e.length;s++)a=e[s],a&&i(a.then)?a.then(r(s),t):o(s,a)})}var r=e.isArray,i=e.isFunction;n.all=t}),e("promise/asap",["exports"],function(e){"use strict";function n(){return function(){process.nextTick(i)}}function t(){var e=0,n=new c(i),t=document.createTextNode("");return n.observe(t,{characterData:!0}),function(){t.data=e=++e%2}}function r(){return function(){s.setTimeout(i,1)}}function i(){for(var e=0;e<l.length;e++){var n=l[e],t=n[0],r=n[1];t(r)}l=[]}function o(e,n){var t=l.push([e,n]);1===t&&a()}var a,u="undefined"!=typeof window?window:{},c=u.MutationObserver||u.WebKitMutationObserver,s="undefined"!=typeof global?global:void 0===this?window:this,l=[];a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?n():c?t():r(),e.asap=o}),e("promise/config",["exports"],function(e){"use strict";function n(e,n){return 2!==arguments.length?t[e]:void(t[e]=n)}var t={instrument:!1};e.config=t,e.configure=n}),e("promise/polyfill",["./promise","./utils","exports"],function(e,n,t){"use strict";function r(){var e;e="undefined"!=typeof global?global:"undefined"!=typeof window&&window.document?window:self;var n="Promise"in e&&"resolve"in e.Promise&&"reject"in e.Promise&&"all"in e.Promise&&"race"in e.Promise&&function(){var n;return new e.Promise(function(e){n=e}),o(n)}();n||(e.Promise=i)}var i=e.Promise,o=n.isFunction;t.polyfill=r}),e("promise/promise",["./config","./utils","./all","./race","./resolve","./reject","./asap","exports"],function(e,n,t,r,i,o,a,u){"use strict";function c(e){if(!y(e))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof c))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._subscribers=[],s(e,this)}function s(e,n){function t(e){f(n,e)}function r(e){g(n,e)}try{e(t,r)}catch(i){r(i)}}function l(e,n,t,r){var i,o,a,u,c=y(t);if(c)try{i=t(r),a=!0}catch(s){u=!0,o=s}else i=r,a=!0;p(n,i)||(c&&a?f(n,i):u?g(n,o):e===A?f(n,i):e===I&&g(n,i))}function d(e,n,t,r){var i=e._subscribers,o=i.length;i[o]=n,i[o+A]=t,i[o+I]=r}function m(e,n){for(var t,r,i=e._subscribers,o=e._detail,a=0;a<i.length;a+=3)t=i[a],r=i[a+n],l(n,t,r,o);e._subscribers=null}function p(e,n){var t,r=null;try{if(e===n)throw new TypeError("A promises callback cannot return that same promise.");if(x(n)&&(r=n.then,y(r)))return r.call(n,function(r){return t?!0:(t=!0,void(n!==r?f(e,r):h(e,r)))},function(n){return t?!0:(t=!0,void g(e,n))}),!0}catch(i){return t?!0:(g(e,i),!0)}return!1}function f(e,n){e===n?h(e,n):p(e,n)||h(e,n)}function h(e,n){e._state===P&&(e._state=S,e._detail=n,E.async(v,e))}function g(e,n){e._state===P&&(e._state=S,e._detail=n,E.async(b,e))}function v(e){m(e,e._state=A)}function b(e){m(e,e._state=I)}var E=e.config,x=(e.configure,n.objectOrFunction),y=n.isFunction,_=(n.now,t.all),D=r.race,w=i.resolve,j=o.reject,C=a.asap;E.async=C;var P=void 0,S=0,A=1,I=2;c.prototype={constructor:c,_state:void 0,_detail:void 0,_subscribers:void 0,then:function(e,n){var t=this,r=new this.constructor(function(){});if(this._state){var i=arguments;E.async(function(){l(t._state,r,i[t._state-1],t._detail)})}else d(this,r,e,n);return r},"catch":function(e){return this.then(null,e)}},c.all=_,c.race=D,c.resolve=w,c.reject=j,u.Promise=c}),e("promise/race",["./utils","exports"],function(e,n){"use strict";function t(e){var n=this;if(!r(e))throw new TypeError("You must pass an array to race.");return new n(function(n,t){for(var r,i=0;i<e.length;i++)r=e[i],r&&"function"==typeof r.then?r.then(n,t):n(r)})}var r=e.isArray;n.race=t}),e("promise/reject",["exports"],function(e){"use strict";function n(e){var n=this;return new n(function(n,t){t(e)})}e.reject=n}),e("promise/resolve",["exports"],function(e){"use strict";function n(e){if(e&&"object"==typeof e&&e.constructor===this)return e;var n=this;return new n(function(n){n(e)})}e.resolve=n}),e("promise/utils",["exports"],function(e){"use strict";function n(e){return t(e)||"object"==typeof e&&null!==e}function t(e){return"function"==typeof e}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}var i=Date.now||function(){return(new Date).getTime()};e.objectOrFunction=n,e.isFunction=t,e.isArray=r,e.now=i}),n("promise/polyfill").polyfill()}()}),require.register("eventric/src/index",function(e,n,t){var r,i,o=function(e,n){return function(){return e.apply(n,arguments)}},a=[].slice;i=n("es6-promise"),"undefined"!=typeof t&&"undefined"!=typeof process&&(global.Promise=i.Promise),r=function(){function e(){this._handleRemoteRPCRequest=o(this._handleRemoteRPCRequest,this),this._contexts={},this._params={},this._domainEventHandlers={},this._domainEventHandlersAll=[],this._processManagerService=n("eventric/src/process_manager"),this._processManagerInstances={},this._storeClasses={},this._remoteEndpoints=[],this.log=n("eventric/src/logger"),this.addRemoteEndpoint("inmemory",n("eventric/src/remote/inmemory").endpoint),this.addStore("inmemory",n("eventric/src/store_inmemory")),this.set("default domain events store","inmemory")}return e.prototype.set=function(e,n){return this._params[e]=n},e.prototype.get=function(e){return e?this._params[e]:this._params},e.prototype.addStore=function(e,n,t){return null==t&&(t={}),this._storeClasses[e]={Class:n,options:t}},e.prototype.getStores=function(){return this._storeClasses},e.prototype.context=function(e){var t,r,i;if(!e)throw i="Contexts must have a name",this.log.error(i),new Error(i);return t=n("eventric/src/context"),r=new t(e),this._delegateAllDomainEventsToGlobalHandlers(r),this._delegateAllDomainEventsToRemoteEndpoints(r),this._contexts[e]=r,r},e.prototype.getContext=function(e){return this._contexts[e]},e.prototype.remote=function(e){var t,r,i;if(!e)throw r="Missing context name",this.log.error(r),new Error(r);return t=n("eventric/src/remote"),i=new t(e)},e.prototype.addRemoteEndpoint=function(e,n){return this._remoteEndpoints.push(n),n.setRPCHandler(this._handleRemoteRPCRequest)},e.prototype._handleRemoteRPCRequest=function(e,n){var t,r;return t=this.getContext(e.contextName),t?e.method in t?t[e.method].apply(t,e.params).then(function(e){return n(null,e)})["catch"](function(e){return n(e)}):(r="Remote RPC method "+e.method+" not found on Context "+e.contextName,this.log.error(r),n(r,null)):(r="Tried to handle Remote RPC with not registered context "+e.contextName,this.log.error(r),n(r,null))},e.prototype._delegateAllDomainEventsToGlobalHandlers=function(e){return e.subscribeToAllDomainEvents(function(n){return function(t){var r,i,o,a,u;for(i=n.getDomainEventHandlers(e.name,t.name),u=[],o=0,a=i.length;a>o;o++)r=i[o],u.push(r(t));return u}}(this))},e.prototype._delegateAllDomainEventsToRemoteEndpoints=function(e){return e.subscribeToAllDomainEvents(function(n){return function(t){return n._remoteEndpoints.forEach(function(n){return n.publish(e.name,t.name,t),t.aggregate?n.publish(e.name,t.name,t.aggregate.id,t):void 0})}}(this))},e.prototype.subscribeToDomainEvent=function(){var e,n,t,r,i,o,u;return r=2<=arguments.length?a.call(arguments,0,u=arguments.length-1):(u=0,[]),n=arguments[u++],e=r[0],t=r[1],null==e&&(e="all"),null==t&&(t="all"),"all"===e&&"all"===t?this._domainEventHandlersAll.push(n):(null==(i=this._domainEventHandlers)[e]&&(i[e]={}),null==(o=this._domainEventHandlers[e])[t]&&(o[t]=[]),this._domainEventHandlers[e][t].push(n))},e.prototype.getDomainEventHandlers=function(e,n){var t,r,i,o,a;return[].concat(null!=(t=null!=(r=this._domainEventHandlers[e])?r[n]:void 0)?t:[],null!=(i=null!=(o=this._domainEventHandlers[e])?o.all:void 0)?i:[],null!=(a=this._domainEventHandlersAll)?a:[])},e.prototype.generateUid=function(e){var n,t;return n=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},t=e||"-",n()+n()+t+n()+t+n()+t+n()+t+n()+n()+n()},e.prototype.addProcessManager=function(e,n){return this._processManagerService.add(e,n,this)},e.prototype.nextTick=function(e){var n,t;return(n=null!=(t="undefined"!=typeof process&&null!==process?process.nextTick:void 0)?t:setTimeout)(function(){return e()})},e.prototype.defaults=function(e,n){var t,r,i,o;for(t=[].concat(Object.keys(e),Object.keys(n)),i=0,o=t.length;o>i;i++)r=t[i],!e[r]&&n[r]&&(e[r]=n[r]);return e},e.prototype.eachSeries=function(e,n,t){var r,i;return t=t||function(){},Array.isArray(e)&&e.length?(r=0,(i=function(){n(e[r],function(n){n?(t(n),t=function(){}):(++r,r>=e.length?t():i())})})()):t()},e}(),t.exports=new r}),require.register("eventric/src/index.spec",function(){describe("Index",function(){return describe("#context",function(){var e,n;return e=null,n=null,beforeEach(function(){return e={subscribeToAllDomainEvents:sandbox.stub()},n=sandbox.stub().returns(e),mockery.registerMock("eventric/src/context",n)}),it("should throw an error if no name given for the context",function(){return expect(function(){return new eventric.context}).to["throw"](Error)}),it("should create a context instance",function(){var e;return e=eventric.context("someContext"),expect(n).to.have.been.calledWithNew}),it("should register global domain event handlers on the context",function(){var n;return n=eventric.context("someContext"),expect(e.subscribeToAllDomainEvents).to.have.been.called})}),describe("#set/#get",function(){return it("should save given key/value pairs",function(){var e,n;return e=Math.random(),n=Math.random(),eventric.set(e,n),expect(eventric.get(e)).to.equal(n)}),it("should return undefined for a not set key",function(){var e;return e=Math.random(),expect(eventric.get(e)).to.not.exist}),it("should overwrite already defined values",function(){var e;return e=Math.random(),eventric.set(e,"1"),eventric.set(e,"2"),expect(eventric.get(e)).to.equal("2")})})})}),require.register("eventric/src/logger",function(e,n,t){t.exports={_logLevel:1,setLogLevel:function(e){return this._logLevel=function(){switch(e){case"debug":return 0;case"warn":return 1;case"info":return 2;case"error":return 3}}()},debug:function(){return this._logLevel>0?void 0:console.log.apply(console,arguments)},warn:function(){return this._logLevel>1?void 0:console.log.apply(console,arguments)},info:function(){return this._logLevel>2?void 0:console.log.apply(console,arguments)},error:function(){return this._logLevel>3?void 0:console.log.apply(console,arguments)}}}),require.register("eventric/src/store_inmemory",function(e,n,t){var r,i,o=[].slice;i=["domain_events","projections"],r=function(){function e(){}return e.prototype._domainEvents={},e.prototype._projections={},e.prototype.initialize=function(){var e,n,t,r,i;return r=arguments[0],t=3<=arguments.length?o.call(arguments,1,i=arguments.length-1):(i=1,[]),e=arguments[i++],this._contextName=r,n=t[0],this._domainEventsCollectionName=""+this._contextName+".DomainEvents",this._projectionCollectionName=""+this._contextName+".Projections",this._domainEvents[this._domainEventsCollectionName]=[],e()},e.prototype.saveDomainEvent=function(e,n){return this._domainEvents[this._domainEventsCollectionName].push(e),n(null,e)},e.prototype.findAllDomainEvents=function(e){return e(null,this._domainEvents[this._domainEventsCollectionName])},e.prototype.findDomainEventsByName=function(e,n){var t,r;return t=e instanceof Array?function(n){return e.indexOf(n)>-1}:function(n){return n===e},r=this._domainEvents[this._domainEventsCollectionName].filter(function(e){return t(e.name)}),n(null,r)},e.prototype.findDomainEventsByNameAndAggregateId=function(e,n,t){var r,i,o;return i=e instanceof Array?function(n){return e.indexOf(n)>-1}:function(n){return n===e},r=n instanceof Array?function(e){return n.indexOf(e)>-1}:function(e){return e===n},o=this._domainEvents[this._domainEventsCollectionName].filter(function(e){var n;return i(e.name)&&r(null!=(n=e.aggregate)?n.id:void 0)}),t(null,o)},e.prototype.findDomainEventsByAggregateId=function(e,n){var t,r;return t=e instanceof Array?function(n){return e.indexOf(n)>-1}:function(n){return n===e},r=this._domainEvents[this._domainEventsCollectionName].filter(function(e){var n;return t(null!=(n=e.aggregate)?n.id:void 0)}),n(null,r)},e.prototype.findDomainEventsByAggregateName=function(e,n){var t,r;return t=e instanceof Array?function(n){return e.indexOf(n)>-1}:function(n){return n===e},r=this._domainEvents[this._domainEventsCollectionName].filter(function(e){var n;return t(null!=(n=e.aggregate)?n.name:void 0)}),n(null,r)},e.prototype.getProjectionStore=function(e,n){var t,r,i;return null==(t=this._projections)[i=this._projectionCollectionName]&&(t[i]={}),null==(r=this._projections[this._projectionCollectionName])[e]&&(r[e]={}),n(null,this._projections[this._projectionCollectionName][e])},e.prototype.clearProjectionStore=function(e,n){var t,r,i;return null==(t=this._projections)[i=this._projectionCollectionName]&&(t[i]={}),null==(r=this._projections[this._projectionCollectionName])[e]&&(r[e]={}),delete this._projections[this._projectionCollectionName][e],n(null,null)},e.prototype.checkSupport=function(e){return i.indexOf(e)>-1},e}(),t.exports=r}),require.register("eventric/src/context/context",function(e,n,t){var r,i,o,a,u,c,s,l=function(e,n){return function(){return e.apply(n,arguments)}},d={}.hasOwnProperty,m=function(e,n){function t(){this.constructor=e}for(var r in n)d.call(n,r)&&(e[r]=n[r]);return t.prototype=n.prototype,e.prototype=new t,e.__super__=n.prototype,e},p=[].slice;c=n("eventric"),u=n("eventric/src/context/repository"),i=n("eventric/src/context/domain_event"),o=n("eventric/src/event_bus"),a=n("eventric/src/pub_sub"),s=n("eventric/src/projection"),r=function(e){function n(e){this.name=e,this.clearProjectionStore=l(this.clearProjectionStore,this),this.getProjectionStore=l(this.getProjectionStore,this),this.publishDomainEvent=l(this.publishDomainEvent,this),this.emitDomainEvent=l(this.emitDomainEvent,this),n.__super__.constructor.apply(this,arguments),this._initialized=!1,this._params=c.get(),this._di={},this._aggregateRootClasses={},this._adapterClasses={},this._adapterInstances={},this._commandHandlers={},this._queryHandlers={},this._domainEventClasses={},this._domainEventHandlers={},this._projectionClasses=[],this._repositoryInstances={},this._domainServices={},this._storeClasses={},this._storeInstances={},this._eventBus=new o}return m(n,e),n.prototype.log=c.log,n.prototype.set=function(e,n){return this._params[e]=n,this},n.prototype.get=function(e){return this._params[e]},n.prototype.emitDomainEvent=function(e,n){var t,r;if(t=this.getDomainEvent(e),!t)throw new Error("Tried to emitDomainEvent '"+e+"' which is not defined");return r=this._createDomainEvent(e,t,n),this.getDomainEventsStore().saveDomainEvent(r,function(e){return function(){return e.publishDomainEvent(r,function(){})}}(this))},n.prototype.publishDomainEvent=function(e,n){return null==n&&(n=function(){}),this._eventBus.publishDomainEvent(e,n)},n.prototype._createDomainEvent=function(e,n,t){return new i({id:c.generateUid(),name:e,context:this.name,payload:new n(t)})},n.prototype.addStore=function(e,n,t){return null==t&&(t={}),this._storeClasses[e]={Class:n,options:t},this},n.prototype.defineDomainEvent=function(e,n){return this._domainEventClasses[e]=n,this},n.prototype.defineDomainEvents=function(e){var n,t;for(t in e)n=e[t],this.defineDomainEvent(t,n);return this},n.prototype.addCommandHandler=function(e,n){return this._commandHandlers[e]=function(t){return function(){var r,i,o,a,s,l,d;r={id:c.generateUid(),name:e,params:null!=(l=arguments[0])?l:null},s={},d=t._di;for(o in d)i=d[o],s[o]=i;return a=null,s.$repository=function(e){var n,i;return a||(n=t._aggregateRootClasses[e],i=new u({aggregateName:e,AggregateRoot:n,context:t}),a=i),a.setCommand(r),a},n.apply(s,arguments)}}(this),this},n.prototype.addCommandHandlers=function(e){var n,t;for(t in e)n=e[t],this.addCommandHandler(t,n);return this},n.prototype.addQueryHandler=function(e,n){return this._queryHandlers[e]=function(e){return function(){return n.apply(e._di,arguments)}}(this),this},n.prototype.addQueryHandlers=function(e){var n,t;for(t in e)n=e[t],this.addQueryHandler(t,n);return this},n.prototype.addAggregate=function(e,n){return this._aggregateRootClasses[e]=n,this},n.prototype.addAggregates=function(e){var n,t;for(t in e)n=e[t],this.addAggregate(t,n);return this},n.prototype.subscribeToDomainEvent=function(e,n,t){var r;return null==t&&(t={}),r=function(e){return function(){return n.apply(e._di,arguments)}}(this),this._eventBus.subscribeToDomainEvent(e,r,t),this},n.prototype.subscribeToDomainEventWithAggregateId=function(e,n,t,r){var i;return null==r&&(r={}),i=function(e){return function(){return t.apply(e._di,arguments)}}(this),this._eventBus.subscribeToDomainEventWithAggregateId(e,n,i,r)},n.prototype.subscribeToAllDomainEvents=function(e,n){var t;return null==n&&(n={}),t=function(n){return function(){return e.apply(n._di,arguments)}}(this),this._eventBus.subscribeToAllDomainEvents(t,n)},n.prototype.subscribeToDomainEvents=function(e){var n,t;for(n in e)t=e[n],this.subscribeToDomainEvent(n,t);return this},n.prototype.addDomainService=function(e,n){return this._domainServices[e]=function(e){return function(){return n.apply(e._di,arguments)}}(this),this},n.prototype.addDomainServices=function(e){var n,t;for(t in e)n=e[t],this.addDomainService(t,n);return this},n.prototype.addAdapter=function(e,n){return this._adapterClasses[e]=n,this},n.prototype.addAdapters=function(e){var n,t;for(n in e)t=e[n],this.addAdapter(n,t);return this},n.prototype.addProjection=function(e,n){return this._projectionClasses.push({name:e,"class":n}),this},n.prototype.addProjections=function(e){var n,t;for(t in e)n=e[t],this.addProjection(t,n);return this},n.prototype.initialize=function(e){return null==e&&(e=function(){}),new Promise(function(n){return function(t,r){return n.log.debug("["+n.name+"] Initializing"),n.log.debug("["+n.name+"] Initializing Store"),n._initializeStores().then(function(){return n.log.debug("["+n.name+"] Finished initializing Store"),n._di={$adapter:function(){return n.getAdapter.apply(n,arguments)},$query:function(){return n.query.apply(n,arguments)},$domainService:function(){return n.getDomainService(arguments[0]).apply(n,[arguments[1],arguments[2]])},$projectionStore:function(){return n.getProjectionStore.apply(n,arguments)},$emitDomainEvent:function(){return n.emitDomainEvent.apply(n,arguments)}},n.log.debug("["+n.name+"] Initializing Adapters"),n._initializeAdapters()}).then(function(){return n.log.debug("["+n.name+"] Finished initializing Adapters"),n.log.debug("["+n.name+"] Initializing Projections"),n._initializeProjections()}).then(function(){return n.log.debug("["+n.name+"] Finished initializing Projections"),n.log.debug("["+n.name+"] Finished initializing"),n._initialized=!0,e(),t()})["catch"](function(n){return e(n),r(n)})}}(this))},n.prototype._initializeStores=function(){return new Promise(function(e){return function(n,t){var r,i,o,a;o=[],a=c.defaults(e._storeClasses,c.getStores());for(i in a)r=a[i],o.push({name:i,Class:r.Class,options:r.options});return c.eachSeries(o,function(n,t){return e.log.debug("["+e.name+"] Initializing Store "+n.name),e._storeInstances[n.name]=new n.Class,e._storeInstances[n.name].initialize(e,n.options,function(){return e.log.debug("["+e.name+"] Finished initializing Store "+n.name),t()})},function(e){return e?t(e):n()})}}(this))},n.prototype._initializeProjections=function(){return new Promise(function(e){return function(n,t){return c.eachSeries(e._projectionClasses,function(n,r){var i,o;return i=null,o=n.name,e.log.debug("["+e.name+"] Initializing Projection "+o),s.initializeInstance(n,{},e).then(function(){return e.log.debug("["+e.name+"] Finished initializing Projection "+o),r()})["catch"](function(e){return t(e)})},function(e){return e?t(e):n()})}}(this))},n.prototype._initializeAdapters=function(){return new Promise(function(e){return function(n){var t,r,i,o;o=e._adapterClasses;for(i in o)r=o[i],t=new e._adapterClasses[i],"function"==typeof t.initialize&&t.initialize(),e._adapterInstances[i]=t;return n()}}(this))},n.prototype.getProjection=function(e){return s.getInstance(e)},n.prototype.getAdapter=function(e){return this._adapterInstances[e]},n.prototype.getDomainEvent=function(e){return this._domainEventClasses[e]},n.prototype.getDomainService=function(e){return this._domainServices[e]},n.prototype.getDomainEventsStore=function(){var e;return e=this.get("default domain events store"),this._storeInstances[e]},n.prototype.saveDomainEvent=function(e){return new Promise(function(n){return function(t,r){return n.getDomainEventsStore().saveDomainEvent(e,function(i,o){return n.publishDomainEvent(e),i?r(i):t(o)})}}(this))},n.prototype.findAllDomainEvents=function(){return new Promise(function(e){return function(n,t){return e.getDomainEventsStore().findAllDomainEvents(function(e,r){return e?t(e):n(r)})}}(this))},n.prototype.findDomainEventsByName=function(){var e;return e=1<=arguments.length?p.call(arguments,0):[],new Promise(function(n){return function(t,r){var i;return(i=n.getDomainEventsStore()).findDomainEventsByName.apply(i,p.call(e).concat([function(e,n){return e?r(e):t(n)}]))}}(this))},n.prototype.findDomainEventsByNameAndAggregateId=function(){var e;return e=1<=arguments.length?p.call(arguments,0):[],new Promise(function(n){return function(t,r){var i;return(i=n.getDomainEventsStore()).findDomainEventsByNameAndAggregateId.apply(i,p.call(e).concat([function(e,n){return e?r(e):t(n)}]))}}(this))},n.prototype.findDomainEventsByAggregateId=function(){var e;return e=1<=arguments.length?p.call(arguments,0):[],new Promise(function(n){return function(t,r){var i;return(i=n.getDomainEventsStore()).findDomainEventsByAggregateId.apply(i,p.call(e).concat([function(e,n){return e?r(e):t(n)}]))}}(this))},n.prototype.findDomainEventsByAggregateName=function(){var e;return e=1<=arguments.length?p.call(arguments,0):[],new Promise(function(n){return function(t,r){var i;return(i=n.getDomainEventsStore()).findDomainEventsByAggregateName.apply(i,p.call(e).concat([function(e,n){return e?r(e):t(n)}]))}}(this))},n.prototype.getProjectionStore=function(e,n,t){return new Promise(function(r){return function(i,o){var a;return r._storeInstances[e]?r._storeInstances[e].getProjectionStore(n,function(e,n){return"function"==typeof t&&t(e,n),e?o(e):i(n)}):(a="Requested Store with name "+e+" not found",r.log.error(a),"function"==typeof t&&t(a,null),o(a))}}(this))},n.prototype.clearProjectionStore=function(e,n,t){return new Promise(function(r){return function(i,o){var a;return r._storeInstances[e]?r._storeInstances[e].clearProjectionStore(n,function(e,n){return"function"==typeof t&&t(e,n),e?o(e):i(n)}):(a="Requested Store with name "+e+" not found",r.log.error(a),"function"==typeof t&&t(a,null),o(a))}}(this))},n.prototype.getEventBus=function(){return this._eventBus},n.prototype.command=function(e,n){return this.log.debug("Got Command",e),new Promise(function(t){return function(r,i){var o;return t._initialized?t._commandHandlers[e]?t._commandHandlers[e](n,function(n,o){return t.log.debug("Completed Command",e),c.nextTick(function(){return n?i(n):r(o)})}):(o="Given command "+e+" not registered on context",t.log.error(o),o=new Error(o),i(o)):(o="Context not initialized yet",t.log.error(o),o=new Error(o),i(o))}}(this))},n.prototype.query=function(e,n){return this.log.debug("Got Query",e),new Promise(function(t){return function(r,i){var o;return t._initialized?t._queryHandlers[e]?t._queryHandlers[e](n,function(n,o){return t.log.debug("Completed Query",e),c.nextTick(function(){return n?i(n):r(o)})}):(o="Given query "+e+" not registered on context",t.log.error(o),o=new Error(o),i(o)):(o="Context not initialized yet",t.log.error(o),o=new Error(o),void i(o))}}(this))},n.prototype.enableWaitingMode=function(){return this.set("waiting mode",!0)},n.prototype.disableWaitingMode=function(){return this.set("waiting mode",!1)},n.prototype.isWaitingModeEnabled=function(){return this.get("waiting mode")},n}(a),t.exports=r}),require.register("eventric/src/context/context.spec",function(e,n){describe("Context",function(){var e,t,r;return e=null,t=function(){function e(){}return e}(),r=null,beforeEach(function(){return r={subscribeToDomainEvent:sandbox.stub(),subscribeToDomainEventWithAggregateId:sandbox.stub(),publishDomainEvent:sandbox.stub()},mockery.registerMock("eventric/src/event_bus",sandbox.stub().returns(r)),mockery.registerMock("eventric/src/context/repository",t),e=n("eventric/src/context")}),describe("#initialize",function(){return it("should instantiate all registered projections",function(){var n,t;return t=new e("exampleContext"),n=function(){function e(){}return e.prototype.stores=["inmemory"],e}(),t.addProjection("SomeProjection",n),t.initialize().then(function(){return t.getProjectionStore("inmemory","SomeProjection",function(e,n){return expect(n).to.deep.equal({})})})}),it("should instantiate and initialize all registered adapters",function(n){var t,r;return r=new e("exampleContext"),t=sandbox.stub(),r.addAdapter("Adapter",t),r.initialize(function(){return function(){return expect(t).to.have.been.calledWithNew,n()}}(this))})}),describe("#command",function(){return describe("given the context was not initialized yet",function(){return it("should callback with an error",function(n){var t;return t=new e("exampleContext"),t.command("getSomething")["catch"](function(e){return expect(e).to.be.an.instanceOf(Error),n()})})}),describe("given the command has no registered handler",function(){return it("should call the callback with a command not found error",function(n){var t;return t=new e("exampleContext"),t.initialize(function(){return function(){var e;return e=sinon.spy(),t.command("doSomething",{id:42,foo:"bar"})["catch"](function(e){return expect(e).to.be.an["instanceof"](Error),n()})}}(this))})}),describe("has a registered handler",function(){return it("should execute the command handler",function(n){var t,r;return t=sandbox.stub(),r=new e("exampleContext"),r.initialize(function(){return function(){var e;return r.addCommandHandler("doSomething",t),e={foo:"bar"},r.command("doSomething",e),expect(t.calledWith(e,sinon.match.func)).to.be["true"],n()}}(this))})})}),describe("#query",function(){var n;return n=null,beforeEach(function(){return n=new e("exampleContext")}),describe("given the context was not initialized yet",function(){return it("should callback with an error",function(e){return n.query("getSomething")["catch"](function(n){return expect(n).to.be.an.instanceOf(Error),e()})})}),describe("given the query has no matching queryhandler",function(){return it("should callback with an error",function(e){return n.initialize(function(){return function(){return n.query("getSomething")["catch"](function(n){return expect(n).to.be.an.instanceOf(Error),e()})}}(this))})}),describe("given the query has a matching queryhandler",function(){return it("should call the queryhandler function",function(e){var t;return t=sandbox.stub().yields(null,"result"),n.addQueryHandler("getSomething",t),n.initialize(function(){return function(){return n.query("getSomething").then(function(n){return expect(n).to.equal("result"),expect(t).to.have.been.calledWith,e()})}}(this))})})}),describe("#emitDomainEvent",function(){return beforeEach(function(n){var t;return t=new e("ExampleContext"),t.defineDomainEvent("WhatSoEver",function(){}),t.initialize(function(){return function(){return t.emitDomainEvent("WhatSoEver"),n()}}(this))}),it("should publish the DomainEvent on the EventBus",function(){return expect(r.publishDomainEvent).to.have.been.called})})})}),require.register("eventric/src/context/feature_adapter.spec",function(){describe("Adapter Feature",function(){return describe("given we created and initialized some example context including an aggregate",function(){var e;return e=null,beforeEach(function(){var n;return e=eventric.context("exampleContext"),e.addAggregate("Example",n=function(){function e(){}return e}())}),describe("when we use a command which calls a previously added adapter function",function(){var n;return n=null,beforeEach(function(){return n=function(){function e(){}return e.prototype.someAdapterFunction=sandbox.stub(),e}(),e.addAdapter("exampleAdapter",n),e.addCommandHandler("doSomething",function(e,n){return this.$adapter("exampleAdapter").someAdapterFunction(),n()})}),it("then it should have called the adapter function",function(){return e.initialize(function(){return function(){return e.command("doSomething").then(function(){return expect(n.prototype.someAdapterFunction).to.have.been.calledOnce})}}(this))})})})})}),require.register("eventric/src/context/feature_command_aggregate.spec",function(){describe("Command Aggregate Feature",function(){return describe("given we created and initialized some example context including an aggregate",function(){var e;return e=null,beforeEach(function(n){var t;return e=eventric.context("exampleContext"),e.addAggregate("Example",t=function(){function e(){}return e}(),e.defineDomainEvent("ExampleCreated",function(){}),e.defineDomainEvent("SomethingHappened",function(e){return this.someId=e.someId,this.someProp=e.someProp,this.entity=e.entity}),t=function(){function e(){}return e.prototype.create=function(e){return this.$emitDomainEvent("ExampleCreated"),e()},e.prototype.doSomething=function(e){return this.$emitDomainEvent("SomethingHappened",{someId:e,someProp:"foo"})},e.prototype.handleExampleCreated=function(){return this.entities=[]},e.prototype.handleSomethingHappened=function(e){return this.someId=e.payload.someId,this.someProp=e.payload.someProp},e}()),e.addAggregate("Example",t),e.addCommandHandlers({CreateExample:function(e,n){var t;return t=null,this.$repository("Example").create().then(function(e){return function(n){return e.$repository("Example").save(n)}}(this)).then(function(e){return n(null,e)})},DoSomething:function(e,n){return this.$repository("Example").findById(e.id).then(function(n){return function(t){return t.doSomething([1]),n.$repository("Example").save(e.id) }}(this)).then(function(){return n()})}}),e.initialize(function(){return n()})}),describe("when we send a command to the context",function(){return it("then it should have triggered the correct DomainEvent",function(n){return e.subscribeToDomainEvent("SomethingHappened",function(e){return expect(e.payload.someProp).to.equal("foo"),expect(e.name).to.equal("SomethingHappened"),n()}),e.command("CreateExample").then(function(n){return e.command("DoSomething",{id:n})})})}),describe("when we send multiple commands to the context",function(){return it("then it should execute all commands as expected",function(n){var t;return t=0,e.subscribeToDomainEvent("SomethingHappened",function(){return t++,2===t?(expect(t).to.equal(2),n()):void 0}),e.command("CreateExample").then(function(n){return e.command("DoSomething",{id:n}),e.command("DoSomething",{id:n})})})})})})}),require.register("eventric/src/context/feature_create_aggregate.spec",function(){describe("Create Aggregate Feature",function(){return describe("given we created and initialized some example context including an aggregate",function(){return describe("when we command the context to create an aggregate",function(){return it("should call the create function on the aggregate with the given params",function(e){var n,t;return t=eventric.context("Examplecontext"),t.defineDomainEvent("ExampleCreated",function(){}),n=function(){function e(){}return e.prototype.create=function(e,n,t){return this.$emitDomainEvent("ExampleCreated"),t()},e}(),sandbox.spy(n.prototype,"create"),t.addAggregate("Example",n),t.addCommandHandler("CreateExample",function(e,n){return this.$repository("Example").create(e.name,e.email).then(function(e){return function(n){return e.$repository("Example").save(n)}}(this)).then(function(){return n()})}),t.initialize(function(){return t.command("CreateExample",{name:"MyName",email:"MyEmail"}).then(function(){return expect(n.prototype.create).to.have.been.calledWith("MyName","MyEmail",sinon.match.func),e()})})})})})})}),require.register("eventric/src/context/feature_domain_service.spec",function(){describe("DomainService Feature",function(){return describe("given we created and initialized some example context including a domain service",function(){var e,n;return e=null,n=null,beforeEach(function(){return e=eventric.context("exampleContext"),e.defineDomainEvent("SomethingHappened",function(){}),e.addCommandHandler("DoSomething",function(e,n){return this.$domainService("DoSomethingSpecial",e,n)}),n=sandbox.stub(),e.addDomainService("DoSomethingSpecial",function(e,t){return n(e.special),this.$emitDomainEvent("SomethingHappened"),t(null,!0)})}),describe("when we call the command",function(){return it("then the domain service should be executed correctly",function(t){return e.initialize(function(){return function(){return e.command("DoSomething",{special:"awesome"}).then(function(){return expect(n).to.have.been.calledWith("awesome"),t()})}}(this))}),it("then should have emitted the correct domain event",function(n){return e.subscribeToDomainEvent("SomethingHappened",function(e){return expect(e.name).to.be.ok,n()}),e.initialize(function(){return function(){return e.command("DoSomething",{special:"awesome"})}}(this))})})})})}),require.register("eventric/src/context/feature_query_projection.spec",function(){describe("Query Projection Feature",function(){return describe("given we created and initialized some example context including a queryhandler",function(){var e;return e=null,beforeEach(function(n){return e=eventric.context("exampleContext"),e.addQueryHandler("getExample",function(e,n){return this.$projectionStore("inmemory","ExampleProjection",function(e,t){return n(null,t)})}),e.initialize(function(){return function(){return n()}}(this))}),describe("when we query the context",function(){return it("then the query should return the correct result",function(){return e.query("getExample",{id:1}).then(function(){return function(e){return expect(e).to.deep.equal({})}}(this))})})})})}),require.register("eventric/src/context/feature_subscribe_with_aggregate_id.spec",function(){describe("Subscribe to event with aggregate id Feature",function(){return describe("given we created and initialized some example context including an aggregate",function(){var e;return e=null,beforeEach(function(n){var t;return e=eventric.context("exampleContext"),e.addAggregate("Example",t=function(){function e(){}return e}(),e.defineDomainEvent("ExampleCreated",function(){}),e.defineDomainEvent("SomethingHappened",function(){}),t=function(){function e(){}return e.prototype.create=function(e){return this.$emitDomainEvent("ExampleCreated"),e()},e.prototype.doSomething=function(){return this.$emitDomainEvent("SomethingHappened")},e}()),e.addAggregate("Example",t),e.addCommandHandlers({CreateExample:function(e,n){var t;return t=null,this.$repository("Example").create().then(function(e){return function(n){return e.$repository("Example").save(n)}}(this)).then(function(e){return n(null,e)})},DoSomething:function(e,n){return this.$repository("Example").findById(e.id).then(function(n){return function(t){return t.doSomething(),n.$repository("Example").save(e.id)}}(this)).then(function(){return n()})}}),e.initialize(function(){return e.enableWaitingMode(),n()})}),describe("when we subscribe to an event with a specific aggregate id",function(){return it("should notify the domain event subscriber if the aggregate id matches",function(){var n;return n=sandbox.spy(),e.command("CreateExample").then(function(t){return e.subscribeToDomainEventWithAggregateId("SomethingHappened",t,n),e.command("DoSomething",{id:t})}).then(function(){return expect(n).to.have.been.called})}),it("should not notify the domain event subscriber if the aggregate does not match",function(){var n;return n=sandbox.spy(),e.command("CreateExample").then(function(t){var r;return r=t+"12345",e.subscribeToDomainEventWithAggregateId("SomethingHappened",r,n),e.command("DoSomething",{id:t})}).then(function(){return expect(n).not.to.have.been.called})})})})})}),require.register("eventric/src/context/feature_waiting_command_aggregate.spec",function(){describe("Waiting Command Aggregate Feature",function(){return describe("given we created and initialized a context with an aggregate",function(){var e;return e=null,beforeEach(function(){var n;return n=function(){function e(){}return e.prototype.create=function(e){return this.$emitDomainEvent("ExampleCreated",{}),e()},e.prototype.handleExampleCreated=function(){},e}(),e=eventric.context("exampleContext"),e.defineDomainEvent("ExampleCreated",function(){}),e.addAggregate("Example",n),e.addCommandHandlers({CreateExample:function(e,n){var t;return t=null,this.$repository("Example").create().then(function(e){return function(n){return e.$repository("Example").save(n)}}(this)).then(function(e){return n(null,e)})}}),e.enableWaitingMode()}),describe("and an according projection and query handler",function(){return beforeEach(function(n){return e.addProjection("ExampleProjection",function(){return{stores:["inmemory"],handleExampleCreated:function(e,n){return setTimeout(function(e){return function(){return e.$store.inmemory.exampleCreated=!0,n()}}(this),500)}}}),e.addQueryHandler("getExample",function(e,n){return this.$projectionStore("inmemory","ExampleProjection",function(e,t){return n(null,t)})}),e.initialize(function(){return n()})}),describe("when we enable waiting mode and send a command",function(){return it("should wait for the projection to be updated before returning from the command",function(n){return e.command("CreateExample",{}).then(function(){return e.query("getExample",{})}).then(function(e){return setTimeout(function(){return expect(e.exampleCreated).to.be["true"],n()},0)})})})}),describe("and an async domain event handler",function(){var n;return n=null,beforeEach(function(t){var r;return n=sandbox.spy(),r=function(e,t){return setTimeout(function(){return n(),t()},500)},e.subscribeToDomainEvent("ExampleCreated",r,{isAsync:!0}),e.initialize(function(){return t()})}),describe("when we enable waiting mode and send a command",function(){return it("should wait for the domain event handler to be finished before returning from the command",function(t){return e.command("CreateExample",{}).then(function(){return setTimeout(function(){return expect(n).to.have.been.called,t()},0)})})})})})})}),require.register("eventric/src/context/index",function(e,n,t){t.exports=n("./context")}),require.register("eventric/src/event_bus/event_bus",function(e,n,t){var r,i;i=n("eventric/src/pub_sub"),r=function(){function e(){this._pubSub=new i}return e.prototype.subscribeToDomainEventWithAggregateId=function(e,n,t,r){return null==r&&(r={}),this.subscribeToDomainEvent(""+e+"/"+n,t,r)},e.prototype.subscribeToDomainEvent=function(e,n,t){return null==t&&(t={}),t.isAsync?this._pubSub.subscribeAsync(e,n):this._pubSub.subscribe(e,n)},e.prototype.subscribeToAllDomainEvents=function(e){return this._pubSub.subscribe("DomainEvent",e)},e.prototype.publishDomainEvent=function(e,n){return null==n&&(n=function(){}),this._publish("publish",e,n)},e.prototype.publishDomainEventAndWait=function(e,n){return null==n&&(n=function(){}),this._publish("publishAsync",e,n)},e.prototype._publish=function(e,n,t){return null==t&&(t=function(){}),this._pubSub[e]("DomainEvent",n,function(r){return function(){return r._pubSub[e](n.name,n,function(){return n.aggregate&&n.aggregate.id?r._pubSub[e](""+n.name+"/"+n.aggregate.id,n,t):t()})}}(this))},e}(),t.exports=r}),require.register("eventric/src/event_bus/event_bus.spec",function(e,n){describe("EventBus",function(){var e,t;return e=null,t=null,beforeEach(function(){var r;return t={subscribe:sandbox.stub(),subscribeAsync:sandbox.stub(),publish:sandbox.stub(),publishAsync:sandbox.stub()},mockery.registerMock("eventric/src/pub_sub",sandbox.stub().returns(t)),r=n("eventric/src/event_bus"),e=new r}),describe("#subscribeToDomainEvent",function(){return it("should subscribe to the event with given event name",function(){var n;return n=function(){},e.subscribeToDomainEvent("SomeEvent",n),expect(t.subscribe).to.have.been.calledWith("SomeEvent",n)})}),describe("#subscribeToDomainEventWithAggregateId",function(){return it("should subscribe to the event with given event name and aggregate id",function(){var n;return n=function(){},e.subscribeToDomainEventWithAggregateId("SomeEvent",12345,n),expect(t.subscribe).to.have.been.calledWith("SomeEvent/12345",n)})}),describe("#subscribeToAllDomainEvents",function(){return it('should subscribe to the generic event "DomainEvent"',function(){var n;return n=function(){},e.subscribeToAllDomainEvents(n),expect(t.subscribe).to.have.been.calledWith("DomainEvent",n)})}),describe("#publishDomainEvent",function(){return beforeEach(function(){}),it('should publish a generic "DomainEvent" event',function(){var n;return n={name:"SomeEvent"},e.publishDomainEvent(n,function(){}),expect(t.publish).to.have.been.calledWith("DomainEvent",n)}),it("should then publish the given event",function(){var n;return t.publish.withArgs("DomainEvent").yields(),n={name:"SomeEvent"},e.publishDomainEvent(n,function(){}),expect(t.publish).to.have.been.calledWith("SomeEvent",n)}),describe("given an event with an aggregate id",function(){return it("should publish an aggregate id specific event",function(){var n;return t.publish.withArgs("DomainEvent").yields(),t.publish.withArgs("SomeEvent").yields(),n={name:"SomeEvent",aggregate:{id:12345}},e.publishDomainEvent(n,function(){}),expect(t.publish).to.have.been.calledWith("SomeEvent/12345",n)})})}),describe("#publishDomainEventAndWait",function(){return it('should publish a generic "DomainEvent" event asynchronously',function(){var n;return n={name:"SomeEvent"},e.publishDomainEventAndWait(n,function(){}),expect(t.publishAsync).to.have.been.calledWith("DomainEvent",n)}),it("should then publish the given event asynchronously",function(){var n;return t.publishAsync.withArgs("DomainEvent").yields(),n={name:"SomeEvent"},e.publishDomainEventAndWait(n,function(){}),expect(t.publishAsync).to.have.been.calledWith("SomeEvent",n)}),describe("given an event with an aggregate id",function(){return it("should publish an aggregate id specific event",function(){var n;return t.publishAsync.withArgs("DomainEvent").yields(),t.publishAsync.withArgs("SomeEvent").yields(),n={name:"SomeEvent",aggregate:{id:12345}},e.publishDomainEventAndWait(n,function(){}),expect(t.publishAsync).to.have.been.calledWith("SomeEvent/12345",n)})})})})}),require.register("eventric/src/event_bus/feature_global_domain_event_handler.spec",function(){describe("Global Domain Event Handler Feature",function(){return describe("given we created and initialized some example context and added a global domain event handler",function(){var e,n,t,r;return t=null,r=null,n=null,e=null,beforeEach(function(){return r=sandbox.stub(),eventric.subscribeToDomainEvent("exampleContext","ExampleCreated",r),n=sandbox.stub(),eventric.subscribeToDomainEvent("exampleContext",n),e=sandbox.stub(),eventric.subscribeToDomainEvent(e),t=eventric.context("exampleContext"),t.defineDomainEvent("ExampleCreated",function(){}),t.addAggregate("Example",function(){return{create:function(e){return this.$emitDomainEvent("ExampleCreated"),e()}}}),t.addCommandHandler("createExample",function(e,n){return this.$repository("Example").create().then(function(e){return function(n){return e.$repository("Example").save(n)}}(this)).then(function(){return function(){return n(null)}}(this))})}),describe("when DomainEvents got emitted which the handler subscribed to",function(){return it("then it should execute the registered global domain event handler",function(i){return t.initialize(function(){return function(){return t.subscribeToDomainEvent("ExampleCreated",function(){return expect(r).to.have.been.called,expect(n).to.have.been.called,expect(e).to.have.been.called,i()}),t.command("createExample")}}(this))})})})})}),require.register("eventric/src/event_bus/index",function(e,n,t){t.exports=n("./event_bus")}),require.register("eventric/src/process_manager/index",function(e,n,t){t.exports=n("./process_manager")}),require.register("eventric/src/process_manager/process_manager",function(e,n,t){var r;r=function(){function e(){this._processManagerInstances={}}return e.prototype.add=function(e,n,t){var r,i,o,a,u;a=n.initializeWhen,u=[];for(r in a)o=a[r],u.push(function(){var a,u,c;for(c=[],a=0,u=o.length;u>a;a++)i=o[a],c.push(t.subscribeToDomainEvent(r,i,function(i){return function(o){return i._spawnProcessManager(e,n["class"],r,o,t)}}(this)));return c}.call(this));return u},e.prototype._spawnProcessManager=function(e,n,t,r,i){var o,a,u,c,s,l,d;c=i.generateUid(),u=new n,u.$endProcess=function(n){return function(){return n._endProcessManager(e,c)}}(this),o=[];for(a in u)s=u[a],0===a.indexOf("from")&&"function"==typeof s&&o.push(a);return this._subscribeProcessManagerToDomainEvents(u,o,i),u.initialize(r),null==(l=this._processManagerInstances)[e]&&(l[e]={}),null==(d=this._processManagerInstances[e])[c]&&(d[c]={}),this._processManagerInstances[e][c]=u},e.prototype._endProcessManager=function(e,n){return delete this._processManagerInstances[e][n]},e.prototype._subscribeProcessManagerToDomainEvents=function(e,n,t){return t.subscribeToDomainEvent(function(t){return function(r){var i,o,a,u;for(u=[],o=0,a=n.length;a>o;o++)i=n[o],u.push("from"+r.context+"_handle"+r.name===i?t._applyDomainEventToProcessManager(i,r,e):void 0);return u}}(this))},e.prototype._applyDomainEventToProcessManager=function(e,n,t){var r;return t[e]?t[e](n):r=new Error("Tried to apply DomainEvent '"+domainEventName+"' to Projection without a matching handle method")},e}(),t.exports=new r}),require.register("eventric/src/process_manager/process_manager_feature.spec",function(){describe("ProcessManager",function(){return describe("given we created a context and added a ProcessManager",function(){var e,n,t;return t=null,n=null,e=null,beforeEach(function(){var r;return t=sandbox.stub(),n=sandbox.stub(),eventric.addProcessManager("ExampleProcess",{initializeWhen:{Example:["ExampleCreated"]},"class":function(){return{initialize:function(n){return t(),e.command("ChangeExample",{id:n.aggregate.id})},fromExample_handleExampleChanged:function(){return n(),this.$endProcess()}}}}),e=eventric.context("Example"),e.defineDomainEvents({ExampleCreated:function(){},ExampleChanged:function(){}}),r=function(){function e(){}return e.prototype.create=function(e){return this.$emitDomainEvent("ExampleCreated"),e()},e.prototype.doSomething=function(){return this.$emitDomainEvent("ExampleChanged")},e}(),e.addAggregate("Example",r),e.addCommandHandler("CreateExample",function(e,n){return this.$repository("Example").create().then(function(e){return function(n){return e.$repository("Example").save(n)}}(this)).then(function(){return function(){return n()}}(this))}),e.addCommandHandler("ChangeExample",function(e,n){return this.$repository("Example").findById(e.id).then(function(n){return function(t){return t.doSomething(),n.$repository("Example").save(e.id)}}(this)).then(function(){return function(){return n()}}(this))}),e.initialize()}),describe("when a DomainEvent gets emitted the ProcessManager defined as initializeWhen",function(){return it("then it should execute and end the process",function(r){return e.subscribeToDomainEvent("ExampleChanged",function(){return expect(t).to.have.been.called,expect(n).to.have.been.called,r()}),e.command("CreateExample")})})})})}),require.register("eventric/src/projection/index",function(e,n,t){t.exports=n("./projection")}),require.register("eventric/src/projection/projection",function(e,n,t){var r,i,o=function(e,n){return function(){return e.apply(n,arguments)}};i=n("eventric"),r=function(){function e(){this._applyDomainEventToProjection=o(this._applyDomainEventToProjection,this),this.log=i.log,this._handlerFunctions={},this._projectionInstances={},this._domainEventsApplied={}}return e.pro