Files: 7e467f6efa8f6320f4c92bbfbe6e905689e0b8eb / example / services / things.js
701 bytesRaw
1 | const pull = require('../../').pull |
2 | |
3 | module.exports = { |
4 | name: 'things', |
5 | version: '1.0.0', |
6 | manifest: { |
7 | getSync: 'sync', |
8 | getAsync: 'async', |
9 | find: 'source' |
10 | }, |
11 | methods: function (server, config) { |
12 | const things = config.data.things |
13 | |
14 | return { |
15 | getSync: getSync, |
16 | getAsync: getAsync, |
17 | find: find |
18 | } |
19 | |
20 | function getSync (options) { |
21 | return things[options.id] |
22 | } |
23 | |
24 | function getAsync (options, cb) { |
25 | cb(null, things[options.id]) |
26 | } |
27 | |
28 | function find () { |
29 | return pull.values(values(things)) |
30 | } |
31 | } |
32 | } |
33 | |
34 | function values (obj) { |
35 | return Object.keys(obj) |
36 | .reduce((sofar, key) => { |
37 | return sofar.concat([obj[key]]) |
38 | }, []) |
39 | } |
40 |
Built with git-ssb-web