Add $context/$flow/$global functions to jsonata

This commit is contained in:
Nick O'Leary
2017-05-03 15:48:30 +01:00
parent 8f92a3e875
commit 30920b1b78
6 changed files with 39 additions and 14 deletions

View File

@@ -17,8 +17,6 @@
module.exports = function(RED) {
"use strict";
var jsonata = require('jsonata');
var operators = {
'eq': function(a, b) { return a == b; },
'neq': function(a, b) { return a != b; },
@@ -44,7 +42,7 @@ module.exports = function(RED) {
if (this.propertyType === 'jsonata') {
try {
this.property = jsonata(this.property);
this.property = RED.util.prepareJSONataExpression(this.property,this);
} catch(err) {
this.error(RED._("switch.errors.invalid-expr",{error:err.message}));
return;
@@ -70,7 +68,7 @@ module.exports = function(RED) {
}
} else if (rule.vt === "jsonata") {
try {
rule.v = jsonata(rule.v);
rule.v = RED.util.prepareJSONataExpression(rule.v,node);
} catch(err) {
this.error(RED._("switch.errors.invalid-expr",{error:err.message}));
valid = false;
@@ -88,7 +86,7 @@ module.exports = function(RED) {
rule.v2 = Number(rule.v2);
} else if (rule.v2t === 'jsonata') {
try {
rule.v2 = jsonata(rule.v2);
rule.v2 = RED.util.prepareJSONataExpression(rule.v2,node);
} catch(err) {
this.error(RED._("switch.errors.invalid-expr",{error:err.message}));
valid = false;

View File

@@ -16,7 +16,6 @@
module.exports = function(RED) {
"use strict";
var jsonata = require("jsonata");
function ChangeNode(n) {
RED.nodes.createNode(this, n);
@@ -88,7 +87,7 @@ module.exports = function(RED) {
rule.to = /^true$/i.test(rule.to);
} else if (rule.tot === 'jsonata') {
try {
rule.to = jsonata(rule.to);
rule.to = RED.util.prepareJSONataExpression(rule.to,this);
} catch(e) {
valid = false;
this.error(RED._("change.errors.invalid-from",{error:e.message}));