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'
8 type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M>
9 type UseOpt<K extends keyof ActorModel, M> = PickWithOpt<ActorModel, K, M>
11 // ############################################################################
13 export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'ActorFollowers' | 'Server' | 'Banners'>
15 // ############################################################################
17 export type MActorUrl = Pick<MActor, 'url'>
18 export type MActorId = Pick<MActor, 'id'>
19 export type MActorUsername = Pick<MActor, 'preferredUsername'>
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
26 export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'>
28 // ############################################################################
30 // Some association attributes
32 export type MActorHostOnly = Use<'Server', MServerHost>
33 export type MActorHost =
35 Use<'Server', MServerHost>
37 export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed>
39 export type MActorDefaultLight =
41 Use<'Server', MServerHost> &
42 Use<'Avatars', MActorImage[]>
44 export type MActorAccountId =
46 Use<'Account', MAccountId>
47 export type MActorAccountIdActor =
49 Use<'Account', MAccountIdActor>
51 export type MActorChannelId =
53 Use<'VideoChannel', MChannelId>
54 export type MActorChannelIdActor =
56 Use<'VideoChannel', MChannelIdActor>
58 export type MActorAccountChannelId = MActorAccountId & MActorChannelId
59 export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor
61 // ############################################################################
63 // Include raw account/channel/server
65 export type MActorAccount =
67 Use<'Account', MAccount>
69 export type MActorChannel =
71 Use<'VideoChannel', MChannel>
73 export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel
75 export type MActorServerLight =
77 Use<'Server', MServer>
79 // ############################################################################
81 // Complex actor associations
83 export type MActorImages =
85 Use<'Avatars', MActorImage[]> &
86 UseOpt<'Banners', MActorImage[]>
88 export type MActorDefault =
90 Use<'Server', MServer> &
91 Use<'Avatars', MActorImage[]>
93 export type MActorDefaultChannelId =
95 Use<'VideoChannel', MChannelId>
97 export type MActorDefaultBanner =
99 Use<'Server', MServer> &
100 Use<'Avatars', MActorImage[]> &
101 Use<'Banners', MActorImage[]>
103 // Actor with channel that is associated to an account and its actor
104 // Actor -> VideoChannel -> Account -> Actor
105 export type MActorChannelAccountActor =
107 Use<'VideoChannel', MChannelAccountActor>
109 export type MActorFull =
111 Use<'Server', MServer> &
112 Use<'Avatars', MActorImage[]> &
113 Use<'Banners', MActorImage[]> &
114 Use<'Account', MAccount> &
115 Use<'VideoChannel', MChannelAccountActor>
117 // Same than ActorFull, but the account and the channel have their actor
118 export type MActorFullActor =
120 Use<'Server', MServer> &
121 Use<'Avatars', MActorImage[]> &
122 Use<'Banners', MActorImage[]> &
123 Use<'Account', MAccountDefault> &
124 Use<'VideoChannel', MChannelAccountDefault>
126 // ############################################################################
130 export type MActorSummary =
131 FunctionProperties<MActor> &
132 Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId'> &
133 Use<'Server', MServerHost> &
134 Use<'Avatars', MActorImage[]>
136 export type MActorSummaryBlocks =
138 Use<'Server', MServerHostBlocks>
140 export type MActorAPI =
141 Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' |
142 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'>
144 // ############################################################################
146 // Format for API or AP object
148 export type MActorSummaryFormattable =
149 FunctionProperties<MActor> &
150 Pick<MActor, 'url' | 'preferredUsername'> &
151 Use<'Server', MServerHost> &
152 Use<'Avatars', MActorImageFormattable[]>
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[]>
163 Use<'Avatars', MActorImage[]>
165 export type MActorAPAccount =
168 export type MActorAPChannel =
170 Use<'Banners', MActorImage[]>