eventric-store-inmemory
Version:
eventric inmemory store adapter
77 lines (65 loc) • 2.32 kB
JavaScript
var InMemoryStore;
InMemoryStore = (function() {
InMemoryStore.prototype.domainEventSequence = {
currentDomainEventId: 1
};
function InMemoryStore() {
this._domainEvents = [];
}
InMemoryStore.prototype.initialize = function(_context) {
this._context = _context;
return new Promise((function(_this) {
return function(resolve) {
_this._domainEventsCollectionName = _this._context.name + ".DomainEvents";
return resolve();
};
})(this));
};
InMemoryStore.prototype.saveDomainEvent = function(domainEvent) {
return new Promise((function(_this) {
return function(resolve) {
domainEvent.id = _this.domainEventSequence.currentDomainEventId++;
_this._domainEvents.push(domainEvent);
return resolve(domainEvent);
};
})(this));
};
InMemoryStore.prototype.findDomainEventsByName = function(domainEventNames, callback) {
var events;
if (!(domainEventNames instanceof Array)) {
domainEventNames = [domainEventNames];
}
events = this._domainEvents.filter(function(domainEvent) {
return domainEventNames.indexOf(domainEvent.name) > -1;
});
return callback(null, events);
};
InMemoryStore.prototype.findDomainEventsByAggregateId = function(aggregateIds, callback) {
var domainEvents;
if (!(aggregateIds instanceof Array)) {
aggregateIds = [aggregateIds];
}
domainEvents = this._domainEvents.filter(function(domainEvent) {
return aggregateIds.indexOf(domainEvent.aggregate.id) > -1;
});
return callback(null, domainEvents);
};
InMemoryStore.prototype.findDomainEventsByNameAndAggregateId = function(domainEventNames, aggregateIds, callback) {
var domainEvents;
if (!(domainEventNames instanceof Array)) {
domainEventNames = [domainEventNames];
}
if (!(aggregateIds instanceof Array)) {
aggregateIds = [aggregateIds];
}
domainEvents = this._domainEvents.filter(function(domainEvent) {
return domainEventNames.indexOf(domainEvent.name) > -1 && aggregateIds.indexOf(domainEvent.aggregate.id) > -1;
});
return callback(null, domainEvents);
};
InMemoryStore.prototype.destroy = function() {
return Promise.resolve();
};
return InMemoryStore;
})();
module.exports = InMemoryStore;