1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

This add jsonata output to trigger node output options

This commit is contained in:
Dave Conway-Jones 2020-12-13 12:31:14 +00:00
parent bbe3ee701f
commit d22979659b
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 46 additions and 8 deletions

View File

@ -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

View File

@ -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) {