Comparing version 0.18.0 to 0.19.0
@@ -71,13 +71,13 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
Remote = __webpack_require__(5); | ||
Remote = __webpack_require__(6); | ||
Projection = __webpack_require__(9); | ||
Projection = __webpack_require__(10); | ||
Context = __webpack_require__(13); | ||
Context = __webpack_require__(14); | ||
inmemoryStore = __webpack_require__(24); | ||
inmemoryStore = __webpack_require__(27); | ||
uuidGenerator = __webpack_require__(11); | ||
uuidGenerator = __webpack_require__(12); | ||
logger = __webpack_require__(7); | ||
logger = __webpack_require__(8); | ||
@@ -446,5 +446,7 @@ Eventric = (function() { | ||
var GlobalContext, | ||
var GlobalContext, domainEventService, | ||
slice = [].slice; | ||
domainEventService = __webpack_require__(5); | ||
GlobalContext = (function() { | ||
@@ -465,3 +467,3 @@ function GlobalContext() { | ||
domainEvents = _this._combineDomainEventsByContext(domainEventsByContext); | ||
_this._sortDomainEventsByTimestamp(domainEvents); | ||
domainEvents = domainEventService.sortDomainEventsById(domainEvents); | ||
return domainEvents; | ||
@@ -495,8 +497,2 @@ }; | ||
GlobalContext.prototype._sortDomainEventsByTimestamp = function(domainEvents) { | ||
return domainEvents.sort(function(firstEvent, secondEvent) { | ||
return firstEvent.timestamp - secondEvent.timestamp; | ||
}); | ||
}; | ||
return GlobalContext; | ||
@@ -511,7 +507,22 @@ | ||
/* 5 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ function(module, exports) { | ||
module.exports = __webpack_require__(6); | ||
var DomainEventService; | ||
DomainEventService = (function() { | ||
function DomainEventService() {} | ||
DomainEventService.prototype.sortDomainEventsById = function(domainEvents) { | ||
return domainEvents.sort(function(firstDomainEvent, secondDomainEvent) { | ||
return firstDomainEvent.id - secondDomainEvent.id; | ||
}); | ||
}; | ||
return DomainEventService; | ||
})(); | ||
module.exports = new DomainEventService; | ||
/***/ }, | ||
@@ -521,2 +532,9 @@ /* 6 */ | ||
module.exports = __webpack_require__(7); | ||
/***/ }, | ||
/* 7 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var Projection, Remote, inmemoryRemote, logger; | ||
@@ -526,5 +544,5 @@ | ||
logger = __webpack_require__(7); | ||
logger = __webpack_require__(8); | ||
Projection = __webpack_require__(9); | ||
Projection = __webpack_require__(10); | ||
@@ -616,10 +634,10 @@ Remote = (function() { | ||
/***/ }, | ||
/* 7 */ | ||
/* 8 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(8); | ||
module.exports = __webpack_require__(9); | ||
/***/ }, | ||
/* 8 */ | ||
/* 9 */ | ||
/***/ function(module, exports) { | ||
@@ -671,18 +689,17 @@ | ||
/***/ }, | ||
/* 9 */ | ||
/* 10 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(10); | ||
module.exports = __webpack_require__(11); | ||
/***/ }, | ||
/* 10 */ | ||
/* 11 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var Projection, logger, uuidGenerator, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
var Projection, logger, uuidGenerator; | ||
logger = __webpack_require__(7); | ||
logger = __webpack_require__(8); | ||
uuidGenerator = __webpack_require__(11); | ||
uuidGenerator = __webpack_require__(12); | ||
@@ -692,3 +709,2 @@ Projection = (function() { | ||
this._context = _context; | ||
this._applyDomainEventToProjection = bind(this._applyDomainEventToProjection, this); | ||
this._handlerFunctions = {}; | ||
@@ -835,11 +851,9 @@ this._projectionInstances = {}; | ||
Projection.prototype._applyDomainEventToProjection = function(domainEvent, projection) { | ||
return Promise.resolve().then((function(_this) { | ||
return function() { | ||
if (!projection["handle" + domainEvent.name]) { | ||
logger.debug("Tried to apply DomainEvent '" + domainEvent.name + "' to Projection without a matching handle method"); | ||
return; | ||
} | ||
return projection["handle" + domainEvent.name](domainEvent); | ||
}; | ||
})(this)); | ||
return Promise.resolve().then(function() { | ||
if (!projection["handle" + domainEvent.name]) { | ||
logger.debug("Tried to apply DomainEvent '" + domainEvent.name + "' to Projection without a matching handle method"); | ||
return; | ||
} | ||
return projection["handle" + domainEvent.name](domainEvent); | ||
}); | ||
}; | ||
@@ -875,10 +889,10 @@ | ||
/***/ }, | ||
/* 11 */ | ||
/* 12 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(12); | ||
module.exports = __webpack_require__(13); | ||
/***/ }, | ||
/* 12 */ | ||
/* 13 */ | ||
/***/ function(module, exports) { | ||
@@ -916,28 +930,26 @@ | ||
/***/ }, | ||
/* 13 */ | ||
/* 14 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(14); | ||
module.exports = __webpack_require__(15); | ||
/***/ }, | ||
/* 14 */ | ||
/* 15 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var AggregateRepository, Context, DomainEvent, EventBus, Projection, logger, uuidGenerator, | ||
var AggregateRepository, Context, EventBus, Projection, domainEventService, logger, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
slice = [].slice; | ||
EventBus = __webpack_require__(15); | ||
EventBus = __webpack_require__(16); | ||
Projection = __webpack_require__(9); | ||
Projection = __webpack_require__(10); | ||
DomainEvent = __webpack_require__(18); | ||
AggregateRepository = __webpack_require__(19); | ||
AggregateRepository = __webpack_require__(20); | ||
logger = __webpack_require__(8); | ||
logger = __webpack_require__(7); | ||
domainEventService = __webpack_require__(5); | ||
uuidGenerator = __webpack_require__(11); | ||
Context = (function() { | ||
@@ -1112,17 +1124,4 @@ function Context(name) { | ||
Context.prototype.createDomainEvent = function(domainEventName, domainEventConstructorParams, aggregate) { | ||
var DomainEventPayloadConstructor, payload; | ||
DomainEventPayloadConstructor = this._domainEventPayloadConstructors[domainEventName]; | ||
if (!DomainEventPayloadConstructor) { | ||
throw new Error("Tried to create domain event '" + domainEventName + "' which is not defined"); | ||
} | ||
payload = {}; | ||
DomainEventPayloadConstructor.apply(payload, [domainEventConstructorParams]); | ||
return new DomainEvent({ | ||
id: uuidGenerator.generateUuid(), | ||
name: domainEventName, | ||
aggregate: aggregate, | ||
context: this.name, | ||
payload: payload | ||
}); | ||
Context.prototype.getDomainEventPayloadConstructor = function(domainEventName) { | ||
return this._domainEventPayloadConstructors[domainEventName]; | ||
}; | ||
@@ -1155,7 +1154,8 @@ | ||
var ref; | ||
return (ref = _this.getDomainEventsStore()).findDomainEventsByName.apply(ref, slice.call(findArguments).concat([function(err, events) { | ||
return (ref = _this.getDomainEventsStore()).findDomainEventsByName.apply(ref, slice.call(findArguments).concat([function(err, domainEvents) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
return resolve(events); | ||
domainEvents = domainEventService.sortDomainEventsById(domainEvents); | ||
return resolve(domainEvents); | ||
}])); | ||
@@ -1172,7 +1172,8 @@ }; | ||
var ref; | ||
return (ref = _this.getDomainEventsStore()).findDomainEventsByNameAndAggregateId.apply(ref, slice.call(findArguments).concat([function(err, events) { | ||
return (ref = _this.getDomainEventsStore()).findDomainEventsByNameAndAggregateId.apply(ref, slice.call(findArguments).concat([function(err, domainEvents) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
return resolve(events); | ||
domainEvents = domainEventService.sortDomainEventsById(domainEvents); | ||
return resolve(domainEvents); | ||
}])); | ||
@@ -1317,10 +1318,10 @@ }; | ||
/***/ }, | ||
/* 15 */ | ||
/* 16 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(16); | ||
module.exports = __webpack_require__(17); | ||
/***/ }, | ||
/* 16 */ | ||
/* 17 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1330,3 +1331,3 @@ | ||
Subscriber = __webpack_require__(17); | ||
Subscriber = __webpack_require__(18); | ||
@@ -1466,3 +1467,3 @@ EventBus = (function() { | ||
/***/ }, | ||
/* 17 */ | ||
/* 18 */ | ||
/***/ function(module, exports) { | ||
@@ -1485,50 +1486,20 @@ | ||
/***/ }, | ||
/* 18 */ | ||
/* 19 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(19); | ||
module.exports = __webpack_require__(20); | ||
/***/ }, | ||
/* 19 */ | ||
/***/ function(module, exports) { | ||
var DomainEvent; | ||
DomainEvent = (function() { | ||
function DomainEvent(params) { | ||
this.id = params.id; | ||
this.name = params.name; | ||
this.payload = params.payload; | ||
this.aggregate = params.aggregate; | ||
this.context = params.context; | ||
this.timestamp = new Date().getTime(); | ||
} | ||
return DomainEvent; | ||
})(); | ||
module.exports = DomainEvent; | ||
/***/ }, | ||
/* 20 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(21); | ||
/***/ }, | ||
/* 21 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var Aggregate, AggregateRepository, logger, uuidGenerator, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
Aggregate = __webpack_require__(22); | ||
Aggregate = __webpack_require__(21); | ||
logger = __webpack_require__(7); | ||
logger = __webpack_require__(8); | ||
uuidGenerator = __webpack_require__(11); | ||
uuidGenerator = __webpack_require__(12); | ||
@@ -1607,3 +1578,3 @@ AggregateRepository = (function() { | ||
}).then(function() { | ||
return logger.debug("Saved DomainEvent", domainEvent); | ||
return logger.debug('Saved DomainEvent', domainEvent); | ||
}); | ||
@@ -1613,3 +1584,3 @@ }); | ||
return domainEvents.forEach(function(domainEvent) { | ||
logger.debug("Publishing DomainEvent", domainEvent); | ||
logger.debug('Publishing DomainEvent', domainEvent); | ||
return _this._context.getEventBus().publishDomainEvent(domainEvent)["catch"](function(error) { | ||
@@ -1634,17 +1605,21 @@ return logger.error(error.stack || error); | ||
/***/ }, | ||
/* 22 */ | ||
/* 21 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(23); | ||
module.exports = __webpack_require__(22); | ||
/***/ }, | ||
/* 23 */ | ||
/* 22 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var Aggregate, logger, | ||
var Aggregate, DomainEvent, domainEventIdGenerator, logger, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | ||
logger = __webpack_require__(7); | ||
DomainEvent = __webpack_require__(23); | ||
domainEventIdGenerator = __webpack_require__(25); | ||
logger = __webpack_require__(8); | ||
Aggregate = (function() { | ||
@@ -1654,3 +1629,2 @@ function Aggregate(_context, _name, AggregateClass) { | ||
this._name = _name; | ||
this.getDomainEvents = bind(this.getDomainEvents, this); | ||
this.emitDomainEvent = bind(this.emitDomainEvent, this); | ||
@@ -1668,3 +1642,3 @@ this._domainEvents = []; | ||
}; | ||
domainEvent = this._context.createDomainEvent(domainEventName, domainEventPayload, aggregate); | ||
domainEvent = this._createDomainEvent(domainEventName, domainEventPayload, aggregate); | ||
this._domainEvents.push(domainEvent); | ||
@@ -1675,7 +1649,22 @@ this._handleDomainEvent(domainEventName, domainEvent); | ||
Aggregate.prototype._createDomainEvent = function(domainEventName, domainEventConstructorParams, aggregate) { | ||
var DomainEventPayloadConstructor, payload; | ||
DomainEventPayloadConstructor = this._context.getDomainEventPayloadConstructor(domainEventName); | ||
if (!DomainEventPayloadConstructor) { | ||
throw new Error("Tried to create domain event '" + domainEventName + "' which is not defined"); | ||
} | ||
payload = {}; | ||
DomainEventPayloadConstructor.apply(payload, [domainEventConstructorParams]); | ||
return new DomainEvent({ | ||
id: domainEventIdGenerator.generateId(), | ||
name: domainEventName, | ||
aggregate: aggregate, | ||
context: this._context.name, | ||
payload: payload | ||
}); | ||
}; | ||
Aggregate.prototype._handleDomainEvent = function(domainEventName, domainEvent) { | ||
if (this.instance["handle" + domainEventName]) { | ||
return this.instance["handle" + domainEventName](domainEvent); | ||
} else { | ||
return logger.debug("Tried to handle the DomainEvent '" + domainEventName + "' without a matching handle method"); | ||
} | ||
@@ -1710,12 +1699,76 @@ }; | ||
/***/ }, | ||
/* 23 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(24); | ||
/***/ }, | ||
/* 24 */ | ||
/***/ function(module, exports) { | ||
var DomainEvent; | ||
DomainEvent = (function() { | ||
function DomainEvent(params) { | ||
this.id = params.id; | ||
this.name = params.name; | ||
this.payload = params.payload; | ||
this.aggregate = params.aggregate; | ||
this.context = params.context; | ||
this.timestamp = new Date().getTime(); | ||
} | ||
return DomainEvent; | ||
})(); | ||
module.exports = DomainEvent; | ||
/***/ }, | ||
/* 25 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(25); | ||
module.exports = __webpack_require__(26); | ||
/***/ }, | ||
/* 25 */ | ||
/* 26 */ | ||
/***/ function(module, exports) { | ||
var counter, lastMicrosecondTimestamp; | ||
lastMicrosecondTimestamp = null; | ||
counter = 0; | ||
module.exports = { | ||
generateId: function() { | ||
var domainEventId, microsecondTimestamp; | ||
microsecondTimestamp = Date.now() * 1000; | ||
if (lastMicrosecondTimestamp === microsecondTimestamp) { | ||
counter++; | ||
domainEventId = microsecondTimestamp + counter; | ||
} else { | ||
counter = 0; | ||
domainEventId = microsecondTimestamp; | ||
} | ||
lastMicrosecondTimestamp = microsecondTimestamp; | ||
return domainEventId; | ||
} | ||
}; | ||
/***/ }, | ||
/* 27 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
module.exports = __webpack_require__(28); | ||
/***/ }, | ||
/* 28 */ | ||
/***/ function(module, exports) { | ||
var InMemoryStore, | ||
@@ -1722,0 +1775,0 @@ slice = [].slice; |
@@ -14,3 +14,3 @@ { | ||
"author": "efa Team <team@efa-gmbh.com>", | ||
"version": "0.18.0", | ||
"version": "0.19.0", | ||
"repository": { | ||
@@ -17,0 +17,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15426
640967
61