mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 09:13:33 +00:00
refactor: introduce @bitwarden/state and other common libs (#15772)
* refactor: introduce @bitwarden/serialization * refactor: introduce @bitwarden/guid * refactor: introduce @bitwaren/client-type * refactor: introduce @bitwarden/core-test-utils * refactor: introduce @bitwarden/state and @bitwarden/state-test-utils Creates initial project structure for centralized application state management. Part of modularization effort to extract state code from common. * Added state provider documentation to README. * Changed callouts to Github format. * Fixed linting on file name. * Forced git to accept rename --------- Co-authored-by: Todd Martin <tmartin@bitwarden.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
|
||||
import { Migrator } from "../migrator";
|
||||
|
||||
const BAD_FOLDER_KEY: KeyDefinitionLike = {
|
||||
key: "folder", // We inadvertently changed the key from "folders" to "folder"
|
||||
stateDefinition: {
|
||||
name: "folder",
|
||||
},
|
||||
};
|
||||
|
||||
const GOOD_FOLDER_KEY: KeyDefinitionLike = {
|
||||
key: "folders", // We should keep the key as "folders"
|
||||
stateDefinition: {
|
||||
name: "folder",
|
||||
},
|
||||
};
|
||||
|
||||
export class MigrateIncorrectFolderKey extends Migrator<68, 69> {
|
||||
async migrate(helper: MigrationHelper): Promise<void> {
|
||||
async function migrateUser(userId: string) {
|
||||
const value = await helper.getFromUser(userId, BAD_FOLDER_KEY);
|
||||
if (value != null) {
|
||||
await helper.setToUser(userId, GOOD_FOLDER_KEY, value);
|
||||
}
|
||||
await helper.removeFromUser(userId, BAD_FOLDER_KEY);
|
||||
}
|
||||
const users = await helper.getKnownUserIds();
|
||||
await Promise.all(users.map((userId) => migrateUser(userId)));
|
||||
}
|
||||
|
||||
async rollback(helper: MigrationHelper): Promise<void> {
|
||||
async function rollbackUser(userId: string) {
|
||||
const value = await helper.getFromUser(userId, GOOD_FOLDER_KEY);
|
||||
if (value != null) {
|
||||
await helper.setToUser(userId, BAD_FOLDER_KEY, value);
|
||||
}
|
||||
await helper.removeFromUser(userId, GOOD_FOLDER_KEY);
|
||||
}
|
||||
const users = await helper.getKnownUserIds();
|
||||
await Promise.all(users.map((userId) => rollbackUser(userId)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user