@libp2p/interface 2.9.0 → 2.10.0-aa25d38ab

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.
Files changed (59) hide show
  1. package/dist/index.min.js +2 -1
  2. package/dist/index.min.js.map +7 -0
  3. package/dist/src/content-routing.d.ts +2 -2
  4. package/dist/src/content-routing.d.ts.map +1 -1
  5. package/dist/src/content-routing.js +1 -1
  6. package/dist/src/errors.d.ts +8 -1
  7. package/dist/src/errors.d.ts.map +1 -1
  8. package/dist/src/errors.js +11 -1
  9. package/dist/src/errors.js.map +1 -1
  10. package/dist/src/event-target.d.ts +2 -2
  11. package/dist/src/event-target.d.ts.map +1 -1
  12. package/dist/src/event-target.js +0 -1
  13. package/dist/src/event-target.js.map +1 -1
  14. package/dist/src/events.d.ts +0 -1
  15. package/dist/src/events.d.ts.map +1 -1
  16. package/dist/src/index.d.ts +40 -3
  17. package/dist/src/index.d.ts.map +1 -1
  18. package/dist/src/index.js.map +1 -1
  19. package/dist/src/metrics.d.ts +1 -2
  20. package/dist/src/metrics.d.ts.map +1 -1
  21. package/dist/src/peer-discovery.d.ts +6 -1
  22. package/dist/src/peer-discovery.d.ts.map +1 -1
  23. package/dist/src/peer-routing.d.ts +3 -3
  24. package/dist/src/peer-routing.d.ts.map +1 -1
  25. package/dist/src/peer-routing.js +2 -2
  26. package/dist/src/peer-store.d.ts +26 -0
  27. package/dist/src/peer-store.d.ts.map +1 -1
  28. package/dist/src/peer-store.js.map +1 -1
  29. package/dist/src/pubsub.d.ts +13 -10
  30. package/dist/src/pubsub.d.ts.map +1 -1
  31. package/dist/src/pubsub.js +8 -8
  32. package/dist/src/pubsub.js.map +1 -1
  33. package/dist/src/record.d.ts +25 -1
  34. package/dist/src/record.d.ts.map +1 -1
  35. package/dist/src/startable.d.ts +52 -1
  36. package/dist/src/startable.d.ts.map +1 -1
  37. package/dist/src/startable.js +51 -0
  38. package/dist/src/startable.js.map +1 -1
  39. package/dist/src/topology.d.ts +2 -1
  40. package/dist/src/topology.d.ts.map +1 -1
  41. package/dist/src/transport.d.ts +40 -4
  42. package/dist/src/transport.d.ts.map +1 -1
  43. package/dist/src/transport.js +3 -0
  44. package/dist/src/transport.js.map +1 -1
  45. package/package.json +4 -11
  46. package/src/content-routing.ts +2 -2
  47. package/src/errors.ts +13 -1
  48. package/src/event-target.ts +2 -2
  49. package/src/index.ts +40 -3
  50. package/src/metrics.ts +1 -1
  51. package/src/peer-discovery.ts +6 -1
  52. package/src/peer-routing.ts +3 -3
  53. package/src/peer-store.ts +27 -0
  54. package/src/pubsub.ts +13 -10
  55. package/src/record.ts +30 -1
  56. package/src/startable.ts +52 -1
  57. package/src/topology.ts +2 -1
  58. package/src/transport.ts +47 -5
  59. package/dist/typedoc-urls.json +0 -221
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACxF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAErE,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAA;IAExB;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;IAE3B;;;OAGG;IACH,OAAO,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,QAAS,SAAQ,gBAAgB,CAAC,cAAc,CAAC;IAChE;;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C,GACpD,aAAa,CAAC,uCAAuC,CAAC,CAAA;AAEtD,MAAM,MAAM,+BAA+B,GAC3C,aAAa,CAAC,sCAAsC,CAAC,GACrD,aAAa,CAAC,wCAAwC,CAAC,CAAA;AAEvD,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,mBAAmB,EAAE,IAAI,CAAC,EAAE,eAAe,CAAC,+BAA+B,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE1H;;;OAGG;IACH,cAAc,CAAC,MAAM,EAAE,mBAAmB,EAAE,IAAI,CAAC,EAAE,eAAe,CAAC,8BAA8B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAElH;;;;;;;OAOG;IACH,wBAAwB,CAAE,MAAM,EAAE,WAAW,GAAG,eAAe,CAAA;IAE/D;;OAEG;IACH,eAAe,IAAK,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;IAEnD;;OAEG;IACH,uBAAuB,IAAK,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;CAC7D"}
@@ -1,4 +1,7 @@
1
1
  export const transportSymbol = Symbol.for('@libp2p/transport');
