chore: add some documentation and somet testing

This commit is contained in:
BluJ
2022-07-18 13:27:51 -06:00
parent cb39f5f3ba
commit 17d4b8048f
7 changed files with 296 additions and 249 deletions

View File

@@ -1,38 +1,42 @@
import { YAML } from "../dependencies.ts";
import { exists } from "../exists.ts";
import { ResultType, Properties, ExpectedExports, Effects } from "../types.ts";
import { Effects, ExpectedExports, Properties, ResultType } from "../types.ts";
// deno-lint-ignore no-explicit-any
const asResult = (result: any) => ({ result: result as Properties })
const asResult = (result: any) => ({ result: result as Properties });
const noPropertiesFound: ResultType<Properties> = {
result: {
version: 2,
data: {
"Not Ready": {
type: "string",
value: "Could not find properties. The service might still be starting",
qr: false,
copyable: false,
masked: false,
description: "Fallback Message When Properties could not be found"
}
}
}
} as const
result: {
version: 2,
data: {
"Not Ready": {
type: "string",
value: "Could not find properties. The service might still be starting",
qr: false,
copyable: false,
masked: false,
description: "Fallback Message When Properties could not be found",
},
},
},
} as const;
/**
* Default will pull from a file (start9/stats.yaml) expected to be made on the main volume
* @param effects
* @returns
* Assumption: start9/stats.yaml is created by some process
* Throws: stats.yaml isn't yaml
* @param effects
* @returns
*/
export const properties: ExpectedExports.properties = async (
effects: Effects,
effects: Effects,
) => {
if (await exists(effects, { path: "start9/stats.yaml", volumeId: "main" }) === false) {
return noPropertiesFound;
}
return await effects.readFile({
path: "start9/stats.yaml",
volumeId: "main",
}).then(YAML.parse).then(asResult)
if (
await exists(effects, { path: "start9/stats.yaml", volumeId: "main" }) ===
false
) {
return noPropertiesFound;
}
return await effects.readFile({
path: "start9/stats.yaml",
volumeId: "main",
}).then(YAML.parse).then(asResult);
};