summaryrefslogtreecommitdiff
path: root/apps/web/src/stores/keybindings/migrations/index.ts
blob: 1689802e0510717d1cf50431f9f2c0853e57bb69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { v2ToV3 } from './v2-to-v3';

type MigrationFn = ({ state }: { state: unknown }) => unknown;

/**
 * key = version we're migrating from
 * value = migration function
 */
const migrations: Record<number, MigrationFn> = {
	2: v2ToV3,
};

export const CURRENT_VERSION = 3;

export function runMigrations({
	state,
	fromVersion,
}: {
	state: unknown;
	fromVersion: number;
}): unknown {
	let current = state;
	for (let version = fromVersion; version < CURRENT_VERSION; version++) {
		const migrate = migrations[version];
		if (migrate) current = migrate({ state: current });
	}
	return current;
}