PeerTube/server/models/pod/pod-interface.ts

64 lines
2.1 KiB
TypeScript
Raw Normal View History

2017-05-22 13:58:25 -05:00
import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird'
2017-05-22 13:58:25 -05:00
2017-06-10 15:15:25 -05:00
// Don't use barrel, import just what we need
2017-08-25 04:45:31 -05:00
import { Pod as FormattedPod } from '../../../shared/models/pods/pod.model'
import { ResultList } from '../../../shared/models/result-list.model'
2017-06-10 15:15:25 -05:00
2017-05-22 13:58:25 -05:00
export namespace PodMethods {
2017-08-25 04:45:31 -05:00
export type ToFormattedJSON = (this: PodInstance) => FormattedPod
2017-05-22 13:58:25 -05:00
export type CountAll = () => Promise<number>
2017-06-10 15:15:25 -05:00
export type IncrementScores = (ids: number[], value: number) => Promise<[ number, PodInstance[] ]>
2017-06-10 15:15:25 -05:00
export type List = () => Promise<PodInstance[]>
2017-06-10 15:15:25 -05:00
export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<PodInstance> >
export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]>
2017-06-10 15:15:25 -05:00
export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string) => Promise<number[]>
2017-06-10 15:15:25 -05:00
export type ListBadPods = () => Promise<PodInstance[]>
2017-06-10 15:15:25 -05:00
export type Load = (id: number) => Promise<PodInstance>
2017-06-10 15:15:25 -05:00
export type LoadByHost = (host: string) => Promise<PodInstance>
2017-06-10 15:15:25 -05:00
export type RemoveAll = () => Promise<number>
2017-06-10 15:15:25 -05:00
export type UpdatePodsScore = (goodPods: number[], badPods: number[]) => void
2017-05-22 13:58:25 -05:00
}
export interface PodClass {
countAll: PodMethods.CountAll
incrementScores: PodMethods.IncrementScores
list: PodMethods.List
listForApi: PodMethods.ListForApi
2017-05-22 13:58:25 -05:00
listAllIds: PodMethods.ListAllIds
listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest
listBadPods: PodMethods.ListBadPods
load: PodMethods.Load
loadByHost: PodMethods.LoadByHost
removeAll: PodMethods.RemoveAll
updatePodsScore: PodMethods.UpdatePodsScore
}
export interface PodAttributes {
2017-08-25 11:36:49 -05:00
id?: number
2017-05-22 13:58:25 -05:00
host?: string
publicKey?: string
score?: number | Sequelize.literal // Sequelize literal for 'score +' + value
email?: string
}
export interface PodInstance extends PodClass, PodAttributes, Sequelize.Instance<PodAttributes> {
createdAt: Date
updatedAt: Date
2017-08-25 04:45:31 -05:00
toFormattedJSON: PodMethods.ToFormattedJSON,
2017-05-22 13:58:25 -05:00
}
export interface PodModel extends PodClass, Sequelize.Model<PodInstance, PodAttributes> {}