feat: Add in the immutable in the types

This commit is contained in:
BluJ
2023-05-02 16:12:13 -06:00
parent 25400610a9
commit bda5fc59a2
2 changed files with 63 additions and 0 deletions

View File

@@ -103,6 +103,9 @@ export class Value<Type, WD> {
description?: string | null description?: string | null
warning?: string | null warning?: string | null
default?: boolean | null default?: boolean | null
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}) { }) {
return new Value<boolean, WD>( return new Value<boolean, WD>(
async () => ({ async () => ({
@@ -111,6 +114,7 @@ export class Value<Type, WD> {
default: null, default: null,
type: "toggle" as const, type: "toggle" as const,
disabled: false, disabled: false,
immutable: a.immutable ?? false,
...a, ...a,
}), }),
boolean, boolean,
@@ -135,6 +139,7 @@ export class Value<Type, WD> {
default: null, default: null,
type: "toggle" as const, type: "toggle" as const,
disabled: false, disabled: false,
immutable: false,
...(await a(options)), ...(await a(options)),
}), }),
boolean, boolean,
@@ -154,6 +159,9 @@ export class Value<Type, WD> {
patterns?: Pattern[] patterns?: Pattern[]
/** Default = 'text' */ /** Default = 'text' */
inputmode?: ValueSpecText["inputmode"] inputmode?: ValueSpecText["inputmode"]
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}) { }) {
return new Value<AsRequired<string, Required>, WD>( return new Value<AsRequired<string, Required>, WD>(
async () => ({ async () => ({
@@ -167,6 +175,7 @@ export class Value<Type, WD> {
patterns: [], patterns: [],
inputmode: "text", inputmode: "text",
disabled: false, disabled: false,
immutable: a.immutable ?? false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
}), }),
@@ -206,6 +215,7 @@ export class Value<Type, WD> {
patterns: [], patterns: [],
inputmode: "text", inputmode: "text",
disabled: false, disabled: false,
immutable: false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
} }
@@ -219,6 +229,9 @@ export class Value<Type, WD> {
minLength?: number | null minLength?: number | null
maxLength?: number | null maxLength?: number | null
placeholder?: string | null placeholder?: string | null
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}) { }) {
return new Value<string, WD>( return new Value<string, WD>(
async () => async () =>
@@ -230,6 +243,7 @@ export class Value<Type, WD> {
placeholder: null, placeholder: null,
type: "textarea" as const, type: "textarea" as const,
disabled: false, disabled: false,
immutable: a.immutable ?? false,
...a, ...a,
} satisfies ValueSpecTextarea), } satisfies ValueSpecTextarea),
string, string,
@@ -260,6 +274,7 @@ export class Value<Type, WD> {
placeholder: null, placeholder: null,
type: "textarea" as const, type: "textarea" as const,
disabled: false, disabled: false,
immutable: false,
...a, ...a,
} }
}, string) }, string)
@@ -276,6 +291,9 @@ export class Value<Type, WD> {
integer: boolean integer: boolean
units?: string | null units?: string | null
placeholder?: string | null placeholder?: string | null
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}) { }) {
return new Value<AsRequired<number, Required>, WD>( return new Value<AsRequired<number, Required>, WD>(
() => ({ () => ({
@@ -288,6 +306,7 @@ export class Value<Type, WD> {
units: null, units: null,
placeholder: null, placeholder: null,
disabled: false, disabled: false,
immutable: a.immutable ?? false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
}), }),
@@ -325,6 +344,7 @@ export class Value<Type, WD> {
units: null, units: null,
placeholder: null, placeholder: null,
disabled: false, disabled: false,
immutable: false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
} }
@@ -335,6 +355,9 @@ export class Value<Type, WD> {
description?: string | null description?: string | null
warning?: string | null warning?: string | null
required: Required required: Required
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}) { }) {
return new Value<AsRequired<string, Required>, WD>( return new Value<AsRequired<string, Required>, WD>(
() => ({ () => ({
@@ -342,6 +365,7 @@ export class Value<Type, WD> {
description: null, description: null,
warning: null, warning: null,
disabled: false, disabled: false,
immutable: a.immutable ?? false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
}), }),
@@ -370,6 +394,7 @@ export class Value<Type, WD> {
description: null, description: null,
warning: null, warning: null,
disabled: false, disabled: false,
immutable: false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
} }
@@ -385,6 +410,9 @@ export class Value<Type, WD> {
min?: string | null min?: string | null
max?: string | null max?: string | null
step?: string | null step?: string | null
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}) { }) {
return new Value<AsRequired<string, Required>, WD>( return new Value<AsRequired<string, Required>, WD>(
() => ({ () => ({
@@ -396,6 +424,7 @@ export class Value<Type, WD> {
max: null, max: null,
step: null, step: null,
disabled: false, disabled: false,
immutable: a.immutable ?? false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
}), }),
@@ -430,6 +459,7 @@ export class Value<Type, WD> {
max: null, max: null,
step: null, step: null,
disabled: false, disabled: false,
immutable: false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
} }
@@ -445,6 +475,9 @@ export class Value<Type, WD> {
warning?: string | null warning?: string | null
required: Required required: Required
values: B values: B
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}) { }) {
return new Value<AsRequired<keyof B, Required>, WD>( return new Value<AsRequired<keyof B, Required>, WD>(
() => ({ () => ({
@@ -452,6 +485,7 @@ export class Value<Type, WD> {
warning: null, warning: null,
type: "select" as const, type: "select" as const,
disabled: false, disabled: false,
immutable: a.immutable ?? false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
}), }),
@@ -483,6 +517,7 @@ export class Value<Type, WD> {
warning: null, warning: null,
type: "select" as const, type: "select" as const,
disabled: false, disabled: false,
immutable: false,
...a, ...a,
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
} }
@@ -496,6 +531,9 @@ export class Value<Type, WD> {
values: Values values: Values
minLength?: number | null minLength?: number | null
maxLength?: number | null maxLength?: number | null
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}) { }) {
return new Value<(keyof Values)[], WD>( return new Value<(keyof Values)[], WD>(
() => ({ () => ({
@@ -505,6 +543,7 @@ export class Value<Type, WD> {
warning: null, warning: null,
description: null, description: null,
disabled: false, disabled: false,
immutable: a.immutable ?? false,
...a, ...a,
}), }),
arrayOf( arrayOf(
@@ -536,6 +575,7 @@ export class Value<Type, WD> {
warning: null, warning: null,
description: null, description: null,
disabled: false, disabled: false,
immutable: false,
...a, ...a,
} }
}, arrayOf(string)) }, arrayOf(string))
@@ -571,6 +611,9 @@ export class Value<Type, WD> {
warning?: string | null warning?: string | null
required: Required required: Required
default?: string | null default?: string | null
/** Immutable means it can only be configed at the first config then never again
Default is false */
immutable?: boolean
}, },
aVariants: Variants<Type, WrapperData>, aVariants: Variants<Type, WrapperData>,
) { ) {
@@ -582,6 +625,7 @@ export class Value<Type, WD> {
...a, ...a,
variants: await aVariants.build(options as any), variants: await aVariants.build(options as any),
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
immutable: a.immutable ?? false,
}), }),
asRequiredParser(aVariants.validator, a), asRequiredParser(aVariants.validator, a),
) )
@@ -614,6 +658,7 @@ export class Value<Type, WD> {
variants: await aVariants.build(options as any), variants: await aVariants.build(options as any),
...requiredLikeToAbove(a.required), ...requiredLikeToAbove(a.required),
disabled: (await getDisabledFn(options)) || [], disabled: (await getDisabledFn(options)) || [],
immutable: false,
}), }),
aVariants.validator.optional(), aVariants.validator.optional(),
) )

