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

@@ -323,11 +323,25 @@ function evaluateNodeProperty(value, type, node, msg) {
} else if (type === 'bool') {
return /^true$/i.test(value);
} else if (type === 'jsonata') {
return jsonata(value).evaluate({msg:msg});
return prepareJSONataExpression(value,node).evaluate({msg:msg});
}
return value;
}
function prepareJSONataExpression(value,node) {
var expr = jsonata(value);
expr.assign('context',function(val) {
return node.context().get(val);
});
expr.assign('flow',function(val) {
return node.context().flow.get(val);
});
expr.assign('global',function(val) {
return node.context().global(val);
});
return expr;
}
function normaliseNodeTypeName(name) {
var result = name.replace(/[^a-zA-Z0-9]/g, " ");
result = result.trim();
@@ -351,5 +365,6 @@ module.exports = {
setMessageProperty: setMessageProperty,
evaluateNodeProperty: evaluateNodeProperty,
normalisePropertyExpression: normalisePropertyExpression,
normaliseNodeTypeName: normaliseNodeTypeName
normaliseNodeTypeName: normaliseNodeTypeName,
prepareJSONataExpression: prepareJSONataExpression
};