mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
feat: Make config of the config top
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Config } from "../config/builder"
|
||||
import { ExtractConfigType } from "../config/builder/config"
|
||||
import { Config, ExtractConfigType } from "../config/builder/config"
|
||||
import { ActionMetaData, ActionResult, Effects, ExportedAction } from "../types"
|
||||
import { Utils, utils } from "../util"
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { AutoConfigure, DeepPartial, Effects, ExpectedExports } from "../types"
|
||||
import { Utils, deepEqual, deepMerge, utils } from "../util"
|
||||
import { Utils, utils } from "../util"
|
||||
import { deepEqual } from "../util/deepEqual"
|
||||
import { deepMerge } from "../util/deepMerge"
|
||||
|
||||
export type AutoConfigFrom<WD, Input, NestedConfigs> = {
|
||||
[key in keyof NestedConfigs & string]: (options: {
|
||||
|
||||
@@ -92,17 +92,19 @@ export class Config<Type extends Record<string, any>, WD> {
|
||||
return answer
|
||||
}
|
||||
|
||||
static of<Type extends Record<string, any>, WrapperData>(spec: {
|
||||
[K in keyof Type]: Value<Type[K], WrapperData>
|
||||
}) {
|
||||
const validatorObj = {} as {
|
||||
[K in keyof Type]: Parser<unknown, Type[K]>
|
||||
static of<WrapperData>() {
|
||||
return <Type extends Record<string, any>>(spec: {
|
||||
[K in keyof Type]: Value<Type[K], WrapperData>
|
||||
}) => {
|
||||
const validatorObj = {} as {
|
||||
[K in keyof Type]: Parser<unknown, Type[K]>
|
||||
}
|
||||
for (const key in spec) {
|
||||
validatorObj[key] = spec[key].validator
|
||||
}
|
||||
const validator = object(validatorObj)
|
||||
return new Config<Type, WrapperData>(spec, validator)
|
||||
}
|
||||
for (const key in spec) {
|
||||
validatorObj[key] = spec[key].validator
|
||||
}
|
||||
const validator = object(validatorObj)
|
||||
return new Config<Type, WrapperData>(spec, validator)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +116,7 @@ export class Config<Type extends Record<string, any>, WD> {
|
||||
required: false,
|
||||
})
|
||||
|
||||
return topConfig<WrapperData>()({
|
||||
return Config.of<WrapperData>()({
|
||||
myValue: a.withWrapperData(),
|
||||
})
|
||||
```
|
||||
@@ -123,9 +125,3 @@ export class Config<Type extends Record<string, any>, WD> {
|
||||
return this as any as Config<Type, NewWrapperData>
|
||||
}
|
||||
}
|
||||
|
||||
export function topConfig<WrapperData>() {
|
||||
return <Type extends Record<string, any>>(spec: {
|
||||
[K in keyof Type]: Value<Type[K], WrapperData>
|
||||
}) => Config.of<Type, WrapperData>(spec)
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ export class List<Type, WD> {
|
||||
required: false,
|
||||
})
|
||||
|
||||
return topConfig<WrapperData>()({
|
||||
return Config.of<WrapperData>()({
|
||||
myValue: a.withWrapperData(),
|
||||
})
|
||||
```
|
||||
|
||||
@@ -675,7 +675,7 @@ export class Value<Type, WD> {
|
||||
required: false,
|
||||
})
|
||||
|
||||
return topConfig<WrapperData>()({
|
||||
return Config.of<WrapperData>()({
|
||||
myValue: a.withWrapperData(),
|
||||
})
|
||||
```
|
||||
|
||||
@@ -65,20 +65,18 @@ export class Variants<Type, WD> {
|
||||
static of<
|
||||
TypeMap extends Record<string, Record<string, any>>,
|
||||
WrapperData,
|
||||
ConfigType,
|
||||
TypeOut = {
|
||||
[K in keyof TypeMap & string]: {
|
||||
unionSelectKey: K
|
||||
unionValueKey: TypeMap[K]
|
||||
}
|
||||
}[keyof TypeMap & string],
|
||||
>(a: {
|
||||
[K in keyof TypeMap]: {
|
||||
name: string
|
||||
spec: Config<TypeMap[K], WrapperData>
|
||||
}
|
||||
}) {
|
||||
type TypeOut = {
|
||||
[K in keyof TypeMap & string]: {
|
||||
unionSelectKey: K
|
||||
unionValueKey: TypeMap[K]
|
||||
}
|
||||
}[keyof TypeMap & string]
|
||||
|
||||
const validator = anyOf(
|
||||
...Object.entries(a).map(([name, { spec }]) =>
|
||||
object({
|
||||
@@ -111,7 +109,7 @@ export class Variants<Type, WD> {
|
||||
required: false,
|
||||
})
|
||||
|
||||
return topConfig<WrapperData>()({
|
||||
return Config.of<WrapperData>()({
|
||||
myValue: a.withWrapperData(),
|
||||
})
|
||||
```
|
||||
|
||||
@@ -11,7 +11,7 @@ describe("builder tests", () => {
|
||||
test("text", async () => {
|
||||
const bitcoinPropertiesBuilt: {
|
||||
"peer-tor-address": ValueSpec
|
||||
} = await Config.of({
|
||||
} = await Config.of<unknown>()({
|
||||
"peer-tor-address": Value.text({
|
||||
name: "Peer tor address",
|
||||
description: "The Tor address of the peer interface",
|
||||
@@ -234,7 +234,7 @@ describe("values", () => {
|
||||
description: null,
|
||||
warning: null,
|
||||
},
|
||||
Config.of({
|
||||
Config.of<null>()({
|
||||
a: Value.toggle({
|
||||
name: "test",
|
||||
description: null,
|
||||
@@ -259,7 +259,7 @@ describe("values", () => {
|
||||
Variants.of({
|
||||
a: {
|
||||
name: "a",
|
||||
spec: Config.of({
|
||||
spec: Config.of<unknown>()({
|
||||
b: Value.toggle({
|
||||
name: "b",
|
||||
description: null,
|
||||
@@ -512,7 +512,7 @@ describe("values", () => {
|
||||
Variants.of({
|
||||
a: {
|
||||
name: "a",
|
||||
spec: Config.of({
|
||||
spec: Config.of<unknown>()({
|
||||
b: Value.toggle({
|
||||
name: "b",
|
||||
description: null,
|
||||
@@ -523,7 +523,7 @@ describe("values", () => {
|
||||
},
|
||||
b: {
|
||||
name: "b",
|
||||
spec: Config.of({
|
||||
spec: Config.of<unknown>()({
|
||||
b: Value.toggle({
|
||||
name: "b",
|
||||
description: null,
|
||||
@@ -584,7 +584,7 @@ describe("Builder List", () => {
|
||||
name: "test",
|
||||
},
|
||||
{
|
||||
spec: Config.of({
|
||||
spec: Config.of<unknown>()({
|
||||
test: Value.toggle({
|
||||
name: "test",
|
||||
description: null,
|
||||
@@ -655,7 +655,7 @@ describe("Builder List", () => {
|
||||
|
||||
describe("Nested nullable values", () => {
|
||||
test("Testing text", async () => {
|
||||
const value = Config.of({
|
||||
const value = Config.of<unknown>()({
|
||||
a: Value.text({
|
||||
name: "Temp Name",
|
||||
description:
|
||||
@@ -670,7 +670,7 @@ describe("Nested nullable values", () => {
|
||||
testOutput<typeof validator._TYPE, { a: string | null | undefined }>()(null)
|
||||
})
|
||||
test("Testing number", async () => {
|
||||
const value = Config.of({
|
||||
const value = Config.of<unknown>()({
|
||||
a: Value.number({
|
||||
name: "Temp Name",
|
||||
description:
|
||||
@@ -692,7 +692,7 @@ describe("Nested nullable values", () => {
|
||||
testOutput<typeof validator._TYPE, { a: number | null | undefined }>()(null)
|
||||
})
|
||||
test("Testing color", async () => {
|
||||
const value = Config.of({
|
||||
const value = Config.of<unknown>()({
|
||||
a: Value.color({
|
||||
name: "Temp Name",
|
||||
description:
|
||||
@@ -708,7 +708,7 @@ describe("Nested nullable values", () => {
|
||||
testOutput<typeof validator._TYPE, { a: string | null | undefined }>()(null)
|
||||
})
|
||||
test("Testing select", async () => {
|
||||
const value = Config.of({
|
||||
const value = Config.of<unknown>()({
|
||||
a: Value.select({
|
||||
name: "Temp Name",
|
||||
description:
|
||||
@@ -737,7 +737,7 @@ describe("Nested nullable values", () => {
|
||||
testOutput<typeof validator._TYPE, { a: "a" | null | undefined }>()(null)
|
||||
})
|
||||
test("Testing multiselect", async () => {
|
||||
const value = Config.of({
|
||||
const value = Config.of<unknown>()({
|
||||
a: Value.multiselect({
|
||||
name: "Temp Name",
|
||||
description:
|
||||
|
||||
@@ -9,7 +9,7 @@ describe("Config Types", () => {
|
||||
for (const option of options) {
|
||||
const test = (option as any)(
|
||||
{} as any,
|
||||
{ spec: Config.of({}) } as any,
|
||||
{ spec: Config.of()({}) } as any,
|
||||
) as any
|
||||
const someList = await Value.list(test).build({} as any)
|
||||
if (isValueSpecListOf(someList, "text")) {
|
||||
|
||||
Reference in New Issue
Block a user