mirror of https://github.com/waku-org/js-waku.git
chore: rename IProtocolSDK interfaces to IProtocol naming convention (#2159)
* chore: rename IProtocolSDK interfaces to IProtocol
This commit is contained in:
parent
1d68526e72
commit
2be0e81a0a
|
@ -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>,
|
||||
|
@ -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>[],
|
||||
|
@ -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
|
||||
>;
|
||||
|
|
|
@ -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>(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<string, SubscriptionManager>();
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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], () => {});
|
||||
|
|
|
@ -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<void> => {
|
||||
const { error, subscription: _subscription } =
|
||||
await waku.filter.subscribe(
|
||||
|
|
|
@ -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<void> => {
|
||||
const result = await waku.filter.subscribe(
|
||||
[TestDecoder],
|
||||
|
|
|
@ -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<void> {
|
||||
try {
|
||||
const { failures, successes } = await subscription.ping();
|
||||
|
|
Loading…
Reference in New Issue