Files: 2ab67531b8a5ecdd7419f3c8d9fa0ccee8cb9377 / query / index.js
1925 bytesRaw
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 = '1.0.0' |
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 | |
69 |
Built with git-ssb-web