-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(deps): replace ipfs-http-client with kubo-rpc-client
- Replace deprecated ipfs-http-client with kubo-rpc-client. - kubo-rpc-client must be imported dynamically since it's ESM-only and we still use CJS. Depends on: #2821 Signed-off-by: Michal Bajer <[email protected]>
- Loading branch information
Showing
11 changed files
with
305 additions
and
307 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
48 changes: 0 additions & 48 deletions
48
extensions/cactus-plugin-object-store-ipfs/src/main/typescript/i-ipfs-http-client.ts
This file was deleted.
Oops, something went wrong.
127 changes: 127 additions & 0 deletions
127
extensions/cactus-plugin-object-store-ipfs/src/main/typescript/kubo-rpc-client-types.ts
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,127 @@ | ||
/** | ||
* Since kubo-rpc-client uses ESM only, we can't import it to get types (since we use CJS). | ||
* To fix this we define required types here, based on their counterparts in kubo-rpc-client. | ||
*/ | ||
|
||
import type { Multiaddr } from "@multiformats/multiaddr"; | ||
import type { MultihashHasher } from "multiformats/hashes/interface"; | ||
import type { Agent as HttpAgent } from "http"; | ||
import type { Agent as HttpsAgent } from "https"; | ||
import type { CID } from "multiformats/cid"; | ||
import type { Mtime } from "ipfs-unixfs"; | ||
|
||
///////////////////////////////////// | ||
// Types from kubo-rpc-client | ||
///////////////////////////////////// | ||
// Some are simplified when details are not needed | ||
|
||
export type MultibaseCodec<Prefix extends string = any> = | ||
import("multiformats/bases/interface").MultibaseCodec<Prefix>; | ||
export type BlockCodec< | ||
T1 = any, | ||
T2 = any, | ||
> = import("multiformats/codecs/interface").BlockCodec<T1, T2>; | ||
|
||
export interface LoadBaseFn { | ||
(codeOrName: number | string): Promise<MultibaseCodec<any>>; | ||
} | ||
export interface LoadCodecFn { | ||
(codeOrName: number | string): Promise<BlockCodec<any, any>>; | ||
} | ||
export interface LoadHasherFn { | ||
(codeOrName: number | string): Promise<MultihashHasher>; | ||
} | ||
|
||
export interface IPLDOptions { | ||
loadBase: LoadBaseFn; | ||
loadCodec: LoadCodecFn; | ||
loadHasher: LoadHasherFn; | ||
bases: Array<MultibaseCodec<any>>; | ||
codecs: Array<BlockCodec<any, any>>; | ||
hashers: MultihashHasher[]; | ||
} | ||
|
||
export interface Options { | ||
host?: string; | ||
port?: number; | ||
protocol?: string; | ||
headers?: Headers | Record<string, string>; | ||
timeout?: number | string; | ||
apiPath?: string; | ||
url?: URL | string | Multiaddr; | ||
ipld?: Partial<IPLDOptions>; | ||
agent?: HttpAgent | HttpsAgent; | ||
} | ||
|
||
export type IPFSPath = CID | string; | ||
|
||
export interface StatResult { | ||
cid: CID; | ||
size: number; | ||
cumulativeSize: number; | ||
type: "directory" | "file"; | ||
blocks: number; | ||
withLocality: boolean; | ||
local?: boolean; | ||
sizeLocal?: number; | ||
mode?: number; | ||
mtime?: Mtime; | ||
} | ||
|
||
///////////////////////////////////////////////////////// | ||
// LikeIpfsHttpClient instead of full IpfsHttpClient | ||
///////////////////////////////////////////////////////// | ||
|
||
/** | ||
* Connector only needs these methods to work. | ||
* More methods can be added in the future. | ||
*/ | ||
export interface LikeIpfsHttpClientFile { | ||
read: ( | ||
ipfsPath: IPFSPath, | ||
options?: Record<string, unknown>, | ||
) => AsyncIterable<Uint8Array>; | ||
|
||
write: ( | ||
ipfsPath: string, | ||
content: | ||
| string | ||
| Uint8Array | ||
| Blob | ||
| AsyncIterable<Uint8Array> | ||
| Iterable<Uint8Array>, | ||
options?: Record<string, unknown>, | ||
) => Promise<void>; | ||
|
||
stat: ( | ||
ipfsPath: IPFSPath, | ||
options?: Record<string, unknown>, | ||
) => Promise<StatResult>; | ||
} | ||
|
||
export function isLikeIpfsHttpClientFile( | ||
x: unknown, | ||
): x is LikeIpfsHttpClientFile { | ||
if (!x) { | ||
return false; | ||
} | ||
return ( | ||
typeof (x as LikeIpfsHttpClientFile).read === "function" && | ||
typeof (x as LikeIpfsHttpClientFile).write === "function" && | ||
typeof (x as LikeIpfsHttpClientFile).stat === "function" | ||
); | ||
} | ||
|
||
/** | ||
* Only files API is used | ||
*/ | ||
export interface LikeIpfsHttpClient { | ||
files: LikeIpfsHttpClientFile; | ||
} | ||
|
||
export function isLikeIpfsHttpClient(x: unknown): x is LikeIpfsHttpClient { | ||
if (!x) { | ||
return false; | ||
} | ||
return isLikeIpfsHttpClientFile((x as LikeIpfsHttpClient).files); | ||
} |
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
6 changes: 5 additions & 1 deletion
6
extensions/cactus-plugin-object-store-ipfs/src/main/typescript/public-api.ts
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.