mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +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 { YAML } from "../dependencies.ts";
|
||||||
import { matches } from "../dependencies.ts";
|
import { matches } from "../dependencies.ts";
|
||||||
import { ExpectedExports } from "../types.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
|
* @returns A funnction for getConfig and the matcher for the spec sent in
|
||||||
*/
|
*/
|
||||||
export const getConfigAndMatcher = <Spec extends ConfigSpec>(
|
export const getConfigAndMatcher = <Spec extends ConfigSpec>(
|
||||||
spec: Spec
|
spec: Config<Spec> | Spec
|
||||||
): [ExpectedExports.getConfig, matches.Parser<unknown, TypeFromProps<Spec>>] => [
|
): [ExpectedExports.getConfig, matches.Parser<unknown, TypeFromProps<Spec>>] => {
|
||||||
async (effects) => {
|
const specBuilt: Spec = spec instanceof Config ? spec.build() : spec;
|
||||||
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 {
|
return [
|
||||||
result: {
|
async (effects) => {
|
||||||
config,
|
const config = await effects
|
||||||
spec,
|
.readFile({
|
||||||
},
|
path: "start9/config.yaml",
|
||||||
};
|
volumeId: "main",
|
||||||
},
|
})
|
||||||
typeFromProps(spec),
|
.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