mirror of
https://github.com/Kong/insomnia.git
synced 2026-06-04 06:10:24 -04:00
Move insomnia-data models, services, database code, and common utilities into a dedicated workspace package. Update consumers to import from the new package entrypoints and declare workspace dependencies for the extracted package.
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
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;
|
|
}
|