@waku/core 0.0.31-1887f4f.0 → 0.0.31-88a29c3.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.
@@ -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
+ }
@@ -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,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE,MAA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O,EAAE,CAAC,GAAG,UAAU,CAAC;QAC1D,CAAC;QACD,OAAO,IAAI,UAAU,CAAC;YACpB,SAAS,EAAE,IAAI,EAAE;YACjB,KAAK,EAAE;gBACL,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,cAAc;gBACd,UAAU;gBACV,SAAS;gBACT,OAAO;aACR;YACD,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,KAAqB;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAEM,MAAM;QACX,OAAO,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;CACF;AAED,SAAS,gBAAgB,CACvB,aAA4B;IAE5B,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,aAAa,CAAC,QAAQ;YACzB,OAAO,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC;QAC7C,KAAK,aAAa,CAAC,OAAO;YACxB,OAAO,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC;QAC5C;YACE,OAAO,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC;IAC/C,CAAC;AACH,CAAC"}
@@ -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
- public get query(): proto.HistoryQuery | undefined {
26
- return this.proto.query;
27
- }
28
-
29
- public get response(): proto.HistoryResponse | undefined {
30
- return this.proto.response;
31
- }
32
-
33
- /**
34
- * Create History Query.
35
- */
36
- public 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
- public decode(bytes: Uint8ArrayList): HistoryRpc {
73
- const res = proto.HistoryRpc.decode(bytes);
74
- return new HistoryRpc(res);
75
- }
76
-
77
- public 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
- }