git ssb

2+

ev / mvd



Commit effdd3de52686c48d958e8d650cf55f286dfb1dd

add local query

Ev Bogue committed on 6/27/2018, 11:31:58 PM
Parent: 0c5dee7c6bea576b8424f649ff2b3ad23e10fcb4

Files changed

bin.jschanged
package.jsonchanged
query/index.jsadded
bin.jsView
@@ -32,9 +32,9 @@
3232 .use(require('scuttlebot/plugins/replicate'))
3333 .use(require('ssb-friends'))
3434 .use(require('ssb-blobs'))
3535 .use(require('ssb-backlinks'))
36- .use(require('ssb-query'))
36 + .use(require('./query'))
3737 .use(require('ssb-links'))
3838 .use(require('ssb-ebt'))
3939 .use(require('scuttlebot/plugins/invite'))
4040 .use(require('scuttlebot/plugins/local'))
package.jsonView
@@ -48,9 +48,8 @@
4848 "ssb-keys": "^7.0.16",
4949 "ssb-links": "^3.0.3",
5050 "ssb-markdown": "^3.6.0",
5151 "ssb-mentions": "^0.5.0",
52- "ssb-query": "git+https://git@github.com/evbogue/ssb-query.git",
5352 "ssb-ref": "^2.11.1",
5453 "visualize-buffer": "0.0.1",
5554 "yargs": "^11.0.0"
5655 }
query/index.jsView
@@ -1,0 +1,68 @@
1 +var pull = require('pull-stream')
2 +var path = require('path')
3 +var FlumeQuery = require('flumeview-query')
4 +var explain = require('explain-error')
5 +
6 +function isString(s) {
7 + return 'string' === typeof s
8 +}
9 +
10 +exports.name = 'query'
11 +exports.version = require('./package.json').version
12 +exports.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 +
24 +var INDEX_VERSION = 8
25 +var 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 +
44 +exports.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 +

Built with git-ssb-web