UNPKG

linkdex

Version:

An index mapping block CID to linked block CID.

107 lines 3.94 kB
/** * @typedef { 'Complete' | 'Partial' | 'Unknown' } DagStructure * @typedef {import('multiformats').UnknownLink} UnknownLink */ /** * @typedef {Object} Report * @property {DagStructure} structure - Are there any Linked CIDs that are not present in the set of blocks * @property {number} blocksIndexed - How many blocks were indexed * @property {number} uniqueCids - How many unique CIDs * @property {number} undecodeable - How many blocks/CIDs failed to decode */ /** * @param {AsyncIterable<Uint8Array>} carStream */ export function decodedBlocks(carStream: AsyncIterable<Uint8Array>): AsyncGenerator<import("multiformats").BlockView<any, any, number, import("multiformats").Version>, void, unknown>; /** * @param {AsyncIterable<Uint8Array>} carStream */ export function linkdex(carStream: AsyncIterable<Uint8Array>): AsyncGenerator<{ src: string; dest: string; } | { src: string; dest?: undefined; }, void, unknown>; /** * A util to record all the links from a given set of Blocks. * Pass blocks to `decodeAndIndex` as you iterate over a CAR. * Then call `getDagStructureLabel` to find out if the dag is * complete... if all linked to CIDs are also contained in in * the set, then it is complete. */ export class LinkIndexer { /** * Map block CID to the set of CIDs it links to * @type {Map<UnknownLink, Set<UnknownLink>>} */ idx: Map<UnknownLink, Set<UnknownLink>>; blocksIndexed: number; undecodable: number; /** * Decode the block and index any CIDs it links to * @param {import('@ipld/car/api').Block} block * @param {object} [opts] * @param {import('./decode.js').BlockDecoders} [opts.codecs] - bring your own codecs */ decodeAndIndex({ cid, bytes }: import('@ipld/car/api').Block, opts?: { codecs?: import("./decode.js").BlockDecoders | undefined; } | undefined): void; /** * Decode and index identity CID but don't count it as a block. * Where a link is an identity cid, The bytes are in the CID! * We consider a CAR complete even if an identity CID appears only as a link, not a block entry. * To make that work we index it, but don't count it as a block. * @param {import('multiformats/cid').CID} cid * @param {object} [opts] * @param {import('./decode.js').BlockDecoders} [opts.codecs] - bring your own codecs */ _decodeAndIndexIdentityCidLink(cid: import('multiformats/cid').CID, opts?: { codecs?: import("./decode.js").BlockDecoders | undefined; } | undefined): void; /** * Index all the links from the block * @template T * @template {number} C * @template {number} A * @template {import('multiformats').Version} V * @param {import('multiformats/block/interface').BlockView<T, C, A, V>} block */ _index<T, C extends number, A extends number, V extends import("multiformats").Version>(block: import("multiformats").BlockView<T, C, A, V>): void; /** * Find out if any of the links point to a CID that isn't in the CAR * @returns {boolean} */ isCompleteDag(): boolean; /** * Provide a value for the `structure` metadata for the CAR. * @returns {DagStructure} */ getDagStructureLabel(): DagStructure; /** * Get the results after all blocks are indexed. * @returns {Report} */ report(): Report; } export type DagStructure = 'Complete' | 'Partial' | 'Unknown'; export type UnknownLink = import('multiformats').UnknownLink; export type Report = { /** * - Are there any Linked CIDs that are not present in the set of blocks */ structure: DagStructure; /** * - How many blocks were indexed */ blocksIndexed: number; /** * - How many unique CIDs */ uniqueCids: number; /** * - How many blocks/CIDs failed to decode */ undecodeable: number; }; //# sourceMappingURL=index.d.ts.map