@libp2p/peer-collections 5.1.1-ad6f70bf3 → 5.1.1-cd8cafcd5

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
@@ -11,6 +11,71 @@ We can't use PeerIds as collection keys because collection keys are compared usi
11
11
 
12
12
  PeerIds cache stringified versions of themselves so this should be a cheap operation.
13
13
 
14
+ Tracked versions are also available which report their current size to the libp2p Metrics collector.
15
+
16
+ ## Example - Peer lists
17
+
18
+ ```TypeScript
19
+ import { peerList } from '@libp2p/peer-collections'
20
+
21
+ const list = peerList()
22
+ list.push(peerId)
23
+ ```
24
+
25
+ ## Example - Tracked peer lists
26
+
27
+ ```TypeScript
28
+ import { trackedPeerList } from '@libp2p/peer-collections'
29
+ import { createLibp2p } from 'libp2p'
30
+
31
+ const libp2p = await createLibp2p()
32
+
33
+ const list = trackedPeerList({ name: 'my_metric_name', metrics: libp2p.metrics })
34
+ list.push(peerId)
35
+ ```
36
+
37
+ ## Example - Peer maps
38
+
39
+ ```TypeScript
40
+ import { peerMap } from '@libp2p/peer-collections'
41
+
42
+ const map = peerMap<string>()
43
+ map.set(peerId, 'value')
44
+ ```
45
+
46
+ ## Example - Tracked peer maps
47
+
48
+ ```TypeScript
49
+ import { trackedPeerMap } from '@libp2p/peer-collections'
50
+ import { createLibp2p } from 'libp2p'
51
+
52
+ const libp2p = await createLibp2p()
53
+
54
+ const list = trackedPeerMap({ name: 'my_metric_name', metrics: libp2p.metrics })
55
+ map.set(peerId, 'value')
56
+ ```
57
+
58
+ ## Example - Peer sets
59
+
60
+ ```TypeScript
61
+ import { peerSet } from '@libp2p/peer-collections'
62
+
63
+ const set = peerSet()
64
+ set.add(peerId)
65
+ ```
66
+
67
+ ## Example - Tracked peer sets
68
+
69
+ ```TypeScript
70
+ import { trackedPeerSet } from '@libp2p/peer-collections'
71
+ import { createLibp2p } from 'libp2p'
72
+
73
+ const libp2p = await createLibp2p()
74
+
75
+ const list = trackedPeerSet({ name: 'my_metric_name', metrics: libp2p.metrics })
76
+ map.add(peerId)
77
+ ```
78
+
14
79
  # Install
15
80
 
