@waku/core 0.0.31-ce62600.0 → 0.0.31-f387f59.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.
Files changed (71) hide show
  1. package/bundle/{base_protocol-C6HnrRx8.js → base_protocol-Dge5_tvU.js} +22 -25
  2. package/bundle/{index-DnW8ifxc.js → index-Gts2Ddu_.js} +41 -56
  3. package/bundle/index.js +291 -288
  4. package/bundle/lib/base_protocol.js +2 -2
  5. package/bundle/lib/message/version_0.js +2 -2
  6. package/bundle/{version_0-DQ9xsSLk.js → version_0-CNRKFufI.js} +154 -308
  7. package/dist/.tsbuildinfo +1 -1
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +2 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/lib/base_protocol.d.ts +3 -4
  12. package/dist/lib/base_protocol.js +4 -8
  13. package/dist/lib/base_protocol.js.map +1 -1
  14. package/dist/lib/connection_manager.d.ts +2 -2
  15. package/dist/lib/connection_manager.js +21 -23
  16. package/dist/lib/connection_manager.js.map +1 -1
  17. package/dist/lib/filter/filter_rpc.js.map +1 -1
  18. package/dist/lib/filter/index.d.ts +4 -3
  19. package/dist/lib/filter/index.js +33 -31
  20. package/dist/lib/filter/index.js.map +1 -1
  21. package/dist/lib/health_manager.d.ts +14 -0
  22. package/dist/lib/health_manager.js +70 -0
  23. package/dist/lib/health_manager.js.map +1 -0
  24. package/dist/lib/keep_alive_manager.d.ts +13 -7
  25. package/dist/lib/keep_alive_manager.js +9 -9
  26. package/dist/lib/keep_alive_manager.js.map +1 -1
  27. package/dist/lib/light_push/index.d.ts +3 -2
  28. package/dist/lib/light_push/index.js +4 -2
  29. package/dist/lib/light_push/index.js.map +1 -1
  30. package/dist/lib/light_push/push_rpc.js.map +1 -1
  31. package/dist/lib/message/version_0.js.map +1 -1
  32. package/dist/lib/metadata/index.d.ts +2 -2
  33. package/dist/lib/metadata/index.js +26 -26
  34. package/dist/lib/metadata/index.js.map +1 -1
  35. package/dist/lib/store/index.d.ts +5 -44
  36. package/dist/lib/store/index.js +39 -45
  37. package/dist/lib/store/index.js.map +1 -1
  38. package/dist/lib/store/rpc.d.ts +22 -0
  39. package/dist/lib/store/rpc.js +74 -0
  40. package/dist/lib/store/rpc.js.map +1 -0
  41. package/dist/lib/stream_manager/index.d.ts +1 -0
  42. package/dist/lib/stream_manager/index.js +2 -0
  43. package/dist/lib/stream_manager/index.js.map +1 -0
  44. package/dist/lib/{stream_manager.js → stream_manager/stream_manager.js} +1 -1
  45. package/dist/lib/stream_manager/stream_manager.js.map +1 -0
  46. package/dist/lib/stream_manager/utils.d.ts +2 -0
  47. package/dist/lib/stream_manager/utils.js +19 -0
  48. package/dist/lib/stream_manager/utils.js.map +1 -0
  49. package/package.json +1 -1
  50. package/src/index.ts +3 -3
  51. package/src/lib/base_protocol.ts +7 -10
  52. package/src/lib/connection_manager.ts +29 -30
  53. package/src/lib/filter/filter_rpc.ts +21 -19
  54. package/src/lib/filter/index.ts +50 -52
  55. package/src/lib/health_manager.ts +90 -0
  56. package/src/lib/keep_alive_manager.ts +27 -18
  57. package/src/lib/light_push/index.ts +7 -10
  58. package/src/lib/light_push/push_rpc.ts +5 -5
  59. package/src/lib/message/version_0.ts +17 -15
  60. package/src/lib/metadata/index.ts +43 -44
  61. package/src/lib/store/index.ts +54 -94
  62. package/src/lib/store/rpc.ts +92 -0
  63. package/src/lib/stream_manager/index.ts +1 -0
  64. package/src/lib/{stream_manager.ts → stream_manager/stream_manager.ts} +3 -2
  65. package/src/lib/stream_manager/utils.ts +22 -0
  66. package/dist/lib/store/history_rpc.d.ts +0 -27
  67. package/dist/lib/store/history_rpc.js +0 -72
  68. package/dist/lib/store/history_rpc.js.map +0 -1
  69. package/dist/lib/stream_manager.js.map +0 -1
  70. package/src/lib/store/history_rpc.ts +0 -93
  71. /package/dist/lib/{stream_manager.d.ts → stream_manager/stream_manager.d.ts} +0 -0
