aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/types/models/account
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-18 10:45:25 +0200
committerChocobozzz <me@florianbigard.com>2020-06-18 10:46:27 +0200
commit26d6bf6533023326fa017812cf31bbe20c752d36 (patch)
tree9c4e3ecdc344420190f17d429bdf05d78fae7a8c /server/types/models/account
parentd6d951ddc0c492f3261065b5dcb4df0534d252fc (diff)
downloadPeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.tar.gz
PeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.tar.zst
PeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.zip
Split types and typings
Diffstat (limited to 'server/types/models/account')
-rw-r--r--server/types/models/account/account-blocklist.ts27
-rw-r--r--server/types/models/account/account.ts109
-rw-r--r--server/types/models/account/actor-follow.ts70
-rw-r--r--server/types/models/account/actor.ts139
-rw-r--r--server/types/models/account/avatar.ts12
-rw-r--r--server/types/models/account/index.ts5
6 files changed, 362 insertions, 0 deletions
diff --git a/server/types/models/account/account-blocklist.ts b/server/types/models/account/account-blocklist.ts
new file mode 100644
index 000000000..0d8bf11bd
--- /dev/null
+++ b/server/types/models/account/account-blocklist.ts
@@ -0,0 +1,27 @@
1import { AccountBlocklistModel } from '../../../models/account/account-blocklist'
2import { PickWith } from '../../utils'
3import { MAccountDefault, MAccountFormattable } from './account'
4
5type Use<K extends keyof AccountBlocklistModel, M> = PickWith<AccountBlocklistModel, K, M>
6
7// ############################################################################
8
9export type MAccountBlocklist = Omit<AccountBlocklistModel, 'ByAccount' | 'BlockedAccount'>
10
11// ############################################################################
12
13export type MAccountBlocklistId = Pick<AccountBlocklistModel, 'id'>
14
15export type MAccountBlocklistAccounts =
16 MAccountBlocklist &
17 Use<'ByAccount', MAccountDefault> &
18 Use<'BlockedAccount', MAccountDefault>
19
20// ############################################################################
21
22// Format for API or AP object
23
24export type MAccountBlocklistFormattable =
25 Pick<MAccountBlocklist, 'createdAt'> &
26 Use<'ByAccount', MAccountFormattable> &
27 Use<'BlockedAccount', MAccountFormattable>
diff --git a/server/types/models/account/account.ts b/server/types/models/account/account.ts
new file mode 100644
index 000000000..7b826ee04
--- /dev/null
+++ b/server/types/models/account/account.ts
@@ -0,0 +1,109 @@
1import { AccountModel } from '../../../models/account/account'
2import {
3 MActor,
4 MActorAP,
5 MActorAPI,
6 MActorAudience,
7 MActorDefault,
8 MActorDefaultLight,
9 MActorFormattable,
10 MActorId,
11 MActorServer,
12 MActorSummary,
13 MActorSummaryFormattable,
14 MActorUrl
15} from './actor'
16import { FunctionProperties, PickWith } from '../../utils'
17import { MAccountBlocklistId } from './account-blocklist'
18import { MChannelDefault } from '../video/video-channels'
19
20type Use<K extends keyof AccountModel, M> = PickWith<AccountModel, K, M>
21
22// ############################################################################
23
24export type MAccount =
25 Omit<AccountModel, 'Actor' | 'User' | 'Application' | 'VideoChannels' | 'VideoPlaylists' |
26 'VideoComments' | 'BlockedAccounts'>
27
28// ############################################################################
29
30// Only some attributes
31export type MAccountId = Pick<MAccount, 'id'>
32export type MAccountUserId = Pick<MAccount, 'userId'>
33
34// Only some Actor attributes
35export type MAccountUrl = Use<'Actor', MActorUrl>
36export type MAccountAudience = Use<'Actor', MActorAudience>
37
38export type MAccountIdActor =
39 MAccountId &
40 Use<'Actor', MActor>
41
42export type MAccountIdActorId =
43 MAccountId &
44 Use<'Actor', MActorId>
45
46// ############################################################################
47
48// Default scope
49export type MAccountDefault =
50 MAccount &
51 Use<'Actor', MActorDefault>
52
53// Default with default association scopes
54export type MAccountDefaultChannelDefault =
55 MAccount &
56 Use<'Actor', MActorDefault> &
57 Use<'VideoChannels', MChannelDefault[]>
58
59// We don't need some actors attributes
60export type MAccountLight =
61 MAccount &
62 Use<'Actor', MActorDefaultLight>
63
64// ############################################################################
65
66// Full actor
67export type MAccountActor =
68 MAccount &
69 Use<'Actor', MActor>
70
71// Full actor with server
72export type MAccountServer =
73 MAccount &
74 Use<'Actor', MActorServer>
75
76// ############################################################################
77
78// For API
79
80export type MAccountSummary =
81 FunctionProperties<MAccount> &
82 Pick<MAccount, 'id' | 'name'> &
83 Use<'Actor', MActorSummary>
84
85export type MAccountSummaryBlocks =
86 MAccountSummary &
87 Use<'BlockedAccounts', MAccountBlocklistId[]>
88
89export type MAccountAPI =
90 MAccount &
91 Use<'Actor', MActorAPI>
92
93// ############################################################################
94
95// Format for API or AP object
96
97export type MAccountSummaryFormattable =
98 FunctionProperties<MAccount> &
99 Pick<MAccount, 'id' | 'name'> &
100 Use<'Actor', MActorSummaryFormattable>
101
102export type MAccountFormattable =
103 FunctionProperties<MAccount> &
104 Pick<MAccount, 'id' | 'name' | 'description' | 'createdAt' | 'updatedAt' | 'userId'> &
105 Use<'Actor', MActorFormattable>
106
107export type MAccountAP =
108 Pick<MAccount, 'name' | 'description'> &
109 Use<'Actor', MActorAP>
diff --git a/server/types/models/account/actor-follow.ts b/server/types/models/account/actor-follow.ts
new file mode 100644
index 000000000..5d0c03c8d
--- /dev/null
+++ b/server/types/models/account/actor-follow.ts
@@ -0,0 +1,70 @@
1import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
2import {
3 MActor,
4 MActorChannelAccountActor,
5 MActorDefault,
6 MActorDefaultAccountChannel,
7 MActorFormattable,
8 MActorHost,
9 MActorUsername
10} from './actor'
11import { PickWith } from '../../utils'
12import { ActorModel } from '@server/models/activitypub/actor'
13import { MChannelDefault } from '../video/video-channels'
14
15type Use<K extends keyof ActorFollowModel, M> = PickWith<ActorFollowModel, K, M>
16
17// ############################################################################
18
19export type MActorFollow = Omit<ActorFollowModel, 'ActorFollower' | 'ActorFollowing'>
20
21// ############################################################################
22
23export type MActorFollowFollowingHost =
24 MActorFollow &
25 Use<'ActorFollowing', MActorUsername & MActorHost>
26
27// ############################################################################
28
29// With actors or actors default
30
31export type MActorFollowActors =
32 MActorFollow &
33 Use<'ActorFollower', MActor> &
34 Use<'ActorFollowing', MActor>
35
36export type MActorFollowActorsDefault =
37 MActorFollow &
38 Use<'ActorFollower', MActorDefault> &
39 Use<'ActorFollowing', MActorDefault>
40
41export type MActorFollowFull =
42 MActorFollow &
43 Use<'ActorFollower', MActorDefaultAccountChannel> &
44 Use<'ActorFollowing', MActorDefaultAccountChannel>
45
46// ############################################################################
47
48// For subscriptions
49
50type SubscriptionFollowing =
51 MActorDefault &
52 PickWith<ActorModel, 'VideoChannel', MChannelDefault>
53
54export type MActorFollowActorsDefaultSubscription =
55 MActorFollow &
56 Use<'ActorFollower', MActorDefault> &
57 Use<'ActorFollowing', SubscriptionFollowing>
58
59export type MActorFollowSubscriptions =
60 MActorFollow &
61 Use<'ActorFollowing', MActorChannelAccountActor>
62
63// ############################################################################
64
65// Format for API or AP object
66
67export type MActorFollowFormattable =
68 Pick<MActorFollow, 'id' | 'score' | 'state' | 'createdAt' | 'updatedAt'> &
69 Use<'ActorFollower', MActorFormattable> &
70 Use<'ActorFollowing', MActorFormattable>
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 @@
1import { ActorModel } from '../../../models/activitypub/actor'
2import { FunctionProperties, PickWith, PickWithOpt } from '../../utils'
3import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account'
4import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server'
5import { MAvatar, MAvatarFormattable } from './avatar'
6import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video'
7
8type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M>
9
10// ############################################################################
11
12export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'Avatar' | 'ActorFollowers' | 'Server'>
13
14// ############################################################################
15
16export type MActorUrl = Pick<MActor, 'url'>
17export type MActorId = Pick<MActor, 'id'>
18export type MActorUsername = Pick<MActor, 'preferredUsername'>
19
20export type MActorFollowersUrl = Pick<MActor, 'followersUrl'>
21export type MActorAudience = MActorUrl & MActorFollowersUrl
22export type MActorWithInboxes = Pick<ActorModel, 'sharedInboxUrl' | 'inboxUrl' | 'getSharedInbox'>
23export type MActorSignature = MActorAccountChannelId
24
25export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'>
26
27// ############################################################################
28
29// Some association attributes
30
31export type MActorHost = Use<'Server', MServerHost>
32export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed>
33
34export type MActorDefaultLight =
35 MActorLight &
36 Use<'Server', MServerHost> &
37 Use<'Avatar', MAvatar>
38
39export type MActorAccountId =
40 MActor &
41 Use<'Account', MAccountId>
42export type MActorAccountIdActor =
43 MActor &
44 Use<'Account', MAccountIdActor>
45
46export type MActorChannelId =
47 MActor &
48 Use<'VideoChannel', MChannelId>
49export type MActorChannelIdActor =
50 MActor &
51 Use<'VideoChannel', MChannelIdActor>
52
53export type MActorAccountChannelId = MActorAccountId & MActorChannelId
54export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor
55
56// ############################################################################
57
58// Include raw account/channel/server
59
60export type MActorAccount =
61 MActor &
62 Use<'Account', MAccount>
63
64export type MActorChannel =
65 MActor &
66 Use<'VideoChannel', MChannel>
67
68export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel
69
70export type MActorServer =
71 MActor &
72 Use<'Server', MServer>
73
74// ############################################################################
75
76// Complex actor associations
77
78export 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
85export type MActorChannelAccountActor =
86 MActor &
87 Use<'VideoChannel', MChannelAccountActor>
88
89export 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
97export 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
108export type MActorSummary =
109 FunctionProperties<MActor> &
110 Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> &
111 Use<'Server', MServerHost> &
112 Use<'Avatar', MAvatar>
113
114export type MActorSummaryBlocks =
115 MActorSummary &
116 Use<'Server', MServerHostBlocks>
117
118export 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
126export type MActorSummaryFormattable =
127 FunctionProperties<MActor> &
128 Pick<MActor, 'url' | 'preferredUsername'> &
129 Use<'Server', MServerHost> &
130 Use<'Avatar', MAvatarFormattable>
131
132export type MActorFormattable =
133 MActorSummaryFormattable &
134 Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt'> &
135 Use<'Server', MServerHost & Partial<Pick<MServer, 'redundancyAllowed'>>>
136
137export type MActorAP =
138 MActor &
139 Use<'Avatar', MAvatar>
diff --git a/server/types/models/account/avatar.ts b/server/types/models/account/avatar.ts
new file mode 100644
index 000000000..6eba59ee4
--- /dev/null
+++ b/server/types/models/account/avatar.ts
@@ -0,0 +1,12 @@
1import { AvatarModel } from '../../../models/avatar/avatar'
2import { FunctionProperties } from '@server/types/utils'
3
4export type MAvatar = AvatarModel
5
6// ############################################################################
7
8// Format for API or AP object
9
10export type MAvatarFormattable =
11 FunctionProperties<MAvatar> &
12 Pick<MAvatar, 'filename' | 'createdAt' | 'updatedAt'>
diff --git a/server/types/models/account/index.ts b/server/types/models/account/index.ts
new file mode 100644
index 000000000..513c09c40
--- /dev/null
+++ b/server/types/models/account/index.ts
@@ -0,0 +1,5 @@
1export * from './account'
2export * from './account-blocklist'
3export * from './actor'
4export * from './actor-follow'
5export * from './avatar'