import { type WaitForPeer } from "@peerbit/stream-interface"; import { type Block } from "multiformats/block"; export type GetOptions = { remote?: | { signal?: AbortSignal; timeout?: number; replicate?: boolean; from?: string[]; priority?: number; } | boolean; }; export type PutOptions = { timeout?: number; }; type MaybePromise = Promise | T; export interface Blocks extends WaitForPeer { put( data: Uint8Array | { block: Block; cid: string }, ): MaybePromise; putMany?( data: Array; cid: string }>, ): MaybePromise; /** * Store raw block bytes when the caller has already computed and verified * the matching CID. Implementations must not recalculate the CID on this path. */ putKnown?(cid: string, bytes: Uint8Array): MaybePromise; putKnownMany?( blocks: Array, ): MaybePromise; has(cid: string): MaybePromise; /** * Return local-storage presence flags aligned with the input CIDs. * * This must not perform remote reads; callers use it to replace repeated * `has(...)` probes without changing block-fetch semantics. */ hasMany?(cids: string[]): MaybePromise; get(cid: string, options?: GetOptions): MaybePromise; getMany?( cids: string[], options?: GetOptions, ): MaybePromise>; /** * Best-effort provider hints for `get(..., { remote: true })` without explicit `remote.from`. * * Implementations should treat hints as advisory and keep them bounded (LRU/TTL). */ hintProviders?(cid: string, providers: string[]): void; rm(cid: string): MaybePromise; iterator(): AsyncGenerator<[string, Uint8Array], void, void>; size(): MaybePromise; persisted(): MaybePromise; } export { cidifyString, stringifyCid, createBlock, getBlockValue, calculateRawCid, checkDecodeBlock, verifyBlockBytes, codecCodes, defaultHasher, codecMap, } from "./block.js"; export type { VerifyBlockBytesOptions } from "./block.js";