diff --git a/module/hooks/ready.mjs b/module/hooks/ready.mjs index 38980e5..1d5e7c8 100644 --- a/module/hooks/ready.mjs +++ b/module/hooks/ready.mjs @@ -1,12 +1,23 @@ import { Database } from "../utils/databases/Database.mjs"; import { Logger } from "../utils/Logger.mjs"; +import { NilDatabase } from "../utils/databases/NilDatabase.mjs"; Hooks.on(`ready`, () => { Logger.log(`Version: ${__VERSION__}`); // Alert GMs when the configured DB is invalid if (!(CONFIG.stats.db.prototype instanceof Database) && game.user.isGM) { - ui.notifications.error(`The database handler does not conform to the required heirarchy, the stats tracker module will almost certainly not work correctly.`, { permanent: true }); + ui.notifications.error(`The database adapter does not conform to the required specification, the stats tracker module overrode the configured database adapter with a stub to protect data that exists already.`, { permanent: true }); + CONFIG.stats.db = NilDatabase; }; + + /* + Prevent any run-time modifications to the CONFIG API so that users can't wreck + themselves nor their data by fooling around with the values. + */ + if (import.meta.env.PROD) { + Object.freeze(CONFIG.stats); + }; + CONFIG.stats.db.registerListeners(); }); diff --git a/module/utils/databases/NilDatabase.mjs b/module/utils/databases/NilDatabase.mjs new file mode 100644 index 0000000..0a76981 --- /dev/null +++ b/module/utils/databases/NilDatabase.mjs @@ -0,0 +1,34 @@ +import { Database } from "./Database.mjs"; + +/** + * This database implemention is not recommended for any actual usage, + * it is intended for overriding the current database implementation + * when a non-conforming Database is provided as the CONFIG.stats.db + * value in order to maintain the API interface for dependant modules + * and systems. + */ +export class NilDatabase extends Database { + // MARK: Table Ops + static async createTable() {}; + static async getTables() {}; + static async getTable() {}; + static async updateTable() {}; + static async deleteTable() {}; + + // MARK: Row Ops + static async createRow() {}; + static async createRows() {}; + static async getRows() {}; + static async updateRow() {}; + static async deleteRow() {}; + + // MARK: Applications + static addApp() {}; + static removeApp() {}; + static async render() {}; + + // MARK: Listeners + static async registerListeners() {}; + static async triggerListeners() {}; + static async unregisterListeners() {}; +};