From aa5573482bbc58888f08a9b59574e5b9b405a49f Mon Sep 17 00:00:00 2001 From: Sasha Date: Fri, 4 Oct 2024 00:21:36 +0200 Subject: [PATCH] chore: rename IProtocolSDK interfaces to IProtocol --- packages/interfaces/src/filter.ts | 10 ++++------ packages/interfaces/src/store.ts | 2 +- packages/interfaces/src/waku.ts | 12 ++++++------ packages/sdk/src/protocols/filter/index.ts | 8 ++++---- .../sdk/src/protocols/filter/subscription_manager.ts | 4 ++-- packages/sdk/src/protocols/store/index.ts | 8 ++++---- packages/sdk/src/waku.ts | 8 ++++---- packages/tests/tests/filter/peer_management.spec.ts | 8 ++------ packages/tests/tests/filter/ping.node.spec.ts | 4 ++-- .../tests/tests/filter/single_node/ping.node.spec.ts | 4 ++-- packages/tests/tests/filter/utils.ts | 4 ++-- 11 files changed, 33 insertions(+), 39 deletions(-) diff --git a/packages/interfaces/src/filter.ts b/packages/interfaces/src/filter.ts index 5b7a62f71e..145f208fe8 100644 --- a/packages/interfaces/src/filter.ts +++ b/packages/interfaces/src/filter.ts @@ -23,9 +23,7 @@ export type SubscribeOptions = { maxMissedMessagesThreshold?: number; }; -export type IFilter = IReceiver & IBaseProtocolCore; - -export interface ISubscriptionSDK { +export interface ISubscription { subscribe( decoders: IDecoder | IDecoder[], callback: Callback, @@ -39,7 +37,7 @@ export interface ISubscriptionSDK { unsubscribeAll(): Promise; } -export type IFilterSDK = IReceiver & +export type IFilter = IReceiver & IBaseProtocolSDK & { protocol: IBaseProtocolCore } & { subscribe( decoders: IDecoder | IDecoder[], @@ -52,7 +50,7 @@ export type IFilterSDK = IReceiver & export type SubscribeResult = SubscriptionSuccess | SubscriptionError; type SubscriptionSuccess = { - subscription: ISubscriptionSDK; + subscription: ISubscription; error: null; results: SDKProtocolResult; }; @@ -65,7 +63,7 @@ type SubscriptionError = { export type CreateSubscriptionResult = ThisOrThat< "subscription", - ISubscriptionSDK, + ISubscription, "error", ProtocolError >; diff --git a/packages/interfaces/src/store.ts b/packages/interfaces/src/store.ts index 737a6267f7..44560db62f 100644 --- a/packages/interfaces/src/store.ts +++ b/packages/interfaces/src/store.ts @@ -78,7 +78,7 @@ export type QueryRequestParams = { export type IStoreCore = IBaseProtocolCore; -export type IStoreSDK = IBaseProtocolSDK & { +export type IStore = IBaseProtocolSDK & { protocol: IBaseProtocolCore; createCursor(message: IDecodedMessage): StoreCursor; queryGenerator: ( diff --git a/packages/interfaces/src/waku.ts b/packages/interfaces/src/waku.ts index 482c2cb19f..c22258e0f5 100644 --- a/packages/interfaces/src/waku.ts +++ b/packages/interfaces/src/waku.ts @@ -2,19 +2,19 @@ import type { PeerId, Stream } from "@libp2p/interface"; import type { MultiaddrInput } from "@multiformats/multiaddr"; import { IConnectionManager } from "./connection_manager.js"; -import type { IFilterSDK } from "./filter.js"; +import type { IFilter } from "./filter.js"; import { IHealthManager } from "./health_manager.js"; import type { Libp2p } from "./libp2p.js"; import type { ILightPush } from "./light_push.js"; import { Protocols } from "./protocols.js"; import type { IRelay } from "./relay.js"; -import type { IStoreSDK } from "./store.js"; +import type { IStore } from "./store.js"; export interface Waku { libp2p: Libp2p; relay?: IRelay; - store?: IStoreSDK; - filter?: IFilterSDK; + store?: IStore; + filter?: IFilter; lightPush?: ILightPush; connectionManager: IConnectionManager; @@ -34,8 +34,8 @@ export interface Waku { export interface LightNode extends Waku { relay: undefined; - store: IStoreSDK; - filter: IFilterSDK; + store: IStore; + filter: IFilter; lightPush: ILightPush; } diff --git a/packages/sdk/src/protocols/filter/index.ts b/packages/sdk/src/protocols/filter/index.ts index c8840ea0e4..ad48298bbd 100644 --- a/packages/sdk/src/protocols/filter/index.ts +++ b/packages/sdk/src/protocols/filter/index.ts @@ -5,7 +5,7 @@ import { type IAsyncIterator, type IDecodedMessage, type IDecoder, - type IFilterSDK, + type IFilter, type Libp2p, NetworkConfig, type ProtocolCreateOptions, @@ -31,7 +31,7 @@ import { SubscriptionManager } from "./subscription_manager.js"; const log = new Logger("sdk:filter"); -class FilterSDK extends BaseProtocolSDK implements IFilterSDK { +class Filter extends BaseProtocolSDK implements IFilter { public readonly protocol: FilterCore; private activeSubscriptions = new Map(); @@ -301,6 +301,6 @@ class FilterSDK extends BaseProtocolSDK implements IFilterSDK { export function wakuFilter( connectionManager: ConnectionManager, init?: ProtocolCreateOptions -): (libp2p: Libp2p) => IFilterSDK { - return (libp2p: Libp2p) => new FilterSDK(connectionManager, libp2p, init); +): (libp2p: Libp2p) => IFilter { + return (libp2p: Libp2p) => new Filter(connectionManager, libp2p, init); } diff --git a/packages/sdk/src/protocols/filter/subscription_manager.ts b/packages/sdk/src/protocols/filter/subscription_manager.ts index 51a9e16e8d..f14efe15c7 100644 --- a/packages/sdk/src/protocols/filter/subscription_manager.ts +++ b/packages/sdk/src/protocols/filter/subscription_manager.ts @@ -9,7 +9,7 @@ import { type IDecodedMessage, type IDecoder, type IProtoMessage, - type ISubscriptionSDK, + type ISubscription, type PeerIdStr, ProtocolError, type PubsubTopic, @@ -27,7 +27,7 @@ import { DEFAULT_KEEP_ALIVE, DEFAULT_SUBSCRIBE_OPTIONS } from "./constants.js"; const log = new Logger("sdk:filter:subscription_manager"); -export class SubscriptionManager implements ISubscriptionSDK { +export class SubscriptionManager implements ISubscription { private reliabilityMonitor: ReceiverReliabilityMonitor; private keepAliveTimer: number | null = null; diff --git a/packages/sdk/src/protocols/store/index.ts b/packages/sdk/src/protocols/store/index.ts index 3aba99b87c..01ef45d58c 100644 --- a/packages/sdk/src/protocols/store/index.ts +++ b/packages/sdk/src/protocols/store/index.ts @@ -2,7 +2,7 @@ import { ConnectionManager, StoreCore } from "@waku/core"; import { IDecodedMessage, IDecoder, - IStoreSDK, + IStore, Libp2p, QueryRequestParams, StoreCursor @@ -20,7 +20,7 @@ const log = new Logger("waku:store:sdk"); * StoreSDK is an implementation of the IStoreSDK interface. * It provides methods to interact with the Waku Store protocol. */ -export class StoreSDK extends BaseProtocolSDK implements IStoreSDK { +export class Store extends BaseProtocolSDK implements IStore { public readonly protocol: StoreCore; public constructor(connectionManager: ConnectionManager, libp2p: Libp2p) { @@ -238,8 +238,8 @@ export class StoreSDK extends BaseProtocolSDK implements IStoreSDK { */ export function wakuStore( connectionManager: ConnectionManager -): (libp2p: Libp2p) => IStoreSDK { +): (libp2p: Libp2p) => IStore { return (libp2p: Libp2p) => { - return new StoreSDK(connectionManager, libp2p); + return new Store(connectionManager, libp2p); }; } diff --git a/packages/sdk/src/waku.ts b/packages/sdk/src/waku.ts index be656ad796..88dddea5df 100644 --- a/packages/sdk/src/waku.ts +++ b/packages/sdk/src/waku.ts @@ -3,11 +3,11 @@ import { isPeerId, PeerId } from "@libp2p/interface"; import { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; import { ConnectionManager, getHealthManager } from "@waku/core"; import type { - IFilterSDK, + IFilter, IHealthManager, ILightPush, IRelay, - IStoreSDK, + IStore, Libp2p, ProtocolCreateOptions, PubsubTopic, @@ -62,8 +62,8 @@ type ProtocolsEnabled = { export class WakuNode implements Waku { public libp2p: Libp2p; public relay?: IRelay; - public store?: IStoreSDK; - public filter?: IFilterSDK; + public store?: IStore; + public filter?: IFilter; public lightPush?: ILightPush; public connectionManager: ConnectionManager; public readonly health: IHealthManager; diff --git a/packages/tests/tests/filter/peer_management.spec.ts b/packages/tests/tests/filter/peer_management.spec.ts index 31a6c07fad..0818e46467 100644 --- a/packages/tests/tests/filter/peer_management.spec.ts +++ b/packages/tests/tests/filter/peer_management.spec.ts @@ -1,8 +1,4 @@ -import { - ISubscriptionSDK, - LightNode, - SDKProtocolResult -} from "@waku/interfaces"; +import { ISubscription, LightNode, SDKProtocolResult } from "@waku/interfaces"; import { createDecoder, createEncoder, @@ -199,7 +195,7 @@ describe("Waku Filter: Peer Management: E2E", function () { }); it("Maintains correct number of peers after multiple subscribe/unsubscribe cycles", async function () { - let subscription: ISubscriptionSDK; + let subscription: ISubscription; for (let i = 0; i < 3; i++) { const { error, subscription: _subscription } = await waku.filter.subscribe([decoder], () => {}); diff --git a/packages/tests/tests/filter/ping.node.spec.ts b/packages/tests/tests/filter/ping.node.spec.ts index f9552f048b..f5ac0200fd 100644 --- a/packages/tests/tests/filter/ping.node.spec.ts +++ b/packages/tests/tests/filter/ping.node.spec.ts @@ -1,4 +1,4 @@ -import { ISubscriptionSDK, LightNode } from "@waku/interfaces"; +import { ISubscription, LightNode } from "@waku/interfaces"; import { utf8ToBytes } from "@waku/sdk"; import { expect } from "chai"; @@ -89,7 +89,7 @@ const runTests = (strictCheckNodes: boolean): void => { }); it("Reopen subscription with peer with lost subscription", async function () { - let subscription: ISubscriptionSDK; + let subscription: ISubscription; const openSubscription = async (): Promise => { const { error, subscription: _subscription } = await waku.filter.subscribe( diff --git a/packages/tests/tests/filter/single_node/ping.node.spec.ts b/packages/tests/tests/filter/single_node/ping.node.spec.ts index f26395c221..ea6fafbc00 100644 --- a/packages/tests/tests/filter/single_node/ping.node.spec.ts +++ b/packages/tests/tests/filter/single_node/ping.node.spec.ts @@ -1,4 +1,4 @@ -import { ISubscriptionSDK, LightNode } from "@waku/interfaces"; +import { ISubscription, LightNode } from "@waku/interfaces"; import { utf8ToBytes } from "@waku/sdk"; import { expect } from "chai"; @@ -84,7 +84,7 @@ describe("Waku Filter V2: Ping", function () { }); it("Reopen subscription with peer with lost subscription", async function () { - let subscription: ISubscriptionSDK; + let subscription: ISubscription; const openSubscription = async (): Promise => { const result = await waku.filter.subscribe( [TestDecoder], diff --git a/packages/tests/tests/filter/utils.ts b/packages/tests/tests/filter/utils.ts index 1e3165af24..e0d02767a0 100644 --- a/packages/tests/tests/filter/utils.ts +++ b/packages/tests/tests/filter/utils.ts @@ -1,7 +1,7 @@ import { createDecoder, createEncoder } from "@waku/core"; import { DefaultNetworkConfig, - ISubscriptionSDK, + ISubscription, LightNode, NetworkConfig, ProtocolCreateOptions, @@ -46,7 +46,7 @@ export const messagePayload = { payload: utf8ToBytes(messageText) }; // Utility to validate errors related to pings in the subscription. export async function validatePingError( - subscription: ISubscriptionSDK + subscription: ISubscription ): Promise { try { const { failures, successes } = await subscription.ping();