# Code coverage report for src/store/middleware/persistenceConfig.ts

# All files / src/store/middleware persistenceConfig.ts

66.66% Statements 50/75
100% Branches 1/1
10% Functions 1/10
66.66% Lines 50/75

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    761x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    107x
    107x
    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

     export interface PersistenceConfig {
      enabled: boolean
      debounceMs: number
      logging: boolean
      actions: string[]
      retryOnFailure: boolean
      maxRetries: number
      retryDelayMs: number
    }

    export const defaultPersistenceConfig: PersistenceConfig = {
      enabled: true,
      debounceMs: 100,
      logging: true,
      actions: [
        'snippets/create/fulfilled',
        'snippets/update/fulfilled',
        'snippets/delete/fulfilled',
        'snippets/bulkMove/fulfilled',
        'namespaces/create/fulfilled',
        'namespaces/delete/fulfilled',
      ],
      retryOnFailure: true,
      maxRetries: 3,
      retryDelayMs: 1000,
    }

    let currentConfig: PersistenceConfig = { ...defaultPersistenceConfig }

    export function getPersistenceConfig(): PersistenceConfig {
      return currentConfig
    }

    export function updatePersistenceConfig(partial: Partial<PersistenceConfig>): void {
      currentConfig = {
        ...currentConfig,
        ...partial,
      }
    }

    export function resetPersistenceConfig(): void {
      currentConfig = { ...defaultPersistenceConfig }
    }

    export function addPersistenceAction(action: string): void {
      if (!currentConfig.actions.includes(action)) {
        currentConfig.actions.push(action)
      }
    }

    export function removePersistenceAction(action: string): void {
      currentConfig.actions = currentConfig.actions.filter(a => a !== action)
    }

    export function enablePersistence(): void {
      currentConfig.enabled = true
    }

    export function disablePersistence(): void {
      currentConfig.enabled = false
    }

    export function enableLogging(): void {
      currentConfig.logging = true
    }

    export function disableLogging(): void {
      currentConfig.logging = false
    }

    export function setDebounceDelay(ms: number): void {
      if (ms >= 0) {
        currentConfig.debounceMs = ms
      }
    }