@waku/interfaces 0.0.26-1887f4f.0 → 0.0.26-77b2cdd.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB;AAgID,MAAM,CAAN,IAAY,aA6DX;AA7DD,WAAY,aAAa;IACvB,4FAA4F;IAC5F,+CAA8B,CAAA;IAC9B;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,iDAAgC,CAAA;IAChC;;;OAGG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,kEAAiD,CAAA;IACjD;;;;;OAKG;IACH,wDAAuC,CAAA;IACvC;;;OAGG;IACH,4DAA2C,CAAA;IAC3C;;;OAGG;IACH,wDAAuC,CAAA;IACvC;;;;OAIG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,oDAAmC,CAAA;AACrC,CAAC,EA7DW,aAAa,KAAb,aAAa,QA6DxB"}
1
+ {"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,oCAAuB,CAAA;IACvB,8BAAiB,CAAA;AACnB,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB;AAiHD,MAAM,CAAN,IAAY,aAkEX;AAlED,WAAY,aAAa;IACvB,4FAA4F;IAC5F,+CAA8B,CAAA;IAC9B;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,mDAAkC,CAAA;IAClC;;;OAGG;IACH,iDAAgC,CAAA;IAChC;;;OAGG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,kEAAiD,CAAA;IACjD;;;OAGG;IACH,kEAAiD,CAAA;IACjD;;;;;OAKG;IACH,wDAAuC,CAAA;IACvC;;;OAGG;IACH,4DAA2C,CAAA;IAC3C;;;OAGG;IACH,wDAAuC,CAAA;IACvC;;;;OAIG;IACH,8DAA6C,CAAA;IAC7C;;;OAGG;IACH,oDAAmC,CAAA;AACrC,CAAC,EAlEW,aAAa,KAAb,aAAa,QAkExB"}
@@ -4,5 +4,7 @@ import type { Callback } from "./protocols.js";
4
4
  export type ActiveSubscriptions = Map<PubsubTopic, ContentTopic[]>;
5
5
  export interface IReceiver {
6
6
  toSubscriptionIterator: <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[]) => Promise<IAsyncIterator<T>>;
7
- subscribe: <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[], callback: Callback<T>) => Unsubscribe | Promise<Unsubscribe>;
7
+ subscribeWithUnsubscribe: SubscribeWithUnsubscribe;
8
8
  }
9
+ type SubscribeWithUnsubscribe = <T extends IDecodedMessage>(decoders: IDecoder<T> | IDecoder<T>[], callback: Callback<T>) => Unsubscribe | Promise<Unsubscribe>;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ export type ShardInfo = {
2
+ clusterId: number;
3
+ shards: number[];
4
+ };
5
+ export type ContentTopicInfo = {
6
+ clusterId?: number;
7
+ contentTopics: string[];
8
+ };
9
+ export type StaticSharding = ShardInfo;
10
+ export type AutoSharding = ContentTopicInfo;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sharding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharding.js","sourceRoot":"","sources":["../src/sharding.ts"],"names":[],"mappings":""}
package/dist/store.d.ts CHANGED
@@ -1,51 +1,75 @@
1
- import { proto_store as proto } from "@waku/proto";
2
1
  import type { IDecodedMessage, IDecoder } from "./message.js";
3
2
  import type { IBaseProtocolCore, IBaseProtocolSDK } from "./protocols.js";
