mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
chore: INput config to remove the transformer
This commit is contained in:
@@ -1,41 +1,161 @@
|
||||
import * as C from "./configTypesRaw";
|
||||
|
||||
export type ValueType = C.ValueType;
|
||||
|
||||
export type RequiredDeep<A> = A extends {}
|
||||
? { [K in keyof A]-?: RequiredDeep<A[K]> }
|
||||
: Required<A>;
|
||||
|
||||
export type InputSpec = Record<string, RequiredDeep<C.ValueSpec>>;
|
||||
|
||||
export type ValueSpec = RequiredDeep<C.ValueSpec>;
|
||||
|
||||
export type InputSpec = Record<string, ValueSpec>;
|
||||
export type ValueType =
|
||||
| "string"
|
||||
| "textarea"
|
||||
| "number"
|
||||
| "boolean"
|
||||
| "select"
|
||||
| "multiselect"
|
||||
| "list"
|
||||
| "object"
|
||||
| "file"
|
||||
| "union";
|
||||
export type ValueSpec = ValueSpecOf<ValueType>;
|
||||
/** core spec types. These types provide the metadata for performing validations */
|
||||
export type ValueSpecOf<T extends ValueType> = RequiredDeep<C.ValueSpecOf<T>>;
|
||||
|
||||
export type ValueSpecString = RequiredDeep<C.ValueSpecString>;
|
||||
export type ValueSpecTextarea = RequiredDeep<C.ValueSpecTextarea>;
|
||||
export type ValueSpecNumber = RequiredDeep<C.ValueSpecNumber>;
|
||||
export type ValueSpecSelect = RequiredDeep<C.ValueSpecSelect>;
|
||||
export type ValueSpecMultiselect = RequiredDeep<C.ValueSpecMultiselect>;
|
||||
export type ValueSpecBoolean = RequiredDeep<C.ValueSpecBoolean>;
|
||||
export type ValueSpecUnion = RequiredDeep<C.ValueSpecUnion>;
|
||||
export type ValueSpecFile = RequiredDeep<C.ValueSpecFile>;
|
||||
export type ValueSpecObject = RequiredDeep<C.ValueSpecObject>;
|
||||
export type WithStandalone = RequiredDeep<C.WithStandalone>;
|
||||
export type SelectBase = RequiredDeep<C.SelectBase>;
|
||||
export type ListValueSpecType = RequiredDeep<C.ListValueSpecType>;
|
||||
export type ValueSpecOf<T extends ValueType> = T extends "string"
|
||||
? ValueSpecString
|
||||
: T extends "number"
|
||||
? ValueSpecTextarea
|
||||
: T extends "textarea"
|
||||
? ValueSpecNumber
|
||||
: T extends "boolean"
|
||||
? ValueSpecBoolean
|
||||
: T extends "select"
|
||||
? ValueSpecSelect
|
||||
: T extends "multiselect"
|
||||
? ValueSpecMultiselect
|
||||
: T extends "list"
|
||||
? ValueSpecList
|
||||
: T extends "object"
|
||||
? ValueSpecObject
|
||||
: T extends "file"
|
||||
? ValueSpecFile
|
||||
: T extends "union"
|
||||
? ValueSpecUnion
|
||||
: never;
|
||||
|
||||
export interface ValueSpecString extends ListValueSpecString, WithStandalone {
|
||||
required: boolean;
|
||||
default: DefaultString | null;
|
||||
}
|
||||
export interface ValueSpecTextarea extends WithStandalone {
|
||||
type: "textarea";
|
||||
placeholder: string | null;
|
||||
required: boolean;
|
||||
}
|
||||
export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone {
|
||||
required: boolean;
|
||||
default: number | null;
|
||||
}
|
||||
export interface ValueSpecSelect extends SelectBase, WithStandalone {
|
||||
type: "select";
|
||||
required: boolean;
|
||||
default: string | null;
|
||||
}
|
||||
export interface ValueSpecMultiselect extends SelectBase, WithStandalone {
|
||||
type: "multiselect";
|
||||
/**'[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules */
|
||||
range: string;
|
||||
default: string[];
|
||||
}
|
||||
export interface ValueSpecBoolean extends WithStandalone {
|
||||
type: "boolean";
|
||||
default: boolean | null;
|
||||
}
|
||||
export interface ValueSpecUnion extends WithStandalone {
|
||||
type: "union";
|
||||
variants: Record<
|
||||
string,
|
||||
{
|
||||
name: string;
|
||||
spec: InputSpec;
|
||||
}
|
||||
>;
|
||||
required: boolean;
|
||||
default: string | null;
|
||||
}
|
||||
export interface ValueSpecFile extends WithStandalone {
|
||||
type: "file";
|
||||
extensions: string[];
|
||||
required: boolean;
|
||||
}
|
||||
export interface ValueSpecObject extends WithStandalone {
|
||||
type: "object";
|
||||
spec: InputSpec;
|
||||
}
|
||||
export interface WithStandalone {
|
||||
name: string;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
}
|
||||
export interface SelectBase {
|
||||
values: Record<string, string>;
|
||||
}
|
||||
export type ListValueSpecType = "string" | "number" | "object";
|
||||
/** represents a spec for the values of a list */
|
||||
export type ListValueSpecOf<T extends ListValueSpecType> = RequiredDeep<
|
||||
C.ListValueSpecOf<T>
|
||||
>;
|
||||
|
||||
export type ListValueSpecOf<T extends ListValueSpecType> = T extends "string"
|
||||
? ListValueSpecString
|
||||
: T extends "number"
|
||||
? ListValueSpecNumber
|
||||
: T extends "object"
|
||||
? ListValueSpecObject
|
||||
: never;
|
||||
/** represents a spec for a list */
|
||||
export type ValueSpecList = RequiredDeep<C.ValueSpecList>;
|
||||
export type ValueSpecListOf<T extends ListValueSpecType> = RequiredDeep<
|
||||
C.ValueSpecListOf<T>
|
||||
>;
|
||||
export type ValueSpecList = ValueSpecListOf<ListValueSpecType>;
|
||||
export interface ValueSpecListOf<T extends ListValueSpecType>
|
||||
extends WithStandalone {
|
||||
type: "list";
|
||||
spec: ListValueSpecOf<T>;
|
||||
range: string;
|
||||
default:
|
||||
| string[]
|
||||
| number[]
|
||||
| DefaultString[]
|
||||
| Record<string, unknown>[]
|
||||
| readonly string[]
|
||||
| readonly number[]
|
||||
| readonly DefaultString[]
|
||||
| readonly Record<string, unknown>[];
|
||||
}
|
||||
export interface ListValueSpecString {
|
||||
type: "string";
|
||||
pattern: string | null;
|
||||
patternDescription: string | null;
|
||||
masked: boolean;
|
||||
inputmode: "text" | "email" | "tel" | "url";
|
||||
placeholder: string | null;
|
||||
}
|
||||
export interface ListValueSpecNumber {
|
||||
type: "number";
|
||||
range: string;
|
||||
integral: boolean;
|
||||
units: string | null;
|
||||
placeholder: string | null;
|
||||
}
|
||||
export interface ListValueSpecObject {
|
||||
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 */
|
||||
uniqueBy: UniqueBy;
|
||||
/** this should be a handlebars template which can make use of the entire config which corresponds to 'spec' */
|
||||
displayAs: string | null;
|
||||
}
|
||||
export type UniqueBy =
|
||||
| null
|
||||
| string
|
||||
| {
|
||||
any: readonly UniqueBy[] | UniqueBy[];
|
||||
}
|
||||
| {
|
||||
all: readonly UniqueBy[] | UniqueBy[];
|
||||
};
|
||||
export type DefaultString =
|
||||
| string
|
||||
| {
|
||||
charset: string;
|
||||
len: number;
|
||||
};
|
||||
|
||||
// sometimes the type checker needs just a little bit of help
|
||||
export function isValueSpecListOf<S extends ListValueSpecType>(
|
||||
@@ -44,12 +164,6 @@ export function isValueSpecListOf<S extends ListValueSpecType>(
|
||||
): t is ValueSpecListOf<S> & { spec: ListValueSpecOf<S> } {
|
||||
return t.spec.type === s;
|
||||
}
|
||||
export type ListValueSpecString = RequiredDeep<C.ListValueSpecString>;
|
||||
export type ListValueSpecNumber = RequiredDeep<C.ListValueSpecNumber>;
|
||||
export type ListValueSpecObject = RequiredDeep<C.ListValueSpecObject>;
|
||||
export type UniqueBy = RequiredDeep<C.UniqueBy>;
|
||||
export type DefaultString = RequiredDeep<C.DefaultString>;
|
||||
|
||||
export const unionSelectKey = "unionSelectKey" as const;
|
||||
export type UnionSelectKey = typeof unionSelectKey;
|
||||
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
export {
|
||||
InputSpec,
|
||||
UnionSelectKey,
|
||||
UnionValueKey,
|
||||
unionSelectKey,
|
||||
unionValueKey,
|
||||
} from "./configTypes";
|
||||
|
||||
export type InputSpecRaw = Record<string, ValueSpec>;
|
||||
export type ValueType =
|
||||
| "string"
|
||||
| "textarea"
|
||||
| "number"
|
||||
| "boolean"
|
||||
| "select"
|
||||
| "multiselect"
|
||||
| "list"
|
||||
| "object"
|
||||
| "file"
|
||||
| "union";
|
||||
export type ValueSpec = ValueSpecOf<ValueType>;
|
||||
/** core spec types. These types provide the metadata for performing validations */
|
||||
export type ValueSpecOf<T extends ValueType> = T extends "string"
|
||||
? ValueSpecString
|
||||
: T extends "number"
|
||||
? ValueSpecTextarea
|
||||
: T extends "textarea"
|
||||
? ValueSpecNumber
|
||||
: T extends "boolean"
|
||||
? ValueSpecBoolean
|
||||
: T extends "select"
|
||||
? ValueSpecSelect
|
||||
: T extends "multiselect"
|
||||
? ValueSpecMultiselect
|
||||
: T extends "list"
|
||||
? ValueSpecList
|
||||
: T extends "object"
|
||||
? ValueSpecObject
|
||||
: T extends "file"
|
||||
? ValueSpecFile
|
||||
: T extends "union"
|
||||
? ValueSpecUnion
|
||||
: never;
|
||||
|
||||
export interface ValueSpecString extends ListValueSpecString, WithStandalone {
|
||||
required: boolean;
|
||||
default?: DefaultString | null;
|
||||
}
|
||||
export interface ValueSpecTextarea extends WithStandalone {
|
||||
type: "textarea";
|
||||
placeholder?: string | null;
|
||||
required: boolean;
|
||||
}
|
||||
export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone {
|
||||
required: boolean;
|
||||
default?: number | null;
|
||||
}
|
||||
export interface ValueSpecSelect extends SelectBase, WithStandalone {
|
||||
type: "select";
|
||||
required: boolean;
|
||||
default?: string | null;
|
||||
}
|
||||
export interface ValueSpecMultiselect extends SelectBase, WithStandalone {
|
||||
type: "multiselect";
|
||||
/**'[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules */
|
||||
range?: string;
|
||||
default?: string[];
|
||||
}
|
||||
export interface ValueSpecBoolean extends WithStandalone {
|
||||
type: "boolean";
|
||||
default?: boolean | null;
|
||||
}
|
||||
export interface ValueSpecUnion extends WithStandalone {
|
||||
type: "union";
|
||||
variants: Record<
|
||||
string,
|
||||
{
|
||||
name: string;
|
||||
spec: InputSpecRaw;
|
||||
}
|
||||
>;
|
||||
required: boolean;
|
||||
default?: string | null;
|
||||
}
|
||||
export interface ValueSpecFile extends WithStandalone {
|
||||
type: "file";
|
||||
extensions: string[];
|
||||
required: boolean;
|
||||
}
|
||||
export interface ValueSpecObject extends WithStandalone {
|
||||
type: "object";
|
||||
spec: InputSpecRaw;
|
||||
}
|
||||
export interface WithStandalone {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
}
|
||||
export interface SelectBase {
|
||||
values: Record<string, string>;
|
||||
}
|
||||
export type ListValueSpecType = "string" | "number" | "object";
|
||||
/** represents a spec for the values of a list */
|
||||
export type ListValueSpecOf<T extends ListValueSpecType> = T extends "string"
|
||||
? ListValueSpecString
|
||||
: T extends "number"
|
||||
? ListValueSpecNumber
|
||||
: T extends "object"
|
||||
? ListValueSpecObject
|
||||
: never;
|
||||
/** represents a spec for a list */
|
||||
export type ValueSpecList = ValueSpecListOf<ListValueSpecType>;
|
||||
export interface ValueSpecListOf<T extends ListValueSpecType>
|
||||
extends WithStandalone {
|
||||
type: "list";
|
||||
spec: ListValueSpecOf<T>;
|
||||
range?: string;
|
||||
default?:
|
||||
| string[]
|
||||
| number[]
|
||||
| DefaultString[]
|
||||
| Record<string, unknown>[]
|
||||
| readonly string[]
|
||||
| readonly number[]
|
||||
| readonly DefaultString[]
|
||||
| readonly Record<string, unknown>[];
|
||||
}
|
||||
export declare function isValueSpecListOf<S extends ListValueSpecType>(
|
||||
t: ValueSpecListOf<ListValueSpecType>,
|
||||
s: S
|
||||
): t is ValueSpecListOf<S> & {
|
||||
spec: ListValueSpecOf<S>;
|
||||
};
|
||||
export interface ListValueSpecString {
|
||||
type: "string";
|
||||
pattern?: string | null;
|
||||
patternDescription?: string | null;
|
||||
masked?: boolean;
|
||||
inputmode?: "text" | "email" | "tel" | "url";
|
||||
placeholder?: string | null;
|
||||
}
|
||||
export interface ListValueSpecNumber {
|
||||
type: "number";
|
||||
range?: string;
|
||||
integral: boolean;
|
||||
units?: string | null;
|
||||
placeholder?: string | null;
|
||||
}
|
||||
export interface ListValueSpecObject {
|
||||
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: InputSpecRaw;
|
||||
/** indicates whether duplicates can be permitted in the list */
|
||||
uniqueBy: UniqueBy;
|
||||
/** this should be a handlebars template which can make use of the entire config which corresponds to 'spec' */
|
||||
displayAs?: string | null;
|
||||
}
|
||||
export type UniqueBy =
|
||||
| null
|
||||
| string
|
||||
| {
|
||||
any: readonly UniqueBy[] | UniqueBy[];
|
||||
}
|
||||
| {
|
||||
all: readonly UniqueBy[] | UniqueBy[];
|
||||
};
|
||||
export type DefaultString =
|
||||
| string
|
||||
| {
|
||||
charset: string;
|
||||
len: number;
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
import camelCase from "lodash/camelCase";
|
||||
import * as fs from "fs";
|
||||
import { InputSpecRaw } from "./configTypesRaw";
|
||||
import * as C from "./configTypesRaw";
|
||||
import { InputSpec } from "./configTypes";
|
||||
import * as C from "./configTypes";
|
||||
|
||||
export async function specToBuilderFile(
|
||||
file: string,
|
||||
inputData: Promise<InputSpecRaw> | InputSpecRaw,
|
||||
inputData: Promise<InputSpec> | InputSpec,
|
||||
options: Parameters<typeof specToBuilder>[1]
|
||||
) {
|
||||
await fs.writeFile(file, await specToBuilder(inputData, options), (err) =>
|
||||
@@ -13,7 +13,7 @@ export async function specToBuilderFile(
|
||||
);
|
||||
}
|
||||
export async function specToBuilder(
|
||||
inputData: Promise<InputSpecRaw> | InputSpecRaw,
|
||||
inputData: Promise<InputSpec> | InputSpec,
|
||||
{ startSdk = "start-sdk" } = {}
|
||||
) {
|
||||
const outputLines: string[] = [];
|
||||
@@ -39,7 +39,7 @@ export async function specToBuilder(
|
||||
outputLines.push(`export const ${variableName} = ${data};`);
|
||||
return variableName;
|
||||
}
|
||||
function convertInputSpec(data: C.InputSpecRaw) {
|
||||
function convertInputSpec(data: C.InputSpec) {
|
||||
let answer = "Config.of({";
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
const variableName = newConst(key, convertValueSpec(value));
|
||||
@@ -153,7 +153,7 @@ export async function specToBuilder(
|
||||
string,
|
||||
{
|
||||
name: string;
|
||||
spec: C.InputSpecRaw;
|
||||
spec: C.InputSpec;
|
||||
}
|
||||
>
|
||||
): string {
|
||||
|
||||
Reference in New Issue
Block a user