Skip to content

Commit

Permalink
feat: expose unixfs progress events in types (#14)
Browse files Browse the repository at this point in the history
Expands types to include unixfs progress events as well as bitswap
and blockstore events.
  • Loading branch information
achingbrain committed Mar 17, 2023
1 parent 972f971 commit 36cf3b2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"go-ipfs": "^0.18.1",
"helia": "next",
"ipfs-core-types": "^0.14.0",
"ipfs-unixfs-importer": "^15.0.1",
"ipfs-unixfs-importer": "^15.1.0",
"ipfsd-ctl": "^13.0.0",
"it-to-buffer": "^3.0.1",
"kubo-rpc-client": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/unixfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@
"hamt-sharding": "^3.0.2",
"interface-blockstore": "^5.0.0",
"ipfs-unixfs": "^11.0.0",
"ipfs-unixfs-exporter": "^13.0.1",
"ipfs-unixfs-importer": "^15.0.1",
"ipfs-unixfs-exporter": "^13.1.0",
"ipfs-unixfs-importer": "^15.1.0",
"it-last": "^2.0.0",
"it-pipe": "^2.0.5",
"merge-options": "^3.0.4",
Expand Down
5 changes: 1 addition & 4 deletions packages/unixfs/src/commands/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ export async function * cat (cid: CID, blockstore: Blocks, options: Partial<CatO
throw new NoContentError()
}

yield * result.content({
offset: opts.offset,
length: opts.length
})
yield * result.content(opts)
}
1 change: 1 addition & 0 deletions packages/unixfs/src/commands/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export async function touch (cid: CID, blockstore: Blocks, options: Partial<Touc
}
}
},
// @ts-expect-error blockstore types are incompatible
(source) => importer(source, blockstore, {
...opts,
dagBuilder: async function * (source, block) {
Expand Down
29 changes: 16 additions & 13 deletions packages/unixfs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,29 @@ import { rm } from './commands/rm.js'
import { stat } from './commands/stat.js'
import { touch } from './commands/touch.js'
import { chmod } from './commands/chmod.js'
import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
import type { ExporterProgressEvents, UnixFSEntry } from 'ipfs-unixfs-exporter'
import { ls } from './commands/ls.js'
import type { ByteStream, DirectoryCandidate, FileCandidate, ImportCandidateStream, ImporterOptions, ImportProgressEvents, ImportResult } from 'ipfs-unixfs-importer'
import type { ByteStream, DirectoryCandidate, FileCandidate, ImportCandidateStream, ImporterOptions, ImporterProgressEvents, ImportResult } from 'ipfs-unixfs-importer'
import type { ProgressOptions } from 'progress-events'

export interface UnixFSComponents {
blockstore: Blocks
}

export type AddEvents = PutBlockProgressEvents
| ImportProgressEvents
| ImporterProgressEvents

export interface AddOptions extends AbortOptions, Omit<ImporterOptions, 'onProgress'>, ProgressOptions<AddEvents> {

}

export type GetEvents = GetBlockProgressEvents
| ExporterProgressEvents

/**
* Options to pass to the cat command
*/
export interface CatOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
export interface CatOptions extends AbortOptions, ProgressOptions<GetEvents> {
/**
* Start reading the file at this offset
*/
Expand All @@ -82,7 +85,7 @@ export interface CatOptions extends AbortOptions, ProgressOptions<GetBlockProgre
/**
* Options to pass to the chmod command
*/
export interface ChmodOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
export interface ChmodOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
/**
* If the target of the operation is a directory and this is true,
* apply the new mode to all directory contents
Expand All @@ -104,7 +107,7 @@ export interface ChmodOptions extends AbortOptions, ProgressOptions<GetBlockProg
/**
* Options to pass to the cp command
*/
export interface CpOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
export interface CpOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
/**
* If true, allow overwriting existing directory entries (default: false)
*/
Expand All @@ -120,7 +123,7 @@ export interface CpOptions extends AbortOptions, ProgressOptions<GetBlockProgres
/**
* Options to pass to the ls command
*/
export interface LsOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
export interface LsOptions extends AbortOptions, ProgressOptions<GetEvents> {
/**
* Optional path to list subdirectory contents if the target CID resolves to
* a directory
Expand All @@ -141,7 +144,7 @@ export interface LsOptions extends AbortOptions, ProgressOptions<GetBlockProgres
/**
* Options to pass to the mkdir command
*/
export interface MkdirOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
export interface MkdirOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
/**
* The CID version to create the new directory with - defaults to the same
* version as the containing directory
Expand Down Expand Up @@ -173,7 +176,7 @@ export interface MkdirOptions extends AbortOptions, ProgressOptions<GetBlockProg
/**
* Options to pass to the rm command
*/
export interface RmOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
export interface RmOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
/**
* DAGs with a root block larger than this value will be sharded. Blocks
* smaller than this value will be regular UnixFS directories.
Expand All @@ -184,7 +187,7 @@ export interface RmOptions extends AbortOptions, ProgressOptions<GetBlockProgres
/**
* Options to pass to the stat command
*/
export interface StatOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
export interface StatOptions extends AbortOptions, ProgressOptions<GetEvents> {
/**
* An optional path to allow statting paths inside directories
*/
Expand Down Expand Up @@ -251,7 +254,7 @@ export interface UnixFSStats {
/**
* Options to pass to the touch command
*/
export interface TouchOptions extends AbortOptions {
export interface TouchOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
/**
* Optional mtime to set on the DAG root, defaults to the current time
*/
Expand Down Expand Up @@ -376,7 +379,7 @@ export interface UnixFS {
* }
* ```
*/
cat: (cid: CID, options?: Partial<CatOptions> & ProgressOptions<GetBlockProgressEvents>) => AsyncIterable<Uint8Array>
cat: (cid: CID, options?: Partial<CatOptions>) => AsyncIterable<Uint8Array>

/**
* Change the permissions on a file or directory in a DAG
Expand Down Expand Up @@ -423,7 +426,7 @@ export interface UnixFS {
* }
* ```
*/
ls: (cid: CID, options?: Partial<LsOptions> & ProgressOptions<GetBlockProgressEvents>) => AsyncIterable<UnixFSEntry>
ls: (cid: CID, options?: Partial<LsOptions>) => AsyncIterable<UnixFSEntry>

/**
* Make a new directory under an existing directory.
Expand Down

0 comments on commit 36cf3b2

Please sign in to comment.