From 757033d5030812980ce388bb91015b37c98c2156 Mon Sep 17 00:00:00 2001 From: BluJ Date: Tue, 14 Feb 2023 10:25:16 -0700 Subject: [PATCH] chore: Update the getCOnfig to use the config builder. --- compat/getConfig.ts | 51 +++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/compat/getConfig.ts b/compat/getConfig.ts index 17e4205..0ab4036 100644 --- a/compat/getConfig.ts +++ b/compat/getConfig.ts @@ -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: Spec -): [ExpectedExports.getConfig, matches.Parser>] => [ - 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 +): [ExpectedExports.getConfig, matches.Parser>] => { + 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), + ]; +};