export type CheckStatus = 'up' | 'down'; export type CheckDetails = Record; /** * Check result is an outcome for a check. It is * a little specialized version of classical Result * abstraction with error and data */ export class CheckResult { /** * Check status */ readonly status: CheckStatus; /** * Custom attributes (key value) Will * be returned to check caller or/and logged */ readonly details: CheckDetails; private constructor(status: CheckStatus, details: CheckDetails) { this.status = status; this.details = details; } /** * Indicated that check was not successful */ get isError(): boolean { return this.status === 'down'; } /** * Creates successful CheckResult * * @param details Any custom attributes * @returns CheckResult */ static up(details: CheckDetails): CheckResult { return new CheckResult('up', details); } /** * Creates failed CheckResult * * @param details Any custom attributes * @returns CheckResult */ static down(details: CheckDetails): CheckResult { return new CheckResult('down', details); } }