Skip to content

Commit 9fe04d8

Browse files
chore: use pubsubTopic/pubsubTopics across the codebase (#1653)
* chore: change all references of pubSubTopic to pubsubTopic * change references of pubSubTopics to pubsubTopics * flag words in cspell
1 parent b96c3bd commit 9fe04d8

39 files changed

+226
-226
lines changed

.cspell.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1",
2+
"version": "0.2",
33
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
44
"language": "en",
55
"words": [
@@ -123,7 +123,7 @@
123123
"Привет",
124124
"مرحبا"
125125
],
126-
"flagWords": [],
126+
"flagWords": ["pubSub", "pubSubTopics", "pubSubTopic"],
127127
"ignorePaths": [
128128
"package.json",
129129
"package-lock.json",

packages/core/src/lib/connection_manager.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class ConnectionManager
4545
peerId: string,
4646
libp2p: Libp2p,
4747
keepAliveOptions: KeepAliveOptions,
48-
pubSubTopics: PubSubTopic[],
48+
pubsubTopics: PubSubTopic[],
4949
relay?: IRelay,
5050
options?: ConnectionManagerOptions
5151
): ConnectionManager {
@@ -54,7 +54,7 @@ export class ConnectionManager
5454
instance = new ConnectionManager(
5555
libp2p,
5656
keepAliveOptions,
57-
pubSubTopics,
57+
pubsubTopics,
5858
relay,
5959
options
6060
);
@@ -500,9 +500,9 @@ export class ConnectionManager
500500
// If there's no shard information, simply return true
501501
if (!shardInfo) return true;
502502

503-
const pubSubTopics = shardInfoToPubSubTopics(shardInfo);
503+
const pubsubTopics = shardInfoToPubSubTopics(shardInfo);
504504

505-
const isTopicConfigured = pubSubTopics.some((topic) =>
505+
const isTopicConfigured = pubsubTopics.some((topic) =>
506506
this.configuredPubSubTopics.includes(topic)
507507
);
508508
return isTopicConfigured;

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

+20-20
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const FilterCodecs = {
5050

5151
class Subscription {
5252
private readonly peer: Peer;
53-
private readonly pubSubTopic: PubSubTopic;
53+
private readonly pubsubTopic: PubSubTopic;
5454
private newStream: (peer: Peer) => Promise<Stream>;
5555

5656
private subscriptionCallbacks: Map<
@@ -59,12 +59,12 @@ class Subscription {
5959
>;
6060

6161
constructor(
62-
pubSubTopic: PubSubTopic,
62+
pubsubTopic: PubSubTopic,
6363
remotePeer: Peer,
6464
newStream: (peer: Peer) => Promise<Stream>
6565
) {
6666
this.peer = remotePeer;
67-
this.pubSubTopic = pubSubTopic;
67+
this.pubsubTopic = pubsubTopic;
6868
this.newStream = newStream;
6969
this.subscriptionCallbacks = new Map();
7070
}
@@ -80,7 +80,7 @@ class Subscription {
8080
const stream = await this.newStream(this.peer);
8181

8282
const request = FilterSubscribeRpc.createSubscribeRequest(
83-
this.pubSubTopic,
83+
this.pubsubTopic,
8484
contentTopics
8585
);
8686

@@ -145,7 +145,7 @@ class Subscription {
145145
async unsubscribe(contentTopics: ContentTopic[]): Promise<void> {
146146
const stream = await this.newStream(this.peer);
147147
const unsubscribeRequest = FilterSubscribeRpc.createUnsubscribeRequest(
148-
this.pubSubTopic,
148+
this.pubsubTopic,
149149
contentTopics
150150
);
151151

@@ -194,7 +194,7 @@ class Subscription {
194194
const stream = await this.newStream(this.peer);
195195

196196
const request = FilterSubscribeRpc.createUnsubscribeAllRequest(
197-
this.pubSubTopic
197+
this.pubsubTopic
198198
);
199199

200200
try {
@@ -229,35 +229,35 @@ class Subscription {
229229
log("No subscription callback available for ", contentTopic);
230230
return;
231231
}
232-
await pushMessage(subscriptionCallback, this.pubSubTopic, message);
232+
await pushMessage(subscriptionCallback, this.pubsubTopic, message);
233233
}
234234
}
235235

236236
class Filter extends BaseProtocol implements IReceiver {
237-
private readonly pubSubTopics: PubSubTopic[] = [];
237+
private readonly pubsubTopics: PubSubTopic[] = [];
238238
private activeSubscriptions = new Map<string, Subscription>();
239239
private readonly NUM_PEERS_PROTOCOL = 1;
240240

241241
private getActiveSubscription(
242-
pubSubTopic: PubSubTopic,
242+
pubsubTopic: PubSubTopic,
243243
peerIdStr: PeerIdStr
244244
): Subscription | undefined {
245-
return this.activeSubscriptions.get(`${pubSubTopic}_${peerIdStr}`);
245+
return this.activeSubscriptions.get(`${pubsubTopic}_${peerIdStr}`);
246246
}
247247

248248
private setActiveSubscription(
249-
pubSubTopic: PubSubTopic,
249+
pubsubTopic: PubSubTopic,
250250
peerIdStr: PeerIdStr,
251251
subscription: Subscription
252252
): Subscription {
253-
this.activeSubscriptions.set(`${pubSubTopic}_${peerIdStr}`, subscription);
253+
this.activeSubscriptions.set(`${pubsubTopic}_${peerIdStr}`, subscription);
254254
return subscription;
255255
}
256256

257257
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
258258
super(FilterCodecs.SUBSCRIBE, libp2p.components);
259259

260-
this.pubSubTopics = options?.pubSubTopics || [DefaultPubSubTopic];
260+
this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic];
261261

262262
libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
263263
log("Failed to register ", FilterCodecs.PUSH, e);
@@ -267,9 +267,9 @@ class Filter extends BaseProtocol implements IReceiver {
267267
}
268268

269269
async createSubscription(
270-
pubSubTopic: string = DefaultPubSubTopic
270+
pubsubTopic: string = DefaultPubSubTopic
271271
): Promise<Subscription> {
272-
ensurePubsubTopicIsConfigured(pubSubTopic, this.pubSubTopics);
272+
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
273273

274274
//TODO: get a relevant peer for the topic/shard
275275
// https://github.com/waku-org/js-waku/pull/1586#discussion_r1336428230
@@ -281,11 +281,11 @@ class Filter extends BaseProtocol implements IReceiver {
281281
)[0];
282282

283283
const subscription =
284-
this.getActiveSubscription(pubSubTopic, peer.id.toString()) ??
284+
this.getActiveSubscription(pubsubTopic, peer.id.toString()) ??
285285
this.setActiveSubscription(
286-
pubSubTopic,
286+
pubsubTopic,
287287
peer.id.toString(),
288-
new Subscription(pubSubTopic, peer, this.getStream.bind(this, peer))
288+
new Subscription(pubsubTopic, peer, this.getStream.bind(this, peer))
289289
);
290290

291291
return subscription;
@@ -385,7 +385,7 @@ export function wakuFilter(
385385

386386
async function pushMessage<T extends IDecodedMessage>(
387387
subscriptionCallback: SubscriptionCallback<T>,
388-
pubSubTopic: PubSubTopic,
388+
pubsubTopic: PubSubTopic,
389389
message: WakuMessage
390390
): Promise<void> {
391391
const { decoders, callback } = subscriptionCallback;
@@ -399,7 +399,7 @@ async function pushMessage<T extends IDecodedMessage>(
399399
try {
400400
const decodePromises = decoders.map((dec) =>
401401
dec
402-
.fromProtoObj(pubSubTopic, message as IProtoMessage)
402+
.fromProtoObj(pubsubTopic, message as IProtoMessage)
403403
.then((decoded) => decoded || Promise.reject("Decoding failed"))
404404
);
405405

packages/core/src/lib/keep_alive_manager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ export class KeepAliveManager {
118118
): NodeJS.Timeout[] {
119119
// send a ping message to each PubSubTopic the peer is part of
120120
const intervals: NodeJS.Timeout[] = [];
121-
for (const topic of relay.pubSubTopics) {
121+
for (const topic of relay.pubsubTopics) {
122122
const meshPeers = relay.getMeshPeers(topic);
123123
if (!meshPeers.includes(peerIdStr)) continue;
124124

125125
const encoder = createEncoder({
126-
pubSubTopic: topic,
126+
pubsubTopic: topic,
127127
contentTopic: RelayPingContentTopic,
128128
ephemeral: true
129129
});

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ type PreparePushMessageResult =
4242
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
4343
*/
4444
class LightPush extends BaseProtocol implements ILightPush {
45-
private readonly pubSubTopics: PubSubTopic[];
45+
private readonly pubsubTopics: PubSubTopic[];
4646
private readonly NUM_PEERS_PROTOCOL = 1;
4747

4848
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
4949
super(LightPushCodec, libp2p.components);
50-
this.pubSubTopics = options?.pubSubTopics ?? [DefaultPubSubTopic];
50+
this.pubsubTopics = options?.pubsubTopics ?? [DefaultPubSubTopic];
5151
}
5252

5353
private async preparePushMessage(
5454
encoder: IEncoder,
5555
message: IMessage,
56-
pubSubTopic: string
56+
pubsubTopic: string
5757
): Promise<PreparePushMessageResult> {
5858
try {
5959
if (!isSizeValid(message.payload)) {
@@ -70,7 +70,7 @@ class LightPush extends BaseProtocol implements ILightPush {
7070
};
7171
}
7272

73-
const query = PushRpc.createRequest(protoMessage, pubSubTopic);
73+
const query = PushRpc.createRequest(protoMessage, pubsubTopic);
7474
return { query, error: null };
7575
} catch (error) {
7676
log("Failed to prepare push message", error);
@@ -83,15 +83,15 @@ class LightPush extends BaseProtocol implements ILightPush {
8383
}
8484

8585
async send(encoder: IEncoder, message: IMessage): Promise<SendResult> {
86-
const { pubSubTopic } = encoder;
87-
ensurePubsubTopicIsConfigured(pubSubTopic, this.pubSubTopics);
86+
const { pubsubTopic } = encoder;
87+
ensurePubsubTopicIsConfigured(pubsubTopic, this.pubsubTopics);
8888

8989
const recipients: PeerId[] = [];
9090

9191
const { query, error: preparationError } = await this.preparePushMessage(
9292
encoder,
9393
message,
94-
pubSubTopic
94+
pubsubTopic
9595
);
9696

9797
if (preparationError || !query) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ export class PushRpc {
77

88
static createRequest(
99
message: proto.WakuMessage,
10-
pubSubTopic: string
10+
pubsubTopic: string
1111
): PushRpc {
1212
return new PushRpc({
1313
requestId: uuid(),
1414
request: {
1515
message: message,
16-
pubsubTopic: pubSubTopic
16+
pubsubTopic: pubsubTopic
1717
},
1818
response: undefined
1919
});

packages/core/src/lib/message/version_0.spec.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ describe("Waku Message version 0", function () {
1111
fc.string({ minLength: 1 }),
1212
fc.string({ minLength: 1 }),
1313
fc.uint8Array({ minLength: 1 }),
14-
async (contentTopic, pubSubTopic, payload) => {
14+
async (contentTopic, pubsubTopic, payload) => {
1515
const encoder = createEncoder({
1616
contentTopic
1717
});
1818
const bytes = await encoder.toWire({ payload });
1919
const decoder = createDecoder(contentTopic);
2020
const protoResult = await decoder.fromWireToProtoObj(bytes);
2121
const result = (await decoder.fromProtoObj(
22-
pubSubTopic,
22+
pubsubTopic,
2323
protoResult!
2424
)) as DecodedMessage;
2525

2626
expect(result.contentTopic).to.eq(contentTopic);
27-
expect(result.pubSubTopic).to.eq(pubSubTopic);
27+
expect(result.pubsubTopic).to.eq(pubsubTopic);
2828
expect(result.version).to.eq(0);
2929
expect(result.ephemeral).to.be.false;
3030
expect(result.payload).to.deep.eq(payload);
@@ -40,7 +40,7 @@ describe("Waku Message version 0", function () {
4040
fc.string({ minLength: 1 }),
4141
fc.string({ minLength: 1 }),
4242
fc.uint8Array({ minLength: 1 }),
43-
async (contentTopic, pubSubTopic, payload) => {
43+
async (contentTopic, pubsubTopic, payload) => {
4444
const encoder = createEncoder({
4545
contentTopic,
4646
ephemeral: true
@@ -49,7 +49,7 @@ describe("Waku Message version 0", function () {
4949
const decoder = createDecoder(contentTopic);
5050
const protoResult = await decoder.fromWireToProtoObj(bytes);
5151
const result = (await decoder.fromProtoObj(
52-
pubSubTopic,
52+
pubsubTopic,
5353
protoResult!
5454
)) as DecodedMessage;
5555

@@ -65,7 +65,7 @@ describe("Waku Message version 0", function () {
6565
fc.string({ minLength: 1 }),
6666
fc.string({ minLength: 1 }),
6767
fc.uint8Array({ minLength: 1 }),
68-
async (contentTopic, pubSubTopic, payload) => {
68+
async (contentTopic, pubsubTopic, payload) => {
6969
// Encode the length of the payload
7070
// Not a relevant real life example
7171
const metaSetter = (
@@ -86,7 +86,7 @@ describe("Waku Message version 0", function () {
8686
const decoder = createDecoder(contentTopic);
8787
const protoResult = await decoder.fromWireToProtoObj(bytes);
8888
const result = (await decoder.fromProtoObj(
89-
pubSubTopic,
89+
pubsubTopic,
9090
protoResult!
9191
)) as DecodedMessage;
9292

packages/core/src/lib/message/version_0.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export { proto };
2222

2323
export class DecodedMessage implements IDecodedMessage {
2424
constructor(
25-
public pubSubTopic: string,
25+
public pubsubTopic: string,
2626
protected proto: proto.WakuMessage
2727
) {}
2828

@@ -76,7 +76,7 @@ export class Encoder implements IEncoder {
7676
constructor(
7777
public contentTopic: string,
7878
public ephemeral: boolean = false,
79-
public pubSubTopic: PubSubTopic,
79+
public pubsubTopic: PubSubTopic,
8080
public metaSetter?: IMetaSetter
8181
) {
8282
if (!contentTopic || contentTopic === "") {
@@ -119,17 +119,17 @@ export class Encoder implements IEncoder {
119119
* messages.
120120
*/
121121
export function createEncoder({
122-
pubSubTopic = DefaultPubSubTopic,
122+
pubsubTopic = DefaultPubSubTopic,
123123
contentTopic,
124124
ephemeral,
125125
metaSetter
126126
}: EncoderOptions): Encoder {
127-
return new Encoder(contentTopic, ephemeral, pubSubTopic, metaSetter);
127+
return new Encoder(contentTopic, ephemeral, pubsubTopic, metaSetter);
128128
}
129129

130130
export class Decoder implements IDecoder<DecodedMessage> {
131131
constructor(
132-
public pubSubTopic: PubSubTopic,
132+
public pubsubTopic: PubSubTopic,
133133
public contentTopic: string
134134
) {
135135
if (!contentTopic || contentTopic === "") {
@@ -152,7 +152,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
152152
}
153153

154154
async fromProtoObj(
155-
pubSubTopic: string,
155+
pubsubTopic: string,
156156
proto: IProtoMessage
157157
): Promise<DecodedMessage | undefined> {
158158
// https://rfc.vac.dev/spec/14/
@@ -167,7 +167,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
167167
return Promise.resolve(undefined);
168168
}
169169

170-
return new DecodedMessage(pubSubTopic, proto);
170+
return new DecodedMessage(pubsubTopic, proto);
171171
}
172172
}
173173

0 commit comments

Comments
 (0)