@node-red/runtime
Advanced tools
Comparing version 2.2.0-beta.1 to 2.2.0
@@ -102,2 +102,3 @@ /** | ||
* @param {String} opts.id - the id of the project to activate | ||
* @param {boolean} opts.clearContext - whether to clear context | ||
* @param {Object} opts.req - the request to log (optional) | ||
@@ -111,3 +112,3 @@ * @return {Promise<Object>} - resolves when complete | ||
if (!currentProject || opts.id !== currentProject.name) { | ||
return runtime.storage.projects.setActiveProject(opts.user, opts.id); | ||
return runtime.storage.projects.setActiveProject(opts.user, opts.id, opts.clearContext); | ||
} | ||
@@ -114,0 +115,0 @@ }, |
@@ -427,2 +427,13 @@ /** | ||
if (group) { | ||
if (name === "NR_GROUP_NAME") { | ||
return [{ | ||
val: group.name | ||
}, null]; | ||
} | ||
if (name === "NR_GROUP_ID") { | ||
return [{ | ||
val: group.id | ||
}, null]; | ||
} | ||
if (group.credentials === undefined) { | ||
@@ -502,3 +513,9 @@ group.credentials = credentials.get(group.id) || {}; | ||
getSetting(key) { | ||
const flow = this.flow; | ||
const flow = this.flow; | ||
if (key === "NR_FLOW_NAME") { | ||
return flow.label; | ||
} | ||
if (key === "NR_FLOW_ID") { | ||
return flow.id; | ||
} | ||
if (flow.credentials === undefined) { | ||
@@ -505,0 +522,0 @@ flow.credentials = credentials.get(flow.id) || {}; |
@@ -374,2 +374,13 @@ /** | ||
const node = this.subflowInstance; | ||
if (node) { | ||
if (name === "NR_NODE_NAME") { | ||
return node.name; | ||
} | ||
if (name === "NR_NODE_ID") { | ||
return node.id; | ||
} | ||
if (name === "NR_NODE_PATH") { | ||
return node._path; | ||
} | ||
} | ||
if (node.g) { | ||
@@ -376,0 +387,0 @@ const group = this.getGroupNode(node.g); |
@@ -88,2 +88,3 @@ /** | ||
Object.defineProperty(conf,'_flow', {value: flow, enumerable: false, writable: true }) | ||
Object.defineProperty(conf,'_path', {value: `${flow.path}/${config._alias||config.id}`, enumerable: false, writable: true }) | ||
newNode = new nodeTypeConstructor(conf); | ||
@@ -90,0 +91,0 @@ } catch (err) { |
@@ -17,26 +17,26 @@ /** | ||
var clone = require("clone"); | ||
var log = require("@node-red/util").log; | ||
var util = require("@node-red/util").util; | ||
var memory = require("./memory"); | ||
const clone = require("clone"); | ||
const log = require("@node-red/util").log; | ||
const util = require("@node-red/util").util; | ||
const memory = require("./memory"); | ||
var settings; | ||
let settings; | ||
// A map of scope id to context instance | ||
var contexts = {}; | ||
let contexts = {}; | ||
// A map of store name to instance | ||
var stores = {}; | ||
var storeList = []; | ||
var defaultStore; | ||
let stores = {}; | ||
let storeList = []; | ||
let defaultStore; | ||
// Whether there context storage has been configured or left as default | ||
var hasConfiguredStore = false; | ||
let hasConfiguredStore = false; | ||
// Unknown Stores | ||
var unknownStores = {}; | ||
let unknownStores = {}; | ||
function logUnknownStore(name) { | ||
if (name) { | ||
var count = unknownStores[name] || 0; | ||
let count = unknownStores[name] || 0; | ||
if (count == 0) { | ||
@@ -56,4 +56,4 @@ log.warn(log._("context.unknown-store", {name: name})); | ||
hasConfiguredStore = false; | ||
var seed = settings.functionGlobalContext || {}; | ||
contexts['global'] = createContext("global",seed); | ||
initialiseGlobalContext(); | ||
// create a default memory store - used by the unit tests that skip the full | ||
@@ -66,2 +66,7 @@ // `load()` initialisation sequence. | ||
function initialiseGlobalContext() { | ||
const seed = settings.functionGlobalContext || {}; | ||
contexts['global'] = createContext("global",seed); | ||
} | ||
function load() { | ||
@@ -239,8 +244,11 @@ return new Promise(function(resolve,reject) { | ||
// Seed is only set for global context - sourced from functionGlobalContext | ||
var scope = id; | ||
var obj = seed || {}; | ||
var seedKeys; | ||
var insertSeedValues; | ||
const scope = id; | ||
const obj = {}; | ||
let seedKeys; | ||
let insertSeedValues; | ||
if (seed) { | ||
seedKeys = Object.keys(seed); | ||
seedKeys.forEach(key => { | ||
obj[key] = seed[key]; | ||
}) | ||
insertSeedValues = function(keys,values) { | ||
@@ -547,4 +555,24 @@ if (!Array.isArray(keys)) { | ||
/** | ||
* Delete the context of the given node/flow/global | ||
* | ||
* If the user has configured a context store, this | ||
* will no-op a request to delete node/flow context. | ||
*/ | ||
function deleteContext(id,flowId) { | ||
if(!hasConfiguredStore){ | ||
if (id === "global") { | ||
// 1. delete global from all configured stores | ||
var promises = []; | ||
for(var plugin in stores){ | ||
if(stores.hasOwnProperty(plugin)){ | ||
promises.push(stores[plugin].delete('global')); | ||
} | ||
} | ||
return Promise.all(promises).then(function() { | ||
// 2. delete global context | ||
delete contexts['global']; | ||
// 3. reinitialise global context | ||
initialiseGlobalContext(); | ||
}) | ||
} else if (!hasConfiguredStore) { | ||
// only delete context if there's no configured storage. | ||
@@ -557,3 +585,3 @@ var contextId = id; | ||
return stores["_"].delete(contextId); | ||
}else{ | ||
} else { | ||
return Promise.resolve(); | ||
@@ -563,3 +591,10 @@ } | ||
/** | ||
* Delete any contexts that are no longer in use | ||
* @param flowConfig object includes allNodes as object of id->node | ||
* | ||
* If flowConfig is undefined, all flow/node contexts will be removed | ||
**/ | ||
function clean(flowConfig) { | ||
flowConfig = flowConfig || { allNodes: {} }; | ||
var promises = []; | ||
@@ -582,2 +617,12 @@ for(var plugin in stores){ | ||
/** | ||
* Deletes all contexts, including global and reinitialises global to | ||
* initial state. | ||
*/ | ||
function clear() { | ||
return clean().then(function() { | ||
return deleteContext('global') | ||
}) | ||
} | ||
function close() { | ||
@@ -605,3 +650,4 @@ var promises = []; | ||
clean: clean, | ||
clear: clear, | ||
close: close | ||
}; |
@@ -209,2 +209,3 @@ /** | ||
clearContext: context.clear, | ||
@@ -211,0 +212,0 @@ installerEnabled: registry.installerEnabled, |
@@ -65,2 +65,5 @@ /** | ||
} | ||
if (n._path) { | ||
Object.defineProperty(this,'_path', {value: n._path, enumerable: false, writable: true }) | ||
} | ||
this.updateWires(n.wires); | ||
@@ -67,0 +70,0 @@ } |
@@ -380,4 +380,13 @@ /** | ||
function reloadActiveProject(action) { | ||
function reloadActiveProject(action, clearContext) { | ||
// Stop the current flows | ||
return runtime.nodes.stopFlows().then(function() { | ||
if (clearContext) { | ||
// Reset context to remove any old values | ||
return runtime.nodes.clearContext() | ||
} else { | ||
return Promise.resolve() | ||
} | ||
}).then(function() { | ||
// Load the new project flows and start them | ||
return runtime.nodes.loadFlows(true).then(function() { | ||
@@ -391,2 +400,5 @@ events.emit("runtime-event",{id:"project-update", payload:{ project: activeProject.name, action:action}}); | ||
}); | ||
}).catch(function(err) { | ||
console.log(err.stack); | ||
throw err; | ||
}); | ||
@@ -429,3 +441,3 @@ } | ||
} | ||
function setActiveProject(user, projectName) { | ||
function setActiveProject(user, projectName, clearContext) { | ||
return loadProject(projectName).then(function(project) { | ||
@@ -440,3 +452,3 @@ var globalProjectSettings = settings.get("projects")||{}; | ||
// console.log(credentialsFile) | ||
return reloadActiveProject("loaded"); | ||
return reloadActiveProject("loaded", clearContext); | ||
}) | ||
@@ -443,0 +455,0 @@ }); |
{ | ||
"name": "@node-red/runtime", | ||
"version": "2.2.0-beta.1", | ||
"version": "2.2.0", | ||
"license": "Apache-2.0", | ||
@@ -19,4 +19,4 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@node-red/registry": "2.2.0-beta.1", | ||
"@node-red/util": "2.2.0-beta.1", | ||
"@node-red/registry": "2.2.0", | ||
"@node-red/util": "2.2.0", | ||
"async-mutex": "0.3.2", | ||
@@ -23,0 +23,0 @@ "clone": "2.1.2", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
547014
12832
1
+ Added@node-red/registry@2.2.0(transitive)
+ Added@node-red/util@2.2.0(transitive)
+ Addedi18next@21.6.10(transitive)
+ Addeduglify-js@3.15.0(transitive)
- Removed@node-red/registry@2.2.0-beta.1(transitive)
- Removed@node-red/util@2.2.0-beta.1(transitive)
- Removedi18next@21.6.6(transitive)
- Removeduglify-js@3.14.5(transitive)
Updated@node-red/registry@2.2.0
Updated@node-red/util@2.2.0