New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eventric

Package Overview
Dependencies
Maintainers
3
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventric - npm Package Compare versions

Comparing version 0.11.1 to 0.11.2

2

bower.json
{
"name": "eventric",
"version": "0.11.1",
"version": "0.11.2",
"homepage": "https://github.com/efacilitation/eventric",

@@ -5,0 +5,0 @@ "authors": [

@@ -1,2 +0,2 @@

!function(){"use strict";var t="undefined"==typeof window?global:window;if("function"!=typeof t.require){var e={},n={_load:function(t,r){var i=n._resolveFilename(t,r),s=e[i];if(!s)throw new Error('Cannot find module "'+i+'" from "'+r+'"');if(n._cache[i])return n._cache[i].exports;var u=o(i),a={id:i,exports:{}};return n._cache[i]=a,s.call(a.exports,a.exports,u,a),a.exports},_cache:{},_resolveFilename:function(t,n){var r=i(s(n),t);return e.hasOwnProperty(r)?r:(r=i(r,"./index"),e.hasOwnProperty(r)?r:t)}},r=function(t,e){return n._load(t,e)},i=function(){var t=/^\.\.?(\/|$)/;return function(e,n){var r,i,o=[];r=(t.test(n)?e+"/"+n:n).split("/");for(var s=0,u=r.length;u>s;s++)i=r[s],".."===i?o.pop():"."!==i&&""!==i&&o.push(i);return o.join("/")}}(),o=function(e){return function(n){return t.require(n,e)}},s=function(t){return t?t.split("/").slice(0,-1).join("/"):""};r.register=r.define=function(t,n){if("object"==typeof t)for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);else e[t]=n},r.list=function(){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t},t.require=r,r.define("module",function(t,e,r){r.exports=n})}}(),require.register("eventric/eventric",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}},o=[].slice;r=function(){function t(){this._handleRemoteRPCRequest=i(this._handleRemoteRPCRequest,this),this.EventBus=e("./event_bus"),this.Remote=e("./remote"),this.Context=e("./context"),this.DomainEvent=e("./domain_event"),this.Aggregate=e("./aggregate"),this.Repository=e("./repository"),this.Projection=e("./projection"),this.Logger=e("./logger"),this.RemoteInMemory=e("./remote/inmemory"),this.StoreInMemory=e("./store/inmemory"),this.GlobalContext=e("./global_context"),this.log=this.Logger,this._contexts={},this._params={},this._domainEventHandlers={},this._domainEventHandlersAll=[],this._storeClasses={},this._remoteEndpoints=[],this._globalProjectionClasses=[],this._globalContext=new this.GlobalContext(this),this._projectionService=new this.Projection(this,this._globalContext),this.addRemoteEndpoint("inmemory",this.RemoteInMemory.endpoint),this.addStore("inmemory",this.StoreInMemory),this.set("default domain events store","inmemory")}return t.prototype.set=function(t,e){return this._params[t]=e},t.prototype.get=function(t){return t?this._params[t]:this._params},t.prototype.addStore=function(t,e,n){return null==n&&(n={}),this._storeClasses[t]={Class:e,options:n}},t.prototype.getStores=function(){return this._storeClasses},t.prototype.context=function(t){var e,n;if(!t)throw n="Contexts must have a name",this.log.error(n),new Error(n);return e=new this.Context(t,this),this._delegateAllDomainEventsToGlobalHandlers(e),this._delegateAllDomainEventsToRemoteEndpoints(e),this._contexts[t]=e,e},t.prototype.initializeGlobalProjections=function(){return Promise.all(this._globalProjectionClasses.map(function(t){return function(e){return t._projectionService.initializeInstance("",new e,{})}}(this)))},t.prototype.addGlobalProjection=function(t){return this._globalProjectionClasses.push(t)},t.prototype.getRegisteredContextNames=function(){return Object.keys(this._contexts)},t.prototype.getContext=function(t){return this._contexts[t]},t.prototype.remote=function(t){var e;if(!t)throw e="Missing context name",this.log.error(e),new Error(e);return new this.Remote(t,this)},t.prototype.addRemoteEndpoint=function(t,e){return this._remoteEndpoints.push(e),e.setRPCHandler(this._handleRemoteRPCRequest)},t.prototype._handleRemoteRPCRequest=function(t,e){var n,r;return n=this.getContext(t.contextName),n?-1===this.Remote.ALLOWED_RPC_OPERATIONS.indexOf(t.functionName)?(r=new Error("RPC operation '"+t.functionName+"' not allowed"),void e(r,null)):t.functionName in n?n[t.functionName].apply(n,t.args).then(function(t){return e(null,t)})["catch"](function(t){return e(t)}):(r=new Error("Remote RPC function "+t.functionName+" not found on Context "+t.contextName),this.log.error(r.stack),void e(r,null)):(r=new Error("Tried to handle Remote RPC with not registered context "+t.contextName),this.log.error(r.stack),void e(r,null))},t.prototype._delegateAllDomainEventsToGlobalHandlers=function(t){return t.subscribeToAllDomainEvents(function(e){return function(n){var r,i,o,s,u;for(i=e.getDomainEventHandlers(t.name,n.name),u=[],o=0,s=i.length;s>o;o++)r=i[o],u.push(r(n));return u}}(this))},t.prototype._delegateAllDomainEventsToRemoteEndpoints=function(t){return t.subscribeToAllDomainEvents(function(e){return function(n){return e._remoteEndpoints.forEach(function(e){return e.publish(t.name,n.name,n),n.aggregate?e.publish(t.name,n.name,n.aggregate.id,n):void 0})}}(this))},t.prototype.subscribeToDomainEvent=function(){var t,e,n,r,i,s,u;return t=2<=arguments.length?o.call(arguments,0,u=arguments.length-1):(u=0,[]),i=arguments[u++],r=t[0],s=t[1],null==r&&(r="all"),null==s&&(s="all"),"all"===r&&"all"===s?this._domainEventHandlersAll.push(i):(null==(e=this._domainEventHandlers)[r]&&(e[r]={}),null==(n=this._domainEventHandlers[r])[s]&&(n[s]=[]),this._domainEventHandlers[r][s].push(i))},t.prototype.getDomainEventHandlers=function(t,e){var n,r,i,o,s;return[].concat(null!=(n=null!=(r=this._domainEventHandlers[t])?r[e]:void 0)?n:[],null!=(i=null!=(o=this._domainEventHandlers[t])?o.all:void 0)?i:[],null!=(s=this._domainEventHandlersAll)?s:[])},t.prototype.generateUid=function(t){var e,n;return e=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},n=t||"-",e()+e()+n+e()+n+e()+n+e()+n+e()+e()+e()},t.prototype.defaults=function(t,e){var n,r,i,o;for(n=[].concat(Object.keys(t),Object.keys(e)),r=0,o=n.length;o>r;r++)i=n[r],!t[i]&&e[i]&&(t[i]=e[i]);return t},t.prototype.mixin=function(t,e){var n,r;r=[];for(n in e)r.push(t[n]=e[n]);return r},t}(),n.exports=r}),require.register("eventric/index",function(t,e,n){n.exports=new(e("./eventric"))}),require.register("eventric/aggregate/aggregate",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}};r=function(){function t(t,e,n,r){this._context=t,this._eventric=e,this._name=n,this.getDomainEvents=i(this.getDomainEvents,this),this.emitDomainEvent=i(this.emitDomainEvent,this),this._domainEvents=[],this.instance=new r,this.instance.$emitDomainEvent=this.emitDomainEvent}return t.prototype.emitDomainEvent=function(t,e){var n,r,i;if(n=this._context.getDomainEvent(t),!n)throw new Error("Tried to emitDomainEvent '"+t+"' which is not defined");return r={id:this.id,name:this._name},i=this._context.createDomainEvent(t,n,e,r),this._domainEvents.push(i),this._handleDomainEvent(t,i),this._eventric.log.debug("Created and Handled DomainEvent in Aggregate",i)},t.prototype._handleDomainEvent=function(t,e){return this.instance["handle"+t]?this.instance["handle"+t](e):this._eventric.log.debug("Tried to handle the DomainEvent '"+t+"' without a matching handle method")},t.prototype.getDomainEvents=function(){return this._domainEvents},t.prototype.applyDomainEvents=function(t){var e,n,r,i;for(i=[],n=0,r=t.length;r>n;n++)e=t[n],i.push(this._applyDomainEvent(e));return i},t.prototype._applyDomainEvent=function(t){return this._handleDomainEvent(t.name,t)},t}(),n.exports=r}),require.register("eventric/aggregate/index",function(t,e,n){n.exports=e("./aggregate")}),require.register("eventric/context/context",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}},o=[].slice;r=function(){function t(t,e){this.name=t,this._eventric=e,this._getAggregateRepository=i(this._getAggregateRepository,this),this.clearProjectionStore=i(this.clearProjectionStore,this),this.getProjectionStore=i(this.getProjectionStore,this),this.emitDomainEvent=i(this.emitDomainEvent,this),this._isInitialized=!1,this._isDestroyed=!1,this._params=this._eventric.get(),this._di={},this._aggregateClasses={},this._commandHandlers={},this._queryHandlers={},this._domainEventClasses={},this._domainEventHandlers={},this._projectionClasses={},this._repositoryInstances={},this._storeClasses={},this._storeInstances={},this._pendingPromises=[],this._eventBus=new this._eventric.EventBus(this._eventric),this.projectionService=new this._eventric.Projection(this._eventric,this),this.log=this._eventric.log}return t.prototype.set=function(t,e){return this._params[t]=e,this},t.prototype.get=function(t){return this._params[t]},t.prototype.addStore=function(t,e,n){return null==n&&(n={}),this._storeClasses[t]={Class:e,options:n},this},t.prototype.defineDomainEvent=function(t,e){return this._domainEventClasses[t]=e,this},t.prototype.defineDomainEvents=function(t){var e,n;for(n in t)e=t[n],this.defineDomainEvent(n,e);return this},t.prototype.addCommandHandlers=function(t){var e,n;for(n in t)e=t[n],this._commandHandlers[n]=e;return this},t.prototype.addQueryHandlers=function(t){var e,n;for(n in t)e=t[n],this._queryHandlers[n]=e;return this},t.prototype.addAggregate=function(t,e){return this._aggregateClasses[t]=e,this},t.prototype.subscribeToAllDomainEvents=function(t){var e;return e=function(e){return function(){return t.apply(e._di,arguments)}}(this),this._eventBus.subscribeToAllDomainEvents(e)},t.prototype.subscribeToDomainEvent=function(t,e){var n;return n=function(t){return function(){return e.apply(t._di,arguments)}}(this),this._eventBus.subscribeToDomainEvent(t,n)},t.prototype.subscribeToDomainEvents=function(t){var e,n,r;r=[];for(e in t)n=t[e],r.push(this.subscribeToDomainEvent(e,n));return r},t.prototype.subscribeToDomainEventWithAggregateId=function(t,e,n){var r;return r=function(t){return function(){return n.apply(t._di,arguments)}}(this),this._eventBus.subscribeToDomainEventWithAggregateId(t,e,r)},t.prototype.addProjection=function(t,e){return this._projectionClasses[t]=e,this},t.prototype.addProjections=function(t){var e,n;for(n in t)e=t[n],this.addProjection(n,e);return this},t.prototype.getProjectionInstance=function(t){return this.projectionService.getInstance(t)},t.prototype.destroyProjectionInstance=function(t){return this.projectionService.destroyInstance(t,this)},t.prototype.initialize=function(){return this.log.debug("["+this.name+"] Initializing"),this.log.debug("["+this.name+"] Initializing Store"),this._initializeStores().then(function(t){return function(){return t.log.debug("["+t.name+"] Finished initializing Store"),t._di={$query:function(){return t.query.apply(t,arguments)},$projectionStore:function(){return t.getProjectionStore.apply(t,arguments)},$emitDomainEvent:function(){return t.emitDomainEvent.apply(t,arguments)}}}}(this)).then(function(t){return function(){return t.log.debug("["+t.name+"] Initializing Projections"),t._initializeProjections()}}(this)).then(function(t){return function(){return t.log.debug("["+t.name+"] Finished initializing Projections"),t.log.debug("["+t.name+"] Finished initializing"),t._isInitialized=!0}}(this))},t.prototype._initializeStores=function(){var t,e,n,r,i;i=[],e=this._eventric.defaults(this._storeClasses,this._eventric.getStores());for(r in e)n=e[r],i.push({name:r,Class:n.Class,options:n.options});return t=new Promise(function(t){return t()}),i.forEach(function(e){return function(n){return e.log.debug("["+e.name+"] Initializing Store "+n.name),e._storeInstances[n.name]=new n.Class,t=t.then(function(){return e._storeInstances[n.name].initialize(e,n.options)}).then(function(){return e.log.debug("["+e.name+"] Finished initializing Store "+n.name)})}}(this)),t},t.prototype._initializeProjections=function(){var t,e,n,r,i;r=new Promise(function(t){return t()}),n=[],i=this._projectionClasses;for(e in i)t=i[e],n.push({name:e,"class":t});return n.forEach(function(t){return function(e){var n;return n=null,t.log.debug("["+t.name+"] Initializing Projection "+e.name),r=r.then(function(){return t.projectionService.initializeInstance(e.name,e["class"],{})}).then(function(n){return t.log.debug("["+t.name+"] Finished initializing Projection "+e.name)})}}(this)),r},t.prototype.emitDomainEvent=function(t,e){var n;return this._isDestroyed?void Promise.reject(new Error("Context "+this.name+" was destroyed, cannot emit domain event "+t)):(n=new Promise(function(n){return function(r,i){var o,s;if(o=n.getDomainEvent(t),!o)throw new Error("Tried to emitDomainEvent '"+t+"' which is not defined");return s=n.createDomainEvent(t,o,e),n.getDomainEventsStore().saveDomainEvent(s).then(function(){return n.getEventBus().publishDomainEvent(s)["catch"](function(t){return null==t&&(t={}),n._eventric.log.error(t.stack||t)}),r(s)})["catch"](i)}}(this)),this._addPendingPromise(n),n)},t.prototype.createDomainEvent=function(t,e,n,r){var i;return i={},e.apply(i,[n]),new this._eventric.DomainEvent({id:this._eventric.generateUid(),name:t,aggregate:r,context:this.name,payload:i})},t.prototype.initializeProjectionInstance=function(t,e){var n;return this._projectionClasses[t]?this.projectionService.initializeInstance(t,this._projectionClasses[t],e):(n="Given projection "+t+" not registered on context",this.log.error(n),n=new Error(n))},t.prototype.getProjection=function(t){return this.projectionService.getInstance(t)},t.prototype.getDomainEvent=function(t){return this._domainEventClasses[t]},t.prototype.getDomainEventsStore=function(){var t;return t=this.get("default domain events store"),this._storeInstances[t]},t.prototype.getEventBus=function(){return this._eventBus},t.prototype.findDomainEventsByName=function(){var t;return t=1<=arguments.length?o.call(arguments,0):[],new Promise(function(e){return function(n,r){var i;return(i=e.getDomainEventsStore()).findDomainEventsByName.apply(i,o.call(t).concat([function(t,e){return t?r(t):n(e)}]))}}(this))},t.prototype.findDomainEventsByNameAndAggregateId=function(){var t;return t=1<=arguments.length?o.call(arguments,0):[],new Promise(function(e){return function(n,r){var i;return(i=e.getDomainEventsStore()).findDomainEventsByNameAndAggregateId.apply(i,o.call(t).concat([function(t,e){return t?r(t):n(e)}]))}}(this))},t.prototype.getProjectionStore=function(t,e){return new Promise(function(n){return function(r,i){var o;return n._storeInstances[t]?n._storeInstances[t].getProjectionStore(e).then(function(t){return r(t)})["catch"](function(t){return i(t)}):(o="Requested Store with name "+t+" not found",n.log.error(o),i(o))}}(this))},t.prototype.clearProjectionStore=function(t,e){return new Promise(function(n){return function(r,i){var o;return n._storeInstances[t]?n._storeInstances[t].clearProjectionStore(e).then(function(){return r()})["catch"](function(t){return i(t)}):(o="Requested Store with name "+t+" not found",n.log.error(o),i(o))}}(this))},t.prototype.command=function(t,e){var n;return this._isDestroyed?void Promise.reject(new Error("Context "+this.name+" was destroyed, cannot execute command "+t+" with arguments "+JSON.stringify(e))):(n=new Promise(function(n){return function(r,i){var o;if(n._verifyContextIsInitialized(t),!n._commandHandlers[t])throw new Error("Given command "+t+" not registered on context");return o=n._getCommandServicesToInject(),Promise.resolve(n._commandHandlers[t].apply(o,[e])).then(function(e){return n.log.debug("Completed Command",t),r(e)})["catch"](i)}}(this)),this._addPendingPromise(n),n)},t.prototype._getCommandServicesToInject=function(){var t,e,n,r;r={},n=this._di;for(e in n)t=n[e],r[e]=t;return r.$aggregate={create:function(t){return function(){var e,n,r;return e=arguments[0],n=2<=arguments.length?o.call(arguments,1):[],r=t._getAggregateRepository(e),r.create.apply(r,n)}}(this),load:function(t){return function(e,n){var r;return r=t._getAggregateRepository(e),r.findById(n)}}(this)},r},t.prototype._getAggregateRepository=function(t){var e,n,r;return n||(n={}),n[t]||(e=this._aggregateClasses[t],r=new this._eventric.Repository({aggregateName:t,AggregateClass:e,context:this,eventric:this._eventric}),n[t]=r),n[t]},t.prototype._addPendingPromise=function(t){var e;return e=t["catch"](function(){}),this._pendingPromises.push(e),e.then(function(t){return function(){return t._pendingPromises.splice(t._pendingPromises.indexOf(e),1)}}(this))},t.prototype.query=function(t,e){return new Promise(function(n){return function(r,i){var o;return n.log.debug("Got Query",t),n._verifyContextIsInitialized(t),n._queryHandlers[t]?Promise.resolve(n._queryHandlers[t].apply(n._di,[e])).then(function(e){return n.log.debug("Completed Query "+t+" with Result "+e),r(e)})["catch"](i):(o="Given query "+t+" not registered on context",n.log.error(o),o=new Error(o),i(o))}}(this))},t.prototype._verifyContextIsInitialized=function(t){if(!this._isInitialized)throw new Error("Context "+this.name+" not initialized yet, cannot execute "+t)},t.prototype.destroy=function(){return Promise.all(this._pendingPromises).then(function(t){return function(){return t._eventBus.destroy().then(function(){return t._isDestroyed=!0})}}(this))},t}(),n.exports=r}),require.register("eventric/context/index",function(t,e,n){n.exports=e("./context")}),require.register("eventric/domain_event/domain_event",function(t,e,n){var r;r=function(){function t(t){this.id=t.id,this.name=t.name,this.payload=t.payload,this.aggregate=t.aggregate,this.context=t.context,this.timestamp=(new Date).getTime()}return t}(),n.exports=r}),require.register("eventric/domain_event/index",function(t,e,n){n.exports=e("./domain_event")}),require.register("eventric/event_bus/event_bus",function(t,e,n){var r,i;i=e("./subscriber"),r=function(){function t(){this._subscribers=[],this._subscriberId=0,this._eventPublishQueue=Promise.resolve(),this._isDestroyed=!1}return t.prototype.subscribeToAllDomainEvents=function(t){return this._subscribe("*",t)},t.prototype.subscribeToDomainEvent=function(t,e){return this._subscribe(t,e)},t.prototype.subscribeToDomainEventWithAggregateId=function(t,e,n){return this._subscribe(t+"/"+e,n)},t.prototype._subscribe=function(t,e){return new Promise(function(n){return function(r){var o;return o=new i({eventName:t,subscriberFunction:e,subscriberId:n._getNextSubscriberId()}),n._subscribers.push(o),r(o.subscriberId)}}(this))},t.prototype._getNextSubscriberId=function(){return this._subscriberId++},t.prototype.publishDomainEvent=function(t){return new Promise(function(e){return function(n,r){var i;return e._verifyPublishIsPossible(t),i=function(){return e._notifySubscribers(t).then(n)["catch"](r)},e._enqueueEventPublishing(i)}}(this))},t.prototype._verifyPublishIsPossible=function(t){var e,n;if(this._isDestroyed)throw e="Event Bus was destroyed, cannot publish "+t.name+"\nwith payload "+JSON.stringify(t.payload),(null!=(n=t.aggregate)?n.id:void 0)&&(e+=" and aggregate id "+t.aggregate.id),new Error(e)},t.prototype._notifySubscribers=function(t){return Promise.resolve().then(function(e){return function(){var n;return n=e._getSubscribersForDomainEvent(t),Promise.all(n.map(function(e){return e.subscriberFunction(t)}))}}(this))},t.prototype._getSubscribersForDomainEvent=function(t){var e,n;return n=this._subscribers.filter(function(t){return"*"===t.eventName}),n=n.concat(this._subscribers.filter(function(e){return e.eventName===t.name})),(null!=(e=t.aggregate)?e.id:void 0)&&(n=n.concat(this._subscribers.filter(function(e){return e.eventName===t.name+"/"+t.aggregate.id}))),n},t.prototype._enqueueEventPublishing=function(t){return this._eventPublishQueue=this._eventPublishQueue.then(t)},t.prototype.unsubscribe=function(t){return Promise.resolve().then(function(e){return function(){return e._subscribers=e._subscribers.filter(function(e){return e.subscriberId!==t})}}(this))},t.prototype.destroy=function(){return this._waitForEventPublishQueue().then(function(t){return function(){return t._isDestroyed=!0}}(this))},t.prototype._waitForEventPublishQueue=function(){var t;return t=this._eventPublishQueue,t.then(function(e){return function(){return e._eventPublishQueue!==t?e._waitForEventPublishQueue():void 0}}(this))},t}(),n.exports=r}),require.register("eventric/event_bus/index",function(t,e,n){n.exports=e("./event_bus")}),require.register("eventric/event_bus/subscriber",function(t,e,n){var r;r=function(){function t(t){this.eventName=t.eventName,this.subscriberFunction=t.subscriberFunction,this.subscriberId=t.subscriberId}return t}(),n.exports=r}),require.register("eventric/global_context/global_context",function(t,e,n){var r,i=[].slice;r=function(){function t(t){this._eventric=t,this.name="Global"}return t.prototype.findDomainEventsByName=function(){var t,e;return t=1<=arguments.length?i.call(arguments,0):[],e=this._getAllContexts().map(function(e){return e.findDomainEventsByName.apply(e,t)}),Promise.all(e).then(function(t){return function(e){var n;return n=t._combineDomainEventsByContext(e),t._sortDomainEventsByTimestamp(n)}}(this))},t.prototype.subscribeToDomainEvent=function(t,e){var n;return n=this._getAllContexts().map(function(n){return n.subscribeToDomainEvent(t,e)}),Promise.all(n)},t.prototype._getAllContexts=function(){var t;return t=this._eventric.getRegisteredContextNames(),t.map(function(t){return function(e){return t._eventric.remote(e)}}(this))},t.prototype._combineDomainEventsByContext=function(t){return t.reduce(function(t,e){return t.concat(e)},[])},t.prototype._sortDomainEventsByTimestamp=function(t){return t.sort(function(t,e){return t.timestamp-e.timestamp})},t}(),n.exports=r}),require.register("eventric/global_context/index",function(t,e,n){n.exports=e("./global_context")}),require.register("eventric/logger/index",function(t,e,n){n.exports=e("./logger")}),require.register("eventric/logger/logger",function(t,e,n){n.exports={_logLevel:1,setLogLevel:function(t){return this._logLevel=function(){switch(t){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/projection/index",function(t,e,n){n.exports=e("./projection")}),require.register("eventric/projection/projection",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}};r=function(){function t(t,e){this._eventric=t,this._context=e,this._applyDomainEventToProjection=i(this._applyDomainEventToProjection,this),this.log=this._eventric.log,this._handlerFunctions={},this._projectionInstances={},this._domainEventsApplied={}}return t.prototype.initializeInstance=function(t,e,n){return new Promise(function(r){return function(i,o){var s,u,a,c,l,h,p;if(l="function"==typeof e?new e:e,r._context._di){p=r._context._di;for(a in p)u=p[a],l[a]=u}return h=r._eventric.generateUid(),s=null,l.$subscribeHandlersWithAggregateId=function(t){return s=t},r.log.debug("["+r._context.name+"] Clearing ProjectionStores "+l.stores+" of "+t),c=null,r._clearProjectionStores(l.stores,t).then(function(){return r.log.debug("["+r._context.name+"] Finished clearing ProjectionStores of "+t),r._injectStoresIntoProjection(t,l)}).then(function(){return r._callInitializeOnProjection(t,l,n)}).then(function(){return r.log.debug("["+r._context.name+"] Replaying DomainEvents against Projection "+t),r._parseEventNamesFromProjection(l)}).then(function(t){return c=t,r._applyDomainEventsFromStoreToProjection(h,l,c,s)}).then(function(){return r.log.debug("["+r._context.name+"] Finished Replaying DomainEvents against Projection "+t),r._subscribeProjectionToDomainEvents(h,t,l,c,s)}).then(function(){return r._projectionInstances[h]=l,i(h)})["catch"](o)}}(this))},t.prototype._callInitializeOnProjection=function(t,e,n){return new Promise(function(r){return function(i,o){return e.initialize?(r.log.debug("["+r._context.name+"] Calling initialize on Projection "+t),e.initialize(n,function(){return r.log.debug("["+r._context.name+"] Finished initialize call on Projection "+t),i(e)})):(r.log.debug("["+r._context.name+"] No initialize function on Projection "+t+" given, skipping"),i(e))}}(this))},t.prototype._injectStoresIntoProjection=function(t,e){var n,r;return n=Promise.resolve(),e.stores?(null==e.$store&&(e.$store={}),null!=(r=e.stores)&&r.forEach(function(r){return function(i){return r.log.debug("["+r._context.name+"] Injecting ProjectionStore "+i+" into Projection "+t),n=n.then(function(){return r._context.getProjectionStore(i,t)}).then(function(n){return n?(e.$store[i]=n,r.log.debug("["+r._context.name+"] Finished Injecting ProjectionStore "+i+" into Projection "+t)):void 0})}}(this)),n):n},t.prototype._clearProjectionStores=function(t,e){var n;return n=Promise.resolve(),t?(t.forEach(function(t){return function(r){return t.log.debug("["+t._context.name+"] Clearing ProjectionStore "+r+" for "+e),n=n.then(function(){return t._context.clearProjectionStore(r,e)}).then(function(){return t.log.debug("["+t._context.name+"] Finished clearing ProjectionStore "+r+" for "+e)})}}(this)),n):n},t.prototype._parseEventNamesFromProjection=function(t){return new Promise(function(e,n){var r,i,o,s;i=[];for(o in t)s=t[o],0===o.indexOf("handle")&&"function"==typeof s&&(r=o.replace(/^handle/,""),i.push(r));return e(i)})},t.prototype._applyDomainEventsFromStoreToProjection=function(t,e,n,r){var i;return this._domainEventsApplied[t]={},i=r?this._context.findDomainEventsByNameAndAggregateId(n,r):this._context.findDomainEventsByName(n),i.then(function(n){return function(r){var i;if(r&&0!==r.length)return i=Promise.resolve(),r.forEach(function(r){return i=i.then(function(){return n._applyDomainEventToProjection(r,e)}).then(function(){return n._domainEventsApplied[t][r.id]=!0})}),i}}(this))},t.prototype._subscribeProjectionToDomainEvents=function(t,e,n,r,i){var o,s;return o=function(e){return function(r){return e._domainEventsApplied[t][r.id]?void 0:e._applyDomainEventToProjection(r,n).then(function(){e._domainEventsApplied[t][r.id]=!0})}}(this),s=Promise.resolve(),r.forEach(function(e){return function(n){return s=s.then(function(){return i?e._context.subscribeToDomainEventWithAggregateId(n,i,o):e._context.subscribeToDomainEvent(n,o)}).then(function(n){var r;return null==(r=e._handlerFunctions)[t]&&(r[t]=[]),e._handlerFunctions[t].push(n)})}}(this)),s},t.prototype._applyDomainEventToProjection=function(t,e){return Promise.resolve().then(function(n){return function(){return e["handle"+t.name]?e["handle"+t.name](t):void n.log.debug("Tried to apply DomainEvent '"+t.name+"' to Projection without a matching handle method")}}(this))},t.prototype.getInstance=function(t){return this._projectionInstances[t]},t.prototype.destroyInstance=function(t){var e,n,r,i,o;if(!this._handlerFunctions[t])return this.log.error("Missing attribute projectionId");for(o=[],r=this._handlerFunctions[t],e=0,n=r.length;n>e;e++)i=r[e],o.push(this._context.unsubscribeFromDomainEvent(i));return delete this._handlerFunctions[t],delete this._projectionInstances[t],Promise.all(o)},t}(),n.exports=r}),require.register("eventric/remote/index",function(t,e,n){n.exports=e("./remote")}),require.register("eventric/remote/remote",function(t,e,n){var r;r=function(){function t(t,n){this._contextName=t,this._eventric=n,this.name=this._contextName,this.InMemoryRemote=e("./inmemory"),this._params={},this._clients={},this._projectionClasses={},this._projectionInstances={},this._handlerFunctions={},this.projectionService=new this._eventric.Projection(this._eventric,this),this.addClient("inmemory",this.InMemoryRemote.client),this.set("default client","inmemory"),this._exposeRpcOperationsAsMemberFunctions()}return t.ALLOWED_RPC_OPERATIONS=["command","query","findDomainEventsByName","findDomainEventsByNameAndAggregateId"],t.prototype._exposeRpcOperationsAsMemberFunctions=function(){return t.ALLOWED_RPC_OPERATIONS.forEach(function(t){return function(e){return t[e]=function(){return t._rpc(e,arguments)}}}(this))},t.prototype.set=function(t,e){return this._params[t]=e,this},t.prototype.get=function(t){return this._params[t]},t.prototype.subscribeToAllDomainEvents=function(t){var e,n;return n=this.get("default client"),e=this.getClient(n),e.subscribe(this._contextName,t)},t.prototype.subscribeToDomainEvent=function(t,e){var n,r;return r=this.get("default client"),n=this.getClient(r),n.subscribe(this._contextName,t,e)},t.prototype.subscribeToDomainEventWithAggregateId=function(t,e,n){var r,i;return i=this.get("default client"),r=this.getClient(i),r.subscribe(this._contextName,t,e,n)},t.prototype.unsubscribeFromDomainEvent=function(t){var e,n;return n=this.get("default client"),e=this.getClient(n),e.unsubscribe(t)},t.prototype._rpc=function(t,e){var n,r;return r=this.get("default client"),n=this.getClient(r),n.rpc({contextName:this._contextName,functionName:t,args:Array.prototype.slice.call(e)})},t.prototype.addClient=function(t,e){return this._clients[t]=e,this},t.prototype.getClient=function(t){return this._clients[t]},t.prototype.addProjection=function(t,e){return this._projectionClasses[t]=e,this},t.prototype.initializeProjection=function(t,e){return this.projectionService.initializeInstance("",t,e)},t.prototype.initializeProjectionInstance=function(t,e){var n;return this._projectionClasses[t]?this.projectionService.initializeInstance(t,this._projectionClasses[t],e):(n="Given projection "+t+" not registered on remote",this._eventric.log.error(n),n=new Error(n))},t.prototype.getProjectionInstance=function(t){return this.projectionService.getInstance(t)},t.prototype.destroyProjectionInstance=function(t){return this.projectionService.destroyInstance(t,this)},t}(),n.exports=r}),require.register("eventric/repository/index",function(t,e,n){n.exports=e("./repository")}),require.register("eventric/repository/repository",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}};r=function(){function t(t){this.save=i(this.save,this),this.create=i(this.create,this),this.findById=i(this.findById,this),this._aggregateName=t.aggregateName,this._AggregateClass=t.AggregateClass,this._context=t.context,this._eventric=t.eventric,this._store=this._context.getDomainEventsStore()}return t.prototype.findById=function(t){return new Promise(function(e){return function(n,r){return e._store.findDomainEventsByAggregateId(t,function(i,o){var s;return i?void r(i):o.length?(s=new e._eventric.Aggregate(e._context,e._eventric,e._aggregateName,e._AggregateClass),s.applyDomainEvents(o),s.id=s.instance.$id=t,s.instance.$save=function(){return e.save(s)},n(s.instance)):void r(new Error("No domainEvents for "+e._aggregateName+" Aggregate with "+t+" available"))})}}(this))},t.prototype.create=function(t){return new Promise(function(e){return function(n,r){var i;if(i=new e._eventric.Aggregate(e._context,e._eventric,e._aggregateName,e._AggregateClass),"function"!=typeof i.instance.create)throw new Error("No create function on aggregate");return i.id=i.instance.$id=e._eventric.generateUid(),i.instance.$save=function(){return e.save(i)},Promise.resolve(i.instance.create(t)).then(function(){return n(i.instance)})["catch"](r)}}(this))},t.prototype.save=function(t){return new Promise(function(e){return function(n,r){var i,o;if(!t)throw new Error("Tried to save unknown aggregate "+e._aggregateName);if(i=t.getDomainEvents(),i.length<1)throw new Error("Tried to save 0 DomainEvents from Aggregate "+e._aggregateName);return e._eventric.log.debug("Going to Save and Publish "+i.length+" DomainEvents from Aggregate "+e._aggregateName),o=new Promise(function(t){return t()}),i.forEach(function(t){return o=o.then(function(){return e._store.saveDomainEvent(t)}).then(function(){return e._eventric.log.debug("Saved DomainEvent",t)})}),o.then(function(){return i.forEach(function(t){return e._eventric.log.debug("Publishing DomainEvent",t),e._context.getEventBus().publishDomainEvent(t)["catch"](function(t){return e._eventric.log.error(t.stack||t)})})}).then(function(){return n(t.id)})["catch"](r)}}(this))},t}(),n.exports=r}),require.register("eventric/remote/inmemory/index",function(t,e,n){n.exports=e("./remote_inmemory")}),require.register("eventric/remote/inmemory/pub_sub",function(t,e,n){var r;r=function(){function t(){this._subscribers=[],
this._subscriberId=0,this._pendingOperations=[]}return t.prototype.subscribe=function(t,e){return new Promise(function(n){return function(r){var i;return i={eventName:t,subscriberFunction:e,subscriberId:n._getNextSubscriberId()},n._subscribers.push(i),r(i.subscriberId)}}(this))},t.prototype.publish=function(t,e){var n,r;return r=this._getRelevantSubscribers(t),n=Promise.all(r.map(function(t){return t.subscriberFunction(e)})),this._addPendingOperation(n),n},t.prototype._getRelevantSubscribers=function(t){return t?this._subscribers.filter(function(e){return e.eventName===t}):this._subscribers},t.prototype._addPendingOperation=function(t){var e;return e=t["catch"](function(){}),this._pendingOperations.push(e),e.then(function(t){return function(){return t._pendingOperations.splice(t._pendingOperations.indexOf(e),1)}}(this))},t.prototype.unsubscribe=function(t){return new Promise(function(e){return function(n){return e._subscribers=e._subscribers.filter(function(e){return e.subscriberId!==t}),n()}}(this))},t.prototype._getNextSubscriberId=function(){return this._subscriberId++},t.prototype.destroy=function(){return Promise.all(this._pendingOperations).then(function(t){return function(){return t.publish=function(t,e){return Promise.reject(new Error("Pub sub was destroyed, cannot publish "+t+" with payload "+JSON.stringify(e)))}}}(this))},t}(),n.exports=r}),require.register("eventric/remote/inmemory/remote_inmemory",function(t,e,n){var r,i,o,s,u,a,c=[].slice;o=e("./pub_sub"),s=null,a=new o,i=function(){function t(){s=function(t){return function(e){return new Promise(function(n,r){return t._handleRPCRequest(e,function(t,e){return t?r(t):n(e)})})}}(this)}return t.prototype.setRPCHandler=function(t){this._handleRPCRequest=t},t.prototype.publish=function(){var t,e,n,r,i,o,s;return n=arguments[0],e=3<=arguments.length?c.call(arguments,1,o=arguments.length-1):(o=1,[]),s=arguments[o++],r=e[0],t=e[1],i=u(n,r,t),a.publish(i,s)},t}(),n.exports.endpoint=new i,r=function(){function t(){}return t.prototype.rpc=function(t){if(!s)throw new Error("No Remote Endpoint available for in memory client");return s(t)},t.prototype.subscribe=function(){var t,e,n,r,i,o,s;return n=arguments[0],e=3<=arguments.length?c.call(arguments,1,s=arguments.length-1):(s=1,[]),o=arguments[s++],r=e[0],t=e[1],i=u(n,r,t),a.subscribe(i,o)},t.prototype.unsubscribe=function(t){return a.unsubscribe(t)},t}(),n.exports.client=new r,u=function(t,e,n){var r;return r=t,e&&(r+="/"+e),n&&(r+="/"+n),r}}),require.register("eventric/store/inmemory/index",function(t,e,n){n.exports=e("./store_inmemory")}),require.register("eventric/store/inmemory/store_inmemory",function(t,e,n){var r,i=[].slice;r=function(){function t(){}return t.prototype._domainEvents={},t.prototype._projections={},t.prototype.initialize=function(){var t,e,n;return t=arguments[0],e=2<=arguments.length?i.call(arguments,1):[],this._context=t,n=e[0],new Promise(function(t){return function(e,n){return t._domainEventsCollectionName=t._context.name+".DomainEvents",t._projectionCollectionName=t._context.name+".Projections",t._domainEvents[t._domainEventsCollectionName]=[],e()}}(this))},t.prototype.saveDomainEvent=function(t,e){return new Promise(function(e){return function(n,r){return e._domainEvents[e._domainEventsCollectionName].push(t),n(t)}}(this))},t.prototype.findDomainEventsByName=function(t,e){var n,r;return n=t instanceof Array?function(e){return t.indexOf(e)>-1}:function(e){return e===t},r=this._domainEvents[this._domainEventsCollectionName].filter(function(t){return n(t.name)}),e(null,r)},t.prototype.findDomainEventsByNameAndAggregateId=function(t,e,n){var r,i,o;return i=t instanceof Array?function(e){return t.indexOf(e)>-1}:function(e){return e===t},r=e instanceof Array?function(t){return e.indexOf(t)>-1}:function(t){return t===e},o=this._domainEvents[this._domainEventsCollectionName].filter(function(t){var e;return i(t.name)&&r(null!=(e=t.aggregate)?e.id:void 0)}),n(null,o)},t.prototype.findDomainEventsByAggregateId=function(t,e){var n,r;return n=t instanceof Array?function(e){return t.indexOf(e)>-1}:function(e){return e===t},r=this._domainEvents[this._domainEventsCollectionName].filter(function(t){var e;return n(null!=(e=t.aggregate)?e.id:void 0)}),e(null,r)},t.prototype.getProjectionStore=function(t){return new Promise(function(e){return function(n,r){var i,o,s;return null==(i=e._projections)[s=e._projectionCollectionName]&&(i[s]={}),null==(o=e._projections[e._projectionCollectionName])[t]&&(o[t]={}),n(e._projections[e._projectionCollectionName][t])}}(this))},t.prototype.clearProjectionStore=function(t){return new Promise(function(e){return function(n,r){var i,o,s;return null==(i=e._projections)[s=e._projectionCollectionName]&&(i[s]={}),null==(o=e._projections[e._projectionCollectionName])[t]&&(o[t]={}),delete e._projections[e._projectionCollectionName][t],n()}}(this))},t}(),n.exports=r});
!function(){"use strict";var t="undefined"==typeof window?global:window;if("function"!=typeof t.require){var e={},n={_load:function(t,r){var i=n._resolveFilename(t,r),s=e[i];if(!s)throw new Error('Cannot find module "'+i+'" from "'+r+'"');if(n._cache[i])return n._cache[i].exports;var u=o(i),a={id:i,exports:{}};return n._cache[i]=a,s.call(a.exports,a.exports,u,a),a.exports},_cache:{},_resolveFilename:function(t,n){var r=i(s(n),t);return e.hasOwnProperty(r)?r:(r=i(r,"./index"),e.hasOwnProperty(r)?r:t)}},r=function(t,e){return n._load(t,e)},i=function(){var t=/^\.\.?(\/|$)/;return function(e,n){var r,i,o=[];r=(t.test(n)?e+"/"+n:n).split("/");for(var s=0,u=r.length;u>s;s++)i=r[s],".."===i?o.pop():"."!==i&&""!==i&&o.push(i);return o.join("/")}}(),o=function(e){return function(n){return t.require(n,e)}},s=function(t){return t?t.split("/").slice(0,-1).join("/"):""};r.register=r.define=function(t,n){if("object"==typeof t)for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);else e[t]=n},r.list=function(){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t},t.require=r,r.define("module",function(t,e,r){r.exports=n})}}(),require.register("eventric/eventric",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}},o=[].slice;r=function(){function t(){this._handleRemoteRPCRequest=i(this._handleRemoteRPCRequest,this),this.EventBus=e("./event_bus"),this.Remote=e("./remote"),this.Context=e("./context"),this.DomainEvent=e("./domain_event"),this.Aggregate=e("./aggregate"),this.Repository=e("./repository"),this.Projection=e("./projection"),this.Logger=e("./logger"),this.RemoteInMemory=e("./remote/inmemory"),this.StoreInMemory=e("./store/inmemory"),this.GlobalContext=e("./global_context"),this.log=this.Logger,this._contexts={},this._params={},this._domainEventHandlers={},this._domainEventHandlersAll=[],this._storeClasses={},this._remoteEndpoints=[],this._globalProjectionClasses=[],this._globalContext=new this.GlobalContext(this),this._projectionService=new this.Projection(this,this._globalContext),this.addRemoteEndpoint("inmemory",this.RemoteInMemory.endpoint),this.addStore("inmemory",this.StoreInMemory),this.set("default domain events store","inmemory")}return t.prototype.set=function(t,e){return this._params[t]=e},t.prototype.get=function(t){return t?this._params[t]:this._params},t.prototype.addStore=function(t,e,n){return null==n&&(n={}),this._storeClasses[t]={Class:e,options:n}},t.prototype.getStores=function(){return this._storeClasses},t.prototype.context=function(t){var e,n;if(!t)throw n="Contexts must have a name",this.log.error(n),new Error(n);return e=new this.Context(t,this),this._delegateAllDomainEventsToGlobalHandlers(e),this._delegateAllDomainEventsToRemoteEndpoints(e),this._contexts[t]=e,e},t.prototype.initializeGlobalProjections=function(){return Promise.all(this._globalProjectionClasses.map(function(t){return function(e){return t._projectionService.initializeInstance("",new e,{})}}(this)))},t.prototype.addGlobalProjection=function(t){return this._globalProjectionClasses.push(t)},t.prototype.getRegisteredContextNames=function(){return Object.keys(this._contexts)},t.prototype.getContext=function(t){return this._contexts[t]},t.prototype.remote=function(t){var e;if(!t)throw e="Missing context name",this.log.error(e),new Error(e);return new this.Remote(t,this)},t.prototype.addRemoteEndpoint=function(t,e){return this._remoteEndpoints.push(e),e.setRPCHandler(this._handleRemoteRPCRequest)},t.prototype._handleRemoteRPCRequest=function(t,e){var n,r;return n=this.getContext(t.contextName),n?-1===this.Remote.ALLOWED_RPC_OPERATIONS.indexOf(t.functionName)?(r=new Error("RPC operation '"+t.functionName+"' not allowed"),void e(r,null)):t.functionName in n?n[t.functionName].apply(n,t.args).then(function(t){return e(null,t)})["catch"](function(t){return e(t)}):(r=new Error("Remote RPC function "+t.functionName+" not found on Context "+t.contextName),this.log.error(r.stack),void e(r,null)):(r=new Error("Tried to handle Remote RPC with not registered context "+t.contextName),this.log.error(r.stack),void e(r,null))},t.prototype._delegateAllDomainEventsToGlobalHandlers=function(t){return t.subscribeToAllDomainEvents(function(e){return function(n){var r,i,o,s,u;for(i=e.getDomainEventHandlers(t.name,n.name),u=[],o=0,s=i.length;s>o;o++)r=i[o],u.push(r(n));return u}}(this))},t.prototype._delegateAllDomainEventsToRemoteEndpoints=function(t){return t.subscribeToAllDomainEvents(function(e){return function(n){return e._remoteEndpoints.forEach(function(e){return e.publish(t.name,n.name,n),n.aggregate?e.publish(t.name,n.name,n.aggregate.id,n):void 0})}}(this))},t.prototype.subscribeToDomainEvent=function(){var t,e,n,r,i,s,u;return t=2<=arguments.length?o.call(arguments,0,u=arguments.length-1):(u=0,[]),i=arguments[u++],r=t[0],s=t[1],null==r&&(r="all"),null==s&&(s="all"),"all"===r&&"all"===s?this._domainEventHandlersAll.push(i):(null==(e=this._domainEventHandlers)[r]&&(e[r]={}),null==(n=this._domainEventHandlers[r])[s]&&(n[s]=[]),this._domainEventHandlers[r][s].push(i))},t.prototype.getDomainEventHandlers=function(t,e){var n,r,i,o,s;return[].concat(null!=(n=null!=(r=this._domainEventHandlers[t])?r[e]:void 0)?n:[],null!=(i=null!=(o=this._domainEventHandlers[t])?o.all:void 0)?i:[],null!=(s=this._domainEventHandlersAll)?s:[])},t.prototype.generateUid=function(t){var e,n;return e=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},n=t||"-",e()+e()+n+e()+n+e()+n+e()+n+e()+e()+e()},t.prototype.defaults=function(t,e){var n,r,i,o;for(n=[].concat(Object.keys(t),Object.keys(e)),r=0,o=n.length;o>r;r++)i=n[r],!t[i]&&e[i]&&(t[i]=e[i]);return t},t.prototype.mixin=function(t,e){var n,r;r=[];for(n in e)r.push(t[n]=e[n]);return r},t}(),n.exports=r}),require.register("eventric/index",function(t,e,n){n.exports=new(e("./eventric"))}),require.register("eventric/aggregate/aggregate",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}};r=function(){function t(t,e,n,r){this._context=t,this._eventric=e,this._name=n,this.getDomainEvents=i(this.getDomainEvents,this),this.emitDomainEvent=i(this.emitDomainEvent,this),this._domainEvents=[],this.instance=new r,this.instance.$emitDomainEvent=this.emitDomainEvent}return t.prototype.emitDomainEvent=function(t,e){var n,r,i;if(n=this._context.getDomainEvent(t),!n)throw new Error("Tried to emitDomainEvent '"+t+"' which is not defined");return r={id:this.id,name:this._name},i=this._context.createDomainEvent(t,n,e,r),this._domainEvents.push(i),this._handleDomainEvent(t,i),this._eventric.log.debug("Created and Handled DomainEvent in Aggregate",i)},t.prototype._handleDomainEvent=function(t,e){return this.instance["handle"+t]?this.instance["handle"+t](e):this._eventric.log.debug("Tried to handle the DomainEvent '"+t+"' without a matching handle method")},t.prototype.getDomainEvents=function(){return this._domainEvents},t.prototype.applyDomainEvents=function(t){var e,n,r,i;for(i=[],n=0,r=t.length;r>n;n++)e=t[n],i.push(this._applyDomainEvent(e));return i},t.prototype._applyDomainEvent=function(t){return this._handleDomainEvent(t.name,t)},t}(),n.exports=r}),require.register("eventric/aggregate/index",function(t,e,n){n.exports=e("./aggregate")}),require.register("eventric/domain_event/domain_event",function(t,e,n){var r;r=function(){function t(t){this.id=t.id,this.name=t.name,this.payload=t.payload,this.aggregate=t.aggregate,this.context=t.context,this.timestamp=(new Date).getTime()}return t}(),n.exports=r}),require.register("eventric/domain_event/index",function(t,e,n){n.exports=e("./domain_event")}),require.register("eventric/context/context",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}},o=[].slice;r=function(){function t(t,e){this.name=t,this._eventric=e,this._getAggregateRepository=i(this._getAggregateRepository,this),this.clearProjectionStore=i(this.clearProjectionStore,this),this.getProjectionStore=i(this.getProjectionStore,this),this.emitDomainEvent=i(this.emitDomainEvent,this),this._isInitialized=!1,this._isDestroyed=!1,this._params=this._eventric.get(),this._di={$query:function(t){return function(){return t.query.apply(t,arguments)}}(this),$projectionStore:function(t){return function(){return t.getProjectionStore.apply(t,arguments)}}(this),$emitDomainEvent:function(t){return function(){return t.emitDomainEvent.apply(t,arguments)}}(this)},this._aggregateClasses={},this._commandHandlers={},this._queryHandlers={},this._domainEventClasses={},this._domainEventHandlers={},this._projectionClasses={},this._repositoryInstances={},this._storeClasses={},this._storeInstances={},this._pendingPromises=[],this._eventBus=new this._eventric.EventBus(this._eventric),this.projectionService=new this._eventric.Projection(this._eventric,this),this.log=this._eventric.log}return t.prototype.set=function(t,e){return this._params[t]=e,this},t.prototype.get=function(t){return this._params[t]},t.prototype.addStore=function(t,e,n){return null==n&&(n={}),this._storeClasses[t]={Class:e,options:n},this},t.prototype.defineDomainEvent=function(t,e){return this._domainEventClasses[t]=e,this},t.prototype.defineDomainEvents=function(t){var e,n;for(n in t)e=t[n],this.defineDomainEvent(n,e);return this},t.prototype.addCommandHandlers=function(t){var e,n;for(n in t)e=t[n],this._commandHandlers[n]=e;return this},t.prototype.addQueryHandlers=function(t){var e,n;for(n in t)e=t[n],this._queryHandlers[n]=e;return this},t.prototype.addAggregate=function(t,e){return this._aggregateClasses[t]=e,this},t.prototype.subscribeToAllDomainEvents=function(t){var e;return e=function(e){return function(){return t.apply(e._di,arguments)}}(this),this._eventBus.subscribeToAllDomainEvents(e)},t.prototype.subscribeToDomainEvent=function(t,e){var n;return n=function(t){return function(){return e.apply(t._di,arguments)}}(this),this._eventBus.subscribeToDomainEvent(t,n)},t.prototype.subscribeToDomainEvents=function(t){var e,n,r;r=[];for(e in t)n=t[e],r.push(this.subscribeToDomainEvent(e,n));return r},t.prototype.subscribeToDomainEventWithAggregateId=function(t,e,n){var r;return r=function(t){return function(){return n.apply(t._di,arguments)}}(this),this._eventBus.subscribeToDomainEventWithAggregateId(t,e,r)},t.prototype.addProjection=function(t,e){return this._projectionClasses[t]=e,this},t.prototype.addProjections=function(t){var e,n;for(n in t)e=t[n],this.addProjection(n,e);return this},t.prototype.getProjectionInstance=function(t){return this.projectionService.getInstance(t)},t.prototype.destroyProjectionInstance=function(t){return this.projectionService.destroyInstance(t,this)},t.prototype.initialize=function(){return this.log.debug("["+this.name+"] Initializing"),this.log.debug("["+this.name+"] Initializing Store"),this._initializeStores().then(function(t){return function(){return t.log.debug("["+t.name+"] Finished initializing Store"),t.log.debug("["+t.name+"] Initializing Projections"),t._initializeProjections()}}(this)).then(function(t){return function(){return t.log.debug("["+t.name+"] Finished initializing Projections"),t.log.debug("["+t.name+"] Finished initializing"),t._isInitialized=!0}}(this))},t.prototype._initializeStores=function(){var t,e,n,r,i;i=[],e=this._eventric.defaults(this._storeClasses,this._eventric.getStores());for(r in e)n=e[r],i.push({name:r,Class:n.Class,options:n.options});return t=Promise.resolve(),i.forEach(function(e){return function(n){return e.log.debug("["+e.name+"] Initializing Store "+n.name),e._storeInstances[n.name]=new n.Class,t=t.then(function(){return e._storeInstances[n.name].initialize(e,n.options)}).then(function(){return e.log.debug("["+e.name+"] Finished initializing Store "+n.name)})}}(this)),t},t.prototype._initializeProjections=function(){var t,e,n,r;e=Promise.resolve(),r=this._projectionClasses;for(n in r)t=r[n],this.log.debug("["+this.name+"] Initializing Projection "+n),e=e.then(function(e){return function(){return e.projectionService.initializeInstance(n,t,{})}}(this)).then(function(t){return function(e){return t.log.debug("["+t.name+"] Finished initializing Projection "+n)}}(this));return e},t.prototype.emitDomainEvent=function(t,e){var n;return this._isDestroyed?void Promise.reject(new Error("Context "+this.name+" was destroyed, cannot emit domain event "+t)):(n=new Promise(function(n){return function(r,i){var o,s;if(o=n.getDomainEvent(t),!o)throw new Error("Tried to emitDomainEvent '"+t+"' which is not defined");return s=n.createDomainEvent(t,o,e),n.getDomainEventsStore().saveDomainEvent(s).then(function(){return n.getEventBus().publishDomainEvent(s)["catch"](function(t){return null==t&&(t={}),n._eventric.log.error(t.stack||t)}),r(s)})["catch"](i)}}(this)),this._addPendingPromise(n),n)},t.prototype.createDomainEvent=function(t,e,n,r){var i;return i={},e.apply(i,[n]),new this._eventric.DomainEvent({id:this._eventric.generateUid(),name:t,aggregate:r,context:this.name,payload:i})},t.prototype.initializeProjectionInstance=function(t,e){var n;return this._projectionClasses[t]?this.projectionService.initializeInstance(t,this._projectionClasses[t],e):(n="Given projection "+t+" not registered on context",this.log.error(n),n=new Error(n))},t.prototype.getProjection=function(t){return this.projectionService.getInstance(t)},t.prototype.getDomainEvent=function(t){return this._domainEventClasses[t]},t.prototype.getDomainEventsStore=function(){var t;return t=this.get("default domain events store"),this._storeInstances[t]},t.prototype.getEventBus=function(){return this._eventBus},t.prototype.findDomainEventsByName=function(){var t;return t=1<=arguments.length?o.call(arguments,0):[],new Promise(function(e){return function(n,r){var i;return(i=e.getDomainEventsStore()).findDomainEventsByName.apply(i,o.call(t).concat([function(t,e){return t?r(t):n(e)}]))}}(this))},t.prototype.findDomainEventsByNameAndAggregateId=function(){var t;return t=1<=arguments.length?o.call(arguments,0):[],new Promise(function(e){return function(n,r){var i;return(i=e.getDomainEventsStore()).findDomainEventsByNameAndAggregateId.apply(i,o.call(t).concat([function(t,e){return t?r(t):n(e)}]))}}(this))},t.prototype.getProjectionStore=function(t,e){return new Promise(function(n){return function(r,i){var o;return n._storeInstances[t]?n._storeInstances[t].getProjectionStore(e).then(function(t){return r(t)})["catch"](function(t){return i(t)}):(o="Requested Store with name "+t+" not found",n.log.error(o),i(o))}}(this))},t.prototype.clearProjectionStore=function(t,e){return new Promise(function(n){return function(r,i){var o;return n._storeInstances[t]?n._storeInstances[t].clearProjectionStore(e).then(function(){return r()})["catch"](function(t){return i(t)}):(o="Requested Store with name "+t+" not found",n.log.error(o),i(o))}}(this))},t.prototype.command=function(t,e){var n;return this._isDestroyed?void Promise.reject(new Error("Context "+this.name+" was destroyed, cannot execute command "+t+" with arguments "+JSON.stringify(e))):(n=new Promise(function(n){return function(r,i){var o;if(n._verifyContextIsInitialized(t),!n._commandHandlers[t])throw new Error("Given command "+t+" not registered on context");return o=n._getCommandServicesToInject(),Promise.resolve(n._commandHandlers[t].apply(o,[e])).then(function(e){return n.log.debug("Completed Command",t),r(e)})["catch"](i)}}(this)),this._addPendingPromise(n),n)},t.prototype._getCommandServicesToInject=function(){var t,e,n,r;r={},n=this._di;for(e in n)t=n[e],r[e]=t;return r.$aggregate={create:function(t){return function(){var e,n,r;return e=arguments[0],n=2<=arguments.length?o.call(arguments,1):[],r=t._getAggregateRepository(e),r.create.apply(r,n)}}(this),load:function(t){return function(e,n){var r;return r=t._getAggregateRepository(e),r.findById(n)}}(this)},r},t.prototype._getAggregateRepository=function(t){var e,n,r;return n||(n={}),n[t]||(e=this._aggregateClasses[t],r=new this._eventric.Repository({aggregateName:t,AggregateClass:e,context:this,eventric:this._eventric}),n[t]=r),n[t]},t.prototype._addPendingPromise=function(t){var e;return e=t["catch"](function(){}),this._pendingPromises.push(e),e.then(function(t){return function(){return t._pendingPromises.splice(t._pendingPromises.indexOf(e),1)}}(this))},t.prototype.query=function(t,e){return new Promise(function(n){return function(r,i){var o;return n.log.debug("Got Query",t),n._verifyContextIsInitialized(t),n._queryHandlers[t]?Promise.resolve(n._queryHandlers[t].apply(n._di,[e])).then(function(e){return n.log.debug("Completed Query "+t+" with Result "+e),r(e)})["catch"](i):(o="Given query "+t+" not registered on context",n.log.error(o),o=new Error(o),i(o))}}(this))},t.prototype._verifyContextIsInitialized=function(t){if(!this._isInitialized)throw new Error("Context "+this.name+" not initialized yet, cannot execute "+t)},t.prototype.destroy=function(){return Promise.all(this._pendingPromises).then(function(t){return function(){return t._eventBus.destroy().then(function(){return t._isDestroyed=!0})}}(this))},t}(),n.exports=r}),require.register("eventric/context/index",function(t,e,n){n.exports=e("./context")}),require.register("eventric/event_bus/event_bus",function(t,e,n){var r,i;i=e("./subscriber"),r=function(){function t(){this._subscribers=[],this._subscriberId=0,this._eventPublishQueue=Promise.resolve(),this._isDestroyed=!1}return t.prototype.subscribeToAllDomainEvents=function(t){return this._subscribe("*",t)},t.prototype.subscribeToDomainEvent=function(t,e){return this._subscribe(t,e)},t.prototype.subscribeToDomainEventWithAggregateId=function(t,e,n){return this._subscribe(t+"/"+e,n)},t.prototype._subscribe=function(t,e){return new Promise(function(n){return function(r){var o;return o=new i({eventName:t,subscriberFunction:e,subscriberId:n._getNextSubscriberId()}),n._subscribers.push(o),r(o.subscriberId)}}(this))},t.prototype._getNextSubscriberId=function(){return this._subscriberId++},t.prototype.publishDomainEvent=function(t){return new Promise(function(e){return function(n,r){var i;return e._verifyPublishIsPossible(t),i=function(){return e._notifySubscribers(t).then(n)["catch"](r)},e._enqueueEventPublishing(i)}}(this))},t.prototype._verifyPublishIsPossible=function(t){var e,n;if(this._isDestroyed)throw e="Event Bus was destroyed, cannot publish "+t.name+"\nwith payload "+JSON.stringify(t.payload),(null!=(n=t.aggregate)?n.id:void 0)&&(e+=" and aggregate id "+t.aggregate.id),new Error(e)},t.prototype._notifySubscribers=function(t){return Promise.resolve().then(function(e){return function(){var n;return n=e._getSubscribersForDomainEvent(t),Promise.all(n.map(function(e){return e.subscriberFunction(t)}))}}(this))},t.prototype._getSubscribersForDomainEvent=function(t){var e,n;return n=this._subscribers.filter(function(t){return"*"===t.eventName}),n=n.concat(this._subscribers.filter(function(e){return e.eventName===t.name})),(null!=(e=t.aggregate)?e.id:void 0)&&(n=n.concat(this._subscribers.filter(function(e){return e.eventName===t.name+"/"+t.aggregate.id}))),n},t.prototype._enqueueEventPublishing=function(t){return this._eventPublishQueue=this._eventPublishQueue.then(t)},t.prototype.unsubscribe=function(t){return Promise.resolve().then(function(e){return function(){return e._subscribers=e._subscribers.filter(function(e){return e.subscriberId!==t})}}(this))},t.prototype.destroy=function(){return this._waitForEventPublishQueue().then(function(t){return function(){return t._isDestroyed=!0}}(this))},t.prototype._waitForEventPublishQueue=function(){var t;return t=this._eventPublishQueue,t.then(function(e){return function(){return e._eventPublishQueue!==t?e._waitForEventPublishQueue():void 0}}(this))},t}(),n.exports=r}),require.register("eventric/event_bus/index",function(t,e,n){n.exports=e("./event_bus")}),require.register("eventric/event_bus/subscriber",function(t,e,n){var r;r=function(){function t(t){this.eventName=t.eventName,this.subscriberFunction=t.subscriberFunction,this.subscriberId=t.subscriberId}return t}(),n.exports=r}),require.register("eventric/global_context/global_context",function(t,e,n){var r,i=[].slice;r=function(){function t(t){this._eventric=t,this.name="Global"}return t.prototype.findDomainEventsByName=function(){var t,e;return t=1<=arguments.length?i.call(arguments,0):[],e=this._getAllContexts().map(function(e){return e.findDomainEventsByName.apply(e,t)}),Promise.all(e).then(function(t){return function(e){var n;return n=t._combineDomainEventsByContext(e),t._sortDomainEventsByTimestamp(n)}}(this))},t.prototype.subscribeToDomainEvent=function(t,e){var n;return n=this._getAllContexts().map(function(n){return n.subscribeToDomainEvent(t,e)}),Promise.all(n)},t.prototype._getAllContexts=function(){var t;return t=this._eventric.getRegisteredContextNames(),t.map(function(t){return function(e){return t._eventric.remote(e)}}(this))},t.prototype._combineDomainEventsByContext=function(t){return t.reduce(function(t,e){return t.concat(e)},[])},t.prototype._sortDomainEventsByTimestamp=function(t){return t.sort(function(t,e){return t.timestamp-e.timestamp})},t}(),n.exports=r}),require.register("eventric/global_context/index",function(t,e,n){n.exports=e("./global_context")}),require.register("eventric/logger/index",function(t,e,n){n.exports=e("./logger")}),require.register("eventric/logger/logger",function(t,e,n){n.exports={_logLevel:1,setLogLevel:function(t){return this._logLevel=function(){switch(t){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/projection/index",function(t,e,n){n.exports=e("./projection")}),require.register("eventric/projection/projection",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}};r=function(){function t(t,e){this._eventric=t,this._context=e,this._applyDomainEventToProjection=i(this._applyDomainEventToProjection,this),this.log=this._eventric.log,this._handlerFunctions={},this._projectionInstances={},this._domainEventsApplied={}}return t.prototype.initializeInstance=function(t,e,n){return new Promise(function(r){return function(i,o){var s,u,a,c,l,h,p;if(l="function"==typeof e?new e:e,r._context._di){p=r._context._di;for(a in p)u=p[a],l[a]=u}return h=r._eventric.generateUid(),s=null,l.$subscribeHandlersWithAggregateId=function(t){return s=t},r.log.debug("["+r._context.name+"] Clearing ProjectionStores "+l.stores+" of "+t),c=null,r._clearProjectionStores(l.stores,t).then(function(){return r.log.debug("["+r._context.name+"] Finished clearing ProjectionStores of "+t),r._injectStoresIntoProjection(t,l)}).then(function(){return r._callInitializeOnProjection(t,l,n)}).then(function(){return r.log.debug("["+r._context.name+"] Replaying DomainEvents against Projection "+t),r._parseEventNamesFromProjection(l)}).then(function(t){return c=t,r._applyDomainEventsFromStoreToProjection(h,l,c,s)}).then(function(){return r.log.debug("["+r._context.name+"] Finished Replaying DomainEvents against Projection "+t),r._subscribeProjectionToDomainEvents(h,t,l,c,s)}).then(function(){return r._projectionInstances[h]=l,i(h)}).then(function(){return l.isInitialized=!0})["catch"](o)}}(this))},t.prototype._callInitializeOnProjection=function(t,e,n){return new Promise(function(r){return function(i,o){return e.initialize?(r.log.debug("["+r._context.name+"] Calling initialize on Projection "+t),e.initialize(n,function(){return r.log.debug("["+r._context.name+"] Finished initialize call on Projection "+t),i(e)})):(r.log.debug("["+r._context.name+"] No initialize function on Projection "+t+" given, skipping"),i(e))}}(this))},t.prototype._injectStoresIntoProjection=function(t,e){var n,r;return n=Promise.resolve(),e.stores?(null==e.$store&&(e.$store={}),null!=(r=e.stores)&&r.forEach(function(r){return function(i){return r.log.debug("["+r._context.name+"] Injecting ProjectionStore "+i+" into Projection "+t),n=n.then(function(){return r._context.getProjectionStore(i,t)}).then(function(n){return n?(e.$store[i]=n,r.log.debug("["+r._context.name+"] Finished Injecting ProjectionStore "+i+" into Projection "+t)):void 0})}}(this)),n):n},t.prototype._clearProjectionStores=function(t,e){var n;return n=Promise.resolve(),t?(t.forEach(function(t){return function(r){return t.log.debug("["+t._context.name+"] Clearing ProjectionStore "+r+" for "+e),n=n.then(function(){return t._context.clearProjectionStore(r,e)}).then(function(){return t.log.debug("["+t._context.name+"] Finished clearing ProjectionStore "+r+" for "+e)})}}(this)),n):n},t.prototype._parseEventNamesFromProjection=function(t){return new Promise(function(e,n){var r,i,o,s;i=[];for(o in t)s=t[o],0===o.indexOf("handle")&&"function"==typeof s&&(r=o.replace(/^handle/,""),i.push(r));return e(i)})},t.prototype._applyDomainEventsFromStoreToProjection=function(t,e,n,r){var i;return this._domainEventsApplied[t]={},i=r?this._context.findDomainEventsByNameAndAggregateId(n,r):this._context.findDomainEventsByName(n),i.then(function(n){return function(r){var i;if(r&&0!==r.length)return i=Promise.resolve(),r.forEach(function(r){return i=i.then(function(){return n._applyDomainEventToProjection(r,e)}).then(function(){return n._domainEventsApplied[t][r.id]=!0})}),i}}(this))},t.prototype._subscribeProjectionToDomainEvents=function(t,e,n,r,i){var o,s;return o=function(e){return function(r){return e._domainEventsApplied[t][r.id]?void 0:e._applyDomainEventToProjection(r,n).then(function(){e._domainEventsApplied[t][r.id]=!0})}}(this),s=Promise.resolve(),r.forEach(function(e){return function(n){return s=s.then(function(){return i?e._context.subscribeToDomainEventWithAggregateId(n,i,o):e._context.subscribeToDomainEvent(n,o)}).then(function(n){var r;return null==(r=e._handlerFunctions)[t]&&(r[t]=[]),e._handlerFunctions[t].push(n)})}}(this)),s},t.prototype._applyDomainEventToProjection=function(t,e){return Promise.resolve().then(function(n){return function(){return e["handle"+t.name]?e["handle"+t.name](t):void n.log.debug("Tried to apply DomainEvent '"+t.name+"' to Projection without a matching handle method")}}(this))},t.prototype.getInstance=function(t){return this._projectionInstances[t]},t.prototype.destroyInstance=function(t){var e,n,r,i,o;if(!this._handlerFunctions[t])return this.log.error("Missing attribute projectionId");for(o=[],r=this._handlerFunctions[t],e=0,n=r.length;n>e;e++)i=r[e],o.push(this._context.unsubscribeFromDomainEvent(i));return delete this._handlerFunctions[t],delete this._projectionInstances[t],Promise.all(o)},t}(),n.exports=r}),require.register("eventric/remote/index",function(t,e,n){n.exports=e("./remote")}),require.register("eventric/remote/remote",function(t,e,n){var r;r=function(){function t(t,n){this._contextName=t,this._eventric=n,this.name=this._contextName,this.InMemoryRemote=e("./inmemory"),this._params={},this._clients={},this._projectionClasses={},this._projectionInstances={},this._handlerFunctions={},this.projectionService=new this._eventric.Projection(this._eventric,this),this.addClient("inmemory",this.InMemoryRemote.client),this.set("default client","inmemory"),this._exposeRpcOperationsAsMemberFunctions()}return t.ALLOWED_RPC_OPERATIONS=["command","query","findDomainEventsByName","findDomainEventsByNameAndAggregateId"],t.prototype._exposeRpcOperationsAsMemberFunctions=function(){return t.ALLOWED_RPC_OPERATIONS.forEach(function(t){return function(e){return t[e]=function(){return t._rpc(e,arguments)}}}(this))},t.prototype.set=function(t,e){return this._params[t]=e,this},t.prototype.get=function(t){return this._params[t]},t.prototype.subscribeToAllDomainEvents=function(t){var e,n;return n=this.get("default client"),e=this.getClient(n),e.subscribe(this._contextName,t)},t.prototype.subscribeToDomainEvent=function(t,e){var n,r;return r=this.get("default client"),n=this.getClient(r),n.subscribe(this._contextName,t,e)},t.prototype.subscribeToDomainEventWithAggregateId=function(t,e,n){var r,i;return i=this.get("default client"),r=this.getClient(i),r.subscribe(this._contextName,t,e,n)},t.prototype.unsubscribeFromDomainEvent=function(t){var e,n;return n=this.get("default client"),e=this.getClient(n),e.unsubscribe(t)},t.prototype._rpc=function(t,e){var n,r;return r=this.get("default client"),n=this.getClient(r),n.rpc({contextName:this._contextName,functionName:t,args:Array.prototype.slice.call(e)})},t.prototype.addClient=function(t,e){return this._clients[t]=e,this},t.prototype.getClient=function(t){return this._clients[t]},t.prototype.addProjection=function(t,e){return this._projectionClasses[t]=e,this},t.prototype.initializeProjection=function(t,e){return this.projectionService.initializeInstance("",t,e)},t.prototype.initializeProjectionInstance=function(t,e){var n;return this._projectionClasses[t]?this.projectionService.initializeInstance(t,this._projectionClasses[t],e):(n="Given projection "+t+" not registered on remote",this._eventric.log.error(n),n=new Error(n))},t.prototype.getProjectionInstance=function(t){return this.projectionService.getInstance(t)},t.prototype.destroyProjectionInstance=function(t){return this.projectionService.destroyInstance(t,this)},t}(),n.exports=r}),require.register("eventric/repository/index",function(t,e,n){n.exports=e("./repository")}),require.register("eventric/repository/repository",function(t,e,n){var r,i=function(t,e){return function(){return t.apply(e,arguments)}};r=function(){function t(t){this.save=i(this.save,this),this.create=i(this.create,this),this.findById=i(this.findById,this),this._aggregateName=t.aggregateName,this._AggregateClass=t.AggregateClass,this._context=t.context,this._eventric=t.eventric,this._store=this._context.getDomainEventsStore()}return t.prototype.findById=function(t){return new Promise(function(e){return function(n,r){return e._store.findDomainEventsByAggregateId(t,function(i,o){var s;return i?void r(i):o.length?(s=new e._eventric.Aggregate(e._context,e._eventric,e._aggregateName,e._AggregateClass),s.applyDomainEvents(o),s.id=s.instance.$id=t,s.instance.$save=function(){return e.save(s)},n(s.instance)):void r(new Error("No domainEvents for "+e._aggregateName+" Aggregate with "+t+" available"))})}}(this))},t.prototype.create=function(t){return new Promise(function(e){return function(n,r){var i;if(i=new e._eventric.Aggregate(e._context,e._eventric,e._aggregateName,e._AggregateClass),"function"!=typeof i.instance.create)throw new Error("No create function on aggregate");return i.id=i.instance.$id=e._eventric.generateUid(),i.instance.$save=function(){return e.save(i)},Promise.resolve(i.instance.create(t)).then(function(){return n(i.instance)})["catch"](r)}}(this))},t.prototype.save=function(t){return new Promise(function(e){return function(n,r){var i,o;if(!t)throw new Error("Tried to save unknown aggregate "+e._aggregateName);if(i=t.getDomainEvents(),i.length<1)throw new Error("Tried to save 0 DomainEvents from Aggregate "+e._aggregateName);return e._eventric.log.debug("Going to Save and Publish "+i.length+" DomainEvents from Aggregate "+e._aggregateName),o=Promise.resolve(),i.forEach(function(t){return o=o.then(function(){return e._store.saveDomainEvent(t)}).then(function(){return e._eventric.log.debug("Saved DomainEvent",t)})}),o.then(function(){return i.forEach(function(t){return e._eventric.log.debug("Publishing DomainEvent",t),e._context.getEventBus().publishDomainEvent(t)["catch"](function(t){return e._eventric.log.error(t.stack||t)})})}).then(function(){return n(t.id)})["catch"](r)}}(this))},t}(),n.exports=r}),require.register("eventric/remote/inmemory/index",function(t,e,n){n.exports=e("./remote_inmemory")}),require.register("eventric/remote/inmemory/pub_sub",function(t,e,n){var r;r=function(){function t(){this._subscribers=[],this._subscriberId=0,this._pendingOperations=[]}return t.prototype.subscribe=function(t,e){
return new Promise(function(n){return function(r){var i;return i={eventName:t,subscriberFunction:e,subscriberId:n._getNextSubscriberId()},n._subscribers.push(i),r(i.subscriberId)}}(this))},t.prototype.publish=function(t,e){var n,r;return r=this._getRelevantSubscribers(t),n=Promise.all(r.map(function(t){return t.subscriberFunction(e)})),this._addPendingOperation(n),n},t.prototype._getRelevantSubscribers=function(t){return t?this._subscribers.filter(function(e){return e.eventName===t}):this._subscribers},t.prototype._addPendingOperation=function(t){var e;return e=t["catch"](function(){}),this._pendingOperations.push(e),e.then(function(t){return function(){return t._pendingOperations.splice(t._pendingOperations.indexOf(e),1)}}(this))},t.prototype.unsubscribe=function(t){return new Promise(function(e){return function(n){return e._subscribers=e._subscribers.filter(function(e){return e.subscriberId!==t}),n()}}(this))},t.prototype._getNextSubscriberId=function(){return this._subscriberId++},t.prototype.destroy=function(){return Promise.all(this._pendingOperations).then(function(t){return function(){return t.publish=function(t,e){return Promise.reject(new Error("Pub sub was destroyed, cannot publish "+t+" with payload "+JSON.stringify(e)))}}}(this))},t}(),n.exports=r}),require.register("eventric/remote/inmemory/remote_inmemory",function(t,e,n){var r,i,o,s,u,a,c=[].slice;o=e("./pub_sub"),s=null,a=new o,i=function(){function t(){s=function(t){return function(e){return new Promise(function(n,r){return t._handleRPCRequest(e,function(t,e){return t?r(t):n(e)})})}}(this)}return t.prototype.setRPCHandler=function(t){this._handleRPCRequest=t},t.prototype.publish=function(){var t,e,n,r,i,o,s;return n=arguments[0],e=3<=arguments.length?c.call(arguments,1,o=arguments.length-1):(o=1,[]),s=arguments[o++],r=e[0],t=e[1],i=u(n,r,t),a.publish(i,s)},t}(),n.exports.endpoint=new i,r=function(){function t(){}return t.prototype.rpc=function(t){if(!s)throw new Error("No Remote Endpoint available for in memory client");return s(t)},t.prototype.subscribe=function(){var t,e,n,r,i,o,s;return n=arguments[0],e=3<=arguments.length?c.call(arguments,1,s=arguments.length-1):(s=1,[]),o=arguments[s++],r=e[0],t=e[1],i=u(n,r,t),a.subscribe(i,o)},t.prototype.unsubscribe=function(t){return a.unsubscribe(t)},t}(),n.exports.client=new r,u=function(t,e,n){var r;return r=t,e&&(r+="/"+e),n&&(r+="/"+n),r}}),require.register("eventric/store/inmemory/index",function(t,e,n){n.exports=e("./store_inmemory")}),require.register("eventric/store/inmemory/store_inmemory",function(t,e,n){var r,i=[].slice;r=function(){function t(){}return t.prototype._domainEvents={},t.prototype._projections={},t.prototype.initialize=function(){var t,e,n;return t=arguments[0],e=2<=arguments.length?i.call(arguments,1):[],this._context=t,n=e[0],new Promise(function(t){return function(e,n){return t._domainEventsCollectionName=t._context.name+".DomainEvents",t._projectionCollectionName=t._context.name+".Projections",t._domainEvents[t._domainEventsCollectionName]=[],e()}}(this))},t.prototype.saveDomainEvent=function(t,e){return new Promise(function(e){return function(n,r){return e._domainEvents[e._domainEventsCollectionName].push(t),n(t)}}(this))},t.prototype.findDomainEventsByName=function(t,e){var n,r;return n=t instanceof Array?function(e){return t.indexOf(e)>-1}:function(e){return e===t},r=this._domainEvents[this._domainEventsCollectionName].filter(function(t){return n(t.name)}),e(null,r)},t.prototype.findDomainEventsByNameAndAggregateId=function(t,e,n){var r,i,o;return i=t instanceof Array?function(e){return t.indexOf(e)>-1}:function(e){return e===t},r=e instanceof Array?function(t){return e.indexOf(t)>-1}:function(t){return t===e},o=this._domainEvents[this._domainEventsCollectionName].filter(function(t){var e;return i(t.name)&&r(null!=(e=t.aggregate)?e.id:void 0)}),n(null,o)},t.prototype.findDomainEventsByAggregateId=function(t,e){var n,r;return n=t instanceof Array?function(e){return t.indexOf(e)>-1}:function(e){return e===t},r=this._domainEvents[this._domainEventsCollectionName].filter(function(t){var e;return n(null!=(e=t.aggregate)?e.id:void 0)}),e(null,r)},t.prototype.getProjectionStore=function(t){return new Promise(function(e){return function(n,r){var i,o,s;return null==(i=e._projections)[s=e._projectionCollectionName]&&(i[s]={}),null==(o=e._projections[e._projectionCollectionName])[t]&&(o[t]={}),n(e._projections[e._projectionCollectionName][t])}}(this))},t.prototype.clearProjectionStore=function(t){return new Promise(function(e){return function(n,r){var i,o,s;return null==(i=e._projections)[s=e._projectionCollectionName]&&(i[s]={}),null==(o=e._projections[e._projectionCollectionName])[t]&&(o[t]={}),delete e._projections[e._projectionCollectionName][t],n()}}(this))},t}(),n.exports=r});

@@ -16,3 +16,19 @@ var Context,

this._params = this._eventric.get();
this._di = {};
this._di = {
$query: (function(_this) {
return function() {
return _this.query.apply(_this, arguments);
};
})(this),
$projectionStore: (function(_this) {
return function() {
return _this.getProjectionStore.apply(_this, arguments);
};
})(this),
$emitDomainEvent: (function(_this) {
return function() {
return _this.emitDomainEvent.apply(_this, arguments);
};
})(this)
};
this._aggregateClasses = {};

@@ -158,16 +174,2 @@ this._commandHandlers = {};

_this.log.debug("[" + _this.name + "] Finished initializing Store");
return _this._di = {
$query: function() {
return _this.query.apply(_this, arguments);
},
$projectionStore: function() {
return _this.getProjectionStore.apply(_this, arguments);
},
$emitDomainEvent: function() {
return _this.emitDomainEvent.apply(_this, arguments);
}
};
};
})(this)).then((function(_this) {
return function() {
_this.log.debug("[" + _this.name + "] Initializing Projections");

@@ -186,3 +188,3 @@ return _this._initializeProjections();

Context.prototype._initializeStores = function() {
var promise, ref, store, storeName, stores;
var initializeStoresPromise, ref, store, storeName, stores;
stores = [];

@@ -198,5 +200,3 @@ ref = this._eventric.defaults(this._storeClasses, this._eventric.getStores());

}
promise = new Promise(function(resolve) {
return resolve();
});
initializeStoresPromise = Promise.resolve();
stores.forEach((function(_this) {

@@ -206,3 +206,3 @@ return function(store) {

_this._storeInstances[store.name] = new store.Class;
return promise = promise.then(function() {
return initializeStoresPromise = initializeStoresPromise.then(function() {
return _this._storeInstances[store.name].initialize(_this, store.options);

@@ -214,32 +214,23 @@ }).then(function() {

})(this));
return promise;
return initializeStoresPromise;
};
Context.prototype._initializeProjections = function() {
var ProjectionClass, projectionName, projections, promise, ref;
promise = new Promise(function(resolve) {
return resolve();
});
projections = [];
var ProjectionClass, initializeProjectionsPromise, projectionName, ref;
initializeProjectionsPromise = Promise.resolve();
ref = this._projectionClasses;
for (projectionName in ref) {
ProjectionClass = ref[projectionName];
projections.push({
name: projectionName,
"class": ProjectionClass
});
this.log.debug("[" + this.name + "] Initializing Projection " + projectionName);
initializeProjectionsPromise = initializeProjectionsPromise.then((function(_this) {
return function() {
return _this.projectionService.initializeInstance(projectionName, ProjectionClass, {});
};
})(this)).then((function(_this) {
return function(projectionId) {
return _this.log.debug("[" + _this.name + "] Finished initializing Projection " + projectionName);
};
})(this));
}
projections.forEach((function(_this) {
return function(projection) {
var eventNames;
eventNames = null;
_this.log.debug("[" + _this.name + "] Initializing Projection " + projection.name);
return promise = promise.then(function() {
return _this.projectionService.initializeInstance(projection.name, projection["class"], {});
}).then(function(projectionId) {
return _this.log.debug("[" + _this.name + "] Finished initializing Projection " + projection.name);
});
};
})(this));
return promise;
return initializeProjectionsPromise;
};

@@ -246,0 +237,0 @@

@@ -55,2 +55,4 @@ var Projection,

return resolve(projectionId);
}).then(function() {
return projection.isInitialized = true;
})["catch"](reject);

@@ -57,0 +59,0 @@ };

@@ -72,5 +72,3 @@ var Repository,

_this._eventric.log.debug("Going to Save and Publish " + domainEvents.length + " DomainEvents from Aggregate " + _this._aggregateName);
saveDomainEventQueue = new Promise(function(resolve) {
return resolve();
});
saveDomainEventQueue = Promise.resolve();
domainEvents.forEach(function(domainEvent) {

@@ -77,0 +75,0 @@ return saveDomainEventQueue = saveDomainEventQueue.then(function() {

@@ -15,3 +15,3 @@ {

"author": "eFa Team <team@efa-gmbh.com>",
"version": "0.11.1",
"version": "0.11.2",
"repository": {

@@ -18,0 +18,0 @@ "type": "git",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc