diff --git a/src/core/repoId.js b/src/core/repoId.js index cea97cc..f99ad27 100644 --- a/src/core/repoId.js +++ b/src/core/repoId.js @@ -10,6 +10,8 @@ export opaque type RepoId: {| +owner: string, |}; +export opaque type RepoIdString: string = string; + export const githubOwnerPattern = "[A-Za-z0-9-]+"; export const githubRepoPattern = "[A-Za-z0-9-._]+"; @@ -33,6 +35,6 @@ export function stringToRepoId(x: string): RepoId { return makeRepoId(pieces[0], pieces[1]); } -export function repoIdToString(x: RepoId): string { +export function repoIdToString(x: RepoId): RepoIdString { return `${x.owner}/${x.name}`; } diff --git a/src/core/repoId.test.js b/src/core/repoId.test.js index 4226755..a7813ab 100644 --- a/src/core/repoId.test.js +++ b/src/core/repoId.test.js @@ -5,6 +5,7 @@ import { stringToRepoId, repoIdToString, type RepoId, + type RepoIdString, } from "./repoId"; describe("core/repoId", () => { @@ -22,6 +23,12 @@ describe("core/repoId", () => { const _unused_name: string = repoId.name; }); }); + describe("RepoIdString type", () => { + it("manually constructing a RepoIdString is illegal", () => { + // $ExpectFlowError + const _unused_repoIdString: RepoIdString = "foobar"; + }); + }); describe("makeRepoId", () => { it("allows a simple repoId", () => { makeRepoId("sourcecred", "sourcecred");