mirror of https://github.com/waku-org/js-waku.git
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:
parent
84ac89e0e8
commit
53af8994bd
|
@ -1,5 +1,5 @@
|
||||||
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
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 { Protocols } from "@waku/interfaces";
|
||||||
import { PeerExchangeCodec } from "@waku/peer-exchange";
|
import { PeerExchangeCodec } from "@waku/peer-exchange";
|
||||||
import debug from "debug";
|
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
|
* Wait for a peer with the given protocol to be connected and in the gossipsub
|
||||||
* mesh.
|
* mesh.
|
||||||
*/
|
*/
|
||||||
async function waitForGossipSubPeerInMesh(waku: Relay): Promise<void> {
|
async function waitForGossipSubPeerInMesh(waku: IRelay): Promise<void> {
|
||||||
let peers = waku.getMeshPeers();
|
let peers = waku.getMeshPeers();
|
||||||
|
|
||||||
while (peers.length == 0) {
|
while (peers.length == 0) {
|
||||||
|
|
|
@ -3,12 +3,12 @@ import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import type { PubSub } from "@libp2p/interface-pubsub";
|
import type { PubSub } from "@libp2p/interface-pubsub";
|
||||||
import type { Multiaddr } from "@multiformats/multiaddr";
|
import type { Multiaddr } from "@multiformats/multiaddr";
|
||||||
import type {
|
import type {
|
||||||
Filter,
|
IFilter,
|
||||||
LightPush,
|
ILightPush,
|
||||||
PeerExchange,
|
IPeerExchange,
|
||||||
|
IRelay,
|
||||||
|
IStore,
|
||||||
PeerExchangeComponents,
|
PeerExchangeComponents,
|
||||||
Relay,
|
|
||||||
Store,
|
|
||||||
Waku,
|
Waku,
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { Protocols } from "@waku/interfaces";
|
import { Protocols } from "@waku/interfaces";
|
||||||
|
@ -56,11 +56,11 @@ export interface WakuOptions {
|
||||||
|
|
||||||
export class WakuNode implements Waku {
|
export class WakuNode implements Waku {
|
||||||
public libp2p: Libp2p;
|
public libp2p: Libp2p;
|
||||||
public relay?: Relay;
|
public relay?: IRelay;
|
||||||
public store?: Store;
|
public store?: IStore;
|
||||||
public filter?: Filter;
|
public filter?: IFilter;
|
||||||
public lightPush?: LightPush;
|
public lightPush?: ILightPush;
|
||||||
public peerExchange?: PeerExchange;
|
public peerExchange?: IPeerExchange;
|
||||||
|
|
||||||
private pingKeepAliveTimers: {
|
private pingKeepAliveTimers: {
|
||||||
[peer: string]: ReturnType<typeof setInterval>;
|
[peer: string]: ReturnType<typeof setInterval>;
|
||||||
|
@ -72,10 +72,10 @@ export class WakuNode implements Waku {
|
||||||
constructor(
|
constructor(
|
||||||
options: WakuOptions,
|
options: WakuOptions,
|
||||||
libp2p: Libp2p,
|
libp2p: Libp2p,
|
||||||
store?: (components: StoreComponents) => Store,
|
store?: (components: StoreComponents) => IStore,
|
||||||
lightPush?: (components: LightPushComponents) => LightPush,
|
lightPush?: (components: LightPushComponents) => ILightPush,
|
||||||
filter?: (components: FilterComponents) => Filter,
|
filter?: (components: FilterComponents) => IFilter,
|
||||||
peerExchange?: (components: PeerExchangeComponents) => PeerExchange
|
peerExchange?: (components: PeerExchangeComponents) => IPeerExchange
|
||||||
) {
|
) {
|
||||||
this.libp2p = libp2p;
|
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) {
|
if (pubsub) {
|
||||||
try {
|
try {
|
||||||
return pubsub.multicodecs.includes(
|
return pubsub.multicodecs.includes(
|
||||||
|
|
|
@ -7,9 +7,9 @@ import type { IncomingStreamData } from "@libp2p/interface-registrar";
|
||||||
import type { Registrar } from "@libp2p/interface-registrar";
|
import type { Registrar } from "@libp2p/interface-registrar";
|
||||||
import type {
|
import type {
|
||||||
Callback,
|
Callback,
|
||||||
Filter,
|
|
||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
|
IFilter,
|
||||||
IMessage,
|
IMessage,
|
||||||
ProtocolOptions,
|
ProtocolOptions,
|
||||||
} from "@waku/interfaces";
|
} 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/go-waku/issues/245
|
||||||
* - https://github.com/status-im/nwaku/issues/948
|
* - https://github.com/status-im/nwaku/issues/948
|
||||||
*/
|
*/
|
||||||
class WakuFilter implements Filter {
|
class WakuFilter implements IFilter {
|
||||||
pubSubTopic: string;
|
pubSubTopic: string;
|
||||||
private subscriptions: Map<string, Callback<any>>;
|
private subscriptions: Map<string, Callback<any>>;
|
||||||
private decoders: Map<
|
private decoders: Map<
|
||||||
|
@ -308,6 +308,6 @@ class WakuFilter implements Filter {
|
||||||
|
|
||||||
export function wakuFilter(
|
export function wakuFilter(
|
||||||
init: Partial<CreateOptions> = {}
|
init: Partial<CreateOptions> = {}
|
||||||
): (components: FilterComponents) => Filter {
|
): (components: FilterComponents) => IFilter {
|
||||||
return (components: FilterComponents) => new WakuFilter(components, init);
|
return (components: FilterComponents) => new WakuFilter(components, init);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import type { Peer } from "@libp2p/interface-peer-store";
|
||||||
import type { PeerStore } from "@libp2p/interface-peer-store";
|
import type { PeerStore } from "@libp2p/interface-peer-store";
|
||||||
import type {
|
import type {
|
||||||
IEncoder,
|
IEncoder,
|
||||||
|
ILightPush,
|
||||||
IMessage,
|
IMessage,
|
||||||
LightPush,
|
|
||||||
ProtocolOptions,
|
ProtocolOptions,
|
||||||
SendResult,
|
SendResult,
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
|
@ -51,7 +51,7 @@ export interface CreateOptions {
|
||||||
/**
|
/**
|
||||||
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
||||||
*/
|
*/
|
||||||
class WakuLightPush implements LightPush {
|
class WakuLightPush implements ILightPush {
|
||||||
pubSubTopic: string;
|
pubSubTopic: string;
|
||||||
|
|
||||||
constructor(public components: LightPushComponents, options?: CreateOptions) {
|
constructor(public components: LightPushComponents, options?: CreateOptions) {
|
||||||
|
@ -151,7 +151,7 @@ class WakuLightPush implements LightPush {
|
||||||
|
|
||||||
export function wakuLightPush(
|
export function wakuLightPush(
|
||||||
init: Partial<CreateOptions> = {}
|
init: Partial<CreateOptions> = {}
|
||||||
): (components: LightPushComponents) => LightPush {
|
): (components: LightPushComponents) => ILightPush {
|
||||||
return (components: LightPushComponents) =>
|
return (components: LightPushComponents) =>
|
||||||
new WakuLightPush(components, init);
|
new WakuLightPush(components, init);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import type {
|
||||||
IDecoder,
|
IDecoder,
|
||||||
IEncoder,
|
IEncoder,
|
||||||
IMessage,
|
IMessage,
|
||||||
Relay,
|
IRelay,
|
||||||
SendResult,
|
SendResult,
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { IDecodedMessage } from "@waku/interfaces";
|
import { IDecodedMessage } from "@waku/interfaces";
|
||||||
|
@ -53,7 +53,7 @@ export type CreateOptions = {
|
||||||
*
|
*
|
||||||
* @implements {require('libp2p-interfaces/src/pubsub')}
|
* @implements {require('libp2p-interfaces/src/pubsub')}
|
||||||
*/
|
*/
|
||||||
class WakuRelay extends GossipSub implements Relay {
|
class WakuRelay extends GossipSub implements IRelay {
|
||||||
pubSubTopic: string;
|
pubSubTopic: string;
|
||||||
defaultDecoder: IDecoder<IDecodedMessage>;
|
defaultDecoder: IDecoder<IDecodedMessage>;
|
||||||
public static multicodec: string = constants.RelayCodecs[0];
|
public static multicodec: string = constants.RelayCodecs[0];
|
||||||
|
@ -189,6 +189,6 @@ WakuRelay.multicodec = constants.RelayCodecs[constants.RelayCodecs.length - 1];
|
||||||
|
|
||||||
export function wakuRelay(
|
export function wakuRelay(
|
||||||
init: Partial<CreateOptions> = {}
|
init: Partial<CreateOptions> = {}
|
||||||
): (components: GossipSubComponents) => Relay {
|
): (components: GossipSubComponents) => IRelay {
|
||||||
return (components: GossipSubComponents) => new WakuRelay(components, init);
|
return (components: GossipSubComponents) => new WakuRelay(components, init);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
Index,
|
Index,
|
||||||
Store,
|
IStore,
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import {
|
import {
|
||||||
getPeersForProtocol,
|
getPeersForProtocol,
|
||||||
|
@ -104,7 +104,7 @@ export interface QueryOptions {
|
||||||
*
|
*
|
||||||
* The Waku Store protocol can be used to retrieved historical messages.
|
* The Waku Store protocol can be used to retrieved historical messages.
|
||||||
*/
|
*/
|
||||||
class WakuStore implements Store {
|
class WakuStore implements IStore {
|
||||||
pubSubTopic: string;
|
pubSubTopic: string;
|
||||||
|
|
||||||
constructor(public components: StoreComponents, options?: CreateOptions) {
|
constructor(public components: StoreComponents, options?: CreateOptions) {
|
||||||
|
@ -432,6 +432,6 @@ export async function createCursor(
|
||||||
|
|
||||||
export function wakuStore(
|
export function wakuStore(
|
||||||
init: Partial<CreateOptions> = {}
|
init: Partial<CreateOptions> = {}
|
||||||
): (components: StoreComponents) => Store {
|
): (components: StoreComponents) => IStore {
|
||||||
return (components: StoreComponents) => new WakuStore(components, init);
|
return (components: StoreComponents) => new WakuStore(components, init);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,12 @@ import {
|
||||||
} from "@waku/core";
|
} from "@waku/core";
|
||||||
import { DefaultUserAgent } from "@waku/core";
|
import { DefaultUserAgent } from "@waku/core";
|
||||||
import { getPredefinedBootstrapNodes } from "@waku/core/lib/predefined_bootstrap_nodes";
|
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 { wakuPeerExchange } from "@waku/peer-exchange";
|
||||||
import type { Libp2p } from "libp2p";
|
import type { Libp2p } from "libp2p";
|
||||||
import { createLibp2p, Libp2pOptions } from "libp2p";
|
import { createLibp2p, Libp2pOptions } from "libp2p";
|
||||||
|
@ -172,7 +177,7 @@ export function defaultPeerDiscovery(): (
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function defaultLibp2p(
|
export async function defaultLibp2p(
|
||||||
wakuRelay?: (components: Libp2pComponents) => Relay,
|
wakuRelay?: (components: Libp2pComponents) => IRelay,
|
||||||
options?: Partial<Libp2pOptions>,
|
options?: Partial<Libp2pOptions>,
|
||||||
userAgent?: string
|
userAgent?: string
|
||||||
): Promise<Libp2p> {
|
): Promise<Libp2p> {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import type {
|
||||||
ProtocolOptions,
|
ProtocolOptions,
|
||||||
} from "./protocols.js";
|
} from "./protocols.js";
|
||||||
|
|
||||||
export interface Filter extends PointToPointProtocol {
|
export interface IFilter extends PointToPointProtocol {
|
||||||
subscribe: <T extends IDecodedMessage>(
|
subscribe: <T extends IDecodedMessage>(
|
||||||
decoders: IDecoder<T>[],
|
decoders: IDecoder<T>[],
|
||||||
callback: Callback<T>,
|
callback: Callback<T>,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import type {
|
||||||
SendResult,
|
SendResult,
|
||||||
} from "./protocols.js";
|
} from "./protocols.js";
|
||||||
|
|
||||||
export interface LightPush extends PointToPointProtocol {
|
export interface ILightPush extends PointToPointProtocol {
|
||||||
push: (
|
push: (
|
||||||
encoder: IEncoder,
|
encoder: IEncoder,
|
||||||
message: IMessage,
|
message: IMessage,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { ENR } from "@waku/enr";
|
||||||
|
|
||||||
import { PointToPointProtocol } from "./protocols.js";
|
import { PointToPointProtocol } from "./protocols.js";
|
||||||
|
|
||||||
export interface PeerExchange extends PointToPointProtocol {
|
export interface IPeerExchange extends PointToPointProtocol {
|
||||||
query(
|
query(
|
||||||
params: PeerExchangeQueryParams,
|
params: PeerExchangeQueryParams,
|
||||||
callback: (response: PeerExchangeResponse) => Promise<void> | void
|
callback: (response: PeerExchangeResponse) => Promise<void> | void
|
||||||
|
|
|
@ -8,7 +8,7 @@ import type {
|
||||||
} from "./message.js";
|
} from "./message.js";
|
||||||
import type { Callback, SendResult } from "./protocols.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>;
|
send: (encoder: IEncoder, message: IMessage) => Promise<SendResult>;
|
||||||
addObserver: <T extends IDecodedMessage>(
|
addObserver: <T extends IDecodedMessage>(
|
||||||
decoder: IDecoder<T>,
|
decoder: IDecoder<T>,
|
||||||
|
|
|
@ -50,7 +50,7 @@ export type StoreQueryOptions = {
|
||||||
cursor?: Cursor;
|
cursor?: Cursor;
|
||||||
} & ProtocolOptions;
|
} & ProtocolOptions;
|
||||||
|
|
||||||
export interface Store extends PointToPointProtocol {
|
export interface IStore extends PointToPointProtocol {
|
||||||
queryOrderedCallback: <T extends IDecodedMessage>(
|
queryOrderedCallback: <T extends IDecodedMessage>(
|
||||||
decoders: IDecoder<T>[],
|
decoders: IDecoder<T>[],
|
||||||
callback: (message: T) => Promise<void | boolean> | boolean | void,
|
callback: (message: T) => Promise<void | boolean> | boolean | void,
|
||||||
|
|
|
@ -3,20 +3,20 @@ import type { PeerId } from "@libp2p/interface-peer-id";
|
||||||
import type { Multiaddr } from "@multiformats/multiaddr";
|
import type { Multiaddr } from "@multiformats/multiaddr";
|
||||||
import type { Libp2p } from "libp2p";
|
import type { Libp2p } from "libp2p";
|
||||||
|
|
||||||
import type { Filter } from "./filter.js";
|
import type { IFilter } from "./filter.js";
|
||||||
import type { LightPush } from "./light_push.js";
|
import type { ILightPush } from "./light_push.js";
|
||||||
import type { PeerExchange } from "./peer_exchange.js";
|
import type { IPeerExchange } from "./peer_exchange.js";
|
||||||
import { Protocols } from "./protocols.js";
|
import { Protocols } from "./protocols.js";
|
||||||
import type { Relay } from "./relay.js";
|
import type { IRelay } from "./relay.js";
|
||||||
import type { Store } from "./store.js";
|
import type { IStore } from "./store.js";
|
||||||
|
|
||||||
export interface Waku {
|
export interface Waku {
|
||||||
libp2p: Libp2p;
|
libp2p: Libp2p;
|
||||||
relay?: Relay;
|
relay?: IRelay;
|
||||||
store?: Store;
|
store?: IStore;
|
||||||
filter?: Filter;
|
filter?: IFilter;
|
||||||
lightPush?: LightPush;
|
lightPush?: ILightPush;
|
||||||
peerExchange?: PeerExchange;
|
peerExchange?: IPeerExchange;
|
||||||
|
|
||||||
dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
|
dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
|
||||||
|
|
||||||
|
@ -29,14 +29,14 @@ export interface Waku {
|
||||||
|
|
||||||
export interface WakuLight extends Waku {
|
export interface WakuLight extends Waku {
|
||||||
relay: undefined;
|
relay: undefined;
|
||||||
store: Store;
|
store: IStore;
|
||||||
filter: Filter;
|
filter: IFilter;
|
||||||
lightPush: LightPush;
|
lightPush: ILightPush;
|
||||||
peerExchange: PeerExchange;
|
peerExchange: IPeerExchange;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WakuPrivacy extends Waku {
|
export interface WakuPrivacy extends Waku {
|
||||||
relay: Relay;
|
relay: IRelay;
|
||||||
store: undefined;
|
store: undefined;
|
||||||
filter: undefined;
|
filter: undefined;
|
||||||
lightPush: undefined;
|
lightPush: undefined;
|
||||||
|
@ -44,9 +44,9 @@ export interface WakuPrivacy extends Waku {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WakuFull extends Waku {
|
export interface WakuFull extends Waku {
|
||||||
relay: Relay;
|
relay: IRelay;
|
||||||
store: Store;
|
store: IStore;
|
||||||
filter: Filter;
|
filter: IFilter;
|
||||||
lightPush: LightPush;
|
lightPush: ILightPush;
|
||||||
peerExchange: PeerExchange;
|
peerExchange: IPeerExchange;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
||||||
import type { IncomingStreamData } from "@libp2p/interface-registrar";
|
import type { IncomingStreamData } from "@libp2p/interface-registrar";
|
||||||
import { ENR } from "@waku/enr";
|
import { ENR } from "@waku/enr";
|
||||||
import type {
|
import type {
|
||||||
PeerExchange,
|
IPeerExchange,
|
||||||
PeerExchangeComponents,
|
PeerExchangeComponents,
|
||||||
PeerExchangeQueryParams,
|
PeerExchangeQueryParams,
|
||||||
PeerExchangeResponse,
|
PeerExchangeResponse,
|
||||||
|
@ -26,7 +26,7 @@ export const PeerExchangeCodec = "/vac/waku/peer-exchange/2.0.0-alpha1";
|
||||||
|
|
||||||
const log = debug("waku:peer-exchange");
|
const log = debug("waku:peer-exchange");
|
||||||
|
|
||||||
export class WakuPeerExchange implements PeerExchange {
|
export class WakuPeerExchange implements IPeerExchange {
|
||||||
private callback:
|
private callback:
|
||||||
| ((response: PeerExchangeResponse) => Promise<void>)
|
| ((response: PeerExchangeResponse) => Promise<void>)
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
Loading…
Reference in New Issue