import { Game , GameId , GameOptions , Score } from '../Game' ; import { SerializedGame } from '../SerializedGame' ; export interface IGameData { gameId : GameId ; playerCount : number ; } /**
 * A game store. Load, save, you know the drill.
 *
 * Each game has a unique ID represented belowe as `game_id`. As games proceed,
 * the game is saved at later states. Inidividual saves of a game's state have a
 * unique and growing `save_id`. A game's initial _save point_ is always 0.
 *
 * This API has an asynchronous callback mechanism, so do not expect something
 * like this to work:
 *
 * ```
 * let count = 0;
 * database.getGames((err, allGames) => {
 *  count++;
 * });
 * expect(count).eq(1);
 * ```
 * More at https://blog.risingstack.com/node-hero-async-programming-in-node-js/
 *
 * Every method's success or failure is derived by the callback. Each callback
 * has an `err` parameter, which, when `undefined`, implies success. An `err`
 * with a defined value represents failure.
 *
 * If a method doesn't have a callback, it's assumed to succeed.
 *
 * Game state is stored as a single JSON string, which is why the `game` parameter is
 * often JSON.
 *
 * Finally, `players` as a number merely represents the number of players
 * in the game. Why, I have no idea, says kberg.
 */ export type DbLoadCallback < T > = ( err : Error | undefined , game : T | undefined ) => void ; export interface IDatabase { /**
     * Creates any tables needed
     */ initialize ( ) : Promise < void > ; param game_id param cb getGame ( game_id , cb ) : void ; param playerId param cb getGameId ( playerId , cb ) : void ; /**
     * Load a game at a specific save point.
     */ getGameVersion ( game_id , save_id , cb ) : void ; param cb param cb getGames ( cb ) : void ; /**
     * Load references to all games that can be cloned. Every game is cloneable,
     * this just returns the original save of the game. However, if a game's
     * original save is pruned, say, due to  deleteGameNbrSaves , it won't
     * appear in this list.
     *
     * Cloneable games are those with a save_id 0.
     *
     *  param cb getClonableGames ( cb ) : void ; /**
     * Saves the current state of the game. at a supplied save point. Used for
     * interim game updates.
     */ saveGame ( game ) : Promise < void > ; /**
     * Stores the results of a game in perpetuity in a separate table from normal
     * games. Called at a game's conclusion along with  cleanSaves .
     *
     * This is not impliemented in  SQLite .
     *
     *  param generations param gameOptions param scores saveGameResults ( game_id , players , generations , gameOptions , scores ) : void ; /**
     * The meat behind player undo. Loads the game at the given save point,
     * and provides it in the callback.
     */ restoreGame ( game_id , save_id , cb ) : void ; /**
     * Load a game at save point 0, and provide it in the callback.
     */ loadCloneableGame ( game_id , cb ) : void ; /**
     * Deletes the last `rollbackCount` saves of the specified game.
     *
     * Accessible by the administrative API to roll back a broken game.
     */ deleteGameNbrSaves ( game_id , rollbackCount ) : void ; /**
     * A maintenance task on a single game to close it out upon its completion.
     * It will:
     *
     * * Purge all saves between `(0, save_id]`.
     * * Mark the game as finished.
     * * It also participates in purging abandoned solo games older
     *   than a given date range, regardless of the supplied `game_id`.
     *   Constraints for this purge vary by database.
     */ cleanSaves ( game_id , save_id ) : void ; /**
     * A maintenance task that purges abandoned solo games older
     * than a given date range.
     *
     * This is currently also part of cleanSaves().
     *
     * Behavior when the environment variable is absent is system-dependent:
     * * In PostgreSQL, it uses a default of 10 days
     * * In Sqlite, it doesn't purge
     * * This whole method is ignored in LocalFilesystem.
     */ purgeUnfinishedGames ( ) : void ; }