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.16.0 to 0.17.0

1523

dist/release/eventric.js

@@ -64,18 +64,20 @@ (function webpackUniversalModuleDefinition(root, factory) {

var Context, Eventric, GlobalContext, Projection, Remote, logger, remoteInmemory, uidGenerator,
var Context, Eventric, GlobalContext, Projection, Remote, inmemoryStore, logger, remoteInmemory, uidGenerator,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
remoteInmemory = __webpack_require__(2);
remoteInmemory = __webpack_require__(19);
GlobalContext = __webpack_require__(3);
GlobalContext = __webpack_require__(20);
Remote = __webpack_require__(5);
Remote = __webpack_require__(22);
Projection = __webpack_require__(9);
Projection = __webpack_require__(7);
Context = __webpack_require__(13);
Context = __webpack_require__(2);
inmemoryStore = __webpack_require__(24);
uidGenerator = __webpack_require__(11);
logger = __webpack_require__(7);
logger = __webpack_require__(9);

@@ -89,3 +91,3 @@ Eventric = (function() {

this._domainEventHandlersAll = [];
this._storeDefintion = null;
this._storeDefinition = null;
this._remoteEndpoints = [];

@@ -96,4 +98,19 @@ this._globalProjectionClasses = [];

this.addRemoteEndpoint(remoteInmemory.endpoint);
this.setStore(inmemoryStore, {});
}
Eventric.prototype.setStore = function(StoreClass, storeOptions) {
if (storeOptions == null) {
storeOptions = {};
}
return this._storeDefinition = {
Class: StoreClass,
options: storeOptions
};
};
Eventric.prototype.getStoreDefinition = function() {
return this._storeDefinition;
};
Eventric.prototype.context = function(name) {

@@ -206,224 +223,5 @@ var context, error;

(function webpackUniversalModuleDefinition(root, factory) {
if(true)
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define(factory);
else if(typeof exports === 'object')
exports["eventric-remote-inmemory"] = factory();
else
root["eventric-remote-inmemory"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
module.exports = __webpack_require__(3);
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = {
endpoint: __webpack_require__(1),
client: __webpack_require__(3)
};
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
var InMemoryRemoteEndpoint, pubSub,
slice = [].slice;
pubSub = __webpack_require__(2);
InMemoryRemoteEndpoint = (function() {
function InMemoryRemoteEndpoint() {}
InMemoryRemoteEndpoint.prototype.setRPCHandler = function(handleRPCRequest) {
this.handleRPCRequest = handleRPCRequest;
};
InMemoryRemoteEndpoint.prototype.publish = function() {
var aggregateId, arg, contextName, domainEventName, fullEventName, i, payload;
contextName = arguments[0], arg = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), payload = arguments[i++];
domainEventName = arg[0], aggregateId = arg[1];
fullEventName = pubSub.getFullEventName(contextName, domainEventName, aggregateId);
return pubSub.publish(fullEventName, payload);
};
return InMemoryRemoteEndpoint;
})();
module.exports = new InMemoryRemoteEndpoint;
/***/ },
/* 2 */
/***/ function(module, exports) {
var PubSub,
slice = [].slice;
PubSub = (function() {
function PubSub() {
this._subscribers = [];
this._subscriberId = 0;
}
PubSub.prototype.subscribe = function(eventName, subscriberFunction) {
return new Promise((function(_this) {
return function(resolve) {
var subscriber;
subscriber = {
eventName: eventName,
subscriberFunction: subscriberFunction,
subscriberId: _this._getNextSubscriberId()
};
_this._subscribers.push(subscriber);
return resolve(subscriber.subscriberId);
};
})(this));
};
PubSub.prototype.publish = function(eventName, payload) {
var subscribers;
subscribers = this._getRelevantSubscribers(eventName);
return Promise.all(subscribers.map(function(subscriber) {
return subscriber.subscriberFunction(payload);
}));
};
PubSub.prototype._getRelevantSubscribers = function(eventName) {
if (eventName) {
return this._subscribers.filter(function(subscriber) {
return subscriber.eventName === eventName;
});
} else {
return this._subscribers;
}
};
PubSub.prototype.unsubscribe = function(subscriberId) {
return new Promise((function(_this) {
return function(resolve) {
_this._subscribers = _this._subscribers.filter(function(subscriber) {
return subscriber.subscriberId !== subscriberId;
});
return resolve();
};
})(this));
};
PubSub.prototype._getNextSubscriberId = function() {
return this._subscriberId++;
};
PubSub.prototype.getFullEventName = function() {
var eventParts;
eventParts = 1 <= arguments.length ? slice.call(arguments, 0) : [];
eventParts = eventParts.filter(function(eventPart) {
return eventPart != null;
});
return eventParts.join('/');
};
return PubSub;
})();
module.exports = new PubSub;
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
var InMemoryRemoteClient, endpoint, pubSub,
slice = [].slice;
endpoint = __webpack_require__(1);
pubSub = __webpack_require__(2);
InMemoryRemoteClient = (function() {
function InMemoryRemoteClient() {}
InMemoryRemoteClient.prototype.rpc = function(rpcRequest) {
return new Promise((function(_this) {
return function(resolve, reject) {
return endpoint.handleRPCRequest(rpcRequest, function(error, result) {
if (error) {
return reject(error);
} else {
return resolve(result);
}
});
};
})(this));
};
InMemoryRemoteClient.prototype.subscribe = function() {
var aggregateId, arg, contextName, domainEventName, fullEventName, handlerFunction, i;
contextName = arguments[0], arg = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), handlerFunction = arguments[i++];
domainEventName = arg[0], aggregateId = arg[1];
fullEventName = pubSub.getFullEventName(contextName, domainEventName, aggregateId);
return pubSub.subscribe(fullEventName, handlerFunction);
};
InMemoryRemoteClient.prototype.unsubscribe = function(subscriberId) {
return pubSub.unsubscribe(subscriberId);
};
return InMemoryRemoteClient;
})();
module.exports = new InMemoryRemoteClient;
/***/ }
/******/ ])
});
;
/***/ },

