chore: Update the config converts

This commit is contained in:
BluJ
2023-04-28 16:29:16 -06:00
parent 539bf47bcc
commit 70905aef14
4 changed files with 63 additions and 42 deletions

View File

@@ -333,18 +333,17 @@ describe("Builder List", () => {
validator.unsafeCast(["test", "text"]) validator.unsafeCast(["test", "text"])
testOutput<typeof validator._TYPE, string[]>()(null) testOutput<typeof validator._TYPE, string[]>()(null)
}) })
test("number", () => { Value.multiselect({
const value = Value.list( name: "Media Sources",
List.number( minLength: null,
{ maxLength: null,
name: "test", default: ["nextcloud"],
}, description: "List of Media Sources to use with Jellyfin",
{ integer: true }, warning: null,
), values: {
) nextcloud: "NextCloud",
const validator = value.validator() filebrowser: "File Browser",
validator.unsafeCast([12, 45]) },
testOutput<typeof validator._TYPE, number[]>()(null)
}) })
}) })

View File

@@ -1,9 +1,25 @@
import { oldSpecToBuilder } from "../../scripts/oldSpecToBuilder" import { oldSpecToBuilder } from "../../scripts/oldSpecToBuilder"
oldSpecToBuilder( oldSpecToBuilder(
"./lib/test/output.ts", // Make the location // Make the location
"./lib/test/output.ts",
// Put the config here
{ {
// Put the config here mediasources: {
type: "list",
subtype: "enum",
name: "Media Sources",
description: "List of Media Sources to use with Jellyfin",
range: "[1,*)",
default: ["nextcloud"],
spec: {
values: ["nextcloud", "filebrowser"],
"value-names": {
nextcloud: "NextCloud",
filebrowser: "File Browser",
},
},
},
testListUnion: { testListUnion: {
type: "list", type: "list",
subtype: "union", subtype: "union",
@@ -406,6 +422,7 @@ oldSpecToBuilder(
}, },
}, },
{ {
startSdk: "start-sdk/lib", // convert this to `start-sdk/lib` for conversions
startSdk: "..",
}, },
) )

View File

@@ -40,6 +40,9 @@ testOutput<
testOutput<InputSpec["testListUnion"][0]["union"][UnionSelectKey], "lnd">()( testOutput<InputSpec["testListUnion"][0]["union"][UnionSelectKey], "lnd">()(
null, null,
) )
testOutput<InputSpec["mediasources"], Array<"filebrowser" | "nextcloud">>()(
null,
)
// @ts-expect-error Because enable should be a boolean // @ts-expect-error Because enable should be a boolean
testOutput<InputSpec["rpc"]["enable"], string>()(null) testOutput<InputSpec["rpc"]["enable"], string>()(null)
@@ -50,6 +53,7 @@ testOutput<InputSpec["testListUnion"][0][UnionSelectKey][UnionSelectKey], "union
/// Here we test the output of the matchInputSpec function /// Here we test the output of the matchInputSpec function
describe("Inputs", () => { describe("Inputs", () => {
const validInput: InputSpec = { const validInput: InputSpec = {
mediasources: ["filebrowser"],
testListUnion: [ testListUnion: [
{ {
union: { [unionSelectKey]: "lnd", [unionValueKey]: { name: "string" } }, union: { [unionSelectKey]: "lnd", [unionValueKey]: { name: "string" } },

View File

@@ -211,6 +211,33 @@ export default async function makeFileContentFromOld(
}, ${variants})` }, ${variants})`
} }
case "list": { case "list": {
if (value.subtype === "enum") {
const allValueNames = new Set([
...(value?.spec?.["values"] || []),
...Object.keys(value?.spec?.["value-names"] || {}),
])
const values = Object.fromEntries(
Array.from(allValueNames)
.filter(isString)
.map((key: string) => [
key,
value?.spec?.["value-names"]?.[key] ?? key,
]),
)
return `Value.multiselect(${JSON.stringify(
{
name: value.name || null,
minLength: null,
maxLength: null,
default: value.default ?? null,
description: value.description || null,
warning: value.warning || null,
values,
},
null,
2,
)})`
}
const list = maybeNewConst(value.name + "_list", convertList(value)) const list = maybeNewConst(value.name + "_list", convertList(value))
return `Value.list(${list})` return `Value.list(${list})`
} }
@@ -271,33 +298,7 @@ export default async function makeFileContentFromOld(
})})` })})`
} }
case "enum": { case "enum": {
const allValueNames = new Set( return "/* error!! list.enum */"
...(value?.spec?.["values"] || []),
...Object.keys(value?.spec?.["value-names"] || {}),
)
const values = Object.fromEntries(
Array.from(allValueNames)
.filter(isString)
.map((key: string) => [
key,
value?.spec?.["value-names"]?.[key] || key,
]),
)
return `${rangeToTodoComment(
value?.range,
)}Value.multiselect(${JSON.stringify(
{
name: value.name || null,
minLength: null,
maxLength: null,
default: value.default || null,
description: value.description || null,
warning: value.warning || null,
values,
},
null,
2,
)})`
} }
case "object": { case "object": {
const specName = maybeNewConst( const specName = maybeNewConst(