@tusss/ood
    Preparing search index...

    Class ConfigLoaderDirector<TEnv, TConfig>

    Coordinates the configuration loading process by querying the loader pool based on the resolved environment.

    Basic usage of ConfigLoaderDirector and ConfigLoaderPool to load configuration for a given environment

    import {
    Config,
    IConfigLoader,
    ConfigLoaderPool,
    ConfigLoaderDirector
    } from './config-loader';

    type AppConfig = Config<{ apiEndpoint: string }>;

    class LoaderDev implements IConfigLoader<AppConfig> {
    async load() {
    return {
    environment: 'development',
    apiEndpoint: 'http://localhost:3000'
    };
    }
    }

    class LoaderProd implements IConfigLoader<AppConfig> {
    async load() {
    return {
    environment: 'production',
    apiEndpoint: 'https://api.example.com'
    };
    }
    }

    const loaderDev = new LoaderDev();
    const loaderProd = new LoaderProd();

    class AppConfigPool extends ConfigLoaderPool<string, AppConfig> {
    override readonly defaultLoader = loaderDev;
    }

    const pool = new AppConfigPool([
    ['development', loaderDev],
    ['production', loaderProd]
    ]);

    const director = new ConfigLoaderDirector(pool);

    // Load configuration (reads process.env.NODE_ENV)
    const config = await director.load();

    // Customize environment resolution manually
    const customConfig = await director
    .customizeEnv(() => 'production')
    .load();

    Type Parameters

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    The pool of configuration loaders to select from.

    Methods

    • Resolves the current environment. By default, it reads process.env.NODE_ENV.

      Returns TEnv

      The current environment value.