Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 0fe8892

Browse files
authored
fix: fix types (#3662)
* fix: fix types Fix type errors exposed by integrating with powergate-client. * chore: remove ipld dependency as the types are too heavy * chore: remove unused dep and import * chore: remove unused type
1 parent 61d0981 commit 0fe8892

File tree

8 files changed

+22
-74
lines changed

8 files changed

+22
-74
lines changed

Diff for: packages/ipfs-core-types/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"license": "(Apache-2.0 OR MIT)",
3030
"dependencies": {
3131
"cids": "^1.1.6",
32-
"ipld": "^0.30.0",
32+
"interface-datastore": "^4.0.0",
33+
"ipld-block": "^0.11.1",
3334
"multiaddr": "^9.0.1",
3435
"multibase": "^4.0.2"
3536
},

Diff for: packages/ipfs-core-types/src/object/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export interface API<OptionExtension = {}> {
88
put: (obj: DAGNode | DAGNodeLike | Uint8Array, options?: PutOptions & OptionExtension) => Promise<CID>
99
get: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<DAGNode>
1010
data: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<Uint8Array>
11-
links: (cid, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<DAGLink[]>
12-
stat: (cid, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<StatResult>
11+
links: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<DAGLink[]>
12+
stat: (cid: CID, options?: AbortOptions & PreloadOptions & OptionExtension) => Promise<StatResult>
1313

1414
patch: PatchAPI
1515
}

Diff for: packages/ipfs-core-types/src/pin/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AbortOptions, AwaitIterable } from '../utils'
22
import type CID from 'cids'
3-
import type { API as remote } from './remote'
3+
import type { API as Remote } from './remote'
44

55
export interface API<OptionExtension = {}> {
66
/**
@@ -92,7 +92,7 @@ export interface API<OptionExtension = {}> {
9292
*/
9393
rmAll: (source: AwaitIterable<RmAllInput>, options?: AbortOptions & OptionExtension) => AsyncIterable<CID>
9494

95-
remote
95+
remote: Remote<OptionExtension>
9696
}
9797

9898
export interface AddOptions extends AbortOptions {

Diff for: packages/ipfs-core-types/src/utils.d.ts

+2-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import CID from 'cids'
22
import { Mtime, MtimeLike } from 'ipfs-unixfs'
3+
import { Options as DatastoreOptions, Query, KeyQuery } from 'interface-datastore'
4+
import Block from 'ipld-block'
35

46
export type Entry<Content extends AsyncIterable<Uint8Array>|Blob> =
57
| FileEntry<Content>
@@ -131,57 +133,3 @@ export interface BufferStore {
131133
get: (key: Uint8Array) => Promise<Uint8Array>
132134
stores: any[]
133135
}
134-
135-
export interface Blockstore {
136-
open: () => Promise<Void>
137-
138-
/**
139-
* Query the store
140-
*/
141-
query: (Query, options?: DatastoreOptions) => AsyncIterable<Block>
142-
143-
/**
144-
* Query the store, returning only keys
145-
*/
146-
queryKeys: (query: KeyQuery, options?: DatastoreOptions) => AsyncIterable<CID>
147-
148-
/**
149-
* Get a single block by CID
150-
*/
151-
get: (cid: CID, options?: DatastoreOptions) => Promise<Block>
152-
153-
/**
154-
* Like get, but for more
155-
*/
156-
getMany: (cids: AwaitIterable<CID>, options?: DatastoreOptions) => AsyncIterable<Block>
157-
158-
/**
159-
* Write a single block to the store
160-
*/
161-
put: (block: Block, options?: DatastoreOptions) => Promise<Block>
162-
163-
/**
164-
* Like put, but for more
165-
*/
166-
putMany: (blocks: AwaitIterable<Block>, options?: DatastoreOptions) => AsyncIterable<Block>
167-
168-
/**
169-
* Does the store contain block with this CID?
170-
*/
171-
has: (cid: CID, options?: DatastoreOptions) => Promise<boolean>
172-
173-
/**
174-
* Delete a block from the store
175-
*/
176-
delete: (cid: CID, options?: DatastoreOptions) => Promise<Void>
177-
178-
/**
179-
* Delete a block from the store
180-
*/
181-
deleteMany: (cids: AwaitIterable<any>, options?: DatastoreOptions) => AsyncIterable<Key>
182-
183-
/**
184-
* Close the store
185-
*/
186-
close: () => Promise<Void>
187-
}

Diff for: packages/ipfs-core/src/components/pin/index.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@ class PinAPI {
2727
this.rm = createRm({ rmAll })
2828
this.ls = createLs({ ipld, pinManager })
2929

30-
const notImplemented = () => Promise.reject(new Error('Not implemented'))
31-
30+
/** @type {import('ipfs-core-types/src/pin/remote').API} */
3231
this.remote = {
33-
add: notImplemented,
34-
ls: notImplemented,
35-
rm: notImplemented,
36-
rmAll: notImplemented,
32+
add: (cid, options = {}) => Promise.reject(new Error('Not implemented')),
33+
ls: async function * (query, options = {}) { return Promise.reject(new Error('Not implemented')) }, // eslint-disable-line require-yield
34+
rm: (query, options = {}) => Promise.reject(new Error('Not implemented')),
35+
rmAll: (query, options = {}) => Promise.reject(new Error('Not implemented')),
3736
service: {
38-
add: notImplemented,
39-
rm: notImplemented,
40-
ls: notImplemented
37+
add: (name, credentials) => Promise.reject(new Error('Not implemented')),
38+
rm: (name, options = {}) => Promise.reject(new Error('Not implemented')),
39+
ls: (options = {}) => Promise.reject(new Error('Not implemented'))
4140
}
4241
}
4342
}

Diff for: packages/ipfs-http-client/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"ipfs-core-utils": "^0.7.2",
5454
"ipfs-unixfs": "^4.0.3",
5555
"ipfs-utils": "^6.0.4",
56-
"ipld": "^0.30.0",
5756
"ipld-block": "^0.11.0",
5857
"ipld-dag-cbor": "^1.0.0",
5958
"ipld-dag-pb": "^0.22.1",

Diff for: packages/ipfs-http-client/src/lib/ipld-formats.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const multicodec = require('multicodec')
88
/**
99
* @typedef {import('cids')} CID
1010
* @typedef {import('interface-ipld-format').Format<any>} IPLDFormat
11-
* @typedef {import('ipld').LoadFormatFn} LoadFormatFn
11+
* @typedef {import('multicodec').CodecName} CodecName
12+
* @typedef {import('../types').LoadFormatFn} LoadFormatFn
1213
*/
1314

1415
/**
@@ -23,7 +24,7 @@ const noop = (codec) => {
2324
*
2425
* @param {object} [options] - IPLD options passed to the http client constructor
2526
* @param {IPLDFormat[]} [options.formats] - A list of IPLD Formats to use
26-
* @param {import('ipld').LoadFormatFn} [options.loadFormat] - An async function that can load a format when passed a codec number
27+
* @param {LoadFormatFn} [options.loadFormat] - An async function that can load a format when passed a codec name
2728
*/
2829
module.exports = ({ formats = [], loadFormat = noop } = {}) => {
2930
formats = formats || []
@@ -42,11 +43,10 @@ module.exports = ({ formats = [], loadFormat = noop } = {}) => {
4243
/**
4344
* Attempts to load an IPLD format for the passed CID
4445
*
45-
* @param {import('multicodec').CodecName} codec - The code to load the format for
46+
* @param {CodecName} codec - The code to load the format for
4647
*/
4748
const loadResolver = async (codec) => {
4849
const number = multicodec.getCodeFromName(codec)
49-
// @ts-ignore wat
5050
const format = configuredFormats[number] || await loadFormat(codec)
5151

5252
if (!format) {

Diff for: packages/ipfs-http-client/src/types.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Format as IPLDFormat } from 'interface-ipld-format'
2-
import { LoadFormatFn } from 'ipld'
32
import { Agent as HttpAgent } from 'http'
43
import { Agent as HttpsAgent } from 'https'
54
import { Multiaddr } from 'multiaddr'
65

6+
export type LoadFormatFn = (name: CodecName) => Promise<IPLDFormat>
7+
78
export interface Options {
89
host?: string
910
port?: number

0 commit comments

Comments
 (0)