chore: Update the start-sdk to use dependencies

This commit is contained in:
BluJ
2023-04-17 13:39:09 -06:00
parent 78076387ef
commit 4b74906ada
6 changed files with 73 additions and 110 deletions

View File

@@ -1,5 +1,5 @@
import { Config } from "./builder";
import { DeepPartial, DependsOn, Effects, ExpectedExports } from "../types";
import { DeepPartial, Dependencies, DependsOn, Effects, ExpectedExports } from "../types";
import { InputSpec } from "./configTypes";
import { nullIfEmpty } from "../util";
import { TypeFromProps } from "../util/propertiesMatcher";
@@ -13,15 +13,8 @@ import { TypeFromProps } from "../util/propertiesMatcher";
*/
export function setupConfigExports<A extends InputSpec, ConfigType>(options: {
spec: Config<A>;
dependsOn: DependsOn;
write(options: {
effects: Effects;
input: TypeFromProps<A>;
}): Promise<ConfigType>;
read(options: {
effects: Effects;
config: ConfigType;
}): Promise<null | DeepPartial<TypeFromProps<A>>>;
write(options: { effects: Effects; input: TypeFromProps<A> }): Promise<[ConfigType, Dependencies]>;
read(options: { effects: Effects; config: ConfigType }): Promise<null | DeepPartial<TypeFromProps<A>>>;
}) {
const validator = options.spec.validator();
return {
@@ -30,17 +23,15 @@ export function setupConfigExports<A extends InputSpec, ConfigType>(options: {
await effects.error(String(validator.errorMessage(input)));
return { error: "Set config type error for config" };
}
const output = await options.write({ input, effects });
if (output) {
await effects.setWrapperData({ path: "config", value: output });
}
const [output, dependencies] = await options.write({ input, effects });
await effects.setDependencies(dependencies);
await effects.setWrapperData({ path: "config", value: output });
}) as ExpectedExports.setConfig,
getConfig: (async ({ effects, config }) => {
return {
spec: options.spec.build(),
config: nullIfEmpty(
await options.read({ effects, config: config as ConfigType })
),
config: nullIfEmpty(await options.read({ effects, config: config as ConfigType })),
};
}) as ExpectedExports.getConfig,
};