Function node: add node.outputCount property to sandbox (#2918)

* Function node: add `node.outputs` property to sandbox

https://discourse.nodered.org/t/expose-configured-output-count-to-function-node-i-can-pr/43848

* style: indetation for function node sanbox code

I guess this was unintentionally unindented in d51aefa156 (diff-24cd715c3b7405ea194bfdc0dc2a350ceb2f5d18696b8163c3e40105b981a666)

* Function node: tests for accessing node properties

consistently tests that `node.id`, `node.name` and `node.outputs`
are available in `init()`, `func()` and `finalize()` methods.

* Function node: rename `node.outputs` to `node.outputCount`

https://discourse.nodered.org/t/expose-configured-output-count-to-function-node-i-can-pr/43848/9?u=kristian
This commit is contained in:
Kristian Heljas
2021-04-08 16:52:02 +03:00
committed by GitHub
parent 0059f9475e
commit 7b8ed487e9
2 changed files with 76 additions and 27 deletions

View File

@@ -93,6 +93,7 @@ module.exports = function(RED) {
var node = this;
node.name = n.name;
node.func = n.func;
node.outputs = n.outputs;
node.ini = n.initialize ? n.initialize.trim() : "";
node.fin = n.finalize ? n.finalize.trim() : "";
node.libs = n.libs || [];
@@ -112,21 +113,22 @@ module.exports = function(RED) {
var functionText = "var results = null;"+
"results = (async function(msg,__send__,__done__){ "+
"var __msgid__ = msg._msgid;"+
"var node = {"+
"id:__node__.id,"+
"name:__node__.name,"+
"log:__node__.log,"+
"error:__node__.error,"+
"warn:__node__.warn,"+
"debug:__node__.debug,"+
"trace:__node__.trace,"+
"on:__node__.on,"+
"status:__node__.status,"+
"send:function(msgs,cloneMsg){ __node__.send(__send__,__msgid__,msgs,cloneMsg);},"+
"done:__done__"+
"};\n"+
node.func+"\n"+
"var __msgid__ = msg._msgid;"+
"var node = {"+
"id:__node__.id,"+
"name:__node__.name,"+
"outputCount:__node__.outputCount,"+
"log:__node__.log,"+
"error:__node__.error,"+
"warn:__node__.warn,"+
"debug:__node__.debug,"+
"trace:__node__.trace,"+
"on:__node__.on,"+
"status:__node__.status,"+
"send:function(msgs,cloneMsg){ __node__.send(__send__,__msgid__,msgs,cloneMsg);},"+
"done:__done__"+
"};\n"+
node.func+"\n"+
"})(msg,__send__,__done__);";
var finScript = null;
var finOpt = null;
@@ -146,6 +148,7 @@ module.exports = function(RED) {
__node__: {
id: node.id,
name: node.name,
outputCount: node.outputs,
log: function() {
node.log.apply(node, arguments);
},
@@ -330,6 +333,7 @@ module.exports = function(RED) {
var node = {
id:__node__.id,
name:__node__.name,
outputCount:__node__.outputCount,
log:__node__.log,
error:__node__.error,
warn:__node__.warn,
@@ -351,6 +355,7 @@ module.exports = function(RED) {
var node = {
id:__node__.id,
name:__node__.name,
outputCount:__node__.outputCount,
log:__node__.log,
error:__node__.error,
warn:__node__.warn,