mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
chore: New sdk things
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ConfigSpec, ValueSpec } from "../../types/config-types";
|
||||
import { InputSpec, ValueSpec } from "../../types/config-types";
|
||||
import { typeFromProps } from "../../util";
|
||||
import { BuilderExtract, IBuilder } from "./builder";
|
||||
import { Value } from "./value";
|
||||
@@ -483,19 +483,19 @@ import { Value } from "./value";
|
||||
|
||||
```
|
||||
*/
|
||||
export class Config<A extends ConfigSpec> extends IBuilder<A> {
|
||||
export class Config<A extends InputSpec> extends IBuilder<A> {
|
||||
static empty() {
|
||||
return new Config({});
|
||||
}
|
||||
static withValue<K extends string, B extends ValueSpec>(
|
||||
key: K,
|
||||
value: Value<B>
|
||||
value: Value<B>,
|
||||
) {
|
||||
return Config.empty().withValue(key, value);
|
||||
}
|
||||
static addValue<K extends string, B extends ValueSpec>(
|
||||
key: K,
|
||||
value: Value<B>
|
||||
value: Value<B>,
|
||||
) {
|
||||
return Config.empty().withValue(key, value);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Default, NumberSpec, StringSpec } from "./value";
|
||||
import { Description } from "./value";
|
||||
import { Variants } from "./variants";
|
||||
import {
|
||||
ConfigSpec,
|
||||
InputSpec,
|
||||
UniqueBy,
|
||||
ValueSpecList,
|
||||
ValueSpecListOf,
|
||||
@@ -38,7 +38,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
Default<string[]> & {
|
||||
range: string;
|
||||
spec: StringSpec;
|
||||
}
|
||||
},
|
||||
>(a: A) {
|
||||
return new List({
|
||||
type: "list" as const,
|
||||
@@ -51,7 +51,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
Default<number[]> & {
|
||||
range: string;
|
||||
spec: NumberSpec;
|
||||
}
|
||||
},
|
||||
>(a: A) {
|
||||
return new List({
|
||||
type: "list" as const,
|
||||
@@ -69,7 +69,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
},
|
||||
>(a: A) {
|
||||
return new List({
|
||||
type: "list" as const,
|
||||
@@ -82,11 +82,11 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
Default<Record<string, unknown>[]> & {
|
||||
range: string;
|
||||
spec: {
|
||||
spec: Config<ConfigSpec>;
|
||||
spec: Config<InputSpec>;
|
||||
"display-as": null | string;
|
||||
"unique-by": null | UniqueBy;
|
||||
};
|
||||
}
|
||||
},
|
||||
>(a: A) {
|
||||
const { spec: previousSpec, ...rest } = a;
|
||||
const { spec: previousSpecSpec, ...restSpec } = previousSpec;
|
||||
@@ -121,13 +121,13 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
variants: Variants<{ [key: string]: ConfigSpec }>;
|
||||
variants: Variants<{ [key: string]: InputSpec }>;
|
||||
"display-as": null | string;
|
||||
"unique-by": UniqueBy;
|
||||
default: string;
|
||||
};
|
||||
},
|
||||
B extends string
|
||||
B extends string,
|
||||
>(a: A) {
|
||||
const { spec: previousSpec, ...rest } = a;
|
||||
const { variants: previousVariants, ...restSpec } = previousSpec;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Config } from "./config";
|
||||
import { List } from "./list";
|
||||
import { Variants } from "./variants";
|
||||
import {
|
||||
ConfigSpec,
|
||||
InputSpec,
|
||||
UniqueBy,
|
||||
ValueSpec,
|
||||
ValueSpecList,
|
||||
@@ -80,7 +80,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
A extends Description &
|
||||
NullableDefault<DefaultString> &
|
||||
Nullable &
|
||||
StringSpec
|
||||
StringSpec,
|
||||
>(a: A) {
|
||||
return new Value({
|
||||
type: "string" as const,
|
||||
@@ -88,7 +88,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
} as ValueSpecString);
|
||||
}
|
||||
static number<
|
||||
A extends Description & NullableDefault<number> & Nullable & NumberSpec
|
||||
A extends Description & NullableDefault<number> & Nullable & NumberSpec,
|
||||
>(a: A) {
|
||||
return new Value({
|
||||
type: "number" as const,
|
||||
@@ -100,7 +100,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
Default<string> & {
|
||||
values: readonly string[] | string[];
|
||||
"value-names": Record<string, string>;
|
||||
}
|
||||
},
|
||||
>(a: A) {
|
||||
return new Value({
|
||||
type: "enum" as const,
|
||||
@@ -115,9 +115,9 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
default: null | { [k: string]: unknown };
|
||||
"display-as": null | string;
|
||||
"unique-by": null | string;
|
||||
spec: Config<ConfigSpec>;
|
||||
spec: Config<InputSpec>;
|
||||
"value-names": Record<string, string>;
|
||||
}
|
||||
},
|
||||
>(a: A) {
|
||||
const { spec: previousSpec, ...rest } = a;
|
||||
const spec = previousSpec.build() as BuilderExtract<A["spec"]>;
|
||||
@@ -139,11 +139,11 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
variants: Variants<{ [key: string]: ConfigSpec }>;
|
||||
variants: Variants<{ [key: string]: InputSpec }>;
|
||||
"display-as": string | null;
|
||||
"unique-by": UniqueBy;
|
||||
},
|
||||
B extends string
|
||||
B extends string,
|
||||
>(a: A) {
|
||||
const { variants: previousVariants, ...rest } = a;
|
||||
const variants = previousVariants.build() as BuilderExtract<A["variants"]>;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ConfigSpec } from "../../types/config-types";
|
||||
import { InputSpec } from "../../types/config-types";
|
||||
import { BuilderExtract, IBuilder } from "./builder";
|
||||
import { Config } from ".";
|
||||
|
||||
@@ -39,12 +39,12 @@ import { Config } from ".";
|
||||
```
|
||||
*/
|
||||
export class Variants<
|
||||
A extends { [key: string]: ConfigSpec }
|
||||
A extends { [key: string]: InputSpec },
|
||||
> extends IBuilder<A> {
|
||||
static of<
|
||||
A extends {
|
||||
[key: string]: Config<ConfigSpec>;
|
||||
}
|
||||
[key: string]: Config<InputSpec>;
|
||||
},
|
||||
>(a: A) {
|
||||
const variants: { [K in keyof A]: BuilderExtract<A[K]> } = {} as any;
|
||||
for (const key in a) {
|
||||
@@ -56,17 +56,14 @@ export class Variants<
|
||||
static empty() {
|
||||
return Variants.of({});
|
||||
}
|
||||
static withVariant<K extends string, B extends ConfigSpec>(
|
||||
static withVariant<K extends string, B extends InputSpec>(
|
||||
key: K,
|
||||
value: Config<B>
|
||||
value: Config<B>,
|
||||
) {
|
||||
return Variants.empty().withVariant(key, value);
|
||||
}
|
||||
|
||||
withVariant<K extends string, B extends ConfigSpec>(
|
||||
key: K,
|
||||
value: Config<B>
|
||||
) {
|
||||
withVariant<K extends string, B extends InputSpec>(key: K, value: Config<B>) {
|
||||
return new Variants({
|
||||
...this.a,
|
||||
[key]: value.build(),
|
||||
|
||||
Reference in New Issue
Block a user