From f13ae5832c317b34f92e8f34d7144427331a415c Mon Sep 17 00:00:00 2001
From: kianenigma
Date: Sun, 16 Oct 2022 11:42:28 +0100
Subject: [PATCH] format
---
src/config-ti.ts | 84 +++++++++++++++++++--------------------
src/index.ts | 2 +-
src/reporters/email.ts | 2 +-
src/reporters/index.ts | 38 +++++++++---------
src/reporters/matrix.ts | 4 +-
src/reporters/telegram.ts | 4 +-
src/tests/index.test.ts | 19 +++++++--
7 files changed, 85 insertions(+), 68 deletions(-)
diff --git a/src/config-ti.ts b/src/config-ti.ts
index 62cefc1..6d6252a 100644
--- a/src/config-ti.ts
+++ b/src/config-ti.ts
@@ -1,90 +1,90 @@
/**
* This module was automatically generated by `ts-interface-builder`
*/
-import * as t from "ts-interface-checker";
+import * as t from 'ts-interface-checker';
// tslint:disable:object-literal-key-quotes
export const Only = t.iface([], {
- "type": t.lit('only'),
- "only": t.array("ISubscriptionTarget"),
+ type: t.lit('only'),
+ only: t.array('ISubscriptionTarget')
});
export const Ignore = t.iface([], {
- "type": t.lit('ignore'),
- "ignore": t.array("ISubscriptionTarget"),
+ type: t.lit('ignore'),
+ ignore: t.array('ISubscriptionTarget')
});
export const All = t.iface([], {
- "type": t.lit('all'),
+ type: t.lit('all')
});
-export const MethodSubscription = t.union("All", "Only", "Ignore");
+export const MethodSubscription = t.union('All', 'Only', 'Ignore');
export const ISubscriptionTarget = t.iface([], {
- "pallet": "string",
- "method": "string",
+ pallet: 'string',
+ method: 'string'
});
export const RawAccount = t.iface([], {
- "address": "string",
- "nickname": "string",
+ address: 'string',
+ nickname: 'string'
});
export const BatchConfig = t.iface([], {
- "interval": "number",
- "misc": t.opt("boolean"),
+ interval: 'number',
+ misc: t.opt('boolean')
});
export const EmailConfig = t.iface([], {
- "from": "string",
- "to": t.array("string"),
- "gpgpubkey": t.opt("string"),
- "transporter": "any",
- "batch": t.opt("BatchConfig"),
+ from: 'string',
+ to: t.array('string'),
+ gpgpubkey: t.opt('string'),
+ transporter: 'any',
+ batch: t.opt('BatchConfig')
});
export const MatrixConfig = t.iface([], {
- "userId": "string",
- "accessToken": "string",
- "roomId": "string",
- "server": "string",
- "batch": t.opt("BatchConfig"),
+ userId: 'string',
+ accessToken: 'string',
+ roomId: 'string',
+ server: 'string',
+ batch: t.opt('BatchConfig')
});
export const FsConfig = t.iface([], {
- "path": "string",
- "batch": t.opt("BatchConfig"),
+ path: 'string',
+ batch: t.opt('BatchConfig')
});
export const ConsoleConfig = t.iface([], {
- "batch": t.opt("BatchConfig"),
+ batch: t.opt('BatchConfig')
});
export const TelegramConfig = t.iface([], {
- "chatId": "string",
- "botToken": "string",
- "batch": t.opt("BatchConfig"),
+ chatId: 'string',
+ botToken: 'string',
+ batch: t.opt('BatchConfig')
});
export const ReportersConfig = t.iface([], {
- "email": t.opt("EmailConfig"),
- "matrix": t.opt("MatrixConfig"),
- "fs": t.opt("FsConfig"),
- "telegram": t.opt("TelegramConfig"),
- "console": t.opt("ConsoleConfig"),
+ email: t.opt('EmailConfig'),
+ matrix: t.opt('MatrixConfig'),
+ fs: t.opt('FsConfig'),
+ telegram: t.opt('TelegramConfig'),
+ console: t.opt('ConsoleConfig')
});
export const ApiSubscription = t.enumtype({
- "Head": "head",
- "Finalized": "finalized",
+ Head: 'head',
+ Finalized: 'finalized'
});
export const AppConfig = t.iface([], {
- "accounts": t.array("RawAccount"),
- "endpoints": t.array("string"),
- "method_subscription": "MethodSubscription",
- "api_subscription": "ApiSubscription",
- "reporters": "ReportersConfig",
+ accounts: t.array('RawAccount'),
+ endpoints: t.array('string'),
+ method_subscription: 'MethodSubscription',
+ api_subscription: 'ApiSubscription',
+ reporters: 'ReportersConfig'
});
const exportedTypeSuite: t.ITypeSuite = {
@@ -102,6 +102,6 @@ const exportedTypeSuite: t.ITypeSuite = {
TelegramConfig,
ReportersConfig,
ApiSubscription,
- AppConfig,
+ AppConfig
};
export default exportedTypeSuite;
diff --git a/src/index.ts b/src/index.ts
index fa34de3..1a4d672 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -213,7 +213,7 @@ async function listAllChains(config: AppConfig, reporters: Reporter[]) {
})
);
// a rather wacky way to make sure this function never returns.
- return new Promise(() => { });
+ return new Promise(() => {});
}
async function main() {
diff --git a/src/reporters/email.ts b/src/reporters/email.ts
index e77f82f..71d941f 100644
--- a/src/reporters/email.ts
+++ b/src/reporters/email.ts
@@ -62,7 +62,7 @@ export class EmailReporter implements Reporter {
}
async groupReport(reports: Report[]): Promise {
- const content = reports.map((r) => new GenericReporter(r).htmlTemplate()).join("\n\n");
+ const content = reports.map((r) => new GenericReporter(r).htmlTemplate()).join('\n\n');
await this.sendEmail(`notification from polkadot-basic-notification`, content);
}
}
diff --git a/src/reporters/index.ts b/src/reporters/index.ts
index 7814c91..78b2008 100644
--- a/src/reporters/index.ts
+++ b/src/reporters/index.ts
@@ -148,9 +148,9 @@ class NotificationReporterHelper implements ReporterHelper {
return str.length < MAX_FORMATTED_MSG_LEN
? str
: `${str.substring(0, MAX_FORMATTED_MSG_LEN / 2)}..${str.substring(
- str.length - MAX_FORMATTED_MSG_LEN / 2,
- str.length
- )}`;
+ str.length - MAX_FORMATTED_MSG_LEN / 2,
+ str.length
+ )}`;
}
subscan(): string {
@@ -176,21 +176,23 @@ class NotificationReporterHelper implements ReporterHelper {
htmlTemplate(): string {
return `
-
📣 Notification at ${this.chain()} #${this.meta.number
- } aka ${new Date(this.meta.timestamp).toTimeString()}
+ 📣 Notification at ${this.chain()} #${
+ this.meta.number
+ } aka ${new Date(this.meta.timestamp).toTimeString()}
${this.meta.details.map(
- (i) => `
+ (i) => `
-
- 💻 type: ${i.inner.type} | ${i.account === 'Wildcard'
- ? ``
- : `for ${i.account.nickname} (${i.account.address})`
- }
+ 💻 type: ${i.inner.type} | ${
+ i.account === 'Wildcard'
+ ? ``
+ : `for ${i.account.nickname} (${i.account.address})`
+ }
pallet: ${this.pallet(i)} |
method: ${this.method(i)} |
data: ${this.data(i)}
`
- )}
+ )}
@@ -254,7 +256,7 @@ export class BatchReporter implements Reporter {
});
}
if (this.inner.groupReport) {
- this.inner.groupReport(batchedReports)
+ this.inner.groupReport(batchedReports);
} else {
for (const report of batchedReports) {
this.inner.report(report);
@@ -262,18 +264,16 @@ export class BatchReporter implements Reporter {
}
}, this.interval);
- logger.info(
- `setting up batch reporter with interval ${this.interval}.`
- );
+ logger.info(`setting up batch reporter with interval ${this.interval}.`);
}
flush(): Report[] {
const reports = existsSync(this.storagePath)
? readFileSync(this.storagePath)
- .toString()
- .split(SEPARATOR)
- .filter((line) => line.length)
- .map((line) => deserializeReport(line))
+ .toString()
+ .split(SEPARATOR)
+ .filter((line) => line.length)
+ .map((line) => deserializeReport(line))
: [];
writeFileSync(this.storagePath, '');
return reports;
diff --git a/src/reporters/matrix.ts b/src/reporters/matrix.ts
index c85b09a..c0528a2 100644
--- a/src/reporters/matrix.ts
+++ b/src/reporters/matrix.ts
@@ -34,7 +34,9 @@ export class MatrixReporter implements Reporter {
}
async groupReport(reports: Report[]): Promise {
- const innerContent = reports.map((r) => new GenericReporter(r).htmlTemplate()).join("\n\n");
+ const innerContent = reports
+ .map((r) => new GenericReporter(r).htmlTemplate())
+ .join('\n\n');
const content = {
formatted_body: innerContent,
body: innerContent,
diff --git a/src/reporters/telegram.ts b/src/reporters/telegram.ts
index b828a16..dc8a69e 100644
--- a/src/reporters/telegram.ts
+++ b/src/reporters/telegram.ts
@@ -19,7 +19,9 @@ export class TelegramReporter implements Reporter {
}
async groupReport(reports: Report[]): Promise {
- const innerContent = reports.map((r) => new GenericReporter(r).markdownTemplate()).join("\n---\n");
+ const innerContent = reports
+ .map((r) => new GenericReporter(r).markdownTemplate())
+ .join('\n---\n');
await this.bot.telegram.sendMessage(this.chatId, innerContent, { parse_mode: 'Markdown' });
}
}
diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts
index 05bca90..c702af7 100644
--- a/src/tests/index.test.ts
+++ b/src/tests/index.test.ts
@@ -1,7 +1,13 @@
import { existsSync, readdirSync, readFileSync, statSync, unlinkSync } from 'fs';
import { join } from 'path';
import { ConfigBuilder } from '../config';
-import { BatchReporter, ConsoleReporter, FileSystemReporter, MiscReport, NotificationReport } from '../reporters';
+import {
+ BatchReporter,
+ ConsoleReporter,
+ FileSystemReporter,
+ MiscReport,
+ NotificationReport
+} from '../reporters';
const mockProcessExit = jest.spyOn(process, 'exit').mockImplementation((code) => {
throw new Error(`Process.exit(${code})`);
@@ -82,8 +88,15 @@ const r = (message: string): MiscReport => {
};
const n = (): NotificationReport => {
- return { _type: "notification", chain: "foo", details: [], number: 10, hash: "0x123", timestamp: 10 }
-}
+ return {
+ _type: 'notification',
+ chain: 'foo',
+ details: [],
+ number: 10,
+ hash: '0x123',
+ timestamp: 10
+ };
+};
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));