Comparing version 1.1.1 to 1.1.2
@@ -106,2 +106,26 @@ 'use strict'; | ||
/** | ||
* Returns the concatenated id (more unique) | ||
* @param {Object} evt The passed eventt. | ||
* @returns {string} | ||
*/ | ||
getConcatenatedId: function (evt) { | ||
var aggregateId = ''; | ||
if (dotty.exists(evt, this.definition.aggregateId)) { | ||
aggregateId = dotty.get(evt, this.definition.aggregateId); | ||
} | ||
var aggregate = ''; | ||
if (dotty.exists(evt, this.definition.aggregate)) { | ||
aggregate = dotty.get(evt, this.definition.aggregate); | ||
} | ||
var context = ''; | ||
if (dotty.exists(evt, this.definition.context)) { | ||
context = dotty.get(evt, this.definition.context); | ||
} | ||
return context + aggregate + aggregateId; | ||
}, | ||
/** | ||
* Queues an event with its callback by aggregateId | ||
@@ -116,8 +140,10 @@ * @param {String} aggId The aggregate id. | ||
var revInEvt = dotty.get(evt, this.definition.revision); | ||
var concatenatedId = this.getConcatenatedId(evt); | ||
this.queue.push(aggId, evtId, evt, callback, function (loopCount, waitAgain) { | ||
self.store.get(aggId, function (err, revInStore) { | ||
this.queue.push(concatenatedId, evtId, evt, callback, function (loopCount, waitAgain) { | ||
self.store.get(concatenatedId, function (err, revInStore) { | ||
if (err) { | ||
debug(err); | ||
self.store.remove(aggId, evtId); | ||
self.store.remove(concatenatedId, evtId); | ||
return callback(err); | ||
@@ -165,5 +191,7 @@ } | ||
var concatenatedId = this.getConcatenatedId(evt); | ||
var self = this; | ||
this.store.set(aggId, revInEvt + 1, revInStore, function (err) { | ||
this.store.set(concatenatedId, revInEvt + 1, revInStore, function (err) { | ||
if (err) { | ||
@@ -183,6 +211,6 @@ debug(err); | ||
self.queue.remove(aggId, evtId); | ||
self.queue.remove(concatenatedId, evtId); | ||
callback(null); | ||
var pendingEvents = self.queue.get(aggId); | ||
var pendingEvents = self.queue.get(concatenatedId); | ||
if (!pendingEvents || pendingEvents.length === 0) return debug('no other pending event found'); | ||
@@ -218,2 +246,4 @@ | ||
var revInEvt = dotty.get(evt, this.definition.revision); | ||
var concatenatedId = this.getConcatenatedId(evt); | ||
@@ -250,3 +280,3 @@ function proceed (revInStore) { | ||
setTimeout(function () { | ||
self.store.get(aggId, function(err, revInStore) { | ||
self.store.get(concatenatedId, function(err, revInStore) { | ||
if (err) { | ||
@@ -272,3 +302,3 @@ debug(err); | ||
process.nextTick(function () { | ||
self.store.get(aggId, function (err, revInStore) { | ||
self.store.get(concatenatedId, function (err, revInStore) { | ||
if (err) { | ||
@@ -275,0 +305,0 @@ debug(err); |
{ | ||
"author": "adrai", | ||
"name": "cqrs-saga", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -0,1 +1,4 @@ | ||
## [v1.1.2](https://github.com/adrai/node-cqrs-saga/compare/v1.1.1...v1.1.2) | ||
- handle case of same aggregateId in different contexts or aggregates | ||
## [v1.1.1](https://github.com/adrai/node-cqrs-saga/compare/v1.1.0...v1.1.1) | ||
@@ -2,0 +5,0 @@ - added azure-table support [#2](https://github.com/adrai/node-cqrs-saga/pull/#2) thanks to [sbiaudet](https://github.com/sbiaudet) and [rvin100](https://github.com/rvin100) |
Sorry, the diff of this file is not supported yet
3880
185069