chore!: update store.proto

Ref: https://github.com/vacp2p/waku
This commit is contained in:
fryorcraken.eth 2023-02-24 23:58:25 +11:00
parent 5cf8ed2030
commit 967e6ffc7e
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
5 changed files with 85 additions and 79 deletions

View File

@ -20,7 +20,7 @@ export interface Params {
} }
export class HistoryRPC { export class HistoryRPC {
private constructor(public readonly proto: proto.HistoryRPC) {} private constructor(public readonly proto: proto.HistoryRpc) {}
get query(): proto.HistoryQuery | undefined { get query(): proto.HistoryQuery | undefined {
return this.proto.query; return this.proto.query;
@ -59,7 +59,7 @@ export class HistoryRPC {
return new HistoryRPC({ return new HistoryRPC({
requestId: uuid(), requestId: uuid(),
query: { query: {
pubSubTopic: params.pubSubTopic, pubsubTopic: params.pubSubTopic,
contentFilters, contentFilters,
pagingInfo, pagingInfo,
startTime, startTime,
@ -70,12 +70,12 @@ export class HistoryRPC {
} }
decode(bytes: Uint8ArrayList): HistoryRPC { decode(bytes: Uint8ArrayList): HistoryRPC {
const res = proto.HistoryRPC.decode(bytes); const res = proto.HistoryRpc.decode(bytes);
return new HistoryRPC(res); return new HistoryRPC(res);
} }
encode(): Uint8Array { encode(): Uint8Array {
return proto.HistoryRPC.encode(this.proto); return proto.HistoryRpc.encode(this.proto);
} }
} }
@ -84,10 +84,10 @@ function directionToProto(
): proto.PagingInfo.Direction { ): proto.PagingInfo.Direction {
switch (pageDirection) { switch (pageDirection) {
case PageDirection.BACKWARD: case PageDirection.BACKWARD:
return proto.PagingInfo.Direction.DIRECTION_BACKWARD_UNSPECIFIED; return proto.PagingInfo.Direction.BACKWARD;
case PageDirection.FORWARD: case PageDirection.FORWARD:
return proto.PagingInfo.Direction.DIRECTION_FORWARD; return proto.PagingInfo.Direction.FORWARD;
default: default:
return proto.PagingInfo.Direction.DIRECTION_BACKWARD_UNSPECIFIED; return proto.PagingInfo.Direction.BACKWARD;
} }
} }

View File

@ -6,7 +6,6 @@ import {
Cursor, Cursor,
IDecodedMessage, IDecodedMessage,
IDecoder, IDecoder,
Index,
IStore, IStore,
ProtocolCreateOptions, ProtocolCreateOptions,
} from "@waku/interfaces"; } from "@waku/interfaces";
@ -294,10 +293,7 @@ async function* paginate<T extends IDecodedMessage>(
const response = reply.response as proto.HistoryResponse; const response = reply.response as proto.HistoryResponse;
if ( if (response.error && response.error !== HistoryError.NONE) {
response.error &&
response.error !== HistoryError.ERROR_NONE_UNSPECIFIED
) {
throw "History response contains an Error: " + response.error; throw "History response contains an Error: " + response.error;
} }
@ -353,7 +349,7 @@ export function isDefined<T>(msg: T | undefined): msg is T {
export async function createCursor( export async function createCursor(
message: IDecodedMessage, message: IDecodedMessage,
pubsubTopic: string = DefaultPubSubTopic pubsubTopic: string = DefaultPubSubTopic
): Promise<Index> { ): Promise<Cursor> {
if ( if (
!message || !message ||
!message.timestamp || !message.timestamp ||
@ -373,7 +369,7 @@ export async function createCursor(
digest, digest,
pubsubTopic, pubsubTopic,
senderTime: messageTime, senderTime: messageTime,
receivedTime: messageTime, receiverTime: messageTime,
}; };
} }

View File

@ -11,19 +11,13 @@ export interface TimeFilter {
endTime: Date; endTime: Date;
} }
export interface Index { export interface Cursor {
digest?: Uint8Array; digest: Uint8Array;
receivedTime?: bigint; receiverTime: bigint;
senderTime?: bigint; senderTime: bigint;
pubsubTopic?: string; pubsubTopic: string;
} }
export type Cursor = {
digest?: Uint8Array;
senderTime?: bigint;
pubsubTopic?: string;
};
export type StoreQueryOptions = { export type StoreQueryOptions = {
/** /**
* The direction in which pages are retrieved: * The direction in which pages are retrieved:
@ -45,7 +39,8 @@ export type StoreQueryOptions = {
*/ */
timeFilter?: TimeFilter; timeFilter?: TimeFilter;
/** /**
* Cursor as an index to start a query from. * Cursor as an index to start a query from. Must be generated from a Waku
* Message.
*/ */
cursor?: Cursor; cursor?: Cursor;
} & ProtocolOptions; } & ProtocolOptions;

View File

@ -1,30 +1,34 @@
// 13/WAKU2-STORE rfc: https://rfc.vac.dev/spec/13/
// Protocol identifier: /vac/waku/store/2.0.0-beta4
syntax = "proto3"; syntax = "proto3";
import "message.proto"; import "message.proto";
message Index { message Index {
optional bytes digest = 1; bytes digest = 1;
optional sint64 received_time = 2; sint64 receiver_time = 2;
optional sint64 sender_time = 3; sint64 sender_time = 3;
optional string pubsub_topic = 4; string pubsub_topic = 4;
} }
message PagingInfo { message PagingInfo {
optional uint64 page_size = 1; optional uint64 page_size = 1;
optional Index cursor = 2; optional Index cursor = 2;
enum Direction { enum Direction {
DIRECTION_BACKWARD_UNSPECIFIED = 0; BACKWARD = 0;
DIRECTION_FORWARD = 1; FORWARD = 1;
} }
optional Direction direction = 3; optional Direction direction = 3;
} }
message ContentFilter { message ContentFilter {
optional string content_topic = 1; string content_topic = 1;
} }
message HistoryQuery { message HistoryQuery {
optional string pub_sub_topic = 2; // The first field is reserved for future use
optional string pubsub_topic = 2;
repeated ContentFilter content_filters = 3; repeated ContentFilter content_filters = 3;
optional PagingInfo paging_info = 4; optional PagingInfo paging_info = 4;
optional sint64 start_time = 5; optional sint64 start_time = 5;
@ -32,17 +36,18 @@ message HistoryQuery {
} }
message HistoryResponse { message HistoryResponse {
// The first field is reserved for future use
repeated WakuMessage messages = 2; repeated WakuMessage messages = 2;
optional PagingInfo paging_info = 3; optional PagingInfo paging_info = 3;
enum HistoryError { enum HistoryError {
ERROR_NONE_UNSPECIFIED = 0; NONE = 0;
ERROR_INVALID_CURSOR = 1; INVALID_CURSOR = 1;
} }
optional HistoryError error = 4; HistoryError error = 4;
} }
message HistoryRPC { message HistoryRpc {
optional string request_id = 1; string request_id = 1;
optional HistoryQuery query = 2; optional HistoryQuery query = 2;
optional HistoryResponse response = 3; optional HistoryResponse response = 3;
} }

View File

@ -14,10 +14,10 @@ import type { Codec } from "protons-runtime";
import type { Uint8ArrayList } from "uint8arraylist"; import type { Uint8ArrayList } from "uint8arraylist";
export interface Index { export interface Index {
digest?: Uint8Array; digest: Uint8Array;
receivedTime?: bigint; receiverTime: bigint;
senderTime?: bigint; senderTime: bigint;
pubsubTopic?: string; pubsubTopic: string;
} }
export namespace Index { export namespace Index {
@ -31,22 +31,22 @@ export namespace Index {
w.fork(); w.fork();
} }
if (obj.digest != null) { if (obj.digest != null && obj.digest.byteLength > 0) {
w.uint32(10); w.uint32(10);
w.bytes(obj.digest); w.bytes(obj.digest);
} }
if (obj.receivedTime != null) { if (obj.receiverTime != null && obj.receiverTime !== 0n) {
w.uint32(16); w.uint32(16);
w.sint64(obj.receivedTime); w.sint64(obj.receiverTime);
} }
if (obj.senderTime != null) { if (obj.senderTime != null && obj.senderTime !== 0n) {
w.uint32(24); w.uint32(24);
w.sint64(obj.senderTime); w.sint64(obj.senderTime);
} }
if (obj.pubsubTopic != null) { if (obj.pubsubTopic != null && obj.pubsubTopic !== "") {
w.uint32(34); w.uint32(34);
w.string(obj.pubsubTopic); w.string(obj.pubsubTopic);
} }
@ -56,7 +56,12 @@ export namespace Index {
} }
}, },
(reader, length) => { (reader, length) => {
const obj: any = {}; const obj: any = {
digest: new Uint8Array(0),
receiverTime: 0n,
senderTime: 0n,
pubsubTopic: "",
};
const end = length == null ? reader.len : reader.pos + length; const end = length == null ? reader.len : reader.pos + length;
@ -68,7 +73,7 @@ export namespace Index {
obj.digest = reader.bytes(); obj.digest = reader.bytes();
break; break;
case 2: case 2:
obj.receivedTime = reader.sint64(); obj.receiverTime = reader.sint64();
break; break;
case 3: case 3:
obj.senderTime = reader.sint64(); obj.senderTime = reader.sint64();
@ -107,13 +112,13 @@ export interface PagingInfo {
export namespace PagingInfo { export namespace PagingInfo {
export enum Direction { export enum Direction {
DIRECTION_BACKWARD_UNSPECIFIED = "DIRECTION_BACKWARD_UNSPECIFIED", BACKWARD = "BACKWARD",
DIRECTION_FORWARD = "DIRECTION_FORWARD", FORWARD = "FORWARD",
} }
enum __DirectionValues { enum __DirectionValues {
DIRECTION_BACKWARD_UNSPECIFIED = 0, BACKWARD = 0,
DIRECTION_FORWARD = 1, FORWARD = 1,
} }
export namespace Direction { export namespace Direction {
@ -193,7 +198,7 @@ export namespace PagingInfo {
} }
export interface ContentFilter { export interface ContentFilter {
contentTopic?: string; contentTopic: string;
} }
export namespace ContentFilter { export namespace ContentFilter {
@ -207,7 +212,7 @@ export namespace ContentFilter {
w.fork(); w.fork();
} }
if (obj.contentTopic != null) { if (obj.contentTopic != null && obj.contentTopic !== "") {
w.uint32(10); w.uint32(10);
w.string(obj.contentTopic); w.string(obj.contentTopic);
} }
@ -217,7 +222,9 @@ export namespace ContentFilter {
} }
}, },
(reader, length) => { (reader, length) => {
const obj: any = {}; const obj: any = {
contentTopic: "",
};
const end = length == null ? reader.len : reader.pos + length; const end = length == null ? reader.len : reader.pos + length;
@ -252,7 +259,7 @@ export namespace ContentFilter {
} }
export interface HistoryQuery { export interface HistoryQuery {
pubSubTopic?: string; pubsubTopic?: string;
contentFilters: ContentFilter[]; contentFilters: ContentFilter[];
pagingInfo?: PagingInfo; pagingInfo?: PagingInfo;
startTime?: bigint; startTime?: bigint;
@ -270,9 +277,9 @@ export namespace HistoryQuery {
w.fork(); w.fork();
} }
if (obj.pubSubTopic != null) { if (obj.pubsubTopic != null) {
w.uint32(18); w.uint32(18);
w.string(obj.pubSubTopic); w.string(obj.pubsubTopic);
} }
if (obj.contentFilters != null) { if (obj.contentFilters != null) {
@ -313,7 +320,7 @@ export namespace HistoryQuery {
switch (tag >>> 3) { switch (tag >>> 3) {
case 2: case 2:
obj.pubSubTopic = reader.string(); obj.pubsubTopic = reader.string();
break; break;
case 3: case 3:
obj.contentFilters.push( obj.contentFilters.push(
@ -358,18 +365,18 @@ export namespace HistoryQuery {
export interface HistoryResponse { export interface HistoryResponse {
messages: WakuMessage[]; messages: WakuMessage[];
pagingInfo?: PagingInfo; pagingInfo?: PagingInfo;
error?: HistoryResponse.HistoryError; error: HistoryResponse.HistoryError;
} }
export namespace HistoryResponse { export namespace HistoryResponse {
export enum HistoryError { export enum HistoryError {
ERROR_NONE_UNSPECIFIED = "ERROR_NONE_UNSPECIFIED", NONE = "NONE",
ERROR_INVALID_CURSOR = "ERROR_INVALID_CURSOR", INVALID_CURSOR = "INVALID_CURSOR",
} }
enum __HistoryErrorValues { enum __HistoryErrorValues {
ERROR_NONE_UNSPECIFIED = 0, NONE = 0,
ERROR_INVALID_CURSOR = 1, INVALID_CURSOR = 1,
} }
export namespace HistoryError { export namespace HistoryError {
@ -400,7 +407,7 @@ export namespace HistoryResponse {
PagingInfo.codec().encode(obj.pagingInfo, w); PagingInfo.codec().encode(obj.pagingInfo, w);
} }
if (obj.error != null) { if (obj.error != null && __HistoryErrorValues[obj.error] !== 0) {
w.uint32(32); w.uint32(32);
HistoryResponse.HistoryError.codec().encode(obj.error, w); HistoryResponse.HistoryError.codec().encode(obj.error, w);
} }
@ -412,6 +419,7 @@ export namespace HistoryResponse {
(reader, length) => { (reader, length) => {
const obj: any = { const obj: any = {
messages: [], messages: [],
error: HistoryError.NONE,
}; };
const end = length == null ? reader.len : reader.pos + length; const end = length == null ? reader.len : reader.pos + length;
@ -457,24 +465,24 @@ export namespace HistoryResponse {
}; };
} }
export interface HistoryRPC { export interface HistoryRpc {
requestId?: string; requestId: string;
query?: HistoryQuery; query?: HistoryQuery;
response?: HistoryResponse; response?: HistoryResponse;
} }
export namespace HistoryRPC { export namespace HistoryRpc {
let _codec: Codec<HistoryRPC>; let _codec: Codec<HistoryRpc>;
export const codec = (): Codec<HistoryRPC> => { export const codec = (): Codec<HistoryRpc> => {
if (_codec == null) { if (_codec == null) {
_codec = message<HistoryRPC>( _codec = message<HistoryRpc>(
(obj, w, opts = {}) => { (obj, w, opts = {}) => {
if (opts.lengthDelimited !== false) { if (opts.lengthDelimited !== false) {
w.fork(); w.fork();
} }
if (obj.requestId != null) { if (obj.requestId != null && obj.requestId !== "") {
w.uint32(10); w.uint32(10);
w.string(obj.requestId); w.string(obj.requestId);
} }
@ -494,7 +502,9 @@ export namespace HistoryRPC {
} }
}, },
(reader, length) => { (reader, length) => {
const obj: any = {}; const obj: any = {
requestId: "",
};
const end = length == null ? reader.len : reader.pos + length; const end = length == null ? reader.len : reader.pos + length;
@ -531,12 +541,12 @@ export namespace HistoryRPC {
return _codec; return _codec;
}; };
export const encode = (obj: Partial<HistoryRPC>): Uint8Array => { export const encode = (obj: Partial<HistoryRpc>): Uint8Array => {
return encodeMessage(obj, HistoryRPC.codec()); return encodeMessage(obj, HistoryRpc.codec());
}; };
export const decode = (buf: Uint8Array | Uint8ArrayList): HistoryRPC => { export const decode = (buf: Uint8Array | Uint8ArrayList): HistoryRpc => {
return decodeMessage(buf, HistoryRPC.codec()); return decodeMessage(buf, HistoryRpc.codec());
}; };
} }