From 510074530f6da4f777920fc391c04920d1f7146d Mon Sep 17 00:00:00 2001 From: BluJ Date: Mon, 3 Apr 2023 10:19:58 -0600 Subject: [PATCH] chore: incr version --- lib/config/builder/config.ts | 10 +++++-- lib/config/builder/list.ts | 8 ++++- lib/config/builder/variants.ts | 5 +++- lib/config/config-types.ts | 6 ++-- package-lock.json | 4 +-- package.json | 2 +- scripts/oldSpecToBuilder.ts | 55 ++++++++++++++++++++++++++-------- 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/lib/config/builder/config.ts b/lib/config/builder/config.ts index 30f266e..9ebfa69 100644 --- a/lib/config/builder/config.ts +++ b/lib/config/builder/config.ts @@ -63,10 +63,16 @@ export class Config extends IBuilder { static empty() { return new Config({}); } - static withValue(key: K, value: Value) { + static withValue( + key: K, + value: Value + ) { return Config.empty().withValue(key, value); } - static addValue(key: K, value: Value) { + static addValue( + key: K, + value: Value + ) { return Config.empty().withValue(key, value); } diff --git a/lib/config/builder/list.ts b/lib/config/builder/list.ts index 901d67d..fb743d8 100644 --- a/lib/config/builder/list.ts +++ b/lib/config/builder/list.ts @@ -1,6 +1,12 @@ import { BuilderExtract, IBuilder } from "./builder"; import { Config } from "./config"; -import { InputSpec, ListValueSpecNumber, ListValueSpecString, UniqueBy, ValueSpecList } from "../config-types"; +import { + InputSpec, + ListValueSpecNumber, + ListValueSpecString, + UniqueBy, + ValueSpecList, +} from "../config-types"; import { guardAll } from "../../util"; /** * Used as a subtype of Value.list diff --git a/lib/config/builder/variants.ts b/lib/config/builder/variants.ts index 8efe5eb..1c92bb3 100644 --- a/lib/config/builder/variants.ts +++ b/lib/config/builder/variants.ts @@ -80,7 +80,10 @@ export class Variants< static empty() { return Variants.of({}); } - static withVariant(key: K, value: Config) { + static withVariant( + key: K, + value: Config + ) { return Variants.empty().withVariant(key, value); } diff --git a/lib/config/config-types.ts b/lib/config/config-types.ts index 9040bfe..8c6ded7 100644 --- a/lib/config/config-types.ts +++ b/lib/config/config-types.ts @@ -136,7 +136,7 @@ export function isValueSpecListOf( } export interface ListValueSpecString { - type: 'string' + type: "string"; pattern: string | null; patternDescription: string | null; masked: boolean; // default = false @@ -145,7 +145,7 @@ export interface ListValueSpecString { } export interface ListValueSpecNumber { - type: 'number'; + type: "number"; /** '[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules */ range: string; integral: boolean; // default = false @@ -155,7 +155,7 @@ export interface ListValueSpecNumber { } export interface ListValueSpecObject { - type: 'object'; + type: "object"; /** this is a mapped type of the config object at this level, replacing the object's values with specs on those values */ spec: InputSpec; /** indicates whether duplicates can be permitted in the list */ diff --git a/package-lock.json b/package-lock.json index 88afd5d..0729941 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "start-sdk", - "version": "0.4.0-lib0.beta5", + "version": "0.4.0-lib0.beta7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "start-sdk", - "version": "0.4.0-lib0.beta5", + "version": "0.4.0-lib0.beta7", "license": "MIT", "dependencies": { "@iarna/toml": "^2.2.5", diff --git a/package.json b/package.json index 1824921..44d2528 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "start-sdk", - "version": "0.4.0-lib0.beta6", + "version": "0.4.0-lib0.beta7", "description": "For making the patterns that are wanted in making services for the startOS.", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/scripts/oldSpecToBuilder.ts b/scripts/oldSpecToBuilder.ts index f84a251..5447655 100644 --- a/scripts/oldSpecToBuilder.ts +++ b/scripts/oldSpecToBuilder.ts @@ -8,10 +8,15 @@ export async function writeConvertedFile( inputData: Promise | any, options: Parameters[1] ) { - await fs.writeFile(file, await makeFileContent(inputData, options), (err) => console.error(err)); + await fs.writeFile(file, await makeFileContent(inputData, options), (err) => + console.error(err) + ); } -export default async function makeFileContent(inputData: Promise | any, { startSdk = "start-sdk" } = {}) { +export default async function makeFileContent( + inputData: Promise | any, + { startSdk = "start-sdk" } = {} +) { const outputLines: string[] = []; outputLines.push(` import {Config, Value, List, Variants} from '${startSdk}/config/builder'; @@ -20,8 +25,13 @@ export default async function makeFileContent(inputData: Promise | any, { s 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"); @@ -101,7 +111,10 @@ export default async function makeFileContent(inputData: Promise | any, { s )})`; } case "enum": { - const allValueNames = new Set([...(value?.["values"] || []), ...Object.keys(value?.["value-names"] || {})]); + const allValueNames = new Set([ + ...(value?.["values"] || []), + ...Object.keys(value?.["value-names"] || {}), + ]); const values = Object.fromEntries( Array.from(allValueNames) .filter(string.test) @@ -121,7 +134,10 @@ export default async function makeFileContent(inputData: Promise | any, { s )} as const)`; } case "object": { - const specName = newConst(value.name + "_spec", convertInputSpec(value.spec)); + const specName = newConst( + value.name + "_spec", + convertInputSpec(value.spec) + ); return `Value.object({ name: ${JSON.stringify(value.name || null)}, description: ${JSON.stringify(value.description || null)}, @@ -158,7 +174,9 @@ export default async function makeFileContent(inputData: Promise | any, { s function convertList(value: any) { switch (value.subtype) { case "string": { - return `List.${value?.spec?.textarea === true ? "textarea" : "string"}(${JSON.stringify( + return `List.${ + value?.spec?.textarea === true ? "textarea" : "string" + }(${JSON.stringify( { name: value.name || null, range: value.range || null, @@ -217,7 +235,10 @@ export default async function makeFileContent(inputData: Promise | any, { s )})`; } case "object": { - const specName = newConst(value.name + "_spec", convertInputSpec(value.spec.spec)); + const specName = newConst( + value.name + "_spec", + convertInputSpec(value.spec.spec) + ); return `List.obj({ name: ${JSON.stringify(value.name || null)}, range: ${JSON.stringify(value.range || null)}, @@ -233,14 +254,19 @@ export default async function makeFileContent(inputData: Promise | any, { s case "union": { const variants = newConst( value.name + "_variants", - convertVariants(value.spec.variants, value.spec["variant-names"] || {}) + convertVariants( + value.spec.variants, + value.spec["variant-names"] || {} + ) ); const unionValueName = newConst( value.name + "_union", ` Value.union({ name: ${JSON.stringify(value?.spec?.tag?.name || null)}, - description: ${JSON.stringify(value?.spec?.tag?.description || null)}, + description: ${JSON.stringify( + value?.spec?.tag?.description || null + )}, warning: ${JSON.stringify(value?.spec?.tag?.warning || null)}, required: ${JSON.stringify(!(value?.spec?.tag?.nullable || false))}, default: ${JSON.stringify(value?.spec?.default || null)}, @@ -271,11 +297,16 @@ export default async function makeFileContent(inputData: Promise | any, { s throw new Error(`Unknown subtype "${value.subtype}"`); } - function convertVariants(variants: Record, variantNames: Record): string { + function convertVariants( + variants: Record, + variantNames: Record + ): string { let answer = "Variants.of({"; for (const [key, value] of Object.entries(variants)) { const variantSpec = newConst(key, convertInputSpec(value)); - answer += `"${key}": {name: "${variantNames[key] || key}", spec: ${variantSpec}},`; + answer += `"${key}": {name: "${ + variantNames[key] || key + }", spec: ${variantSpec}},`; } return `${answer}})`; }