MafiaDao
sockMafia DAO Provider
Author: Accalia
License: MIT
- MafiaDao
- ~MafiaDao
- new MafiaDao(connection)
- [.createGame(topicId, [name], [active])](#sockmafia.src.dao.module_MafiaDao..MafiaDao+createGame) ⇒
Promise.<MafiaGame>
- .getGame(game) ⇒
Promise.<MafiaGame>
- .getGameByTopicId(topicId) ⇒
Promise.<MafiaGame>
- .getGameByChatId(chatId) ⇒
Promise.<MafiaGame>
- .getGameByName(name) ⇒
Promise.<MafiaGame>
- .getGameByAlias(alias) ⇒
Promise.<MafiaGame>
- .load() ⇒
Promise.<Array>
- .save() ⇒
Promise
- .toJSON() ⇒
object
- ~readData(filename) ⇒
Promise.<Array>
- ~saveData(filename, data) ⇒
Promise
- ~MafiaDao
MafiaDao~MafiaDao
MafiaDao Class
Kind: inner class of MafiaDao
- ~MafiaDao
- new MafiaDao(connection)
- [.createGame(topicId, [name], [active])](#sockmafia.src.dao.module_MafiaDao..MafiaDao+createGame) ⇒
Promise.<MafiaGame>
- .getGame(game) ⇒
Promise.<MafiaGame>
- .getGameByTopicId(topicId) ⇒
Promise.<MafiaGame>
- .getGameByChatId(chatId) ⇒
Promise.<MafiaGame>
- .getGameByName(name) ⇒
Promise.<MafiaGame>
- .getGameByAlias(alias) ⇒
Promise.<MafiaGame>
- .load() ⇒
Promise.<Array>
- .save() ⇒
Promise
- .toJSON() ⇒
object
new MafiaDao(connection)
MafiaDao constructor. Creates a new MafiaDao instance
Param | Type | Description |
---|---|---|
connection | string |
File Path of the data store this dao will use |
mafiaDao.createGame(topicId, [name], [active]) ⇒ Promise.<MafiaGame>
Create a new MafiaGame and store it in this DAO
Kind: instance method of MafiaDao
Returns: Promise.<MafiaGame>
- Resolves to created game, rejects if preconditions or save state fails
Param | Type | Default | Description |
---|---|---|---|
topicId | number |
Game topic. Must be an integer | |
[name] | string |
Custom name for the game | |
[active] | boolean |
true |
Start the game in this active state |
mafiaDao.getGame(game) ⇒ Promise.<MafiaGame>
Retrieve a previously created game by topicId or name
Kind: instance method of MafiaDao
Returns: Promise.<MafiaGame>
- Resolves to requested game, rejects when read error occurs or game not found
Param | Type | Description |
---|---|---|
game | number | string |
Game identifier. |
mafiaDao.getGameByTopicId(topicId) ⇒ Promise.<MafiaGame>
Retrieve a previously created game by topicId
Kind: instance method of MafiaDao
Returns: Promise.<MafiaGame>
- Resolves to requested game, rejects when read error occurs or game not found
Param | Type | Description |
---|---|---|
topicId | number |
Game Topic identifier. Must be an integer |
mafiaDao.getGameByChatId(chatId) ⇒ Promise.<MafiaGame>
Retrieve a previously created game by chatId
Kind: instance method of MafiaDao
Returns: Promise.<MafiaGame>
- Resolves to requested game, rejects when read error occurs or game not found
Param | Type | Description |
---|---|---|
chatId | number |
Chat identifier. Must be an integer |
mafiaDao.getGameByName(name) ⇒ Promise.<MafiaGame>
Retrieve a previously created game by topicId
Kind: instance method of MafiaDao
Returns: Promise.<MafiaGame>
- Resolves to requested game, rejects when read error occurs or game not found
Param | Type | Description |
---|---|---|
name | string |
Custom game name |
mafiaDao.getGameByAlias(alias) ⇒ Promise.<MafiaGame>
Retrieve a previously created game by alias
Kind: instance method of MafiaDao
Returns: Promise.<MafiaGame>
- Resolves to requested game, rejects when read error occurs or game not found
Param | Type | Description |
---|---|---|
alias | string |
Custom game alias |
mafiaDao.load() ⇒ Promise.<Array>
Load data from disk, once.
Cache read results to remove need to fetch from disk multiple times
Kind: instance method of MafiaDao
Returns: Promise.<Array>
- Resolves to read data, rejects on read error
mafiaDao.save() ⇒ Promise
Save DAO Data to disk
Kind: instance method of MafiaDao
Returns: Promise
- Resolves when data has been written to disk, rejects wehn write error occurs
mafiaDao.toJSON() ⇒ object
Create a serializeable representation of the DAO object.
Kind: instance method of MafiaDao
Returns: object
- A serializeable clone of this dao's internal data store.
MafiaDao~readData(filename) ⇒ Promise.<Array>
Read a serialized mafia configuration from disk and resolve to deserialized contents
Assumes an ENOENT error on read is okay and resolves to the empty array in this case.
Kind: inner method of MafiaDao
Returns: Promise.<Array>
- Resolves to the deserialized mafia configurations. Rejects on read or parse error.
Param | Type | Description |
---|---|---|
filename | string |
Filename to read |
MafiaDao~saveData(filename, data) ⇒ Promise
Save serialized data to disk
Kind: inner method of MafiaDao
Returns: Promise
- Resolves when data has been written, rejects on serialization or file access error
Param | Type | Description |
---|---|---|
filename | string |
Filename to write |
data | * |
Data to serialize and write |