From c282ccc5b2fc4c8b61b530d00e441ca65f475b69 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 30 Aug 2022 21:34:15 +0100 Subject: [PATCH] fix: specify return type of the importer to generate correct types If we don't to this, we end up importing deep paths from `unixfs` in the generated types which aren't in the exports map so fail when people are compiling their dependencies. Fixes #214 --- packages/ipfs-unixfs-exporter/src/types.ts | 7 +++++++ .../ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js | 5 +---- packages/ipfs-unixfs-importer/src/index.js | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/src/types.ts b/packages/ipfs-unixfs-exporter/src/types.ts index 5675ccd5..e1210b4b 100644 --- a/packages/ipfs-unixfs-exporter/src/types.ts +++ b/packages/ipfs-unixfs-exporter/src/types.ts @@ -2,6 +2,7 @@ import type { CID } from 'multiformats/cid' import type { UnixFS } from 'ipfs-unixfs' import type { PBNode } from '@ipld/dag-pb' import type { Blockstore } from 'interface-blockstore' +import type { Bucket } from 'hamt-sharding' export interface ExporterOptions { offset?: number @@ -68,3 +69,9 @@ export type UnixfsV1FileContent = AsyncIterable | Iterable | Iterable export type UnixfsV1Content = UnixfsV1FileContent | UnixfsV1DirectoryContent export interface UnixfsV1Resolver { (cid: CID, node: PBNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, blockstore: Blockstore): (options: ExporterOptions) => UnixfsV1Content } + +export interface ShardTraversalContext { + hamtDepth: number + rootBucket: Bucket + lastBucket: Bucket +} diff --git a/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js b/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js index c3a38322..d089532d 100644 --- a/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js +++ b/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js @@ -81,10 +81,7 @@ const toBucketPath = (position) => { } /** - * @typedef {object} ShardTraversalContext - * @property {number} hamtDepth - * @property {Bucket} rootBucket - * @property {Bucket} lastBucket + * @typedef {import('../types').ShardTraversalContext} ShardTraversalContext * * @param {PBNode} node * @param {string} name diff --git a/packages/ipfs-unixfs-importer/src/index.js b/packages/ipfs-unixfs-importer/src/index.js index 522aefac..80044289 100644 --- a/packages/ipfs-unixfs-importer/src/index.js +++ b/packages/ipfs-unixfs-importer/src/index.js @@ -25,6 +25,7 @@ import treeBuilderFn from './tree-builder.js' * @param {AsyncIterable | Iterable | ImportCandidate} source * @param {Blockstore} blockstore * @param {UserImporterOptions} options + * @returns {AsyncGenerator} */ export async function * importer (source, blockstore, options = {}) { const opts = defaultOptions(options)