-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
65 lines (59 loc) · 1.15 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var thunkify = require('thunkify');
var thunker = function thunker(methods, object) {
var thunked = {};
methods.forEach(function(method) {
switch (typeof method) {
case 'string':
thunked[method] = thunkify(object[method]);
break;
case 'object':
thunked[method.name] = thunker(method.methods, object[method.name]);
break;
}
});
return thunked;
};
var methods = [
'create',
'get',
'destroy',
'list',
'compact',
'replicate',
'changes',
'follow'
];
var db_methods = [
'insert',
'destroy',
'get',
'head',
'copy',
'bulk',
'list',
'fetch',
'view',
'show',
'atomic',
'search',
{
name: 'attachment',
methods: ['insert', 'get', 'destroy']
},
{
name: 'multipart',
methods: ['insert', 'get']
}
];
module.exports = function(nano) {
thunkedNano = {
db: thunker(methods, nano.db),
use: function(db_name) { return thunker(db_methods, nano.use(db_name)) },
request: thunkify(nano.request),
auth: thunkify(nano.auth),
session: thunkify(nano.session),
config: nano.config
};
thunkedNano.db.use = thunkedNano.use;
return thunkedNano;
};