New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chainit

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chainit - npm Package Compare versions

Comparing version 1.3.1 to 2.0.0-backcompat

82

index.js

@@ -17,5 +17,2 @@ module.exports = chainit;

/**
* push chained function into queue
*/
function pushTo(depth, task) {

@@ -25,4 +22,3 @@ var queue = queues[depth] || (queues[depth] = getNewQueue(depth));

if (depth > 0) {
queue.push(task);
return queue.start();
return queue.push(task);
}

@@ -37,3 +33,2 @@

queue.push(task);
queue.start();
});

@@ -52,6 +47,2 @@

/**
* initialize new queue as subqueue to API command
* @param {Integer} newDepth queue depth
*/
function getNewQueue(newDepth) {

@@ -63,3 +54,3 @@ var queue = new Queue({

queue.on('end', function() {
queue.on('drain', function() {
if (newDepth > 0) {

@@ -78,3 +69,3 @@ wakeupChain(newDepth);

queues[depth - 1].concurrency = 1;
queues[depth - 1].start();
queues[depth - 1].process();
}

@@ -94,5 +85,3 @@

/**
* register static methods, not chained
*/
// static methods, not chained
Object.keys(Constructor)

@@ -103,5 +92,3 @@ .forEach(function(name) {

/**
* register prototype methods, chained
*/
// prototype methods, chained
var allFn = Object.keys(Constructor.prototype);

@@ -136,3 +123,2 @@

// if parent queue is running, stop it and run new subquene
if (currentDepth > 0 && queues[currentDepth - 1].concurrency > 0) {

@@ -150,6 +136,6 @@ queues[currentDepth - 1].concurrency = 0;

if (arguments[0] instanceof Error) {
arguments[0].message = '[' + fnName + niceArgs(callArguments) + '] ' + arguments[0].message;
arguments[0].message = '[' + fnName + niceArgs(callArguments) + '] <= \n ' + arguments[0].message;
}
// if API provides custom async callback, execute it
if (customCb) {

@@ -159,3 +145,2 @@ customCb.apply(ctx, cbArgs);

// call required Queue callback
cb();

@@ -168,7 +153,4 @@ });

// put async function into queue
pushTo(currentDepth, task);
// return this to make API chainable
// like api.command1().command2()
return this;

@@ -182,29 +164,5 @@ }

Chain.prototype.__start = function() {
if(!queues.length || !queues[currentDepth-1]) {
return false;
}
queues[currentDepth-1].start();
}
Chain.prototype.__stop = function() {
if(!queues.length || !queues[currentDepth-1]) {
return false;
}
queues[currentDepth-1].stop();
}
return Chain;
}
/**
* add custom function into chain
* @param {Object} to Context
* @param {String} fnName function name
* @param {Function} fn function
*/
chainit.add = function add(to, fnName, fn) {

@@ -218,26 +176,2 @@ if (to.prototype && to.prototype.__addToChain) {

/**
* start chain
* @param {Object} to Context
*/
chainit.start = function start(to) {
if (to.prototype && to.prototype.__start) {
to.prototype.__start();
} else {
to.__start();
}
}
/**
* stop chain
* @param {Object} to Context
*/
chainit.stop = function stop(to) {
if (to.prototype && to.prototype.__stop) {
to.prototype.__stop();
} else {
to.__stop();
}
}
function hasPending(queue) {

@@ -252,2 +186,2 @@ return queue.length >= 1;

.replace(/\]$/, ')');
};
};

4

package.json
{
"name": "chainit",
"version": "1.3.1",
"version": "2.0.0-backcompat",
"description": "Turn an asynchronous JavaScript api into an asynchronous chainable JavaScript api.",

@@ -19,3 +19,3 @@ "main": "index.js",

"dependencies": {
"queue": "~2.2.0"
"queue": "~1.0.2"
},

@@ -22,0 +22,0 @@ "keywords": [

@@ -368,25 +368,2 @@ describe('chaining an Api', function() {

it('supports starting and stopping a queue', function(done) {
var hasStopped = false;
setTimeout(function() {
assert.equal(hasStopped,true);
chainit.start(o);
hasStopped = false;
},300)
o
.concat('1')
.concat('2')
.call(function() {
chainit.stop(o);
hasStopped = true;
})
.concat('3',function() {
assert.equal(this.s,'123');
assert.equal(hasStopped, false);
done();
})
});
describe('inherited APIS', function() {

@@ -393,0 +370,0 @@ var ChainedInheritedApi;

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