BranchNametypetype BranchName = Brand<string, "BranchName">;A branch's name, by the rules of git check-ref-format --branch.
The branded types of Intellectual Frontiers Workspaces (commons 0002-workspace-model FR-006 to FR-012): a Git host's name, a path segment that is valid on Linux, macOS and Windows alike, a path of the workspace, a branch, a commit and a pinned version are each a type of their own, made only by the function that refuses what it should, so that an unchecked string never reaches the layout or the plan.
PortableSegment and RepoPath are made in portable.ts; the others are made here. A refusal is a Result whose error says what is wrong and names the text, never a throw.
BranchNametypetype BranchName = Brand<string, "BranchName">;A branch's name, by the rules of git check-ref-format --branch.
branchNamefunctionfunction branchName(text: string): Result<BranchName, BrandError>A branch's name, by the rules of Git's ref names (git check-ref-format): no control character, space, ~ ^ : ? * [ \, .. or @{, no component that starts with . or ends in .lock, and no start with -.
BrandErrortypeno test imports ittype BrandError =
| {
readonly kind: "git-host";
readonly text: string;
readonly reason: string;
}
| {
readonly kind: "branch-name";
readonly text: string;
readonly reason: string;
}
| { readonly kind: "sha"; readonly text: string }
| {
readonly kind: "version";
readonly text: string;
readonly reason: string;
};A text refused as a type of this module, and why.
describeBrandErrorfunctionno test imports itfunction describeBrandError(e: BrandError): stringA refusal as one sentence.
GitHosttypeno test imports ittype GitHost = Brand<string, "GitHost">;A Git host's name in lower case, as the first folder of a repository's path (github.com).
gitHostfunctionfunction gitHost(text: string): Result<GitHost, BrandError>A Git host's name: letters, digits, -, _ and . between labels, lower-cased; no port, no scheme, no credential.
PortableSegmenttypeno test imports ittype PortableSegment = Brand<string, "PortableSegment">;One name in a path, valid on every operating system (made only by segment in portable.ts).
RepoPathtypetype RepoPath = Brand<string, "RepoPath">;A path of the workspace below its root: portable segments with / between them, never absolute and never holding .. (made only by repoPath in portable.ts).
Shatypeno test imports ittype Sha = Brand<string, "Sha">;A commit's object id: 40 (SHA-1) or 64 (SHA-256) lower-case hexadecimal digits.
shafunctionfunction sha(text: string): Result<Sha, BrandError>A commit id.
Versiontypeno test imports ittype Version = Brand<string, "Version">;A pinned version of a tool: major.minor.patch with an optional pre-release and build, never latest and never a range.
versionfunctionfunction version(text: string): Result<Version, BrandError>A pinned version: a semantic version with no v and nothing around it, so latest, 1.x, ^1.2.0, >=1 and v1.2.3 are refused (0002-workspace-model FR-037).