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

Commit a45a814

Browse files
committed
chore: use 0.30 rc
1 parent 7430d80 commit a45a814

File tree

17 files changed

+45
-43
lines changed

17 files changed

+45
-43
lines changed

packages/ipfs-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"it-first": "^1.0.4",
8989
"it-last": "^1.0.4",
9090
"it-pipe": "^1.1.0",
91-
"libp2p": "libp2p/js-libp2p#0.30.x",
91+
"libp2p": "libp2p/js-libp2p#fix/types-with-dist",
9292
"libp2p-bootstrap": "^0.12.1",
9393
"libp2p-crypto": "^0.18.0",
9494
"libp2p-floodsub": "^0.24.0",

packages/ipfs-core/src/components/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class IPFS {
7070
})
7171
const dns = createDNSAPI()
7272
const isOnline = createIsOnlineAPI({ network })
73+
// @ts-ignore This type check fails as options.
74+
// libp2p can be a function, while IPNS router config expects libp2p config
7375
const ipns = new IPNSAPI(options)
7476
const dagReader = DagAPI.reader({ ipld, preload })
7577

packages/ipfs-core/src/components/is-online.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ module.exports = ({ network }) =>
1010
*/
1111
() => {
1212
const net = network.try()
13-
return net != null && net.libp2p.isStarted()
13+
return net != null && Boolean(net.libp2p.isStarted())
1414
}

packages/ipfs-core/src/components/key/export.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ module.exports = ({ keychain }) => {
2323
* ```
2424
* @param {string} name - The name of the key to export
2525
* @param {string} password - Password to set on the PEM output
26-
* @param {import('.').AbortOptions} options
2726
* @returns {Promise<string>} - The string representation of the key
2827
*/
29-
const exportKey = (name, password, options) =>
30-
keychain.exportKey(name, password, options)
28+
const exportKey = (name, password) =>
29+
keychain.exportKey(name, password)
3130

3231
return withTimeoutOption(exportKey)
3332
}

packages/ipfs-core/src/components/key/import.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ module.exports = ({ keychain }) => {
2121
* @param {string} name - The name of the key to import
2222
* @param {string} pem - The PEM encoded key
2323
* @param {string} password - The password that protects the PEM key
24-
* @param {import('.').AbortOptions} options
2524
* @returns {Promise<import('.').Key>} - An object that describes the new key
2625
*/
27-
const importKey = (name, pem, password, options) => {
28-
return keychain.importKey(name, pem, password, options)
26+
const importKey = (name, pem, password) => {
27+
return keychain.importKey(name, pem, password)
2928
}
3029

3130
return withTimeoutOption(importKey)

packages/ipfs-core/src/components/key/info.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
99
module.exports = ({ keychain }) => {
1010
/**
1111
* @param {string} name
12-
* @param {AbortOptions} [options]
1312
* @returns {Promise<Key>}
1413
*/
15-
const info = (name, options = {}) => keychain.findKeyByName(name, options)
14+
const info = (name) => keychain.findKeyByName(name)
1615

1716
return withTimeoutOption(info)
1817
}

packages/ipfs-core/src/components/key/list.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,9 @@ module.exports = ({ keychain }) => {
2323
* // ]
2424
* ```
2525
*
26-
* @param {AbortOptions} [options]
27-
* @returns {Promise<KeyEntry[]>}
26+
* @returns {Promise<import('libp2p/src/keychain').KeyInfo[]>}
2827
*/
29-
const list = (options = {}) => keychain.listKeys(options)
28+
const list = () => keychain.listKeys()
3029

3130
return withTimeoutOption(list)
3231
}
33-
34-
/**
35-
* @typedef {Object} KeyEntry
36-
* @property {string} name - The name of the key
37-
* @property {string} hash - The hash of the key
38-
*
39-
* @typedef {import('.').AbortOptions} AbortOptions
40-
*/

