Define previous Project type versions (#1517)

These are important to accurately add types to function
signatures of validating and upgrading logic.
This commit is contained in:
Robin van Boven 2020-01-03 14:36:01 +01:00 committed by GitHub
parent 5b9455cf9d
commit 89529ea4fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,10 @@ export type ProjectId = string;
* the future (e.g. showing the last update time for each of the project's data
* dependencies).
*/
export type Project = {|
export type Project = Project_v040;
export type SupportedProject = Project_v030 | Project_v031 | Project_v040;
type Project_v040 = {|
+id: ProjectId,
+repoIds: $ReadOnlyArray<RepoId>,
+discourseServer: DiscourseServer | null,
@ -33,17 +36,6 @@ export type Project = {|
const COMPAT_INFO = {type: "sourcecred/project", version: "0.4.0"};
const upgradeFrom030 = (p) => ({
...p,
discourseServer:
p.discourseServer != null ? {serverUrl: p.discourseServer.serverUrl} : null,
});
const upgrades = {
"0.3.0": upgradeFrom030,
"0.3.1": upgradeFrom030,
};
export type ProjectJSON = Compatible<Project>;
export function projectToJSON(p: Project): ProjectJSON {
@ -61,3 +53,34 @@ export function projectFromJSON(j: ProjectJSON): Project {
export function encodeProjectId(id: ProjectId): string {
return base64url.encode(id);
}
const upgradeFrom030 = (p) => ({
...p,
discourseServer:
p.discourseServer != null ? {serverUrl: p.discourseServer.serverUrl} : null,
});
type Project_v031 = {|
+id: ProjectId,
+repoIds: $ReadOnlyArray<RepoId>,
+discourseServer: {|
+serverUrl: string,
+apiUsername?: string,
|} | null,
+identities: $ReadOnlyArray<Identity>,
|};
type Project_v030 = {|
+id: ProjectId,
+repoIds: $ReadOnlyArray<RepoId>,
+discourseServer: {|
+serverUrl: string,
+apiUsername: string,
|} | null,
+identities: $ReadOnlyArray<Identity>,
|};
const upgrades = {
"0.3.0": upgradeFrom030,
"0.3.1": upgradeFrom030,
};