mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 11:13:46 +00:00
* 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>
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { CURRENT_VERSION, currentVersion, MigrationHelper } from "@bitwarden/state";
|
|
|
|
import { ClientType } from "../../enums";
|
|
import { waitForMigrations } from "../../state-migrations";
|
|
import { LogService } from "../abstractions/log.service";
|
|
import { AbstractStorageService } from "../abstractions/storage.service";
|
|
|
|
import { MigrationBuilderService } from "./migration-builder.service";
|
|
|
|
export class MigrationRunner {
|
|
constructor(
|
|
protected diskStorage: AbstractStorageService,
|
|
protected logService: LogService,
|
|
protected migrationBuilderService: MigrationBuilderService,
|
|
private clientType: ClientType,
|
|
) {}
|
|
|
|
async run(): Promise<void> {
|
|
const migrationHelper = new MigrationHelper(
|
|
await currentVersion(this.diskStorage, this.logService),
|
|
this.diskStorage,
|
|
this.logService,
|
|
"general",
|
|
this.clientType,
|
|
);
|
|
|
|
if (migrationHelper.currentVersion < 0) {
|
|
// Cannot determine state, assuming empty so we don't repeatedly apply a migration.
|
|
await this.diskStorage.save("stateVersion", CURRENT_VERSION);
|
|
return;
|
|
}
|
|
|
|
const migrationBuilder = this.migrationBuilderService.build();
|
|
|
|
await migrationBuilder.migrate(migrationHelper);
|
|
}
|
|
|
|
async waitForCompletion(): Promise<void> {
|
|
await waitForMigrations(this.diskStorage, this.logService);
|
|
}
|
|
}
|