Skip to content

Commit 76ec6e5

Browse files
authored
fix: declare types in .ts files (#168)
`.d.ts` files are not type checked as they are usually machine generated. Switch to using `.ts` files instead so we get some compiler safety. Refs: ipfs/aegir#849
1 parent 2713329 commit 76ec6e5

File tree

4 files changed

+93
-93
lines changed

4 files changed

+93
-93
lines changed

packages/ipfs-unixfs-exporter/src/types.d.ts

-70
This file was deleted.
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import type { CID } from 'multiformats/cid'
2+
import type { UnixFS } from 'ipfs-unixfs'
3+
import type { PBNode } from '@ipld/dag-pb'
4+
import type { Blockstore } from 'interface-blockstore'
5+
6+
export interface ExporterOptions {
7+
offset?: number
8+
length?: number
9+
signal?: AbortSignal
10+
timeout?: number
11+
}
12+
13+
export interface Exportable<T> {
14+
type: 'file' | 'directory' | 'object' | 'raw' | 'identity'
15+
name: string
16+
path: string
17+
cid: CID
18+
depth: number
19+
size: number
20+
content: (options?: ExporterOptions) => AsyncIterable<T>
21+
}
22+
23+
export interface UnixFSFile extends Exportable<Uint8Array> {
24+
type: 'file'
25+
unixfs: UnixFS
26+
node: PBNode
27+
}
28+
29+
export interface UnixFSDirectory extends Exportable<UnixFSEntry> {
30+
type: 'directory'
31+
unixfs: UnixFS
32+
node: PBNode
33+
}
34+
35+
export interface ObjectNode extends Exportable<any> {
36+
type: 'object'
37+
node: Uint8Array
38+
}
39+
40+
export interface RawNode extends Exportable<Uint8Array> {
41+
type: 'raw'
42+
node: Uint8Array
43+
}
44+
45+
export interface IdentityNode extends Exportable<Uint8Array> {
46+
type: 'identity'
47+
node: Uint8Array
48+
}
49+
50+
export type UnixFSEntry = UnixFSFile | UnixFSDirectory | ObjectNode | RawNode | IdentityNode
51+
52+
export interface NextResult {
53+
cid: CID
54+
name: string
55+
path: string
56+
toResolve: string[]
57+
}
58+
59+
export interface ResolveResult {
60+
entry: UnixFSEntry
61+
next?: NextResult
62+
}
63+
64+
export interface Resolve { (cid: CID, name: string, path: string, toResolve: string[], depth: number, blockstore: Blockstore, options: ExporterOptions): Promise<ResolveResult> }
65+
export interface Resolver { (cid: CID, name: string, path: string, toResolve: string[], resolve: Resolve, depth: number, blockstore: Blockstore, options: ExporterOptions): Promise<ResolveResult> }
66+
67+
export type UnixfsV1FileContent = AsyncIterable<Uint8Array> | Iterable<Uint8Array>
68+
export type UnixfsV1DirectoryContent = AsyncIterable<UnixFSEntry> | Iterable<UnixFSEntry>
69+
export type UnixfsV1Content = UnixfsV1FileContent | UnixfsV1DirectoryContent
70+
export interface UnixfsV1Resolver { (cid: CID, node: PBNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, blockstore: Blockstore): (options: ExporterOptions) => UnixfsV1Content }

packages/ipfs-unixfs-importer/src/types.d.ts renamed to packages/ipfs-unixfs-importer/src/types.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
import { UnixFS, Mtime } from 'ipfs-unixfs'
2-
import { CID, CIDVersion } from 'multiformats/cid'
3-
import { MultihashHasher } from 'multiformats/hashes/interface'
4-
import { BlockCodec } from 'multiformats/codecs/interface'
5-
import { Blockstore } from 'interface-blockstore'
1+
import type { UnixFS, Mtime } from 'ipfs-unixfs'
2+
import type { CID, CIDVersion } from 'multiformats/cid'
3+
import type { MultihashHasher } from 'multiformats/hashes/interface'
4+
import type { BlockCodec } from 'multiformats/codecs/interface'
5+
import type { Blockstore } from 'interface-blockstore'
66

7-
interface ImportCandidate {
7+
export interface ImportCandidate {
88
path?: string
99
content?: AsyncIterable<Uint8Array> | Iterable<Uint8Array> | Uint8Array
1010
mtime?: Mtime
1111
mode?: number
1212
}
1313

14-
interface File {
14+
export interface File {
1515
content: AsyncIterable<Uint8Array>
1616
path?: string
1717
mtime?: Mtime
1818
mode?: number
1919
}
2020

21-
interface Directory {
21+
export interface Directory {
2222
path?: string
2323
mtime?: Mtime
2424
mode?: number
2525
}
2626

27-
interface ImportResult {
27+
export interface ImportResult {
2828
cid: CID
2929
size: number
3030
path?: string
3131
unixfs?: UnixFS
3232
}
3333

34-
interface InProgressImportResult extends ImportResult {
34+
export interface InProgressImportResult extends ImportResult {
3535
single?: boolean
3636
}
3737

38-
type ChunkerType = 'fixed' | 'rabin'
39-
interface ProgressHandler { (chunkSize: number, path?: string): void }
40-
interface HamtHashFn { (value: Uint8Array): Promise<Uint8Array> }
41-
interface Chunker { (source: AsyncIterable<Uint8Array>, options: ImporterOptions): AsyncIterable<Uint8Array> }
42-
interface DAGBuilder { (source: AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise<InProgressImportResult>> }
43-
interface TreeBuilder { (source: AsyncIterable<InProgressImportResult>, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<ImportResult> }
44-
interface BufferImporter { (file: File, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise<InProgressImportResult>> }
45-
interface ChunkValidator { (source: AsyncIterable<Uint8Array>, options: ImporterOptions): AsyncIterable<Uint8Array> }
46-
interface UnixFSV1DagBuilder<T> { (item: T, blockstore: Blockstore, options: ImporterOptions): Promise<InProgressImportResult> }
47-
interface Reducer { (leaves: InProgressImportResult[]): Promise<InProgressImportResult> }
38+
export type ChunkerType = 'fixed' | 'rabin'
39+
export interface ProgressHandler { (chunkSize: number, path?: string): void }
40+
export interface HamtHashFn { (value: Uint8Array): Promise<Uint8Array> }
41+
export interface Chunker { (source: AsyncIterable<Uint8Array>, options: ImporterOptions): AsyncIterable<Uint8Array> }
42+
export interface DAGBuilder { (source: AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise<InProgressImportResult>> }
43+
export interface TreeBuilder { (source: AsyncIterable<InProgressImportResult>, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<ImportResult> }
44+
export interface BufferImporter { (file: File, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise<InProgressImportResult>> }
45+
export interface ChunkValidator { (source: AsyncIterable<Uint8Array>, options: ImporterOptions): AsyncIterable<Uint8Array> }
46+
export interface UnixFSV1DagBuilder<T> { (item: T, blockstore: Blockstore, options: ImporterOptions): Promise<InProgressImportResult> }
47+
export interface Reducer { (leaves: InProgressImportResult[]): Promise<InProgressImportResult> }
4848

49-
interface FileDAGBuilder { (source: AsyncIterable<InProgressImportResult> | Iterable<InProgressImportResult>, reducer: Reducer, options: ImporterOptions): Promise<InProgressImportResult> }
49+
export interface FileDAGBuilder { (source: AsyncIterable<InProgressImportResult> | Iterable<InProgressImportResult>, reducer: Reducer, options: ImporterOptions): Promise<InProgressImportResult> }
5050

51-
interface UserImporterOptions {
51+
export interface UserImporterOptions {
5252
strategy?: 'balanced' | 'flat' | 'trickle'
5353
rawLeaves?: boolean
5454
onlyHash?: boolean
@@ -81,7 +81,7 @@ interface UserImporterOptions {
8181
chunkValidator?: ChunkValidator
8282
}
8383

84-
interface ImporterOptions {
84+
export interface ImporterOptions {
8585
strategy: 'balanced' | 'flat' | 'trickle'
8686
rawLeaves: boolean
8787
onlyHash: boolean

0 commit comments

Comments
 (0)