mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
remove subtype and also inputmode for numbers
This commit is contained in:
@@ -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->");
|
||||
|
||||
@@ -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 "<USERNAME>:<SALT>$<HASH>".',
|
||||
"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<A extends ValueSpecList> extends IBuilder<A> {
|
||||
static string(
|
||||
a: {
|
||||
@@ -48,6 +25,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
}
|
||||
) {
|
||||
const spec = {
|
||||
type: 'string' as const,
|
||||
placeholder: null,
|
||||
pattern: null,
|
||||
patternDescription: null,
|
||||
@@ -60,7 +38,6 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
warning: null,
|
||||
default: [],
|
||||
type: "list" as const,
|
||||
subtype: "string" as const,
|
||||
range: "(*,*)",
|
||||
...a,
|
||||
spec,
|
||||
@@ -82,13 +59,11 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
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<A extends ValueSpecList> extends IBuilder<A> {
|
||||
range: "(*,*)",
|
||||
default: [],
|
||||
type: "list" as const,
|
||||
subtype: "number" as const,
|
||||
...a,
|
||||
spec,
|
||||
});
|
||||
@@ -123,6 +97,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
const { spec: previousSpecSpec, ...restSpec } = aSpec;
|
||||
const specSpec = previousSpecSpec.build() as BuilderExtract<Spec>;
|
||||
const spec = {
|
||||
type: "object" as const,
|
||||
displayAs: null,
|
||||
uniqueBy: null,
|
||||
...restSpec,
|
||||
@@ -137,7 +112,6 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
warning: null,
|
||||
range: "(*,*)",
|
||||
type: "list" as const,
|
||||
subtype: "object" as const,
|
||||
...value,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<A extends ValueSpec> extends IBuilder<A> {
|
||||
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,
|
||||
|
||||
@@ -37,7 +37,6 @@ export type ValueSpecOf<T extends ValueType> = 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<ListValueSpecType>;
|
||||
export interface ValueSpecListOf<T extends ListValueSpecType>
|
||||
extends WithStandalone {
|
||||
type: "list";
|
||||
subtype: T;
|
||||
spec: ListValueSpecOf<T>;
|
||||
range: string; // '[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules
|
||||
default:
|
||||
@@ -135,27 +132,29 @@ export function isValueSpecListOf<S extends ListValueSpecType>(
|
||||
t: ValueSpecList,
|
||||
s: S
|
||||
): t is ValueSpecListOf<S> {
|
||||
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 */
|
||||
|
||||
@@ -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<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2
|
||||
? Y
|
||||
|
||||
@@ -49,8 +49,8 @@ type GuardObject<A> =
|
||||
unknown
|
||||
// prettier-ignore
|
||||
export type GuardList<A> =
|
||||
A extends { type: TypeList, subtype: infer B, spec?: { spec?: infer C } } ? Array<GuardAll<Omit<A, "type" | "subtype" | "spec"> & ({ type: B, spec: C })>> :
|
||||
A extends { type: TypeList, subtype: infer B, spec?: {} } ? Array<GuardAll<Omit<A, "type"> & ({ type: B })>> :
|
||||
A extends { type: TypeList, spec?: { type: infer B, spec?: infer C } } ? Array<GuardAll<Omit<A, "type" | "spec"> & ({ type: B, spec: C })>> :
|
||||
A extends { type: TypeList, spec?: { type: infer B } } ? Array<GuardAll<Omit<A, "type"> & ({ type: B })>> :
|
||||
unknown
|
||||
// prettier-ignore
|
||||
type GuardSelect<A> =
|
||||
@@ -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<A extends ValueSpecAny>(value: A): Parser<unknown, Guar
|
||||
const spec = (matchSpec.test(value) && value.spec) || {};
|
||||
const rangeValidate = (matchRange.test(value) && matchNumberWithRange(value.range).test) || (() => 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;
|
||||
|
||||
Reference in New Issue
Block a user