mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: Update to the new dependencyConfig
This commit is contained in:
239
lib/StartSdk.ts
239
lib/StartSdk.ts
@@ -21,7 +21,7 @@ import {
|
|||||||
DeepPartial,
|
DeepPartial,
|
||||||
} from "./types"
|
} from "./types"
|
||||||
import { Utils } from "./util/utils"
|
import { Utils } from "./util/utils"
|
||||||
import { AutoConfig } from "./autoconfig/AutoConfig"
|
import { DependencyConfig } from "./dependencyConfig/DependencyConfig"
|
||||||
import { BackupSet, Backups } from "./backup/Backups"
|
import { BackupSet, Backups } from "./backup/Backups"
|
||||||
import { smtpConfig } from "./config/configConstants"
|
import { smtpConfig } from "./config/configConstants"
|
||||||
import { Daemons } from "./mainFn/Daemons"
|
import { Daemons } from "./mainFn/Daemons"
|
||||||
@@ -35,7 +35,7 @@ import { List } from "./config/builder/list"
|
|||||||
import { Migration } from "./inits/migrations/Migration"
|
import { Migration } from "./inits/migrations/Migration"
|
||||||
import { Install, InstallFn, setupInstall } from "./inits/setupInstall"
|
import { Install, InstallFn, setupInstall } from "./inits/setupInstall"
|
||||||
import { setupActions } from "./actions/setupActions"
|
import { setupActions } from "./actions/setupActions"
|
||||||
import { setupAutoConfig } from "./autoconfig/setupAutoConfig"
|
import { setupDependencyConfig } from "./dependencyConfig/setupDependencyConfig"
|
||||||
import { SetupBackupsParams, setupBackups } from "./backup/setupBackups"
|
import { SetupBackupsParams, setupBackups } from "./backup/setupBackups"
|
||||||
import { setupInit } from "./inits/setupInit"
|
import { setupInit } from "./inits/setupInit"
|
||||||
import {
|
import {
|
||||||
@@ -76,29 +76,106 @@ export class StartSdk<Manifest extends SDKManifest, Store, Vault> {
|
|||||||
isReady: AnyNeverCond<[Manifest, Store, Vault], "Build not ready", true>,
|
isReady: AnyNeverCond<[Manifest, Store, Vault], "Build not ready", true>,
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
AutoConfig: {
|
configConstants: { smtpConfig },
|
||||||
of<
|
createAction: <
|
||||||
LocalConfig extends Record<string, any>,
|
Store,
|
||||||
RemoteConfig extends Record<string, any>,
|
ConfigType extends
|
||||||
>({
|
| Record<string, any>
|
||||||
localConfig,
|
| Config<any, any, any>
|
||||||
remoteConfig,
|
| Config<any, never, never>,
|
||||||
autoconfig,
|
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||||
}: {
|
>(
|
||||||
localConfig: Config<LocalConfig, Store, Vault>
|
metaData: Omit<ActionMetadata, "input"> & {
|
||||||
remoteConfig: Config<RemoteConfig, any, any>
|
input: Config<Type, Store, Vault> | Config<Type, never, never>
|
||||||
autoconfig: (options: {
|
|
||||||
effects: Effects
|
|
||||||
localConfig: LocalConfig
|
|
||||||
remoteConfig: RemoteConfig
|
|
||||||
utils: Utils<Store, Vault>
|
|
||||||
}) => Promise<void | DeepPartial<RemoteConfig>>
|
|
||||||
}) {
|
|
||||||
return new AutoConfig<Store, Vault, LocalConfig, RemoteConfig>(
|
|
||||||
autoconfig,
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
|
fn: (options: {
|
||||||
|
effects: Effects
|
||||||
|
utils: Utils<Store, Vault>
|
||||||
|
input: Type
|
||||||
|
}) => Promise<ActionResult>,
|
||||||
|
) => createAction<Store, Vault, ConfigType, Type>(metaData, fn),
|
||||||
|
healthCheck: {
|
||||||
|
checkPortListening,
|
||||||
|
checkWebUrl,
|
||||||
|
of: healthCheck,
|
||||||
|
runHealthScript,
|
||||||
},
|
},
|
||||||
|
setupActions: (...createdActions: CreatedAction<any, any, any>[]) =>
|
||||||
|
setupActions<Store, Vault>(...createdActions),
|
||||||
|
setupBackups: (...args: SetupBackupsParams<Manifest>) =>
|
||||||
|
setupBackups<Manifest>(...args),
|
||||||
|
setupConfig: <
|
||||||
|
ConfigType extends
|
||||||
|
| Config<any, Store, Vault>
|
||||||
|
| Config<any, never, never>,
|
||||||
|
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||||
|
>(
|
||||||
|
spec: ConfigType,
|
||||||
|
write: Save<Store, Vault, Type, Manifest>,
|
||||||
|
read: Read<Store, Vault, Type>,
|
||||||
|
) =>
|
||||||
|
setupConfig<Store, Vault, ConfigType, Manifest, Type>(
|
||||||
|
spec,
|
||||||
|
write,
|
||||||
|
read,
|
||||||
|
),
|
||||||
|
setupConfigRead: <
|
||||||
|
ConfigSpec extends
|
||||||
|
| Config<Record<string, any>, any, any>
|
||||||
|
| Config<Record<string, never>, never, never>,
|
||||||
|
>(
|
||||||
|
_configSpec: ConfigSpec,
|
||||||
|
fn: Read<Store, Vault, ConfigSpec>,
|
||||||
|
) => fn,
|
||||||
|
setupConfigSave: <
|
||||||
|
ConfigSpec extends
|
||||||
|
| Config<Record<string, any>, any, any>
|
||||||
|
| Config<Record<string, never>, never, never>,
|
||||||
|
>(
|
||||||
|
_configSpec: ConfigSpec,
|
||||||
|
fn: Save<Store, Vault, ConfigSpec, Manifest>,
|
||||||
|
) => fn,
|
||||||
|
setupDependencyConfig: <Input extends Record<string, any>>(
|
||||||
|
config: Config<Input, Store, Vault>,
|
||||||
|
autoConfigs: {
|
||||||
|
[K in keyof Manifest["dependencies"]]: DependencyConfig<
|
||||||
|
Store,
|
||||||
|
Vault,
|
||||||
|
Input,
|
||||||
|
any
|
||||||
|
>
|
||||||
|
},
|
||||||
|
) =>
|
||||||
|
setupDependencyConfig<Store, Vault, Input, Manifest>(
|
||||||
|
config,
|
||||||
|
autoConfigs,
|
||||||
|
),
|
||||||
|
setupDependencyMounts,
|
||||||
|
setupInit: (
|
||||||
|
migrations: Migrations<Store, Vault>,
|
||||||
|
install: Install<Store, Vault>,
|
||||||
|
uninstall: Uninstall<Store, Vault>,
|
||||||
|
) => setupInit<Store, Vault>(migrations, install, uninstall),
|
||||||
|
setupInstall: (fn: InstallFn<Store, Vault>) => Install.of(fn),
|
||||||
|
setupMain: (
|
||||||
|
fn: (o: {
|
||||||
|
effects: Effects
|
||||||
|
started(onTerm: () => void): null
|
||||||
|
utils: Utils<Store, Vault, {}>
|
||||||
|
}) => Promise<Daemons<any>>,
|
||||||
|
) => setupMain<Store, Vault>(fn),
|
||||||
|
setupMigrations: <Migrations extends Array<Migration<Store, Vault, any>>>(
|
||||||
|
...migrations: EnsureUniqueId<Migrations>
|
||||||
|
) =>
|
||||||
|
setupMigrations<Store, Vault, Migrations>(this.manifest, ...migrations),
|
||||||
|
setupUninstall: (fn: UninstallFn<Store, Vault>) =>
|
||||||
|
setupUninstall<Store, Vault>(fn),
|
||||||
|
trigger: {
|
||||||
|
defaultTrigger,
|
||||||
|
cooldownTrigger,
|
||||||
|
changeOnFirstSuccess,
|
||||||
|
},
|
||||||
|
|
||||||
Backups: {
|
Backups: {
|
||||||
volumes: (...volumeNames: Array<keyof Manifest["volumes"] & string>) =>
|
volumes: (...volumeNames: Array<keyof Manifest["volumes"] & string>) =>
|
||||||
Backups.volumes<Manifest>(...volumeNames),
|
Backups.volumes<Manifest>(...volumeNames),
|
||||||
@@ -118,30 +195,29 @@ export class StartSdk<Manifest extends SDKManifest, Store, Vault> {
|
|||||||
spec: Spec,
|
spec: Spec,
|
||||||
) => Config.of<Spec, Store, Vault>(spec),
|
) => Config.of<Spec, Store, Vault>(spec),
|
||||||
},
|
},
|
||||||
configConstants: { smtpConfig },
|
|
||||||
createAction: <
|
|
||||||
Store,
|
|
||||||
ConfigType extends
|
|
||||||
| Record<string, any>
|
|
||||||
| Config<any, any, any>
|
|
||||||
| Config<any, never, never>,
|
|
||||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
|
||||||
>(
|
|
||||||
metaData: Omit<ActionMetadata, "input"> & {
|
|
||||||
input: Config<Type, Store, Vault> | Config<Type, never, never>
|
|
||||||
},
|
|
||||||
fn: (options: {
|
|
||||||
effects: Effects
|
|
||||||
utils: Utils<Store, Vault>
|
|
||||||
input: Type
|
|
||||||
}) => Promise<ActionResult>,
|
|
||||||
) => createAction<Store, Vault, ConfigType, Type>(metaData, fn),
|
|
||||||
Daemons: { of: Daemons.of },
|
Daemons: { of: Daemons.of },
|
||||||
healthCheck: {
|
DependencyConfig: {
|
||||||
checkPortListening,
|
of<
|
||||||
checkWebUrl,
|
LocalConfig extends Record<string, any>,
|
||||||
of: healthCheck,
|
RemoteConfig extends Record<string, any>,
|
||||||
runHealthScript,
|
>({
|
||||||
|
localConfig,
|
||||||
|
remoteConfig,
|
||||||
|
dependencyConfig,
|
||||||
|
}: {
|
||||||
|
localConfig: Config<LocalConfig, Store, Vault>
|
||||||
|
remoteConfig: Config<RemoteConfig, any, any>
|
||||||
|
dependencyConfig: (options: {
|
||||||
|
effects: Effects
|
||||||
|
localConfig: LocalConfig
|
||||||
|
remoteConfig: RemoteConfig
|
||||||
|
utils: Utils<Store, Vault>
|
||||||
|
}) => Promise<void | DeepPartial<RemoteConfig>>
|
||||||
|
}) {
|
||||||
|
return new DependencyConfig<Store, Vault, LocalConfig, RemoteConfig>(
|
||||||
|
dependencyConfig,
|
||||||
|
)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
List: {
|
List: {
|
||||||
text: List.text,
|
text: List.text,
|
||||||
@@ -227,77 +303,6 @@ export class StartSdk<Manifest extends SDKManifest, Store, Vault> {
|
|||||||
}) => Promise<void>
|
}) => Promise<void>
|
||||||
}) => Migration.of<Store, Vault, Version>(options),
|
}) => Migration.of<Store, Vault, Version>(options),
|
||||||
},
|
},
|
||||||
setupActions: (...createdActions: CreatedAction<any, any, any>[]) =>
|
|
||||||
setupActions<Store, Vault>(...createdActions),
|
|
||||||
setupAutoConfig: <Input extends Record<string, any>>(
|
|
||||||
config: Config<Input, Store, Vault>,
|
|
||||||
autoConfigs: {
|
|
||||||
[K in keyof Manifest["dependencies"]]: AutoConfig<
|
|
||||||
Store,
|
|
||||||
Vault,
|
|
||||||
Input,
|
|
||||||
any
|
|
||||||
>
|
|
||||||
},
|
|
||||||
) => setupAutoConfig<Store, Vault, Input, Manifest>(config, autoConfigs),
|
|
||||||
setupBackups: (...args: SetupBackupsParams<Manifest>) =>
|
|
||||||
setupBackups<Manifest>(...args),
|
|
||||||
setupConfig: <
|
|
||||||
ConfigType extends
|
|
||||||
| Config<any, Store, Vault>
|
|
||||||
| Config<any, never, never>,
|
|
||||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
|
||||||
>(
|
|
||||||
spec: ConfigType,
|
|
||||||
write: Save<Store, Vault, Type, Manifest>,
|
|
||||||
read: Read<Store, Vault, Type>,
|
|
||||||
) =>
|
|
||||||
setupConfig<Store, Vault, ConfigType, Manifest, Type>(
|
|
||||||
spec,
|
|
||||||
write,
|
|
||||||
read,
|
|
||||||
),
|
|
||||||
setupConfigRead: <
|
|
||||||
ConfigSpec extends
|
|
||||||
| Config<Record<string, any>, any, any>
|
|
||||||
| Config<Record<string, never>, never, never>,
|
|
||||||
>(
|
|
||||||
_configSpec: ConfigSpec,
|
|
||||||
fn: Read<Store, Vault, ConfigSpec>,
|
|
||||||
) => fn,
|
|
||||||
setupConfigSave: <
|
|
||||||
ConfigSpec extends
|
|
||||||
| Config<Record<string, any>, any, any>
|
|
||||||
| Config<Record<string, never>, never, never>,
|
|
||||||
>(
|
|
||||||
_configSpec: ConfigSpec,
|
|
||||||
fn: Save<Store, Vault, ConfigSpec, Manifest>,
|
|
||||||
) => fn,
|
|
||||||
setupDependencyMounts,
|
|
||||||
setupInit: (
|
|
||||||
migrations: Migrations<Store, Vault>,
|
|
||||||
install: Install<Store, Vault>,
|
|
||||||
uninstall: Uninstall<Store, Vault>,
|
|
||||||
) => setupInit<Store, Vault>(migrations, install, uninstall),
|
|
||||||
setupInstall: (fn: InstallFn<Store, Vault>) => Install.of(fn),
|
|
||||||
setupMain: (
|
|
||||||
fn: (o: {
|
|
||||||
effects: Effects
|
|
||||||
started(onTerm: () => void): null
|
|
||||||
utils: Utils<Store, Vault, {}>
|
|
||||||
}) => Promise<Daemons<any>>,
|
|
||||||
) => setupMain<Store, Vault>(fn),
|
|
||||||
setupMigrations: <Migrations extends Array<Migration<Store, Vault, any>>>(
|
|
||||||
...migrations: EnsureUniqueId<Migrations>
|
|
||||||
) =>
|
|
||||||
setupMigrations<Store, Vault, Migrations>(this.manifest, ...migrations),
|
|
||||||
setupUninstall: (fn: UninstallFn<Store, Vault>) =>
|
|
||||||
setupUninstall<Store, Vault>(fn),
|
|
||||||
trigger: {
|
|
||||||
defaultTrigger,
|
|
||||||
cooldownTrigger,
|
|
||||||
changeOnFirstSuccess,
|
|
||||||
},
|
|
||||||
Value: {
|
Value: {
|
||||||
toggle: Value.toggle,
|
toggle: Value.toggle,
|
||||||
text: Value.text,
|
text: Value.text,
|
||||||
|
|||||||
@@ -2,16 +2,15 @@ import { AutoConfigure, DeepPartial, Effects, ExpectedExports } from "../types"
|
|||||||
import { Utils, utils } from "../util/utils"
|
import { Utils, utils } from "../util/utils"
|
||||||
import { deepEqual } from "../util/deepEqual"
|
import { deepEqual } from "../util/deepEqual"
|
||||||
import { deepMerge } from "../util/deepMerge"
|
import { deepMerge } from "../util/deepMerge"
|
||||||
import { Config } from "../config/builder/config"
|
|
||||||
|
|
||||||
export class AutoConfig<
|
export class DependencyConfig<
|
||||||
Store,
|
Store,
|
||||||
Vault,
|
Vault,
|
||||||
Input extends Record<string, any>,
|
Input extends Record<string, any>,
|
||||||
RemoteConfig extends Record<string, any>,
|
RemoteConfig extends Record<string, any>,
|
||||||
> {
|
> {
|
||||||
constructor(
|
constructor(
|
||||||
readonly autoconfig: (options: {
|
readonly dependencyConfig: (options: {
|
||||||
effects: Effects
|
effects: Effects
|
||||||
localConfig: Input
|
localConfig: Input
|
||||||
remoteConfig: RemoteConfig
|
remoteConfig: RemoteConfig
|
||||||
@@ -32,7 +31,11 @@ export class AutoConfig<
|
|||||||
if (
|
if (
|
||||||
!deepEqual(
|
!deepEqual(
|
||||||
origConfig,
|
origConfig,
|
||||||
deepMerge({}, options.localConfig, await this.autoconfig(newOptions)),
|
deepMerge(
|
||||||
|
{},
|
||||||
|
options.localConfig,
|
||||||
|
await this.dependencyConfig(newOptions),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
throw new Error(`Check failed`)
|
throw new Error(`Check failed`)
|
||||||
@@ -49,7 +52,7 @@ export class AutoConfig<
|
|||||||
return deepMerge(
|
return deepMerge(
|
||||||
{},
|
{},
|
||||||
options.remoteConfig,
|
options.remoteConfig,
|
||||||
await this.autoconfig(newOptions),
|
await this.dependencyConfig(newOptions),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,5 @@ export type ReadonlyDeep<A> =
|
|||||||
export type MaybePromise<A> = Promise<A> | A
|
export type MaybePromise<A> = Promise<A> | A
|
||||||
export type Message = string
|
export type Message = string
|
||||||
|
|
||||||
import "./AutoConfig"
|
import "./DependencyConfig"
|
||||||
import "./setupAutoConfig"
|
import "./setupDependencyConfig"
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Config } from "../config/builder/config"
|
import { Config } from "../config/builder/config"
|
||||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||||
import { AutoConfig } from "./AutoConfig"
|
import { DependencyConfig } from "./DependencyConfig"
|
||||||
|
|
||||||
export function setupAutoConfig<
|
export function setupDependencyConfig<
|
||||||
Store,
|
Store,
|
||||||
Vault,
|
Vault,
|
||||||
Input extends Record<string, any>,
|
Input extends Record<string, any>,
|
||||||
@@ -10,7 +10,7 @@ export function setupAutoConfig<
|
|||||||
>(
|
>(
|
||||||
_config: Config<Input, Store, Vault>,
|
_config: Config<Input, Store, Vault>,
|
||||||
autoConfigs: {
|
autoConfigs: {
|
||||||
[key in keyof Manifest["dependencies"] & string]: AutoConfig<
|
[key in keyof Manifest["dependencies"] & string]: DependencyConfig<
|
||||||
Store,
|
Store,
|
||||||
Vault,
|
Vault,
|
||||||
Input,
|
Input,
|
||||||
@@ -11,7 +11,7 @@ import "@iarna/toml"
|
|||||||
import "./types"
|
import "./types"
|
||||||
import "./util"
|
import "./util"
|
||||||
import "yaml"
|
import "yaml"
|
||||||
import "./autoconfig"
|
import "./dependencyConfig"
|
||||||
import "./actions"
|
import "./actions"
|
||||||
import "./manifest"
|
import "./manifest"
|
||||||
import "./inits"
|
import "./inits"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { sdk } from "./output.sdk"
|
import { sdk } from "./output.sdk"
|
||||||
|
|
||||||
describe("setupAutoConfig", () => {
|
describe("setupDependencyConfig", () => {
|
||||||
test("test", () => {
|
test("test", () => {
|
||||||
const testConfig = sdk.Config.of({
|
const testConfig = sdk.Config.of({
|
||||||
test: sdk.Value.text({
|
test: sdk.Value.text({
|
||||||
@@ -15,12 +15,12 @@ describe("setupAutoConfig", () => {
|
|||||||
required: false,
|
required: false,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
const remoteTest = sdk.AutoConfig.of({
|
const remoteTest = sdk.DependencyConfig.of({
|
||||||
localConfig: testConfig,
|
localConfig: testConfig,
|
||||||
remoteConfig: testConfig2,
|
remoteConfig: testConfig2,
|
||||||
autoconfig: async ({}) => {},
|
dependencyConfig: async ({}) => {},
|
||||||
})
|
})
|
||||||
sdk.setupAutoConfig(testConfig, {
|
sdk.setupDependencyConfig(testConfig, {
|
||||||
remoteTest,
|
remoteTest,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user