diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-18 10:45:25 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-18 10:46:27 +0200 |
commit | 26d6bf6533023326fa017812cf31bbe20c752d36 (patch) | |
tree | 9c4e3ecdc344420190f17d429bdf05d78fae7a8c /server/types/models/account/actor.ts | |
parent | d6d951ddc0c492f3261065b5dcb4df0534d252fc (diff) | |
download | PeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.tar.gz PeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.tar.zst PeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.zip |
Split types and typings
Diffstat (limited to 'server/types/models/account/actor.ts')
-rw-r--r-- | server/types/models/account/actor.ts | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/server/types/models/account/actor.ts b/server/types/models/account/actor.ts new file mode 100644 index 000000000..1160e84cb --- /dev/null +++ b/server/types/models/account/actor.ts | |||
@@ -0,0 +1,139 @@ | |||
1 | import { ActorModel } from '../../../models/activitypub/actor' | ||
2 | import { FunctionProperties, PickWith, PickWithOpt } from '../../utils' | ||
3 | import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account' | ||
4 | import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server' | ||
5 | import { MAvatar, MAvatarFormattable } from './avatar' | ||
6 | import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video' | ||
7 | |||
8 | type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M> | ||
9 | |||
10 | // ############################################################################ | ||
11 | |||
12 | export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'Avatar' | 'ActorFollowers' | 'Server'> | ||
13 | |||
14 | // ############################################################################ | ||
15 | |||
16 | export type MActorUrl = Pick<MActor, 'url'> | ||
17 | export type MActorId = Pick<MActor, 'id'> | ||
18 | export type MActorUsername = Pick<MActor, 'preferredUsername'> | ||
19 | |||
20 | export type MActorFollowersUrl = Pick<MActor, 'followersUrl'> | ||
21 | export type MActorAudience = MActorUrl & MActorFollowersUrl | ||
22 | export type MActorWithInboxes = Pick<ActorModel, 'sharedInboxUrl' | 'inboxUrl' | 'getSharedInbox'> | ||
23 | export type MActorSignature = MActorAccountChannelId | ||
24 | |||
25 | export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'> | ||
26 | |||
27 | // ############################################################################ | ||
28 | |||
29 | // Some association attributes | ||
30 | |||
31 | export type MActorHost = Use<'Server', MServerHost> | ||
32 | export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed> | ||
33 | |||
34 | export type MActorDefaultLight = | ||
35 | MActorLight & | ||
36 | Use<'Server', MServerHost> & | ||
37 | Use<'Avatar', MAvatar> | ||
38 | |||
39 | export type MActorAccountId = | ||
40 | MActor & | ||
41 | Use<'Account', MAccountId> | ||
42 | export type MActorAccountIdActor = | ||
43 | MActor & | ||
44 | Use<'Account', MAccountIdActor> | ||
45 | |||
46 | export type MActorChannelId = | ||
47 | MActor & | ||
48 | Use<'VideoChannel', MChannelId> | ||
49 | export type MActorChannelIdActor = | ||
50 | MActor & | ||
51 | Use<'VideoChannel', MChannelIdActor> | ||
52 | |||
53 | export type MActorAccountChannelId = MActorAccountId & MActorChannelId | ||
54 | export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor | ||
55 | |||
56 | // ############################################################################ | ||
57 | |||
58 | // Include raw account/channel/server | ||
59 | |||
60 | export type MActorAccount = | ||
61 | MActor & | ||
62 | Use<'Account', MAccount> | ||
63 | |||
64 | export type MActorChannel = | ||
65 | MActor & | ||
66 | Use<'VideoChannel', MChannel> | ||
67 | |||
68 | export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel | ||
69 | |||
70 | export type MActorServer = | ||
71 | MActor & | ||
72 | Use<'Server', MServer> | ||
73 | |||
74 | // ############################################################################ | ||
75 | |||
76 | // Complex actor associations | ||
77 | |||
78 | export type MActorDefault = | ||
79 | MActor & | ||
80 | Use<'Server', MServer> & | ||
81 | Use<'Avatar', MAvatar> | ||
82 | |||
83 | // Actor with channel that is associated to an account and its actor | ||
84 | // Actor -> VideoChannel -> Account -> Actor | ||
85 | export type MActorChannelAccountActor = | ||
86 | MActor & | ||
87 | Use<'VideoChannel', MChannelAccountActor> | ||
88 | |||
89 | export type MActorFull = | ||
90 | MActor & | ||
91 | Use<'Server', MServer> & | ||
92 | Use<'Avatar', MAvatar> & | ||
93 | Use<'Account', MAccount> & | ||
94 | Use<'VideoChannel', MChannelAccountActor> | ||
95 | |||
96 | // Same than ActorFull, but the account and the channel have their actor | ||
97 | export type MActorFullActor = | ||
98 | MActor & | ||
99 | Use<'Server', MServer> & | ||
100 | Use<'Avatar', MAvatar> & | ||
101 | Use<'Account', MAccountDefault> & | ||
102 | Use<'VideoChannel', MChannelAccountDefault> | ||
103 | |||
104 | // ############################################################################ | ||
105 | |||
106 | // API | ||
107 | |||
108 | export type MActorSummary = | ||
109 | FunctionProperties<MActor> & | ||
110 | Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> & | ||
111 | Use<'Server', MServerHost> & | ||
112 | Use<'Avatar', MAvatar> | ||
113 | |||
114 | export type MActorSummaryBlocks = | ||
115 | MActorSummary & | ||
116 | Use<'Server', MServerHostBlocks> | ||
117 | |||
118 | export type MActorAPI = | ||
119 | Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' | | ||
120 | 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'> | ||
121 | |||
122 | // ############################################################################ | ||
123 | |||
124 | // Format for API or AP object | ||
125 | |||
126 | export type MActorSummaryFormattable = | ||
127 | FunctionProperties<MActor> & | ||
128 | Pick<MActor, 'url' | 'preferredUsername'> & | ||
129 | Use<'Server', MServerHost> & | ||
130 | Use<'Avatar', MAvatarFormattable> | ||
131 | |||
132 | export type MActorFormattable = | ||
133 | MActorSummaryFormattable & | ||
134 | Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt'> & | ||
135 | Use<'Server', MServerHost & Partial<Pick<MServer, 'redundancyAllowed'>>> | ||
136 | |||
137 | export type MActorAP = | ||
138 | MActor & | ||
139 | Use<'Avatar', MAvatar> | ||