import * as plugins from '../ts/plugins.js'; import type { FlexStore } from '../ts/classes.flexstore.js'; export interface IFlexHarnessV3MigrationOptions { store: FlexStore; storageKeys: Iterable; } export class FlexHarnessV3MigrationRunner { private readonly store: FlexStore; private readonly storageKeys: string[]; constructor(optionsArg: IFlexHarnessV3MigrationOptions) { this.store = optionsArg.store; this.storageKeys = [...new Set(optionsArg.storageKeys)].sort(); } public async run(signalArg?: AbortSignal): Promise { const migrationStores = this.store.getLegacyMigrationStores(); for (const storageKey of this.storageKeys) { signalArg?.throwIfAborted(); if (!await this.store.hasCompletedLegacyMigration(storageKey)) { const legacySnapshot = await this.store.loadLegacy(storageKey); if (legacySnapshot) { await plugins.flexharnessMigration.migrateLegacyFlexHarnessSnapshot( storageKey, legacySnapshot, migrationStores, ); await this.store.completeLegacyMigration(storageKey); } } } } }