Refactor config to JSON data class pattern

Refactor the Config and ConfigGroup classes to match the JSON data class
pattern with toJSON, toRemote and fromJSON methods replacing the load,
init, and serialize methods.  Since fromJSON requires extra information
the messages structures passes around the plain JSON representation of
the configs instead of serialising instances of the config classes
automatically.
This commit is contained in:
Hornwitser committed 2024-01-06 19:53:32 +01:00
1 parent 27af142a87
commit 001db4befe
24 files changed
+269 -334

No files matched your search

+10 -1
View File
@@ -1,4 +1,4 @@
import { Type } from "@sinclair/typebox";
import { Static, TSchema, Type } from "@sinclair/typebox";
export function StringEnum<T extends string[]>(values: [...T]) {
return Type.Unsafe<T[number]>({ type: "string", enum: values });
@@ -32,3 +32,12 @@ export function jsonPrimitive<T, U>(type: U) {
export const JsonBoolean = jsonPrimitive<boolean, "boolean">("boolean");
export const JsonNumber = jsonPrimitive<number, "number">("number");
export const JsonString = jsonPrimitive<string, "string">("string");
export function plainJson<T extends TSchema>(schema: T) {
return {
jsonSchema: schema,
fromJSON(json: Static<T>) {
return json;
},
};
}