import type { Constructor } from '@rsdk/common'; import type { PipelineException } from '../base'; export interface ExceptionMetadata { description: string; } export interface ThrowsMetadata { // eslint-disable-next-line @typescript-eslint/ban-types class: Function; method: string; exceptions: Constructor[]; } const isExceptionMeta = ( arg: ExceptionMetadata | ThrowsMetadata, ): arg is ExceptionMetadata => !!(arg as any).description; export class ExceptionsRegistry { private static _instance: ExceptionsRegistry; private exceptions: ExceptionMetadata[] = []; private throws: ThrowsMetadata[] = []; // eslint-disable-next-line @typescript-eslint/no-empty-function private constructor() {} static getInstance(): ExceptionsRegistry { if (!this._instance) { this._instance = new ExceptionsRegistry(); } return this._instance; } register(meta: ThrowsMetadata): void; register(meta: ExceptionMetadata): void; register(meta: ThrowsMetadata | ExceptionMetadata): void { if (isExceptionMeta(meta)) { this.exceptions.push(meta); } else { this.throws.push(meta); } } getAll(): { exceptions: ExceptionMetadata[]; throws: ThrowsMetadata[] } { return { exceptions: this.exceptions, throws: this.throws }; } }