aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/types/models/actor/actor.ts
blob: 280256bab209c9d414e25bd66ad701c6faf31910 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { FunctionProperties, PickWith, PickWithOpt } from '@shared/typescript-utils'
import { ActorModel } from '../../../models/actor/actor'
import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from '../account'
import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server'
import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video'
import { MActorImage, MActorImageFormattable } from './actor-image'

type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M>
type UseOpt<K extends keyof ActorModel, M> = PickWithOpt<ActorModel, K, M>

// ############################################################################

export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'ActorFollowers' | 'Server' | 'Banners'>

// ############################################################################

export type MActorUrl = Pick<MActor, 'url'>
export type MActorId = Pick<MActor, 'id'>
export type MActorUsername = Pick<MActor, 'preferredUsername'>

export type MActorFollowersUrl = Pick<MActor, 'followersUrl'>
export type MActorAudience = MActorUrl & MActorFollowersUrl
export type MActorWithInboxes = Pick<ActorModel, 'sharedInboxUrl' | 'inboxUrl' | 'getSharedInbox'>
export type MActorSignature = MActorAccountChannelId

export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'>

// ############################################################################

// Some association attributes

export type MActorHost = Use<'Server', MServerHost>
export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed>

export type MActorDefaultLight =
  MActorLight &
  Use<'Server', MServerHost> &
  Use<'Avatars', MActorImage[]>

export type MActorAccountId =
  MActor &
  Use<'Account', MAccountId>
export type MActorAccountIdActor =
  MActor &
  Use<'Account', MAccountIdActor>

export type MActorChannelId =
  MActor &
  Use<'VideoChannel', MChannelId>
export type MActorChannelIdActor =
  MActor &
  Use<'VideoChannel', MChannelIdActor>

export type MActorAccountChannelId = MActorAccountId & MActorChannelId
export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor

// ############################################################################

// Include raw account/channel/server

export type MActorAccount =
  MActor &
  Use<'Account', MAccount>

export type MActorChannel =
  MActor &
  Use<'VideoChannel', MChannel>

export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel

export type MActorServer =
  MActor &
  Use<'Server', MServer>

// ############################################################################

// Complex actor associations

export type MActorImages =
  MActor &
  Use<'Avatars', MActorImage[]> &
  UseOpt<'Banners', MActorImage[]>

export type MActorDefault =
  MActor &
  Use<'Server', MServer> &
  Use<'Avatars', MActorImage[]>

export type MActorDefaultChannelId =
  MActorDefault &
  Use<'VideoChannel', MChannelId>

export type MActorDefaultBanner =
  MActor &
  Use<'Server', MServer> &
  Use<'Avatars', MActorImage[]> &
  Use<'Banners', MActorImage[]>

// Actor with channel that is associated to an account and its actor
// Actor -> VideoChannel -> Account -> Actor
export type MActorChannelAccountActor =
  MActor &
  Use<'VideoChannel', MChannelAccountActor>

export type MActorFull =
  MActor &
  Use<'Server', MServer> &
  Use<'Avatars', MActorImage[]> &
  Use<'Banners', MActorImage[]> &
  Use<'Account', MAccount> &
  Use<'VideoChannel', MChannelAccountActor>

// Same than ActorFull, but the account and the channel have their actor
export type MActorFullActor =
  MActor &
  Use<'Server', MServer> &
  Use<'Avatars', MActorImage[]> &
  Use<'Banners', MActorImage[]> &
  Use<'Account', MAccountDefault> &
  Use<'VideoChannel', MChannelAccountDefault>

// ############################################################################

// API

export type MActorSummary =
  FunctionProperties<MActor> &
  Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId'> &
  Use<'Server', MServerHost> &
  Use<'Avatars', MActorImage[]>

export type MActorSummaryBlocks =
  MActorSummary &
  Use<'Server', MServerHostBlocks>

export type MActorAPI =
  Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' |
  'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'>

// ############################################################################

// Format for API or AP object

export type MActorSummaryFormattable =
  FunctionProperties<MActor> &
  Pick<MActor, 'url' | 'preferredUsername'> &
  Use<'Server', MServerHost> &
  Use<'Avatars', MActorImageFormattable[]>

export type MActorFormattable =
  MActorSummaryFormattable &
  Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt' | 'remoteCreatedAt'> &
  Use<'Server', MServerHost & Partial<Pick<MServer, 'redundancyAllowed'>>> &
  UseOpt<'Banners', MActorImageFormattable[]> &
  UseOpt<'Avatars', MActorImageFormattable[]>

type MActorAPBase =
  MActor &
  Use<'Avatars', MActorImage[]>

export type MActorAPAccount =
  MActorAPBase

export type MActorAPChannel =
  MActorAPBase &
  Use<'Banners', MActorImage[]>