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