| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /**
- * Available configuration sources
- */
- export const ConfigSource = {
- env: 'env',
- db: 'db',
- } as const;
- export type ConfigSource = typeof ConfigSource[keyof typeof ConfigSource];
- /**
- * Metadata for a configuration value
- */
- export interface ConfigDefinition<T> {
- defaultValue: T;
- envVarName?: string;
- isSecret?: boolean;
- }
- /**
- * Helper function for defining configurations with type safety
- */
- export const defineConfig = <T>(config: ConfigDefinition<T>): ConfigDefinition<T> => config;
- /**
- * Interface for loading configuration values
- */
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- export interface IConfigLoader<K extends string, V extends Record<K, any>> {
- /**
- * Load configurations from environment variables
- */
- loadFromEnv(): Promise<RawConfigData<K, V>>;
- /**
- * Load configurations from database
- */
- loadFromDB(): Promise<RawConfigData<K, V>>;
- }
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- export type RawConfigData<K extends string, V extends Record<K, any>> = Record<K, {
- value: V[K];
- definition?: ConfigDefinition<V[K]>;
- }>;
- export type UpdateConfigOptions = { skipPubsub?: boolean };
- /**
- * Interface for managing configuration values
- */
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- export interface IConfigManager<K extends string, V extends Record<K, any>> {
- /**
- * Load configurations
- * @param options.source - Specify which source to load from
- */
- loadConfigs(options?: { source?: ConfigSource }): Promise<void>;
- /**
- * Get a configuration value
- */
- getConfig<T extends K>(key: T, source?: ConfigSource): V[T];
- /**
- * Update a configuration value
- */
- updateConfig<T extends K>(key: T, value: V[T], options?: UpdateConfigOptions): Promise<void>;
- /**
- * Update multiple configuration values
- */
- updateConfigs(updates: Partial<{ [T in K]: V[T] }>, options?: UpdateConfigOptions): Promise<void>;
- /**
- * Remove multiple configuration values
- */
- removeConfigs(keys: K[], options?: UpdateConfigOptions): Promise<void>;
- /**
- * Get environment variables managed with ConfigDefinitions
- */
- getManagedEnvVars(showSecretValues: boolean): Record<string, string>;
- }
|