Skip to content

Commit 1361cf5

Browse files
committed
fix: align libp2p types
1 parent a7f30b1 commit 1361cf5

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

packages/core/src/lib/filter/filter.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { PeerId } from "@libp2p/interface";
2-
import type { IncomingStreamData } from "@libp2p/interface-internal";
1+
import type { PeerId, StreamHandler } from "@libp2p/interface";
32
import {
43
type ContentTopic,
54
type CoreProtocolResult,
@@ -52,7 +51,7 @@ export class FilterCore {
5251

5352
public async start(): Promise<void> {
5453
try {
55-
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
54+
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest, {
5655
maxInboundStreams: 100
5756
});
5857
} catch (e) {
@@ -304,7 +303,7 @@ export class FilterCore {
304303
};
305304
}
306305

307-
private onRequest(streamData: IncomingStreamData): void {
306+
private onRequest: StreamHandler = (streamData) => {
308307
const { connection, stream } = streamData;
309308
const { remotePeer } = connection;
310309
log.info(`Received message from ${remotePeer.toString()}`);
@@ -345,5 +344,5 @@ export class FilterCore {
345344
} catch (e) {
346345
log.error("Error decoding message", e);
347346
}
348-
}
347+
};
349348
}

packages/core/src/lib/stream_manager/stream_manager.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("StreamManager", () => {
3434
createMockStream({ id: "1", protocol: MULTICODEC, writeStatus })
3535
];
3636

37-
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
37+
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
3838
_peerId: PeerId | undefined
3939
) => [con1];
4040

@@ -46,7 +46,7 @@ describe("StreamManager", () => {
4646
});
4747

4848
it("should return undefined if no connection provided", async () => {
49-
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
49+
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
5050
_peerId: PeerId | undefined
5151
) => [];
5252

@@ -70,7 +70,7 @@ describe("StreamManager", () => {
7070
);
7171

7272
con1.newStream = newStreamSpy;
73-
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
73+
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
7474
_peerId: PeerId | undefined
7575
) => [con1];
7676

@@ -97,7 +97,7 @@ describe("StreamManager", () => {
9797
);
9898

9999
con1.newStream = newStreamSpy;
100-
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
100+
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
101101
_peerId: PeerId | undefined
102102
) => [con1];
103103

@@ -148,7 +148,7 @@ describe("StreamManager", () => {
148148
writeStatus: "writable"
149149
})
150150
];
151-
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
151+
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
152152
_id: PeerId | undefined
153153
) => [con1];
154154

@@ -178,7 +178,6 @@ function createMockConnection(options: MockConnectionOptions = {}): Connection {
178178
}
179179
} as Connection;
180180
}
181-
182181
type MockStreamOptions = {
183182
id?: string;
184183
protocol?: string;

packages/interfaces/src/waku.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,35 @@ export type CreateEncoderParams = CreateDecoderParams & {
2525
ephemeral?: boolean;
2626
};
2727

28-
export enum WakuEvent {
29-
Connection = "waku:connection",
30-
Health = "waku:health"
31-
}
28+
export const WakuEvent = {
29+
Connection: "waku:connection",
30+
Health: "waku:health"
31+
} as const;
32+
33+
export type WakuEvent = (typeof WakuEvent)[keyof typeof WakuEvent];
3234

3335
export interface IWakuEvents {
3436
/**
3537
* Emitted when a connection is established or lost.
3638
*
3739
* @example
3840
* ```typescript
39-
* waku.addEventListener(WakuEvent.Connection, (event) => {
41+
* waku.events.addEventListener("waku:connection", (event) => {
4042
* console.log(event.detail); // true if connected, false if disconnected
4143
* });
4244
*/
43-
[WakuEvent.Connection]: CustomEvent<boolean>;
45+
"waku:connection": CustomEvent<boolean>;
4446

4547
/**
4648
* Emitted when the health status changes.
4749
*
4850
* @example
4951
* ```typescript
50-
* waku.addEventListener(WakuEvent.Health, (event) => {
52+
* waku.events.addEventListener("waku:health", (event) => {
5153
* console.log(event.detail); // 'Unhealthy', 'MinimallyHealthy', or 'SufficientlyHealthy'
5254
* });
5355
*/
54-
[WakuEvent.Health]: CustomEvent<HealthStatus>;
56+
"waku:health": CustomEvent<HealthStatus>;
5557
}
5658

5759
export type IWakuEventEmitter = TypedEventEmitter<IWakuEvents>;
@@ -66,12 +68,12 @@ export interface IWaku {
6668
/**
6769
* Emits events related to the Waku node.
6870
* Those are:
69-
* - WakuEvent.Connection
70-
* - WakuEvent.Health
71+
* - "waku:connection"
72+
* - "waku:health"
7173
*
7274
* @example
7375
* ```typescript
74-
* waku.events.addEventListener(WakuEvent.Connection, (event) => {
76+
* waku.events.addEventListener("waku:connection", (event) => {
7577
* console.log(event.detail); // true if connected, false if disconnected
7678
* });
7779
* ```

0 commit comments

Comments
 (0)