@libp2p/interface 2.9.0-f1de46607 → 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 (58) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.map +3 -3
  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
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