import type { ClassConstructor, ParamInfo, Scope } from './types' export interface ServiceMetadata { constructor: ClassConstructor scope: Scope autorun: boolean params: ParamInfo[] } interface InternalServiceMeta { scope: Scope autorun: boolean } class MetadataRegistry { private services = new Map() private paramMap = new Map() registerService(ctor: ClassConstructor, scope: Scope, autorun: boolean) { this.services.set(ctor, { scope, autorun }) } registerParamType(target: ClassConstructor, index: number, type: any) { const list = this.paramMap.get(target) || [] list[index] = { ...list[index], index, type } this.paramMap.set(target, list) } registerParamOptional( target: ClassConstructor, index: number, fallback?: any, ) { const list = this.paramMap.get(target) || [] list[index] = { ...list[index], index, optional: true, fallback } this.paramMap.set(target, list) } getAllMetadata(): ServiceMetadata[] { return Array.from(this.services.entries()).map(([ctor, meta]) => ({ constructor: ctor, scope: meta.scope, autorun: meta.autorun, params: this.paramMap.get(ctor) || [], })) } getParamInfo(target: ClassConstructor): ParamInfo[] { return this.paramMap.get(target) || [] } clear(): void { this.services.clear() this.paramMap.clear() } } // Export the singleton instance export const metadataRegistry = new MetadataRegistry()