]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/typings/models/video/video-channels.ts
Type toActivityPubObject functions
[github/Chocobozzz/PeerTube.git] / server / typings / models / video / video-channels.ts
index e10bd68426f8dfd2ce07fa4196efb6285c07dd32..292d0ac95335184341a8ae7a69180b9e61f9250d 100644 (file)
-import { FunctionProperties, PickWith } from '../../utils'
+import { FunctionProperties, PickWith, PickWithOpt } from '../../utils'
 import { VideoChannelModel } from '../../../models/video/video-channel'
 import {
   MAccountActor,
   MAccountAPI,
-  MAccountBlocks,
   MAccountDefault,
+  MAccountFormattable,
   MAccountLight,
+  MAccountSummaryBlocks,
+  MAccountSummaryFormattable,
+  MAccountUrl,
   MAccountUserId,
   MActor,
   MActorAccountChannelId,
+  MActorAP,
   MActorAPI,
   MActorDefault,
-  MActorDefaultLight, MActorLight,
-  MActorSummary
+  MActorDefaultLight,
+  MActorFormattable,
+  MActorLight,
+  MActorSummary,
+  MActorSummaryFormattable, MActorUrl
 } from '../account'
 import { MVideo } from './video'
 
-export type MChannelId = FunctionProperties<VideoChannelModel>
-export type MChannelIdActor = MChannelId &
-  PickWith<VideoChannelModel, 'Actor', MActorAccountChannelId>
+type Use<K extends keyof VideoChannelModel, M> = PickWith<VideoChannelModel, K, M>
+
+// ############################################################################
 
 export type MChannel = Omit<VideoChannelModel, 'Actor' | 'Account' | 'Videos' | 'VideoPlaylists'>
 
+// ############################################################################
+
+export type MChannelId = Pick<MChannel, 'id'>
+
+// ############################################################################
+
+export type MChannelIdActor = MChannelId &
+  Use<'Actor', MActorAccountChannelId>
+
 export type MChannelUserId = Pick<MChannel, 'accountId'> &
-  PickWith<VideoChannelModel, 'Account', MAccountUserId>
+  Use<'Account', MAccountUserId>
+
+export type MChannelActor = MChannel &
+  Use<'Actor', MActor>
+
+export type MChannelUrl = Use<'Actor', MActorUrl>
 
 // Default scope
 export type MChannelDefault = MChannel &
-  PickWith<VideoChannelModel, 'Actor', MActorDefault>
+  Use<'Actor', MActorDefault>
+
+// ############################################################################
+
+// Not all association attributes
 
 export type MChannelLight = MChannel &
-  PickWith<VideoChannelModel, 'Actor', MActorDefaultLight>
+  Use<'Actor', MActorDefaultLight>
+
+export type MChannelActorLight = MChannel &
+  Use<'Actor', MActorLight>
 
 export type MChannelAccountLight = MChannel &
-  PickWith<VideoChannelModel, 'Actor', MActorDefaultLight> &
-  PickWith<VideoChannelModel, 'Account', MAccountLight>
+  Use<'Actor', MActorDefaultLight> &
+  Use<'Account', MAccountLight>
+
+// ############################################################################
 
-export type MChannelSummary = Pick<MChannel, 'id' | 'name' | 'description' | 'actorId'> &
-  PickWith<VideoChannelModel, 'Actor', MActorSummary>
+// Account associations
+
+export type MChannelAccountActor = MChannel &
+  Use<'Account', MAccountActor>
+
+export type MChannelAccountDefault = MChannel &
+  Use<'Actor', MActorDefault> &
+  Use<'Account', MAccountDefault>
+
+export type MChannelActorAccountActor = MChannel &
+  Use<'Account', MAccountActor> &
+  Use<'Actor', MActor>
+
+// ############################################################################
+
+// Videos  associations
+export type MChannelVideos = MChannel &
+  Use<'Videos', MVideo[]>
+
+export type MChannelActorAccountDefaultVideos = MChannel &
+  Use<'Actor', MActorDefault> &
+  Use<'Account', MAccountDefault> &
+  Use<'Videos', MVideo[]>
+
+// ############################################################################
+
+// For API
+
+export type MChannelSummary = FunctionProperties<MChannel> &
+  Pick<MChannel, 'id' | 'name' | 'description' | 'actorId'> &
+  Use<'Actor', MActorSummary>
 
 export type MChannelSummaryAccount = MChannelSummary &
-  PickWith<VideoChannelModel, 'Account', MAccountBlocks>
+  Use<'Account', MAccountSummaryBlocks>
 
 export type MChannelAPI = MChannel &
-  PickWith<VideoChannelModel, 'Actor', MActorAPI> &
-  PickWith<VideoChannelModel, 'Account', MAccountAPI>
+  Use<'Actor', MActorAPI> &
+  Use<'Account', MAccountAPI>
 
-export type MChannelAccountActor = MChannel &
-  PickWith<VideoChannelModel, 'Account', MAccountActor>
-export type MChannelAccountDefault = MChannelActor &
-  PickWith<VideoChannelModel, 'Account', MAccountDefault>
+// ############################################################################
 
-export type MChannelVideos = MChannel &
-  PickWith<VideoChannelModel, 'Videos', MVideo[]>
+// Format for API or AP object
 
-export type MChannelActor = MChannel &
-  PickWith<VideoChannelModel, 'Actor', MActor>
-export type MChannelActorLight = MChannel &
-  PickWith<VideoChannelModel, 'Actor', MActorLight>
-export type MChannelActorDefault = MChannel &
-  PickWith<VideoChannelModel, 'Actor', MActorDefault>
+export type MChannelSummaryFormattable = FunctionProperties<MChannel> &
+  Pick<MChannel, 'id' | 'name'> &
+  Use<'Actor', MActorSummaryFormattable>
 
-export type MChannelActorAccountActor = MChannelAccountActor & MChannelActor
+export type MChannelAccountSummaryFormattable = MChannelSummaryFormattable &
+  Use<'Account', MAccountSummaryFormattable>
 
-export type MChannelActorAccountDefault = MChannel &
-  PickWith<VideoChannelModel, 'Actor', MActorDefault> &
-  PickWith<VideoChannelModel, 'Account', MAccountDefault>
+export type MChannelFormattable = FunctionProperties<MChannel> &
+  Pick<MChannel, 'id' | 'name' | 'description' | 'createdAt' | 'updatedAt' | 'support'> &
+  Use<'Actor', MActorFormattable> &
+  PickWithOpt<VideoChannelModel, 'Account', MAccountFormattable>
 
-export type MChannelActorAccountDefaultVideos = MChannelActorAccountDefault & MChannelVideos
+export type MChannelAP = Pick<MChannel, 'name' | 'description' | 'support'> &
+  Use<'Actor', MActorAP> &
+  Use<'Account', MAccountUrl>