16
81
  ```console
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @example Peer lists
11
11
  *
12
- * ```JavaScript
12
+ * ```TypeScript
13
13
  * import { peerList } from '@libp2p/peer-collections'
14
14
  *
15
15
  * const list = peerList()
@@ -18,7 +18,7 @@
18
18
  *
19
19
  * @example Tracked peer lists
20
20
  *
21
- * * ```Typescript
21
+ * ```TypeScript
22
22
  * import { trackedPeerList } from '@libp2p/peer-collections'
23
23
  * import { createLibp2p } from 'libp2p'
24
24
  *
@@ -30,7 +30,7 @@
30
30
  *
31
31
  * @example Peer maps
32
32
  *
33
- * ```JavaScript
33
+ * ```TypeScript
34
34
  * import { peerMap } from '@libp2p/peer-collections'
35
35
  *
36
36
  * const map = peerMap<string>()
@@ -39,7 +39,7 @@
39
39
  *
40
40
  * @example Tracked peer maps
41
41
  *
42
- * * ```Typescript
42
+ * ```TypeScript
43
43
  * import { trackedPeerMap } from '@libp2p/peer-collections'
44
44
  * import { createLibp2p } from 'libp2p'
45
45
  *
@@ -51,7 +51,7 @@
51
51
  *
52
52
  * @example Peer sets
53
53
  *
54
- * ```JavaScript
54
+ * ```TypeScript
55
55
  * import { peerSet } from '@libp2p/peer-collections'
56
56
  *
57
57
  * const set = peerSet()
@@ -60,7 +60,7 @@
60
60
  *
61
61
  * @example Tracked peer sets
62
62
  *
63
- * * ```Typescript
63
+ * ```TypeScript
64
64
  * import { trackedPeerSet } from '@libp2p/peer-collections'
65
65
  * import { createLibp2p } from 'libp2p'
66
66
  *
package/dist/src/index.js CHANGED
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @example Peer lists
11
11
  *
12
- * ```JavaScript
12
+ * ```TypeScript
13
13
  * import { peerList } from '@libp2p/peer-collections'
14
14
  *
15
15
  * const list = peerList()
@@ -18,7 +18,7 @@
18
18
  *
19
19
  * @example Tracked peer lists
20
20
  *
21
- * * ```Typescript
21
+ * ```TypeScript
22
22
  * import { trackedPeerList } from '@libp2p/peer-collections'
23
23
  * import { createLibp2p } from 'libp2p'
24
24
  *
@@ -30,7 +30,7 @@
30
30
  *
31
31
  * @example Peer maps
32
32
  *
33
- * ```JavaScript
33
+ * ```TypeScript
34
34
  * import { peerMap } from '@libp2p/peer-collections'
35
35
  *
36
36
  * const map = peerMap<string>()
@@ -39,7 +39,7 @@
39
39
  *
40
40
  * @example Tracked peer maps
41
41
  *
42
- * * ```Typescript
42
+ * ```TypeScript
43
43
  * import { trackedPeerMap } from '@libp2p/peer-collections'
44
44
  * import { createLibp2p } from 'libp2p'
45
45
  *
@@ -51,7 +51,7 @@
51
51
  *
52
52
  * @example Peer sets
53
53
  *
54
- * ```JavaScript
54
+ * ```TypeScript
55
55
  * import { peerSet } from '@libp2p/peer-collections'
56
56
  *
57
57
  * const set = peerSet()
@@ -60,7 +60,7 @@
60
60
  *
61
61
  * @example Tracked peer sets
62
62
  *
63
- * * ```Typescript
63
+ * ```TypeScript
64
64
  * import { trackedPeerSet } from '@libp2p/peer-collections'
65
65
  * import { createLibp2p } from 'libp2p'
66
66
  *
@@ -9,7 +9,7 @@ import type { PeerId } from '@libp2p/interface';
9
9
  *
10
10
  * @example
11
11
  *
12
- * ```JavaScript
12
+ * ```TypeScript
13
13
  * import { peerList } from '@libp2p/peer-collections'
14
14
  *
15
15
  * const list = peerList()
package/dist/src/list.js CHANGED
@@ -10,7 +10,7 @@ import { mapIterable } from './util.js';
10
10
  *
11
11
  * @example
12
12
  *
13
- * ```JavaScript
13
+ * ```TypeScript
14
14
  * import { peerList } from '@libp2p/peer-collections'
15
15
  *
16
16
  * const list = peerList()
package/dist/src/map.d.ts CHANGED
@@ -9,7 +9,7 @@ import type { PeerId } from '@libp2p/interface';
9
9
  *
10
10
  * @example
11
11
  *
12
- * ```JavaScript
12
+ * ```TypeScript
13
13
  * import { peerMap } from '@libp2p/peer-collections'
14
14
  *
15
15
  * const map = peerMap<string>()
package/dist/src/map.js CHANGED
@@ -10,7 +10,7 @@ import { mapIterable } from './util.js';
10
10
  *
11
11
  * @example
12
12
  *
13
- * ```JavaScript
13
+ * ```TypeScript
14
14
  * import { peerMap } from '@libp2p/peer-collections'
15
15
  *
16
16
  * const map = peerMap<string>()
package/dist/src/set.d.ts CHANGED
@@ -9,7 +9,7 @@ import type { PeerId } from '@libp2p/interface';
9
9
  *
10
10
  * @example
11
11
  *
12
- * ```JavaScript
12
+ * ```TypeScript
13
13
  * import { peerSet } from '@libp2p/peer-collections'
14
14
  *
15
15
  * const set = peerSet()
package/dist/src/set.js CHANGED
@@ -10,7 +10,7 @@ import { mapIterable } from './util.js';
10
10
  *
11
11
  * @example
12
12
  *
13
- * ```JavaScript
13
+ * ```TypeScript
14
14
  * import { peerSet } from '@libp2p/peer-collections'
15
15
  *
16
16
  * const set = peerSet()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/peer-collections",
3
- "version": "5.1.1-ad6f70bf3",
3
+ "version": "5.1.1-cd8cafcd5",
4
4
  "description": "Stores values against a peer id",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-collections#readme",
@@ -53,11 +53,11 @@
53
53
  "test:electron-main": "aegir test -t electron-main"
54
54
  },
55
55
  "dependencies": {
56
- "@libp2p/interface": "1.0.2-ad6f70bf3",
57
- "@libp2p/peer-id": "4.0.2-ad6f70bf3"
56
+ "@libp2p/interface": "1.0.2-cd8cafcd5",
57
+ "@libp2p/peer-id": "4.0.2-cd8cafcd5"
58
58
  },
59
59
  "devDependencies": {
60
- "@libp2p/peer-id-factory": "4.0.1-ad6f70bf3",
60
+ "@libp2p/peer-id-factory": "4.0.1-cd8cafcd5",
61
61
  "@types/sinon": "^17.0.2",
62
62
  "aegir": "^41.0.2",
63
63
  "sinon": "^17.0.1",
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @example Peer lists
11
11
  *
12
- * ```JavaScript
12
+ * ```TypeScript
13
13
  * import { peerList } from '@libp2p/peer-collections'
14
14
  *
15
15
  * const list = peerList()
@@ -18,7 +18,7 @@
18
18
  *
19
19
  * @example Tracked peer lists
20
20
  *
21
- * * ```Typescript
21
+ * ```TypeScript
22
22
  * import { trackedPeerList } from '@libp2p/peer-collections'
23
23
  * import { createLibp2p } from 'libp2p'
24
24
  *
@@ -30,7 +30,7 @@
30
30
  *
31
31
  * @example Peer maps
32
32
  *
33
- * ```JavaScript
33
+ * ```TypeScript
34
34
  * import { peerMap } from '@libp2p/peer-collections'
35
35
  *
36
36
  * const map = peerMap<string>()
@@ -39,7 +39,7 @@
39
39
  *
40
40
  * @example Tracked peer maps
41
41
  *
42
- * * ```Typescript
42
+ * ```TypeScript
43
43
  * import { trackedPeerMap } from '@libp2p/peer-collections'
44
44
  * import { createLibp2p } from 'libp2p'
45
45
  *
@@ -51,7 +51,7 @@
51
51
  *
52
52
  * @example Peer sets
53
53
  *
54
- * ```JavaScript
54
+ * ```TypeScript
55
55
  * import { peerSet } from '@libp2p/peer-collections'
56
56
  *
57
57
  * const set = peerSet()
@@ -60,7 +60,7 @@
60
60
  *
61
61
  * @example Tracked peer sets
62
62
  *
63
- * * ```Typescript
63
+ * ```TypeScript
64
64
  * import { trackedPeerSet } from '@libp2p/peer-collections'
65
65
  * import { createLibp2p } from 'libp2p'
66
66
  *
package/src/list.ts CHANGED
@@ -12,7 +12,7 @@ import type { PeerId } from '@libp2p/interface'
12
12
  *
13
13
  * @example
14
14
  *
15
- * ```JavaScript
15
+ * ```TypeScript
16
16
  * import { peerList } from '@libp2p/peer-collections'
17
17
  *
18
18
  * const list = peerList()
package/src/map.ts CHANGED
@@ -12,7 +12,7 @@ import type { PeerId } from '@libp2p/interface'
12
12
  *
13
13
  * @example
14
14
  *
15
- * ```JavaScript
15
+ * ```TypeScript
16
16
  * import { peerMap } from '@libp2p/peer-collections'
17
17
  *
18
18
  * const map = peerMap<string>()
package/src/set.ts CHANGED
@@ -12,7 +12,7 @@ import type { PeerId } from '@libp2p/interface'
12
12
  *
13
13
  * @example
14
14
  *
15
- * ```JavaScript
15
+ * ```TypeScript
16
16
  * import { peerSet } from '@libp2p/peer-collections'
17
17
  *
18
18
  * const set = peerSet()