4
- export declare enum PageDirection {
5
- BACKWARD = "backward",
6
- FORWARD = "forward"
7
- }
8
- export interface TimeFilter {
9
- startTime: Date;
10
- endTime: Date;
11
- }
12
- export interface Cursor {
13
- digest: Uint8Array;
14
- receiverTime: bigint;
15
- senderTime: bigint;
3
+ export type StoreCursor = Uint8Array;
4
+ /**
5
+ * Parameters for a store query request, as specified in the Waku Store v3 RFC.
6
+ */
7
+ export type QueryRequestParams = {
8
+ /**
9
+ * Whether to include the full message data in the response.
10
+ * - `true`: The response will include the message content and associated pubsub topic for each matching message.
11
+ * - `false`: The response will only include the message hashes for each matching message.
12
+ * @default true
13
+ */
14
+ includeData: boolean;
15
+ /**
16
+ * The pubsub topic to query. This field is mandatory.
17
+ * The query will only return messages that were published on this specific pubsub topic.
18
+ */
16
19
  pubsubTopic: string;
17
- }
18
- export type StoreQueryOptions = {
19
20
  /**
20
- * The direction in which pages are retrieved:
21
- * - { @link PageDirection.BACKWARD }: Most recent page first.
22
- * - { @link PageDirection.FORWARD }: Oldest page first.
23
- *
24
- * Note: This does not affect the ordering of messages with the page
25
- * (the oldest message is always first).
26
- *
27
- * @default { @link PageDirection.BACKWARD }
21
+ * The content topics to filter the messages.
22
+ * The query will only return messages that have a content topic included in this array.
23
+ * This field MUST be populated together with the `pubsubTopic` field for content topic filtering to be applied.
24
+ * If either `contentTopics` or `pubsubTopic` is not provided or empty, no content topic filtering will be applied.
25
+ */
26
+ contentTopics: string[];
27
+ /**
28
+ * The start time for the time range filter.
29
+ * The query will only return messages with a timestamp greater than or equal to `timeStart`.
30
+ * If not provided, no start time filtering will be applied.
31
+ */
32
+ timeStart?: Date;
33
+ /**
34
+ * The end time for the time range filter.
35
+ * The query will only return messages with a timestamp strictly less than `timeEnd`.
36
+ * If not provided, no end time filtering will be applied.
37
+ */
38
+ timeEnd?: Date;
39
+ /**
40
+ * The message hashes to lookup.
41
+ * If provided, the query will be a message hash lookup query and will only return messages that match the specified hashes.
42
+ * If not provided or empty, the query will be a content filtered query based on the other filter parameters.
43
+ * @default undefined
28
44
  */
29
- pageDirection?: PageDirection;
45
+ messageHashes?: Uint8Array[];
30
46
  /**
31
- * The number of message per page.
47
+ * The cursor to start the query from.
48
+ * The cursor represents the message hash of the last message returned in the previous query.
49
+ * The query will start from the message immediately following the cursor, excluding the message at the cursor itself.
50
+ * If not provided, the query will start from the beginning or end of the store, depending on the `paginationForward` option.
51
+ * @default undefined
32
52
  */
33
- pageSize?: number;
53
+ paginationCursor?: Uint8Array;
34
54
  /**
35
- * Retrieve messages with a timestamp within the provided values.
55
+ * The direction of pagination.
56
+ * - `true`: Forward pagination, starting from the oldest message and moving towards the newest.
57
+ * - `false`: Backward pagination, starting from the newest message and moving towards the oldest.
58
+ * @default false
36
59
  */
37
- timeFilter?: TimeFilter;
60
+ paginationForward: boolean;
38
61
  /**
39
- * Cursor as an index to start a query from. Must be generated from a Waku
40
- * Message.
62
+ * The maximum number of messages to retrieve per page.
63
+ * If not provided, the store's default pagination limit will be used.
64
+ * @default undefined
41
65
  */
42
- cursor?: proto.Index;
66
+ paginationLimit?: number;
43
67
  };
44
68
  export type IStoreCore = IBaseProtocolCore;
45
69
  export type IStoreSDK = IBaseProtocolSDK & {
46
70
  protocol: IBaseProtocolCore;
47
- createCursor(message: IDecodedMessage): Cursor;
48
- queryGenerator: <T extends IDecodedMessage>(decoders: IDecoder<T>[], options?: StoreQueryOptions) => AsyncGenerator<Promise<T | undefined>[]>;
49
- queryWithOrderedCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
50
- queryWithPromiseCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
71
+ createCursor(message: IDecodedMessage): StoreCursor;
72
+ queryGenerator: <T extends IDecodedMessage>(decoders: IDecoder<T>[], options?: Partial<QueryRequestParams>) => AsyncGenerator<Promise<T | undefined>[]>;
73
+ queryWithOrderedCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: Partial<QueryRequestParams>) => Promise<void>;
74
+ queryWithPromiseCallback: <T extends IDecodedMessage>(decoders: IDecoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: Partial<QueryRequestParams>) => Promise<void>;
51
75
  };
