@libp2p/interface 1.1.3 → 1.1.4

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 CHANGED
@@ -1,3 +1,5 @@
1
+ # @libp2p/interface
2
+
1
3
  [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
2
4
  [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
3
5
  [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
@@ -7,6 +9,21 @@
7
9
 
8
10
  # About
9
11
 
12
+ <!--
13
+
14
+ !IMPORTANT!
15
+
16
+ Everything in this README between "# About" and "# Install" is automatically
17
+ generated and will be overwritten the next time the doc generator is run.
18
+
19
+ To make changes to this section, please update the @packageDocumentation section
20
+ of src/index.js or src/index.ts
21
+
22
+ To experiment with formatting, please run "npm run docs" from the root of this
23
+ repo and examine the changes made.
24
+
25
+ -->
26
+
10
27
  Exports a `Libp2p` type for modules to use as a type argument.
11
28
 
12
29
  ## Example
@@ -25,14 +42,6 @@ function doSomethingWithLibp2p (node: Libp2p) {
25
42
  $ npm i @libp2p/interface
26
43
  ```
27
44
 
28
- ## Browser `<script>` tag
29
-
30
- Loading this module through a script tag will make it's exports available as `Libp2pInterface` in the global namespace.
31
-
32
- ```html
33
- <script src="https://unpkg.com/@libp2p/interface/dist/index.min.js"></script>
34
- ```
35
-
36
45
  # API Docs
37
46
 
38
47
  - <https://libp2p.github.io/js-libp2p/modules/_libp2p_interface.html>
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PInterface = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PInterface=(()=>{var n=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var g=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},I=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _(t))!L.call(e,r)&&r!==o&&n(e,r,{get:()=>t[r],enumerable:!(s=y(t,r))||s.enumerable});return e};var N=e=>I(n({},"__esModule",{value:!0}),e);var q={};g(q,{AbortError:()=>i,AggregateCodeError:()=>l,CodeError:()=>a,CustomEvent:()=>b,ERR_INVALID_MESSAGE:()=>X,ERR_INVALID_PARAMETERS:()=>G,ERR_NOT_FOUND:()=>j,ERR_TIMEOUT:()=>F,Ed25519:()=>w,FaultTolerance:()=>p,InvalidCryptoExchangeError:()=>x,InvalidCryptoTransmissionError:()=>u,KEEP_ALIVE:()=>C,RSA:()=>P,StrictNoSign:()=>k,StrictSign:()=>U,TopicValidatorResult:()=>c,TypedEventEmitter:()=>m,UnexpectedPeerError:()=>f,connectionSymbol:()=>S,contentRoutingSymbol:()=>v,isConnection:()=>T,isPeerId:()=>M,isStartable:()=>E,isTransport:()=>B,peerDiscoverySymbol:()=>D,peerIdSymbol:()=>R,peerRoutingSymbol:()=>V,secp256k1:()=>O,setMaxListeners:()=>Y,start:()=>H,stop:()=>K,transportSymbol:()=>A});var S=Symbol.for("@libp2p/connection");function T(e){return e!=null&&!!e[S]}var v=Symbol.for("@libp2p/content-routing");var w="Ed25519",P="RSA",O="secp256k1";var D=Symbol.for("@libp2p/peer-discovery");var R=Symbol.for("@libp2p/peer-id");function M(e){return e!=null&&!!e[R]}var V=Symbol.for("@libp2p/peer-routing");var C="keep-alive";var U="StrictSign",k="StrictNoSign",c;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(c||(c={}));var A=Symbol.for("@libp2p/transport");function B(e){return e!=null&&!!e[A]}var p;(function(e){e[e.FATAL_ALL=0]="FATAL_ALL",e[e.NO_FATAL=1]="NO_FATAL"})(p||(p={}));var i=class e extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.code=e.code,this.type=e.type}static code="ABORT_ERR";static type="aborted"},a=class extends Error{code;props;constructor(t,o,s){super(t),this.code=o,this.name=s?.name??"CodeError",this.props=s??{}}},l=class extends AggregateError{code;props;constructor(t,o,s,r){super(t,o),this.code=s,this.name=r?.name??"AggregateCodeError",this.props=r??{}}},f=class e extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=e.code}static code="ERR_UNEXPECTED_PEER"},x=class e extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=e.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"},u=class e extends Error{code;constructor(t="Invalid crypto transmission"){super(t),this.code=e.code}static code="ERR_INVALID_CRYPTO_TRANSMISSION"},F="ERR_TIMEOUT",G="ERR_INVALID_PARAMETERS",j="ERR_NOT_FOUND",X="ERR_INVALID_MESSAGE";var m=class extends EventTarget{#t=new Map;listenerCount(t){let o=this.#t.get(t);return o==null?0:o.length}addEventListener(t,o,s){super.addEventListener(t,o,s);let r=this.#t.get(t);r==null&&(r=[],this.#t.set(t,r)),r.push({callback:o,once:(s!==!0&&s!==!1&&s?.once)??!1})}removeEventListener(t,o,s){super.removeEventListener(t.toString(),o??null,s);let r=this.#t.get(t);r!=null&&(r=r.filter(({callback:h})=>h!==o),this.#t.set(t,r))}dispatchEvent(t){let o=super.dispatchEvent(t),s=this.#t.get(t.type);return s==null||(s=s.filter(({once:r})=>!r),this.#t.set(t.type,s)),o}safeDispatchEvent(t,o={}){return this.dispatchEvent(new b(t,o))}},d=class extends Event{detail;constructor(t,o){super(t,o),this.detail=o?.detail}},b=globalThis.CustomEvent??d;var Y=(e,...t)=>{try{[...t]}catch{}};function E(e){return e!=null&&typeof e.start=="function"&&typeof e.stop=="function"}async function H(...e){let t=[];for(let o of e)E(o)&&t.push(o);await Promise.all(t.map(async o=>{o.beforeStart!=null&&await o.beforeStart()})),await Promise.all(t.map(async o=>{await o.start()})),await Promise.all(t.map(async o=>{o.afterStart!=null&&await o.afterStart()}))}async function K(...e){let t=[];for(let o of e)E(o)&&t.push(o);await Promise.all(t.map(async o=>{o.beforeStop!=null&&await o.beforeStop()})),await Promise.all(t.map(async o=>{await o.stop()})),await Promise.all(t.map(async o=>{o.afterStop!=null&&await o.afterStop()}))}return N(q);})();
2
+ "use strict";var Libp2PInterface=(()=>{var n=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},N=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _(t))!g.call(e,r)&&r!==o&&n(e,r,{get:()=>t[r],enumerable:!(s=L(t,r))||s.enumerable});return e};var T=e=>N(n({},"__esModule",{value:!0}),e);var q={};I(q,{AbortError:()=>i,AggregateCodeError:()=>l,CodeError:()=>a,CustomEvent:()=>b,ERR_INVALID_MESSAGE:()=>Y,ERR_INVALID_PARAMETERS:()=>j,ERR_NOT_FOUND:()=>X,ERR_TIMEOUT:()=>G,Ed25519:()=>P,FaultTolerance:()=>p,InvalidCryptoExchangeError:()=>x,InvalidCryptoTransmissionError:()=>u,KEEP_ALIVE:()=>U,RSA:()=>M,StrictNoSign:()=>B,StrictSign:()=>k,TopicValidatorResult:()=>c,TypedEventEmitter:()=>d,UnexpectedPeerError:()=>f,connectionSymbol:()=>R,contentRoutingSymbol:()=>w,isConnection:()=>v,isPeerId:()=>V,isStartable:()=>S,isTransport:()=>F,peerDiscoverySymbol:()=>D,peerIdSymbol:()=>h,peerRoutingSymbol:()=>C,secp256k1:()=>O,setMaxListeners:()=>m,start:()=>H,stop:()=>K,transportSymbol:()=>A});var R=Symbol.for("@libp2p/connection");function v(e){return e!=null&&!!e[R]}var w=Symbol.for("@libp2p/content-routing");var P="Ed25519",M="RSA",O="secp256k1";var D=Symbol.for("@libp2p/peer-discovery");var h=Symbol.for("@libp2p/peer-id");function V(e){return e!=null&&!!e[h]}var C=Symbol.for("@libp2p/peer-routing");var U="keep-alive";var k="StrictSign",B="StrictNoSign",c;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(c||(c={}));var A=Symbol.for("@libp2p/transport");function F(e){return e!=null&&!!e[A]}var p;(function(e){e[e.FATAL_ALL=0]="FATAL_ALL",e[e.NO_FATAL=1]="NO_FATAL"})(p||(p={}));var i=class e extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.code=e.code,this.type=e.type}static code="ABORT_ERR";static type="aborted"},a=class extends Error{code;props;constructor(t,o,s){super(t),this.code=o,this.name=s?.name??"CodeError",this.props=s??{}}},l=class extends AggregateError{code;props;constructor(t,o,s,r){super(t,o),this.code=s,this.name=r?.name??"AggregateCodeError",this.props=r??{}}},f=class e extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=e.code}static code="ERR_UNEXPECTED_PEER"},x=class e extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=e.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"},u=class e extends Error{code;constructor(t="Invalid crypto transmission"){super(t),this.code=e.code}static code="ERR_INVALID_CRYPTO_TRANSMISSION"},G="ERR_TIMEOUT",j="ERR_INVALID_PARAMETERS",X="ERR_NOT_FOUND",Y="ERR_INVALID_MESSAGE";var m=(e,...t)=>{try{[...t]}catch{}};var d=class extends EventTarget{#t=new Map;constructor(){super(),m(1/0,this)}listenerCount(t){let o=this.#t.get(t);return o==null?0:o.length}addEventListener(t,o,s){super.addEventListener(t,o,s);let r=this.#t.get(t);r==null&&(r=[],this.#t.set(t,r)),r.push({callback:o,once:(s!==!0&&s!==!1&&s?.once)??!1})}removeEventListener(t,o,s){super.removeEventListener(t.toString(),o??null,s);let r=this.#t.get(t);r!=null&&(r=r.filter(({callback:y})=>y!==o),this.#t.set(t,r))}dispatchEvent(t){let o=super.dispatchEvent(t),s=this.#t.get(t.type);return s==null||(s=s.filter(({once:r})=>!r),this.#t.set(t.type,s)),o}safeDispatchEvent(t,o={}){return this.dispatchEvent(new b(t,o))}},E=class extends Event{detail;constructor(t,o){super(t,o),this.detail=o?.detail}},b=globalThis.CustomEvent??E;function S(e){return e!=null&&typeof e.start=="function"&&typeof e.stop=="function"}async function H(...e){let t=[];for(let o of e)S(o)&&t.push(o);await Promise.all(t.map(async o=>{o.beforeStart!=null&&await o.beforeStart()})),await Promise.all(t.map(async o=>{await o.start()})),await Promise.all(t.map(async o=>{o.afterStart!=null&&await o.afterStart()}))}async function K(...e){let t=[];for(let o of e)S(o)&&t.push(o);await Promise.all(t.map(async o=>{o.beforeStop!=null&&await o.beforeStop()})),await Promise.all(t.map(async o=>{await o.stop()})),await Promise.all(t.map(async o=>{o.afterStop!=null&&await o.afterStop()}))}return T(q);})();
3
3
  return Libp2PInterface}));
@@ -8,7 +8,7 @@ import type { CID } from 'multiformats/cid';
8
8
  *
9
9
  * @example
10
10
  *
11
- * ```js
11
+ * ```TypeScript
12
12
  * import { contentRoutingSymbol, ContentRouting } from '@libp2p/content-routing'
13
13
  *
14
14
  * class MyContentRouter implements ContentRouting {
@@ -35,7 +35,7 @@ export interface ContentRouting {
35
35
  *
36
36
  * @example
37
37
  *
38
- * ```js
38
+ * ```TypeScript
39
39
  * // ...
40
40
  * await contentRouting.provide(cid)
41
41
  * ```
@@ -46,7 +46,7 @@ export interface ContentRouting {
46
46
  *
47
47
  * @example
48
48
  *
49
- * ```js
49
+ * ```TypeScript
50
50
  * // Iterate over the providers found for the given cid
51
51
  * for await (const provider of contentRouting.findProviders(cid)) {
52
52
  * console.log(provider.id, provider.multiaddrs)
@@ -60,7 +60,7 @@ export interface ContentRouting {
60
60
  *
61
61
  * @example
62
62
  *
63
- * ```js
63
+ * ```TypeScript
64
64
  * // ...
65
65
  * const key = '/key'
66
66
  * const value = uint8ArrayFromString('oh hello there')
@@ -74,7 +74,7 @@ export interface ContentRouting {
74
74
  *
75
75
  * @example
76
76
  *
77
- * ```js
77
+ * ```TypeScript
78
78
  * // ...
79
79
  *
80
80
  * const key = '/key'
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @example
7
7
  *
8
- * ```js
8
+ * ```TypeScript
9
9
  * import { contentRoutingSymbol, ContentRouting } from '@libp2p/content-routing'
10
10
  *
11
11
  * class MyContentRouter implements ContentRouting {
@@ -26,6 +26,7 @@ export interface TypedEventTarget<EventMap extends Record<string, any>> extends
26
26
  */
27
27
  export declare class TypedEventEmitter<EventMap extends Record<string, any>> extends EventTarget implements TypedEventTarget<EventMap> {
28
28
  #private;
29
+ constructor();
29
30
  listenerCount(type: string): number;
30
31
  addEventListener<K extends keyof EventMap>(type: K, listener: EventHandler<EventMap[K]> | null, options?: boolean | AddEventListenerOptions): void;
31
32
  removeEventListener<K extends keyof EventMap>(type: K, listener?: EventHandler<EventMap[K]> | null, options?: boolean | EventListenerOptions): void;
@@ -1 +1 @@
1
- {"version":3,"file":"event-target.d.ts","sourceRoot":"","sources":["../../src/event-target.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,SAAS;IAAI,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE;AACpE,MAAM,WAAW,WAAW,CAAC,SAAS;IAAI,WAAW,EAAE,aAAa,CAAC,SAAS,CAAC,CAAA;CAAE;AACjF,MAAM,MAAM,YAAY,CAAC,SAAS,IAAI,aAAa,CAAC,SAAS,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC,CAAA;AAOvF;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB,CAAE,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,SAAQ,WAAW;IAC1F,gBAAgB,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAAG,IAAI,CAAA;IAElJ,aAAa,CAAE,IAAI,EAAE,MAAM,GAAG,MAA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AE,MAAM,QAAQ,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,OAAO,CAAA;CAC1F;AAED;;;GAGG;AACH,qBAAa,iBAAiB,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,SAAQ,WAAY,YAAW,gBAAgB,CAAC,QAAQ,CAAC;;;IAW5H,aAAa,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAUpC,gBAAgB,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAAG,IAAI;IAiBlJ,mBAAmB,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GAAG,IAAI;IAcnJ,aAAa,CAAE,KAAK,EAAE,KAAK,GAAG,OAAO;IAerC,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,EAAE,MAAM,GAAE,eAAe,CAAC,MAAM,CAAM,GAAG,OAAO;CAG/F;AAoBD,eAAO,MAAM,WAAW;;;CAAgD,CAAA"}
@@ -1,9 +1,16 @@
1
+ import { setMaxListeners } from './events.js';
1
2
  /**
2
3
  * An implementation of a typed event target
3
4
  * etc
4
5
  */
5
6
  export class TypedEventEmitter extends EventTarget {
6
7
  #listeners = new Map();
8
+ constructor() {
9
+ super();
10
+ // silence MaxListenersExceededWarning warning on Node.js, this is a red
11
+ // herring almost all of the time
12
+ setMaxListeners(Infinity, this);
13
+ }
7
14
  listenerCount(type) {
8
15
  const listeners = this.#listeners.get(type);
9
16
  if (listeners == null) {
@@ -1 +1 @@
1
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;CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,IAAI,mBAAmB,CAAA"}
@@ -120,7 +120,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
120
120
  *
121
121
  * @example
122
122
  *
123
- * ```js
123
+ * ```TypeScript
124
124
  * libp2p.addEventListener('peer:discovery', (event) => {
125
125
  * const peerInfo = event.detail
126
126
  * // ...
@@ -133,7 +133,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
133
133
  *
134
134
  * @example
135
135
  *
136
- * ```js
136
+ * ```TypeScript
137
137
  * libp2p.addEventListener('peer:connect', (event) => {
138
138
  * const peerId = event.detail
139
139
  * // ...
@@ -148,7 +148,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
148
148
  *
149
149
  * @example
150
150
  *
151
- * ```js
151
+ * ```TypeScript
152
152
  * libp2p.addEventListener('peer:disconnect', (event) => {
153
153
  * const peerId = event.detail
154
154
  * // ...
@@ -163,7 +163,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
163
163
  *
164
164
  * @example
165
165
  *
166
- * ```js
166
+ * ```TypeScript
167
167
  * libp2p.addEventListener('peer:identify', (event) => {
168
168
  * const identifyResult = event.detail
169
169
  * // ...
@@ -189,7 +189,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
189
189
  *
190
190
  * @example
191
191
  *
192
- * ```js
192
+ * ```TypeScript
193
193
  * libp2p.addEventListener('self:peer:update', (event) => {
194
194
  * const { peer } = event.detail
195
195
  * // ...
@@ -224,7 +224,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
224
224
  /**
225
225
  * This event notifies listeners that the node has started
226
226
  *
227
- * ```js
227
+ * ```TypeScript
228
228
  * libp2p.addEventListener('start', (event) => {
229
229
  * console.info(libp2p.isStarted()) // true
230
230
  * })
@@ -234,7 +234,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
234
234
  /**
235
235
  * This event notifies listeners that the node has stopped
236
236
  *
237
- * ```js
237
+ * ```TypeScript
238
238
  * libp2p.addEventListener('stop', (event) => {
239
239
  * console.info(libp2p.isStarted()) // false
240
240
  * })
@@ -248,7 +248,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
248
248
  *
249
249
  * @example
250
250
  *
251
- * ```js
251
+ * ```TypeScript
252
252
  * const node = await createLibp2p({
253
253
  * // ...other options
254
254
  * services: {
@@ -300,7 +300,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
300
300
  *
301
301
  * @example
302
302
  *
303
- * ```js
303
+ * ```TypeScript
304
304
  * console.info(libp2p.peerId)
305
305
  * // PeerId(12D3Foo...)
306
306
  * ````
@@ -312,7 +312,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
312
312
  *
313
313
  * @example
314
314
  *
315
- * ```js
315
+ * ```TypeScript
316
316
  * const peer = await libp2p.peerStore.get(peerId)
317
317
  * console.info(peer)
318
318
  * // { id: PeerId(12D3Foo...), addresses: [] ... }
@@ -325,7 +325,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
325
325
  *
326
326
  * @example
327
327
  *
328
- * ```js
328
+ * ```TypeScript
329
329
  * const peerInfo = await libp2p.peerRouting.findPeer(peerId)
330
330
  * console.info(peerInfo)
331
331
  * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
@@ -333,7 +333,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
333
333
  *
334
334
  * @example
335
335
  *
336
- * ```js
336
+ * ```TypeScript
337
337
  * for await (const peerInfo of libp2p.peerRouting.getClosestPeers(key)) {
338
338
  * console.info(peerInfo)
339
339
  * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
@@ -348,7 +348,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
348
348
  *
349
349
  * @example
350
350
  *
351
- * ```js
351
+ * ```TypeScript
352
352
  * for await (const peerInfo of libp2p.contentRouting.findProviders(cid)) {
353
353
  * console.info(peerInfo)
354
354
  * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
@@ -362,7 +362,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
362
362
  *
363
363
  * @example
364
364
  *
365
- * ```js
365
+ * ```TypeScript
366
366
  * const metric = libp2p.metrics.registerMetric({
367
367
  * 'my-metric'
368
368
  * })
@@ -390,7 +390,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
390
390
  *
391
391
  * @example
392
392
  *
393
- * ```js
393
+ * ```TypeScript
394
394
  * const listenMa = libp2p.getMultiaddrs()
395
395
  * // [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
396
396
  * ```
@@ -401,7 +401,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
401
401
  *
402
402
  * @example
403
403
  *
404
- * ```js
404
+ * ```TypeScript
405
405
  * const protocols = libp2p.getProtocols()
406
406
  * // [ '/ipfs/ping/1.0.0', '/ipfs/id/1.0.0' ]
407
407
  * ```
@@ -413,7 +413,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
413
413
  *
414
414
  * @example
415
415
  *
416
- * ```js
416
+ * ```TypeScript
417
417
  * for (const connection of libp2p.getConnections()) {
418
418
  * console.log(peerId, connection.remoteAddr.toString())
419
419
  * // Logs the PeerId string and the observed remote multiaddr of each Connection
@@ -426,7 +426,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
426
426
  *
427
427
  * @example
428
428
  *
429
- * ```js
429
+ * ```TypeScript
430
430
  * for (const pendingDial of libp2p.getDialQueue()) {
431
431
  * console.log(pendingDial)
432
432
  * }
@@ -445,7 +445,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
445
445
  *
446
446
  * @example
447
447
  *
448
- * ```js
448
+ * ```TypeScript
449
449
  * const conn = await libp2p.dial(remotePeerId)
450
450
  *
451
451
  * // create a new stream within the connection
@@ -465,7 +465,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
465
465
  *
466
466
  * @example
467
467
  *
468
- * ```js
468
+ * ```TypeScript
469
469
  * import { pipe } from 'it-pipe'
470
470
  *
471
471
  * const { stream, protocol } = await libp2p.dialProtocol(remotePeerId, protocols)
@@ -484,7 +484,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
484
484
  *
485
485
  * @example
486
486
  *
487
- * ```js
487
+ * ```TypeScript
488
488
  * await libp2p.hangUp(remotePeerId)
489
489
  * ```
490
490
  */
@@ -498,7 +498,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
498
498
  *
499
499
  * @example
500
500
  *
501
- * ```js
501
+ * ```TypeScript
502
502
  * const handler = ({ connection, stream, protocol }) => {
503
503
  * // use stream or connection according to the needs
504
504
  * }
@@ -516,7 +516,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
516
516
  *
517
517
  * @example
518
518
  *
519
- * ```js
519
+ * ```TypeScript
520
520
  * libp2p.unhandle(['/echo/1.0.0'])
521
521
  * ```
522
522
  */
@@ -527,7 +527,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
527
527
  *
528
528
  * @example
529
529
  *
530
- * ```js
530
+ * ```TypeScript
531
531
  * const id = await libp2p.register('/echo/1.0.0', {
532
532
  * onConnect: (peer, connection) => {
533
533
  * // handle connect
@@ -545,7 +545,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
545
545
  *
546
546
  * @example
547
547
  *
548
- * ```js
548
+ * ```TypeScript
549
549
  * const id = await libp2p.register(...)
550
550
  *
551
551
  * libp2p.unregister(id)
@@ -582,7 +582,7 @@ export interface NodeInfo {
582
582
  *
583
583
  * @example
584
584
  *
585
- * ```js
585
+ * ```TypeScript
586
586
  * const controller = new AbortController()
587
587
  *
588
588
  * aLongRunningOperation({
@@ -7,7 +7,7 @@ import type { PeerInfo } from '../peer-info/index.js';
7
7
  *
8
8
  * @example
9
9
  *
10
- * ```js
10
+ * ```TypeScript
11
11
  * import { peerDiscovery, PeerDiscovery } from '@libp2p/peer-discovery'
12
12
  *
13
13
  * class MyPeerDiscoverer implements PeerDiscovery {
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @example
7
7
  *
8
- * ```js
8
+ * ```TypeScript
9
9
  * import { peerDiscovery, PeerDiscovery } from '@libp2p/peer-discovery'
10
10
  *
11
11
  * class MyPeerDiscoverer implements PeerDiscovery {
@@ -8,7 +8,7 @@ import type { PeerInfo } from '../peer-info/index.js';
8
8
  *
9
9
  * @example
10
10
  *
11
- * ```js
11
+ * ```TypeScript
12
12
  * import { peerRouting, PeerRouting } from '@libp2p/peer-routing'
13
13
  *
14
14
  * class MyPeerRouter implements PeerRouting {
@@ -34,7 +34,7 @@ export interface PeerRouting {
34
34
  *
35
35
  * @example
36
36
  *
37
- * ```js
37
+ * ```TypeScript
38
38
  * // ...
39
39
  * const peer = await peerRouting.findPeer(peerId, options)
40
40
  * ```
@@ -46,7 +46,7 @@ export interface PeerRouting {
46
46
  *
47
47
  * @example
48
48
  *
49
- * ```js
49
+ * ```TypeScript
50
50
  * // Iterate over the closest peers found for the given key
51
51
  * for await (const peer of peerRouting.getClosestPeers(key)) {
52
52
  * console.log(peer.id, peer.multiaddrs)
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @example
7
7
  *
8
- * ```js
8
+ * ```TypeScript
9
9
  * import { peerRouting, PeerRouting } from '@libp2p/peer-routing'
10
10
  *
11
11
  * class MyPeerRouter implements PeerRouting {
@@ -132,7 +132,7 @@ export interface PeerStore {
132
132
  *
133
133
  * @example
134
134
  *
135
- * ```js
135
+ * ```TypeScript
136
136
  * await peerStore.forEach(peer => {
137
137
  * // ...
138
138
  * })
@@ -144,7 +144,7 @@ export interface PeerStore {
144
144
  *
145
145
  * @example
146
146
  *
147
- * ```js
147
+ * ```TypeScript
148
148
  * for (const peer of await peerStore.all()) {
149
149
  * // ...
150
150
  * }
@@ -156,7 +156,7 @@ export interface PeerStore {
156
156
  *
157
157
  * @example
158
158
  *
159
- * ```js
159
+ * ```TypeScript
160
160
  * await peerStore.addressBook.set(peerId, multiaddrs)
161
161
  * await peerStore.addressBook.get(peerId)
162
162
  * // multiaddrs[]
@@ -173,7 +173,7 @@ export interface PeerStore {
173
173
  *
174
174
  * @example
175
175
  *
176
- * ```js
176
+ * ```TypeScript
177
177
  * await peerStore.has(peerId)
178
178
  * // false
179
179
  * await peerStore.addressBook.add(peerId, multiaddrs)
@@ -187,7 +187,7 @@ export interface PeerStore {
187
187
  *
188
188
  * @example
189
189
  *
190
- * ```js
190
+ * ```TypeScript
191
191
  * const peer = await peerStore.get(peerId)
192
192
  * // { .. }
193
193
  * ```
@@ -198,7 +198,7 @@ export interface PeerStore {
198
198
  *
199
199
  * @example
200
200
  *
201
- * ```js
201
+ * ```TypeScript
202
202
  * await peerStore.save(peerId, {
203
203
  * multiaddrs
204
204
  * })
@@ -210,7 +210,7 @@ export interface PeerStore {
210
210
  *
211
211
  * @example
212
212
  *
213
- * ```js
213
+ * ```TypeScript
214
214
  * await peerStore.patch(peerId, {
215
215
  * multiaddrs
216
216
  * })
@@ -222,7 +222,7 @@ export interface PeerStore {
222
222
  *
223
223
  * @example
224
224
  *
225
- * ```js
225
+ * ```TypeScript
226
226
  * await peerStore.merge(peerId, {
227
227
  * multiaddrs
228
228
  * })
@@ -238,7 +238,7 @@ export interface PeerStore {
238
238
  *
239
239
  * @example
240
240
  *
241
- * ```js
241
+ * ```TypeScript
242
242
  * await peerStore.consumePeerRecord(buf, expectedPeer)
243
243
  * ```
244
244
  */
@@ -146,7 +146,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
146
146
  *
147
147
  * @example
148
148
  *
149
- * ```js
149
+ * ```TypeScript
150
150
  * const topic = 'topic'
151
151
  * const validateMessage = (msgTopic, msg) => {
152
152
  * const input = uint8ArrayToString(msg.data)
@@ -164,7 +164,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
164
164
  /**
165
165
  * Gets a list of topics the node is subscribed to.
166
166
  *
167
- * ```js
167
+ * ```TypeScript
168
168
  * const topics = libp2p.pubsub.getTopics()
169
169
  * ```
170
170
  */
@@ -174,7 +174,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
174
174
  *
175
175
  * @example
176
176
  *
177
- * ```js
177
+ * ```TypeScript
178
178
  * const topic = 'topic'
179
179
  * const handler = (msg) => {
180
180
  * if (msg.topic === topic) {
@@ -192,7 +192,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
192
192
  *
193
193
  * @example
194
194
  *
195
- * ```js
195
+ * ```TypeScript
196
196
  * const topic = 'topic'
197
197
  * const handler = (msg) => {
198
198
  * // msg.data - pubsub data received
@@ -208,7 +208,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
208
208
  *
209
209
  * @example
210
210
  *
211
- * ```js
211
+ * ```TypeScript
212
212
  * const peerIds = libp2p.pubsub.getSubscribers(topic)
213
213
  * ```
214
214
  */
@@ -218,7 +218,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
218
218
  *
219
219
  * @example
220
220
  *
221
- * ```js
221
+ * ```TypeScript
222
222
  * const topic = 'topic'
223
223
  * const data = uint8ArrayFromString('data')
224
224
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
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 -i @libp2p/utils",
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.1",
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.3"
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
83
+ * ```TypeScript
84
84
  * // ...
85
85
  *
86
86
  * const key = '/key'
@@ -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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
644
+ * ```TypeScript
645
645
  * const controller = new AbortController()
646
646
  *
647
647
  * aLongRunningOperation({
@@ -8,7 +8,7 @@ import type { PeerInfo } from '../peer-info/index.js'
8
8
  *
9
9
  * @example
10
10
  *
11
- * ```js
11
+ * ```TypeScript
12
12
  * import { peerDiscovery, PeerDiscovery } from '@libp2p/peer-discovery'
13
13
  *
14
14
  * class MyPeerDiscoverer implements PeerDiscovery {
@@ -9,7 +9,7 @@ import type { PeerInfo } from '../peer-info/index.js'
9
9
  *
10
10
  * @example
11
11
  *
12
- * ```js
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
- * ```js
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
- * ```js
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)
@@ -150,7 +150,7 @@ export interface PeerStore {
150
150
  *
151
151
  * @example
152
152
  *
153
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
267
+ * ```TypeScript
268
268
  * await peerStore.consumePeerRecord(buf, expectedPeer)
269
269
  * ```
270
270
  */
@@ -174,7 +174,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
174
174
  *
175
175
  * @example
176
176
  *
177
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
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
- * ```js
255
+ * ```TypeScript
256
256
  * const topic = 'topic'
257
257
  * const data = uint8ArrayFromString('data')
258
258
  *