mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Moved get node set response to /nodes/:mod/:set
Updated tests Changed plugin back to module
This commit is contained in:
parent
0ff65f6805
commit
d614b7c39f
@ -52,10 +52,12 @@ function init(adminApp) {
|
|||||||
adminApp.get("/nodes",nodes.getAll);
|
adminApp.get("/nodes",nodes.getAll);
|
||||||
adminApp.post("/nodes",nodes.post);
|
adminApp.post("/nodes",nodes.post);
|
||||||
|
|
||||||
adminApp.get("/nodes/:id",nodes.get);
|
adminApp.get("/nodes/:mod",nodes.getModule);
|
||||||
adminApp.put("/nodes/:id",nodes.put);
|
adminApp.put("/nodes/:id",nodes.put);
|
||||||
adminApp.delete("/nodes/:id",nodes.delete);
|
adminApp.delete("/nodes/:id",nodes.delete);
|
||||||
|
|
||||||
|
adminApp.get("/nodes/:mod/:set",nodes.getSet);
|
||||||
|
|
||||||
// Plugins
|
// Plugins
|
||||||
adminApp.get("/plugins",plugins.getAll);
|
adminApp.get("/plugins",plugins.getAll);
|
||||||
adminApp.get("/plugins/:id",plugins.get);
|
adminApp.get("/plugins/:id",plugins.get);
|
||||||
|
@ -97,10 +97,10 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get: function(req,res) {
|
getSet: function(req,res) {
|
||||||
var id = req.params.id;
|
var id = req.params.mod + "/" + req.params.set;
|
||||||
var result = null;
|
var result = null;
|
||||||
if (req.get("accept") == "application/json") {
|
if (req.get("accept") === "application/json") {
|
||||||
result = redNodes.getNodeInfo(id);
|
result = redNodes.getNodeInfo(id);
|
||||||
} else {
|
} else {
|
||||||
result = redNodes.getNodeConfig(id);
|
result = redNodes.getNodeConfig(id);
|
||||||
@ -112,6 +112,16 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getModule: function(req,res) {
|
||||||
|
var module = req.params.mod;
|
||||||
|
var result = redNodes.getModuleInfo(module);
|
||||||
|
if (result) {
|
||||||
|
res.send(result);
|
||||||
|
} else {
|
||||||
|
res.send(404);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
put: function(req,res) {
|
put: function(req,res) {
|
||||||
if (!settings.available()) {
|
if (!settings.available()) {
|
||||||
res.send(400,new Error("Settings unavailable").toString());
|
res.send(400,new Error("Settings unavailable").toString());
|
||||||
@ -152,4 +162,4 @@ module.exports = {
|
|||||||
res.send(400,err.toString());
|
res.send(400,err.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
@ -18,11 +18,11 @@ var redNodes = require("../nodes");
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getAll: function(req,res) {
|
getAll: function(req,res) {
|
||||||
res.json(redNodes.getPluginList());
|
res.json(redNodes.getModuleList());
|
||||||
},
|
},
|
||||||
get: function(req,res) {
|
get: function(req,res) {
|
||||||
var id = req.params.id;
|
var id = req.params.id;
|
||||||
var result = redNodes.getPluginInfo(id);
|
var result = redNodes.getModuleInfo(id);
|
||||||
if (result) {
|
if (result) {
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} else {
|
} else {
|
||||||
|
@ -112,13 +112,18 @@ module.exports = {
|
|||||||
// Node type registry
|
// Node type registry
|
||||||
registerType: registerType,
|
registerType: registerType,
|
||||||
getType: registry.get,
|
getType: registry.get,
|
||||||
|
|
||||||
getNodeInfo: registry.getNodeInfo,
|
getNodeInfo: registry.getNodeInfo,
|
||||||
getNodeModuleInfo: registry.getNodeModuleInfo,
|
|
||||||
getPluginInfo: registry.getPluginInfo,
|
|
||||||
getNodeList: registry.getNodeList,
|
getNodeList: registry.getNodeList,
|
||||||
getPluginList: registry.getPluginList,
|
|
||||||
|
getNodeModuleInfo: registry.getNodeModuleInfo,
|
||||||
|
|
||||||
|
getModuleInfo: registry.getModuleInfo,
|
||||||
|
getModuleList: registry.getModuleList,
|
||||||
|
|
||||||
getNodeConfigs: registry.getNodeConfigs,
|
getNodeConfigs: registry.getNodeConfigs,
|
||||||
getNodeConfig: registry.getNodeConfig,
|
getNodeConfig: registry.getNodeConfig,
|
||||||
|
|
||||||
clearRegistry: registry.clear,
|
clearRegistry: registry.clear,
|
||||||
cleanNodeList: registry.cleanNodeList,
|
cleanNodeList: registry.cleanNodeList,
|
||||||
|
|
||||||
|
@ -161,31 +161,31 @@ var registry = (function() {
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
},
|
},
|
||||||
getPluginList: function() {
|
getModuleList: function() {
|
||||||
var list = [];
|
var list = [];
|
||||||
for (var plugin in nodeModules) {
|
for (var module in nodeModules) {
|
||||||
if (nodeModules.hasOwnProperty(plugin)) {
|
if (nodeModules.hasOwnProperty(module)) {
|
||||||
var nodes = nodeModules[plugin].nodes;
|
var nodes = nodeModules[module].nodes;
|
||||||
var m = {
|
var m = {
|
||||||
name: plugin,
|
name: module,
|
||||||
nodes: []
|
nodes: []
|
||||||
};
|
};
|
||||||
for (var i = 0; i < nodes.length; ++i) {
|
for (var i = 0; i < nodes.length; ++i) {
|
||||||
m.nodes.push(filterNodeInfo(nodeConfigs[plugin+"/"+nodes[i]]));
|
m.nodes.push(filterNodeInfo(nodeConfigs[module+"/"+nodes[i]]));
|
||||||
}
|
}
|
||||||
list.push(m);
|
list.push(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
},
|
},
|
||||||
getPluginInfo: function(plugin) {
|
getModuleInfo: function(module) {
|
||||||
var nodes = nodeModules[plugin].nodes;
|
var nodes = nodeModules[module].nodes;
|
||||||
var m = {
|
var m = {
|
||||||
name: plugin,
|
name: module,
|
||||||
nodes: []
|
nodes: []
|
||||||
};
|
};
|
||||||
for (var i = 0; i < nodes.length; ++i) {
|
for (var i = 0; i < nodes.length; ++i) {
|
||||||
m.nodes.push(filterNodeInfo(nodeConfigs[plugin+"/"+nodes[i]]));
|
m.nodes.push(filterNodeInfo(nodeConfigs[module+"/"+nodes[i]]));
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
},
|
},
|
||||||
@ -260,7 +260,7 @@ var registry = (function() {
|
|||||||
return nodeTypeToId[type];
|
return nodeTypeToId[type];
|
||||||
},
|
},
|
||||||
|
|
||||||
getModuleInfo: function(type) {
|
getNodeModuleInfo: function(type) {
|
||||||
return nodeModules[type];
|
return nodeModules[type];
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -398,7 +398,7 @@ function scanTreeForNodesModules(moduleName) {
|
|||||||
var files = fs.readdirSync(pm);
|
var files = fs.readdirSync(pm);
|
||||||
for (var i=0;i<files.length;i++) {
|
for (var i=0;i<files.length;i++) {
|
||||||
var fn = files[i];
|
var fn = files[i];
|
||||||
if (!registry.getModuleInfo(fn)) {
|
if (!registry.getNodeModuleInfo(fn)) {
|
||||||
if (!moduleName || fn == moduleName) {
|
if (!moduleName || fn == moduleName) {
|
||||||
var pkgfn = path.join(pm,fn,"package.json");
|
var pkgfn = path.join(pm,fn,"package.json");
|
||||||
try {
|
try {
|
||||||
@ -675,7 +675,7 @@ function addModule(module) {
|
|||||||
throw new Error("Settings unavailable");
|
throw new Error("Settings unavailable");
|
||||||
}
|
}
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
if (registry.getModuleInfo(module)) {
|
if (registry.getNodeModuleInfo(module)) {
|
||||||
return when.reject(new Error("Module already loaded"));
|
return when.reject(new Error("Module already loaded"));
|
||||||
}
|
}
|
||||||
var moduleFiles = scanTreeForNodesModules(module);
|
var moduleFiles = scanTreeForNodesModules(module);
|
||||||
@ -695,14 +695,19 @@ module.exports = {
|
|||||||
load:load,
|
load:load,
|
||||||
clear: registry.clear,
|
clear: registry.clear,
|
||||||
registerType: registry.registerNodeConstructor,
|
registerType: registry.registerNodeConstructor,
|
||||||
|
|
||||||
get: registry.getNodeConstructor,
|
get: registry.getNodeConstructor,
|
||||||
getNodeInfo: registry.getNodeInfo,
|
getNodeInfo: registry.getNodeInfo,
|
||||||
getNodeModuleInfo: registry.getModuleInfo,
|
|
||||||
getPluginInfo: registry.getPluginInfo,
|
|
||||||
getNodeList: registry.getNodeList,
|
getNodeList: registry.getNodeList,
|
||||||
getPluginList: registry.getPluginList,
|
|
||||||
|
getNodeModuleInfo: registry.getNodeModuleInfo,
|
||||||
|
|
||||||
|
getModuleInfo: registry.getModuleInfo,
|
||||||
|
getModuleList: registry.getModuleList,
|
||||||
|
|
||||||
getNodeConfigs: registry.getAllNodeConfigs,
|
getNodeConfigs: registry.getAllNodeConfigs,
|
||||||
getNodeConfig: registry.getNodeConfig,
|
getNodeConfig: registry.getNodeConfig,
|
||||||
|
|
||||||
addNode: addNode,
|
addNode: addNode,
|
||||||
removeNode: registry.removeNode,
|
removeNode: registry.removeNode,
|
||||||
enableNode: registry.enableNodeSet,
|
enableNode: registry.enableNodeSet,
|
||||||
|
@ -36,7 +36,8 @@ describe("nodes api", function() {
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.get("/nodes",nodes.getAll);
|
app.get("/nodes",nodes.getAll);
|
||||||
app.post("/nodes",nodes.post);
|
app.post("/nodes",nodes.post);
|
||||||
app.get("/nodes/:id",nodes.get);
|
app.get("/nodes/:mod",nodes.getModule);
|
||||||
|
app.get("/nodes/:mod/:set",nodes.getSet);
|
||||||
app.put("/nodes/:id",nodes.put);
|
app.put("/nodes/:id",nodes.put);
|
||||||
app.delete("/nodes/:id",nodes.delete);
|
app.delete("/nodes/:id",nodes.delete);
|
||||||
});
|
});
|
||||||
@ -78,12 +79,45 @@ describe("nodes api", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns an individual node info', function(done) {
|
it('returns node module info', function(done) {
|
||||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
var getNodeInfo = sinon.stub(redNodes,'getModuleInfo', function(id) {
|
||||||
return {"123":{id:"123"}}[id];
|
return {"node-red":{name:"node-red"}}[id];
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
.get('/nodes/123')
|
.get('/nodes/node-red')
|
||||||
|
.expect(200)
|
||||||
|
.end(function(err,res) {
|
||||||
|
getNodeInfo.restore();
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
res.body.should.have.property("name","node-red");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 404 for unknown module', function(done) {
|
||||||
|
var getNodeInfo = sinon.stub(redNodes,'getModuleInfo', function(id) {
|
||||||
|
return {"node-red":{name:"node-red"}}[id];
|
||||||
|
});
|
||||||
|
request(app)
|
||||||
|
.get('/nodes/node-blue')
|
||||||
|
.expect(404)
|
||||||
|
.end(function(err,res) {
|
||||||
|
getNodeInfo.restore();
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns individual node info', function(done) {
|
||||||
|
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
||||||
|
return {"node-red/123":{id:"node-red/123"}}[id];
|
||||||
|
});
|
||||||
|
request(app)
|
||||||
|
.get('/nodes/node-red/123')
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
@ -91,17 +125,17 @@ describe("nodes api", function() {
|
|||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
res.body.should.have.property("id","123");
|
res.body.should.have.property("id","node-red/123");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns an individual node configs', function(done) {
|
it('returns individual node configs', function(done) {
|
||||||
var getNodeConfig = sinon.stub(redNodes,'getNodeConfig', function(id) {
|
var getNodeConfig = sinon.stub(redNodes,'getNodeConfig', function(id) {
|
||||||
return {"123":"<script></script>"}[id];
|
return {"node-red/123":"<script></script>"}[id];
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
.get('/nodes/123')
|
.get('/nodes/node-red/123')
|
||||||
.set('Accept', 'text/html')
|
.set('Accept', 'text/html')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect("<script></script>")
|
.expect("<script></script>")
|
||||||
@ -116,10 +150,10 @@ describe("nodes api", function() {
|
|||||||
|
|
||||||
it('returns 404 for unknown node', function(done) {
|
it('returns 404 for unknown node', function(done) {
|
||||||
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
var getNodeInfo = sinon.stub(redNodes,'getNodeInfo', function(id) {
|
||||||
return {"123":{id:"123"}}[id];
|
return {"node-red/123":{id:"node-red/123"}}[id];
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
.get('/nodes/456')
|
.get('/nodes/node-red/456')
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.expect(404)
|
.expect(404)
|
||||||
.end(function(err,res) {
|
.end(function(err,res) {
|
||||||
|
@ -40,7 +40,7 @@ describe("plugins api", function() {
|
|||||||
|
|
||||||
describe('get plugins', function() {
|
describe('get plugins', function() {
|
||||||
it('returns plugins list', function(done) {
|
it('returns plugins list', function(done) {
|
||||||
var getPluginList = sinon.stub(redNodes,'getPluginList', function() {
|
var getPluginList = sinon.stub(redNodes,'getModuleList', function() {
|
||||||
return [1,2,3];
|
return [1,2,3];
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
@ -57,7 +57,7 @@ describe("plugins api", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns an individual plugin info', function(done) {
|
it('returns an individual plugin info', function(done) {
|
||||||
var getPluginInfo = sinon.stub(redNodes,'getPluginInfo', function(id) {
|
var getPluginInfo = sinon.stub(redNodes,'getModuleInfo', function(id) {
|
||||||
return {"name":"123", "nodes":[1,2,3]};
|
return {"name":"123", "nodes":[1,2,3]};
|
||||||
});
|
});
|
||||||
request(app)
|
request(app)
|
||||||
|
@ -435,7 +435,7 @@ describe('NodeRegistry', function() {
|
|||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
|
|
||||||
typeRegistry.addModule("TestNodeModule").then(function() {
|
typeRegistry.addModule("TestNodeModule").then(function() {
|
||||||
var list = typeRegistry.getPluginList();
|
var list = typeRegistry.getModuleList();
|
||||||
list.should.be.an.Array.and.have.lengthOf(1);
|
list.should.be.an.Array.and.have.lengthOf(1);
|
||||||
list[0].should.have.property("name", "TestNodeModule");
|
list[0].should.have.property("name", "TestNodeModule");
|
||||||
list[0].should.have.property("nodes");
|
list[0].should.have.property("nodes");
|
||||||
@ -487,9 +487,9 @@ describe('NodeRegistry', function() {
|
|||||||
typeRegistry.load("wontexist",true).then(function(){
|
typeRegistry.load("wontexist",true).then(function(){
|
||||||
|
|
||||||
typeRegistry.addModule("TestNodeModule").then(function(nodes) {
|
typeRegistry.addModule("TestNodeModule").then(function(nodes) {
|
||||||
var list = typeRegistry.getPluginList();
|
var list = typeRegistry.getModuleList();
|
||||||
|
|
||||||
var plugin = typeRegistry.getPluginInfo(list[0].name);
|
var plugin = typeRegistry.getModuleInfo(list[0].name);
|
||||||
plugin.should.have.property("name", list[0].name);
|
plugin.should.have.property("name", list[0].name);
|
||||||
plugin.should.have.property("nodes", nodes);
|
plugin.should.have.property("nodes", nodes);
|
||||||
done();
|
done();
|
||||||
|
Loading…
Reference in New Issue
Block a user