mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 20:24:47 +00:00
feat: Make config of the config top
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user