All checks were successful
Build & Test / build-run (push) Successful in 42s
37 lines
824 B
TypeScript
37 lines
824 B
TypeScript
import { LocalStorage } from "./storage_manager.mjs"
|
|
|
|
type InstanceV0 = {
|
|
name: string,
|
|
origin: string,
|
|
software: string,
|
|
iconURL?: string,
|
|
preferredFor?: string[],
|
|
}
|
|
type LocalStorageV0 = {
|
|
version: undefined,
|
|
instances: InstanceV0[],
|
|
}
|
|
|
|
type LocalStorageV1 = LocalStorage;
|
|
|
|
function migrate0to1(s: LocalStorageV0): LocalStorageV1 {
|
|
return {
|
|
version: 1,
|
|
instances: s.instances.map(i => ({
|
|
preferredFor: i.preferredFor ?? [],
|
|
...i
|
|
}))
|
|
};
|
|
}
|
|
|
|
type AnyLocalStorage = LocalStorageV0 | LocalStorageV1;
|
|
|
|
export default function migrate(storage: AnyLocalStorage): LocalStorage {
|
|
switch (storage.version) {
|
|
case undefined:
|
|
storage = migrate0to1(storage);
|
|
case 1:
|
|
default:
|
|
return storage;
|
|
}
|
|
}
|