package/dist/store.js CHANGED
@@ -1,6 +1,2 @@
1
- export var PageDirection;
2
- (function (PageDirection) {
3
- PageDirection["BACKWARD"] = "backward";
4
- PageDirection["FORWARD"] = "forward";
5
- })(PageDirection || (PageDirection = {}));
1
+ export {};
6
2
  //# sourceMappingURL=store.js.map
package/dist/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;AACrB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB"}
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":""}
package/dist/waku.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { PeerId, Stream } from "@libp2p/interface";
2
2
  import type { MultiaddrInput } from "@multiformats/multiaddr";
3
3
  import { IConnectionManager } from "./connection_manager.js";
4
4
  import type { IFilterSDK } from "./filter.js";
5
+ import { IHealthManager } from "./health_manager.js";
5
6
  import type { Libp2p } from "./libp2p.js";
6
7
  import type { ILightPushSDK } from "./light_push.js";
7
8
  import { Protocols } from "./protocols.js";
@@ -19,6 +20,7 @@ export interface Waku {
19
20
  stop(): Promise<void>;
20
21
  isStarted(): boolean;
21
22
  isConnected(): boolean;
23
+ health: IHealthManager;
22
24
  }
23
25
  export interface LightNode extends Waku {
24
26
  relay: undefined;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@waku/interfaces","version":"0.0.26-1887f4f.0","description":"Definition of Waku interfaces","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","author":"Waku Team","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/interfaces#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralized","secure","communication","web3","ethereum","dapps","privacy"],"scripts":{"build":"run-s build:**","build:esm":"tsc","fix":"run-s fix:*","fix:lint":"eslint src --fix","check":"run-s check:*","check:lint":"eslint src","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","check:tsc":"tsc -p tsconfig.dev.json","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=18"},"devDependencies":{"@chainsafe/libp2p-gossipsub":"^12.0.0","@multiformats/multiaddr":"^12.0.0","cspell":"^8.6.1","npm-run-all":"^4.1.5","libp2p":"^1.1.2"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@waku/proto":"0.0.8-1887f4f.0"}}
1
+ {"name":"@waku/interfaces","version":"0.0.26-77b2cdd.0","description":"Definition of Waku interfaces","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"type":"module","author":"Waku Team","homepage":"https://github.com/waku-org/js-waku/tree/master/packages/interfaces#readme","repository":{"type":"git","url":"https://github.com/waku-org/js-waku.git"},"bugs":{"url":"https://github.com/waku-org/js-waku/issues"},"license":"MIT OR Apache-2.0","keywords":["waku","decentralized","secure","communication","web3","ethereum","dapps","privacy"],"scripts":{"build":"run-s build:**","build:esm":"tsc","fix":"run-s fix:*","fix:lint":"eslint src --fix","check":"run-s check:*","check:lint":"eslint src","check:spelling":"cspell \"{README.md,src/**/*.ts}\"","check:tsc":"tsc -p tsconfig.dev.json","prepublish":"npm run build","reset-hard":"git clean -dfx -e .idea && git reset --hard && npm i && npm run build"},"engines":{"node":">=18"},"devDependencies":{"@chainsafe/libp2p-gossipsub":"^13.1.0","@multiformats/multiaddr":"^12.0.0","cspell":"^8.6.1","npm-run-all":"^4.1.5","libp2p":"^1.8.1"},"files":["dist","bundle","src/**/*.ts","!**/*.spec.*","!**/*.json","CHANGELOG.md","LICENSE","README.md"],"dependencies":{"@waku/proto":"0.0.8-77b2cdd.0"}}
@@ -1,5 +1,7 @@
1
1
  import type { Peer, PeerId, TypedEventEmitter } from "@libp2p/interface";
2
2
 
3
+ import { PubsubTopic } from "./misc";
4
+
3
5
  export enum Tags {
4
6
  BOOTSTRAP = "bootstrap",
5
7
  PEER_EXCHANGE = "peer-exchange",
@@ -61,6 +63,7 @@ export interface IConnectionStateEvents {
61
63
 
62
64
  export interface IConnectionManager
63
65
  extends TypedEventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents> {
66
+ configuredPubsubTopics: PubsubTopic[];
64
67
  dropConnection(peerId: PeerId): Promise<void>;
65
68
  getPeersByDiscovery(): Promise<PeersByDiscoveryResult>;
66
69
  stop(): void;
package/src/constants.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ShardInfo } from "./enr";
1
+ import type { ShardInfo } from "./sharding";
2
2
 
3
3
  /**
4
4
  * The default cluster ID for The Waku Network
@@ -12,3 +12,5 @@ export const DefaultShardInfo: ShardInfo = {
12
12
  clusterId: DEFAULT_CLUSTER_ID,
13
13
  shards: [0, 1, 2, 3, 4, 5, 6, 7, 8]
14
14
  };
15
+
16
+ export const DefaultNetworkConfig = DefaultShardInfo;
package/src/enr.ts CHANGED
@@ -2,6 +2,8 @@ import type { PeerId } from "@libp2p/interface";
2
2
  import type { PeerInfo } from "@libp2p/interface";
3
3
  import type { Multiaddr } from "@multiformats/multiaddr";
4
4
 
5
+ import { ShardInfo } from "./sharding";
6
+
5
7
  export type ENRKey = string;
6
8
  export type ENRValue = Uint8Array;
7
9
  /**
@@ -18,11 +20,6 @@ export interface Waku2 {
18
20
  lightPush: boolean;
19
21
  }
20
22
 
21
- export interface ShardInfo {
22
- clusterId: number;
23
- shards: number[];
24
- }
25
-
26
23
  export interface IEnr extends Map<ENRKey, ENRValue> {
27
24
  nodeId?: NodeId;
28
25
  peerId?: PeerId;
package/src/filter.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import type { PeerId } from "@libp2p/interface";
2
2
 
3
3
  import type { IDecodedMessage, IDecoder } from "./message.js";
4
- import type { ContentTopic, PubsubTopic, ThisOrThat } from "./misc.js";
4
+ import type { ContentTopic, ThisOrThat } from "./misc.js";
5
5
  import type {
6
6
  Callback,
7
7
  IBaseProtocolCore,
8
8
  IBaseProtocolSDK,
9
9
  ProtocolError,
10
10
  ProtocolUseOptions,
11
- SDKProtocolResult,
12
- ShardingParams
11
+ SDKProtocolResult
13
12
  } from "./protocols.js";
14
13
  import type { IReceiver } from "./receiver.js";
15
14
 
@@ -37,12 +36,28 @@ export interface ISubscriptionSDK {
37
36
 
38
37
  export type IFilterSDK = IReceiver &
39
38
  IBaseProtocolSDK & { protocol: IBaseProtocolCore } & {
40
- createSubscription(
41
- pubsubTopicShardInfo?: ShardingParams | PubsubTopic,
42
- options?: ProtocolUseOptions
43
- ): Promise<CreateSubscriptionResult>;
39
+ subscribe<T extends IDecodedMessage>(
40
+ decoders: IDecoder<T> | IDecoder<T>[],
41
+ callback: Callback<T>,
42
+ protocolUseOptions?: ProtocolUseOptions,
43
+ subscribeOptions?: SubscribeOptions
44
+ ): Promise<SubscribeResult>;
44
45
  };
45
46
 
47
+ export type SubscribeResult = SubscriptionSuccess | SubscriptionError;
48
+
49
+ type SubscriptionSuccess = {
50
+ subscription: ISubscriptionSDK;
51
+ error: null;
52
+ results: SDKProtocolResult;
53
+ };
54
+
55
+ type SubscriptionError = {
56
+ subscription: null;
57
+ error: ProtocolError;
58
+ results: null;
59
+ };
60
+
46
61
  export type CreateSubscriptionResult = ThisOrThat<
47
62
  "subscription",
48
63
  ISubscriptionSDK,
@@ -0,0 +1,26 @@
1
+ import { Protocols } from "./protocols";
2
+
3
+ export enum HealthStatus {
4
+ Unhealthy = "Unhealthy",
5
+ MinimallyHealthy = "MinimallyHealthy",
6
+ SufficientlyHealthy = "SufficientlyHealthy"
7
+ }
8
+
9
+ export interface IHealthManager {
10
+ getHealthStatus: () => HealthStatus;
11
+ getProtocolStatus: (protocol: Protocols) => ProtocolHealth | undefined;
12
+ updateProtocolHealth: (multicodec: string, connectedPeers: number) => void;
13
+ }
14
+
15
+ export type NodeHealth = {
16
+ overallStatus: HealthStatus;
17
+ protocolStatuses: ProtocolsHealthStatus;
18
+ };
19
+
20
+ export type ProtocolHealth = {
21
+ name: Protocols;
22
+ status: HealthStatus;
23
+ lastUpdate: Date;
24
+ };
25
+
26
+ export type ProtocolsHealthStatus = Map<Protocols, ProtocolHealth>;
package/src/index.ts CHANGED
@@ -17,3 +17,5 @@ export * from "./dns_discovery.js";
17
17
  export * from "./metadata.js";
18
18
  export * from "./constants.js";
19
19
  export * from "./local_storage.js";
20
+ export * from "./health_manager.js";
21
+ export * from "./sharding.js";
package/src/libp2p.ts CHANGED
@@ -30,4 +30,9 @@ export type CreateLibp2pOptions = Libp2pOptions & {
30
30
  */
31
31
  hideWebSocketInfo?: boolean;
32
32
  pingMaxInboundStreams?: number;
33
+ /**
34
+ * Applies secure web socket filters.
35
+ * @default true
36
+ */
37
+ filterMultiaddrs?: boolean;
33
38
  };
package/src/metadata.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import type { PeerId } from "@libp2p/interface";
2
2
 
3
- import { type ShardInfo } from "./enr.js";
4
- import { ThisOrThat } from "./misc.js";
5
- import type { IBaseProtocolCore, ShardingParams } from "./protocols.js";
3
+ import { PubsubTopic, ThisOrThat } from "./misc.js";
4
+ import type { IBaseProtocolCore } from "./protocols.js";
5
+ import type { ShardInfo } from "./sharding.js";
6
6
 
7
7
  export type MetadataQueryResult = ThisOrThat<"shardInfo", ShardInfo>;
8
8
 
9
9
  // IMetadata always has shardInfo defined while it is optionally undefined in IBaseProtocol
10
10
  export interface IMetadata extends Omit<IBaseProtocolCore, "shardInfo"> {
11
- shardInfo: ShardingParams;
11
+ pubsubTopics: PubsubTopic[];
12
12
  confirmOrAttemptHandshake(peerId: PeerId): Promise<MetadataQueryResult>;
13
13
  query(peerId: PeerId): Promise<MetadataQueryResult>;
14
14
  }
package/src/protocols.ts CHANGED
@@ -2,10 +2,10 @@ import type { Libp2p } from "@libp2p/interface";
2
2
  import type { PeerId } from "@libp2p/interface";
3
3
  import type { Peer, PeerStore } from "@libp2p/interface";
4
4
 
5
- import type { ShardInfo } from "./enr.js";
6
5
  import type { CreateLibp2pOptions } from "./libp2p.js";
7
6
  import type { IDecodedMessage } from "./message.js";
8
- import { PubsubTopic, ThisAndThat, ThisOrThat } from "./misc.js";
7
+ import { ThisAndThat, ThisOrThat } from "./misc.js";
8
+ import { AutoSharding, StaticSharding } from "./sharding.js";
9
9
 
10
10
  export enum Protocols {
11
11
  Relay = "relay",
@@ -15,7 +15,6 @@ export enum Protocols {
15
15
  }
16
16
 
17
17
  export type IBaseProtocolCore = {
18
- shardInfo?: ShardInfo;
19
18
  multicodec: string;
20
19
  peerStore: PeerStore;
21
20
  allPeers: () => Promise<Peer[]>;
@@ -25,23 +24,12 @@ export type IBaseProtocolCore = {
25
24
  };
26
25
 
27
26
  export type IBaseProtocolSDK = {
28
- renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
29
27
  readonly connectedPeers: Peer[];
28
+ renewPeer: (peerToDisconnect: PeerId) => Promise<Peer>;
30
29
  readonly numPeersToUse: number;
31
30
  };
32
31
 
33
- export type ContentTopicInfo = {
34
- clusterId?: number;
35
- contentTopics: string[];
36
- };
37
-
38
- export type ApplicationInfo = {
39
- clusterId: number;
40
- application: string;
41
- version: string;
42
- };
43
-
44
- export type ShardingParams = ShardInfo | ContentTopicInfo | ApplicationInfo;
32
+ export type NetworkConfig = StaticSharding | AutoSharding;
45
33
 
46
34
  //TODO: merge this with ProtocolCreateOptions or establish distinction: https://github.com/waku-org/js-waku/issues/2048
47
35
  /**
@@ -72,38 +60,35 @@ export type ProtocolUseOptions = {
72
60
 
73
61
  export type ProtocolCreateOptions = {
74
62
  /**
75
- * @deprecated
76
- * Should be used ONLY if some other than The Waku Network is in use.
77
- *
78
- * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#pubsub-topics) for details.
63
+ * Configuration for determining the network in use.
79
64
  *
80
- * This is used by:
81
- * - WakuRelay to receive, route and send messages,
82
- * - WakuLightPush to send messages,
83
- * - WakuStore to retrieve messages.
84
- *
85
- * If no pubsub topic is specified, the default pubsub topic will be determined from DefaultShardInfo.
65
+ * If using Static Sharding:
66
+ * Default value is configured for The Waku Network.
67
+ * The format to specify a shard is: clusterId: number, shards: number[]
68
+ * To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
86
69
  *
87
- * You cannot add or remove pubsub topics after initialization of the node.
70
+ * If using Auto Sharding:
71
+ * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
72
+ * You cannot add or remove content topics after initialization of the node.
88
73
  */
89
- pubsubTopics?: PubsubTopic[];
90
74
  /**
91
- * ShardInfo is used to determine which network is in use.
92
- * Defaults to {@link @waku/interfaces!DefaultShardInfo}.
93
- * Default value is configured for The Waku Network
75
+ * Configuration for determining the network in use.
76
+ * Network configuration refers to the shards and clusters used in the network.
94
77
  *
95
- * The format to specify a shard is:
96
- * clusterId: number, shards: number[]
78
+ * If using Static Sharding:
79
+ * Cluster ID and shards are specified in the format: clusterId: number, shards: number[]
80
+ * The default value is configured for The Waku Network => clusterId: 0, shards: [0, 1, 2, 3, 4, 5, 6, 7]
97
81
  * To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
98
- */
99
- shardInfo?: Partial<ShardingParams>;
100
- /**
101
- * Content topics are used to determine network in use.
102
- * See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
103
82
  *
104
- * You cannot add or remove content topics after initialization of the node.
83
+ * If using Auto Sharding:
84
+ * Cluster ID and content topics are specified in the format: clusterId: number, contentTopics: string[]
85
+ * Content topics are used to determine the shards to be configured for the network.
86
+ * Cluster ID is optional, and defaults to The Waku Network's cluster ID => 0
87
+ * To specify content topics, see [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details
88
+ *
89
+ * @default { clusterId: 1, shards: [0, 1, 2, 3, 4, 5, 6, 7] }
105
90
  */
106
- contentTopics?: string[];
91
+ networkConfig?: NetworkConfig;
107
92
  /**
108
93
  * You can pass options to the `Libp2p` instance used by {@link @waku/sdk!WakuNode} using the `libp2p` property.
109
94
  * This property is the same type as the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create)
@@ -173,6 +158,11 @@ export enum ProtocolError {
173
158
  * Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
174
159
  */
175
160
  TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
161
+ /**
162
+ * The topics passed in the decoders do not match each other, or don't exist at all.
163
+ * Ensure that all the pubsub topics used in the decoders are valid and match each other.
164
+ */
165
+ INVALID_DECODER_TOPICS = "Invalid decoder topics",
176
166
  /**
177
167
  * Failure to find a peer with suitable protocols. This may due to a connection issue.
178
168
  * Mitigation can be: retrying after a given time period, display connectivity issue
package/src/receiver.ts CHANGED
@@ -13,8 +13,10 @@ export interface IReceiver {
13
13
  toSubscriptionIterator: <T extends IDecodedMessage>(
14
14
  decoders: IDecoder<T> | IDecoder<T>[]
15
15
  ) => Promise<IAsyncIterator<T>>;
16
- subscribe: <T extends IDecodedMessage>(
17
- decoders: IDecoder<T> | IDecoder<T>[],
18
- callback: Callback<T>
19
- ) => Unsubscribe | Promise<Unsubscribe>;
16
+ subscribeWithUnsubscribe: SubscribeWithUnsubscribe;
20
17
  }
18
+
19
+ type SubscribeWithUnsubscribe = <T extends IDecodedMessage>(
20
+ decoders: IDecoder<T> | IDecoder<T>[],
21
+ callback: Callback<T>
22
+ ) => Unsubscribe | Promise<Unsubscribe>;
@@ -0,0 +1,12 @@
1
+ export type ShardInfo = {
2
+ clusterId: number;
3
+ shards: number[];
4
+ };
5
+
6
+ export type ContentTopicInfo = {
7
+ clusterId?: number;
8
+ contentTopics: string[];
9
+ };
10
+
11
+ export type StaticSharding = ShardInfo;
12
+ export type AutoSharding = ContentTopicInfo;
package/src/store.ts CHANGED
@@ -1,72 +1,101 @@
1
- import { proto_store as proto } from "@waku/proto";
2
-
3
1
  import type { IDecodedMessage, IDecoder } from "./message.js";
4
2
  import type { IBaseProtocolCore, IBaseProtocolSDK } from "./protocols.js";
5
3
 
6
- export enum PageDirection {
7
- BACKWARD = "backward",
8
- FORWARD = "forward"
9
- }
4
+ export type StoreCursor = Uint8Array;
10
5
 
11
- export interface TimeFilter {
12
- startTime: Date;
13
- endTime: Date;
14
- }
6
+ /**
7
+ * Parameters for a store query request, as specified in the Waku Store v3 RFC.
8
+ */
9
+ export type QueryRequestParams = {
10
+ /**
11
+ * Whether to include the full message data in the response.
12
+ * - `true`: The response will include the message content and associated pubsub topic for each matching message.
13
+ * - `false`: The response will only include the message hashes for each matching message.
14
+ * @default true
15
+ */
16
+ includeData: boolean;
15
17
 
16
- export interface Cursor {
17
- digest: Uint8Array;
18
- receiverTime: bigint;
19
- senderTime: bigint;
18
+ /**
19
+ * The pubsub topic to query. This field is mandatory.
20
+ * The query will only return messages that were published on this specific pubsub topic.
21
+ */
20
22
  pubsubTopic: string;
21
- }
22
23
 
23
- export type StoreQueryOptions = {
24
24
  /**
25
- * The direction in which pages are retrieved:
26
- * - { @link PageDirection.BACKWARD }: Most recent page first.
27
- * - { @link PageDirection.FORWARD }: Oldest page first.
28
- *
29
- * Note: This does not affect the ordering of messages with the page
30
- * (the oldest message is always first).
31
- *
32
- * @default { @link PageDirection.BACKWARD }
25
+ * The content topics to filter the messages.
26
+ * The query will only return messages that have a content topic included in this array.
27
+ * This field MUST be populated together with the `pubsubTopic` field for content topic filtering to be applied.
28
+ * If either `contentTopics` or `pubsubTopic` is not provided or empty, no content topic filtering will be applied.
33
29
  */
34
- pageDirection?: PageDirection;
30
+ contentTopics: string[];
31
+
35
32
  /**
36
- * The number of message per page.
33
+ * The start time for the time range filter.
34
+ * The query will only return messages with a timestamp greater than or equal to `timeStart`.
35
+ * If not provided, no start time filtering will be applied.
37
36
  */
38
- pageSize?: number;
37
+ timeStart?: Date;
38
+
39
39
  /**
40
- * Retrieve messages with a timestamp within the provided values.
40
+ * The end time for the time range filter.
41
+ * The query will only return messages with a timestamp strictly less than `timeEnd`.
42
+ * If not provided, no end time filtering will be applied.
41
43
  */
42
- timeFilter?: TimeFilter;
44
+ timeEnd?: Date;
45
+
46
+ /**
47
+ * The message hashes to lookup.
48
+ * If provided, the query will be a message hash lookup query and will only return messages that match the specified hashes.
49
+ * If not provided or empty, the query will be a content filtered query based on the other filter parameters.
50
+ * @default undefined
51
+ */
52
+ messageHashes?: Uint8Array[];
53
+
54
+ /**
55
+ * The cursor to start the query from.
56
+ * The cursor represents the message hash of the last message returned in the previous query.
57
+ * The query will start from the message immediately following the cursor, excluding the message at the cursor itself.
58
+ * If not provided, the query will start from the beginning or end of the store, depending on the `paginationForward` option.
59
+ * @default undefined
60
+ */
61
+ paginationCursor?: Uint8Array;
62
+
63
+ /**
64
+ * The direction of pagination.
65
+ * - `true`: Forward pagination, starting from the oldest message and moving towards the newest.
66
+ * - `false`: Backward pagination, starting from the newest message and moving towards the oldest.
67
+ * @default false
68
+ */
69
+ paginationForward: boolean;
70
+
43
71
  /**
44
- * Cursor as an index to start a query from. Must be generated from a Waku
45
- * Message.
72
+ * The maximum number of messages to retrieve per page.
73
+ * If not provided, the store's default pagination limit will be used.
74
+ * @default undefined
46
75
  */
47
- cursor?: proto.Index;
76
+ paginationLimit?: number;
48
77
  };
49
78
 
50
79
  export type IStoreCore = IBaseProtocolCore;
51
80
 
52
81
  export type IStoreSDK = IBaseProtocolSDK & {
53
82
  protocol: IBaseProtocolCore;
54
- createCursor(message: IDecodedMessage): Cursor;
83
+ createCursor(message: IDecodedMessage): StoreCursor;
55
84
  queryGenerator: <T extends IDecodedMessage>(
56
85
  decoders: IDecoder<T>[],
57
- options?: StoreQueryOptions
86
+ options?: Partial<QueryRequestParams>
58
87
  ) => AsyncGenerator<Promise<T | undefined>[]>;
59
88
 
60
89
  queryWithOrderedCallback: <T extends IDecodedMessage>(
61
90
  decoders: IDecoder<T>[],
62
91
  callback: (message: T) => Promise<void | boolean> | boolean | void,
63
- options?: StoreQueryOptions
92
+ options?: Partial<QueryRequestParams>
64
93
  ) => Promise<void>;
65
94
  queryWithPromiseCallback: <T extends IDecodedMessage>(
66
95
  decoders: IDecoder<T>[],
67
96
  callback: (
68
97
  message: Promise<T | undefined>
69
98
  ) => Promise<void | boolean> | boolean | void,
70
- options?: StoreQueryOptions
99
+ options?: Partial<QueryRequestParams>
71
100
  ) => Promise<void>;
72
101
  };