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'
9 type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M>
10 type UseOpt<K extends keyof ActorModel, M> = PickWithOpt<ActorModel, K, M>
12 // ############################################################################
14 export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'Avatar' | 'ActorFollowers' | 'Server' | 'Banner'>
16 // ############################################################################
18 export type MActorUrl = Pick<MActor, 'url'>
19 export type MActorId = Pick<MActor, 'id'>
20 export type MActorUsername = Pick<MActor, 'preferredUsername'>
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
27 export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'>
29 // ############################################################################
31 // Some association attributes
33 export type MActorHost = Use<'Server', MServerHost>
34 export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed>
36 export type MActorDefaultLight =
38 Use<'Server', MServerHost> &
39 Use<'Avatar', MActorImage>
41 export type MActorAccountId =
43 Use<'Account', MAccountId>
44 export type MActorAccountIdActor =
46 Use<'Account', MAccountIdActor>
48 export type MActorChannelId =
50 Use<'VideoChannel', MChannelId>
51 export type MActorChannelIdActor =
53 Use<'VideoChannel', MChannelIdActor>
55 export type MActorAccountChannelId = MActorAccountId & MActorChannelId
56 export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor
58 // ############################################################################
60 // Include raw account/channel/server
62 export type MActorAccount =
64 Use<'Account', MAccount>
66 export type MActorChannel =
68 Use<'VideoChannel', MChannel>
70 export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel
72 export type MActorServer =
74 Use<'Server', MServer>
76 // ############################################################################
78 // Complex actor associations
80 export type MActorImages =
82 Use<'Avatar', MActorImage> &
83 UseOpt<'Banner', MActorImage>
85 export type MActorDefault =
87 Use<'Server', MServer> &
88 Use<'Avatar', MActorImage>
90 export type MActorDefaultChannelId =
92 Use<'VideoChannel', MChannelId>
94 export type MActorDefaultBanner =
96 Use<'Server', MServer> &
97 Use<'Avatar', MActorImage> &
98 Use<'Banner', MActorImage>
100 // Actor with channel that is associated to an account and its actor
101 // Actor -> VideoChannel -> Account -> Actor
102 export type MActorChannelAccountActor =
104 Use<'VideoChannel', MChannelAccountActor>
106 export type MActorFull =
108 Use<'Server', MServer> &
109 Use<'Avatar', MActorImage> &
110 Use<'Banner', MActorImage> &
111 Use<'Account', MAccount> &
112 Use<'VideoChannel', MChannelAccountActor>
114 // Same than ActorFull, but the account and the channel have their actor
115 export type MActorFullActor =
117 Use<'Server', MServer> &
118 Use<'Avatar', MActorImage> &
119 Use<'Banner', MActorImage> &
120 Use<'Account', MAccountDefault> &
121 Use<'VideoChannel', MChannelAccountDefault>
123 // ############################################################################
127 export type MActorSummary =
128 FunctionProperties<MActor> &
129 Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> &
130 Use<'Server', MServerHost> &
131 Use<'Avatar', MActorImage>
133 export type MActorSummaryBlocks =
135 Use<'Server', MServerHostBlocks>
137 export type MActorAPI =
138 Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' |
139 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'>
141 // ############################################################################
143 // Format for API or AP object
145 export type MActorSummaryFormattable =
146 FunctionProperties<MActor> &
147 Pick<MActor, 'url' | 'preferredUsername'> &
148 Use<'Server', MServerHost> &
149 Use<'Avatar', MActorImageFormattable>
151 export type MActorFormattable =
152 MActorSummaryFormattable &
153 Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt' | 'bannerId' | 'avatarId'> &
154 Use<'Server', MServerHost & Partial<Pick<MServer, 'redundancyAllowed'>>> &
155 UseOpt<'Banner', MActorImageFormattable>
159 Use<'Avatar', MActorImage>
161 export type MActorAPAccount =
164 export type MActorAPChannel =
166 Use<'Banner', MActorImage>