Skip to content

Commit 36cf3b2

Browse files
authored
feat: expose unixfs progress events in types (#14)
Expands types to include unixfs progress events as well as bitswap and blockstore events.
1 parent 972f971 commit 36cf3b2

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

packages/interop/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"go-ipfs": "^0.18.1",
6565
"helia": "next",
6666
"ipfs-core-types": "^0.14.0",
67-
"ipfs-unixfs-importer": "^15.0.1",
67+
"ipfs-unixfs-importer": "^15.1.0",
6868
"ipfsd-ctl": "^13.0.0",
6969
"it-to-buffer": "^3.0.1",
7070
"kubo-rpc-client": "^3.0.0",

packages/unixfs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@
147147
"hamt-sharding": "^3.0.2",
148148
"interface-blockstore": "^5.0.0",
149149
"ipfs-unixfs": "^11.0.0",
150-
"ipfs-unixfs-exporter": "^13.0.1",
151-
"ipfs-unixfs-importer": "^15.0.1",
150+
"ipfs-unixfs-exporter": "^13.1.0",
151+
"ipfs-unixfs-importer": "^15.1.0",
152152
"it-last": "^2.0.0",
153153
"it-pipe": "^2.0.5",
154154
"merge-options": "^3.0.4",

packages/unixfs/src/commands/cat.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,5 @@ export async function * cat (cid: CID, blockstore: Blocks, options: Partial<CatO
2525
throw new NoContentError()
2626
}
2727

28-
yield * result.content({
29-
offset: opts.offset,
30-
length: opts.length
31-
})
28+
yield * result.content(opts)
3229
}

packages/unixfs/src/commands/touch.ts

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export async function touch (cid: CID, blockstore: Blocks, options: Partial<Touc
6767
}
6868
}
6969
},
70+
// @ts-expect-error blockstore types are incompatible
7071
(source) => importer(source, blockstore, {
7172
...opts,
7273
dagBuilder: async function * (source, block) {

packages/unixfs/src/index.ts

+16-13
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,29 @@ import { rm } from './commands/rm.js'
4343
import { stat } from './commands/stat.js'
4444
import { touch } from './commands/touch.js'
4545
import { chmod } from './commands/chmod.js'
46-
import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
46+
import type { ExporterProgressEvents, UnixFSEntry } from 'ipfs-unixfs-exporter'
4747
import { ls } from './commands/ls.js'
48-
import type { ByteStream, DirectoryCandidate, FileCandidate, ImportCandidateStream, ImporterOptions, ImportProgressEvents, ImportResult } from 'ipfs-unixfs-importer'
48+
import type { ByteStream, DirectoryCandidate, FileCandidate, ImportCandidateStream, ImporterOptions, ImporterProgressEvents, ImportResult } from 'ipfs-unixfs-importer'
4949
import type { ProgressOptions } from 'progress-events'
5050

5151
export interface UnixFSComponents {
5252
blockstore: Blocks
5353
}
5454

5555
export type AddEvents = PutBlockProgressEvents
56-
| ImportProgressEvents
56+
| ImporterProgressEvents
5757

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

6060
}
6161

62+
export type GetEvents = GetBlockProgressEvents
63+
| ExporterProgressEvents
64+
6265
/**
6366
* Options to pass to the cat command
6467
*/
65-
export interface CatOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
68+
export interface CatOptions extends AbortOptions, ProgressOptions<GetEvents> {
6669
/**
6770
* Start reading the file at this offset
6871
*/
@@ -82,7 +85,7 @@ export interface CatOptions extends AbortOptions, ProgressOptions<GetBlockProgre
8285
/**
8386
* Options to pass to the chmod command
8487
*/
85-
export interface ChmodOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
88+
export interface ChmodOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
8689
/**
8790
* If the target of the operation is a directory and this is true,
8891
* apply the new mode to all directory contents
@@ -104,7 +107,7 @@ export interface ChmodOptions extends AbortOptions, ProgressOptions<GetBlockProg
104107
/**
105108
* Options to pass to the cp command
106109
*/
107-
export interface CpOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
110+
export interface CpOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
108111
/**
109112
* If true, allow overwriting existing directory entries (default: false)
110113
*/
@@ -120,7 +123,7 @@ export interface CpOptions extends AbortOptions, ProgressOptions<GetBlockProgres
120123
/**
121124
* Options to pass to the ls command
122125
*/
123-
export interface LsOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
126+
export interface LsOptions extends AbortOptions, ProgressOptions<GetEvents> {
124127
/**
125128
* Optional path to list subdirectory contents if the target CID resolves to
126129
* a directory
@@ -141,7 +144,7 @@ export interface LsOptions extends AbortOptions, ProgressOptions<GetBlockProgres
141144
/**
142145
* Options to pass to the mkdir command
143146
*/
144-
export interface MkdirOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
147+
export interface MkdirOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
145148
/**
146149
* The CID version to create the new directory with - defaults to the same
147150
* version as the containing directory
@@ -173,7 +176,7 @@ export interface MkdirOptions extends AbortOptions, ProgressOptions<GetBlockProg
173176
/**
174177
* Options to pass to the rm command
175178
*/
176-
export interface RmOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents | PutBlockProgressEvents> {
179+
export interface RmOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
177180
/**
178181
* DAGs with a root block larger than this value will be sharded. Blocks
179182
* smaller than this value will be regular UnixFS directories.
@@ -184,7 +187,7 @@ export interface RmOptions extends AbortOptions, ProgressOptions<GetBlockProgres
184187
/**
185188
* Options to pass to the stat command
186189
*/
187-
export interface StatOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
190+
export interface StatOptions extends AbortOptions, ProgressOptions<GetEvents> {
188191
/**
189192
* An optional path to allow statting paths inside directories
190193
*/
@@ -251,7 +254,7 @@ export interface UnixFSStats {
251254
/**
252255
* Options to pass to the touch command
253256
*/
254-
export interface TouchOptions extends AbortOptions {
257+
export interface TouchOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents> {
255258
/**
256259
* Optional mtime to set on the DAG root, defaults to the current time
257260
*/
@@ -376,7 +379,7 @@ export interface UnixFS {
376379
* }
377380
* ```
378381
*/
379-
cat: (cid: CID, options?: Partial<CatOptions> & ProgressOptions<GetBlockProgressEvents>) => AsyncIterable<Uint8Array>
382+
cat: (cid: CID, options?: Partial<CatOptions>) => AsyncIterable<Uint8Array>
380383

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

428431
/**
429432
* Make a new directory under an existing directory.

0 commit comments

Comments
 (0)