/* eslint-disable @typescript-eslint/ban-types */ import type { Constructor } from '@rsdk/common'; import { DEFAULT_HEALTH_CHECK_SCOPE } from '../health.const'; import type { HealthIndicator } from '../types'; import { IndicatorsRegistry } from './indicators.registry'; export interface IndicatorOptions { /** * Description */ description?: string; /** * FIXME: WTF? */ scope?: string; /** * Flag indicating whether the readiness probe is optional. * If set to `true`, an error in the probe will not affect the global system status. */ isOptional?: boolean; } /** * Registers health indicator. Indicators should be added to application * modules as providers and use common DI to inject necessary services * (api, database clients, etc.) * @param {string} key Healthcheck response is object where each key * is a specific indicator. Thus you can use key to recognize an * indicator in healthcheck response * @param {IndicatorOptions} options Indicator metadata * @returns {ClassDecorator} */ export const Indicator = ( key: string, options: IndicatorOptions = {}, ): ClassDecorator => { return function (target: Function): void { IndicatorsRegistry.register(target as Constructor, { key, scope: options.scope ?? DEFAULT_HEALTH_CHECK_SCOPE, ...options, }); }; };