From d0cb3c5c333ffef44267bddb94fca383801cd568 Mon Sep 17 00:00:00 2001 From: BluJ Date: Tue, 2 May 2023 14:51:05 -0600 Subject: [PATCH] feat: Disabled on the types' --- lib/config/builder/list.ts | 15 +++++++++++--- lib/config/builder/value.ts | 25 ++++++++++++++++++++++- lib/config/configTypes.ts | 9 +++++++++ lib/test/configBuilder.test.ts | 37 ++++++++++++++++------------------ 4 files changed, 62 insertions(+), 24 deletions(-) diff --git a/lib/config/builder/list.ts b/lib/config/builder/list.ts index a6259ea..e0c3cfa 100644 --- a/lib/config/builder/list.ts +++ b/lib/config/builder/list.ts @@ -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: "list" as const, minLength: null, maxLength: null, + disabled: false, ...a, spec, - } + } satisfies ValueSpecListOf<"text"> }, arrayOf(string)) } static dynamicText( @@ -78,6 +81,7 @@ export class List { default?: string[] minLength?: number | null maxLength?: number | null + disabled?: false | string spec: { /** Default = false */ masked?: boolean @@ -109,9 +113,10 @@ export class List { type: "list" as const, minLength: null, maxLength: null, + disabled: false, ...a, spec, - } + } satisfies ValueSpecListOf<"text"> }, arrayOf(string)) } static number( @@ -150,9 +155,10 @@ export class List { maxLength: null, default: [], type: "list" as const, + disabled: false, ...a, spec, - } + } satisfies ValueSpecListOf<"number"> }, arrayOf(number)) } static dynamicNumber( @@ -166,6 +172,7 @@ export class List { default?: string[] minLength?: number | null maxLength?: number | null + disabled?: false | string spec: { integer: boolean min?: number | null @@ -195,6 +202,7 @@ export class List { maxLength: null, default: [], type: "list" as const, + disabled: false, ...a, spec, } @@ -237,6 +245,7 @@ export class List { minLength: null, maxLength: null, type: "list" as const, + disabled: false, ...value, } }, arrayOf(aSpec.spec.validator)) diff --git a/lib/config/builder/value.ts b/lib/config/builder/value.ts index d4a4316..ec84f92 100644 --- a/lib/config/builder/value.ts +++ b/lib/config/builder/value.ts @@ -110,6 +110,7 @@ export class Value { warning: null, default: null, type: "toggle" as const, + disabled: false, ...a, }), boolean, @@ -123,6 +124,7 @@ export class Value { description?: string | null warning?: string | null default?: boolean | null + disabled?: false | string } >, ) { @@ -132,6 +134,7 @@ export class Value { warning: null, default: null, type: "toggle" as const, + disabled: false, ...(await a(options)), }), boolean, @@ -163,6 +166,7 @@ export class Value { maxLength: null, patterns: [], inputmode: "text", + disabled: false, ...a, ...requiredLikeToAbove(a.required), }), @@ -201,6 +205,7 @@ export class Value { maxLength: null, patterns: [], inputmode: "text", + disabled: false, ...a, ...requiredLikeToAbove(a.required), } @@ -224,6 +229,7 @@ export class Value { maxLength: null, placeholder: null, type: "textarea" as const, + disabled: false, ...a, } satisfies ValueSpecTextarea), string, @@ -240,6 +246,7 @@ export class Value { minLength?: number | null maxLength?: number | null placeholder?: string | null + disabled?: false | string } >, ) { @@ -252,6 +259,7 @@ export class Value { maxLength: null, placeholder: null, type: "textarea" as const, + disabled: false, ...a, } }, string) @@ -279,6 +287,7 @@ export class Value { step: null, units: null, placeholder: null, + disabled: false, ...a, ...requiredLikeToAbove(a.required), }), @@ -300,6 +309,7 @@ export class Value { integer: boolean units?: string | null placeholder?: string | null + disabled?: false | string } >, ) { @@ -314,6 +324,7 @@ export class Value { step: null, units: null, placeholder: null, + disabled: false, ...a, ...requiredLikeToAbove(a.required), } @@ -330,6 +341,7 @@ export class Value { type: "color" as const, description: null, warning: null, + disabled: false, ...a, ...requiredLikeToAbove(a.required), }), @@ -346,6 +358,8 @@ export class Value { description?: string | null warning?: string | null required: RequiredDefault + + disabled?: false | string } >, ) { @@ -355,6 +369,7 @@ export class Value { type: "color" as const, description: null, warning: null, + disabled: false, ...a, ...requiredLikeToAbove(a.required), } @@ -380,6 +395,7 @@ export class Value { min: null, max: null, step: null, + disabled: false, ...a, ...requiredLikeToAbove(a.required), }), @@ -399,6 +415,7 @@ export class Value { min?: string | null max?: string | null step?: string | null + disabled?: false | string } >, ) { @@ -412,6 +429,7 @@ export class Value { min: null, max: null, step: null, + disabled: false, ...a, ...requiredLikeToAbove(a.required), } @@ -421,7 +439,6 @@ export class Value { Required extends RequiredDefault, B extends Record, WD, - CT, >(a: { name: string description?: string | null @@ -434,6 +451,7 @@ export class Value { description: null, warning: null, type: "select" as const, + disabled: false, ...a, ...requiredLikeToAbove(a.required), }), @@ -454,6 +472,7 @@ export class Value { warning?: string | null required: RequiredDefault values: Record + disabled?: false | string } >, ) { @@ -463,6 +482,7 @@ export class Value { description: null, warning: null, type: "select" as const, + disabled: false, ...a, ...requiredLikeToAbove(a.required), } @@ -484,6 +504,7 @@ export class Value { maxLength: null, warning: null, description: null, + disabled: false, ...a, }), arrayOf( @@ -502,6 +523,7 @@ export class Value { values: Record minLength?: number | null maxLength?: number | null + disabled?: false | string } >, ) { @@ -513,6 +535,7 @@ export class Value { maxLength: null, warning: null, description: null, + disabled: false, ...a, } }, arrayOf(string)) diff --git a/lib/config/configTypes.ts b/lib/config/configTypes.ts index 68119bc..db2b101 100644 --- a/lib/config/configTypes.ts +++ b/lib/config/configTypes.ts @@ -43,6 +43,7 @@ export type ValueSpecOf = 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 spec: ListValueSpecOf minLength: number | null maxLength: number | null + disabled: false | string default: | string[] | number[] diff --git a/lib/test/configBuilder.test.ts b/lib/test/configBuilder.test.ts index 298772a..fa05f4f 100644 --- a/lib/test/configBuilder.test.ts +++ b/lib/test/configBuilder.test.ts @@ -18,26 +18,23 @@ describe("builder tests", () => { required: { default: null }, }), }).build({} as any) - expect(JSON.stringify(bitcoinPropertiesBuilt)).toEqual( - /*json*/ `{ - "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(": ", ":"), - ) + 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: [], + disabled: false, + inputmode: "text", + name: "Peer tor address", + required: true, + default: null, + }, + }) }) })