@libp2p/multistream-select 2.0.1 → 2.0.2

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,15 +1,19 @@
1
- # js-multistream-select <!-- omit in toc -->
1
+ # @libp2p/multistream-select <!-- omit in toc -->
2
2
 
3
- [![test & maybe release](https://github.com/libp2p/js-libp2p-multistream-select/actions/workflows/js-test-and-release.yml/badge.svg)](https://github.com/libp2p/js-libp2p-multistream-select/actions/workflows/js-test-and-release.yml)
3
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
+ [![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
5
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
6
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-multistream-select.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-multistream-select)
7
+ [![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-multistream-select/actions/workflows/js-test-and-release.yml)
4
8
 
5
- > JavaScript implementation of [multistream-select](https://github.com/multiformats/multistream-select)
9
+ > JavaScript implementation of multistream-select
6
10
 
7
- ## Table of Contents <!-- omit in toc -->
11
+ ## Table of contents <!-- omit in toc -->
8
12
 
13
+ - [Install](#install)
9
14
  - [Background](#background)
10
15
  - [What is `multistream-select`?](#what-is-multistream-select)
11
16
  - [Select a protocol flow](#select-a-protocol-flow)
12
- - [Install](#install)
13
17
  - [Usage](#usage)
14
18
  - [Dialer](#dialer)
15
19
  - [Listener](#listener)
@@ -35,7 +39,13 @@
35
39
  - [Returns](#returns-4)
36
40
  - [Examples](#examples-4)
37
41
  - [License](#license)
38
- - [Contribution](#contribution)
42
+ - [Contribution](#contribution)
43
+
44
+ ## Install
45
+
46
+ ```console
47
+ $ npm i @libp2p/multistream-select
48
+ ```
39
49
 
40
50
  ## Background
41
51
 
@@ -61,12 +71,6 @@ The caller will send "interactive" messages, expecting for some acknowledgement
61
71
 
62
72
  This mode also packs a `ls` option, so that the callee can list the protocols it currently supports
63
73
 
64
- ## Install
65
-
66
- ```sh
67
- npm i @libp2p/multistream-select
68
- ```
69
-
70
74
  ## Usage
71
75
 
72
76
  ```js
@@ -161,7 +165,7 @@ Create a new multistream select "dialer" instance which can be used to negotiate
161
165
 
162
166
  #### Parameters
163
167
 
164
- * `duplex` (`Object`) - A [duplex iterable stream](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) to dial on.
168
+ - `duplex` (`Object`) - A [duplex iterable stream](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) to dial on.
165
169
 
166
170
  #### Returns
167
171
 
@@ -179,8 +183,8 @@ Negotiate a protocol to use from a list of protocols.
179
183
 
180
184
  #### Parameters
181
185
 
182
- * `protocols` (`String[]`/`String`) - A list of protocols (or single protocol) to negotiate with. Protocols are attempted in order until a match is made.
183
- * `options` (`{ signal: AbortSignal }`) - an options object containing an AbortSignal
186
+ - `protocols` (`String[]`/`String`) - A list of protocols (or single protocol) to negotiate with. Protocols are attempted in order until a match is made.
187
+ - `options` (`{ signal: AbortSignal }`) - an options object containing an AbortSignal
184
188
 
185
189
  #### Returns
186
190
 
@@ -205,7 +209,7 @@ List protocols that the remote supports.
205
209
 
206
210
  #### Parameters
207
211
 
208
- * `options` (`{ signal: AbortSignal }`) - an options object containing an AbortSignal
212
+ - `options` (`{ signal: AbortSignal }`) - an options object containing an AbortSignal
209
213
 
210
214
  #### Returns
211
215
 
@@ -230,7 +234,7 @@ Construct a new multistream select "listener" instance which can be used to hand
230
234
 
231
235
  #### Parameters
232
236
 
233
- * `duplex` (`Object`) - A [duplex iterable stream](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) to listen on.
237
+ - `duplex` (`Object`) - A [duplex iterable stream](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it) to listen on.
234
238
 
235
239
  #### Returns
236
240
 
@@ -248,8 +252,8 @@ Handle multistream protocol selections for the given list of protocols.
248
252
 
249
253
  #### Parameters
250
254
 
251
- * `protocols` (`String[]`/`String`) - A list of protocols (or single protocol) that this listener is able to speak.
252
- * `options` (`{ signal: AbortSignal }`) - an options object containing an AbortSignal
255
+ - `protocols` (`String[]`/`String`) - A list of protocols (or single protocol) that this listener is able to speak.
256
+ - `options` (`{ signal: AbortSignal }`) - an options object containing an AbortSignal
253
257
 
254
258
  #### Returns
255
259
 
@@ -271,9 +275,9 @@ const { stream, protocol } = await listener.handle([
271
275
 
272
276
  Licensed under either of
273
277
 
274
- * Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
275
- * MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
278
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
279
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
276
280
 
277
- ### Contribution
281
+ ## Contribution
278
282
 
279
283
  Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
@@ -9,13 +9,13 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
9
9
  const NewLine = uint8ArrayFromString('\n');
10
10
  export function encode(buffer) {
11
11
  const list = new Uint8ArrayList(buffer, NewLine);
12
- return lp.encode.single(list).slice();
12
+ return lp.encode.single(list).subarray();
13
13
  }
14
14
  /**
15
15
  * `write` encodes and writes a single buffer
16
16
  */
17
17
  export function write(writer, buffer) {
18
- writer.push(encode(buffer).slice());
18
+ writer.push(encode(buffer).subarray());
19
19
  }
20
20
  /**
21
21
  * `writeAll` behaves like `write`, except it encodes an array of items as a single write
@@ -45,7 +45,7 @@ export async function read(reader, options) {
45
45
  if (buf == null) {
46
46
  throw errCode(new Error('no buffer returned'), 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE');
47
47
  }
48
- if (buf[buf.length - 1] !== NewLine[0]) {
48
+ if (buf.get(buf.byteLength - 1) !== NewLine[0]) {
49
49
  throw errCode(new Error('missing newline'), 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE');
50
50
  }
51
51
  return buf.slice(0, -1); // Remove newline
@@ -1 +1 @@
1
- {"version":3,"file":"multistream.js","sourceRoot":"","sources":["../../src/multistream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAMtE,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAA;AAE1C,MAAM,UAAU,MAAM,CAAE,MAAmC;IACzD,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEhD,OAAO,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAA;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAE,MAA4B,EAAE,MAAmC;IACtF,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,M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,MAAM,KAAK,CAAC,MAAM,CAAC,CACtC,CAAA;IAED,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,EAAE,wCAAwC,CAAC,CAAA;KACzF;IAED,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE;QAC9C,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,EAAE,wCAAwC,CAAC,CAAA;KACtF;IAED,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA,CAAC,iBAAiB;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAE,MAAc,EAAE,OAAsB;IACtE,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEvC,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAA;AAChC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/multistream-select",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "JavaScript implementation of multistream-select",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p-multistream-select#readme",
@@ -32,6 +32,7 @@
32
32
  ],
33
33
  "exports": {
34
34
  ".": {
35
+ "types": "./dist/src/index.d.ts",
35
36
  "import": "./dist/src/index.js"
36
37
  }
37
38
  },
@@ -68,15 +69,15 @@
68
69
  "release": "patch"
69
70
  },
70
71
  {
71
- "type": "chore",
72
+ "type": "docs",
72
73
  "release": "patch"
73
74
  },
74
75
  {
75
- "type": "docs",
76
+ "type": "test",
76
77
  "release": "patch"
77
78
  },
78
79
  {
79
- "type": "test",
80
+ "type": "deps",
80
81
  "release": "patch"
81
82
  },
82
83
  {
@@ -106,7 +107,11 @@
106
107
  },
107
108
  {
108
109
  "type": "docs",
109
- "section": "Trivial Changes"
110
+ "section": "Documentation"
111
+ },
112
+ {
113
+ "type": "deps",
114
+ "section": "Dependencies"
110
115
  },
111
116
  {
112
117
  "type": "test",
@@ -142,14 +147,14 @@
142
147
  "abortable-iterator": "^4.0.2",
143
148
  "err-code": "^3.0.1",
144
149
  "it-first": "^1.0.6",
145
- "it-handshake": "^4.0.0",
146
- "it-length-prefixed": "^7.0.1",
150
+ "it-handshake": "^4.0.1",
151
+ "it-length-prefixed": "^8.0.2",
147
152
  "it-pipe": "^2.0.3",
148
153
  "it-pushable": "^3.0.0",
149
- "it-reader": "^5.0.0",
154
+ "it-reader": "^6.0.1",
150
155
  "it-stream-types": "^1.0.4",
151
156
  "p-defer": "^4.0.0",
152
- "uint8arraylist": "^1.5.1",
157
+ "uint8arraylist": "^2.0.0",
153
158
  "uint8arrays": "^3.0.0"
154
159
  },
155
160
  "devDependencies": {
@@ -159,7 +164,7 @@
159
164
  "it-all": "^1.0.6",
160
165
  "it-map": "^1.0.6",
161
166
  "it-pair": "^2.0.2",
162
- "p-timeout": "^5.0.2",
167
+ "p-timeout": "^6.0.0",
163
168
  "timeout-abort-controller": "^3.0.0",
164
169
  "util": "^0.12.4",
165
170
  "varint": "^6.0.0"
@@ -17,14 +17,14 @@ const NewLine = uint8ArrayFromString('\n')
17
17
  export function encode (buffer: Uint8Array | Uint8ArrayList): Uint8Array {
18
18
  const list = new Uint8ArrayList(buffer, NewLine)
19
19
 
20
- return lp.encode.single(list).slice()
20
+ return lp.encode.single(list).subarray()
21
21
  }
22
22
 
23
23
  /**
24
24
  * `write` encodes and writes a single buffer
25
25
  */
26
26
  export function write (writer: Pushable<Uint8Array>, buffer: Uint8Array | Uint8ArrayList) {
27
- writer.push(encode(buffer).slice())
27
+ writer.push(encode(buffer).subarray())
28
28
  }
29
29
 
30
30
  /**
@@ -68,7 +68,7 @@ export async function read (reader: Reader, options?: AbortOptions) {
68
68
  throw errCode(new Error('no buffer returned'), 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
69
69
  }
70
70
 
71
- if (buf[buf.length - 1] !== NewLine[0]) {
71
+ if (buf.get(buf.byteLength - 1) !== NewLine[0]) {
72
72
  throw errCode(new Error('missing newline'), 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
73
73
  }
74
74