mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Revert "Add callback to getSetting to support async jsonata access"
This commit is contained in:
parent
2448e137c8
commit
51a0b68d8e
@ -281,21 +281,4 @@ declare class env {
|
|||||||
* ```const flowName = env.get("NR_FLOW_NAME");```
|
* ```const flowName = env.get("NR_FLOW_NAME");```
|
||||||
*/
|
*/
|
||||||
static get(name:string) :any;
|
static get(name:string) :any;
|
||||||
/**
|
|
||||||
* Get an environment variable value (asynchronous).
|
|
||||||
*
|
|
||||||
* Predefined node-red variables...
|
|
||||||
* * `NR_NODE_ID` - the ID of the node
|
|
||||||
* * `NR_NODE_NAME` - the Name of the node
|
|
||||||
* * `NR_NODE_PATH` - the Path of the node
|
|
||||||
* * `NR_GROUP_ID` - the ID of the containing group
|
|
||||||
* * `NR_GROUP_NAME` - the Name of the containing group
|
|
||||||
* * `NR_FLOW_ID` - the ID of the flow the node is on
|
|
||||||
* * `NR_FLOW_NAME` - the Name of the flow the node is on
|
|
||||||
* @param name Name of the environment variable to get
|
|
||||||
* @param callback Callback function (`(err,value) => {}`)
|
|
||||||
* @example
|
|
||||||
* ```const flowName = env.get("NR_FLOW_NAME");```
|
|
||||||
*/
|
|
||||||
static get(name:string, callback: Function) :void;
|
|
||||||
}
|
}
|
||||||
|
@ -242,8 +242,8 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
get: function(envVar, callback) {
|
get: function(envVar) {
|
||||||
return RED.util.getSetting(node, envVar, node._flow, callback);
|
return RED.util.getSetting(node, envVar);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setTimeout: function () {
|
setTimeout: function () {
|
||||||
|
@ -416,50 +416,23 @@ class Flow {
|
|||||||
return this.activeNodes;
|
return this.activeNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
/**
|
* Get value of environment variable defined in group node.
|
||||||
* Group callback signature
|
* @param {String} group - group node
|
||||||
*
|
* @param {String} name - name of variable
|
||||||
* @callback GroupEnvCallback
|
* @return {Object} object containing the value in val property or null if not defined
|
||||||
* @param {Error} err The error object (or null)
|
|
||||||
* @param {[result: {val:Any}, name: String]} result The result of the callback
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
*/
|
||||||
|
getGroupEnvSetting(node, group, name) {
|
||||||
/**
|
|
||||||
* @function getGroupEnvSetting
|
|
||||||
* Get a group setting value synchronously.
|
|
||||||
* This currently automatically defers to the parent
|
|
||||||
* @overload
|
|
||||||
* @param {Object} node
|
|
||||||
* @param {Object} group
|
|
||||||
* @param {String} name
|
|
||||||
* @returns {Any}
|
|
||||||
*
|
|
||||||
* Get a group setting value asynchronously.
|
|
||||||
* @overload
|
|
||||||
* @param {Object} node
|
|
||||||
* @param {Object} group
|
|
||||||
* @param {String} name
|
|
||||||
* @param {GroupEnvCallback} callback
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
|
|
||||||
getGroupEnvSetting(node, group, name, callback) {
|
|
||||||
/** @type {GroupEnvCallback} */
|
|
||||||
const returnOrCallback = (err, [result, newName]) => {
|
|
||||||
if (callback) {
|
|
||||||
callback(err, [result, newName]);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return [result, newName];
|
|
||||||
}
|
|
||||||
if (group) {
|
if (group) {
|
||||||
if (name === "NR_GROUP_NAME") {
|
if (name === "NR_GROUP_NAME") {
|
||||||
return returnOrCallback(null, [{ val: group.name }, null]);
|
return [{
|
||||||
|
val: group.name
|
||||||
|
}, null];
|
||||||
}
|
}
|
||||||
if (name === "NR_GROUP_ID") {
|
if (name === "NR_GROUP_ID") {
|
||||||
return returnOrCallback(null, [{ val: group.id }, null]);
|
return [{
|
||||||
|
val: group.id
|
||||||
|
}, null];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.credentials === undefined) {
|
if (group.credentials === undefined) {
|
||||||
@ -484,32 +457,33 @@ class Flow {
|
|||||||
if (env) {
|
if (env) {
|
||||||
let value = env.value;
|
let value = env.value;
|
||||||
const type = env.type;
|
const type = env.type;
|
||||||
if ((type !== "env") || (value !== name)) {
|
if ((type !== "env") ||
|
||||||
|
(value !== name)) {
|
||||||
if (type === "env") {
|
if (type === "env") {
|
||||||
value = value.replace(new RegExp("\\${"+name+"}","g"),"${$parent."+name+"}");
|
value = value.replace(new RegExp("\\${"+name+"}","g"),"${$parent."+name+"}");
|
||||||
} else if (type === "bool") {
|
}
|
||||||
const val = ((value === "true") || (value === true));
|
if (type === "bool") {
|
||||||
return returnOrCallback(null, [{ val: val }, null])
|
const val
|
||||||
|
= ((value === "true") ||
|
||||||
|
(value === true));
|
||||||
|
return [{
|
||||||
|
val: val
|
||||||
|
}, null];
|
||||||
}
|
}
|
||||||
if (type === "cred") {
|
if (type === "cred") {
|
||||||
return returnOrCallback(null, [{ val: value }, null])
|
return [{
|
||||||
|
val: value
|
||||||
|
}, null];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!callback) {
|
var val = redUtil.evaluateNodeProperty(value, type, node, null, null);
|
||||||
var val = redUtil.evaluateNodeProperty(value, type, node, null, null);
|
return [{
|
||||||
return [{ val: val }, null];
|
val: val
|
||||||
} else {
|
}, null];
|
||||||
redUtil.evaluateNodeProperty(value, type, node, null, (err, value) => {
|
|
||||||
return returnOrCallback(err, [{ val: value }, null])
|
|
||||||
});
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (!callback) {
|
this.error(e);
|
||||||
this.error(e);
|
return [null, null];
|
||||||
}
|
|
||||||
return returnOrCallback(e, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -520,47 +494,27 @@ class Flow {
|
|||||||
}
|
}
|
||||||
if (group.g) {
|
if (group.g) {
|
||||||
const parent = this.getGroupNode(group.g);
|
const parent = this.getGroupNode(group.g);
|
||||||
const gVal = this.getGroupEnvSetting(node, parent, name, callback);
|
return this.getGroupEnvSetting(node, parent, name);
|
||||||
if (callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return gVal;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnOrCallback(null, [null, name]);
|
return [null, name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Settings callback signature
|
|
||||||
*
|
|
||||||
* @callback SettingsCallback
|
|
||||||
* @param {Error} err The error object (or null)
|
|
||||||
* @param {Any} result The result of the callback
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Get a flow setting value. This currently automatically defers to the parent
|
* Get a flow setting value. This currently automatically defers to the parent
|
||||||
* flow which, as defined in ./index.js returns `process.env[key]`.
|
* flow which, as defined in ./index.js returns `process.env[key]`.
|
||||||
* This lays the groundwork for Subflow to have instance-specific settings
|
* This lays the groundwork for Subflow to have instance-specific settings
|
||||||
* @param {String} key The settings key
|
* @param {[type]} key [description]
|
||||||
* @param {SettingsCallback} callback Optional callback function
|
* @return {[type]} [description]
|
||||||
* @return {Any}
|
|
||||||
*/
|
*/
|
||||||
getSetting(key, callback) {
|
getSetting(key) {
|
||||||
/** @type {SettingsCallback} */
|
|
||||||
const returnOrCallback = (err, result) => {
|
|
||||||
if (callback) {
|
|
||||||
callback(err, result);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
const flow = this.flow;
|
const flow = this.flow;
|
||||||
if (key === "NR_FLOW_NAME") {
|
if (key === "NR_FLOW_NAME") {
|
||||||
return returnOrCallback(null, flow.label);
|
return flow.label;
|
||||||
}
|
}
|
||||||
if (key === "NR_FLOW_ID") {
|
if (key === "NR_FLOW_ID") {
|
||||||
return returnOrCallback(null, flow.id);
|
return flow.id;
|
||||||
}
|
}
|
||||||
if (flow.credentials === undefined) {
|
if (flow.credentials === undefined) {
|
||||||
flow.credentials = credentials.get(flow.id) || {};
|
flow.credentials = credentials.get(flow.id) || {};
|
||||||
@ -590,14 +544,15 @@ class Flow {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (type === "bool") {
|
if (type === "bool") {
|
||||||
const val = ((value === "true") || (value === true));
|
const val = ((value === "true") ||
|
||||||
return returnOrCallback(null, val);
|
(value === true));
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
if (type === "cred") {
|
if (type === "cred") {
|
||||||
return returnOrCallback(null, value);
|
return value;
|
||||||
}
|
}
|
||||||
var val = redUtil.evaluateNodeProperty(value, type, null, null, null);
|
var val = redUtil.evaluateNodeProperty(value, type, null, null, null);
|
||||||
return returnOrCallback(null, val);
|
return val;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
this.error(e);
|
this.error(e);
|
||||||
@ -609,11 +564,7 @@ class Flow {
|
|||||||
key = key.substring(8);
|
key = key.substring(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const pVal = this.parent.getSetting(key, callback);
|
return this.parent.getSetting(key);
|
||||||
if (callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return pVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -780,7 +780,7 @@ const flowAPI = {
|
|||||||
getNode: getNode,
|
getNode: getNode,
|
||||||
handleError: () => false,
|
handleError: () => false,
|
||||||
handleStatus: () => false,
|
handleStatus: () => false,
|
||||||
getSetting: (k, callback) => flowUtil.getEnvVar(k, callback),
|
getSetting: k => flowUtil.getEnvVar(k),
|
||||||
log: m => log.log(m)
|
log: m => log.log(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,34 +308,16 @@ module.exports = {
|
|||||||
runtime.settings.envVarExcludes.forEach(v => envVarExcludes[v] = true);
|
runtime.settings.envVarExcludes.forEach(v => envVarExcludes[v] = true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
getEnvVar: function(k) {
|
||||||
* Get the value of an environment variable
|
if (!envVarExcludes[k]) {
|
||||||
* Call with a callback to get the value asynchronously
|
const item = getGlobalEnv(k);
|
||||||
* or without to get the value synchronously
|
|
||||||
* @param {String} key The name of the environment variable
|
|
||||||
* @param {(err: Error, val: Any)} [callback] Optional callback for asynchronous call
|
|
||||||
* @returns {Any | void} The value of the environment variable or undefined if not found
|
|
||||||
*/
|
|
||||||
getEnvVar: function(key, callback) {
|
|
||||||
const returnOrCallback = function(err, val) {
|
|
||||||
if (callback) {
|
|
||||||
callback(err, val);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
if (!envVarExcludes[key]) {
|
|
||||||
const item = getGlobalEnv(key);
|
|
||||||
if (item) {
|
if (item) {
|
||||||
const val = redUtil.evaluateNodeProperty(item.value, item.type, null, null, callback);
|
const val = redUtil.evaluateNodeProperty(item.value, item.type, null, null, null);
|
||||||
if (callback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
return returnOrCallback(null, process.env[key]);
|
return process.env[k];
|
||||||
}
|
}
|
||||||
return returnOrCallback(undefined);
|
return undefined;
|
||||||
},
|
},
|
||||||
diffNodes: diffNodes,
|
diffNodes: diffNodes,
|
||||||
mapEnvVarProperties: mapEnvVarProperties,
|
mapEnvVarProperties: mapEnvVarProperties,
|
||||||
|
83
packages/node_modules/@node-red/util/lib/util.js
vendored
83
packages/node_modules/@node-red/util/lib/util.js
vendored
@ -18,7 +18,6 @@
|
|||||||
/**
|
/**
|
||||||
* @mixin @node-red/util_util
|
* @mixin @node-red/util_util
|
||||||
*/
|
*/
|
||||||
/** @typedef {import('../../runtime/lib/flows/Flow.js').Flow} RuntimeLibFlowsFlow */
|
|
||||||
|
|
||||||
const clonedeep = require("lodash.clonedeep");
|
const clonedeep = require("lodash.clonedeep");
|
||||||
const jsonata = require("jsonata");
|
const jsonata = require("jsonata");
|
||||||
@ -527,68 +526,37 @@ function setObjectProperty(msg,prop,value,createMissing) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*!
|
||||||
* Get value of environment variable.
|
* Get value of environment variable.
|
||||||
* @param {Node} node - accessing node
|
* @param {Node} node - accessing node
|
||||||
* @param {String} name - name of variable
|
* @param {String} name - name of variable
|
||||||
* @param {RuntimeLibFlowsFlow} flow_ - (optional) flow to check for setting
|
|
||||||
* @param {(err: Error, result: Any) => void} callback - (optional) called when the property is evaluated
|
|
||||||
* @return {String} value of env var
|
* @return {String} value of env var
|
||||||
*/
|
*/
|
||||||
function getSetting(node, name, flow_, callback) {
|
function getSetting(node, name, flow_) {
|
||||||
const returnOrCallback = (err, result) => {
|
|
||||||
if (callback) {
|
|
||||||
callback(err, result);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (node) {
|
if (node) {
|
||||||
if (name === "NR_NODE_NAME") {
|
if (name === "NR_NODE_NAME") {
|
||||||
return returnOrCallback(null, node.name);
|
return node.name;
|
||||||
}
|
}
|
||||||
if (name === "NR_NODE_ID") {
|
if (name === "NR_NODE_ID") {
|
||||||
return returnOrCallback(null, node.id);
|
return node.id;
|
||||||
}
|
}
|
||||||
if (name === "NR_NODE_PATH") {
|
if (name === "NR_NODE_PATH") {
|
||||||
return returnOrCallback(null, node._path);
|
return node._path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {RuntimeLibFlowsFlow} */
|
|
||||||
var flow = (flow_ ? flow_ : (node ? node._flow : null));
|
var flow = (flow_ ? flow_ : (node ? node._flow : null));
|
||||||
if (flow) {
|
if (flow) {
|
||||||
if (node && node.g) {
|
if (node && node.g) {
|
||||||
const group = flow.getGroupNode(node.g);
|
const group = flow.getGroupNode(node.g);
|
||||||
if (callback) {
|
const [result, newName] = flow.getGroupEnvSetting(node, group, name);
|
||||||
flow.getGroupEnvSetting(node, group, name, (e, [result, newName]) => {
|
if (result) {
|
||||||
if (e) {
|
return result.val;
|
||||||
callback(e);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (result) {
|
|
||||||
callback(null, result.val);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
name = newName;
|
|
||||||
flow.getSetting(name, callback);
|
|
||||||
});
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
const [result, newName] = flow.getGroupEnvSetting(node, group, name);
|
|
||||||
if (result) {
|
|
||||||
return result.val;
|
|
||||||
}
|
|
||||||
name = newName;
|
|
||||||
}
|
}
|
||||||
|
name = newName;
|
||||||
}
|
}
|
||||||
const fVal = flow.getSetting(name, callback)
|
return flow.getSetting(name);
|
||||||
if (callback) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return fVal;
|
|
||||||
}
|
}
|
||||||
return returnOrCallback(null, process.env[name]);
|
return process.env[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -600,34 +568,19 @@ function getSetting(node, name, flow_, callback) {
|
|||||||
* will return `Hello Joe!`.
|
* will return `Hello Joe!`.
|
||||||
* @param {String} value - the string to parse
|
* @param {String} value - the string to parse
|
||||||
* @param {Node} node - the node evaluating the property
|
* @param {Node} node - the node evaluating the property
|
||||||
* @param {(err: Error, result: Any) => void} callback - (optional) called when the property is evaluated
|
|
||||||
* @return {String} The parsed string
|
* @return {String} The parsed string
|
||||||
* @memberof @node-red/util_util
|
* @memberof @node-red/util_util
|
||||||
*/
|
*/
|
||||||
function evaluateEnvProperty(value, node, callback) {
|
function evaluateEnvProperty(value, node) {
|
||||||
const returnOrCallback = (err, result) => {
|
|
||||||
if (callback) {
|
|
||||||
callback(err, result);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/** @type {RuntimeLibFlowsFlow} */
|
|
||||||
var flow = (node && hasOwnProperty.call(node, "_flow")) ? node._flow : null;
|
var flow = (node && hasOwnProperty.call(node, "_flow")) ? node._flow : null;
|
||||||
var result;
|
var result;
|
||||||
if (/^\${[^}]+}$/.test(value)) {
|
if (/^\${[^}]+}$/.test(value)) {
|
||||||
// ${ENV_VAR}
|
// ${ENV_VAR}
|
||||||
var name = value.substring(2,value.length-1);
|
var name = value.substring(2,value.length-1);
|
||||||
result = getSetting(node, name, flow, callback);
|
result = getSetting(node, name, flow);
|
||||||
if (callback) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else if (!/\${\S+}/.test(value)) {
|
} else if (!/\${\S+}/.test(value)) {
|
||||||
// ENV_VAR
|
// ENV_VAR
|
||||||
result = getSetting(node, value, flow, callback);
|
result = getSetting(node, value, flow);
|
||||||
if (callback) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// FOO${ENV_VAR}BAR
|
// FOO${ENV_VAR}BAR
|
||||||
return value.replace(/\${([^}]+)}/g, function(match, name) {
|
return value.replace(/\${([^}]+)}/g, function(match, name) {
|
||||||
@ -635,7 +588,8 @@ function evaluateEnvProperty(value, node, callback) {
|
|||||||
return (val === undefined)?"":val;
|
return (val === undefined)?"":val;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return returnOrCallback(null, (result === undefined)?"":result);
|
return (result === undefined)?"":result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -723,10 +677,7 @@ function evaluateNodeProperty(value, type, node, msg, callback) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if (type === 'env') {
|
} else if (type === 'env') {
|
||||||
result = evaluateEnvProperty(value, node, callback);
|
result = evaluateEnvProperty(value, node);
|
||||||
if (callback) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(null,result);
|
callback(null,result);
|
||||||
|
@ -44,30 +44,4 @@ describe('unknown Node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate a global environment variable that is a JSONata value', function (done) {
|
|
||||||
const flow = [{
|
|
||||||
id: "n1", type: "global-config", name: "XYZ",
|
|
||||||
env: [
|
|
||||||
{ name: "now-var", type: "jsonata", value: "$millis()" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{ id: "n2", type: "inject", topic: "t1", payload: "now-var", payloadType: "env", wires: [["n3"]], z: "flow" },
|
|
||||||
{ id: "n3", type: "helper" }
|
|
||||||
];
|
|
||||||
helper.load([config, inject], flow, function () {
|
|
||||||
var n2 = helper.getNode("n2");
|
|
||||||
var n3 = helper.getNode("n3");
|
|
||||||
n3.on("input", (msg) => {
|
|
||||||
try {
|
|
||||||
const now = Date.now();
|
|
||||||
msg.should.have.property("payload").and.be.approximately(now, 1000);
|
|
||||||
done();
|
|
||||||
} catch (err) {
|
|
||||||
done(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
n2.receive({});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -686,7 +686,7 @@ describe('Flow', function() {
|
|||||||
},50);
|
},50);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes a status event to the group scoped status node",function(done) {
|
it.only("passes a status event to the group scoped status node",function(done) {
|
||||||
var config = flowUtils.parseConfig([
|
var config = flowUtils.parseConfig([
|
||||||
{id:"t1",type:"tab"},
|
{id:"t1",type:"tab"},
|
||||||
{id: "g1", type: "group", g: "g3" },
|
{id: "g1", type: "group", g: "g3" },
|
||||||
@ -1311,42 +1311,33 @@ describe('Flow', function() {
|
|||||||
})
|
})
|
||||||
process.env.V0 = "gv0";
|
process.env.V0 = "gv0";
|
||||||
process.env.V1 = "gv1";
|
process.env.V1 = "gv1";
|
||||||
process.env.V3 = "gv3";
|
|
||||||
var config = flowUtils.parseConfig([
|
var config = flowUtils.parseConfig([
|
||||||
{id:"t1",type:"tab",env:[
|
{id:"t1",type:"tab",env:[
|
||||||
{"name": "V0", value: "t1v0", type: "str"},
|
{"name": "V0", value: "v0", type: "str"}
|
||||||
{"name": "V2", value: "t1v2", type: "str"}
|
|
||||||
]},
|
]},
|
||||||
{id:"g1",type:"group",z:"t1",env:[
|
{id:"g1",type:"group",z:"t1",env:[
|
||||||
{"name": "V0", value: "g1v0", type: "str"},
|
{"name": "V0", value: "v1", type: "str"},
|
||||||
{"name": "V1", value: "g1v1", type: "str"}
|
{"name": "V1", value: "v2", type: "str"}
|
||||||
]},
|
]},
|
||||||
{id:"g2",type:"group",z:"t1",g:"g1",env:[
|
{id:"g2",type:"group",z:"t1",g:"g1",env:[
|
||||||
{"name": "V1", value: "g2v1", type: "str"}
|
{"name": "V1", value: "v3", type: "str"}
|
||||||
]},
|
]},
|
||||||
{id:"t1__V0",x:10,y:10,z:"t1",type:"test",foo:"${V0}",wires:[]}, // V0 will come from tab env V0
|
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"$(V0)",wires:[]},
|
||||||
{id:"t1g1V0",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"${V0}",wires:[]}, // V0 will come from group 1 env V0
|
{id:"2",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V0)",wires:[]},
|
||||||
{id:"t1g1V1",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"${V1}",wires:[]}, // V1 will come from group 1 env V1
|
{id:"3",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V1)",wires:[]},
|
||||||
{id:"t1g2V0",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${V0}",wires:[]}, // V0 will come from group 1 env V0
|
{id:"4",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"$(V1)",wires:[]},
|
||||||
{id:"t1g2V1",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${V1}",wires:[]}, // V1 will come from group 2 env V1
|
{id:"5",x:10,y:10,z:"t1",type:"test",foo:"$(V1)",wires:[]},
|
||||||
{id:"t1g2V2",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${V2}",wires:[]}, // V2 will come from tab 1 env V2
|
|
||||||
{id:"t1g2V3",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${V3}",wires:[]}, // V3 will come from process env V3
|
|
||||||
|
|
||||||
{id:"t1__V1",x:10,y:10,z:"t1",type:"test",foo:"${V1}",wires:[]},
|
|
||||||
]);
|
]);
|
||||||
var flow = Flow.create({getSetting:v=>process.env[v]},config,config.flows["t1"]);
|
var flow = Flow.create({getSetting:v=>process.env[v]},config,config.flows["t1"]);
|
||||||
flow.start();
|
flow.start();
|
||||||
|
|
||||||
var activeNodes = flow.getActiveNodes();
|
var activeNodes = flow.getActiveNodes();
|
||||||
|
|
||||||
activeNodes.t1__V0.foo.should.equal("t1v0"); // node in tab 1, get tab 1 env V0
|
activeNodes["1"].foo.should.equal("v0");
|
||||||
activeNodes.t1__V1.foo.should.equal("gv1"); // node in tab 1, get V1, (tab 1 no V1) --> parent (global has V1)
|
activeNodes["2"].foo.should.equal("v1");
|
||||||
activeNodes.t1g1V0.foo.should.equal("g1v0"); // node in group 1, get V0, (group 1 has V0)
|
activeNodes["3"].foo.should.equal("v2");
|
||||||
activeNodes.t1g1V1.foo.should.equal("g1v1"); // node in group 1, get V1, (group 1 has V1)
|
activeNodes["4"].foo.should.equal("v3");
|
||||||
activeNodes.t1g2V0.foo.should.equal("g1v0"); // node in group 2, get V0, (group 2 no V0) --> parent (group 1 has V0)
|
activeNodes["5"].foo.should.equal("gv1");
|
||||||
activeNodes.t1g2V1.foo.should.equal("g2v1"); // node in group 2, get V1, (group 2 has V1)
|
|
||||||
activeNodes.t1g2V2.foo.should.equal("t1v2"); // node in group 2, get V2, (group 2 no V2) --> parent (tab 1 has V2)
|
|
||||||
activeNodes.t1g2V3.foo.should.equal("gv3"); // node in group 2, get V3, (group 2 no V3) --> parent (tab 1 no V2) --> parent (global has V3)
|
|
||||||
|
|
||||||
flow.stop().then(function() {
|
flow.stop().then(function() {
|
||||||
done();
|
done();
|
||||||
@ -1356,6 +1347,7 @@ describe('Flow', function() {
|
|||||||
console.log(e.stack);
|
console.log(e.stack);
|
||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
it("can access environment variable property using $parent", function (done) {
|
it("can access environment variable property using $parent", function (done) {
|
||||||
try {
|
try {
|
||||||
@ -1401,6 +1393,7 @@ describe('Flow', function() {
|
|||||||
console.log(e.stack);
|
console.log(e.stack);
|
||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can define environment variable using JSONata", function (done) {
|
it("can define environment variable using JSONata", function (done) {
|
||||||
@ -1434,40 +1427,9 @@ describe('Flow', function() {
|
|||||||
console.log(e.stack);
|
console.log(e.stack);
|
||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can access global environment variables defined as JSONata values", function (done) {
|
|
||||||
try {
|
|
||||||
after(function() {
|
|
||||||
delete process.env.V0;
|
|
||||||
})
|
|
||||||
var config = flowUtils.parseConfig([
|
|
||||||
{id:"t1",type:"tab",env:[
|
|
||||||
{"name": "V0", value: "1+2", type: "jsonata"}
|
|
||||||
]},
|
|
||||||
{id:"g1",type:"group",z:"t1",env:[
|
|
||||||
{"name": "V1", value: "2+3", type: "jsonata"},
|
|
||||||
]},
|
|
||||||
{id:"1",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V0)",wires:[]},
|
|
||||||
{id:"2",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V1)",wires:[]},
|
|
||||||
]);
|
|
||||||
var flow = Flow.create({getSetting:v=>process.env[v]},config,config.flows["t1"]);
|
|
||||||
flow.start();
|
|
||||||
|
|
||||||
var activeNodes = flow.getActiveNodes();
|
|
||||||
|
|
||||||
activeNodes["1"].foo.should.equal(3);
|
|
||||||
activeNodes["2"].foo.should.equal(5);
|
|
||||||
|
|
||||||
flow.stop().then(function() {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
console.log(e.stack);
|
|
||||||
done(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -489,7 +489,7 @@ describe('storage/localfilesystem', function() {
|
|||||||
var rootdir = path.win32.resolve(userDir+'/some');
|
var rootdir = path.win32.resolve(userDir+'/some');
|
||||||
// make it into a local UNC path
|
// make it into a local UNC path
|
||||||
flowFile = flowFile.replace('C:\\', '\\\\localhost\\c$\\');
|
flowFile = flowFile.replace('C:\\', '\\\\localhost\\c$\\');
|
||||||
localfilesystem.init({userDir:userDir, flowFile:flowFile, getUserSettings: () => {{}}}, mockRuntime).then(function() {
|
localfilesystem.init({userDir:userDir, flowFile:flowFile}, mockRuntime).then(function() {
|
||||||
fs.existsSync(flowFile).should.be.false();
|
fs.existsSync(flowFile).should.be.false();
|
||||||
localfilesystem.saveFlows(testFlow).then(function() {
|
localfilesystem.saveFlows(testFlow).then(function() {
|
||||||
fs.existsSync(flowFile).should.be.true();
|
fs.existsSync(flowFile).should.be.true();
|
||||||
|
Loading…
Reference in New Issue
Block a user