Hard-override any configured database handler that is erroneous and freeze the config after ready.

This commit is contained in:
Oliver-Akins 2025-05-27 23:34:27 -06:00
parent a354629839
commit 47deb24d67
2 changed files with 46 additions and 1 deletions

View file

@ -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();
});

View file

@ -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() {};
};