Skip to content

Commit 0f6a594

Browse files
authored
feat!: use ISender and deprecate Light Push .push (#1217)
1 parent b8f7db2 commit 0f6a594

File tree

9 files changed

+40
-44
lines changed

9 files changed

+40
-44
lines changed

packages/core/src/lib/light_push/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LightPush extends BaseProtocol implements ILightPush {
3636
this.options = options || {};
3737
}
3838

39-
async push(
39+
async send(
4040
encoder: IEncoder,
4141
message: IMessage,
4242
opts?: ProtocolOptions

packages/interfaces/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from "./relay.js";
88
export * from "./store.js";
99
export * from "./waku.js";
1010
export * from "./connection_manager.js";
11+
export * from "./sender.js";

packages/interfaces/src/light_push.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import type { IEncoder, IMessage } from "./message.js";
2-
import type {
3-
PointToPointProtocol,
4-
ProtocolOptions,
5-
SendResult,
6-
} from "./protocols.js";
1+
import type { PointToPointProtocol } from "./protocols.js";
2+
import type { ISender } from "./sender.js";
73

8-
export interface ILightPush extends PointToPointProtocol {
9-
push: (
10-
encoder: IEncoder,
11-
message: IMessage,
12-
opts?: ProtocolOptions
13-
) => Promise<SendResult>;
14-
}
4+
export type ILightPush = ISender & PointToPointProtocol;

packages/interfaces/src/relay.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import type { GossipSub, GossipsubEvents } from "@chainsafe/libp2p-gossipsub";
22
import type { EventEmitter } from "@libp2p/interfaces/events";
33

4-
import type {
5-
IDecodedMessage,
6-
IDecoder,
7-
IEncoder,
8-
IMessage,
9-
} from "./message.js";
10-
import type { Callback, SendResult } from "./protocols.js";
4+
import type { IDecodedMessage, IDecoder } from "./message.js";
5+
import type { Callback } from "./protocols.js";
6+
import type { ISender } from "./sender.js";
117

128
export interface RelayEvents {
139
"observer:added": CustomEvent;
@@ -16,13 +12,12 @@ export interface RelayEvents {
1612

1713
type IRelayEmitter = EventEmitter<RelayEvents & GossipsubEvents>;
1814

19-
interface IRelayAPI extends GossipSub {
20-
send: (encoder: IEncoder, message: IMessage) => Promise<SendResult>;
15+
interface IRelayAPI {
2116
addObserver: <T extends IDecodedMessage>(
2217
decoder: IDecoder<T>,
2318
callback: Callback<T>
2419
) => () => void;
2520
getMeshPeers: () => string[];
2621
}
2722

28-
export type IRelay = IRelayAPI & IRelayEmitter;
23+
export type IRelay = ISender & GossipSub & IRelayAPI & IRelayEmitter;

packages/interfaces/src/sender.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { IEncoder, IMessage } from "./message.js";
2+
import type { ProtocolOptions, SendResult } from "./protocols.js";
3+
4+
export interface ISender {
5+
send: (
6+
encoder: IEncoder,
7+
message: IMessage,
8+
opts?: ProtocolOptions
9+
) => Promise<SendResult>;
10+
}

packages/tests/tests/ephemeral.node.spec.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ describe("Waku Message Ephemeral field", () => {
135135

136136
log("Sending messages using light push");
137137
await Promise.all([
138-
waku1.lightPush.push(asymEncoder, asymMsg),
139-
waku1.lightPush.push(symEncoder, symMsg),
140-
waku1.lightPush.push(clearEncoder, clearMsg),
138+
waku1.lightPush.send(asymEncoder, asymMsg),
139+
waku1.lightPush.send(symEncoder, symMsg),
140+
waku1.lightPush.send(clearEncoder, clearMsg),
141141
]);
142142

143143
await waitForRemotePeer(waku2, [Protocols.Store]);
@@ -181,10 +181,10 @@ describe("Waku Message Ephemeral field", () => {
181181
await delay(200);
182182
const normalTxt = "Normal message";
183183
const ephemeralTxt = "Ephemeral Message";
184-
await waku.lightPush.push(TestEncoder, {
184+
await waku.lightPush.send(TestEncoder, {
185185
payload: utf8ToBytes(normalTxt),
186186
});
187-
await waku.lightPush.push(ephemeralEncoder, {
187+
await waku.lightPush.send(ephemeralEncoder, {
188188
payload: utf8ToBytes(ephemeralTxt),
189189
});
190190
while (messages.length < 2) {
@@ -230,10 +230,10 @@ describe("Waku Message Ephemeral field", () => {
230230
await delay(200);
231231
const normalTxt = "Normal message";
232232
const ephemeralTxt = "Ephemeral Message";
233-
await waku.lightPush.push(encoder, {
233+
await waku.lightPush.send(encoder, {
234234
payload: utf8ToBytes(normalTxt),
235235
});
236-
await waku.lightPush.push(ephemeralEncoder, {
236+
await waku.lightPush.send(ephemeralEncoder, {
237237
payload: utf8ToBytes(ephemeralTxt),
238238
});
239239
while (messages.length < 2) {
@@ -280,10 +280,10 @@ describe("Waku Message Ephemeral field", () => {
280280
await delay(200);
281281
const normalTxt = "Normal message";
282282
const ephemeralTxt = "Ephemeral Message";
283-
await waku.lightPush.push(encoder, {
283+
await waku.lightPush.send(encoder, {
284284
payload: utf8ToBytes(normalTxt),
285285
});
286-
await waku.lightPush.push(ephemeralEncoder, {
286+
await waku.lightPush.send(ephemeralEncoder, {
287287
payload: utf8ToBytes(ephemeralTxt),
288288
});
289289
while (messages.length < 2) {

packages/tests/tests/filter.node.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("Waku Filter", () => {
6363
// correct in future versions of the protocol.
6464
await delay(200);
6565

66-
await waku.lightPush.push(TestEncoder, message);
66+
await waku.lightPush.send(TestEncoder, message);
6767
while (messageCount === 0) {
6868
await delay(250);
6969
}
@@ -81,10 +81,10 @@ describe("Waku Filter", () => {
8181
await waku.filter.subscribe([TestDecoder], callback);
8282

8383
await delay(200);
84-
await waku.lightPush.push(TestEncoder, {
84+
await waku.lightPush.send(TestEncoder, {
8585
payload: utf8ToBytes("Filtering works!"),
8686
});
87-
await waku.lightPush.push(TestEncoder, {
87+
await waku.lightPush.send(TestEncoder, {
8888
payload: utf8ToBytes("Filtering still works!"),
8989
});
9090
while (messageCount < 2) {
@@ -101,13 +101,13 @@ describe("Waku Filter", () => {
101101
const unsubscribe = await waku.filter.subscribe([TestDecoder], callback);
102102

103103
await delay(200);
104-
await waku.lightPush.push(TestEncoder, {
104+
await waku.lightPush.send(TestEncoder, {
105105
payload: utf8ToBytes("This should be received"),
106106
});
107107
await delay(100);
108108
await unsubscribe();
109109
await delay(200);
110-
await waku.lightPush.push(TestEncoder, {
110+
await waku.lightPush.send(TestEncoder, {
111111
payload: utf8ToBytes("This should not be received"),
112112
});
113113
await delay(100);

packages/tests/tests/light_push.node.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("Waku Light Push [node only]", () => {
4646

4747
const messageText = "Light Push works!";
4848

49-
const pushResponse = await waku.lightPush.push(TestEncoder, {
49+
const pushResponse = await waku.lightPush.send(TestEncoder, {
5050
payload: utf8ToBytes(messageText),
5151
});
5252
expect(pushResponse.recipients.length).to.eq(1);
@@ -87,7 +87,7 @@ describe("Waku Light Push [node only]", () => {
8787
const messageText = "Light Push works!";
8888

8989
log("Send message via lightpush");
90-
const pushResponse = await waku.lightPush.push(
90+
const pushResponse = await waku.lightPush.send(
9191
TestEncoder,
9292
{ payload: utf8ToBytes(messageText) },
9393
{

packages/tests/tests/store.node.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ describe("Waku Store", () => {
412412

413413
log("Sending messages using light push");
414414
await Promise.all([
415-
waku1.lightPush.push(eciesEncoder, asymMsg),
416-
waku1.lightPush.push(symEncoder, symMsg),
417-
waku1.lightPush.push(otherEncoder, otherMsg),
418-
waku1.lightPush.push(TestEncoder, clearMsg),
415+
waku1.lightPush.send(eciesEncoder, asymMsg),
416+
waku1.lightPush.send(symEncoder, symMsg),
417+
waku1.lightPush.send(otherEncoder, otherMsg),
418+
waku1.lightPush.send(TestEncoder, clearMsg),
419419
]);
420420

421421
await waitForRemotePeer(waku2, [Protocols.Store]);

0 commit comments

Comments
 (0)