]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/types/models/video/video-channels.ts
Move typescript utils in its own directory
[github/Chocobozzz/PeerTube.git] / server / types / models / video / video-channels.ts
1 import { FunctionProperties, PickWith, PickWithOpt } from '@shared/typescript-utils'
2 import { VideoChannelModel } from '../../../models/video/video-channel'
3 import {
4 MAccountActor,
5 MAccountAPI,
6 MAccountDefault,
7 MAccountFormattable,
8 MAccountLight,
9 MAccountSummaryBlocks,
10 MAccountSummaryFormattable,
11 MAccountUrl,
12 MAccountUserId
13 } from '../account'
14 import {
15 MActor,
16 MActorAccountChannelId,
17 MActorAPChannel,
18 MActorAPI,
19 MActorDefault,
20 MActorDefaultBanner,
21 MActorDefaultLight,
22 MActorFormattable,
23 MActorHost,
24 MActorLight,
25 MActorSummary,
26 MActorSummaryFormattable,
27 MActorUrl
28 } from '../actor'
29 import { MVideo } from './video'
30
31 type Use<K extends keyof VideoChannelModel, M> = PickWith<VideoChannelModel, K, M>
32
33 // ############################################################################
34
35 export type MChannel = Omit<VideoChannelModel, 'Actor' | 'Account' | 'Videos' | 'VideoPlaylists'>
36
37 // ############################################################################
38
39 export type MChannelId = Pick<MChannel, 'id'>
40
41 // ############################################################################
42
43 export type MChannelIdActor =
44 MChannelId &
45 Use<'Actor', MActorAccountChannelId>
46
47 export type MChannelUserId =
48 Pick<MChannel, 'accountId'> &
49 Use<'Account', MAccountUserId>
50
51 export type MChannelActor =
52 MChannel &
53 Use<'Actor', MActor>
54
55 export type MChannelUrl = Use<'Actor', MActorUrl>
56
57 // Default scope
58 export type MChannelDefault =
59 MChannel &
60 Use<'Actor', MActorDefault>
61
62 export type MChannelBannerDefault =
63 MChannel &
64 Use<'Actor', MActorDefaultBanner>
65
66 // ############################################################################
67
68 // Not all association attributes
69
70 export type MChannelActorLight =
71 MChannel &
72 Use<'Actor', MActorLight>
73
74 export type MChannelAccountLight =
75 MChannel &
76 Use<'Actor', MActorDefaultLight> &
77 Use<'Account', MAccountLight>
78
79 export type MChannelHost =
80 MChannelId &
81 Use<'Actor', MActorHost>
82
83 // ############################################################################
84
85 // Account associations
86
87 export type MChannelAccountActor =
88 MChannel &
89 Use<'Account', MAccountActor>
90
91 export type MChannelBannerAccountDefault =
92 MChannel &
93 Use<'Actor', MActorDefaultBanner> &
94 Use<'Account', MAccountDefault>
95
96 export type MChannelAccountDefault =
97 MChannel &
98 Use<'Actor', MActorDefault> &
99 Use<'Account', MAccountDefault>
100
101 // ############################################################################
102
103 // Videos associations
104 export type MChannelVideos =
105 MChannel &
106 Use<'Videos', MVideo[]>
107
108 // ############################################################################
109
110 // For API
111
112 export type MChannelSummary =
113 FunctionProperties<MChannel> &
114 Pick<MChannel, 'id' | 'name' | 'description' | 'actorId'> &
115 Use<'Actor', MActorSummary>
116
117 export type MChannelSummaryAccount =
118 MChannelSummary &
119 Use<'Account', MAccountSummaryBlocks>
120
121 export type MChannelAPI =
122 MChannel &
123 Use<'Actor', MActorAPI> &
124 Use<'Account', MAccountAPI>
125
126 // ############################################################################
127
128 // Format for API or AP object
129
130 export type MChannelSummaryFormattable =
131 FunctionProperties<MChannel> &
132 Pick<MChannel, 'id' | 'name'> &
133 Use<'Actor', MActorSummaryFormattable>
134
135 export type MChannelAccountSummaryFormattable =
136 MChannelSummaryFormattable &
137 Use<'Account', MAccountSummaryFormattable>
138
139 export type MChannelFormattable =
140 FunctionProperties<MChannel> &
141 Pick<MChannel, 'id' | 'name' | 'description' | 'createdAt' | 'updatedAt' | 'support'> &
142 Use<'Actor', MActorFormattable> &
143 PickWithOpt<VideoChannelModel, 'Account', MAccountFormattable>
144
145 export type MChannelAP =
146 Pick<MChannel, 'name' | 'description' | 'support'> &
147 Use<'Actor', MActorAPChannel> &
148 Use<'Account', MAccountUrl>