Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
kianenigma committed Oct 16, 2022
1 parent cbee7a2 commit f13ae58
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 68 deletions.
84 changes: 42 additions & 42 deletions src/config-ti.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -102,6 +102,6 @@ const exportedTypeSuite: t.ITypeSuite = {
TelegramConfig,
ReportersConfig,
ApiSubscription,
AppConfig,
AppConfig
};
export default exportedTypeSuite;
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class EmailReporter implements Reporter {
}

async groupReport(reports: Report[]): Promise<void> {
const content = reports.map((r) => new GenericReporter(r).htmlTemplate()).join("\n</hr>\n");
const content = reports.map((r) => new GenericReporter(r).htmlTemplate()).join('\n</hr>\n');
await this.sendEmail(`notification from polkadot-basic-notification`, content);
}
}
38 changes: 19 additions & 19 deletions src/reporters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -176,21 +176,23 @@ class NotificationReporterHelper implements ReporterHelper {
htmlTemplate(): string {
return `
<p>
<p>📣 <b> Notification</b> at ${this.chain()} #<a href='${this.subscan()}'>${this.meta.number
}</a> aka ${new Date(this.meta.timestamp).toTimeString()}</p>
<p>📣 <b> Notification</b> at ${this.chain()} #<a href='${this.subscan()}'>${
this.meta.number
}</a> aka ${new Date(this.meta.timestamp).toTimeString()}</p>
<ul>
${this.meta.details.map(
(i) => `
(i) => `
<li>
💻 type: ${i.inner.type} | ${i.account === 'Wildcard'
? ``
: `for <b style="background-color: ${COLOR.Primary}">${i.account.nickname}</b> (${i.account.address})`
}
💻 type: ${i.inner.type} | ${
i.account === 'Wildcard'
? ``
: `for <b style="background-color: ${COLOR.Primary}">${i.account.nickname}</b> (${i.account.address})`
}
pallet: <b style="background-color: ${COLOR.Primary}">${this.pallet(i)}</b> |
method: <b style="background-color: ${COLOR.Primary}">${this.method(i)}</b> |
data: ${this.data(i)}
</li>`
)}
)}
</ul>
</p>
<details>
Expand Down Expand Up @@ -254,26 +256,24 @@ export class BatchReporter<Inner extends Reporter> implements Reporter {
});
}
if (this.inner.groupReport) {
this.inner.groupReport(batchedReports)
this.inner.groupReport(batchedReports);
} else {
for (const report of batchedReports) {
this.inner.report(report);
}
}
}, 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;
Expand Down
4 changes: 3 additions & 1 deletion src/reporters/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class MatrixReporter implements Reporter {
}

async groupReport(reports: Report[]): Promise<void> {
const innerContent = reports.map((r) => new GenericReporter(r).htmlTemplate()).join("\n</br>\n");
const innerContent = reports
.map((r) => new GenericReporter(r).htmlTemplate())
.join('\n</br>\n');
const content = {
formatted_body: innerContent,
body: innerContent,
Expand Down
4 changes: 3 additions & 1 deletion src/reporters/telegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export class TelegramReporter implements Reporter {
}

async groupReport(reports: Report[]): Promise<void> {
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' });
}
}
19 changes: 16 additions & 3 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -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})`);
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit f13ae58

Please sign in to comment.