Socket
Socket
Sign inDemoInstall

rheactor-event-store

Package Overview
Dependencies
7
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 9.6.0 to 9.7.0

LICENSE

26

dist/aggregate-repository.js

@@ -135,2 +135,20 @@ 'use strict';

/**
* Load aggregate by id including deleted aggregates
*
* @param {String} id
* @returns {Promise.<AggregateRoot>} or undefined if not found
*/
}, {
key: 'findByIdWithDeleted',
value: function findByIdWithDeleted(id) {
var _this3 = this;
(0, _types.AggregateIdType)(id);
return this.eventStore.fetch(id).then(function (events) {
return _this3.aggregate(events);
});
}
/**
* Creates an instance of this repositories aggregate root by applying all events

@@ -177,3 +195,3 @@ *

value: function findAll() {
var _this3 = this;
var _this4 = this;

@@ -183,3 +201,3 @@ return this.redis.getAsync(this.aggregateAlias + ':id').then(function (maxId) {

for (var i = 1; i <= maxId; i++) {
promises.push(_this3.findById('' + i));
promises.push(_this4.findById('' + i));
}

@@ -203,7 +221,7 @@ return _bluebird.Promise.all(promises);

value: function getById(id) {
var _this4 = this;
var _this5 = this;
(0, _types.AggregateIdType)(id);
return this.eventStore.fetch(id).then(function (events) {
return _this4.eventsToAggregate(id, events);
return _this5.eventsToAggregate(id, events);
});

@@ -210,0 +228,0 @@ }

@@ -178,2 +178,26 @@ 'use strict';

/**
* Load aggregate by id including deleted aggregates
*
* @param {String} id
* @returns {Promise.<AggregateRoot>}
* @throws {EntryNotFoundError} if entity is not found
*/
}, {
key: 'findByIdWithDeleted',
value: function findByIdWithDeleted(id) {
var _this5 = this;
(0, _types.AggregateIdType)(id, ['ImmutableAggregateRepository', 'getById()', 'id:AggregateId']);
return this.eventStore.fetch(id).reduce(function (aggregate, event) {
return _this5.applyEvent(event, aggregate === false ? undefined : aggregate);
}, false).then(function (aggregate) {
if (!aggregate) {
throw new _rheactorErrors.EntryNotFoundError(_this5.alias + ' with id "' + id + '" not found.');
}
return aggregate;
});
}
/**
* Returns true if x is of type ImmutableAggregateRepository

@@ -180,0 +204,0 @@ *

8

package.json
{
"name": "rheactor-event-store",
"description": "Implementation of an event store based on redis",
"version": "9.6.0",
"version": "9.7.0",
"main": "dist/index.js",

@@ -19,3 +19,3 @@ "scripts": {

},
"author": "Resourceful Humans <info@resourceful-humans.com>",
"author": "Resourceful Humans GmbH <info@resourceful-humans.com>",
"license": "MIT",

@@ -36,3 +36,3 @@ "bugs": {

"babel-cli": "^6.22.2",
"babel-preset-env": "^1.1.8",
"babel-preset-env": "^1.3.2",
"babel-preset-es2015": "^6.22.0",

@@ -47,3 +47,3 @@ "babel-register": "^6.22.0",

"semantic-release": "^6.3.2",
"standard": "^9.0.0",
"standard": "^10.0.1",
"validate-commit-msg": "^2.11.1"

@@ -50,0 +50,0 @@ },

@@ -12,4 +12,35 @@ # rheactor-event-store

Implementation of an event store based on redis.
Implementation of an event store based on [redis](https://redis.io/).
Contains helper methods to manage secondary indices.
Contains [helper methods to manage secondary indices](https://github.com/ResourcefulHumans/rheactor-event-store/blob/master/src/aggregate-index.js).
## Versioning
Storing events per aggregate is done in a list per individual aggregate, the order of the insertion is guaranteed by using [Redis lists](https://redis.io/topics/data-types#lists). This gives use an version number per event for free.
Lets assume we want to create a user `17`, we store a `UserCreatedEvent` for this aggregate id:
```javascript
eventStore.persist(new ModelEvent('UserCreatedEvent', '17', {name: 'John'}))
```
If we add another event later:
```javascript
eventStore.persist(new ModelEvent('UserNameUpdatedEvent', '17', {name: 'Mike'}))
```
this event will be appended to the list.
When aggregating the events, we can increase the version of the aggregate per event.
## Mutable Aggregates have been deprecated
The initial implementation of the event store modified models in place. More recently we decied to use immutable models instead.
The [`ImmutableAggregateRepository`](https://github.com/ResourcefulHumans/rheactor-event-store/blob/master/src/immutable-aggregate-repository.js) changes how Models are instantiated. It moves the responsibility of creating the model instance to the repository, where the `applyEvent()` method is invoked as a reducer. The method will return an instance of [`ImmutableAggregateRoot`](https://github.com/ResourcefulHumans/rheactor-event-store/blob/master/src/immutable-aggregate-root.js) which can no longer be manipulated directly.
This also changes how meta information is stored in the Aggregates, it is now encapsuled in a separate object called [`AggregateMeta`](https://github.com/ResourcefulHumans/rheactor-event-store/blob/master/src/aggregate-meta.js).
See the [tests](https://github.com/ResourcefulHumans/rheactor-event-store/blob/master/test/immutable-aggregate-repository.spec.js) for details.

@@ -100,2 +100,14 @@ import {EventStore} from './event-store'

/**
* Load aggregate by id including deleted aggregates
*
* @param {String} id
* @returns {Promise.<AggregateRoot>} or undefined if not found
*/
findByIdWithDeleted (id) {
AggregateIdType(id)
return this.eventStore.fetch(id)
.then(events => this.aggregate(events))
}
/**
* Creates an instance of this repositories aggregate root by applying all events

@@ -102,0 +114,0 @@ *

@@ -129,2 +129,21 @@ import {EventStore} from './event-store'

/**
* Load aggregate by id including deleted aggregates
*
* @param {String} id
* @returns {Promise.<AggregateRoot>}
* @throws {EntryNotFoundError} if entity is not found
*/
findByIdWithDeleted (id) {
AggregateIdType(id, ['ImmutableAggregateRepository', 'getById()', 'id:AggregateId'])
return this.eventStore.fetch(id)
.reduce((aggregate, event) => this.applyEvent(event, aggregate === false ? undefined : aggregate), false)
.then(aggregate => {
if (!aggregate) {
throw new EntryNotFoundError(this.alias + ' with id "' + id + '" not found.')
}
return aggregate
})
}
/**
* Returns true if x is of type ImmutableAggregateRepository

@@ -131,0 +150,0 @@ *

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc