mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: update the types to inference better
This commit is contained in:
@@ -7,9 +7,10 @@ export class Config<A extends ConfigSpec> extends IBuilder<A> {
|
||||
return new Config({});
|
||||
}
|
||||
static withValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
|
||||
return new Config({
|
||||
[key]: value.build(),
|
||||
} as { [key in K]: B });
|
||||
return Config.empty().withValue(key, value);
|
||||
}
|
||||
static addValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
|
||||
return Config.empty().withValue(key, value);
|
||||
}
|
||||
|
||||
static of<B extends { [key: string]: Value<C> }, C extends ValueSpec>(spec: B) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IBuilder } from "./builder.ts";
|
||||
import { BuilderExtract, IBuilder } from "./builder.ts";
|
||||
import { Config } from "./config.ts";
|
||||
import { Default, NullableDefault, NumberSpec, StringSpec } from "./value.ts";
|
||||
import { Description } from "./value.ts";
|
||||
@@ -50,19 +50,18 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
}
|
||||
static objectV<
|
||||
A extends Description &
|
||||
NullableDefault<Record<string, unknown>[]> & {
|
||||
Default<Record<string, unknown>[]> & {
|
||||
range: string;
|
||||
spec: {
|
||||
spec: Config<B>;
|
||||
spec: Config<ConfigSpec>;
|
||||
"display-as": null | string;
|
||||
"unique-by": null | UniqueBy;
|
||||
};
|
||||
},
|
||||
B extends ConfigSpec
|
||||
}
|
||||
>(a: A) {
|
||||
const { spec: previousSpec, ...rest } = a;
|
||||
const { spec: previousSpecSpec, ...restSpec } = previousSpec;
|
||||
const specSpec = previousSpecSpec.build();
|
||||
const specSpec = previousSpecSpec.build() as BuilderExtract<A["spec"]["spec"]>;
|
||||
const spec = {
|
||||
...restSpec,
|
||||
spec: specSpec,
|
||||
@@ -75,7 +74,7 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
type: "list" as const,
|
||||
subtype: "object" as const,
|
||||
...value,
|
||||
} as ValueSpecListOf<"object">);
|
||||
});
|
||||
}
|
||||
static union<
|
||||
A extends Description &
|
||||
@@ -90,17 +89,16 @@ export class List<A extends ValueSpecList> extends IBuilder<A> {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
variants: Variants<B>;
|
||||
variants: Variants<{ [key: string]: ConfigSpec }>;
|
||||
"display-as": null | string;
|
||||
"unique-by": UniqueBy;
|
||||
default: string;
|
||||
};
|
||||
},
|
||||
B extends { [key: string]: ConfigSpec }
|
||||
}
|
||||
>(a: A) {
|
||||
const { spec: previousSpec, ...rest } = a;
|
||||
const { variants: previousVariants, ...restSpec } = previousSpec;
|
||||
const variants = previousVariants.build();
|
||||
const variants = previousVariants.build() as BuilderExtract<A["spec"]["variants"]>;
|
||||
const spec = {
|
||||
...restSpec,
|
||||
variants,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IBuilder } from "./builder.ts";
|
||||
import { BuilderExtract, IBuilder } from "./builder.ts";
|
||||
import { Config } from "./config.ts";
|
||||
import { List } from "./list.ts";
|
||||
import { Pointer } from "./pointer.ts";
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
ValueSpec,
|
||||
ValueSpecList,
|
||||
ValueSpecNumber,
|
||||
ValueSpecObject,
|
||||
ValueSpecString,
|
||||
} from "../types/config-types.ts";
|
||||
|
||||
@@ -80,18 +81,20 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
...a,
|
||||
});
|
||||
}
|
||||
static objectV<
|
||||
A extends Description &
|
||||
NullableDefault<{ [k: string]: unknown }> & {
|
||||
"display-as": null | string;
|
||||
"unique-by": null | string;
|
||||
spec: Config<B>;
|
||||
"value-names": Record<string, string>;
|
||||
},
|
||||
B extends ConfigSpec
|
||||
static object<
|
||||
A extends {
|
||||
name: string;
|
||||
description: string | null;
|
||||
warning: string | null;
|
||||
default: null | { [k: string]: unknown };
|
||||
"display-as": null | string;
|
||||
"unique-by": null | string;
|
||||
spec: Config<ConfigSpec>;
|
||||
"value-names": Record<string, string>;
|
||||
}
|
||||
>(a: A) {
|
||||
const { spec: previousSpec, ...rest } = a;
|
||||
const spec = previousSpec.build();
|
||||
const spec = previousSpec.build() as BuilderExtract<A["spec"]>;
|
||||
return new Value({
|
||||
type: "object" as const,
|
||||
...rest,
|
||||
@@ -110,14 +113,13 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
[key: string]: string;
|
||||
};
|
||||
};
|
||||
variants: Variants<B>;
|
||||
variants: Variants<{ [key: string]: ConfigSpec }>;
|
||||
"display-as": string | null;
|
||||
"unique-by": UniqueBy;
|
||||
},
|
||||
B extends { [key: string]: ConfigSpec }
|
||||
}
|
||||
>(a: A) {
|
||||
const { variants: previousVariants, ...rest } = a;
|
||||
const variants = previousVariants.build();
|
||||
const variants = previousVariants.build() as BuilderExtract<A["variants"]>;
|
||||
return new Value({
|
||||
type: "union" as const,
|
||||
...rest,
|
||||
@@ -128,7 +130,7 @@ export class Value<A extends ValueSpec> extends IBuilder<A> {
|
||||
static pointer<A extends ValueSpec>(a: Pointer<A>) {
|
||||
return new Value(a.build());
|
||||
}
|
||||
static list<A extends List<B>, B extends ValueSpecList>(a: A) {
|
||||
static list<A extends List<ValueSpecList>>(a: A) {
|
||||
return new Value(a.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ export interface ListValueSpecEnum {
|
||||
export interface ListValueSpecObject {
|
||||
spec: ConfigSpec; // this is a mapped type of the config object at this level, replacing the object's values with specs on those values
|
||||
"unique-by": UniqueBy; // indicates whether duplicates can be permitted in the list
|
||||
"display-as"?: string; // this should be a handlebars template which can make use of the entire config which corresponds to 'spec'
|
||||
"display-as"?: null | string; // this should be a handlebars template which can make use of the entire config which corresponds to 'spec'
|
||||
}
|
||||
|
||||
export type UniqueBy =
|
||||
|
||||
@@ -52,7 +52,7 @@ type GuardList<A> =
|
||||
// prettier-ignore
|
||||
// deno-fmt-ignore
|
||||
type GuardPointer<A> =
|
||||
A extends {readonly type:TypePointer} ? {_UNKNOWN: "Pointer"} :
|
||||
A extends {readonly type:TypePointer} ? (string | null) :
|
||||
unknown
|
||||
// prettier-ignore
|
||||
// deno-fmt-ignore
|
||||
|
||||
Reference in New Issue
Block a user