Export validators on Config class as static

This commit is contained in:
Cooldude2606 committed 2026-03-04 21:07:30 +00:00
1 parent 014b18caf8
commit 61232e3537
2 files changed
+35 -31

No files matched your search

+4
View File
@@ -8,6 +8,7 @@ import { basicType } from "../helpers";
import * as libSchema from "../schema"; import * as libSchema from "../schema";
import { StringEnum } from "../data/composites"; import { StringEnum } from "../data/composites";
import { safeOutputFile } from "../file_ops"; import { safeOutputFile } from "../file_ops";
import * as validators from "./validators";
const ConfigLocation = StringEnum(["controller", "host", "control"]); const ConfigLocation = StringEnum(["controller", "host", "control"]);
export type ConfigLocation = Static<typeof ConfigLocation>; export type ConfigLocation = Static<typeof ConfigLocation>;
@@ -203,6 +204,9 @@ export class Config<
declare static fieldDefinitions: ConfigDefs<any>; declare static fieldDefinitions: ConfigDefs<any>;
declare ["constructor"]: typeof Config; declare ["constructor"]: typeof Config;
/** A set of common validators and validator factories */
static validators = validators;
/** /**
* Handle migration between clusterio versions * Handle migration between clusterio versions
* *
+31 -31
View File
@@ -1,6 +1,6 @@
// Core definitions for the configuration system // Core definitions for the configuration system
import * as classes from "./classes"; import * as classes from "./classes";
import * as validate from "./validators"; import * as validators from "./validators";
import type { PluginNodeEnvInfo, PluginWebpackEnvInfo } from "../plugin"; import type { PluginNodeEnvInfo, PluginWebpackEnvInfo } from "../plugin";
import { Static } from "@sinclair/typebox"; import { Static } from "@sinclair/typebox";
import { isTargetVersion } from "../data/version"; import { isTargetVersion } from "../data/version";
@@ -75,21 +75,21 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
restartRequired: true, restartRequired: true,
type: "string", type: "string",
initialValue: "mods", initialValue: "mods",
extendedValidation: validate.filePath, extendedValidation: validators.filePath,
}, },
"controller.database_directory": { "controller.database_directory": {
title: "Database directory", title: "Database directory",
description: "Directory where item and configuration data is stored.", description: "Directory where item and configuration data is stored.",
type: "string", type: "string",
initialValue: "database", initialValue: "database",
extendedValidation: validate.filePath, extendedValidation: validators.filePath,
}, },
"controller.autosave_interval": { "controller.autosave_interval": {
title: "Autosave Interval", title: "Autosave Interval",
description: "Interval in seconds to autosave data in memory to disk.", description: "Interval in seconds to autosave data in memory to disk.",
type: "number", type: "number",
initialValue: 60, initialValue: 60,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
"controller.http_port": { "controller.http_port": {
title: "HTTP Port", title: "HTTP Port",
@@ -98,9 +98,9 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
type: "number", type: "number",
optional: true, optional: true,
initialValue: 8080, initialValue: 8080,
extendedValidation: validate.optional(validate.all( extendedValidation: validators.optional(validators.all(
validate.integer, validators.integer,
validate.greaterThanZero validators.greaterThanZero
)), )),
}, },
"controller.https_port": { "controller.https_port": {
@@ -109,9 +109,9 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
restartRequired: true, restartRequired: true,
type: "number", type: "number",
optional: true, optional: true,
extendedValidation: validate.optional(validate.all( extendedValidation: validators.optional(validators.all(
validate.integer, validators.integer,
validate.greaterThanZero validators.greaterThanZero
)), )),
}, },
"controller.bind_address": { "controller.bind_address": {
@@ -143,7 +143,7 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
restartRequired: true, restartRequired: true,
type: "string", type: "string",
optional: true, optional: true,
extendedValidation: validate.optional(validate.filePath), extendedValidation: validators.optional(validators.filePath),
}, },
"controller.tls_private_key": { "controller.tls_private_key": {
title: "TLS Private Key", title: "TLS Private Key",
@@ -151,7 +151,7 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
restartRequired: true, restartRequired: true,
type: "string", type: "string",
optional: true, optional: true,
extendedValidation: validate.optional(validate.filePath), extendedValidation: validators.optional(validators.filePath),
}, },
"controller.auth_secret": { "controller.auth_secret": {
access: ["controller"], access: ["controller"],
@@ -169,35 +169,35 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
description: "Interval heartbeats are sent out on WebSocket connections.", description: "Interval heartbeats are sent out on WebSocket connections.",
type: "number", type: "number",
initialValue: 15, initialValue: 15,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
"controller.session_timeout": { "controller.session_timeout": {
title: "Session Timeout", title: "Session Timeout",
description: "Time in seconds before giving up resuming a dropped WebSocket session.", description: "Time in seconds before giving up resuming a dropped WebSocket session.",
type: "number", type: "number",
initialValue: 60, initialValue: 60,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
"controller.metrics_timeout": { "controller.metrics_timeout": {
title: "Metrics Timeout", title: "Metrics Timeout",
description: "Timeout in seconds for metrics gathering from hosts.", description: "Timeout in seconds for metrics gathering from hosts.",
type: "number", type: "number",
initialValue: 8, initialValue: 8,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
"controller.system_metrics_interval": { "controller.system_metrics_interval": {
title: "System Metrics Interval", title: "System Metrics Interval",
description: "Interval in seconds to collect and update system metrics for the Web UI", description: "Interval in seconds to collect and update system metrics for the Web UI",
type: "number", type: "number",
initialValue: 10, initialValue: 10,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
"controller.proxy_stream_timeout": { "controller.proxy_stream_timeout": {
title: "Proxy Stream Timeout", title: "Proxy Stream Timeout",
description: "Timeout in seconds for proxy streams to start flowing.", description: "Timeout in seconds for proxy streams to start flowing.",
type: "number", type: "number",
initialValue: 15, initialValue: 15,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
"controller.factorio_username": { "controller.factorio_username": {
title: "Factorio Username", title: "Factorio Username",
@@ -243,14 +243,14 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
description: "Duration in minutes to cache mod portal API responses.", description: "Duration in minutes to cache mod portal API responses.",
type: "number", type: "number",
initialValue: 30, initialValue: 30,
extendedValidation: validate.greaterThanEqualZero, // Zero is allowed here to disable cache extendedValidation: validators.greaterThanEqualZero, // Zero is allowed here to disable cache
}, },
"controller.mod_portal_page_size": { "controller.mod_portal_page_size": {
title: "Mod Portal Page Size", title: "Mod Portal Page Size",
description: "Maximum number of results per page when querying the Factorio mod portal API.", description: "Maximum number of results per page when querying the Factorio mod portal API.",
type: "number", type: "number",
initialValue: 1000, initialValue: 1000,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
"controller.allow_remote_updates": { "controller.allow_remote_updates": {
description: "When true, allows a remote event to trigger a clusterio update via npm", description: "When true, allows a remote event to trigger a clusterio update via npm",
@@ -326,7 +326,7 @@ export class HostConfig extends classes.Config<HostConfigFields> {
description: "Path to directory to look for factorio installs", description: "Path to directory to look for factorio installs",
type: "string", type: "string",
initialValue: "factorio", initialValue: "factorio",
extendedValidation: validate.filePath, extendedValidation: validators.filePath,
}, },
"host.mods_directory": { "host.mods_directory": {
title: "Mods Directory", title: "Mods Directory",
@@ -334,14 +334,14 @@ export class HostConfig extends classes.Config<HostConfigFields> {
restartRequired: true, restartRequired: true,
type: "string", type: "string",
initialValue: "mods", initialValue: "mods",
extendedValidation: validate.filePath, extendedValidation: validators.filePath,
}, },
"host.instances_directory": { "host.instances_directory": {
description: "Path to directory to store instances in.", description: "Path to directory to store instances in.",
restartRequired: true, restartRequired: true,
type: "string", type: "string",
initialValue: "instances", initialValue: "instances",
extendedValidation: validate.filePath, extendedValidation: validators.filePath,
}, },
"host.controller_url": { "host.controller_url": {
description: "URL to connect to the controller at", description: "URL to connect to the controller at",
@@ -363,7 +363,7 @@ export class HostConfig extends classes.Config<HostConfigFields> {
restartRequired: true, restartRequired: true,
type: "string", type: "string",
optional: true, optional: true,
extendedValidation: validate.optional(validate.filePath), extendedValidation: validators.optional(validators.filePath),
}, },
"host.public_address": { "host.public_address": {
description: "Public facing address players should connect to in order to join instances on this host", description: "Public facing address players should connect to in order to join instances on this host",
@@ -404,7 +404,7 @@ export class HostConfig extends classes.Config<HostConfigFields> {
description: "Maximum delay to wait before attempting to reconnect WebSocket", description: "Maximum delay to wait before attempting to reconnect WebSocket",
type: "number", type: "number",
initialValue: 60, initialValue: 60,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
"host.allow_remote_updates": { "host.allow_remote_updates": {
description: "When true, allows a remote event to trigger a clusterio update via npm", description: "When true, allows a remote event to trigger a clusterio update via npm",
@@ -529,7 +529,7 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
restartRequired: true, restartRequired: true,
type: "string", type: "string",
optional: true, optional: true,
extendedValidation: validate.optional(validate.filePath), extendedValidation: validators.optional(validators.filePath),
}, },
"factorio.shutdown_timeout": { "factorio.shutdown_timeout": {
description: description:
@@ -537,14 +537,14 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
"the process. Set to 0 to disable.", "the process. Set to 0 to disable.",
type: "number", type: "number",
initialValue: 300, initialValue: 300,
extendedValidation: validate.greaterThanEqualZero, extendedValidation: validators.greaterThanEqualZero,
}, },
"factorio.game_port": { "factorio.game_port": {
description: "UDP port to run game on, uses a port in host.factorio_port_range if null", description: "UDP port to run game on, uses a port in host.factorio_port_range if null",
restartRequired: true, restartRequired: true,
type: "number", type: "number",
optional: true, optional: true,
extendedValidation: validate.optional(validate.greaterThanZero), extendedValidation: validators.optional(validators.greaterThanZero),
}, },
"factorio.host_assigned_game_port": { "factorio.host_assigned_game_port": {
access: ["host"], access: ["host"],
@@ -557,7 +557,7 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
restartRequired: true, restartRequired: true,
type: "number", type: "number",
optional: true, optional: true,
extendedValidation: validate.optional(validate.greaterThanZero), extendedValidation: validators.optional(validators.greaterThanZero),
}, },
"factorio.rcon_password": { "factorio.rcon_password": {
credential: ["host", "controller"], credential: ["host", "controller"],
@@ -670,7 +670,7 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
restartRequired: true, restartRequired: true,
type: "number", type: "number",
initialValue: 5, initialValue: 5,
extendedValidation: validate.greaterThanZero, extendedValidation: validators.greaterThanZero,
}, },
}; };
} }
@@ -705,14 +705,14 @@ export class ControlConfig extends classes.Config<ControlConfigFields> {
description: "Path to Certificate Authority to validate TLS connection to controller against.", description: "Path to Certificate Authority to validate TLS connection to controller against.",
type: "string", type: "string",
optional: true, optional: true,
extendedValidation: validate.optional(validate.filePath), extendedValidation: validators.optional(validators.filePath),
}, },
"control.max_reconnect_delay": { "control.max_reconnect_delay": {
title: "Max Reconnect Delay", title: "Max Reconnect Delay",
description: "Maximum delay to wait before attempting to reconnect WebSocket", description: "Maximum delay to wait before attempting to reconnect WebSocket",
type: "number", type: "number",
initialValue: 60, initialValue: 60,
extendedValidation: validate.greaterThanEqualZero, extendedValidation: validators.greaterThanEqualZero,
}, },
}; };
} }