-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.ts
42 lines (35 loc) · 1.15 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { Option } from "./option";
/**
* The following formats are valid:
* - v1
* - v1.2
* - v1.2.3
*/
export type SemanticVersion =
| ExactSemanticVersion
| (string & { readonly __tag: unique symbol });
/**
* The following format is valid: v1.2.3
*/
export type ExactSemanticVersion = string & { readonly __tag: unique symbol };
export function isExactSemanticVersion(
value: string,
): value is ExactSemanticVersion {
const regex =
/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
return regex.test(value);
}
export type Sha1Hash = string & { readonly __tag: unique symbol };
export type Sha256Hash = string & { readonly __tag: unique symbol };
export type RepositorySlug = {
owner: string;
repository: string;
};
export type TargetTriple = string & { readonly __tag: unique symbol };
export type BinaryName = string & { readonly __tag: unique symbol };
export type TargetRelease = {
slug: RepositorySlug;
tag: SemanticVersion;
binaryName: Option<BinaryName>;
checksum: Option<Sha256Hash>;
};