mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-31 04:33:40 +00:00
feat: Add in the beginnings of the new config builders.
This commit is contained in:
24
config/config.ts
Normal file
24
config/config.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { BuilderExtract, IBuilder } from "./builder.ts";
|
||||
import { Value } from "./value.ts";
|
||||
|
||||
export class Config<A> extends IBuilder<A> {
|
||||
static empty() {
|
||||
return new Config({});
|
||||
}
|
||||
|
||||
static of<B extends { [key: string]: Value<unknown> }>(spec: B) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const answer: { [K in keyof B]: BuilderExtract<B[K]> } = {} as any;
|
||||
for (const key in spec) {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
answer[key] = spec[key].build() as any;
|
||||
}
|
||||
return new Config(answer);
|
||||
}
|
||||
addValue<K extends string, B>(key: K, value: Value<B>) {
|
||||
return new Config({
|
||||
...this.a,
|
||||
[key]: value.build(),
|
||||
} as A & { [key in K]: B });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user