{"version":3,"file":"context-bridge.mjs","sources":["../../../src/lib/coordination/context-bridge.tsx"],"sourcesContent":["/* eslint-disable react-refresh/only-export-components */\n/* @refresh reset */\n/**\n * @file Context Bridge\n * @module coordination/context-bridge\n * @description PhD-level React context bridging across provider boundaries.\n *\n * Implements sophisticated context bridging with:\n * - Cross-boundary context value passing\n * - Type-safe context transformation\n * - Batched update propagation\n * - Selective subscription\n * - Context composition utilities\n *\n * @author Agent 5 - PhD TypeScript Architect\n * @version 1.0.0\n */\n\nimport React, {\n  createContext,\n  useContext,\n  useState,\n  useEffect,\n  useMemo,\n  useCallback,\n  useRef,\n  type Context,\n  type ReactNode,\n  type FC,\n} from 'react';\nimport { BridgeManagerContext } from '../contexts/BridgeManagerContext';\n\nimport type { ContextBridgeDefinition } from './types';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Context bridge registry entry.\n */\ninterface BridgeEntry<TSource = unknown, TTarget = unknown> {\n  /** Bridge definition */\n  definition: ContextBridgeDefinition<TSource, TTarget>;\n  /** Current transformed value */\n  currentValue: TTarget | null;\n  /** Subscribers to value changes */\n  subscribers: Set<(value: TTarget) => void>;\n  /** Last update timestamp */\n  lastUpdate: number;\n}\n\n/**\n * Bridge configuration options.\n */\nexport interface BridgeOptions<TSource, TTarget> {\n  /** Transform source to target value */\n  transformer: (source: TSource) => TTarget;\n  /** Update strategy */\n  updateStrategy?: 'immediate' | 'batched' | 'debounced';\n  /** Debounce/batch window (ms) */\n  updateWindow?: number;\n  /** Equality check for optimization */\n  equalityFn?: (prev: TTarget, next: TTarget) => boolean;\n  /** Debug mode */\n  debug?: boolean;\n}\n\n/**\n * Composed context value type.\n */\nexport type ComposedContextValue<T extends Record<string, unknown>> = T;\n\n/**\n * Context selector function.\n */\nexport type ContextSelector<TContext, TSelected> = (context: TContext) => TSelected;\n\n// ============================================================================\n// ContextBridgeImpl Class\n// ============================================================================\n\n/**\n * Implementation of the context bridge manager.\n *\n * @example\n * ```tsx\n * const bridge = new ContextBridgeImpl();\n *\n * // Register a bridge from Auth context to User context\n * bridge.registerBridge({\n *   id: 'auth-to-user',\n *   sourceContext: AuthContext,\n *   targetContext: UserContext,\n *   transformer: (auth) => ({\n *     id: auth.user?.id,\n *     name: auth.user?.name,\n *     isAdmin: auth.roles?.includes('admin'),\n *   }),\n *   updateStrategy: 'batched',\n * });\n * ```\n */\nexport class ContextBridgeImpl {\n  /** Registered bridges */\n  private readonly bridges: Map<string, BridgeEntry> = new Map();\n\n  /** Pending batched updates */\n  private pendingUpdates: Map<string, unknown> = new Map();\n\n  /** Batch timer */\n  private batchTimer: ReturnType<typeof setTimeout> | null = null;\n\n  /** Batch window (ms) */\n  private readonly batchWindow: number;\n\n  /**\n   * Creates a new context bridge manager.\n   * @param batchWindow - Default batch window in ms\n   */\n  constructor(batchWindow = 16) {\n    this.batchWindow = batchWindow;\n  }\n\n  // ==========================================================================\n  // Bridge Registration\n  // ==========================================================================\n\n  /**\n   * Registers a context bridge.\n   * @template TSource - Source context type\n   * @template TTarget - Target context type\n   * @param definition - Bridge definition\n   */\n  registerBridge<TSource, TTarget>(\n    definition: ContextBridgeDefinition<TSource, TTarget>\n  ): void {\n    const entry: BridgeEntry<TSource, TTarget> = {\n      definition,\n      currentValue: null,\n      subscribers: new Set(),\n      lastUpdate: 0,\n    };\n\n    this.bridges.set(definition.id, entry as BridgeEntry);\n  }\n\n  /**\n   * Unregisters a context bridge.\n   * @param id - Bridge ID\n   */\n  unregisterBridge(id: string): void {\n    const entry = this.bridges.get(id);\n    if (entry) {\n      entry.subscribers.clear();\n      this.bridges.delete(id);\n    }\n  }\n\n  /**\n   * Updates a bridge with new source value.\n   * @param id - Bridge ID\n   * @param sourceValue - New source value\n   */\n  updateBridge<TSource>(id: string, sourceValue: TSource): void {\n    const entry = this.bridges.get(id) as BridgeEntry<TSource> | undefined;\n    if (!entry) return;\n\n    const { definition } = entry;\n    const newValue = definition.transformer(sourceValue);\n\n    switch (definition.updateStrategy) {\n      case 'batched':\n        this.pendingUpdates.set(id, newValue);\n        this.scheduleBatch();\n        break;\n\n      case 'debounced':\n        this.pendingUpdates.set(id, newValue);\n        this.scheduleBatch(definition.updateWindow ?? this.batchWindow);\n        break;\n\n      case 'immediate':\n      default:\n        this.notifySubscribers(id, newValue);\n    }\n  }\n\n  /**\n   * Subscribes to bridge value changes.\n   * @param id - Bridge ID\n   * @param callback - Change callback\n   * @returns Unsubscribe function\n   */\n  subscribe<TTarget>(id: string, callback: (value: TTarget) => void): () => void {\n    const entry = this.bridges.get(id);\n    if (!entry) return () => {};\n\n    entry.subscribers.add(callback as (value: unknown) => void);\n\n    // Send current value immediately\n    if (entry.currentValue !== null) {\n      callback(entry.currentValue as TTarget);\n    }\n\n    return () => {\n      entry.subscribers.delete(callback as (value: unknown) => void);\n    };\n  }\n\n  /**\n   * Gets current bridged value.\n   * @param id - Bridge ID\n   * @returns Current value or null\n   */\n  getValue<TTarget>(id: string): TTarget | null {\n    const entry = this.bridges.get(id);\n    return (entry?.currentValue as TTarget) ?? null;\n  }\n\n  // ==========================================================================\n  // Private Methods\n  // ==========================================================================\n\n  /**\n   * Disposes the bridge manager.\n   */\n  dispose(): void {\n    if (this.batchTimer) {\n      clearTimeout(this.batchTimer);\n      this.batchTimer = null;\n    }\n\n    for (const entry of this.bridges.values()) {\n      entry.subscribers.clear();\n    }\n\n    this.bridges.clear();\n    this.pendingUpdates.clear();\n  }\n\n  /**\n   * Schedules batch processing.\n   */\n  private scheduleBatch(delay = this.batchWindow): void {\n    if (this.batchTimer) return;\n\n    this.batchTimer = setTimeout(() => {\n      this.batchTimer = null;\n      this.processBatch();\n    }, delay);\n  }\n\n  /**\n   * Processes batched updates.\n   */\n  private processBatch(): void {\n    const updates = this.pendingUpdates;\n    this.pendingUpdates = new Map();\n\n    for (const [id, value] of updates) {\n      this.notifySubscribers(id, value);\n    }\n  }\n\n  /**\n   * Notifies subscribers of a value change.\n   */\n  private notifySubscribers(id: string, value: unknown): void {\n    const entry = this.bridges.get(id);\n    if (!entry) return;\n\n    entry.currentValue = value;\n    entry.lastUpdate = Date.now();\n\n    for (const subscriber of entry.subscribers) {\n      try {\n        subscriber(value);\n      } catch (error) {\n        console.error(`[ContextBridge] Subscriber error for ${id}:`, error);\n      }\n    }\n  }\n}\n\n// ============================================================================\n// React Components and Hooks\n// ============================================================================\n\n/**\n * Props for ContextBridgeProvider.\n */\nexport interface ContextBridgeProviderProps {\n  /** Children to render */\n  children: ReactNode;\n  /** Optional custom bridge manager */\n  manager?: ContextBridgeImpl;\n}\n\n/**\n * Provider component for context bridge manager.\n */\nexport const ContextBridgeProvider: FC<ContextBridgeProviderProps> = ({\n  children,\n  manager,\n}) => {\n  const bridgeManager = useMemo(() => manager ?? new ContextBridgeImpl(), [manager]);\n\n  useEffect(() => {\n    return () => {\n      if (!manager) {\n        bridgeManager.dispose();\n      }\n    };\n  }, [bridgeManager, manager]);\n\n  return (\n    <BridgeManagerContext.Provider value={bridgeManager}>\n      {children}\n    </BridgeManagerContext.Provider>\n  );\n};\n\nContextBridgeProvider.displayName = 'ContextBridgeProvider';\n\n/**\n * Hook to access the bridge manager.\n */\nexport function useBridgeManager(): import('../contexts/BridgeManagerContext').ContextBridgeImpl {\n  const manager = useContext(BridgeManagerContext);\n  if (!manager) {\n    throw new Error('useBridgeManager must be used within a ContextBridgeProvider');\n  }\n  return manager;\n}\n\n/**\n * Hook to consume a bridged context value.\n * @template TTarget - Target value type\n * @param bridgeId - Bridge ID\n * @returns Bridged value\n */\nexport function useBridgedContext<TTarget>(bridgeId: string): TTarget | null {\n  const manager = useBridgeManager();\n  const [value, setValue] = useState<TTarget | null>(() => manager.getValue<TTarget>(bridgeId));\n\n  useEffect(() => {\n    return manager.subscribe<TTarget>(bridgeId, setValue);\n  }, [manager, bridgeId]);\n\n  return value;\n}\n\n/**\n * Props for BridgeSource component.\n */\nexport interface BridgeSourceProps<TSource> {\n  /** Bridge ID */\n  bridgeId: string;\n  /** Source context */\n  context: Context<TSource | null>;\n  /** Children to render */\n  children: ReactNode;\n}\n\n/**\n * Component that bridges a source context to the bridge manager.\n */\nexport function BridgeSource<TSource>({\n  bridgeId,\n  context,\n  children,\n}: BridgeSourceProps<TSource>): React.JSX.Element {\n  const manager = useBridgeManager();\n  const sourceValue = useContext(context);\n\n  useEffect(() => {\n    if (sourceValue !== null) {\n      manager.updateBridge(bridgeId, sourceValue);\n    }\n  }, [manager, bridgeId, sourceValue]);\n\n  return <>{children}</>;\n}\n\n/**\n * Props for BridgeConsumer component.\n */\nexport interface BridgeConsumerProps<TTarget> {\n  /** Bridge ID */\n  bridgeId: string;\n  /** Render function */\n  children: (value: TTarget | null) => ReactNode;\n}\n\n/**\n * Component that consumes a bridged context value.\n */\nexport function BridgeConsumer<TTarget>({\n  bridgeId,\n  children,\n}: BridgeConsumerProps<TTarget>): React.JSX.Element {\n  const value = useBridgedContext<TTarget>(bridgeId);\n  return <>{children(value)}</>;\n}\n\n// ============================================================================\n// Context Composition Utilities\n// ============================================================================\n\n/**\n * Creates a composed context from multiple source contexts.\n * @template T - Composed context type\n * @param config - Context configuration\n * @returns Composed context and provider\n */\nexport function createComposedContext<T extends Record<string, unknown>>(config: {\n  displayName: string;\n  sources: {\n    [K in keyof T]: {\n      context: Context<T[K] | null>;\n      selector?: (value: T[K]) => unknown;\n    };\n  };\n}): {\n  Context: Context<T | null>;\n  Provider: FC<{ children: ReactNode }>;\n  useComposed: () => T;\n} {\n  const ComposedContext = createContext<T | null>(null);\n  ComposedContext.displayName = config.displayName;\n\n  const ComposedProvider: FC<{ children: ReactNode }> = ({ children }) => {\n    // Get all source values\n    const sourceEntries = Object.entries(config.sources) as Array<[keyof T, typeof config.sources[keyof T]]>;\n\n    // Collect all context values for memoization\n    const contextValues: unknown[] = [];\n\n    for (const [_key, source] of sourceEntries) {\n      // eslint-disable-next-line react-hooks/rules-of-hooks\n      const value = useContext(source.context);\n      const transformedValue = (source.selector != null && value != null ? source.selector(value) : value);\n      contextValues.push(transformedValue);\n    }\n\n    // Memoize the composed value based on individual context values\n    const composedValue = useMemo(() => {\n      const sourceValues = {} as Partial<T>;\n      for (let i = 0; i < sourceEntries.length; i++) {\n        const entry = sourceEntries[i];\n        if (entry !== undefined) {\n          const [key] = entry;\n          (sourceValues as Record<string, unknown>)[key as string] = contextValues[i];\n        }\n      }\n      return sourceValues as T;\n      // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, [...contextValues]);\n\n    return (\n      <ComposedContext.Provider value={composedValue}>\n        {children}\n      </ComposedContext.Provider>\n    );\n  };\n\n  ComposedProvider.displayName = `${config.displayName}Provider`;\n\n  const useComposed = (): T => {\n    const value = useContext(ComposedContext);\n    if (value === null) {\n      throw new Error(`useComposed must be used within a ${config.displayName}Provider`);\n    }\n    return value;\n  };\n\n  return {\n    Context: ComposedContext,\n    Provider: ComposedProvider,\n    useComposed,\n  };\n}\n\n/**\n * Hook to select from multiple contexts with optimization.\n * @template TResult - Result type\n * @param selector - Selector function receiving context getters\n * @param deps - Dependencies for the selector\n * @returns Selected value\n */\nexport function useMultiContextSelector<TResult>(\n  selector: (getContext: <T>(context: Context<T | null>) => T | null) => TResult,\n  deps: Array<Context<unknown>>\n): TResult {\n  const contextValues = useRef<Map<Context<unknown>, unknown>>(new Map());\n\n  // Get all context values\n  for (const ctx of deps) {\n    // eslint-disable-next-line react-hooks/rules-of-hooks\n    const value = useContext(ctx);\n    contextValues.current.set(ctx, value);\n  }\n\n  const getContext = useCallback(<T,>(context: Context<T | null>): T | null => {\n    return contextValues.current.get(context as Context<unknown>) as T | null;\n  }, []);\n\n  return useMemo(() => selector(getContext), [selector, getContext]);\n}\n\n// ============================================================================\n// Higher-Order Component\n// ============================================================================\n\n/**\n * Props added by withBridgedContext HOC.\n */\nexport interface WithBridgedContextProps<T> {\n  bridgedValue: T | null;\n}\n\n/**\n * HOC to inject bridged context value as prop.\n * @template P - Component props\n * @template T - Bridged value type\n * @param bridgeId - Bridge ID\n * @returns HOC function\n */\nexport function withBridgedContext<P extends WithBridgedContextProps<T>, T>(\n  bridgeId: string\n): (Component: React.ComponentType<P>) => React.FC<Omit<P, keyof WithBridgedContextProps<T>>> {\n  return (Component) => {\n    const WrappedComponent: React.FC<Omit<P, keyof WithBridgedContextProps<T>>> = (props) => {\n      const bridgedValue = useBridgedContext<T>(bridgeId);\n      return <Component {...(props as P)} bridgedValue={bridgedValue} />;\n    };\n\n    WrappedComponent.displayName = `withBridgedContext(${Component.displayName ?? Component.name ?? 'Component'})`;\n\n    return WrappedComponent;\n  };\n}\n\n// ============================================================================\n// Singleton Instance\n// ============================================================================\n\n/**\n * Global context bridge manager.\n */\nlet globalBridgeManager: ContextBridgeImpl | null = null;\n\n/**\n * Gets the global context bridge manager.\n */\nexport function getContextBridgeManager(): ContextBridgeImpl {\n  globalBridgeManager ??= new ContextBridgeImpl();\n  return globalBridgeManager;\n}\n\n/**\n * Sets the global context bridge manager.\n */\nexport function setContextBridgeManager(manager: ContextBridgeImpl): void {\n  if (globalBridgeManager) {\n    globalBridgeManager.dispose();\n  }\n  globalBridgeManager = manager;\n}\n\n/**\n * Resets the global context bridge manager.\n */\nexport function resetContextBridgeManager(): void {\n  if (globalBridgeManager) {\n    globalBridgeManager.dispose();\n    globalBridgeManager = null;\n  }\n}\n\n// ============================================================================\n// Export\n// ============================================================================\n\nexport { BridgeManagerContext };\n"],"names":["ContextBridgeImpl","batchWindow","definition","entry","id","sourceValue","newValue","callback","delay","updates","value","subscriber","error","ContextBridgeProvider","children","manager","bridgeManager","useMemo","useEffect","BridgeManagerContext","useBridgeManager","useContext","useBridgedContext","bridgeId","setValue","useState","BridgeSource","context","BridgeConsumer","jsx","Fragment","createComposedContext","config","ComposedContext","createContext","ComposedProvider","sourceEntries","contextValues","_key","source","transformedValue","composedValue","sourceValues","i","key","useMultiContextSelector","selector","deps","useRef","ctx","getContext","useCallback","withBridgedContext","Component","WrappedComponent","props","bridgedValue","globalBridgeManager","getContextBridgeManager","setContextBridgeManager","resetContextBridgeManager"],"mappings":";;;AAuGO,MAA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