chore: fix the old spec to build

This commit is contained in:
BluJ
2023-05-02 15:50:06 -06:00
parent 27145c3974
commit 7a3e1e90bd
2 changed files with 17 additions and 19 deletions

View File

@@ -384,19 +384,17 @@ describe("values", () => {
}) })
}) })
test("datetime", async () => { test("datetime", async () => {
const value = Value.dynamicDatetime<{ test: "a" }>( const value = Value.dynamicDatetime<{ test: "a" }>(async ({ utils }) => {
async ({ effects, utils }) => { ;async () => {
;async () => { ;(await utils.getOwnWrapperData("/test").once()) satisfies "a"
;(await utils.getOwnWrapperData("/test").once()) satisfies "a" }
}
return { return {
name: "Testing", name: "Testing",
required: { default: null }, required: { default: null },
inputmode: "date", inputmode: "date",
} }
}, })
)
const validator = value.validator const validator = value.validator
validator.unsafeCast("2021-01-01") validator.unsafeCast("2021-01-01")
validator.unsafeCast(null) validator.unsafeCast(null)

View File

@@ -2,13 +2,12 @@ import * as fs from "fs"
// https://stackoverflow.com/questions/2970525/converting-any-string-into-camel-case // https://stackoverflow.com/questions/2970525/converting-any-string-into-camel-case
export function camelCase(value: string) { export function camelCase(value: string) {
return value.replace( return value
/^([A-Z])|[\s-_](\w)/g, .replace(/([\(\)\[\]])/g, "")
function (match, p1, p2, offset) { .replace(/^([A-Z])|[\s-_](\w)/g, function (match, p1, p2, offset) {
if (p2) return p2.toUpperCase() if (p2) return p2.toUpperCase()
return p1.toLowerCase() return p1.toLowerCase()
}, })
)
} }
export async function oldSpecToBuilder( export async function oldSpecToBuilder(
@@ -41,6 +40,7 @@ export default async function makeFileContentFromOld(
import {WrapperData} from '${wrapperData}' import {WrapperData} from '${wrapperData}'
`) `)
const data = await inputData const data = await inputData
const hammerWrapperData = !nested ? ".withWrapperData()" : ""
const namedConsts = new Set(["Config", "Value", "List"]) const namedConsts = new Set(["Config", "Value", "List"])
const configName = newConst( const configName = newConst(
@@ -73,7 +73,7 @@ export default async function makeFileContentFromOld(
for (const [key, value] of Object.entries(data)) { for (const [key, value] of Object.entries(data)) {
const variableName = maybeNewConst(key, convertValueSpec(value)) const variableName = maybeNewConst(key, convertValueSpec(value))
answer += `${JSON.stringify(key)}: ${variableName},` answer += `${JSON.stringify(key)}: ${variableName}${hammerWrapperData},`
} }
return `${answer}}` return `${answer}}`
} }
@@ -364,7 +364,7 @@ export default async function makeFileContentFromOld(
value.name + "_list_config", value.name + "_list_config",
` `
Config.of({ Config.of({
"union": ${unionValueName} "union": ${unionValueName}${hammerWrapperData}
}) })
`, `,
) )