mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 20:24:47 +00:00
chore: add some documentation and somet testing
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import { YAML } from "../dependencies.ts";
|
||||
import { matches } from "../dependencies.ts";
|
||||
import { ExpectedExports } from "../types.ts";
|
||||
@@ -8,22 +7,31 @@ const { any, string, dictionary } = matches;
|
||||
|
||||
const matchConfig = dictionary([string, any]);
|
||||
|
||||
export const getConfig = (spec: ConfigSpec): ExpectedExports.getConfig => async (effects) => {
|
||||
/**
|
||||
* Call with the configuration to get a standard getConfig for the expected exports
|
||||
* Assumption: start9/config.yaml is where the config will be stored
|
||||
* Throws: Error if there is no file
|
||||
* Throws: Error if the config.yaml isn't yaml nor config shape
|
||||
* @param spec
|
||||
* @returns
|
||||
*/
|
||||
export const getConfig = (spec: ConfigSpec): ExpectedExports.getConfig =>
|
||||
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;
|
||||
});
|
||||
.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,
|
||||
},
|
||||
result: {
|
||||
config,
|
||||
spec,
|
||||
},
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user