import type {Migration} from '@holllo/migration-helper'; export const dataMigrations: Array> = [ { version: '0.1.7', async migrate(data: Record) { const migrated: Record = { version: '0.1.7', }; const items = (data.queue as Queue.Item[]) ?? []; for (const item of items) { const key = `qi${item.id}`; migrated[key] = item; } return migrated; }, }, ]; export function deserializeQueue(data: Record): Queue.Item[] { const deserialized: Queue.Item[] = []; for (const [key, item] of Object.entries(data)) { if (/^qi\d+$/.test(key)) { item.added = new Date(item.added); deserialized.push(item); } } return deserialized; } export function serializeQueue(queue: Queue.Item[]): Record { const serialized: Record = {}; for (const item of queue) { const key = `qi${item.id}`; serialized[key] = {...item}; serialized[key].added = item.added.toISOString(); } return serialized; }