import { DiscoveryEngine, DiscoveryResult, DiscoveryEngineConfig } from './discovery-engine'; import { TransformedRoute } from './route-transformer'; /** * Watch mode configuration */ export interface WatchModeConfig { /** Root directory to watch */ readonly rootDir: string; /** Directories to watch (relative to rootDir) */ readonly watchPaths?: readonly string[]; /** File extensions to watch */ readonly extensions?: readonly string[]; /** Patterns to ignore */ readonly ignorePatterns?: readonly string[]; /** Debounce delay in milliseconds */ readonly debounceMs?: number; /** Enable verbose logging */ readonly verbose?: boolean; /** Discovery engine configuration */ readonly discovery?: Partial; /** Called when routes change */ readonly onRoutesChanged?: (routes: readonly TransformedRoute[], result: DiscoveryResult) => void; /** Called when a file is added */ readonly onFileAdded?: (filePath: string) => void; /** Called when a file is removed */ readonly onFileRemoved?: (filePath: string) => void; /** Called when a file is changed */ readonly onFileChanged?: (filePath: string) => void; /** Called when an error occurs */ readonly onError?: (error: Error) => void; /** Feature flag for watch mode */ readonly featureFlag?: string; } /** * File change event */ export interface FileChangeEvent { /** Change type */ readonly type: 'add' | 'change' | 'unlink'; /** Absolute file path */ readonly path: string; /** Relative path from root */ readonly relativePath: string; /** Timestamp of change */ readonly timestamp: number; } /** * Watch mode state */ export type WatchModeState = 'stopped' | 'starting' | 'running' | 'stopping' | 'error'; /** * Watch mode statistics */ export interface WatchModeStats { /** Total files watched */ readonly filesWatched: number; /** Directories watched */ readonly directoriesWatched: number; /** Total changes processed */ readonly changesProcessed: number; /** Total rediscoveries performed */ readonly rediscoveries: number; /** Average rediscovery time (ms) */ readonly avgRediscoveryMs: number; /** Watch mode uptime (ms) */ readonly uptimeMs: number; /** Last change timestamp */ readonly lastChangeAt: number | null; /** Last rediscovery timestamp */ readonly lastRediscoveryAt: number | null; } /** * Default watch mode configuration */ export declare const DEFAULT_WATCH_MODE_CONFIG: Partial; /** * Watch mode for hot-reloading route discovery * * @example * ```typescript * const watcher = new WatchMode({ * rootDir: '/project', * onRoutesChanged: (routes) => { * // Update your router with new routes * router.replaceRoutes(routes); * }, * }); * * await watcher.start(); * ``` */ export declare class WatchMode { private readonly config; private readonly engine; private watcher; private state; private pendingChanges; private debounceTimer; private startedAt; private stats; constructor(config: WatchModeConfig); /** * Get current watch mode state */ getState(): WatchModeState; /** * Get watch mode statistics */ getStats(): WatchModeStats; /** * Start watching for file changes * * @returns Initial discovery result */ start(): Promise; /** * Stop watching for file changes */ stop(): Promise; /** * Trigger an immediate rediscovery * * @param forceRefresh - Skip cache * @returns Discovery result */ rediscover(forceRefresh?: boolean): Promise; /** * Get the underlying discovery engine */ getEngine(): DiscoveryEngine; /** * Start the file system watcher */ private startWatcher; /** * Check if a path should be ignored */ private shouldIgnore; /** * Handle a file change event */ private handleFileChange; /** * Schedule a debounced rediscovery */ private scheduleRediscovery; /** * Perform route rediscovery */ private performRediscovery; /** * Log a message if verbose mode is enabled */ private log; } /** * Create a new WatchMode instance * * @param config - Watch mode configuration * @returns Configured WatchMode instance */ export declare function createWatchMode(config: WatchModeConfig): WatchMode; /** * HMR update handler type */ export type HMRUpdateHandler = (routes: readonly TransformedRoute[]) => void; /** * Create an HMR-compatible route updater * * @param updateHandler - Function to call when routes update * @returns Object with HMR lifecycle methods * * @example * ```typescript * const hmr = createHMRUpdater((routes) => { * // Update your router * router.replaceRoutes(routes); * }); * * // In your Vite plugin or webpack config * if (import.meta.hot) { * import.meta.hot.accept('./routes', hmr.accept); * import.meta.hot.dispose(hmr.dispose); * } * ``` */ export declare function createHMRUpdater(updateHandler: HMRUpdateHandler): { accept: (newModule: { routes: readonly TransformedRoute[]; }) => void; dispose: () => void; prune: () => void; }; /** * Vite plugin configuration for route discovery watch mode */ export interface VitePluginConfig { /** Root directory */ readonly rootDir?: string; /** Watch mode configuration */ readonly watchMode?: Partial; /** Enable in production (not recommended) */ readonly enableInProduction?: boolean; } /** * Create a Vite plugin configuration for watch mode * * @param config - Plugin configuration * @returns Vite plugin object * * @example * ```typescript * // vite.config.ts * import { createVitePlugin } from '@/lib/routing/discovery/watch-mode'; * * export default defineConfig({ * plugins: [ * createVitePlugin({ * rootDir: process.cwd(), * }), * ], * }); * ``` */ export declare function createVitePlugin(config?: VitePluginConfig): { name: string; configureServer?: (server: unknown) => void; }; /** * Get or create the default watch mode instance * * @param config - Configuration (required on first call) * @returns WatchMode instance */ export declare function getWatchMode(config?: WatchModeConfig): WatchMode; /** * Initialize the default watch mode * * @param config - Watch mode configuration */ export declare function initWatchMode(config: WatchModeConfig): void; /** * Reset the default watch mode */ export declare function resetWatchMode(): Promise;