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