feat: added `I` prefix to protocols interfaces

This will enable the remove of `Waku` prefix on all protocol
implementations, which is redundant due to the context.
This commit is contained in:
fryorcraken.eth 2022-12-06 12:36:29 +11:00
parent 84ac89e0e8
commit 53af8994bd
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
14 changed files with 63 additions and 58 deletions

View File

@ -1,5 +1,5 @@
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
import type { PointToPointProtocol, Relay, Waku } from "@waku/interfaces";
import type { IRelay, PointToPointProtocol, Waku } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces";
import { PeerExchangeCodec } from "@waku/peer-exchange";
import debug from "debug";
@ -117,7 +117,7 @@ async function waitForConnectedPeer(
* Wait for a peer with the given protocol to be connected and in the gossipsub
* mesh.
*/
async function waitForGossipSubPeerInMesh(waku: Relay): Promise<void> {
async function waitForGossipSubPeerInMesh(waku: IRelay): Promise<void> {
let peers = waku.getMeshPeers();
while (peers.length == 0) {

View File

@ -3,12 +3,12 @@ import type { PeerId } from "@libp2p/interface-peer-id";
import type { PubSub } from "@libp2p/interface-pubsub";
import type { Multiaddr } from "@multiformats/multiaddr";
import type {
Filter,
LightPush,
PeerExchange,
IFilter,
ILightPush,
IPeerExchange,
IRelay,
IStore,
PeerExchangeComponents,
Relay,
Store,
Waku,
} from "@waku/interfaces";
import { Protocols } from "@waku/interfaces";
@ -56,11 +56,11 @@ export interface WakuOptions {
export class WakuNode implements Waku {
public libp2p: Libp2p;
public relay?: Relay;
public store?: Store;
public filter?: Filter;
public lightPush?: LightPush;
public peerExchange?: PeerExchange;
public relay?: IRelay;
public store?: IStore;
public filter?: IFilter;
public lightPush?: ILightPush;
public peerExchange?: IPeerExchange;
private pingKeepAliveTimers: {
[peer: string]: ReturnType<typeof setInterval>;
@ -72,10 +72,10 @@ export class WakuNode implements Waku {
constructor(
options: WakuOptions,
libp2p: Libp2p,
store?: (components: StoreComponents) => Store,
lightPush?: (components: LightPushComponents) => LightPush,
filter?: (components: FilterComponents) => Filter,
peerExchange?: (components: PeerExchangeComponents) => PeerExchange
store?: (components: StoreComponents) => IStore,
lightPush?: (components: LightPushComponents) => ILightPush,
filter?: (components: FilterComponents) => IFilter,
peerExchange?: (components: PeerExchangeComponents) => IPeerExchange
) {
this.libp2p = libp2p;
@ -274,7 +274,7 @@ export class WakuNode implements Waku {
}
}
function isRelay(pubsub: PubSub): pubsub is Relay {
function isRelay(pubsub: PubSub): pubsub is IRelay {
if (pubsub) {
try {
return pubsub.multicodecs.includes(

View File

@ -7,9 +7,9 @@ import type { IncomingStreamData } from "@libp2p/interface-registrar";
import type { Registrar } from "@libp2p/interface-registrar";
import type {
Callback,
Filter,
IDecodedMessage,
IDecoder,
IFilter,
IMessage,
ProtocolOptions,
} from "@waku/interfaces";
@ -64,7 +64,7 @@ export type UnsubscribeFunction = () => Promise<void>;
* - https://github.com/status-im/go-waku/issues/245
* - https://github.com/status-im/nwaku/issues/948
*/
class WakuFilter implements Filter {
class WakuFilter implements IFilter {
pubSubTopic: string;
private subscriptions: Map<string, Callback<any>>;
private decoders: Map<
@ -308,6 +308,6 @@ class WakuFilter implements Filter {
export function wakuFilter(
init: Partial<CreateOptions> = {}
): (components: FilterComponents) => Filter {
): (components: FilterComponents) => IFilter {
return (components: FilterComponents) => new WakuFilter(components, init);
}

View File

@ -4,8 +4,8 @@ import type { Peer } from "@libp2p/interface-peer-store";
import type { PeerStore } from "@libp2p/interface-peer-store";
import type {
IEncoder,
ILightPush,
IMessage,
LightPush,
ProtocolOptions,
SendResult,
} from "@waku/interfaces";
@ -51,7 +51,7 @@ export interface CreateOptions {
/**
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
*/
class WakuLightPush implements LightPush {
class WakuLightPush implements ILightPush {
pubSubTopic: string;
constructor(public components: LightPushComponents, options?: CreateOptions) {
@ -151,7 +151,7 @@ class WakuLightPush implements LightPush {
export function wakuLightPush(
init: Partial<CreateOptions> = {}
): (components: LightPushComponents) => LightPush {
): (components: LightPushComponents) => ILightPush {
return (components: LightPushComponents) =>
new WakuLightPush(components, init);
}

View File

@ -11,7 +11,7 @@ import type {
IDecoder,
IEncoder,
IMessage,
Relay,
IRelay,
SendResult,
} from "@waku/interfaces";
import { IDecodedMessage } from "@waku/interfaces";
@ -53,7 +53,7 @@ export type CreateOptions = {
*
* @implements {require('libp2p-interfaces/src/pubsub')}
*/
class WakuRelay extends GossipSub implements Relay {
class WakuRelay extends GossipSub implements IRelay {
pubSubTopic: string;
defaultDecoder: IDecoder<IDecodedMessage>;
public static multicodec: string = constants.RelayCodecs[0];
@ -189,6 +189,6 @@ WakuRelay.multicodec = constants.RelayCodecs[constants.RelayCodecs.length - 1];
export function wakuRelay(
init: Partial<CreateOptions> = {}
): (components: GossipSubComponents) => Relay {
): (components: GossipSubComponents) => IRelay {
return (components: GossipSubComponents) => new WakuRelay(components, init);
}

View File

@ -9,7 +9,7 @@ import {
IDecodedMessage,
IDecoder,
Index,
Store,
IStore,
} from "@waku/interfaces";
import {
getPeersForProtocol,
@ -104,7 +104,7 @@ export interface QueryOptions {
*
* The Waku Store protocol can be used to retrieved historical messages.
*/
class WakuStore implements Store {
class WakuStore implements IStore {
pubSubTopic: string;
constructor(public components: StoreComponents, options?: CreateOptions) {
@ -432,6 +432,6 @@ export async function createCursor(
export function wakuStore(
init: Partial<CreateOptions> = {}
): (components: StoreComponents) => Store {
): (components: StoreComponents) => IStore {
return (components: StoreComponents) => new WakuStore(components, init);
}

View File

@ -15,7 +15,12 @@ import {
} from "@waku/core";
import { DefaultUserAgent } from "@waku/core";
import { getPredefinedBootstrapNodes } from "@waku/core/lib/predefined_bootstrap_nodes";
import type { Relay, WakuFull, WakuLight, WakuPrivacy } from "@waku/interfaces";
import type {
IRelay,
WakuFull,
WakuLight,
WakuPrivacy,
} from "@waku/interfaces";
import { wakuPeerExchange } from "@waku/peer-exchange";
import type { Libp2p } from "libp2p";
import { createLibp2p, Libp2pOptions } from "libp2p";
@ -172,7 +177,7 @@ export function defaultPeerDiscovery(): (
}
export async function defaultLibp2p(
wakuRelay?: (components: Libp2pComponents) => Relay,
wakuRelay?: (components: Libp2pComponents) => IRelay,
options?: Partial<Libp2pOptions>,
userAgent?: string
): Promise<Libp2p> {

View File

@ -5,7 +5,7 @@ import type {
ProtocolOptions,
} from "./protocols.js";
export interface Filter extends PointToPointProtocol {
export interface IFilter extends PointToPointProtocol {
subscribe: <T extends IDecodedMessage>(
decoders: IDecoder<T>[],
callback: Callback<T>,

View File

@ -5,7 +5,7 @@ import type {
SendResult,
} from "./protocols.js";
export interface LightPush extends PointToPointProtocol {
export interface ILightPush extends PointToPointProtocol {
push: (
encoder: IEncoder,
message: IMessage,

View File

@ -5,7 +5,7 @@ import { ENR } from "@waku/enr";
import { PointToPointProtocol } from "./protocols.js";
export interface PeerExchange extends PointToPointProtocol {
export interface IPeerExchange extends PointToPointProtocol {
query(
params: PeerExchangeQueryParams,
callback: (response: PeerExchangeResponse) => Promise<void> | void

View File

@ -8,7 +8,7 @@ import type {
} from "./message.js";
import type { Callback, SendResult } from "./protocols.js";
export interface Relay extends GossipSub {
export interface IRelay extends GossipSub {
send: (encoder: IEncoder, message: IMessage) => Promise<SendResult>;
addObserver: <T extends IDecodedMessage>(
decoder: IDecoder<T>,

View File

@ -50,7 +50,7 @@ export type StoreQueryOptions = {
cursor?: Cursor;
} & ProtocolOptions;
export interface Store extends PointToPointProtocol {
export interface IStore extends PointToPointProtocol {
queryOrderedCallback: <T extends IDecodedMessage>(
decoders: IDecoder<T>[],
callback: (message: T) => Promise<void | boolean> | boolean | void,

View File

@ -3,20 +3,20 @@ import type { PeerId } from "@libp2p/interface-peer-id";
import type { Multiaddr } from "@multiformats/multiaddr";
import type { Libp2p } from "libp2p";
import type { Filter } from "./filter.js";
import type { LightPush } from "./light_push.js";
import type { PeerExchange } from "./peer_exchange.js";
import type { IFilter } from "./filter.js";
import type { ILightPush } from "./light_push.js";
import type { IPeerExchange } from "./peer_exchange.js";
import { Protocols } from "./protocols.js";
import type { Relay } from "./relay.js";
import type { Store } from "./store.js";
import type { IRelay } from "./relay.js";
import type { IStore } from "./store.js";
export interface Waku {
libp2p: Libp2p;
relay?: Relay;
store?: Store;
filter?: Filter;
lightPush?: LightPush;
peerExchange?: PeerExchange;
relay?: IRelay;
store?: IStore;
filter?: IFilter;
lightPush?: ILightPush;
peerExchange?: IPeerExchange;
dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
@ -29,14 +29,14 @@ export interface Waku {
export interface WakuLight extends Waku {
relay: undefined;
store: Store;
filter: Filter;
lightPush: LightPush;
peerExchange: PeerExchange;
store: IStore;
filter: IFilter;
lightPush: ILightPush;
peerExchange: IPeerExchange;
}
export interface WakuPrivacy extends Waku {
relay: Relay;
relay: IRelay;
store: undefined;
filter: undefined;
lightPush: undefined;
@ -44,9 +44,9 @@ export interface WakuPrivacy extends Waku {
}
export interface WakuFull extends Waku {
relay: Relay;
store: Store;
filter: Filter;
lightPush: LightPush;
peerExchange: PeerExchange;
relay: IRelay;
store: IStore;
filter: IFilter;
lightPush: ILightPush;
peerExchange: IPeerExchange;
}

View File

@ -4,7 +4,7 @@ import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
import type { IncomingStreamData } from "@libp2p/interface-registrar";
import { ENR } from "@waku/enr";
import type {
PeerExchange,
IPeerExchange,
PeerExchangeComponents,
PeerExchangeQueryParams,
PeerExchangeResponse,
@ -26,7 +26,7 @@ export const PeerExchangeCodec = "/vac/waku/peer-exchange/2.0.0-alpha1";
const log = debug("waku:peer-exchange");
export class WakuPeerExchange implements PeerExchange {
export class WakuPeerExchange implements IPeerExchange {
private callback:
| ((response: PeerExchangeResponse) => Promise<void>)
| undefined;