packages/ipfs-core/src/components/key/rename.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ module.exports = ({ keychain }) => {
2222
* ```
2323
* @param {string} oldName - The current key name
2424
* @param {string} newName - The desired key name
25-
* @param {AbortOptions} [options]
2625
* @returns {Promise<RenamedKey>}
2726
*/
28-
const rename = async (oldName, newName, options = {}) => {
29-
const key = await keychain.renameKey(oldName, newName, options)
27+
const rename = async (oldName, newName) => {
28+
const key = await keychain.renameKey(oldName, newName)
29+
3030
return {
3131
was: oldName,
3232
now: key.name,

packages/ipfs-core/src/components/key/rm.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ module.exports = ({ keychain }) => {
2020
* ```
2121
*
2222
* @param {string} name - The name of the key to remove
23-
* @param {import('.').AbortOptions} options
2423
* @returns {Promise<RemovedKey>} - An object that describes the removed key
2524
*/
26-
const rm = (name, options) => keychain.removeKey(name, options)
25+
const rm = (name) => keychain.removeKey(name)
2726

2827
return withTimeoutOption(rm)
2928
}

packages/ipfs-core/src/components/libp2p.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
164164
* @typedef {import('.').PeerId} PeerId
165165
* @typedef {import('.').Options} IPFSOptions
166166
* @typedef {import('libp2p')} LibP2P
167-
* @typedef {import('libp2p').Options} Options
167+
* @typedef {import('libp2p').Libp2pOptions} Options
168168
* @typedef {import('.').IPFSConfig} IPFSConfig
169169
*/

packages/ipfs-core/src/components/ping.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,28 @@ module.exports = ({ network }) => {
3535
peerId = PeerId.createFromCID(peerId)
3636
}
3737

38-
let peer = libp2p.peerStore.get(peerId)
38+
const storedPeer = libp2p.peerStore.get(peerId)
39+
let id = storedPeer && storedPeer.id
3940

