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