Files: dbbf237575999fcd3273f83ef6f4908813631a95 / indexes / clock.js
1426 bytesRaw
1 | var ref = require('ssb-ref') |
2 | var path = require('path') |
3 | var Follower = require('../follower') |
4 | var pull = require('pull-stream') |
5 | var ltgt = require('ltgt') |
6 | //53 bit integer |
7 | var MAX_INT = 0x1fffffffffffff |
8 | var u = require('../util') |
9 | |
10 | module.exports = function (db, opts) { |
11 | |
12 | var indexPath = path.join(db.location, 'clock') |
13 | var index = Follower(db, indexPath, 1, function (data) { |
14 | if(data.sync) return |
15 | return { |
16 | key: [data.value.author, data.value.sequence], value: data.key, type: 'put' |
17 | } |
18 | }) |
19 | |
20 | index.createHistoryStream = function (opts) { |
21 | var opts = u.options(opts) |
22 | var id = opts.id |
23 | var seq = opts.sequence || opts.seq || 0 |
24 | var limit = opts.limit |
25 | return pull( |
26 | index.read({ |
27 | gte: [id, seq], |
28 | lte: [id, MAX_INT], |
29 | live: opts && opts.live, |
30 | old: opts && opts.old, |
31 | keys: false, |
32 | sync: false === (opts && opts.sync), |
33 | limit: limit |
34 | }), |
35 | db.lookup(opts.keys !== false, opts.values !== false) |
36 | ) |
37 | } |
38 | |
39 | index.createUserStream = function (opts) { |
40 | opts = u.options(opts) |
41 | //mutates opts |
42 | ltgt.toLtgt(opts, opts, function (value) { |
43 | return [opts.id, value] |
44 | }, u.lo, u.hi) |
45 | var keys = opts.keys, values = opts.values |
46 | opts.keys = false |
47 | opts.values = true |
48 | |
49 | return pull( |
50 | index.read(opts), |
51 | db.lookup(keys, values) |
52 | ) |
53 | } |
54 | |
55 | return index |
56 | |
57 | |
58 | } |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 |
Built with git-ssb-web