chore: Add changes

This commit is contained in:
BluJ
2023-04-05 14:48:51 -06:00
parent 45192e0358
commit 5414b301f3
15 changed files with 326 additions and 97 deletions

View File

@@ -63,10 +63,16 @@ export class Config<A extends InputSpec> extends IBuilder<A> {
static empty() {
return new Config({});
}
static withValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
static withValue<K extends string, B extends ValueSpec>(
key: K,
value: Value<B>
) {
return Config.empty().withValue(key, value);
}
static addValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
static addValue<K extends string, B extends ValueSpec>(
key: K,
value: Value<B>
) {
return Config.empty().withValue(key, value);
}

View File

@@ -1,6 +1,12 @@
import { BuilderExtract, IBuilder } from "./builder";
import { Config } from "./config";
import { InputSpec, ListValueSpecNumber, ListValueSpecString, UniqueBy, ValueSpecList } from "../configTypes";
import {
InputSpec,
ListValueSpecNumber,
ListValueSpecString,
UniqueBy,
ValueSpecList,
} from "../configTypes";
import { guardAll } from "../../util";
/**
* Used as a subtype of Value.list

View File

@@ -35,7 +35,12 @@ const username = Value.string({
```
*/
export class Value<A extends ValueSpec> extends IBuilder<A> {
static boolean(a: { name: string; description?: string | null; warning?: string | null; default?: boolean | null }) {
static boolean(a: {
name: string;
description?: string | null;
warning?: string | null;
default?: boolean | null;
}) {
return new Value({
description: null,
warning: null,
@@ -161,7 +166,9 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
spec,
});
}
static union<V extends Variants<{ [key: string]: { name: string; spec: InputSpec } }>>(
static union<
V extends Variants<{ [key: string]: { name: string; spec: InputSpec } }>
>(
a: {
name: string;
description?: string | null;

View File

@@ -80,7 +80,10 @@ export class Variants<
static empty() {
return Variants.of({});
}
static withVariant<K extends string, B extends InputSpec>(key: K, value: Config<B>) {
static withVariant<K extends string, B extends InputSpec>(
key: K,
value: Config<B>
) {
return Variants.empty().withVariant(key, value);
}

View File

@@ -11,7 +11,9 @@ export type InputSpec = Record<string, WithOutOptionals<C.ValueSpec>>;
export type ValueSpec = WithOutOptionals<C.ValueSpec>;
/** core spec types. These types provide the metadata for performing validations */
export type ValueSpecOf<T extends ValueType> = WithOutOptionals<C.ValueSpecOf<T>>;
export type ValueSpecOf<T extends ValueType> = WithOutOptionals<
C.ValueSpecOf<T>
>;
export type ValueSpecString = WithOutOptionals<C.ValueSpecString>;
export type ValueSpecTextarea = WithOutOptionals<C.ValueSpecTextarea>;
@@ -27,11 +29,15 @@ export type SelectBase = WithOutOptionals<C.SelectBase>;
export type ListValueSpecType = WithOutOptionals<C.ListValueSpecType>;
/** represents a spec for the values of a list */
export type ListValueSpecOf<T extends ListValueSpecType> = WithOutOptionals<C.ListValueSpecOf<T>>;
export type ListValueSpecOf<T extends ListValueSpecType> = WithOutOptionals<
C.ListValueSpecOf<T>
>;
/** represents a spec for a list */
export type ValueSpecList = WithOutOptionals<C.ValueSpecList>;
export type ValueSpecListOf<T extends ListValueSpecType> = WithOutOptionals<C.ValueSpecListOf<T>>;
export type ValueSpecListOf<T extends ListValueSpecType> = WithOutOptionals<
C.ValueSpecListOf<T>
>;
// sometimes the type checker needs just a little bit of help
export function isValueSpecListOf<S extends ListValueSpecType>(

View File

@@ -101,7 +101,8 @@ export type ListValueSpecOf<T extends ListValueSpecType> = T extends "string"
: never;
/** represents a spec for a list */
export type ValueSpecList = ValueSpecListOf<ListValueSpecType>;
export interface ValueSpecListOf<T extends ListValueSpecType> extends WithStandalone {
export interface ValueSpecListOf<T extends ListValueSpecType>
extends WithStandalone {
type: "list";
spec: ListValueSpecOf<T>;
range?: string;