import type { FlexStore } from '../ts/classes.flexstore.js'; export interface IFlexProjectionOrderMigrationOptions { store: FlexStore; storageKeys: Iterable; } export class FlexProjectionOrderMigration { private readonly store: FlexStore; private readonly storageKeys: string[]; constructor(optionsArg: IFlexProjectionOrderMigrationOptions) { this.store = optionsArg.store; this.storageKeys = [...new Set(optionsArg.storageKeys)].sort(); } public async run(signalArg?: AbortSignal): Promise { for (const storageKey of this.storageKeys) { let cursor: Awaited>[ 'nextCursor' ]; do { signalArg?.throwIfAborted(); const page = await this.store.listProjectionOrderMigrationPage(storageKey, cursor); for (const sessionId of page.sessionIds) { signalArg?.throwIfAborted(); await this.store.rewriteProjectionSourceOrder(storageKey, sessionId); } cursor = page.nextCursor; } while (cursor); } } }