diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ea3845c2..9d24243fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,59 @@ +#### 1.0.6: Maintenance Release + +Runtime + + - Update to JSONata 1.8.3 + - #2536 Handle clone of null in utils + +Editor + + - Prevent button label wrapping in typedInput + - Handle error objects when reporting in palette manager + +Nodes + + - Inject: Revert to cron 1.7.2 + - UDP: when reusing input socket honour the broadcast mode. + +#### 1.0.5: Maintenance Release + +Runtime + + - #2500 Support for context stores using JSONata and evaluateNodeProperty() + - Add better handling of host-key-verify error with projects + - #2517 Handle false values in $env() properly + - #2514 Ensure complete node scope is remapped in subflows + - #2513 Flows/subflows must preinitialise their context objects + - Clear node.close timeout to avoid unnecessary work on restart + - #2532 Set flow.disabled when disabled property is false + - #2522 Ensure file context does not write 'undefined' to store + +Editor + + - #2489 Fix XPath in UI tests + - #2504 Fix paletteCategories order + - #2501 Add page objects for UI testing + - #2494 Check node props when deciding if pasted node can splice links + - #2521 Don't double-sanitize node name in debug sidebar + - #2519 German i18n updates + - #2523 Update nodeTabMap when replacing unknown nodes + - Update TypedInput to use flexbox and remove resizing code + - Handle nodes with no wires array + - Do not collapse whitespace in Debug string messages + +Nodes + + - File: Remove old legacy wording from file node info to stop confusing users. + - Join: Ensure join node handles missing buffer joiner when not in string mode + - Exec: make exec node logging consistent with itself. (only be verbose when in verbose mode) + - Trigger: reset default timeout value when switching away from wait for reset + - Join: Fix join to not crash on appending invalid types to buffer. + - MQTT out: Add warning if topic contains + or # + - #2502 WebSocket i18n update + - #2508 Add Japanese translation for join node + - TCP out: tidy up select of which rows to display + + #### 1.0.4: Maintenance Release Runtime diff --git a/package.json b/package.json index 0ccf2767c..5bf4e5ee0 100644 --- a/package.json +++ b/package.json @@ -32,9 +32,9 @@ "clone": "2.1.2", "content-type": "1.0.4", "cookie": "0.4.0", - "cookie-parser": "1.4.4", + "cookie-parser": "1.4.5", "cors": "2.8.5", - "cron": "1.8.2", + "cron": "1.7.2", "denque": "1.4.1", "express": "4.17.1", "express-session": "1.17.0", @@ -47,18 +47,18 @@ "is-utf8": "0.2.1", "js-yaml": "3.13.1", "json-stringify-safe": "5.0.1", - "jsonata": "1.8.1", + "jsonata": "1.8.3", "lodash.clonedeep": "^4.5.0", "media-typer": "1.1.0", "memorystore": "1.6.2", "mime": "2.4.4", "mqtt": "2.18.8", "multer": "1.4.2", - "mustache": "4.0.0", + "mustache": "4.0.1", "node-red-node-rbe": "^0.2.6", "node-red-node-sentiment": "^0.1.6", "node-red-node-tail": "^0.1.0", - "nopt": "4.0.1", + "nopt": "4.0.3", "oauth2orize": "1.11.0", "on-headers": "1.0.2", "passport": "0.4.1", @@ -67,16 +67,16 @@ "raw-body": "2.4.1", "request": "2.88.0", "semver": "6.3.0", - "uglify-js": "3.8.0", + "uglify-js": "3.8.1", "when": "3.7.8", "ws": "6.2.1", "xml2js": "0.4.23" }, "optionalDependencies": { - "bcrypt": "3.0.6" + "bcrypt": "3.0.8" }, "devDependencies": { - "marked": "0.8.0", + "marked": "0.8.2", "dompurify": "2.0.8", "grunt": "~1.0.4", "grunt-chmod": "~1.1.1", diff --git a/packages/node_modules/@node-red/editor-api/package.json b/packages/node_modules/@node-red/editor-api/package.json index 01d49bd96..936fe3edc 100644 --- a/packages/node_modules/@node-red/editor-api/package.json +++ b/packages/node_modules/@node-red/editor-api/package.json @@ -26,7 +26,7 @@ "express": "4.17.1", "memorystore": "1.6.2", "mime": "2.4.4", - "mustache": "4.0.0", + "mustache": "4.0.1", "oauth2orize": "1.11.0", "passport-http-bearer": "1.0.1", "passport-oauth2-client-password": "0.1.2", diff --git a/packages/node_modules/@node-red/editor-client/src/js/nodes.js b/packages/node_modules/@node-red/editor-client/src/js/nodes.js index 587a23d5b..e6b4bccca 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/nodes.js +++ b/packages/node_modules/@node-red/editor-client/src/js/nodes.js @@ -1224,7 +1224,7 @@ RED.nodes = (function() { defaults: {}, label: "unknown: "+n.type, labelStyle: "red-ui-flow-node-label-italic", - outputs: n.outputs||n.wires.length, + outputs: n.outputs|| (n.wires && n.wires.length) || 0, set: registry.getNodeSet("node-red/unknown") } } else { diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js index 760f3c879..06b0dc81d 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/typedInput.js @@ -737,11 +737,13 @@ this.optionExpandButton.shown = false; } if (this.optionSelectTrigger) { - this.optionSelectTrigger.show(); + this.optionSelectTrigger.css({"display":"inline-flex"}); if (!opt.hasValue) { + this.optionSelectTrigger.css({"flex-grow":1}) this.elementDiv.hide(); this.valueLabelContainer.hide(); } else { + this.optionSelectTrigger.css({"flex-grow":0}) this.elementDiv.show(); this.valueLabelContainer.hide(); } diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js index 97214ace9..f89d6ab9e 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js @@ -223,7 +223,11 @@ RED.palette.editor = (function() { var setElements = nodeEntry.sets[setName]; if (set.err) { errorCount++; - $("
The node can be configured to resend a message at a regular interval until it is reset by a received message.
-Optionally, the node can be configured to treat messages with msg.topic
as if they
- are separate streams.
Optionally, the node can be configured to treat messages as if they are separate streams,
+ using a msg property to identify each stream. Default msg.topic
.
The column template can contain an ordered list of column names. When converting CSV to an object, the column names will be used as the property names. Alternatively, the column names can be taken from the first row of the CSV.
When converting to CSV, the column template is used to identify which properties to extract from the object and in what order.
+If the template is blank then the node can use a simple comma separated list of properties supplied in msg.columns
to
+ determine what to extract. If that is not present then all the object properties are ouput in the order in which they are found.
If the input is an array then the columns template is only used to optionally generate a row of column titles.
If 'parse numerical values' option is checked, string numerical values will be returned as numbers, ie. middle value '1,"1.5",2'.
If 'include empty strings' option is checked, empty strings will be returned in result, ie. middle value '"1","",3'.
If 'include null values' option is checked, null values will be returned in result, ie. middle value '"1",,3'.
-The node can accept a multi-part input as long as the parts
property is set correctly.
The node can accept a multi-part input as long as the parts
property is set correctly, for example from a file-in node or split node.
If outputting multiple messages they will have their parts
property set and form a complete message sequence.
Note: the column template must be comma separated - even if a different separator is chosen for the data.
diff --git a/packages/node_modules/@node-red/nodes/locales/ja/messages.json b/packages/node_modules/@node-red/nodes/locales/ja/messages.json index e15947fa6..32b59361b 100755 --- a/packages/node_modules/@node-red/nodes/locales/ja/messages.json +++ b/packages/node_modules/@node-red/nodes/locales/ja/messages.json @@ -302,7 +302,7 @@ "wait-for": "指定した時間待機", "wait-loop": "指定した時間間隔毎に送信を繰り返す", "for": "処理対象", - "bytopics": "msg.topic毎", + "bytopics": "毎", "alltopics": "全メッセージ", "duration": { "ms": "ミリ秒", @@ -719,6 +719,11 @@ "mac": "Mac (\\r)", "windows": "Windows (\\r\\n)" }, + "hdrout": { + "none": "カラムヘッダを送信しない", + "all": "カラムヘッダを常に送信する", + "once": "ヘッダを一度だけ送信する(msg.resetの受け付けると再送)" + }, "errors": { "csv_js": "本ノードが処理できる形式は、CSV文字列またはJSONのみです", "obj_csv": "オブジェクトをCSVへ変換する際の列名が設定されていません" diff --git a/packages/node_modules/@node-red/nodes/package.json b/packages/node_modules/@node-red/nodes/package.json index d1120d12c..96e829eaf 100644 --- a/packages/node_modules/@node-red/nodes/package.json +++ b/packages/node_modules/@node-red/nodes/package.json @@ -19,10 +19,10 @@ "body-parser": "1.19.0", "cheerio": "0.22.0", "content-type": "1.0.4", - "cookie-parser": "1.4.4", + "cookie-parser": "1.4.5", "cookie": "0.4.0", "cors": "2.8.5", - "cron": "1.8.2", + "cron": "1.7.2", "denque": "1.4.1", "fs-extra": "8.1.0", "fs.notify": "0.0.4", @@ -33,7 +33,7 @@ "media-typer": "1.1.0", "mqtt": "2.18.8", "multer": "1.4.2", - "mustache": "4.0.0", + "mustache": "4.0.1", "on-headers": "1.0.2", "raw-body": "2.4.1", "request": "2.88.0", diff --git a/packages/node_modules/@node-red/registry/package.json b/packages/node_modules/@node-red/registry/package.json index f1d81a2f7..1ac6ce528 100644 --- a/packages/node_modules/@node-red/registry/package.json +++ b/packages/node_modules/@node-red/registry/package.json @@ -18,7 +18,7 @@ "dependencies": { "@node-red/util": "1.1.0", "semver": "6.3.0", - "uglify-js": "3.8.0", + "uglify-js": "3.8.1", "when": "3.7.8" } } diff --git a/packages/node_modules/@node-red/runtime/lib/nodes/context/localfilesystem.js b/packages/node_modules/@node-red/runtime/lib/nodes/context/localfilesystem.js index cf1769700..9755681d8 100644 --- a/packages/node_modules/@node-red/runtime/lib/nodes/context/localfilesystem.js +++ b/packages/node_modules/@node-red/runtime/lib/nodes/context/localfilesystem.js @@ -203,10 +203,10 @@ LocalFileSystem.prototype.open = function(){ var newContext = self.cache._export(); scopes.forEach(function(scope) { var storagePath = getStoragePath(self.storageBaseDir,scope); - var context = newContext[scope]; + var context = newContext[scope] || {}; var stringifiedContext = stringify(context); if (stringifiedContext.circular && !self.knownCircularRefs[scope]) { - log.warn(log._("error-circular",{scope:scope})); + log.warn(log._("context.localfilesystem.error-circular",{scope:scope})); self.knownCircularRefs[scope] = true; } else { delete self.knownCircularRefs[scope]; @@ -324,7 +324,7 @@ LocalFileSystem.prototype.set = function(scope, key, value, callback) { } var stringifiedContext = stringify(obj); if (stringifiedContext.circular && !self.knownCircularRefs[scope]) { - log.warn(log._("error-circular",{scope:scope})); + log.warn(log._("context.localfilesystem.error-circular",{scope:scope})); self.knownCircularRefs[scope] = true; } else { delete self.knownCircularRefs[scope]; diff --git a/packages/node_modules/@node-red/runtime/lib/nodes/flows/index.js b/packages/node_modules/@node-red/runtime/lib/nodes/flows/index.js index 16166fbc1..1a350ce7c 100644 --- a/packages/node_modules/@node-red/runtime/lib/nodes/flows/index.js +++ b/packages/node_modules/@node-red/runtime/lib/nodes/flows/index.js @@ -553,7 +553,7 @@ function getFlow(id) { if (flow.label) { result.label = flow.label; } - if (flow.disabled) { + if (flow.hasOwnProperty('disabled')) { result.disabled = flow.disabled; } if (flow.hasOwnProperty('info')) { diff --git a/packages/node_modules/@node-red/util/package.json b/packages/node_modules/@node-red/util/package.json index 571582b35..16951b6ba 100644 --- a/packages/node_modules/@node-red/util/package.json +++ b/packages/node_modules/@node-red/util/package.json @@ -18,7 +18,7 @@ "clone": "2.1.2", "i18next": "15.1.2", "json-stringify-safe": "5.0.1", - "jsonata": "1.8.1", + "jsonata": "1.8.3", "lodash.clonedeep": "^4.5.0", "when": "3.7.8" } diff --git a/packages/node_modules/node-red/package.json b/packages/node_modules/node-red/package.json index d4c002702..5c7192a20 100644 --- a/packages/node_modules/node-red/package.json +++ b/packages/node_modules/node-red/package.json @@ -41,7 +41,7 @@ "fs-extra": "8.1.0", "node-red-node-rbe": "^0.2.6", "node-red-node-tail": "^0.1.0", - "nopt": "4.0.1", + "nopt": "4.0.3", "semver": "6.3.0" }, "optionalDependencies": { diff --git a/test/nodes/core/function/89-trigger_spec.js b/test/nodes/core/function/89-trigger_spec.js index 7d7450580..3377ee1f7 100644 --- a/test/nodes/core/function/89-trigger_spec.js +++ b/test/nodes/core/function/89-trigger_spec.js @@ -102,20 +102,20 @@ describe('trigger node', function() { function basicTest(type, val, rval) { it('should output 1st value when triggered ('+type+')', function(done) { var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:val, op1type:type, op2:"", op2type:"null", duration:"20", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; process.env[val] = rval; helper.load(triggerNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); n2.on("input", function(msg) { try { - if (rval) { - msg.should.have.property("payload"); - should.deepEqual(msg.payload, rval); - } - else { - msg.should.have.property("payload", val); - } + if (rval) { + msg.should.have.property("payload"); + should.deepEqual(msg.payload, rval); + } + else { + msg.should.have.property("payload", val); + } delete process.env[val]; done(); } @@ -127,7 +127,7 @@ describe('trigger node', function() { it('should output 2st value when triggered ('+type+')', function(done) { var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"foo", op1type:"str", op2:val, op2type:type, duration:"20", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; process.env[val] = rval; helper.load(triggerNode, flow, function() { var n1 = helper.getNode("n1"); @@ -136,17 +136,17 @@ describe('trigger node', function() { n2.on("input", function(msg) { try { if (c === 0) { - msg.should.have.property("payload", "foo"); + msg.should.have.property("payload", "foo"); c++; } else { - if (rval) { - msg.should.have.property("payload"); - should.deepEqual(msg.payload, rval); - } - else { - msg.should.have.property("payload", val); - } + if (rval) { + msg.should.have.property("payload"); + should.deepEqual(msg.payload, rval); + } + else { + msg.should.have.property("payload", val); + } delete process.env[val]; done(); } @@ -378,6 +378,51 @@ describe('trigger node', function() { }); }); + it('should handle multiple other properties individually if asked to do so', function(done) { + var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", bytopic:"topic", topic:"foo", op1:"1", op2:"0", op1type:"num", op2type:"num", duration:"30", wires:[["n2"]] }, + {id:"n2", type:"helper"} ]; + helper.load(triggerNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + var c = 0; + n2.on("input", function(msg) { + try { + c += 1; + if (c === 1) { + msg.should.have.a.property("payload", 1); + msg.should.have.a.property("foo", "A"); + } + else if (c === 2) { + msg.should.have.a.property("payload", 1); + msg.should.have.a.property("foo", "B"); + } + else if (c === 3) { + msg.should.have.a.property("payload", 1); + msg.should.have.a.property("foo", "C"); + } + else if (c === 4) { + msg.should.have.a.property("payload", 0); + msg.should.have.a.property("foo", "A"); + } + else if (c === 5) { + msg.should.have.a.property("payload", 0); + msg.should.have.a.property("foo", "B"); + } + else if (c === 6) { + msg.should.have.a.property("payload", 0); + msg.should.have.a.property("foo", "C"); + done(); + } + } catch(err) { + done(err); + } + }); + n1.emit("input", {payload:1,foo:"A"}); + n1.emit("input", {payload:2,foo:"B"}); + n1.emit("input", {payload:3,foo:"C"}); + }); + }); + it('should be able to return things from flow and global context variables', function(done) { var spy = sinon.stub(RED.util, 'evaluateNodeProperty', function(arg1, arg2, arg3, arg4, arg5) { if (arg5) { arg5(null, arg1) } else { return arg1; } } @@ -408,8 +453,8 @@ describe('trigger node', function() { it('should be able to return things from persistable flow and global context variables', function (done) { var flow = [{"id": "n1", "type": "trigger", "name": "triggerNode", "op1": "#:(memory1)::foo", "op1type": "flow", - "op2": "#:(memory1)::bar", "op2type": "global", "duration": "20", "wires": [["n2"]], "z": "flow" }, - {"id": "n2", "type": "helper"}]; + "op2": "#:(memory1)::bar", "op2type": "global", "duration": "20", "wires": [["n2"]], "z": "flow" }, + {"id": "n2", "type": "helper"}]; helper.load(triggerNode, flow, function () { initContext(function () { var n1 = helper.getNode("n1"); @@ -442,11 +487,11 @@ describe('trigger node', function() { it('should be able to return things from multiple persistable global context variables', function (done) { var flow = [{"id": "n1", "z": "flow", "type": "trigger", - "duration": "20", "wires": [["n2"]], - "op1": "#:(memory1)::val", "op1type": "global", - "op2": "#:(memory2)::val", "op2type": "global" - }, - {"id": "n2", "type": "helper"}]; + "duration": "20", "wires": [["n2"]], + "op1": "#:(memory1)::val", "op1type": "global", + "op2": "#:(memory2)::val", "op2type": "global" + }, + {"id": "n2", "type": "helper"}]; helper.load(triggerNode, flow, function () { initContext(function () { var n1 = helper.getNode("n1"); @@ -481,11 +526,11 @@ describe('trigger node', function() { it('should be able to return things from multiple persistable flow context variables', function (done) { var flow = [{"id": "n1", "z": "flow", "type": "trigger", - "duration": "20", "wires": [["n2"]], - "op1": "#:(memory1)::val", "op1type": "flow", - "op2": "#:(memory2)::val", "op2type": "flow" - }, - {"id": "n2", "type": "helper"}]; + "duration": "20", "wires": [["n2"]], + "op1": "#:(memory1)::val", "op1type": "flow", + "op2": "#:(memory2)::val", "op2type": "flow" + }, + {"id": "n2", "type": "helper"}]; helper.load(triggerNode, flow, function () { initContext(function () { var n1 = helper.getNode("n1"); @@ -520,11 +565,11 @@ describe('trigger node', function() { it('should be able to return things from multiple persistable flow & global context variables', function (done) { var flow = [{"id": "n1", "z": "flow", "type": "trigger", - "duration": "20", "wires": [["n2"]], - "op1": "#:(memory1)::val", "op1type": "flow", - "op2": "#:(memory2)::val", "op2type": "global" - }, - {"id": "n2", "type": "helper"}]; + "duration": "20", "wires": [["n2"]], + "op1": "#:(memory1)::val", "op1type": "flow", + "op2": "#:(memory2)::val", "op2type": "global" + }, + {"id": "n2", "type": "helper"}]; helper.load(triggerNode, flow, function () { initContext(function () { var n1 = helper.getNode("n1"); @@ -818,6 +863,40 @@ describe('trigger node', function() { }); }); + it('should be able to send 2nd message to a 2nd output', function(done) { + var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"val", op2type:"val", op1:"hello", op2:"world", duration:"50", outputs:2, wires:[["n2"],["n3"]] }, + {id:"n2", type:"helper"}, {id:"n3", type:"helper"} ]; + helper.load(triggerNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + var n3 = helper.getNode("n3"); + var c = 0; + n2.on("input", function(msg) { + try { + if (c === 0) { + msg.should.have.a.property("payload", "hello"); + msg.should.have.a.property("topic", "test"); + c+=1; + } + else { done(err); } + } + catch(err) { done(err); } + }); + n3.on("input", function(msg) { + try { + if (c === 1) { + msg.should.have.a.property("payload", "world"); + msg.should.have.a.property("topic", "test"); + done(); + } + else { done(err); } + } + catch(err) { done(err); } + }); + n1.emit("input", {payload:"go",topic:"test"}); + }); + }); + it('should handle string null as null', function(done) { var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"val", op2type:"pay", op1:"null", op2:"null", duration:"40", wires:[["n2"]] }, {id:"n2", type:"helper"} ]; diff --git a/test/nodes/core/parsers/70-CSV_spec.js b/test/nodes/core/parsers/70-CSV_spec.js index 4d5d7b27a..10e167b6d 100644 --- a/test/nodes/core/parsers/70-CSV_spec.js +++ b/test/nodes/core/parsers/70-CSV_spec.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ /** * Copyright JS Foundation and other contributors, http://js.foundation * @@ -70,12 +71,13 @@ describe('CSV node', function() { it('should convert a simple csv string to a javascript object', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); n2.on("input", function(msg) { msg.should.have.property('payload', { a: 1, b: 2, c: 3, d: 4 }); + msg.should.have.property('columns', "a,b,c,d"); check_parts(msg, 0, 1); done(); }); @@ -86,7 +88,7 @@ describe('CSV node', function() { it('should remove quotes and whitespace from template', function(done) { var flow = [ { id:"n1", type:"csv", temp:'"a", "b" , " c "," d " ', wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -102,12 +104,13 @@ describe('CSV node', function() { it('should create column names if no template provided', function(done) { var flow = [ { id:"n1", type:"csv", temp:'', wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); n2.on("input", function(msg) { msg.should.have.property('payload', { col1: 1, col2: 2, col3: 3, col4: 4 }); + msg.should.have.property('columns', "col1,col2,col3,col4"); check_parts(msg, 0, 1); done(); }); @@ -118,12 +121,13 @@ describe('CSV node', function() { it('should allow dropping of fields from the template', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,,,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); n2.on("input", function(msg) { msg.should.have.property('payload', { a: 1, d: 4 }); + msg.should.have.property('columns', 'a,d'); check_parts(msg, 0, 1); done(); }); @@ -134,7 +138,7 @@ describe('CSV node', function() { it('should leave numbers starting with 0, e and + as strings (except 0.)', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e,f,g", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -150,7 +154,7 @@ describe('CSV node', function() { it('should not parse numbers when told not to do so', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e,f,g", strings:false, wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -166,7 +170,7 @@ describe('CSV node', function() { it('should leave handle strings with scientific notation as numbers', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e,f,g", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -183,7 +187,7 @@ describe('CSV node', function() { it('should allow quotes in the input (but drop blank strings)', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e,f,g,h", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -327,12 +331,13 @@ describe('CSV node', function() { it('should be able to output multiple lines as one array', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", multi:"yes", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); n2.on("input", function(msg) { msg.should.have.property('payload', [ { a: 1, b: 2, c: 3, d: 4 },{ a: 5, b: -6, c: '07', d: '+8' },{ a: 9, b: 0, c: 'a', d: 'b' },{ a: 'c', b: 'd', c: 'e', d: 'f' } ]); + msg.should.have.property('columns','a,b,c,d'); msg.should.not.have.property('parts'); done(); }); @@ -343,7 +348,7 @@ describe('CSV node', function() { it('should handle numbers in strings but not IP addresses', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -359,7 +364,7 @@ describe('CSV node', function() { it('should preserve parts property', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -403,7 +408,7 @@ describe('CSV node', function() { it('should skip several lines from start if requested', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", skip: 2, wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -417,9 +422,9 @@ describe('CSV node', function() { }); }); - it('should skip several lines from start then use next line as a tempate', function(done) { + it('should skip several lines from start then use next line as a template', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", hdrin:true, skip: 2, wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -435,7 +440,7 @@ describe('CSV node', function() { it('should skip several lines from start and correct parts', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", skip: 2, wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -467,11 +472,13 @@ describe('CSV node', function() { n2.on("input", function(msg) { if (c === 0) { msg.should.have.property('payload', { w: 1, x: 2, y: 3, z: 4 }); + msg.should.have.property('columns', 'w,x,y,z'); check_parts(msg, 0, 2); c += 1; } else { msg.should.have.property('payload', { w: 5, x: 6, y: 7, z: 8 }); + msg.should.have.property('columns', 'w,x,y,z'); check_parts(msg, 1, 2); done(); } @@ -495,7 +502,7 @@ describe('CSV node', function() { it('should convert a simple object back to a csv', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,,e", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -513,7 +520,7 @@ describe('CSV node', function() { it('should convert a simple object back to a csv with no template', function(done) { var flow = [ { id:"n1", type:"csv", temp:" ", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -531,7 +538,7 @@ describe('CSV node', function() { it('should handle a template with spaces in the property names', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b o,c p,,e", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -549,7 +556,7 @@ describe('CSV node', function() { it('should convert an array of objects to a multi-line csv', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -567,7 +574,7 @@ describe('CSV node', function() { it('should convert a simple array back to a csv', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -585,7 +592,7 @@ describe('CSV node', function() { it('should convert an array of arrays back to a multi-line csv', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -603,7 +610,7 @@ describe('CSV node', function() { it('should be able to include column names as first row', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", hdrout:true, ret:"\r\n", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -619,9 +626,36 @@ describe('CSV node', function() { }); }); + it('should be able to pass in column names', function(done) { + var flow = [ { id:"n1", type:"csv", temp:"", hdrout:"once", ret:"\r\n", wires:[["n2"]] }, + {id:"n2", type:"helper"} ]; + helper.load(csvNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + var count = 0; + n2.on("input", function(msg) { + count += 1; + try { + if (count === 1) { + msg.should.have.property('payload', 'a,,b,a\r\n4,,3,4\r\n'); + } + if (count === 3) { + msg.should.have.property('payload', '4,,3,4\r\n'); + done() + } + } + catch(e) { done(e); } + }); + var testJson = [{ d: 1, b: 3, c: 2, a: 4 }]; + n1.emit("input", {payload:testJson, columns:"a,,b,a"}); + n1.emit("input", {payload:testJson}); + n1.emit("input", {payload:testJson}); + }); + }); + it('should handle quotes and sub-properties', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -641,7 +675,7 @@ describe('CSV node', function() { it('should just pass through if no payload provided', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2"); @@ -661,7 +695,7 @@ describe('CSV node', function() { it('should warn if provided a number or boolean', function(done) { var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + {id:"n2", type:"helper"} ]; helper.load(csvNode, flow, function() { var n1 = helper.getNode("n1"); var n2 = helper.getNode("n2");