Rename all `pubsubTopic` occurrences to `pubSubTopic`

This commit is contained in:
Franck Royer 2021-08-20 10:12:19 +10:00
parent 026aaaf67e
commit 1d48dc4372
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
15 changed files with 71 additions and 70 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Examples (eth-pm): Use sign typed data EIP-712 instead of personal sign.
- Upgraded dependencies to remove warning at installation.
- **Breaking**: Moved `DefaultPubSubTopic` to `waku.ts` and fixed the casing.
- **Breaking**: Rename all `pubsubTopic` occurrences to `pubSubTopic`, across all interfaces.
### Removed
- Examples (cli-chat): The focus of this library is Web environment;

View File

@ -5,7 +5,7 @@ package waku.v2;
import "waku/v2/message.proto";
message PushRequest {
string pubsub_topic = 1;
string pub_sub_topic = 1;
WakuMessage message = 2;
}

View File

@ -25,7 +25,7 @@ message ContentFilter {
}
message HistoryQuery {
optional string pubsub_topic = 2;
optional string pub_sub_topic = 2;
repeated ContentFilter content_filters = 3;
optional PagingInfo paging_info = 4;
optional double start_time = 5;

View File

@ -50,7 +50,7 @@ export interface CreateOptions {
*
* @default {@link DefaultPubSubTopic}
*/
pubsubTopic?: string;
pubSubTopic?: string;
/**
* Set keep alive frequency in seconds: Waku will send a `/ipfs/ping/1.0.0`
* request to each peer after the set number of seconds. Set to 0 to disable.
@ -158,9 +158,9 @@ export class Waku {
);
// Pass pubsub topic to relay
if (options?.pubsubTopic) {
if (options?.pubSubTopic) {
libp2pOpts.config.pubsub = Object.assign(
{ pubsubTopic: options.pubsubTopic },
{ pubSubTopic: options.pubSubTopic },
libp2pOpts.config.pubsub
);
}
@ -222,7 +222,7 @@ export class Waku {
const libp2p = await Libp2p.create(libp2pOpts);
const wakuStore = new WakuStore(libp2p, {
pubsubTopic: options?.pubsubTopic,
pubSubTopic: options?.pubSubTopic,
});
const wakuLightPush = new WakuLightPush(libp2p);

View File

@ -66,7 +66,7 @@ describe('Waku Light Push', () => {
await nimWaku.start({ lightpush: true, topics: customPubSubTopic });
waku = await Waku.create({
pubsubTopic: customPubSubTopic,
pubSubTopic: customPubSubTopic,
staticNoiseKey: NOISE_KEY_1,
libp2p: { modules: { transport: [TCP] } },
});

View File

@ -66,10 +66,10 @@ export class WakuLightPush {
const { stream } = await connection.newStream(LightPushCodec);
try {
const pubsubTopic = opts?.pubSubTopic
const pubSubTopic = opts?.pubSubTopic
? opts.pubSubTopic
: this.pubSubTopic;
const query = PushRPC.createRequest(message, pubsubTopic);
const query = PushRPC.createRequest(message, pubSubTopic);
const res = await pipe(
[query.encode()],
lp.encode(),

View File

@ -7,12 +7,12 @@ import { WakuMessage } from '../waku_message';
export class PushRPC {
public constructor(public proto: proto.PushRPC) {}
static createRequest(message: WakuMessage, pubsubTopic: string): PushRPC {
static createRequest(message: WakuMessage, pubSubTopic: string): PushRPC {
return new PushRPC({
requestId: uuid(),
request: {
message: message.proto,
pubsubTopic,
pubSubTopic: pubSubTopic,
},
response: undefined,
});

View File

@ -178,16 +178,16 @@ describe('Waku Relay', () => {
it('Publish', async function () {
this.timeout(10000);
const pubsubTopic = '/some/pubsub/topic';
const pubSubTopic = '/some/pubsub/topic';
// 1 and 2 uses a custom pubsub
const [waku1, waku2, waku3] = await Promise.all([
Waku.create({
pubsubTopic,
pubSubTopic: pubSubTopic,
staticNoiseKey: NOISE_KEY_1,
}),
Waku.create({
pubsubTopic,
pubSubTopic: pubSubTopic,
staticNoiseKey: NOISE_KEY_2,
libp2p: { addresses: { listen: ['/ip4/0.0.0.0/tcp/0/ws'] } },
}),

View File

@ -62,7 +62,7 @@ export interface GossipOptions {
*/
export class WakuRelay extends Gossipsub {
heartbeat: RelayHeartbeat;
pubsubTopic: string;
pubSubTopic: string;
/**
* Decryption private keys to use to attempt decryption of incoming messages.
@ -97,7 +97,7 @@ export class WakuRelay extends Gossipsub {
Object.assign(this, { multicodecs });
this.pubsubTopic = options?.pubsubTopic || DefaultPubSubTopic;
this.pubSubTopic = options?.pubSubTopic || DefaultPubSubTopic;
}
/**
@ -109,7 +109,7 @@ export class WakuRelay extends Gossipsub {
*/
public start(): void {
super.start();
this.subscribe(this.pubsubTopic);
this.subscribe(this.pubSubTopic);
}
/**
@ -120,7 +120,7 @@ export class WakuRelay extends Gossipsub {
*/
public async send(message: WakuMessage): Promise<void> {
const msg = message.encode();
await super.publish(this.pubsubTopic, Buffer.from(msg));
await super.publish(this.pubSubTopic, Buffer.from(msg));
}
/**
@ -194,7 +194,7 @@ export class WakuRelay extends Gossipsub {
* Return the relay peers we are connected to and we would publish a message to
*/
getPeers(): Set<string> {
return getRelayPeers(this, this.pubsubTopic, this._options.D, (id) => {
return getRelayPeers(this, this.pubSubTopic, this._options.D, (id) => {
// Filter peers we would not publish to
return (
this.score.score(id) >= this._options.scoreThresholds.publishThreshold
@ -207,9 +207,9 @@ export class WakuRelay extends Gossipsub {
*
* @override
*/
subscribe(pubsubTopic: string): void {
this.on(pubsubTopic, (event) => {
dbg(`Message received on ${pubsubTopic}`);
subscribe(pubSubTopic: string): void {
this.on(pubSubTopic, (event) => {
dbg(`Message received on ${pubSubTopic}`);
WakuMessage.decode(event.data, Array.from(this.decryptionKeys))
.then((wakuMsg) => {
if (!wakuMsg) {
@ -235,7 +235,7 @@ export class WakuRelay extends Gossipsub {
});
});
super.subscribe(pubsubTopic);
super.subscribe(pubSubTopic);
}
/**

View File

@ -11,7 +11,7 @@ export enum Direction {
export interface Params {
contentTopics: string[];
cursor?: proto.Index;
pubsubTopic: string;
pubSubTopic: string;
direction: Direction;
pageSize: number;
}
@ -37,7 +37,7 @@ export class HistoryRPC {
return new HistoryRPC({
requestId: uuid(),
query: {
pubsubTopic: params.pubsubTopic,
pubSubTopic: params.pubSubTopic,
contentFilters,
pagingInfo,
startTime: undefined,

View File

@ -120,7 +120,7 @@ describe('Waku Store', () => {
}
waku = await Waku.create({
pubsubTopic: customPubSubTopic,
pubSubTopic: customPubSubTopic,
staticNoiseKey: NOISE_KEY_1,
libp2p: { modules: { transport: [TCP] } },
});

View File

@ -28,12 +28,12 @@ export interface CreateOptions {
*
* @default {@link DefaultPubSubTopic}
*/
pubsubTopic?: string;
pubSubTopic?: string;
}
export interface QueryOptions {
peerId?: PeerId;
pubsubTopic?: string;
pubSubTopic?: string;
direction?: Direction;
pageSize?: number;
callback?: (messages: WakuMessage[]) => void;
@ -44,13 +44,13 @@ export interface QueryOptions {
* Implements the [Waku v2 Store protocol](https://rfc.vac.dev/spec/13/).
*/
export class WakuStore {
pubsubTopic: string;
pubSubTopic: string;
constructor(public libp2p: Libp2p, options?: CreateOptions) {
if (options?.pubsubTopic) {
this.pubsubTopic = options.pubsubTopic;
if (options?.pubSubTopic) {
this.pubSubTopic = options.pubSubTopic;
} else {
this.pubsubTopic = DefaultPubSubTopic;
this.pubSubTopic = DefaultPubSubTopic;
}
}
@ -61,7 +61,7 @@ export class WakuStore {
* retrieve all messages.
* @param options
* @param options.peerId The peer to query.Options
* @param options.pubsubTopic The pubsub topic to pass to the query. Defaults
* @param options.pubSubTopic The pubsub topic to pass to the query. Defaults
* to the value set at creation. See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/).
* @param options.callback Callback called on page of stored messages as they are retrieved
* @param options.decryptionKeys Keys that will be used to decrypt messages.
@ -75,7 +75,7 @@ export class WakuStore {
): Promise<WakuMessage[]> {
const opts = Object.assign(
{
pubsubTopic: this.pubsubTopic,
pubSubTopic: this.pubSubTopic,
direction: Direction.BACKWARD,
pageSize: 10,
},
@ -131,7 +131,7 @@ export class WakuStore {
}
dbg(
`${response.messages.length} messages retrieved for pubsub topic ${opts.pubsubTopic}`
`${response.messages.length} messages retrieved for pubsub topic ${opts.pubSubTopic}`
);
const pageMessages: WakuMessage[] = [];

View File

@ -6,7 +6,7 @@ import { WakuMessage } from '../../waku/v2/message';
export const protobufPackage = 'waku.v2';
export interface PushRequest {
pubsubTopic: string;
pubSubTopic: string;
message: WakuMessage | undefined;
}
@ -21,15 +21,15 @@ export interface PushRPC {
response: PushResponse | undefined;
}
const basePushRequest: object = { pubsubTopic: '' };
const basePushRequest: object = { pubSubTopic: '' };
export const PushRequest = {
encode(
message: PushRequest,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.pubsubTopic !== '') {
writer.uint32(10).string(message.pubsubTopic);
if (message.pubSubTopic !== '') {
writer.uint32(10).string(message.pubSubTopic);
}
if (message.message !== undefined) {
WakuMessage.encode(message.message, writer.uint32(18).fork()).ldelim();
@ -45,7 +45,7 @@ export const PushRequest = {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.pubsubTopic = reader.string();
message.pubSubTopic = reader.string();
break;
case 2:
message.message = WakuMessage.decode(reader, reader.uint32());
@ -60,10 +60,10 @@ export const PushRequest = {
fromJSON(object: any): PushRequest {
const message = { ...basePushRequest } as PushRequest;
if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) {
message.pubsubTopic = String(object.pubsubTopic);
if (object.pubSubTopic !== undefined && object.pubSubTopic !== null) {
message.pubSubTopic = String(object.pubSubTopic);
} else {
message.pubsubTopic = '';
message.pubSubTopic = '';
}
if (object.message !== undefined && object.message !== null) {
message.message = WakuMessage.fromJSON(object.message);
@ -75,8 +75,8 @@ export const PushRequest = {
toJSON(message: PushRequest): unknown {
const obj: any = {};
message.pubsubTopic !== undefined &&
(obj.pubsubTopic = message.pubsubTopic);
message.pubSubTopic !== undefined &&
(obj.pubSubTopic = message.pubSubTopic);
message.message !== undefined &&
(obj.message = message.message
? WakuMessage.toJSON(message.message)
@ -86,10 +86,10 @@ export const PushRequest = {
fromPartial(object: DeepPartial<PushRequest>): PushRequest {
const message = { ...basePushRequest } as PushRequest;
if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) {
message.pubsubTopic = object.pubsubTopic;
if (object.pubSubTopic !== undefined && object.pubSubTopic !== null) {
message.pubSubTopic = object.pubSubTopic;
} else {
message.pubsubTopic = '';
message.pubSubTopic = '';
}
if (object.message !== undefined && object.message !== null) {
message.message = WakuMessage.fromPartial(object.message);

View File

@ -58,7 +58,7 @@ export interface ContentFilter {
}
export interface HistoryQuery {
pubsubTopic?: string | undefined;
pubSubTopic?: string | undefined;
contentFilters: ContentFilter[];
pagingInfo?: PagingInfo | undefined;
startTime?: number | undefined;
@ -366,8 +366,8 @@ export const HistoryQuery = {
message: HistoryQuery,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.pubsubTopic !== undefined) {
writer.uint32(18).string(message.pubsubTopic);
if (message.pubSubTopic !== undefined) {
writer.uint32(18).string(message.pubSubTopic);
}
for (const v of message.contentFilters) {
ContentFilter.encode(v!, writer.uint32(26).fork()).ldelim();
@ -393,7 +393,7 @@ export const HistoryQuery = {
const tag = reader.uint32();
switch (tag >>> 3) {
case 2:
message.pubsubTopic = reader.string();
message.pubSubTopic = reader.string();
break;
case 3:
message.contentFilters.push(
@ -420,10 +420,10 @@ export const HistoryQuery = {
fromJSON(object: any): HistoryQuery {
const message = { ...baseHistoryQuery } as HistoryQuery;
message.contentFilters = [];
if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) {
message.pubsubTopic = String(object.pubsubTopic);
if (object.pubSubTopic !== undefined && object.pubSubTopic !== null) {
message.pubSubTopic = String(object.pubSubTopic);
} else {
message.pubsubTopic = undefined;
message.pubSubTopic = undefined;
}
if (object.contentFilters !== undefined && object.contentFilters !== null) {
for (const e of object.contentFilters) {
@ -450,8 +450,8 @@ export const HistoryQuery = {
toJSON(message: HistoryQuery): unknown {
const obj: any = {};
message.pubsubTopic !== undefined &&
(obj.pubsubTopic = message.pubsubTopic);
message.pubSubTopic !== undefined &&
(obj.pubSubTopic = message.pubSubTopic);
if (message.contentFilters) {
obj.contentFilters = message.contentFilters.map((e) =>
e ? ContentFilter.toJSON(e) : undefined
@ -471,10 +471,10 @@ export const HistoryQuery = {
fromPartial(object: DeepPartial<HistoryQuery>): HistoryQuery {
const message = { ...baseHistoryQuery } as HistoryQuery;
message.contentFilters = [];
if (object.pubsubTopic !== undefined && object.pubsubTopic !== null) {
message.pubsubTopic = object.pubsubTopic;
if (object.pubSubTopic !== undefined && object.pubSubTopic !== null) {
message.pubSubTopic = object.pubSubTopic;
} else {
message.pubsubTopic = undefined;
message.pubSubTopic = undefined;
}
if (object.contentFilters !== undefined && object.contentFilters !== null) {
for (const e of object.contentFilters) {

View File

@ -171,7 +171,7 @@ export class NimWaku {
async sendMessage(
message: WakuMessage,
pubsubTopic?: string
pubSubTopic?: string
): Promise<boolean> {
this.checkProcess();
@ -195,7 +195,7 @@ export class NimWaku {
};
return this.rpcCall<boolean>('post_waku_v2_relay_v1_message', [
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
rpcMessage,
]);
}
@ -233,7 +233,7 @@ export class NimWaku {
async postAsymmetricMessage(
message: WakuRelayMessage,
publicKey: Uint8Array,
pubsubTopic?: string
pubSubTopic?: string
): Promise<boolean> {
this.checkProcess();
@ -242,7 +242,7 @@ export class NimWaku {
}
return this.rpcCall<boolean>('post_waku_v2_private_v1_asymmetric_message', [
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
message,
'0x' + bufToHex(publicKey),
]);
@ -250,14 +250,14 @@ export class NimWaku {
async getAsymmetricMessages(
privateKey: Uint8Array,
pubsubTopic?: string
pubSubTopic?: string
): Promise<WakuRelayMessage[]> {
this.checkProcess();
return await this.rpcCall<WakuRelayMessage[]>(
'get_waku_v2_private_v1_asymmetric_messages',
[
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
'0x' + bufToHex(privateKey),
]
);
@ -275,7 +275,7 @@ export class NimWaku {
async postSymmetricMessage(
message: WakuRelayMessage,
symKey: Uint8Array,
pubsubTopic?: string
pubSubTopic?: string
): Promise<boolean> {
this.checkProcess();
@ -284,7 +284,7 @@ export class NimWaku {
}
return this.rpcCall<boolean>('post_waku_v2_private_v1_symmetric_message', [
pubsubTopic ? pubsubTopic : DefaultPubSubTopic,
pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
message,
'0x' + bufToHex(symKey),
]);
@ -292,13 +292,13 @@ export class NimWaku {
async getSymmetricMessages(
symKey: Uint8Array,
pubsubTopic?: string
pubSubTopic?: string
): Promise<WakuRelayMessage[]> {
this.checkProcess();
return await this.rpcCall<WakuRelayMessage[]>(
'get_waku_v2_private_v1_symmetric_messages',
[pubsubTopic ? pubsubTopic : DefaultPubSubTopic, '0x' + bufToHex(symKey)]
[pubSubTopic ? pubSubTopic : DefaultPubSubTopic, '0x' + bufToHex(symKey)]
);
}