Merge pull request #786 from status-im/esm-no-libp2p-upgrade

Migrate package to ESM (no libp2p upgrade)
This commit is contained in:
Franck R 2022-06-20 15:09:11 +10:00 committed by GitHub
commit 9b4c3ecfb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
56 changed files with 2451 additions and 4599 deletions

View File

@ -42,18 +42,6 @@ jobs:
cd nim-waku/build
./wakunode2 --help
- name: Install bufbuild
uses: mathematic-inc/setup-buf@v2beta
with:
buf-version: ${{ env.BUF_VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: "3.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache npm cache
uses: actions/cache@v2
with:
@ -64,7 +52,9 @@ jobs:
uses: bahmutov/npm-install@v1
- name: Generate protobuf code
run: npm run proto
run: |
npm run proto
npm run fix
- name: Check all protobuf code was committed
shell: bash
@ -76,11 +66,6 @@ jobs:
- name: build
run: npm run build
- name: Check no proto files changed
shell: bash
run: |
[ $(git status --short --ignore-submodules|wc -l) -eq 0 ]
- name: test
env:
DEBUG: "waku:nim-waku*,waku:test*"

View File

@ -11,4 +11,5 @@ jobs:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1
with:
skip_step: build # Done in the package.json script
github_token: ${{ secrets.GITHUB_TOKEN }}

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
.nyc_output
.angular
build
dist
node_modules
src/**.js
coverage

View File

@ -2,5 +2,9 @@
"extension": ["ts"],
"spec": "src/**/*.spec.ts",
"require": ["ts-node/register", "isomorphic-fetch", "jsdom-global/register"],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"exit": true
}

View File

@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Published files moved from `build` to `dist/`.
- Migrate from ts-proto to protons;
the latter does not bring Buffer/Long deps, is ESM compatible and remove the need for bufbuild and protoc.
- Move package to `"type": "module"`.
- Use ESM code in Mocha and Karma tests.
## [0.24.0] - 2022-05-27
### Added

View File

@ -20,8 +20,6 @@ To help ensure your PR passes, just run before committing:
To build and test this repository, you need:
- [Node.js & npm](https://nodejs.org/en/).
- [bufbuild](https://github.com/bufbuild/buf) (only if changing protobuf files).
- [protoc](https://grpc.io/docs/protoc-installation/) (only if changing protobuf files).
- Chrome (for browser testing).
- g++ & make (to build nim-waku)

View File

@ -0,0 +1,69 @@
import path from "path";
import fs from "fs";
const START_PATH = path.join(process.cwd(), "dist/esm");
const IMPORT_REGEXP =
/^((import|export) [^';]* from "(@[^";]+\/)?([^@";]*\/[^";]*)[^";]*)"/g;
const JUST_ADD_AN_EXTENSION = '$1.js"';
const ADD_INDEX_FILE = '$1/index.js"';
const JS_EXT = ".js";
function fixImportsAtFolder(rootPath) {
const entries = fs.readdirSync(rootPath);
entries.forEach((entry) => {
const entryPath = path.join(rootPath, entry);
if (entry.endsWith(JS_EXT)) {
fixImportsAtFile(entryPath);
} else {
const extName = path.extname(entry);
if (!extName) {
const stat = fs.statSync(entryPath);
if (stat.isDirectory()) {
fixImportsAtFolder(entryPath);
}
}
}
});
}
function fixImportsAtFile(filePath) {
const content = fs.readFileSync(filePath).toString("utf8");
const lines = content.split("\n");
const fixedLines = lines.map((l) => {
if (!l.match(IMPORT_REGEXP)) {
return l;
}
const [_, importPath] = l.split(`"`);
let exists = true;
let fullPath;
if (importPath.startsWith(".")) {
fullPath = path.join(filePath, "..", importPath);
exists = fs.existsSync(fullPath);
} else {
fullPath = path.join(process.cwd(), "node_modules", importPath);
exists = fs.existsSync(fullPath);
}
if (exists === false) {
console.log("Update ", l);
return l.replace(IMPORT_REGEXP, JUST_ADD_AN_EXTENSION);
}
const stat = fs.statSync(fullPath);
const isDirectory = stat.isDirectory();
if (isDirectory === true) {
console.log("Update ", l);
return l.replace(IMPORT_REGEXP, ADD_INDEX_FILE);
}
return l;
});
const withFixedImports = fixedLines.join("\n");
fs.writeFileSync(filePath, withFixedImports);
}
fixImportsAtFolder(START_PATH);
console.log("imports fixed...");
console.log("================");

View File

@ -1,16 +0,0 @@
// import settings from default config file
let properties = null;
const originalConfigFn = require("./karma.conf.js");
originalConfigFn({
set: function (arg) {
properties = arg;
},
});
// pass `--grep '[live data]'` to mocha to only run live data tests
properties.client.args = ["--grep", "[live data]]"];
// export settings
module.exports = function (config) {
config.set(properties);
};

34
karma.conf.cjs Normal file
View File

@ -0,0 +1,34 @@
process.env.CHROME_BIN = require("puppeteer").executablePath();
const webpackConfig = require("./webpack.config.cjs");
const webpack = require("webpack");
module.exports = function (config) {
config.set({
frameworks: ["webpack", "mocha"],
files: ["src/lib/**/!(node).spec.ts"],
preprocessors: {
"src/lib/**/!(node).spec.ts": ["webpack"],
},
envPreprocessor: ["CI"],
reporters: ["progress"],
browsers: ["ChromeHeadless"],
singleRun: true,
client: {
mocha: {
timeout: 6000, // Default is 2s
},
},
webpack: {
mode: "production",
module: webpackConfig.module,
plugins: [
new webpack.DefinePlugin({
"process.env.CI": process.env.CI || false,
}),
...webpackConfig.plugins,
],
resolve: webpackConfig.resolve,
stats: { warnings: false },
},
});
};

View File

@ -1,46 +0,0 @@
process.env.CHROME_BIN = require("puppeteer").executablePath();
module.exports = function (config) {
config.set({
frameworks: ["mocha", "karma-typescript"],
files: ["src/lib/**/*.ts", "src/proto/**/*.ts"],
preprocessors: {
"**/*.ts": ["karma-typescript", "env"],
},
envPreprocessor: ["CI"],
plugins: [
require("karma-mocha"),
require("karma-typescript"),
require("karma-chrome-launcher"),
require("karma-env-preprocessor"),
],
reporters: ["progress", "karma-typescript"],
browsers: ["ChromeHeadless"],
singleRun: true,
client: {
mocha: {
timeout: 6000, // Default is 2s
},
},
karmaTypescriptConfig: {
bundlerOptions: {
entrypoints: /^.*[^(node)]\.spec\.ts$/,
},
coverageOptions: {
instrumentation: false,
},
tsconfig: "./tsconfig.json",
compilerOptions: {
noEmit: false,
},
include: {
mode: "replace",
values: ["src/lib/**/*.ts", "src/proto/**/*.ts"],
},
exclude: {
mode: "replace",
values: ["node_modules/**"],
},
},
});
};

3133
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,16 +2,17 @@
"name": "js-waku",
"version": "0.24.0",
"description": "TypeScript implementation of the Waku v2 protocol",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
"module": "build/esm/index.js",
"types": "./dist/esm/index.d.ts",
"main": "./dist/cjs/index.cjs",
"module": "./dist/esm/index.js",
"exports": {
"node": {
"module": "./build/esm/index.js",
"import": "./build/main/index.js"
},
"default": "./build/main/index.js"
".": {
"types": "./dist/esm/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.cjs"
}
},
"type": "module",
"repository": "https://github.com/status-im/js-waku",
"license": "MIT OR Apache-2.0",
"keywords": [
@ -24,16 +25,14 @@
],
"scripts": {
"prepare": "husky install",
"build": "rimraf ./build; run-p build:**",
"build:main": "tsc -p tsconfig.json",
"build:esm": "tsc --module es2015 --target es2015 --outDir build/esm",
"build:umd": "webpack --config webpack.config.js",
"build:umd:min": "webpack --config webpack.config.min.js",
"build:umd:bundle": "webpack --config webpack.config.bundle.js",
"build:umd:min:bundle": "webpack --config webpack.config.min.bundle.js",
"size": "npm run build:esm && size-limit",
"build": "rimraf ./dist; run-s build:**",
"build:esm": "tsc && node build-scripts/fix-imports.js",
"build:cjs": "rollup --config rollup.cjs.config.js -- dist/esm/index.js",
"build:umd": "webpack --config webpack.umd.config.cjs",
"build:umd:min": "terser --ecma 6 --compress --mangle -o dist/umd/index.min.js -- dist/umd/index.js && gzip -9 -c dist/umd/index.min.js > dist/umd/index.min.js.gz",
"size": "npm run build && size-limit",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.conf.js\" \".github/**/*.yml\" --write",
"fix:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.*js\" \".github/**/*.yml\" --write",
"fix:lint": "eslint src --ext .ts --fix",
"pretest": "run-s pretest:*",
"pretest:1-init-git-submodules": "[ -f './nim-waku/build/wakunode2' ] || git submodule update --init --recursive",
@ -43,15 +42,13 @@
"nim-waku:force-build": "(cd nim-waku && rm -rf ./build/ ./vendor && make -j$(nproc --all 2>/dev/null || echo 2) update) && run-s nim-waku:build",
"test": "run-s test:*",
"test:lint": "eslint src --ext .ts",
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.conf.js\" \".github/**/*.yml\" --list-different",
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.*js\" \".github/**/*.yml\" --list-different",
"test:spelling": "cspell \"{README.md,.github/*.md,guides/*.md,src/**/*.ts}\"",
"test:tsc": "tsc -p tsconfig.dev.json",
"test:unit": "nyc --silent mocha",
"test:karma": "karma start",
"test:karma": "karma start karma.conf.cjs",
"examples:test": "run-s examples:pretest; for d in examples/*/; do (cd $d && npm test;); done",
"proto": "run-s proto:*",
"proto:lint": "buf lint",
"proto:build": "rimraf ./src/proto && buf generate",
"proto": "rimraf src/proto/*.ts; protons src/proto/*.proto",
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "nyc --silent mocha --watch",
"doc": "run-s doc:*",
@ -86,17 +83,19 @@
"libp2p-interfaces": "^4.0.6",
"libp2p-mplex": "^0.10.4",
"libp2p-websockets": "^0.16.1",
"long": "^4.0.0",
"multiaddr": "^10.0.1",
"multiformats": "^9.6.5",
"peer-id": "^0.16.0",
"protobufjs": "^6.8.8",
"protons-runtime": "^1.0.4",
"uint8arrays": "^3.0.0",
"uuid": "^8.3.2",
"varint": "^6.0.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@size-limit/preset-big-lib": "^7.0.8",
"@types/app-root-path": "^1.2.4",
"@types/chai": "^4.2.15",
@ -121,14 +120,14 @@
"fast-check": "^2.14.0",
"gh-pages": "^3.2.3",
"husky": "^7.0.4",
"ignore-loader": "^0.1.2",
"isomorphic-fetch": "^3.0.0",
"jsdom": "^19.0.0",
"jsdom-global": "^3.0.2",
"karma": "^6.3.12",
"karma-chrome-launcher": "^3.1.0",
"karma-env-preprocessor": "^0.1.1",
"karma-mocha": "^2.0.1",
"karma-typescript": "^5.5.3",
"karma-webpack": "^5.0.0",
"lint-staged": "^12.3.4",
"mocha": "^9.1.3",
"npm-run-all": "^4.1.5",
@ -137,23 +136,28 @@
"portfinder": "^1.0.28",
"prettier": "^2.1.1",
"process": "^0.11.10",
"protons": "^3.0.4",
"puppeteer": "^13.0.1",
"rollup": "^2.75.0",
"rollup-plugin-polyfill-node": "^0.9.0",
"size-limit": "^7.0.8",
"stream-browserify": "^3.0.0",
"tail": "^2.2.0",
"terser": "^5.13.1",
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"ts-proto": "^1.82.5",
"typedoc": "^0.22.10",
"typedoc-plugin-no-inherit": "^1.3.1",
"typescript": "^4.5.5",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0"
"webpack-cli": "^4.10.0"
},
"files": [
"build/main",
"build/esm",
"build/umd",
"dist/esm",
"dist/cjs",
"dist/umd",
"src/*.ts",
"src/lib/**/*.ts",
"src/proto/**/*.ts",
"!**/*.spec.*",
"!**/*.json",
"CHANGELOG.md",
@ -168,9 +172,9 @@
},
"size-limit": [
{
"path": "build/esm/index.js",
"path": "dist/umd/index.js",
"import": "{ Waku }",
"config": "./webpack.config.js"
"config": "./webpack.umd.config.cjs"
}
],
"lint-staged": {

View File

@ -1,25 +0,0 @@
syntax = "proto3";
package waku.v2;
import "waku/v2/message.proto";
message FilterRequest {
bool subscribe = 1;
string topic = 2;
repeated ContentFilter content_filters = 3;
message ContentFilter {
string content_topic = 1;
}
}
message MessagePush {
repeated WakuMessage messages = 1;
}
message FilterRPC {
string request_id = 1;
FilterRequest request = 2;
MessagePush push = 3;
}

View File

@ -1,21 +0,0 @@
syntax = "proto3";
package waku.v2;
import "waku/v2/message.proto";
message PushRequest {
string pub_sub_topic = 1;
WakuMessage message = 2;
}
message PushResponse {
bool is_success = 1;
string info = 2;
}
message PushRPC {
string request_id = 1;
PushRequest request = 2;
PushResponse response = 3;
}

21
rollup.cjs.config.js Normal file
View File

@ -0,0 +1,21 @@
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import nodePolyfills from "rollup-plugin-polyfill-node";
export default {
output: {
file: "dist/cjs/index.cjs",
format: "cjs",
name: "waku",
},
plugins: [
commonjs(),
json(),
nodePolyfills(),
nodeResolve({
browser: true,
preferBuiltins: false,
}),
],
};

21
rollup.config.js Normal file
View File

@ -0,0 +1,21 @@
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import nodePolyfills from "rollup-plugin-polyfill-node";
export default {
output: {
file: "dist/umd/index.js",
format: "umd",
name: "waku",
},
plugins: [
commonjs(),
json(),
nodePolyfills(),
nodeResolve({
browser: true,
preferBuiltins: false,
}),
],
};

View File

@ -1,7 +1,7 @@
import nodeCrypto from "crypto";
import * as secp from "@noble/secp256k1";
import * as sha3 from "js-sha3";
import sha3 from "js-sha3";
import { concat } from "uint8arrays/concat";
import { Asymmetric, Symmetric } from "./waku_message/constants";

View File

@ -3,13 +3,6 @@ import { expect } from "chai";
import { DnsClient, DnsNodeDiscovery } from "./dns";
import testData from "./testdata.json";
declare global {
interface Window {
__env__?: any;
}
}
declare let window: Window | undefined;
const mockData = testData.dns;
const host = "nodes.example.org";
@ -273,7 +266,7 @@ describe("DNS Node Discovery [live data]", function () {
const maxQuantity = 3;
before(function () {
if (process.env.CI || window?.__env__?.CI) {
if (process.env.CI) {
this.skip();
}
});

View File

@ -1,4 +1,4 @@
import { debug } from "debug";
import debug from "debug";
import { ENR } from "../enr";

View File

@ -1,4 +1,4 @@
import * as base32 from "hi-base32";
import base32 from "hi-base32";
import { fromString } from "uint8arrays/from-string";
import { keccak256, verifySignature } from "../crypto";

View File

@ -1,4 +1,4 @@
import { debug } from "debug";
import debug from "debug";
import { ENR, Waku2 } from "../enr";

View File

@ -3,13 +3,6 @@ import { expect } from "chai";
import { fleets } from "./predefined";
import { getPseudoRandomSubset } from "./random_subset";
declare global {
interface Window {
__env__?: any;
}
}
declare let window: Window | undefined;
describe("Discovery", () => {
it("returns all values when wanted number matches available values", function () {
const values = ["a", "b", "c"];
@ -44,7 +37,7 @@ describe("Discovery", () => {
describe("Discovery [live data]", function () {
before(function () {
if (process.env.CI || window?.__env__?.CI) {
if (process.env.CI) {
this.skip();
}
});

View File

@ -3,13 +3,6 @@ import PeerId from "peer-id";
import { Waku } from "./waku";
declare global {
interface Window {
__env__?: any;
}
}
declare let window: Window | undefined;
describe("Waku Dial", function () {
describe("Bootstrap [live data]", function () {
let waku: Waku;
@ -19,7 +12,7 @@ describe("Waku Dial", function () {
});
before(function () {
if (process.env.CI || window?.__env__?.CI) {
if (process.env.CI) {
this.skip();
}
});

View File

@ -1,7 +1,6 @@
import { Reader } from "protobufjs/minimal";
import { v4 as uuid } from "uuid";
import * as proto from "../../proto/waku/v2/filter";
import * as proto from "../../proto/filter";
export type ContentFilter = {
contentTopic: string;
@ -36,7 +35,7 @@ export class FilterRPC {
* @returns FilterRPC
*/
static decode(bytes: Uint8Array): FilterRPC {
const res = proto.FilterRPC.decode(Reader.create(bytes));
const res = proto.FilterRPC.decode(bytes);
return new FilterRPC(res);
}
@ -45,14 +44,14 @@ export class FilterRPC {
* @returns Uint8Array
*/
encode(): Uint8Array {
return proto.FilterRPC.encode(this.proto).finish();
return proto.FilterRPC.encode(this.proto);
}
get push(): proto.MessagePush | undefined {
return this.proto.push;
}
get requestId(): string {
get requestId(): string | undefined {
return this.proto.requestId;
}
}

View File

@ -4,7 +4,7 @@ import { pipe } from "it-pipe";
import Libp2p, { MuxedStream } from "libp2p";
import { Peer, PeerId } from "libp2p/src/peer-store";
import { WakuMessage as WakuMessageProto } from "../../proto/waku/v2/message";
import { WakuMessage as WakuMessageProto } from "../../proto/message";
import { DefaultPubSubTopic } from "../constants";
import { getPeersForProtocol, selectRandomPeer } from "../select_peer";
import { hexToBytes } from "../utils";
@ -73,6 +73,12 @@ export class WakuFilter {
true
);
const requestId = request.requestId;
if (!requestId)
throw new Error(
"Internal error: createRequest expected to set `requestId`"
);
const peer = await this.getPeer(opts?.peerId);
const stream = await this.newStream(peer);
@ -90,11 +96,11 @@ export class WakuFilter {
throw e;
}
this.addCallback(request.requestId, callback);
this.addCallback(requestId, callback);
return async () => {
await this.unsubscribe(topic, contentFilters, request.requestId, peer);
this.removeCallback(request.requestId);
await this.unsubscribe(topic, contentFilters, requestId, peer);
this.removeCallback(requestId);
};
}
@ -107,7 +113,7 @@ export class WakuFilter {
async (source: AsyncIterable<Buffer>) => {
for await (const bytes of source) {
const res = FilterRPC.decode(bytes.slice());
if (res.push?.messages?.length) {
if (res.requestId && res.push?.messages?.length) {
await this.pushMessages(res.requestId, res.push.messages);
}
}

View File

@ -5,7 +5,7 @@ import Libp2p from "libp2p";
import { Peer } from "libp2p/src/peer-store";
import PeerId from "peer-id";
import { PushResponse } from "../../proto/waku/v2/light_push";
import { PushResponse } from "../../proto/light_push";
import { DefaultPubSubTopic } from "../constants";
import { getPeersForProtocol, selectRandomPeer } from "../select_peer";
import { WakuMessage } from "../waku_message";

View File

@ -1,7 +1,6 @@
import { Reader } from "protobufjs/minimal";
import { v4 as uuid } from "uuid";
import * as proto from "../../proto/waku/v2/light_push";
import * as proto from "../../proto/light_push";
import { WakuMessage } from "../waku_message";
export class PushRPC {
@ -19,12 +18,12 @@ export class PushRPC {
}
static decode(bytes: Uint8Array): PushRPC {
const res = proto.PushRPC.decode(Reader.create(bytes));
const res = proto.PushRPC.decode(bytes);
return new PushRPC(res);
}
encode(): Uint8Array {
return proto.PushRPC.encode(this.proto).finish();
return proto.PushRPC.encode(this.proto);
}
get query(): proto.PushRequest | undefined {

View File

@ -1,14 +1,13 @@
import debug from "debug";
import Long from "long";
import { Reader } from "protobufjs/minimal";
import * as proto from "../../proto/waku/v2/message";
import * as proto from "../../proto/message";
import { bytesToUtf8, utf8ToBytes } from "../utils";
import * as version_1 from "./version_1";
const DefaultVersion = 0;
const dbg = debug("waku:message");
const OneMillion = BigInt(1_000_000);
export enum DecryptionMethod {
Asymmetric = "asymmetric",
@ -105,7 +104,7 @@ export class WakuMessage {
payload: _payload,
timestampDeprecated: timestamp.valueOf() / 1000,
// milliseconds 10^-3 to nanoseconds 10^-9
timestamp: Long.fromNumber(timestamp.valueOf()).mul(1_000_000),
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
version,
contentTopic,
},
@ -131,7 +130,7 @@ export class WakuMessage {
contentTopic?: string[];
}>
): Promise<WakuMessage | undefined> {
const protoBuf = proto.WakuMessage.decode(Reader.create(bytes));
const protoBuf = proto.WakuMessage.decode(bytes);
return WakuMessage.decodeProto(protoBuf, decryptionKeys);
}
@ -248,7 +247,7 @@ export class WakuMessage {
}
encode(): Uint8Array {
return proto.WakuMessage.encode(this.proto).finish();
return proto.WakuMessage.encode(this.proto);
}
get payloadAsUtf8(): string {
@ -285,8 +284,8 @@ export class WakuMessage {
try {
if (this.proto.timestamp) {
// nanoseconds 10^-9 to milliseconds 10^-3
const timestamp = this.proto.timestamp.div(1_000_000).toNumber();
return new Date(timestamp);
const timestamp = this.proto.timestamp / OneMillion;
return new Date(Number(timestamp));
}
if (this.proto.timestampDeprecated) {

View File

@ -78,7 +78,7 @@ export class WakuRelay extends Gossipsub {
) {
super(
libp2p,
Object.assign(options, {
Object.assign(options ?? {}, {
// Ensure that no signature is included nor expected in the messages.
globalSignaturePolicy: SignaturePolicy.StrictNoSign,
})

View File

@ -1,12 +1,12 @@
import Long from "long";
import { Reader } from "protobufjs/minimal";
import { v4 as uuid } from "uuid";
import * as protoV2Beta3 from "../../proto/waku/v2/store/v2beta3/store";
import * as protoV2Beta4 from "../../proto/waku/v2/store/v2beta4/store";
import * as protoV2Beta3 from "../../proto/store_v2beta3";
import * as protoV2Beta4 from "../../proto/store_v2beta4";
import { StoreCodecs } from "./constants";
const OneMillion = BigInt(1_000_000);
export enum PageDirection {
BACKWARD = "backward",
FORWARD = "forward",
@ -24,7 +24,9 @@ export interface Params {
}
export class HistoryRPC {
private readonly protoCodec: any;
private readonly historyRpc:
| typeof protoV2Beta3.HistoryRPC
| typeof protoV2Beta4.HistoryRPC;
private constructor(
public readonly proto: protoV2Beta3.HistoryRPC | protoV2Beta4.HistoryRPC,
@ -32,10 +34,10 @@ export class HistoryRPC {
) {
switch (storeCodec) {
case StoreCodecs.V2Beta3:
this.protoCodec = protoV2Beta3;
this.historyRpc = protoV2Beta3.HistoryRPC;
break;
case StoreCodecs.V2Beta4:
this.protoCodec = protoV2Beta4;
this.historyRpc = protoV2Beta4.HistoryRPC;
break;
default:
throw `Internal Error: Unexpected store codec value received in constructor: ${storeCodec}`;
@ -73,7 +75,7 @@ export class HistoryRPC {
// Using function to scope variables
return ((): HistoryRPC => {
const pagingInfo = {
pageSize: Long.fromNumber(params.pageSize),
pageSize: BigInt(params.pageSize),
cursor: params.cursor,
direction,
} as protoV2Beta3.PagingInfo;
@ -101,7 +103,7 @@ export class HistoryRPC {
case StoreCodecs.V2Beta4:
return ((): HistoryRPC => {
const pagingInfo = {
pageSize: Long.fromNumber(params.pageSize),
pageSize: BigInt(params.pageSize),
cursor: params.cursor,
direction,
} as protoV2Beta4.PagingInfo;
@ -109,14 +111,12 @@ export class HistoryRPC {
let startTime, endTime;
if (params.startTime) {
// milliseconds 10^-3 to nanoseconds 10^-9
startTime = Long.fromNumber(params.startTime.valueOf()).mul(
1_000_000
);
startTime = BigInt(params.startTime.valueOf()) * OneMillion;
}
if (params.endTime) {
// milliseconds 10^-3 to nanoseconds 10^-9
endTime = Long.fromNumber(params.endTime.valueOf()).mul(1_000_000);
endTime = BigInt(params.endTime.valueOf()) * OneMillion;
}
return new HistoryRPC(
{
@ -140,24 +140,24 @@ export class HistoryRPC {
}
decode(bytes: Uint8Array): HistoryRPC {
const res = this.protoCodec.HistoryRPC.decode(Reader.create(bytes));
const res = this.historyRpc.decode(bytes);
return new HistoryRPC(res, this.storeCodec);
}
encode(): Uint8Array {
return this.protoCodec.HistoryRPC.encode(this.proto).finish();
return this.historyRpc.encode(this.proto as any);
}
}
function directionToProto(
pageDirection: PageDirection
): protoV2Beta4.PagingInfo_Direction {
): protoV2Beta4.PagingInfo.Direction {
switch (pageDirection) {
case PageDirection.BACKWARD:
return protoV2Beta4.PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED;
return protoV2Beta4.PagingInfo.Direction.DIRECTION_BACKWARD_UNSPECIFIED;
case PageDirection.FORWARD:
return protoV2Beta4.PagingInfo_Direction.DIRECTION_FORWARD;
return protoV2Beta4.PagingInfo.Direction.DIRECTION_FORWARD;
default:
return protoV2Beta4.PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED;
return protoV2Beta4.PagingInfo.Direction.DIRECTION_BACKWARD_UNSPECIFIED;
}
}

View File

@ -6,6 +6,8 @@ import Libp2p from "libp2p";
import { Peer } from "libp2p/src/peer-store";
import PeerId from "peer-id";
import * as protoV2Beta4 from "../../proto/store_v2beta4";
import { HistoryResponse } from "../../proto/store_v2beta4";
import { DefaultPubSubTopic, StoreCodecs } from "../constants";
import { getPeersForProtocol, selectRandomPeer } from "../select_peer";
import { hexToBytes } from "../utils";
@ -13,6 +15,8 @@ import { DecryptionMethod, WakuMessage } from "../waku_message";
import { HistoryRPC, PageDirection } from "./history_rpc";
import Error = HistoryResponse.Error;
const dbg = debug("waku:store");
export const DefaultPageSize = 10;
@ -211,13 +215,14 @@ export class WakuStore {
);
const reply = historyRpcQuery.decode(res.slice());
const response = reply.response;
if (!response) {
if (!reply.response) {
throw "History response misses response field";
}
if (response.error) {
throw "History response contains an Error" + response.error;
const response = reply.response as protoV2Beta4.HistoryResponse;
if (response.error && response.error !== Error.ERROR_NONE_UNSPECIFIED) {
throw "History response contains an Error: " + response.error;
}
if (!response.messages || !response.messages.length) {

23
src/proto/filter.proto Normal file
View File

@ -0,0 +1,23 @@
syntax = "proto3";
import "message.proto";
message FilterRequest {
optional bool subscribe = 1;
optional string topic = 2;
repeated ContentFilter content_filters = 3;
message ContentFilter {
optional string content_topic = 1;
}
}
message MessagePush {
repeated WakuMessage messages = 1;
}
message FilterRPC {
optional string request_id = 1;
optional FilterRequest request = 2;
optional MessagePush push = 3;
}

135
src/proto/filter.ts Normal file
View File

@ -0,0 +1,135 @@
/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-namespace */
import {
encodeMessage,
decodeMessage,
message,
string,
bool,
bytes,
uint32,
double,
sint64,
} from "protons-runtime";
import type { Codec } from "protons-runtime";
export interface FilterRequest {
subscribe?: boolean;
topic?: string;
contentFilters: FilterRequest.ContentFilter[];
}
export namespace FilterRequest {
export interface ContentFilter {
contentTopic?: string;
}
export namespace ContentFilter {
export const codec = (): Codec<ContentFilter> => {
return message<ContentFilter>({
1: { name: "contentTopic", codec: string, optional: true },
});
};
export const encode = (obj: ContentFilter): Uint8Array => {
return encodeMessage(obj, ContentFilter.codec());
};
export const decode = (buf: Uint8Array): ContentFilter => {
return decodeMessage(buf, ContentFilter.codec());
};
}
export const codec = (): Codec<FilterRequest> => {
return message<FilterRequest>({
1: { name: "subscribe", codec: bool, optional: true },
2: { name: "topic", codec: string, optional: true },
3: {
name: "contentFilters",
codec: FilterRequest.ContentFilter.codec(),
repeats: true,
},
});
};
export const encode = (obj: FilterRequest): Uint8Array => {
return encodeMessage(obj, FilterRequest.codec());
};
export const decode = (buf: Uint8Array): FilterRequest => {
return decodeMessage(buf, FilterRequest.codec());
};
}
export interface MessagePush {
messages: WakuMessage[];
}
export namespace MessagePush {
export const codec = (): Codec<MessagePush> => {
return message<MessagePush>({
1: { name: "messages", codec: WakuMessage.codec(), repeats: true },
});
};
export const encode = (obj: MessagePush): Uint8Array => {
return encodeMessage(obj, MessagePush.codec());
};
export const decode = (buf: Uint8Array): MessagePush => {
return decodeMessage(buf, MessagePush.codec());
};
}
export interface FilterRPC {
requestId?: string;
request?: FilterRequest;
push?: MessagePush;
}
export namespace FilterRPC {
export const codec = (): Codec<FilterRPC> => {
return message<FilterRPC>({
1: { name: "requestId", codec: string, optional: true },
2: { name: "request", codec: FilterRequest.codec(), optional: true },
3: { name: "push", codec: MessagePush.codec(), optional: true },
});
};
export const encode = (obj: FilterRPC): Uint8Array => {
return encodeMessage(obj, FilterRPC.codec());
};
export const decode = (buf: Uint8Array): FilterRPC => {
return decodeMessage(buf, FilterRPC.codec());
};
}
export interface WakuMessage {
payload?: Uint8Array;
contentTopic?: string;
version?: number;
timestampDeprecated?: number;
timestamp?: bigint;
}
export namespace WakuMessage {
export const codec = (): Codec<WakuMessage> => {
return message<WakuMessage>({
1: { name: "payload", codec: bytes, optional: true },
2: { name: "contentTopic", codec: string, optional: true },
3: { name: "version", codec: uint32, optional: true },
4: { name: "timestampDeprecated", codec: double, optional: true },
10: { name: "timestamp", codec: sint64, optional: true },
});
};
export const encode = (obj: WakuMessage): Uint8Array => {
return encodeMessage(obj, WakuMessage.codec());
};
export const decode = (buf: Uint8Array): WakuMessage => {
return decodeMessage(buf, WakuMessage.codec());
};
}

View File

@ -0,0 +1,19 @@
syntax = "proto3";
import "message.proto";
message PushRequest {
optional string pub_sub_topic = 1;
optional WakuMessage message = 2;
}
message PushResponse {
optional bool is_success = 1;
optional string info = 2;
}
message PushRPC {
optional string request_id = 1;
optional PushRequest request = 2;
optional PushResponse response = 3;
}

111
src/proto/light_push.ts Normal file
View File

@ -0,0 +1,111 @@
/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-namespace */
import {
encodeMessage,
decodeMessage,
message,
string,
bool,
bytes,
uint32,
double,
sint64,
} from "protons-runtime";
import type { Codec } from "protons-runtime";
export interface PushRequest {
pubSubTopic?: string;
message?: WakuMessage;
}
export namespace PushRequest {
export const codec = (): Codec<PushRequest> => {
return message<PushRequest>({
1: { name: "pubSubTopic", codec: string, optional: true },
2: { name: "message", codec: WakuMessage.codec(), optional: true },
});
};
export const encode = (obj: PushRequest): Uint8Array => {
return encodeMessage(obj, PushRequest.codec());
};
export const decode = (buf: Uint8Array): PushRequest => {
return decodeMessage(buf, PushRequest.codec());
};
}
export interface PushResponse {
isSuccess?: boolean;
info?: string;
}
export namespace PushResponse {
export const codec = (): Codec<PushResponse> => {
return message<PushResponse>({
1: { name: "isSuccess", codec: bool, optional: true },
2: { name: "info", codec: string, optional: true },
});
};
export const encode = (obj: PushResponse): Uint8Array => {
return encodeMessage(obj, PushResponse.codec());
};
export const decode = (buf: Uint8Array): PushResponse => {
return decodeMessage(buf, PushResponse.codec());
};
}
export interface PushRPC {
requestId?: string;
request?: PushRequest;
response?: PushResponse;
}
export namespace PushRPC {
export const codec = (): Codec<PushRPC> => {
return message<PushRPC>({
1: { name: "requestId", codec: string, optional: true },
2: { name: "request", codec: PushRequest.codec(), optional: true },
3: { name: "response", codec: PushResponse.codec(), optional: true },
});
};
export const encode = (obj: PushRPC): Uint8Array => {
return encodeMessage(obj, PushRPC.codec());
};
export const decode = (buf: Uint8Array): PushRPC => {
return decodeMessage(buf, PushRPC.codec());
};
}
export interface WakuMessage {
payload?: Uint8Array;
contentTopic?: string;
version?: number;
timestampDeprecated?: number;
timestamp?: bigint;
}
export namespace WakuMessage {
export const codec = (): Codec<WakuMessage> => {
return message<WakuMessage>({
1: { name: "payload", codec: bytes, optional: true },
2: { name: "contentTopic", codec: string, optional: true },
3: { name: "version", codec: uint32, optional: true },
4: { name: "timestampDeprecated", codec: double, optional: true },
10: { name: "timestamp", codec: sint64, optional: true },
});
};
export const encode = (obj: WakuMessage): Uint8Array => {
return encodeMessage(obj, WakuMessage.codec());
};
export const decode = (buf: Uint8Array): WakuMessage => {
return decodeMessage(buf, WakuMessage.codec());
};
}

View File

@ -1,7 +1,5 @@
syntax = "proto3";
package waku.v2;
message WakuMessage {
optional bytes payload = 1;
optional string content_topic = 2;

42
src/proto/message.ts Normal file
View File

@ -0,0 +1,42 @@
/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-namespace */
import {
encodeMessage,
decodeMessage,
message,
bytes,
string,
uint32,
double,
sint64,
} from "protons-runtime";
import type { Codec } from "protons-runtime";
export interface WakuMessage {
payload?: Uint8Array;
contentTopic?: string;
version?: number;
timestampDeprecated?: number;
timestamp?: bigint;
}
export namespace WakuMessage {
export const codec = (): Codec<WakuMessage> => {
return message<WakuMessage>({
1: { name: "payload", codec: bytes, optional: true },
2: { name: "contentTopic", codec: string, optional: true },
3: { name: "version", codec: uint32, optional: true },
4: { name: "timestampDeprecated", codec: double, optional: true },
10: { name: "timestamp", codec: sint64, optional: true },
});
};
export const encode = (obj: WakuMessage): Uint8Array => {
return encodeMessage(obj, WakuMessage.codec());
};
export const decode = (buf: Uint8Array): WakuMessage => {
return decodeMessage(buf, WakuMessage.codec());
};
}

View File

@ -1,27 +1,25 @@
syntax = "proto3";
package waku.v2.store.v2beta3;
import "waku/v2/message.proto";
import "message.proto";
message Index {
bytes digest = 1;
double received_time = 2;
double sender_time = 3;
optional bytes digest = 1;
optional double received_time = 2;
optional double sender_time = 3;
}
message PagingInfo {
uint64 page_size = 1;
Index cursor = 2;
optional uint64 page_size = 1;
optional Index cursor = 2;
enum Direction {
DIRECTION_BACKWARD_UNSPECIFIED = 0;
DIRECTION_FORWARD = 1;
}
Direction direction = 3;
optional Direction direction = 3;
}
message ContentFilter {
string content_topic = 1;
optional string content_topic = 1;
}
message HistoryQuery {
@ -34,16 +32,16 @@ message HistoryQuery {
message HistoryResponse {
repeated WakuMessage messages = 2;
PagingInfo paging_info = 3;
optional PagingInfo paging_info = 3;
enum Error {
ERROR_NONE_UNSPECIFIED = 0;
ERROR_INVALID_CURSOR = 1;
}
Error error = 4;
optional Error error = 4;
}
message HistoryRPC {
string request_id = 1;
HistoryQuery query = 2;
HistoryResponse response = 3;
optional string request_id = 1;
optional HistoryQuery query = 2;
optional HistoryResponse response = 3;
}

232
src/proto/store_v2beta3.ts Normal file
View File

@ -0,0 +1,232 @@
/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-namespace */
import {
encodeMessage,
decodeMessage,
message,
bytes,
double,
enumeration,
uint64,
string,
uint32,
sint64,
} from "protons-runtime";
import type { Codec } from "protons-runtime";
export interface Index {
digest?: Uint8Array;
receivedTime?: number;
senderTime?: number;
}
export namespace Index {
export const codec = (): Codec<Index> => {
return message<Index>({
1: { name: "digest", codec: bytes, optional: true },
2: { name: "receivedTime", codec: double, optional: true },
3: { name: "senderTime", codec: double, optional: true },
});
};
export const encode = (obj: Index): Uint8Array => {
return encodeMessage(obj, Index.codec());
};
export const decode = (buf: Uint8Array): Index => {
return decodeMessage(buf, Index.codec());
};
}
export interface PagingInfo {
pageSize?: bigint;
cursor?: Index;
direction?: PagingInfo.Direction;
}
export namespace PagingInfo {
export enum Direction {
DIRECTION_BACKWARD_UNSPECIFIED = "DIRECTION_BACKWARD_UNSPECIFIED",
DIRECTION_FORWARD = "DIRECTION_FORWARD",
}
enum __DirectionValues {
DIRECTION_BACKWARD_UNSPECIFIED = 0,
DIRECTION_FORWARD = 1,
}
export namespace Direction {
export const codec = () => {
return enumeration<typeof Direction>(__DirectionValues);
};
}
export const codec = (): Codec<PagingInfo> => {
return message<PagingInfo>({
1: { name: "pageSize", codec: uint64, optional: true },
2: { name: "cursor", codec: Index.codec(), optional: true },
3: {
name: "direction",
codec: PagingInfo.Direction.codec(),
optional: true,
},
});
};
export const encode = (obj: PagingInfo): Uint8Array => {
return encodeMessage(obj, PagingInfo.codec());
};
export const decode = (buf: Uint8Array): PagingInfo => {
return decodeMessage(buf, PagingInfo.codec());
};
}
export interface ContentFilter {
contentTopic?: string;
}
export namespace ContentFilter {
export const codec = (): Codec<ContentFilter> => {
return message<ContentFilter>({
1: { name: "contentTopic", codec: string, optional: true },
});
};
export const encode = (obj: ContentFilter): Uint8Array => {
return encodeMessage(obj, ContentFilter.codec());
};
export const decode = (buf: Uint8Array): ContentFilter => {
return decodeMessage(buf, ContentFilter.codec());
};
}
export interface HistoryQuery {
pubSubTopic?: string;
contentFilters: ContentFilter[];
pagingInfo?: PagingInfo;
startTime?: number;
endTime?: number;
}
export namespace HistoryQuery {
export const codec = (): Codec<HistoryQuery> => {
return message<HistoryQuery>({
2: { name: "pubSubTopic", codec: string, optional: true },
3: {
name: "contentFilters",
codec: ContentFilter.codec(),
repeats: true,
},
4: { name: "pagingInfo", codec: PagingInfo.codec(), optional: true },
5: { name: "startTime", codec: double, optional: true },
6: { name: "endTime", codec: double, optional: true },
});
};
export const encode = (obj: HistoryQuery): Uint8Array => {
return encodeMessage(obj, HistoryQuery.codec());
};
export const decode = (buf: Uint8Array): HistoryQuery => {
return decodeMessage(buf, HistoryQuery.codec());
};
}
export interface HistoryResponse {
messages: WakuMessage[];
pagingInfo?: PagingInfo;
error?: HistoryResponse.Error;
}
export namespace HistoryResponse {
export enum Error {
ERROR_NONE_UNSPECIFIED = "ERROR_NONE_UNSPECIFIED",
ERROR_INVALID_CURSOR = "ERROR_INVALID_CURSOR",
}
enum __ErrorValues {
ERROR_NONE_UNSPECIFIED = 0,
ERROR_INVALID_CURSOR = 1,
}
export namespace Error {
export const codec = () => {
return enumeration<typeof Error>(__ErrorValues);
};
}
export const codec = (): Codec<HistoryResponse> => {
return message<HistoryResponse>({
2: { name: "messages", codec: WakuMessage.codec(), repeats: true },
3: { name: "pagingInfo", codec: PagingInfo.codec(), optional: true },
4: {
name: "error",
codec: HistoryResponse.Error.codec(),
optional: true,
},
});
};
export const encode = (obj: HistoryResponse): Uint8Array => {
return encodeMessage(obj, HistoryResponse.codec());
};
export const decode = (buf: Uint8Array): HistoryResponse => {
return decodeMessage(buf, HistoryResponse.codec());
};
}
export interface HistoryRPC {
requestId?: string;
query?: HistoryQuery;
response?: HistoryResponse;
}
export namespace HistoryRPC {
export const codec = (): Codec<HistoryRPC> => {
return message<HistoryRPC>({
1: { name: "requestId", codec: string, optional: true },
2: { name: "query", codec: HistoryQuery.codec(), optional: true },
3: { name: "response", codec: HistoryResponse.codec(), optional: true },
});
};
export const encode = (obj: HistoryRPC): Uint8Array => {
return encodeMessage(obj, HistoryRPC.codec());
};
export const decode = (buf: Uint8Array): HistoryRPC => {
return decodeMessage(buf, HistoryRPC.codec());
};
}
export interface WakuMessage {
payload?: Uint8Array;
contentTopic?: string;
version?: number;
timestampDeprecated?: number;
timestamp?: bigint;
}
export namespace WakuMessage {
export const codec = (): Codec<WakuMessage> => {
return message<WakuMessage>({
1: { name: "payload", codec: bytes, optional: true },
2: { name: "contentTopic", codec: string, optional: true },
3: { name: "version", codec: uint32, optional: true },
4: { name: "timestampDeprecated", codec: double, optional: true },
10: { name: "timestamp", codec: sint64, optional: true },
});
};
export const encode = (obj: WakuMessage): Uint8Array => {
return encodeMessage(obj, WakuMessage.codec());
};
export const decode = (buf: Uint8Array): WakuMessage => {
return decodeMessage(buf, WakuMessage.codec());
};
}

View File

@ -1,28 +1,26 @@
syntax = "proto3";
package waku.v2.store.v2beta4;
import "waku/v2/message.proto";
import "message.proto";
message Index {
bytes digest = 1;
sint64 received_time = 2;
sint64 sender_time = 3;
string pubsub_topic = 4;
optional bytes digest = 1;
optional sint64 received_time = 2;
optional sint64 sender_time = 3;
optional string pubsub_topic = 4;
}
message PagingInfo {
uint64 page_size = 1;
Index cursor = 2;
optional uint64 page_size = 1;
optional Index cursor = 2;
enum Direction {
DIRECTION_BACKWARD_UNSPECIFIED = 0;
DIRECTION_FORWARD = 1;
}
Direction direction = 3;
optional Direction direction = 3;
}
message ContentFilter {
string content_topic = 1;
optional string content_topic = 1;
}
message HistoryQuery {
@ -35,16 +33,16 @@ message HistoryQuery {
message HistoryResponse {
repeated WakuMessage messages = 2;
PagingInfo paging_info = 3;
optional PagingInfo paging_info = 3;
enum Error {
ERROR_NONE_UNSPECIFIED = 0;
ERROR_INVALID_CURSOR = 1;
}
Error error = 4;
optional Error error = 4;
}
message HistoryRPC {
string request_id = 1;
HistoryQuery query = 2;
HistoryResponse response = 3;
optional string request_id = 1;
optional HistoryQuery query = 2;
optional HistoryResponse response = 3;
}

234
src/proto/store_v2beta4.ts Normal file
View File

@ -0,0 +1,234 @@
/* eslint-disable import/export */
/* eslint-disable @typescript-eslint/no-namespace */
import {
encodeMessage,
decodeMessage,
message,
bytes,
sint64,
string,
enumeration,
uint64,
uint32,
double,
} from "protons-runtime";
import type { Codec } from "protons-runtime";
export interface Index {
digest?: Uint8Array;
receivedTime?: bigint;
senderTime?: bigint;
pubsubTopic?: string;
}
export namespace Index {
export const codec = (): Codec<Index> => {
return message<Index>({
1: { name: "digest", codec: bytes, optional: true },
2: { name: "receivedTime", codec: sint64, optional: true },
3: { name: "senderTime", codec: sint64, optional: true },
4: { name: "pubsubTopic", codec: string, optional: true },
});
};
export const encode = (obj: Index): Uint8Array => {
return encodeMessage(obj, Index.codec());
};
export const decode = (buf: Uint8Array): Index => {
return decodeMessage(buf, Index.codec());
};
}
export interface PagingInfo {
pageSize?: bigint;
cursor?: Index;
direction?: PagingInfo.Direction;
}
export namespace PagingInfo {
export enum Direction {
DIRECTION_BACKWARD_UNSPECIFIED = "DIRECTION_BACKWARD_UNSPECIFIED",
DIRECTION_FORWARD = "DIRECTION_FORWARD",
}
enum __DirectionValues {
DIRECTION_BACKWARD_UNSPECIFIED = 0,
DIRECTION_FORWARD = 1,
}
export namespace Direction {
export const codec = () => {
return enumeration<typeof Direction>(__DirectionValues);
};
}
export const codec = (): Codec<PagingInfo> => {
return message<PagingInfo>({
1: { name: "pageSize", codec: uint64, optional: true },
2: { name: "cursor", codec: Index.codec(), optional: true },
3: {
name: "direction",
codec: PagingInfo.Direction.codec(),
optional: true,
},
});
};
export const encode = (obj: PagingInfo): Uint8Array => {
return encodeMessage(obj, PagingInfo.codec());
};
export const decode = (buf: Uint8Array): PagingInfo => {
return decodeMessage(buf, PagingInfo.codec());
};
}
export interface ContentFilter {
contentTopic?: string;
}
export namespace ContentFilter {
export const codec = (): Codec<ContentFilter> => {
return message<ContentFilter>({
1: { name: "contentTopic", codec: string, optional: true },
});
};
export const encode = (obj: ContentFilter): Uint8Array => {
return encodeMessage(obj, ContentFilter.codec());
};
export const decode = (buf: Uint8Array): ContentFilter => {
return decodeMessage(buf, ContentFilter.codec());
};
}
export interface HistoryQuery {
pubSubTopic?: string;
contentFilters: ContentFilter[];
pagingInfo?: PagingInfo;
startTime?: bigint;
endTime?: bigint;
}
export namespace HistoryQuery {
export const codec = (): Codec<HistoryQuery> => {
return message<HistoryQuery>({
2: { name: "pubSubTopic", codec: string, optional: true },
3: {
name: "contentFilters",
codec: ContentFilter.codec(),
repeats: true,
},
4: { name: "pagingInfo", codec: PagingInfo.codec(), optional: true },
5: { name: "startTime", codec: sint64, optional: true },
6: { name: "endTime", codec: sint64, optional: true },
});
};
export const encode = (obj: HistoryQuery): Uint8Array => {
return encodeMessage(obj, HistoryQuery.codec());
};
export const decode = (buf: Uint8Array): HistoryQuery => {
return decodeMessage(buf, HistoryQuery.codec());
};
}
export interface HistoryResponse {
messages: WakuMessage[];
pagingInfo?: PagingInfo;
error?: HistoryResponse.Error;
}
export namespace HistoryResponse {
export enum Error {
ERROR_NONE_UNSPECIFIED = "ERROR_NONE_UNSPECIFIED",
ERROR_INVALID_CURSOR = "ERROR_INVALID_CURSOR",
}
enum __ErrorValues {
ERROR_NONE_UNSPECIFIED = 0,
ERROR_INVALID_CURSOR = 1,
}
export namespace Error {
export const codec = () => {
return enumeration<typeof Error>(__ErrorValues);
};
}
export const codec = (): Codec<HistoryResponse> => {
return message<HistoryResponse>({
2: { name: "messages", codec: WakuMessage.codec(), repeats: true },
3: { name: "pagingInfo", codec: PagingInfo.codec(), optional: true },
4: {
name: "error",
codec: HistoryResponse.Error.codec(),
optional: true,
},
});
};
export const encode = (obj: HistoryResponse): Uint8Array => {
return encodeMessage(obj, HistoryResponse.codec());
};
export const decode = (buf: Uint8Array): HistoryResponse => {
return decodeMessage(buf, HistoryResponse.codec());
};
}
export interface HistoryRPC {
requestId?: string;
query?: HistoryQuery;
response?: HistoryResponse;
}
export namespace HistoryRPC {
export const codec = (): Codec<HistoryRPC> => {
return message<HistoryRPC>({
1: { name: "requestId", codec: string, optional: true },
2: { name: "query", codec: HistoryQuery.codec(), optional: true },
3: { name: "response", codec: HistoryResponse.codec(), optional: true },
});
};
export const encode = (obj: HistoryRPC): Uint8Array => {
return encodeMessage(obj, HistoryRPC.codec());
};
export const decode = (buf: Uint8Array): HistoryRPC => {
return decodeMessage(buf, HistoryRPC.codec());
};
}
export interface WakuMessage {
payload?: Uint8Array;
contentTopic?: string;
version?: number;
timestampDeprecated?: number;
timestamp?: bigint;
}
export namespace WakuMessage {
export const codec = (): Codec<WakuMessage> => {
return message<WakuMessage>({
1: { name: "payload", codec: bytes, optional: true },
2: { name: "contentTopic", codec: string, optional: true },
3: { name: "version", codec: uint32, optional: true },
4: { name: "timestampDeprecated", codec: double, optional: true },
10: { name: "timestamp", codec: sint64, optional: true },
});
};
export const encode = (obj: WakuMessage): Uint8Array => {
return encodeMessage(obj, WakuMessage.codec());
};
export const decode = (buf: Uint8Array): WakuMessage => {
return decodeMessage(buf, WakuMessage.codec());
};
}

View File

@ -1,358 +0,0 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { WakuMessage } from "../../waku/v2/message";
export const protobufPackage = "waku.v2";
export interface FilterRequest {
subscribe: boolean;
topic: string;
contentFilters: FilterRequest_ContentFilter[];
}
export interface FilterRequest_ContentFilter {
contentTopic: string;
}
export interface MessagePush {
messages: WakuMessage[];
}
export interface FilterRPC {
requestId: string;
request: FilterRequest | undefined;
push: MessagePush | undefined;
}
function createBaseFilterRequest(): FilterRequest {
return { subscribe: false, topic: "", contentFilters: [] };
}
export const FilterRequest = {
encode(
message: FilterRequest,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.subscribe === true) {
writer.uint32(8).bool(message.subscribe);
}
if (message.topic !== "") {
writer.uint32(18).string(message.topic);
}
for (const v of message.contentFilters) {
FilterRequest_ContentFilter.encode(v!, writer.uint32(26).fork()).ldelim();
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): FilterRequest {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseFilterRequest();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.subscribe = reader.bool();
break;
case 2:
message.topic = reader.string();
break;
case 3:
message.contentFilters.push(
FilterRequest_ContentFilter.decode(reader, reader.uint32())
);
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): FilterRequest {
return {
subscribe: isSet(object.subscribe) ? Boolean(object.subscribe) : false,
topic: isSet(object.topic) ? String(object.topic) : "",
contentFilters: Array.isArray(object?.contentFilters)
? object.contentFilters.map((e: any) =>
FilterRequest_ContentFilter.fromJSON(e)
)
: [],
};
},
toJSON(message: FilterRequest): unknown {
const obj: any = {};
message.subscribe !== undefined && (obj.subscribe = message.subscribe);
message.topic !== undefined && (obj.topic = message.topic);
if (message.contentFilters) {
obj.contentFilters = message.contentFilters.map((e) =>
e ? FilterRequest_ContentFilter.toJSON(e) : undefined
);
} else {
obj.contentFilters = [];
}
return obj;
},
fromPartial<I extends Exact<DeepPartial<FilterRequest>, I>>(
object: I
): FilterRequest {
const message = createBaseFilterRequest();
message.subscribe = object.subscribe ?? false;
message.topic = object.topic ?? "";
message.contentFilters =
object.contentFilters?.map((e) =>
FilterRequest_ContentFilter.fromPartial(e)
) || [];
return message;
},
};
function createBaseFilterRequest_ContentFilter(): FilterRequest_ContentFilter {
return { contentTopic: "" };
}
export const FilterRequest_ContentFilter = {
encode(
message: FilterRequest_ContentFilter,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.contentTopic !== "") {
writer.uint32(10).string(message.contentTopic);
}
return writer;
},
decode(
input: _m0.Reader | Uint8Array,
length?: number
): FilterRequest_ContentFilter {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseFilterRequest_ContentFilter();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.contentTopic = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): FilterRequest_ContentFilter {
return {
contentTopic: isSet(object.contentTopic)
? String(object.contentTopic)
: "",
};
},
toJSON(message: FilterRequest_ContentFilter): unknown {
const obj: any = {};
message.contentTopic !== undefined &&
(obj.contentTopic = message.contentTopic);
return obj;
},
fromPartial<I extends Exact<DeepPartial<FilterRequest_ContentFilter>, I>>(
object: I
): FilterRequest_ContentFilter {
const message = createBaseFilterRequest_ContentFilter();
message.contentTopic = object.contentTopic ?? "";
return message;
},
};
function createBaseMessagePush(): MessagePush {
return { messages: [] };
}
export const MessagePush = {
encode(
message: MessagePush,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
for (const v of message.messages) {
WakuMessage.encode(v!, writer.uint32(10).fork()).ldelim();
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): MessagePush {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMessagePush();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.messages.push(WakuMessage.decode(reader, reader.uint32()));
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): MessagePush {
return {
messages: Array.isArray(object?.messages)
? object.messages.map((e: any) => WakuMessage.fromJSON(e))
: [],
};
},
toJSON(message: MessagePush): unknown {
const obj: any = {};
if (message.messages) {
obj.messages = message.messages.map((e) =>
e ? WakuMessage.toJSON(e) : undefined
);
} else {
obj.messages = [];
}
return obj;
},
fromPartial<I extends Exact<DeepPartial<MessagePush>, I>>(
object: I
): MessagePush {
const message = createBaseMessagePush();
message.messages =
object.messages?.map((e) => WakuMessage.fromPartial(e)) || [];
return message;
},
};
function createBaseFilterRPC(): FilterRPC {
return { requestId: "", request: undefined, push: undefined };
}
export const FilterRPC = {
encode(
message: FilterRPC,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.requestId !== "") {
writer.uint32(10).string(message.requestId);
}
if (message.request !== undefined) {
FilterRequest.encode(message.request, writer.uint32(18).fork()).ldelim();
}
if (message.push !== undefined) {
MessagePush.encode(message.push, writer.uint32(26).fork()).ldelim();
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): FilterRPC {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseFilterRPC();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.requestId = reader.string();
break;
case 2:
message.request = FilterRequest.decode(reader, reader.uint32());
break;
case 3:
message.push = MessagePush.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): FilterRPC {
return {
requestId: isSet(object.requestId) ? String(object.requestId) : "",
request: isSet(object.request)
? FilterRequest.fromJSON(object.request)
: undefined,
push: isSet(object.push) ? MessagePush.fromJSON(object.push) : undefined,
};
},
toJSON(message: FilterRPC): unknown {
const obj: any = {};
message.requestId !== undefined && (obj.requestId = message.requestId);
message.request !== undefined &&
(obj.request = message.request
? FilterRequest.toJSON(message.request)
: undefined);
message.push !== undefined &&
(obj.push = message.push ? MessagePush.toJSON(message.push) : undefined);
return obj;
},
fromPartial<I extends Exact<DeepPartial<FilterRPC>, I>>(
object: I
): FilterRPC {
const message = createBaseFilterRPC();
message.requestId = object.requestId ?? "";
message.request =
object.request !== undefined && object.request !== null
? FilterRequest.fromPartial(object.request)
: undefined;
message.push =
object.push !== undefined && object.push !== null
? MessagePush.fromPartial(object.push)
: undefined;
return message;
},
};
type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: 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>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin
? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
Exclude<keyof I, KeysOfUnion<P>>,
never
>;
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

View File

@ -1,281 +0,0 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { WakuMessage } from "../../waku/v2/message";
export const protobufPackage = "waku.v2";
export interface PushRequest {
pubSubTopic: string;
message: WakuMessage | undefined;
}
export interface PushResponse {
isSuccess: boolean;
info: string;
}
export interface PushRPC {
requestId: string;
request: PushRequest | undefined;
response: PushResponse | undefined;
}
function createBasePushRequest(): PushRequest {
return { pubSubTopic: "", message: undefined };
}
export const PushRequest = {
encode(
message: PushRequest,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.pubSubTopic !== "") {
writer.uint32(10).string(message.pubSubTopic);
}
if (message.message !== undefined) {
WakuMessage.encode(message.message, writer.uint32(18).fork()).ldelim();
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): PushRequest {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePushRequest();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.pubSubTopic = reader.string();
break;
case 2:
message.message = WakuMessage.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): PushRequest {
return {
pubSubTopic: isSet(object.pubSubTopic) ? String(object.pubSubTopic) : "",
message: isSet(object.message)
? WakuMessage.fromJSON(object.message)
: undefined,
};
},
toJSON(message: PushRequest): unknown {
const obj: any = {};
message.pubSubTopic !== undefined &&
(obj.pubSubTopic = message.pubSubTopic);
message.message !== undefined &&
(obj.message = message.message
? WakuMessage.toJSON(message.message)
: undefined);
return obj;
},
fromPartial<I extends Exact<DeepPartial<PushRequest>, I>>(
object: I
): PushRequest {
const message = createBasePushRequest();
message.pubSubTopic = object.pubSubTopic ?? "";
message.message =
object.message !== undefined && object.message !== null
? WakuMessage.fromPartial(object.message)
: undefined;
return message;
},
};
function createBasePushResponse(): PushResponse {
return { isSuccess: false, info: "" };
}
export const PushResponse = {
encode(
message: PushResponse,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.isSuccess === true) {
writer.uint32(8).bool(message.isSuccess);
}
if (message.info !== "") {
writer.uint32(18).string(message.info);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): PushResponse {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePushResponse();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.isSuccess = reader.bool();
break;
case 2:
message.info = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): PushResponse {
return {
isSuccess: isSet(object.isSuccess) ? Boolean(object.isSuccess) : false,
info: isSet(object.info) ? String(object.info) : "",
};
},
toJSON(message: PushResponse): unknown {
const obj: any = {};
message.isSuccess !== undefined && (obj.isSuccess = message.isSuccess);
message.info !== undefined && (obj.info = message.info);
return obj;
},
fromPartial<I extends Exact<DeepPartial<PushResponse>, I>>(
object: I
): PushResponse {
const message = createBasePushResponse();
message.isSuccess = object.isSuccess ?? false;
message.info = object.info ?? "";
return message;
},
};
function createBasePushRPC(): PushRPC {
return { requestId: "", request: undefined, response: undefined };
}
export const PushRPC = {
encode(
message: PushRPC,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.requestId !== "") {
writer.uint32(10).string(message.requestId);
}
if (message.request !== undefined) {
PushRequest.encode(message.request, writer.uint32(18).fork()).ldelim();
}
if (message.response !== undefined) {
PushResponse.encode(message.response, writer.uint32(26).fork()).ldelim();
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): PushRPC {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePushRPC();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.requestId = reader.string();
break;
case 2:
message.request = PushRequest.decode(reader, reader.uint32());
break;
case 3:
message.response = PushResponse.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): PushRPC {
return {
requestId: isSet(object.requestId) ? String(object.requestId) : "",
request: isSet(object.request)
? PushRequest.fromJSON(object.request)
: undefined,
response: isSet(object.response)
? PushResponse.fromJSON(object.response)
: undefined,
};
},
toJSON(message: PushRPC): unknown {
const obj: any = {};
message.requestId !== undefined && (obj.requestId = message.requestId);
message.request !== undefined &&
(obj.request = message.request
? PushRequest.toJSON(message.request)
: undefined);
message.response !== undefined &&
(obj.response = message.response
? PushResponse.toJSON(message.response)
: undefined);
return obj;
},
fromPartial<I extends Exact<DeepPartial<PushRPC>, I>>(object: I): PushRPC {
const message = createBasePushRPC();
message.requestId = object.requestId ?? "";
message.request =
object.request !== undefined && object.request !== null
? PushRequest.fromPartial(object.request)
: undefined;
message.response =
object.response !== undefined && object.response !== null
? PushResponse.fromPartial(object.response)
: undefined;
return message;
},
};
type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: 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>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin
? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
Exclude<keyof I, KeysOfUnion<P>>,
never
>;
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

View File

@ -1,200 +0,0 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
export const protobufPackage = "waku.v2";
export interface WakuMessage {
payload?: Uint8Array | undefined;
contentTopic?: string | undefined;
version?: number | undefined;
timestampDeprecated?: number | undefined;
timestamp?: Long | undefined;
}
function createBaseWakuMessage(): WakuMessage {
return {
payload: undefined,
contentTopic: undefined,
version: undefined,
timestampDeprecated: undefined,
timestamp: undefined,
};
}
export const WakuMessage = {
encode(
message: WakuMessage,
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.timestampDeprecated !== undefined) {
writer.uint32(33).double(message.timestampDeprecated);
}
if (message.timestamp !== undefined) {
writer.uint32(80).sint64(message.timestamp);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): WakuMessage {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseWakuMessage();
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.timestampDeprecated = reader.double();
break;
case 10:
message.timestamp = reader.sint64() as Long;
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): WakuMessage {
return {
payload: isSet(object.payload)
? bytesFromBase64(object.payload)
: undefined,
contentTopic: isSet(object.contentTopic)
? String(object.contentTopic)
: undefined,
version: isSet(object.version) ? Number(object.version) : undefined,
timestampDeprecated: isSet(object.timestampDeprecated)
? Number(object.timestampDeprecated)
: undefined,
timestamp: isSet(object.timestamp)
? Long.fromString(object.timestamp)
: undefined,
};
},
toJSON(message: WakuMessage): 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 = Math.round(message.version));
message.timestampDeprecated !== undefined &&
(obj.timestampDeprecated = message.timestampDeprecated);
message.timestamp !== undefined &&
(obj.timestamp = (message.timestamp || undefined).toString());
return obj;
},
fromPartial<I extends Exact<DeepPartial<WakuMessage>, I>>(
object: I
): WakuMessage {
const message = createBaseWakuMessage();
message.payload = object.payload ?? undefined;
message.contentTopic = object.contentTopic ?? undefined;
message.version = object.version ?? undefined;
message.timestampDeprecated = object.timestampDeprecated ?? undefined;
message.timestamp =
object.timestamp !== undefined && object.timestamp !== null
? Long.fromValue(object.timestamp)
: undefined;
return message;
},
};
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: 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 (const byte of arr) {
bin.push(String.fromCharCode(byte));
}
return btoa(bin.join(""));
}
type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: 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>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin
? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
Exclude<keyof I, KeysOfUnion<P>>,
never
>;
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

View File

@ -1,704 +0,0 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { WakuMessage } from "../../../../waku/v2/message";
export const protobufPackage = "waku.v2.store.v2beta3";
export interface Index {
digest: Uint8Array;
receivedTime: number;
senderTime: number;
}
export interface PagingInfo {
pageSize: Long;
cursor: Index | undefined;
direction: PagingInfo_Direction;
}
export enum PagingInfo_Direction {
DIRECTION_BACKWARD_UNSPECIFIED = 0,
DIRECTION_FORWARD = 1,
UNRECOGNIZED = -1,
}
export function pagingInfo_DirectionFromJSON(
object: any
): PagingInfo_Direction {
switch (object) {
case 0:
case "DIRECTION_BACKWARD_UNSPECIFIED":
return PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED;
case 1:
case "DIRECTION_FORWARD":
return PagingInfo_Direction.DIRECTION_FORWARD;
case -1:
case "UNRECOGNIZED":
default:
return PagingInfo_Direction.UNRECOGNIZED;
}
}
export function pagingInfo_DirectionToJSON(
object: PagingInfo_Direction
): string {
switch (object) {
case PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED:
return "DIRECTION_BACKWARD_UNSPECIFIED";
case PagingInfo_Direction.DIRECTION_FORWARD:
return "DIRECTION_FORWARD";
default:
return "UNKNOWN";
}
}
export interface ContentFilter {
contentTopic: string;
}
export interface HistoryQuery {
pubSubTopic?: string | undefined;
contentFilters: ContentFilter[];
pagingInfo?: PagingInfo | undefined;
startTime?: number | undefined;
endTime?: number | undefined;
}
export interface HistoryResponse {
messages: WakuMessage[];
pagingInfo: PagingInfo | undefined;
error: HistoryResponse_Error;
}
export enum HistoryResponse_Error {
ERROR_NONE_UNSPECIFIED = 0,
ERROR_INVALID_CURSOR = 1,
UNRECOGNIZED = -1,
}
export function historyResponse_ErrorFromJSON(
object: any
): HistoryResponse_Error {
switch (object) {
case 0:
case "ERROR_NONE_UNSPECIFIED":
return HistoryResponse_Error.ERROR_NONE_UNSPECIFIED;
case 1:
case "ERROR_INVALID_CURSOR":
return HistoryResponse_Error.ERROR_INVALID_CURSOR;
case -1:
case "UNRECOGNIZED":
default:
return HistoryResponse_Error.UNRECOGNIZED;
}
}
export function historyResponse_ErrorToJSON(
object: HistoryResponse_Error
): string {
switch (object) {
case HistoryResponse_Error.ERROR_NONE_UNSPECIFIED:
return "ERROR_NONE_UNSPECIFIED";
case HistoryResponse_Error.ERROR_INVALID_CURSOR:
return "ERROR_INVALID_CURSOR";
default:
return "UNKNOWN";
}
}
export interface HistoryRPC {
requestId: string;
query: HistoryQuery | undefined;
response: HistoryResponse | undefined;
}
function createBaseIndex(): Index {
return { digest: new Uint8Array(), receivedTime: 0, senderTime: 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);
}
if (message.senderTime !== 0) {
writer.uint32(25).double(message.senderTime);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): Index {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseIndex();
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;
case 3:
message.senderTime = reader.double();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): Index {
return {
digest: isSet(object.digest)
? bytesFromBase64(object.digest)
: new Uint8Array(),
receivedTime: isSet(object.receivedTime)
? Number(object.receivedTime)
: 0,
senderTime: isSet(object.senderTime) ? Number(object.senderTime) : 0,
};
},
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);
message.senderTime !== undefined && (obj.senderTime = message.senderTime);
return obj;
},
fromPartial<I extends Exact<DeepPartial<Index>, I>>(object: I): Index {
const message = createBaseIndex();
message.digest = object.digest ?? new Uint8Array();
message.receivedTime = object.receivedTime ?? 0;
message.senderTime = object.senderTime ?? 0;
return message;
},
};
function createBasePagingInfo(): PagingInfo {
return { pageSize: Long.UZERO, cursor: undefined, direction: 0 };
}
export const PagingInfo = {
encode(
message: PagingInfo,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (!message.pageSize.isZero()) {
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 _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePagingInfo();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.pageSize = 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 {
return {
pageSize: isSet(object.pageSize)
? Long.fromString(object.pageSize)
: Long.UZERO,
cursor: isSet(object.cursor) ? Index.fromJSON(object.cursor) : undefined,
direction: isSet(object.direction)
? pagingInfo_DirectionFromJSON(object.direction)
: 0,
};
},
toJSON(message: PagingInfo): unknown {
const obj: any = {};
message.pageSize !== undefined &&
(obj.pageSize = (message.pageSize || Long.UZERO).toString());
message.cursor !== undefined &&
(obj.cursor = message.cursor ? Index.toJSON(message.cursor) : undefined);
message.direction !== undefined &&
(obj.direction = pagingInfo_DirectionToJSON(message.direction));
return obj;
},
fromPartial<I extends Exact<DeepPartial<PagingInfo>, I>>(
object: I
): PagingInfo {
const message = createBasePagingInfo();
message.pageSize =
object.pageSize !== undefined && object.pageSize !== null
? Long.fromValue(object.pageSize)
: Long.UZERO;
message.cursor =
object.cursor !== undefined && object.cursor !== null
? Index.fromPartial(object.cursor)
: undefined;
message.direction = object.direction ?? 0;
return message;
},
};
function createBaseContentFilter(): ContentFilter {
return { contentTopic: "" };
}
export const ContentFilter = {
encode(
message: ContentFilter,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.contentTopic !== "") {
writer.uint32(10).string(message.contentTopic);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): ContentFilter {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseContentFilter();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.contentTopic = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): ContentFilter {
return {
contentTopic: isSet(object.contentTopic)
? String(object.contentTopic)
: "",
};
},
toJSON(message: ContentFilter): unknown {
const obj: any = {};
message.contentTopic !== undefined &&
(obj.contentTopic = message.contentTopic);
return obj;
},
fromPartial<I extends Exact<DeepPartial<ContentFilter>, I>>(
object: I
): ContentFilter {
const message = createBaseContentFilter();
message.contentTopic = object.contentTopic ?? "";
return message;
},
};
function createBaseHistoryQuery(): HistoryQuery {
return {
pubSubTopic: undefined,
contentFilters: [],
pagingInfo: undefined,
startTime: undefined,
endTime: undefined,
};
}
export const HistoryQuery = {
encode(
message: HistoryQuery,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.pubSubTopic !== undefined) {
writer.uint32(18).string(message.pubSubTopic);
}
for (const v of message.contentFilters) {
ContentFilter.encode(v!, writer.uint32(26).fork()).ldelim();
}
if (message.pagingInfo !== undefined) {
PagingInfo.encode(message.pagingInfo, writer.uint32(34).fork()).ldelim();
}
if (message.startTime !== undefined) {
writer.uint32(41).double(message.startTime);
}
if (message.endTime !== undefined) {
writer.uint32(49).double(message.endTime);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): HistoryQuery {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseHistoryQuery();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 2:
message.pubSubTopic = reader.string();
break;
case 3:
message.contentFilters.push(
ContentFilter.decode(reader, reader.uint32())
);
break;
case 4:
message.pagingInfo = PagingInfo.decode(reader, reader.uint32());
break;
case 5:
message.startTime = reader.double();
break;
case 6:
message.endTime = reader.double();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): HistoryQuery {
return {
pubSubTopic: isSet(object.pubSubTopic)
? String(object.pubSubTopic)
: undefined,
contentFilters: Array.isArray(object?.contentFilters)
? object.contentFilters.map((e: any) => ContentFilter.fromJSON(e))
: [],
pagingInfo: isSet(object.pagingInfo)
? PagingInfo.fromJSON(object.pagingInfo)
: undefined,
startTime: isSet(object.startTime) ? Number(object.startTime) : undefined,
endTime: isSet(object.endTime) ? Number(object.endTime) : undefined,
};
},
toJSON(message: HistoryQuery): unknown {
const obj: any = {};
message.pubSubTopic !== undefined &&
(obj.pubSubTopic = message.pubSubTopic);
if (message.contentFilters) {
obj.contentFilters = message.contentFilters.map((e) =>
e ? ContentFilter.toJSON(e) : undefined
);
} else {
obj.contentFilters = [];
}
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<I extends Exact<DeepPartial<HistoryQuery>, I>>(
object: I
): HistoryQuery {
const message = createBaseHistoryQuery();
message.pubSubTopic = object.pubSubTopic ?? undefined;
message.contentFilters =
object.contentFilters?.map((e) => ContentFilter.fromPartial(e)) || [];
message.pagingInfo =
object.pagingInfo !== undefined && object.pagingInfo !== null
? PagingInfo.fromPartial(object.pagingInfo)
: undefined;
message.startTime = object.startTime ?? undefined;
message.endTime = object.endTime ?? undefined;
return message;
},
};
function createBaseHistoryResponse(): HistoryResponse {
return { messages: [], pagingInfo: undefined, error: 0 };
}
export const HistoryResponse = {
encode(
message: HistoryResponse,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
for (const v of message.messages) {
WakuMessage.encode(v!, writer.uint32(18).fork()).ldelim();
}
if (message.pagingInfo !== undefined) {
PagingInfo.encode(message.pagingInfo, writer.uint32(26).fork()).ldelim();
}
if (message.error !== 0) {
writer.uint32(32).int32(message.error);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): HistoryResponse {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseHistoryResponse();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 2:
message.messages.push(WakuMessage.decode(reader, reader.uint32()));
break;
case 3:
message.pagingInfo = PagingInfo.decode(reader, reader.uint32());
break;
case 4:
message.error = reader.int32() as any;
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): HistoryResponse {
return {
messages: Array.isArray(object?.messages)
? object.messages.map((e: any) => WakuMessage.fromJSON(e))
: [],
pagingInfo: isSet(object.pagingInfo)
? PagingInfo.fromJSON(object.pagingInfo)
: undefined,
error: isSet(object.error)
? historyResponse_ErrorFromJSON(object.error)
: 0,
};
},
toJSON(message: HistoryResponse): unknown {
const obj: any = {};
if (message.messages) {
obj.messages = message.messages.map((e) =>
e ? WakuMessage.toJSON(e) : undefined
);
} else {
obj.messages = [];
}
message.pagingInfo !== undefined &&
(obj.pagingInfo = message.pagingInfo
? PagingInfo.toJSON(message.pagingInfo)
: undefined);
message.error !== undefined &&
(obj.error = historyResponse_ErrorToJSON(message.error));
return obj;
},
fromPartial<I extends Exact<DeepPartial<HistoryResponse>, I>>(
object: I
): HistoryResponse {
const message = createBaseHistoryResponse();
message.messages =
object.messages?.map((e) => WakuMessage.fromPartial(e)) || [];
message.pagingInfo =
object.pagingInfo !== undefined && object.pagingInfo !== null
? PagingInfo.fromPartial(object.pagingInfo)
: undefined;
message.error = object.error ?? 0;
return message;
},
};
function createBaseHistoryRPC(): HistoryRPC {
return { requestId: "", query: undefined, response: undefined };
}
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 _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseHistoryRPC();
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 {
return {
requestId: isSet(object.requestId) ? String(object.requestId) : "",
query: isSet(object.query)
? HistoryQuery.fromJSON(object.query)
: undefined,
response: isSet(object.response)
? HistoryResponse.fromJSON(object.response)
: undefined,
};
},
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<I extends Exact<DeepPartial<HistoryRPC>, I>>(
object: I
): HistoryRPC {
const message = createBaseHistoryRPC();
message.requestId = object.requestId ?? "";
message.query =
object.query !== undefined && object.query !== null
? HistoryQuery.fromPartial(object.query)
: undefined;
message.response =
object.response !== undefined && object.response !== null
? HistoryResponse.fromPartial(object.response)
: undefined;
return message;
},
};
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: 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 (const byte of arr) {
bin.push(String.fromCharCode(byte));
}
return btoa(bin.join(""));
}
type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: 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>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin
? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
Exclude<keyof I, KeysOfUnion<P>>,
never
>;
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

View File

@ -1,741 +0,0 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { WakuMessage } from "../../../../waku/v2/message";
export const protobufPackage = "waku.v2.store.v2beta4";
export interface Index {
digest: Uint8Array;
receivedTime: Long;
senderTime: Long;
pubsubTopic: string;
}
export interface PagingInfo {
pageSize: Long;
cursor: Index | undefined;
direction: PagingInfo_Direction;
}
export enum PagingInfo_Direction {
DIRECTION_BACKWARD_UNSPECIFIED = 0,
DIRECTION_FORWARD = 1,
UNRECOGNIZED = -1,
}
export function pagingInfo_DirectionFromJSON(
object: any
): PagingInfo_Direction {
switch (object) {
case 0:
case "DIRECTION_BACKWARD_UNSPECIFIED":
return PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED;
case 1:
case "DIRECTION_FORWARD":
return PagingInfo_Direction.DIRECTION_FORWARD;
case -1:
case "UNRECOGNIZED":
default:
return PagingInfo_Direction.UNRECOGNIZED;
}
}
export function pagingInfo_DirectionToJSON(
object: PagingInfo_Direction
): string {
switch (object) {
case PagingInfo_Direction.DIRECTION_BACKWARD_UNSPECIFIED:
return "DIRECTION_BACKWARD_UNSPECIFIED";
case PagingInfo_Direction.DIRECTION_FORWARD:
return "DIRECTION_FORWARD";
default:
return "UNKNOWN";
}
}
export interface ContentFilter {
contentTopic: string;
}
export interface HistoryQuery {
pubSubTopic?: string | undefined;
contentFilters: ContentFilter[];
pagingInfo?: PagingInfo | undefined;
startTime?: Long | undefined;
endTime?: Long | undefined;
}
export interface HistoryResponse {
messages: WakuMessage[];
pagingInfo: PagingInfo | undefined;
error: HistoryResponse_Error;
}
export enum HistoryResponse_Error {
ERROR_NONE_UNSPECIFIED = 0,
ERROR_INVALID_CURSOR = 1,
UNRECOGNIZED = -1,
}
export function historyResponse_ErrorFromJSON(
object: any
): HistoryResponse_Error {
switch (object) {
case 0:
case "ERROR_NONE_UNSPECIFIED":
return HistoryResponse_Error.ERROR_NONE_UNSPECIFIED;
case 1:
case "ERROR_INVALID_CURSOR":
return HistoryResponse_Error.ERROR_INVALID_CURSOR;
case -1:
case "UNRECOGNIZED":
default:
return HistoryResponse_Error.UNRECOGNIZED;
}
}
export function historyResponse_ErrorToJSON(
object: HistoryResponse_Error
): string {
switch (object) {
case HistoryResponse_Error.ERROR_NONE_UNSPECIFIED:
return "ERROR_NONE_UNSPECIFIED";
case HistoryResponse_Error.ERROR_INVALID_CURSOR:
return "ERROR_INVALID_CURSOR";
default:
return "UNKNOWN";
}
}
export interface HistoryRPC {
requestId: string;
query: HistoryQuery | undefined;
response: HistoryResponse | undefined;
}
function createBaseIndex(): Index {
return {
digest: new Uint8Array(),
receivedTime: Long.ZERO,
senderTime: Long.ZERO,
pubsubTopic: "",
};
}
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.isZero()) {
writer.uint32(16).sint64(message.receivedTime);
}
if (!message.senderTime.isZero()) {
writer.uint32(24).sint64(message.senderTime);
}
if (message.pubsubTopic !== "") {
writer.uint32(34).string(message.pubsubTopic);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): Index {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseIndex();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.digest = reader.bytes();
break;
case 2:
message.receivedTime = reader.sint64() as Long;
break;
case 3:
message.senderTime = reader.sint64() as Long;
break;
case 4:
message.pubsubTopic = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): Index {
return {
digest: isSet(object.digest)
? bytesFromBase64(object.digest)
: new Uint8Array(),
receivedTime: isSet(object.receivedTime)
? Long.fromString(object.receivedTime)
: Long.ZERO,
senderTime: isSet(object.senderTime)
? Long.fromString(object.senderTime)
: Long.ZERO,
pubsubTopic: isSet(object.pubsubTopic) ? String(object.pubsubTopic) : "",
};
},
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 || Long.ZERO).toString());
message.senderTime !== undefined &&
(obj.senderTime = (message.senderTime || Long.ZERO).toString());
message.pubsubTopic !== undefined &&
(obj.pubsubTopic = message.pubsubTopic);
return obj;
},
fromPartial<I extends Exact<DeepPartial<Index>, I>>(object: I): Index {
const message = createBaseIndex();
message.digest = object.digest ?? new Uint8Array();
message.receivedTime =
object.receivedTime !== undefined && object.receivedTime !== null
? Long.fromValue(object.receivedTime)
: Long.ZERO;
message.senderTime =
object.senderTime !== undefined && object.senderTime !== null
? Long.fromValue(object.senderTime)
: Long.ZERO;
message.pubsubTopic = object.pubsubTopic ?? "";
return message;
},
};
function createBasePagingInfo(): PagingInfo {
return { pageSize: Long.UZERO, cursor: undefined, direction: 0 };
}
export const PagingInfo = {
encode(
message: PagingInfo,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (!message.pageSize.isZero()) {
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 _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePagingInfo();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.pageSize = 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 {
return {
pageSize: isSet(object.pageSize)
? Long.fromString(object.pageSize)
: Long.UZERO,
cursor: isSet(object.cursor) ? Index.fromJSON(object.cursor) : undefined,
direction: isSet(object.direction)
? pagingInfo_DirectionFromJSON(object.direction)
: 0,
};
},
toJSON(message: PagingInfo): unknown {
const obj: any = {};
message.pageSize !== undefined &&
(obj.pageSize = (message.pageSize || Long.UZERO).toString());
message.cursor !== undefined &&
(obj.cursor = message.cursor ? Index.toJSON(message.cursor) : undefined);
message.direction !== undefined &&
(obj.direction = pagingInfo_DirectionToJSON(message.direction));
return obj;
},
fromPartial<I extends Exact<DeepPartial<PagingInfo>, I>>(
object: I
): PagingInfo {
const message = createBasePagingInfo();
message.pageSize =
object.pageSize !== undefined && object.pageSize !== null
? Long.fromValue(object.pageSize)
: Long.UZERO;
message.cursor =
object.cursor !== undefined && object.cursor !== null
? Index.fromPartial(object.cursor)
: undefined;
message.direction = object.direction ?? 0;
return message;
},
};
function createBaseContentFilter(): ContentFilter {
return { contentTopic: "" };
}
export const ContentFilter = {
encode(
message: ContentFilter,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.contentTopic !== "") {
writer.uint32(10).string(message.contentTopic);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): ContentFilter {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseContentFilter();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.contentTopic = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): ContentFilter {
return {
contentTopic: isSet(object.contentTopic)
? String(object.contentTopic)
: "",
};
},
toJSON(message: ContentFilter): unknown {
const obj: any = {};
message.contentTopic !== undefined &&
(obj.contentTopic = message.contentTopic);
return obj;
},
fromPartial<I extends Exact<DeepPartial<ContentFilter>, I>>(
object: I
): ContentFilter {
const message = createBaseContentFilter();
message.contentTopic = object.contentTopic ?? "";
return message;
},
};
function createBaseHistoryQuery(): HistoryQuery {
return {
pubSubTopic: undefined,
contentFilters: [],
pagingInfo: undefined,
startTime: undefined,
endTime: undefined,
};
}
export const HistoryQuery = {
encode(
message: HistoryQuery,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.pubSubTopic !== undefined) {
writer.uint32(18).string(message.pubSubTopic);
}
for (const v of message.contentFilters) {
ContentFilter.encode(v!, writer.uint32(26).fork()).ldelim();
}
if (message.pagingInfo !== undefined) {
PagingInfo.encode(message.pagingInfo, writer.uint32(34).fork()).ldelim();
}
if (message.startTime !== undefined) {
writer.uint32(40).sint64(message.startTime);
}
if (message.endTime !== undefined) {
writer.uint32(48).sint64(message.endTime);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): HistoryQuery {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseHistoryQuery();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 2:
message.pubSubTopic = reader.string();
break;
case 3:
message.contentFilters.push(
ContentFilter.decode(reader, reader.uint32())
);
break;
case 4:
message.pagingInfo = PagingInfo.decode(reader, reader.uint32());
break;
case 5:
message.startTime = reader.sint64() as Long;
break;
case 6:
message.endTime = reader.sint64() as Long;
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): HistoryQuery {
return {
pubSubTopic: isSet(object.pubSubTopic)
? String(object.pubSubTopic)
: undefined,
contentFilters: Array.isArray(object?.contentFilters)
? object.contentFilters.map((e: any) => ContentFilter.fromJSON(e))
: [],
pagingInfo: isSet(object.pagingInfo)
? PagingInfo.fromJSON(object.pagingInfo)
: undefined,
startTime: isSet(object.startTime)
? Long.fromString(object.startTime)
: undefined,
endTime: isSet(object.endTime)
? Long.fromString(object.endTime)
: undefined,
};
},
toJSON(message: HistoryQuery): unknown {
const obj: any = {};
message.pubSubTopic !== undefined &&
(obj.pubSubTopic = message.pubSubTopic);
if (message.contentFilters) {
obj.contentFilters = message.contentFilters.map((e) =>
e ? ContentFilter.toJSON(e) : undefined
);
} else {
obj.contentFilters = [];
}
message.pagingInfo !== undefined &&
(obj.pagingInfo = message.pagingInfo
? PagingInfo.toJSON(message.pagingInfo)
: undefined);
message.startTime !== undefined &&
(obj.startTime = (message.startTime || undefined).toString());
message.endTime !== undefined &&
(obj.endTime = (message.endTime || undefined).toString());
return obj;
},
fromPartial<I extends Exact<DeepPartial<HistoryQuery>, I>>(
object: I
): HistoryQuery {
const message = createBaseHistoryQuery();
message.pubSubTopic = object.pubSubTopic ?? undefined;
message.contentFilters =
object.contentFilters?.map((e) => ContentFilter.fromPartial(e)) || [];
message.pagingInfo =
object.pagingInfo !== undefined && object.pagingInfo !== null
? PagingInfo.fromPartial(object.pagingInfo)
: undefined;
message.startTime =
object.startTime !== undefined && object.startTime !== null
? Long.fromValue(object.startTime)
: undefined;
message.endTime =
object.endTime !== undefined && object.endTime !== null
? Long.fromValue(object.endTime)
: undefined;
return message;
},
};
function createBaseHistoryResponse(): HistoryResponse {
return { messages: [], pagingInfo: undefined, error: 0 };
}
export const HistoryResponse = {
encode(
message: HistoryResponse,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
for (const v of message.messages) {
WakuMessage.encode(v!, writer.uint32(18).fork()).ldelim();
}
if (message.pagingInfo !== undefined) {
PagingInfo.encode(message.pagingInfo, writer.uint32(26).fork()).ldelim();
}
if (message.error !== 0) {
writer.uint32(32).int32(message.error);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): HistoryResponse {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseHistoryResponse();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 2:
message.messages.push(WakuMessage.decode(reader, reader.uint32()));
break;
case 3:
message.pagingInfo = PagingInfo.decode(reader, reader.uint32());
break;
case 4:
message.error = reader.int32() as any;
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): HistoryResponse {
return {
messages: Array.isArray(object?.messages)
? object.messages.map((e: any) => WakuMessage.fromJSON(e))
: [],
pagingInfo: isSet(object.pagingInfo)
? PagingInfo.fromJSON(object.pagingInfo)
: undefined,
error: isSet(object.error)
? historyResponse_ErrorFromJSON(object.error)
: 0,
};
},
toJSON(message: HistoryResponse): unknown {
const obj: any = {};
if (message.messages) {
obj.messages = message.messages.map((e) =>
e ? WakuMessage.toJSON(e) : undefined
);
} else {
obj.messages = [];
}
message.pagingInfo !== undefined &&
(obj.pagingInfo = message.pagingInfo
? PagingInfo.toJSON(message.pagingInfo)
: undefined);
message.error !== undefined &&
(obj.error = historyResponse_ErrorToJSON(message.error));
return obj;
},
fromPartial<I extends Exact<DeepPartial<HistoryResponse>, I>>(
object: I
): HistoryResponse {
const message = createBaseHistoryResponse();
message.messages =
object.messages?.map((e) => WakuMessage.fromPartial(e)) || [];
message.pagingInfo =
object.pagingInfo !== undefined && object.pagingInfo !== null
? PagingInfo.fromPartial(object.pagingInfo)
: undefined;
message.error = object.error ?? 0;
return message;
},
};
function createBaseHistoryRPC(): HistoryRPC {
return { requestId: "", query: undefined, response: undefined };
}
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 _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseHistoryRPC();
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 {
return {
requestId: isSet(object.requestId) ? String(object.requestId) : "",
query: isSet(object.query)
? HistoryQuery.fromJSON(object.query)
: undefined,
response: isSet(object.response)
? HistoryResponse.fromJSON(object.response)
: undefined,
};
},
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<I extends Exact<DeepPartial<HistoryRPC>, I>>(
object: I
): HistoryRPC {
const message = createBaseHistoryRPC();
message.requestId = object.requestId ?? "";
message.query =
object.query !== undefined && object.query !== null
? HistoryQuery.fromPartial(object.query)
: undefined;
message.response =
object.response !== undefined && object.response !== null
? HistoryResponse.fromPartial(object.response)
: undefined;
return message;
},
};
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: 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 (const byte of arr) {
bin.push(String.fromCharCode(byte));
}
return btoa(bin.join(""));
}
type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: 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>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin
? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<
Exclude<keyof I, KeysOfUnion<P>>,
never
>;
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

View File

@ -14,7 +14,7 @@ import portfinder from "portfinder";
import { DefaultPubSubTopic } from "../lib/constants";
import { hexToBytes } from "../lib/utils";
import { WakuMessage } from "../lib/waku_message";
import * as proto from "../proto/waku/v2/message";
import * as proto from "../proto/message";
import { existsAsync, mkdirAsync, openAsync } from "./async_fs";
import waitForLine from "./log_file";
@ -88,7 +88,7 @@ export class Nwaku {
let timestamp;
if (message.proto.timestamp) {
timestamp = message.proto.timestamp.toNumber();
timestamp = Number.parseInt(message.proto.timestamp.toString(10));
}
return {

View File

@ -3,5 +3,5 @@
"compilerOptions": {
"noEmit": true
},
"exclude": ["node_modules/**"]
"exclude": []
}

View File

@ -2,10 +2,10 @@
"compilerOptions": {
"incremental": true,
"target": "es2020",
"outDir": "build/main",
"outDir": "dist/esm",
"rootDir": "src",
"moduleResolution": "node",
"module": "commonjs",
"module": "es2020",
"declaration": true,
"sourceMap": true,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
@ -45,8 +45,8 @@
"types": ["node", "mocha"],
"typeRoots": ["node_modules/@types", "src/types"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules/**", "src/**/*.spec.ts", "src/test_utils"],
"include": ["src"],
"exclude": ["src/**/*.spec.ts", "src/test_utils"],
"compileOnSave": false,
"ts-node": {
"files": true

View File

@ -1,10 +0,0 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "UMD",
"target": "es6",
"removeComments": true,
"outFile": "build/min.js"
},
"exclude": ["node_modules/**", "src/**/*.spec.ts", "src/test_utils"]
}

View File

@ -1,38 +0,0 @@
const webpack = require('webpack');
const path = require('path');
module.exports = {
mode: 'development',
entry: {
"js-waku": './src/index.ts'
},
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}]
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
})
],
resolve: {
extensions: ['.ts', '.js'],
fallback: {
buffer: require.resolve('buffer/'),
crypto: false,
stream: require.resolve('stream-browserify'),
},
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'build/umd'),
library: 'jswaku',
libraryTarget: 'umd',
globalObject: 'this',
}
};

50
webpack.config.cjs Normal file
View File

@ -0,0 +1,50 @@
const webpack = require("webpack");
const path = require("path");
module.exports = {
mode: "development",
entry: {
"js-waku": "./src/index.ts",
},
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.(js|tsx?)$/,
use: "ts-loader",
exclude: /(node_modules)|(node\.spec\.ts)/,
},
{
test: /node\.spec\.ts$/,
use: "ignore-loader",
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser.js",
Buffer: ["buffer", "Buffer"],
}),
],
resolve: {
extensions: [".ts", ".js"],
fallback: {
buffer: require.resolve("buffer/"),
crypto: false,
stream: require.resolve("stream-browserify"),
},
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "build/umd"),
library: "jswaku",
libraryTarget: "umd",
globalObject: "this",
},
optimization: {
splitChunks: {
name: "vendors",
chunks: "all",
},
},
};

View File

@ -1,44 +0,0 @@
const webpack = require('webpack');
const path = require('path');
module.exports = {
mode: 'development',
entry: {
"js-waku": './src/index.ts'
},
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}]
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
})
],
resolve: {
extensions: ['.ts', '.js'],
fallback: {
buffer: require.resolve('buffer/'),
crypto: false,
stream: require.resolve('stream-browserify'),
},
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build/umd'),
library: 'jswaku',
libraryTarget: 'umd',
globalObject: 'this',
},
optimization: {
splitChunks: {
name: 'vendors',
chunks: 'all',
}
}
};

View File

@ -1,38 +0,0 @@
const webpack = require('webpack');
const path = require('path');
module.exports = {
mode: 'production',
entry: {
"js-waku": './src/index.ts'
},
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}]
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
})
],
resolve: {
extensions: ['.ts', '.js'],
fallback: {
buffer: require.resolve('buffer/'),
crypto: false,
stream: require.resolve('stream-browserify'),
},
},
output: {
filename: '[name].min.bundle.js',
path: path.resolve(__dirname, 'build/umd'),
library: 'jswaku',
libraryTarget: 'umd',
globalObject: 'this',
}
};

44
webpack.config.min.js vendored
View File

@ -1,44 +0,0 @@
const webpack = require('webpack');
const path = require('path');
module.exports = {
mode: 'production',
entry: {
"js-waku": './src/index.ts'
},
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}]
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
})
],
resolve: {
extensions: ['.ts', '.js'],
fallback: {
buffer: require.resolve('buffer/'),
crypto: false,
stream: require.resolve('stream-browserify'),
},
},
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, 'build/umd'),
library: 'jswaku',
libraryTarget: 'umd',
globalObject: 'this',
},
optimization: {
splitChunks: {
name: 'vendors',
chunks: 'all',
}
}
};

40
webpack.umd.config.cjs Normal file
View File

@ -0,0 +1,40 @@
const webpack = require("webpack");
const path = require("path");
module.exports = {
mode: "production",
entry: {
"js-waku": "./src/index.ts",
},
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser.js",
Buffer: ["buffer", "Buffer"],
}),
],
resolve: {
extensions: [".ts", ".js"],
fallback: {
buffer: require.resolve("buffer/"),
crypto: false,
stream: require.resolve("stream-browserify"),
},
},
output: {
filename: "index.js",
path: path.resolve(__dirname, "dist/umd"),
library: "waku",
libraryTarget: "umd",
globalObject: "this",
},
};