UNPKG

@nexe/config-manager

Version:

Nexe Config Manager - A flexible configuration management solution with multiple sources and hot reload support

29 lines 1.13 kB
import 'reflect-metadata'; import { CONFIG_PROPERTY_METADATA, CONFIG_SECTION_METADATA, } from './interfaces'; /** * 配置属性装饰器,用于将配置值映射到类属性 * @param key 配置键,如果不提供则使用属性名 */ export function ConfigProperty(key) { return (target, propertyKey) => { const configKey = key ?? String(propertyKey); // 存储配置属性元数据 const existingProperties = Reflect.getMetadata(CONFIG_PROPERTY_METADATA, target.constructor) ?? []; existingProperties.push({ key: configKey, propertyKey: String(propertyKey), }); Reflect.defineMetadata(CONFIG_PROPERTY_METADATA, existingProperties, target.constructor); }; } /** * 配置分区装饰器,用于定义配置类所对应的配置分区 * @param section 配置分区名称 */ export function ConfigSection(section) { // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type return (target) => { Reflect.defineMetadata(CONFIG_SECTION_METADATA, section, target); }; } //# sourceMappingURL=decorators.js.map