{"version":3,"file":"useDataIntegrity.mjs","sources":["../../../../src/lib/data/hooks/useDataIntegrity.ts"],"sourcesContent":["/**\n * @file useDataIntegrity Hook\n * @description React hook for monitoring and maintaining data integrity\n * with automatic validation, repair capabilities, and drift detection.\n *\n * Features:\n * - Real-time integrity monitoring\n * - Automatic and manual validation\n * - Integrity violation tracking\n * - Repair suggestions and execution\n * - State drift detection\n *\n * @example\n * ```typescript\n * import { useDataIntegrity, createIntegrityChecker } from '@/lib/data';\n *\n * const checker = createIntegrityChecker({\n *   entities: ['users', 'posts'],\n *   relations: [{ from: 'posts', field: 'authorId', to: 'users' }],\n * });\n *\n * function DataStatus() {\n *   const {\n *     isValid,\n *     violations,\n *     checkIntegrity,\n *     repair,\n *   } = useDataIntegrity(checker, normalizedEntities);\n *\n *   if (!isValid) {\n *     return <Alert>Data integrity issues: {violations.length}</Alert>;\n *   }\n * }\n * ```\n */\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport type { NormalizedEntities } from '../normalization/normalizer';\nimport type {\n  IntegrityChecker,\n  IntegrityReport,\n  IntegrityViolation,\n  RepairOptions,\n  RepairResult,\n} from '../integrity/integrity-checker';\nimport type { ConsistencyMonitor, DriftResult, MonitorStatus, StateSnapshot, } from '../integrity/consistency-monitor';\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\n/**\n * Integrity state\n */\nexport interface IntegrityState {\n  /** Overall validity */\n  isValid: boolean;\n  /** Is checking */\n  isChecking: boolean;\n  /** Is repairing */\n  isRepairing: boolean;\n  /** Last check report */\n  lastReport: IntegrityReport | null;\n  /** Current violations */\n  violations: IntegrityViolation[];\n  /** Violations by severity */\n  violationsByType: {\n    errors: IntegrityViolation[];\n    warnings: IntegrityViolation[];\n    info: IntegrityViolation[];\n  };\n  /** Last check timestamp */\n  lastCheckAt: number | null;\n  /** Check duration */\n  lastCheckDuration: number | null;\n}\n\n/**\n * Integrity hook options\n */\nexport interface UseDataIntegrityOptions {\n  /** Auto check on mount */\n  autoCheck?: boolean;\n  /** Auto check on entity changes */\n  checkOnChange?: boolean;\n  /** Debounce delay for change checks */\n  debounceMs?: number;\n  /** Auto repair on violations */\n  autoRepair?: boolean;\n  /** Repair only errors (not warnings) */\n  repairErrorsOnly?: boolean;\n  /** Callback on violations detected */\n  onViolations?: (violations: IntegrityViolation[]) => void;\n  /** Callback on integrity valid */\n  onValid?: () => void;\n  /** Callback on repair complete */\n  onRepair?: (result: RepairResult) => void;\n}\n\n/**\n * Integrity hook return type\n */\nexport interface UseDataIntegrityReturn {\n  /** Current state */\n  state: IntegrityState;\n  /** Is valid */\n  isValid: boolean;\n  /** Is checking */\n  isChecking: boolean;\n  /** Is repairing */\n  isRepairing: boolean;\n  /** All violations */\n  violations: IntegrityViolation[];\n  /** Error violations only */\n  errors: IntegrityViolation[];\n  /** Warning violations only */\n  warnings: IntegrityViolation[];\n  /** Last report */\n  lastReport: IntegrityReport | null;\n  /** Check integrity now */\n  checkIntegrity: () => IntegrityReport;\n  /** Check specific entity */\n  checkEntity: (entityType: string, entityId: string) => IntegrityViolation[];\n  /** Repair violations */\n  repair: (options?: RepairOptions) => RepairResult;\n  /** Clear state */\n  clear: () => void;\n  /** Get violations for entity */\n  getEntityViolations: (entityType: string, entityId: string) => IntegrityViolation[];\n  /** Check if entity has violations */\n  hasEntityViolations: (entityType: string, entityId: string) => boolean;\n}\n\n// =============================================================================\n// HOOK IMPLEMENTATION\n// =============================================================================\n\n/**\n * Hook for data integrity checking\n *\n * @param checker - Integrity checker instance\n * @param entities - Normalized entities to check\n * @param options - Hook options\n * @returns Integrity state and methods\n */\nexport function useDataIntegrity(\n  checker: IntegrityChecker,\n  entities: NormalizedEntities,\n  options: UseDataIntegrityOptions = {}\n): UseDataIntegrityReturn {\n  const {\n    autoCheck = true,\n    checkOnChange = false,\n    debounceMs = 300,\n    autoRepair = false,\n    repairErrorsOnly = true,\n    onViolations,\n    onValid,\n    onRepair,\n  } = options;\n\n  // State\n  const [state, setState] = useState<IntegrityState>({\n    isValid: true,\n    isChecking: false,\n    isRepairing: false,\n    lastReport: null,\n    violations: [],\n    violationsByType: {\n      errors: [],\n      warnings: [],\n      info: [],\n    },\n    lastCheckAt: null,\n    lastCheckDuration: null,\n  });\n\n  // Refs\n  const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n  const checkerRef = useRef(checker);\n  const entitiesRef = useRef(entities);\n  const repairRef = useRef<((repairOptions?: RepairOptions) => RepairResult) | null>(null);\n\n  // Update refs without causing re-renders\n  useEffect(() => {\n    checkerRef.current = checker;\n  }, [checker]);\n\n  useEffect(() => {\n    entitiesRef.current = entities;\n  }, [entities]);\n\n  // Group violations by severity\n  const groupViolations = useCallback((violations: IntegrityViolation[]) => {\n    return {\n      errors: violations.filter((v) => v.severity === 'error'),\n      warnings: violations.filter((v) => v.severity === 'warning'),\n      info: violations.filter((v) => v.severity === 'info'),\n    };\n  }, []);\n\n  // Check integrity\n  const checkIntegrity = useCallback((): IntegrityReport => {\n    setState((prev) => ({ ...prev, isChecking: true }));\n\n    const startTime = performance.now();\n    const report = checkerRef.current.check(entitiesRef.current);\n    const duration = performance.now() - startTime;\n\n    const violationsByType = groupViolations(report.violations);\n\n    setState({\n      isValid: report.valid,\n      isChecking: false,\n      isRepairing: false,\n      lastReport: report,\n      violations: report.violations,\n      violationsByType,\n      lastCheckAt: Date.now(),\n      lastCheckDuration: duration,\n    });\n\n    if (report.violations.length > 0) {\n      onViolations?.(report.violations);\n\n      if (autoRepair && repairRef.current != null) {\n        // Defer repair to next tick\n        setTimeout(() => {\n          if (repairRef.current != null) {\n            repairRef.current({ errorsOnly: repairErrorsOnly });\n          }\n        }, 0);\n      }\n    } else {\n      onValid?.();\n    }\n\n    return report;\n  }, [groupViolations, autoRepair, repairErrorsOnly, onViolations, onValid]);\n\n  // Check specific entity\n  const checkEntity = useCallback((entityType: string, entityId: string): IntegrityViolation[] => {\n    return checkerRef.current.checkEntity(entityType, entityId, entitiesRef.current);\n  }, []);\n\n  // Repair violations\n  const repair = useCallback(\n    (repairOptions?: RepairOptions): RepairResult => {\n      if (state.lastReport == null) {\n        // Run check first if no report\n        const report = checkIntegrity();\n        if (report.valid) {\n          return {\n            entities: entitiesRef.current,\n            repairs: [],\n            remaining: [],\n          };\n        }\n      }\n\n      setState((prev) => ({ ...prev, isRepairing: true }));\n\n      const result = checkerRef.current.repair(\n        entitiesRef.current,\n        state.lastReport as IntegrityReport,\n        repairOptions\n      );\n\n      const violationsByType = groupViolations(result.remaining);\n\n      setState((prev) => ({\n        ...prev,\n        isRepairing: false,\n        isValid: result.remaining.length === 0,\n        violations: result.remaining,\n        violationsByType,\n      }));\n\n      onRepair?.(result);\n\n      return result;\n    },\n    [state.lastReport, checkIntegrity, groupViolations, onRepair]\n  );\n\n  // Update repair ref\n  useEffect(() => {\n    repairRef.current = repair;\n  }, [repair]);\n\n  // Clear state\n  const clear = useCallback(() => {\n    setState({\n      isValid: true,\n      isChecking: false,\n      isRepairing: false,\n      lastReport: null,\n      violations: [],\n      violationsByType: {\n        errors: [],\n        warnings: [],\n        info: [],\n      },\n      lastCheckAt: null,\n      lastCheckDuration: null,\n    });\n  }, []);\n\n  // Get violations for entity\n  const getEntityViolations = useCallback(\n    (entityType: string, entityId: string): IntegrityViolation[] => {\n      return state.violations.filter((v) => v.entityType === entityType && v.entityId === entityId);\n    },\n    [state.violations]\n  );\n\n  // Check if entity has violations\n  const hasEntityViolations = useCallback(\n    (entityType: string, entityId: string): boolean => {\n      return state.violations.some((v) => v.entityType === entityType && v.entityId === entityId);\n    },\n    [state.violations]\n  );\n\n  // Auto check on mount\n  useEffect(() => {\n    if (autoCheck) {\n      checkIntegrity();\n    }\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  // Check on entity changes with debounce\n  useEffect(() => {\n    if (!checkOnChange) return;\n\n    if (debounceRef.current) {\n      clearTimeout(debounceRef.current);\n    }\n\n    debounceRef.current = setTimeout(() => {\n      checkIntegrity();\n    }, debounceMs);\n\n    return () => {\n      if (debounceRef.current) {\n        clearTimeout(debounceRef.current);\n      }\n    };\n  }, [entities, checkOnChange, debounceMs, checkIntegrity]);\n\n  return {\n    state,\n    isValid: state.isValid,\n    isChecking: state.isChecking,\n    isRepairing: state.isRepairing,\n    violations: state.violations,\n    errors: state.violationsByType.errors,\n    warnings: state.violationsByType.warnings,\n    lastReport: state.lastReport,\n    checkIntegrity,\n    checkEntity,\n    repair,\n    clear,\n    getEntityViolations,\n    hasEntityViolations,\n  };\n}\n\n// =============================================================================\n// SPECIALIZED HOOKS\n// =============================================================================\n\n/**\n * Hook for monitoring integrity with consistency monitor\n *\n * @param monitor - Consistency monitor instance\n * @param entities - Normalized entities\n * @returns Monitor state and actions\n */\nexport function useIntegrityMonitor(\n  monitor: ConsistencyMonitor,\n  entities: NormalizedEntities\n): {\n  status: MonitorStatus;\n  isValid: boolean;\n  violations: IntegrityViolation[];\n  lastReport: IntegrityReport | null;\n  check: () => Promise<IntegrityReport>;\n  repair: (options?: RepairOptions) => Promise<RepairResult>;\n  createSnapshot: (label?: string) => StateSnapshot;\n  snapshots: StateSnapshot[];\n} {\n  const [status, setStatus] = useState<MonitorStatus>(monitor.getStatus());\n  const [lastReport, setLastReport] = useState<IntegrityReport | null>(monitor.getLastReport());\n  const [snapshots, setSnapshots] = useState<StateSnapshot[]>(monitor.getSnapshots());\n\n  const entitiesRef = useRef(entities);\n\n  // Update ref without causing re-renders\n  useEffect(() => {\n    entitiesRef.current = entities;\n  }, [entities]);\n\n  useEffect(() => {\n\n\n    return monitor.subscribe((event) => {\n      switch (event.type) {\n        case 'status-change':\n          setStatus((event.data as { status: MonitorStatus }).status);\n          break;\n        case 'check-complete':\n          setLastReport((event.data as { report: IntegrityReport }).report);\n          break;\n        case 'snapshot-created':\n          setSnapshots(monitor.getSnapshots());\n          break;\n      }\n    });\n  }, [monitor]);\n\n  const check = useCallback(async () => {\n    return monitor.check(entitiesRef.current);\n  }, [monitor]);\n\n  const repair = useCallback(\n    async (options?: RepairOptions): Promise<RepairResult> => {\n      await Promise.resolve(); // Satisfy require-await lint rule\n      return monitor.repair(entitiesRef.current, options);\n    },\n    [monitor]\n  );\n\n  const createSnapshot = useCallback(\n    (label?: string) => {\n      return monitor.createSnapshot(entitiesRef.current, label);\n    },\n    [monitor]\n  );\n\n  return {\n    status,\n    isValid: status === 'valid',\n    violations: lastReport?.violations ?? [],\n    lastReport,\n    check,\n    repair,\n    createSnapshot,\n    snapshots,\n  };\n}\n\n/**\n * Hook for drift detection\n *\n * @param monitor - Consistency monitor instance\n * @param entities - Normalized entities\n * @returns Drift detection state\n */\nexport function useIntegrityDrift(\n  monitor: ConsistencyMonitor,\n  entities: NormalizedEntities\n): {\n  hasDrift: boolean;\n  drift: DriftResult | null;\n  detectDrift: () => DriftResult | null;\n  compareWithSnapshot: (snapshotId: string) => DriftResult | null;\n  createSnapshot: (label?: string) => StateSnapshot;\n  snapshots: StateSnapshot[];\n} {\n  const [drift, setDrift] = useState<DriftResult | null>(null);\n  const [snapshots, setSnapshots] = useState<StateSnapshot[]>(monitor.getSnapshots());\n\n  const entitiesRef = useRef(entities);\n\n  // Update ref without causing re-renders\n  useEffect(() => {\n    entitiesRef.current = entities;\n  }, [entities]);\n\n  useEffect(() => {\n\n\n    return monitor.subscribe((event) => {\n      if (event.type === 'drift-detected') {\n        setDrift((event.data as { drift: DriftResult }).drift);\n      }\n      if (event.type === 'snapshot-created') {\n        setSnapshots(monitor.getSnapshots());\n      }\n    });\n  }, [monitor]);\n\n  const detectDrift = useCallback(() => {\n    const result = monitor.detectDrift(entitiesRef.current);\n    setDrift(result);\n    return result;\n  }, [monitor]);\n\n  const compareWithSnapshot = useCallback(\n    (snapshotId: string) => {\n      const result = monitor.compareWithSnapshot(entitiesRef.current, snapshotId);\n      setDrift(result);\n      return result;\n    },\n    [monitor]\n  );\n\n  const createSnapshot = useCallback(\n    (label?: string) => {\n      return monitor.createSnapshot(entitiesRef.current, label);\n    },\n    [monitor]\n  );\n\n  return {\n    hasDrift: drift?.hasDrift ?? false,\n    drift,\n    detectDrift,\n    compareWithSnapshot,\n    createSnapshot,\n    snapshots,\n  };\n}\n\n/**\n * Hook for entity-level integrity checking\n *\n * @param checker - Integrity checker instance\n * @param entities - Normalized entities\n * @param entityType - Entity type to check\n * @param entityId - Entity ID to check\n * @returns Entity integrity state\n */\nexport function useEntityIntegrity(\n  checker: IntegrityChecker,\n  entities: NormalizedEntities,\n  entityType: string,\n  entityId: string\n): {\n  isValid: boolean;\n  violations: IntegrityViolation[];\n  check: () => IntegrityViolation[];\n} {\n  // Use useMemo to compute violations from dependencies\n  const violations = useMemo(() => {\n    return checker.checkEntity(entityType, entityId, entities);\n  }, [checker, entities, entityType, entityId]);\n\n  const [manualViolations, setManualViolations] = useState<IntegrityViolation[] | null>(null);\n\n  const check = useCallback(() => {\n    const result = checker.checkEntity(entityType, entityId, entities);\n    setManualViolations(result);\n    return result;\n  }, [checker, entities, entityType, entityId]);\n\n  // Use manual violations if available, otherwise use auto-computed\n  const activeViolations = manualViolations ?? violations;\n\n  return {\n    isValid: activeViolations.length === 0,\n    violations: activeViolations,\n    check,\n  };\n}\n"],"names":["useDataIntegrity","checker","entities","options","autoCheck","checkOnChange","debounceMs","autoRepair","repairErrorsOnly","onViolations","onValid","onRepair","state","setState","useState","debounceRef","useRef","checkerRef","entitiesRef","repairRef","useEffect","groupViolations","useCallback","violations","v","checkIntegrity","prev","startTime","report","duration","violationsByType","checkEntity","entityType","entityId","repair","repairOptions","result","clear","getEntityViolations","hasEntityViolations","useIntegrityMonitor","monitor","status","setStatus","lastReport","setLastReport","snapshots","setSnapshots","event","check","createSnapshot","label","useIntegrityDrift","drift","setDrift","detectDrift","compareWithSnapshot","snapshotId","useEntityIntegrity","useMemo","manualViolations","setManualViolations","activeViolations"],"mappings":";AAiJO,SAASA,EACdC,GACAC,GACAC,IAAmC,CAAA,GACX;AACxB,QAAM;AAAA,IACJ,WAAAC,IAAY;AAAA,IACZ,eAAAC,IAAgB;AAAA,IAChB,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