mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-01 21:13:11 +00:00
wip: Working so far
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { _ } from "../../util";
|
||||
export class IBuilder<A> {
|
||||
protected constructor(readonly a: A) {}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { InputSpec, ValueSpec } from "../configTypes";
|
||||
import { typeFromProps } from "../../util";
|
||||
import { BuilderExtract, IBuilder } from "./builder";
|
||||
import { Value } from "./value";
|
||||
import { _ } from "../../util";
|
||||
|
||||
/**
|
||||
* Configs are the specs that are used by the os configuration form for this service.
|
||||
|
||||
@@ -10,11 +10,17 @@ import {
|
||||
ValueSpecDatetime,
|
||||
ValueSpecList,
|
||||
ValueSpecNumber,
|
||||
ValueSpecSelect,
|
||||
ValueSpecText,
|
||||
ValueSpecTextarea,
|
||||
} from "../configTypes";
|
||||
import { guardAll } from "../../util";
|
||||
import { DefaultString } from "../configTypes";
|
||||
import { _ } from "../../util";
|
||||
|
||||
function flatten<A>(a: A): _<A> {
|
||||
return a as _<A>;
|
||||
}
|
||||
/**
|
||||
* A value is going to be part of the form in the FE of the OS.
|
||||
* Something like a boolean, a string, a number, etc.
|
||||
@@ -40,179 +46,146 @@ const username = Value.string({
|
||||
export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
static toggle(a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
default?: boolean | null;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
default: boolean | null;
|
||||
}) {
|
||||
return new Value({
|
||||
description: null,
|
||||
warning: null,
|
||||
default: null,
|
||||
type: "toggle" as const,
|
||||
...a,
|
||||
});
|
||||
}
|
||||
static text(a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
required: boolean;
|
||||
default?: DefaultString | null;
|
||||
/** Default = false */
|
||||
masked?: boolean;
|
||||
placeholder?: string | null;
|
||||
minLength?: number | null;
|
||||
maxLength?: number | null;
|
||||
patterns?: Pattern[];
|
||||
/** Default = 'text' */
|
||||
inputmode?: ValueSpecText["inputmode"];
|
||||
}) {
|
||||
static text<
|
||||
A extends {
|
||||
name: string;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
required: boolean;
|
||||
default: DefaultString | null;
|
||||
/** Default = false */
|
||||
masked: boolean;
|
||||
placeholder: string | null;
|
||||
minLength: number | null;
|
||||
maxLength: number | null;
|
||||
patterns: Pattern[];
|
||||
/** Default = 'text' */
|
||||
inputmode: ValueSpecText["inputmode"];
|
||||
},
|
||||
>(a: A) {
|
||||
return new Value({
|
||||
type: "text" as const,
|
||||
default: null,
|
||||
description: null,
|
||||
warning: null,
|
||||
masked: false,
|
||||
placeholder: null,
|
||||
minLength: null,
|
||||
maxLength: null,
|
||||
patterns: [],
|
||||
inputmode: "text",
|
||||
...a,
|
||||
});
|
||||
}
|
||||
static textarea(a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
required: boolean;
|
||||
minLength?: number | null;
|
||||
maxLength?: number | null;
|
||||
placeholder?: string | null;
|
||||
minLength: number | null;
|
||||
maxLength: number | null;
|
||||
placeholder: string | null;
|
||||
}) {
|
||||
return new Value({
|
||||
description: null,
|
||||
warning: null,
|
||||
minLength: null,
|
||||
maxLength: null,
|
||||
placeholder: null,
|
||||
type: "textarea" as const,
|
||||
...a,
|
||||
} as ValueSpecTextarea);
|
||||
}
|
||||
static number(a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
required: boolean;
|
||||
default?: number | null;
|
||||
min?: number | null;
|
||||
max?: number | null;
|
||||
/** Default = '1' */
|
||||
step?: string | null;
|
||||
integer: boolean;
|
||||
units?: string | null;
|
||||
placeholder?: string | null;
|
||||
}) {
|
||||
static number<
|
||||
A extends {
|
||||
name: string;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
required: boolean;
|
||||
default: number | null;
|
||||
min: number | null;
|
||||
max: number | null;
|
||||
/** Default = '1' */
|
||||
step: string | null;
|
||||
integer: boolean;
|
||||
units: string | null;
|
||||
placeholder: string | null;
|
||||
},
|
||||
>(a: A) {
|
||||
return new Value({
|
||||
type: "number" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
default: null,
|
||||
min: null,
|
||||
max: null,
|
||||
step: null,
|
||||
units: null,
|
||||
placeholder: null,
|
||||
...a,
|
||||
} as ValueSpecNumber);
|
||||
});
|
||||
}
|
||||
static color(a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
required: boolean;
|
||||
default?: number | null;
|
||||
}) {
|
||||
static color<
|
||||
A extends {
|
||||
name: string;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
required: boolean;
|
||||
default: string | null;
|
||||
},
|
||||
>(a: A) {
|
||||
return new Value({
|
||||
type: "color" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
default: null,
|
||||
...a,
|
||||
} as ValueSpecColor);
|
||||
});
|
||||
}
|
||||
static datetime(a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
required: boolean;
|
||||
/** Default = 'datetime-local' */
|
||||
inputmode?: ValueSpecDatetime["inputmode"];
|
||||
min?: string | null;
|
||||
max?: string | null;
|
||||
step?: string | null;
|
||||
default?: number | null;
|
||||
inputmode: ValueSpecDatetime["inputmode"];
|
||||
min: string | null;
|
||||
max: string | null;
|
||||
step: string | null;
|
||||
default: string | null;
|
||||
}) {
|
||||
return new Value({
|
||||
type: "datetime" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
inputmode: "datetime-local",
|
||||
min: null,
|
||||
max: null,
|
||||
step: null,
|
||||
default: null,
|
||||
...a,
|
||||
} as ValueSpecDatetime);
|
||||
});
|
||||
}
|
||||
static select<B extends Record<string, string>>(a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
required: boolean;
|
||||
default?: string | null;
|
||||
values: B;
|
||||
}) {
|
||||
static select<
|
||||
A extends {
|
||||
name: string;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
required: boolean;
|
||||
default: string | null;
|
||||
values: { [key: string]: string };
|
||||
},
|
||||
>(a: A) {
|
||||
return new Value({
|
||||
description: null,
|
||||
warning: null,
|
||||
default: null,
|
||||
type: "select" as const,
|
||||
...a,
|
||||
});
|
||||
}
|
||||
static multiselect<Values extends Record<string, string>>(a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
default: string[];
|
||||
values: Values;
|
||||
minLength?: number | null;
|
||||
maxLength?: number | null;
|
||||
}) {
|
||||
static multiselect<
|
||||
A extends {
|
||||
name: string;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
default: string[];
|
||||
values: Values;
|
||||
minLength: number | null;
|
||||
maxLength: number | null;
|
||||
},
|
||||
Values extends Record<string, string>,
|
||||
>(a: A) {
|
||||
return new Value({
|
||||
type: "multiselect" as const,
|
||||
minLength: null,
|
||||
maxLength: null,
|
||||
warning: null,
|
||||
description: null,
|
||||
...a,
|
||||
});
|
||||
}
|
||||
static object<Spec extends Config<InputSpec>>(
|
||||
a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
},
|
||||
previousSpec: Spec,
|
||||
) {
|
||||
const spec = previousSpec.build() as BuilderExtract<Spec>;
|
||||
return new Value({
|
||||
type: "object" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
...a,
|
||||
spec,
|
||||
});
|
||||
@@ -222,19 +195,16 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
>(
|
||||
a: {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
warning?: string | null;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
required: boolean;
|
||||
default?: string | null;
|
||||
default: string | null;
|
||||
},
|
||||
aVariants: V,
|
||||
) {
|
||||
const variants = aVariants.build() as BuilderExtract<V>;
|
||||
return new Value({
|
||||
type: "union" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
default: null,
|
||||
...a,
|
||||
variants,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user