Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit e0bf45a

Browse files
maschadachingbrain
andauthored
deps(dev): Upgrade aegir to 38.1.7 (#257)
Updates aegir and removes superfluous typescript dep --------- Co-authored-by: achingbrain <alex@achingbrain.net>
1 parent a3590af commit e0bf45a

10 files changed

+73
-57
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@
165165
"devDependencies": {
166166
"@libp2p/interface-stream-muxer-compliance-tests": "^6.0.0",
167167
"@types/varint": "^6.0.0",
168-
"aegir": "^37.2.0",
168+
"aegir": "^38.1.7",
169169
"cborg": "^1.8.1",
170170
"delay": "^5.0.0",
171+
"eslint-plugin-etc": "^2.0.2",
171172
"iso-random-stream": "^2.0.2",
172173
"it-all": "^2.0.0",
173174
"it-drain": "^2.0.0",
@@ -176,8 +177,7 @@
176177
"it-pipe": "^2.0.3",
177178
"it-to-buffer": "^3.0.0",
178179
"p-defer": "^4.0.0",
179-
"random-int": "^3.0.0",
180-
"typescript": "^5.0.2"
180+
"random-int": "^3.0.0"
181181
},
182182
"browser": {
183183
"./dist/src/alloc-unsafe.js": "./dist/src/alloc-unsafe-browser.js"

src/alloc-unsafe-browser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export function allocUnsafe (size: number) {
1+
export function allocUnsafe (size: number): Uint8Array {
22
return new Uint8Array(size)
33
}

src/alloc-unsafe.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export function allocUnsafe (size: number) {
1+
export function allocUnsafe (size: number): Buffer {
22
return Buffer.allocUnsafe(size)
33
}

src/decode.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class Decoder {
2525
this._maxUnprocessedMessageQueueSize = maxUnprocessedMessageQueueSize
2626
}
2727

28-
write (chunk: Uint8Array) {
28+
write (chunk: Uint8Array): Message[] {
2929
if (chunk == null || chunk.length === 0) {
3030
return []
3131
}
@@ -109,7 +109,12 @@ export class Decoder {
109109
const MSB = 0x80
110110
const REST = 0x7F
111111

112-
function readVarInt (buf: Uint8ArrayList, offset: number = 0) {
112+
export interface ReadVarIntResult {
113+
value: number
114+
offset: number
115+
}
116+
117+
function readVarInt (buf: Uint8ArrayList, offset: number = 0): ReadVarIntResult {
113118
let res = 0
114119
let shift = 0
115120
let counter = offset

src/encode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const encoder = new Encoder()
5656
/**
5757
* Encode and yield one or more messages
5858
*/
59-
export async function * encode (source: Source<Message[]>, minSendBytes: number = 0) {
59+
export async function * encode (source: Source<Message[]>, minSendBytes: number = 0): AsyncGenerator<Uint8Array, void, undefined> {
6060
if (minSendBytes == null || minSendBytes === 0) {
6161
// just send the messages
6262
for await (const messages of source) {

src/mplex.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const MAX_STREAMS_OUTBOUND_STREAMS_PER_CONNECTION = 1024
2222
const MAX_STREAM_BUFFER_SIZE = 1024 * 1024 * 4 // 4MB
2323
const DISCONNECT_THRESHOLD = 5
2424

25-
function printMessage (msg: Message) {
25+
function printMessage (msg: Message): any {
2626
const output: any = {
2727
...msg,
2828
type: `${MessageTypeNames[msg.type]} (${msg.type})`
@@ -101,7 +101,7 @@ export class MplexStreamMuxer implements StreamMuxer {
101101
/**
102102
* Returns a Map of streams and their ids
103103
*/
104-
get streams () {
104+
get streams (): Stream[] {
105105
// Inbound and Outbound streams may have the same ids, so we need to make those unique
106106
const streams: Stream[] = []
107107
for (const stream of this._streams.initiators.values()) {
@@ -135,23 +135,23 @@ export class MplexStreamMuxer implements StreamMuxer {
135135
if (this.closeController.signal.aborted) return
136136

137137
if (err != null) {
138-
this.streams.forEach(s => s.abort(err))
138+
this.streams.forEach(s => { s.abort(err) })
139139
} else {
140-
this.streams.forEach(s => s.close())
140+
this.streams.forEach(s => { s.close() })
141141
}
142142
this.closeController.abort()
143143
}
144144

145145
/**
146146
* Called whenever an inbound stream is created
147147
*/
148-
_newReceiverStream (options: { id: number, name: string }) {
148+
_newReceiverStream (options: { id: number, name: string }): MplexStream {
149149
const { id, name } = options
150150
const registry = this._streams.receivers
151151
return this._newStream({ id, name, type: 'receiver', registry })
152152
}
153153

154-
_newStream (options: { id: number, name: string, type: 'initiator' | 'receiver', registry: Map<number, MplexStream> }) {
154+
_newStream (options: { id: number, name: string, type: 'initiator' | 'receiver', registry: Map<number, MplexStream> }): MplexStream {
155155
const { id, name, type, registry } = options
156156

157157
log('new %s stream %s', type, id)
@@ -164,15 +164,15 @@ export class MplexStreamMuxer implements StreamMuxer {
164164
throw new Error(`${type} stream ${id} already exists!`)
165165
}
166166

167-
const send = (msg: Message) => {
167+
const send = (msg: Message): void => {
168168
if (log.enabled) {
169169
log.trace('%s stream %s send', type, id, printMessage(msg))
170170
}
171171

172172
this._source.push(msg)
173173
}
174174

175-
const onEnd = () => {
175+
const onEnd = (): void => {
176176
log('%s stream with id %s and protocol %s ended', type, id, stream.stat.protocol)
177177
registry.delete(id)
178178

@@ -190,7 +190,7 @@ export class MplexStreamMuxer implements StreamMuxer {
190190
* Creates a sink with an abortable source. Incoming messages will
191191
* also have their size restricted. All messages will be varint decoded.
192192
*/
193-
_createSink () {
193+
_createSink (): Sink<Uint8Array> {
194194
const sink: Sink<Uint8Array> = async source => {
195195
// see: https://github.com/jacobheun/any-signal/pull/18
196196
const abortSignals = [this.closeController.signal]
@@ -222,8 +222,8 @@ export class MplexStreamMuxer implements StreamMuxer {
222222
* Creates a source that restricts outgoing message sizes
223223
* and varint encodes them
224224
*/
225-
_createSource () {
226-
const onEnd = (err?: Error) => {
225+
_createSource (): any {
226+
const onEnd = (err?: Error): void => {
227227
this.close(err)
228228
}
229229
const source = pushableV<Message>({
@@ -238,7 +238,7 @@ export class MplexStreamMuxer implements StreamMuxer {
238238
})
239239
}
240240

241-
async _handleIncoming (message: Message) {
241+
async _handleIncoming (message: Message): Promise<void> {
242242
const { id, type } = message
243243

244244
if (log.enabled) {

src/stream.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function createStream (options: Options): MplexStream {
4747
open: Date.now()
4848
}
4949

50-
const onSourceEnd = (err?: Error) => {
50+
const onSourceEnd = (err?: Error): void => {
5151
if (sourceEnded) {
5252
return
5353
}
@@ -68,7 +68,7 @@ export function createStream (options: Options): MplexStream {
6868
}
6969
}
7070

71-
const onSinkEnd = (err?: Error) => {
71+
const onSinkEnd = (err?: Error): void => {
7272
if (sinkEnded) {
7373
return
7474
}

test/fixtures/utils.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { Message, MessageTypes } from '../../src/message-types.js'
22

3-
export function messageWithBytes (msg: Message) {
3+
export type MessageWithBytes = {
4+
[k in keyof Message]: Message[k]
5+
} & {
6+
data: Uint8Array
7+
}
8+
9+
export function messageWithBytes (msg: Message): Message | MessageWithBytes {
410
if (msg.type === MessageTypes.NEW_STREAM || msg.type === MessageTypes.MESSAGE_INITIATOR || msg.type === MessageTypes.MESSAGE_RECEIVER) {
511
return {
612
...msg,
7-
data: msg.data.slice() // convert Uint8ArrayList to Buffer
13+
data: msg.data.slice() // convert Uint8ArrayList to Uint8Array
814
}
915
}
1016

test/restrict-size.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('restrict size', () => {
3333
(source) => each(source, chunk => {
3434
output.push(chunk)
3535
}),
36-
async (source) => await drain(source)
36+
async (source) => { await drain(source) }
3737
)
3838
} catch (err: any) {
3939
expect(err).to.have.property('code', 'ERR_MSG_TOO_BIG')
@@ -90,7 +90,7 @@ describe('restrict size', () => {
9090
(source) => each(source, chunk => {
9191
output.push(chunk)
9292
}),
93-
async (source) => await drain(source)
93+
async (source) => { await drain(source) }
9494
)
9595
} catch (err: any) {
9696
expect(err).to.have.property('code', 'ERR_MSG_QUEUE_TOO_BIG')
@@ -113,7 +113,7 @@ describe('restrict size', () => {
113113
(source) => each(source, chunk => {
114114
output.push(chunk)
115115
}),
116-
async (source) => await drain(source)
116+
async (source) => { await drain(source) }
117117
)
118118
} catch (err: any) {
119119
expect(err).to.have.property('code', 'ERR_MSG_QUEUE_TOO_BIG')

0 commit comments

Comments
 (0)