mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: Update the config converts
This commit is contained in:
@@ -333,18 +333,17 @@ describe("Builder List", () => {
|
||||
validator.unsafeCast(["test", "text"])
|
||||
testOutput<typeof validator._TYPE, string[]>()(null)
|
||||
})
|
||||
test("number", () => {
|
||||
const value = Value.list(
|
||||
List.number(
|
||||
{
|
||||
name: "test",
|
||||
},
|
||||
{ integer: true },
|
||||
),
|
||||
)
|
||||
const validator = value.validator()
|
||||
validator.unsafeCast([12, 45])
|
||||
testOutput<typeof validator._TYPE, number[]>()(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",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -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: "..",
|
||||
},
|
||||
)
|
||||
|
||||
@@ -40,6 +40,9 @@ testOutput<
|
||||
testOutput<InputSpec["testListUnion"][0]["union"][UnionSelectKey], "lnd">()(
|
||||
null,
|
||||
)
|
||||
testOutput<InputSpec["mediasources"], Array<"filebrowser" | "nextcloud">>()(
|
||||
null,
|
||||
)
|
||||
|
||||
// @ts-expect-error Because enable should be a boolean
|
||||
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
|
||||
describe("Inputs", () => {
|
||||
const validInput: InputSpec = {
|
||||
mediasources: ["filebrowser"],
|
||||
testListUnion: [
|
||||
{
|
||||
union: { [unionSelectKey]: "lnd", [unionValueKey]: { name: "string" } },
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user