From 36cf3b2143276a59b685ceb58299c4f881545fee Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 17 Mar 2023 12:27:21 +0100 Subject: [PATCH] feat: expose unixfs progress events in types (#14) Expands types to include unixfs progress events as well as bitswap and blockstore events. --- packages/interop/package.json | 2 +- packages/unixfs/package.json | 4 ++-- packages/unixfs/src/commands/cat.ts | 5 +---- packages/unixfs/src/commands/touch.ts | 1 + packages/unixfs/src/index.ts | 29 +++++++++++++++------------ 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/interop/package.json b/packages/interop/package.json index d8e99cb..0f2dee7 100644 --- a/packages/interop/package.json +++ b/packages/interop/package.json @@ -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", diff --git a/packages/unixfs/package.json b/packages/unixfs/package.json index 40be6ae..81015ff 100644 --- a/packages/unixfs/package.json +++ b/packages/unixfs/package.json @@ -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", diff --git a/packages/unixfs/src/commands/cat.ts b/packages/unixfs/src/commands/cat.ts index eb31c76..328cdae 100644 --- a/packages/unixfs/src/commands/cat.ts +++ b/packages/unixfs/src/commands/cat.ts @@ -25,8 +25,5 @@ export async function * cat (cid: CID, blockstore: Blocks, options: Partial importer(source, blockstore, { ...opts, dagBuilder: async function * (source, block) { diff --git a/packages/unixfs/src/index.ts b/packages/unixfs/src/index.ts index d20f303..2f71c2a 100644 --- a/packages/unixfs/src/index.ts +++ b/packages/unixfs/src/index.ts @@ -43,9 +43,9 @@ 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 { @@ -53,16 +53,19 @@ export interface UnixFSComponents { } export type AddEvents = PutBlockProgressEvents -| ImportProgressEvents +| ImporterProgressEvents export interface AddOptions extends AbortOptions, Omit, ProgressOptions { } +export type GetEvents = GetBlockProgressEvents +| ExporterProgressEvents + /** * Options to pass to the cat command */ -export interface CatOptions extends AbortOptions, ProgressOptions { +export interface CatOptions extends AbortOptions, ProgressOptions { /** * Start reading the file at this offset */ @@ -82,7 +85,7 @@ export interface CatOptions extends AbortOptions, ProgressOptions { +export interface ChmodOptions extends AbortOptions, ProgressOptions { /** * If the target of the operation is a directory and this is true, * apply the new mode to all directory contents @@ -104,7 +107,7 @@ export interface ChmodOptions extends AbortOptions, ProgressOptions { +export interface CpOptions extends AbortOptions, ProgressOptions { /** * If true, allow overwriting existing directory entries (default: false) */ @@ -120,7 +123,7 @@ export interface CpOptions extends AbortOptions, ProgressOptions { +export interface LsOptions extends AbortOptions, ProgressOptions { /** * Optional path to list subdirectory contents if the target CID resolves to * a directory @@ -141,7 +144,7 @@ export interface LsOptions extends AbortOptions, ProgressOptions { +export interface MkdirOptions extends AbortOptions, ProgressOptions { /** * The CID version to create the new directory with - defaults to the same * version as the containing directory @@ -173,7 +176,7 @@ export interface MkdirOptions extends AbortOptions, ProgressOptions { +export interface RmOptions extends AbortOptions, ProgressOptions { /** * DAGs with a root block larger than this value will be sharded. Blocks * smaller than this value will be regular UnixFS directories. @@ -184,7 +187,7 @@ export interface RmOptions extends AbortOptions, ProgressOptions { +export interface StatOptions extends AbortOptions, ProgressOptions { /** * An optional path to allow statting paths inside directories */ @@ -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 { /** * Optional mtime to set on the DAG root, defaults to the current time */ @@ -376,7 +379,7 @@ export interface UnixFS { * } * ``` */ - cat: (cid: CID, options?: Partial & ProgressOptions) => AsyncIterable + cat: (cid: CID, options?: Partial) => AsyncIterable /** * Change the permissions on a file or directory in a DAG @@ -423,7 +426,7 @@ export interface UnixFS { * } * ``` */ - ls: (cid: CID, options?: Partial & ProgressOptions) => AsyncIterable + ls: (cid: CID, options?: Partial) => AsyncIterable /** * Make a new directory under an existing directory.