Skip to content

Commit

Permalink
chore: fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Aug 1, 2024
1 parent c1186e2 commit d9f4f09
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/libp2p-daemon-client/src/dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class DHT {
throw new CodeError(response.error?.msg ?? 'DHT get failed', 'ERR_DHT_GET_FAILED')
}

if (response.dht == null || response.dht.value == null) {
if (response.dht?.value == null) {
throw new CodeError('Invalid DHT get response', 'ERR_DHT_GET_FAILED')
}

Expand Down Expand Up @@ -108,7 +108,7 @@ export class DHT {
throw new CodeError(response.error?.msg ?? 'DHT find peer failed', 'ERR_DHT_FIND_PEER_FAILED')
}

if (response.dht == null || response.dht.peer == null || response.dht.peer.addrs == null) {
if (response.dht?.peer?.addrs == null) {
throw new CodeError('Invalid response', 'ERR_DHT_FIND_PEER_FAILED')
}

Expand Down Expand Up @@ -178,7 +178,7 @@ export class DHT {
}

// Stream values
if (dhtResponse.type === DHTResponse.Type.VALUE && dhtResponse.peer != null && dhtResponse.peer?.addrs != null) {
if (dhtResponse.type === DHTResponse.Type.VALUE && dhtResponse.peer?.addrs != null) {
yield {
id: peerIdFromBytes(dhtResponse.peer.id),
multiaddrs: dhtResponse.peer.addrs.map((a) => multiaddr(a))
Expand Down
5 changes: 4 additions & 1 deletion packages/libp2p-daemon-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Client implements DaemonClient {
throw new CodeError(response.error?.msg ?? 'Identify failed', 'ERR_IDENTIFY_FAILED')
}

if (response.identify == null || response.identify.addrs == null) {
if (response.identify?.addrs == null) {
throw new CodeError('Invalid response', 'ERR_IDENTIFY_FAILED')
}

Expand Down Expand Up @@ -211,6 +211,9 @@ class Client implements DaemonClient {
// @ts-expect-error because we are using a passthrough upgrader, this is a MultiaddrConnection
await handler(sh.rest())
})
.catch(err => {
connection.abort(err)
})
.finally(() => {
connection.close()
.catch(err => {
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p-daemon-client/src/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Pubsub {
throw new CodeError(response.error?.msg ?? 'Pubsub get topics failed', 'ERR_PUBSUB_GET_TOPICS_FAILED')
}

if (response.pubsub == null || response.pubsub.topics == null) {
if (response.pubsub?.topics == null) {
throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_TOPICS_FAILED')
}

Expand Down Expand Up @@ -134,7 +134,7 @@ export class Pubsub {
throw new CodeError(response.error?.msg ?? 'Pubsub get subscribers failed', 'ERR_PUBSUB_GET_SUBSCRIBERS_FAILED')
}

if (response.pubsub == null || response.pubsub.topics == null) {
if (response.pubsub?.topics == null) {
throw new CodeError('Invalid response', 'ERR_PUBSUB_GET_SUBSCRIBERS_FAILED')
}

Expand Down
6 changes: 3 additions & 3 deletions packages/libp2p-daemon-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class Server implements Libp2pServer {
* Connects the daemons libp2p node to the peer provided
*/
async connect (request: Request): Promise<Connection> {
if (request.connect == null || request.connect.addrs == null) {
if (request.connect?.addrs == null) {
throw new Error('Invalid request')
}

Expand All @@ -102,7 +102,7 @@ export class Server implements Libp2pServer {
* Opens a stream on one of the given protocols to the given peer
*/
async openStream (request: Request): Promise<OpenStream> {
if (request.streamOpen == null || request.streamOpen.proto == null) {
if (request.streamOpen?.proto == null) {
throw new Error('Invalid request')
}

Expand Down Expand Up @@ -135,7 +135,7 @@ export class Server implements Libp2pServer {
* is registered at the path, it will be overridden.
*/
async registerStreamHandler (request: Request): Promise<void> {
if (request.streamHandler == null || request.streamHandler.proto == null) {
if (request.streamHandler?.proto == null) {
throw new Error('Invalid request')
}

Expand Down

0 comments on commit d9f4f09

Please sign in to comment.