2
+ /**
3
+ * Used to disambiguate transport implementations
4
+ */
2
5
  export function isTransport(other) {
3
6
  return other != null && Boolean(other[transportSymbol]);
4
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAgDA,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAyD9D,MAAM,UAAU,WAAW,CAAE,KAAU;IACrC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAA;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB;;OAEG;IACH,6DAAa,CAAA;IAEb;;OAEG;IACH,2DAAQ,CAAA;AACV,CAAC,EAVW,cAAc,KAAd,cAAc,QAUzB"}
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAgDA,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AA8D9D;;GAEG;AACH,MAAM,UAAU,WAAW,CAAE,KAAW;IACtC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAA;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB;;OAEG;IACH,6DAAa,CAAA;IAEb;;OAEG;IACH,2DAAQ,CAAA;AACV,CAAC,EAVW,cAAc,KAAd,cAAc,QAUzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface",
3
- "version": "2.9.0",
3
+ "version": "2.10.0-aa25d38ab",
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",
@@ -33,13 +33,6 @@
33
33
  "import": "./dist/src/index.js"
34
34
  }
35
35
  },
36
- "eslintConfig": {
37
- "extends": "ipfs",
38
- "parserOptions": {
39
- "project": true,
40
- "sourceType": "module"
41
- }
42
- },
43
36
  "scripts": {
44
37
  "clean": "aegir clean",
45
38
  "lint": "aegir lint",
@@ -48,15 +41,15 @@
48
41
  "build": "aegir build"
49
42
  },
50
43
  "dependencies": {
51
- "@multiformats/multiaddr": "^12.3.3",
44
+ "@multiformats/multiaddr": "^12.4.0",
52
45
  "it-pushable": "^3.2.3",
53
46
  "it-stream-types": "^2.0.2",
54
- "multiformats": "^13.3.1",
47
+ "multiformats": "^13.3.4",
55
48
  "progress-events": "^1.0.1",
56
49
  "uint8arraylist": "^2.4.8"
57
50
  },
58
51
  "devDependencies": {
59
- "aegir": "^45.1.1"
52
+ "aegir": "^47.0.6"
60
53
  },
