Files: 533b73eebb0583f344a236933331d527606ed657 / indexes / last.js
917 bytesRaw
1 | var Follower = require('../follower') |
2 | var pull = require('pull-stream') |
3 | var path = require('path') |
4 | var ltgt = require('ltgt') |
5 | var u = require('../util') |
6 | |
7 | function isNumber (n) { |
8 | return typeof n === 'number' |
9 | } |
10 | |
11 | function toSeq (latest) { |
12 | return isNumber(latest) ? latest : latest.sequence |
13 | } |
14 | |
15 | module.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