From 4d950258964dbad29407153d823a885d718f0cce Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Mon, 3 Apr 2023 08:39:57 -0600 Subject: [PATCH] remove subtype and also inputmode for numbers --- lib/config/builder/index.test.ts | 14 ++++++------- lib/config/builder/list.ts | 34 ++++---------------------------- lib/config/builder/value.ts | 5 ----- lib/config/config-types.ts | 11 +++++------ lib/test/output.test.ts | 2 +- lib/util/propertiesMatcher.ts | 8 +++----- 6 files changed, 20 insertions(+), 54 deletions(-) diff --git a/lib/config/builder/index.test.ts b/lib/config/builder/index.test.ts index 48c9cb4..a3a8df3 100644 --- a/lib/config/builder/index.test.ts +++ b/lib/config/builder/index.test.ts @@ -1,15 +1,15 @@ -describe("test", () => { - test("test", () => { - expect(true).toEqual(true); - }); -}); -import { values } from "lodash"; -import { Validator } from "ts-matches"; import { testOutput } from "../../test/output.test"; import { Config } from "./config"; import { List } from "./list"; import { Value } from "./value"; import { Variants } from "./variants"; + +describe("test", () => { + test("test", () => { + expect(true).toEqual(true); + }); +}); + describe("builder tests", () => { test("String", () => { console.log("BLUJ->"); diff --git a/lib/config/builder/list.ts b/lib/config/builder/list.ts index f658d60..4587d9c 100644 --- a/lib/config/builder/list.ts +++ b/lib/config/builder/list.ts @@ -1,31 +1,8 @@ import { BuilderExtract, IBuilder } from "./builder"; import { Config } from "./config"; -import { InputSpec, ListValueSpecNumber, ListValueSpecString, UniqueBy, ValueSpecList } from "../config-types"; +import { InputSpec, ListValueSpecString, UniqueBy, ValueSpecList } from "../config-types"; import { guardAll } from "../../util"; -import { range } from "lodash"; -/** - * Used as a subtype of Value.list -```ts - - export const authorizationList = List.string({ - "name": "Authorization", - "range": "[0,*)", - "spec": { - "masked": null, - "placeholder": null, - "pattern": "^[a-zA-Z0-9_-]+:([0-9a-fA-F]{2})+\\$([0-9a-fA-F]{2})+$", - "patternDescription": - 'Each item must be of the form ":$".', - "textarea": false, - }, - "default": [], - "description": - "Username and hashed password for JSON-RPC connections. RPC clients connect using the usual http basic authentication.", - "warning": null, - }); -``` - */ export class List extends IBuilder { static string( a: { @@ -48,6 +25,7 @@ export class List extends IBuilder { } ) { const spec = { + type: 'string' as const, placeholder: null, pattern: null, patternDescription: null, @@ -60,7 +38,6 @@ export class List extends IBuilder { warning: null, default: [], type: "list" as const, - subtype: "string" as const, range: "(*,*)", ...a, spec, @@ -82,13 +59,11 @@ export class List extends IBuilder { range?: string; units?: string | null; placeholder?: string | null; - /** Default = "decimal" */ - inputmode?: ListValueSpecNumber["inputmode"]; } ) { const spec = { + type: "number" as const, placeholder: null, - inputmode: "decimal" as const, range: "(*,*)", units: null, ...aSpec, @@ -100,7 +75,6 @@ export class List extends IBuilder { range: "(*,*)", default: [], type: "list" as const, - subtype: "number" as const, ...a, spec, }); @@ -123,6 +97,7 @@ export class List extends IBuilder { const { spec: previousSpecSpec, ...restSpec } = aSpec; const specSpec = previousSpecSpec.build() as BuilderExtract; const spec = { + type: "object" as const, displayAs: null, uniqueBy: null, ...restSpec, @@ -137,7 +112,6 @@ export class List extends IBuilder { warning: null, range: "(*,*)", type: "list" as const, - subtype: "object" as const, ...value, }); } diff --git a/lib/config/builder/value.ts b/lib/config/builder/value.ts index 635814a..56df3c0 100644 --- a/lib/config/builder/value.ts +++ b/lib/config/builder/value.ts @@ -4,12 +4,10 @@ import { List } from "./list"; import { Variants } from "./variants"; import { InputSpec, - ListValueSpecNumber, ListValueSpecString, ValueSpec, ValueSpecList, ValueSpecNumber, - ValueSpecString, ValueSpecTextarea, } from "../config-types"; import { guardAll } from "../../util"; @@ -100,12 +98,9 @@ export class Value extends IBuilder { integral: boolean; units?: string | null; placeholder?: string | null; - /** Default = 'decimal' */ - inputmode?: ListValueSpecNumber["inputmode"]; }) { return new Value({ type: "number" as const, - inputmode: "decimal", description: null, warning: null, default: null, diff --git a/lib/config/config-types.ts b/lib/config/config-types.ts index 88783a7..5131a0b 100644 --- a/lib/config/config-types.ts +++ b/lib/config/config-types.ts @@ -37,7 +37,6 @@ export type ValueSpecOf = T extends "string" : never; export interface ValueSpecString extends ListValueSpecString, WithStandalone { - type: "string"; required: boolean; default: DefaultString | null; } @@ -49,7 +48,6 @@ export interface ValueSpecTextarea extends WithStandalone { } export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone { - type: "number"; required: boolean; default: number | null; } @@ -116,7 +114,6 @@ export type ValueSpecList = ValueSpecListOf; export interface ValueSpecListOf extends WithStandalone { type: "list"; - subtype: T; spec: ListValueSpecOf; range: string; // '[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules default: @@ -135,27 +132,29 @@ export function isValueSpecListOf( t: ValueSpecList, s: S ): t is ValueSpecListOf { - return t.subtype === s; + return t.spec.type === s; } export interface ListValueSpecString { + type: 'string' pattern: string | null; patternDescription: string | null; masked: boolean; // default = false - inputmode: 'text' | 'email' | 'tel' | 'url' // default = 'text' + inputmode: 'text' | 'email' | 'tel' | 'url'; // default = 'text' placeholder: string | null; } export interface ListValueSpecNumber { + type: 'number'; /** '[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules */ range: string; integral: boolean; // default = false units: string | null; - inputmode: 'numeric' | 'decimal' // default = 'decimal' placeholder: string | null; } export interface ListValueSpecObject { + type: 'object'; /** this is a mapped type of the config object at this level, replacing the object's values with specs on those values */ spec: InputSpec; /** indicates whether duplicates can be permitted in the list */ diff --git a/lib/test/output.test.ts b/lib/test/output.test.ts index 47e8f9d..8f8b5e1 100644 --- a/lib/test/output.test.ts +++ b/lib/test/output.test.ts @@ -1,5 +1,5 @@ import { UnionSelectKey, unionSelectKey } from "../config/config-types"; -import { InputSpec, matchInputSpec, threads } from "./output"; +import { InputSpec, matchInputSpec } from "./output"; export type IfEquals = (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 ? Y diff --git a/lib/util/propertiesMatcher.ts b/lib/util/propertiesMatcher.ts index 143b1a3..bd71f4a 100644 --- a/lib/util/propertiesMatcher.ts +++ b/lib/util/propertiesMatcher.ts @@ -49,8 +49,8 @@ type GuardObject = unknown // prettier-ignore export type GuardList = - A extends { type: TypeList, subtype: infer B, spec?: { spec?: infer C } } ? Array & ({ type: B, spec: C })>> : - A extends { type: TypeList, subtype: infer B, spec?: {} } ? Array & ({ type: B })>> : + A extends { type: TypeList, spec?: { type: infer B, spec?: infer C } } ? Array & ({ type: B, spec: C })>> : + A extends { type: TypeList, spec?: { type: infer B } } ? Array & ({ type: B })>> : unknown // prettier-ignore type GuardSelect = @@ -102,7 +102,6 @@ const rangeRegex = /(\[|\()(\*|(\d|\.)+),(\*|(\d|\.)+)(\]|\))/; const matchRange = object({ range: string }); const matchIntegral = object({ integral: literals(true) }); const matchSpec = object({ spec: recordString }); -const matchSubType = object({ subtype: string }); const matchUnion = object({ variants: dictionary([string, matchVariant]), }); @@ -230,10 +229,9 @@ export function guardAll(value: A): Parser true); - const subtype = matchSubType.unsafeCast(value).subtype; return defaultRequired( matches - .arrayOf(guardAll({ type: subtype, ...spec } as any)) + .arrayOf(guardAll(spec as any)) .validate((x) => rangeValidate(x.length), "valid length"), value ) as any;