chore: Use the types from the fronted system

This commit is contained in:
BluJ
2023-02-13 16:58:04 -07:00
parent 2989347a55
commit 1c4a14d631
13 changed files with 252 additions and 273 deletions

View File

@@ -1,4 +1,4 @@
import { ConfigSpec, ValueSpecAny } from "../types.ts";
import { ConfigSpec, ValueSpec } from "../types/config-types.ts";
import { BuilderExtract, IBuilder } from "./builder.ts";
import { Value } from "./value.ts";
@@ -6,13 +6,13 @@ export class Config<A extends ConfigSpec> extends IBuilder<A> {
static empty() {
return new Config({});
}
static withValue<K extends string, B extends ValueSpecAny>(key: K, value: Value<B>) {
static withValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
return new Config({
[key]: value.build(),
} as { [key in K]: B });
}
static of<B extends { [key: string]: Value<C> }, C extends ValueSpecAny>(spec: B) {
static of<B extends { [key: string]: Value<C> }, C extends ValueSpec>(spec: B) {
// deno-lint-ignore no-explicit-any
const answer: { [K in keyof B]: BuilderExtract<B[K]> } = {} as any;
for (const key in spec) {
@@ -21,13 +21,13 @@ export class Config<A extends ConfigSpec> extends IBuilder<A> {
}
return new Config(answer);
}
withValue<K extends string, B extends ValueSpecAny>(key: K, value: Value<B>) {
withValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
return new Config({
...this.a,
[key]: value.build(),
} as A & { [key in K]: B });
}
addValue<K extends string, B extends ValueSpecAny>(key: K, value: Value<B>) {
addValue<K extends string, B extends ValueSpec>(key: K, value: Value<B>) {
return new Config({
...this.a,
[key]: value.build(),

View File

@@ -1,27 +1,27 @@
import { ConfigSpec, Tag, UniqueBy, ValueSpecList } from "../types.ts";
import { IBuilder } from "./builder.ts";
import { Config } from "./config.ts";
import { Default, NullableDefault, NumberSpec, StringSpec } from "./value.ts";
import { Description } from "./value.ts";
import * as T from "../types.ts";
import { Variants } from "./variants.ts";
import { ConfigSpec, UniqueBy, ValueSpecList, ValueSpecListOf } from "../types/config-types.ts";
export class List<A extends Tag<"list", ValueSpecList>> extends IBuilder<A> {
// deno-lint-ignore ban-types
static boolean<A extends Description & Default<boolean[]> & { range: string; spec: {} }>(a: A) {
return new List({
type: "list" as const,
subtype: "boolean" as const,
...a,
});
}
export class List<A extends ValueSpecList> extends IBuilder<A> {
// // deno-lint-ignore ban-types
// static boolean<A extends Description & Default<boolean[]> & { range: string; spec: {}; default: boolean }>(a: A) {
// return new List({
// type: "list" as const,
// subtype: "boolean" as const,
// ...a,
// });
// }
static string<A extends Description & Default<string[]> & { range: string; spec: StringSpec }>(a: A) {
return new List({
type: "list" as const,
subtype: "string" as const,
...a,
} as T.Tag<"list", T.Subtype<"string", T.WithDescription<T.WithDefault<T.ListSpec<T.ValueSpecString>, string[]>>>>);
} as ValueSpecListOf<"string">);
}
static number<A extends Description & Default<number[]> & { range: string; spec: NumberSpec }>(a: A) {
return new List({
@@ -75,7 +75,7 @@ export class List<A extends Tag<"list", ValueSpecList>> extends IBuilder<A> {
type: "list" as const,
subtype: "object" as const,
...value,
} as T.Tag<"list", T.Subtype<"object", T.WithDescription<T.WithNullableDefault<T.ListSpec<T.ValueSpecObject>, Record<string, unknown>[]>>>>);
} as ValueSpecListOf<"object">);
}
static union<
A extends Description &
@@ -84,15 +84,16 @@ export class List<A extends Tag<"list", ValueSpecList>> extends IBuilder<A> {
spec: {
tag: {
id: string;
name: null | string | undefined;
description: null | string | undefined;
name: string;
description: null | string;
"variant-names": {
[key: string]: string;
};
};
variants: Variants<B>;
"display-as": null | string | undefined;
"unique-by": null | UniqueBy | undefined;
"display-as": null | string;
"unique-by": UniqueBy;
default: string;
};
},
B extends { [key: string]: ConfigSpec }

View File

@@ -1,8 +1,8 @@
import { ValueSpecAny } from "../types.ts";
import { ValueSpec } from "../types/config-types.ts";
import { IBuilder } from "./builder.ts";
import { Description } from "./value.ts";
export class Pointer<A extends ValueSpecAny> extends IBuilder<A> {
export class Pointer<A extends ValueSpec> extends IBuilder<A> {
static packageTorKey<A extends Description & { "package-id": string; interface: string }>(a: A) {
return new Pointer({
type: "pointer" as const,
@@ -27,7 +27,9 @@ export class Pointer<A extends ValueSpecAny> extends IBuilder<A> {
...a,
});
}
static packageConfig<A extends Description & { "package-id": string; selector: string; multi: boolean }>(a: A) {
static packageConfig<
A extends Description & { "package-id": string; selector: string; multi: boolean; interface: string }
>(a: A) {
return new Pointer({
type: "pointer" as const,
subtype: "package" as const,
@@ -35,10 +37,13 @@ export class Pointer<A extends ValueSpecAny> extends IBuilder<A> {
...a,
});
}
static system<A extends Description & Record<string, unknown>>(a: A) {
static system<A extends Description & { "package-id": string; selector: string; multi: boolean; interface: string }>(
a: A
) {
return new Pointer({
type: "pointer" as const,
subtype: "system" as const,
target: "system" as const,
...a,
});
}

View File

@@ -1,10 +1,9 @@
import { ConfigSpec, Tag, ValueSpecAny, ValueSpecList } from "../types.ts";
import * as T from "../types.ts";
import { BuilderExtract, IBuilder } from "./builder.ts";
import { IBuilder } from "./builder.ts";
import { Config } from "./config.ts";
import { List } from "./list.ts";
import { Pointer } from "./pointer.ts";
import { Variants } from "./variants.ts";
import { ConfigSpec, ValueSpec, ValueSpecList, ValueSpecNumber, ValueSpecString } from "../types/config-types.ts";
export type DefaultString =
| string
@@ -37,10 +36,10 @@ export type StringSpec = {
| {}
);
export type NumberSpec = {
range: string | null;
integral: boolean | null;
range: string;
integral: boolean;
units: string | null;
placeholder: number | null;
placeholder: string | null;
};
export type Nullable = {
nullable: boolean;
@@ -52,7 +51,7 @@ type _UniqueBy =
any: _UniqueBy[];
};
export class Value<A extends ValueSpecAny> extends IBuilder<A> {
export class Value<A extends ValueSpec> extends IBuilder<A> {
static boolean<A extends Description & Default<boolean>>(a: A) {
return new Value({
type: "boolean" as const,
@@ -63,13 +62,13 @@ export class Value<A extends ValueSpecAny> extends IBuilder<A> {
return new Value({
type: "string" as const,
...a,
} as Tag<"string", T.WithDescription<T.WithNullableDefault<T.WithNullable<T.ValueSpecString>, DefaultString>>>);
} as ValueSpecString);
}
static number<A extends Description & NullableDefault<number> & Nullable & NumberSpec>(a: A) {
return new Value({
type: "number" as const,
...a,
} as Tag<"number", T.WithDescription<T.WithNullableDefault<T.WithNullable<T.ValueSpecNumber>, number>>>);
} as ValueSpecNumber);
}
static enum<
A extends Description &
@@ -103,15 +102,16 @@ export class Value<A extends ValueSpecAny> extends IBuilder<A> {
Default<string> & {
tag: {
id: string;
name: string | null;
name: string;
description: string | null;
warning: string | null;
"variant-names": {
[key: string]: string;
};
};
variants: Variants<B>;
"display-as": string | null;
"unique-by": _UniqueBy | null;
"unique-by": _UniqueBy;
},
B extends { [key: string]: ConfigSpec }
>(a: A) {
@@ -124,10 +124,10 @@ export class Value<A extends ValueSpecAny> extends IBuilder<A> {
});
}
static pointer<A extends ValueSpecAny>(a: Pointer<A>) {
static pointer<A extends ValueSpec>(a: Pointer<A>) {
return new Value(a.build());
}
static list<A extends List<B>, B extends Tag<"list", ValueSpecList>>(a: A) {
static list<A extends List<B>, B extends ValueSpecList>(a: A) {
return new Value(a.build());
}
}

View File

@@ -1,4 +1,4 @@
import { ConfigSpec } from "../types.ts";
import { ConfigSpec } from "../types/config-types.ts";
import { BuilderExtract, IBuilder } from "./builder.ts";
import { Config } from "./mod.ts";