/* eslint-disable @typescript-eslint/ban-types */ import type { Constructor } from '@rsdk/common'; import { ConfigMetadataRegistry } from '../metadata'; import type { SourceType } from '../types'; const SOURCE_METADATA_KEY = 'CONFIG_SOURCE_METADATA_KEY'; export interface SourceOptions { description?: string; name?: string; } const DEFAULT_OPTIONS = {}; /** * This decorator is used to register additional configuration * sourcePropertyParser * @param type * @param options Metadata used mostly for docs generation * @returns */ export const Source = ( type: SourceType, options: SourceOptions = {}, ): ClassDecorator => { return function (target: Function): void { const name = options.name || target.name; const effectiveOptions = { ...DEFAULT_OPTIONS, ...options, name, type }; Reflect.defineMetadata(SOURCE_METADATA_KEY, effectiveOptions, target); ConfigMetadataRegistry.registerSource( target as Constructor, effectiveOptions, ); }; };