/**
* MultiRepoOverlayProtocolV2 — sidecar override of upstream
* `OverlayProtocolV2._resolveFilePath`.
*
* Upstream's resolver checks `_filePaths` cache, then falls back to
* joining `_syncBaseDirs` with the overlay path. The sidecar has many
* working-tree roots (one per repo), so we override to translate
* `<reponame>/<relPath>` keys via `OverlayManager.getDiskPathSync` —
* a synchronous lookup over the in-memory repoRoot cache (warmed at
* startup by `OverlayManager.warmRepoCache()`).
*
* Cold-cache misses fall through to the upstream resolver and return
* undefined — the protocol then skips that offer/request, which is
* fine: the sidecar will pick it up on the next attempt once the cache
* is warm or the repo is registered.
*
* No other behavior is changed; the sync engine, transfer manager,
* channel lifecycle, and message handlers all come from upstream.
*/
import { OverlayProtocol } from 'hyper-overlay/protocol'
export class MultiRepoOverlayProtocolV2 extends OverlayProtocol {
constructor (syncEngine, transferManager, overlayManager, opts = {}) {
super(syncEngine, transferManager, opts)
this._overlayManager = overlayManager
}
_resolveFilePath (overlayPath) {
if (this._filePaths.has(overlayPath)) return this._filePaths.get(overlayPath)
const root = this._overlayManager.getDiskPathSync(overlayPath)
if (root) {
this._filePaths.set(overlayPath, root)
return root
}
return super._resolveFilePath(overlayPath)
}
}