actor.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { ActorModel } from '../../../models/activitypub/actor'
  2. import { FunctionProperties, PickWith, PickWithOpt } from '../../utils'
  3. import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account'
  4. import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server'
  5. import { MAvatar, MAvatarFormattable } from './avatar'
  6. import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video'
  7. type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M>
  8. // ############################################################################
  9. export type MActor = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'Avatar' | 'ActorFollowers' | 'Server'>
  10. // ############################################################################
  11. export type MActorUrl = Pick<MActor, 'url'>
  12. export type MActorId = Pick<MActor, 'id'>
  13. export type MActorUsername = Pick<MActor, 'preferredUsername'>
  14. export type MActorFollowersUrl = Pick<MActor, 'followersUrl'>
  15. export type MActorAudience = MActorUrl & MActorFollowersUrl
  16. export type MActorFollowerException = Pick<ActorModel, 'sharedInboxUrl' | 'inboxUrl'>
  17. export type MActorSignature = MActorAccountChannelId
  18. export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'>
  19. // ############################################################################
  20. // Some association attributes
  21. export type MActorHost = Use<'Server', MServerHost>
  22. export type MActorRedundancyAllowedOpt = PickWithOpt<ActorModel, 'Server', MServerRedundancyAllowed>
  23. export type MActorDefaultLight = MActorLight &
  24. Use<'Server', MServerHost> &
  25. Use<'Avatar', MAvatar>
  26. export type MActorAccountId = MActor &
  27. Use<'Account', MAccountId>
  28. export type MActorAccountIdActor = MActor &
  29. Use<'Account', MAccountIdActor>
  30. export type MActorChannelId = MActor &
  31. Use<'VideoChannel', MChannelId>
  32. export type MActorChannelIdActor = MActor &
  33. Use<'VideoChannel', MChannelIdActor>
  34. export type MActorAccountChannelId = MActorAccountId & MActorChannelId
  35. export type MActorAccountChannelIdActor = MActorAccountIdActor & MActorChannelIdActor
  36. // ############################################################################
  37. // Include raw account/channel/server
  38. export type MActorAccount = MActor &
  39. Use<'Account', MAccount>
  40. export type MActorChannel = MActor &
  41. Use<'VideoChannel', MChannel>
  42. export type MActorDefaultAccountChannel = MActorDefault & MActorAccount & MActorChannel
  43. export type MActorServer = MActor &
  44. Use<'Server', MServer>
  45. // ############################################################################
  46. // Complex actor associations
  47. export type MActorDefault = MActor &
  48. Use<'Server', MServer> &
  49. Use<'Avatar', MAvatar>
  50. // Actor with channel that is associated to an account and its actor
  51. // Actor -> VideoChannel -> Account -> Actor
  52. export type MActorChannelAccountActor = MActor &
  53. Use<'VideoChannel', MChannelAccountActor>
  54. export type MActorFull = MActor &
  55. Use<'Server', MServer> &
  56. Use<'Avatar', MAvatar> &
  57. Use<'Account', MAccount> &
  58. Use<'VideoChannel', MChannelAccountActor>
  59. // Same than ActorFull, but the account and the channel have their actor
  60. export type MActorFullActor = MActor &
  61. Use<'Server', MServer> &
  62. Use<'Avatar', MAvatar> &
  63. Use<'Account', MAccountDefault> &
  64. Use<'VideoChannel', MChannelAccountDefault>
  65. // ############################################################################
  66. // API
  67. export type MActorSummary = FunctionProperties<MActor> &
  68. Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> &
  69. Use<'Server', MServerHost> &
  70. Use<'Avatar', MAvatar>
  71. export type MActorSummaryBlocks = MActorSummary &
  72. Use<'Server', MServerHostBlocks>
  73. export type MActorAPI = Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' |
  74. 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'>
  75. // ############################################################################
  76. // Format for API or AP object
  77. export type MActorSummaryFormattable = FunctionProperties<MActor> &
  78. Pick<MActor, 'url' | 'preferredUsername'> &
  79. Use<'Server', MServerHost> &
  80. Use<'Avatar', MAvatarFormattable>
  81. export type MActorFormattable = MActorSummaryFormattable &
  82. Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt'> &
  83. Use<'Server', MServerHost & Partial<Pick<MServer, 'redundancyAllowed'>>>
  84. export type MActorAP = MActor &
  85. Use<'Avatar', MAvatar>