mirror of https://github.com/status-im/js-waku.git
Merge #116
116: Add few tsconfig rules r=D4nte a=D4nte Co-authored-by: Franck Royer <franck@status.im>
This commit is contained in:
commit
abbbd50512
|
@ -15,6 +15,7 @@
|
|||
],
|
||||
"globals": { "BigInt": true, "console": true, "WebAssembly": true },
|
||||
"rules": {
|
||||
"@typescript-eslint/explicit-function-return-type": ["error"],
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"eslint-comments/disable-enable-pair": [
|
||||
"error",
|
||||
|
@ -30,5 +31,13 @@
|
|||
"error",
|
||||
{ "ignoreDeclarationSort": true, "ignoreCase": true }
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.spec.ts", "**/test_utils/*.ts"],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-non-null-assertion": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
"dbaeumer.vscode-eslint",
|
||||
"esbenp.prettier-vscode",
|
||||
"eamodio.gitlens",
|
||||
"streetsidesoftware.code-spell-checker",
|
||||
"streetsidesoftware.code-spell-checker"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -25,5 +25,6 @@
|
|||
"outputCapture": "std",
|
||||
"skipFiles": ["<node_internals>/**/*.js"]
|
||||
// "smartStep": true
|
||||
}]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"build:main": "tsc -p tsconfig.json",
|
||||
"build:module": "tsc -p tsconfig.module.json",
|
||||
"fix": "run-s fix:*",
|
||||
"fix:prettier": "prettier \"src/**/*.ts\" --write",
|
||||
"fix:prettier": "prettier \"src/**/*.ts\" \"./*.json\" --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",
|
||||
|
@ -22,7 +22,7 @@
|
|||
"chat": "ts-node src/chat/index.ts",
|
||||
"test": "run-s build test:*",
|
||||
"test:lint": "eslint src --ext .ts",
|
||||
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
||||
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" --list-different",
|
||||
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
||||
"test:unit": "nyc --silent mocha --exit # TODO: Remove `--exit` and fix hanging processes",
|
||||
"proto": "run-s proto:*",
|
||||
|
|
|
@ -13,7 +13,7 @@ import { ChatMessage } from './chat_message';
|
|||
|
||||
const ChatContentTopic = 'dingpu';
|
||||
|
||||
(async function () {
|
||||
(async function (): Promise<void> {
|
||||
const opts = processArguments();
|
||||
|
||||
const waku = await Waku.create({
|
||||
|
@ -124,7 +124,7 @@ function processArguments(): Options {
|
|||
return opts;
|
||||
}
|
||||
|
||||
function printMessage(chatMsg: ChatMessage) {
|
||||
function printMessage(chatMsg: ChatMessage): void {
|
||||
const timestamp = chatMsg.timestamp.toLocaleString([], {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export function delay(ms: number) {
|
||||
export function delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
|
|
@ -98,16 +98,21 @@ export default class Waku {
|
|||
* Dials to the provided peer.
|
||||
* @param peer The peer to dial
|
||||
*/
|
||||
async dial(peer: PeerId | Multiaddr | string) {
|
||||
await this.libp2p.dialProtocol(peer, [RelayCodec, StoreCodec]);
|
||||
async dial(
|
||||
peer: PeerId | Multiaddr | string
|
||||
): Promise<{
|
||||
stream: import('libp2p-interfaces/src/stream-muxer/types').MuxedStream;
|
||||
protocol: string;
|
||||
}> {
|
||||
return this.libp2p.dialProtocol(peer, [RelayCodec, StoreCodec]);
|
||||
}
|
||||
|
||||
addPeerToAddressBook(peerId: PeerId, multiaddr: Multiaddr[]) {
|
||||
addPeerToAddressBook(peerId: PeerId, multiaddr: Multiaddr[]): void {
|
||||
this.libp2p.peerStore.addressBook.set(peerId, multiaddr);
|
||||
}
|
||||
|
||||
async stop() {
|
||||
await this.libp2p.stop();
|
||||
async stop(): Promise<void> {
|
||||
return this.libp2p.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@ export function getRelayPeers(
|
|||
router: Gossipsub,
|
||||
topic: string,
|
||||
count: number,
|
||||
filter: (id: string) => boolean = () => true
|
||||
filter: (id: string) => boolean = (): boolean => true
|
||||
): Set<string> {
|
||||
const peersInTopic = router.topics.get(topic);
|
||||
if (!peersInTopic) {
|
||||
|
|
|
@ -32,10 +32,7 @@ describe('Waku Relay', () => {
|
|||
}),
|
||||
]);
|
||||
|
||||
await waku1.addPeerToAddressBook(
|
||||
waku2.libp2p.peerId,
|
||||
waku2.libp2p.multiaddrs
|
||||
);
|
||||
waku1.addPeerToAddressBook(waku2.libp2p.peerId, waku2.libp2p.multiaddrs);
|
||||
|
||||
await Promise.all([
|
||||
new Promise((resolve) =>
|
||||
|
@ -133,7 +130,7 @@ describe('Waku Relay', () => {
|
|||
|
||||
await waku.relay.send(message);
|
||||
|
||||
let msgs = [];
|
||||
let msgs: WakuMessage[] = [];
|
||||
|
||||
while (msgs.length === 0) {
|
||||
await delay(200);
|
||||
|
@ -143,7 +140,7 @@ describe('Waku Relay', () => {
|
|||
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
|
||||
expect(msgs[0].version).to.equal(message.version);
|
||||
|
||||
const payload = Buffer.from(msgs[0].payload);
|
||||
const payload = Buffer.from(msgs[0].payload!);
|
||||
expect(Buffer.compare(payload, message.payload!)).to.equal(0);
|
||||
});
|
||||
|
||||
|
@ -216,7 +213,7 @@ describe('Waku Relay', () => {
|
|||
await delay(1000);
|
||||
await waku.relay.send(message);
|
||||
|
||||
let msgs = [];
|
||||
let msgs: WakuMessage[] = [];
|
||||
|
||||
while (msgs.length === 0) {
|
||||
console.log('Waiting for messages');
|
||||
|
@ -227,7 +224,7 @@ describe('Waku Relay', () => {
|
|||
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
|
||||
expect(msgs[0].version).to.equal(message.version);
|
||||
|
||||
const payload = Buffer.from(msgs[0].payload);
|
||||
const payload = Buffer.from(msgs[0].payload!);
|
||||
expect(Buffer.compare(payload, message.payload!)).to.equal(0);
|
||||
});
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ export class WakuRelay extends Gossipsub {
|
|||
* @override
|
||||
* @returns {void}
|
||||
*/
|
||||
start() {
|
||||
start(): void {
|
||||
super.start();
|
||||
super.subscribe(constants.RelayDefaultTopic);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ export class WakuRelay extends Gossipsub {
|
|||
* @param {WakuMessage} message
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async send(message: WakuMessage) {
|
||||
async send(message: WakuMessage): Promise<void> {
|
||||
const msg = message.encode();
|
||||
await super.publish(constants.RelayDefaultTopic, Buffer.from(msg));
|
||||
}
|
||||
|
|
|
@ -31,10 +31,10 @@ export class RelayHeartbeat extends Heartbeat {
|
|||
|
||||
this._heartbeatTimer = {
|
||||
_intervalId: undefined,
|
||||
runPeriodically: (fn, period) => {
|
||||
runPeriodically: (fn, period): void => {
|
||||
this._heartbeatTimer!._intervalId = setInterval(fn, period);
|
||||
},
|
||||
cancel: () => {
|
||||
cancel: (): void => {
|
||||
clearTimeout(timeout);
|
||||
clearInterval(this._heartbeatTimer?._intervalId as NodeJS.Timeout);
|
||||
},
|
||||
|
|
|
@ -2,14 +2,14 @@ import fs, { promises as asyncFs } from 'fs';
|
|||
import { promisify } from 'util';
|
||||
|
||||
import { delay } from '../lib/delay';
|
||||
export const existsAsync = (filepath: string) =>
|
||||
export const existsAsync = (filepath: string): Promise<void> =>
|
||||
asyncFs.access(filepath, fs.constants.F_OK);
|
||||
|
||||
export const openAsync = promisify(fs.open);
|
||||
|
||||
export const mkdirAsync = asyncFs.mkdir;
|
||||
|
||||
export async function waitForFile(path: string) {
|
||||
export async function waitForFile(path: string): Promise<void> {
|
||||
let found = false;
|
||||
do {
|
||||
try {
|
||||
|
|
|
@ -4,7 +4,10 @@ import { Tail } from 'tail';
|
|||
|
||||
import { waitForFile } from './async_fs';
|
||||
|
||||
export default async function waitForLine(filepath: string, logLine: string) {
|
||||
export default async function waitForLine(
|
||||
filepath: string,
|
||||
logLine: string
|
||||
): Promise<void> {
|
||||
await pTimeout(waitForFile(filepath), 2000);
|
||||
|
||||
const options = {
|
||||
|
@ -22,7 +25,7 @@ export default async function waitForLine(filepath: string, logLine: string) {
|
|||
tail.unwatch();
|
||||
}
|
||||
|
||||
async function find(tail: Tail, line: string) {
|
||||
async function find(tail: Tail, line: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
tail.on('line', (data: string) => {
|
||||
if (data.includes(line)) {
|
||||
|
|
|
@ -58,7 +58,7 @@ export class NimWaku {
|
|||
this.logPath = `${LOG_DIR}/nim-waku_${logName}.log`;
|
||||
}
|
||||
|
||||
async start(args?: Args) {
|
||||
async start(args?: Args): Promise<void> {
|
||||
try {
|
||||
await existsAsync(LOG_DIR);
|
||||
} catch (e) {
|
||||
|
@ -116,7 +116,7 @@ export class NimWaku {
|
|||
await this.waitForLog('RPC Server started');
|
||||
}
|
||||
|
||||
public stop() {
|
||||
public stop(): void {
|
||||
dbg(
|
||||
`nim-waku ${
|
||||
this.process ? this.process.pid : this.pid
|
||||
|
@ -126,7 +126,7 @@ export class NimWaku {
|
|||
this.process = undefined;
|
||||
}
|
||||
|
||||
async waitForLog(msg: string) {
|
||||
async waitForLog(msg: string): Promise<void> {
|
||||
return waitForLine(this.logPath, msg);
|
||||
}
|
||||
|
||||
|
@ -134,23 +134,19 @@ export class NimWaku {
|
|||
* for known peers
|
||||
* @throws if nim-waku2 isn't started.
|
||||
*/
|
||||
async peers() {
|
||||
async peers(): Promise<string[]> {
|
||||
this.checkProcess();
|
||||
|
||||
const res = await this.rpcCall('get_waku_v2_admin_v1_peers', []);
|
||||
|
||||
return res.result;
|
||||
return this.rpcCall<string[]>('get_waku_v2_admin_v1_peers', []);
|
||||
}
|
||||
|
||||
async info(): Promise<RpcInfoResponse> {
|
||||
this.checkProcess();
|
||||
|
||||
const res = await this.rpcCall('get_waku_v2_debug_v1_info', []);
|
||||
|
||||
return res.result;
|
||||
return this.rpcCall<RpcInfoResponse>('get_waku_v2_debug_v1_info', []);
|
||||
}
|
||||
|
||||
async sendMessage(message: WakuMessage) {
|
||||
async sendMessage(message: WakuMessage): Promise<boolean> {
|
||||
this.checkProcess();
|
||||
|
||||
if (!message.payload) {
|
||||
|
@ -162,22 +158,18 @@ export class NimWaku {
|
|||
contentTopic: message.contentTopic,
|
||||
};
|
||||
|
||||
const res = await this.rpcCall('post_waku_v2_relay_v1_message', [
|
||||
return this.rpcCall<boolean>('post_waku_v2_relay_v1_message', [
|
||||
RelayDefaultTopic,
|
||||
rpcMessage,
|
||||
]);
|
||||
|
||||
return res.result;
|
||||
}
|
||||
|
||||
async messages() {
|
||||
async messages(): Promise<WakuMessage[]> {
|
||||
this.checkProcess();
|
||||
|
||||
const res = await this.rpcCall('get_waku_v2_relay_v1_messages', [
|
||||
return this.rpcCall<WakuMessage[]>('get_waku_v2_relay_v1_messages', [
|
||||
RelayDefaultTopic,
|
||||
]);
|
||||
|
||||
return res.result;
|
||||
}
|
||||
|
||||
async getPeerId(): Promise<PeerId> {
|
||||
|
@ -213,10 +205,10 @@ export class NimWaku {
|
|||
return `http://localhost:${port}/`;
|
||||
}
|
||||
|
||||
private async rpcCall(
|
||||
private async rpcCall<T>(
|
||||
method: string,
|
||||
params: Array<string | number | unknown>
|
||||
) {
|
||||
): Promise<T> {
|
||||
const res = await axios.post(
|
||||
this.rpcUrl,
|
||||
{
|
||||
|
@ -230,10 +222,10 @@ export class NimWaku {
|
|||
}
|
||||
);
|
||||
|
||||
return res.data;
|
||||
return res.data.result;
|
||||
}
|
||||
|
||||
private checkProcess() {
|
||||
private checkProcess(): void {
|
||||
if (!this.process) {
|
||||
throw "Nim Waku isn't started";
|
||||
}
|
||||
|
@ -282,7 +274,7 @@ export function strToHex(str: string): string {
|
|||
return hex;
|
||||
}
|
||||
|
||||
export function bufToHex(buffer: Uint8Array) {
|
||||
export function bufToHex(buffer: Uint8Array): string {
|
||||
return Array.prototype.map
|
||||
.call(buffer, (x) => ('00' + x.toString(16)).slice(-2))
|
||||
.join('');
|
||||
|
|
|
@ -14,18 +14,19 @@
|
|||
"strict": true /* Enable all strict type-checking options. */,
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
// "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||
// "strictNullChecks": true /* Enable strict null checks. */,
|
||||
// "strictFunctionTypes": true /* Enable strict checking of function types. */,
|
||||
// "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
|
||||
// "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
|
||||
// "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
|
||||
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||
"strictNullChecks": true /* Enable strict null checks. */,
|
||||
"strictFunctionTypes": true /* Enable strict checking of function types. */,
|
||||
"strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
|
||||
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
|
||||
"alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
|
||||
|
||||
/* Additional Checks */
|
||||
"noUnusedLocals": true /* Report errors on unused locals. */,
|
||||
"noUnusedParameters": true /* Report errors on unused parameters. */,
|
||||
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
||||
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
||||
/* Debugging Options */
|
||||
"traceResolution": false /* Report module resolution log messages. */,
|
||||
|
|
|
@ -5,7 +5,5 @@
|
|||
"outDir": "build/module",
|
||||
"module": "esnext"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules/**"
|
||||
]
|
||||
"exclude": ["node_modules/**"]
|
||||
}
|
||||
|
|
|
@ -35,9 +35,9 @@
|
|||
"fix": "run-s fix:*",
|
||||
"test": "run-s build test:*",
|
||||
"test:lint": "eslint src --ext .ts --ext .tsx",
|
||||
"test:prettier": "prettier \"src/**/*.{ts,tsx}\" --list-different",
|
||||
"test:prettier": "prettier \"src/**/*.{ts,tsx}\" \"./*.json\" --list-different",
|
||||
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.{ts,tsx},public/**/*.html}\"",
|
||||
"fix:prettier": "prettier \"src/**/*.{ts,tsx}\" --write",
|
||||
"fix:prettier": "prettier \"src/**/*.{ts,tsx}\" \"./*.json\" --write",
|
||||
"fix:lint": "eslint src --ext .ts --ext .tsx --fix",
|
||||
"js-waku:build": "cd ../; npm run build",
|
||||
"predeploy": "run-s js-waku:build build",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { multiaddr } from 'multiaddr';
|
||||
import PeerId from 'peer-id';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import './App.css';
|
||||
import { ChatMessage } from 'waku-chat/chat_message';
|
||||
import { WakuMessage } from 'waku/waku_message';
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"incremental": true,
|
||||
"target": "es2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
|
@ -8,6 +9,8 @@
|
|||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
|
|
Loading…
Reference in New Issue