import { DeepPartial } from '../../utils/DeepPartial' ; import { deepMerge } from '../../utils/DeepMerge' ; import { NanoID , Dimension } from '../../Dimension' ; import { Match } from '../../Match' ; import { Plugin } from '..' ; import { nanoid } from '../..' ; import { Tournament } from '../../Tournament' ; import { TournamentStatus } from '../../Tournament/TournamentStatus' ; /**
 * The database plugin class, of which Dimensions uses internally to store data onto the database
 * Must be extended in order to be used as a database plugin
 */ export abstract class Database extends Plugin { constructor ( configs ) { super ( ) ; deepMerge ( this . configs , configs ) ; } /** Default configs */ public configs : Database . Configs = { saveMatches : true , saveTournamentMatches : true , } ; /**
     * Performs any intialization tasks
     * Resolves when done
     */ abstract async initialize ( dimension ) ; param match param governId - a form of identification. Indicates what created this match. This can be a dimension ID or tournament
     * ID, both of which are  nanoid *
     * Resolves when done
      abstract storeMatch ( match , governID ) ; param id abstract getMatch ( id ) ; param username param password abstract loginUser ( username , password ) ; param username param password param userData abstract registerUser ( username , password , userData ? ) ; /**
     * Authenticates a user by a JWT, resolves with the token data signed in the  loginUser function,
     * rejects otherwise
     *  param jwt abstract verifyToken ( jwt ) ; param usernameOrID abstract deleteUser ( usernameOrID ) ; param usernameOrID param update abstract updateUser ( usernameOrID , update ) ; param usernameOrID param publicView abstract getUser ( usernameOrID , publicView ? ) ; param tournamentKeyName param offset param limit abstract getUsersInTournament ( tournamentKeyName , offset , limit ) ; /**
     * Returns true if the user info indicate the user is an admin
     */ abstract isAdmin ( user ) ; param playerID param governID param offset param limit param order abstract getPlayerMatches ( playerID , governID , offset , limit , order ) ; param tournamentID abstract getTournamentConfigs ( tournamentID ) ; param tournamentID abstract getTournamentConfigsModificationDate ( tournamentID ) ; param tournamentID param tournamentConfigs param status abstract storeTournamentConfigs ( tournamentID , tournamentConfigs , status ) ; } export namespace Database { /**
     * Configuration interface for the  Database plugin
      export interface Configs { /** Whether or not to save matches into the database when we run  Dimension . runMatch saveMatches : boolean ; /** Whether or not to save matches into the database when the tournament runs a match */ saveTournamentMatches : boolean ; } /**
     * Public information retrievable about users
     */ export interface PublicUser { /** User's username */ username : string ; /** Related Statistics */ statistics ? : { [ x in string ] : any ; } ; /** Creation date of the user */ creationDate ? : Date ; /** A Player ID generated using  Player . generatePlayerID , returning a 12 char nanoid  playerID ? : NanoID ; /** any other user related meta data such as email, user statistics, etc. */ meta ? : { [ x in string ] : any ; } ; } /**
     * User interface for use by Database Plugins
     */ export interface User extends PublicUser { /** Hashed password */ passwordHash : string ; } }