Compare commits

..

7 Commits

Author SHA1 Message Date
Nick O'Leary
3169f93cc2 Bump for 0.19.2 2018-08-24 13:25:02 +01:00
Nick O'Leary
c1a1a73599 Ensure node default color is used if palette.theme has no match 2018-08-24 13:08:49 +01:00
Christopher Hiller
db1b0ccb79 fix lost messages / properties in TCPRequest Node; closes #1863 (#1864)
- Added some more checks around this.
- We're choosing to only use the latest message when sending, which is
  effectively what was happening before the queue implementation.
2018-08-23 08:50:51 +01:00
Nick O'Leary
d373105b32 Fix typo in template.html 2018-08-21 13:42:51 +01:00
Nick O'Leary
28b311b7ed Improve error reporting from context plugin loading 2018-08-16 14:36:11 +01:00
Nick O'Leary
dcda513901 Prevent no-op edit of node marking as changed due to icon 2018-08-16 10:54:27 +01:00
Nick O'Leary
72c400794c Change node must handle empty rule set 2018-08-16 09:41:43 +01:00
14 changed files with 233 additions and 49 deletions

View File

@@ -1,3 +1,12 @@
#### 0.19.2: Maintenance Release
- Ensure node default colour is used if palette.theme has no match
- fix lost messages / properties in TCPRequest Node; closes #1863 (#1864)
- Fix typo in template.html
- Improve error reporting from context plugin loading
- Prevent no-op edit of node marking as changed due to icon
- Change node must handle empty rule set
#### 0.19.1: Maintenance Release
- Pull in latest twitter node

View File

