feat: Disabled on the types'

This commit is contained in:
BluJ
2023-05-02 14:51:05 -06:00
parent 78d04219b9
commit d0cb3c5c33
4 changed files with 62 additions and 24 deletions

View File

@@ -4,6 +4,8 @@ import {
Pattern,
UniqueBy,
ValueSpecList,
ValueSpecListOf,
ValueSpecText,
} from "../configTypes"
import { Parser, arrayOf, number, string } from "ts-matches"
/**
@@ -62,9 +64,10 @@ export class List<Type, WD> {
type: "list" as const,
minLength: null,
maxLength: null,
disabled: false,
...a,
spec,
}
} satisfies ValueSpecListOf<"text">
}, arrayOf(string))
}
static dynamicText<WD>(
@@ -78,6 +81,7 @@ export class List<Type, WD> {
default?: string[]
minLength?: number | null
maxLength?: number | null
disabled?: false | string
spec: {
/** Default = false */
masked?: boolean
@@ -109,9 +113,10 @@ export class List<Type, WD> {
type: "list" as const,
minLength: null,
maxLength: null,
disabled: false,
...a,
spec,
}
} satisfies ValueSpecListOf<"text">
}, arrayOf(string))
}
static number<WD>(
@@ -150,9 +155,10 @@ export class List<Type, WD> {
maxLength: null,
default: [],
type: "list" as const,
disabled: false,
...a,
spec,
}
} satisfies ValueSpecListOf<"number">
}, arrayOf(number))
}
static dynamicNumber<WD>(
@@ -166,6 +172,7 @@ export class List<Type, WD> {
default?: string[]
minLength?: number | null
maxLength?: number | null
disabled?: false | string
spec: {
integer: boolean
min?: number | null
@@ -195,6 +202,7 @@ export class List<Type, WD> {
maxLength: null,
default: [],
type: "list" as const,
disabled: false,
...a,
spec,
}
@@ -237,6 +245,7 @@ export class List<Type, WD> {
minLength: null,
maxLength: null,
type: "list" as const,
disabled: false,
...value,
}
}, arrayOf(aSpec.spec.validator))

View File

@@ -110,6 +110,7 @@ export class Value<Type, WD> {
warning: null,
default: null,
type: "toggle" as const,
disabled: false,
...a,
}),
boolean,
@@ -123,6 +124,7 @@ export class Value<Type, WD> {
description?: string | null
warning?: string | null
default?: boolean | null
disabled?: false | string
}
>,
) {
@@ -132,6 +134,7 @@ export class Value<Type, WD> {
warning: null,
default: null,
type: "toggle" as const,
disabled: false,
...(await a(options)),
}),
boolean,
@@ -163,6 +166,7 @@ export class Value<Type, WD> {
maxLength: null,
patterns: [],
inputmode: "text",
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}),
@@ -201,6 +205,7 @@ export class Value<Type, WD> {
maxLength: null,
patterns: [],
inputmode: "text",
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}
@@ -224,6 +229,7 @@ export class Value<Type, WD> {
maxLength: null,
placeholder: null,
type: "textarea" as const,
disabled: false,
...a,
} satisfies ValueSpecTextarea),
string,
@@ -240,6 +246,7 @@ export class Value<Type, WD> {
minLength?: number | null
maxLength?: number | null
placeholder?: string | null
disabled?: false | string
}
>,
) {
@@ -252,6 +259,7 @@ export class Value<Type, WD> {
maxLength: null,
placeholder: null,
type: "textarea" as const,
disabled: false,
...a,
}
}, string)
@@ -279,6 +287,7 @@ export class Value<Type, WD> {
step: null,
units: null,
placeholder: null,
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}),
@@ -300,6 +309,7 @@ export class Value<Type, WD> {
integer: boolean
units?: string | null
placeholder?: string | null
disabled?: false | string
}
>,
) {
@@ -314,6 +324,7 @@ export class Value<Type, WD> {
step: null,
units: null,
placeholder: null,
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}
@@ -330,6 +341,7 @@ export class Value<Type, WD> {
type: "color" as const,
description: null,
warning: null,
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}),
@@ -346,6 +358,8 @@ export class Value<Type, WD> {
description?: string | null
warning?: string | null
required: RequiredDefault<string>
disabled?: false | string
}
>,
) {
@@ -355,6 +369,7 @@ export class Value<Type, WD> {
type: "color" as const,
description: null,
warning: null,
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}
@@ -380,6 +395,7 @@ export class Value<Type, WD> {
min: null,
max: null,
step: null,
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}),
@@ -399,6 +415,7 @@ export class Value<Type, WD> {
min?: string | null
max?: string | null
step?: string | null
disabled?: false | string
}
>,
) {
@@ -412,6 +429,7 @@ export class Value<Type, WD> {
min: null,
max: null,
step: null,
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}
@@ -421,7 +439,6 @@ export class Value<Type, WD> {
Required extends RequiredDefault<string>,
B extends Record<string, string>,
WD,
CT,
>(a: {
name: string
description?: string | null
@@ -434,6 +451,7 @@ export class Value<Type, WD> {
description: null,
warning: null,
type: "select" as const,
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}),
@@ -454,6 +472,7 @@ export class Value<Type, WD> {
warning?: string | null
required: RequiredDefault<string>
values: Record<string, string>
disabled?: false | string
}
>,
) {
@@ -463,6 +482,7 @@ export class Value<Type, WD> {
description: null,
warning: null,
type: "select" as const,
disabled: false,
...a,
...requiredLikeToAbove(a.required),
}
@@ -484,6 +504,7 @@ export class Value<Type, WD> {
maxLength: null,
warning: null,
description: null,
disabled: false,
...a,
}),
arrayOf(
@@ -502,6 +523,7 @@ export class Value<Type, WD> {
values: Record<string, string>
minLength?: number | null
maxLength?: number | null
disabled?: false | string
}
>,
) {
@@ -513,6 +535,7 @@ export class Value<Type, WD> {
maxLength: null,
warning: null,
description: null,
disabled: false,
...a,
}
}, arrayOf(string))

View File

@@ -43,6 +43,7 @@ export type ValueSpecOf<T extends ValueType> = T extends "text"
export interface ValueSpecText extends ListValueSpecText, WithStandalone {
required: boolean
default: DefaultString | null
disabled: false | string
}
export interface ValueSpecTextarea extends WithStandalone {
type: "textarea"
@@ -50,15 +51,18 @@ export interface ValueSpecTextarea extends WithStandalone {
minLength: number | null
maxLength: number | null
required: boolean
disabled: false | string
}
export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone {
required: boolean
default: number | null
disabled: false | string
}
export interface ValueSpecColor extends WithStandalone {
type: "color"
required: boolean
default: string | null
disabled: false | string
}
export interface ValueSpecDatetime extends WithStandalone {
type: "datetime"
@@ -68,21 +72,25 @@ export interface ValueSpecDatetime extends WithStandalone {
max: string | null
step: string | null
default: string | null
disabled: false | string
}
export interface ValueSpecSelect extends SelectBase, WithStandalone {
type: "select"
required: boolean
default: string | null
disabled: false | string
}
export interface ValueSpecMultiselect extends SelectBase, WithStandalone {
type: "multiselect"
minLength: number | null
maxLength: number | null
disabled: false | string
default: string[]
}
export interface ValueSpecToggle extends WithStandalone {
type: "toggle"
default: boolean | null
disabled: false | string
}
export interface ValueSpecUnion extends WithStandalone {
type: "union"
@@ -131,6 +139,7 @@ export interface ValueSpecListOf<T extends ListValueSpecType>
spec: ListValueSpecOf<T>
minLength: number | null
maxLength: number | null
disabled: false | string
default:
| string[]
| number[]

View File

@@ -18,26 +18,23 @@ describe("builder tests", () => {
required: { default: null },
}),
}).build({} as any)
expect(JSON.stringify(bitcoinPropertiesBuilt)).toEqual(
/*json*/ `{
expect(bitcoinPropertiesBuilt).toMatchObject({
"peer-tor-address": {
"type": "text",
"description": "The Tor address of the peer interface",
"warning": null,
"masked": false,
"placeholder": null,
"minLength": null,
"maxLength": null,
"patterns": [],
"inputmode":"text",
"name": "Peer tor address",
"required": true,
"default": null
}}`
.replaceAll("\n", " ")
.replaceAll(/\s{2,}/g, "")
.replaceAll(": ", ":"),
)
type: "text",
description: "The Tor address of the peer interface",
warning: null,
masked: false,
placeholder: null,
minLength: null,
maxLength: null,
patterns: [],
disabled: false,
inputmode: "text",
name: "Peer tor address",
required: true,
default: null,
},
})
})
})