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

Commit 0ddbb1b

Browse files
authored
fix: update types after feedback from ceramic (#3657)
Some of the types need a little correcting. Fixes #3640
1 parent 7e61fbf commit 0ddbb1b

File tree

9 files changed

+27
-39
lines changed

9 files changed

+27
-39
lines changed

examples/custom-ipfs-repo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependencies": {
1313
"datastore-fs": "4.0.0",
1414
"ipfs": "^0.54.4",
15-
"ipfs-repo": "^9.1.1",
15+
"ipfs-repo": "^9.1.3",
1616
"it-all": "^1.0.4"
1717
},
1818
"devDependencies": {

packages/ipfs-cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"ipfs-core-utils": "^0.7.2",
4343
"ipfs-daemon": "^0.5.4",
4444
"ipfs-http-client": "^49.0.4",
45-
"ipfs-repo": "^9.1.1",
45+
"ipfs-repo": "^9.1.3",
4646
"ipfs-utils": "^6.0.4",
4747
"ipld-dag-cbor": "^1.0.0",
4848
"ipld-dag-pb": "^0.22.1",

packages/ipfs-core-types/src/config/index.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export interface AddressConfig {
5151
RPC?: string
5252
Delegates?: string[]
5353
Gateway?: string
54-
Swarm?: string[]
54+
Swarm?: string[],
55+
Announce?: string[],
56+
NoAnnounce?: string[]
5557
}
5658

5759
export interface APIConfig {

packages/ipfs-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"ipfs-block-service": "^0.19.0",
7575
"ipfs-core-types": "^0.3.1",
7676
"ipfs-core-utils": "^0.7.2",
77-
"ipfs-repo": "^9.1.1",
77+
"ipfs-repo": "^9.1.3",
7878
"ipfs-unixfs": "^4.0.3",
7979
"ipfs-unixfs-exporter": "^5.0.3",
8080
"ipfs-unixfs-importer": "^7.0.3",

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

+16-29
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const PubsubRouters = require('../runtime/libp2p-pubsub-routers-nodejs')
1313
* @typedef {import('peer-id')} PeerId
1414
* @typedef {import('../types').Options} IPFSOptions
1515
* @typedef {import('libp2p')} LibP2P
16-
* @typedef {import('libp2p').Libp2pOptions & import('libp2p').constructorOptions} Options
16+
* @typedef {import('libp2p').Libp2pOptions & import('libp2p').CreateOptions} Libp2pOptions
1717
* @typedef {import('ipfs-core-types/src/config').Config} IPFSConfig
1818
* @typedef {import('multiaddr').Multiaddr} Multiaddr
1919
*/
@@ -66,6 +66,7 @@ module.exports = ({
6666
* @param {KeychainConfig} input.keychainConfig
6767
* @param {PeerId} input.peerId
6868
* @param {Multiaddr[]} input.multiaddrs
69+
* @returns {Libp2pOptions}
6970
*/
7071
function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, peerId, multiaddrs }) {
7172
const getPubsubRouter = () => {
@@ -93,25 +94,20 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
9394
config: {
9495
peerDiscovery: {
9596
mdns: {
96-
enabled: get(options, 'config.Discovery.MDNS.Enabled',
97-
get(config, 'Discovery.MDNS.Enabled', true))
97+
enabled: get(options, 'config.Discovery.MDNS.Enabled', get(config, 'Discovery.MDNS.Enabled', true))
9898
},
9999
webRTCStar: {
100-
enabled: get(options, 'config.Discovery.webRTCStar.Enabled',
101-
get(config, 'Discovery.webRTCStar.Enabled', true))
100+
enabled: get(options, 'config.Discovery.webRTCStar.Enabled', get(config, 'Discovery.webRTCStar.Enabled', true))
102101
},
103102
bootstrap: {
104103
list: get(options, 'config.Bootstrap', get(config, 'Bootstrap', []))
105104
}
106105
},
107106
relay: {
108-
enabled: get(options, 'relay.enabled',
109-
get(config, 'relay.enabled', true)),
107+
enabled: get(options, 'relay.enabled', get(config, 'relay.enabled', true)),
110108
hop: {
111-
enabled: get(options, 'relay.hop.enabled',
112-
get(config, 'relay.hop.enabled', false)),
113-
active: get(options, 'relay.hop.active',
114-
get(config, 'relay.hop.active', false))
109+
enabled: get(options, 'relay.hop.enabled', get(config, 'relay.hop.enabled', false)),
110+
active: get(options, 'relay.hop.active', get(config, 'relay.hop.active', false))
115111
}
116112
},
117113
dht: {
@@ -120,30 +116,20 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
120116
kBucketSize: get(options, 'dht.kBucketSize', 20)
121117
},
122118
pubsub: {
123-
enabled: get(options, 'config.Pubsub.Enabled',
124-
get(config, 'Pubsub.Enabled', true))
119+
enabled: get(options, 'config.Pubsub.Enabled', get(config, 'Pubsub.Enabled', true))
125120
},
126121
nat: {
127-
enabled: get(options, 'libp2p.config.nat.enabled', !get(config, 'Swarm.DisableNatPortMap', false)),
128-
ttl: get(options, 'libp2p.config.nat.ttl', 7200),
129-
keepAlive: get(options, 'libp2p.config.nat.keepAlive', true),
130-
gateway: get(options, 'libp2p.config.nat.gateway'),
131-
externalIp: get(options, 'libp2p.config.nat.externalIp'),
132-
pmp: {
133-
enabled: get(options, 'libp2p.config.nat.pmp.enabled', false)
134-
}
122+
enabled: !get(config, 'Swarm.DisableNatPortMap', false)
135123
}
136124
},
137125
addresses: {
138126
listen: multiaddrs.map(ma => ma.toString()),
139-
announce: get(options, 'addresses.announce',
140-
get(config, 'Addresses.Announce', []))
127+
announce: get(options, 'addresses.announce', get(config, 'Addresses.Announce', [])),
128+
noAnnounce: get(options, 'addresses.noAnnounce', get(config, 'Addresses.NoAnnounce', []))
141129
},
142130
connectionManager: get(options, 'connectionManager', {
143-
maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater',
144-
get(config, 'Swarm.ConnMgr.HighWater')),
145-
minConnections: get(options, 'config.Swarm.ConnMgr.LowWater',
146-
get(config, 'Swarm.ConnMgr.LowWater'))
131+
maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater', get(config, 'Swarm.ConnMgr.HighWater')),
132+
minConnections: get(options, 'config.Swarm.ConnMgr.LowWater', get(config, 'Swarm.ConnMgr.LowWater'))
147133
}),
148134
keychain: {
149135
datastore: keys,
@@ -155,10 +141,11 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
155141
// Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified
156142
const getEnvLibp2pOptions = require('../runtime/libp2p-nodejs')
157143

158-
let constructorOptions = get(options, 'libp2p', {})
144+
/** @type {import('libp2p').Libp2pOptions | undefined} */
145+
let constructorOptions = get(options, 'libp2p', undefined)
159146

160147
if (typeof constructorOptions === 'function') {
161-
constructorOptions = {}
148+
constructorOptions = undefined
162149
}
163150

164151
// Merge defaults with Node.js/browser/other environments options and configuration

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ class Network {
4848
await repo.open()
4949
}
5050

51+
/** @type {IPFSConfig} */
5152
const config = await repo.config.getAll()
5253

5354
const libp2p = await createLibP2P({
5455
options,
5556
repo,
5657
peerId,
57-
// @ts-ignore - TODO move config types into ipfs-repo
5858
multiaddrs: readAddrs(peerId, config),
59-
// @ts-ignore - TODO move config types into ipfs-repo
6059
config,
6160
keychainConfig: undefined
6261
})
@@ -90,10 +89,8 @@ class Network {
9089
module.exports = Network
9190

9291
/**
93-
*
9492
* @param {PeerId} peerId
9593
* @param {IPFSConfig} config
96-
* @returns {Multiaddr[]}
9794
*/
9895
const readAddrs = (peerId, config) => {
9996
const peerIdStr = peerId.toB58String()

packages/ipfs-core/src/runtime/config-browser.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = () => ({
55
Swarm: [
66
],
77
Announce: [],
8+
NoAnnounce: [],
89
API: '',
910
Gateway: '',
1011
RPC: '',

packages/ipfs-core/src/runtime/config-nodejs.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = () => ({
77
'/ip4/127.0.0.1/tcp/4003/ws'
88
],
99
Announce: [],
10+
NoAnnounce: [],
1011
API: '/ip4/127.0.0.1/tcp/5002',
1112
Gateway: '/ip4/127.0.0.1/tcp/9090',
1213
RPC: '/ip4/127.0.0.1/tcp/5003',

packages/ipfs-core/src/types.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ProfileNames } from 'ipfs-core-types/src/config/profiles'
55
import type IPLD from 'ipld'
66
import type { Options as IPLDOptions } from 'ipld'
77
import type Libp2p from 'libp2p'
8-
import type { Libp2pConfig as Libp2pOptions } from 'libp2p'
8+
import type { Libp2pOptions } from 'libp2p'
99
import type IPFSRepo from 'ipfs-repo'
1010
import type { ProgressCallback as MigrationProgressCallback } from 'ipfs-repo-migrations'
1111
import type { Datastore } from 'interface-datastore'
@@ -117,7 +117,7 @@ export interface Options {
117117
* in Node.js, [`libp2p-browser.js`](../src/core/runtime/libp2p-browser.js) in
118118
* browsers.
119119
*/
120-
libp2p?: Libp2pOptions | Libp2pFactoryFn
120+
libp2p?: Partial<Libp2pOptions> | Libp2pFactoryFn
121121

122122
silent?: boolean
123123
}

0 commit comments

Comments
 (0)