mafintosh / hyperdb

Distributed scalable database
MIT License
753 stars 75 forks source link

Include original clock and feeds in history() elements etc #118

Open xloem opened 6 years ago

xloem commented 6 years ago

Writer._decode converts results taken from the database before being passed to the user. The vector clock entries are rearranged to match the local feed list. (It looks like the trie is altered as well although I'm not familiar with the trie yet)

It would be nice for the original, remote vector clock to be available in the result, in case the clock was used for anything (I'm using it to hash the feed tips together). For this to be useful, the remote feeds could be returned too (which I guess means passing them via _encodeMap).

Something like this perhaps:

diff --git a/index.js b/index.js
index bfd9c46..f84e084 100644
--- a/index.js
+++ b/index.js
@@ -748,6 +748,10 @@ Writer.prototype._decode = function (seq, buf, cb) {
   val.path = hash(val.key, true)
   val.value = val.value && this._db._valueEncoding.decode(val.value)

+  val.rawClock = val.clock
+  val.rawTrie = val.trie
+  val.rawFeeds = this._mapList(this._db.feeds, this._encodeMap, null)
+
   if (this._feedsMessage && this._feedsLoaded === val.inflate) {
     this._maybeUpdateFeeds()
     val.feed = this._id
mafintosh commented 6 years ago

Either that or we expose a method do denormalize. I'm fine either way :)