You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

cqrs-saga

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cqrs-saga - npm Package Compare versions

Comparing version

to
1.7.0

84

lib/pm.js

@@ -82,5 +82,6 @@ 'use strict';

this.onCommand(function (cmd) {
debug('emit:', cmd);
});
// DO not register a "dummy" onCommand handler because of getTimeoutedSagas handling
// this.onCommand(function (cmd) {
// debug('emit:', cmd);
// });

@@ -468,25 +469,58 @@ this.onEventMissing(function (info, evt) {

sagaModel.commit = function (clb) {
if (sagaModel.isDestroyed()) {
self.removeSaga(sagaModel, clb);
} else if (calledAddCommandToSend) {
var cmds = sagaModel.getUndispatchedCommands();
async.each(cmds, function (cmd, fn) {
if (dotty.exists(cmd, self.definitions.command.id)) {
return fn(null);
}
var cmds = calledAddCommandToSend ? sagaModel.getUndispatchedCommands() : [];
self.getNewId(function (err, id) {
function onAfterCommit(err) {
if (err) return clb(err);
var undispCmds = _.map(sagaModel.getUndispatchedCommands(), function (c) {
return { id: dotty.get(c, self.definitions.command.id), payload: c };
});
function setCommandToDispatched (c, cb) {
debug('set command to dispatched');
self.setCommandToDispatched(dotty.get(c, self.definitions.command.id), sagaModel.id, function (err) {
if (err) {
return cb(err);
}
sagaModel.removeUnsentCommand(c);
cb(null);
});
}
if (!self.onCommandHandle) return clb(null);
async.each(undispCmds, function (cmd, callback) {
debug('publish a command');
self.onCommandHandle(cmd, function (err) {
if (err) {
debug(err);
return fn(err);
return callback(err);
}
dotty.put(cmd, self.definitions.command.id, id);
fn(null);
setCommandToDispatched(cmd, callback);
});
}, function (err) {
}, clb);
}
async.each(cmds, function (cmd, fn) {
if (dotty.exists(cmd, self.definitions.command.id)) {
return fn(null);
}
self.getNewId(function (err, id) {
if (err) {
debug(err);
return callback(err);
return fn(err);
}
dotty.put(cmd, self.definitions.command.id, id);
fn(null);
});
}, function (err) {
if (err) {
debug(err);
return callback(err);
}
if (sagaModel.isDestroyed()) {
self.removeSaga(sagaModel, onAfterCommit);
} else if (calledAddCommandToSend) {
sagaModel.setCommitStamp(new Date());

@@ -496,10 +530,10 @@ var undispCmds = _.map(sagaModel.getUndispatchedCommands(), function (c) {

});
self.sagaStore.save(sagaModel.toJSON(), undispCmds, clb);
});
} else {
var err = new Error('Use commit only to remove a saga or to addCommandToSend!');
debug(err);
if (clb) { return clb(err); }
throw err;
}
self.sagaStore.save(sagaModel.toJSON(), undispCmds, onAfterCommit);
} else {
var err = new Error('Use commit only to remove a saga or to addCommandToSend!');
debug(err);
if (clb) { return clb(err); }
throw err;
}
});
};

@@ -506,0 +540,0 @@ sagaModels.push(sagaModel);

{
"author": "adrai",
"name": "cqrs-saga",
"version": "1.6.27",
"version": "1.7.0",
"private": false,

@@ -15,9 +15,9 @@ "main": "index.js",

"async": "1.5.2",
"debug": "2.3.3",
"debug": "2.6.3",
"dotty": "0.0.2",
"jsondate": "0.0.1",
"lodash": "4.17.2",
"lodash": "4.17.4",
"parent-require": "1.0.0",
"tolerance": "1.0.0",
"uuid": "3.0.0"
"uuid": "3.0.1"
},

@@ -24,0 +24,0 @@ "devDependencies": {

@@ -482,2 +482,4 @@ # Introduction

saga.commit(function (err) {
// if you have registered the pm.onCommand handler it will be automatically executed,
// if you have not registered the pm.onCommand handler you need to publish and set the command to dispatched on your own!
cmds.forEach(function (cmd) {

@@ -484,0 +486,0 @@ // publish cmd...

@@ -0,1 +1,4 @@

## [v1.7.0](https://github.com/adrai/node-cqrs-saga/compare/v1.6.27...v1.7.0)
- for getTimeoutedSagas handling: if the pm.onCommand handler is registered it will be automatically executed
## [v1.6.27](https://github.com/adrai/node-cqrs-saga/compare/v1.6.25...v1.6.27)

@@ -2,0 +5,0 @@ - fix for new mongodb driver