chore: Update the builder to ignore the original naming

This commit is contained in:
BluJ
2023-04-30 15:00:20 -06:00
parent ec7f8beac8
commit cb89f3a65f
3 changed files with 24 additions and 23 deletions

View File

@@ -15,5 +15,4 @@
- run the script `npm run buildOutput` to make the output.ts - run the script `npm run buildOutput` to make the output.ts
- Copy this whole file into startos/procedures/config/spec.ts - Copy this whole file into startos/procedures/config/spec.ts
- rename `inputSpec` -> `configSpec` and `InputSpec` -> `ConfigSpec`
- Fix all the TODO - Fix all the TODO

View File

@@ -5,7 +5,7 @@ import {
unionValueKey, unionValueKey,
} from "../config/configTypes" } from "../config/configTypes"
import { deepMerge } from "../util" import { deepMerge } from "../util"
import { InputSpec, matchInputSpec } from "./output" import { ConfigSpec, matchConfigSpec } from "./output"
import * as _I from "../index" import * as _I from "../index"
import { camelCase } from "../../scripts/oldSpecToBuilder" import { camelCase } from "../../scripts/oldSpecToBuilder"
@@ -19,40 +19,40 @@ export function testOutput<A, B>(): (c: IfEquals<A, B>) => null {
} }
/// Testing the types of the input spec /// Testing the types of the input spec
testOutput<InputSpec["rpc"]["enable"], boolean>()(null) testOutput<ConfigSpec["rpc"]["enable"], boolean>()(null)
testOutput<InputSpec["rpc"]["username"], string>()(null) testOutput<ConfigSpec["rpc"]["username"], string>()(null)
testOutput<InputSpec["rpc"]["username"], string>()(null) testOutput<ConfigSpec["rpc"]["username"], string>()(null)
testOutput<InputSpec["rpc"]["advanced"]["auth"], string[]>()(null) testOutput<ConfigSpec["rpc"]["advanced"]["auth"], string[]>()(null)
testOutput< testOutput<
InputSpec["rpc"]["advanced"]["serialversion"], ConfigSpec["rpc"]["advanced"]["serialversion"],
"segwit" | "non-segwit" "segwit" | "non-segwit"
>()(null) >()(null)
testOutput<InputSpec["rpc"]["advanced"]["servertimeout"], number>()(null) testOutput<ConfigSpec["rpc"]["advanced"]["servertimeout"], number>()(null)
testOutput< testOutput<
InputSpec["advanced"]["peers"]["addnode"][0]["hostname"], ConfigSpec["advanced"]["peers"]["addnode"][0]["hostname"],
string | null | undefined string | null | undefined
>()(null) >()(null)
testOutput< testOutput<
InputSpec["testListUnion"][0]["union"][UnionValueKey]["name"], ConfigSpec["testListUnion"][0]["union"][UnionValueKey]["name"],
string string
>()(null) >()(null)
testOutput<InputSpec["testListUnion"][0]["union"][UnionSelectKey], "lnd">()( testOutput<ConfigSpec["testListUnion"][0]["union"][UnionSelectKey], "lnd">()(
null, null,
) )
testOutput<InputSpec["mediasources"], Array<"filebrowser" | "nextcloud">>()( testOutput<ConfigSpec["mediasources"], Array<"filebrowser" | "nextcloud">>()(
null, 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<ConfigSpec["rpc"]["enable"], string>()(null)
// prettier-ignore // prettier-ignore
// @ts-expect-error Expect that the string is the one above // @ts-expect-error Expect that the string is the one above
testOutput<InputSpec["testListUnion"][0][UnionSelectKey][UnionSelectKey], "unionSelectKey">()(null); testOutput<ConfigSpec["testListUnion"][0][UnionSelectKey][UnionSelectKey], "unionSelectKey">()(null);
/// Here we test the output of the matchInputSpec function /// Here we test the output of the matchConfigSpec function
describe("Inputs", () => { describe("Inputs", () => {
const validInput: InputSpec = { const validInput: ConfigSpec = {
mediasources: ["filebrowser"], mediasources: ["filebrowser"],
testListUnion: [ testListUnion: [
{ {
@@ -107,24 +107,24 @@ describe("Inputs", () => {
} }
test("test valid input", () => { test("test valid input", () => {
const output = matchInputSpec.unsafeCast(validInput) const output = matchConfigSpec.unsafeCast(validInput)
expect(output).toEqual(validInput) expect(output).toEqual(validInput)
}) })
test("test no longer care about the conversion of min/max and validating", () => { test("test no longer care about the conversion of min/max and validating", () => {
matchInputSpec.unsafeCast( matchConfigSpec.unsafeCast(
deepMerge({}, validInput, { rpc: { advanced: { threads: 0 } } }), deepMerge({}, validInput, { rpc: { advanced: { threads: 0 } } }),
) )
}) })
test("test errors should throw for number in string", () => { test("test errors should throw for number in string", () => {
expect(() => expect(() =>
matchInputSpec.unsafeCast( matchConfigSpec.unsafeCast(
deepMerge({}, validInput, { rpc: { enable: 2 } }), deepMerge({}, validInput, { rpc: { enable: 2 } }),
), ),
).toThrowError() ).toThrowError()
}) })
test("Test that we set serialversion to something not segwit or non-segwit", () => { test("Test that we set serialversion to something not segwit or non-segwit", () => {
expect(() => expect(() =>
matchInputSpec.unsafeCast( matchConfigSpec.unsafeCast(
deepMerge({}, validInput, { deepMerge({}, validInput, {
rpc: { advanced: { serialversion: "testing" } }, rpc: { advanced: { serialversion: "testing" } },
}), }),

View File

@@ -38,12 +38,14 @@ export default async function makeFileContentFromOld(
const data = await inputData const data = await inputData
const namedConsts = new Set(["Config", "Value", "List"]) const namedConsts = new Set(["Config", "Value", "List"])
const configName = newConst("InputSpec", convertInputSpec(data)) const configName = newConst("ConfigSpec", convertInputSpec(data))
const configMatcherName = newConst( const configMatcherName = newConst(
"matchInputSpec", "matchConfigSpec",
`${configName}.validator()`, `${configName}.validator()`,
) )
outputLines.push(`export type InputSpec = typeof ${configMatcherName}._TYPE;`) outputLines.push(
`export type ConfigSpec = typeof ${configMatcherName}._TYPE;`,
)
return outputLines.join("\n") return outputLines.join("\n")