feat: Utils to do bindLan and have ipv4 and ipv6 if need be

This commit is contained in:
BluJ
2023-04-27 11:22:42 -06:00
parent 353692bf55
commit c7d38fc7ce
79 changed files with 1754 additions and 1744 deletions

View File

@@ -1,24 +1,24 @@
import { testOutput } from "./output.test";
import { Config } from "../config/builder/config";
import { List } from "../config/builder/list";
import { Value } from "../config/builder/value";
import { Variants } from "../config/builder/variants";
import { testOutput } from "./output.test"
import { Config } from "../config/builder/config"
import { List } from "../config/builder/list"
import { Value } from "../config/builder/value"
import { Variants } from "../config/builder/variants"
describe("builder tests", () => {
test("text", () => {
const bitcoinPropertiesBuilt: {
"peer-tor-address": {
name: string;
description: string | null;
type: "text";
};
name: string
description: string | null
type: "text"
}
} = Config.of({
"peer-tor-address": Value.text({
name: "Peer tor address",
description: "The Tor address of the peer interface",
required: true,
required: { default: null },
}),
}).build();
}).build()
expect(JSON.stringify(bitcoinPropertiesBuilt)).toEqual(
/*json*/ `{
"peer-tor-address": {
@@ -38,9 +38,9 @@ describe("builder tests", () => {
.replaceAll("\n", " ")
.replaceAll(/\s{2,}/g, "")
.replaceAll(": ", ":"),
);
});
});
)
})
})
describe("values", () => {
test("toggle", () => {
@@ -49,71 +49,70 @@ describe("values", () => {
description: null,
warning: null,
default: null,
});
const validator = value.validator();
validator.unsafeCast(false);
testOutput<typeof validator._TYPE, boolean>()(null);
});
})
const validator = value.validator()
validator.unsafeCast(false)
testOutput<typeof validator._TYPE, boolean>()(null)
})
test("text", () => {
const value = Value.text({
name: "Testing",
required: { default: null },
})
const validator = value.validator()
const rawIs = value.build()
validator.unsafeCast("test text")
expect(() => validator.unsafeCast(null)).toThrowError()
testOutput<typeof validator._TYPE, string>()(null)
})
test("text", () => {
const value = Value.text({
name: "Testing",
required: { default: "null" },
})
const validator = value.validator()
const rawIs = value.build()
validator.unsafeCast("test text")
expect(() => validator.unsafeCast(null)).toThrowError()
testOutput<typeof validator._TYPE, string>()(null)
})
test("optional text", () => {
const value = Value.text({
name: "Testing",
required: false,
description: null,
warning: null,
masked: false,
placeholder: null,
minLength: null,
maxLength: null,
patterns: [],
inputmode: "text",
});
const validator = value.validator();
validator.unsafeCast("test text");
testOutput<typeof validator._TYPE, string | null | undefined>()(null);
});
test("text", () => {
const value = Value.text({
name: "Testing",
required: true,
description: null,
warning: null,
masked: false,
placeholder: null,
minLength: null,
maxLength: null,
patterns: [],
inputmode: "text",
});
const validator = value.validator();
validator.unsafeCast("test text");
testOutput<typeof validator._TYPE, string>()(null);
});
})
const validator = value.validator()
const rawIs = value.build()
validator.unsafeCast("test text")
validator.unsafeCast(null)
testOutput<typeof validator._TYPE, string | null | undefined>()(null)
})
test("color", () => {
const value = Value.color({
name: "Testing",
required: false,
description: null,
warning: null,
});
const validator = value.validator();
validator.unsafeCast("#000000");
testOutput<typeof validator._TYPE, string | null | undefined>()(null);
});
})
const validator = value.validator()
validator.unsafeCast("#000000")
testOutput<typeof validator._TYPE, string | null | undefined>()(null)
})
test("datetime", () => {
const value = Value.datetime({
name: "Testing",
required: true,
required: { default: null },
description: null,
warning: null,
inputmode: "date",
min: null,
max: null,
step: null,
});
const validator = value.validator();
validator.unsafeCast("2021-01-01");
testOutput<typeof validator._TYPE, string>()(null);
});
})
const validator = value.validator()
validator.unsafeCast("2021-01-01")
testOutput<typeof validator._TYPE, string>()(null)
})
test("optional datetime", () => {
const value = Value.datetime({
name: "Testing",
@@ -124,11 +123,11 @@ describe("values", () => {
min: null,
max: null,
step: null,
});
const validator = value.validator();
validator.unsafeCast("2021-01-01");
testOutput<typeof validator._TYPE, string | null | undefined>()(null);
});
})
const validator = value.validator()
validator.unsafeCast("2021-01-01")
testOutput<typeof validator._TYPE, string | null | undefined>()(null)
})
test("textarea", () => {
const value = Value.textarea({
name: "Testing",
@@ -138,15 +137,15 @@ describe("values", () => {
minLength: null,
maxLength: null,
placeholder: null,
});
const validator = value.validator();
validator.unsafeCast("test text");
testOutput<typeof validator._TYPE, string>()(null);
});
})
const validator = value.validator()
validator.unsafeCast("test text")
testOutput<typeof validator._TYPE, string>()(null)
})
test("number", () => {
const value = Value.number({
name: "Testing",
required: true,
required: { default: null },
integer: false,
description: null,
warning: null,
@@ -155,11 +154,11 @@ describe("values", () => {
step: null,
units: null,
placeholder: null,
});
const validator = value.validator();
validator.unsafeCast(2);
testOutput<typeof validator._TYPE, number>()(null);
});
})
const validator = value.validator()
validator.unsafeCast(2)
testOutput<typeof validator._TYPE, number>()(null)
})
test("optional number", () => {
const value = Value.number({
name: "Testing",
@@ -172,28 +171,28 @@ describe("values", () => {
step: null,
units: null,
placeholder: null,
});
const validator = value.validator();
validator.unsafeCast(2);
testOutput<typeof validator._TYPE, number | null | undefined>()(null);
});
})
const validator = value.validator()
validator.unsafeCast(2)
testOutput<typeof validator._TYPE, number | null | undefined>()(null)
})
test("select", () => {
const value = Value.select({
name: "Testing",
required: true,
required: { default: null },
values: {
a: "A",
b: "B",
},
description: null,
warning: null,
});
const validator = value.validator();
validator.unsafeCast("a");
validator.unsafeCast("b");
expect(() => validator.unsafeCast(null)).toThrowError();
testOutput<typeof validator._TYPE, "a" | "b">()(null);
});
})
const validator = value.validator()
validator.unsafeCast("a")
validator.unsafeCast("b")
expect(() => validator.unsafeCast(null)).toThrowError()
testOutput<typeof validator._TYPE, "a" | "b">()(null)
})
test("nullable select", () => {
const value = Value.select({
name: "Testing",
@@ -204,13 +203,13 @@ describe("values", () => {
},
description: null,
warning: null,
});
const validator = value.validator();
validator.unsafeCast("a");
validator.unsafeCast("b");
validator.unsafeCast(null);
testOutput<typeof validator._TYPE, "a" | "b" | null | undefined>()(null);
});
})
const validator = value.validator()
validator.unsafeCast("a")
validator.unsafeCast("b")
validator.unsafeCast(null)
testOutput<typeof validator._TYPE, "a" | "b" | null | undefined>()(null)
})
test("multiselect", () => {
const value = Value.multiselect({
name: "Testing",
@@ -223,12 +222,12 @@ describe("values", () => {
warning: null,
minLength: null,
maxLength: null,
});
const validator = value.validator();
validator.unsafeCast([]);
validator.unsafeCast(["a", "b"]);
testOutput<typeof validator._TYPE, Array<"a" | "b">>()(null);
});
})
const validator = value.validator()
validator.unsafeCast([])
validator.unsafeCast(["a", "b"])
testOutput<typeof validator._TYPE, Array<"a" | "b">>()(null)
})
test("object", () => {
const value = Value.object(
{
@@ -244,16 +243,16 @@ describe("values", () => {
default: null,
}),
}),
);
const validator = value.validator();
validator.unsafeCast({ a: true });
testOutput<typeof validator._TYPE, { a: boolean }>()(null);
});
)
const validator = value.validator()
validator.unsafeCast({ a: true })
testOutput<typeof validator._TYPE, { a: boolean }>()(null)
})
test("union", () => {
const value = Value.union(
{
name: "Testing",
required: true,
required: { default: null },
description: null,
warning: null,
default: null,
@@ -271,14 +270,14 @@ describe("values", () => {
}),
},
}),
);
const validator = value.validator();
validator.unsafeCast({ unionSelectKey: "a", unionValueKey: { b: false } });
type Test = typeof validator._TYPE;
)
const validator = value.validator()
validator.unsafeCast({ unionSelectKey: "a", unionValueKey: { b: false } })
type Test = typeof validator._TYPE
testOutput<Test, { unionSelectKey: "a"; unionValueKey: { b: boolean } }>()(
null,
);
});
)
})
test("list", () => {
const value = Value.list(
List.number(
@@ -289,12 +288,12 @@ describe("values", () => {
integer: false,
},
),
);
const validator = value.validator();
validator.unsafeCast([1, 2, 3]);
testOutput<typeof validator._TYPE, number[]>()(null);
});
});
)
const validator = value.validator()
validator.unsafeCast([1, 2, 3])
testOutput<typeof validator._TYPE, number[]>()(null)
})
})
describe("Builder List", () => {
test("obj", () => {
@@ -314,11 +313,11 @@ describe("Builder List", () => {
}),
},
),
);
const validator = value.validator();
validator.unsafeCast([{ test: true }]);
testOutput<typeof validator._TYPE, { test: boolean }[]>()(null);
});
)
const validator = value.validator()
validator.unsafeCast([{ test: true }])
testOutput<typeof validator._TYPE, { test: boolean }[]>()(null)
})
test("text", () => {
const value = Value.list(
List.text(
@@ -329,11 +328,11 @@ describe("Builder List", () => {
patterns: [],
},
),
);
const validator = value.validator();
validator.unsafeCast(["test", "text"]);
testOutput<typeof validator._TYPE, string[]>()(null);
});
)
const validator = value.validator()
validator.unsafeCast(["test", "text"])
testOutput<typeof validator._TYPE, string[]>()(null)
})
test("number", () => {
const value = Value.list(
List.number(
@@ -342,12 +341,12 @@ describe("Builder List", () => {
},
{ integer: true },
),
);
const validator = value.validator();
validator.unsafeCast([12, 45]);
testOutput<typeof validator._TYPE, number[]>()(null);
});
});
)
const validator = value.validator()
validator.unsafeCast([12, 45])
testOutput<typeof validator._TYPE, number[]>()(null)
})
})
describe("Nested nullable values", () => {
test("Testing text", () => {
@@ -358,15 +357,13 @@ describe("Nested nullable values", () => {
"If no name is provided, the name from config will be used",
required: false,
}),
});
const validator = value.validator();
validator.unsafeCast({ a: null });
validator.unsafeCast({ a: "test" });
expect(() => validator.unsafeCast({ a: 4 })).toThrowError();
testOutput<typeof validator._TYPE, { a: string | null | undefined }>()(
null,
);
});
})
const validator = value.validator()
validator.unsafeCast({ a: null })
validator.unsafeCast({ a: "test" })
expect(() => validator.unsafeCast({ a: 4 })).toThrowError()
testOutput<typeof validator._TYPE, { a: string | null | undefined }>()(null)
})
test("Testing number", () => {
const value = Config.of({
a: Value.number({
@@ -382,15 +379,13 @@ describe("Nested nullable values", () => {
step: null,
units: null,
}),
});
const validator = value.validator();
validator.unsafeCast({ a: null });
validator.unsafeCast({ a: 5 });
expect(() => validator.unsafeCast({ a: "4" })).toThrowError();
testOutput<typeof validator._TYPE, { a: number | null | undefined }>()(
null,
);
});
})
const validator = value.validator()
validator.unsafeCast({ a: null })
validator.unsafeCast({ a: 5 })
expect(() => validator.unsafeCast({ a: "4" })).toThrowError()
testOutput<typeof validator._TYPE, { a: number | null | undefined }>()(null)
})
test("Testing color", () => {
const value = Config.of({
a: Value.color({
@@ -400,15 +395,13 @@ describe("Nested nullable values", () => {
required: false,
warning: null,
}),
});
const validator = value.validator();
validator.unsafeCast({ a: null });
validator.unsafeCast({ a: "5" });
expect(() => validator.unsafeCast({ a: 4 })).toThrowError();
testOutput<typeof validator._TYPE, { a: string | null | undefined }>()(
null,
);
});
})
const validator = value.validator()
validator.unsafeCast({ a: null })
validator.unsafeCast({ a: "5" })
expect(() => validator.unsafeCast({ a: 4 })).toThrowError()
testOutput<typeof validator._TYPE, { a: string | null | undefined }>()(null)
})
test("Testing select", () => {
const value = Config.of({
a: Value.select({
@@ -421,7 +414,7 @@ describe("Nested nullable values", () => {
a: "A",
},
}),
});
})
const higher = Value.select({
name: "Temp Name",
description: "If no name is provided, the name from config will be used",
@@ -430,14 +423,14 @@ describe("Nested nullable values", () => {
values: {
a: "A",
},
}).build();
}).build()
const validator = value.validator();
validator.unsafeCast({ a: null });
validator.unsafeCast({ a: "a" });
expect(() => validator.unsafeCast({ a: "4" })).toThrowError();
testOutput<typeof validator._TYPE, { a: "a" | null | undefined }>()(null);
});
const validator = value.validator()
validator.unsafeCast({ a: null })
validator.unsafeCast({ a: "a" })
expect(() => validator.unsafeCast({ a: "4" })).toThrowError()
testOutput<typeof validator._TYPE, { a: "a" | null | undefined }>()(null)
})
test("Testing multiselect", () => {
const value = Config.of({
a: Value.multiselect({
@@ -453,11 +446,11 @@ describe("Nested nullable values", () => {
minLength: null,
maxLength: null,
}),
});
const validator = value.validator();
validator.unsafeCast({ a: [] });
validator.unsafeCast({ a: ["a"] });
expect(() => validator.unsafeCast({ a: "4" })).toThrowError();
testOutput<typeof validator._TYPE, { a: "a"[] }>()(null);
});
});
})
const validator = value.validator()
validator.unsafeCast({ a: [] })
validator.unsafeCast({ a: ["a"] })
expect(() => validator.unsafeCast({ a: "4" })).toThrowError()
testOutput<typeof validator._TYPE, { a: "a"[] }>()(null)
})
})