Skip to content

Commit

Permalink
fix: declare types in .ts files
Browse files Browse the repository at this point in the history
`.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
  • Loading branch information
achingbrain committed Aug 27, 2021
1 parent 2713329 commit 1ca90f4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 93 deletions.
70 changes: 0 additions & 70 deletions packages/ipfs-unixfs-exporter/src/types.d.ts

This file was deleted.

70 changes: 70 additions & 0 deletions packages/ipfs-unixfs-exporter/src/types.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
type: 'file' | 'directory' | 'object' | 'raw' | 'identity'
name: string
path: string
cid: CID
depth: number
size: number
content: (options?: ExporterOptions) => AsyncIterable<T>
}

export interface UnixFSFile extends Exportable<Uint8Array> {
type: 'file'
unixfs: UnixFS
node: PBNode
}

export interface UnixFSDirectory extends Exportable<UnixFSEntry> {
type: 'directory'
unixfs: UnixFS
node: PBNode
}

export interface ObjectNode extends Exportable<any> {
type: 'object'
node: Uint8Array
}

export interface RawNode extends Exportable<Uint8Array> {
type: 'raw'
node: Uint8Array
}

export interface IdentityNode extends Exportable<Uint8Array> {
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<ResolveResult> }
export interface Resolver { (cid: CID, name: string, path: string, toResolve: string[], resolve: Resolve, depth: number, blockstore: Blockstore, options: ExporterOptions): Promise<ResolveResult> }

export type UnixfsV1FileContent = AsyncIterable<Uint8Array> | Iterable<Uint8Array>
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 }
Original file line number Diff line number Diff line change
@@ -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<Uint8Array> | Iterable<Uint8Array> | Uint8Array
mtime?: Mtime
mode?: number
}

interface File {
export interface File {
content: AsyncIterable<Uint8Array>
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<Uint8Array> }
interface Chunker { (source: AsyncIterable<Uint8Array>, options: ImporterOptions): AsyncIterable<Uint8Array> }
interface DAGBuilder { (source: AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise<InProgressImportResult>> }
interface TreeBuilder { (source: AsyncIterable<InProgressImportResult>, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<ImportResult> }
interface BufferImporter { (file: File, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise<InProgressImportResult>> }
interface ChunkValidator { (source: AsyncIterable<Uint8Array>, options: ImporterOptions): AsyncIterable<Uint8Array> }
interface UnixFSV1DagBuilder<T> { (item: T, blockstore: Blockstore, options: ImporterOptions): Promise<InProgressImportResult> }
interface Reducer { (leaves: InProgressImportResult[]): Promise<InProgressImportResult> }
export type ChunkerType = 'fixed' | 'rabin'
export interface ProgressHandler { (chunkSize: number, path?: string): void }
export interface HamtHashFn { (value: Uint8Array): Promise<Uint8Array> }
export interface Chunker { (source: AsyncIterable<Uint8Array>, options: ImporterOptions): AsyncIterable<Uint8Array> }
export interface DAGBuilder { (source: AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise<InProgressImportResult>> }
export interface TreeBuilder { (source: AsyncIterable<InProgressImportResult>, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<ImportResult> }
export interface BufferImporter { (file: File, blockstore: Blockstore, options: ImporterOptions): AsyncIterable<() => Promise<InProgressImportResult>> }
export interface ChunkValidator { (source: AsyncIterable<Uint8Array>, options: ImporterOptions): AsyncIterable<Uint8Array> }
export interface UnixFSV1DagBuilder<T> { (item: T, blockstore: Blockstore, options: ImporterOptions): Promise<InProgressImportResult> }
export interface Reducer { (leaves: InProgressImportResult[]): Promise<InProgressImportResult> }

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

interface UserImporterOptions {
export interface UserImporterOptions {
strategy?: 'balanced' | 'flat' | 'trickle'
rawLeaves?: boolean
onlyHash?: boolean
Expand Down Expand Up @@ -81,7 +81,7 @@ interface UserImporterOptions {
chunkValidator?: ChunkValidator
}

interface ImporterOptions {
export interface ImporterOptions {
strategy: 'balanced' | 'flat' | 'trickle'
rawLeaves: boolean
onlyHash: boolean
Expand Down
File renamed without changes.

0 comments on commit 1ca90f4

Please sign in to comment.