@dbs-portal/core-module-registry
Version:
Core module registry system for automatic module discovery and registration
116 lines • 3.46 kB
TypeScript
/**
* Platform-Agnostic Module Loader
*
* Provides a unified interface for loading platform-specific modules
* (Node.js vs Browser) with automatic fallbacks and error handling.
*/
/**
* Path utilities interface
*/
export interface PlatformPath {
resolve(...paths: string[]): string;
join(...paths: string[]): string;
dirname(path: string): string;
basename(path: string, ext?: string): string;
extname(path: string): string;
relative(from: string, to: string): string;
isAbsolute(path: string): boolean;
normalize(path: string): string;
sep: string;
delimiter: string;
}
/**
* File system utilities interface
*/
export interface PlatformFs {
readFile(path: string, encoding?: string): Promise<string>;
writeFile(path: string, data: string, encoding?: string): Promise<void>;
access(path: string): Promise<void>;
stat(path: string): Promise<any>;
readdir(path: string): Promise<string[]>;
mkdir(path: string, options?: any): Promise<void>;
exists(path: string): Promise<boolean>;
}
/**
* Glob utilities interface
*/
export interface PlatformGlob {
glob(pattern: string | string[], options?: any): Promise<string[]>;
globSync(pattern: string | string[], options?: any): string[];
}
/**
* Load platform-specific path utilities
*/
export declare function loadPath(): Promise<PlatformPath>;
/**
* Load platform-specific file system utilities
*/
export declare function loadFs(): Promise<PlatformFs>;
/**
* Load platform-specific glob utilities
*/
export declare function loadGlob(): Promise<PlatformGlob>;
/**
* Get cached path utilities
*/
export declare const getPath: () => Promise<PlatformPath>;
/**
* Get cached file system utilities
*/
export declare const getFs: () => Promise<PlatformFs>;
/**
* Get cached glob utilities
*/
export declare const getGlob: () => Promise<PlatformGlob>;
/**
* Clear module cache (useful for testing)
*/
export declare const clearModuleCache: () => void;
/**
* Initialize all platform modules
*/
export declare function initializePlatformModules(): Promise<{
path: PlatformPath;
fs: PlatformFs;
glob: PlatformGlob;
}>;
/**
* Preload browser modules with mock data (for browser usage)
*/
export declare function preloadBrowserModules(mockData: {
files?: Record<string, string>;
directories?: Record<string, string[]>;
structure?: Record<string, string[]>;
}): Promise<void>;
/**
* Get platform-specific module information
*/
export declare function getPlatformInfo(): {
platform: string;
canReadFiles: boolean;
canScanDirectories: boolean;
canUseGlob: boolean;
requiresPreloading: boolean;
features: {
fileSystem: boolean;
glob: boolean;
dynamicImport: boolean;
fetch: boolean;
};
};
/**
* Create platform-specific error with helpful context
*/
export declare function createPlatformError(operation: string, originalError: Error, suggestions?: string[]): Error;
declare const _default: {
getPath: () => Promise<PlatformPath>;
getFs: () => Promise<PlatformFs>;
getGlob: () => Promise<PlatformGlob>;
initializePlatformModules: typeof initializePlatformModules;
preloadBrowserModules: typeof preloadBrowserModules;
getPlatformInfo: typeof getPlatformInfo;
createPlatformError: typeof createPlatformError;
clearModuleCache: () => void;
};
export default _default;
//# sourceMappingURL=platform-modules.d.ts.map