git ssb

0+

ev / gitmx



Tree: b3bdb4f23168852c91700c8b3e7a474dc7b7eb2c

Files: b3bdb4f23168852c91700c8b3e7a474dc7b7eb2c / query / index.js

1925 bytesRaw
1var pull = require('pull-stream')
2var path = require('path')
3var FlumeQuery = require('flumeview-query')
4var explain = require('explain-error')
5
6function isString(s) {
7 return 'string' === typeof s
8}
9
10exports.name = 'query'
11exports.version = '1.0.0'
12exports.manifest = {
13 read: 'source',
14 explain: 'sync'
15}
16
17//what are links used for?
18//query follows
19//query replies
20//query mentions (backlinks & mentions)
21//query votes
22
23
24var INDEX_VERSION = 8
25var indexes = [
26 {key: 'log', value: ['timestamp']},
27 {key: 'clk', value: [['value', 'author'], ['value', 'sequence']] },
28 {key: 'typ', value: [['value', 'content', 'type'], ['timestamp']] },
29 {key: 'tya', value: [['value', 'content', 'type'], ['value', 'timestamp']] },
30 {key: 'cha', value: [['value', 'content', 'channel'], ['timestamp']] },
31 {key: 'aty', value: [['value', 'author'], ['value', 'content', 'type'], ['timestamp']]},
32 {key: 'ata', value: [['value', 'author'], ['value', 'content', 'type'], ['value', 'timestamp']]},
33 {key: 'art', value: [['value', 'content', 'root'], ['value', 'timestamp']]},
34 {key: 'lor', value: [['value', 'timestamp' ]]}
35]
36
37//createHistoryStream( id, seq )
38//[{$filter: {author: <id>, sequence: {$gt: <seq>}}}, {$map: true}]
39
40//messagesByType (type)
41
42//[{$filter: {content: {type: <type>}}}, {$map: true}]
43
44exports.init = function (ssb, config) {
45 var s = ssb._flumeUse('query', FlumeQuery(INDEX_VERSION, {indexes: indexes}))
46 var read = s.read
47 var explain = s.explain
48 s.explain = function (opts) {
49 if(!opts) opts = {}
50 if(isString(opts))
51 opts = {query: JSON.parse(opts)}
52 else if(isString(opts.query))
53 opts.query = JSON.parse(opts.query)
54 return explain(opts)
55 }
56
57 s.read = function (opts) {
58 if(!opts) opts = {}
59 if(isString(opts))
60 opts = {query: JSON.parse(opts)}
61 else if(isString(opts.query))
62 opts.query = JSON.parse(opts.query)
63 return read(opts)
64 }
65 return s
66}
67
68
69

Built with git-ssb-web