@libp2p/interface 1.1.3 → 1.1.4-1fc929c1c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -8
- package/dist/index.min.js +1 -1
- package/dist/src/content-routing/index.d.ts +5 -5
- package/dist/src/content-routing/index.js +1 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +4 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/event-target.d.ts +1 -0
- package/dist/src/event-target.d.ts.map +1 -1
- package/dist/src/event-target.js +7 -0
- package/dist/src/event-target.js.map +1 -1
- package/dist/src/index.d.ts +26 -26
- package/dist/src/peer-discovery/index.d.ts +1 -1
- package/dist/src/peer-discovery/index.js +1 -1
- package/dist/src/peer-routing/index.d.ts +3 -3
- package/dist/src/peer-routing/index.js +1 -1
- package/dist/src/peer-store/index.d.ts +9 -9
- package/dist/src/pubsub/index.d.ts +6 -6
- package/package.json +5 -4
- package/src/content-routing/index.ts +5 -5
- package/src/errors.ts +4 -0
- package/src/event-target.ts +10 -0
- package/src/index.ts +26 -26
- package/src/peer-discovery/index.ts +1 -1
- package/src/peer-routing/index.ts +3 -3
- package/src/peer-store/index.ts +9 -9
- package/src/pubsub/index.ts +6 -6
- package/dist/typedoc-urls.json +0 -158
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/interface",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4-1fc929c1c",
|
|
4
4
|
"description": "The interface implemented by a libp2p node",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface#readme",
|
|
@@ -43,19 +43,20 @@
|
|
|
43
43
|
"scripts": {
|
|
44
44
|
"clean": "aegir clean",
|
|
45
45
|
"lint": "aegir lint",
|
|
46
|
-
"dep-check": "aegir dep-check
|
|
46
|
+
"dep-check": "aegir dep-check",
|
|
47
|
+
"doc-check": "aegir doc-check",
|
|
47
48
|
"build": "aegir build"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
51
|
"@multiformats/multiaddr": "^12.1.14",
|
|
51
52
|
"it-pushable": "^3.2.3",
|
|
52
53
|
"it-stream-types": "^2.0.1",
|
|
53
|
-
"multiformats": "^13.0
|
|
54
|
+
"multiformats": "^13.1.0",
|
|
54
55
|
"progress-events": "^1.0.0",
|
|
55
56
|
"uint8arraylist": "^2.4.8"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"aegir": "^42.2.
|
|
59
|
+
"aegir": "^42.2.4"
|
|
59
60
|
},
|
|
60
61
|
"browser": {
|
|
61
62
|
"events": "./dist/src/events.browser.js"
|
|
@@ -9,7 +9,7 @@ import type { CID } from 'multiformats/cid'
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
*
|
|
12
|
-
* ```
|
|
12
|
+
* ```TypeScript
|
|
13
13
|
* import { contentRoutingSymbol, ContentRouting } from '@libp2p/content-routing'
|
|
14
14
|
*
|
|
15
15
|
* class MyContentRouter implements ContentRouting {
|
|
@@ -38,7 +38,7 @@ export interface ContentRouting {
|
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
*
|
|
41
|
-
* ```
|
|
41
|
+
* ```TypeScript
|
|
42
42
|
* // ...
|
|
43
43
|
* await contentRouting.provide(cid)
|
|
44
44
|
* ```
|
|
@@ -50,7 +50,7 @@ export interface ContentRouting {
|
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
52
52
|
*
|
|
53
|
-
* ```
|
|
53
|
+
* ```TypeScript
|
|
54
54
|
* // Iterate over the providers found for the given cid
|
|
55
55
|
* for await (const provider of contentRouting.findProviders(cid)) {
|
|
56
56
|
* console.log(provider.id, provider.multiaddrs)
|
|
@@ -65,7 +65,7 @@ export interface ContentRouting {
|
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
67
67
|
*
|
|
68
|
-
* ```
|
|
68
|
+
* ```TypeScript
|
|
69
69
|
* // ...
|
|
70
70
|
* const key = '/key'
|
|
71
71
|
* const value = uint8ArrayFromString('oh hello there')
|
|
@@ -80,7 +80,7 @@ export interface ContentRouting {
|
|
|
80
80
|
*
|
|
81
81
|
* @example
|
|
82
82
|
*
|
|
83
|
-
* ```
|
|
83
|
+
* ```TypeScript
|
|
84
84
|
* // ...
|
|
85
85
|
*
|
|
86
86
|
* const key = '/key'
|
package/src/errors.ts
CHANGED
|
@@ -9,6 +9,7 @@ export class AbortError extends Error {
|
|
|
9
9
|
|
|
10
10
|
constructor (message: string = 'The operation was aborted') {
|
|
11
11
|
super(message)
|
|
12
|
+
this.name = 'AbortError'
|
|
12
13
|
this.code = AbortError.code
|
|
13
14
|
this.type = AbortError.type
|
|
14
15
|
}
|
|
@@ -54,6 +55,7 @@ export class UnexpectedPeerError extends Error {
|
|
|
54
55
|
|
|
55
56
|
constructor (message = 'Unexpected Peer') {
|
|
56
57
|
super(message)
|
|
58
|
+
this.name = 'UnexpectedPeerError'
|
|
57
59
|
this.code = UnexpectedPeerError.code
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -65,6 +67,7 @@ export class InvalidCryptoExchangeError extends Error {
|
|
|
65
67
|
|
|
66
68
|
constructor (message = 'Invalid crypto exchange') {
|
|
67
69
|
super(message)
|
|
70
|
+
this.name = 'InvalidCryptoExchangeError'
|
|
68
71
|
this.code = InvalidCryptoExchangeError.code
|
|
69
72
|
}
|
|
70
73
|
|
|
@@ -76,6 +79,7 @@ export class InvalidCryptoTransmissionError extends Error {
|
|
|
76
79
|
|
|
77
80
|
constructor (message = 'Invalid crypto transmission') {
|
|
78
81
|
super(message)
|
|
82
|
+
this.name = 'InvalidCryptoTransmissionError'
|
|
79
83
|
this.code = InvalidCryptoTransmissionError.code
|
|
80
84
|
}
|
|
81
85
|
|
package/src/event-target.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { setMaxListeners } from './events.js'
|
|
2
|
+
|
|
1
3
|
export interface EventCallback<EventType> { (evt: EventType): void }
|
|
2
4
|
export interface EventObject<EventType> { handleEvent: EventCallback<EventType> }
|
|
3
5
|
export type EventHandler<EventType> = EventCallback<EventType> | EventObject<EventType>
|
|
@@ -34,6 +36,14 @@ export interface TypedEventTarget <EventMap extends Record<string, any>> extends
|
|
|
34
36
|
export class TypedEventEmitter<EventMap extends Record<string, any>> extends EventTarget implements TypedEventTarget<EventMap> {
|
|
35
37
|
#listeners = new Map<any, Listener[]>()
|
|
36
38
|
|
|
39
|
+
constructor () {
|
|
40
|
+
super()
|
|
41
|
+
|
|
42
|
+
// silence MaxListenersExceededWarning warning on Node.js, this is a red
|
|
43
|
+
// herring almost all of the time
|
|
44
|
+
setMaxListeners(Infinity, this)
|
|
45
|
+
}
|
|
46
|
+
|
|
37
47
|
listenerCount (type: string): number {
|
|
38
48
|
const listeners = this.#listeners.get(type)
|
|
39
49
|
|
package/src/index.ts
CHANGED
|
@@ -136,7 +136,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
136
136
|
*
|
|
137
137
|
* @example
|
|
138
138
|
*
|
|
139
|
-
* ```
|
|
139
|
+
* ```TypeScript
|
|
140
140
|
* libp2p.addEventListener('peer:discovery', (event) => {
|
|
141
141
|
* const peerInfo = event.detail
|
|
142
142
|
* // ...
|
|
@@ -150,7 +150,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
150
150
|
*
|
|
151
151
|
* @example
|
|
152
152
|
*
|
|
153
|
-
* ```
|
|
153
|
+
* ```TypeScript
|
|
154
154
|
* libp2p.addEventListener('peer:connect', (event) => {
|
|
155
155
|
* const peerId = event.detail
|
|
156
156
|
* // ...
|
|
@@ -166,7 +166,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
166
166
|
*
|
|
167
167
|
* @example
|
|
168
168
|
*
|
|
169
|
-
* ```
|
|
169
|
+
* ```TypeScript
|
|
170
170
|
* libp2p.addEventListener('peer:disconnect', (event) => {
|
|
171
171
|
* const peerId = event.detail
|
|
172
172
|
* // ...
|
|
@@ -182,7 +182,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
182
182
|
*
|
|
183
183
|
* @example
|
|
184
184
|
*
|
|
185
|
-
* ```
|
|
185
|
+
* ```TypeScript
|
|
186
186
|
* libp2p.addEventListener('peer:identify', (event) => {
|
|
187
187
|
* const identifyResult = event.detail
|
|
188
188
|
* // ...
|
|
@@ -210,7 +210,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
210
210
|
*
|
|
211
211
|
* @example
|
|
212
212
|
*
|
|
213
|
-
* ```
|
|
213
|
+
* ```TypeScript
|
|
214
214
|
* libp2p.addEventListener('self:peer:update', (event) => {
|
|
215
215
|
* const { peer } = event.detail
|
|
216
216
|
* // ...
|
|
@@ -251,7 +251,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
251
251
|
/**
|
|
252
252
|
* This event notifies listeners that the node has started
|
|
253
253
|
*
|
|
254
|
-
* ```
|
|
254
|
+
* ```TypeScript
|
|
255
255
|
* libp2p.addEventListener('start', (event) => {
|
|
256
256
|
* console.info(libp2p.isStarted()) // true
|
|
257
257
|
* })
|
|
@@ -262,7 +262,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
262
262
|
/**
|
|
263
263
|
* This event notifies listeners that the node has stopped
|
|
264
264
|
*
|
|
265
|
-
* ```
|
|
265
|
+
* ```TypeScript
|
|
266
266
|
* libp2p.addEventListener('stop', (event) => {
|
|
267
267
|
* console.info(libp2p.isStarted()) // false
|
|
268
268
|
* })
|
|
@@ -277,7 +277,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
|
|
|
277
277
|
*
|
|
278
278
|
* @example
|
|
279
279
|
*
|
|
280
|
-
* ```
|
|
280
|
+
* ```TypeScript
|
|
281
281
|
* const node = await createLibp2p({
|
|
282
282
|
* // ...other options
|
|
283
283
|
* services: {
|
|
@@ -336,7 +336,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
336
336
|
*
|
|
337
337
|
* @example
|
|
338
338
|
*
|
|
339
|
-
* ```
|
|
339
|
+
* ```TypeScript
|
|
340
340
|
* console.info(libp2p.peerId)
|
|
341
341
|
* // PeerId(12D3Foo...)
|
|
342
342
|
* ````
|
|
@@ -349,7 +349,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
349
349
|
*
|
|
350
350
|
* @example
|
|
351
351
|
*
|
|
352
|
-
* ```
|
|
352
|
+
* ```TypeScript
|
|
353
353
|
* const peer = await libp2p.peerStore.get(peerId)
|
|
354
354
|
* console.info(peer)
|
|
355
355
|
* // { id: PeerId(12D3Foo...), addresses: [] ... }
|
|
@@ -363,7 +363,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
363
363
|
*
|
|
364
364
|
* @example
|
|
365
365
|
*
|
|
366
|
-
* ```
|
|
366
|
+
* ```TypeScript
|
|
367
367
|
* const peerInfo = await libp2p.peerRouting.findPeer(peerId)
|
|
368
368
|
* console.info(peerInfo)
|
|
369
369
|
* // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
|
|
@@ -371,7 +371,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
371
371
|
*
|
|
372
372
|
* @example
|
|
373
373
|
*
|
|
374
|
-
* ```
|
|
374
|
+
* ```TypeScript
|
|
375
375
|
* for await (const peerInfo of libp2p.peerRouting.getClosestPeers(key)) {
|
|
376
376
|
* console.info(peerInfo)
|
|
377
377
|
* // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
|
|
@@ -387,7 +387,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
387
387
|
*
|
|
388
388
|
* @example
|
|
389
389
|
*
|
|
390
|
-
* ```
|
|
390
|
+
* ```TypeScript
|
|
391
391
|
* for await (const peerInfo of libp2p.contentRouting.findProviders(cid)) {
|
|
392
392
|
* console.info(peerInfo)
|
|
393
393
|
* // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
|
|
@@ -402,7 +402,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
402
402
|
*
|
|
403
403
|
* @example
|
|
404
404
|
*
|
|
405
|
-
* ```
|
|
405
|
+
* ```TypeScript
|
|
406
406
|
* const metric = libp2p.metrics.registerMetric({
|
|
407
407
|
* 'my-metric'
|
|
408
408
|
* })
|
|
@@ -433,7 +433,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
433
433
|
*
|
|
434
434
|
* @example
|
|
435
435
|
*
|
|
436
|
-
* ```
|
|
436
|
+
* ```TypeScript
|
|
437
437
|
* const listenMa = libp2p.getMultiaddrs()
|
|
438
438
|
* // [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
|
|
439
439
|
* ```
|
|
@@ -445,7 +445,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
445
445
|
*
|
|
446
446
|
* @example
|
|
447
447
|
*
|
|
448
|
-
* ```
|
|
448
|
+
* ```TypeScript
|
|
449
449
|
* const protocols = libp2p.getProtocols()
|
|
450
450
|
* // [ '/ipfs/ping/1.0.0', '/ipfs/id/1.0.0' ]
|
|
451
451
|
* ```
|
|
@@ -458,7 +458,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
458
458
|
*
|
|
459
459
|
* @example
|
|
460
460
|
*
|
|
461
|
-
* ```
|
|
461
|
+
* ```TypeScript
|
|
462
462
|
* for (const connection of libp2p.getConnections()) {
|
|
463
463
|
* console.log(peerId, connection.remoteAddr.toString())
|
|
464
464
|
* // Logs the PeerId string and the observed remote multiaddr of each Connection
|
|
@@ -472,7 +472,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
472
472
|
*
|
|
473
473
|
* @example
|
|
474
474
|
*
|
|
475
|
-
* ```
|
|
475
|
+
* ```TypeScript
|
|
476
476
|
* for (const pendingDial of libp2p.getDialQueue()) {
|
|
477
477
|
* console.log(pendingDial)
|
|
478
478
|
* }
|
|
@@ -493,7 +493,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
493
493
|
*
|
|
494
494
|
* @example
|
|
495
495
|
*
|
|
496
|
-
* ```
|
|
496
|
+
* ```TypeScript
|
|
497
497
|
* const conn = await libp2p.dial(remotePeerId)
|
|
498
498
|
*
|
|
499
499
|
* // create a new stream within the connection
|
|
@@ -514,7 +514,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
514
514
|
*
|
|
515
515
|
* @example
|
|
516
516
|
*
|
|
517
|
-
* ```
|
|
517
|
+
* ```TypeScript
|
|
518
518
|
* import { pipe } from 'it-pipe'
|
|
519
519
|
*
|
|
520
520
|
* const { stream, protocol } = await libp2p.dialProtocol(remotePeerId, protocols)
|
|
@@ -534,7 +534,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
534
534
|
*
|
|
535
535
|
* @example
|
|
536
536
|
*
|
|
537
|
-
* ```
|
|
537
|
+
* ```TypeScript
|
|
538
538
|
* await libp2p.hangUp(remotePeerId)
|
|
539
539
|
* ```
|
|
540
540
|
*/
|
|
@@ -549,7 +549,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
549
549
|
*
|
|
550
550
|
* @example
|
|
551
551
|
*
|
|
552
|
-
* ```
|
|
552
|
+
* ```TypeScript
|
|
553
553
|
* const handler = ({ connection, stream, protocol }) => {
|
|
554
554
|
* // use stream or connection according to the needs
|
|
555
555
|
* }
|
|
@@ -568,7 +568,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
568
568
|
*
|
|
569
569
|
* @example
|
|
570
570
|
*
|
|
571
|
-
* ```
|
|
571
|
+
* ```TypeScript
|
|
572
572
|
* libp2p.unhandle(['/echo/1.0.0'])
|
|
573
573
|
* ```
|
|
574
574
|
*/
|
|
@@ -580,7 +580,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
580
580
|
*
|
|
581
581
|
* @example
|
|
582
582
|
*
|
|
583
|
-
* ```
|
|
583
|
+
* ```TypeScript
|
|
584
584
|
* const id = await libp2p.register('/echo/1.0.0', {
|
|
585
585
|
* onConnect: (peer, connection) => {
|
|
586
586
|
* // handle connect
|
|
@@ -599,7 +599,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
|
|
|
599
599
|
*
|
|
600
600
|
* @example
|
|
601
601
|
*
|
|
602
|
-
* ```
|
|
602
|
+
* ```TypeScript
|
|
603
603
|
* const id = await libp2p.register(...)
|
|
604
604
|
*
|
|
605
605
|
* libp2p.unregister(id)
|
|
@@ -641,7 +641,7 @@ export interface NodeInfo {
|
|
|
641
641
|
*
|
|
642
642
|
* @example
|
|
643
643
|
*
|
|
644
|
-
* ```
|
|
644
|
+
* ```TypeScript
|
|
645
645
|
* const controller = new AbortController()
|
|
646
646
|
*
|
|
647
647
|
* aLongRunningOperation({
|
|
@@ -9,7 +9,7 @@ import type { PeerInfo } from '../peer-info/index.js'
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
*
|
|
12
|
-
* ```
|
|
12
|
+
* ```TypeScript
|
|
13
13
|
* import { peerRouting, PeerRouting } from '@libp2p/peer-routing'
|
|
14
14
|
*
|
|
15
15
|
* class MyPeerRouter implements PeerRouting {
|
|
@@ -37,7 +37,7 @@ export interface PeerRouting {
|
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
*
|
|
40
|
-
* ```
|
|
40
|
+
* ```TypeScript
|
|
41
41
|
* // ...
|
|
42
42
|
* const peer = await peerRouting.findPeer(peerId, options)
|
|
43
43
|
* ```
|
|
@@ -50,7 +50,7 @@ export interface PeerRouting {
|
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
52
52
|
*
|
|
53
|
-
* ```
|
|
53
|
+
* ```TypeScript
|
|
54
54
|
* // Iterate over the closest peers found for the given key
|
|
55
55
|
* for await (const peer of peerRouting.getClosestPeers(key)) {
|
|
56
56
|
* console.log(peer.id, peer.multiaddrs)
|
package/src/peer-store/index.ts
CHANGED
|
@@ -150,7 +150,7 @@ export interface PeerStore {
|
|
|
150
150
|
*
|
|
151
151
|
* @example
|
|
152
152
|
*
|
|
153
|
-
* ```
|
|
153
|
+
* ```TypeScript
|
|
154
154
|
* await peerStore.forEach(peer => {
|
|
155
155
|
* // ...
|
|
156
156
|
* })
|
|
@@ -163,7 +163,7 @@ export interface PeerStore {
|
|
|
163
163
|
*
|
|
164
164
|
* @example
|
|
165
165
|
*
|
|
166
|
-
* ```
|
|
166
|
+
* ```TypeScript
|
|
167
167
|
* for (const peer of await peerStore.all()) {
|
|
168
168
|
* // ...
|
|
169
169
|
* }
|
|
@@ -176,7 +176,7 @@ export interface PeerStore {
|
|
|
176
176
|
*
|
|
177
177
|
* @example
|
|
178
178
|
*
|
|
179
|
-
* ```
|
|
179
|
+
* ```TypeScript
|
|
180
180
|
* await peerStore.addressBook.set(peerId, multiaddrs)
|
|
181
181
|
* await peerStore.addressBook.get(peerId)
|
|
182
182
|
* // multiaddrs[]
|
|
@@ -194,7 +194,7 @@ export interface PeerStore {
|
|
|
194
194
|
*
|
|
195
195
|
* @example
|
|
196
196
|
*
|
|
197
|
-
* ```
|
|
197
|
+
* ```TypeScript
|
|
198
198
|
* await peerStore.has(peerId)
|
|
199
199
|
* // false
|
|
200
200
|
* await peerStore.addressBook.add(peerId, multiaddrs)
|
|
@@ -209,7 +209,7 @@ export interface PeerStore {
|
|
|
209
209
|
*
|
|
210
210
|
* @example
|
|
211
211
|
*
|
|
212
|
-
* ```
|
|
212
|
+
* ```TypeScript
|
|
213
213
|
* const peer = await peerStore.get(peerId)
|
|
214
214
|
* // { .. }
|
|
215
215
|
* ```
|
|
@@ -221,7 +221,7 @@ export interface PeerStore {
|
|
|
221
221
|
*
|
|
222
222
|
* @example
|
|
223
223
|
*
|
|
224
|
-
* ```
|
|
224
|
+
* ```TypeScript
|
|
225
225
|
* await peerStore.save(peerId, {
|
|
226
226
|
* multiaddrs
|
|
227
227
|
* })
|
|
@@ -234,7 +234,7 @@ export interface PeerStore {
|
|
|
234
234
|
*
|
|
235
235
|
* @example
|
|
236
236
|
*
|
|
237
|
-
* ```
|
|
237
|
+
* ```TypeScript
|
|
238
238
|
* await peerStore.patch(peerId, {
|
|
239
239
|
* multiaddrs
|
|
240
240
|
* })
|
|
@@ -247,7 +247,7 @@ export interface PeerStore {
|
|
|
247
247
|
*
|
|
248
248
|
* @example
|
|
249
249
|
*
|
|
250
|
-
* ```
|
|
250
|
+
* ```TypeScript
|
|
251
251
|
* await peerStore.merge(peerId, {
|
|
252
252
|
* multiaddrs
|
|
253
253
|
* })
|
|
@@ -264,7 +264,7 @@ export interface PeerStore {
|
|
|
264
264
|
*
|
|
265
265
|
* @example
|
|
266
266
|
*
|
|
267
|
-
* ```
|
|
267
|
+
* ```TypeScript
|
|
268
268
|
* await peerStore.consumePeerRecord(buf, expectedPeer)
|
|
269
269
|
* ```
|
|
270
270
|
*/
|
package/src/pubsub/index.ts
CHANGED
|
@@ -174,7 +174,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
174
174
|
*
|
|
175
175
|
* @example
|
|
176
176
|
*
|
|
177
|
-
* ```
|
|
177
|
+
* ```TypeScript
|
|
178
178
|
* const topic = 'topic'
|
|
179
179
|
* const validateMessage = (msgTopic, msg) => {
|
|
180
180
|
* const input = uint8ArrayToString(msg.data)
|
|
@@ -194,7 +194,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
194
194
|
/**
|
|
195
195
|
* Gets a list of topics the node is subscribed to.
|
|
196
196
|
*
|
|
197
|
-
* ```
|
|
197
|
+
* ```TypeScript
|
|
198
198
|
* const topics = libp2p.pubsub.getTopics()
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
@@ -205,7 +205,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
205
205
|
*
|
|
206
206
|
* @example
|
|
207
207
|
*
|
|
208
|
-
* ```
|
|
208
|
+
* ```TypeScript
|
|
209
209
|
* const topic = 'topic'
|
|
210
210
|
* const handler = (msg) => {
|
|
211
211
|
* if (msg.topic === topic) {
|
|
@@ -224,7 +224,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
224
224
|
*
|
|
225
225
|
* @example
|
|
226
226
|
*
|
|
227
|
-
* ```
|
|
227
|
+
* ```TypeScript
|
|
228
228
|
* const topic = 'topic'
|
|
229
229
|
* const handler = (msg) => {
|
|
230
230
|
* // msg.data - pubsub data received
|
|
@@ -241,7 +241,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
241
241
|
*
|
|
242
242
|
* @example
|
|
243
243
|
*
|
|
244
|
-
* ```
|
|
244
|
+
* ```TypeScript
|
|
245
245
|
* const peerIds = libp2p.pubsub.getSubscribers(topic)
|
|
246
246
|
* ```
|
|
247
247
|
*/
|
|
@@ -252,7 +252,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
|
|
|
252
252
|
*
|
|
253
253
|
* @example
|
|
254
254
|
*
|
|
255
|
-
* ```
|
|
255
|
+
* ```TypeScript
|
|
256
256
|
* const topic = 'topic'
|
|
257
257
|
* const data = uint8ArrayFromString('data')
|
|
258
258
|
*
|