account.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { AccountModel } from '../../../models/account/account'
  2. import {
  3. MActor,
  4. MActorAP,
  5. MActorAPI,
  6. MActorAudience,
  7. MActorDefault,
  8. MActorDefaultLight,
  9. MActorFormattable,
  10. MActorId,
  11. MActorServer,
  12. MActorSummary,
  13. MActorSummaryFormattable,
  14. MActorUrl
  15. } from './actor'
  16. import { FunctionProperties, PickWith } from '../../utils'
  17. import { MAccountBlocklistId } from './account-blocklist'
  18. import { MChannelDefault } from '../video/video-channels'
  19. type Use<K extends keyof AccountModel, M> = PickWith<AccountModel, K, M>
  20. // ############################################################################
  21. export type MAccount = Omit<AccountModel, 'Actor' | 'User' | 'Application' | 'VideoChannels' | 'VideoPlaylists' |
  22. 'VideoComments' | 'BlockedAccounts'>
  23. // ############################################################################
  24. // Only some attributes
  25. export type MAccountId = Pick<MAccount, 'id'>
  26. export type MAccountUserId = Pick<MAccount, 'userId'>
  27. // Only some Actor attributes
  28. export type MAccountUrl = Use<'Actor', MActorUrl>
  29. export type MAccountAudience = Use<'Actor', MActorAudience>
  30. export type MAccountIdActor = MAccountId &
  31. Use<'Actor', MActor>
  32. export type MAccountIdActorId = MAccountId &
  33. Use<'Actor', MActorId>
  34. // ############################################################################
  35. // Default scope
  36. export type MAccountDefault = MAccount &
  37. Use<'Actor', MActorDefault>
  38. // Default with default association scopes
  39. export type MAccountDefaultChannelDefault = MAccount &
  40. Use<'Actor', MActorDefault> &
  41. Use<'VideoChannels', MChannelDefault[]>
  42. // We don't need some actors attributes
  43. export type MAccountLight = MAccount &
  44. Use<'Actor', MActorDefaultLight>
  45. // ############################################################################
  46. // Full actor
  47. export type MAccountActor = MAccount &
  48. Use<'Actor', MActor>
  49. // Full actor with server
  50. export type MAccountServer = MAccount &
  51. Use<'Actor', MActorServer>
  52. // ############################################################################
  53. // For API
  54. export type MAccountSummary = FunctionProperties<MAccount> &
  55. Pick<MAccount, 'id' | 'name'> &
  56. Use<'Actor', MActorSummary>
  57. export type MAccountSummaryBlocks = MAccountSummary &
  58. Use<'BlockedAccounts', MAccountBlocklistId[]>
  59. export type MAccountAPI = MAccount &
  60. Use<'Actor', MActorAPI>
  61. // ############################################################################
  62. // Format for API or AP object
  63. export type MAccountSummaryFormattable = FunctionProperties<MAccount> &
  64. Pick<MAccount, 'id' | 'name'> &
  65. Use<'Actor', MActorSummaryFormattable>
  66. export type MAccountFormattable = FunctionProperties<MAccount> &
  67. Pick<MAccount, 'id' | 'name' | 'description' | 'createdAt' | 'updatedAt' | 'userId'> &
  68. Use<'Actor', MActorFormattable>
  69. export type MAccountAP = Pick<MAccount, 'name' | 'description'> &
  70. Use<'Actor', MActorAP>