1
Fork 0
tildes-reextended/source/storage/migrations/v1-1-2.ts

134 lines
3.0 KiB
TypeScript
Raw Permalink Normal View History

2023-06-29 16:44:30 +00:00
/**
* The deserialize data function from version 1.1.2 and before.
*/
export function v112DeserializeData(data: Record<string, any>): {
userLabels: V112Settings["data"]["userLabels"];
usernameColors: V112Settings["data"]["usernameColors"];
} {
const deserialized: ReturnType<typeof v112DeserializeData> = {
userLabels: [],
usernameColors: [],
};
if (data.data?.userLabels !== undefined) {
deserialized.userLabels = data.data
.userLabels as V112Settings["data"]["userLabels"];
}
if (data.data?.usernameColors !== undefined) {
deserialized.usernameColors = data.data
.usernameColors as V112Settings["data"]["usernameColors"];
}
for (const [key, value] of Object.entries(data)) {
if (key.startsWith("userLabel")) {
deserialized.userLabels.push(
value as (typeof deserialized)["userLabels"][number],
);
} else if (key.startsWith("usernameColor")) {
deserialized.usernameColors.push(
value as (typeof deserialized)["usernameColors"][number],
);
}
}
return deserialized;
}
2023-06-29 16:44:30 +00:00
/**
* The Settings data structure from version 1.1.2 and before.
*/
export type V112Settings = {
[index: string]: any;
data: {
hideVotes: {
comments: boolean;
topics: boolean;
ownComments: boolean;
ownTopics: boolean;
};
knownGroups: string[];
latestActiveFeatureTab: string;
userLabels: Array<{
color: string;
id: number;
priority: number;
text: string;
username: string;
}>;
usernameColors: Array<{
color: string;
id: number;
username: string;
}>;
};
features: {
anonymizeUsernames: boolean;
autocomplete: boolean;
backToTop: boolean;
debug: boolean;
hideVotes: boolean;
jumpToNewComment: boolean;
markdownToolbar: boolean;
themedLogo: boolean;
userLabels: boolean;
usernameColors: boolean;
};
version: string;
};
2023-06-29 16:44:30 +00:00
/**
* A sample of the version 1.1.2 Settings data to use in testing.
*/
export const v112Sample: V112Settings = {
data: {
hideVotes: {
comments: true,
ownComments: true,
ownTopics: false,
topics: true,
},
knownGroups: ["~group", "~group.subgroup", "~test"],
latestActiveFeatureTab: "userLabels",
userLabels: [],
usernameColors: [],
},
features: {
anonymizeUsernames: false,
autocomplete: true,
backToTop: true,
debug: true,
hideVotes: true,
jumpToNewComment: true,
markdownToolbar: true,
themedLogo: true,
userLabels: true,
usernameColors: false,
},
version: "1.1.2",
userLabel1: {
color: "#ff00ff",
id: 1,
priority: 0,
text: "Test Label",
username: "Test",
},
userLabel15: {
id: 15,
color: "var(--syntax-string-color)",
priority: 0,
text: "Another Label",
username: "AnotherTest",
},
usernameColor4: {
color: "red",
id: 4,
username: "Test",
},
usernameColor18: {
color: "green",
id: 18,
username: "AnotherTest",
},
};