remove list of unions

This commit is contained in:
Matt Hill
2023-03-28 01:02:14 -06:00
parent 53ef640ed7
commit 60a6a27682
5 changed files with 48 additions and 106 deletions

View File

@@ -1,5 +1,3 @@
import { typeFromProps } from "../../util";
export class IBuilder<A> {
protected constructor(readonly a: A) { }

View File

@@ -1,6 +1,5 @@
import { BuilderExtract, IBuilder } from "./builder";
import { Config } from "./config";
import { Variants } from "./variants";
import {
InputSpec,
UniqueBy,
@@ -107,47 +106,6 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
...value,
});
}
static union<
A extends {
name: string;
description: string | null;
warning: string | null;
default: Record<string, unknown>[];
range: string;
spec: {
select: {
name: string;
description: string | null;
warning: string | null;
}
variants: Variants<{
[key: string]: { name: string; spec: InputSpec };
}>;
displayAs: null | string;
uniqueBy: UniqueBy;
default: string;
};
}
>(a: A) {
const { spec: previousSpec, ...rest } = a;
const { variants: previousVariants, ...restSpec } = previousSpec;
const variants = previousVariants.build() as BuilderExtract<
A["spec"]["variants"]
>;
const spec = {
...restSpec,
variants,
};
const value = {
spec,
...rest,
};
return new List({
type: "list" as const,
subtype: "union" as const,
...value,
});
}
public validator() {
return guardAll(this.a);

View File

@@ -7,7 +7,6 @@ import {
ValueSpec,
ValueSpecList,
ValueSpecNumber,
ValueSpecOf,
ValueSpecString,
} from "../config-types";
import { guardAll } from "../../util";
@@ -146,8 +145,10 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
name: string;
description: string | null;
warning: string | null;
selectKey: string;
variants: Variants<{ [key: string]: { name: string; spec: InputSpec } }>;
default: string;
nullable: boolean;
default: string | null;
}
>(a: A) {
const { variants: previousVariants, ...rest } = a;