import { KeyDefinitionLike, MigrationHelper } from "../migration-helper"; import { Migrator } from "../migrator"; type ExpectedGlobal = { enableDuckDuckGoBrowserIntegration?: boolean; }; export const DDG_KEY: KeyDefinitionLike = { key: "enableDuckDuckGoBrowserIntegration", stateDefinition: { name: "autofillSettings", }, }; export class MoveDdgToStateProviderMigrator extends Migrator<47, 48> { async migrate(helper: MigrationHelper): Promise { // global state const global = await helper.get("global"); if (global?.enableDuckDuckGoBrowserIntegration == null) { return; } await helper.setToGlobal(DDG_KEY, global.enableDuckDuckGoBrowserIntegration); delete global.enableDuckDuckGoBrowserIntegration; await helper.set("global", global); } async rollback(helper: MigrationHelper): Promise { const enableDdg = await helper.getFromGlobal(DDG_KEY); if (!enableDdg) { return; } const global = (await helper.get("global")) ?? {}; global.enableDuckDuckGoBrowserIntegration = enableDdg; await helper.set("global", global); await helper.removeFromGlobal(DDG_KEY); } }