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

Commit

Permalink
deps: bump it-stream-types from 1.0.5 to 2.0.1 (#89)
Browse files Browse the repository at this point in the history
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alex Potsides <alex@achingbrain.net>
  • Loading branch information
dependabot[bot] and achingbrain authored Apr 18, 2023
1 parent 64f1e87 commit 0de4a85
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 42 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,22 @@
},
"dependencies": {
"@achingbrain/ip-address": "^8.1.0",
"@libp2p/interface-connection": "^4.0.0",
"@libp2p/interface-connection": "^5.0.1",
"@libp2p/interface-peer-store": "^1.2.1",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/logger": "^2.0.0",
"@multiformats/multiaddr": "^12.0.0",
"abortable-iterator": "^4.0.2",
"abortable-iterator": "^5.0.0",
"is-loopback-addr": "^2.0.1",
"it-stream-types": "^1.0.4",
"it-stream-types": "^2.0.1",
"private-ip": "^3.0.0",
"uint8arraylist": "^2.3.2"
},
"devDependencies": {
"aegir": "^38.1.7",
"it-all": "^3.0.1",
"it-map": "^3.0.2",
"it-pair": "^2.0.6",
"it-pipe": "^3.0.0",
"p-defer": "^4.0.0",
"uint8arrays": "^4.0.2"
}
}
11 changes: 7 additions & 4 deletions src/stream-to-ma-conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { abortableSource } from 'abortable-iterator'
import { logger } from '@libp2p/logger'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { MultiaddrConnection } from '@libp2p/interface-connection'
import type { Duplex } from 'it-stream-types'
import type { Duplex, Source } from 'it-stream-types'
import type { Uint8ArrayList } from 'uint8arraylist'

const log = logger('libp2p:stream:converter')
Expand Down Expand Up @@ -30,7 +30,7 @@ export interface StreamOptions {
}

export interface StreamProperties {
stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>
stream: Duplex<AsyncIterable<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>>
remoteAddr: Multiaddr
localAddr: Multiaddr
}
Expand All @@ -45,7 +45,11 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp

const mapSource = (async function * () {
for await (const list of source) {
yield * list
if (list instanceof Uint8Array) {
yield list
} else {
yield * list
}
}
}())

Expand All @@ -70,7 +74,6 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp
},
source: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource,
remoteAddr,
/** @type {Timeline} */
timeline: { open: Date.now(), close: undefined },
async close () {
await sink(async function * () {
Expand Down
28 changes: 0 additions & 28 deletions test/fixtures/pair.ts

This file was deleted.

10 changes: 5 additions & 5 deletions test/stream-to-ma-conn.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* eslint-env mocha */

import { expect } from 'aegir/chai'
import { pair } from './fixtures/pair.js'
import { pair } from 'it-pair'
import { pipe } from 'it-pipe'
import { multiaddr } from '@multiformats/multiaddr'
import { streamToMaConnection } from '../src/stream-to-ma-conn.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import all from 'it-all'
import type { Stream } from '@libp2p/interface-connection'
import type { Duplex } from 'it-stream-types'
import type { Duplex, Source } from 'it-stream-types'
import type { Uint8ArrayList } from 'uint8arraylist'

function toMuxedStream (stream: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>): Stream {
function toMuxedStream (stream: Duplex<AsyncGenerator<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>, Promise<void>>): Stream {
const muxedStream: Stream = {
...stream,
close: () => {},
Expand All @@ -37,7 +37,7 @@ describe('Convert stream into a multiaddr connection', () => {
const remoteAddr = multiaddr('/ip4/100.46.74.201/tcp/6002')

it('converts a stream and adds the provided metadata', async () => {
const stream = pair()
const stream = pair<any>()

const maConn = streamToMaConnection({
stream: toMuxedStream(stream),
Expand All @@ -58,7 +58,7 @@ describe('Convert stream into a multiaddr connection', () => {
})

it('can stream data over the multiaddr connection', async () => {
const stream = pair()
const stream = pair<any>()
const maConn = streamToMaConnection({
stream: toMuxedStream(stream),
localAddr,
Expand Down

0 comments on commit 0de4a85

Please sign in to comment.