import * as _$_nestjs_common0 from "@nestjs/common"; import { DynamicModule, Type } from "@nestjs/common"; import { Class, Promisable } from "type-fest"; //#region src/types/config-loader.d.ts interface LoadRawConfigFnOptions { suppressWarnings?: true; debug?: true; } /** * 配置加载器函数 */ type LoadRawConfigFn = (options: LoadRawConfigFnOptions) => Promisable>; /** * 静态配置加载器 */ interface StaticConfigLoader { load: LoadRawConfigFn; } /** * watcher 清理函数 */ type WatcherDisposer = () => void | Promise; /** * 可监听的配置加载器 */ interface WatchableConfigLoader extends StaticConfigLoader { startWatch?: (reload: () => Promise) => WatcherDisposer; } type ConfigLoader = StaticConfigLoader | WatchableConfigLoader; //#endregion //#region src/types/config-module-options.d.ts interface ConfigModuleOptions extends LoadRawConfigFnOptions { /** * @default ".env" */ loaders?: (string | LoadRawConfigFn | ConfigLoader)[]; /** * Provider can be automatically loaded, in most cases. */ providers?: Type[]; } //#endregion //#region src/config.module-definition.d.ts declare const ConfigurableModuleClass: _$_nestjs_common0.ConfigurableModuleCls, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: ConfigModuleOptions & Partial<{ isGlobal: boolean; }>, ASYNC_OPTIONS_TYPE: _$_nestjs_common0.ConfigurableModuleAsyncOptions & Partial<{ isGlobal: boolean; }>; //#endregion //#region src/types/configuration-defintion.d.ts /** * Configuration class constructor type * Represents a NestJS type that can be instantiated as a configuration class */ type ConfigurationCtor = Class; //#endregion //#region src/types/injected-module.d.ts /** * Options for asynchronous module configuration using factory pattern * * @description * Defines the structure for async configuration options that use a factory function * to generate configuration objects. The factory can return either a synchronous value * or a Promise. * * @example * ```typescript * const asyncOptions: AsyncOptions = { * useFactory: (configService: ConfigService) => ({ * apiKey: configService.get('API_KEY'), * timeout: 5000 * }) * }; * ``` * * @example * ```typescript * // Async factory returning a Promise * const asyncOptions: AsyncOptions = { * useFactory: async (httpService: HttpService) => { * const remoteConfig = await httpService.get('/config').toPromise(); * return remoteConfig.data; * } * }; * ``` */ interface AsyncOptions { useFactory(...args: any[]): T; useFactory(...args: any[]): Promisable; } /** * Interface for NestJS modules that support async registration via registerAsync method * * @description * Represents a module that can be dynamically registered with asynchronous configuration. * This pattern is commonly used for modules that need to be configured with dependencies * from other modules (e.g., ConfigService, DatabaseService). * * @example * ```typescript * @Module({}) * class DatabaseModule implements InjectedModuleWithRegisterAsync { * static registerAsync(options: T): DynamicModule { * return { * module: DatabaseModule, * providers: [ * { * provide: 'DATABASE_OPTIONS', * useFactory: options.useFactory, * inject: options.inject || [] * } * ] * }; * } * } * ``` */ interface InjectedModuleWithRegisterAsync { registerAsync(options: T): DynamicModule; } /** * Interface for NestJS modules that support async registration via forRootAsync method * * @description * Represents a module that can be dynamically registered as a global/root module * with asynchronous configuration. This pattern is commonly used for singleton * modules that should be registered once at the application root level. * * @example * ```typescript * @Module({}) * class CacheModule implements InjectedModuleWithForRootAsync { * static forRootAsync(options: T): DynamicModule { * return { * module: CacheModule, * global: true, * providers: [ * { * provide: 'CACHE_OPTIONS', * useFactory: options.useFactory, * inject: options.inject || [] * } * ] * }; * } * } * ``` */ interface InjectedModuleWithForRootAsync { forRootAsync(options: T): DynamicModule; } /** * Union type representing any module that can be injected with async configuration * * @description * A module can use either `registerAsync` or `forRootAsync` pattern for * asynchronous configuration injection. * * @example * ```typescript * function configureModule(Module: InjectedModule, options: any) { * if ('forRootAsync' in Module) { * return Module.forRootAsync(options); * } else { * return Module.registerAsync(options); * } * } * ``` */ type InjectedModule = InjectedModuleWithRegisterAsync | InjectedModuleWithForRootAsync; /** * Type utility to infer the async options type from an injected module * * @description * Extracts the options type from a module's async registration method. * This is useful for type-safe configuration when working with different * module types dynamically. * * @template M - The injected module type * @returns The inferred async options type for the given module * * @example * ```typescript * class MyModule implements InjectedModuleWithForRootAsync { * static forRootAsync(options: { useFactory: () => { apiKey: string } }) { * // ... * } * } * * // Type will be: { useFactory: () => { apiKey: string } } * type MyModuleOptions = InferAsyncOptions; * ``` * * @example * ```typescript * // Generic function with type inference * function registerModuleAsync( * Module: M, * options: InferAsyncOptions * ) { * if ('forRootAsync' in Module) { * return Module.forRootAsync(options); * } * return (Module as InjectedModuleWithRegisterAsync).registerAsync(options); * } * ``` */ type InferAsyncOptions = M extends InjectedModuleWithForRootAsync ? Parameters[0] : M extends InjectedModuleWithRegisterAsync ? Parameters[0] : never; //#endregion //#region src/types/loader-watch-options.d.ts /** * 配置加载器的监听选项 */ interface LoaderWatchOptions { /** * 监听类型 * - 'watch': 使用文件系统监听(chokidar) * - 'interval': 使用定时轮询 * @default 'watch' */ type?: 'watch' | 'interval'; /** * 防抖时间(毫秒) * 防止短时间内多次触发重载 * @default 300 */ debounceMs?: number; /** * 定时轮询间隔(毫秒) * 仅在 type='interval' 时有效 * @default 5000 */ intervalMs?: number; /** * 配置变化时的回调 * 在配置重载前调用 */ onChange?: (newConfig: Record) => void | Promise; /** * 错误处理回调 */ onError?: (error: Error) => void | Promise; } /** * Loader 的热重载配置 * - true: 使用默认配置启用监听 * - LoaderWatchOptions: 使用自定义配置 * - false/undefined: 不启用监听 */ type HotReloadConfig = boolean | LoaderWatchOptions; //#endregion //#region src/config.module.d.ts declare class ConfigModule extends ConfigurableModuleClass { /** * Configure global options for ConfigModule * These options will be used as defaults for preload() and register() */ static configure(options: ConfigModuleOptions): void; /** * Load config and provider before registering the module * If no options provided, will use global options set by configure() */ static preload(options?: ConfigModuleOptions): Promise; /** * Get the loaded config */ static get(ctor: T, options?: ConfigModuleOptions): Promise | undefined>; static getOrFail(ctor: T, options?: ConfigModuleOptions): Promise>; private static createConfigurationProvider; private static createRuntimeConfigProvider; static register(options?: typeof OPTIONS_TYPE): DynamicModule; static registerAsync(options?: typeof ASYNC_OPTIONS_TYPE): DynamicModule; static inject, O extends Awaited>, P extends Class>(provider: P, module: M): DynamicModule; static inject, O extends Awaited>, P extends Class>(provider: P, module: M, optionsFactory: (config: P['prototype']) => Promise | O): DynamicModule; static inject, O extends Awaited>, P extends Class>(provider: P, module: M, moduleAsyncOptions: Omit): DynamicModule; static inject, O extends Awaited>, P extends Class>(provider: P, module: M, moduleAsyncOptions: Omit, optionsFactory: (config: P['prototype']) => Promise): DynamicModule; } //#endregion //#region src/runtime-config.d.ts /** * Normalized configuration options object * Automatically normalizes and merges options on construction */ declare class RuntimeConfig { /** * Global options used as defaults for all ConfigOption instances */ private static globalOptions; /** * Normalized loaders in WatchableConfigLoader format */ readonly loaders: ConfigLoader[]; /** * Provider classes */ readonly providers?: Type[]; /** * Suppress warnings flag */ readonly suppressWarnings?: true; /** * Debug mode flag */ readonly debug?: true; /** * Set global options that will be used as defaults */ static setGlobal(options: ConfigModuleOptions): void; /** * Get current global options */ static getGlobal(): ConfigModuleOptions | null; /** * Reset global options (useful for testing) */ static resetGlobal(): void; /** * Normalize loaders to unified WatchableConfigLoader format */ private static normalizeLoaders; /** * Constructor that automatically normalizes and merges options * @param options - Raw configuration options */ constructor(options?: ConfigModuleOptions); } //#endregion //#region src/decorators/config-key.decorator.d.ts declare function ConfigKey(key?: string): PropertyDecorator; //#endregion //#region src/decorators/config-name.decorator.d.ts /** * @deprecated Use `@ConfigKey` instead */ declare function ConfigName(name: string): PropertyDecorator; //#endregion //#region src/decorators/configuration.decorator.d.ts declare function Configuration(scope?: string): ClassDecorator; //#endregion //#region src/decorators/static-config.decorator.d.ts /** * @deprecated */ declare function StaticConfig(): PropertyDecorator; //#endregion //#region src/utils/compose-loader.d.ts declare function composeLoader(loaders: LoadRawConfigFn[]): LoadRawConfigFn; //#endregion //#region src/config-loader/dotenv-loader.d.ts interface DotenvLoaderOptions$1 { /** * @default '__' */ separator?: string; /** * @default true */ jsonParse?: boolean; /** * 热重载配置 * - true: 使用默认配置启用文件监听 * - LoaderWatchOptions: 自定义监听配置 * - false/undefined: 不启用监听 */ hotReload?: HotReloadConfig; } declare function dotenvLoader(filepath: string, loaderOptions?: DotenvLoaderOptions$1): WatchableConfigLoader; //#endregion //#region src/config-loader/json-file-loader.d.ts interface JsonFileLoaderOptions { /** * 热重载配置 */ hotReload?: HotReloadConfig; } declare function jsonFileLoader(filepath: string, encoding?: BufferEncoding, options?: JsonFileLoaderOptions): WatchableConfigLoader; //#endregion //#region src/config-loader/process-env-loader.d.ts interface ProcessEnvLoaderOptions { /** * @default '__' */ separator?: string; /** * @default true */ jsonParse?: boolean; } declare function processEnvLoader(loaderOptions?: ProcessEnvLoaderOptions): LoadRawConfigFn; //#endregion //#region src/config-loader/dotenvx-loader.d.ts interface DotenvLoaderOptions { /** * @default '__' */ separator?: string; /** * @default true */ jsonParse?: boolean; /** * See More: https://dotenvx.com/docs/advanced/parse-process-env */ processEnv?: Record; /** * See More: https://dotenvx.com/docs/advanced/parse-private-key */ privateKey?: string; /** * 热重载配置 * - true: 使用默认配置启用文件监听 * - LoaderWatchOptions: 自定义监听配置 * - false/undefined: 不启用监听 */ hotReload?: HotReloadConfig; } declare function dotenvxLoader(filepath: string, loaderOptions?: DotenvLoaderOptions): WatchableConfigLoader; //#endregion //#region src/config-loader/yaml-file-loader.d.ts interface YamlFileLoaderOptions { /** * 热重载配置 */ hotReload?: HotReloadConfig; } declare function yamlFileLoader(filepath: string, encoding?: BufferEncoding, options?: YamlFileLoaderOptions): WatchableConfigLoader; //#endregion //#region src/config-loader/toml-file-loader.d.ts interface TomlFileLoaderOptions { /** * 热重载配置 */ hotReload?: HotReloadConfig; } declare function tomlFileLoader(filepath: string, encoding?: BufferEncoding, options?: TomlFileLoaderOptions): WatchableConfigLoader; //#endregion export { ConfigKey, type LoadRawConfigFn as ConfigLoader, ConfigModule, type ConfigModuleOptions, ConfigName, RuntimeConfig as ConfigOption, Configuration, type ConfigLoader as EnhancedConfigLoader, type HotReloadConfig, type LoaderWatchOptions, StaticConfig, type WatchableConfigLoader, type WatcherDisposer, composeLoader, dotenvLoader, dotenvxLoader, jsonFileLoader, processEnvLoader, tomlFileLoader, yamlFileLoader };