View File

@@ -44,6 +44,8 @@ export interface ValueSpecText extends ListValueSpecText, WithStandalone {
required: boolean required: boolean
default: DefaultString | null default: DefaultString | null
disabled: false | string disabled: false | string
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecTextarea extends WithStandalone { export interface ValueSpecTextarea extends WithStandalone {
type: "textarea" type: "textarea"
@@ -52,17 +54,23 @@ export interface ValueSpecTextarea extends WithStandalone {
maxLength: number | null maxLength: number | null
required: boolean required: boolean
disabled: false | string disabled: false | string
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone { export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone {
required: boolean required: boolean
default: number | null default: number | null
disabled: false | string disabled: false | string
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecColor extends WithStandalone { export interface ValueSpecColor extends WithStandalone {
type: "color" type: "color"
required: boolean required: boolean
default: string | null default: string | null
disabled: false | string disabled: false | string
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecDatetime extends WithStandalone { export interface ValueSpecDatetime extends WithStandalone {
type: "datetime" type: "datetime"
@@ -73,12 +81,16 @@ export interface ValueSpecDatetime extends WithStandalone {
step: string | null step: string | null
default: string | null default: string | null
disabled: false | string disabled: false | string
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecSelect extends SelectBase, WithStandalone { export interface ValueSpecSelect extends SelectBase, WithStandalone {
type: "select" type: "select"
required: boolean required: boolean
default: string | null default: string | null
disabled: false | string disabled: false | string
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecMultiselect extends SelectBase, WithStandalone { export interface ValueSpecMultiselect extends SelectBase, WithStandalone {
type: "multiselect" type: "multiselect"
@@ -86,11 +98,15 @@ export interface ValueSpecMultiselect extends SelectBase, WithStandalone {
maxLength: number | null maxLength: number | null
disabled: false | string disabled: false | string
default: string[] default: string[]
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecToggle extends WithStandalone { export interface ValueSpecToggle extends WithStandalone {
type: "toggle" type: "toggle"
default: boolean | null default: boolean | null
disabled: false | string disabled: false | string
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecUnion extends WithStandalone { export interface ValueSpecUnion extends WithStandalone {
type: "union" type: "union"
@@ -104,6 +120,8 @@ export interface ValueSpecUnion extends WithStandalone {
disabled?: string[] disabled?: string[]
required: boolean required: boolean
default: string | null default: string | null
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
} }
export interface ValueSpecFile extends WithStandalone { export interface ValueSpecFile extends WithStandalone {
type: "file" type: "file"