mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
wip: SDK up to createAction
This commit is contained in:
@@ -11,8 +11,17 @@ import {
|
||||
} from "./config/configTypes"
|
||||
import { Variants } from "./config/builder/variants"
|
||||
import { createAction } from "./actions/createAction"
|
||||
import { ActionMetaData, Effects, ActionResult, Metadata } from "./types"
|
||||
import {
|
||||
ActionMetaData,
|
||||
Effects,
|
||||
ActionResult,
|
||||
Metadata,
|
||||
BackupOptions,
|
||||
} from "./types"
|
||||
import { Utils } from "./util"
|
||||
import { AutoConfig, AutoConfigFrom } from "./autoconfig/AutoConfig"
|
||||
import { BackupSet, Backups } from "./backup/Backups"
|
||||
import { smtpConfig } from "./config/configConstants"
|
||||
|
||||
// prettier-ignore
|
||||
type AnyNeverCond<T extends any[], Then, Else> =
|
||||
@@ -41,11 +50,27 @@ class StartSDK<Manifest extends SDKManifest, Store> {
|
||||
|
||||
build() {
|
||||
return this.anyOf({
|
||||
// TODO AutoConfig
|
||||
// TODO Backup
|
||||
// TODO Config
|
||||
// TODO configConstants
|
||||
// TODO configDependencies
|
||||
AutoConfig: <Input, NestedConfigs>(
|
||||
configs: AutoConfigFrom<Store, Input, NestedConfigs>,
|
||||
path: keyof AutoConfigFrom<Store, Input, NestedConfigs>,
|
||||
) => new AutoConfig<Store, Input, NestedConfigs>(configs, path),
|
||||
Backups: {
|
||||
volumes: (...volumeNames: Array<keyof Manifest["volumes"] & string>) =>
|
||||
Backups.volumes<Manifest>(...volumeNames),
|
||||
addSets: (
|
||||
...options: BackupSet<keyof Manifest["volumes"] & string>[]
|
||||
) => Backups.addSets<Manifest>(...options),
|
||||
withOptions: (options?: Partial<BackupOptions>) =>
|
||||
Backups.with_options<Manifest>(options),
|
||||
},
|
||||
Config: {
|
||||
of: <
|
||||
Spec extends Record<string, Value<any, Manifest> | Value<any, never>>,
|
||||
>(
|
||||
spec: Spec,
|
||||
) => Config.of(spec),
|
||||
},
|
||||
configConstants: { smtpConfig },
|
||||
createAction: <
|
||||
Store,
|
||||
ConfigType extends
|
||||
|
||||
@@ -2,21 +2,19 @@ import { AutoConfigure, DeepPartial, Effects, ExpectedExports } from "../types"
|
||||
import { Utils, utils } from "../util"
|
||||
import { deepEqual } from "../util/deepEqual"
|
||||
import { deepMerge } from "../util/deepMerge"
|
||||
import { WrapperDataContract } from "../wrapperData/wrapperDataContract"
|
||||
|
||||
export type AutoConfigFrom<WD, Input, NestedConfigs> = {
|
||||
export type AutoConfigFrom<Store, Input, NestedConfigs> = {
|
||||
[key in keyof NestedConfigs & string]: (options: {
|
||||
effects: Effects
|
||||
localConfig: Input
|
||||
remoteConfig: NestedConfigs[key]
|
||||
utils: Utils<WD>
|
||||
utils: Utils<Store>
|
||||
}) => Promise<void | DeepPartial<NestedConfigs[key]>>
|
||||
}
|
||||
export class AutoConfig<WD, Input, NestedConfigs> {
|
||||
export class AutoConfig<Store, Input, NestedConfigs> {
|
||||
constructor(
|
||||
readonly wrapperDataContract: WrapperDataContract<WD>,
|
||||
readonly configs: AutoConfigFrom<WD, Input, NestedConfigs>,
|
||||
readonly path: keyof AutoConfigFrom<WD, Input, NestedConfigs>,
|
||||
readonly configs: AutoConfigFrom<Store, Input, NestedConfigs>,
|
||||
readonly path: keyof AutoConfigFrom<Store, Input, NestedConfigs>,
|
||||
) {}
|
||||
|
||||
async check(
|
||||
@@ -25,7 +23,7 @@ export class AutoConfig<WD, Input, NestedConfigs> {
|
||||
const origConfig = JSON.parse(JSON.stringify(options.localConfig))
|
||||
const newOptions = {
|
||||
...options,
|
||||
utils: utils(this.wrapperDataContract, options.effects),
|
||||
utils: utils<Store>(options.effects),
|
||||
localConfig: options.localConfig as Input,
|
||||
remoteConfig: options.remoteConfig as any,
|
||||
}
|
||||
@@ -46,7 +44,7 @@ export class AutoConfig<WD, Input, NestedConfigs> {
|
||||
): ReturnType<AutoConfigure["autoConfigure"]> {
|
||||
const newOptions = {
|
||||
...options,
|
||||
utils: utils(this.wrapperDataContract, options.effects),
|
||||
utils: utils<Store>(options.effects),
|
||||
localConfig: options.localConfig as Input,
|
||||
remoteConfig: options.remoteConfig as any,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { SDKManifest } from "../manifest/ManifestTypes"
|
||||
import * as T from "../types"
|
||||
import fs from "fs"
|
||||
|
||||
export type BACKUP = "BACKUP"
|
||||
export const DEFAULT_OPTIONS: T.BackupOptions = {
|
||||
@@ -9,7 +8,7 @@ export const DEFAULT_OPTIONS: T.BackupOptions = {
|
||||
ignoreExisting: false,
|
||||
exclude: [],
|
||||
}
|
||||
type BackupSet<Volumes extends string> = {
|
||||
export type BackupSet<Volumes extends string> = {
|
||||
srcPath: string
|
||||
srcVolume: Volumes | BACKUP
|
||||
dstPath: string
|
||||
@@ -41,7 +40,7 @@ type BackupSet<Volumes extends string> = {
|
||||
export class Backups<M extends SDKManifest> {
|
||||
static BACKUP: BACKUP = "BACKUP"
|
||||
|
||||
constructor(
|
||||
private constructor(
|
||||
private options = DEFAULT_OPTIONS,
|
||||
private backupSet = [] as BackupSet<keyof M["volumes"] & string>[],
|
||||
) {}
|
||||
@@ -67,7 +66,9 @@ export class Backups<M extends SDKManifest> {
|
||||
) {
|
||||
return new Backups({ ...DEFAULT_OPTIONS, ...options })
|
||||
}
|
||||
set_options(options?: Partial<T.BackupOptions>) {
|
||||
|
||||
static withOptions = Backups.with_options
|
||||
setOptions(options?: Partial<T.BackupOptions>) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...options,
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { SmtpValue } from "../types"
|
||||
import {
|
||||
createWrapperDataContract,
|
||||
neverWrapperDataContract,
|
||||
} from "../wrapperData/wrapperDataContract"
|
||||
import { Config, ConfigSpecOf } from "./builder/config"
|
||||
import { Value } from "./builder/value"
|
||||
import { Variants } from "./builder/variants"
|
||||
|
||||
export const smtpConfig = Value.filteredUnion(
|
||||
neverWrapperDataContract,
|
||||
async ({ effects, utils }) => {
|
||||
const smtp = await utils.getSystemSmtp().once()
|
||||
return smtp ? [] : ["system"]
|
||||
|
||||
Reference in New Issue
Block a user