Files: b3369beb8b305b3fd5c63b483fdd8810799b0e2d / book / obs / book.js
556 bytesRaw
1 | const nest = require('depnest') |
2 | const ref = require('ssb-ref') |
3 | const { Value, Struct } = require('mutant') |
4 | |
5 | exports.needs = nest({ |
6 | 'book.pull.get': 'first', |
7 | 'blob.sync.url': 'first' |
8 | }) |
9 | |
10 | exports.gives = nest('book.obs.book') |
11 | |
12 | exports.create = function (api) { |
13 | return nest('book.obs.book', function (id) { |
14 | if (!ref.isLink(id)) throw new Error('a valid id must be specified') |
15 | |
16 | let book = api.book.pull.get(id) |
17 | const s = Struct() |
18 | |
19 | Object.keys(book).forEach(k => { |
20 | if (book[k]) |
21 | s[k].set(book[k]) |
22 | }) |
23 | |
24 | return s |
25 | }) |
26 | } |
27 |
Built with git-ssb-web