import { LibraryId } from './types'; /** * Feature identifier. */ export type FeatureId = string & { readonly __brand: 'FeatureId'; }; /** * Creates a FeatureId. */ export declare function createFeatureId(id: string): FeatureId; /** * Feature capability definition. */ export interface FeatureCapability { /** Capability name */ name: string; /** Capability version */ version: string; /** Capability handler */ handler: T; /** Required dependencies */ dependencies?: FeatureId[]; /** Description */ description?: string; } /** * Feature registration. */ export interface FeatureRegistration { /** Feature identifier */ id: FeatureId; /** Feature name */ name: string; /** Feature version */ version: string; /** Owning library */ library: LibraryId; /** Capabilities provided by this feature */ capabilities: Map; /** Dependencies on other features */ dependencies: FeatureId[]; /** Whether feature is loaded/active */ isActive: boolean; /** Lazy loader for the feature */ loader?: () => Promise; } /** * Bridge invocation options. */ export interface InvocationOptions { /** Timeout for the invocation (ms) */ timeout?: number; /** Fallback value if capability not available */ fallback?: unknown; /** Whether to throw on missing capability */ throwOnMissing?: boolean; /** Required minimum version */ minVersion?: string; } /** * Bridge invocation result. */ export interface InvocationResult { /** Whether invocation succeeded */ success: boolean; /** Result value */ value?: T; /** Error if failed */ error?: Error; /** Feature that handled the invocation */ handledBy?: FeatureId; /** Time taken (ms) */ duration: number; } /** * Feature bridge configuration. */ export interface FeatureBridgeConfig { /** Default invocation timeout (ms) */ defaultTimeout: number; /** Enable lazy loading */ enableLazyLoading: boolean; /** Enable invocation logging */ debug: boolean; /** Fallback behavior */ defaultFallbackBehavior: 'throw' | 'return-undefined' | 'use-fallback'; } /** * Implementation of the feature bridge. * * @example * ```typescript * const bridge = new FeatureBridgeImpl(); * * // Register a feature with capabilities * bridge.registerFeature({ * id: createFeatureId('user-management'), * name: 'User Management', * version: '1.0.0', * library: createLibraryId('auth'), * capabilities: new Map([ * ['getUserById', { * name: 'getUserById', * version: '1.0.0', * handler: async (id: string) => userService.getById(id), * }], * ]), * dependencies: [], * isActive: true, * }); * * // Invoke a capability * const result = await bridge.invoke( * 'user-management', * 'getUserById', * ['user-123'] * ); * ``` */ export declare class FeatureBridgeImpl { /** Configuration */ private readonly config; /** Registered features */ private readonly features; /** Capability index for fast lookup */ private readonly capabilityIndex; /** Loading promises for lazy features */ private readonly loadingPromises; /** * Creates a new feature bridge. * @param config - Configuration options */ constructor(config?: Partial); /** * Registers a feature. * @param registration - Feature registration */ registerFeature(registration: FeatureRegistration): void; /** * Unregisters a feature. * @param id - Feature ID */ unregisterFeature(id: FeatureId): void; /** * Adds a capability to a feature. * @param featureId - Feature ID * @param capability - Capability to add */ addCapability(featureId: FeatureId, capability: FeatureCapability): void; /** * Removes a capability from a feature. * @param featureId - Feature ID * @param capabilityName - Capability name */ removeCapability(featureId: FeatureId, capabilityName: string): void; /** * Invokes a capability on a specific feature. * @template T - Return type * @param featureId - Feature ID * @param capability - Capability name * @param args - Arguments to pass * @param options - Invocation options * @returns Invocation result */ invoke(featureId: FeatureId | string, capability: string, args?: unknown[], options?: InvocationOptions): Promise>; /** * Invokes a capability on any feature that provides it. * @template T - Return type * @param capability - Capability name * @param args - Arguments to pass * @param options - Invocation options * @returns Invocation result */ invokeAny(capability: string, args?: unknown[], options?: InvocationOptions): Promise>; /** * Checks if a feature is registered. * @param id - Feature ID */ hasFeature(id: FeatureId | string): boolean; /** * Checks if a capability is available. * @param capability - Capability name */ hasCapability(capability: string): boolean; /** * Gets features that provide a capability. * @param capability - Capability name * @returns Array of feature IDs */ getFeaturesWithCapability(capability: string): FeatureId[]; /** * Gets all capabilities of a feature. * @param id - Feature ID * @returns Array of capability names */ getFeatureCapabilities(id: FeatureId | string): string[]; /** * Gets all registered features. * @returns Array of feature registrations */ getAllFeatures(): FeatureRegistration[]; /** * Gets feature by ID. * @param id - Feature ID */ getFeature(id: FeatureId | string): FeatureRegistration | undefined; /** * Loads a lazy feature. * @param id - Feature ID */ loadFeature(id: FeatureId): Promise; /** * Activates a feature (marks as active without loading). * @param id - Feature ID */ activateFeature(id: FeatureId): void; /** * Deactivates a feature. * @param id - Feature ID */ deactivateFeature(id: FeatureId): void; /** * Disposes the bridge. */ dispose(): void; /** * Handles missing capability/feature. */ private handleMissing; /** * Invokes a handler with timeout. */ private invokeWithTimeout; } /** * Gets the global feature bridge. * @param config - Optional configuration */ export declare function getFeatureBridge(config?: Partial): FeatureBridgeImpl; /** * Sets the global feature bridge. * @param bridge - Feature bridge instance */ export declare function setFeatureBridge(bridge: FeatureBridgeImpl): void; /** * Resets the global feature bridge. */ export declare function resetFeatureBridge(): void; /** * Registers a feature with the global bridge. */ export declare function registerFeature(registration: FeatureRegistration): void; /** * Invokes a capability on the global bridge. */ export declare function invokeCapability(featureId: FeatureId | string, capability: string, args?: unknown[], options?: InvocationOptions): Promise>; /** * Invokes a capability on any providing feature. */ export declare function invokeAnyCapability(capability: string, args?: unknown[], options?: InvocationOptions): Promise>;