index.jsView |
---|
3 | 3 … | const get = require('lodash/get') |
4 | 4 … | const extend = require('xtend') |
5 | 5 … | const pry = require('pryjs') |
6 | 6 … | |
7 | | -const FLUME_VIEW_VERSION = 1.01111111111 |
| 7 … | +const FLUME_VIEW_VERSION = 1.011111111111 |
8 | 8 … | const FLUME_VIEW_NAME = "secrets" |
9 | 9 … | |
10 | 10 … | const MODULE_NAME = "secrets" |
11 | 11 … | const MSG_TYPES = ["root", "invite", "response", "contract", "secret", "announcement"] |
17 | 17 … | get: 'async', |
18 | 18 … | stream: 'source' |
19 | 19 … | }, |
20 | 20 … | init: function (server, config) { |
21 | | - const db = server._flumeUse( |
22 | | - FLUME_VIEW_NAME, |
23 | | - flumeView(FLUME_VIEW_VERSION, reduce, map, null, {}) |
24 | | - ) |
| 21 … | + const root = server._flumeUse("root", flumeView(FLUME_VIEW_VERSION, reduce, () => { |
25 | 22 … | |
| 23 … | + }, null, {})) |
| 24 … | + |
| 25 … | + const invites = server._flumeUse("invite", flumeView(FLUME_VIEW_VERSION, reduce, () => { |
| 26 … | + |
| 27 … | + }, null, {})) |
| 28 … | + |
| 29 … | + const responses = server._flumeUse("response", flumeView(FLUME_VIEW_VERSION, reduce, () => { |
|
| 30 … | + |
| 31 … | + }, null, {})) |
| 32 … | + |
| 33 … | + const contract = server._flumeUse("contract", flumeView(FLUME_VIEW_VERSION, reduce, () => { |
| 34 … | + |
| 35 … | + }, null, {})) |
| 36 … | + |
| 37 … | + const secrets= server._flumeUse("secret", flumeView(FLUME_VIEW_VERSION, reduce, () => { |
| 38 … | + |
| 39 … | + }, null, {})) |
| 40 … | + |
26 | 41 … | return { |
27 | | - get: db.get, |
28 | | - stream: db.stream |
| 42 … | + root: (opts: {}, cb: ()) => { |
| 43 … | + root.get(opts, cb) |
| 44 … | + }, |
| 45 … | + invites: (opts: {}, cb: ()) => { |
| 46 … | + invites.get(opts, cb) |
| 47 … | + }, |
| 48 … | + responses: (opts: {}, cb: ()) => { |
| 49 … | + responses.get(opts, cb) |
| 50 … | + }, |
| 51 … | + contract: (opts: {}, cb: ()) => { |
| 52 … | + contract.get(opts, cb) |
| 53 … | + }, |
| 54 … | + secrets: (opts: {}, cb: ()) => { |
| 55 … | + secrets.get(opts, cb) |
| 56 … | + } |
29 | 57 … | } |
30 | 58 … | |
31 | 59 … | function reduce (accumulator, item) { |
32 | 60 … | var accumulator = accumulator || {} |
| 61 … | + eval(pry.it) |
33 | 62 … | const { root, author, invite, response, contract } = item |
34 | 63 … | var rootNode = get(accumulator, [root], {}) |
35 | 64 … | if (invite.recp) { |
36 | 65 … | hasInvite = rootNode.invites.filter(invite => invite.id === invite.recp.id).length > 0 |
58 | 87 … | ? recp !== data.author |
59 | 88 … | : recp.id !== data.author |
60 | 89 … | }) |
61 | 90 … | : null |
| 91 … | + if (data.type === "invite") { |
| 92 … | + return { |
| 93 … | + |
| 94 … | + } |
| 95 … | + } |
62 | 96 … | return { |
63 | 97 … | root: data.root || msg.key, |
64 | 98 … | author: author, |
65 | 99 … | invite: { |