40-
if (!peer) {
41+
if (!id) {
4142
yield { ...basePacket, text: `Looking up peer ${peerId}` }
42-
peer = await libp2p.peerRouting.findPeer(peerId)
43+
const remotePeer = await libp2p.peerRouting.findPeer(peerId)
44+
45+
id = remotePeer && remotePeer.id
46+
}
47+
48+
if (!id) {
49+
throw new Error('Peer was not found')
4350
}
4451

45-
yield { ...basePacket, text: `PING ${peer.id.toB58String()}` }
52+
yield { ...basePacket, text: `PING ${id.toB58String()}` }
4653

4754
let packetCount = 0
4855
let totalTime = 0
4956

5057
for (let i = 0; i < options.count; i++) {
5158
try {
52-
const time = await libp2p.ping(peer.id)
59+
const time = await libp2p.ping(id)
5360
totalTime += time
5461
packetCount++
5562
yield { ...basePacket, time }

packages/ipfs-core/src/components/pubsub.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = ({ network, config }) => {
4141
*/
4242
async function subscribe (topic, handler, options) {
4343
const { libp2p } = await network.use(options)
44+
// @ts-ignore Libp2p Pubsub is deprecating the handler, using the EventEmitter
4445
return libp2p.pubsub.subscribe(topic, handler, options)
4546
}
4647

@@ -75,6 +76,7 @@ module.exports = ({ network, config }) => {
7576
*/
7677
async function unsubscribe (topic, handler, options) {
7778
const { libp2p } = await network.use(options)
79+
// @ts-ignore Libp2p Pubsub is deprecating the handler, using the EventEmitter
7880
libp2p.pubsub.unsubscribe(topic, handler, options)
7981
}
8082

@@ -111,7 +113,7 @@ module.exports = ({ network, config }) => {
111113
*/
112114
async function ls (options) {
113115
const { libp2p } = await network.use(options)
114-
return libp2p.pubsub.getTopics(options)
116+
return libp2p.pubsub.getTopics()
115117
}
116118

117119
/**
@@ -131,7 +133,7 @@ module.exports = ({ network, config }) => {
131133
*/
132134
async function peers (topic, options) {
133135
const { libp2p } = await network.use(options)
134-
return libp2p.pubsub.getSubscribers(topic, options)
136+
return libp2p.pubsub.getSubscribers(topic)
135137
}
136138
}
137139

packages/ipfs-core/src/components/stats/bw.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
1313
function getBandwidthStats (libp2p, opts) {
1414
let stats
1515

16-
if (opts.peer) {
16+
if (!libp2p.metrics) {
17+
stats = undefined
18+
} else if (opts.peer) {
1719
stats = libp2p.metrics.forPeer(opts.peer)
1820
} else if (opts.proto) {
1921
stats = libp2p.metrics.forProtocol(opts.proto)
@@ -85,7 +87,7 @@ module.exports = ({ network }) => {
8587

8688
/**
8789
* @typedef {Object} BWOptions
88-
* @property {PeerId|CID|string} [peer] - Specifies a peer to print bandwidth for
90+
* @property {PeerId} [peer] - Specifies a peer to print bandwidth for
8991
* @property {string} [proto] - Specifies a protocol to print bandwidth for
9092
* @property {boolean} [poll] - Is used to yield bandwidth info at an interval
9193
* @property {number|string} [interval=1000] - The time interval to wait between updating output, if `poll` is `true`.

packages/ipfs-core/src/components/storage.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Storage {
4343

4444
const { peerId, keychain, isNew } = await loadRepo(repo, options)
4545

46+
// TODO: throw error?
47+
// @ts-ignore On start, keychain will always be available
4648
return new Storage(peerId, keychain, repo, print, isNew)
4749
}
4850
}
@@ -52,7 +54,7 @@ module.exports = Storage
5254
*
5355
* @param {Repo} repo
5456
* @param {RepoOptions & InitOptions} options
55-
* @returns {Promise<{peerId: PeerId, keychain:Keychain, isNew:boolean }>}
57+
* @returns {Promise<{peerId: PeerId, keychain: Keychain | undefined, isNew:boolean }>}
5658
*/
5759
const loadRepo = async (repo, options) => {
5860
const openError = await openRepo(repo)
@@ -96,7 +98,7 @@ const openRepo = async (repo) => {
9698
/**
9799
* @param {Repo} repo
98100
* @param {RepoOptions & InitOptions} options
99-
* @returns {Promise<{peerId: PeerId, keychain:Keychain}>}
101+
* @returns {Promise<{peerId: PeerId, keychain: Keychain | undefined}>}
100102
*/
101103
const initRepo = async (repo, options) => {
102104
// 1. Verify that repo does not exist yet (if it does and we could not
@@ -197,7 +199,7 @@ const peerIdToIdentity = (peerId) => ({
197199
*
198200
* @param {Repo} repo
199201
* @param {ConfigureOptions} options
200-
* @returns {Promise<{peerId: PeerId, keychain:Keychain}>}
202+
* @returns {Promise<{peerId: PeerId, keychain: Keychain | undefined}>}
201203
*/
202204
const configureRepo = async (repo, { config, profiles, pass }) => {
203205
const original = await repo.config.getAll()
@@ -297,5 +299,5 @@ const applyProfiles = (config, profiles) => {
297299
* @typedef {import('.').IPFSConfig} IPFSConfig
298300
* @typedef {import('../interface/repo').Repo<IPFSConfig>} Repo
299301
* @typedef {import('libp2p-crypto').KeyType} KeyType
300-
* @typedef {import('libp2p').LibP2PKeychain} Keychain
302+
* @typedef {import('libp2p/src/keychain')} Keychain
301303
*/

packages/ipfs-core/src/components/swarm/addrs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = ({ network }) => {
1616
async function addrs (options) { // eslint-disable-line require-await
1717
const peers = []
1818
const { libp2p } = await network.use(options)
19-
for (const [peerId, peer] of libp2p.peerStore.peers.entries(options)) {
19+
for (const [peerId, peer] of libp2p.peerStore.peers.entries()) {
2020
peers.push({
2121
id: peerId,
2222
addrs: peer.addresses.map((mi) => mi.multiaddr)

packages/ipfs-core/src/components/swarm/connect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = ({ network }) => {
1616
*/
1717
async function connect (addr, options) {
1818
const { libp2p } = await network.use(options)
19-
return libp2p.dial(addr, options)
19+
await libp2p.dial(addr, options)
2020
}
2121

2222
return withTimeoutOption(connect)

packages/ipfs-core/src/components/swarm/disconnect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = ({ network }) => {
1616
*/
1717
async function disconnect (addr, options) {
1818
const { libp2p } = await network.use(options)
19-
return libp2p.hangUp(addr, options)
19+
return libp2p.hangUp(addr)
2020
}
2121

2222
return withTimeoutOption(disconnect)

0 commit comments

Comments
 (0)