import type { Settings } from 'insomnia-data'; import type { KeyboardShortcut } from 'insomnia-data/common'; import { newDefaultRegistry } from 'insomnia-data/common'; export function migrate(doc: Settings) { try { doc = migrateEnsureHotKeys(doc); return doc; } catch (e) { console.log('[db] Error during settings migration', e); throw e; } } /** * Ensure map is updated when new hotkeys are added */ function migrateEnsureHotKeys(settings: Settings): Settings { const defaultHotKeyRegistry = newDefaultRegistry(); // Remove any hotkeys that are no longer in the default registry const hotKeyRegistry = (Object.keys(settings.hotKeyRegistry) as KeyboardShortcut[]).reduce( (newHotKeyRegistry, key) => { if (key in defaultHotKeyRegistry) { newHotKeyRegistry[key] = settings.hotKeyRegistry[key]; } return newHotKeyRegistry; }, {} as Settings['hotKeyRegistry'], ); settings.hotKeyRegistry = { ...defaultHotKeyRegistry, ...hotKeyRegistry }; return settings; }