@@ -881,7 +881,6 @@ RED.diff = (function() {
}
}
}
var properties = Object.keys(node).filter(function(p) { return p!='inputLabels'&&p!='outputLabels'&&p!='z'&&p!='wires'&&p!=='x'&&p!=='y'&&p!=='id'&&p!=='type'&&(!def.defaults||!def.defaults.hasOwnProperty(p))});
if (def.defaults) {
properties = properties.concat(Object.keys(def.defaults));
@@ -889,6 +888,13 @@ RED.diff = (function() {
if (node.type !== 'tab') {
properties = properties.concat(['inputLabels','outputLabels']);
}
if ( ((localNode && localNode.hasOwnProperty('icon')) || (remoteNode && remoteNode.hasOwnProperty('icon'))) &&
properties.indexOf('icon') === -1
) {
properties.unshift('icon');
}
properties.forEach(function(d) {
localChanged = false;
remoteChanged = false;

View File

@@ -1110,7 +1110,7 @@ RED.editor = (function() {
changed = true;
}
} else {
if (icon !== defaultIcon) {
if (icon !== "" && icon !== defaultIcon) {
changes.icon = editing_node.icon;
editing_node.icon = icon;
changed = true;

View File

@@ -800,8 +800,9 @@ RED.utils = (function() {
var paletteTheme = RED.settings.theme('palette.theme') || [];
if (paletteTheme.length > 0) {
if (!nodeColorCache.hasOwnProperty(type)) {
nodeColorCache[type] = def.color;
var l = paletteTheme.length;
for (var i=0;i<l;i++ ){
for (var i = 0; i < l; i++ ){
var themeRule = paletteTheme[i];
if (themeRule.hasOwnProperty('category')) {
if (!themeRule.hasOwnProperty('_category')) {

View File

@@ -77,7 +77,9 @@
}</pre>
<p>The resulting property will be:
<pre>Hello Fred. Today is Monday</pre>
<p>It is possible to use a property from the flow context or global context. Just use <code>{{flow.name}}</code> or <code>{{global.name}}</code>, or for persistable store <code>store</code> use <code>{{flow[store].name}}</code> or <code>{{flobal[store].name}}</code>.
<p>It is possible to use a property from the flow context or global context. Just use <code>{{flow.name}}</code> or
<code>{{global.name}}</code>, or for persistable store <code>store</code> use <code>{{flow[store].name}}</code> or
<code>{{global[store].name}}</code>.
<p><b>Note: </b>By default, <i>mustache</i> will escape any HTML entities in the values it substitutes.
To prevent this, use <code>{{{triple}}}</code> braces.
</script>

View File

@@ -467,6 +467,7 @@ module.exports = function(RED) {
connecting: false
};
enqueue(clients[connection_id].msgQueue, msg);
clients[connection_id].lastMsg = msg;
if (!clients[connection_id].connecting && !clients[connection_id].connected) {
var buf;
@@ -507,8 +508,7 @@ module.exports = function(RED) {
clients[connection_id].client.on('data', function(data) {
if (node.out === "sit") { // if we are staying connected just send the buffer
if (clients[connection_id]) {
let msg = dequeue(clients[connection_id].msgQueue) || {};
clients[connection_id].msgQueue.unshift(msg);
const msg = clients[connection_id].lastMsg || {};
msg.payload = data;
node.send(RED.util.cloneMessage(msg));
}
@@ -530,8 +530,7 @@ module.exports = function(RED) {
clients[connection_id].timeout = setTimeout(function () {
if (clients[connection_id]) {
clients[connection_id].timeout = null;
let msg = dequeue(clients[connection_id].msgQueue) || {};
clients[connection_id].msgQueue.unshift(msg);
const msg = clients[connection_id].lastMsg || {};
msg.payload = Buffer.alloc(i+1);
buf.copy(msg.payload,0,0,i+1);
node.send(msg);
@@ -553,8 +552,7 @@ module.exports = function(RED) {
i += 1;
if ( i >= node.splitc) {
if (clients[connection_id]) {
let msg = dequeue(clients[connection_id].msgQueue) || {};
clients[connection_id].msgQueue.unshift(msg);
const msg = clients[connection_id].lastMsg || {};
msg.payload = Buffer.alloc(i);
buf.copy(msg.payload,0,0,i);
node.send(msg);
@@ -573,8 +571,7 @@ module.exports = function(RED) {
i += 1;
if (data[j] == node.splitc) {
if (clients[connection_id]) {
let msg = dequeue(clients[connection_id].msgQueue) || {};
clients[connection_id].msgQueue.unshift(msg);
const msg = clients[connection_id].lastMsg || {};
msg.payload = Buffer.alloc(i);
buf.copy(msg.payload,0,0,i);
node.send(msg);

View File

@@ -283,6 +283,9 @@ module.exports = function(RED) {
}
}
function applyRules(msg, currentRule) {
if (currentRule >= node.rules.length) {
return Promise.resolve(msg);
}
var r = node.rules[currentRule];
var rulePromise;
if (r.t === "move") {

View File

@@ -1,6 +1,6 @@
{
"name": "node-red",
"version": "0.19.1",
"version": "0.19.2",
"description": "A visual tool for wiring the Internet of Things",
"homepage": "http://nodered.org",
"license": "Apache-2.0",
@@ -33,7 +33,7 @@
"flow"
],
"dependencies": {
"ajv": "6.5.2",
"ajv": "6.5.3",
"basic-auth": "2.0.0",
"bcryptjs": "2.4.3",
"body-parser": "1.18.3",
@@ -56,7 +56,7 @@
"jsonata": "1.5.4",
"media-typer": "0.3.0",
"memorystore": "1.6.0",
"mqtt": "2.18.3",
"mqtt": "2.18.5",
"multer": "1.3.1",
"mustache": "2.3.1",
"node-red-node-email": "0.1.*",
@@ -71,9 +71,9 @@
"passport-oauth2-client-password": "0.1.2",
"raw-body": "2.3.3",
"request": "2.88.0",
"semver": "5.5.0",
"semver": "5.5.1",
"sentiment": "2.1.0",
"uglify-js": "3.4.7",
"uglify-js": "3.4.8",
"when": "3.7.8",
"ws": "1.1.5",
"xml2js": "0.4.19"
@@ -103,6 +103,7 @@
"http-proxy": "^1.16.2",
"istanbul": "0.4.5",
"mocha": "^5.2.0",
"node-red-node-test-helper": "0.1.7",
"should": "^8.4.0",
"sinon": "1.17.7",
"stoppable": "^1.0.6",
@@ -110,8 +111,7 @@
"wdio-chromedriver-service": "^0.1.3",
"wdio-mocha-framework": "^0.6.2",
"wdio-spec-reporter": "^0.1.5",
"webdriverio": "^4.13.1",
"node-red-node-test-helper": "^0.1.7"
"webdriverio": "^4.13.1"
},
"engines": {
"node": ">=4"

View File

@@ -162,12 +162,10 @@ function start() {
if (settings.httpStatic) {
log.info(log._("runtime.paths.httpStatic",{path:path.resolve(settings.httpStatic)}));
}
redNodes.loadContextsPlugin().then(function () {
return redNodes.loadContextsPlugin().then(function () {
redNodes.loadFlows().then(redNodes.startFlows).catch(function(err) {});
started = true;
});
}).catch(function(err) {
console.log(err);
});
});
}

View File

@@ -163,7 +163,12 @@
"error-module-not-defined": "Context store '__storage__' missing 'module' option",
"error-invalid-module-name": "Invalid context store name: '__name__'",
"error-invalid-default-module": "Default context store unknown: '__storage__'",
"unknown-store": "Unknown context store '__name__' specified. Using default store."
"unknown-store": "Unknown context store '__name__' specified. Using default store.",
"error-loading-module": "Error loading context store: __message__",
"localfilesystem": {
"error-circular": "Context __scope__ contains a circular reference that cannot be persisted",
"error-write": "Error writing context: __message__"
}
}
}

View File

@@ -170,6 +170,8 @@ function load() {
defaultStore = "memory";
}
return resolve(Promise.all(promises));
}).catch(function(err) {
throw new Error(log._("context.error-loading-module",{message:err.toString()}));
});
}

View File

@@ -104,8 +104,6 @@ function loadFile(storagePath){
}else{
return Promise.resolve(undefined);
}
}).catch(function(err){
throw Promise.reject(err);
});
}
@@ -113,9 +111,21 @@ function listFiles(storagePath) {
var promises = [];
return fs.readdir(storagePath).then(function(files) {
files.forEach(function(file) {
promises.push(fs.readdir(path.join(storagePath,file)).then(function(subdirFiles) {
return subdirFiles.map(subfile => path.join(file,subfile));
}))
if (!/^\./.test(file)) {
var fullPath = path.join(storagePath,file);
var stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
promises.push(fs.readdir(fullPath).then(function(subdirFiles) {
var result = [];
subdirFiles.forEach(subfile => {
if (/\.json$/.test(subfile)) {
result.push(path.join(file,subfile))
}
});
return result;
}))
}
}
});
return Promise.all(promises);
}).then(dirs => dirs.reduce((acc, val) => acc.concat(val), []));
@@ -172,7 +182,7 @@ LocalFileSystem.prototype.open = function(){
if(err.code == 'ENOENT') {
return fs.ensureDir(self.storageBaseDir);
}else{
return Promise.reject(err);
throw err;
}
}).then(function() {
self._flushPendingWrites = function() {
@@ -185,7 +195,7 @@ LocalFileSystem.prototype.open = function(){
var context = newContext[scope];
var stringifiedContext = stringify(context);
if (stringifiedContext.circular && !self.knownCircularRefs[scope]) {
log.warn("Context "+scope+" contains a circular reference that cannot be persisted");
log.warn(log._("error-circular",{scope:scope}));
self.knownCircularRefs[scope] = true;
} else {
delete self.knownCircularRefs[scope];
@@ -249,7 +259,11 @@ LocalFileSystem.prototype.set = function(scope, key, value, callback) {
// there's a pending write which will handle this
return;
} else {
this._pendingWriteTimeout = setTimeout(function() { self._flushPendingWrites.call(self)}, this.flushInterval);
this._pendingWriteTimeout = setTimeout(function() {
self._flushPendingWrites.call(self).catch(function(err) {
log.error(log._("context.localfilesystem.error-write",{message:err.toString()}))
});
}, this.flushInterval);
}
} else if (callback && typeof callback !== 'function') {
throw new Error("Callback must be a function");
@@ -272,7 +286,7 @@ LocalFileSystem.prototype.set = function(scope, key, value, callback) {
}
var stringifiedContext = stringify(obj);
if (stringifiedContext.circular && !self.knownCircularRefs[scope]) {
log.warn("Context "+scope+" contains a circular reference that cannot be persisted");
log.warn(log._("error-circular",{scope:scope}));
self.knownCircularRefs[scope] = true;
} else {
delete self.knownCircularRefs[scope];

View File

@@ -59,7 +59,11 @@ describe('TCP Request Node', function() {
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('payload', Buffer(val1));
if (typeof val1 === 'object') {
msg.should.have.properties(Object.assign({}, val1, {payload: Buffer(val1.payload)}));
} else {
msg.should.have.property('payload', Buffer(val1));
}
done();
} catch(err) {
done(err);
@@ -79,7 +83,11 @@ describe('TCP Request Node', function() {
const n2 = helper.getNode("n2");
n2.on("input", msg => {
try {
msg.should.have.property('payload', Buffer(result));
if (typeof result === 'object') {
msg.should.have.properties(Object.assign({}, result, {payload: Buffer(result.payload)}));
} else {
msg.should.have.property('payload', Buffer(result));
}
done();
} catch(err) {
done(err);
@@ -95,31 +103,75 @@ describe('TCP Request Node', function() {
it('should send & recv data', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"time", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo", "ACK:foo", done)
testTCP(flow, {
payload: 'foo',
topic: 'bar'
}, {
payload: 'ACK:foo',
topic: 'bar'
}, done);
});
it('should retain complete message', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"time", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, {
payload: 'foo',
topic: 'bar'
}, {
payload: 'ACK:foo',
topic: 'bar'
}, done);
});
it('should send & recv data when specified character received', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"char", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo0bar0", "ACK:foo0", done);
testTCP(flow, {
payload: 'foo0bar0',
topic: 'bar'
}, {
payload: 'ACK:foo0',
topic: 'bar'
}, done);
});
it('should send & recv data after fixed number of chars received', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"count", splitc: "7", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo bar", "ACK:foo", done);
testTCP(flow, {
payload: 'foo bar',
topic: 'bar'
}, {
payload: 'ACK:foo',
topic: 'bar'
}, done);
});
it('should send & receive, then keep connection', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"sit", splitc: "5", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, "foo", "ACK:foo", done);
testTCP(flow, {
payload: 'foo',
topic: 'bar'
}, {
payload: 'ACK:foo',
topic: 'bar'
}, done);
});
it('should send & recv data to/from server:port from msg', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"", port:"", out:"time", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCP(flow, {payload:"foo", host:"localhost", port:port}, "ACK:foo", done)
testTCP(flow, {
payload: "foo",
host: "localhost",
port: port
}, {
payload: "ACK:foo",
host: 'localhost',
port: port
}, done);
});
});
@@ -127,36 +179,95 @@ describe('TCP Request Node', function() {
it('should send & recv data', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"time", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCPMany(flow, ['f', 'o', 'o'], 'ACK:foo', done);
testTCPMany(flow, [{
payload: 'f',
topic: 'bar'
}, {
payload: 'o',
topic: 'bar'
}, {
payload: 'o',
topic: 'bar'
}], {
payload: 'ACK:foo',
topic: 'bar'
}, done);
});
it('should send & recv data when specified character received', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"char", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCPMany(flow, ["foo0","bar0"], "ACK:foo0", done);
testTCPMany(flow, [{
payload: "foo0",
topic: 'bar'
}, {
payload: "bar0",
topic: 'bar'
}], {
payload: "ACK:foo0",
topic: 'bar'
}, done);
});
it('should send & recv data after fixed number of chars received', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"count", splitc: "7", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCPMany(flow, ["fo", "ob", "ar"], "ACK:foo", done);
testTCPMany(flow, [{
payload: "fo",
topic: 'bar'
}, {
payload: "ob",
topic: 'bar'
}, {
payload: "ar",
topic: 'bar'
}], {
payload: "ACK:foo",
topic: 'bar'
}, done);
});
it('should send & receive, then keep connection', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"sit", splitc: "5", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCPMany(flow, ["foo", "bar", "baz"], "ACK:foobarbaz", done);
testTCPMany(flow, [{
payload: "foo",
topic: 'bar'
}, {
payload: "bar",
topic: 'bar'
}, {
payload: "baz",
topic: 'bar'
}], {
payload: "ACK:foobarbaz",
topic: 'bar'
}, done);
});
it('should send & recv data to/from server:port from msg', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"", port:"", out:"time", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCPMany(flow, [
{payload:"f", host:"localhost", port:port},
{payload:"o", host:"localhost", port:port},
{payload:"o", host:"localhost", port:port}], "ACK:foo", done);
testTCPMany(flow, [{
payload: "f",
host: "localhost",
port: port
},
{
payload: "o",
host: "localhost",
port: port
},
{
payload: "o",
host: "localhost",
port: port
}
], {
payload: "ACK:foo",
host: 'localhost',
port: port
}, done);
});
it('should limit the queue size', function (done) {
@@ -168,5 +279,23 @@ describe('TCP Request Node', function() {
const expected = msgs.slice(0, -1);
testTCPMany(flow, msgs, "ACK:" + expected.join(''), done);
});
it('should only retain the latest message', function(done) {
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"time", splitc: "0", wires:[["n2"]] },
{id:"n2", type:"helper"}];
testTCPMany(flow, [{
payload: 'f',
topic: 'bar'
}, {
payload: 'o',
topic: 'baz'
}, {
payload: 'o',
topic: 'quux'
}], {
payload: 'ACK:foo',
topic: 'quux'
}, done);
});
});
});

View File

@@ -78,6 +78,24 @@ describe('change Node', function() {
done();
});
});
it('should no-op if there are no rules', function(done) {
var flow = [{"id":"changeNode1","type":"change","rules":[],"action":"","property":"","from":"","to":"","reg":false,"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.should.eql(sentMsg);
done();
} catch(err) {
done(err);
}
});
var sentMsg = {payload:"leaveMeAlong"};
changeNode1.receive(sentMsg);
});
});
describe('#set' , function() {