Files: ca816818ec9f749ff0cd2d1fcacc082af7bf6574 / index.js
1225 bytesRaw
1 | const inject = require('./inject') |
2 | |
3 | const methods = { |
4 | async: { |
5 | comment: require('./async/comment'), |
6 | create: require('./async/create'), |
7 | get: require('./async/get'), |
8 | isBookComment: require('./async/isBookComment'), |
9 | isBookUpdate: require('./async/isBookUpdate'), |
10 | update: require('./async/update'), |
11 | }, |
12 | obs: { |
13 | authors: require('./obs/authors'), |
14 | book: require('./obs/book'), |
15 | shelves: require('./obs/shelves'), |
16 | }, |
17 | pull: { |
18 | books: require('./pull/books'), |
19 | comments: require('./pull/comments'), |
20 | updates: require('./pull/updates'), |
21 | }, |
22 | sync: { |
23 | isBook: require('./isBook'), // << exception |
24 | } |
25 | } |
26 | |
27 | // Note : if you don't like this export pattern, there's no reason we can't add different mappings !! |
28 | // e.g. book.validate.bookComment |
29 | |
30 | module.exports = function Book (client, opts) { |
31 | return inject(client, methods) |
32 | } |
33 | |
34 | |
35 | // auto-inject the ssb-client instance to all methods to reduce repition |
36 | function inject (client, methods) { |
37 | for (var key in methods) { |
38 | if (typeof methods[key] === 'function') { |
39 | methods[key] = methods[key](client) |
40 | |
41 | // TODO skip isBook |
42 | } |
43 | else { |
44 | methods[key] = inject(client, methods[key]) |
45 | } |
46 | } |
47 | |
48 | return methods |
49 | } |
50 | |
51 | |
52 |
Built with git-ssb-web