refactor(core): Validate all string union config fields (#14527)

This commit is contained in:
Iván Ovejero
2025-04-11 13:58:07 +02:00
committed by GitHub
parent be627f08a4
commit 9397320af9
13 changed files with 88 additions and 33 deletions

View File

@@ -1,5 +1,10 @@
import { z } from 'zod';
import { Config, Env, Nested } from '../decorators';
const dbLoggingOptionsSchema = z.enum(['query', 'error', 'schema', 'warn', 'info', 'log', 'all']);
type DbLoggingOptions = z.infer<typeof dbLoggingOptionsSchema>;
@Config
class LoggingConfig {
/** Whether database logging is enabled. */
@@ -9,8 +14,8 @@ class LoggingConfig {
/**
* Database logging level. Requires `DB_LOGGING_MAX_EXECUTION_TIME` to be higher than `0`.
*/
@Env('DB_LOGGING_OPTIONS')
options: 'query' | 'error' | 'schema' | 'warn' | 'info' | 'log' | 'all' = 'error';
@Env('DB_LOGGING_OPTIONS', dbLoggingOptionsSchema)
options: DbLoggingOptions = 'error';
/**
* Only queries that exceed this time (ms) will be logged. Set `0` to disable.
@@ -131,11 +136,14 @@ export class SqliteConfig {
executeVacuumOnStartup: boolean = false;
}
const dbTypeSchema = z.enum(['sqlite', 'mariadb', 'mysqldb', 'postgresdb']);
type DbType = z.infer<typeof dbTypeSchema>;
@Config
export class DatabaseConfig {
/** Type of database to use */
@Env('DB_TYPE')
type: 'sqlite' | 'mariadb' | 'mysqldb' | 'postgresdb' = 'sqlite';
@Env('DB_TYPE', dbTypeSchema)
type: DbType = 'sqlite';
/** Prefix for table names */
@Env('DB_TABLE_PREFIX')