@@ -433,497 +231,21 @@ /* 3 */

module.exports = __webpack_require__(4);
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
var GlobalContext,
slice = [].slice;
GlobalContext = (function() {
function GlobalContext() {
this.name = 'Global';
}
GlobalContext.prototype.findDomainEventsByName = function() {
var findArguments, findDomainEventsByName;
findArguments = 1 <= arguments.length ? slice.call(arguments, 0) : [];
findDomainEventsByName = this._getAllContexts().map(function(context) {
return context.findDomainEventsByName.apply(context, findArguments);
});
return Promise.all(findDomainEventsByName).then((function(_this) {
return function(domainEventsByContext) {
var domainEvents;
domainEvents = _this._combineDomainEventsByContext(domainEventsByContext);
_this._sortDomainEventsByTimestamp(domainEvents);
return domainEvents;
};
})(this));
};
GlobalContext.prototype.subscribeToDomainEvent = function(eventName, domainEventHandler) {
var subscribeToDomainEvents;
subscribeToDomainEvents = this._getAllContexts().map(function(context) {
return context.subscribeToDomainEvent(eventName, domainEventHandler);
});
return Promise.all(subscribeToDomainEvents);
};
GlobalContext.prototype._getAllContexts = function() {
var contextNames, eventric;
eventric = __webpack_require__(1);
contextNames = eventric.getRegisteredContextNames();
return contextNames.map((function(_this) {
return function(contextName) {
return eventric.remote(contextName);
};
})(this));
};
GlobalContext.prototype._combineDomainEventsByContext = function(domainEventsByContext) {
return domainEventsByContext.reduce(function(allDomainEvents, contextDomainEvents) {
return allDomainEvents.concat(contextDomainEvents);
}, []);
};
GlobalContext.prototype._sortDomainEventsByTimestamp = function(domainEvents) {
return domainEvents.sort(function(firstEvent, secondEvent) {
return firstEvent.timestamp - secondEvent.timestamp;
});
};
return GlobalContext;
})();
module.exports = GlobalContext;
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(6);
/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {
var Projection, Remote, logger, remoteInmemory;
remoteInmemory = __webpack_require__(2);
logger = __webpack_require__(7);
Projection = __webpack_require__(9);
Remote = (function() {
Remote.ALLOWED_RPC_OPERATIONS = ['command', 'query', 'findDomainEventsByName', 'findDomainEventsByNameAndAggregateId'];
function Remote(_contextName) {
this._contextName = _contextName;
this.name = this._contextName;
this._params = {};
this._projectionClasses = {};
this._projectionInstances = {};
this._handlerFunctions = {};
this.projectionService = new Projection(this);
this.setClient(remoteInmemory.client);
this._exposeRpcOperationsAsMemberFunctions();
}
Remote.prototype._exposeRpcOperationsAsMemberFunctions = function() {
return Remote.ALLOWED_RPC_OPERATIONS.forEach((function(_this) {
return function(rpcOperation) {
return _this[rpcOperation] = function() {
return _this._rpc(rpcOperation, arguments);
};
};
})(this));
};
Remote.prototype.subscribeToAllDomainEvents = function(handlerFn) {
return this._client.subscribe(this._contextName, handlerFn);
};
Remote.prototype.subscribeToDomainEvent = function(domainEventName, handlerFn) {
return this._client.subscribe(this._contextName, domainEventName, handlerFn);
};
Remote.prototype.subscribeToDomainEventWithAggregateId = function(domainEventName, aggregateId, handlerFn) {
return this._client.subscribe(this._contextName, domainEventName, aggregateId, handlerFn);
};
Remote.prototype.unsubscribeFromDomainEvent = function(subscriberId) {
return this._client.unsubscribe(subscriberId);
};
Remote.prototype._rpc = function(functionName, args) {
return this._client.rpc({
contextName: this._contextName,
functionName: functionName,
args: Array.prototype.slice.call(args)
});
};
Remote.prototype.setClient = function(client) {
this._client = client;
return this;
};
Remote.prototype.addProjection = function(projectionName, projectionClass) {
this._projectionClasses[projectionName] = projectionClass;
return this;
};
Remote.prototype.initializeProjection = function(projectionObject, params) {
return this.projectionService.initializeInstance('', projectionObject, params);
};
Remote.prototype.initializeProjectionInstance = function(projectionName, params) {
if (!this._projectionClasses[projectionName]) {
return Promise.reject(new Error("Given projection " + projectionName + " not registered on remote"));
}
return this.projectionService.initializeInstance(projectionName, this._projectionClasses[projectionName], params);
};
Remote.prototype.getProjectionInstance = function(projectionId) {
return this.projectionService.getInstance(projectionId);
};
Remote.prototype.destroyProjectionInstance = function(projectionId) {
return this.projectionService.destroyInstance(projectionId, this);
};
return Remote;
})();
module.exports = Remote;
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(8);
/***/ },
/* 8 */
/***/ function(module, exports) {
module.exports = {
_logLevel: 1,
setLogLevel: function(logLevel) {
return this._logLevel = (function() {
switch (logLevel) {
case 'debug':
return 0;
case 'warn':
return 1;
case 'info':
return 2;
case 'error':
return 3;
}
})();
},
debug: function() {
if (this._logLevel > 0) {
return;
}
return console.log.apply(console, arguments);
},
warn: function() {
if (this._logLevel > 1) {
return;
}
return console.log.apply(console, arguments);
},
info: function() {
if (this._logLevel > 2) {
return;
}
return console.log.apply(console, arguments);
},
error: function() {
if (this._logLevel > 3) {
return;
}
return console.log.apply(console, arguments);
}
};
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(10);
/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {
var Projection, logger, uidGenerator,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
logger = __webpack_require__(7);
uidGenerator = __webpack_require__(11);
Projection = (function() {
function Projection(_context) {
this._context = _context;
this._applyDomainEventToProjection = bind(this._applyDomainEventToProjection, this);
this._handlerFunctions = {};
this._projectionInstances = {};
this._domainEventsApplied = {};
}
Projection.prototype.initializeInstance = function(projectionName, Projection, params) {
var aggregateId, diFn, diName, eventNames, projection, projectionId, ref;
if (typeof Projection === 'function') {
projection = new Projection;
} else {
projection = Projection;
}
if (this._context._di) {
ref = this._context._di;
for (diName in ref) {
diFn = ref[diName];
projection[diName] = diFn;
}
}
projectionId = uidGenerator.generateUid();
aggregateId = null;
projection.$subscribeHandlersWithAggregateId = function(_aggregateId) {
return aggregateId = _aggregateId;
};
eventNames = null;
return this._callInitializeOnProjection(projectionName, projection, params).then((function(_this) {
return function() {
return _this._parseEventNamesFromProjection(projection);
};
})(this)).then((function(_this) {
return function(_eventNames) {
eventNames = _eventNames;
return _this._applyDomainEventsFromStoreToProjection(projectionId, projection, eventNames, aggregateId);
};
})(this)).then((function(_this) {
return function() {
return _this._subscribeProjectionToDomainEvents(projectionId, projectionName, projection, eventNames, aggregateId);
};
})(this)).then((function(_this) {
return function() {
return _this._projectionInstances[projectionId] = projection;
};
})(this)).then(function() {
return projection.isInitialized = true;
}).then(function() {
return projectionId;
});
};
Projection.prototype._callInitializeOnProjection = function(projectionName, projection, params) {
return new Promise((function(_this) {
return function(resolve, reject) {
if (!projection.initialize) {
logger.debug("[" + _this._context.name + "] No initialize function on Projection " + projectionName + " given, skipping");
return resolve(projection);
}
logger.debug("[" + _this._context.name + "] Calling initialize on Projection " + projectionName);
return projection.initialize(params, function() {
logger.debug("[" + _this._context.name + "] Finished initialize call on Projection " + projectionName);
return resolve(projection);
});
};
})(this));
};
Projection.prototype._parseEventNamesFromProjection = function(projection) {
return new Promise(function(resolve, reject) {
var eventName, eventNames, key, value;
eventNames = [];
for (key in projection) {
value = projection[key];
if ((key.indexOf('handle')) === 0 && (typeof value === 'function')) {
eventName = key.replace(/^handle/, '');
eventNames.push(eventName);
}
}
return resolve(eventNames);
});
};
Projection.prototype._applyDomainEventsFromStoreToProjection = function(projectionId, projection, eventNames, aggregateId) {
var findEvents;
this._domainEventsApplied[projectionId] = {};
if (aggregateId) {
findEvents = this._context.findDomainEventsByNameAndAggregateId(eventNames, aggregateId);
} else {
findEvents = this._context.findDomainEventsByName(eventNames);
}
return findEvents.then((function(_this) {
return function(domainEvents) {
var applyDomainEventsToProjectionPromise;
if (!domainEvents || domainEvents.length === 0) {
return;
}
applyDomainEventsToProjectionPromise = Promise.resolve();
domainEvents.forEach(function(domainEvent) {
return applyDomainEventsToProjectionPromise = applyDomainEventsToProjectionPromise.then(function() {
return _this._applyDomainEventToProjection(domainEvent, projection);
}).then(function() {
return _this._domainEventsApplied[projectionId][domainEvent.id] = true;
});
});
return applyDomainEventsToProjectionPromise;
};
})(this));
};
Projection.prototype._subscribeProjectionToDomainEvents = function(projectionId, projectionName, projection, eventNames, aggregateId) {
var domainEventHandler, subscribeProjectionToDomainEventsPromise;
domainEventHandler = (function(_this) {
return function(domainEvent) {
if (_this._domainEventsApplied[projectionId][domainEvent.id]) {
return;
}
return _this._applyDomainEventToProjection(domainEvent, projection).then(function() {
_this._domainEventsApplied[projectionId][domainEvent.id] = true;
});
};
})(this);
subscribeProjectionToDomainEventsPromise = Promise.resolve();
eventNames.forEach((function(_this) {
return function(eventName) {
return subscribeProjectionToDomainEventsPromise = subscribeProjectionToDomainEventsPromise.then(function() {
if (aggregateId) {
return _this._context.subscribeToDomainEventWithAggregateId(eventName, aggregateId, domainEventHandler);
} else {
return _this._context.subscribeToDomainEvent(eventName, domainEventHandler);
}
}).then(function(subscriberId) {
var base;
if ((base = _this._handlerFunctions)[projectionId] == null) {
base[projectionId] = [];
}
return _this._handlerFunctions[projectionId].push(subscriberId);
});
};
})(this));
return subscribeProjectionToDomainEventsPromise;
};
Projection.prototype._applyDomainEventToProjection = function(domainEvent, projection) {
return Promise.resolve().then((function(_this) {
return function() {
if (!projection["handle" + domainEvent.name]) {
logger.debug("Tried to apply DomainEvent '" + domainEvent.name + "' to Projection without a matching handle method");
return;
}
return projection["handle" + domainEvent.name](domainEvent);
};
})(this));
};
Projection.prototype.getInstance = function(projectionId) {
return this._projectionInstances[projectionId];
};
Projection.prototype.destroyInstance = function(projectionId) {
var i, len, ref, subscriberId, unsubscribePromises;
if (!this._handlerFunctions[projectionId]) {
return Promise.reject(new Error('Missing attribute projectionId'));
}
unsubscribePromises = [];
ref = this._handlerFunctions[projectionId];
for (i = 0, len = ref.length; i < len; i++) {
subscriberId = ref[i];
unsubscribePromises.push(this._context.unsubscribeFromDomainEvent(subscriberId));
}
delete this._handlerFunctions[projectionId];
delete this._projectionInstances[projectionId];
return Promise.all(unsubscribePromises);
};
return Projection;
})();
module.exports = Projection;
/***/ },
/* 11 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(12);
/***/ },
/* 12 */
/***/ function(module, exports) {
var UidGenerator;
UidGenerator = (function() {
function UidGenerator() {}
UidGenerator.prototype.generateUid = function(delimiter) {
if (delimiter == null) {
delimiter = "-";
}
return this._s4() + this._s4() + delimiter + this._s4() + delimiter + this._s4() + delimiter + this._s4() + delimiter + this._s4() + this._s4() + this._s4();
};
UidGenerator.prototype._s4 = function() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return UidGenerator;
})();
module.exports = new UidGenerator;
/***/ },
/* 13 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(14);
/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {
var AggregateRepository, Context, DomainEvent, EventBus, Projection, StoreInMemory, logger, uidGenerator,
var AggregateRepository, Context, DomainEvent, EventBus, Projection, logger, uidGenerator,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
slice = [].slice;
EventBus = __webpack_require__(15);
EventBus = __webpack_require__(4);
Projection = __webpack_require__(9);
Projection = __webpack_require__(7);
DomainEvent = __webpack_require__(18);
DomainEvent = __webpack_require__(13);
AggregateRepository = __webpack_require__(20);
AggregateRepository = __webpack_require__(15);
logger = __webpack_require__(7);
logger = __webpack_require__(9);
uidGenerator = __webpack_require__(11);
StoreInMemory = __webpack_require__(24);
Context = (function() {
function Context(name, _storeDefinition) {
function Context(name) {
this.name = name;
this._storeDefinition = _storeDefinition;
this._getAggregateRepository = bind(this._getAggregateRepository, this);

@@ -942,3 +264,3 @@ this._isInitialized = false;

this._queryHandlers = {};
this._domainEventClasses = {};
this._domainEventPayloadConstructors = {};
this._domainEventHandlers = {};

@@ -951,7 +273,6 @@ this._projectionClasses = {};

this.projectionService = new Projection(this);
this.setStore(StoreInMemory, {});
}
Context.prototype.defineDomainEvent = function(domainEventName, DomainEventClass) {
this._domainEventClasses[domainEventName] = DomainEventClass;
Context.prototype.defineDomainEvent = function(domainEventName, DomainEventPayloadConstructor) {
this._domainEventPayloadConstructors[domainEventName] = DomainEventPayloadConstructor;
return this;

@@ -961,6 +282,6 @@ };

Context.prototype.defineDomainEvents = function(domainEventClassesObj) {
var DomainEventClass, domainEventName;
var DomainEventPayloadConstructor, domainEventName;
for (domainEventName in domainEventClassesObj) {
DomainEventClass = domainEventClassesObj[domainEventName];
this.defineDomainEvent(domainEventName, DomainEventClass);
DomainEventPayloadConstructor = domainEventClassesObj[domainEventName];
this.defineDomainEvent(domainEventName, DomainEventPayloadConstructor);
}

@@ -1055,12 +376,2 @@ return this;

Context.prototype.setStore = function(StoreClass, storeOptions) {
if (storeOptions == null) {
storeOptions = {};
}
return this._storeDefinition = {
Class: StoreClass,
options: storeOptions
};
};
Context.prototype.initialize = function() {

@@ -1082,5 +393,7 @@ logger.debug("[" + this.name + "] Initializing");

Context.prototype._initializeStore = function() {
var initializeStorePromise;
this._storeInstance = new this._storeDefinition.Class;
initializeStorePromise = this._storeInstance.initialize(this, this._storeDefinition.options);
var eventric, initializeStorePromise, storeDefinition;
eventric = __webpack_require__(1);
storeDefinition = eventric.getStoreDefinition();
this._storeInstance = new storeDefinition.Class;
initializeStorePromise = this._storeInstance.initialize(this, storeDefinition.options);
return initializeStorePromise;

@@ -1109,6 +422,10 @@ };

Context.prototype.createDomainEvent = function(domainEventName, DomainEventClass, domainEventPayload, aggregate) {
var payload;
Context.prototype.createDomainEvent = function(domainEventName, domainEventConstructorParams, aggregate) {
var DomainEventPayloadConstructor, payload;
DomainEventPayloadConstructor = this._domainEventPayloadConstructors[domainEventName];
if (!DomainEventPayloadConstructor) {
throw new Error("Tried to create domain event '" + domainEventName + "' which is not defined");
}
payload = {};
DomainEventClass.apply(payload, [domainEventPayload]);
DomainEventPayloadConstructor.apply(payload, [domainEventConstructorParams]);
return new DomainEvent({

@@ -1134,6 +451,2 @@ id: uidGenerator.generateUid(),

Context.prototype.getDomainEvent = function(domainEventName) {
return this._domainEventClasses[domainEventName];
};
Context.prototype.getDomainEventsStore = function() {

@@ -1300,10 +613,10 @@ return this._storeInstance;

/***/ },
/* 15 */
/* 4 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(16);
module.exports = __webpack_require__(5);
/***/ },
/* 16 */
/* 5 */
/***/ function(module, exports, __webpack_require__) {

@@ -1313,3 +626,3 @@

Subscriber = __webpack_require__(17);
Subscriber = __webpack_require__(6);

@@ -1449,3 +762,3 @@ EventBus = (function() {

/***/ },
/* 17 */
/* 6 */
/***/ function(module, exports) {

@@ -1468,12 +781,301 @@

/***/ },
/* 18 */
/* 7 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(19);
module.exports = __webpack_require__(8);
/***/ },
/* 19 */
/* 8 */
/***/ function(module, exports, __webpack_require__) {
var Projection, logger, uidGenerator,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
logger = __webpack_require__(9);
uidGenerator = __webpack_require__(11);
Projection = (function() {
function Projection(_context) {
this._context = _context;
this._applyDomainEventToProjection = bind(this._applyDomainEventToProjection, this);
this._handlerFunctions = {};
this._projectionInstances = {};
this._domainEventsApplied = {};
}
Projection.prototype.initializeInstance = function(projectionName, Projection, params) {
var aggregateId, diFn, diName, eventNames, projection, projectionId, ref;
if (typeof Projection === 'function') {
projection = new Projection;
} else {
projection = Projection;
}
if (this._context._di) {
ref = this._context._di;
for (diName in ref) {
diFn = ref[diName];
projection[diName] = diFn;
}
}
projectionId = uidGenerator.generateUid();
aggregateId = null;
projection.$subscribeHandlersWithAggregateId = function(_aggregateId) {
return aggregateId = _aggregateId;
};
eventNames = null;
return this._callInitializeOnProjection(projectionName, projection, params).then((function(_this) {
return function() {
return _this._parseEventNamesFromProjection(projection);
};
})(this)).then((function(_this) {
return function(_eventNames) {
eventNames = _eventNames;
return _this._applyDomainEventsFromStoreToProjection(projectionId, projection, eventNames, aggregateId);
};
})(this)).then((function(_this) {
return function() {
return _this._subscribeProjectionToDomainEvents(projectionId, projectionName, projection, eventNames, aggregateId);
};
})(this)).then((function(_this) {
return function() {
return _this._projectionInstances[projectionId] = projection;
};
})(this)).then(function() {
return projection.isInitialized = true;
}).then(function() {
return projectionId;
});
};
Projection.prototype._callInitializeOnProjection = function(projectionName, projection, params) {
return new Promise((function(_this) {
return function(resolve, reject) {
if (!projection.initialize) {
logger.debug("[" + _this._context.name + "] No initialize function on Projection " + projectionName + " given, skipping");
return resolve(projection);
}
logger.debug("[" + _this._context.name + "] Calling initialize on Projection " + projectionName);
return projection.initialize(params, function() {
logger.debug("[" + _this._context.name + "] Finished initialize call on Projection " + projectionName);
return resolve(projection);
});
};
})(this));
};
Projection.prototype._parseEventNamesFromProjection = function(projection) {
return new Promise(function(resolve, reject) {
var eventName, eventNames, key, value;
eventNames = [];
for (key in projection) {
value = projection[key];
if ((key.indexOf('handle')) === 0 && (typeof value === 'function')) {
eventName = key.replace(/^handle/, '');
eventNames.push(eventName);
}
}
return resolve(eventNames);
});
};
Projection.prototype._applyDomainEventsFromStoreToProjection = function(projectionId, projection, eventNames, aggregateId) {
var findEvents;
this._domainEventsApplied[projectionId] = {};
if (aggregateId) {
findEvents = this._context.findDomainEventsByNameAndAggregateId(eventNames, aggregateId);
} else {
findEvents = this._context.findDomainEventsByName(eventNames);
}
return findEvents.then((function(_this) {
return function(domainEvents) {
var applyDomainEventsToProjectionPromise;
if (!domainEvents || domainEvents.length === 0) {
return;
}
applyDomainEventsToProjectionPromise = Promise.resolve();
domainEvents.forEach(function(domainEvent) {
return applyDomainEventsToProjectionPromise = applyDomainEventsToProjectionPromise.then(function() {
return _this._applyDomainEventToProjection(domainEvent, projection);
}).then(function() {
return _this._domainEventsApplied[projectionId][domainEvent.id] = true;
});
});
return applyDomainEventsToProjectionPromise;
};
})(this));
};
Projection.prototype._subscribeProjectionToDomainEvents = function(projectionId, projectionName, projection, eventNames, aggregateId) {
var domainEventHandler, subscribeProjectionToDomainEventsPromise;
domainEventHandler = (function(_this) {
return function(domainEvent) {
if (_this._domainEventsApplied[projectionId][domainEvent.id]) {
return;
}
return _this._applyDomainEventToProjection(domainEvent, projection).then(function() {
_this._domainEventsApplied[projectionId][domainEvent.id] = true;
});
};
})(this);
subscribeProjectionToDomainEventsPromise = Promise.resolve();
eventNames.forEach((function(_this) {
return function(eventName) {
return subscribeProjectionToDomainEventsPromise = subscribeProjectionToDomainEventsPromise.then(function() {
if (aggregateId) {
return _this._context.subscribeToDomainEventWithAggregateId(eventName, aggregateId, domainEventHandler);
} else {
return _this._context.subscribeToDomainEvent(eventName, domainEventHandler);
}
}).then(function(subscriberId) {
var base;
if ((base = _this._handlerFunctions)[projectionId] == null) {
base[projectionId] = [];
}
return _this._handlerFunctions[projectionId].push(subscriberId);
});
};
})(this));
return subscribeProjectionToDomainEventsPromise;
};
Projection.prototype._applyDomainEventToProjection = function(domainEvent, projection) {
return Promise.resolve().then((function(_this) {
return function() {
if (!projection["handle" + domainEvent.name]) {
logger.debug("Tried to apply DomainEvent '" + domainEvent.name + "' to Projection without a matching handle method");
return;
}
return projection["handle" + domainEvent.name](domainEvent);
};
})(this));
};
Projection.prototype.getInstance = function(projectionId) {
return this._projectionInstances[projectionId];
};
Projection.prototype.destroyInstance = function(projectionId) {
var i, len, ref, subscriberId, unsubscribePromises;
if (!this._handlerFunctions[projectionId]) {
return Promise.reject(new Error('Missing attribute projectionId'));
}
unsubscribePromises = [];
ref = this._handlerFunctions[projectionId];
for (i = 0, len = ref.length; i < len; i++) {
subscriberId = ref[i];
unsubscribePromises.push(this._context.unsubscribeFromDomainEvent(subscriberId));
}
delete this._handlerFunctions[projectionId];
delete this._projectionInstances[projectionId];
return Promise.all(unsubscribePromises);
};
return Projection;
})();
module.exports = Projection;
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(10);
/***/ },
/* 10 */
/***/ function(module, exports) {
module.exports = {
_logLevel: 1,
setLogLevel: function(logLevel) {
return this._logLevel = (function() {
switch (logLevel) {
case 'debug':
return 0;
case 'warn':
return 1;
case 'info':
return 2;
case 'error':
return 3;
}
})();
},
debug: function() {
if (this._logLevel > 0) {
return;
}
return console.log.apply(console, arguments);
},
warn: function() {
if (this._logLevel > 1) {
return;
}
return console.log.apply(console, arguments);
},
info: function() {
if (this._logLevel > 2) {
return;
}
return console.log.apply(console, arguments);
},
error: function() {
if (this._logLevel > 3) {
return;
}
return console.log.apply(console, arguments);
}
};
/***/ },
/* 11 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(12);
/***/ },
/* 12 */
/***/ function(module, exports) {
var UidGenerator;
UidGenerator = (function() {
function UidGenerator() {}
UidGenerator.prototype.generateUid = function(delimiter) {
if (delimiter == null) {
delimiter = "-";
}
return this._s4() + this._s4() + delimiter + this._s4() + delimiter + this._s4() + delimiter + this._s4() + delimiter + this._s4() + this._s4() + this._s4();
};
UidGenerator.prototype._s4 = function() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return UidGenerator;
})();
module.exports = new UidGenerator;
/***/ },
/* 13 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(14);
/***/ },
/* 14 */
/***/ function(module, exports) {
var DomainEvent;

@@ -1499,10 +1101,10 @@

/***/ },
/* 20 */
/* 15 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(21);
module.exports = __webpack_require__(16);
/***/ },
/* 21 */
/* 16 */
/***/ function(module, exports, __webpack_require__) {

@@ -1513,5 +1115,5 @@

Aggregate = __webpack_require__(22);
Aggregate = __webpack_require__(17);
logger = __webpack_require__(7);
logger = __webpack_require__(9);

@@ -1617,10 +1219,10 @@ uidGenerator = __webpack_require__(11);

/***/ },
/* 22 */
/* 17 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(23);
module.exports = __webpack_require__(18);
/***/ },
/* 23 */
/* 18 */
/***/ function(module, exports, __webpack_require__) {

@@ -1631,3 +1233,3 @@

logger = __webpack_require__(7);
logger = __webpack_require__(9);

@@ -1646,7 +1248,3 @@ Aggregate = (function() {

Aggregate.prototype.emitDomainEvent = function(domainEventName, domainEventPayload) {
var DomainEventClass, aggregate, domainEvent;
DomainEventClass = this._context.getDomainEvent(domainEventName);
if (!DomainEventClass) {
throw new Error("Tried to emitDomainEvent '" + domainEventName + "' which is not defined");
}
var aggregate, domainEvent;
aggregate = {

@@ -1656,3 +1254,3 @@ id: this.id,

};
domainEvent = this._context.createDomainEvent(domainEventName, DomainEventClass, domainEventPayload, aggregate);
domainEvent = this._context.createDomainEvent(domainEventName, domainEventPayload, aggregate);
this._domainEvents.push(domainEvent);

@@ -1697,2 +1295,405 @@ this._handleDomainEvent(domainEventName, domainEvent);

/***/ },
/* 19 */
/***/ function(module, exports, __webpack_require__) {
(function webpackUniversalModuleDefinition(root, factory) {
if(true)
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define(factory);
else if(typeof exports === 'object')
exports["eventric-remote-inmemory"] = factory();
else
root["eventric-remote-inmemory"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = {
endpoint: __webpack_require__(1),
client: __webpack_require__(3)
};
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
var InMemoryRemoteEndpoint, pubSub,
slice = [].slice;
pubSub = __webpack_require__(2);
InMemoryRemoteEndpoint = (function() {
function InMemoryRemoteEndpoint() {}
InMemoryRemoteEndpoint.prototype.setRPCHandler = function(handleRPCRequest) {
this.handleRPCRequest = handleRPCRequest;
};
InMemoryRemoteEndpoint.prototype.publish = function() {
var aggregateId, arg, contextName, domainEventName, fullEventName, i, payload;
contextName = arguments[0], arg = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), payload = arguments[i++];
domainEventName = arg[0], aggregateId = arg[1];
fullEventName = pubSub.getFullEventName(contextName, domainEventName, aggregateId);
return pubSub.publish(fullEventName, payload);
};
return InMemoryRemoteEndpoint;
})();
module.exports = new InMemoryRemoteEndpoint;
/***/ },
/* 2 */
/***/ function(module, exports) {
var PubSub,
slice = [].slice;
PubSub = (function() {
function PubSub() {
this._subscribers = [];
this._subscriberId = 0;
}
PubSub.prototype.subscribe = function(eventName, subscriberFunction) {
return new Promise((function(_this) {
return function(resolve) {
var subscriber;
subscriber = {
eventName: eventName,
subscriberFunction: subscriberFunction,
subscriberId: _this._getNextSubscriberId()
};
_this._subscribers.push(subscriber);
return resolve(subscriber.subscriberId);
};
})(this));
};
PubSub.prototype.publish = function(eventName, payload) {
var subscribers;
subscribers = this._getRelevantSubscribers(eventName);
return Promise.all(subscribers.map(function(subscriber) {
return subscriber.subscriberFunction(payload);
}));
};
PubSub.prototype._getRelevantSubscribers = function(eventName) {
if (eventName) {
return this._subscribers.filter(function(subscriber) {
return subscriber.eventName === eventName;
});
} else {
return this._subscribers;
}
};
PubSub.prototype.unsubscribe = function(subscriberId) {
return new Promise((function(_this) {
return function(resolve) {
_this._subscribers = _this._subscribers.filter(function(subscriber) {
return subscriber.subscriberId !== subscriberId;
});
return resolve();
};
})(this));
};
PubSub.prototype._getNextSubscriberId = function() {
return this._subscriberId++;
};
PubSub.prototype.getFullEventName = function() {
var eventParts;
eventParts = 1 <= arguments.length ? slice.call(arguments, 0) : [];
eventParts = eventParts.filter(function(eventPart) {
return eventPart != null;
});
return eventParts.join('/');
};
return PubSub;
})();
module.exports = new PubSub;
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
var InMemoryRemoteClient, endpoint, pubSub,
slice = [].slice;
endpoint = __webpack_require__(1);
pubSub = __webpack_require__(2);
InMemoryRemoteClient = (function() {
function InMemoryRemoteClient() {}
InMemoryRemoteClient.prototype.rpc = function(rpcRequest) {
return new Promise((function(_this) {
return function(resolve, reject) {
return endpoint.handleRPCRequest(rpcRequest, function(error, result) {
if (error) {
return reject(error);
} else {
return resolve(result);
}
});
};
})(this));
};
InMemoryRemoteClient.prototype.subscribe = function() {
var aggregateId, arg, contextName, domainEventName, fullEventName, handlerFunction, i;
contextName = arguments[0], arg = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), handlerFunction = arguments[i++];
domainEventName = arg[0], aggregateId = arg[1];
fullEventName = pubSub.getFullEventName(contextName, domainEventName, aggregateId);
return pubSub.subscribe(fullEventName, handlerFunction);
};
InMemoryRemoteClient.prototype.unsubscribe = function(subscriberId) {
return pubSub.unsubscribe(subscriberId);
};
return InMemoryRemoteClient;
})();
module.exports = new InMemoryRemoteClient;
/***/ }
/******/ ])
});
;
/***/ },
/* 20 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(21);
/***/ },
/* 21 */
/***/ function(module, exports, __webpack_require__) {
var GlobalContext,
slice = [].slice;
GlobalContext = (function() {
function GlobalContext() {
this.name = 'Global';
}
GlobalContext.prototype.findDomainEventsByName = function() {
var findArguments, findDomainEventsByName;
findArguments = 1 <= arguments.length ? slice.call(arguments, 0) : [];
findDomainEventsByName = this._getAllContexts().map(function(context) {
return context.findDomainEventsByName.apply(context, findArguments);
});
return Promise.all(findDomainEventsByName).then((function(_this) {
return function(domainEventsByContext) {
var domainEvents;
domainEvents = _this._combineDomainEventsByContext(domainEventsByContext);
_this._sortDomainEventsByTimestamp(domainEvents);
return domainEvents;
};
})(this));
};
GlobalContext.prototype.subscribeToDomainEvent = function(eventName, domainEventHandler) {
var subscribeToDomainEvents;
subscribeToDomainEvents = this._getAllContexts().map(function(context) {
return context.subscribeToDomainEvent(eventName, domainEventHandler);
});
return Promise.all(subscribeToDomainEvents);
};
GlobalContext.prototype._getAllContexts = function() {
var contextNames, eventric;
eventric = __webpack_require__(1);
contextNames = eventric.getRegisteredContextNames();
return contextNames.map((function(_this) {
return function(contextName) {
return eventric.remote(contextName);
};
})(this));
};
GlobalContext.prototype._combineDomainEventsByContext = function(domainEventsByContext) {
return domainEventsByContext.reduce(function(allDomainEvents, contextDomainEvents) {
return allDomainEvents.concat(contextDomainEvents);
}, []);
};
GlobalContext.prototype._sortDomainEventsByTimestamp = function(domainEvents) {
return domainEvents.sort(function(firstEvent, secondEvent) {
return firstEvent.timestamp - secondEvent.timestamp;
});
};
return GlobalContext;
})();
module.exports = GlobalContext;
/***/ },
/* 22 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(23);
/***/ },
/* 23 */
/***/ function(module, exports, __webpack_require__) {
var Projection, Remote, logger, remoteInmemory;
remoteInmemory = __webpack_require__(19);
logger = __webpack_require__(9);
Projection = __webpack_require__(7);
Remote = (function() {
Remote.ALLOWED_RPC_OPERATIONS = ['command', 'query', 'findDomainEventsByName', 'findDomainEventsByNameAndAggregateId'];
function Remote(_contextName) {
this._contextName = _contextName;
this.name = this._contextName;
this._params = {};
this._projectionClasses = {};
this._projectionInstances = {};
this._handlerFunctions = {};
this.projectionService = new Projection(this);
this.setClient(remoteInmemory.client);
this._exposeRpcOperationsAsMemberFunctions();
}
Remote.prototype._exposeRpcOperationsAsMemberFunctions = function() {
return Remote.ALLOWED_RPC_OPERATIONS.forEach((function(_this) {
return function(rpcOperation) {
return _this[rpcOperation] = function() {
return _this._rpc(rpcOperation, arguments);
};
};
})(this));
};
Remote.prototype.subscribeToAllDomainEvents = function(handlerFn) {
return this._client.subscribe(this._contextName, handlerFn);
};
Remote.prototype.subscribeToDomainEvent = function(domainEventName, handlerFn) {
return this._client.subscribe(this._contextName, domainEventName, handlerFn);
};
Remote.prototype.subscribeToDomainEventWithAggregateId = function(domainEventName, aggregateId, handlerFn) {
return this._client.subscribe(this._contextName, domainEventName, aggregateId, handlerFn);
};
Remote.prototype.unsubscribeFromDomainEvent = function(subscriberId) {
return this._client.unsubscribe(subscriberId);
};
Remote.prototype._rpc = function(functionName, args) {
return this._client.rpc({
contextName: this._contextName,
functionName: functionName,
args: Array.prototype.slice.call(args)
});
};
Remote.prototype.setClient = function(client) {
this._client = client;
return this;
};
Remote.prototype.addProjection = function(projectionName, projectionClass) {
this._projectionClasses[projectionName] = projectionClass;
return this;
};
Remote.prototype.initializeProjection = function(projectionObject, params) {
return this.projectionService.initializeInstance('', projectionObject, params);
};
Remote.prototype.initializeProjectionInstance = function(projectionName, params) {
if (!this._projectionClasses[projectionName]) {
return Promise.reject(new Error("Given projection " + projectionName + " not registered on remote"));
}
return this.projectionService.initializeInstance(projectionName, this._projectionClasses[projectionName], params);
};
Remote.prototype.getProjectionInstance = function(projectionId) {
return this.projectionService.getInstance(projectionId);
};
Remote.prototype.destroyProjectionInstance = function(projectionId) {
return this.projectionService.destroyInstance(projectionId, this);
};
return Remote;
})();
module.exports = Remote;
/***/ },
/* 24 */

@@ -1699,0 +1700,0 @@ /***/ function(module, exports, __webpack_require__) {

@@ -14,3 +14,3 @@ {

"author": "efa Team <team@efa-gmbh.com>",
"version": "0.16.0",
"version": "0.17.0",
"repository": {

@@ -23,3 +23,4 @@ "type": "git",

"test": "node_modules/.bin/gulp specs",
"prepublish": "node_modules/.bin/gulp build"
"prepublish": "node_modules/.bin/gulp build",
"postinstall": "node_modules/.bin/gulp symlink"
},

@@ -26,0 +27,0 @@ "dependencies": {

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 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

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