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

apw

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apw - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

lib/asserts.js

60

lib/arch.js
var Q = require('qq'),
INHERIT = require('inherit'),
ASSERT = require('assert'),
ASSERTS = require('./asserts'),
Plan = require('./plan'),

@@ -76,3 +76,3 @@ U = require('./util'),

this.lock();
return Q.when(cb.apply(context))
return Q.call(cb, context)
.fin(function() {

@@ -125,6 +125,5 @@ _this.unlock();

addNode: function(node, parents, children) {
ASSERT.ok(!this.hasNode(node));
ASSERTS.absentId(node, this);
var id = node.getId();
this._assertNode('addNode call', id, parents, children);

@@ -171,3 +170,3 @@ this.nodes[id] = node;

replaceNode: function(node, parents, children) {
ASSERT.ok(this.hasNode(node));
ASSERTS.hasId(node, this);

@@ -217,22 +216,2 @@ var id = node.getId();

/**
* Assert simple loops for node.
*
* @param {String} id Node ID.
* @param {String[]|String} [parents] Parent nodes IDs to link with.
* @param {String[]|String} [children] Children nodes IDs to link with.
*/
_assertNode: function(place, id, parents, children) {
if (!parents && !children) return;
if (parents === true) parents = [];
if (children === true) children = [];
parents = U.toArray(parents);
children = U.toArray(children);
ASSERT.ok(parents.indexOf(id) === -1, 'found loop in ' + place + ': id = ' + id + ', parents = ' + parents);
ASSERT.ok(children.indexOf(id) === -1, 'found loop in ' + place + ': id = ' + id + ', children = ' + children);
parents.forEach(function(pId) {
ASSERT.ok(children.indexOf(pId) === -1, 'found loop in ' + place + ': parent id = ' + pId + ', children = ' + children);
});
},
/**
* Check if node with such ID has parents with provided IDs.

@@ -245,2 +224,5 @@ *

hasParents: function(id, parents) {
ASSERTS.idTypeIsOk(id);
ASSERTS.hasId(id, this);
return U.hasLink(U.getNodeId(id), this, 'parents', parents);

@@ -257,2 +239,5 @@ },

hasChildren: function(id, children) {
ASSERTS.idTypeIsOk(id);
ASSERTS.hasId(id, this);
return U.hasLink(U.getNodeId(id), this, 'children', children);

@@ -268,2 +253,5 @@ },

getChildren: function(id) {
ASSERTS.idTypeIsOk(id);
ASSERTS.hasId(id, this);
return [].concat(this.children[U.getNodeId(id)] || []);

@@ -279,2 +267,5 @@ },

getParents: function(id) {
ASSERTS.idTypeIsOk(id);
ASSERTS.hasId(id, this);
return [].concat(this.parents[U.getNodeId(id)] || []);

@@ -313,4 +304,9 @@ },

link: function(children, parents) {
children = U.toArray(children);
parents = U.toArray(parents);
U.toArray(children).forEach(function(child) {
ASSERTS.hasIds(children, this);
ASSERTS.hasIds(parents, this);
children.forEach(function(child) {
this._link(child, parents);

@@ -359,2 +355,7 @@ }, this);

unlink: function(id1, id2) {
ASSERTS.idTypeIsOk(id1);
ASSERTS.idTypeIsOk(id2);
ASSERTS.hasId(id1, this);
ASSERTS.hasId(id2, this);
U.unlink(this.parents[id1], this.children[id1], id2);

@@ -381,2 +382,5 @@ U.unlink(this.parents[id2], this.children[id2], id1);

removeTree: function(id, forced) {
ASSERTS.idTypeIsOk(id);
ASSERTS.hasId(id, this);
var children = this.children[id];

@@ -413,2 +417,6 @@

createPlan: function(targets) {
targets = U.toArray(targets);
ASSERTS.hasIds(targets, this);
var _this = this,

@@ -415,0 +423,0 @@ plan = new Plan(this, targets, '__plan_root__');

var INHERIT = require('inherit'),
ASSERTS = require('./asserts'),
util = require('./util'),

@@ -27,2 +28,3 @@ EventEmitter = require('events').EventEmitter,

this.children[this.root] = [];
this.parents[this.root] = [];

@@ -98,2 +100,11 @@ this.jobs = [];

/**
* Return this plan targets.
*
* @return {String[]} This plan targets.
*/
getTargets: function() {
return this.children[this.root];
},
/**
* Rescan jobs to find next ready to run jobs, previously blocked by unfinished jobs.

@@ -222,2 +233,6 @@ *

isActiveJob: function(id) {
return this.activeJobs.indexOf(id) !== -1;
},
/**

@@ -292,3 +307,3 @@ * Collect leaves IDs starting search from provided root node ID.

for (var job in hJobs) {
if (this.activeJobs.indexOf(job) === -1) jobs.push(job);
if (!this.isActiveJob(job)) jobs.push(job);
}

@@ -314,6 +329,8 @@

parents.forEach(function(parent) {
this.injectSubArch(child, parent)
}, this)
this.injectSubArch(child, parent);
}, this);
}, this);
ASSERTS.planNodesLinkedToRoot(this);
return this;

@@ -330,7 +347,14 @@ },

injectSubArch: function(child, parent) {
if (!this.isJobAlreadyDone(child) && !this.isJobAlreadyDone(parent)) {
var children = this.arch.getChildren(child);
ASSERTS.idTypeIsString(child);
ASSERTS.idTypeIsString(parent);
if (this.hasNode(parent) &&
!this.isJobAlreadyDone(child) &&
!this.isJobAlreadyDone(parent)) {
// NOTE: assert parent in case we are really going to link to it
ASSERTS.notActiveJob(parent, this);
this._link(child, parent);
children.forEach(function(id) {
this.arch.getChildren(child).forEach(function(id) {
this.injectSubArch(id, child);

@@ -377,2 +401,7 @@ }, this);

unlink: function(id1, id2) {
ASSERTS.idTypeIsString(id1);
ASSERTS.idTypeIsString(id2);
ASSERTS.hasId(id1, this);
ASSERTS.hasId(id2, this);
var parents1 = this.parents[id1],

@@ -401,3 +430,3 @@ parents2 = this.parents[id2];

hasNode: function(id) {
return !!this.parents[id] && this.parents[id].length > 0;
return !!this.parents[id];
},

@@ -413,2 +442,5 @@

hasParents: function(id, parents) {
ASSERTS.idTypeIsString(id);
ASSERTS.hasId(id, this);
return util.hasLink(id, this, 'parents', parents);

@@ -425,2 +457,5 @@ },

hasChildren: function(id, children) {
ASSERTS.idTypeIsString(id);
ASSERTS.hasId(id, this);
return util.hasLink(id, this, 'children', children);

@@ -436,2 +471,5 @@ },

removeNode: function(id) {
ASSERTS.idTypeIsString(id);
ASSERTS.hasId(id, this);
var parents = this.parents[id],

@@ -459,2 +497,5 @@ children = this.children[id];

removeTree: function(id, forced) {
ASSERTS.idTypeIsString(id);
ASSERTS.hasId(id, this);
var children = this.children[id];

@@ -490,4 +531,6 @@

addJob: function(id) {
if (this.doneJobs.indexOf(id) === -1 &&
this.activeJobs.indexOf(id) === -1 &&
ASSERTS.idTypeIsString(id);
if (!this.isJobAlreadyDone(id) &&
!this.isActiveJob(id) &&
this.jobs.indexOf(id) === -1) this.jobs.push(id);

@@ -527,2 +570,4 @@

onJobDone: function(id) {
ASSERTS.hasId(id, this.arch);
this.parents[id].forEach(function(pID) {

@@ -552,3 +597,3 @@ var children = this.children[pID];

this.failed = true;
this.onAllDone();
this.onAllFail();

@@ -564,2 +609,4 @@ return this;

onAllDone: function() {
ASSERTS.planDone(this);
this.emit('allDone', this.getId());

@@ -571,2 +618,15 @@

/**
* Finalize all done activity on plan fail, emit allDone event.
*
* @returns {Plan} Chainable API.
*/
onAllFail: function() {
ASSERTS.planFail(this);
this.emit('allDone', this.getId());
return this;
},
/**
* Check if all jobs are done.

@@ -573,0 +633,0 @@ *

var Q = require('qq'),
INHERIT = require('inherit'),
ASSERTS = require('./asserts'),
extend = require('./util').extend;

@@ -34,2 +35,3 @@

if (Object.keys(_this.plans).length) {
console.error('*************************************************');
console.error('WARNING! There are %s unfinished build processes!', Object.keys(_this.plans).length);

@@ -40,2 +42,12 @@ console.error(

'they return.');
console.log('Dump of plans of unfinished build processes follow.');
Object.keys(_this.plans).forEach(function(id) {
var plan = _this.plans[id];
console.error('\nPlan(%s) for targets: %s\n%s', plan.getId(), plan.getTargets().join(', '), plan);
console.error('Jobs: %s', plan.jobs.join(', '));
console.error('Active jobs: %s', plan.activeJobs.join(', '));
});
console.error('*************************************************');
}

@@ -190,2 +202,4 @@

workPlan: function(job, plan) {
ASSERTS.planLinksOk(plan);
var _this = this,

@@ -192,0 +206,0 @@ onDone = function() {

{
"name": "apw",
"version": "0.3.0",
"version": "0.3.1",
"homepage": "http://github.com/bem/apw",

@@ -5,0 +5,0 @@ "author": "Sergey Kryzhanovsky <skryzhanovsky@ya.ru> (http://github.com/afelix)",

@@ -231,11 +231,2 @@ var VOWS = require('vows'),

'Node removal (absent)': {
topic: getSimpleArch,
'removeNode() absent': function(arch) {
assert.equal(arch.hasNode('XXX'), false);
arch.removeNode('XXX');
}
},
'Node link': {

@@ -242,0 +233,0 @@ topic: function() {

@@ -66,49 +66,2 @@ var Q = require('qq'),

.addNode({
getId: function() {
return '5A';
},
run: function(ctx) {
state.push(ctx.plan);
}
})
.addNode({
getId: function() {
return '5B';
},
run: function(ctx) {
ctx.plan.lock();
ctx.plan.link('5D', '5C');
ctx.plan.unlock();
}
}, '5A')
.addNode(createNode('5C'), '5B')
.addNode(createNode('5D'), '5C')
.addNode({
getId: function() {
return '6A';
},
run: function(ctx) {
state.push(ctx.plan);
}
})
.addNode(createNode('6B'), '6A')
.addNode(createNode('6C'), '6A')
.addNode(createNode('6D'), '6B')
.addNode({
getId: function() {
return '6E';
},
run: function(ctx) {
ctx.plan.lock();
ctx.plan.link('6C', '6B');
ctx.plan.unlock();
}
}, ['6B', '6C'])
.addNode(createNode('6F'), '6D')
.addNode(createNode('6G'), '6D')
.addNode(createNode('6H'), '6E')
.addNode(createNode('6I'), '6H')
.addNode(createNode('7A'))

@@ -200,23 +153,2 @@ .addNode(createNode('7B'), '7A')

'Do not link done node (simple plan)': {
topic: function() {
var _this = this,
state = [];
Q.when(
getAPW(getArch(state)).process('5A'),
function(value) { _this.callback(null, state) },
function(error) { _this.callback(error, null) }
).end();
},
'there are no double done jobs': function(error, state) {
var plan = state.pop();
assert.isNull(error);
assert.lengthOf(plan.doneJobs, 4);
['5A', '5B', '5C', 'D']
.forEach(function(id) {
assert.equal(plan.hasNode(id), false, 'has ID: ' + id);
});
}
},
'Run plans on same node': {

@@ -242,23 +174,2 @@ topic: function() {

'Do not link done node (partly done subarch)': {
topic: function() {
var _this = this,
state = [];
Q.when(
getAPW(getArch(state)).process('6A'),
function(value) { _this.callback(null, state) },
function(error) { _this.callback(error, null) }
).end();
},
'there are no double done jobs': function(error, state) {
var plan = state.pop();
assert.isNull(error);
assert.lengthOf(plan.doneJobs, 9);
['6A', '6B', '6C', '6D', '6E', '6F', '6G', '6H', '6I']
.forEach(function(id) {
assert.equal(plan.hasNode(id), false, 'has ID: ' + id);
});
}
},
'All done subscribers': {

@@ -265,0 +176,0 @@ topic: function() {

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