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