PeerTube/server/types/models/video/video-channels.ts

149 lines
3.7 KiB
TypeScript
Raw Normal View History

import { FunctionProperties, PickWith, PickWithOpt } from '@shared/typescript-utils'
2019-08-15 11:53:26 +02:00
import { VideoChannelModel } from '../../../models/video/video-channel'
import {
MAccountActor,
MAccountAPI,
MAccountDefault,
2019-08-20 19:05:31 +02:00
MAccountFormattable,
2019-08-15 11:53:26 +02:00
MAccountLight,
2019-08-20 13:52:49 +02:00
MAccountSummaryBlocks,
2019-08-20 19:05:31 +02:00
MAccountSummaryFormattable,
2019-08-21 14:31:57 +02:00
MAccountUrl,
2021-05-11 11:15:29 +02:00
MAccountUserId
} from '../account'
import {
2019-08-15 11:53:26 +02:00
MActor,
MActorAccountChannelId,
2021-04-06 17:01:35 +02:00
MActorAPChannel,
2019-08-15 11:53:26 +02:00
MActorAPI,
MActorDefault,
2021-04-06 17:01:35 +02:00
MActorDefaultBanner,
2019-08-20 13:52:49 +02:00
MActorDefaultLight,
2019-08-20 19:05:31 +02:00
MActorFormattable,
MActorHost,
2019-08-20 13:52:49 +02:00
MActorLight,
2019-08-20 19:05:31 +02:00
MActorSummary,
2021-04-06 17:01:35 +02:00
MActorSummaryFormattable,
MActorUrl
2021-05-11 11:15:29 +02:00
} from '../actor'
2019-08-15 11:53:26 +02:00
import { MVideo } from './video'
2019-08-20 13:52:49 +02:00
type Use<K extends keyof VideoChannelModel, M> = PickWith<VideoChannelModel, K, M>
// ############################################################################
2019-08-15 11:53:26 +02:00
export type MChannel = Omit<VideoChannelModel, 'Actor' | 'Account' | 'Videos' | 'VideoPlaylists'>
2019-08-20 13:52:49 +02:00
// ############################################################################
export type MChannelId = Pick<MChannel, 'id'>
// ############################################################################
2020-01-31 16:56:52 +01:00
export type MChannelIdActor =
MChannelId &
2019-08-20 13:52:49 +02:00
Use<'Actor', MActorAccountChannelId>
2020-01-31 16:56:52 +01:00
export type MChannelUserId =
Pick<MChannel, 'accountId'> &
2019-08-20 13:52:49 +02:00
Use<'Account', MAccountUserId>
2020-01-31 16:56:52 +01:00
export type MChannelActor =
MChannel &
2019-08-20 13:52:49 +02:00
Use<'Actor', MActor>
2019-08-15 11:53:26 +02:00
2019-08-21 14:31:57 +02:00
export type MChannelUrl = Use<'Actor', MActorUrl>
2019-08-15 11:53:26 +02:00
// Default scope
2020-01-31 16:56:52 +01:00
export type MChannelDefault =
MChannel &
2019-08-20 13:52:49 +02:00
Use<'Actor', MActorDefault>
2021-04-06 17:01:35 +02:00
export type MChannelBannerDefault =
MChannel &
Use<'Actor', MActorDefaultBanner>
2019-08-20 13:52:49 +02:00
// ############################################################################
// Not all association attributes
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MChannelActorLight =
MChannel &
2019-08-20 13:52:49 +02:00
Use<'Actor', MActorLight>
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MChannelAccountLight =
MChannel &
2019-08-20 13:52:49 +02:00
Use<'Actor', MActorDefaultLight> &
Use<'Account', MAccountLight>
2019-08-15 11:53:26 +02:00
export type MChannelHost =
MChannelId &
Use<'Actor', MActorHost>
2019-08-20 13:52:49 +02:00
// ############################################################################
2019-08-15 11:53:26 +02:00
2019-08-20 13:52:49 +02:00
// Account associations
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MChannelAccountActor =
MChannel &
2019-08-20 13:52:49 +02:00
Use<'Account', MAccountActor>
2021-04-06 17:01:35 +02:00
export type MChannelBannerAccountDefault =
2020-01-31 16:56:52 +01:00
MChannel &
2021-04-06 17:01:35 +02:00
Use<'Actor', MActorDefaultBanner> &
2019-08-20 13:52:49 +02:00
Use<'Account', MAccountDefault>
2019-08-15 11:53:26 +02:00
2021-04-06 17:01:35 +02:00
export type MChannelAccountDefault =
2020-01-31 16:56:52 +01:00
MChannel &
2021-04-06 17:01:35 +02:00
Use<'Actor', MActorDefault> &
Use<'Account', MAccountDefault>
2019-08-20 13:52:49 +02:00
// ############################################################################
2021-04-06 17:01:35 +02:00
// Videos associations
2020-01-31 16:56:52 +01:00
export type MChannelVideos =
MChannel &
2019-08-20 13:52:49 +02:00
Use<'Videos', MVideo[]>
2019-08-15 11:53:26 +02:00
2019-08-20 13:52:49 +02:00
// ############################################################################
// For API
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MChannelSummary =
FunctionProperties<MChannel> &
2019-08-20 19:05:31 +02:00
Pick<MChannel, 'id' | 'name' | 'description' | 'actorId'> &
2019-08-20 13:52:49 +02:00
Use<'Actor', MActorSummary>
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MChannelSummaryAccount =
MChannelSummary &
2019-08-20 13:52:49 +02:00
Use<'Account', MAccountSummaryBlocks>
2019-08-15 11:53:26 +02:00
2020-01-31 16:56:52 +01:00
export type MChannelAPI =
MChannel &
2019-08-20 13:52:49 +02:00
Use<'Actor', MActorAPI> &
Use<'Account', MAccountAPI>
2019-08-20 19:05:31 +02:00
// ############################################################################
// Format for API or AP object
2020-01-31 16:56:52 +01:00
export type MChannelSummaryFormattable =
FunctionProperties<MChannel> &
2019-08-20 19:05:31 +02:00
Pick<MChannel, 'id' | 'name'> &
Use<'Actor', MActorSummaryFormattable>
2020-01-31 16:56:52 +01:00
export type MChannelAccountSummaryFormattable =
MChannelSummaryFormattable &
2019-08-20 19:05:31 +02:00
Use<'Account', MAccountSummaryFormattable>
2020-01-31 16:56:52 +01:00
export type MChannelFormattable =
FunctionProperties<MChannel> &
2019-08-20 19:05:31 +02:00
Pick<MChannel, 'id' | 'name' | 'description' | 'createdAt' | 'updatedAt' | 'support'> &
Use<'Actor', MActorFormattable> &
PickWithOpt<VideoChannelModel, 'Account', MAccountFormattable>
2019-08-21 14:31:57 +02:00
2020-01-31 16:56:52 +01:00
export type MChannelAP =
Pick<MChannel, 'name' | 'description' | 'support'> &
2021-04-06 17:01:35 +02:00
Use<'Actor', MActorAPChannel> &
2019-08-21 14:31:57 +02:00
Use<'Account', MAccountUrl>