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

Update RED.util.evaluateNodeProperty to support context stores

This commit is contained in:
Nick O'Leary 2018-07-05 10:43:33 +01:00
parent 372c213c2c
commit 946a6d6041
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -322,35 +322,54 @@ function evaluteEnvProperty(value) {
return value; return value;
} }
function evaluateNodeProperty(value, type, node, msg) { var parseContextStore = function(key) {
var parts = {};
var m = /^#:\((\S+?)\)::(.*)$/.exec(key);
if (m) {
parts.store = m[1];
parts.key = m[2];
} else {
parts.key = key;
}
return parts;
}
function evaluateNodeProperty(value, type, node, msg, callback) {
var result;
if (type === 'str') { if (type === 'str') {
return ""+value; result = ""+value;
} else if (type === 'num') { } else if (type === 'num') {
return Number(value); result = Number(value);
} else if (type === 'json') { } else if (type === 'json') {
return JSON.parse(value); result = JSON.parse(value);
} else if (type === 're') { } else if (type === 're') {
return new RegExp(value); result = new RegExp(value);
} else if (type === 'date') { } else if (type === 'date') {
return Date.now(); result = Date.now();
} else if (type === 'bin') { } else if (type === 'bin') {
var data = JSON.parse(value); var data = JSON.parse(value);
return Buffer.from(data); result = Buffer.from(data);
} else if (type === 'msg' && msg) { } else if (type === 'msg' && msg) {
return getMessageProperty(msg,value); result = getMessageProperty(msg,value);
} else if (type === 'flow' && node) { } else if ((type === 'flow' || type === 'global') && node) {
return node.context().flow.get(value); var contextKey = parseContextStore(value);
} else if (type === 'global' && node) { result = node.context()[type].get(contextKey.key,contextKey.store,callback);
return node.context().global.get(value); if (callback) {
return;
}
} else if (type === 'bool') { } else if (type === 'bool') {
return /^true$/i.test(value); result = /^true$/i.test(value);
} else if (type === 'jsonata') { } else if (type === 'jsonata') {
var expr = prepareJSONataExpression(value,node); var expr = prepareJSONataExpression(value,node);
return evaluateJSONataExpression(expr,msg); result = evaluateJSONataExpression(expr,msg);
} else if (type === 'env') { } else if (type === 'env') {
return evaluteEnvProperty(value); result = evaluteEnvProperty(value);
} }
if (callback) {
callback(result);
} else {
return value; return value;
}
} }
function prepareJSONataExpression(value,node) { function prepareJSONataExpression(value,node) {