mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
Some fixes to config setting
This commit is contained in:
6 files changed
+28
-19
No files matched your search
@@ -9,7 +9,6 @@ import * as libSchema from "../schema";
|
||||
import { StringEnum } from "../data/composites";
|
||||
import { safeOutputFile } from "../file_ops";
|
||||
import * as validators from "./validators";
|
||||
import { string } from "yargs";
|
||||
|
||||
const ConfigLocation = StringEnum(["controller", "host", "control"]);
|
||||
export type ConfigLocation = Static<typeof ConfigLocation>;
|
||||
@@ -208,7 +207,7 @@ export class Config<
|
||||
* Note that mutating this object will lead to unexpected behaviour.
|
||||
*/
|
||||
declare static fieldDefinitions: ConfigDefs<any>;
|
||||
declare ["constructor"]: typeof Config;
|
||||
declare ["constructor"]: typeof Config<Fields>;
|
||||
|
||||
/** A set of common validators and validator factories */
|
||||
static validators = validators;
|
||||
@@ -272,14 +271,14 @@ export class Config<
|
||||
}
|
||||
|
||||
/** A staging version of the config with changes tracked, invalided by revertStaging */
|
||||
private _staging?: { config: Config<Fields>, changes: Set<keyof Fields & string> };
|
||||
private _staging?: { config: Config<Fields>, changes: Set<string>};
|
||||
|
||||
/** Get the latest version of staging */
|
||||
get staging(): Config<Fields> {
|
||||
if (this._staging) { return this._staging.config; }
|
||||
const config = new this.constructor(this.location, this.fields) as this;
|
||||
const changes = new Set<keyof Fields & string>();
|
||||
config.on("fieldChanged", name => changes.add(name as keyof Fields & string));
|
||||
const config = new this.constructor(this.location, this.fields);
|
||||
const changes = new Set<string>();
|
||||
config.on("fieldChanged", name => changes.add(name));
|
||||
this._staging = { config, changes };
|
||||
return config;
|
||||
}
|
||||
@@ -832,7 +831,8 @@ export class Config<
|
||||
|
||||
// Validation success, set all values which have changed
|
||||
for (const fieldName of staging.changes) {
|
||||
this._set(fieldName, config.fields[fieldName]);
|
||||
const field = fieldName as keyof Fields & string;
|
||||
this._set(field, config.fields[field]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ export class ControllerConfigSetRequest {
|
||||
static permission = "core.controller.update_config" as const;
|
||||
|
||||
constructor(
|
||||
public fields: Record<string, string | Record<string, string>>,
|
||||
public fields: Record<string, string | Record<string, unknown>>,
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"fields": Type.Record(Type.String(), Type.Union([
|
||||
Type.String(), Type.Record(Type.String(), Type.String()),
|
||||
Type.String(), Type.Record(Type.String(), Type.Unknown()),
|
||||
])),
|
||||
});
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ export class HostConfigSetRequest {
|
||||
static permission = "core.host.update_config" as const;
|
||||
|
||||
constructor(
|
||||
public fields: Record<string, string | Record<string, string>>,
|
||||
public fields: Record<string, string | Record<string, unknown>>,
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"fields": Type.Record(Type.String(), Type.Union([
|
||||
Type.String(), Type.Record(Type.String(), Type.String()),
|
||||
Type.String(), Type.Record(Type.String(), Type.Unknown()),
|
||||
])),
|
||||
});
|
||||
|
||||
|
||||
@@ -111,13 +111,13 @@ export class InstanceConfigSetRequest {
|
||||
|
||||
constructor(
|
||||
public instanceId: number,
|
||||
public fields: Record<string, string | Record<string, string>>,
|
||||
public fields: Record<string, string | Record<string, unknown>>,
|
||||
) { }
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"instanceId": Type.Integer(),
|
||||
"fields": Type.Record(Type.String(), Type.Union([
|
||||
Type.String(), Type.Record(Type.String(), Type.String()),
|
||||
Type.String(), Type.Record(Type.String(), Type.Unknown()),
|
||||
])),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user