Skip to content

Commit 738dd40

Browse files
authored
fix!: release majors of modules that had patches during v1.0 (#2286)
Pre-v1.0 versions of libp2p are still depending on post-1.0 modules which means they have a mixed set of versions. The change here is to cause those modules to have major releases. BREAKING CHANGE: requires libp2p v1
1 parent d34d330 commit 738dd40

File tree

10 files changed

+88
-49
lines changed

10 files changed

+88
-49
lines changed

packages/multistream-select/src/handle.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import type { Duplex } from 'it-stream-types'
5555
*/
5656
export async function handle <Stream extends Duplex<any, any, any>> (stream: Stream, protocols: string | string[], options: MultistreamSelectInit): Promise<ProtocolStream<Stream>> {
5757
protocols = Array.isArray(protocols) ? protocols : [protocols]
58-
options?.log?.trace('handle: available protocols %s', protocols)
58+
options.log.trace('handle: available protocols %s', protocols)
5959

6060
const lp = lpStream(stream, {
6161
...options,
@@ -64,21 +64,21 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
6464
})
6565

6666
while (true) {
67-
options?.log?.trace('handle: reading incoming string')
67+
options.log.trace('handle: reading incoming string')
6868
const protocol = await multistream.readString(lp, options)
69-
options?.log?.trace('handle: read "%s"', protocol)
69+
options.log.trace('handle: read "%s"', protocol)
7070

7171
if (protocol === PROTOCOL_ID) {
72-
options?.log?.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol)
72+
options.log.trace('handle: respond with "%s" for "%s"', PROTOCOL_ID, protocol)
7373
await multistream.write(lp, uint8ArrayFromString(`${PROTOCOL_ID}\n`), options)
74-
options?.log?.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol)
74+
options.log.trace('handle: responded with "%s" for "%s"', PROTOCOL_ID, protocol)
7575
continue
7676
}
7777

7878
if (protocols.includes(protocol)) {
79-
options?.log?.trace('handle: respond with "%s" for "%s"', protocol, protocol)
79+
options.log.trace('handle: respond with "%s" for "%s"', protocol, protocol)
8080
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
81-
options?.log?.trace('handle: responded with "%s" for "%s"', protocol, protocol)
81+
options.log.trace('handle: responded with "%s" for "%s"', protocol, protocol)
8282

8383
return { stream: lp.unwrap(), protocol }
8484
}
@@ -90,14 +90,14 @@ export async function handle <Stream extends Duplex<any, any, any>> (stream: Str
9090
uint8ArrayFromString('\n')
9191
)
9292

93-
options?.log?.trace('handle: respond with "%s" for %s', protocols, protocol)
93+
options.log.trace('handle: respond with "%s" for %s', protocols, protocol)
9494
await multistream.write(lp, protos, options)
95-
options?.log?.trace('handle: responded with "%s" for %s', protocols, protocol)
95+
options.log.trace('handle: responded with "%s" for %s', protocols, protocol)
9696
continue
9797
}
9898

99-
options?.log?.('handle: respond with "na" for "%s"', protocol)
99+
options.log('handle: respond with "na" for "%s"', protocol)
100100
await multistream.write(lp, uint8ArrayFromString('na\n'), options)
101-
options?.log?.('handle: responded with "na" for "%s"', protocol)
101+
options.log('handle: responded with "na" for "%s"', protocol)
102102
}
103103
}

