cqrs-eventdenormalizer
Advanced tools
Comparing version 1.9.1 to 1.9.2
'use strict'; | ||
var Definition = require('../definitionBase'), | ||
@@ -11,3 +10,2 @@ util = require('util'), | ||
debug = require('debug')('denormalizer:collection'); | ||
/** | ||
@@ -21,3 +19,2 @@ * Collection constructor | ||
Definition.call(this, meta); | ||
// used for replay... | ||
@@ -28,21 +25,12 @@ this.workerId = uuid().toString(); | ||
this.replayingVmsToDelete = {}; | ||
meta = meta || {}; | ||
this.defaultPayload = meta.defaultPayload || ''; | ||
this.indexes = meta.indexes || []; | ||
this.noReplay = !!meta.noReplay || false; | ||
this.modelInitValues = modelInitValues || {}; | ||
this.viewBuilders = []; | ||
this.eventExtenders = []; | ||
} | ||
util.inherits(Collection, Definition); | ||
_.extend(Collection.prototype, { | ||
/** | ||
@@ -58,3 +46,2 @@ * Injects the needed repository. | ||
} | ||
this.repository = repository.extend({ | ||
@@ -65,3 +52,2 @@ collectionName: this.name, | ||
}, | ||
/** | ||
@@ -77,7 +63,5 @@ * Add viewBuilder module. | ||
} | ||
if (viewBuilder.payload === null || viewBuilder.payload === undefined) { | ||
viewBuilder.payload = this.defaultPayload; | ||
} | ||
if (this.viewBuilders.indexOf(viewBuilder) < 0) { | ||
@@ -88,3 +72,2 @@ viewBuilder.useCollection(this); | ||
}, | ||
/** | ||
@@ -100,3 +83,2 @@ * Add eventExtender module. | ||
} | ||
if (this.eventExtenders.indexOf(eventExtender) < 0) { | ||
@@ -107,3 +89,2 @@ eventExtender.useCollection(this); | ||
}, | ||
/** | ||
@@ -118,3 +99,2 @@ * Returns the viewBuilder module by query. | ||
} | ||
query.name = query.name || ''; | ||
@@ -124,3 +104,2 @@ query.version = query.version || 0; | ||
query.context = query.context || null; | ||
var found = _.filter(this.viewBuilders, function (vB) { | ||
@@ -132,7 +111,5 @@ return vB.name === query.name && | ||
}); | ||
if (found.length !== 0) { | ||
return found; | ||
} | ||
found = _.filter(this.viewBuilders, function (vB) { | ||
@@ -144,7 +121,5 @@ return vB.name === query.name && | ||
}); | ||
if (found.length !== 0) { | ||
return found; | ||
} | ||
found = _.filter(this.viewBuilders, function (vB) { | ||
@@ -156,7 +131,5 @@ return vB.name === query.name && | ||
}); | ||
if (found.length !== 0) { | ||
return found; | ||
} | ||
return _.filter(this.viewBuilders, function (vB) { | ||
@@ -169,3 +142,2 @@ return vB.name === '' && | ||
}, | ||
/** | ||
@@ -182,3 +154,2 @@ * Returns the eventExtender module by query. | ||
} | ||
query.name = query.name || ''; | ||
@@ -188,3 +159,2 @@ query.version = query.version || 0; | ||
query.context = query.context || null; | ||
var found = _.find(this.eventExtenders, function (evExt) { | ||
@@ -196,7 +166,5 @@ return evExt.name === query.name && | ||
}); | ||
if (found) { | ||
return found; | ||
} | ||
found = _.find(this.eventExtenders, function (evExt) { | ||
@@ -208,7 +176,5 @@ return evExt.name === query.name && | ||
}); | ||
if (found) { | ||
return found; | ||
} | ||
found = _.find(this.eventExtenders, function (evExt) { | ||
@@ -220,7 +186,5 @@ return evExt.name === query.name && | ||
}); | ||
if (found) { | ||
return found; | ||
} | ||
return _.find(this.eventExtenders, function (evExt) { | ||
@@ -233,3 +197,2 @@ return evExt.name === '' && | ||
}, | ||
/** | ||
@@ -242,3 +205,2 @@ * Returns all eventExtener modules. | ||
}, | ||
/** | ||
@@ -255,7 +217,5 @@ * Use this function to obtain a new id. | ||
} | ||
callback(null, newId); | ||
}); | ||
}, | ||
/** | ||
@@ -280,6 +240,4 @@ * Save the passed viewModel object in the read model. | ||
} | ||
this.repository.commit(vm, callback); | ||
}, | ||
/** | ||
@@ -308,5 +266,3 @@ * Loads a viewModel object by id. | ||
} | ||
var self = this; | ||
this.repository.get(id, function(err, vm) { | ||
@@ -317,3 +273,2 @@ if (err) { | ||
} | ||
if (!vm) { | ||
@@ -324,3 +279,2 @@ err = new Error('No vm object returned!'); | ||
} | ||
var clonedInitValues = _.cloneDeep(self.modelInitValues); | ||
@@ -332,3 +286,2 @@ for (var prop in clonedInitValues) { | ||
} | ||
if (self.isReplaying) { | ||
@@ -340,7 +293,5 @@ if (!self.replayingVms[vm.id]) { | ||
} | ||
callback(null, vm); | ||
}); | ||
}, | ||
/** | ||
@@ -363,12 +314,12 @@ * Loads a viewModel array by optional query and query options. | ||
} | ||
var self = this; | ||
var localFoundVms = {}; | ||
if (this.isReplaying) { | ||
_.each(sift(query, _.values(this.replayingVms)), function (vm) { | ||
localFoundVms[vm.id] = vm; | ||
var replVms = _.map(this.replayingVms, function (vm) { | ||
return vm.toJSON(); | ||
}); | ||
_.each(sift(query, replVms), function (vm) { | ||
localFoundVms[vm.id] = self.replayingVms[vm.id]; | ||
}); | ||
} | ||
this.repository.find(query, queryOptions, function (err, vms) { | ||
@@ -379,3 +330,2 @@ if (err) { | ||
} | ||
vms.forEach(function (vm) { | ||
@@ -389,12 +339,11 @@ var clonedInitValues = _.cloneDeep(self.modelInitValues); | ||
}); | ||
if (self.isReplaying) { | ||
var mergedVms = _.map(vms, function (vm) { | ||
var mergedVmsFromRepo = _.map(vms, function (vm) { | ||
return localFoundVms[vm.id] || vm; | ||
}); | ||
mergedVms = _.reject(mergedVms, function (vm) { | ||
mergedVmsFromRepo = _.reject(mergedVmsFromRepo, function (vm) { | ||
return !!self.replayingVmsToDelete[vm.id]; | ||
}); | ||
mergedVms.forEach(function (vm) { | ||
mergedVmsFromRepo = _.union(mergedVmsFromRepo, _.values(localFoundVms)); | ||
mergedVmsFromRepo.forEach(function (vm) { | ||
if (!self.replayingVms[vm.id]) { | ||
@@ -404,10 +353,7 @@ self.replayingVms[vm.id] = vm; | ||
}); | ||
return callback(null, mergedVms); | ||
return callback(null, mergedVmsFromRepo); | ||
} | ||
callback(null, vms); | ||
}); | ||
}, | ||
/** | ||
@@ -424,8 +370,5 @@ * Saves all replaying viewmodels. | ||
} | ||
var replVms = _.values(this.replayingVms); | ||
var replVmsToDelete = _.values(this.replayingVmsToDelete); | ||
var self = this; | ||
async.each(replVmsToDelete.concat(replVms), function (vm, callback) { | ||
@@ -448,5 +391,3 @@ if (!vm.actionOnCommitForReplay) { | ||
} | ||
}); | ||
module.exports = Collection; |
@@ -121,3 +121,3 @@ 'use strict'; | ||
}); | ||
done(callback) | ||
done(callback); | ||
}); | ||
@@ -124,0 +124,0 @@ }, |
{ | ||
"author": "adrai", | ||
"name": "cqrs-eventdenormalizer", | ||
"version": "1.9.1", | ||
"version": "1.9.2", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -0,1 +1,4 @@ | ||
## [v1.9.2](https://github.com/adrai/node-cqrs-eventdenormalizer/compare/v1.9.1...v1.9.2) | ||
- fix replay handling when fetching by query | ||
## [v1.9.1](https://github.com/adrai/node-cqrs-eventdenormalizer/compare/v1.9.0...v1.9.1) | ||
@@ -2,0 +5,0 @@ - update viewmodel dependency |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
158320
3684