chore: Update the types

This commit is contained in:
BluJ
2023-04-11 11:54:57 -06:00
parent 9810c222dd
commit be2019fda1
13 changed files with 188 additions and 101 deletions

View File

@@ -8,9 +8,14 @@ export async function specToBuilderFile(
inputData: Promise<InputSpecRaw> | InputSpecRaw,
options: Parameters<typeof specToBuilder>[1]
) {
await fs.writeFile(file, await specToBuilder(inputData, options), (err) => console.error(err));
await fs.writeFile(file, await specToBuilder(inputData, options), (err) =>
console.error(err)
);
}
export async function specToBuilder(inputData: Promise<InputSpecRaw> | InputSpecRaw, { startSdk = "start-sdk" } = {}) {
export async function specToBuilder(
inputData: Promise<InputSpecRaw> | InputSpecRaw,
{ startSdk = "start-sdk" } = {}
) {
const outputLines: string[] = [];
outputLines.push(`
import {Config, Value, List, Variants} from '${startSdk}/config/builder';
@@ -19,8 +24,13 @@ export async function specToBuilder(inputData: Promise<InputSpecRaw> | InputSpec
const namedConsts = new Set(["Config", "Value", "List"]);
const configName = newConst("InputSpec", convertInputSpec(data));
const configMatcherName = newConst("matchInputSpec", `${configName}.validator()`);
outputLines.push(`export type InputSpec = typeof ${configMatcherName}._TYPE;`);
const configMatcherName = newConst(
"matchInputSpec",
`${configName}.validator()`
);
outputLines.push(
`export type InputSpec = typeof ${configMatcherName}._TYPE;`
);
return outputLines.join("\n");
@@ -61,7 +71,10 @@ export async function specToBuilder(inputData: Promise<InputSpecRaw> | InputSpec
}
case "union": {
const { variants, type, ...rest } = value;
const variantVariable = newConst(value.name + "_variants", convertVariants(variants));
const variantVariable = newConst(
value.name + "_variants",
convertVariants(variants)
);
return `Value.union(${JSON.stringify(rest)}, ${variantVariable})`;
}
@@ -116,7 +129,10 @@ export async function specToBuilder(inputData: Promise<InputSpecRaw> | InputSpec
})})`;
}
case "object": {
const specName = newConst(value.name + "_spec", convertInputSpec(spec.spec));
const specName = newConst(
value.name + "_spec",
convertInputSpec(spec.spec)
);
return `List.obj({
name: ${JSON.stringify(value.name || null)},
range: ${JSON.stringify(value.range || null)},