]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/pod/pod-interface.ts
Better typescript typing for a better world
[github/Chocobozzz/PeerTube.git] / server / models / pod / pod-interface.ts
1 import * as Sequelize from 'sequelize'
2 import * as Promise from 'bluebird'
3
4 // Don't use barrel, import just what we need
5 import { Pod as FormatedPod } from '../../../shared/models/pods/pod.model'
6
7 export namespace PodMethods {
8 export type ToFormatedJSON = (this: PodInstance) => FormatedPod
9
10 export type CountAll = () => Promise<number>
11
12 export type IncrementScores = (ids: number[], value: number) => Promise<[ number, PodInstance[] ]>
13
14 export type List = () => Promise<PodInstance[]>
15
16 export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]>
17
18 export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string) => Promise<number[]>
19
20 export type ListBadPods = () => Promise<PodInstance[]>
21
22 export type Load = (id: number) => Promise<PodInstance>
23
24 export type LoadByHost = (host: string) => Promise<PodInstance>
25
26 export type RemoveAll = () => Promise<number>
27
28 export type UpdatePodsScore = (goodPods: number[], badPods: number[]) => void
29 }
30
31 export interface PodClass {
32 countAll: PodMethods.CountAll
33 incrementScores: PodMethods.IncrementScores
34 list: PodMethods.List
35 listAllIds: PodMethods.ListAllIds
36 listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest
37 listBadPods: PodMethods.ListBadPods
38 load: PodMethods.Load
39 loadByHost: PodMethods.LoadByHost
40 removeAll: PodMethods.RemoveAll
41 updatePodsScore: PodMethods.UpdatePodsScore
42 }
43
44 export interface PodAttributes {
45 host?: string
46 publicKey?: string
47 score?: number | Sequelize.literal // Sequelize literal for 'score +' + value
48 email?: string
49 }
50
51 export interface PodInstance extends PodClass, PodAttributes, Sequelize.Instance<PodAttributes> {
52 id: number
53 createdAt: Date
54 updatedAt: Date
55
56 toFormatedJSON: PodMethods.ToFormatedJSON,
57 }
58
59 export interface PodModel extends PodClass, Sequelize.Model<PodInstance, PodAttributes> {}