Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: specify return type of the importer to generate correct types #251

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/ipfs-unixfs-exporter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,3 +69,9 @@ export type UnixfsV1FileContent = AsyncIterable<Uint8Array> | Iterable<Uint8Arra
export type UnixfsV1DirectoryContent = AsyncIterable<UnixFSEntry> | Iterable<UnixFSEntry>
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<boolean>
lastBucket: Bucket<boolean>
}
5 changes: 1 addition & 4 deletions packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ const toBucketPath = (position) => {
}

/**
* @typedef {object} ShardTraversalContext
* @property {number} hamtDepth
* @property {Bucket<boolean>} rootBucket
* @property {Bucket<boolean>} lastBucket
* @typedef {import('../types').ShardTraversalContext} ShardTraversalContext
*
* @param {PBNode} node
* @param {string} name
Expand Down
1 change: 1 addition & 0 deletions packages/ipfs-unixfs-importer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import treeBuilderFn from './tree-builder.js'
* @param {AsyncIterable<ImportCandidate> | Iterable<ImportCandidate> | ImportCandidate} source
* @param {Blockstore} blockstore
* @param {UserImporterOptions} options
* @returns {AsyncGenerator<ImportResult, void, unknown>}
*/
export async function * importer (source, blockstore, options = {}) {
const opts = defaultOptions(options)
Expand Down