Complete module API expansion: clearAll and batch helpers on every remaining module.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 03:48:27 -04:00
co-authored by Cursor
parent ff129d56b0
commit d1e8608280
22 changed files with 152 additions and 6 deletions
@@ -413,6 +413,17 @@ class HyperP2PCausalConsensus extends EventEmitter {
return n return n
} }
clearAll () {
const decided = this.clearDecided()
const proposals = this.proposals.size
this.proposals.clear()
this.forksDetected.clear()
this.vectorClock.clear()
for (const timer of this._proposalTimers.values()) clearTimeout(timer)
this._proposalTimers.clear()
return { proposals, decided }
}
getMetrics () { getMetrics () {
return { ...this._metrics, peers: this.peers.size, pendingProposals: this.proposals.size - this.decidedOrders.size } return { ...this._metrics, peers: this.peers.size, pendingProposals: this.proposals.size - this.decidedOrders.size }
} }
@@ -358,6 +358,14 @@ class HyperP2PDistributedLock extends EventEmitter {
return ids.length return ids.length
} }
async clearAll () {
const released = await this.releaseAllOwned()
const locks = this.locks.size
this.locks.clear()
this.myLocks.clear()
return { released, locks }
}
/** /**
* List all currently active locks (local + remote). * List all currently active locks (local + remote).
* Supports optional filter by owner or resource prefix. * Supports optional filter by owner or resource prefix.
@@ -249,6 +249,20 @@ class SpatialIndex extends EventEmitter {
return n return n
} }
async clearAll () {
const local = this.clearLocal()
return { local }
}
async insertBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
const out = []
for (const e of entries) {
out.push(await this.insert(e.id, e.x, e.y, e.data || {}))
}
return out
}
hasPoint (id) { hasPoint (id) {
return this.localPoints.has(String(id)) return this.localPoints.has(String(id))
} }
@@ -105,6 +105,10 @@ class HyperP2PPercentileSketch extends EventEmitter {
return true return true
} }
clearAll () {
return this.reset()
}
summarize () { summarize () {
this._sort() this._sort()
if (!this._sorted.length) return null if (!this._sorted.length) return null
@@ -124,6 +124,15 @@ class HyperP2PSlaBudget extends EventEmitter {
return true return true
} }
clearAll () {
return this.reset()
}
consumeBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.consume(e.service, e.n ?? 1))
}
serviceCount () { serviceCount () {
return this._services.size return this._services.size
} }
@@ -47,6 +47,10 @@ class HyperP2PStreamChunker extends EventEmitter {
return this return this
} }
clearAll () {
return this.reset()
}
flush () { flush () {
if (!this._pending.length) return null if (!this._pending.length) return null
const tail = this._pending const tail = this._pending
@@ -112,6 +112,15 @@ class HyperP2PStreamResumeToken extends EventEmitter {
return this return this
} }
clearAll () {
return this.reset()
}
writeBatch (chunks) {
if (!Array.isArray(chunks)) throw new Error('chunks array required')
return chunks.map((c) => this.write(c))
}
getStats () { getStats () {
return { return {
...this._stats, ...this._stats,
@@ -82,6 +82,10 @@ class HyperP2PStreamTransform extends EventEmitter {
return n return n
} }
clearAll () {
return this.clearPending()
}
writeBatch (chunks) { writeBatch (chunks) {
if (!Array.isArray(chunks)) throw new Error('chunks must be an array') if (!Array.isArray(chunks)) throw new Error('chunks must be an array')
let ok = 0 let ok = 0
@@ -98,6 +98,15 @@ class HyperP2PCircuitLoom extends EventEmitter {
return n return n
} }
clearAll () {
return this.teardownAll()
}
buildCircuitBatch (specs) {
if (!Array.isArray(specs)) throw new Error('specs array required')
return specs.map((s) => this.buildCircuit(s.hopPeers))
}
circuitCount () { circuitCount () {
return this._circuits.size return this._circuits.size
} }
@@ -64,6 +64,11 @@ class HyperP2PUdxMetrics extends EventEmitter {
this._recvWindow = [] this._recvWindow = []
} }
clearAll () {
this.resetTotals()
return true
}
setWindowMs (ms) { setWindowMs (ms) {
if (ms < 100) throw new Error('windowMs must be >= 100') if (ms < 100) throw new Error('windowMs must be >= 100')
this.windowMs = ms | 0 this.windowMs = ms | 0
@@ -101,6 +101,11 @@ class HyperBareArgvBridge extends EventEmitter {
return this.setArgv(argv) return this.setArgv(argv)
} }
clearAll () {
this.clearFlags()
return this.resetArgv([])
}
getStats () { getStats () {
return platformStats(this._stats, PROTOCOL, { return platformStats(this._stats, PROTOCOL, {
flags: this._flags.size, flags: this._flags.size,
@@ -87,6 +87,11 @@ class HyperBareHeadlessUi extends EventEmitter {
this.emit('teardown') this.emit('teardown')
} }
clearAll () {
this.teardown()
return true
}
pipeChannels () { pipeChannels () {
return this._pipe ? [...this._pipe.channels] : [] return this._pipe ? [...this._pipe.channels] : []
} }
@@ -106,6 +106,18 @@ class HyperBareProcessSpawn extends EventEmitter {
return n return n
} }
clearAll () {
this.killAll()
const n = this._children.size
this._children.clear()
return n
}
spawnPlanBatch (plans) {
if (!Array.isArray(plans)) throw new Error('plans array required')
return plans.map((plan) => this.spawnPlan(plan))
}
waitFor (id, timeoutMs = 0) { waitFor (id, timeoutMs = 0) {
const c = this.getChild(id) const c = this.getChild(id)
if (!c) return Promise.resolve(null) if (!c) return Promise.resolve(null)
@@ -98,6 +98,10 @@ class HyperBareTargetMatrix extends EventEmitter {
return this.list() return this.list()
} }
clearAll () {
return this.resetToDefaults()
}
targetCount () { targetCount () {
return this._targets.length return this._targets.length
} }
@@ -83,6 +83,12 @@ class HyperPearApplinkConfig extends EventEmitter {
return this.load(pkg) return this.load(pkg)
} }
clearAll () {
const had = this._config != null
this._config = null
return had
}
isLoaded () { isLoaded () {
return this._config != null return this._config != null
} }
+4 -6
View File
@@ -36,6 +36,10 @@ class HyperPearTrustGate extends EventEmitter {
return n return n
} }
clearAll () {
return this.untrustAll()
}
check (key, autoTrust = false) { check (key, autoTrust = false) {
const k = String(key) const k = String(key)
this._stats.checks++ this._stats.checks++
@@ -88,12 +92,6 @@ class HyperPearTrustGate extends EventEmitter {
return this._trusted.size return this._trusted.size
} }
untrustAll () {
const n = this._trusted.size
this._trusted.clear()
return n
}
checkBatch (keys, autoTrust = false) { checkBatch (keys, autoTrust = false) {
if (!Array.isArray(keys)) throw new Error('keys must be an array') if (!Array.isArray(keys)) throw new Error('keys must be an array')
return keys.map((k) => this.check(k, autoTrust)) return keys.map((k) => this.check(k, autoTrust))
@@ -88,6 +88,13 @@ class HyperPearUpdateGossip extends EventEmitter {
return n return n
} }
clearAll () {
const subs = this.unsubscribeAll()
const history = this.clearHistory()
this._latest = null
return { subs, history }
}
_notify (update) { _notify (update) {
for (const fn of this._subs) { for (const fn of this._subs) {
try { fn(update) } catch (_) { /* ignore */ } try { fn(update) } catch (_) { /* ignore */ }
@@ -105,6 +105,10 @@ class HyperP2PPatternRouter extends EventEmitter {
return n return n
} }
clearAll () {
return this.clearRoutes()
}
async ready () { async ready () {
if (this.swarm || !this.topic) return this if (this.swarm || !this.topic) return this
await initModuleSwarm(this, { await initModuleSwarm(this, {
@@ -70,6 +70,10 @@ class HyperP2PPeerScheduler extends EventEmitter {
return ids.length return ids.length
} }
clearAll () {
return this.cancelAll()
}
jobIds () { jobIds () {
return [...this._jobs.keys()] return [...this._jobs.keys()]
} }
@@ -101,6 +101,10 @@ class HyperP2PBeeBatchWrite extends EventEmitter {
return this.rollbackBatch() return this.rollbackBatch()
} }
clearAll () {
return this.clearPending()
}
bufferPutMany (entries) { bufferPutMany (entries) {
if (!Array.isArray(entries)) throw new Error('entries must be an array') if (!Array.isArray(entries)) throw new Error('entries must be an array')
let n = 0 let n = 0
@@ -133,6 +133,15 @@ class HyperP2PCoreMerkleSync extends EventEmitter {
return n return n
} }
clearAll () {
return this.clearRanges()
}
applyRangeBatch (ranges) {
if (!Array.isArray(ranges)) throw new Error('ranges array required')
return ranges.map((range) => this.applyRange(range))
}
_onGossip (d) { _onGossip (d) {
if (!d) return if (!d) return
if (d.type === 'merkle-ranges' && Array.isArray(d.ranges)) { if (d.type === 'merkle-ranges' && Array.isArray(d.ranges)) {
@@ -95,6 +95,17 @@ class HyperP2PBlindPairHandoff extends EventEmitter {
return n return n
} }
clearAll () {
const n = this._handoffs.size
this._handoffs.clear()
return n
}
offerHandoffBatch (entries) {
if (!Array.isArray(entries)) throw new Error('entries array required')
return entries.map((e) => this.offerHandoff(e.sessionId, e.targetPeer))
}
sessionIds () { sessionIds () {
return [...this._handoffs.keys()] return [...this._handoffs.keys()]
} }