import type { AbortOptions } from "@libp2p/interface"; type AwaitIterable = Iterable | AsyncIterable; /** * The dependency tree has historically carried more than one copy of multiformats (helia 6's * internals were on 13 while our tree was on 14) and of interface-blockstore, making a CID handed * to us by helia a different class from a CID we construct, and the packages' `Blockstore`/`Pair` * types not mutually assignable. helia 7 unified the copies, but the wrapper keeps typing * structurally so a future skew can't break it: the only thing it ever needs from a CID is the * multihash bytes, and every backend we use (blockstore-core, blockstore-fs, blockstore-idb) * addresses blocks by exactly those bytes and ignores the codec. */ export interface BlockstoreCid { multihash: { bytes: Uint8Array; }; } export interface BlockstorePair { cid: BlockstoreCid; bytes: AwaitIterable; } export interface ChildBlockstore { has(cid: BlockstoreCid, options?: AbortOptions): boolean | Promise; put(cid: BlockstoreCid, val: Uint8Array | AwaitIterable, options?: AbortOptions): unknown; get(cid: BlockstoreCid, options?: AbortOptions): AwaitIterable; delete(cid: BlockstoreCid, options?: AbortOptions): void | Promise; getAll(options?: AbortOptions): AwaitIterable; } export interface LruBlockstoreOptions { maxBytes: number; lowWaterRatio?: number; } /** * A size-capped LRU cache in front of any blockstore. * * pkc-js pins nothing: every block we hold is refetchable from the network and we are not a * provider of record for any of it. So the eviction policy here is a plain cache policy rather * than helia's pin-based `gc()`, which with zero pins would simply delete everything. * * Recency is tracked by `_sizes` insertion order (a Map iterates in insertion order, so the front * is the least recently used). Reads and writes move a key to the back; `getAll` deliberately does * NOT, since a full scan would otherwise flatten the LRU ordering into scan order. * * Nothing protects a block that an in-flight DAG walk is midway through reading. Worst case an * eviction lands between two blocks of an active load and that load re-fetches the block, which is * latency rather than corruption. Do not "fix" this with pins. */ export declare class LruBlockstore { private readonly _child; private readonly _maxBytes; private readonly _lowWaterBytes; private readonly _sizes; private _totalBytes; private _evicting?; constructor(child: ChildBlockstore, options: LruBlockstoreOptions); get totalBytes(): number; get blockCount(): number; private _keyOf; private _touch; private _register; private _unregister; has(cid: BlockstoreCid, options?: AbortOptions): Promise; put(cid: BlockstoreCid, val: Uint8Array | AwaitIterable, options?: AbortOptions): Promise; get(cid: BlockstoreCid, options?: AbortOptions): AsyncGenerator, void, unknown>; delete(cid: BlockstoreCid, options?: AbortOptions): Promise; putMany(source: AwaitIterable<{ cid: BlockstoreCid; bytes: Uint8Array | AwaitIterable; }>, options?: AbortOptions): AsyncGenerator; getMany(source: AwaitIterable, options?: AbortOptions): AsyncGenerator<{ cid: BlockstoreCid; bytes: AsyncGenerator, void, unknown>; }, void, unknown>; deleteMany(source: AwaitIterable, options?: AbortOptions): AsyncGenerator; getAll(options?: AbortOptions): AsyncGenerator; private _evictIfNeeded; private _evict; /** * Populate the index from a child that already holds blocks (a persistent backend on a second * run). Sizes are only knowable by reading every block back, so this is O(store) in IO and is * meant to be kicked off in the background rather than awaited before the first load. Until it * finishes the store can sit over its cap, since we cannot evict what we have not counted. * * Resilient by design: blockstore-fs reconstructs a CID in `getAll` by decoding raw multihash * bytes, which throws for any hash that is not a valid CIDv0 (i.e. anything but sha2-256). * A store holding such a block would otherwise abort the whole scan, so a failure here leaves * a partial index rather than propagating. */ rebuildIndex(options?: AbortOptions): Promise<{ blocks: number; bytes: number; }>; } export {};