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,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);