From 70905aef149ca05983121103dc0cd77c0fece420 Mon Sep 17 00:00:00 2001 From: BluJ Date: Fri, 28 Apr 2023 16:29:16 -0600 Subject: [PATCH] chore: Update the config converts --- lib/test/configBuilder.test.ts | 23 +++++++------- lib/test/makeOutput.ts | 23 ++++++++++++-- lib/test/output.test.ts | 4 +++ scripts/oldSpecToBuilder.ts | 55 +++++++++++++++++----------------- 4 files changed, 63 insertions(+), 42 deletions(-) diff --git a/lib/test/configBuilder.test.ts b/lib/test/configBuilder.test.ts index 12dfe3b..c04f82a 100644 --- a/lib/test/configBuilder.test.ts +++ b/lib/test/configBuilder.test.ts @@ -333,18 +333,17 @@ describe("Builder List", () => { validator.unsafeCast(["test", "text"]) testOutput()(null) }) - test("number", () => { - const value = Value.list( - List.number( - { - name: "test", - }, - { integer: true }, - ), - ) - const validator = value.validator() - validator.unsafeCast([12, 45]) - testOutput()(null) + Value.multiselect({ + name: "Media Sources", + minLength: null, + maxLength: null, + default: ["nextcloud"], + description: "List of Media Sources to use with Jellyfin", + warning: null, + values: { + nextcloud: "NextCloud", + filebrowser: "File Browser", + }, }) }) diff --git a/lib/test/makeOutput.ts b/lib/test/makeOutput.ts index 9386833..5d0143b 100644 --- a/lib/test/makeOutput.ts +++ b/lib/test/makeOutput.ts @@ -1,9 +1,25 @@ import { oldSpecToBuilder } from "../../scripts/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: { type: "list", subtype: "union", @@ -406,6 +422,7 @@ oldSpecToBuilder( }, }, { - startSdk: "start-sdk/lib", + // convert this to `start-sdk/lib` for conversions + startSdk: "..", }, ) diff --git a/lib/test/output.test.ts b/lib/test/output.test.ts index b25d81e..328f02f 100644 --- a/lib/test/output.test.ts +++ b/lib/test/output.test.ts @@ -40,6 +40,9 @@ testOutput< testOutput()( null, ) +testOutput>()( + null, +) // @ts-expect-error Because enable should be a boolean testOutput()(null) @@ -50,6 +53,7 @@ testOutput { const validInput: InputSpec = { + mediasources: ["filebrowser"], testListUnion: [ { union: { [unionSelectKey]: "lnd", [unionValueKey]: { name: "string" } }, diff --git a/scripts/oldSpecToBuilder.ts b/scripts/oldSpecToBuilder.ts index 70817c0..73021db 100644 --- a/scripts/oldSpecToBuilder.ts +++ b/scripts/oldSpecToBuilder.ts @@ -211,6 +211,33 @@ export default async function makeFileContentFromOld( }, ${variants})` } 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)) return `Value.list(${list})` } @@ -271,33 +298,7 @@ export default async function makeFileContentFromOld( })})` } case "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 `${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, - )})` + return "/* error!! list.enum */" } case "object": { const specName = maybeNewConst(