]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/typings/models/account/account.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / typings / models / account / account.ts
index f3646d5102dcb54e64fb73ce6b80b6bf4e7814a0..ec78fece8a589cac377037bff3f2094fe2b4dfe2 100644 (file)
@@ -1,56 +1,95 @@
 import { AccountModel } from '../../../models/account/account'
 import {
   MActor,
-  MActorAccountChannelId,
+  MActorAP,
   MActorAPI,
   MActorAudience,
   MActorDefault,
-  MActorDefaultLight, MActorId,
+  MActorDefaultLight,
+  MActorFormattable,
+  MActorId,
   MActorServer,
   MActorSummary,
+  MActorSummaryFormattable,
   MActorUrl
 } from './actor'
-import { PickWith } from '../../utils'
+import { FunctionProperties, PickWith } from '../../utils'
 import { MAccountBlocklistId } from './account-blocklist'
 import { MChannelDefault } from '@server/typings/models'
 
-export type MAccountId = Pick<AccountModel, 'id'>
-export type MAccountIdActor = MAccountId &
-  PickWith<AccountModel, 'Actor', MActorAccountChannelId>
-export type MAccountIdActorId = MAccountId &
-  PickWith<AccountModel, 'Actor', MActorId>
+type Use<K extends keyof AccountModel, M> = PickWith<AccountModel, K, M>
+
+// ############################################################################
 
 export type MAccount = Omit<AccountModel, 'Actor' | 'User' | 'Application' | 'VideoChannels' | 'VideoPlaylists' |
   'VideoComments' | 'BlockedAccounts'>
 
+// ############################################################################
+
+// Only some attributes
+export type MAccountId = Pick<MAccount, 'id'>
+export type MAccountUserId = Pick<MAccount, 'userId'>
+
+// Only some Actor attributes
+export type MAccountUrl = Use<'Actor', MActorUrl>
+export type MAccountAudience = Use<'Actor', MActorAudience>
+
+export type MAccountIdActor = MAccountId &
+  Use<'Actor', MActor>
+
+export type MAccountIdActorId = MAccountId &
+  Use<'Actor', MActorId>
+
+// ############################################################################
+
 // Default scope
 export type MAccountDefault = MAccount &
-  PickWith<AccountModel, 'Actor', MActorDefault>
+  Use<'Actor', MActorDefault>
 
-export type MAccountDefaultChannelDefault = MAccountDefault &
-  PickWith<AccountModel, 'VideoChannels', MChannelDefault[]>
+// 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<AccountModel, 'Actor', MActorDefaultLight>
+  Use<'Actor', MActorDefaultLight>
 
-export type MAccountUserId = Pick<MAccount, 'userId'>
+// ############################################################################
 
+// Full actor
 export type MAccountActor = MAccount &
-  PickWith<AccountModel, 'Actor', MActor>
-export type MAccountServer = MAccountActor &
-  PickWith<AccountModel, 'Actor', MActorServer>
+  Use<'Actor', MActor>
+
+// Full actor with server
+export type MAccountServer = MAccount &
+  Use<'Actor', MActorServer>
+
+// ############################################################################
+
+// For API
+
+export type MAccountSummary = FunctionProperties<MAccount> &
+  Pick<MAccount, 'id' | 'name'> &
+  Use<'Actor', MActorSummary>
+
+export type MAccountSummaryBlocks = MAccountSummary &
+  Use<'BlockedAccounts', MAccountBlocklistId[]>
+
+export type MAccountAPI = MAccount &
+  Use<'Actor', MActorAPI>
 
-export type MAccountActorDefault = MAccount &
-  PickWith<AccountModel, 'Actor', MActorDefault>
+// ############################################################################
 
-export type MAccountSummary = Pick<MAccount, 'id' | 'name'> &
-  PickWith<AccountModel, 'Actor', MActorSummary>
+// Format for API or AP object
 
-export type MAccountBlocks = MAccountSummary &
-  PickWith<AccountModel, 'BlockedAccounts', MAccountBlocklistId[]>
+export type MAccountSummaryFormattable = FunctionProperties<MAccount> &
+  Pick<MAccount, 'id' | 'name'> &
+  Use<'Actor', MActorSummaryFormattable>
 
-export type MAccountAPI = MAccountDefault &
-  PickWith<AccountModel, 'Actor', MActorAPI>
+export type MAccountFormattable = FunctionProperties<MAccount> &
+  Pick<MAccount, 'id' | 'name' | 'description' | 'createdAt' | 'updatedAt' | 'userId'> &
+  Use<'Actor', MActorFormattable>
 
-export type MAccountUrl = PickWith<AccountModel, 'Actor', MActorUrl>
-export type MAccountAudience = PickWith<AccountModel, 'Actor', MActorAudience>
+export type MAccountAP = Pick<MAccount, 'name' | 'description'> &
+  Use<'Actor', MActorAP>