Comparing version 0.13.0 to 0.13.1
@@ -64,12 +64,12 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var Context, Eventric, GlobalContext, Projection, Remote, RemoteInMemory, StoreInMemory, | ||
var Context, Eventric, GlobalContext, Projection, Remote, RemoteInMemory, StoreInMemory, uidGenerator, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
GlobalContext = __webpack_require__(8); | ||
GlobalContext = __webpack_require__(2); | ||
RemoteInMemory = __webpack_require__(10); | ||
RemoteInMemory = __webpack_require__(4); | ||
Remote = __webpack_require__(13); | ||
Remote = __webpack_require__(7); | ||
Projection = __webpack_require__(2); | ||
Projection = __webpack_require__(11); | ||
@@ -80,2 +80,4 @@ Context = __webpack_require__(15); | ||
uidGenerator = __webpack_require__(13); | ||
Eventric = (function() { | ||
@@ -155,2 +157,6 @@ function Eventric() { | ||
Eventric.prototype.generateUid = function() { | ||
return uidGenerator.generateUid(); | ||
}; | ||
Eventric.prototype._handleRemoteRPCRequest = function(request, callback) { | ||
@@ -214,291 +220,2 @@ var context, error; | ||
var Projection, logger, uidGenerator, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
logger = __webpack_require__(4); | ||
uidGenerator = __webpack_require__(6); | ||
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; | ||
/***/ }, | ||
/* 4 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(5); | ||
/***/ }, | ||
/* 5 */ | ||
/***/ 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); | ||
} | ||
}; | ||
/***/ }, | ||
/* 6 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(7); | ||
/***/ }, | ||
/* 7 */ | ||
/***/ 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; | ||
/***/ }, | ||
/* 8 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(9); | ||
/***/ }, | ||
/* 9 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var GlobalContext, | ||
@@ -567,10 +284,10 @@ slice = [].slice; | ||
/***/ }, | ||
/* 10 */ | ||
/* 4 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(11); | ||
module.exports = __webpack_require__(5); | ||
/***/ }, | ||
/* 11 */ | ||
/* 5 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -581,3 +298,3 @@ | ||
PubSub = __webpack_require__(12); | ||
PubSub = __webpack_require__(6); | ||
@@ -664,3 +381,3 @@ customRemoteBridge = null; | ||
/***/ }, | ||
/* 12 */ | ||
/* 6 */ | ||
/***/ function(module, exports) { | ||
@@ -756,10 +473,10 @@ | ||
/***/ }, | ||
/* 13 */ | ||
/* 7 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(14); | ||
module.exports = __webpack_require__(8); | ||
/***/ }, | ||
/* 14 */ | ||
/* 8 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -769,5 +486,5 @@ | ||
logger = __webpack_require__(4); | ||
logger = __webpack_require__(9); | ||
Projection = __webpack_require__(2); | ||
Projection = __webpack_require__(11); | ||
@@ -780,3 +497,3 @@ Remote = (function() { | ||
this.name = this._contextName; | ||
this.InMemoryRemote = __webpack_require__(10); | ||
this.InMemoryRemote = __webpack_require__(4); | ||
this._params = {}; | ||
@@ -892,2 +609,291 @@ this._clients = {}; | ||
/***/ }, | ||
/* 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, __webpack_require__) { | ||
var Projection, logger, uidGenerator, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
logger = __webpack_require__(9); | ||
uidGenerator = __webpack_require__(13); | ||
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; | ||
/***/ }, | ||
/* 13 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(14); | ||
/***/ }, | ||
/* 14 */ | ||
/***/ 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; | ||
/***/ }, | ||
/* 15 */ | ||
@@ -909,3 +915,3 @@ /***/ function(module, exports, __webpack_require__) { | ||
Projection = __webpack_require__(2); | ||
Projection = __webpack_require__(11); | ||
@@ -916,5 +922,5 @@ DomainEvent = __webpack_require__(24); | ||
logger = __webpack_require__(4); | ||
logger = __webpack_require__(9); | ||
uidGenerator = __webpack_require__(6); | ||
uidGenerator = __webpack_require__(13); | ||
@@ -1293,5 +1299,5 @@ Context = (function() { | ||
logger = __webpack_require__(4); | ||
logger = __webpack_require__(9); | ||
uidGenerator = __webpack_require__(6); | ||
uidGenerator = __webpack_require__(13); | ||
@@ -1408,3 +1414,3 @@ AggregateRepository = (function() { | ||
logger = __webpack_require__(4); | ||
logger = __webpack_require__(9); | ||
@@ -1411,0 +1417,0 @@ Aggregate = (function() { |
@@ -14,3 +14,3 @@ { | ||
"author": "eFa Team <team@efa-gmbh.com>", | ||
"version": "0.13.0", | ||
"version": "0.13.1", | ||
"repository": { | ||
@@ -17,0 +17,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
70
15175
686103