diff --git a/lib/config/builder/list.ts b/lib/config/builder/list.ts
index a2f162a..37fccad 100644
--- a/lib/config/builder/list.ts
+++ b/lib/config/builder/list.ts
@@ -36,7 +36,7 @@ export class List extends IBuilder {
name: string;
description: string | null;
warning: string | null;
- default: string[]
+ default: string[];
range: string;
spec: {
masked: boolean | null;
@@ -58,7 +58,7 @@ export class List extends IBuilder {
name: string;
description: string | null;
warning: string | null;
- default: string[]
+ default: string[];
range: string;
spec: {
range: string;
@@ -79,7 +79,7 @@ export class List extends IBuilder {
name: string;
description: string | null;
warning: string | null;
- default: Record[]
+ default: Record[];
range: string;
spec: {
spec: Config;
@@ -112,10 +112,12 @@ export class List extends IBuilder {
name: string;
description: string | null;
warning: string | null;
- default: Record[]
+ default: Record[];
range: string;
spec: {
- variants: Variants<{ [key: string]: { name: string, spec: InputSpec } }>;
+ variants: Variants<{
+ [key: string]: { name: string; spec: InputSpec };
+ }>;
displayAs: null | string;
uniqueBy: UniqueBy;
default: string;
diff --git a/lib/config/builder/value.ts b/lib/config/builder/value.ts
index c698d78..9f62f86 100644
--- a/lib/config/builder/value.ts
+++ b/lib/config/builder/value.ts
@@ -13,9 +13,9 @@ import {
export type DefaultString =
| string
| {
- charset: string | null | undefined;
- len: number;
- };
+ charset: string | null | undefined;
+ len: number;
+ };
/**
* A value is going to be part of the form in the FE of the OS.
@@ -43,10 +43,10 @@ export type DefaultString =
export class Value extends IBuilder {
static boolean<
A extends {
- name: string,
- description: string | null
- warning: string | null
- default: boolean | null
+ name: string;
+ description: string | null;
+ warning: string | null;
+ default: boolean | null;
}
>(a: A) {
return new Value({
@@ -56,11 +56,11 @@ export class Value extends IBuilder {
}
static string<
A extends {
- name: string,
- description: string | null
- warning: string | null
- nullable: boolean
- default: DefaultString | null
+ name: string;
+ description: string | null;
+ warning: string | null;
+ nullable: boolean;
+ default: DefaultString | null;
masked: boolean | null;
placeholder: string | null;
pattern: string | null;
@@ -75,11 +75,11 @@ export class Value extends IBuilder {
}
static number<
A extends {
- name: string
- description: string | null
- warning: string | null
- nullable: boolean
- default: number | null
+ name: string;
+ description: string | null;
+ warning: string | null;
+ nullable: boolean;
+ default: number | null;
range: string;
integral: boolean;
units: string | null;
@@ -93,11 +93,11 @@ export class Value extends IBuilder {
}
static select<
A extends {
- name: string
- description: string | null
- warning: string | null
- nullable: boolean
- default: string | null
+ name: string;
+ description: string | null;
+ warning: string | null;
+ nullable: boolean;
+ default: string | null;
values: Record;
}
>(a: A) {
@@ -108,12 +108,12 @@ export class Value extends IBuilder {
}
static multiselect<
A extends {
- name: string
- description: string | null
- warning: string | null
- default: string[]
+ name: string;
+ description: string | null;
+ warning: string | null;
+ default: string[];
values: Record;
- range: string
+ range: string;
}
>(a: A) {
return new Value({
@@ -139,11 +139,11 @@ export class Value extends IBuilder {
});
}
static union<
- A extends {
+ A extends {
name: string;
description: string | null;
warning: string | null;
- variants: Variants<{ [key: string]: { name: string, spec: InputSpec } }>;
+ variants: Variants<{ [key: string]: { name: string; spec: InputSpec } }>;
default: string;
}
>(a: A) {
diff --git a/lib/config/builder/variants.ts b/lib/config/builder/variants.ts
index 1ceee99..9be91ef 100644
--- a/lib/config/builder/variants.ts
+++ b/lib/config/builder/variants.ts
@@ -41,22 +41,25 @@ import { Config } from ".";
export class Variants<
A extends {
[key: string]: {
- name: string,
- spec: InputSpec
- }
+ name: string;
+ spec: InputSpec;
+ };
}
> extends IBuilder {
static of<
A extends {
- [key: string]: { name: string, spec: Config };
+ [key: string]: { name: string; spec: Config };
}
>(a: A) {
- const variants: { [K in keyof A]: { name: string, spec: BuilderExtract } } = {} as any;
+ const variants: {
+ [K in keyof A]: { name: string; spec: BuilderExtract };
+ } = {} as any;
for (const key in a) {
- const value = a[key]
+ const value = a[key];
variants[key] = {
- name: value.name, spec: value.spec.build() as any
- }
+ name: value.name,
+ spec: value.spec.build() as any,
+ };
}
return new Variants(variants);
}
diff --git a/lib/config/config-types.ts b/lib/config/config-types.ts
index eceecfe..903b305 100644
--- a/lib/config/config-types.ts
+++ b/lib/config/config-types.ts
@@ -48,9 +48,8 @@ export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone {
export interface ValueSpecSelect extends SelectBase, WithStandalone {
type: "select";
- nullable: boolean
+ nullable: boolean;
default: null | string;
-
}
export interface ValueSpecMultiselect extends SelectBase, WithStandalone {
@@ -67,7 +66,7 @@ export interface ValueSpecBoolean extends WithStandalone {
export interface ValueSpecUnion extends WithStandalone {
type: "union";
- variants: { [key: string]: { name: string, spec: InputSpec } };
+ variants: { [key: string]: { name: string; spec: InputSpec } };
default: null | string;
}
@@ -116,14 +115,14 @@ export interface ValueSpecListOf
spec: ListValueSpecOf;
range: string; // '[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules
default:
- | string[]
- | number[]
- | DefaultString[]
- | Record[]
- | readonly string[]
- | readonly number[]
- | readonly DefaultString[]
- | readonly Record[];
+ | string[]
+ | number[]
+ | DefaultString[]
+ | Record[]
+ | readonly string[]
+ | readonly number[]
+ | readonly DefaultString[]
+ | readonly Record[];
}
// sometimes the type checker needs just a little bit of help
@@ -166,7 +165,7 @@ export type UniqueBy =
| { all: readonly UniqueBy[] | UniqueBy[] };
export interface ListValueSpecUnion {
- variants: { [key: string]: { name: string, spec: InputSpec } };
+ variants: { [key: string]: { name: string; spec: InputSpec } };
/** this may be a handlebars template which can conditionally (on tag.id) make use of each union's entries, or if left blank will display as tag.id*/
displayAs: null | string;
uniqueBy: UniqueBy;
diff --git a/lib/util/propertiesMatcher.ts b/lib/util/propertiesMatcher.ts
index 26be210..6d81511 100644
--- a/lib/util/propertiesMatcher.ts
+++ b/lib/util/propertiesMatcher.ts
@@ -2,7 +2,16 @@ import * as matches from "ts-matches";
import { Parser } from "ts-matches";
import { InputSpec, ValueSpec as ValueSpecAny } from "../config/config-types";
-const { string, some, object, arrayOf, dictionary, unknown, number, literals, boolean, array } = matches
+const {
+ string,
+ some,
+ object,
+ dictionary,
+ unknown,
+ number,
+ literals,
+ boolean,
+} = matches;
type TypeBoolean = "boolean";
type TypeString = "string";
@@ -83,8 +92,8 @@ export type TypeFromProps =
const isType = object({ type: string });
const matchVariant = object({
name: string,
- spec: unknown
-})
+ spec: unknown,
+});
const recordString = dictionary([string, unknown]);
const matchDefault = object({ default: unknown });
const matchNullable = object({ nullable: literals(true) });
@@ -157,13 +166,13 @@ export function matchNumberWithRange(range: string) {
leftValue === "*"
? (_) => true
: left === "["
- ? (x) => x >= Number(leftValue)
- : (x) => x > Number(leftValue),
+ ? (x) => x >= Number(leftValue)
+ : (x) => x > Number(leftValue),
leftValue === "*"
? "any"
: left === "["
- ? `greaterThanOrEqualTo${leftValue}`
- : `greaterThan${leftValue}`
+ ? `greaterThanOrEqualTo${leftValue}`
+ : `greaterThan${leftValue}`
)
.validate(
// prettier-ignore
@@ -192,10 +201,7 @@ const isGenerator = object({
charset: string,
len: number,
}).test;
-function defaultNullable(
- parser: Parser,
- value: unknown
-) {
+function defaultNullable(parser: Parser, value: unknown) {
if (matchDefault.test(value)) {
if (isGenerator(value.default)) {
return parser.defaultTo(
@@ -257,7 +263,7 @@ export function guardAll(
}
case "select":
if (matchValues.test(value)) {
- const valueKeys = Object.keys(value.values)
+ const valueKeys = Object.keys(value.values);
return defaultNullable(
literals(valueKeys[0], ...valueKeys),
value
@@ -270,7 +276,7 @@ export function guardAll(
(matchRange.test(value) && matchNumberWithRange(value.range).test) ||
(() => true);
- const valueKeys = Object.keys(value.values)
+ const valueKeys = Object.keys(value.values);
return defaultNullable(
matches
.literals(valueKeys[0], ...valueKeys)
diff --git a/package-lock.json b/package-lock.json
index db1d8af..7953108 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "start-sdk",
- "version": "0.4.0-lib0.alpha6",
+ "version": "0.4.0-lib0.alpha9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "start-sdk",
- "version": "0.4.0-lib0.alpha6",
+ "version": "0.4.0-lib0.alpha9",
"license": "MIT",
"dependencies": {
"@iarna/toml": "^2.2.5",
diff --git a/scripts/oldSpecToBuilder.ts b/scripts/oldSpecToBuilder.ts
index 2a8e558..6817b3f 100644
--- a/scripts/oldSpecToBuilder.ts
+++ b/scripts/oldSpecToBuilder.ts
@@ -99,14 +99,14 @@ export default async function makeFileContent(
}
case "enum": {
const allValueNames = new Set(
- ...value?.spec?.["values"] || [],
+ ...(value?.spec?.["values"] || []),
...Object.keys(value?.spec?.["value-names"] || {})
);
const values = Object.fromEntries(
Array.from(allValueNames)
.filter(string.test)
- .map(key => [key, value?.spec?.["value-names"]?.[key] || key])
- )
+ .map((key) => [key, value?.spec?.["value-names"]?.[key] || key])
+ );
return `Value.select(${JSON.stringify(
{
name: value.name || null,
@@ -169,8 +169,7 @@ export default async function makeFileContent(
masked: value?.spec?.masked || null,
placeholder: value?.spec?.placeholder || null,
pattern: value?.spec?.pattern || null,
- patternDescription:
- value?.spec?.["pattern-description"] || null,
+ patternDescription: value?.spec?.["pattern-description"] || null,
textarea: value?.spec?.textarea || false,
},
default: value.default || null,
@@ -202,14 +201,14 @@ export default async function makeFileContent(
}
case "enum": {
const allValueNames = new Set(
- ...value?.spec?.["values"] || [],
+ ...(value?.spec?.["values"] || []),
...Object.keys(value?.spec?.["value-names"] || {})
);
const values = Object.fromEntries(
Array.from(allValueNames)
.filter(string.test)
- .map(key => [key, value?.spec?.["value-names"]?.[key] || key])
- )
+ .map((key) => [key, value?.spec?.["value-names"]?.[key] || key])
+ );
return `Value.multiselect(${JSON.stringify(
{
name: value.name || null,
@@ -233,9 +232,7 @@ export default async function makeFileContent(
range: ${JSON.stringify(value.range || null)},
spec: {
spec: ${specName},
- displayAs: ${JSON.stringify(
- value?.spec?.["display-as"] || null
- )},
+ displayAs: ${JSON.stringify(value?.spec?.["display-as"] || null)},
uniqueBy: ${JSON.stringify(value?.spec?.["unique-by"] || null)},
},
default: ${JSON.stringify(value.default || null)},
@@ -246,7 +243,10 @@ export default async function makeFileContent(
case "union": {
const variants = newConst(
value.name + "_variants",
- convertVariants(value.spec.variants, value.spec['variant-names'] || {})
+ convertVariants(
+ value.spec.variants,
+ value.spec["variant-names"] || {}
+ )
);
return `List.union(
{
@@ -255,11 +255,9 @@ export default async function makeFileContent(
spec: {
variants: ${variants},
displayAs: ${JSON.stringify(
- value?.spec?.["display-as"] || null
- )},
- uniqueBy: ${JSON.stringify(
- value?.spec?.["unique-by"] || null
- )},
+ value?.spec?.["display-as"] || null
+ )},
+ uniqueBy: ${JSON.stringify(value?.spec?.["unique-by"] || null)},
default: ${JSON.stringify(value?.spec?.default || null)},
},
default: ${JSON.stringify(value.default || null)},
@@ -272,11 +270,16 @@ export default async function makeFileContent(
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}})`;
}