import { Value } from '@sinclair/typebox/value'; import { TObject } from "@sinclair/typebox"; export class AppConfig> { private appConfig: Partial = {}; public get(key: K, defaultValue?: unknown): unknown public get(key: K, defaultValue?: T[K]): T[K] | undefined { return this.appConfig[key] || defaultValue; } public set(key: K, value: T[K]): void { this.appConfig[key] = value; } public prepare(data?: Record, schema?: TObject): void { this.appConfig = (data || {}) as Partial; if (schema) { try { this.appConfig = Value.Cast(schema, data) as Partial; } catch (error) { console.error(`Error while parsing config schema: ${error.message}`); } } } public getConfig( defaultConfig?: Partial ): C { return { ...defaultConfig, ...this.appConfig } as C; } }