mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 13:53:12 +00:00
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;
|
maxMissedMessagesThreshold?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IFilter = IReceiver & IBaseProtocolCore;
|
export interface ISubscription {
|
||||||
|
|
||||||
export interface ISubscriptionSDK {
|
|
||||||
subscribe<T extends IDecodedMessage>(
|
subscribe<T extends IDecodedMessage>(
|
||||||
decoders: IDecoder<T> | IDecoder<T>[],
|
decoders: IDecoder<T> | IDecoder<T>[],
|
||||||
callback: Callback<T>,
|
callback: Callback<T>,
|
||||||
@ -39,7 +37,7 @@ export interface ISubscriptionSDK {
|
|||||||
unsubscribeAll(): Promise<SDKProtocolResult>;
|
unsubscribeAll(): Promise<SDKProtocolResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IFilterSDK = IReceiver &
|
export type IFilter = IReceiver &
|
||||||
IBaseProtocolSDK & { protocol: IBaseProtocolCore } & {
|
IBaseProtocolSDK & { protocol: IBaseProtocolCore } & {
|
||||||
subscribe<T extends IDecodedMessage>(
|
subscribe<T extends IDecodedMessage>(
|
||||||
decoders: IDecoder<T> | IDecoder<T>[],
|
decoders: IDecoder<T> | IDecoder<T>[],
|
||||||
@ -52,7 +50,7 @@ export type IFilterSDK = IReceiver &
|
|||||||
export type SubscribeResult = SubscriptionSuccess | SubscriptionError;
|
export type SubscribeResult = SubscriptionSuccess | SubscriptionError;
|
||||||
|
|
||||||
type SubscriptionSuccess = {
|
type SubscriptionSuccess = {
|
||||||
subscription: ISubscriptionSDK;
|
subscription: ISubscription;
|
||||||
error: null;
|
error: null;
|
||||||
results: SDKProtocolResult;
|
results: SDKProtocolResult;
|
||||||
};
|
};
|
||||||
@ -65,7 +63,7 @@ type SubscriptionError = {
|
|||||||
|
|
||||||
export type CreateSubscriptionResult = ThisOrThat<
|
export type CreateSubscriptionResult = ThisOrThat<
|
||||||
"subscription",
|
"subscription",
|
||||||
ISubscriptionSDK,
|
ISubscription,
|
||||||
"error",
|
"error",
|
||||||
ProtocolError
|
ProtocolError
|
||||||
>;
|
>;
|
||||||
|
|||||||
@ -78,7 +78,7 @@ export type QueryRequestParams = {
|
|||||||
|
|
||||||
export type IStoreCore = IBaseProtocolCore;
|
export type IStoreCore = IBaseProtocolCore;
|
||||||
|
|
||||||
export type IStoreSDK = IBaseProtocolSDK & {
|
export type IStore = IBaseProtocolSDK & {
|
||||||
protocol: IBaseProtocolCore;
|
protocol: IBaseProtocolCore;
|
||||||
createCursor(message: IDecodedMessage): StoreCursor;
|
createCursor(message: IDecodedMessage): StoreCursor;
|
||||||
queryGenerator: <T extends IDecodedMessage>(
|
queryGenerator: <T extends IDecodedMessage>(
|
||||||
|
|||||||
@ -2,19 +2,19 @@ import type { PeerId, Stream } from "@libp2p/interface";
|
|||||||
import type { MultiaddrInput } from "@multiformats/multiaddr";
|
import type { MultiaddrInput } from "@multiformats/multiaddr";
|
||||||
|
|
||||||
import { IConnectionManager } from "./connection_manager.js";
|
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 { IHealthManager } from "./health_manager.js";
|
||||||
import type { Libp2p } from "./libp2p.js";
|
import type { Libp2p } from "./libp2p.js";
|
||||||
import type { ILightPush } from "./light_push.js";
|
import type { ILightPush } from "./light_push.js";
|
||||||
import { Protocols } from "./protocols.js";
|
import { Protocols } from "./protocols.js";
|
||||||
import type { IRelay } from "./relay.js";
|
import type { IRelay } from "./relay.js";
|
||||||
import type { IStoreSDK } from "./store.js";
|
import type { IStore } from "./store.js";
|
||||||
|
|
||||||
export interface Waku {
|
export interface Waku {
|
||||||
libp2p: Libp2p;
|
libp2p: Libp2p;
|
||||||
relay?: IRelay;
|
relay?: IRelay;
|
||||||
store?: IStoreSDK;
|
store?: IStore;
|
||||||
filter?: IFilterSDK;
|
filter?: IFilter;
|
||||||
lightPush?: ILightPush;
|
lightPush?: ILightPush;
|
||||||
|
|
||||||
connectionManager: IConnectionManager;
|
connectionManager: IConnectionManager;
|
||||||
@ -34,8 +34,8 @@ export interface Waku {
|
|||||||
|
|
||||||
export interface LightNode extends Waku {
|
export interface LightNode extends Waku {
|
||||||
relay: undefined;
|
relay: undefined;
|
||||||
store: IStoreSDK;
|
store: IStore;
|
||||||
filter: IFilterSDK;
|
filter: IFilter;
|
||||||
lightPush: ILightPush;
|
lightPush: ILightPush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import {
|
|||||||
type IAsyncIterator,
|
type IAsyncIterator,
|
||||||
type IDecodedMessage,
|
type IDecodedMessage,
|
||||||
type IDecoder,
|
type IDecoder,
|
||||||
type IFilterSDK,
|
type IFilter,
|
||||||
type Libp2p,
|
type Libp2p,
|
||||||
NetworkConfig,
|
NetworkConfig,
|
||||||
type ProtocolCreateOptions,
|
type ProtocolCreateOptions,
|
||||||
@ -31,7 +31,7 @@ import { SubscriptionManager } from "./subscription_manager.js";
|
|||||||
|
|
||||||
const log = new Logger("sdk:filter");
|
const log = new Logger("sdk:filter");
|
||||||
|
|
||||||
class FilterSDK extends BaseProtocolSDK implements IFilterSDK {
|
class Filter extends BaseProtocolSDK implements IFilter {
|
||||||
public readonly protocol: FilterCore;
|
public readonly protocol: FilterCore;
|
||||||
|
|
||||||
private activeSubscriptions = new Map<string, SubscriptionManager>();
|
private activeSubscriptions = new Map<string, SubscriptionManager>();
|
||||||
@ -301,6 +301,6 @@ class FilterSDK extends BaseProtocolSDK implements IFilterSDK {
|
|||||||
export function wakuFilter(
|
export function wakuFilter(
|
||||||
connectionManager: ConnectionManager,
|
connectionManager: ConnectionManager,
|
||||||
init?: ProtocolCreateOptions
|
init?: ProtocolCreateOptions
|
||||||
): (libp2p: Libp2p) => IFilterSDK {
|
): (libp2p: Libp2p) => IFilter {
|
||||||
return (libp2p: Libp2p) => new FilterSDK(connectionManager, libp2p, init);
|
return (libp2p: Libp2p) => new Filter(connectionManager, libp2p, init);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import {
|
|||||||
type IDecodedMessage,
|
type IDecodedMessage,
|
||||||
type IDecoder,
|
type IDecoder,
|
||||||
type IProtoMessage,
|
type IProtoMessage,
|
||||||
type ISubscriptionSDK,
|
type ISubscription,
|
||||||
type PeerIdStr,
|
type PeerIdStr,
|
||||||
ProtocolError,
|
ProtocolError,
|
||||||
type PubsubTopic,
|
type PubsubTopic,
|
||||||
@ -27,7 +27,7 @@ import { DEFAULT_KEEP_ALIVE, DEFAULT_SUBSCRIBE_OPTIONS } from "./constants.js";
|
|||||||
|
|
||||||
const log = new Logger("sdk:filter:subscription_manager");
|
const log = new Logger("sdk:filter:subscription_manager");
|
||||||
|
|
||||||
export class SubscriptionManager implements ISubscriptionSDK {
|
export class SubscriptionManager implements ISubscription {
|
||||||
private reliabilityMonitor: ReceiverReliabilityMonitor;
|
private reliabilityMonitor: ReceiverReliabilityMonitor;
|
||||||
|
|
||||||
private keepAliveTimer: number | null = null;
|
private keepAliveTimer: number | null = null;
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { ConnectionManager, StoreCore } from "@waku/core";
|
|||||||
import {
|
import {
|
||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
IStoreSDK,
|
IStore,
|
||||||
Libp2p,
|
Libp2p,
|
||||||
QueryRequestParams,
|
QueryRequestParams,
|
||||||
StoreCursor
|
StoreCursor
|
||||||
@ -20,7 +20,7 @@ const log = new Logger("waku:store:sdk");
|
|||||||
* StoreSDK is an implementation of the IStoreSDK interface.
|
* StoreSDK is an implementation of the IStoreSDK interface.
|
||||||
* It provides methods to interact with the Waku Store protocol.
|
* 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 readonly protocol: StoreCore;
|
||||||
|
|
||||||
public constructor(connectionManager: ConnectionManager, libp2p: Libp2p) {
|
public constructor(connectionManager: ConnectionManager, libp2p: Libp2p) {
|
||||||
@ -238,8 +238,8 @@ export class StoreSDK extends BaseProtocolSDK implements IStoreSDK {
|
|||||||
*/
|
*/
|
||||||
export function wakuStore(
|
export function wakuStore(
|
||||||
connectionManager: ConnectionManager
|
connectionManager: ConnectionManager
|
||||||
): (libp2p: Libp2p) => IStoreSDK {
|
): (libp2p: Libp2p) => IStore {
|
||||||
return (libp2p: Libp2p) => {
|
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 { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr";
|
||||||
import { ConnectionManager, getHealthManager } from "@waku/core";
|
import { ConnectionManager, getHealthManager } from "@waku/core";
|
||||||
import type {
|
import type {
|
||||||
IFilterSDK,
|
IFilter,
|
||||||
IHealthManager,
|
IHealthManager,
|
||||||
ILightPush,
|
ILightPush,
|
||||||
IRelay,
|
IRelay,
|
||||||
IStoreSDK,
|
IStore,
|
||||||
Libp2p,
|
Libp2p,
|
||||||
ProtocolCreateOptions,
|
ProtocolCreateOptions,
|
||||||
PubsubTopic,
|
PubsubTopic,
|
||||||
@ -62,8 +62,8 @@ type ProtocolsEnabled = {
|
|||||||
export class WakuNode implements Waku {
|
export class WakuNode implements Waku {
|
||||||
public libp2p: Libp2p;
|
public libp2p: Libp2p;
|
||||||
public relay?: IRelay;
|
public relay?: IRelay;
|
||||||
public store?: IStoreSDK;
|
public store?: IStore;
|
||||||
public filter?: IFilterSDK;
|
public filter?: IFilter;
|
||||||
public lightPush?: ILightPush;
|
public lightPush?: ILightPush;
|
||||||
public connectionManager: ConnectionManager;
|
public connectionManager: ConnectionManager;
|
||||||
public readonly health: IHealthManager;
|
public readonly health: IHealthManager;
|
||||||
|
|||||||
@ -1,8 +1,4 @@
|
|||||||
import {
|
import { ISubscription, LightNode, SDKProtocolResult } from "@waku/interfaces";
|
||||||
ISubscriptionSDK,
|
|
||||||
LightNode,
|
|
||||||
SDKProtocolResult
|
|
||||||
} from "@waku/interfaces";
|
|
||||||
import {
|
import {
|
||||||
createDecoder,
|
createDecoder,
|
||||||
createEncoder,
|
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 () {
|
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++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
const { error, subscription: _subscription } =
|
const { error, subscription: _subscription } =
|
||||||
await waku.filter.subscribe([decoder], () => {});
|
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 { utf8ToBytes } from "@waku/sdk";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ const runTests = (strictCheckNodes: boolean): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Reopen subscription with peer with lost subscription", async function () {
|
it("Reopen subscription with peer with lost subscription", async function () {
|
||||||
let subscription: ISubscriptionSDK;
|
let subscription: ISubscription;
|
||||||
const openSubscription = async (): Promise<void> => {
|
const openSubscription = async (): Promise<void> => {
|
||||||
const { error, subscription: _subscription } =
|
const { error, subscription: _subscription } =
|
||||||
await waku.filter.subscribe(
|
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 { utf8ToBytes } from "@waku/sdk";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ describe("Waku Filter V2: Ping", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Reopen subscription with peer with lost subscription", async function () {
|
it("Reopen subscription with peer with lost subscription", async function () {
|
||||||
let subscription: ISubscriptionSDK;
|
let subscription: ISubscription;
|
||||||
const openSubscription = async (): Promise<void> => {
|
const openSubscription = async (): Promise<void> => {
|
||||||
const result = await waku.filter.subscribe(
|
const result = await waku.filter.subscribe(
|
||||||
[TestDecoder],
|
[TestDecoder],
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { createDecoder, createEncoder } from "@waku/core";
|
import { createDecoder, createEncoder } from "@waku/core";
|
||||||
import {
|
import {
|
||||||
DefaultNetworkConfig,
|
DefaultNetworkConfig,
|
||||||
ISubscriptionSDK,
|
ISubscription,
|
||||||
LightNode,
|
LightNode,
|
||||||
NetworkConfig,
|
NetworkConfig,
|
||||||
ProtocolCreateOptions,
|
ProtocolCreateOptions,
|
||||||
@ -46,7 +46,7 @@ export const messagePayload = { payload: utf8ToBytes(messageText) };
|
|||||||
|
|
||||||
// Utility to validate errors related to pings in the subscription.
|
// Utility to validate errors related to pings in the subscription.
|
||||||
export async function validatePingError(
|
export async function validatePingError(
|
||||||
subscription: ISubscriptionSDK
|
subscription: ISubscription
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const { failures, successes } = await subscription.ping();
|
const { failures, successes } = await subscription.ping();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user