Skip to content

Commit

Permalink
chore: rename IProtocolSDK interfaces to IProtocol naming convention (#…
Browse files Browse the repository at this point in the history
…2159)

* chore: rename IProtocolSDK interfaces to IProtocol
  • Loading branch information
weboko authored Oct 4, 2024
1 parent 1d68526 commit 2be0e81
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 39 deletions.
10 changes: 4 additions & 6 deletions packages/interfaces/src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export type SubscribeOptions = {
maxMissedMessagesThreshold?: number;
};

export type IFilter = IReceiver & IBaseProtocolCore;

export interface ISubscriptionSDK {
export interface ISubscription {
subscribe<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T>,
Expand All @@ -39,7 +37,7 @@ export interface ISubscriptionSDK {
unsubscribeAll(): Promise<SDKProtocolResult>;
}

export type IFilterSDK = IReceiver &
export type IFilter = IReceiver &
IBaseProtocolSDK & { protocol: IBaseProtocolCore } & {
subscribe<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[],
Expand All @@ -52,7 +50,7 @@ export type IFilterSDK = IReceiver &
export type SubscribeResult = SubscriptionSuccess | SubscriptionError;

type SubscriptionSuccess = {
subscription: ISubscriptionSDK;
subscription: ISubscription;
error: null;
results: SDKProtocolResult;
};
Expand All @@ -65,7 +63,7 @@ type SubscriptionError = {

export type CreateSubscriptionResult = ThisOrThat<
"subscription",
ISubscriptionSDK,
ISubscription,
"error",
ProtocolError
>;
2 changes: 1 addition & 1 deletion packages/interfaces/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <T extends IDecodedMessage>(
Expand Down
12 changes: 6 additions & 6 deletions packages/interfaces/src/waku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,8 +34,8 @@ export interface Waku {

export interface LightNode extends Waku {
relay: undefined;
store: IStoreSDK;
filter: IFilterSDK;
store: IStore;
filter: IFilter;
lightPush: ILightPush;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/protocols/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type IAsyncIterator,
type IDecodedMessage,
type IDecoder,
type IFilterSDK,
type IFilter,
type Libp2p,
NetworkConfig,
type ProtocolCreateOptions,
Expand All @@ -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<string, SubscriptionManager>();
Expand Down Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions packages/sdk/src/protocols/filter/subscription_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type IDecodedMessage,
type IDecoder,
type IProtoMessage,
type ISubscriptionSDK,
type ISubscription,
type PeerIdStr,
ProtocolError,
type PubsubTopic,
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/protocols/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ConnectionManager, StoreCore } from "@waku/core";
import {
IDecodedMessage,
IDecoder,
IStoreSDK,
IStore,
Libp2p,
QueryRequestParams,
StoreCursor
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
};
}
8 changes: 4 additions & 4 deletions packages/sdk/src/waku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions packages/tests/tests/filter/peer_management.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ISubscriptionSDK,
LightNode,
SDKProtocolResult
} from "@waku/interfaces";
import { ISubscription, LightNode, SDKProtocolResult } from "@waku/interfaces";
import {
createDecoder,
createEncoder,
Expand Down Expand Up @@ -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], () => {});
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/tests/filter/ping.node.spec.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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<void> => {
const { error, subscription: _subscription } =
await waku.filter.subscribe(
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/tests/filter/single_node/ping.node.spec.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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<void> => {
const result = await waku.filter.subscribe(
[TestDecoder],
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/tests/filter/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createDecoder, createEncoder } from "@waku/core";
import {
DefaultNetworkConfig,
ISubscriptionSDK,
ISubscription,
LightNode,
NetworkConfig,
ProtocolCreateOptions,
Expand Down Expand Up @@ -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<void> {
try {
const { failures, successes } = await subscription.ping();
Expand Down

0 comments on commit 2be0e81

Please sign in to comment.