mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import {
|
|
DependencyConfig as DependencyConfigType,
|
|
DeepPartial,
|
|
Effects,
|
|
} from "../types"
|
|
import { deepEqual } from "../util/deepEqual"
|
|
import { deepMerge } from "../util/deepMerge"
|
|
import { SDKManifest } from "../manifest/ManifestTypes"
|
|
|
|
export type Update<QueryResults, RemoteConfig> = (options: {
|
|
remoteConfig: RemoteConfig
|
|
queryResults: QueryResults
|
|
}) => Promise<RemoteConfig>
|
|
|
|
export class DependencyConfig<
|
|
Manifest extends SDKManifest,
|
|
Store,
|
|
Input extends Record<string, any>,
|
|
RemoteConfig extends Record<string, any>,
|
|
> {
|
|
static defaultUpdate = async (options: {
|
|
queryResults: unknown
|
|
remoteConfig: unknown
|
|
}): Promise<unknown> => {
|
|
return deepMerge({}, options.remoteConfig, options.queryResults || {})
|
|
}
|
|
constructor(
|
|
readonly dependencyConfig: (options: {
|
|
effects: Effects
|
|
localConfig: Input
|
|
}) => Promise<void | DeepPartial<RemoteConfig>>,
|
|
readonly update: Update<
|
|
void | DeepPartial<RemoteConfig>,
|
|
RemoteConfig
|
|
> = DependencyConfig.defaultUpdate as any,
|
|
) {}
|
|
|
|
async query(options: { effects: Effects; localConfig: unknown }) {
|
|
return this.dependencyConfig({
|
|
localConfig: options.localConfig as Input,
|
|
effects: options.effects,
|
|
})
|
|
}
|
|
}
|