chore: Update the builder.

This commit is contained in:
BluJ
2023-03-31 09:30:11 -06:00
parent 0aab08585d
commit 26f544718b
10 changed files with 429 additions and 374 deletions

View File

@@ -1,23 +1,17 @@
import { UnionSelectKey, unionSelectKey } from "../config/config-types";
import { InputSpec, matchInputSpec, threads } from "./output";
type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T
? 1
: 2) extends <G>() => G extends U ? 1 : 2
export type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2
? Y
: N;
function testOutput<A, B>(): (c: IfEquals<A, B>) => null {
export function testOutput<A, B>(): (c: IfEquals<A, B>) => null {
return () => null;
}
function isObject(item: unknown): item is object {
return !!(item && typeof item === "object" && !Array.isArray(item));
}
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (
x: infer R
) => any
? R
: never;
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
export function mergeDeep<A extends unknown[]>(...sources: A) {
return _mergeDeep({}, ...sources);
}
@@ -49,21 +43,11 @@ testOutput<InputSpec["rpc"]["enable"], boolean>()(null);
testOutput<InputSpec["rpc"]["username"], string>()(null);
testOutput<InputSpec["rpc"]["advanced"]["auth"], string[]>()(null);
testOutput<
InputSpec["rpc"]["advanced"]["serialversion"],
"segwit" | "non-segwit"
>()(null);
testOutput<InputSpec["rpc"]["advanced"]["serialversion"], "segwit" | "non-segwit">()(null);
testOutput<InputSpec["rpc"]["advanced"]["servertimeout"], number>()(null);
testOutput<InputSpec["advanced"]["peers"]["addnode"][0]["hostname"], string>()(
null
);
testOutput<InputSpec["testListUnion"][0][UnionSelectKey]["name"], string>()(
null
);
testOutput<
InputSpec["testListUnion"][0][UnionSelectKey][UnionSelectKey],
"lnd"
>()(null);
testOutput<InputSpec["advanced"]["peers"]["addnode"][0]["hostname"], string>()(null);
testOutput<InputSpec["testListUnion"][0][UnionSelectKey]["name"], string>()(null);
testOutput<InputSpec["testListUnion"][0][UnionSelectKey][UnionSelectKey], "lnd">()(null);
// prettier-ignore
// @ts-expect-error Expect that the string is the one above
testOutput<InputSpec["testListUnion"][0][UnionSelectKey][UnionSelectKey], "unionSelectKey">()(null);
@@ -78,6 +62,7 @@ describe("Inputs", () => {
],
rpc: {
enable: true,
bio: "This is a bio",
username: "test",
password: "test",
advanced: {
@@ -126,13 +111,9 @@ describe("Inputs", () => {
});
test("test errors", () => {
expect(() =>
matchInputSpec.unsafeCast(
mergeDeep(validInput, { rpc: { advanced: { threads: 0 } } })
)
).toThrowError();
expect(() =>
matchInputSpec.unsafeCast(mergeDeep(validInput, { rpc: { enable: 2 } }))
matchInputSpec.unsafeCast(mergeDeep(validInput, { rpc: { advanced: { threads: 0 } } }))
).toThrowError();
expect(() => matchInputSpec.unsafeCast(mergeDeep(validInput, { rpc: { enable: 2 } }))).toThrowError();
expect(() =>
matchInputSpec.unsafeCast(