mirror of https://github.com/waku-org/js-waku.git
Merge #43
43: Improve chat cli setup UX r=D4nte a=D4nte Resolves #39 Co-authored-by: Franck Royer <franck@royer.one>
This commit is contained in:
commit
136cb1fb9e
|
@ -66,6 +66,14 @@ jobs:
|
|||
- name: install using npm ci
|
||||
uses: bahmutov/npm-install@v1
|
||||
|
||||
- name: Generate protobuf code
|
||||
run: npm run proto
|
||||
|
||||
- name: Check all protobuf code was committed
|
||||
shell: bash
|
||||
run: |
|
||||
[ $(git status --short --ignore-submodules|wc -l) -eq 0 ]
|
||||
|
||||
- name: build
|
||||
run: npm run build
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@ build
|
|||
node_modules
|
||||
test
|
||||
src/**.js
|
||||
src/gen
|
||||
coverage
|
||||
*.log
|
||||
yarn.lock
|
||||
src/proto/**/*.ts
|
||||
|
|
|
@ -57,8 +57,8 @@ it is not necessary in normal usage when you just connect to the fleet.
|
|||
To build and test this repository, you need:
|
||||
|
||||
- [Node.js & npm](https://nodejs.org/en/)
|
||||
- [bufbuild](https://github.com/bufbuild/buf)
|
||||
- [protoc](https://grpc.io/docs/protoc-installation/)
|
||||
- [bufbuild](https://github.com/bufbuild/buf) (only if changing protobuf files)
|
||||
- [protoc](https://grpc.io/docs/protoc-installation/) (only if changing protobuf files)
|
||||
|
||||
To ensure interoperability with [nim-waku](https://github.com/status-im/nim-waku/), some tests are run against a nim-waku node.
|
||||
This is why `nim-waku` is present as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules), which itself contain several submodules.
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
"keywords": [],
|
||||
"scripts": {
|
||||
"build": "run-s build:*",
|
||||
"build:1-proto": "buf generate",
|
||||
"build:main": "tsc -p tsconfig.json",
|
||||
"build:module": "tsc -p tsconfig.module.json",
|
||||
"fix": "run-s fix:*",
|
||||
|
@ -26,7 +25,9 @@
|
|||
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
||||
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
||||
"test:unit": "nyc --silent mocha --exit # TODO: Remove `--exit` and fix hanging processes",
|
||||
"test:lint-proto": "buf lint",
|
||||
"proto": "run-s proto:*",
|
||||
"proto:lint": "buf lint",
|
||||
"proto:build": "buf generate",
|
||||
"check-cli": "run-s test diff-integration-tests check-integration-tests",
|
||||
"check-integration-tests": "run-s check-integration-test:*",
|
||||
"diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'",
|
||||
|
|
|
@ -31,12 +31,17 @@ const ChatContentTopic = 'dingpu';
|
|||
output: process.stdout,
|
||||
});
|
||||
|
||||
let nick = 'js-waku';
|
||||
try {
|
||||
const question = util.promisify(rl.question).bind(rl);
|
||||
// Looks like wrong type definition of promisify is picked.
|
||||
// May be related to https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20497
|
||||
const nick = ((await question(
|
||||
nick = ((await question(
|
||||
'Please choose a nickname: '
|
||||
)) as unknown) as string;
|
||||
} catch (e) {
|
||||
console.log('Using default nick.');
|
||||
}
|
||||
|
||||
console.log(`Hi, ${nick}!`);
|
||||
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
/* eslint-disable */
|
||||
import Long from 'long';
|
||||
import _m0 from 'protobufjs/minimal';
|
||||
|
||||
export const protobufPackage = 'chat.v2';
|
||||
|
||||
export interface ChatMessageProto {
|
||||
timestamp: number;
|
||||
nick: string;
|
||||
payload: Uint8Array;
|
||||
}
|
||||
|
||||
const baseChatMessageProto: object = { timestamp: 0, nick: '' };
|
||||
|
||||
export const ChatMessageProto = {
|
||||
encode(
|
||||
message: ChatMessageProto,
|
||||
writer: _m0.Writer = _m0.Writer.create()
|
||||
): _m0.Writer {
|
||||
if (message.timestamp !== 0) {
|
||||
writer.uint32(8).uint64(message.timestamp);
|
||||
}
|
||||
if (message.nick !== '') {
|
||||
writer.uint32(18).string(message.nick);
|
||||
}
|
||||
if (message.payload.length !== 0) {
|
||||
writer.uint32(26).bytes(message.payload);
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): ChatMessageProto {
|
||||
const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input;
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = { ...baseChatMessageProto } as ChatMessageProto;
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.timestamp = longToNumber(reader.uint64() as Long);
|
||||
break;
|
||||
case 2:
|
||||
message.nick = reader.string();
|
||||
break;
|
||||
case 3:
|
||||
message.payload = reader.bytes();
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
fromJSON(object: any): ChatMessageProto {
|
||||
const message = { ...baseChatMessageProto } as ChatMessageProto;
|
||||
if (object.timestamp !== undefined && object.timestamp !== null) {
|
||||
message.timestamp = Number(object.timestamp);
|
||||
} else {
|
||||
message.timestamp = 0;
|
||||
}
|
||||
if (object.nick !== undefined && object.nick !== null) {
|
||||
message.nick = String(object.nick);
|
||||
} else {
|
||||
message.nick = '';
|
||||
}
|
||||
if (object.payload !== undefined && object.payload !== null) {
|
||||
message.payload = bytesFromBase64(object.payload);
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
toJSON(message: ChatMessageProto): unknown {
|
||||
const obj: any = {};
|
||||
message.timestamp !== undefined && (obj.timestamp = message.timestamp);
|
||||
message.nick !== undefined && (obj.nick = message.nick);
|
||||
message.payload !== undefined &&
|
||||
(obj.payload = base64FromBytes(
|
||||
message.payload !== undefined ? message.payload : new Uint8Array()
|
||||
));
|
||||
return obj;
|
||||
},
|
||||
|
||||
fromPartial(object: DeepPartial<ChatMessageProto>): ChatMessageProto {
|
||||
const message = { ...baseChatMessageProto } as ChatMessageProto;
|
||||
if (object.timestamp !== undefined && object.timestamp !== null) {
|
||||
message.timestamp = object.timestamp;
|
||||
} else {
|
||||
message.timestamp = 0;
|
||||
}
|
||||
if (object.nick !== undefined && object.nick !== null) {
|
||||
message.nick = object.nick;
|
||||
} else {
|
||||
message.nick = '';
|
||||
}
|
||||
if (object.payload !== undefined && object.payload !== null) {
|
||||
message.payload = object.payload;
|
||||
} else {
|
||||
message.payload = new Uint8Array();
|
||||
}
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
||||
declare var self: any | undefined;
|
||||
declare var window: any | undefined;
|
||||
var globalThis: any = (() => {
|
||||
if (typeof globalThis !== 'undefined') return globalThis;
|
||||
if (typeof self !== 'undefined') return self;
|
||||
if (typeof window !== 'undefined') return window;
|
||||
if (typeof global !== 'undefined') return global;
|
||||
throw 'Unable to locate global object';
|
||||
})();
|
||||
|
||||
const atob: (b64: string) => string =
|
||||
globalThis.atob ||
|
||||
((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
|
||||
function bytesFromBase64(b64: string): Uint8Array {
|
||||
const bin = atob(b64);
|
||||
const arr = new Uint8Array(bin.length);
|
||||
for (let i = 0; i < bin.length; ++i) {
|
||||
arr[i] = bin.charCodeAt(i);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
const btoa: (bin: string) => string =
|
||||
globalThis.btoa ||
|
||||
((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
|
||||
function base64FromBytes(arr: Uint8Array): string {
|
||||
const bin: string[] = [];
|
||||
for (let i = 0; i < arr.byteLength; ++i) {
|
||||
bin.push(String.fromCharCode(arr[i]));
|
||||
}
|
||||
return btoa(bin.join(''));
|
||||
}
|
||||
|
||||
type Builtin = Date | Function | Uint8Array | string | number | undefined;
|
||||
export type DeepPartial<T> = T extends Builtin
|
||||
? T
|
||||
: T extends Array<infer U>
|
||||
? Array<DeepPartial<U>>
|
||||
: T extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<DeepPartial<U>>
|
||||
: T extends {}
|
||||
? { [K in keyof T]?: DeepPartial<T[K]> }
|
||||
: Partial<T>;
|
||||
|
||||
function longToNumber(long: Long): number {
|
||||
if (long.gt(Number.MAX_SAFE_INTEGER)) {
|
||||
throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
|
||||
}
|
||||
return long.toNumber();
|
||||
}
|
||||
|
||||
if (_m0.util.Long !== Long) {
|
||||
_m0.util.Long = Long as any;
|
||||
_m0.configure();
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
/* eslint-disable */
|
||||
import _m0 from 'protobufjs/minimal';
|
||||
|
||||
export const protobufPackage = 'waku.v2';
|
||||
|
||||
export interface WakuMessageProto {
|
||||
payload?: Uint8Array | undefined;
|
||||
contentTopic?: string | undefined;
|
||||
version?: number | undefined;
|
||||
timestamp?: number | undefined;
|
||||
}
|
||||
|
||||
const baseWakuMessageProto: object = {};
|
||||
|
||||
export const WakuMessageProto = {
|
||||
encode(
|
||||
message: WakuMessageProto,
|
||||
writer: _m0.Writer = _m0.Writer.create()
|
||||
): _m0.Writer {
|
||||
if (message.payload !== undefined) {
|
||||
writer.uint32(10).bytes(message.payload);
|
||||
}
|
||||
if (message.contentTopic !== undefined) {
|
||||
writer.uint32(18).string(message.contentTopic);
|
||||
}
|
||||
if (message.version !== undefined) {
|
||||
writer.uint32(24).uint32(message.version);
|
||||
}
|
||||
if (message.timestamp !== undefined) {
|
||||
writer.uint32(33).double(message.timestamp);
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): WakuMessageProto {
|
||||
const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input;
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = { ...baseWakuMessageProto } as WakuMessageProto;
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.payload = reader.bytes();
|
||||
break;
|
||||
case 2:
|
||||
message.contentTopic = reader.string();
|
||||
break;
|
||||
case 3:
|
||||
message.version = reader.uint32();
|
||||
break;
|
||||
case 4:
|
||||
message.timestamp = reader.double();
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
fromJSON(object: any): WakuMessageProto {
|
||||
const message = { ...baseWakuMessageProto } as WakuMessageProto;
|
||||
if (object.payload !== undefined && object.payload !== null) {
|
||||
message.payload = bytesFromBase64(object.payload);
|
||||
}
|
||||
if (object.contentTopic !== undefined && object.contentTopic !== null) {
|
||||
message.contentTopic = String(object.contentTopic);
|
||||
} else {
|
||||
message.contentTopic = undefined;
|
||||
}
|
||||
if (object.version !== undefined && object.version !== null) {
|
||||
message.version = Number(object.version);
|
||||
} else {
|
||||
message.version = undefined;
|
||||
}
|
||||
if (object.timestamp !== undefined && object.timestamp !== null) {
|
||||
message.timestamp = Number(object.timestamp);
|
||||
} else {
|
||||
message.timestamp = undefined;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
toJSON(message: WakuMessageProto): unknown {
|
||||
const obj: any = {};
|
||||
message.payload !== undefined &&
|
||||
(obj.payload =
|
||||
message.payload !== undefined
|
||||
? base64FromBytes(message.payload)
|
||||
: undefined);
|
||||
message.contentTopic !== undefined &&
|
||||
(obj.contentTopic = message.contentTopic);
|
||||
message.version !== undefined && (obj.version = message.version);
|
||||
message.timestamp !== undefined && (obj.timestamp = message.timestamp);
|
||||
return obj;
|
||||
},
|
||||
|
||||
fromPartial(object: DeepPartial<WakuMessageProto>): WakuMessageProto {
|
||||
const message = { ...baseWakuMessageProto } as WakuMessageProto;
|
||||
if (object.payload !== undefined && object.payload !== null) {
|
||||
message.payload = object.payload;
|
||||
} else {
|
||||
message.payload = undefined;
|
||||
}
|
||||
if (object.contentTopic !== undefined && object.contentTopic !== null) {
|
||||
message.contentTopic = object.contentTopic;
|
||||
} else {
|
||||
message.contentTopic = undefined;
|
||||
}
|
||||
if (object.version !== undefined && object.version !== null) {
|
||||
message.version = object.version;
|
||||
} else {
|
||||
message.version = undefined;
|
||||
}
|
||||
if (object.timestamp !== undefined && object.timestamp !== null) {
|
||||
message.timestamp = object.timestamp;
|
||||
} else {
|
||||
message.timestamp = undefined;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
||||
declare var self: any | undefined;
|
||||
declare var window: any | undefined;
|
||||
var globalThis: any = (() => {
|
||||
if (typeof globalThis !== 'undefined') return globalThis;
|
||||
if (typeof self !== 'undefined') return self;
|
||||
if (typeof window !== 'undefined') return window;
|
||||
if (typeof global !== 'undefined') return global;
|
||||
throw 'Unable to locate global object';
|
||||
})();
|
||||
|
||||
const atob: (b64: string) => string =
|
||||
globalThis.atob ||
|
||||
((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
|
||||
function bytesFromBase64(b64: string): Uint8Array {
|
||||
const bin = atob(b64);
|
||||
const arr = new Uint8Array(bin.length);
|
||||
for (let i = 0; i < bin.length; ++i) {
|
||||
arr[i] = bin.charCodeAt(i);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
const btoa: (bin: string) => string =
|
||||
globalThis.btoa ||
|
||||
((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
|
||||
function base64FromBytes(arr: Uint8Array): string {
|
||||
const bin: string[] = [];
|
||||
for (let i = 0; i < arr.byteLength; ++i) {
|
||||
bin.push(String.fromCharCode(arr[i]));
|
||||
}
|
||||
return btoa(bin.join(''));
|
||||
}
|
||||
|
||||
type Builtin = Date | Function | Uint8Array | string | number | undefined;
|
||||
export type DeepPartial<T> = T extends Builtin
|
||||
? T
|
||||
: T extends Array<infer U>
|
||||
? Array<DeepPartial<U>>
|
||||
: T extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<DeepPartial<U>>
|
||||
: T extends {}
|
||||
? { [K in keyof T]?: DeepPartial<T[K]> }
|
||||
: Partial<T>;
|
|
@ -0,0 +1,600 @@
|
|||
/* eslint-disable */
|
||||
import Long from 'long';
|
||||
import { WakuMessageProto } from '../../waku/v2/message';
|
||||
import _m0 from 'protobufjs/minimal';
|
||||
|
||||
export const protobufPackage = 'waku.v2';
|
||||
|
||||
export enum Direction {
|
||||
DIRECTION_BACKWARD_UNSPECIFIED = 0,
|
||||
DIRECTION_FORWARD = 1,
|
||||
UNRECOGNIZED = -1,
|
||||
}
|
||||
|
||||
export function directionFromJSON(object: any): Direction {
|
||||
switch (object) {
|
||||
case 0:
|
||||
case 'DIRECTION_BACKWARD_UNSPECIFIED':
|
||||
return Direction.DIRECTION_BACKWARD_UNSPECIFIED;
|
||||
case 1:
|
||||
case 'DIRECTION_FORWARD':
|
||||
return Direction.DIRECTION_FORWARD;
|
||||
case -1:
|
||||
case 'UNRECOGNIZED':
|
||||
default:
|
||||
return Direction.UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
export function directionToJSON(object: Direction): string {
|
||||
switch (object) {
|
||||
case Direction.DIRECTION_BACKWARD_UNSPECIFIED:
|
||||
return 'DIRECTION_BACKWARD_UNSPECIFIED';
|
||||
case Direction.DIRECTION_FORWARD:
|
||||
return 'DIRECTION_FORWARD';
|
||||
default:
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
|
||||
export interface Index {
|
||||
digest: Uint8Array;
|
||||
receivedTime: number;
|
||||
}
|
||||
|
||||
export interface PagingInfo {
|
||||
pageSize: number;
|
||||
cursor: Index | undefined;
|
||||
direction: Direction;
|
||||
}
|
||||
|
||||
export interface HistoryQuery {
|
||||
topics: string[];
|
||||
pagingInfo?: PagingInfo | undefined;
|
||||
startTime?: number | undefined;
|
||||
endTime?: number | undefined;
|
||||
}
|
||||
|
||||
export interface HistoryResponse {
|
||||
messages: WakuMessageProto[];
|
||||
pagingInfo: PagingInfo | undefined;
|
||||
}
|
||||
|
||||
export interface HistoryRPC {
|
||||
requestId: string;
|
||||
query: HistoryQuery | undefined;
|
||||
response: HistoryResponse | undefined;
|
||||
}
|
||||
|
||||
const baseIndex: object = { receivedTime: 0 };
|
||||
|
||||
export const Index = {
|
||||
encode(message: Index, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
|
||||
if (message.digest.length !== 0) {
|
||||
writer.uint32(10).bytes(message.digest);
|
||||
}
|
||||
if (message.receivedTime !== 0) {
|
||||
writer.uint32(17).double(message.receivedTime);
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): Index {
|
||||
const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input;
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = { ...baseIndex } as Index;
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.digest = reader.bytes();
|
||||
break;
|
||||
case 2:
|
||||
message.receivedTime = reader.double();
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
fromJSON(object: any): Index {
|
||||
const message = { ...baseIndex } as Index;
|
||||
if (object.digest !== undefined && object.digest !== null) {
|
||||
message.digest = bytesFromBase64(object.digest);
|
||||
}
|
||||
if (object.receivedTime !== undefined && object.receivedTime !== null) {
|
||||
message.receivedTime = Number(object.receivedTime);
|
||||
} else {
|
||||
message.receivedTime = 0;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
toJSON(message: Index): unknown {
|
||||
const obj: any = {};
|
||||
message.digest !== undefined &&
|
||||
(obj.digest = base64FromBytes(
|
||||
message.digest !== undefined ? message.digest : new Uint8Array()
|
||||
));
|
||||
message.receivedTime !== undefined &&
|
||||
(obj.receivedTime = message.receivedTime);
|
||||
return obj;
|
||||
},
|
||||
|
||||
fromPartial(object: DeepPartial<Index>): Index {
|
||||
const message = { ...baseIndex } as Index;
|
||||
if (object.digest !== undefined && object.digest !== null) {
|
||||
message.digest = object.digest;
|
||||
} else {
|
||||
message.digest = new Uint8Array();
|
||||
}
|
||||
if (object.receivedTime !== undefined && object.receivedTime !== null) {
|
||||
message.receivedTime = object.receivedTime;
|
||||
} else {
|
||||
message.receivedTime = 0;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
||||
const basePagingInfo: object = { pageSize: 0, direction: 0 };
|
||||
|
||||
export const PagingInfo = {
|
||||
encode(
|
||||
message: PagingInfo,
|
||||
writer: _m0.Writer = _m0.Writer.create()
|
||||
): _m0.Writer {
|
||||
if (message.pageSize !== 0) {
|
||||
writer.uint32(8).uint64(message.pageSize);
|
||||
}
|
||||
if (message.cursor !== undefined) {
|
||||
Index.encode(message.cursor, writer.uint32(18).fork()).ldelim();
|
||||
}
|
||||
if (message.direction !== 0) {
|
||||
writer.uint32(24).int32(message.direction);
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): PagingInfo {
|
||||
const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input;
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = { ...basePagingInfo } as PagingInfo;
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.pageSize = longToNumber(reader.uint64() as Long);
|
||||
break;
|
||||
case 2:
|
||||
message.cursor = Index.decode(reader, reader.uint32());
|
||||
break;
|
||||
case 3:
|
||||
message.direction = reader.int32() as any;
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
fromJSON(object: any): PagingInfo {
|
||||
const message = { ...basePagingInfo } as PagingInfo;
|
||||
if (object.pageSize !== undefined && object.pageSize !== null) {
|
||||
message.pageSize = Number(object.pageSize);
|
||||
} else {
|
||||
message.pageSize = 0;
|
||||
}
|
||||
if (object.cursor !== undefined && object.cursor !== null) {
|
||||
message.cursor = Index.fromJSON(object.cursor);
|
||||
} else {
|
||||
message.cursor = undefined;
|
||||
}
|
||||
if (object.direction !== undefined && object.direction !== null) {
|
||||
message.direction = directionFromJSON(object.direction);
|
||||
} else {
|
||||
message.direction = 0;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
toJSON(message: PagingInfo): unknown {
|
||||
const obj: any = {};
|
||||
message.pageSize !== undefined && (obj.pageSize = message.pageSize);
|
||||
message.cursor !== undefined &&
|
||||
(obj.cursor = message.cursor ? Index.toJSON(message.cursor) : undefined);
|
||||
message.direction !== undefined &&
|
||||
(obj.direction = directionToJSON(message.direction));
|
||||
return obj;
|
||||
},
|
||||
|
||||
fromPartial(object: DeepPartial<PagingInfo>): PagingInfo {
|
||||
const message = { ...basePagingInfo } as PagingInfo;
|
||||
if (object.pageSize !== undefined && object.pageSize !== null) {
|
||||
message.pageSize = object.pageSize;
|
||||
} else {
|
||||
message.pageSize = 0;
|
||||
}
|
||||
if (object.cursor !== undefined && object.cursor !== null) {
|
||||
message.cursor = Index.fromPartial(object.cursor);
|
||||
} else {
|
||||
message.cursor = undefined;
|
||||
}
|
||||
if (object.direction !== undefined && object.direction !== null) {
|
||||
message.direction = object.direction;
|
||||
} else {
|
||||
message.direction = 0;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
||||
const baseHistoryQuery: object = { topics: '' };
|
||||
|
||||
export const HistoryQuery = {
|
||||
encode(
|
||||
message: HistoryQuery,
|
||||
writer: _m0.Writer = _m0.Writer.create()
|
||||
): _m0.Writer {
|
||||
for (const v of message.topics) {
|
||||
writer.uint32(18).string(v!);
|
||||
}
|
||||
if (message.pagingInfo !== undefined) {
|
||||
PagingInfo.encode(message.pagingInfo, writer.uint32(26).fork()).ldelim();
|
||||
}
|
||||
if (message.startTime !== undefined) {
|
||||
writer.uint32(33).double(message.startTime);
|
||||
}
|
||||
if (message.endTime !== undefined) {
|
||||
writer.uint32(41).double(message.endTime);
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): HistoryQuery {
|
||||
const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input;
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = { ...baseHistoryQuery } as HistoryQuery;
|
||||
message.topics = [];
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 2:
|
||||
message.topics.push(reader.string());
|
||||
break;
|
||||
case 3:
|
||||
message.pagingInfo = PagingInfo.decode(reader, reader.uint32());
|
||||
break;
|
||||
case 4:
|
||||
message.startTime = reader.double();
|
||||
break;
|
||||
case 5:
|
||||
message.endTime = reader.double();
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
fromJSON(object: any): HistoryQuery {
|
||||
const message = { ...baseHistoryQuery } as HistoryQuery;
|
||||
message.topics = [];
|
||||
if (object.topics !== undefined && object.topics !== null) {
|
||||
for (const e of object.topics) {
|
||||
message.topics.push(String(e));
|
||||
}
|
||||
}
|
||||
if (object.pagingInfo !== undefined && object.pagingInfo !== null) {
|
||||
message.pagingInfo = PagingInfo.fromJSON(object.pagingInfo);
|
||||
} else {
|
||||
message.pagingInfo = undefined;
|
||||
}
|
||||
if (object.startTime !== undefined && object.startTime !== null) {
|
||||
message.startTime = Number(object.startTime);
|
||||
} else {
|
||||
message.startTime = undefined;
|
||||
}
|
||||
if (object.endTime !== undefined && object.endTime !== null) {
|
||||
message.endTime = Number(object.endTime);
|
||||
} else {
|
||||
message.endTime = undefined;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
toJSON(message: HistoryQuery): unknown {
|
||||
const obj: any = {};
|
||||
if (message.topics) {
|
||||
obj.topics = message.topics.map((e) => e);
|
||||
} else {
|
||||
obj.topics = [];
|
||||
}
|
||||
message.pagingInfo !== undefined &&
|
||||
(obj.pagingInfo = message.pagingInfo
|
||||
? PagingInfo.toJSON(message.pagingInfo)
|
||||
: undefined);
|
||||
message.startTime !== undefined && (obj.startTime = message.startTime);
|
||||
message.endTime !== undefined && (obj.endTime = message.endTime);
|
||||
return obj;
|
||||
},
|
||||
|
||||
fromPartial(object: DeepPartial<HistoryQuery>): HistoryQuery {
|
||||
const message = { ...baseHistoryQuery } as HistoryQuery;
|
||||
message.topics = [];
|
||||
if (object.topics !== undefined && object.topics !== null) {
|
||||
for (const e of object.topics) {
|
||||
message.topics.push(e);
|
||||
}
|
||||
}
|
||||
if (object.pagingInfo !== undefined && object.pagingInfo !== null) {
|
||||
message.pagingInfo = PagingInfo.fromPartial(object.pagingInfo);
|
||||
} else {
|
||||
message.pagingInfo = undefined;
|
||||
}
|
||||
if (object.startTime !== undefined && object.startTime !== null) {
|
||||
message.startTime = object.startTime;
|
||||
} else {
|
||||
message.startTime = undefined;
|
||||
}
|
||||
if (object.endTime !== undefined && object.endTime !== null) {
|
||||
message.endTime = object.endTime;
|
||||
} else {
|
||||
message.endTime = undefined;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
||||
const baseHistoryResponse: object = {};
|
||||
|
||||
export const HistoryResponse = {
|
||||
encode(
|
||||
message: HistoryResponse,
|
||||
writer: _m0.Writer = _m0.Writer.create()
|
||||
): _m0.Writer {
|
||||
for (const v of message.messages) {
|
||||
WakuMessageProto.encode(v!, writer.uint32(10).fork()).ldelim();
|
||||
}
|
||||
if (message.pagingInfo !== undefined) {
|
||||
PagingInfo.encode(message.pagingInfo, writer.uint32(18).fork()).ldelim();
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): HistoryResponse {
|
||||
const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input;
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = { ...baseHistoryResponse } as HistoryResponse;
|
||||
message.messages = [];
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.messages.push(
|
||||
WakuMessageProto.decode(reader, reader.uint32())
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
message.pagingInfo = PagingInfo.decode(reader, reader.uint32());
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
fromJSON(object: any): HistoryResponse {
|
||||
const message = { ...baseHistoryResponse } as HistoryResponse;
|
||||
message.messages = [];
|
||||
if (object.messages !== undefined && object.messages !== null) {
|
||||
for (const e of object.messages) {
|
||||
message.messages.push(WakuMessageProto.fromJSON(e));
|
||||
}
|
||||
}
|
||||
if (object.pagingInfo !== undefined && object.pagingInfo !== null) {
|
||||
message.pagingInfo = PagingInfo.fromJSON(object.pagingInfo);
|
||||
} else {
|
||||
message.pagingInfo = undefined;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
toJSON(message: HistoryResponse): unknown {
|
||||
const obj: any = {};
|
||||
if (message.messages) {
|
||||
obj.messages = message.messages.map((e) =>
|
||||
e ? WakuMessageProto.toJSON(e) : undefined
|
||||
);
|
||||
} else {
|
||||
obj.messages = [];
|
||||
}
|
||||
message.pagingInfo !== undefined &&
|
||||
(obj.pagingInfo = message.pagingInfo
|
||||
? PagingInfo.toJSON(message.pagingInfo)
|
||||
: undefined);
|
||||
return obj;
|
||||
},
|
||||
|
||||
fromPartial(object: DeepPartial<HistoryResponse>): HistoryResponse {
|
||||
const message = { ...baseHistoryResponse } as HistoryResponse;
|
||||
message.messages = [];
|
||||
if (object.messages !== undefined && object.messages !== null) {
|
||||
for (const e of object.messages) {
|
||||
message.messages.push(WakuMessageProto.fromPartial(e));
|
||||
}
|
||||
}
|
||||
if (object.pagingInfo !== undefined && object.pagingInfo !== null) {
|
||||
message.pagingInfo = PagingInfo.fromPartial(object.pagingInfo);
|
||||
} else {
|
||||
message.pagingInfo = undefined;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
||||
const baseHistoryRPC: object = { requestId: '' };
|
||||
|
||||
export const HistoryRPC = {
|
||||
encode(
|
||||
message: HistoryRPC,
|
||||
writer: _m0.Writer = _m0.Writer.create()
|
||||
): _m0.Writer {
|
||||
if (message.requestId !== '') {
|
||||
writer.uint32(10).string(message.requestId);
|
||||
}
|
||||
if (message.query !== undefined) {
|
||||
HistoryQuery.encode(message.query, writer.uint32(18).fork()).ldelim();
|
||||
}
|
||||
if (message.response !== undefined) {
|
||||
HistoryResponse.encode(
|
||||
message.response,
|
||||
writer.uint32(26).fork()
|
||||
).ldelim();
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
|
||||
decode(input: _m0.Reader | Uint8Array, length?: number): HistoryRPC {
|
||||
const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input;
|
||||
let end = length === undefined ? reader.len : reader.pos + length;
|
||||
const message = { ...baseHistoryRPC } as HistoryRPC;
|
||||
while (reader.pos < end) {
|
||||
const tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.requestId = reader.string();
|
||||
break;
|
||||
case 2:
|
||||
message.query = HistoryQuery.decode(reader, reader.uint32());
|
||||
break;
|
||||
case 3:
|
||||
message.response = HistoryResponse.decode(reader, reader.uint32());
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
fromJSON(object: any): HistoryRPC {
|
||||
const message = { ...baseHistoryRPC } as HistoryRPC;
|
||||
if (object.requestId !== undefined && object.requestId !== null) {
|
||||
message.requestId = String(object.requestId);
|
||||
} else {
|
||||
message.requestId = '';
|
||||
}
|
||||
if (object.query !== undefined && object.query !== null) {
|
||||
message.query = HistoryQuery.fromJSON(object.query);
|
||||
} else {
|
||||
message.query = undefined;
|
||||
}
|
||||
if (object.response !== undefined && object.response !== null) {
|
||||
message.response = HistoryResponse.fromJSON(object.response);
|
||||
} else {
|
||||
message.response = undefined;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
toJSON(message: HistoryRPC): unknown {
|
||||
const obj: any = {};
|
||||
message.requestId !== undefined && (obj.requestId = message.requestId);
|
||||
message.query !== undefined &&
|
||||
(obj.query = message.query
|
||||
? HistoryQuery.toJSON(message.query)
|
||||
: undefined);
|
||||
message.response !== undefined &&
|
||||
(obj.response = message.response
|
||||
? HistoryResponse.toJSON(message.response)
|
||||
: undefined);
|
||||
return obj;
|
||||
},
|
||||
|
||||
fromPartial(object: DeepPartial<HistoryRPC>): HistoryRPC {
|
||||
const message = { ...baseHistoryRPC } as HistoryRPC;
|
||||
if (object.requestId !== undefined && object.requestId !== null) {
|
||||
message.requestId = object.requestId;
|
||||
} else {
|
||||
message.requestId = '';
|
||||
}
|
||||
if (object.query !== undefined && object.query !== null) {
|
||||
message.query = HistoryQuery.fromPartial(object.query);
|
||||
} else {
|
||||
message.query = undefined;
|
||||
}
|
||||
if (object.response !== undefined && object.response !== null) {
|
||||
message.response = HistoryResponse.fromPartial(object.response);
|
||||
} else {
|
||||
message.response = undefined;
|
||||
}
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
||||
declare var self: any | undefined;
|
||||
declare var window: any | undefined;
|
||||
var globalThis: any = (() => {
|
||||
if (typeof globalThis !== 'undefined') return globalThis;
|
||||
if (typeof self !== 'undefined') return self;
|
||||
if (typeof window !== 'undefined') return window;
|
||||
if (typeof global !== 'undefined') return global;
|
||||
throw 'Unable to locate global object';
|
||||
})();
|
||||
|
||||
const atob: (b64: string) => string =
|
||||
globalThis.atob ||
|
||||
((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
|
||||
function bytesFromBase64(b64: string): Uint8Array {
|
||||
const bin = atob(b64);
|
||||
const arr = new Uint8Array(bin.length);
|
||||
for (let i = 0; i < bin.length; ++i) {
|
||||
arr[i] = bin.charCodeAt(i);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
const btoa: (bin: string) => string =
|
||||
globalThis.btoa ||
|
||||
((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
|
||||
function base64FromBytes(arr: Uint8Array): string {
|
||||
const bin: string[] = [];
|
||||
for (let i = 0; i < arr.byteLength; ++i) {
|
||||
bin.push(String.fromCharCode(arr[i]));
|
||||
}
|
||||
return btoa(bin.join(''));
|
||||
}
|
||||
|
||||
type Builtin = Date | Function | Uint8Array | string | number | undefined;
|
||||
export type DeepPartial<T> = T extends Builtin
|
||||
? T
|
||||
: T extends Array<infer U>
|
||||
? Array<DeepPartial<U>>
|
||||
: T extends ReadonlyArray<infer U>
|
||||
? ReadonlyArray<DeepPartial<U>>
|
||||
: T extends {}
|
||||
? { [K in keyof T]?: DeepPartial<T[K]> }
|
||||
: Partial<T>;
|
||||
|
||||
function longToNumber(long: Long): number {
|
||||
if (long.gt(Number.MAX_SAFE_INTEGER)) {
|
||||
throw new globalThis.Error('Value is larger than Number.MAX_SAFE_INTEGER');
|
||||
}
|
||||
return long.toNumber();
|
||||
}
|
||||
|
||||
if (_m0.util.Long !== Long) {
|
||||
_m0.util.Long = Long as any;
|
||||
_m0.configure();
|
||||
}
|
Loading…
Reference in New Issue