b369766dc4d6b6ecd399715eded4163684c972c8
[oweals/peertube.git] / server / models / account / account-interface.ts
1 import * as Bluebird from 'bluebird'
2 import * as Sequelize from 'sequelize'
3 import { Account as FormattedAccount, ActivityPubActor } from '../../../shared'
4 import { ServerInstance } from '../server/server-interface'
5 import { VideoChannelInstance } from '../video/video-channel-interface'
6
7 export namespace AccountMethods {
8   export type LoadApplication = () => Bluebird<AccountInstance>
9
10   export type Load = (id: number) => Bluebird<AccountInstance>
11   export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance>
12   export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance>
13   export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>
14   export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>
15   export type ListByFollowersUrls = (followerUrls: string[], transaction: Sequelize.Transaction) => Bluebird<AccountInstance[]>
16
17   export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor
18   export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount
19   export type IsOwned = (this: AccountInstance) => boolean
20   export type GetFollowerSharedInboxUrls = (this: AccountInstance, t: Sequelize.Transaction) => Bluebird<string[]>
21   export type GetFollowingUrl = (this: AccountInstance) => string
22   export type GetFollowersUrl = (this: AccountInstance) => string
23   export type GetPublicKeyUrl = (this: AccountInstance) => string
24 }
25
26 export interface AccountClass {
27   loadApplication: AccountMethods.LoadApplication
28   load: AccountMethods.Load
29   loadByUUID: AccountMethods.LoadByUUID
30   loadByUrl: AccountMethods.LoadByUrl
31   loadLocalByName: AccountMethods.LoadLocalByName
32   loadByNameAndHost: AccountMethods.LoadByNameAndHost
33   listByFollowersUrls: AccountMethods.ListByFollowersUrls
34 }
35
36 export interface AccountAttributes {
37   name: string
38   url?: string
39   publicKey: string
40   privateKey: string
41   followersCount: number
42   followingCount: number
43   inboxUrl: string
44   outboxUrl: string
45   sharedInboxUrl: string
46   followersUrl: string
47   followingUrl: string
48
49   uuid?: string
50
51   serverId?: number
52   userId?: number
53   applicationId?: number
54 }
55
56 export interface AccountInstance extends AccountClass, AccountAttributes, Sequelize.Instance<AccountAttributes> {
57   isOwned: AccountMethods.IsOwned
58   toActivityPubObject: AccountMethods.ToActivityPubObject
59   toFormattedJSON: AccountMethods.ToFormattedJSON
60   getFollowerSharedInboxUrls: AccountMethods.GetFollowerSharedInboxUrls
61   getFollowingUrl: AccountMethods.GetFollowingUrl
62   getFollowersUrl: AccountMethods.GetFollowersUrl
63   getPublicKeyUrl: AccountMethods.GetPublicKeyUrl
64
65   id: number
66   createdAt: Date
67   updatedAt: Date
68
69   Server: ServerInstance
70   VideoChannels: VideoChannelInstance[]
71 }
72
73 export interface AccountModel extends AccountClass, Sequelize.Model<AccountInstance, AccountAttributes> {}