mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
chore: Update the getCOnfig to use the config builder.
This commit is contained in:
@@ -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),
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user