mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-20 07:23:13 +09:00
Let the framework own sets and lists instead of the features
Feature.to_set made every feature turn its config lists into sets on
each lookup, which is work the framework should do once. Sets are now a
field type of their own. Feature.set{...} declares one, the controller
sends a list, and _apply converts it when the override is applied, on
load and on update alike. Features index the config directly, and
to_set and its cache are gone.
Lists are explicit too. Feature.list{...} declares one, where before
any table of strings, and any empty table, counted as a list. Untagged
tables with string keys are nested sections, and other tables can not
be overridden. Feature.optional uses the same marker as list and set.
On the web side a string list can no longer name an input component,
so the cast that made one look like an object field is gone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
628e4df514
commit
f8ca285ff6
9 files changed
+128
-90
No files matched your search
@@ -17,16 +17,20 @@ export type FeatureField = {
|
||||
name: string,
|
||||
title: string,
|
||||
description: string,
|
||||
} & (
|
||||
| ScalarField<{ type: "boolean", default: boolean }>
|
||||
| ScalarField<{ type: "number", default: number | null, min?: number, unit?: string }>
|
||||
| ScalarField<{ type: "string", default: string | null, enum?: string[] }>
|
||||
/** Feature.list or Feature.set on the lua side, both are sent as a list */
|
||||
| { type: "string_list", default: string[] }
|
||||
);
|
||||
|
||||
type ScalarField<T> = T & {
|
||||
/** Allows null, the lua side uses Feature.optional */
|
||||
optional?: boolean,
|
||||
/** Name of an input component registered with the web interface, such as "role" */
|
||||
inputComponent?: string,
|
||||
} & (
|
||||
| { type: "boolean", default: boolean }
|
||||
| { type: "number", default: number | null, min?: number, unit?: string }
|
||||
| { type: "string", default: string | null, enum?: string[] }
|
||||
| { type: "string_list", default: string[] }
|
||||
);
|
||||
};
|
||||
|
||||
export type Feature = {
|
||||
name: string,
|
||||
@@ -238,7 +242,7 @@ export function validateFeatureValues(name: string, values: Record<string, Featu
|
||||
|
||||
function checkFieldValue(field: FeatureField, value: FeatureValue, label: string) {
|
||||
if (value === null) {
|
||||
if (!field.optional) {
|
||||
if (field.type === "string_list" || !field.optional) {
|
||||
throw new Error(`${label} can not be null`);
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user