@@ -6,10 +6,11 @@ import {
6
6
  type MetadataQueryResult,
7
7
  type PeerIdStr,
8
8
  ProtocolError,
9
+ PubsubTopic,
9
10
  type ShardInfo
10
11
  } from "@waku/interfaces";
11
12
  import { proto_metadata } from "@waku/proto";
12
- import { encodeRelayShard, Logger, shardInfoToPubsubTopics } from "@waku/utils";
13
+ import { encodeRelayShard, Logger, pubsubTopicsToShardInfo } from "@waku/utils";
13
14
  import all from "it-all";
14
15
  import * as lp from "it-length-prefixed";
15
16
  import { pipe } from "it-pipe";
@@ -23,59 +24,26 @@ export const MetadataCodec = "/vac/waku/metadata/1.0.0";
23
24
 
24
25
  class Metadata extends BaseProtocol implements IMetadata {
25
26
  private libp2pComponents: Libp2pComponents;
26
- handshakesConfirmed: Map<PeerIdStr, ShardInfo> = new Map();
27
+ protected handshakesConfirmed: Map<PeerIdStr, ShardInfo> = new Map();
27
28
 
28
- constructor(
29
- public shardInfo: ShardInfo,
29
+ public constructor(
30
+ public pubsubTopics: PubsubTopic[],
30
31
  libp2p: Libp2pComponents
31
32
  ) {
32
- super(
33
- MetadataCodec,
34
- libp2p.components,
35
- log,
36
- shardInfoToPubsubTopics(shardInfo)
37
- );
33
+ super(MetadataCodec, libp2p.components, log, pubsubTopics);
38
34
  this.libp2pComponents = libp2p;
39
35
  void libp2p.registrar.handle(MetadataCodec, (streamData) => {
40
36
  void this.onRequest(streamData);
41
37
  });
42
38
  }
43
39
 
44
- /**
45
- * Handle an incoming metadata request
46
- */
47
- private async onRequest(streamData: IncomingStreamData): Promise<void> {
48
- try {
49
- const { stream, connection } = streamData;
50
- const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(
51
- this.shardInfo
52
- );
53
-
54
- const encodedResponse = await pipe(
55
- [encodedShardInfo],
56
- lp.encode,
57
- stream,
58
- lp.decode,
59
- async (source) => await all(source)
60
- );
61
-
62
- const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
63
-
64
- if (error) {
65
- return;
66
- }
67
-
68
- await this.savePeerShardInfo(connection.remotePeer, shardInfo);
69
- } catch (error) {
70
- log.error("Error handling metadata request", error);
71
- }
72
- }
73
-
74
40
  /**
75
41
  * Make a metadata query to a peer
76
42
  */
77
- async query(peerId: PeerId): Promise<MetadataQueryResult> {
78
- const request = proto_metadata.WakuMetadataRequest.encode(this.shardInfo);
43
+ public async query(peerId: PeerId): Promise<MetadataQueryResult> {
44
+ const request = proto_metadata.WakuMetadataRequest.encode(
45
+ pubsubTopicsToShardInfo(this.pubsubTopics)
46
+ );
79
47
 
80
48
  const peer = await this.peerStore.get(peerId);
81
49
  if (!peer) {
@@ -135,6 +103,36 @@ class Metadata extends BaseProtocol implements IMetadata {
135
103
  return await this.query(peerId);
136
104
  }
137
105
 
106
+ /**
107
+ * Handle an incoming metadata request
108
+ */
109
+ private async onRequest(streamData: IncomingStreamData): Promise<void> {
110
+ try {
111
+ const { stream, connection } = streamData;
112
+ const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(
113
+ pubsubTopicsToShardInfo(this.pubsubTopics)
114
+ );
115
+
116
+ const encodedResponse = await pipe(
117
+ [encodedShardInfo],
118
+ lp.encode,
119
+ stream,
120
+ lp.decode,
121
+ async (source) => await all(source)
122
+ );
123
+
124
+ const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
125
+
126
+ if (error) {
127
+ return;
128
+ }
129
+
130
+ await this.savePeerShardInfo(connection.remotePeer, shardInfo);
131
+ } catch (error) {
132
+ log.error("Error handling metadata request", error);
133
+ }
134
+ }
135
+
138
136
  private decodeMetadataResponse(
139
137
  encodedResponse: Uint8ArrayList[]
140
138
  ): MetadataQueryResult {
@@ -177,7 +175,8 @@ class Metadata extends BaseProtocol implements IMetadata {
177
175
  }
178
176
 
179
177
  export function wakuMetadata(
180
- shardInfo: ShardInfo
178
+ pubsubTopics: PubsubTopic[]
181
179
  ): (components: Libp2pComponents) => IMetadata {
182
- return (components: Libp2pComponents) => new Metadata(shardInfo, components);
180
+ return (components: Libp2pComponents) =>
181
+ new Metadata(pubsubTopics, components);
183
182
  }
@@ -1,13 +1,12 @@
1
1
  import type { Peer } from "@libp2p/interface";
2
2
  import {
3
- Cursor,
4
3
  IDecodedMessage,
5
4
  IDecoder,
6
5
  IStoreCore,
7
6
  Libp2p,
8
- ProtocolCreateOptions
7
+ PubsubTopic,
8
+ QueryRequestParams
9
9
  } from "@waku/interfaces";
10
- import { proto_store as proto } from "@waku/proto";
11
10
  import { Logger } from "@waku/utils";
12
11
  import all from "it-all";
13
12
  import * as lp from "it-length-prefixed";
@@ -17,63 +16,27 @@ import { Uint8ArrayList } from "uint8arraylist";
17
16
  import { BaseProtocol } from "../base_protocol.js";
18
17
  import { toProtoMessage } from "../to_proto_message.js";
19
18
 
20
- import { HistoryRpc, PageDirection, Params } from "./history_rpc.js";
21
-
22
- import HistoryError = proto.HistoryResponse.HistoryError;
19
+ import {
20
+ DEFAULT_PAGE_SIZE,
21
+ MAX_PAGE_SIZE,
22
+ StoreQueryRequest,
23
+ StoreQueryResponse
24
+ } from "./rpc.js";
23
25
 
24
26
  const log = new Logger("store");
25
27
 
26
- export const StoreCodec = "/vac/waku/store/2.0.0-beta4";
27
-
28
- export { PageDirection, Params };
29
-
30
- export interface TimeFilter {
31
- startTime: Date;
32
- endTime: Date;
33
- }
34
-
35
- export interface QueryOptions {
36
- /**
37
- * The direction in which pages are retrieved:
38
- * - { @link PageDirection.BACKWARD }: Most recent page first.
39
- * - { @link PageDirection.FORWARD }: Oldest page first.
40
- *
41
- * Note: This does not affect the ordering of messages with the page
42
- * (the oldest message is always first).
43
- *
44
- * @default { @link PageDirection.BACKWARD }
45
- */
46
- pageDirection?: PageDirection;
47
- /**
48
- * The number of message per page.
49
- *
50
- * @default { @link DefaultPageSize }
51
- */
52
- pageSize?: number;
53
- /**
54
- * Retrieve messages with a timestamp within the provided values.
55
- */
56
- timeFilter?: TimeFilter;
57
- /**
58
- * Cursor as an index to start a query from.
59
- * The cursor index will be exclusive (i.e. the message at the cursor index will not be included in the result).
60
- * If undefined, the query will start from the beginning or end of the history, depending on the page direction.
61
- */
62
- cursor?: Cursor;
63
- }
28
+ export const StoreCodec = "/vac/waku/store-query/3.0.0";
64
29
 
65
- /**
66
- * Implements the [Waku v2 Store protocol](https://rfc.vac.dev/spec/13/).
67
- *
68
- * The Waku Store protocol can be used to retrieved historical messages.
69
- */
70
30
  export class StoreCore extends BaseProtocol implements IStoreCore {
71
- constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
72
- super(StoreCodec, libp2p.components, log, options!.pubsubTopics!, options);
31
+ public constructor(
32
+ public readonly pubsubTopics: PubsubTopic[],
33
+ libp2p: Libp2p
34
+ ) {
35
+ super(StoreCodec, libp2p.components, log, pubsubTopics);
73
36
  }
74
37
 
75
- async *queryPerPage<T extends IDecodedMessage>(
76
- queryOpts: Params,
38
+ public async *queryPerPage<T extends IDecodedMessage>(
39
+ queryOpts: QueryRequestParams,
77
40
  decoders: Map<string, IDecoder<T>>,
78
41
  peer: Peer
79
42
  ): AsyncGenerator<Promise<T | undefined>[]> {
@@ -86,11 +49,12 @@ export class StoreCore extends BaseProtocol implements IStoreCore {
86
49
  );
87
50
  }
88
51
 
89
- let currentCursor = queryOpts.cursor;
52
+ let currentCursor = queryOpts.paginationCursor;
90
53
  while (true) {
91
- queryOpts.cursor = currentCursor;
92
-
93
- const historyRpcQuery = HistoryRpc.createQuery(queryOpts);
54
+ const storeQueryRequest = StoreQueryRequest.create({
55
+ ...queryOpts,
56
+ paginationCursor: currentCursor
57
+ });
94
58
 
95
59
  let stream;
96
60
  try {
@@ -101,7 +65,7 @@ export class StoreCore extends BaseProtocol implements IStoreCore {
101
65
  }
102
66
 
103
67
  const res = await pipe(
104
- [historyRpcQuery.encode()],
68
+ [storeQueryRequest.encode()],
105
69
  lp.encode,
106
70
  stream,
107
71
  lp.decode,
@@ -113,61 +77,57 @@ export class StoreCore extends BaseProtocol implements IStoreCore {
113
77
  bytes.append(chunk);
114
78
  });
115
79
 
116
- const reply = historyRpcQuery.decode(bytes);
117
-
118
- if (!reply.response) {
119
- log.warn("Stopping pagination due to store `response` field missing");
120
- break;
121
- }
122
-
123
- const response = reply.response as proto.HistoryResponse;
80
+ const storeQueryResponse = StoreQueryResponse.decode(bytes);
124
81
 
125
- if (response.error && response.error !== HistoryError.NONE) {
126
- throw "History response contains an Error: " + response.error;
82
+ if (
83
+ !storeQueryResponse.statusCode ||
84
+ storeQueryResponse.statusCode >= 300
85
+ ) {
86
+ const errorMessage = `Store query failed with status code: ${storeQueryResponse.statusCode}, description: ${storeQueryResponse.statusDesc}`;
87
+ log.error(errorMessage);
88
+ throw new Error(errorMessage);
127
89
  }
128
90
 
129
- if (!response.messages || !response.messages.length) {
130
- log.warn(
131
- "Stopping pagination due to store `response.messages` field missing or empty"
132
- );
91
+ if (!storeQueryResponse.messages || !storeQueryResponse.messages.length) {
92
+ log.warn("Stopping pagination due to empty messages in response");
133
93
  break;
134
94
  }
135
95
 
136
- log.error(`${response.messages.length} messages retrieved from store`);
96
+ log.info(
97
+ `${storeQueryResponse.messages.length} messages retrieved from store`
98
+ );
137
99
 
138
- yield response.messages.map((protoMsg) => {
139
- const contentTopic = protoMsg.contentTopic;
140
- if (typeof contentTopic !== "undefined") {
100
+ const decodedMessages = storeQueryResponse.messages.map((protoMsg) => {
101
+ if (!protoMsg.message) {
102
+ return Promise.resolve(undefined);
103
+ }
104
+ const contentTopic = protoMsg.message.contentTopic;
105
+ if (contentTopic) {
141
106
  const decoder = decoders.get(contentTopic);
142
107
  if (decoder) {
143
108
  return decoder.fromProtoObj(
144
- queryOpts.pubsubTopic,
145
- toProtoMessage(protoMsg)
109
+ protoMsg.pubsubTopic || "",
110
+ toProtoMessage(protoMsg.message)
146
111
  );
147
112
  }
148
113
  }
149
114
  return Promise.resolve(undefined);
150
115
  });
151
116
 
152
- const nextCursor = response.pagingInfo?.cursor;
153
- if (typeof nextCursor === "undefined") {
154
- // If the server does not return cursor then there is an issue,
155
- // Need to abort, or we end up in an infinite loop
156
- log.warn(
157
- "Stopping pagination due to `response.pagingInfo.cursor` missing from store response"
158
- );
159
- break;
160
- }
117
+ yield decodedMessages;
161
118
 
162
- currentCursor = nextCursor;
119
+ if (queryOpts.paginationForward) {
120
+ currentCursor =
121
+ storeQueryResponse.messages[storeQueryResponse.messages.length - 1]
122
+ .messageHash;
123
+ } else {
124
+ currentCursor = storeQueryResponse.messages[0].messageHash;
125
+ }
163
126
 
164
- const responsePageSize = response.pagingInfo?.pageSize;
165
- const queryPageSize = historyRpcQuery.query?.pagingInfo?.pageSize;
166
127
  if (
167
- // Response page size smaller than query, meaning this is the last page
168
- responsePageSize &&
169
- queryPageSize &&
170
- responsePageSize < queryPageSize
128
+ storeQueryResponse.messages.length > MAX_PAGE_SIZE &&
129
+ storeQueryResponse.messages.length <
130
+ (queryOpts.paginationLimit || DEFAULT_PAGE_SIZE)
171
131
  ) {
172
132
  break;
173
133
  }
@@ -0,0 +1,92 @@
1
+ import { QueryRequestParams } from "@waku/interfaces";
2
+ import { proto_store as proto } from "@waku/proto";
3
+ import type { Uint8ArrayList } from "uint8arraylist";
4
+ import { v4 as uuid } from "uuid";
5
+
6
+ // https://github.com/waku-org/nwaku/blob/7205f95cff9f49ca0bb762e8fd0bf56a6a7f3b3b/waku/waku_store/common.nim#L12
7
+ export const DEFAULT_PAGE_SIZE = 20;
8
+ export const MAX_PAGE_SIZE = 100;
9
+ const ONE_MILLION = 1_000000;
10
+
11
+ export class StoreQueryRequest {
12
+ public constructor(public proto: proto.StoreQueryRequest) {}
13
+
14
+ public static create(params: QueryRequestParams): StoreQueryRequest {
15
+ const request = new StoreQueryRequest({
16
+ ...params,
17
+ requestId: uuid(),
18
+ timeStart: params.timeStart
19
+ ? BigInt(params.timeStart.getTime() * ONE_MILLION)
20
+ : undefined,
21
+ timeEnd: params.timeEnd
22
+ ? BigInt(params.timeEnd.getTime() * ONE_MILLION)
23
+ : undefined,
24
+ messageHashes: params.messageHashes || [],
25
+ paginationLimit: params.paginationLimit
26
+ ? BigInt(params.paginationLimit)
27
+ : undefined
28
+ });
29
+
30
+ // Validate request parameters based on RFC
31
+ if (
32
+ (params.pubsubTopic && !params.contentTopics) ||
33
+ (!params.pubsubTopic && params.contentTopics)
34
+ ) {
35
+ throw new Error(
36
+ "Both pubsubTopic and contentTopics must be set or unset"
37
+ );
38
+ }
39
+
40
+ if (
41
+ params.messageHashes &&
42
+ (params.pubsubTopic ||
43
+ params.contentTopics ||
44
+ params.timeStart ||
45
+ params.timeEnd)
46
+ ) {
47
+ throw new Error(
48
+ "Message hash lookup queries cannot include content filter criteria"
49
+ );
50
+ }
51
+
52
+ return request;
53
+ }
54
+
55
+ public static decode(bytes: Uint8ArrayList): StoreQueryRequest {
56
+ const res = proto.StoreQueryRequest.decode(bytes);
57
+ return new StoreQueryRequest(res);
58
+ }
59
+
60
+ public encode(): Uint8Array {
61
+ return proto.StoreQueryRequest.encode(this.proto);
62
+ }
63
+ }
64
+
65
+ export class StoreQueryResponse {
66
+ public constructor(public proto: proto.StoreQueryResponse) {}
67
+
68
+ public static decode(bytes: Uint8ArrayList): StoreQueryResponse {
69
+ const res = proto.StoreQueryResponse.decode(bytes);
70
+ return new StoreQueryResponse(res);
71
+ }
72
+
73
+ public encode(): Uint8Array {
74
+ return proto.StoreQueryResponse.encode(this.proto);
75
+ }
76
+
77
+ public get statusCode(): number | undefined {
78
+ return this.proto.statusCode;
79
+ }
80
+
81
+ public get statusDesc(): string | undefined {
82
+ return this.proto.statusDesc;
83
+ }
84
+
85
+ public get messages(): proto.WakuMessageKeyValue[] {
86
+ return this.proto.messages;
87
+ }
88
+
89
+ public get paginationCursor(): Uint8Array | undefined {
90
+ return this.proto.paginationCursor;
91
+ }
92
+ }
@@ -0,0 +1 @@
1
+ export { StreamManager } from "./stream_manager.js";
@@ -2,7 +2,8 @@ import type { PeerUpdate, Stream } from "@libp2p/interface";
2
2
  import type { Peer, PeerId } from "@libp2p/interface";
3
3
  import { Libp2p } from "@waku/interfaces";
4
4
  import { Logger } from "@waku/utils";
5
- import { selectConnection } from "@waku/utils/libp2p";
5
+
6
+ import { selectConnection } from "./utils.js";
6
7
 
7
8
  const CONNECTION_TIMEOUT = 5_000;
8
9
  const RETRY_BACKOFF_BASE = 1_000;
@@ -12,7 +13,7 @@ export class StreamManager {
12
13
  private readonly streamPool: Map<string, Promise<Stream | void>>;
13
14
  private readonly log: Logger;
14
15
 
15
- constructor(
16
+ public constructor(
16
17
  public multicodec: string,
17
18
  public getConnections: Libp2p["getConnections"],
18
19
  public addEventListener: Libp2p["addEventListener"]
@@ -0,0 +1,22 @@
1
+ import type { Connection } from "@libp2p/interface";
2
+
3
+ export function selectConnection(
4
+ connections: Connection[]
5
+ ): Connection | undefined {
6
+ if (!connections.length) return;
7
+ if (connections.length === 1) return connections[0];
8
+
9
+ let latestConnection: Connection | undefined;
10
+
11
+ connections.forEach((connection) => {
12
+ if (connection.status === "open") {
13
+ if (!latestConnection) {
14
+ latestConnection = connection;
15
+ } else if (connection.timeline.open > latestConnection.timeline.open) {
16
+ latestConnection = connection;
17
+ }
18
+ }
19
+ });
20
+
21
+ return latestConnection;
22
+ }
@@ -1,27 +0,0 @@
1
- import { proto_store as proto } from "@waku/proto";
2
- import type { Uint8ArrayList } from "uint8arraylist";
3
- export declare enum PageDirection {
4
- BACKWARD = "backward",
5
- FORWARD = "forward"
6
- }
7
- export interface Params {
8
- contentTopics: string[];
9
- pubsubTopic: string;
10
- pageDirection: PageDirection;
11
- pageSize: number;
12
- startTime?: Date;
13
- endTime?: Date;
14
- cursor?: proto.Index;
15
- }
16
- export declare class HistoryRpc {
17
- readonly proto: proto.HistoryRpc;
18
- private constructor();
19
- get query(): proto.HistoryQuery | undefined;
20
- get response(): proto.HistoryResponse | undefined;
21
- /**
22
- * Create History Query.
23
- */
24
- static createQuery(params: Params): HistoryRpc;
25
- decode(bytes: Uint8ArrayList): HistoryRpc;
26
- encode(): Uint8Array;
27
- }
@@ -1,72 +0,0 @@
1
- import { proto_store as proto } from "@waku/proto";
2
- import { v4 as uuid } from "uuid";
3
- const OneMillion = BigInt(1_000_000);
4
- export var PageDirection;
5
- (function (PageDirection) {
6
- PageDirection["BACKWARD"] = "backward";
7
- PageDirection["FORWARD"] = "forward";
8
- })(PageDirection || (PageDirection = {}));
9
- export class HistoryRpc {
10
- proto;
11
- constructor(proto) {
12
- this.proto = proto;
13
- }
14
- get query() {
15
- return this.proto.query;
16
- }
17
- get response() {
18
- return this.proto.response;
19
- }
20
- /**
21
- * Create History Query.
22
- */
23
- static createQuery(params) {
24
- const contentFilters = params.contentTopics.map((contentTopic) => {
25
- return { contentTopic };
26
- });
27
- const direction = directionToProto(params.pageDirection);
28
- const pagingInfo = {
29
- pageSize: BigInt(params.pageSize),
30
- cursor: params.cursor,
31
- direction
32
- };
33
- let startTime, endTime;
34
- if (params.startTime) {
35
- // milliseconds 10^-3 to nanoseconds 10^-9
36
- startTime = BigInt(params.startTime.valueOf()) * OneMillion;
37
- }
38
- if (params.endTime) {
39
- // milliseconds 10^-3 to nanoseconds 10^-9
40
- endTime = BigInt(params.endTime.valueOf()) * OneMillion;
41
- }
42
- return new HistoryRpc({
43
- requestId: uuid(),
44
- query: {
45
- pubsubTopic: params.pubsubTopic,
46
- contentFilters,
47
- pagingInfo,
48
- startTime,
49
- endTime
50
- },
51
- response: undefined
52
- });
53
- }
54
- decode(bytes) {
55
- const res = proto.HistoryRpc.decode(bytes);
56
- return new HistoryRpc(res);
57
- }
58
- encode() {
59
- return proto.HistoryRpc.encode(this.proto);
60
- }
61
- }
62
- function directionToProto(pageDirection) {
63
- switch (pageDirection) {
64
- case PageDirection.BACKWARD:
65
- return proto.PagingInfo.Direction.BACKWARD;
66
- case PageDirection.FORWARD:
67
- return proto.PagingInfo.Direction.FORWARD;
68
- default:
69
- return proto.PagingInfo.Direction.BACKWARD;
70
- }
71
- }
72
- //# sourceMappingURL=history_rpc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history_rpc.js","sourceRoot":"","sources":["../../../src/lib/store/history_rpc.ts"],"names":[],"mappings":"AAAA,O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,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;IACxE,CAAC;CACF"}
@@ -1,93 +0,0 @@
1
- import { proto_store as proto } from "@waku/proto";
2
- import type { Uint8ArrayList } from "uint8arraylist";
3
- import { v4 as uuid } from "uuid";
4
-
5
- const OneMillion = BigInt(1_000_000);
6
-
7
- export enum PageDirection {
8
- BACKWARD = "backward",
9
- FORWARD = "forward"
10
- }
11
-
12
- export interface Params {
13
- contentTopics: string[];
14
- pubsubTopic: string;
15
- pageDirection: PageDirection;
16
- pageSize: number;
17
- startTime?: Date;
18
- endTime?: Date;
19
- cursor?: proto.Index;
20
- }
21
-
22
- export class HistoryRpc {
23
- private constructor(public readonly proto: proto.HistoryRpc) {}
24
-
25
- get query(): proto.HistoryQuery | undefined {
26
- return this.proto.query;
27
- }
28
-
29
- get response(): proto.HistoryResponse | undefined {
30
- return this.proto.response;
31
- }
32
-
33
- /**
34
- * Create History Query.
35
- */
36
- static createQuery(params: Params): HistoryRpc {
37
- const contentFilters = params.contentTopics.map((contentTopic) => {
38
- return { contentTopic };
39
- });
40
-
41
- const direction = directionToProto(params.pageDirection);
42
-
43
- const pagingInfo = {
44
- pageSize: BigInt(params.pageSize),
45
- cursor: params.cursor,
46
- direction
47
- } as proto.PagingInfo;
48
-
49
- let startTime, endTime;
50
- if (params.startTime) {
51
- // milliseconds 10^-3 to nanoseconds 10^-9
52
- startTime = BigInt(params.startTime.valueOf()) * OneMillion;
53
- }
54
-
55
- if (params.endTime) {
56
- // milliseconds 10^-3 to nanoseconds 10^-9
57
- endTime = BigInt(params.endTime.valueOf()) * OneMillion;
58
- }
59
- return new HistoryRpc({
60
- requestId: uuid(),
61
- query: {
62
- pubsubTopic: params.pubsubTopic,
63
- contentFilters,
64
- pagingInfo,
65
- startTime,
66
- endTime
67
- },
68
- response: undefined
69
- });
70
- }
71
-
72
- decode(bytes: Uint8ArrayList): HistoryRpc {
73
- const res = proto.HistoryRpc.decode(bytes);
74
- return new HistoryRpc(res);
75
- }
76
-
77
- encode(): Uint8Array {
78
- return proto.HistoryRpc.encode(this.proto);
79
- }
80
- }
81
-
82
- function directionToProto(
83
- pageDirection: PageDirection
84
- ): proto.PagingInfo.Direction {
85
- switch (pageDirection) {
86
- case PageDirection.BACKWARD:
87
- return proto.PagingInfo.Direction.BACKWARD;
88
- case PageDirection.FORWARD:
89
- return proto.PagingInfo.Direction.FORWARD;
90
- default:
91
- return proto.PagingInfo.Direction.BACKWARD;
92
- }
93
- }