diff --git a/packages/node_modules/@node-red/nodes/core/function/89-trigger.html b/packages/node_modules/@node-red/nodes/core/function/89-trigger.html index a7ab0356f..f3f81f044 100644 --- a/packages/node_modules/@node-red/nodes/core/function/89-trigger.html +++ b/packages/node_modules/@node-red/nodes/core/function/89-trigger.html @@ -181,7 +181,7 @@ $("#node-input-op1").typedInput({ default: 'str', typeField: $("#node-input-op1type"), - types:['flow','global','str','num','bool','json','bin','date','env', + types:['flow','global','str','num','bool','json','bin','date','jsonata','env', optionPayload, optionNothing ] @@ -189,7 +189,7 @@ $("#node-input-op2").typedInput({ default: 'str', typeField: $("#node-input-op2type"), - types:['flow','global','str','num','bool','json','bin','date','env', + types:['flow','global','str','num','bool','json','bin','date','jsonata','env', optionOriginalPayload, optionLatestPayload, optionNothing diff --git a/packages/node_modules/@node-red/nodes/core/function/89-trigger.js b/packages/node_modules/@node-red/nodes/core/function/89-trigger.js index 7b5b820b7..8a0d67915 100644 --- a/packages/node_modules/@node-red/nodes/core/function/89-trigger.js +++ b/packages/node_modules/@node-red/nodes/core/function/89-trigger.js @@ -75,6 +75,20 @@ module.exports = function(RED) { //catch(e) { this.op1 = this.op1; } //try { this.op2 = JSON.parse(this.op2); } //catch(e) { this.op2 = this.op2; } + if (this.op1type === 'jsonata') { + try { + this.op1j = RED.util.prepareJSONataExpression(this.op1,this); + } catch(e) { + this.error(RED._("change.errors.invalid-expr",{error:e.message})); + } + } + if (this.op2type === 'jsonata') { + try { + this.op2j = RED.util.prepareJSONataExpression(this.op2,this); + } catch(e) { + this.error(RED._("change.errors.invalid-expr",{error:e.message})); + } + } var node = this; node.topics = {}; @@ -137,10 +151,10 @@ module.exports = function(RED) { node.status(stat()); } else { - if (node.op2type === "payl") { npay[topic] = RED.util.cloneMessage(msg); } + if (node.op2type !== "nul") { npay[topic] = RED.util.cloneMessage(msg); } if (((!node.topics[topic].tout) && (node.topics[topic].tout !== 0)) || (node.loop === true)) { promise = Promise.resolve(); - if (node.op2type === "pay") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); } + if (node.op2type !== "nul") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); } else if (node.op2Templated) { node.topics[topic].m2 = mustache.render(node.op2,msg); } else if (node.op2type !== "nul") { promise = new Promise((resolve,reject) => { @@ -159,6 +173,18 @@ module.exports = function(RED) { promise = Promise.resolve(); if (node.op1type === "pay") { } else if (node.op1Templated) { msg.payload = mustache.render(node.op1,msg); } + else if (node.op1type === 'jsonata') { + promise = new Promise((resolve,reject) => { + RED.util.evaluateJSONataExpression(node.op1j,msg, (err, value) => { + if (err) { + reject(err); + } else { + msg.payload = value; + resolve(); + } + }); + }); + } else if (node.op1type !== "nul") { promise = new Promise((resolve,reject) => { RED.util.evaluateNodeProperty(node.op1,node.op1type,node,msg,(err,value) => { @@ -188,10 +214,22 @@ module.exports = function(RED) { var msg2 = null; if (node.op2type !== "nul") { var promise = Promise.resolve(); - msg2 = RED.util.cloneMessage(msg); - if (node.op2type === "flow" || node.op2type === "global") { + msg2 = npay[topic]; + if (node.op2type === "flow" || node.op2type === "global" || node.op2type === "env") { promise = new Promise((resolve,reject) => { - RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg,(err,value) => { + RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg2,(err,value) => { + if (err) { + reject(err); + } else { + node.topics[topic].m2 = value; + resolve(); + } + }); + }); + } + else if (node.op2type === 'jsonata') { + promise = new Promise((resolve,reject) => { + RED.util.evaluateJSONataExpression(node.op2j,msg2,(err, value) => { if (err) { reject(err); } else { @@ -240,7 +278,7 @@ module.exports = function(RED) { var promise = Promise.resolve(); if (node.op2type !== "nul") { - if (node.op2type === "flow" || node.op2type === "global") { + if (node.op2type === "flow" || node.op2type === "global" || node.op2type === "env") { promise = new Promise((resolve,reject) => { RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg,(err,value) => { if (err) {