import type { Constructor } from '@rsdk/common'; import type { Resource, RsdkMetadataProvider } from '@rsdk/metadata'; import type { Config } from '../config.abstract'; import type { ConfigSource } from '../sources'; import type { PropertyMetadata, SectionMetadata, SourceMetadata, } from '../types'; import { CONFIG_PROPERTIES_RSDK_METADATA_SCOPE, CONFIG_SECTION_RSDK_METADATA_SCOPE, CONFIG_SOURCE_RSDK_METADATA_SCOPE, } from './constants'; import type { PropertyRsdkMetadata, SectionRsdkMetadata, SourcesRsdkMetadata, } from './types'; export class ConfigMetadataProvider { constructor(private rsdkMetadataProvider: RsdkMetadataProvider) {} getPropertiesMetadata(): Resource[] { return this.rsdkMetadataProvider.get( CONFIG_PROPERTIES_RSDK_METADATA_SCOPE, ); } getMetadata(): Readonly<{ sources: Map, SourceMetadata>; sections: Map, SectionMetadata>; properties: Map; }> { return { properties: this.getPropertiesMap(), sections: this.getSectionsMap(), sources: this.getSourcesMap(), }; } getPropertiesMap(): Map { return new Map( this.getPropertiesMetadata().map( (resource) => [resource.value.alias, resource.value.metadata] as const, ), ); } getSectionsMap(): Map, SectionMetadata> { return new Map( this.getSectionsMetadata().map( (resource) => [resource.value.target, resource.value.metadata] as const, ), ); } getSourcesMap(): Map, SourceMetadata> { return new Map( this.getSourcesMetadata().map( (resource) => [resource.value.target, resource.value.metadata] as const, ), ); } getSectionsMetadata(): Resource[] { return this.rsdkMetadataProvider.get( CONFIG_SECTION_RSDK_METADATA_SCOPE, ); } private getSourcesMetadata(): Resource[] { return this.rsdkMetadataProvider.get( CONFIG_SOURCE_RSDK_METADATA_SCOPE, ); } }