rheactor-event-store
Advanced tools
Comparing version 9.1.1 to 9.2.0
@@ -10,2 +10,4 @@ 'use strict'; | ||
var _types = require('./types'); | ||
var _tcomb = require('tcomb'); | ||
@@ -15,4 +17,2 @@ | ||
var scalarType = (0, _tcomb.union)([_tcomb.String, _tcomb.Number]); | ||
var AggregateRelation = exports.AggregateRelation = function () { | ||
@@ -47,3 +47,3 @@ /** | ||
(0, _tcomb.String)(relation); | ||
scalarType(relatedId); | ||
(0, _types.AggregateIdType)(relatedId); | ||
var self = this; | ||
@@ -71,4 +71,4 @@ return self.redis.smembersAsync(self.repository.aggregateAlias + ':' + relation + ':' + relatedId).map(self.repository.findById.bind(self.repository)).filter(function (model) { | ||
(0, _tcomb.String)(relation); | ||
scalarType(relatedId); | ||
scalarType(aggregateId); | ||
(0, _types.AggregateIdType)(relatedId); | ||
(0, _types.AggregateIdType)(aggregateId); | ||
var self = this; | ||
@@ -91,4 +91,4 @@ return self.redis.saddAsync(self.repository.aggregateAlias + ':' + relation + ':' + relatedId, aggregateId); | ||
(0, _tcomb.String)(relation); | ||
scalarType(relatedId); | ||
scalarType(aggregateId); | ||
(0, _types.AggregateIdType)(relatedId); | ||
(0, _types.AggregateIdType)(aggregateId); | ||
var self = this; | ||
@@ -95,0 +95,0 @@ return self.redis.sremAsync(self.repository.aggregateAlias + ':' + relation + ':' + relatedId, aggregateId); |
@@ -20,8 +20,4 @@ 'use strict'; | ||
var _tcomb = require('tcomb'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var ModelEventTypeList = (0, _tcomb.list)(_modelEvent.ModelEventType); | ||
var AggregateRepository = exports.AggregateRepository = function () { | ||
@@ -140,3 +136,3 @@ | ||
value: function aggregate(events) { | ||
ModelEventTypeList(events); | ||
(0, _modelEvent.ModelEventTypeList)(events); | ||
if (!events.length) { | ||
@@ -143,0 +139,0 @@ return; |
@@ -10,2 +10,4 @@ 'use strict'; | ||
var _types = require('./types'); | ||
var _tcomb = require('tcomb'); | ||
@@ -45,3 +47,3 @@ | ||
(0, _tcomb.String)(aggregateId); | ||
(0, _types.AggregateIdType)(aggregateId); | ||
(0, _tcomb.Date)(createdAt); | ||
@@ -185,3 +187,3 @@ this.$aggregateMeta.id = aggregateId; | ||
value: function is(x) { | ||
return x instanceof AggregateRoot || x && x.constructor && x.constructor.name === AggregateRoot.name && '$aggregateMeta' in x; | ||
return x instanceof AggregateRoot || x && x.constructor && x.constructor.name === AggregateRoot.name && '$aggregateMeta' in x && 'id' in x.$aggregateMeta && 'version' in x.$aggregateMeta && 'deleted' in x.$aggregateMeta && 'createdAt' in x.$aggregateMeta && 'updatedAt' in x.$aggregateMeta && 'deletedAt' in x.$aggregateMeta; | ||
} | ||
@@ -188,0 +190,0 @@ }]); |
@@ -14,3 +14,3 @@ 'use strict'; | ||
var _tcomb = require('tcomb'); | ||
var _types = require('./types'); | ||
@@ -77,3 +77,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
(0, _tcomb.String)(aggregateId); | ||
(0, _types.AggregateIdType)(aggregateId); | ||
var aggregateEvents = this.aggregate + '.events.' + aggregateId; | ||
@@ -80,0 +80,0 @@ var start = 0; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.ModelEventType = exports.ModelEvent = undefined; | ||
exports.ModelEventTypeList = exports.ModelEventType = exports.ModelEvent = undefined; | ||
@@ -13,6 +13,6 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _types = require('./types'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var MaybeStringType = (0, _tcomb.maybe)(_tcomb.String); | ||
var ModelEvent = exports.ModelEvent = function () { | ||
@@ -36,7 +36,7 @@ /** | ||
(0, _tcomb.String)(aggregateId); | ||
(0, _types.AggregateIdType)(aggregateId); | ||
(0, _tcomb.String)(name); | ||
(0, _tcomb.Object)(data); | ||
(0, _tcomb.Date)(createdAt); | ||
MaybeStringType(createdBy); | ||
(0, _types.MaybeStringType)(createdBy); | ||
Object.defineProperty(this, 'aggregateId', { value: aggregateId, enumerable: true }); | ||
@@ -67,2 +67,3 @@ Object.defineProperty(this, 'name', { value: name, enumerable: true }); | ||
var ModelEventType = exports.ModelEventType = (0, _tcomb.irreducible)('ModelEventType', ModelEvent.is); | ||
var ModelEventType = exports.ModelEventType = (0, _tcomb.irreducible)('ModelEventType', ModelEvent.is); | ||
var ModelEventTypeList = exports.ModelEventTypeList = (0, _tcomb.list)(ModelEventType); |
{ | ||
"name": "rheactor-event-store", | ||
"description": "Implementation of an event store based on redis", | ||
"version": "9.1.1", | ||
"version": "9.2.0", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -1,5 +0,4 @@ | ||
import {String as StringType, Number as NumberType, union} from 'tcomb' | ||
import {AggregateIdType} from './types' | ||
import {String as StringType} from 'tcomb' | ||
const scalarType = union([StringType, NumberType]) | ||
export class AggregateRelation { | ||
@@ -28,3 +27,3 @@ /** | ||
StringType(relation) | ||
scalarType(relatedId) | ||
AggregateIdType(relatedId) | ||
let self = this | ||
@@ -51,4 +50,4 @@ return self.redis.smembersAsync(self.repository.aggregateAlias + ':' + relation + ':' + relatedId) | ||
StringType(relation) | ||
scalarType(relatedId) | ||
scalarType(aggregateId) | ||
AggregateIdType(relatedId) | ||
AggregateIdType(aggregateId) | ||
let self = this | ||
@@ -68,4 +67,4 @@ return self.redis.saddAsync(self.repository.aggregateAlias + ':' + relation + ':' + relatedId, aggregateId) | ||
StringType(relation) | ||
scalarType(relatedId) | ||
scalarType(aggregateId) | ||
AggregateIdType(relatedId) | ||
AggregateIdType(aggregateId) | ||
let self = this | ||
@@ -72,0 +71,0 @@ return self.redis.sremAsync(self.repository.aggregateAlias + ':' + relation + ':' + relatedId, aggregateId) |
import {EventStore} from './event-store' | ||
import {ModelEvent, ModelEventType} from './model-event' | ||
import {ModelEvent, ModelEventType, ModelEventTypeList} from './model-event' | ||
import {EntryNotFoundError, EntryDeletedError} from '@resourcefulhumans/rheactor-errors' | ||
import {Promise} from 'bluebird' | ||
import {AggregateRoot} from './aggregate-root' | ||
import {list} from 'tcomb' | ||
const ModelEventTypeList = list(ModelEventType) | ||
export class AggregateRepository { | ||
@@ -11,0 +8,0 @@ |
@@ -1,2 +0,3 @@ | ||
import {String as StringType, Date as DateType, irreducible} from 'tcomb' | ||
import {AggregateIdType} from './types' | ||
import {Date as DateType, irreducible} from 'tcomb' | ||
@@ -25,3 +26,3 @@ export class AggregateRoot { | ||
persisted (aggregateId, createdAt = new Date()) { | ||
StringType(aggregateId) | ||
AggregateIdType(aggregateId) | ||
DateType(createdAt) | ||
@@ -131,3 +132,14 @@ this.$aggregateMeta.id = aggregateId | ||
static is (x) { | ||
return (x instanceof AggregateRoot) || (x && x.constructor && x.constructor.name === AggregateRoot.name && '$aggregateMeta' in x) | ||
return (x instanceof AggregateRoot) || ( | ||
x && | ||
x.constructor && | ||
x.constructor.name === AggregateRoot.name && | ||
'$aggregateMeta' in x && | ||
'id' in x.$aggregateMeta && | ||
'version' in x.$aggregateMeta && | ||
'deleted' in x.$aggregateMeta && | ||
'createdAt' in x.$aggregateMeta && | ||
'updatedAt' in x.$aggregateMeta && | ||
'deletedAt' in x.$aggregateMeta | ||
) | ||
} | ||
@@ -134,0 +146,0 @@ } |
import {Promise} from 'bluebird' | ||
import {ModelEvent, ModelEventType} from './model-event' | ||
import {String as StringType} from 'tcomb' | ||
import {AggregateIdType} from './types' | ||
@@ -52,3 +52,3 @@ export class EventStore { | ||
fetch (aggregateId) { | ||
StringType(aggregateId) | ||
AggregateIdType(aggregateId) | ||
let aggregateEvents = this.aggregate + '.events.' + aggregateId | ||
@@ -82,2 +82,1 @@ let start = 0 | ||
} | ||
@@ -1,3 +0,3 @@ | ||
import {irreducible, String as StringType, Date as DateType, Object as ObjectType, maybe} from 'tcomb' | ||
const MaybeStringType = maybe(StringType) | ||
import {list, String as StringType, irreducible, Object as ObjectType, Date as DateType} from 'tcomb' | ||
import {MaybeStringType, AggregateIdType} from './types' | ||
@@ -16,3 +16,3 @@ export class ModelEvent { | ||
constructor (aggregateId, name, data = {}, createdAt = new Date(), createdBy) { | ||
StringType(aggregateId) | ||
AggregateIdType(aggregateId) | ||
StringType(name) | ||
@@ -41,1 +41,2 @@ ObjectType(data) | ||
export const ModelEventType = irreducible('ModelEventType', ModelEvent.is) | ||
export const ModelEventTypeList = list(ModelEventType) |
@@ -88,2 +88,21 @@ /* global describe, it */ | ||
}) | ||
describe('.is()', () => { | ||
it('should return true, if AggregateRoot is passed', () => { | ||
expect(AggregateRoot.is(new AggregateRoot())).to.equal(true) | ||
}) | ||
it('should return true, if a similar object is passed', () => { | ||
const root = { | ||
constructor: {name: AggregateRoot.name}, | ||
$aggregateMeta: { | ||
id: null, | ||
version: null, | ||
deleted: false, | ||
createdAt: null, | ||
updatedAt: null, | ||
deletedAt: null | ||
} | ||
} | ||
expect(AggregateRoot.is(root)).to.equal(true) | ||
}) | ||
}) | ||
}) |
@@ -13,2 +13,18 @@ /* global describe, it */ | ||
}) | ||
describe('.is()', () => { | ||
it('should return true, if AggregateRoot is passed', () => { | ||
expect(ModelEvent.is(new ModelEvent('17', 'SomeEvent'))).to.equal(true) | ||
}) | ||
it('should return true, if a similar object is passed', () => { | ||
const root = { | ||
constructor: {name: ModelEvent.name}, | ||
aggregateId: null, | ||
name: null, | ||
data: null, | ||
createdAt: null, | ||
createdBy: null | ||
} | ||
expect(ModelEvent.is(root)).to.equal(true) | ||
}) | ||
}) | ||
}) |
69187
26
1879