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'
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' | 'Avatar' | 'ActorFollowers' | 'Server' | 'Banner'>
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 MActorHost = Use<'Server', MServerHost>
33 export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed>
35 export type MActorDefaultLight =
37 Use<'Server', MServerHost> &
38 Use<'Avatar', MActorImage>
40 export type MActorAccountId =
42 Use<'Account', MAccountId>
43 export type MActorAccountIdActor =
45 Use<'Account', MAccountIdActor>
47 export type MActorChannelId =
49 Use<'VideoChannel', MChannelId>
50 export type MActorChannelIdActor =
52 Use<'VideoChannel', MChannelIdActor>
54 export type MActorAccountChannelId = MActorAccountId & MActorChannelId
55 export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor
57 // ############################################################################
59 // Include raw account/channel/server
61 export type MActorAccount =
63 Use<'Account', MAccount>
65 export type MActorChannel =
67 Use<'VideoChannel', MChannel>
69 export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel
71 export type MActorServer =
73 Use<'Server', MServer>
75 // ############################################################################
77 // Complex actor associations
79 export type MActorImages =
81 Use<'Avatar', MActorImage> &
82 UseOpt<'Banner', MActorImage>
84 export type MActorDefault =
86 Use<'Server', MServer> &
87 Use<'Avatar', MActorImage>
89 export type MActorDefaultChannelId =
91 Use<'VideoChannel', MChannelId>
93 export type MActorDefaultBanner =
95 Use<'Server', MServer> &
96 Use<'Avatar', MActorImage> &
97 Use<'Banner', MActorImage>
99 // Actor with channel that is associated to an account and its actor
100 // Actor -> VideoChannel -> Account -> Actor
101 export type MActorChannelAccountActor =
103 Use<'VideoChannel', MChannelAccountActor>
105 export type MActorFull =
107 Use<'Server', MServer> &
108 Use<'Avatar', MActorImage> &
109 Use<'Banner', MActorImage> &
110 Use<'Account', MAccount> &
111 Use<'VideoChannel', MChannelAccountActor>
113 // Same than ActorFull, but the account and the channel have their actor
114 export type MActorFullActor =
116 Use<'Server', MServer> &
117 Use<'Avatar', MActorImage> &
118 Use<'Banner', MActorImage> &
119 Use<'Account', MAccountDefault> &
120 Use<'VideoChannel', MChannelAccountDefault>
122 // ############################################################################
126 export type MActorSummary =
127 FunctionProperties<MActor> &
128 Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> &
129 Use<'Server', MServerHost> &
130 Use<'Avatar', MActorImage>
132 export type MActorSummaryBlocks =
134 Use<'Server', MServerHostBlocks>
136 export type MActorAPI =
137 Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' |
138 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'>
140 // ############################################################################
142 // Format for API or AP object
144 export type MActorSummaryFormattable =
145 FunctionProperties<MActor> &
146 Pick<MActor, 'url' | 'preferredUsername'> &
147 Use<'Server', MServerHost> &
148 Use<'Avatar', MActorImageFormattable>
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>
158 Use<'Avatar', MActorImage>
160 export type MActorAPAccount =
163 export type MActorAPChannel =
165 Use<'Banner', MActorImage>