diff --git a/packages/ipfs-unixfs-exporter/src/types.d.ts b/packages/ipfs-unixfs-exporter/src/types.d.ts deleted file mode 100644 index ea7e7131..00000000 --- a/packages/ipfs-unixfs-exporter/src/types.d.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { CID } from 'multiformats/cid' -import { UnixFS } from 'ipfs-unixfs' -import { PBNode } from '@ipld/dag-pb' -import { Blockstore } from 'interface-blockstore' - -interface ExporterOptions { - offset?: number - length?: number - signal?: AbortSignal - timeout?: number -} - -interface Exportable { - type: 'file' | 'directory' | 'object' | 'raw' | 'identity' - name: string - path: string - cid: CID - depth: number - size: number - content: (options?: ExporterOptions) => AsyncIterable -} - -interface UnixFSFile extends Exportable { - type: 'file' - unixfs: UnixFS - node: PBNode -} - -interface UnixFSDirectory extends Exportable { - type: 'directory' - unixfs: UnixFS - node: PBNode -} - -interface ObjectNode extends Exportable { - type: 'object' - node: Uint8Array -} - -interface RawNode extends Exportable { - type: 'raw' - node: Uint8Array -} - -interface IdentityNode extends Exportable { - type: 'identity' - node: Uint8Array -} - -type UnixFSEntry = UnixFSFile | UnixFSDirectory | ObjectNode | RawNode | IdentityNode - -interface NextResult { - cid: CID - name: string - path: string - toResolve: string[] -} - -interface ResolveResult { - entry: UnixFSEntry - next?: NextResult -} - -interface Resolve { (cid: CID, name: string, path: string, toResolve: string[], depth: number, blockstore: Blockstore, options: ExporterOptions): Promise } -interface Resolver { (cid: CID, name: string, path: string, toResolve: string[], resolve: Resolve, depth: number, blockstore: Blockstore, options: ExporterOptions): Promise } - -type UnixfsV1FileContent = AsyncIterable | Iterable -type UnixfsV1DirectoryContent = AsyncIterable | Iterable -type UnixfsV1Content = UnixfsV1FileContent | UnixfsV1DirectoryContent -interface UnixfsV1Resolver { (cid: CID, node: PBNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, blockstore: Blockstore): (options: ExporterOptions) => UnixfsV1Content } diff --git a/packages/ipfs-unixfs-exporter/src/types.ts b/packages/ipfs-unixfs-exporter/src/types.ts new file mode 100644 index 00000000..5675ccd5 --- /dev/null +++ b/packages/ipfs-unixfs-exporter/src/types.ts @@ -0,0 +1,70 @@ +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' + +export interface ExporterOptions { + offset?: number + length?: number + signal?: AbortSignal + timeout?: number +} + +export interface Exportable { + type: 'file' | 'directory' | 'object' | 'raw' | 'identity' + name: string + path: string + cid: CID + depth: number + size: number + content: (options?: ExporterOptions) => AsyncIterable +} + +export interface UnixFSFile extends Exportable { + type: 'file' + unixfs: UnixFS + node: PBNode +} + +export interface UnixFSDirectory extends Exportable { + type: 'directory' + unixfs: UnixFS + node: PBNode +} + +export interface ObjectNode extends Exportable { + type: 'object' + node: Uint8Array +} + +export interface RawNode extends Exportable { + type: 'raw' + node: Uint8Array +} + +export interface IdentityNode extends Exportable { + type: 'identity' + node: Uint8Array +} + +export type UnixFSEntry = UnixFSFile | UnixFSDirectory | ObjectNode | RawNode | IdentityNode + +export interface NextResult { + cid: CID + name: string + path: string + toResolve: string[] +} + +export interface ResolveResult { + entry: UnixFSEntry + next?: NextResult +} + +export interface Resolve { (cid: CID, name: string, path: string, toResolve: string[], depth: number, blockstore: Blockstore, options: ExporterOptions): Promise } +export interface Resolver { (cid: CID, name: string, path: string, toResolve: string[], resolve: Resolve, depth: number, blockstore: Blockstore, options: ExporterOptions): Promise } + +export type UnixfsV1FileContent = AsyncIterable | Iterable +export type UnixfsV1DirectoryContent = AsyncIterable | 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 } diff --git a/packages/ipfs-unixfs-importer/src/types.d.ts b/packages/ipfs-unixfs-importer/src/types.ts similarity index 56% rename from packages/ipfs-unixfs-importer/src/types.d.ts rename to packages/ipfs-unixfs-importer/src/types.ts index 61753744..9474a238 100644 --- a/packages/ipfs-unixfs-importer/src/types.d.ts +++ b/packages/ipfs-unixfs-importer/src/types.ts @@ -1,54 +1,54 @@ -import { UnixFS, Mtime } from 'ipfs-unixfs' -import { CID, CIDVersion } from 'multiformats/cid' -import { MultihashHasher } from 'multiformats/hashes/interface' -import { BlockCodec } from 'multiformats/codecs/interface' -import { Blockstore } from 'interface-blockstore' +import type { UnixFS, Mtime } from 'ipfs-unixfs' +import type { CID, CIDVersion } from 'multiformats/cid' +import type { MultihashHasher } from 'multiformats/hashes/interface' +import type { BlockCodec } from 'multiformats/codecs/interface' +import type { Blockstore } from 'interface-blockstore' -interface ImportCandidate { +export interface ImportCandidate { path?: string content?: AsyncIterable | Iterable | Uint8Array mtime?: Mtime mode?: number } -interface File { +export interface File { content: AsyncIterable path?: string mtime?: Mtime mode?: number } -interface Directory { +export interface Directory { path?: string mtime?: Mtime mode?: number } -interface ImportResult { +export interface ImportResult { cid: CID size: number path?: string unixfs?: UnixFS } -interface InProgressImportResult extends ImportResult { +export interface InProgressImportResult extends ImportResult { single?: boolean } -type ChunkerType = 'fixed' | 'rabin' -interface ProgressHandler { (chunkSize: number, path?: string): void } -interface HamtHashFn { (value: Uint8Array): Promise } -interface Chunker { (source: AsyncIterable, options: ImporterOptions): AsyncIterable } -interface DAGBuilder { (source: AsyncIterable | Iterable, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise> } -interface TreeBuilder { (source: AsyncIterable, blockstore: Blockstore, options: ImporterOptions): AsyncIterable } -interface BufferImporter { (file: File, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise> } -interface ChunkValidator { (source: AsyncIterable, options: ImporterOptions): AsyncIterable } -interface UnixFSV1DagBuilder { (item: T, blockstore: Blockstore, options: ImporterOptions): Promise } -interface Reducer { (leaves: InProgressImportResult[]): Promise } +export type ChunkerType = 'fixed' | 'rabin' +export interface ProgressHandler { (chunkSize: number, path?: string): void } +export interface HamtHashFn { (value: Uint8Array): Promise } +export interface Chunker { (source: AsyncIterable, options: ImporterOptions): AsyncIterable } +export interface DAGBuilder { (source: AsyncIterable | Iterable, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise> } +export interface TreeBuilder { (source: AsyncIterable, blockstore: Blockstore, options: ImporterOptions): AsyncIterable } +export interface BufferImporter { (file: File, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise> } +export interface ChunkValidator { (source: AsyncIterable, options: ImporterOptions): AsyncIterable } +export interface UnixFSV1DagBuilder { (item: T, blockstore: Blockstore, options: ImporterOptions): Promise } +export interface Reducer { (leaves: InProgressImportResult[]): Promise } -interface FileDAGBuilder { (source: AsyncIterable | Iterable, reducer: Reducer, options: ImporterOptions): Promise } +export interface FileDAGBuilder { (source: AsyncIterable | Iterable, reducer: Reducer, options: ImporterOptions): Promise } -interface UserImporterOptions { +export interface UserImporterOptions { strategy?: 'balanced' | 'flat' | 'trickle' rawLeaves?: boolean onlyHash?: boolean @@ -81,7 +81,7 @@ interface UserImporterOptions { chunkValidator?: ChunkValidator } -interface ImporterOptions { +export interface ImporterOptions { strategy: 'balanced' | 'flat' | 'trickle' rawLeaves: boolean onlyHash: boolean diff --git a/packages/ipfs-unixfs/src/types.d.ts b/packages/ipfs-unixfs/src/types.ts similarity index 100% rename from packages/ipfs-unixfs/src/types.d.ts rename to packages/ipfs-unixfs/src/types.ts