@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
105 lines • 3.25 kB
TypeScript
/**
* @module runtime/module-loader
* @description Module loader with dependency injection and lifecycle management
*/
import type { GlobalContext } from './types/context.js';
import type { Module, ModuleLoaderConfig } from './types/module.js';
/**
* Module loader with dependency injection
*/
export declare class ModuleLoader {
private registry;
private config;
private initializingModules;
constructor(config?: ModuleLoaderConfig);
/**
* Register a module
*
* @param module - Module to register
* @param gctx - Global context (required if autoInit is true)
* @throws {ModuleError} If module already registered
*/
register<T>(module: Module<T>, gctx?: GlobalContext): Promise<void>;
/**
* Initialize a module and its dependencies
*
* @param name - Module name to initialize
* @param gctx - Global context
* @param dependencyChain - Internal tracking for circular dependency detection
* @throws {ModuleNotFoundError} If module not found
* @throws {CircularDependencyError} If circular dependency detected
* @throws {ModuleInitializationError} If initialization fails
*/
initialize(name: string, gctx: GlobalContext, dependencyChain?: string[]): Promise<void>;
/**
* Get module exports
*
* @param name - Module name
* @param gctx - Global context (for lazy initialization)
* @returns Module exports
* @throws {ModuleNotFoundError} If module not found
* @throws {ModuleError} If module not initialized and can't auto-initialize
*/
get<T>(name: string, gctx?: GlobalContext): Promise<T>;
/**
* Get module exports synchronously (only works for initialized modules)
*
* @param name - Module name
* @returns Module exports
* @throws {ModuleNotFoundError} If module not found
* @throws {ModuleError} If module not initialized
*/
getSync<T>(name: string): T;
/**
* Shutdown a module
*
* @param name - Module name
* @throws {ModuleNotFoundError} If module not found
*/
shutdown(name: string): Promise<void>;
/**
* Shutdown all modules
*/
shutdownAll(): Promise<void>;
/**
* Check if a module is registered
*
* @param name - Module name
* @returns true if module is registered
*/
has(name: string): boolean;
/**
* Get all registered module names
*
* @returns Array of module names
*/
getModuleNames(): string[];
/**
* Get module statistics
*
* @returns Statistics object
*/
getStatistics(): {
total: number;
initialized: number;
uninitialized: number;
initializing: number;
error: number;
shutdown: number;
totalUsage: number;
};
/**
* Run health checks on all modules
*
* @returns Map of module name to health status
*/
healthCheck(): Promise<Map<string, boolean>>;
}
/**
* Create a new module loader
*
* @param config - Module loader configuration
* @returns New module loader instance
*/
export declare function createModuleLoader(config?: ModuleLoaderConfig): ModuleLoader;
//# sourceMappingURL=module-loader.d.ts.map