git ssb

1+

Dominic / secure-scuttlebutt



Commit 36227b9a6794632411dc1e0feb5c7617389106fd

add getAtSequence and getVectorClock

Dominic Tarr committed on 4/4/2017, 10:23:41 AM
Parent: 6960c89edc86ecb7f519c14ff1743fb4628fcee9

Files changed

index.jschanged
index.jsView
@@ -86,15 +86,19 @@
8686
8787 var _get = db.get
8888
8989 db.get = function (key, cb) {
90- if(ref.isMsg(key)) return db.keys.get(key, function (err, seq) {
91- if(err) cb(err)
92- else _get(seq, function (err, data) {
90 + if(ref.isMsg(key))
91 + return db.keys.get(key, function (err, seq) {
9392 if(err) cb(err)
94- else cb(err, data && data.value)
93 +// else if(Number.isInteger(seq)) _get(seq, function (err, data) {
94 +// if(err) cb(err)
95 +// else cb(err, data && data.value)
96 +// })
97 + else
98 + cb(err, seq && seq.value)
9599 })
96- })
100 +// else cb(null, seq)
97101 else _get(key, cb) //seq
98102 }
99103
100104 db.add = Validator(db, opts)
@@ -183,9 +187,9 @@
183187 return db.stream()
184188
185189 var keys = opts.keys; delete opts.keys
186190 var values = opts.values; delete opts.values
187- return pull(db.time.read(opts), /*pull.through(console.log), */Format(keys, values))
191 + return pull(db.time.read(opts), Format(keys, values))
188192 }
189193
190194 db.messagesByType = db.links.messagesByType
191195
@@ -196,7 +200,24 @@
196200 //get all messages that link to a given message.
197201
198202 db.relatedMessages = Related(db)
199203
204 + //called with [id, seq] or "<id>:<seq>"
205 + db.getAtSequence = function (seqid, cb) {
206 + db.clock.get(isString(seqid) ? seqid.split(':') : seqid, cb)
207 + }
208 +
209 + db.getVectorClock = function (_, cb) {
210 + if(!cb) cb = _
211 + db.last.get(function (err, h) {
212 + if(err) return cb(err)
213 + var clock = {}
214 + for(var k in h)
215 + clock[k] = h[k].sequence
216 + cb(null, clock)
217 + })
218 +
219 + }
220 +
200221 return db
201222 }
202223

Built with git-ssb-web