git ssb

1+

Dominic / secure-scuttlebutt



Tree: 9a7e43ac498a13a9720df2ba9fdd94eafe23d04d

Files: 9a7e43ac498a13a9720df2ba9fdd94eafe23d04d / indexes / clock.js

1671 bytesRaw
1var ref = require('ssb-ref')
2var path = require('path')
3var pull = require('pull-stream')
4var ltgt = require('ltgt')
5//53 bit integer
6var MAX_INT = 0x1fffffffffffff
7var u = require('../util')
8var Format = u.formatStream
9
10var ViewLevel = require('flumeview-level')
11
12module.exports = function (db, opts) {
13
14 var createIndex = ViewLevel(1, function (data) {
15 return [[data.value.author, data.value.sequence]]
16 })
17
18 return function (log, name) {
19
20 var index = createIndex(log, name)
21
22 index.methods.createHistoryStream = 'source'
23 index.methods.createUserStream = 'source'
24
25 index.createHistoryStream = function (opts) {
26 var opts = u.options(opts)
27 var id = opts.id
28 var seq = opts.sequence || opts.seq || 0
29 var limit = opts.limit
30 var keys = opts.keys
31 var values = opts.values
32 return pull(
33 index.read({
34 gte: [id, seq],
35 lte: [id, MAX_INT],
36 live: opts && opts.live,
37 old: opts && opts.old,
38 keys: false,
39 sync: false === (opts && opts.sync),
40 limit: limit
41 }),
42 pull.map(function (e) {
43 return keys && values ? e.value : keys ? e.value.key : e.value.value
44 })
45 )
46 }
47
48 index.createUserStream = function (opts) {
49 opts = u.options(opts)
50 //mutates opts
51 ltgt.toLtgt(opts, opts, function (value) {
52 return [opts.id, value]
53 }, u.lo, u.hi)
54 var keys = opts.keys !== false
55 var values = opts.values !== false
56 opts.keys = false
57 opts.values = true
58
59 return pull(index.read(opts), Format(keys, values))
60 }
61
62 return index
63
64 }
65}
66
67
68
69
70

Built with git-ssb-web