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:
parent
bbe3ee701f
commit
d22979659b
@ -181,7 +181,7 @@
|
|||||||
$("#node-input-op1").typedInput({
|
$("#node-input-op1").typedInput({
|
||||||
default: 'str',
|
default: 'str',
|
||||||
typeField: $("#node-input-op1type"),
|
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,
|
optionPayload,
|
||||||
optionNothing
|
optionNothing
|
||||||
]
|
]
|
||||||
@ -189,7 +189,7 @@
|
|||||||
$("#node-input-op2").typedInput({
|
$("#node-input-op2").typedInput({
|
||||||
default: 'str',
|
default: 'str',
|
||||||
typeField: $("#node-input-op2type"),
|
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,
|
optionOriginalPayload,
|
||||||
optionLatestPayload,
|
optionLatestPayload,
|
||||||
optionNothing
|
optionNothing
|
||||||
|
@ -75,6 +75,20 @@ module.exports = function(RED) {
|
|||||||
//catch(e) { this.op1 = this.op1; }
|
//catch(e) { this.op1 = this.op1; }
|
||||||
//try { this.op2 = JSON.parse(this.op2); }
|
//try { this.op2 = JSON.parse(this.op2); }
|
||||||
//catch(e) { this.op2 = 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;
|
var node = this;
|
||||||
node.topics = {};
|
node.topics = {};
|
||||||
@ -137,10 +151,10 @@ module.exports = function(RED) {
|
|||||||
node.status(stat());
|
node.status(stat());
|
||||||
}
|
}
|
||||||
else {
|
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)) {
|
if (((!node.topics[topic].tout) && (node.topics[topic].tout !== 0)) || (node.loop === true)) {
|
||||||
promise = Promise.resolve();
|
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.op2Templated) { node.topics[topic].m2 = mustache.render(node.op2,msg); }
|
||||||
else if (node.op2type !== "nul") {
|
else if (node.op2type !== "nul") {
|
||||||
promise = new Promise((resolve,reject) => {
|
promise = new Promise((resolve,reject) => {
|
||||||
@ -159,6 +173,18 @@ module.exports = function(RED) {
|
|||||||
promise = Promise.resolve();
|
promise = Promise.resolve();
|
||||||
if (node.op1type === "pay") { }
|
if (node.op1type === "pay") { }
|
||||||
else if (node.op1Templated) { msg.payload = mustache.render(node.op1,msg); }
|
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") {
|
else if (node.op1type !== "nul") {
|
||||||
promise = new Promise((resolve,reject) => {
|
promise = new Promise((resolve,reject) => {
|
||||||
RED.util.evaluateNodeProperty(node.op1,node.op1type,node,msg,(err,value) => {
|
RED.util.evaluateNodeProperty(node.op1,node.op1type,node,msg,(err,value) => {
|
||||||
@ -188,10 +214,22 @@ module.exports = function(RED) {
|
|||||||
var msg2 = null;
|
var msg2 = null;
|
||||||
if (node.op2type !== "nul") {
|
if (node.op2type !== "nul") {
|
||||||
var promise = Promise.resolve();
|
var promise = Promise.resolve();
|
||||||
msg2 = RED.util.cloneMessage(msg);
|
msg2 = npay[topic];
|
||||||
if (node.op2type === "flow" || node.op2type === "global") {
|
if (node.op2type === "flow" || node.op2type === "global" || node.op2type === "env") {
|
||||||
promise = new Promise((resolve,reject) => {
|
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) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@ -240,7 +278,7 @@ module.exports = function(RED) {
|
|||||||
var promise = Promise.resolve();
|
var promise = Promise.resolve();
|
||||||
|
|
||||||
if (node.op2type !== "nul") {
|
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) => {
|
promise = new Promise((resolve,reject) => {
|
||||||
RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg,(err,value) => {
|
RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg,(err,value) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user