import { SyncConflict, SyncEngine, SyncOptions, SyncResult, SyncStatus } from '../sync/sync-engine'; import { ConflictResolutionResult, ConflictStrategy } from '../sync/conflict-resolver'; import { Entity } from '../normalization/normalizer'; /** * Sync state for an entity type */ export interface SyncState { /** Current data */ data: T[]; /** Sync status */ status: SyncStatus; /** Is initial load */ isLoading: boolean; /** Is syncing */ isSyncing: boolean; /** Is offline */ isOffline: boolean; /** Last sync timestamp */ lastSyncAt: number | null; /** Pending changes count */ pendingChanges: number; /** Active conflicts */ conflicts: SyncConflict[]; /** Last error */ error: Error | null; } /** * Sync hook options */ export interface UseDataSyncOptions { /** Sync engine instance */ engine: SyncEngine; /** Entity type to sync */ entityType: string; /** Initial data */ initialData?: T[]; /** Auto sync on mount */ autoSync?: boolean; /** Sync interval in ms (0 = manual only) */ syncInterval?: number; /** Conflict resolution strategy */ conflictStrategy?: ConflictStrategy; /** Custom conflict resolver */ onConflict?: (conflict: SyncConflict) => Promise>; /** Callback on sync success */ onSyncSuccess?: (result: SyncResult) => void; /** Callback on sync error */ onSyncError?: (error: Error) => void; /** Callback on data change */ onDataChange?: (data: T[]) => void; /** Enable optimistic updates */ optimisticUpdates?: boolean; /** Filter function for data */ filter?: (item: T) => boolean; /** Sort function for data */ sort?: (a: T, b: T) => number; } /** * Sync hook return type */ export interface UseDataSyncReturn { /** Current state */ state: SyncState; /** Current data */ data: T[]; /** Is loading */ isLoading: boolean; /** Is syncing */ isSyncing: boolean; /** Is offline */ isOffline: boolean; /** Has conflicts */ hasConflicts: boolean; /** Active conflicts */ conflicts: SyncConflict[]; /** Last error */ error: Error | null; /** Trigger sync */ sync: (options?: SyncOptions) => Promise; /** Create entity */ create: (data: Omit) => Promise; /** Update entity */ update: (id: string, data: Partial) => Promise; /** Delete entity */ remove: (id: string) => Promise; /** Resolve conflict */ resolveConflict: (conflictId: string, resolution: 'local' | 'remote' | 'merge', mergedData?: T) => Promise; /** Resolve all conflicts */ resolveAllConflicts: (strategy: 'local' | 'remote') => Promise; /** Retry failed syncs */ retryFailed: () => Promise; /** Clear offline queue */ clearOfflineQueue: () => void; /** Get entity by ID */ getById: (id: string) => T | undefined; /** Refresh data */ refresh: () => Promise; } /** * Hook for data synchronization * * @param options - Sync options * @returns Sync state and methods */ export declare function useDataSync(options: UseDataSyncOptions): UseDataSyncReturn; /** * Hook for sync status only * * @param engine - Sync engine instance * @returns Sync status */ export declare function useSyncStatus(engine: SyncEngine): { status: SyncStatus; isOnline: boolean; pendingChanges: number; lastSyncAt: number | null; }; /** * Hook for conflict management * * @param engine - Sync engine instance * @returns Conflict management methods */ export declare function useSyncConflicts(engine: SyncEngine): { conflicts: SyncConflict[]; hasConflicts: boolean; resolveConflict: (id: string, data: Entity) => Promise; resolveAllLocal: () => Promise; resolveAllRemote: () => Promise; };