This commit is contained in:
Raven Scott
2026-05-21 02:00:00 -04:00
parent 8971182b3f
commit 3b75e74dbd
107 changed files with 1060 additions and 211 deletions
@@ -1,6 +1,7 @@
require('bare-process/global')
const EventEmitter = require('bare-events')
const { assertBee } = require('../../_shared/storage-gossip-base.js')
const { beeStats } = require('../../_shared/hyperbee-base.js')
const PROTOCOL = 'bee-diff-follow/v1'
class HyperP2PBeeDiffFollow extends EventEmitter {
@@ -66,6 +67,15 @@ class HyperP2PBeeDiffFollow extends EventEmitter {
return this._cursor
}
behindCount () {
return this._buffer.filter((e) => e.version > this._cursor).length
}
peekBuffered (n = 8) {
if (n < 0) throw new Error('n must be non-negative')
return this._buffer.slice(0, n).map((e) => ({ ...e }))
}
applyBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries must be an array')
let n = 0
@@ -91,12 +101,11 @@ class HyperP2PBeeDiffFollow extends EventEmitter {
}
getStats () {
return {
...this._stats,
return beeStats(this._stats, PROTOCOL, {
cursor: this._cursor,
buffered: this._buffer.length,
protocol: PROTOCOL
}
behind: this.behindCount()
})
}
async ready () { return this }
@@ -1,6 +1,6 @@
{
"name": "hyper-p2p-bee-diff-follow",
"version": "0.3.1",
"version": "0.3.2",
"description": "Diff stream follower.",
"main": "index.js",
"type": "commonjs",
@@ -36,6 +36,7 @@ test('recordDiff skips old', async (t) => {
test('getStats', async (t) => {
const m = new HyperP2PBeeDiffFollow()
t.is(m.getStats().protocol, 'bee-diff-follow/v1')
t.is(m.getStats().mode, 'hyperbee')
await m.close()
})