import {Migration} from 'migration-helper'; export const migrations: Array> = [ { version: '1.1.2', async migrate(data: Record) { const migrated: Record = { data: { hideVotes: data.data.hideVotes as Record, knownGroups: data.data.knownGroups as string[], latestActiveFeatureTab: data.data.latestActiveFeatureTab as string, }, features: (data.features as Record) ?? {}, version: '1.1.2', }; const userLabels = data.data.userLabels as UserLabel[]; for (const label of userLabels) { migrated[`userLabel${label.id}`] = label; } const usernameColors = data.data.usernameColors as UsernameColor[]; for (const color of usernameColors) { migrated[`usernameColor${color.id}`] = color; } return migrated; }, }, ]; export function deserializeData(data: Record): { userLabels: UserLabel[]; usernameColors: UsernameColor[]; } { const deserialized: ReturnType = { userLabels: [], usernameColors: [], }; for (const [key, value] of Object.entries(data)) { if (key.startsWith('userLabel')) { deserialized.userLabels.push(value); } else if (key.startsWith('usernameColor')) { deserialized.usernameColors.push(value); } } return deserialized; }