]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/types/models/actor/actor.ts
Cleanup models directory organization
[github/Chocobozzz/PeerTube.git] / server / types / models / actor / actor.ts
... / ...
CommitLineData
1import { FunctionProperties, PickWith, PickWithOpt } from '@shared/core-utils'
2import { ActorModel } from '../../../models/actor/actor'
3import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from '../account'
4import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server'
5import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video'
6import { MActorImage, MActorImageFormattable } from './actor-image'
7
8type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M>
9type UseOpt<K extends keyof ActorModel, M> = PickWithOpt<ActorModel, K, M>
10
11// ############################################################################
12
13export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'Avatar' | 'ActorFollowers' | 'Server' | 'Banner'>
14
15// ############################################################################
16
17export type MActorUrl = Pick<MActor, 'url'>
18export type MActorId = Pick<MActor, 'id'>
19export type MActorUsername = Pick<MActor, 'preferredUsername'>
20
21export type MActorFollowersUrl = Pick<MActor, 'followersUrl'>
22export type MActorAudience = MActorUrl & MActorFollowersUrl
23export type MActorWithInboxes = Pick<ActorModel, 'sharedInboxUrl' | 'inboxUrl' | 'getSharedInbox'>
24export type MActorSignature = MActorAccountChannelId
25
26export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'>
27
28// ############################################################################
29
30// Some association attributes
31
32export type MActorHost = Use<'Server', MServerHost>
33export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed>
34
35export type MActorDefaultLight =
36 MActorLight &
37 Use<'Server', MServerHost> &
38 Use<'Avatar', MActorImage>
39
40export type MActorAccountId =
41 MActor &
42 Use<'Account', MAccountId>
43export type MActorAccountIdActor =
44 MActor &
45 Use<'Account', MAccountIdActor>
46
47export type MActorChannelId =
48 MActor &
49 Use<'VideoChannel', MChannelId>
50export type MActorChannelIdActor =
51 MActor &
52 Use<'VideoChannel', MChannelIdActor>
53
54export type MActorAccountChannelId = MActorAccountId & MActorChannelId
55export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor
56
57// ############################################################################
58
59// Include raw account/channel/server
60
61export type MActorAccount =
62 MActor &
63 Use<'Account', MAccount>
64
65export type MActorChannel =
66 MActor &
67 Use<'VideoChannel', MChannel>
68
69export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel
70
71export type MActorServer =
72 MActor &
73 Use<'Server', MServer>
74
75// ############################################################################
76
77// Complex actor associations
78
79export type MActorImages =
80 MActor &
81 Use<'Avatar', MActorImage> &
82 UseOpt<'Banner', MActorImage>
83
84export type MActorDefault =
85 MActor &
86 Use<'Server', MServer> &
87 Use<'Avatar', MActorImage>
88
89export type MActorDefaultChannelId =
90 MActorDefault &
91 Use<'VideoChannel', MChannelId>
92
93export type MActorDefaultBanner =
94 MActor &
95 Use<'Server', MServer> &
96 Use<'Avatar', MActorImage> &
97 Use<'Banner', MActorImage>
98
99// Actor with channel that is associated to an account and its actor
100// Actor -> VideoChannel -> Account -> Actor
101export type MActorChannelAccountActor =
102 MActor &
103 Use<'VideoChannel', MChannelAccountActor>
104
105export type MActorFull =
106 MActor &
107 Use<'Server', MServer> &
108 Use<'Avatar', MActorImage> &
109 Use<'Banner', MActorImage> &
110 Use<'Account', MAccount> &
111 Use<'VideoChannel', MChannelAccountActor>
112
113// Same than ActorFull, but the account and the channel have their actor
114export type MActorFullActor =
115 MActor &
116 Use<'Server', MServer> &
117 Use<'Avatar', MActorImage> &
118 Use<'Banner', MActorImage> &
119 Use<'Account', MAccountDefault> &
120 Use<'VideoChannel', MChannelAccountDefault>
121
122// ############################################################################
123
124// API
125
126export type MActorSummary =
127 FunctionProperties<MActor> &
128 Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> &
129 Use<'Server', MServerHost> &
130 Use<'Avatar', MActorImage>
131
132export type MActorSummaryBlocks =
133 MActorSummary &
134 Use<'Server', MServerHostBlocks>
135
136export type MActorAPI =
137 Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' |
138 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'>
139
140// ############################################################################
141
142// Format for API or AP object
143
144export type MActorSummaryFormattable =
145 FunctionProperties<MActor> &
146 Pick<MActor, 'url' | 'preferredUsername'> &
147 Use<'Server', MServerHost> &
148 Use<'Avatar', MActorImageFormattable>
149
150export type MActorFormattable =
151 MActorSummaryFormattable &
152 Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt' | 'remoteCreatedAt' | 'bannerId' | 'avatarId'> &
153 Use<'Server', MServerHost & Partial<Pick<MServer, 'redundancyAllowed'>>> &
154 UseOpt<'Banner', MActorImageFormattable>
155
156type MActorAPBase =
157 MActor &
158 Use<'Avatar', MActorImage>
159
160export type MActorAPAccount =
161 MActorAPBase
162
163export type MActorAPChannel =
164 MActorAPBase &
165 Use<'Banner', MActorImage>