()
| 58 | * 3. Raw data: `{ workflowEntries: {...}, isOpen }` (current format) |
| 59 | */ |
| 60 | export async function loadConsoleData(): Promise<PersistedConsoleData | null> { |
| 61 | if (typeof window === 'undefined') return null |
| 62 | |
| 63 | if (migrationPromise) { |
| 64 | await migrationPromise |
| 65 | } |
| 66 | |
| 67 | try { |
| 68 | const raw = await get<string>(STORE_KEY) |
| 69 | if (!raw) return null |
| 70 | |
| 71 | const parsed = typeof raw === 'string' ? JSON.parse(raw) : raw |
| 72 | if (!parsed || typeof parsed !== 'object') return null |
| 73 | |
| 74 | const data = parsed.state ?? parsed |
| 75 | |
| 76 | if (Array.isArray(data.entries) && !data.workflowEntries) { |
| 77 | const workflowEntries: Record<string, ConsoleEntry[]> = {} |
| 78 | for (const entry of data.entries) { |
| 79 | if (!entry?.workflowId) continue |
| 80 | const wfId = entry.workflowId |
| 81 | if (!workflowEntries[wfId]) workflowEntries[wfId] = [] |
| 82 | workflowEntries[wfId].push(entry) |
| 83 | } |
| 84 | return { workflowEntries, isOpen: Boolean(data.isOpen) } |
| 85 | } |
| 86 | |
| 87 | return { |
| 88 | workflowEntries: data.workflowEntries ?? {}, |
| 89 | isOpen: Boolean(data.isOpen), |
| 90 | } |
| 91 | } catch (error) { |
| 92 | logger.warn('Failed to load console data from IndexedDB', { error }) |
| 93 | return null |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | let activeWrite: Promise<void> | null = null |
| 98 |
no test coverage detected