Config as class

This commit is contained in:
Rory& 2025-10-03 19:17:55 +02:00
parent 2e365718ed
commit 1f3e5ac004

View File

@ -31,8 +31,8 @@ let pairs: ConfigEntity[];
// TODO: use events to inform about config updates // TODO: use events to inform about config updates
// Config keys are separated with _ // Config keys are separated with _
export const Config = { export class Config {
init: async function init() { public static async init() {
if (config) return config; if (config) return config;
console.log("[Config] Loading configuration..."); console.log("[Config] Loading configuration...");
if (!process.env.CONFIG_PATH) { if (!process.env.CONFIG_PATH) {
@ -55,8 +55,8 @@ export const Config = {
config = OrmUtils.mergeDeep({}, { ...new ConfigValue() }, config); config = OrmUtils.mergeDeep({}, { ...new ConfigValue() }, config);
return this.set(config); return this.set(config);
}, };
get: function get() { public static get() {
if (!config) { if (!config) {
// If we haven't initialised the config yet, return default config. // If we haven't initialised the config yet, return default config.
// Typeorm instantiates each entity once when initising database, // Typeorm instantiates each entity once when initising database,
@ -67,14 +67,14 @@ export const Config = {
} }
return config; return config;
}, };
set: function set(val: Partial<ConfigValue>) { public static set(val: Partial<ConfigValue>) {
if (!config || !val) return; if (!config || !val) return;
config = val.merge(config); config = OrmUtils.mergeDeep(config);
return applyConfig(config); return applyConfig(config);
}, };
}; }
// TODO: better types // TODO: better types
const generatePairs = (obj: object | null, key = ""): ConfigEntity[] => { const generatePairs = (obj: object | null, key = ""): ConfigEntity[] => {