mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-01 21:13:11 +00:00
chore: Update the types for autoconfig
This commit is contained in:
@@ -1,30 +1,36 @@
|
||||
import { AutoConfigure, Effects, ExpectedExports } from "../types";
|
||||
import { deepEqual, deepMerge } from "../util";
|
||||
import { Utils, deepEqual, deepMerge, utils } from "../util";
|
||||
|
||||
export type AutoConfigFrom = {
|
||||
export type AutoConfigFrom<WD, Input> = {
|
||||
[key: string]: (options: {
|
||||
effects: Effects;
|
||||
localConfig: unknown;
|
||||
localConfig: Input;
|
||||
remoteConfig: unknown;
|
||||
utils: Utils<WD>;
|
||||
}) => Promise<void | Record<string, unknown>>;
|
||||
};
|
||||
export class AutoConfig {
|
||||
export class AutoConfig<WD, Input> {
|
||||
constructor(
|
||||
readonly configs: AutoConfigFrom,
|
||||
readonly path: keyof AutoConfigFrom,
|
||||
readonly configs: AutoConfigFrom<WD, Input>,
|
||||
readonly path: keyof AutoConfigFrom<WD, Input>,
|
||||
) {}
|
||||
|
||||
async check(
|
||||
options: Parameters<AutoConfigure["check"]>[0],
|
||||
): ReturnType<AutoConfigure["check"]> {
|
||||
const origConfig = JSON.parse(JSON.stringify(options.localConfig));
|
||||
const newOptions = {
|
||||
...options,
|
||||
utils: utils<WD>(options.effects),
|
||||
localConfig: options.localConfig as Input,
|
||||
};
|
||||
if (
|
||||
!deepEqual(
|
||||
origConfig,
|
||||
deepMerge(
|
||||
{},
|
||||
options.localConfig,
|
||||
await this.configs[this.path](options),
|
||||
await this.configs[this.path](newOptions),
|
||||
),
|
||||
)
|
||||
)
|
||||
@@ -33,10 +39,15 @@ export class AutoConfig {
|
||||
async autoConfigure(
|
||||
options: Parameters<AutoConfigure["autoConfigure"]>[0],
|
||||
): ReturnType<AutoConfigure["autoConfigure"]> {
|
||||
const newOptions = {
|
||||
...options,
|
||||
utils: utils<WD>(options.effects),
|
||||
localConfig: options.localConfig as Input,
|
||||
};
|
||||
return deepMerge(
|
||||
{},
|
||||
options.localConfig,
|
||||
await this.configs[this.path](options),
|
||||
await this.configs[this.path](newOptions),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user