Skip to content

Commit 3343366

Browse files
authored
fix: specify return type of the importer to generate correct types (#251)
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
1 parent 47f3d5a commit 3343366

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Diff for: packages/ipfs-unixfs-exporter/src/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CID } from 'multiformats/cid'
22
import type { UnixFS } from 'ipfs-unixfs'
33
import type { PBNode } from '@ipld/dag-pb'
44
import type { Blockstore } from 'interface-blockstore'
5+
import type { Bucket } from 'hamt-sharding'
56

67
export interface ExporterOptions {
78
offset?: number
@@ -68,3 +69,9 @@ export type UnixfsV1FileContent = AsyncIterable<Uint8Array> | Iterable<Uint8Arra
6869
export type UnixfsV1DirectoryContent = AsyncIterable<UnixFSEntry> | Iterable<UnixFSEntry>
6970
export type UnixfsV1Content = UnixfsV1FileContent | UnixfsV1DirectoryContent
7071
export interface UnixfsV1Resolver { (cid: CID, node: PBNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, blockstore: Blockstore): (options: ExporterOptions) => UnixfsV1Content }
72+
73+
export interface ShardTraversalContext {
74+
hamtDepth: number
75+
rootBucket: Bucket<boolean>
76+
lastBucket: Bucket<boolean>
77+
}

Diff for: packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ const toBucketPath = (position) => {
8181
}
8282

8383
/**
84-
* @typedef {object} ShardTraversalContext
85-
* @property {number} hamtDepth
86-
* @property {Bucket<boolean>} rootBucket
87-
* @property {Bucket<boolean>} lastBucket
84+
* @typedef {import('../types').ShardTraversalContext} ShardTraversalContext
8885
*
8986
* @param {PBNode} node
9087
* @param {string} name

Diff for: packages/ipfs-unixfs-importer/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import treeBuilderFn from './tree-builder.js'
2525
* @param {AsyncIterable<ImportCandidate> | Iterable<ImportCandidate> | ImportCandidate} source
2626
* @param {Blockstore} blockstore
2727
* @param {UserImporterOptions} options
28+
* @returns {AsyncGenerator<ImportResult, void, unknown>}
2829
*/
2930
export async function * importer (source, blockstore, options = {}) {
3031
const opts = defaultOptions(options)

0 commit comments

Comments
 (0)