Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (part[0] === '[') {
paths[k] = +part.slice(1, part.length - 1);
}
}
error.errors[i].paths = paths;
}
}
// Custom validators
if (contexts) {
for (var i = 0; i < contexts.length; i++) {
var context = contexts[i];
if (!context.customValidator.sync) continue;
var value;
if (context.paths.length) {
value = dotty.get(doc, context.paths);
} else {
value = doc;
}
if (!value) continue;
var err = context.customValidator.sync(value, context);
if (err) {
err.paths = context.paths;
error.errors.push(err);
}
}
}
if (error.errors.length) {
//console.log(JSON.stringify(error));
return error;
}
dotty.put(notification, this.definitions.notification.meta, _.cloneDeep(dotty.get(evt, this.definitions.event.meta)));
}
if (!!this.definitions.notification.eventId && !!this.definitions.event.id) {
dotty.put(notification, this.definitions.notification.eventId, dotty.get(evt, this.definitions.event.id));
}
if (!!this.definitions.notification.event && !!this.definitions.event.name) {
dotty.put(notification, this.definitions.notification.event, dotty.get(evt, this.definitions.event.name));
}
if (!!this.definitions.notification.aggregateId && !!this.definitions.event.aggregateId) {
dotty.put(notification, this.definitions.notification.aggregateId, dotty.get(evt, this.definitions.event.aggregateId));
}
if (!!this.definitions.notification.aggregate && !!this.definitions.event.aggregate) {
dotty.put(notification, this.definitions.notification.aggregate, dotty.get(evt, this.definitions.event.aggregate));
}
if (!!this.definitions.notification.context && !!this.definitions.event.context) {
dotty.put(notification, this.definitions.notification.context, dotty.get(evt, this.definitions.event.context));
}
if (!!this.definitions.notification.revision && !!this.definitions.event.revision) {
dotty.put(notification, this.definitions.notification.revision, dotty.get(evt, this.definitions.event.revision));
}
dotty.put(notification, this.definitions.notification.correlationId, dotty.get(evt, this.definitions.event.correlationId));
// vm
dotty.put(notification, this.definitions.notification.payload, vm.toJSON());
dotty.put(notification, this.definitions.notification.collection, this.collection.name);
dotty.put(notification, this.definitions.notification.action, vm.actionOnCommit);
return notification;
},
}
return res;
}, 0);
dotty.put(evt, aggregate.definitions.event.version, maxVersion);
}
}
var aggName, ctxName;
if (!!aggregate.definitions.event.aggregate && !!aggregate.definitions.command.aggregate) {
aggName = dotty.get(cmd, aggregate.definitions.command.aggregate) || aggregate.name;
dotty.put(evt, aggregate.definitions.event.aggregate, aggName);
}
if (!!aggregate.definitions.event.context && !!aggregate.definitions.command.context) {
ctxName = dotty.get(cmd, aggregate.definitions.command.context) || aggregate.context.name;
dotty.put(evt, aggregate.definitions.event.context, ctxName);
}
var aggregateId;
if (!!aggregate.definitions.event.aggregateId) {
aggregateId = dotty.get(evt, aggregate.definitions.event.aggregateId);
}
var streamInfo = {
context: ctxName,// || aggregate.context.name,
aggregate: aggName,// || aggregate.name,
aggregateId: aggregateId || aggregateModel.id
};
if (!aggregate.disablePersistence) {
var revision = aggregateModel.getRevision(streamInfo) + 1;
for (let i = 0; i < this.structure.length; i++) {
// get the properties of each object
const segment = this.structure[i];
const fallback = segment.default;
const required = segment.required;
let fragment = segment.fragment;
// search and replace with the data values
let matches;
while ((matches = regex.exec(fragment)) !== null) {
const matchStr = matches[0];
const match = matches[1];
if (dotty.exists(this, match)) {
fragment = fragment.replace(matchStr, dotty.get(this, match));
}
else if (fallback) {
fragment = fallback;
}
else if (!required) {
fragment = null;
}
// the data object passed in is missing critical data. Fail softly.
else {
this.$el.html('<span></span>');
return;
}
}
for (let i = 0; i < this.structure.length; i++) {
// get the properties of each object
const segment = this.structure[i];
const fallback = segment.default;
const required = segment.required;
let fragment = segment.fragment;
// search and replace with the data values
let matches;
while ((matches = regex.exec(fragment)) !== null) {
const matchStr = matches[0];
const match = matches[1];
if (dotty.exists(this, match)) {
fragment = fragment.replace(matchStr, dotty.get(this, match));
}
else if (fallback) {
fragment = fallback;
}
else if (!required) {
fragment = null;
}
// the data object passed in is missing critical data. Fail softly.
else {
this.$el.html('<span></span>');
return;
}
dotty.put(evt, aggregate.definitions.event.payload, payload);
}
if (!!aggregate.definitions.event.meta && !!aggregate.definitions.command.meta) {
var commandMeta = dotty.get(cmd, aggregate.definitions.command.meta);
var userAddedMeta = dotty.get(evt, aggregate.definitions.event.meta);
var meta = (commandMeta || userAddedMeta) && _.extend({}, commandMeta, userAddedMeta);
dotty.put(evt, aggregate.definitions.event.meta, meta);
}
dotty.put(evt, aggregate.definitions.event.aggregateId, aggregateModel.id);
dotty.put(evt, aggregate.definitions.event.correlationId, dotty.get(cmd, aggregate.definitions.command.id));
if (!!aggregate.definitions.event.version) {
if (_.isNumber(version)) {
dotty.put(evt, aggregate.definitions.event.version, version);
}
if (!dotty.exists(evt, aggregate.definitions.event.version)) {
// if version is not defined in event, search the latest version number...
var evtName = dotty.get(evt, aggregate.definitions.event.name);
var maxVersion = _.reduce(aggregate.getEvents(), function (res, e) {
if (e.name !== evtName) {
return res;
}
var v = e.version || 0;
if (v > res) {
return v;
}
return res;
}, 0);
generateNotification: function (evt, vm) {
var notification = {};
// event
if (!!this.definitions.notification.meta && !!this.definitions.event.meta) {
dotty.put(notification, this.definitions.notification.meta, _.cloneDeep(dotty.get(evt, this.definitions.event.meta)));
}
if (!!this.definitions.notification.eventId && !!this.definitions.event.id) {
dotty.put(notification, this.definitions.notification.eventId, dotty.get(evt, this.definitions.event.id));
}
if (!!this.definitions.notification.event && !!this.definitions.event.name) {
dotty.put(notification, this.definitions.notification.event, dotty.get(evt, this.definitions.event.name));
}
if (!!this.definitions.notification.aggregateId && !!this.definitions.event.aggregateId) {
dotty.put(notification, this.definitions.notification.aggregateId, dotty.get(evt, this.definitions.event.aggregateId));
}
if (!!this.definitions.notification.aggregate && !!this.definitions.event.aggregate) {
dotty.put(notification, this.definitions.notification.aggregate, dotty.get(evt, this.definitions.event.aggregate));
}
if (!!this.definitions.notification.context && !!this.definitions.event.context) {
dotty.put(notification, this.definitions.notification.context, dotty.get(evt, this.definitions.event.context));
}
if (!!this.definitions.notification.revision && !!this.definitions.event.revision) {
dotty.put(notification, this.definitions.notification.revision, dotty.get(evt, this.definitions.event.revision));
}
evt = name;
}
} else {
evt = {};
dotty.put(evt, aggregate.definitions.event.name, name);
dotty.put(evt, aggregate.definitions.event.payload, payload);
}
if (!!aggregate.definitions.event.meta && !!aggregate.definitions.command.meta) {
var commandMeta = dotty.get(cmd, aggregate.definitions.command.meta);
var userAddedMeta = dotty.get(evt, aggregate.definitions.event.meta);
var meta = (commandMeta || userAddedMeta) && _.extend({}, commandMeta, userAddedMeta);
dotty.put(evt, aggregate.definitions.event.meta, meta);
}
dotty.put(evt, aggregate.definitions.event.aggregateId, aggregateModel.id);
dotty.put(evt, aggregate.definitions.event.correlationId, dotty.get(cmd, aggregate.definitions.command.id));
if (!!aggregate.definitions.event.version) {
if (_.isNumber(version)) {
dotty.put(evt, aggregate.definitions.event.version, version);
}
if (!dotty.exists(evt, aggregate.definitions.event.version)) {
// if version is not defined in event, search the latest version number...
var evtName = dotty.get(evt, aggregate.definitions.event.name);
var maxVersion = _.reduce(aggregate.getEvents(), function (res, e) {
if (e.name !== evtName) {
return res;
}
var v = e.version || 0;
if (!revInStore && self.options.startRevisionNumber >= 0 && revInEvt > self.options.startRevisionNumber) {
debug('queue event (startRevisionNumber is set) [concatenatedId]=' + concatenatedId + ', [startRevisionNumber]=' + self.options.startRevisionNumber + ', [revInEvt]=' + revInEvt);
self.queueEvent(evt, callback);
return;
}
if (!revInStore && self.currentHandlingRevisions[concatenatedId] >= 0 && revInEvt > self.currentHandlingRevisions[concatenatedId]) {
debug('queue event [concatenatedId]=' + concatenatedId + ', [currentlyHandling]=' + self.currentHandlingRevisions[concatenatedId] + ', [revInEvt]=' + revInEvt);
self.queueEvent(evt, callback);
return;
}
if (self.currentHandlingRevisions[concatenatedId] >= revInEvt) {
debug('event already denormalizing [concatenatedId]=' + concatenatedId + ', [revInStore]=' + revInStore + ', [revInEvt]=' + revInEvt);
callback(new AlreadyDenormalizingError('Event: [id]=' + dotty.get(evt, self.definition.id) + ', [revision]=' + revInEvt + ', [concatenatedId]=' + concatenatedId + ' already denormalizing!'), function (clb) {
clb(null);
});
return;
}
self.currentHandlingRevisions[concatenatedId] = revInEvt;
debug('event is in correct order => go for it! [concatenatedId]=' + concatenatedId + ', [revInStore]=' + revInStore + ', [revInEvt]=' + revInEvt);
callback(null, function (clb) {
self.finishGuard(evt, revInStore, clb);
});
}
handleNext(aggregateId, cmdEntry.command);
cmdEntry.callback(err, evts, aggData, meta);
});
return;
}
self.cmdHndlFn(aggregateId, cmdEntry.command, self, function (err, evts) {
self.removeCommandFromQueue(concId, cmdEntry.command);
handleNext(aggregateId, cmdEntry.command);
cmdEntry.callback(err, evts);
});
}
})(aggId, cmd);
}
if (dotty.exists(cmd, this.definitions.command.aggregateId)) {
return _handle(dotty.get(cmd, this.definitions.command.aggregateId));
}
debug('no aggregateId in command, so generate a new one');
this.getNewAggregateId(cmd, function (err, id) {
if (err) {
debug(err);
return callback(err);
}
return _handle(id);
});
}