From 0283eaac2a8e73006c66df3cf5bb9012e37450e5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Aug 2019 13:52:49 +0200 Subject: Cleanup model types --- server/typings/models/account/account-blocklist.ts | 10 ++- server/typings/models/account/account.ts | 69 ++++++++++------ server/typings/models/account/actor-follow.ts | 56 +++++++++---- server/typings/models/account/actor.ts | 93 ++++++++++++++-------- 4 files changed, 156 insertions(+), 72 deletions(-) (limited to 'server/typings/models/account') 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 import { PickWith } from '../../utils' import { MAccountDefault } from './account' +type Use = PickWith + +// ############################################################################ + export type MAccountBlocklist = Omit +// ############################################################################ + export type MAccountBlocklistId = Pick export type MAccountBlocklistAccounts = MAccountBlocklist & - PickWith & - PickWith + Use<'ByAccount', MAccountDefault> & + 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 { MActorAPI, MActorAudience, MActorDefault, - MActorDefaultLight, MActorId, + MActorDefaultLight, + MActorId, MActorServer, MActorSummary, MActorUrl @@ -14,43 +15,63 @@ import { PickWith } from '../../utils' import { MAccountBlocklistId } from './account-blocklist' import { MChannelDefault } from '@server/typings/models' -export type MAccountId = Pick -export type MAccountIdActor = MAccountId & - PickWith -export type MAccountIdActorId = MAccountId & - PickWith +type Use = PickWith + +// ############################################################################ export type MAccount = Omit +// ############################################################################ + +// Only some attributes +export type MAccountId = Pick +export type MAccountUserId = Pick + +// Only some Actor attributes +export type MAccountUrl = Use<'Actor', MActorUrl> +export type MAccountAudience = Use<'Actor', MActorAudience> + +export type MAccountIdActor = MAccountId & + Use<'Actor', MActorAccountChannelId> + +export type MAccountIdActorId = MAccountId & + Use<'Actor', MActorId> + +// ############################################################################ + // Default scope export type MAccountDefault = MAccount & - PickWith + Use<'Actor', MActorDefault> -export type MAccountDefaultChannelDefault = MAccountDefault & - PickWith +// Default with default association scopes +export type MAccountDefaultChannelDefault = MAccount & + Use<'Actor', MActorDefault> & + Use<'VideoChannels', MChannelDefault[]> +// We don't need some actors attributes export type MAccountLight = MAccount & - PickWith + Use<'Actor', MActorDefaultLight> -export type MAccountUserId = Pick +// ############################################################################ +// Full actor export type MAccountActor = MAccount & - PickWith -export type MAccountServer = MAccountActor & - PickWith + Use<'Actor', MActor> -export type MAccountActorDefault = MAccount & - PickWith +// Full actor with server +export type MAccountServer = MAccount & + Use<'Actor', MActorServer> -export type MAccountSummary = Pick & - PickWith +// ############################################################################ -export type MAccountBlocks = MAccountSummary & - PickWith +// For API + +export type MAccountSummary = Pick & + Use<'Actor', MActorSummary> -export type MAccountAPI = MAccountDefault & - PickWith +export type MAccountSummaryBlocks = MAccountSummary & + Use<'BlockedAccounts', MAccountBlocklistId[]> -export type MAccountUrl = PickWith -export type MAccountAudience = PickWith +export type MAccountAPI = MAccount & + 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 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow' -import { MActor, MActorAccountChannel, MActorChannel, MActorChannelAccount, MActorDefault, MActorHost, MActorUsername } from './actor' +import { + MActor, + MActorAccount, + MActorAccountChannel, + MActorChannel, + MActorChannelAccountActor, + MActorDefault, + MActorHost, + MActorUsername +} from './actor' import { PickWith } from '../../utils' +import { ActorModel } from '@server/models/activitypub/actor' + +type Use = PickWith + +// ############################################################################ export type MActorFollow = Omit +// ############################################################################ + +export type MActorFollowFollowingHost = MActorFollow & + Use<'ActorFollowing', MActorUsername & MActorHost> + +// ############################################################################ + +// With actors or actors default + export type MActorFollowActors = MActorFollow & - PickWith & - PickWith + Use<'ActorFollower', MActor> & + Use<'ActorFollowing', MActor> export type MActorFollowActorsDefault = MActorFollow & - PickWith & - PickWith - -export type MActorFollowActorsDefaultSubscription = MActorFollow & - PickWith & - PickWith + Use<'ActorFollower', MActorDefault> & + Use<'ActorFollowing', MActorDefault> export type MActorFollowFull = MActorFollow & - PickWith & - PickWith + Use<'ActorFollower', MActorAccountChannel> & + Use<'ActorFollowing', MActorAccountChannel> -export type MActorFollowFollowingHost = MActorFollow & - PickWith +// ############################################################################ + +// For subscriptions + +export type MActorFollowActorsDefaultSubscription = MActorFollow & + Use<'ActorFollower', MActorDefault> & + Use<'ActorFollowing', MActorDefault & MActorChannel> + +export type MActorFollowFollowingFullFollowerAccount = MActorFollow & + Use<'ActorFollower', MActorAccount> & + Use<'ActorFollowing', MActorAccountChannel> export type MActorFollowSubscriptions = MActorFollow & - PickWith + 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 @@ import { ActorModel } from '../../../models/activitypub/actor' import { PickWith } from '../../utils' -import { MAccount, MAccountActorDefault, MAccountId, MAccountIdActor } from './account' -import { MServerHost, MServerHostBlocks, MServer } from '../server' +import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account' +import { MServer, MServerHost, MServerHostBlocks } from '../server' import { MAvatar } from './avatar' -import { MChannel, MChannelAccountActor, MChannelActorAccountDefault, MChannelId, MChannelIdActor } from '../video' +import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video' + +type Use = PickWith + +// ############################################################################ export type MActor = Omit +// ############################################################################ + export type MActorUrl = Pick export type MActorId = Pick export type MActorUsername = Pick -export type MActorHost = PickWith export type MActorFollowersUrl = Pick export type MActorAudience = MActorUrl & MActorFollowersUrl +export type MActorFollowerException = Pick +export type MActorSignature = MActorAccountChannelId export type MActorLight = Omit +// ############################################################################ + +// Some association attributes + +export type MActorHost = Use<'Server', MServerHost> + export type MActorDefaultLight = MActorLight & - MActorHost & - PickWith + Use<'Server', MServerHost> & + Use<'Avatar', MAvatar> export type MActorAccountId = MActor & - PickWith + Use<'Account', MAccountId> export type MActorAccountIdActor = MActor & - PickWith + Use<'Account', MAccountIdActor> export type MActorChannelId = MActor & - PickWith + Use<'VideoChannel', MChannelId> export type MActorChannelIdActor = MActor & - PickWith + Use<'VideoChannel', MChannelIdActor> export type MActorAccountChannelId = MActorAccountId & MActorChannelId export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor +// ############################################################################ + +// Include raw account/channel/server + export type MActorAccount = MActor & - PickWith + Use<'Account', MAccount> export type MActorChannel = MActor & - PickWith + Use<'VideoChannel', MChannel> export type MActorAccountChannel = MActorAccount & MActorChannel -export type MActorChannelAccount = MActor & - PickWith - export type MActorServer = MActor & - PickWith + Use<'Server', MServer> -export type MActorDefault = MActorServer & - PickWith +// ############################################################################ -export type MActorFull = MActorDefault & - PickWith & - PickWith +// Complex actor associations -export type MActorFullActor = MActorDefault & - PickWith & - PickWith +export type MActorDefault = MActor & + Use<'Server', MServer> & + Use<'Avatar', MAvatar> -export type MActorSummary = Pick & - MActorHost & - PickWith +// 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 MActorSummaryBlocks = Omit & - PickWith +export type MActorFull = MActor & + Use<'Server', MServer> & + Use<'Avatar', MAvatar> & + Use<'Account', MAccount> & + Use<'VideoChannel', MChannelAccountActor> -export type MActorFollowerException = Pick +// Same than ActorFull, but the account and the channel have their actor +export type MActorFullActor = MActor & + Use<'Server', MServer> & + Use<'Avatar', MAvatar> & + Use<'Account', MAccountDefault> & + Use<'VideoChannel', MChannelAccountDefault> + +// ############################################################################ + +// API + +export type MActorSummary = Pick & + Use<'Server', MServerHost> & + Use<'Avatar', MAvatar> + +export type MActorSummaryBlocks = MActorSummary & + Use<'Server', MServerHostBlocks> export type MActorAPI = Omit - -export type MActorSignature = MActorAccountChannelId -- cgit v1.2.3