This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pass file name to add/addAll progress handler (#3372)
Since ipfs/js-ipfs-unixfs#87 landed we can now pass the file name to the progress handler for adding files: ```js await ipfs.addAll(..., { progress: (bytes, fileName) => { //... } }) ``` This should make showing progress a bit more usable. Co-authored-by: Hugo Dias <hugomrdias@gmail.com>
- Loading branch information
1 parent
7a0f1a2
commit 69681a7
Showing
15 changed files
with
178 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This file contains some utility types that either can't be expressed in | ||
// JSDoc syntax or that result in a different behaviour when typed in JSDoc. | ||
|
||
/** | ||
* Utility type that takes IPFS Core API function type (with 0 to 4 arguments | ||
* & last **optional** `options` parameter) and derives a function type with | ||
* `options` parameter extended with given `Extra` options. | ||
* | ||
* **Caution**: API Functions with more than for arguments ahead of `options` | ||
* will result to `never` type. API function that does not take `options` will | ||
* result in function whose last argument is extended with `Extra` which would | ||
* be an error. | ||
*/ | ||
// This is typed in TS file because otherwise TS unifies on the first parameter | ||
// regardless of number of parameters function has. | ||
export type APIWithExtraOptions<API extends (...args: any[]) => any, Extra> = | ||
(...args: WithExtendedOptions<Parameters<API>, Extra>) => ReturnType<API> | ||
|
||
type End = never[] | ||
type WithExtendedOptions<Params, Ext> = Params extends [...End] | ||
? [] | ||
// (options?: Options) -> (options?: Options & Ext) | ||
: Params extends [options?: infer Options, ...end: End] | ||
? [options?: Options & Ext] | ||
// (a: A1, options?: Options) -> (a1: A1, options?: Options & Ext) | ||
: Params extends [a1: infer A1, options?: infer Options, ...end: End] | ||
? [a1: A1, options?: Options & Ext] | ||
// (a1?: A1, options?: Options) -> (a1?: A1, options?: Options & Ext) | ||
: Params extends [a1?: infer A1, options?: infer Options, ...end: End] | ||
? [a1?: A1, options?: Options & Ext] | ||
// (a1: A1, a2: A2, options?: Options) -> (a1: A1, a2: A2 options?: Options & Ext) | ||
: Params extends [a1: infer A1, a2: infer A2, options?: infer Options, ...end: End] | ||
? [a1: A1, a2: A2, options?: Options & Ext] | ||
// (a1: A1, a2?: A2, options?: Options) -> (a1: A1, a2?: A2 options?: Options & Ext) | ||
: Params extends [a1: infer A1, a2?: infer A2, options?: infer Options, ...end: End] | ||
? [a1: A1, a2?: A2, options?: Options & Ext] | ||
// (a1: A1, a2?: A2, options?: Options) -> (a1: A1, a2?: A2 options?: Options & Ext) | ||
: Params extends [a1?: infer A1, a2?: infer A2, options?: infer Options, ...end: End] | ||
? [a1?: A1, a2?: A2, options?: Options & Ext] | ||
// (a1: A1, a2: A2, a3:A3 options?: Options) -> (a1: A1, a2: A2, a3:A3, options?: Options & Ext) | ||
: Params extends [a1: infer A1, a2: infer A2, a3:infer A3, options?: infer Options, ...end: End] | ||
? [a1: A1, a2: A2, a3: A3, options?: Options & Ext] | ||
// (a1: A1, a2: A2, a3?:A3 options?: Options) -> (a1: A1, a2: A2, a3?:A3, options?: Options & Ext) | ||
: Params extends [a1: infer A1, a2:infer A2, a3?: infer A3, options?: infer Options, ...end: End] | ||
? [a1: A1, a2: A2, a3?: A3, options?: Options & Ext] | ||
// (a1: A1, a2?: A2, a3?:A3 options?: Options) -> (a1: A1, a2?: A2, a3?:A3, options?: Options & Ext) | ||
: Params extends [a1: infer A1, a2?: infer A2, a3?: infer A3, options?: infer Options, ...end: End] | ||
? [a1: A1, a2?: A2, a3?: A3, options?: Options & Ext] | ||
// (a1?: A1, a2?: A2, a3?:A3 options?: Options) -> (a1?: A1, a2?: A2, a3?:A3, options?: Options & Ext) | ||
: Params extends [a1?: infer A1, a2?: infer A2, a3?: infer A3, options?: infer Options, ...end: End] | ||
? [a1?: A1, a2?: A2, a3?: A3, options?: Options & Ext] | ||
: never | ||
|
||
export type APIMethodWithExtraOptions < | ||
API, | ||
Key extends keyof API, | ||
Extra | ||
> = API[Key] extends (...args: any[]) => any ? APIWithExtraOptions<API[Key], Extra> : never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,12 @@ | |
}, | ||
{ | ||
"path": "../ipfs-message-port-server" | ||
}, | ||
{ | ||
"path": "../ipfs-core" | ||
}, | ||
{ | ||
"path": "../ipfs-core-utils" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.