Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cqrs-swissknife

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cqrs-swissknife - npm Package Compare versions

Comparing version 0.4.33 to 0.4.34

27

domain/apis/generateAggregateApi.js

@@ -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 @@ };

7

domain/builders/commandBuilder.js

@@ -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",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc