@libp2p/pubsub 1.0.0 → 1.0.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/dist/src/peer-streams.d.ts +2 -6
- package/dist/src/peer-streams.d.ts.map +1 -1
- package/dist/src/peer-streams.js +4 -8
- package/dist/src/peer-streams.js.map +1 -1
- package/package.json +153 -56
- package/src/peer-streams.ts +6 -9
- package/dist/test/emit-self.spec.d.ts +0 -2
- package/dist/test/emit-self.spec.d.ts.map +0 -1
- package/dist/test/emit-self.spec.js +0 -63
- package/dist/test/emit-self.spec.js.map +0 -1
- package/dist/test/instance.spec.d.ts +0 -2
- package/dist/test/instance.spec.d.ts.map +0 -1
- package/dist/test/instance.spec.js +0 -50
- package/dist/test/instance.spec.js.map +0 -1
- package/dist/test/lifesycle.spec.d.ts +0 -2
- package/dist/test/lifesycle.spec.d.ts.map +0 -1
- package/dist/test/lifesycle.spec.js +0 -192
- package/dist/test/lifesycle.spec.js.map +0 -1
- package/dist/test/message.spec.d.ts +0 -2
- package/dist/test/message.spec.d.ts.map +0 -1
- package/dist/test/message.spec.js +0 -83
- package/dist/test/message.spec.js.map +0 -1
- package/dist/test/pubsub.spec.d.ts +0 -2
- package/dist/test/pubsub.spec.d.ts.map +0 -1
- package/dist/test/pubsub.spec.js +0 -310
- package/dist/test/pubsub.spec.js.map +0 -1
- package/dist/test/sign.spec.d.ts +0 -2
- package/dist/test/sign.spec.d.ts.map +0 -1
- package/dist/test/sign.spec.js +0 -93
- package/dist/test/sign.spec.js.map +0 -1
- package/dist/test/topic-validators.spec.d.ts +0 -2
- package/dist/test/topic-validators.spec.d.ts.map +0 -1
- package/dist/test/topic-validators.spec.js +0 -86
- package/dist/test/topic-validators.spec.js.map +0 -1
- package/dist/test/utils/index.d.ts +0 -22
- package/dist/test/utils/index.d.ts.map +0 -1
- package/dist/test/utils/index.js +0 -86
- package/dist/test/utils/index.js.map +0 -1
- package/dist/test/utils.spec.d.ts +0 -2
- package/dist/test/utils.spec.d.ts.map +0 -1
- package/dist/test/utils.spec.js +0 -53
- package/dist/test/utils.spec.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,8 +1,8 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { EventEmitter } from 'events';
|
3
|
-
import pushable from 'it-pushable';
|
4
3
|
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
5
4
|
import type { MuxedStream } from '@libp2p/interfaces/stream-muxer';
|
5
|
+
import type { Pushable } from 'it-pushable';
|
6
6
|
export interface Options {
|
7
7
|
id: PeerId;
|
8
8
|
protocol: string;
|
@@ -16,7 +16,7 @@ export declare class PeerStreams extends EventEmitter {
|
|
16
16
|
/**
|
17
17
|
* Write stream - it's preferable to use the write method
|
18
18
|
*/
|
19
|
-
outboundStream:
|
19
|
+
outboundStream: Pushable<Uint8Array> | undefined;
|
20
20
|
/**
|
21
21
|
* Read stream
|
22
22
|
*/
|
@@ -36,14 +36,10 @@ export declare class PeerStreams extends EventEmitter {
|
|
36
36
|
constructor(opts: Options);
|
37
37
|
/**
|
38
38
|
* Do we have a connection to read from?
|
39
|
-
*
|
40
|
-
* @type {boolean}
|
41
39
|
*/
|
42
40
|
get isReadable(): boolean;
|
43
41
|
/**
|
44
42
|
* Do we have a connection to write on?
|
45
|
-
*
|
46
|
-
* @type {boolean}
|
47
43
|
*/
|
48
44
|
get isWritable(): boolean;
|
49
45
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"peer-streams.d.ts","sourceRoot":"","sources":["../../src/peer-streams.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;
|
1
|
+
{"version":3,"file":"peer-streams.d.ts","sourceRoot":"","sources":["../../src/peer-streams.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAMrC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAM3C,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C,SAAgB,EAAE,EAAE,MAAM,CAAA;IAC1B,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAChC;;OAEG;IACI,cAAc,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;IACvD;;OAEG;IACI,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;IAC3D;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAAyB;IACnD;;OAEG;IACH,OAAO,CAAC,iBAAiB,CAAyB;IAClD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAiB;gBAE5C,IAAI,EAAE,OAAO;IAS1B;;OAEG;IACH,IAAI,UAAU,YAEb;IAED;;OAEG;IACH,IAAI,UAAU,YAEb;IAED;;;OAGG;IACH,KAAK,CAAE,IAAI,EAAE,UAAU;IASvB;;OAEG;IACH,mBAAmB,CAAE,MAAM,EAAE,WAAW;IAmBxC;;OAEG;IACG,oBAAoB,CAAE,MAAM,EAAE,WAAW;IAsC/C;;OAEG;IACH,KAAK;CAgBN"}
|
package/dist/src/peer-streams.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import debug from 'debug';
|
2
2
|
import { EventEmitter } from 'events';
|
3
|
-
import lp from 'it-length-prefixed';
|
4
|
-
import pushable from 'it-pushable';
|
3
|
+
import * as lp from 'it-length-prefixed';
|
4
|
+
import { pushable } from 'it-pushable';
|
5
5
|
import { pipe } from 'it-pipe';
|
6
|
-
import {
|
6
|
+
import { abortableSource } from 'abortable-iterator';
|
7
7
|
import AbortController from 'abort-controller';
|
8
8
|
const log = Object.assign(debug('libp2p-pubsub:peer-streams'), {
|
9
9
|
error: debug('libp2p-pubsub:peer-streams:err')
|
@@ -20,16 +20,12 @@ export class PeerStreams extends EventEmitter {
|
|
20
20
|
}
|
21
21
|
/**
|
22
22
|
* Do we have a connection to read from?
|
23
|
-
*
|
24
|
-
* @type {boolean}
|
25
23
|
*/
|
26
24
|
get isReadable() {
|
27
25
|
return Boolean(this.inboundStream);
|
28
26
|
}
|
29
27
|
/**
|
30
28
|
* Do we have a connection to write on?
|
31
|
-
*
|
32
|
-
* @type {boolean}
|
33
29
|
*/
|
34
30
|
get isWritable() {
|
35
31
|
return Boolean(this.outboundStream);
|
@@ -54,7 +50,7 @@ export class PeerStreams extends EventEmitter {
|
|
54
50
|
// - abortable, set to only return on abort, rather than throw
|
55
51
|
// - transformed with length-prefix transform
|
56
52
|
this._rawInboundStream = stream;
|
57
|
-
this.inboundStream =
|
53
|
+
this.inboundStream = abortableSource(pipe(this._rawInboundStream, lp.decode()), this._inboundAbortController.signal, { returnOnAbort: true });
|
58
54
|
this.emit('stream:inbound');
|
59
55
|
return this.inboundStream;
|
60
56
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"peer-streams.js","sourceRoot":"","sources":["../../src/peer-streams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,MAAM,oBAAoB,CAAA;
|
1
|
+
{"version":3,"file":"peer-streams.js","sourceRoot":"","sources":["../../src/peer-streams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA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B,CAAC,CAAA;SAC7B;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,0BAA0B;QAC1B,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,EAAE;YAC/B,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAAA;SAC1B;QACD,yBAAyB;QACzB,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,EAAE;YAC9B,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAA;SACrC;QAED,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;QACnC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAA;QAC/B,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,SAAS,CAAA;QAC9B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACpB,CAAC;CACF"}
|
package/package.json
CHANGED
@@ -1,28 +1,169 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/pubsub",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.4",
|
4
4
|
"description": "libp2p pubsub base class",
|
5
|
-
"
|
6
|
-
"
|
7
|
-
|
8
|
-
"
|
5
|
+
"license": "Apache-2.0 OR MIT",
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-pubsub#readme",
|
7
|
+
"repository": {
|
8
|
+
"type": "git",
|
9
|
+
"url": "git+https://github.com/libp2p/js-libp2p-interfaces.git"
|
10
|
+
},
|
11
|
+
"bugs": {
|
12
|
+
"url": "https://github.com/libp2p/js-libp2p-interfaces/issues"
|
13
|
+
},
|
14
|
+
"keywords": [
|
15
|
+
"interface",
|
16
|
+
"libp2p"
|
9
17
|
],
|
10
|
-
"
|
18
|
+
"engines": {
|
19
|
+
"node": ">=16.0.0",
|
20
|
+
"npm": ">=7.0.0"
|
21
|
+
},
|
22
|
+
"type": "module",
|
23
|
+
"types": "./dist/src/index.d.ts",
|
11
24
|
"typesVersions": {
|
12
25
|
"*": {
|
13
26
|
"*": [
|
27
|
+
"*",
|
28
|
+
"dist/*",
|
29
|
+
"dist/src/*",
|
30
|
+
"dist/src/*/index"
|
31
|
+
],
|
32
|
+
"src/*": [
|
33
|
+
"*",
|
34
|
+
"dist/*",
|
14
35
|
"dist/src/*",
|
15
36
|
"dist/src/*/index"
|
16
37
|
]
|
17
38
|
}
|
18
39
|
},
|
40
|
+
"files": [
|
41
|
+
"src",
|
42
|
+
"dist/src",
|
43
|
+
"!dist/test",
|
44
|
+
"!**/*.tsbuildinfo"
|
45
|
+
],
|
46
|
+
"exports": {
|
47
|
+
".": {
|
48
|
+
"import": "./dist/src/index.js",
|
49
|
+
"types": "./dist/src/index.d.ts"
|
50
|
+
},
|
51
|
+
"./errors": {
|
52
|
+
"import": "./dist/src/errors.js",
|
53
|
+
"types": "./dist/src/errors.d.ts"
|
54
|
+
},
|
55
|
+
"./peer-streams": {
|
56
|
+
"import": "./dist/src/peer-streams.js",
|
57
|
+
"types": "./dist/src/peer-streams.d.ts"
|
58
|
+
},
|
59
|
+
"./signature-policy": {
|
60
|
+
"import": "./dist/src/signature-policy.js",
|
61
|
+
"types": "./dist/src/signature-policy.d.ts"
|
62
|
+
},
|
63
|
+
"./utils": {
|
64
|
+
"import": "./dist/src/utils.js",
|
65
|
+
"types": "./dist/src/utils.d.ts"
|
66
|
+
},
|
67
|
+
"./message/rpc": {
|
68
|
+
"import": "./dist/src/message/rpc.js",
|
69
|
+
"types": "./dist/src/message/rpc.d.ts"
|
70
|
+
},
|
71
|
+
"./message/topic-descriptor": {
|
72
|
+
"import": "./dist/src/message/topic-descriptor.js",
|
73
|
+
"types": "./dist/src/message/topic-descriptor.d.ts"
|
74
|
+
}
|
75
|
+
},
|
19
76
|
"eslintConfig": {
|
20
77
|
"extends": "ipfs",
|
78
|
+
"parserOptions": {
|
79
|
+
"sourceType": "module"
|
80
|
+
},
|
21
81
|
"ignorePatterns": [
|
22
82
|
"src/message/*.d.ts",
|
23
83
|
"src/message/*.js"
|
24
84
|
]
|
25
85
|
},
|
86
|
+
"release": {
|
87
|
+
"branches": [
|
88
|
+
"master"
|
89
|
+
],
|
90
|
+
"plugins": [
|
91
|
+
[
|
92
|
+
"@semantic-release/commit-analyzer",
|
93
|
+
{
|
94
|
+
"preset": "conventionalcommits",
|
95
|
+
"releaseRules": [
|
96
|
+
{
|
97
|
+
"breaking": true,
|
98
|
+
"release": "major"
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"revert": true,
|
102
|
+
"release": "patch"
|
103
|
+
},
|
104
|
+
{
|
105
|
+
"type": "feat",
|
106
|
+
"release": "minor"
|
107
|
+
},
|
108
|
+
{
|
109
|
+
"type": "fix",
|
110
|
+
"release": "patch"
|
111
|
+
},
|
112
|
+
{
|
113
|
+
"type": "chore",
|
114
|
+
"release": "patch"
|
115
|
+
},
|
116
|
+
{
|
117
|
+
"type": "docs",
|
118
|
+
"release": "patch"
|
119
|
+
},
|
120
|
+
{
|
121
|
+
"type": "test",
|
122
|
+
"release": "patch"
|
123
|
+
},
|
124
|
+
{
|
125
|
+
"scope": "no-release",
|
126
|
+
"release": false
|
127
|
+
}
|
128
|
+
]
|
129
|
+
}
|
130
|
+
],
|
131
|
+
[
|
132
|
+
"@semantic-release/release-notes-generator",
|
133
|
+
{
|
134
|
+
"preset": "conventionalcommits",
|
135
|
+
"presetConfig": {
|
136
|
+
"types": [
|
137
|
+
{
|
138
|
+
"type": "feat",
|
139
|
+
"section": "Features"
|
140
|
+
},
|
141
|
+
{
|
142
|
+
"type": "fix",
|
143
|
+
"section": "Bug Fixes"
|
144
|
+
},
|
145
|
+
{
|
146
|
+
"type": "chore",
|
147
|
+
"section": "Trivial Changes"
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"type": "docs",
|
151
|
+
"section": "Trivial Changes"
|
152
|
+
},
|
153
|
+
{
|
154
|
+
"type": "test",
|
155
|
+
"section": "Tests"
|
156
|
+
}
|
157
|
+
]
|
158
|
+
}
|
159
|
+
}
|
160
|
+
],
|
161
|
+
"@semantic-release/changelog",
|
162
|
+
"@semantic-release/npm",
|
163
|
+
"@semantic-release/github",
|
164
|
+
"@semantic-release/git"
|
165
|
+
]
|
166
|
+
},
|
26
167
|
"scripts": {
|
27
168
|
"lint": "aegir lint",
|
28
169
|
"dep-check": "aegir dep-check dist/src/**/*.js",
|
@@ -44,32 +185,18 @@
|
|
44
185
|
"build:proto-types:topic-descriptor": "pbts -o src/message/topic-descriptor.d.ts src/message/topic-descriptor.js",
|
45
186
|
"build:copy-proto-files": "cp src/message/*.js dist/src/message && cp src/message/*.d.ts dist/src/message"
|
46
187
|
},
|
47
|
-
"repository": {
|
48
|
-
"type": "git",
|
49
|
-
"url": "git+https://github.com/libp2p/js-libp2p-interfaces.git"
|
50
|
-
},
|
51
|
-
"keywords": [
|
52
|
-
"libp2p",
|
53
|
-
"interface"
|
54
|
-
],
|
55
|
-
"author": "",
|
56
|
-
"license": "(Apache-2.0 OR MIT)",
|
57
|
-
"bugs": {
|
58
|
-
"url": "https://github.com/libp2p/js-libp2p-interfaces/issues"
|
59
|
-
},
|
60
|
-
"homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-pubsub#readme",
|
61
188
|
"dependencies": {
|
62
189
|
"@libp2p/crypto": "^0.22.2",
|
63
|
-
"@libp2p/interfaces": "^0.
|
64
|
-
"@libp2p/peer-id": "^0.
|
65
|
-
"@libp2p/peer-id-factory": "^0.
|
66
|
-
"@libp2p/topology": "^0.
|
190
|
+
"@libp2p/interfaces": "^1.0.0",
|
191
|
+
"@libp2p/peer-id": "^1.0.0",
|
192
|
+
"@libp2p/peer-id-factory": "^1.0.0",
|
193
|
+
"@libp2p/topology": "^1.0.0",
|
67
194
|
"@multiformats/multiaddr": "^10.1.1",
|
68
195
|
"debug": "^4.3.2",
|
69
196
|
"err-code": "^3.0.1",
|
70
197
|
"iso-random-stream": "^2.0.0",
|
71
|
-
"it-length-prefixed": "^
|
72
|
-
"it-pipe": "^
|
198
|
+
"it-length-prefixed": "^6.0.1",
|
199
|
+
"it-pipe": "^2.0.2",
|
73
200
|
"multiformats": "^9.4.10",
|
74
201
|
"p-queue": "^7.1.0",
|
75
202
|
"uint8arrays": "^3.0.0"
|
@@ -80,35 +207,5 @@
|
|
80
207
|
"aegir": "^36.1.3",
|
81
208
|
"protobufjs": "^6.10.2",
|
82
209
|
"util": "^0.12.4"
|
83
|
-
},
|
84
|
-
"exports": {
|
85
|
-
".": {
|
86
|
-
"import": "./dist/src/index.js",
|
87
|
-
"types": "./dist/src/index.d.ts"
|
88
|
-
},
|
89
|
-
"./errors": {
|
90
|
-
"import": "./dist/src/errors.js",
|
91
|
-
"types": "./dist/src/errors.d.ts"
|
92
|
-
},
|
93
|
-
"./peer-streams": {
|
94
|
-
"import": "./dist/src/peer-streams.js",
|
95
|
-
"types": "./dist/src/peer-streams.d.ts"
|
96
|
-
},
|
97
|
-
"./signature-policy": {
|
98
|
-
"import": "./dist/src/signature-policy.js",
|
99
|
-
"types": "./dist/src/signature-policy.d.ts"
|
100
|
-
},
|
101
|
-
"./utils": {
|
102
|
-
"import": "./dist/src/utils.js",
|
103
|
-
"types": "./dist/src/utils.d.ts"
|
104
|
-
},
|
105
|
-
"./message/rpc": {
|
106
|
-
"import": "./dist/src/message/rpc.js",
|
107
|
-
"types": "./dist/src/message/rpc.d.ts"
|
108
|
-
},
|
109
|
-
"./message/topic-descriptor": {
|
110
|
-
"import": "./dist/src/message/topic-descriptor.js",
|
111
|
-
"types": "./dist/src/message/topic-descriptor.d.ts"
|
112
|
-
}
|
113
210
|
}
|
114
211
|
}
|
package/src/peer-streams.ts
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
import debug from 'debug'
|
2
2
|
import { EventEmitter } from 'events'
|
3
|
-
import lp from 'it-length-prefixed'
|
4
|
-
import pushable from 'it-pushable'
|
3
|
+
import * as lp from 'it-length-prefixed'
|
4
|
+
import { pushable } from 'it-pushable'
|
5
5
|
import { pipe } from 'it-pipe'
|
6
|
-
import {
|
6
|
+
import { abortableSource } from 'abortable-iterator'
|
7
7
|
import AbortController from 'abort-controller'
|
8
8
|
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
9
9
|
import type { MuxedStream } from '@libp2p/interfaces/stream-muxer'
|
10
|
+
import type { Pushable } from 'it-pushable'
|
10
11
|
|
11
12
|
const log = Object.assign(debug('libp2p-pubsub:peer-streams'), {
|
12
13
|
error: debug('libp2p-pubsub:peer-streams:err')
|
@@ -26,7 +27,7 @@ export class PeerStreams extends EventEmitter {
|
|
26
27
|
/**
|
27
28
|
* Write stream - it's preferable to use the write method
|
28
29
|
*/
|
29
|
-
public outboundStream:
|
30
|
+
public outboundStream: Pushable<Uint8Array> | undefined
|
30
31
|
/**
|
31
32
|
* Read stream
|
32
33
|
*/
|
@@ -55,8 +56,6 @@ export class PeerStreams extends EventEmitter {
|
|
55
56
|
|
56
57
|
/**
|
57
58
|
* Do we have a connection to read from?
|
58
|
-
*
|
59
|
-
* @type {boolean}
|
60
59
|
*/
|
61
60
|
get isReadable () {
|
62
61
|
return Boolean(this.inboundStream)
|
@@ -64,8 +63,6 @@ export class PeerStreams extends EventEmitter {
|
|
64
63
|
|
65
64
|
/**
|
66
65
|
* Do we have a connection to write on?
|
67
|
-
*
|
68
|
-
* @type {boolean}
|
69
66
|
*/
|
70
67
|
get isWritable () {
|
71
68
|
return Boolean(this.outboundStream)
|
@@ -93,7 +90,7 @@ export class PeerStreams extends EventEmitter {
|
|
93
90
|
// - abortable, set to only return on abort, rather than throw
|
94
91
|
// - transformed with length-prefix transform
|
95
92
|
this._rawInboundStream = stream
|
96
|
-
this.inboundStream =
|
93
|
+
this.inboundStream = abortableSource(
|
97
94
|
pipe(
|
98
95
|
this._rawInboundStream,
|
99
96
|
lp.decode()
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"emit-self.spec.d.ts","sourceRoot":"","sources":["../../test/emit-self.spec.ts"],"names":[],"mappings":""}
|
@@ -1,63 +0,0 @@
|
|
1
|
-
import { expect } from 'aegir/utils/chai.js';
|
2
|
-
import { createPeerId, mockRegistrar, PubsubImplementation } from './utils/index.js';
|
3
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
4
|
-
import delay from 'delay';
|
5
|
-
const protocol = '/pubsub/1.0.0';
|
6
|
-
const topic = 'foo';
|
7
|
-
const data = uint8ArrayFromString('bar');
|
8
|
-
const shouldNotHappen = () => expect.fail();
|
9
|
-
describe('emitSelf', () => {
|
10
|
-
let pubsub;
|
11
|
-
describe('enabled', () => {
|
12
|
-
before(async () => {
|
13
|
-
const peerId = await createPeerId();
|
14
|
-
pubsub = new PubsubImplementation({
|
15
|
-
multicodecs: [protocol],
|
16
|
-
libp2p: {
|
17
|
-
peerId,
|
18
|
-
registrar: mockRegistrar
|
19
|
-
},
|
20
|
-
emitSelf: true
|
21
|
-
});
|
22
|
-
});
|
23
|
-
before(async () => {
|
24
|
-
await pubsub.start();
|
25
|
-
pubsub.subscribe(topic);
|
26
|
-
});
|
27
|
-
after(async () => {
|
28
|
-
await pubsub.stop();
|
29
|
-
});
|
30
|
-
it('should emit to self on publish', async () => {
|
31
|
-
const promise = new Promise((resolve) => pubsub.once(topic, resolve));
|
32
|
-
await pubsub.publish(topic, data);
|
33
|
-
return await promise;
|
34
|
-
});
|
35
|
-
});
|
36
|
-
describe('disabled', () => {
|
37
|
-
before(async () => {
|
38
|
-
const peerId = await createPeerId();
|
39
|
-
pubsub = new PubsubImplementation({
|
40
|
-
multicodecs: [protocol],
|
41
|
-
libp2p: {
|
42
|
-
peerId,
|
43
|
-
registrar: mockRegistrar
|
44
|
-
},
|
45
|
-
emitSelf: false
|
46
|
-
});
|
47
|
-
});
|
48
|
-
before(async () => {
|
49
|
-
await pubsub.start();
|
50
|
-
pubsub.subscribe(topic);
|
51
|
-
});
|
52
|
-
after(async () => {
|
53
|
-
await pubsub.stop();
|
54
|
-
});
|
55
|
-
it('should not emit to self on publish', async () => {
|
56
|
-
pubsub.once(topic, () => shouldNotHappen);
|
57
|
-
await pubsub.publish(topic, data);
|
58
|
-
// Wait 1 second to guarantee that self is not noticed
|
59
|
-
await delay(1000);
|
60
|
-
});
|
61
|
-
});
|
62
|
-
});
|
63
|
-
//# sourceMappingURL=emit-self.spec.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"emit-self.spec.js","sourceRoot":"","sources":["../../test/emit-self.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,QAAQ,GAAG,eAAe,CAAA;AAChC,MAAM,KAAK,GAAG,KAAK,CAAA;AACnB,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAA;AACxC,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;AAE3C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,IAAI,MAA4B,CAAA;IAEhC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACvB,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB,MAAM,MAAM,GAAG,MAAM,YAAY,EAAE,CAAA;YAEnC,MAAM,GAAG,IAAI,oBAAoB,CAAC;gBAChC,WAAW,EAAE,CAAC,QAAQ,CAAC;gBACvB,MAAM,EAAE;oBACN,MAAM;oBACN,SAAS,EAAE,aAAa;iBACzB;gBACD,QAAQ,EAAE,IAAI;aACf,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;YACpB,MAAM,CAAC,SAAS,CAAC,KAA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E,IAAI,CAAC,CAAA;YAEjC,sDAAsD;YACtD,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"instance.spec.d.ts","sourceRoot":"","sources":["../../test/instance.spec.ts"],"names":[],"mappings":""}
|
@@ -1,50 +0,0 @@
|
|
1
|
-
import { expect } from 'aegir/utils/chai.js';
|
2
|
-
import { PubsubBaseProtocol } from '../src/index.js';
|
3
|
-
import { createPeerId, mockRegistrar } from './utils/index.js';
|
4
|
-
class PubsubProtocol extends PubsubBaseProtocol {
|
5
|
-
async _publish(message) {
|
6
|
-
throw new Error('Method not implemented.');
|
7
|
-
}
|
8
|
-
}
|
9
|
-
describe('pubsub instance', () => {
|
10
|
-
let peerId;
|
11
|
-
before(async () => {
|
12
|
-
peerId = await createPeerId();
|
13
|
-
});
|
14
|
-
it('should throw if no debugName is provided', () => {
|
15
|
-
expect(() => {
|
16
|
-
// @ts-expect-error incorrect constructor args
|
17
|
-
new PubsubProtocol(); // eslint-disable-line no-new
|
18
|
-
}).to.throw();
|
19
|
-
});
|
20
|
-
it('should throw if no multicodec is provided', () => {
|
21
|
-
expect(() => {
|
22
|
-
// @ts-expect-error incorrect constructor args
|
23
|
-
new PubsubProtocol({
|
24
|
-
debugName: 'pubsub'
|
25
|
-
});
|
26
|
-
}).to.throw();
|
27
|
-
});
|
28
|
-
it('should throw if no libp2p is provided', () => {
|
29
|
-
expect(() => {
|
30
|
-
// @ts-expect-error incorrect constructor args
|
31
|
-
new PubsubProtocol({
|
32
|
-
debugName: 'pubsub',
|
33
|
-
multicodecs: ['/pubsub/1.0.0']
|
34
|
-
});
|
35
|
-
}).to.throw();
|
36
|
-
});
|
37
|
-
it('should accept valid parameters', () => {
|
38
|
-
expect(() => {
|
39
|
-
new PubsubProtocol({
|
40
|
-
debugName: 'pubsub',
|
41
|
-
multicodecs: ['/pubsub/1.0.0'],
|
42
|
-
libp2p: {
|
43
|
-
peerId: peerId,
|
44
|
-
registrar: mockRegistrar
|
45
|
-
}
|
46
|
-
});
|
47
|
-
}).not.to.throw();
|
48
|
-
});
|
49
|
-
});
|
50
|
-
//# sourceMappingURL=instance.spec.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"instance.spec.js","sourceRoot":"","sources":["../../test/instance.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EACL,YAAY,EACZ,aAAa,EACd,MAAM,kBAAkB,CAAA;AAIzB,MAAM,cAAe,SAAQ,kBAAkB;IAC7C,KAAK,CAAC,QAAQ,CAAE,OAAgB;QAC9B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;CACF;AAED,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,MAAc,CAAA;IAElB,MAAM,CAAC,KAAK,IAAI,EAAE;QAChB,MAAM,GAAG,MAAM,YAAY,EAAE,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,CAAC,GAAG,EAAE;YACV,8CAA8C;YAC9C,IAAI,cAAc,EAAE,CAAA,CAAC,6BAA6B;QACpD,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,CAAC,GAAG,EAAE;YACV,8CAA8C;YAC9C,IAAI,cAAc,CAAC;gBACjB,SAAS,EAAE,QAAQ;aACpB,CAAC,CAAA;QACJ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,EA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