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

arch-orchestrator

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arch-orchestrator - npm Package Compare versions

Comparing version 1.3.3 to 1.4.0

39

lib/orchestrator.js

@@ -30,2 +30,18 @@ 'use strict';

function downstreamResult(result, toFn, metadata) {
/*jshint validthis:true */
var orchestrator = this;
if (metadata.resultTo) {
// argument of metadata.retulsTo functions will be
// the same as result of current function -> only this step of chain
orchestrator.redirect.prependResult(result, metadata);
}
// downstream result
result = toFn.call(toFn, result);
return orchestrator.normalizer.normalizeResult(result);
}
/**

@@ -62,21 +78,10 @@ * Wrapper for all chain functions.

if (metadata.resultTo) {
var oldNext = next;
next = function () {
// result from current function
var result = Array.prototype.slice.apply(arguments);
// argument of metadata.retulsTo functions will be
// the same as result of current function -> only this step of chain
orchestrator.redirect.prependResult(result, metadata);
return oldNext.apply(oldNext, arguments);
};
var res = fn.apply(fn, args);
if (res.then) {
return res.then(function (_res) {
return downstreamResult.call(orchestrator, _res, next, metadata);
});
}
args.unshift(next);
var res = fn.apply(fn, args);
return orchestrator.normalizer.normalizeResult(res);
return downstreamResult.call(orchestrator, res, next, metadata);
};

@@ -83,0 +88,0 @@ }

@@ -68,7 +68,7 @@ 'use strict';

metadata.resultTo.forEach(function (fn) {
if (!fn.meta.args) {
fn.meta.args = result;
} else {
fn.meta.args = fn.meta.args.concat(result);
if (!Array.isArray(fn.meta.args)) {
fn.meta.args = [];
}
fn.meta.args = fn.meta.args.concat(result);
});

@@ -75,0 +75,0 @@ }

{
"name": "arch-orchestrator",
"version": "1.3.3",
"version": "1.4.0",
"description": "Orchestrator for large node.js applications",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -39,2 +39,3 @@ arch-orchestrator

When end of chain is reached, result will be available.
**Note that if you use ``arch-orchestrator`` next function will be called automatically for you.**

@@ -83,21 +84,21 @@ So, central point of this system is orchestrator, and there is power of architecture this type.

```
// each task accepts next as fist argument,
// and result from previous action as second argument.
function add(next, arg) {
// each task accepts result(s) from previous action(s).
function add(arg) {
// each task need to call next function
// next function will call next part of chain, which is dynamic,
// and defined by orchestrator
return next(arg + 10);
// here ``arch-orchestrator`` is calling ``next`` function for us,
return arg + 10;
}
function substract(next, arg) {
return next(arg - 10);
function substract(arg) {
return arg - 10;
}
function multiply(next, arg) {
return next(arg * 10);
function multiply(arg) {
return arg * 10;
}
function divide(next, arg) {
return next(arg / 10);
function divide(arg) {
return arg / 10;
}

@@ -222,3 +223,3 @@ ```

```Javascript
function fn4(next, argFromArgsTo, argFromResultTo) {
function fn4(argFromArgsTo, argFromResultTo) {
// do something awesome

@@ -225,0 +226,0 @@ }

@@ -12,56 +12,64 @@ 'use strict';

function fn1(next, arg) {
return next(arg + 100);
function fn1(arg) {
return (arg + 100);
}
function fn2(next, arg) {
return next(arg + 200);
function fn2(arg) {
return (arg + 200);
}
function fn3(next, arg) {
return next(arg + 300);
function fn3(arg) {
return (arg + 300);
}
function fn4(next, arg1, arg2) {
return next(arg1 + arg2 + 10);
function fn4(arg1, arg2) {
return (arg1 + arg2 + 10);
}
function first(next) {
return next('first');
function first() {
return 'first';
}
function second(next) {
return next('second');
function second() {
return 'second';
}
function third(next) {
return next('third');
function third() {
return 'third';
}
function * firstGen(next, arg) {
return next(arg + 1);
function * firstGen(arg) {
return arg + 1;
}
function * secondGen(next, arg) {
return next(arg + 10);
function * secondGen(arg) {
return arg + 10;
}
function * thirdGen(next, arg) {
return next(arg + 10);
function * thirdGen(arg) {
return (arg + 10);
}
function fnMultipleArgs1(next, arg1, arg2) {
function fnMultipleArgs1(arg1, arg2) {
arg1 += 1;
arg2 += 2;
return next(arg1, arg2);
return arg1 + arg2;
}
function fnMultipleArgs2(next, arg1, arg2) {
arg1 += 3;
arg2 += 4;
function fnMultipleArgs2(sum) {
sum += 3;
return next(arg1, arg2);
return sum;
}
function fnArray(arg) {
return [arg, arg];
}
function fnExpectArray(arg) {
console.log(Array.isArray(arg));
return arg;
}
describe('arch-orchestrator', function () {

@@ -80,3 +88,22 @@ var fn;

it('should receive array if array is passed as result', function () {
fn = orchestrator()
.setNext(fnArray)
.setNext(fnExpectArray)
.end();
var res = fn(5);
res[0].should.be.exactly(5);
res[1].should.be.exactly(5);
(Array.isArray(res)).should.be.ok;
});
it('should be able to use result from multiple functions', function () {
fn = orchestrator()
.setNext(fn1)
.setNext(fn2)
.setNext(fn3)
.end();
var res = fn(0);

@@ -180,6 +207,5 @@ res.should.be.exactly(600);

var res = fn(10, 20);
var res = fn(1, 1);
res[0].should.be.exactly(14);
res[1].should.be.exactly(26);
res.should.be.exactly(8);
});

@@ -186,0 +212,0 @@

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