mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: incr version
This commit is contained in:
@@ -63,10 +63,16 @@ export class Config<A extends InputSpec> extends IBuilder<A> {
|
|||||||
static empty() {
|
static empty() {
|
||||||
return new Config({});
|
return new Config({});
|
||||||
}
|
}
|
||||||
static withValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
|
static withValue<K extends string, B extends ValueSpec>(
|
||||||
|
key: K,
|
||||||
|
value: Value<B>
|
||||||
|
) {
|
||||||
return Config.empty().withValue(key, value);
|
return Config.empty().withValue(key, value);
|
||||||
}
|
}
|
||||||
static addValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
|
static addValue<K extends string, B extends ValueSpec>(
|
||||||
|
key: K,
|
||||||
|
value: Value<B>
|
||||||
|
) {
|
||||||
return Config.empty().withValue(key, value);
|
return Config.empty().withValue(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { BuilderExtract, IBuilder } from "./builder";
|
import { BuilderExtract, IBuilder } from "./builder";
|
||||||
import { Config } from "./config";
|
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";
|
import { guardAll } from "../../util";
|
||||||
/**
|
/**
|
||||||
* Used as a subtype of Value.list
|
* Used as a subtype of Value.list
|
||||||
|
|||||||
@@ -80,7 +80,10 @@ export class Variants<
|
|||||||
static empty() {
|
static empty() {
|
||||||
return Variants.of({});
|
return Variants.of({});
|
||||||
}
|
}
|
||||||
static withVariant<K extends string, B extends InputSpec>(key: K, value: Config<B>) {
|
static withVariant<K extends string, B extends InputSpec>(
|
||||||
|
key: K,
|
||||||
|
value: Config<B>
|
||||||
|
) {
|
||||||
return Variants.empty().withVariant(key, value);
|
return Variants.empty().withVariant(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export function isValueSpecListOf<S extends ListValueSpecType>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ListValueSpecString {
|
export interface ListValueSpecString {
|
||||||
type: 'string'
|
type: "string";
|
||||||
pattern: string | null;
|
pattern: string | null;
|
||||||
patternDescription: string | null;
|
patternDescription: string | null;
|
||||||
masked: boolean; // default = false
|
masked: boolean; // default = false
|
||||||
@@ -145,7 +145,7 @@ export interface ListValueSpecString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ListValueSpecNumber {
|
export interface ListValueSpecNumber {
|
||||||
type: 'number';
|
type: "number";
|
||||||
/** '[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules */
|
/** '[0,1]' (inclusive) OR '[0,*)' (right unbounded), normal math rules */
|
||||||
range: string;
|
range: string;
|
||||||
integral: boolean; // default = false
|
integral: boolean; // default = false
|
||||||
@@ -155,7 +155,7 @@ export interface ListValueSpecNumber {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ListValueSpecObject {
|
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 */
|
/** this is a mapped type of the config object at this level, replacing the object's values with specs on those values */
|
||||||
spec: InputSpec;
|
spec: InputSpec;
|
||||||
/** indicates whether duplicates can be permitted in the list */
|
/** indicates whether duplicates can be permitted in the list */
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "start-sdk",
|
"name": "start-sdk",
|
||||||
"version": "0.4.0-lib0.beta5",
|
"version": "0.4.0-lib0.beta7",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "start-sdk",
|
"name": "start-sdk",
|
||||||
"version": "0.4.0-lib0.beta5",
|
"version": "0.4.0-lib0.beta7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iarna/toml": "^2.2.5",
|
"@iarna/toml": "^2.2.5",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "start-sdk",
|
"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.",
|
"description": "For making the patterns that are wanted in making services for the startOS.",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"types": "./lib/index.d.ts",
|
"types": "./lib/index.d.ts",
|
||||||
|
|||||||
@@ -8,10 +8,15 @@ export async function writeConvertedFile(
|
|||||||
inputData: Promise<any> | any,
|
inputData: Promise<any> | any,
|
||||||
options: Parameters<typeof makeFileContent>[1]
|
options: Parameters<typeof makeFileContent>[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> | any, { startSdk = "start-sdk" } = {}) {
|
export default async function makeFileContent(
|
||||||
|
inputData: Promise<any> | any,
|
||||||
|
{ startSdk = "start-sdk" } = {}
|
||||||
|
) {
|
||||||
const outputLines: string[] = [];
|
const outputLines: string[] = [];
|
||||||
outputLines.push(`
|
outputLines.push(`
|
||||||
import {Config, Value, List, Variants} from '${startSdk}/config/builder';
|
import {Config, Value, List, Variants} from '${startSdk}/config/builder';
|
||||||
@@ -20,8 +25,13 @@ export default async function makeFileContent(inputData: Promise<any> | any, { s
|
|||||||
|
|
||||||
const namedConsts = new Set(["Config", "Value", "List"]);
|
const namedConsts = new Set(["Config", "Value", "List"]);
|
||||||
const configName = newConst("InputSpec", convertInputSpec(data));
|
const configName = newConst("InputSpec", convertInputSpec(data));
|
||||||
const configMatcherName = newConst("matchInputSpec", `${configName}.validator()`);
|
const configMatcherName = newConst(
|
||||||
outputLines.push(`export type InputSpec = typeof ${configMatcherName}._TYPE;`);
|
"matchInputSpec",
|
||||||
|
`${configName}.validator()`
|
||||||
|
);
|
||||||
|
outputLines.push(
|
||||||
|
`export type InputSpec = typeof ${configMatcherName}._TYPE;`
|
||||||
|
);
|
||||||
|
|
||||||
return outputLines.join("\n");
|
return outputLines.join("\n");
|
||||||
|
|
||||||
@@ -101,7 +111,10 @@ export default async function makeFileContent(inputData: Promise<any> | any, { s
|
|||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "enum": {
|
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(
|
const values = Object.fromEntries(
|
||||||
Array.from(allValueNames)
|
Array.from(allValueNames)
|
||||||
.filter(string.test)
|
.filter(string.test)
|
||||||
@@ -121,7 +134,10 @@ export default async function makeFileContent(inputData: Promise<any> | any, { s
|
|||||||
)} as const)`;
|
)} as const)`;
|
||||||
}
|
}
|
||||||
case "object": {
|
case "object": {
|
||||||
const specName = newConst(value.name + "_spec", convertInputSpec(value.spec));
|
const specName = newConst(
|
||||||
|
value.name + "_spec",
|
||||||
|
convertInputSpec(value.spec)
|
||||||
|
);
|
||||||
return `Value.object({
|
return `Value.object({
|
||||||
name: ${JSON.stringify(value.name || null)},
|
name: ${JSON.stringify(value.name || null)},
|
||||||
description: ${JSON.stringify(value.description || null)},
|
description: ${JSON.stringify(value.description || null)},
|
||||||
@@ -158,7 +174,9 @@ export default async function makeFileContent(inputData: Promise<any> | any, { s
|
|||||||
function convertList(value: any) {
|
function convertList(value: any) {
|
||||||
switch (value.subtype) {
|
switch (value.subtype) {
|
||||||
case "string": {
|
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,
|
name: value.name || null,
|
||||||
range: value.range || null,
|
range: value.range || null,
|
||||||
@@ -217,7 +235,10 @@ export default async function makeFileContent(inputData: Promise<any> | any, { s
|
|||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
case "object": {
|
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({
|
return `List.obj({
|
||||||
name: ${JSON.stringify(value.name || null)},
|
name: ${JSON.stringify(value.name || null)},
|
||||||
range: ${JSON.stringify(value.range || null)},
|
range: ${JSON.stringify(value.range || null)},
|
||||||
@@ -233,14 +254,19 @@ export default async function makeFileContent(inputData: Promise<any> | any, { s
|
|||||||
case "union": {
|
case "union": {
|
||||||
const variants = newConst(
|
const variants = newConst(
|
||||||
value.name + "_variants",
|
value.name + "_variants",
|
||||||
convertVariants(value.spec.variants, value.spec["variant-names"] || {})
|
convertVariants(
|
||||||
|
value.spec.variants,
|
||||||
|
value.spec["variant-names"] || {}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
const unionValueName = newConst(
|
const unionValueName = newConst(
|
||||||
value.name + "_union",
|
value.name + "_union",
|
||||||
`
|
`
|
||||||
Value.union({
|
Value.union({
|
||||||
name: ${JSON.stringify(value?.spec?.tag?.name || null)},
|
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)},
|
warning: ${JSON.stringify(value?.spec?.tag?.warning || null)},
|
||||||
required: ${JSON.stringify(!(value?.spec?.tag?.nullable || false))},
|
required: ${JSON.stringify(!(value?.spec?.tag?.nullable || false))},
|
||||||
default: ${JSON.stringify(value?.spec?.default || null)},
|
default: ${JSON.stringify(value?.spec?.default || null)},
|
||||||
@@ -271,11 +297,16 @@ export default async function makeFileContent(inputData: Promise<any> | any, { s
|
|||||||
throw new Error(`Unknown subtype "${value.subtype}"`);
|
throw new Error(`Unknown subtype "${value.subtype}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertVariants(variants: Record<string, unknown>, variantNames: Record<string, string>): string {
|
function convertVariants(
|
||||||
|
variants: Record<string, unknown>,
|
||||||
|
variantNames: Record<string, string>
|
||||||
|
): string {
|
||||||
let answer = "Variants.of({";
|
let answer = "Variants.of({";
|
||||||
for (const [key, value] of Object.entries(variants)) {
|
for (const [key, value] of Object.entries(variants)) {
|
||||||
const variantSpec = newConst(key, convertInputSpec(value));
|
const variantSpec = newConst(key, convertInputSpec(value));
|
||||||
answer += `"${key}": {name: "${variantNames[key] || key}", spec: ${variantSpec}},`;
|
answer += `"${key}": {name: "${
|
||||||
|
variantNames[key] || key
|
||||||
|
}", spec: ${variantSpec}},`;
|
||||||
}
|
}
|
||||||
return `${answer}})`;
|
return `${answer}})`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user