cqrs-swissknife
Advanced tools
Comparing version 0.4.33 to 0.4.34
@@ -8,2 +8,9 @@ 'use strict'; | ||
const deferredEventsSymbol = Symbol('aggregate:deferedEvents'); | ||
const commandSymbol = Symbol('aggregate:command'); | ||
const modeSymbol = Symbol('aggregate:modeSymbol'); | ||
const HANDLER_MORE = 'handler'; | ||
const ASYNC_HANDLER_MODE = 'async_handle'; | ||
// direct copy from : https://github.com/adrai/node-cqrs-domain/blob/9b17c73853ec59d451d3101492cb00b16e1ec9e3/lib/definitions/aggregate.js#L70 | ||
@@ -79,7 +86,17 @@ const generateEvent = (aggregate, model, eventEnricher, cmd, name, payload, metadata, version = 0) => { | ||
const generateAggregateApi = (aggregate, eventEnricher = valueop) => { | ||
const AggregateApi = function AggregateApi(aggregateModel, command) { | ||
const AggregateApi = function AggregateApi(aggregateModel, command, mode = HANDLER_MORE) { | ||
this._aggregateModel = aggregateModel; | ||
this._command = command; | ||
this.id = this._aggregateModel.id; | ||
this[modeSymbol] = mode; | ||
this[commandSymbol] = command; | ||
this.apply.__self = this; | ||
if (mode === ASYNC_HANDLER_MODE && !this._aggregateModel[deferredEventsSymbol]) { | ||
this._aggregateModel[deferredEventsSymbol] = this._aggregateModel[deferredEventsSymbol] || []; | ||
} else if (mode === HANDLER_MORE && this._aggregateModel[deferredEventsSymbol]) { | ||
this._aggregateModel[deferredEventsSymbol].forEach(params => this.apply(...params)); | ||
this._aggregateModel[deferredEventsSymbol] = []; | ||
} | ||
}; | ||
@@ -89,3 +106,3 @@ | ||
if (!attr) | ||
return this._aggregateModel.attributes: | ||
return this._aggregateModel.attributes; | ||
return this._aggregateModel.get(attr); | ||
@@ -95,3 +112,5 @@ }; | ||
AggregateApi.prototype.apply = function apply(name, payload, metadata) { | ||
generateEvent(aggregate, this._aggregateModel, eventEnricher, this._command, name, payload, metadata); | ||
if (this[modeSymbol] === HANDLER_MORE) | ||
return generateEvent(aggregate, this._aggregateModel, eventEnricher, this[commandSymbol], name, payload, metadata); | ||
return this._aggregateModel[deferredEventsSymbol].push([name, payload, metadata]); | ||
// this._aggregateModel.apply(eventEnricher(evt, this._aggregateModel, this._command) || evt); | ||
@@ -98,0 +117,0 @@ }; |
@@ -75,3 +75,3 @@ 'use strict'; | ||
if (typeof item === 'function') { | ||
result.command = new Command(commandSettings, (cmd, agg) => item(cmd, new AggregateApi(agg, cmd), customApiBuilder(cmd))); | ||
result.command = new Command(commandSettings, (cmd, agg) => item(cmd, new AggregateApi(agg, cmd, 'handler'), customApiBuilder(cmd))); | ||
continue; | ||
@@ -96,4 +96,7 @@ } | ||
if (item.preCondition) | ||
if (item.preCondition) { | ||
if ('mode' in item) | ||
item.preCondition = async (cmd, agg) => item.preCondition(cmd, new AggregateApi(agg, cmd, item.mode)); | ||
result.preConditions.push(new PreCondition({ name: [commandName] }, asyncParamCustomErrorApiCallback(item.preCondition, errorBuilders.businessRule, customApiBuilder, 'cmd', 'agg'))); | ||
} | ||
} | ||
@@ -100,0 +103,0 @@ |
{ | ||
"name": "cqrs-swissknife", | ||
"version": "0.4.33", | ||
"version": "0.4.34", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31158
823