]>
Commit | Line | Data |
---|---|---|
1 | import { FunctionProperties, PickWith, PickWithOpt } from '@shared/core-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' | 'Avatar' | 'ActorFollowers' | 'Server' | 'Banner'> | |
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 MActorHost = Use<'Server', MServerHost> | |
33 | export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed> | |
34 | ||
35 | export type MActorDefaultLight = | |
36 | MActorLight & | |
37 | Use<'Server', MServerHost> & | |
38 | Use<'Avatar', MActorImage> | |
39 | ||
40 | export type MActorAccountId = | |
41 | MActor & | |
42 | Use<'Account', MAccountId> | |
43 | export type MActorAccountIdActor = | |
44 | MActor & | |
45 | Use<'Account', MAccountIdActor> | |
46 | ||
47 | export type MActorChannelId = | |
48 | MActor & | |
49 | Use<'VideoChannel', MChannelId> | |
50 | export type MActorChannelIdActor = | |
51 | MActor & | |
52 | Use<'VideoChannel', MChannelIdActor> | |
53 | ||
54 | export type MActorAccountChannelId = MActorAccountId & MActorChannelId | |
55 | export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor | |
56 | ||
57 | // ############################################################################ | |
58 | ||
59 | // Include raw account/channel/server | |
60 | ||
61 | export type MActorAccount = | |
62 | MActor & | |
63 | Use<'Account', MAccount> | |
64 | ||
65 | export type MActorChannel = | |
66 | MActor & | |
67 | Use<'VideoChannel', MChannel> | |
68 | ||
69 | export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel | |
70 | ||
71 | export type MActorServer = | |
72 | MActor & | |
73 | Use<'Server', MServer> | |
74 | ||
75 | // ############################################################################ | |
76 | ||
77 | // Complex actor associations | |
78 | ||
79 | export type MActorImages = | |
80 | MActor & | |
81 | Use<'Avatar', MActorImage> & | |
82 | UseOpt<'Banner', MActorImage> | |
83 | ||
84 | export type MActorDefault = | |
85 | MActor & | |
86 | Use<'Server', MServer> & | |
87 | Use<'Avatar', MActorImage> | |
88 | ||
89 | export type MActorDefaultChannelId = | |
90 | MActorDefault & | |
91 | Use<'VideoChannel', MChannelId> | |
92 | ||
93 | export 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 | |
101 | export type MActorChannelAccountActor = | |
102 | MActor & | |
103 | Use<'VideoChannel', MChannelAccountActor> | |
104 | ||
105 | export 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 | |
114 | export 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 | ||
126 | export type MActorSummary = | |
127 | FunctionProperties<MActor> & | |
128 | Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> & | |
129 | Use<'Server', MServerHost> & | |
130 | Use<'Avatar', MActorImage> | |
131 | ||
132 | export type MActorSummaryBlocks = | |
133 | MActorSummary & | |
134 | Use<'Server', MServerHostBlocks> | |
135 | ||
136 | export 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 | ||
144 | export type MActorSummaryFormattable = | |
145 | FunctionProperties<MActor> & | |
146 | Pick<MActor, 'url' | 'preferredUsername'> & | |
147 | Use<'Server', MServerHost> & | |
148 | Use<'Avatar', MActorImageFormattable> | |
149 | ||
150 | export 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 | ||
156 | type MActorAPBase = | |
157 | MActor & | |
158 | Use<'Avatar', MActorImage> | |
159 | ||
160 | export type MActorAPAccount = | |
161 | MActorAPBase | |
162 | ||
163 | export type MActorAPChannel = | |
164 | MActorAPBase & | |
165 | Use<'Banner', MActorImage> |