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

Pass full runtime object to storage and flow sub-components

This commit is contained in:
Nick O'Leary 2016-09-21 10:22:04 +01:00
parent ee45d6b48f
commit e06cadd761
6 changed files with 42 additions and 32 deletions

View File

@ -83,7 +83,7 @@ function start() {
.then(function() {
return i18n.registerMessageCatalog("runtime",path.resolve(path.join(__dirname,"locales")),"runtime.json")
})
.then(function() { return storage.init(settings)})
.then(function() { return storage.init(runtime)})
.then(function() { return settings.load(storage)})
.then(function() {

View File

@ -43,12 +43,12 @@ var subflowInstanceNodeMap = {};
var typeEventRegistered = false;
function init(_settings, _storage) {
function init(runtime) {
if (started) {
throw new Error("Cannot init without a stop");
}
settings = _settings;
storage = _storage;
settings = runtime.settings;
storage = runtime.storage;
started = false;
if (!typeEventRegistered) {
events.on('type-registered',function(type) {

View File

@ -78,7 +78,7 @@ function createNode(node,def) {
function init(runtime) {
settings = runtime.settings;
credentials.init(runtime.storage);
flows.init(runtime.settings,runtime.storage);
flows.init(runtime);
registry.init(runtime);
context.init(runtime.settings);
}

View File

@ -18,6 +18,7 @@ var when = require('when');
var Path = require('path');
var log = require("../log");
var runtime;
var storageModule;
var settingsAvailable;
var sessionsAvailable;
@ -42,15 +43,16 @@ function is_malicious(path) {
}
var storageModuleInterface = {
init: function(settings) {
init: function(_runtime) {
runtime = _runtime;
try {
storageModule = moduleSelector(settings);
storageModule = moduleSelector(runtime.settings);
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
} catch (e) {
return when.reject(e);
}
return storageModule.init(settings);
return storageModule.init(runtime.settings);
},
getFlows: function() {
return storageModule.getFlows();

View File

@ -119,7 +119,7 @@ describe('flows/index', function() {
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
{id:"t1",type:"tab"}
];
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.setFlows(originalConfig).then(function() {
credentialsExtract.called.should.be.false;
credentialsClean.called.should.be.true;
@ -134,7 +134,7 @@ describe('flows/index', function() {
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
{id:"t1",type:"tab"}
];
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.setFlows(originalConfig,"load").then(function() {
credentialsExtract.called.should.be.false;
credentialsClean.called.should.be.true;
@ -151,7 +151,7 @@ describe('flows/index', function() {
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[],credentials:{}},
{id:"t1",type:"tab"}
];
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.setFlows(originalConfig).then(function() {
credentialsExtract.called.should.be.true;
credentialsClean.called.should.be.true;
@ -188,7 +188,7 @@ describe('flows/index', function() {
})
});
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
});
@ -217,7 +217,7 @@ describe('flows/index', function() {
})
});
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
});
@ -234,7 +234,7 @@ describe('flows/index', function() {
storage.getFlows = function() {
return when.resolve(originalConfig);
}
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
credentialsExtract.called.should.be.false;
credentialsLoad.called.should.be.true;
@ -262,7 +262,7 @@ describe('flows/index', function() {
done();
});
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
});
@ -277,7 +277,7 @@ describe('flows/index', function() {
return when.resolve(originalConfig);
}
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
flowCreate.called.should.be.false;
@ -295,7 +295,7 @@ describe('flows/index', function() {
storage.getFlows = function() {
return when.resolve(originalConfig);
}
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
flowCreate.called.should.be.false;
@ -329,7 +329,7 @@ describe('flows/index', function() {
storage.getFlows = function() {
return when.resolve(originalConfig);
}
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
var c = 0;
flows.eachNode(function(node) {
@ -360,7 +360,7 @@ describe('flows/index', function() {
done();
});
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
});
@ -391,7 +391,7 @@ describe('flows/index', function() {
}
});
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
});
@ -413,7 +413,7 @@ describe('flows/index', function() {
done();
});
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
});
@ -445,7 +445,7 @@ describe('flows/index', function() {
}
});
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
});
@ -473,7 +473,7 @@ describe('flows/index', function() {
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
{id:"t1",type:"tab"}
];
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.setFlows(originalConfig).then(function() {
flows.checkTypeInUse("unused-module");
done();
@ -484,7 +484,7 @@ describe('flows/index', function() {
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
{id:"t1",type:"tab"}
];
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.setFlows(originalConfig).then(function() {
/*jshint immed: false */
try {
@ -507,7 +507,7 @@ describe('flows/index', function() {
storage.getFlows = function() {
return when.resolve(originalConfig);
}
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
flows.addFlow({
label:'new flow',
@ -534,7 +534,7 @@ describe('flows/index', function() {
storage.setFlows = function() {
return when.resolve();
}
flows.init({},storage);
flows.init({settings:{},storage:storage});
flows.load().then(function() {
return flows.startFlows();
}).then(function() {

View File

@ -22,7 +22,9 @@ describe("red/storage/index", function() {
it('rejects the promise when settings suggest loading a bad module', function(done) {
var wrongModule = {
settings:{
storageModule : "thisaintloading"
}
};
storage.init(wrongModule).then( function() {
@ -42,13 +44,15 @@ describe("red/storage/index", function() {
var initSetsMeToTrue = false;
var moduleWithBooleanSettingInit = {
init : function() {
initSetsMeToTrue = true;
}
init : function() {
initSetsMeToTrue = true;
}
};
var setsBooleanModule = {
settings: {
storageModule : moduleWithBooleanSettingInit
}
};
storage.init(setsBooleanModule);
@ -116,7 +120,9 @@ describe("red/storage/index", function() {
};
var moduleToLoad = {
storageModule : interfaceCheckerModule
settings: {
storageModule : interfaceCheckerModule
}
};
storage.init(moduleToLoad);
@ -172,7 +178,9 @@ describe("red/storage/index", function() {
};
var moduleToLoad = {
storageModule : interfaceCheckerModule
settings: {
storageModule : interfaceCheckerModule
}
};
before(function() {
storage.init(moduleToLoad);
@ -220,7 +228,7 @@ describe("red/storage/index", function() {
var interfaceCheckerModule = {
init : function () {}
};
storage.init({storageModule: interfaceCheckerModule});
storage.init({settings:{storageModule: interfaceCheckerModule}});
});
it('defaults missing getSettings',function(done) {