mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
33 lines
996 B
TypeScript
33 lines
996 B
TypeScript
/**
|
|
* @file index.ts
|
|
* @summary ConfigManager system to retrieve and modify system configuration
|
|
* @description Can read from a hand-written file, config.toml, or from a machine-saved file, config.internal.toml
|
|
* Fuses both and provides a way to retrieve individual values
|
|
*/
|
|
|
|
import { loadConfig, watchConfig } from "c12";
|
|
import { fromZodError } from "zod-validation-error";
|
|
import { type Config, configValidator } from "./config.type";
|
|
export type { Config } from "./config.type";
|
|
|
|
const { config } = await watchConfig({
|
|
configFile: "./config/config.toml",
|
|
overrides:
|
|
(
|
|
await loadConfig<Config>({
|
|
configFile: "./config/config.internal.toml",
|
|
})
|
|
).config ?? undefined,
|
|
});
|
|
|
|
const parsed = await configValidator.safeParseAsync(config);
|
|
|
|
if (!parsed.success) {
|
|
console.error("Invalid config file:");
|
|
throw fromZodError(parsed.error).message;
|
|
}
|
|
|
|
const exportedConfig = parsed.data;
|
|
|
|
export { exportedConfig as config };
|