Skip to content

Commit e06cadd

Browse files
committed
Pass full runtime object to storage and flow sub-components
1 parent ee45d6b commit e06cadd

6 files changed

Lines changed: 42 additions & 32 deletions

File tree

red/runtime/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function start() {
8383
.then(function() {
8484
return i18n.registerMessageCatalog("runtime",path.resolve(path.join(__dirname,"locales")),"runtime.json")
8585
})
86-
.then(function() { return storage.init(settings)})
86+
.then(function() { return storage.init(runtime)})
8787
.then(function() { return settings.load(storage)})
8888
.then(function() {
8989

red/runtime/nodes/flows/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ var subflowInstanceNodeMap = {};
4343

4444
var typeEventRegistered = false;
4545

46-
function init(_settings, _storage) {
46+
function init(runtime) {
4747
if (started) {
4848
throw new Error("Cannot init without a stop");
4949
}
50-
settings = _settings;
51-
storage = _storage;
50+
settings = runtime.settings;
51+
storage = runtime.storage;
5252
started = false;
5353
if (!typeEventRegistered) {
5454
events.on('type-registered',function(type) {

red/runtime/nodes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function createNode(node,def) {
7878
function init(runtime) {
7979
settings = runtime.settings;
8080
credentials.init(runtime.storage);
81-
flows.init(runtime.settings,runtime.storage);
81+
flows.init(runtime);
8282
registry.init(runtime);
8383
context.init(runtime.settings);
8484
}

red/runtime/storage/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var when = require('when');
1818
var Path = require('path');
1919
var log = require("../log");
2020

21+
var runtime;
2122
var storageModule;
2223
var settingsAvailable;
2324
var sessionsAvailable;
@@ -42,15 +43,16 @@ function is_malicious(path) {
4243
}
4344

4445
var storageModuleInterface = {
45-
init: function(settings) {
46+
init: function(_runtime) {
47+
runtime = _runtime;
4648
try {
47-
storageModule = moduleSelector(settings);
49+
storageModule = moduleSelector(runtime.settings);
4850
settingsAvailable = storageModule.hasOwnProperty("getSettings") && storageModule.hasOwnProperty("saveSettings");
4951
sessionsAvailable = storageModule.hasOwnProperty("getSessions") && storageModule.hasOwnProperty("saveSessions");
5052
} catch (e) {
5153
return when.reject(e);
5254
}
53-
return storageModule.init(settings);
55+
return storageModule.init(runtime.settings);
5456
},
5557
getFlows: function() {
5658
return storageModule.getFlows();

test/red/runtime/nodes/flows/index_spec.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('flows/index', function() {
119119
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
120120
{id:"t1",type:"tab"}
121121
];
122-
flows.init({},storage);
122+
flows.init({settings:{},storage:storage});
123123
flows.setFlows(originalConfig).then(function() {
124124
credentialsExtract.called.should.be.false;
125125
credentialsClean.called.should.be.true;
@@ -134,7 +134,7 @@ describe('flows/index', function() {
134134
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
135135
{id:"t1",type:"tab"}
136136
];
137-
flows.init({},storage);
137+
flows.init({settings:{},storage:storage});
138138
flows.setFlows(originalConfig,"load").then(function() {
139139
credentialsExtract.called.should.be.false;
140140
credentialsClean.called.should.be.true;
@@ -151,7 +151,7 @@ describe('flows/index', function() {
151151
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[],credentials:{}},
152152
{id:"t1",type:"tab"}
153153
];
154-
flows.init({},storage);
154+
flows.init({settings:{},storage:storage});
155155
flows.setFlows(originalConfig).then(function() {
156156
credentialsExtract.called.should.be.true;
157157
credentialsClean.called.should.be.true;
@@ -188,7 +188,7 @@ describe('flows/index', function() {
188188
})
189189
});
190190

191-
flows.init({},storage);
191+
flows.init({settings:{},storage:storage});
192192
flows.load().then(function() {
193193
flows.startFlows();
194194
});
@@ -217,7 +217,7 @@ describe('flows/index', function() {
217217
})
218218
});
219219

220-
flows.init({},storage);
220+
flows.init({settings:{},storage:storage});
221221
flows.load().then(function() {
222222
flows.startFlows();
223223
});
@@ -234,7 +234,7 @@ describe('flows/index', function() {
234234
storage.getFlows = function() {
235235
return when.resolve(originalConfig);
236236
}
237-
flows.init({},storage);
237+
flows.init({settings:{},storage:storage});
238238
flows.load().then(function() {
239239
credentialsExtract.called.should.be.false;
240240
credentialsLoad.called.should.be.true;
@@ -262,7 +262,7 @@ describe('flows/index', function() {
262262
done();
263263
});
264264

265-
flows.init({},storage);
265+
flows.init({settings:{},storage:storage});
266266
flows.load().then(function() {
267267
flows.startFlows();
268268
});
@@ -277,7 +277,7 @@ describe('flows/index', function() {
277277
return when.resolve(originalConfig);
278278
}
279279

280-
flows.init({},storage);
280+
flows.init({settings:{},storage:storage});
281281
flows.load().then(function() {
282282
flows.startFlows();
283283
flowCreate.called.should.be.false;
@@ -295,7 +295,7 @@ describe('flows/index', function() {
295295
storage.getFlows = function() {
296296
return when.resolve(originalConfig);
297297
}
298-
flows.init({},storage);
298+
flows.init({settings:{},storage:storage});
299299
flows.load().then(function() {
300300
flows.startFlows();
301301
flowCreate.called.should.be.false;
@@ -329,7 +329,7 @@ describe('flows/index', function() {
329329
storage.getFlows = function() {
330330
return when.resolve(originalConfig);
331331
}
332-
flows.init({},storage);
332+
flows.init({settings:{},storage:storage});
333333
flows.load().then(function() {
334334
var c = 0;
335335
flows.eachNode(function(node) {
@@ -360,7 +360,7 @@ describe('flows/index', function() {
360360
done();
361361
});
362362

363-
flows.init({},storage);
363+
flows.init({settings:{},storage:storage});
364364
flows.load().then(function() {
365365
flows.startFlows();
366366
});
@@ -391,7 +391,7 @@ describe('flows/index', function() {
391391
}
392392
});
393393

394-
flows.init({},storage);
394+
flows.init({settings:{},storage:storage});
395395
flows.load().then(function() {
396396
flows.startFlows();
397397
});
@@ -413,7 +413,7 @@ describe('flows/index', function() {
413413
done();
414414
});
415415

416-
flows.init({},storage);
416+
flows.init({settings:{},storage:storage});
417417
flows.load().then(function() {
418418
flows.startFlows();
419419
});
@@ -445,7 +445,7 @@ describe('flows/index', function() {
445445
}
446446
});
447447

448-
flows.init({},storage);
448+
flows.init({settings:{},storage:storage});
449449
flows.load().then(function() {
450450
flows.startFlows();
451451
});
@@ -473,7 +473,7 @@ describe('flows/index', function() {
473473
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
474474
{id:"t1",type:"tab"}
475475
];
476-
flows.init({},storage);
476+
flows.init({settings:{},storage:storage});
477477
flows.setFlows(originalConfig).then(function() {
478478
flows.checkTypeInUse("unused-module");
479479
done();
@@ -484,7 +484,7 @@ describe('flows/index', function() {
484484
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
485485
{id:"t1",type:"tab"}
486486
];
487-
flows.init({},storage);
487+
flows.init({settings:{},storage:storage});
488488
flows.setFlows(originalConfig).then(function() {
489489
/*jshint immed: false */
490490
try {
@@ -507,7 +507,7 @@ describe('flows/index', function() {
507507
storage.getFlows = function() {
508508
return when.resolve(originalConfig);
509509
}
510-
flows.init({},storage);
510+
flows.init({settings:{},storage:storage});
511511
flows.load().then(function() {
512512
flows.addFlow({
513513
label:'new flow',
@@ -534,7 +534,7 @@ describe('flows/index', function() {
534534
storage.setFlows = function() {
535535
return when.resolve();
536536
}
537-
flows.init({},storage);
537+
flows.init({settings:{},storage:storage});
538538
flows.load().then(function() {
539539
return flows.startFlows();
540540
}).then(function() {

test/red/runtime/storage/index_spec.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ describe("red/storage/index", function() {
2222
it('rejects the promise when settings suggest loading a bad module', function(done) {
2323

2424
var wrongModule = {
25+
settings:{
2526
storageModule : "thisaintloading"
27+
}
2628
};
2729

2830
storage.init(wrongModule).then( function() {
@@ -42,13 +44,15 @@ describe("red/storage/index", function() {
4244
var initSetsMeToTrue = false;
4345

4446
var moduleWithBooleanSettingInit = {
45-
init : function() {
46-
initSetsMeToTrue = true;
47-
}
47+
init : function() {
48+
initSetsMeToTrue = true;
49+
}
4850
};
4951

5052
var setsBooleanModule = {
53+
settings: {
5154
storageModule : moduleWithBooleanSettingInit
55+
}
5256
};
5357

5458
storage.init(setsBooleanModule);
@@ -116,7 +120,9 @@ describe("red/storage/index", function() {
116120
};
117121

118122
var moduleToLoad = {
119-
storageModule : interfaceCheckerModule
123+
settings: {
124+
storageModule : interfaceCheckerModule
125+
}
120126
};
121127

122128
storage.init(moduleToLoad);
@@ -172,7 +178,9 @@ describe("red/storage/index", function() {
172178
};
173179

174180
var moduleToLoad = {
175-
storageModule : interfaceCheckerModule
181+
settings: {
182+
storageModule : interfaceCheckerModule
183+
}
176184
};
177185
before(function() {
178186
storage.init(moduleToLoad);
@@ -220,7 +228,7 @@ describe("red/storage/index", function() {
220228
var interfaceCheckerModule = {
221229
init : function () {}
222230
};
223-
storage.init({storageModule: interfaceCheckerModule});
231+
storage.init({settings:{storageModule: interfaceCheckerModule}});
224232
});
225233

226234
it('defaults missing getSettings',function(done) {

0 commit comments

Comments
 (0)