1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00
node-red/packages/node_modules/@node-red/runtime/lib/flows/Group.js
2023-06-23 02:11:57 +01:00

56 lines
1.3 KiB
JavaScript

const flowUtil = require("./util");
const credentials = require("../nodes/credentials");
/**
* This class represents a group within the runtime.
*/
class Group {
/**
* Create a Group object.
* @param {[type]} parent The parent flow/group
* @param {[type]} groupDef This group's definition
*/
constructor(parent, groupDef) {
this.TYPE = 'group'
this.name = groupDef.name
this.parent = parent
this.group = groupDef
this.id = this.group.id
this.g = this.group.g
this.env = this.group.env
this._env = {}
}
async start() {
if (this.env) {
this._env = await flowUtil.evaluateEnvProperties(this, this.env, credentials.get(this.id))
}
}
/**
* Get a group setting value.
* @param {[type]} key [description]
* @return {[type]} [description]
*/
getSetting(key) {
if (key === "NR_GROUP_NAME") {
return this.name;
}
if (key === "NR_GROUP_ID") {
return this.id;
}
if (!key.startsWith("$parent.")) {
if (this._env.hasOwnProperty(key)) {
return this._env[key]
}
} else {
key = key.substring(8);
}
return this.parent.getSetting(key);
}
}
module.exports = {
Group
}