Files
insomnia/packages/insomnia-data/node-src/database/init-model/settings.ts
Bingbing b09cde814d refactor: extract insomnia-data into workspace package (#10010)
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.
2026-06-02 09:49:10 +00:00

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;
}