61
54
  "browser": {
62
55
  "./dist/src/events.js": "./dist/src/events.browser.js"
@@ -4,7 +4,7 @@ import type { CID } from 'multiformats/cid'
4
4
 
5
5
  /**
6
6
  * Any object that implements this Symbol as a property should return a
7
- * ContentRouting instance as the property value, similar to how
7
+ * Partial<ContentRouting> instance as the property value, similar to how
8
8
  * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.
9
9
  *
10
10
  * @example
@@ -28,7 +28,7 @@ export const contentRoutingSymbol = Symbol.for('@libp2p/content-routing')
28
28
  * interested callers.
29
29
  */
30
30
  export interface ContentRoutingProvider {
31
- [contentRoutingSymbol]: ContentRouting
31
+ [contentRoutingSymbol]: Partial<ContentRouting>
32
32
  }
33
33
 
34
34
  export interface ContentRouting {
package/src/errors.ts CHANGED
@@ -353,7 +353,7 @@ export class TooManyOutboundProtocolStreamsError extends Error {
353
353
  }
354
354
 
355
355
  /**
356
- * Thrown when and attempt to operate on an unsupported key was made
356
+ * Thrown when an attempt to operate on an unsupported key was made
357
357
  */
358
358
  export class UnsupportedKeyTypeError extends Error {
359
359
  static name = 'UnsupportedKeyTypeError'
@@ -363,3 +363,15 @@ export class UnsupportedKeyTypeError extends Error {
363
363
  this.name = 'UnsupportedKeyTypeError'
364
364
  }
365
365
  }
366
+
367
+ /**
368
+ * Thrown when an operation has not been implemented
369
+ */
370
+ export class NotImplementedError extends Error {
371
+ static name = 'NotImplementedError'
372
+
373
+ constructor (message = 'Not implemented') {
374
+ super(message)
375
+ this.name = 'NotImplementedError'
376
+ }
377
+ }
@@ -10,7 +10,8 @@ interface Listener {
10
10
  }
11
11
 
12
12
  /**
13
- * Adds types to the EventTarget class. Hopefully this won't be necessary forever.
13
+ * Adds types to the EventTarget class. Hopefully this won't be necessary
14
+ * forever.
14
15
  *
15
16
  * https://github.com/microsoft/TypeScript/issues/28357
16
17
  * https://github.com/microsoft/TypeScript/issues/43477
@@ -31,7 +32,6 @@ export interface TypedEventTarget <EventMap extends Record<string, any>> extends
31
32
 
32
33
  /**
33
34
  * An implementation of a typed event target
34
- * etc
35
35
  */
36
36
  export class TypedEventEmitter<EventMap extends Record<string, any>> extends EventTarget implements TypedEventTarget<EventMap> {
37
37
  readonly #listeners = new Map<any, Listener[]>()
package/src/index.ts CHANGED
@@ -53,6 +53,9 @@ export interface SignedPeerRecord {
53
53
  seq: bigint
54
54
  }
55
55
 
56
+ /**
57
+ * A certificate that can be used to secure connections
58
+ */
56
59
  export interface TLSCertificate {
57
60
  /**
58
61
  * The private key that corresponds to the certificate in PEM format
@@ -130,9 +133,43 @@ export interface Logger {
130
133
  }
131
134
 
132
135
  /**
133
- * Peer logger component for libp2p
136
+ * Peer logger component for libp2p. This can be used to create loggers that are
137
+ * scoped to individual system components or services.
138
+ *
139
+ * To see logs, run your app with `DEBUG` set as an env var or for browsers, in
140
+ * `localStorage`:
141
+ *
142
+ * ```console
143
+ * $ DEBUG=libp2p* node index.js
144
+ * libp2p:my-service hello +0ms
145
+ * ```
134
146
  */
135
147
  export interface ComponentLogger {
148
+ /**
149
+ * Returns a logger for the specified component.
150
+ *
151
+ * @example
152
+ *
153
+ * ```TypeScript
154
+ * import { ComponentLogger, Logger } from '@libp2p/interface'
155
+ *
156
+ * interface MyServiceComponents {
157
+ * logger: ComponentLogger
158
+ * }
159
+ *
160
+ * class MyService {
161
+ * private readonly log: Logger
162
+ *
163
+ * constructor (components) {
164
+ * this.log = components.logger.forComponent('libp2p:my-service')
165
+ *
166
+ * this.log('hello')
167
+ * // logs:
168
+ * // libp2p:my-service hello +0ms
169
+ * }
170
+ * }
171
+ * ```
172
+ */
136
173
  forComponent(name: string): Logger
137
174
  }
138
175
 
@@ -299,7 +336,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
299
336
  * })
300
337
  * ```
301
338
  */
302
- 'start': CustomEvent<Libp2p<T>>
339
+ start: CustomEvent<Libp2p<T>>
303
340
 
304
341
  /**
305
342
  * This event notifies listeners that the node has stopped
@@ -310,7 +347,7 @@ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
310
347
  * })
311
348
  * ```
312
349
  */
313
- 'stop': CustomEvent<Libp2p<T>>
350
+ stop: CustomEvent<Libp2p<T>>
314
351
  }
315
352
 
316
353
  /**
package/src/metrics.ts CHANGED
@@ -510,7 +510,7 @@ export interface Metrics {
510
510
  /**
511
511
  * Infer the yielded type of an (async)iterable
512
512
  */
513
- type YieldType<T extends AsyncIterator<any> | Iterator<any>> = T extends AsyncIterator<infer Y> ? Y : T extends Iterator<infer Y, any, any> ? Y : never
513
+ export type YieldType<T extends AsyncIterator<any> | Iterator<any>> = T extends AsyncIterator<infer Y> ? Y : T extends Iterator<infer Y, any, any> ? Y : never
514
514
 
515
515
  export type TraceAttributes = Record<string, number | string | boolean | number[] | string[] | boolean[]>
516
516
 
@@ -31,7 +31,12 @@ export interface PeerDiscoveryProvider {
31
31
  }
32
32
 
33
33
  export interface PeerDiscoveryEvents {
34
- 'peer': CustomEvent<PeerInfo>
34
+ peer: CustomEvent<PeerInfo>
35
35
  }
36
36
 
37
+ /**
38
+ * A class that implements the `PeerDiscovery` interface uses an
39
+ * implementation-specific method to discover peers. These peers are then added
40
+ * to the peer store for use by other system components and services.
41
+ */
37
42
  export interface PeerDiscovery extends TypedEventTarget<PeerDiscoveryEvents> {}
@@ -4,8 +4,8 @@ import type { PeerInfo } from './peer-info.js'
4
4
 
5
5
  /**
6
6
  * Any object that implements this Symbol as a property should return a
7
- * PeerRouting instance as the property value, similar to how
8
- * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.
7
+ * PeerRouting instance as the property value, similar to how `Symbol.Iterable`
8
+ * can be used to return an `Iterable` from an `Iterator`.
9
9
  *
10
10
  * @example
11
11
  *
@@ -28,7 +28,7 @@ export const peerRoutingSymbol = Symbol.for('@libp2p/peer-routing')
28
28
  * interested callers.
29
29
  */
30
30
  export interface PeerRoutingProvider {
31
- [peerRoutingSymbol]: PeerRouting
31
+ [peerRoutingSymbol]: Partial<PeerRouting>
32
32
  }
33
33
 
34
34
  export interface PeerRouting {
package/src/peer-store.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { PublicKey } from './keys.js'
2
2
  import type { PeerId } from './peer-id.js'
3
+ import type { PeerInfo } from './peer-info.js'
3
4
  import type { Multiaddr } from '@multiformats/multiaddr'
4
5
 
5
6
  /**
@@ -229,6 +230,32 @@ export interface PeerStore {
229
230
  */
230
231
  get(peerId: PeerId): Promise<Peer>
231
232
 
233
+ /**
234
+ * Returns a PeerInfo object for the passed peer id. This is similar to `get`
235
+ * except the returned value contains fewer fields and is often used to
236
+ * exchange peer information with other systems.
237
+ *
238
+ * The returned object can be passed to `JSON.stringify` without any
239
+ * additional processing.
240
+ *
241
+ * @see https://docs.libp2p.io/concepts/fundamentals/peers/#peer-info
242
+ *
243
+ * @example
244
+ *
245
+ * ```TypeScript
246
+ * const peerInfo = await peerStore.getInfo(peerId)
247
+ *
248
+ * console.info(JSON.stringify(peerInfo))
249
+ * // {
250
+ * // id: 'peerId'
251
+ * // multiaddrs: [
252
+ * // '...'
253
+ * // ]
254
+ * // }
255
+ * ```
256
+ */
257
+ getInfo (peerId: PeerId): Promise<PeerInfo>
258
+
232
259
  /**
233
260
  * Adds a peer to the peer store, overwriting any existing data
234
261
  *
package/src/pubsub.ts CHANGED
@@ -7,23 +7,23 @@ import type { Uint8ArrayList } from 'uint8arraylist'
7
7
 
8
8
  /**
9
9
  * On the producing side:
10
- * * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
10
+ * - Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
11
11
  *
12
12
  * On the consuming side:
13
- * * Enforce the fields to be present, reject otherwise.
14
- * * Propagate only if the fields are valid and signature can be verified, reject otherwise.
13
+ * - Enforce the fields to be present, reject otherwise.
14
+ * - Propagate only if the fields are valid and signature can be verified, reject otherwise.
15
15
  */
16
16
  export const StrictSign = 'StrictSign'
17
17
 
18
18
  /**
19
19
  * On the producing side:
20
- * * Build messages without the signature, key, from and seqno fields.
21
- * * The corresponding protobuf key-value pairs are absent from the marshaled message, not just empty.
20
+ * - Build messages without the signature, key, from and seqno fields.
21
+ * - The corresponding protobuf key-value pairs are absent from the marshaled message, not just empty.
22
22
  *
23
23
  * On the consuming side:
24
- * * Enforce the fields to be absent, reject otherwise.
25
- * * Propagate only if the fields are absent, reject otherwise.
26
- * * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
24
+ * - Enforce the fields to be absent, reject otherwise.
25
+ * - Propagate only if the fields are absent, reject otherwise.
26
+ * - A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
27
27
  */
28
28
  export const StrictNoSign = 'StrictNoSign'
29
29
 
@@ -127,7 +127,7 @@ export interface SubscriptionChangeData {
127
127
 
128
128
  export interface PubSubEvents {
129
129
  'subscription-change': CustomEvent<SubscriptionChangeData>
130
- 'message': CustomEvent<Message>
130
+ message: CustomEvent<Message>
131
131
  }
132
132
 
133
133
  export interface PublishResult {
@@ -153,6 +153,9 @@ export interface TopicValidatorFn {
153
153
  (peer: PeerId, message: Message): TopicValidatorResult | Promise<TopicValidatorResult>
154
154
  }
155
155
 
156
+ /**
157
+ * @deprecated This will be removed from `@libp2p/interface` in a future release, pubsub implementations should declare their own types
158
+ */
156
159
  export interface PubSub<Events extends Record<string, any> = PubSubEvents> extends TypedEventTarget<Events> {
157
160
  /**
158
161
  * The global signature policy controls whether or not we sill send and receive
@@ -266,7 +269,7 @@ export interface PubSub<Events extends Record<string, any> = PubSubEvents> exten
266
269
  export interface PeerStreamEvents {
267
270
  'stream:inbound': CustomEvent<never>
268
271
  'stream:outbound': CustomEvent<never>
269
- 'close': CustomEvent<never>
272
+ close: CustomEvent<never>
270
273
  }
271
274
 
272
275
  /**
package/src/record.ts CHANGED
@@ -23,13 +23,42 @@ export interface Record {
23
23
  equals(other: Record): boolean
24
24
  }
25
25
 
26
+ /**
27
+ * A message with a signed payload.
28
+ */
26
29
  export interface Envelope {
30
+ /**
31
+ * The public key of the keypair used to sign the payload
32
+ */
27
33
  publicKey: PublicKey
34
+
35
+ /**
36
+ * How the payload should be interpreted
37
+ */
28
38
  payloadType: Uint8Array | Uint8ArrayList
39
+
40
+ /**
41
+ * The contents of the envelope
42
+ */
29
43
  payload: Uint8Array
44
+
45
+ /**
46
+ * A signature that can be used to verify the payload is intact
47
+ */
30
48
  signature: Uint8Array | Uint8ArrayList
31
49
 
50
+ /**
51
+ * Serialize the envelope to a binary format
52
+ */
32
53
  marshal(): Uint8Array
54
+
55
+ /**
56
+ * Use the public key to validate that the payload is intact
57
+ */
33
58
  validate(domain: string): Promise<boolean>
34
- equals(other: Envelope): boolean
59
+
60
+ /**
61
+ * Returns true if this envelope has equivalency with the passed object
62
+ */
63
+ equals(other?: Envelope): boolean
35
64
  }
package/src/startable.ts CHANGED
@@ -45,10 +45,37 @@ export interface Startable {
45
45
  afterStop?(): void | Promise<void>
46
46
  }
47
47
 
48
- export function isStartable (obj: any): obj is Startable {
48
+ /**
49
+ * Returns `true` if the object has type overlap with `Startable`
50
+ */
51
+ export function isStartable (obj?: any): obj is Startable {
49
52
  return obj != null && typeof obj.start === 'function' && typeof obj.stop === 'function'
50
53
  }
51
54
 
55
+ /**
56
+ * A function that can be used to start and objects passed to it. This checks
57
+ * that an object is startable before invoking its lifecycle methods so it is
58
+ * safe to pass non-`Startable`s in.
59
+ *
60
+ * @example
61
+ *
62
+ * ```TypeScript
63
+ * import { start } from '@libp2p/interface'
64
+ * import type { Startable } from '@libp2p/interface'
65
+ *
66
+ * const startable: Startable = {
67
+ * start: () => {},
68
+ * stop: () => {}
69
+ * }
70
+ *
71
+ * const notStartable = 5
72
+ *
73
+ * await start(
74
+ * startable,
75
+ * notStartable
76
+ * )
77
+ * ```
78
+ */
52
79
  export async function start (...objs: any[]): Promise<void> {
53
80
  const startables: Startable[] = []
54
81
 
@@ -81,6 +108,30 @@ export async function start (...objs: any[]): Promise<void> {
81
108
  )
82
109
  }
83
110
 
111
+ /**
112
+ * A function that can be used to stop and objects passed to it. This checks
113
+ * that an object is startable before invoking its lifecycle methods so it is
114
+ * safe to pass non-`Startable`s in.
115
+ *
116
+ * @example
117
+ *
118
+ * ```TypeScript
119
+ * import { stop } from '@libp2p/interface'
120
+ * import type { Startable } from '@libp2p/interface'
121
+ *
122
+ * const startable: Startable = {
123
+ * start: () => {},
124
+ * stop: () => {}
125
+ * }
126
+ *
127
+ * const notStartable = 5
128
+ *
129
+ * await stop(
130
+ * startable,
131
+ * notStartable
132
+ * )
133
+ * ```
134
+ */
84
135
  export async function stop (...objs: any[]): Promise<void> {
85
136
  const startables: Startable[] = []
86
137
 
package/src/topology.ts CHANGED
@@ -2,7 +2,8 @@ import type { Connection } from './connection.js'
2
2
  import type { PeerId } from './peer-id.js'
3
3
 
4
4
  /**
5
- * A topology filter
5
+ * A topology filter - this can be used by topologies to ensure they do not
6
+ * receive duplicate notifications of individual peers
6
7
  *
7
8
  * @see https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.peerFilter-1.html
8
9
  */
package/src/transport.ts CHANGED
@@ -10,18 +10,18 @@ export interface ListenerEvents {
10
10
  * This event signals to the transport manager that the listening addresses
11
11
  * have changed and may be emitted at any point and/or multiple times
12
12
  */
13
- 'listening': CustomEvent
13
+ listening: CustomEvent
14
14
 
15
15
  /**
16
16
  * Emitted if listening on an address failed
17
17
  */
18
- 'error': CustomEvent<Error>
18
+ error: CustomEvent<Error>
19
19
 
20
20
  /**
21
21
  * Emitted when the listener has been shut down, has no open connections and
22
22
  * will no longer accept new connections
23
23
  */
24
- 'close': CustomEvent
24
+ close: CustomEvent
25
25
  }
26
26
 
27
27
  export interface Listener extends TypedEventTarget<ListenerEvents> {
@@ -48,7 +48,12 @@ export interface Listener extends TypedEventTarget<ListenerEvents> {
48
48
 
49
49
  export const transportSymbol = Symbol.for('@libp2p/transport')
50
50
 
51
- export interface MultiaddrFilter { (multiaddrs: Multiaddr[]): Multiaddr[] }
51
+ /**
52
+ * A filter that acts on a list of multiaddrs
53
+ */
54
+ export interface MultiaddrFilter {
55
+ (multiaddrs: Multiaddr[]): Multiaddr[]
56
+ }
52
57
 
53
58
  export interface CreateListenerOptions {
54
59
  /**
@@ -103,7 +108,10 @@ export interface Transport<DialEvents extends ProgressEvent = ProgressEvent> {
103
108
  dialFilter: MultiaddrFilter
104
109
  }
105
110
 
106
- export function isTransport (other: any): other is Transport {
111
+ /**
112
+ * Used to disambiguate transport implementations
113
+ */
114
+ export function isTransport (other?: any): other is Transport {
107
115
  return other != null && Boolean(other[transportSymbol])
108
116
  }
109
117
 
@@ -122,11 +130,45 @@ export enum FaultTolerance {
122
130
  NO_FATAL
123
131
  }
124
132
 
133
+ /**
134
+ * Options accepted by the upgrader during connection establishment
135
+ */
125
136
  export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents>, Required<AbortOptions> {
137
+ /**
138
+ * If true the invoking transport is expected to implement it's own encryption
139
+ * and an encryption protocol will not attempted to be negotiated via
140
+ * multi-stream select
141
+ *
142
+ * @default false
143
+ */
126
144
  skipEncryption?: boolean
145
+
146
+ /**
147
+ * If true no connection protection will be performed on the connection.
148
+ */
127
149
  skipProtection?: boolean
150
+
151
+ /**
152
+ * By default a stream muxer protocol will be negotiated via multi-stream
153
+ * select after an encryption protocol has been agreed on.
154
+ *
155
+ * If a transport provides it's own stream muxing facility pass a muxer
156
+ * factory instance here to skip muxer negotiation.
157
+ */
128
158
  muxerFactory?: StreamMuxerFactory
159
+
160
+ /**
161
+ * If the connection is to have limits applied to it, pass them here
162
+ */
129
163
  limits?: ConnectionLimits
164
+
165
+ /**
166
+ * Multi-stream select is a initiator/responder protocol. By default a
167
+ * connection returned from `upgrader.upgradeOutbound` will be the initiator
168
+ * and one returned from `upgrader.upgradeInbound` will be the responder.
169
+ *
170
+ * Pass a value here to override the default.
171
+ */
130
172
  initiator?: boolean
131
173
  }
132
174