chore: Update the getCOnfig to use the config builder.

This commit is contained in:
BluJ
2023-02-14 10:25:16 -07:00
parent c47fc98620
commit 757033d503

View File

@@ -1,3 +1,4 @@
import { Config } from "../config/config.ts";
import { YAML } from "../dependencies.ts";
import { matches } from "../dependencies.ts";
import { ExpectedExports } from "../types.ts";
@@ -48,27 +49,31 @@ export const getConfig =
* @returns A funnction for getConfig and the matcher for the spec sent in
*/
export const getConfigAndMatcher = <Spec extends ConfigSpec>(
spec: Spec
): [ExpectedExports.getConfig, matches.Parser<unknown, TypeFromProps<Spec>>] => [
async (effects) => {
const config = await effects
.readFile({
path: "start9/config.yaml",
volumeId: "main",
})
.then((x) => YAML.parse(x))
.then((x) => matchConfig.unsafeCast(x))
.catch((e) => {
effects.info(`Got error ${e} while trying to read the config`);
return undefined;
});
spec: Config<Spec> | Spec
): [ExpectedExports.getConfig, matches.Parser<unknown, TypeFromProps<Spec>>] => {
const specBuilt: Spec = spec instanceof Config ? spec.build() : spec;
return {
result: {
config,
spec,
},
};
},
typeFromProps(spec),
];
return [
async (effects) => {
const config = await effects
.readFile({
path: "start9/config.yaml",
volumeId: "main",
})
.then((x) => YAML.parse(x))
.then((x) => matchConfig.unsafeCast(x))
.catch((e) => {
effects.info(`Got error ${e} while trying to read the config`);
return undefined;
});
return {
result: {
config,
spec: specBuilt,
},
};
},
typeFromProps(specBuilt),
];
};