Rename to page direction

As the direction only affects the page ordering,
not the message ordering in the pages.
This commit is contained in:
Franck Royer 2021-10-04 12:21:13 +11:00
parent 087f5bf774
commit f5a0416efd
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
6 changed files with 22 additions and 16 deletions

View File

@ -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

View File

@ -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,

View File

@ -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';

View File

@ -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;

View File

@ -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);

View File

@ -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,