-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
39 lines (35 loc) · 799 Bytes
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var db = require('./db');
function APIElem(name,path,type,version,children,attr) {
this.name = name;
this.path = path;
this.fullName = name + path;
this.type = type;
this.children = children;
this.attr = attr;
}
function mapChildren(api,f) {
if(api.children) {
for(var i = 0; i < api.children.length; i++) {
api.children[i] = f(api.children[i]);
}
}
return api;
}
function purge(api) {
var newAPI = new Object();
newAPI.name = api.name;
newAPI.children = api.children;
newAPI = mapChildren(newAPI,purge);
return newAPI;
}
//api has to be either elem or full name
function loadChildren(api,callback) {
api = mapChildren(api,
function(name) {
return api.fullName + '/' + name;
});
db.get({fullName:{$in:api.children}},
function(err,res) {
callback(res);
});
}