packages/multistream-select/src/multistream.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { CodeError } from '@libp2p/interface'
22
import { type Uint8ArrayList } from 'uint8arraylist'
33
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
44
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
5-
import type { MultistreamSelectInit } from '.'
65
import type { AbortOptions, LoggerOptions } from '@libp2p/interface'
76
import type { LengthPrefixedStream } from 'it-length-prefixed-stream'
87
import type { Duplex, Source } from 'it-stream-types'
@@ -12,25 +11,25 @@ const NewLine = uint8ArrayFromString('\n')
1211
/**
1312
* `write` encodes and writes a single buffer
1413
*/
15-
export async function write (writer: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, buffer: Uint8Array | Uint8ArrayList, options?: MultistreamSelectInit): Promise<void> {
14+
export async function write (writer: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, buffer: Uint8Array | Uint8ArrayList, options?: AbortOptions): Promise<void> {
1615
await writer.write(buffer, options)
1716
}
1817

1918
/**
2019
* `writeAll` behaves like `write`, except it encodes an array of items as a single write
2120
*/
22-
export async function writeAll (writer: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, buffers: Uint8Array[], options?: MultistreamSelectInit): Promise<void> {
21+
export async function writeAll (writer: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, buffers: Uint8Array[], options?: AbortOptions): Promise<void> {
2322
await writer.writeV(buffers, options)
2423
}
2524

2625
/**
2726
* Read a length-prefixed buffer from the passed stream, stripping the final newline character
2827
*/
29-
export async function read (reader: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, options?: AbortOptions & LoggerOptions): Promise<Uint8ArrayList> {
28+
export async function read (reader: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, options: AbortOptions & LoggerOptions): Promise<Uint8ArrayList> {
3029
const buf = await reader.read(options)
3130

3231
if (buf.byteLength === 0 || buf.get(buf.byteLength - 1) !== NewLine[0]) {
33-
options?.log?.error('Invalid mss message - missing newline', buf)
32+
options.log.error('Invalid mss message - missing newline', buf)
3433
throw new CodeError('missing newline', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
3534
}
3635

@@ -40,7 +39,7 @@ export async function read (reader: LengthPrefixedStream<Duplex<AsyncGenerator<U
4039
/**
4140
* Read a length-prefixed string from the passed stream, stripping the final newline character
4241
*/
43-
export async function readString (reader: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, options?: AbortOptions & LoggerOptions): Promise<string> {
42+
export async function readString (reader: LengthPrefixedStream<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>>>, options: AbortOptions & LoggerOptions): Promise<string> {
4443
const buf = await read(reader, options)
4544

4645
return uint8ArrayToString(buf.subarray())

packages/multistream-select/src/select.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ export async function select <Stream extends SelectStream> (stream: Stream, prot
7878
throw new Error('At least one protocol must be specified')
7979
}
8080

81-
options?.log?.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
81+
options.log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
8282
const p1 = uint8ArrayFromString(`${PROTOCOL_ID}\n`)
8383
const p2 = uint8ArrayFromString(`${protocol}\n`)
8484
await multistream.writeAll(lp, [p1, p2], options)
8585

86-
options?.log?.trace('select: reading multistream-select header')
86+
options.log.trace('select: reading multistream-select header')
8787
let response = await multistream.readString(lp, options)
88-
options?.log?.trace('select: read "%s"', response)
88+
options.log.trace('select: read "%s"', response)
8989

9090
// Read the protocol response if we got the protocolId in return
9191
if (response === PROTOCOL_ID) {
92-
options?.log?.trace('select: reading protocol response')
92+
options.log.trace('select: reading protocol response')
9393
response = await multistream.readString(lp, options)
94-
options?.log?.trace('select: read "%s"', response)
94+
options.log.trace('select: read "%s"', response)
9595
}
9696

9797
// We're done
@@ -101,11 +101,11 @@ export async function select <Stream extends SelectStream> (stream: Stream, prot
101101

102102
// We haven't gotten a valid ack, try the other protocols
103103
for (const protocol of protocols) {
104-
options?.log?.trace('select: write "%s"', protocol)
104+
options.log.trace('select: write "%s"', protocol)
105105
await multistream.write(lp, uint8ArrayFromString(`${protocol}\n`), options)
106-
options?.log?.trace('select: reading protocol response')
106+
options.log.trace('select: reading protocol response')
107107
const response = await multistream.readString(lp, options)
108-
options?.log?.trace('select: read "%s" for "%s"', response, protocol)
108+
options.log.trace('select: read "%s" for "%s"', response, protocol)
109109

110110
if (response === protocol) {
111111
return { stream: lp.unwrap(), protocol }
@@ -163,7 +163,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
163163
if (!sentProtocol) {
164164
sendingProtocol = true
165165

166-
options?.log?.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
166+
options.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
167167

168168
const protocolString = `${protocol}\n`
169169

@@ -176,7 +176,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
176176
buf
177177
).subarray()
178178

179-
options?.log?.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
179+
options.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink', PROTOCOL_ID, protocol, buf.byteLength)
180180

181181
sentProtocol = true
182182
sendingProtocol = false
@@ -198,7 +198,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
198198

199199
async function negotiate (): Promise<void> {
200200
if (negotiating) {
201-
options?.log?.trace('optimistic: already negotiating %s stream', protocol)
201+
options.log.trace('optimistic: already negotiating %s stream', protocol)
202202
await doneNegotiating.promise
203203
return
204204
}
@@ -208,13 +208,13 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
208208
try {
209209
// we haven't sent the protocol yet, send it now
210210
if (!sentProtocol) {
211-
options?.log?.trace('optimistic: doing send protocol for %s stream', protocol)
211+
options.log.trace('optimistic: doing send protocol for %s stream', protocol)
212212
await doSendProtocol()
213213
}
214214

215215
// if we haven't read the protocol response yet, do it now
216216
if (!readProtocol) {
217-
options?.log?.trace('optimistic: doing read protocol for %s stream', protocol)
217+
options.log.trace('optimistic: doing read protocol for %s stream', protocol)
218218
await doReadProtocol()
219219
}
220220
} finally {
@@ -233,12 +233,12 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
233233
sendingProtocol = true
234234

235235
try {
236-
options?.log?.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
236+
options.log.trace('optimistic: write ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
237237
await lp.writeV([
238238
uint8ArrayFromString(`${PROTOCOL_ID}\n`),
239239
uint8ArrayFromString(`${protocol}\n`)
240240
])
241-
options?.log?.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
241+
options.log.trace('optimistic: wrote ["%s", "%s", data] in source', PROTOCOL_ID, protocol)
242242
} finally {
243243
sentProtocol = true
244244
sendingProtocol = false
@@ -255,15 +255,15 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
255255
readingProtocol = true
256256

257257
try {
258-
options?.log?.trace('optimistic: reading multistream select header')
258+
options.log.trace('optimistic: reading multistream select header')
259259
let response = await multistream.readString(lp, options)
260-
options?.log?.trace('optimistic: read multistream select header "%s"', response)
260+
options.log.trace('optimistic: read multistream select header "%s"', response)
261261

262262
if (response === PROTOCOL_ID) {
263263
response = await multistream.readString(lp, options)
264264
}
265265

266-
options?.log?.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol)
266+
options.log.trace('optimistic: read protocol "%s", expecting "%s"', response, protocol)
267267

268268
if (response !== protocol) {
269269
throw new CodeError('protocol selection failed', 'ERR_UNSUPPORTED_PROTOCOL')
@@ -279,7 +279,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
279279
// make sure we've done protocol negotiation before we read stream data
280280
await negotiate()
281281

282-
options?.log?.trace('optimistic: reading data from "%s" stream', protocol)
282+
options.log.trace('optimistic: reading data from "%s" stream', protocol)
283283
yield * lp.unwrap().source
284284
})()
285285

@@ -291,7 +291,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
291291
// this before closing the readable end of the stream
292292
if (!negotiated) {
293293
await negotiate().catch(err => {
294-
options?.log?.error('could not negotiate protocol before close read', err)
294+
options.log.error('could not negotiate protocol before close read', err)
295295
})
296296
}
297297

@@ -308,7 +308,7 @@ function optimisticSelect <Stream extends SelectStream> (stream: Stream, protoco
308308
// this before closing the writable end of the stream
309309
if (!negotiated) {
310310
await negotiate().catch(err => {
311-
options?.log?.error('could not negotiate protocol before close write', err)
311+
options.log.error('could not negotiate protocol before close write', err)
312312
})
313313
}
314314

packages/multistream-select/test/multistream.spec.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ describe('Multistream', () => {
1616
const inputStream = lpStream(duplexes[0])
1717
const outputStream = lpStream(duplexes[1])
1818

19-
void Multistream.write(inputStream, input, {
20-
log: logger('mss:test')
21-
})
19+
void Multistream.write(inputStream, input)
2220

2321
const output = await outputStream.read()
2422
expect(output.subarray()).to.equalBytes(input)
@@ -36,7 +34,9 @@ describe('Multistream', () => {
3634

3735
void inputStream.write(uint8ArrayFromString(`${input}\n`))
3836

39-
const output = await Multistream.read(outputStream)
37+
const output = await Multistream.read(outputStream, {
38+
log: logger('mss:test')
39+
})
4040
expect(output.subarray()).to.equalBytes(inputBuf)
4141
})
4242

@@ -50,7 +50,9 @@ describe('Multistream', () => {
5050

5151
void inputStream.write(inputBuf)
5252

53-
await expect(Multistream.read(outputStream)).to.eventually.be.rejected()
53+
await expect(Multistream.read(outputStream, {
54+
log: logger('mss:test')
55+
})).to.eventually.be.rejected()
5456
.with.property('code', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
5557
})
5658

@@ -66,7 +68,9 @@ describe('Multistream', () => {
6668

6769
void inputStream.write(input)
6870

69-
await expect(Multistream.read(outputStream)).to.eventually.be.rejected()
71+
await expect(Multistream.read(outputStream, {
72+
log: logger('mss:test')
73+
})).to.eventually.be.rejected()
7074
.with.property('code', 'ERR_MSG_DATA_TOO_LONG')
7175
})
7276

@@ -79,7 +83,9 @@ describe('Multistream', () => {
7983

8084
void inputStream.write(input)
8185

82-
await expect(Multistream.read(outputStream)).to.eventually.be.rejected()
86+
await expect(Multistream.read(outputStream, {
87+
log: logger('mss:test')
88+
})).to.eventually.be.rejected()
8389
.with.property('code', 'ERR_INVALID_MULTISTREAM_SELECT_MESSAGE')
8490
})
8591

packages/peer-collections/src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44
* We can't use PeerIds as collection keys because collection keys are compared using same-value-zero equality, so this is just a group of collections that stringifies PeerIds before storing them.
55
*
66
* PeerIds cache stringified versions of themselves so this should be a cheap operation.
7+
*
8+
* @example Peer lists
9+
*
10+
* ```JavaScript
11+
* import { peerList } from '@libp2p/peer-collections'
12+
*
13+
* const list = peerList()
14+
* list.push(peerId)
15+
* ```
16+
*
17+
* @example Peer maps
18+
*
19+
* ```JavaScript
20+
* import { peerMap } from '@libp2p/peer-collections'
21+
*
22+
* const map = peerMap<string>()
23+
* map.set(peerId, 'value')
24+
* ```
25+
*
26+
* @example Peer sets
27+
*
28+
* ```JavaScript
29+
* import { peerSet } from '@libp2p/peer-collections'
30+
*
31+
* const set = peerSet()
32+
* set.add(peerId)
33+
* ```
734
*/
835

936
export { PeerMap } from './map.js'

packages/peer-id-factory/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @packageDocumentation
33
*
4-
* Generate, import, and export PeerIDs, for use with [IPFS](https://github.com/ipfs/ipfs).
4+
* Generate, import, and export PeerIDs.
55
*
66
* A Peer ID is the SHA-256 [multihash](https://github.com/multiformats/multihash) of a public key.
77
*

packages/peer-record/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* You can read further about the envelope in [libp2p/specs#217](https://github.com/libp2p/specs/pull/217).
1313
*
14-
* @example
14+
* @example Creating a peer record
1515
*
1616
* Create an envelope with an instance of an [interface-record](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/record/index.ts) implementation and prepare it for being exchanged:
1717
*
@@ -42,7 +42,7 @@
4242
* const wireData = e.marshal()
4343
* ```
4444
*
45-
* @example
45+
* @example Consuming a peer record
4646
*
4747
* Consume a received envelope (`wireData`) and transform it back to a record:
4848
*

packages/peer-store/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @packageDocumentation
3+
*
4+
* The peer store is where libp2p stores data about the peers it has encountered on the network.
5+
*/
6+
17
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
28
import all from 'it-all'
39
import { PersistentStore, type PeerUpdate } from './store.js'

packages/pubsub-floodsub/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Instead please use [gossipsub](https://www.npmjs.com/package/@chainsafe/libp2p-gossipsub) - a more complete implementation which is also compatible with floodsub.
1111
*
12-
* @example
12+
* @example Configuring libp2p to use floodsub
1313
*
1414
* ```JavaScript
1515
* import { createLibp2pNode } from 'libp2p'

packages/pubsub/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* A set of components to be extended in order to create a pubsub implementation.
55
*
66
* @example
7+
*
78
* ```javascript
89
* import { PubSubBaseProtocol } from '@libp2p/pubsub'
910
*

0 commit comments

Comments
 (0)