-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_types.test.ts
87 lines (79 loc) · 2.47 KB
/
api_types.test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import type {
AvailableKeys,
CollectIncludes,
WithIncludes,
} from "@/api_includes.ts";
import type {
$ReleaseGroup,
Area,
MinimalReleaseGroup,
Recording,
Relationship,
ReleaseGroup,
} from "@/api_types.ts";
import type { ReleaseGroupSecondaryType } from "@/data/release_group.ts";
import type { Expect, ExpectNot, ToEqual } from "@/utils/type_utils.ts";
type WithAllIncludesToRemoveNoPropertyFrom<Entity extends object> = ToEqual<
keyof Entity,
AvailableKeys<Entity, string>
>;
type TestReleaseGroupWithAllIncludes = Expect<
WithAllIncludesToRemoveNoPropertyFrom<$ReleaseGroup>
>;
type MinimalEntityMiscInclude =
| "tags"
| "user-tags"
| "genres"
| "user-genres"
| "ratings"
| "user-ratings";
type ReleaseGroupInclude =
| "aliases"
| "artist-credits"
| "artists"
| "releases"
| MinimalEntityMiscInclude;
type TestMinimalReleaseGroupIncludeCollection = Expect<
ToEqual<CollectIncludes<MinimalReleaseGroup>, ReleaseGroupInclude>
>;
type IncludesHaveNoEffectOnPrimitive = Expect<
ToEqual<
ReleaseGroup["disambiguation"],
string
>
>;
type IncludesHaveNoEffectOnPrimitiveArray = Expect<
ToEqual<
ReleaseGroup["secondary-types"],
ReleaseGroupSecondaryType[]
>
>;
type ActivatedInclude<RequiredInclude extends string, Include extends string> =
ToEqual<RequiredInclude extends Include ? true : never, true>;
type TestNoIncludeGiven = ExpectNot<ActivatedInclude<"A", never>>;
type TestWrongIncludeGiven = ExpectNot<ActivatedInclude<"A", "X">>;
type TestExactMatchInclude = Expect<ActivatedInclude<"A", "A">>;
type TestExactMatchIncludeAndOthers = Expect<ActivatedInclude<"A", "A" | "X">>;
type TestAllPossibleIncludes = Expect<ActivatedInclude<"A", string>>;
type TestFullMatchInclude = Expect<ActivatedInclude<"A" | "B", "A" | "B">>;
type TestFullMatchIncludeAndOthers = Expect<
ActivatedInclude<"A" | "B", "A" | "B" | "X">
>;
type TestPartialMatchInclude = Expect<ActivatedInclude<"A" | "B", "A">>;
type TestPartialMatchIncludeAndOthers = Expect<
ActivatedInclude<"A" | "B", "A" | "X">
>;
type RecordingHasACForArtistsInclude = Recording<"artists">["artist-credit"];
type RecordingHasACForArtistCreditsInclude = Recording<
"artist-credits"
>["artist-credit"];
type EntityRelsWithMixedTargetType = Area<
"area-rels" | "url-rels"
>["relations"];
type RelsWithMixedTargetType = WithIncludes<
Relationship<"area" | "url">,
never
>[];
type TestRelsWithMixedTargetType = Expect<
ToEqual<EntityRelsWithMixedTargetType, RelsWithMixedTargetType>
>;