git ssb

1+

Dominic / secure-scuttlebutt



Tree: 533b73eebb0583f344a236933331d527606ed657

Files: 533b73eebb0583f344a236933331d527606ed657 / indexes / last.js

917 bytesRaw
1var Follower = require('../follower')
2var pull = require('pull-stream')
3var path = require('path')
4var ltgt = require('ltgt')
5var u = require('../util')
6
7function isNumber (n) {
8 return typeof n === 'number'
9}
10
11function toSeq (latest) {
12 return isNumber(latest) ? latest : latest.sequence
13}
14
15module.exports = function (db) {
16 var indexPath = path.join(db.location, 'last')
17 var index = Follower(db, indexPath, 1, function (data) {
18 if(data.sync) return
19
20 return {
21 key: data.value.author, value: {sequence: data.value.sequence, ts: data.timestamp },
22 type: 'put'
23 }
24 })
25
26 index.latest = function (opts) {
27 opts = opts || {}
28 if(!(opts.gt || opts.gte))
29 opts.gt = '\x00'
30 return pull(
31 index.read(opts),
32 pull.map(function (data) {
33 var d = {id: data.key, sequence: toSeq(data.value), ts: data.value.ts }
34 return d
35 })
36 )
37 }
38
39 return index
40
41}
42
43
44

Built with git-ssb-web