import type { ILogger } from '@rsdk/logging'; import type { ReloadEvents } from '../../reload'; import type { SourceType } from '../../types'; import { ConfigSource } from './config-source.abstract'; export abstract class ReloadableConfigSource extends ConfigSource { protected readonly logger: ILogger; constructor( logger: ILogger, private readonly events: ReloadEvents, ) { super(); this.logger = logger; } type(): SourceType { return 'reloadable'; } async reload(): Promise { try { const vars = await this.load(); this.events.emit('reload', this, vars); } catch (error: any) { this.logger.error( `Failed to reload configuration (${this.constructor.name})`, error, ); this.events.emit('reload_failure', this, error); } } abstract init(): void; } export const isReloadable = (s: ConfigSource): s is ReloadableConfigSource => s.type() === 'reloadable';