mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-30 19:12:57 -04:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import type { Settings } from 'insomnia-data';
|
|
|
|
import * as hotkeys from '../../../common-src/hotkeys';
|
|
import type { KeyboardShortcut } from '../../../common-src/settings';
|
|
|
|
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 = hotkeys.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;
|
|
}
|