diff --git a/CHANGELOG.md b/CHANGELOG.md index 67e107ce43..c4e7a98877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- **Breaking**: Renamed `WakuStore.QueryOptions`'s `direction` to `pageDirection` (and its type) as it only affects the page ordering, + not the ordering of messages with the page. + ## [0.13.1] - 2021-09-21 ### Fixed diff --git a/examples/web-chat/src/App.tsx b/examples/web-chat/src/App.tsx index bebbe23cc5..bc4eaa9e8d 100644 --- a/examples/web-chat/src/App.tsx +++ b/examples/web-chat/src/App.tsx @@ -1,6 +1,6 @@ import { useEffect, useReducer, useState } from 'react'; import './App.css'; -import { Direction, getBootstrapNodes, Waku, WakuMessage } from 'js-waku'; +import { PageDirection, getBootstrapNodes, Waku, WakuMessage } from 'js-waku'; import handleCommand from './command'; import Room from './Room'; import { WakuContext } from './WakuContext'; @@ -64,7 +64,7 @@ async function retrieveStoreMessages( try { const res = await waku.store.queryHistory([ChatContentTopic], { pageSize: 5, - direction: Direction.FORWARD, + pageDirection: PageDirection.FORWARD, timeFilter: { startTime, endTime, diff --git a/src/index.ts b/src/index.ts index 69c667b160..324459c865 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,6 +20,6 @@ export { export { WakuRelay, RelayCodecs } from './lib/waku_relay'; -export { Direction, WakuStore, StoreCodec } from './lib/waku_store'; +export { PageDirection, WakuStore, StoreCodec } from './lib/waku_store'; export * as proto from './proto'; diff --git a/src/lib/waku_store/history_rpc.ts b/src/lib/waku_store/history_rpc.ts index cdf328fb57..2e2194c981 100644 --- a/src/lib/waku_store/history_rpc.ts +++ b/src/lib/waku_store/history_rpc.ts @@ -3,7 +3,7 @@ import { v4 as uuid } from 'uuid'; import * as proto from '../../proto/waku/v2/store'; -export enum Direction { +export enum PageDirection { BACKWARD = 'backward', FORWARD = 'forward', } @@ -11,7 +11,7 @@ export enum Direction { export interface Params { contentTopics: string[]; pubSubTopic: string; - direction: Direction; + pageDirection: PageDirection; pageSize: number; startTime?: number; endTime?: number; @@ -25,7 +25,7 @@ export class HistoryRPC { * Create History Query. */ static createQuery(params: Params): HistoryRPC { - const direction = directionToProto(params.direction); + const direction = directionToProto(params.pageDirection); const pagingInfo = { pageSize: params.pageSize, cursor: params.cursor, @@ -67,11 +67,13 @@ export class HistoryRPC { } } -function directionToProto(direction: Direction): proto.PagingInfo_Direction { - switch (direction) { - case Direction.BACKWARD: +function directionToProto( + pageDirection: PageDirection +): proto.PagingInfo_Direction { + switch (pageDirection) { + case PageDirection.BACKWARD: return proto.PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED; - case Direction.FORWARD: + case PageDirection.FORWARD: return proto.PagingInfo_Direction.DIRECTION_FORWARD; default: return proto.PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED; diff --git a/src/lib/waku_store/index.node.spec.ts b/src/lib/waku_store/index.node.spec.ts index b11daf570f..6fb739a0ac 100644 --- a/src/lib/waku_store/index.node.spec.ts +++ b/src/lib/waku_store/index.node.spec.ts @@ -19,7 +19,7 @@ import { getPublicKey, } from '../waku_message/version_1'; -import { Direction } from './history_rpc'; +import { PageDirection } from './history_rpc'; const dbg = debug('waku:test:store'); @@ -94,7 +94,7 @@ describe('Waku Store', () => { }); const messages = await waku.store.queryHistory([], { - direction: Direction.FORWARD, + pageDirection: PageDirection.FORWARD, }); expect(messages?.length).eq(15); diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index 1b2286186f..ffc197b166 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -12,13 +12,13 @@ import { hexToBuf } from '../utils'; import { DefaultPubSubTopic } from '../waku'; import { WakuMessage } from '../waku_message'; -import { Direction, HistoryRPC } from './history_rpc'; +import { HistoryRPC, PageDirection } from './history_rpc'; const dbg = debug('waku:store'); export const StoreCodec = '/vac/waku/store/2.0.0-beta3'; -export { Direction }; +export { PageDirection }; export interface CreateOptions { /** @@ -40,7 +40,7 @@ export interface TimeFilter { export interface QueryOptions { peerId?: PeerId; pubSubTopic?: string; - direction?: Direction; + pageDirection?: PageDirection; pageSize?: number; timeFilter?: TimeFilter; callback?: (messages: WakuMessage[]) => void; @@ -93,7 +93,7 @@ export class WakuStore { const opts = Object.assign( { pubSubTopic: this.pubSubTopic, - direction: Direction.BACKWARD, + pageDirection: PageDirection.BACKWARD, pageSize: 10, }, options,