Skip to content

Commit

Permalink
deps!: update it-stream-types to 2.x.x (#196)
Browse files Browse the repository at this point in the history
libp2p streams are now explicit about the types of sync/sources they provide, showing that they are `AsyncGenerator`s and not just
`AsyncIterable`s.

Refs: achingbrain/it-stream-types#45

BREAKING CHANGE: the type of the source/sink properties have changed
  • Loading branch information
achingbrain authored Apr 19, 2023
1 parent b77587d commit a09f6d5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
12 changes: 6 additions & 6 deletions packages/libp2p-daemon-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,25 @@
},
"dependencies": {
"@libp2p/daemon-protocol": "^3.0.0",
"@libp2p/interface-connection": "^4.0.0",
"@libp2p/interface-connection": "^5.0.1",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface-peer-info": "^1.0.1",
"@libp2p/interface-transport": "^2.0.0",
"@libp2p/interface-transport": "^3.0.0",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/logger": "^2.0.0",
"@libp2p/peer-id": "^2.0.0",
"@libp2p/tcp": "^6.0.8",
"@libp2p/tcp": "^7.0.0",
"@multiformats/multiaddr": "^12.0.0",
"it-stream-types": "^1.0.4",
"it-stream-types": "^2.0.1",
"multiformats": "^11.0.0",
"uint8arraylist": "^2.3.2"
},
"devDependencies": {
"@libp2p/daemon-server": "^4.0.0",
"@libp2p/interface-dht": "^2.0.0",
"@libp2p/interface-mocks": "^9.0.0",
"@libp2p/interface-mocks": "^10.0.3",
"@libp2p/interface-peer-store": "^1.0.0",
"@libp2p/interface-pubsub": "^3.0.0",
"@libp2p/interface-pubsub": "^4.0.0",
"aegir": "^38.1.6",
"it-all": "^3.0.1",
"it-pipe": "^3.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/libp2p-daemon-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Pubsub } from './pubsub.js'
import { isPeerId, PeerId } from '@libp2p/interface-peer-id'
import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader'
import { peerIdFromBytes } from '@libp2p/peer-id'
import type { Duplex } from 'it-stream-types'
import type { Duplex, Source } from 'it-stream-types'
import type { CID } from 'multiformats/cid'
import type { PeerInfo } from '@libp2p/interface-peer-info'
import type { MultiaddrConnection } from '@libp2p/interface-connection'
Expand Down Expand Up @@ -168,7 +168,7 @@ class Client implements DaemonClient {
/**
* Initiate an outbound stream to a peer on one of a set of protocols.
*/
async openStream (peerId: PeerId, protocol: string): Promise<Duplex<Uint8ArrayList, Uint8Array>> {
async openStream (peerId: PeerId, protocol: string): Promise<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>, Promise<void>>> {
if (!isPeerId(peerId)) {
throw new CodeError('invalid peer id received', 'ERR_INVALID_PEER_ID')
}
Expand Down Expand Up @@ -282,7 +282,7 @@ export interface IdentifyResult {
}

export interface StreamHandlerFunction {
(stream: Duplex<Uint8ArrayList, Uint8Array>): Promise<void>
(stream: Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>, Promise<void>>): Promise<void>
}

export interface DHTClient {
Expand Down Expand Up @@ -314,7 +314,7 @@ export interface DaemonClient {
pubsub: PubSubClient

send: (request: Request) => Promise<StreamHandler>
openStream: (peerId: PeerId, protocol: string) => Promise<Duplex<Uint8ArrayList, Uint8Array>>
openStream: (peerId: PeerId, protocol: string) => Promise<Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>, Source<Uint8Array>, Promise<void>>>
registerStreamHandler: (protocol: string, handler: StreamHandlerFunction) => Promise<void>
}

Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p-daemon-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"release": "aegir release"
},
"dependencies": {
"@libp2p/interface-transport": "^2.0.0",
"@libp2p/interface-transport": "^3.0.0",
"it-handshake": "^4.0.0",
"protons-runtime": "^5.0.0",
"uint8arraylist": "^2.3.2"
Expand Down
7 changes: 4 additions & 3 deletions packages/libp2p-daemon-protocol/src/stream-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import type { Uint8ArrayList } from 'uint8arraylist'
const log = logger('libp2p:daemon-protocol:stream-handler')

export interface StreamHandlerOptions {
stream: Duplex<Uint8Array>
stream: Duplex<AsyncIterable<Uint8Array>, Source<Uint8Array>, Promise<void>>
maxLength?: number
}

export class StreamHandler {
private readonly stream: Duplex<Uint8Array>
private readonly stream: Duplex<AsyncIterable<Uint8Array>, Source<Uint8Array>, Promise<void>>
private readonly shake: Handshake<Uint8Array>
public decoder: Source<Uint8ArrayList>

/**
* Create a stream handler for connection
*/
Expand Down Expand Up @@ -52,7 +53,7 @@ export class StreamHandler {
/**
* Return the handshake rest stream and invalidate handler
*/
rest (): Duplex<Uint8ArrayList, Uint8Array> {
rest (): Duplex<AsyncGenerator<Uint8ArrayList | Uint8Array>, Source<Uint8Array>, Promise<void>> {
this.shake.rest()
return this.shake.stream
}
Expand Down
8 changes: 4 additions & 4 deletions packages/libp2p-daemon-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@
},
"dependencies": {
"@libp2p/daemon-protocol": "^3.0.0",
"@libp2p/interface-connection": "^4.0.0",
"@libp2p/interface-connection": "^5.0.1",
"@libp2p/interface-dht": "^2.0.0",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface-peer-store": "^1.2.8",
"@libp2p/interface-pubsub": "^3.0.6",
"@libp2p/interface-pubsub": "^4.0.0",
"@libp2p/interface-registrar": "^2.0.1",
"@libp2p/interface-transport": "^2.0.0",
"@libp2p/interface-transport": "^3.0.0",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/logger": "^2.0.0",
"@libp2p/peer-id": "^2.0.0",
"@libp2p/tcp": "^6.0.8",
"@libp2p/tcp": "^7.0.0",
"@multiformats/multiaddr": "^12.0.0",
"it-drain": "^3.0.1",
"it-length-prefixed": "^9.0.0",
Expand Down

0 comments on commit a09f6d5

Please sign in to comment.