mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-28 08:21:33 +00:00
fix: create has optional peer id type (#875)
This commit is contained in:
@ -82,10 +82,12 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
|||||||
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
|
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
|
||||||
* @property {PeerStoreOptions & import('./peer-store/persistent').PersistentPeerStoreOptions} [peerStore]
|
* @property {PeerStoreOptions & import('./peer-store/persistent').PersistentPeerStoreOptions} [peerStore]
|
||||||
* @property {Libp2pConfig} [config]
|
* @property {Libp2pConfig} [config]
|
||||||
|
*
|
||||||
|
* @typedef {Object} constructorOptions
|
||||||
* @property {PeerId} peerId
|
* @property {PeerId} peerId
|
||||||
*
|
*
|
||||||
* @typedef {Object} CreateOptions
|
* @typedef {Object} CreateOptions
|
||||||
* @property {PeerId} peerId
|
* @property {PeerId} [peerId]
|
||||||
*
|
*
|
||||||
* @extends {EventEmitter}
|
* @extends {EventEmitter}
|
||||||
* @fires Libp2p#error Emitted when an error occurs
|
* @fires Libp2p#error Emitted when an error occurs
|
||||||
@ -101,12 +103,14 @@ class Libp2p extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
static async create (options) {
|
static async create (options) {
|
||||||
if (options.peerId) {
|
if (options.peerId) {
|
||||||
|
// @ts-ignore 'Libp2pOptions & CreateOptions' is not assignable to 'Libp2pOptions & constructorOptions'
|
||||||
return new Libp2p(options)
|
return new Libp2p(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
const peerId = await PeerId.create()
|
const peerId = await PeerId.create()
|
||||||
|
|
||||||
options.peerId = peerId
|
options.peerId = peerId
|
||||||
|
// @ts-ignore 'Libp2pOptions & CreateOptions' is not assignable to 'Libp2pOptions & constructorOptions'
|
||||||
return new Libp2p(options)
|
return new Libp2p(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +118,7 @@ class Libp2p extends EventEmitter {
|
|||||||
* Libp2p node.
|
* Libp2p node.
|
||||||
*
|
*
|
||||||
* @class
|
* @class
|
||||||
* @param {Libp2pOptions} _options
|
* @param {Libp2pOptions & constructorOptions} _options
|
||||||
*/
|
*/
|
||||||
constructor (_options) {
|
constructor (_options) {
|
||||||
super()
|
super()
|
||||||
|
Reference in New Issue
Block a user