diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-20 13:52:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-20 14:53:42 +0200 |
commit | 0283eaac2a8e73006c66df3cf5bb9012e37450e5 (patch) | |
tree | 1fb73aeef57f984a77f47828ade23c6365ce8eb0 /server/typings/models/account | |
parent | 96ca24f00e5ae5471dee9ee596489fe50af2b46f (diff) | |
download | PeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.tar.gz PeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.tar.zst PeerTube-0283eaac2a8e73006c66df3cf5bb9012e37450e5.zip |
Cleanup model types
Diffstat (limited to 'server/typings/models/account')
-rw-r--r-- | server/typings/models/account/account-blocklist.ts | 10 | ||||
-rw-r--r-- | server/typings/models/account/account.ts | 69 | ||||
-rw-r--r-- | server/typings/models/account/actor-follow.ts | 56 | ||||
-rw-r--r-- | server/typings/models/account/actor.ts | 93 |
4 files changed, 156 insertions, 72 deletions
diff --git a/server/typings/models/account/account-blocklist.ts b/server/typings/models/account/account-blocklist.ts index 6d1771de8..d20d97aa8 100644 --- a/server/typings/models/account/account-blocklist.ts +++ b/server/typings/models/account/account-blocklist.ts | |||
@@ -2,10 +2,16 @@ import { AccountBlocklistModel } from '../../../models/account/account-blocklist | |||
2 | import { PickWith } from '../../utils' | 2 | import { PickWith } from '../../utils' |
3 | import { MAccountDefault } from './account' | 3 | import { MAccountDefault } from './account' |
4 | 4 | ||
5 | type Use<K extends keyof AccountBlocklistModel, M> = PickWith<AccountBlocklistModel, K, M> | ||
6 | |||
7 | // ############################################################################ | ||
8 | |||
5 | export type MAccountBlocklist = Omit<AccountBlocklistModel, 'ByAccount' | 'BlockedAccount'> | 9 | export type MAccountBlocklist = Omit<AccountBlocklistModel, 'ByAccount' | 'BlockedAccount'> |
6 | 10 | ||
11 | // ############################################################################ | ||
12 | |||
7 | export type MAccountBlocklistId = Pick<AccountBlocklistModel, 'id'> | 13 | export type MAccountBlocklistId = Pick<AccountBlocklistModel, 'id'> |
8 | 14 | ||
9 | export type MAccountBlocklistAccounts = MAccountBlocklist & | 15 | export type MAccountBlocklistAccounts = MAccountBlocklist & |
10 | PickWith<AccountBlocklistModel, 'ByAccount', MAccountDefault> & | 16 | Use<'ByAccount', MAccountDefault> & |
11 | PickWith<AccountBlocklistModel, 'BlockedAccount', MAccountDefault> | 17 | Use<'BlockedAccount', MAccountDefault> |
diff --git a/server/typings/models/account/account.ts b/server/typings/models/account/account.ts index f3646d510..9a8784e6b 100644 --- a/server/typings/models/account/account.ts +++ b/server/typings/models/account/account.ts | |||
@@ -5,7 +5,8 @@ import { | |||
5 | MActorAPI, | 5 | MActorAPI, |
6 | MActorAudience, | 6 | MActorAudience, |
7 | MActorDefault, | 7 | MActorDefault, |
8 | MActorDefaultLight, MActorId, | 8 | MActorDefaultLight, |
9 | MActorId, | ||
9 | MActorServer, | 10 | MActorServer, |
10 | MActorSummary, | 11 | MActorSummary, |
11 | MActorUrl | 12 | MActorUrl |
@@ -14,43 +15,63 @@ import { PickWith } from '../../utils' | |||
14 | import { MAccountBlocklistId } from './account-blocklist' | 15 | import { MAccountBlocklistId } from './account-blocklist' |
15 | import { MChannelDefault } from '@server/typings/models' | 16 | import { MChannelDefault } from '@server/typings/models' |
16 | 17 | ||
17 | export type MAccountId = Pick<AccountModel, 'id'> | 18 | type Use<K extends keyof AccountModel, M> = PickWith<AccountModel, K, M> |
18 | export type MAccountIdActor = MAccountId & | 19 | |
19 | PickWith<AccountModel, 'Actor', MActorAccountChannelId> | 20 | // ############################################################################ |
20 | export type MAccountIdActorId = MAccountId & | ||
21 | PickWith<AccountModel, 'Actor', MActorId> | ||
22 | 21 | ||
23 | export type MAccount = Omit<AccountModel, 'Actor' | 'User' | 'Application' | 'VideoChannels' | 'VideoPlaylists' | | 22 | export type MAccount = Omit<AccountModel, 'Actor' | 'User' | 'Application' | 'VideoChannels' | 'VideoPlaylists' | |
24 | 'VideoComments' | 'BlockedAccounts'> | 23 | 'VideoComments' | 'BlockedAccounts'> |
25 | 24 | ||
25 | // ############################################################################ | ||
26 | |||
27 | // Only some attributes | ||
28 | export type MAccountId = Pick<MAccount, 'id'> | ||
29 | export type MAccountUserId = Pick<MAccount, 'userId'> | ||
30 | |||
31 | // Only some Actor attributes | ||
32 | export type MAccountUrl = Use<'Actor', MActorUrl> | ||
33 | export type MAccountAudience = Use<'Actor', MActorAudience> | ||
34 | |||
35 | export type MAccountIdActor = MAccountId & | ||
36 | Use<'Actor', MActorAccountChannelId> | ||
37 | |||
38 | export type MAccountIdActorId = MAccountId & | ||
39 | Use<'Actor', MActorId> | ||
40 | |||
41 | // ############################################################################ | ||
42 | |||
26 | // Default scope | 43 | // Default scope |
27 | export type MAccountDefault = MAccount & | 44 | export type MAccountDefault = MAccount & |
28 | PickWith<AccountModel, 'Actor', MActorDefault> | 45 | Use<'Actor', MActorDefault> |
29 | 46 | ||
30 | export type MAccountDefaultChannelDefault = MAccountDefault & | 47 | // Default with default association scopes |
31 | PickWith<AccountModel, 'VideoChannels', MChannelDefault[]> | 48 | export type MAccountDefaultChannelDefault = MAccount & |
49 | Use<'Actor', MActorDefault> & | ||
50 | Use<'VideoChannels', MChannelDefault[]> | ||
32 | 51 | ||
52 | // We don't need some actors attributes | ||
33 | export type MAccountLight = MAccount & | 53 | export type MAccountLight = MAccount & |
34 | PickWith<AccountModel, 'Actor', MActorDefaultLight> | 54 | Use<'Actor', MActorDefaultLight> |
35 | 55 | ||
36 | export type MAccountUserId = Pick<MAccount, 'userId'> | 56 | // ############################################################################ |
37 | 57 | ||
58 | // Full actor | ||
38 | export type MAccountActor = MAccount & | 59 | export type MAccountActor = MAccount & |
39 | PickWith<AccountModel, 'Actor', MActor> | 60 | Use<'Actor', MActor> |
40 | export type MAccountServer = MAccountActor & | ||
41 | PickWith<AccountModel, 'Actor', MActorServer> | ||
42 | 61 | ||
43 | export type MAccountActorDefault = MAccount & | 62 | // Full actor with server |
44 | PickWith<AccountModel, 'Actor', MActorDefault> | 63 | export type MAccountServer = MAccount & |
64 | Use<'Actor', MActorServer> | ||
45 | 65 | ||
46 | export type MAccountSummary = Pick<MAccount, 'id' | 'name'> & | 66 | // ############################################################################ |
47 | PickWith<AccountModel, 'Actor', MActorSummary> | ||
48 | 67 | ||
49 | export type MAccountBlocks = MAccountSummary & | 68 | // For API |
50 | PickWith<AccountModel, 'BlockedAccounts', MAccountBlocklistId[]> | 69 | |
70 | export type MAccountSummary = Pick<MAccount, 'id' | 'name'> & | ||
71 | Use<'Actor', MActorSummary> | ||
51 | 72 | ||
52 | export type MAccountAPI = MAccountDefault & | 73 | export type MAccountSummaryBlocks = MAccountSummary & |
53 | PickWith<AccountModel, 'Actor', MActorAPI> | 74 | Use<'BlockedAccounts', MAccountBlocklistId[]> |
54 | 75 | ||
55 | export type MAccountUrl = PickWith<AccountModel, 'Actor', MActorUrl> | 76 | export type MAccountAPI = MAccount & |
56 | export type MAccountAudience = PickWith<AccountModel, 'Actor', MActorAudience> | 77 | Use<'Actor', MActorAPI> |
diff --git a/server/typings/models/account/actor-follow.ts b/server/typings/models/account/actor-follow.ts index 96c53d857..87050ac63 100644 --- a/server/typings/models/account/actor-follow.ts +++ b/server/typings/models/account/actor-follow.ts | |||
@@ -1,27 +1,55 @@ | |||
1 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 1 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
2 | import { MActor, MActorAccountChannel, MActorChannel, MActorChannelAccount, MActorDefault, MActorHost, MActorUsername } from './actor' | 2 | import { |
3 | MActor, | ||
4 | MActorAccount, | ||
5 | MActorAccountChannel, | ||
6 | MActorChannel, | ||
7 | MActorChannelAccountActor, | ||
8 | MActorDefault, | ||
9 | MActorHost, | ||
10 | MActorUsername | ||
11 | } from './actor' | ||
3 | import { PickWith } from '../../utils' | 12 | import { PickWith } from '../../utils' |
13 | import { ActorModel } from '@server/models/activitypub/actor' | ||
14 | |||
15 | type Use<K extends keyof ActorFollowModel, M> = PickWith<ActorFollowModel, K, M> | ||
16 | |||
17 | // ############################################################################ | ||
4 | 18 | ||
5 | export type MActorFollow = Omit<ActorFollowModel, 'ActorFollower' | 'ActorFollowing'> | 19 | export type MActorFollow = Omit<ActorFollowModel, 'ActorFollower' | 'ActorFollowing'> |
6 | 20 | ||
21 | // ############################################################################ | ||
22 | |||
23 | export type MActorFollowFollowingHost = MActorFollow & | ||
24 | Use<'ActorFollowing', MActorUsername & MActorHost> | ||
25 | |||
26 | // ############################################################################ | ||
27 | |||
28 | // With actors or actors default | ||
29 | |||
7 | export type MActorFollowActors = MActorFollow & | 30 | export type MActorFollowActors = MActorFollow & |
8 | PickWith<ActorFollowModel, 'ActorFollower', MActor> & | 31 | Use<'ActorFollower', MActor> & |
9 | PickWith<ActorFollowModel, 'ActorFollowing', MActor> | 32 | Use<'ActorFollowing', MActor> |
10 | 33 | ||
11 | export type MActorFollowActorsDefault = MActorFollow & | 34 | export type MActorFollowActorsDefault = MActorFollow & |
12 | PickWith<ActorFollowModel, 'ActorFollower', MActorDefault> & | 35 | Use<'ActorFollower', MActorDefault> & |
13 | PickWith<ActorFollowModel, 'ActorFollowing', MActorDefault> | 36 | Use<'ActorFollowing', MActorDefault> |
14 | |||
15 | export type MActorFollowActorsDefaultSubscription = MActorFollow & | ||
16 | PickWith<ActorFollowModel, 'ActorFollower', MActorDefault> & | ||
17 | PickWith<ActorFollowModel, 'ActorFollowing', MActorDefault & MActorChannel> | ||
18 | 37 | ||
19 | export type MActorFollowFull = MActorFollow & | 38 | export type MActorFollowFull = MActorFollow & |
20 | PickWith<ActorFollowModel, 'ActorFollower', MActorAccountChannel> & | 39 | Use<'ActorFollower', MActorAccountChannel> & |
21 | PickWith<ActorFollowModel, 'ActorFollowing', MActorAccountChannel> | 40 | Use<'ActorFollowing', MActorAccountChannel> |
22 | 41 | ||
23 | export type MActorFollowFollowingHost = MActorFollow & | 42 | // ############################################################################ |
24 | PickWith<ActorFollowModel, 'ActorFollowing', MActorUsername & MActorHost> | 43 | |
44 | // For subscriptions | ||
45 | |||
46 | export type MActorFollowActorsDefaultSubscription = MActorFollow & | ||
47 | Use<'ActorFollower', MActorDefault> & | ||
48 | Use<'ActorFollowing', MActorDefault & MActorChannel> | ||
49 | |||
50 | export type MActorFollowFollowingFullFollowerAccount = MActorFollow & | ||
51 | Use<'ActorFollower', MActorAccount> & | ||
52 | Use<'ActorFollowing', MActorAccountChannel> | ||
25 | 53 | ||
26 | export type MActorFollowSubscriptions = MActorFollow & | 54 | export type MActorFollowSubscriptions = MActorFollow & |
27 | PickWith<ActorFollowModel, 'ActorFollowing', MActorChannelAccount> | 55 | Use<'ActorFollowing', MActorChannelAccountActor> |
diff --git a/server/typings/models/account/actor.ts b/server/typings/models/account/actor.ts index f3e752a98..7d99a433b 100644 --- a/server/typings/models/account/actor.ts +++ b/server/typings/models/account/actor.ts | |||
@@ -1,74 +1,103 @@ | |||
1 | import { ActorModel } from '../../../models/activitypub/actor' | 1 | import { ActorModel } from '../../../models/activitypub/actor' |
2 | import { PickWith } from '../../utils' | 2 | import { PickWith } from '../../utils' |
3 | import { MAccount, MAccountActorDefault, MAccountId, MAccountIdActor } from './account' | 3 | import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account' |
4 | import { MServerHost, MServerHostBlocks, MServer } from '../server' | 4 | import { MServer, MServerHost, MServerHostBlocks } from '../server' |
5 | import { MAvatar } from './avatar' | 5 | import { MAvatar } from './avatar' |
6 | import { MChannel, MChannelAccountActor, MChannelActorAccountDefault, MChannelId, MChannelIdActor } from '../video' | 6 | import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video' |
7 | |||
8 | type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M> | ||
9 | |||
10 | // ############################################################################ | ||
7 | 11 | ||
8 | export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'Avatar' | 'ActorFollowers' | 'Server'> | 12 | export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'Avatar' | 'ActorFollowers' | 'Server'> |
9 | 13 | ||
14 | // ############################################################################ | ||
15 | |||
10 | export type MActorUrl = Pick<MActor, 'url'> | 16 | export type MActorUrl = Pick<MActor, 'url'> |
11 | export type MActorId = Pick<MActor, 'id'> | 17 | export type MActorId = Pick<MActor, 'id'> |
12 | export type MActorUsername = Pick<MActor, 'preferredUsername'> | 18 | export type MActorUsername = Pick<MActor, 'preferredUsername'> |
13 | export type MActorHost = PickWith<ActorModel, 'Server', MServerHost> | ||
14 | 19 | ||
15 | export type MActorFollowersUrl = Pick<MActor, 'followersUrl'> | 20 | export type MActorFollowersUrl = Pick<MActor, 'followersUrl'> |
16 | export type MActorAudience = MActorUrl & MActorFollowersUrl | 21 | export type MActorAudience = MActorUrl & MActorFollowersUrl |
22 | export type MActorFollowerException = Pick<ActorModel, 'sharedInboxUrl' | 'inboxUrl'> | ||
23 | export type MActorSignature = MActorAccountChannelId | ||
17 | 24 | ||
18 | export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'> | 25 | export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'> |
19 | 26 | ||
27 | // ############################################################################ | ||
28 | |||
29 | // Some association attributes | ||
30 | |||
31 | export type MActorHost = Use<'Server', MServerHost> | ||
32 | |||
20 | export type MActorDefaultLight = MActorLight & | 33 | export type MActorDefaultLight = MActorLight & |
21 | MActorHost & | 34 | Use<'Server', MServerHost> & |
22 | PickWith<ActorModel, 'Avatar', MAvatar> | 35 | Use<'Avatar', MAvatar> |
23 | 36 | ||
24 | export type MActorAccountId = MActor & | 37 | export type MActorAccountId = MActor & |
25 | PickWith<ActorModel, 'Account', MAccountId> | 38 | Use<'Account', MAccountId> |
26 | export type MActorAccountIdActor = MActor & | 39 | export type MActorAccountIdActor = MActor & |
27 | PickWith<ActorModel, 'Account', MAccountIdActor> | 40 | Use<'Account', MAccountIdActor> |
28 | 41 | ||
29 | export type MActorChannelId = MActor & | 42 | export type MActorChannelId = MActor & |
30 | PickWith<ActorModel, 'VideoChannel', MChannelId> | 43 | Use<'VideoChannel', MChannelId> |
31 | export type MActorChannelIdActor = MActor & | 44 | export type MActorChannelIdActor = MActor & |
32 | PickWith<ActorModel, 'VideoChannel', MChannelIdActor> | 45 | Use<'VideoChannel', MChannelIdActor> |
33 | 46 | ||
34 | export type MActorAccountChannelId = MActorAccountId & MActorChannelId | 47 | export type MActorAccountChannelId = MActorAccountId & MActorChannelId |
35 | export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor | 48 | export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor |
36 | 49 | ||
50 | // ############################################################################ | ||
51 | |||
52 | // Include raw account/channel/server | ||
53 | |||
37 | export type MActorAccount = MActor & | 54 | export type MActorAccount = MActor & |
38 | PickWith<ActorModel, 'Account', MAccount> | 55 | Use<'Account', MAccount> |
39 | 56 | ||
40 | export type MActorChannel = MActor & | 57 | export type MActorChannel = MActor & |
41 | PickWith<ActorModel, 'VideoChannel', MChannel> | 58 | Use<'VideoChannel', MChannel> |
42 | 59 | ||
43 | export type MActorAccountChannel = MActorAccount & MActorChannel | 60 | export type MActorAccountChannel = MActorAccount & MActorChannel |
44 | 61 | ||
45 | export type MActorChannelAccount = MActor & | ||
46 | PickWith<ActorModel, 'VideoChannel', MChannelAccountActor> | ||
47 | |||
48 | export type MActorServer = MActor & | 62 | export type MActorServer = MActor & |
49 | PickWith<ActorModel, 'Server', MServer> | 63 | Use<'Server', MServer> |
50 | 64 | ||
51 | export type MActorDefault = MActorServer & | 65 | // ############################################################################ |
52 | PickWith<ActorModel, 'Avatar', MAvatar> | ||
53 | 66 | ||
54 | export type MActorFull = MActorDefault & | 67 | // Complex actor associations |
55 | PickWith<ActorModel, 'Account', MAccount> & | ||
56 | PickWith<ActorModel, 'VideoChannel', MChannelAccountActor> | ||
57 | 68 | ||
58 | export type MActorFullActor = MActorDefault & | 69 | export type MActorDefault = MActor & |
59 | PickWith<ActorModel, 'Account', MAccountActorDefault> & | 70 | Use<'Server', MServer> & |
60 | PickWith<ActorModel, 'VideoChannel', MChannelActorAccountDefault> | 71 | Use<'Avatar', MAvatar> |
61 | 72 | ||
62 | export type MActorSummary = Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> & | 73 | // Actor with channel that is associated to an account and its actor |
63 | MActorHost & | 74 | // Actor -> VideoChannel -> Account -> Actor |
64 | PickWith<ActorModel, 'Avatar', MAvatar> | 75 | export type MActorChannelAccountActor = MActor & |
76 | Use<'VideoChannel', MChannelAccountActor> | ||
65 | 77 | ||
66 | export type MActorSummaryBlocks = Omit<MActorSummary, 'Server'> & | 78 | export type MActorFull = MActor & |
67 | PickWith<ActorModel, 'Server', MServerHostBlocks> | 79 | Use<'Server', MServer> & |
80 | Use<'Avatar', MAvatar> & | ||
81 | Use<'Account', MAccount> & | ||
82 | Use<'VideoChannel', MChannelAccountActor> | ||
68 | 83 | ||
69 | export type MActorFollowerException = Pick<ActorModel, 'sharedInboxUrl' | 'inboxUrl'> | 84 | // Same than ActorFull, but the account and the channel have their actor |
85 | export type MActorFullActor = MActor & | ||
86 | Use<'Server', MServer> & | ||
87 | Use<'Avatar', MAvatar> & | ||
88 | Use<'Account', MAccountDefault> & | ||
89 | Use<'VideoChannel', MChannelAccountDefault> | ||
90 | |||
91 | // ############################################################################ | ||
92 | |||
93 | // API | ||
94 | |||
95 | export type MActorSummary = Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> & | ||
96 | Use<'Server', MServerHost> & | ||
97 | Use<'Avatar', MAvatar> | ||
98 | |||
99 | export type MActorSummaryBlocks = MActorSummary & | ||
100 | Use<'Server', MServerHostBlocks> | ||
70 | 101 | ||
71 | export type MActorAPI = Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' | | 102 | export type MActorAPI = Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' | |
72 | 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'> | 103 | 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'> |
73 | |||
74 | export type MActorSignature = MActorAccountChannelId | ||