Skip to content

Commit 967e6ff

Browse files
committed
chore!: update store.proto
Ref: https://github.com/vacp2p/waku
1 parent 5cf8ed2 commit 967e6ff

File tree

5 files changed

+85
-79
lines changed

5 files changed

+85
-79
lines changed

packages/core/src/lib/store/history_rpc.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface Params {
2020
}
2121

2222
export class HistoryRPC {
23-
private constructor(public readonly proto: proto.HistoryRPC) {}
23+
private constructor(public readonly proto: proto.HistoryRpc) {}
2424

2525
get query(): proto.HistoryQuery | undefined {
2626
return this.proto.query;
@@ -59,7 +59,7 @@ export class HistoryRPC {
5959
return new HistoryRPC({
6060
requestId: uuid(),
6161
query: {
62-
pubSubTopic: params.pubSubTopic,
62+
pubsubTopic: params.pubSubTopic,
6363
contentFilters,
6464
pagingInfo,
6565
startTime,
@@ -70,12 +70,12 @@ export class HistoryRPC {
7070
}
7171

7272
decode(bytes: Uint8ArrayList): HistoryRPC {
73-
const res = proto.HistoryRPC.decode(bytes);
73+
const res = proto.HistoryRpc.decode(bytes);
7474
return new HistoryRPC(res);
7575
}
7676

7777
encode(): Uint8Array {
78-
return proto.HistoryRPC.encode(this.proto);
78+
return proto.HistoryRpc.encode(this.proto);
7979
}
8080
}
8181

@@ -84,10 +84,10 @@ function directionToProto(
8484
): proto.PagingInfo.Direction {
8585
switch (pageDirection) {
8686
case PageDirection.BACKWARD:
87-
return proto.PagingInfo.Direction.DIRECTION_BACKWARD_UNSPECIFIED;
87+
return proto.PagingInfo.Direction.BACKWARD;
8888
case PageDirection.FORWARD:
89-
return proto.PagingInfo.Direction.DIRECTION_FORWARD;
89+
return proto.PagingInfo.Direction.FORWARD;
9090
default:
91-
return proto.PagingInfo.Direction.DIRECTION_BACKWARD_UNSPECIFIED;
91+
return proto.PagingInfo.Direction.BACKWARD;
9292
}
9393
}

packages/core/src/lib/store/index.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Cursor,
77
IDecodedMessage,
88
IDecoder,
9-
Index,
109
IStore,
1110
ProtocolCreateOptions,
1211
} from "@waku/interfaces";
@@ -294,10 +293,7 @@ async function* paginate<T extends IDecodedMessage>(
294293

295294
const response = reply.response as proto.HistoryResponse;
296295

297-
if (
298-
response.error &&
299-
response.error !== HistoryError.ERROR_NONE_UNSPECIFIED
300-
) {
296+
if (response.error && response.error !== HistoryError.NONE) {
301297
throw "History response contains an Error: " + response.error;
302298
}
303299

@@ -353,7 +349,7 @@ export function isDefined<T>(msg: T | undefined): msg is T {
353349
export async function createCursor(
354350
message: IDecodedMessage,
355351
pubsubTopic: string = DefaultPubSubTopic
356-
): Promise<Index> {
352+
): Promise<Cursor> {
357353
if (
358354
!message ||
359355
!message.timestamp ||
@@ -373,7 +369,7 @@ export async function createCursor(
373369
digest,
374370
pubsubTopic,
375371
senderTime: messageTime,
376-
receivedTime: messageTime,
372+
receiverTime: messageTime,
377373
};
378374
}
379375

packages/interfaces/src/store.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@ export interface TimeFilter {
1111
endTime: Date;
1212
}
1313

14-
export interface Index {
15-
digest?: Uint8Array;
16-
receivedTime?: bigint;
17-
senderTime?: bigint;
18-
pubsubTopic?: string;
14+
export interface Cursor {
15+
digest: Uint8Array;
16+
receiverTime: bigint;
17+
senderTime: bigint;
18+
pubsubTopic: string;
1919
}
2020

21-
export type Cursor = {
22-
digest?: Uint8Array;
23-
senderTime?: bigint;
24-
pubsubTopic?: string;
25-
};
26-
2721
export type StoreQueryOptions = {
2822
/**
2923
* The direction in which pages are retrieved:
@@ -45,7 +39,8 @@ export type StoreQueryOptions = {
4539
*/
4640
timeFilter?: TimeFilter;
4741
/**
48-
* Cursor as an index to start a query from.
42+
* Cursor as an index to start a query from. Must be generated from a Waku
43+
* Message.
4944
*/
5045
cursor?: Cursor;
5146
} & ProtocolOptions;

packages/proto/src/lib/store.proto

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
1+
// 13/WAKU2-STORE rfc: https://rfc.vac.dev/spec/13/
2+
// Protocol identifier: /vac/waku/store/2.0.0-beta4
3+
14
syntax = "proto3";
25

36
import "message.proto";
47

58
message Index {
6-
optional bytes digest = 1;
7-
optional sint64 received_time = 2;
8-
optional sint64 sender_time = 3;
9-
optional string pubsub_topic = 4;
9+
bytes digest = 1;
10+
sint64 receiver_time = 2;
11+
sint64 sender_time = 3;
12+
string pubsub_topic = 4;
1013
}
1114

1215
message PagingInfo {
1316
optional uint64 page_size = 1;
1417
optional Index cursor = 2;
1518
enum Direction {
16-
DIRECTION_BACKWARD_UNSPECIFIED = 0;
17-
DIRECTION_FORWARD = 1;
19+
BACKWARD = 0;
20+
FORWARD = 1;
1821
}
1922
optional Direction direction = 3;
2023
}
2124

2225
message ContentFilter {
23-
optional string content_topic = 1;
26+
string content_topic = 1;
2427
}
2528

2629
message HistoryQuery {
27-
optional string pub_sub_topic = 2;
30+
// The first field is reserved for future use
31+
optional string pubsub_topic = 2;
2832
repeated ContentFilter content_filters = 3;
2933
optional PagingInfo paging_info = 4;
3034
optional sint64 start_time = 5;
3135
optional sint64 end_time = 6;
3236
}
3337

3438
message HistoryResponse {
39+
// The first field is reserved for future use
3540
repeated WakuMessage messages = 2;
3641
optional PagingInfo paging_info = 3;
3742
enum HistoryError {
38-
ERROR_NONE_UNSPECIFIED = 0;
39-
ERROR_INVALID_CURSOR = 1;
43+
NONE = 0;
44+
INVALID_CURSOR = 1;
4045
}
41-
optional HistoryError error = 4;
46+
HistoryError error = 4;
4247
}
4348

44-
message HistoryRPC {
45-
optional string request_id = 1;
49+
message HistoryRpc {
50+
string request_id = 1;
4651
optional HistoryQuery query = 2;
4752
optional HistoryResponse response = 3;
4853
}

0 commit comments

Comments
 (0)