mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
chore: Wrapper Data Contract
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
ValueSpecText,
|
||||
} from "../configTypes"
|
||||
import { Parser, arrayOf, number, string } from "ts-matches"
|
||||
import { WrapperDataContract } from "../../wrapperData/wrapperDataContract"
|
||||
/**
|
||||
* Used as a subtype of Value.list
|
||||
```ts
|
||||
@@ -74,6 +75,7 @@ export class List<Type, WD> {
|
||||
}, arrayOf(string))
|
||||
}
|
||||
static dynamicText<WD = never>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
{
|
||||
@@ -167,6 +169,7 @@ export class List<Type, WD> {
|
||||
}, arrayOf(number))
|
||||
}
|
||||
static dynamicNumber<WD = never>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
unknown,
|
||||
} from "ts-matches"
|
||||
import { once } from "../../util/once"
|
||||
import { WrapperDataContract } from "../../wrapperData/wrapperDataContract"
|
||||
|
||||
type RequiredDefault<A> =
|
||||
| false
|
||||
@@ -121,6 +122,7 @@ export class Value<Type, WD> {
|
||||
)
|
||||
}
|
||||
static dynamicToggle<WD = never>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
a: LazyBuild<
|
||||
WD,
|
||||
{
|
||||
@@ -184,6 +186,7 @@ export class Value<Type, WD> {
|
||||
)
|
||||
}
|
||||
static dynamicText<WD = never>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
{
|
||||
@@ -255,6 +258,7 @@ export class Value<Type, WD> {
|
||||
)
|
||||
}
|
||||
static dynamicTextarea<WD = never>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
{
|
||||
@@ -321,6 +325,7 @@ export class Value<Type, WD> {
|
||||
)
|
||||
}
|
||||
static dynamicNumber<WD = never>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
{
|
||||
@@ -382,6 +387,7 @@ export class Value<Type, WD> {
|
||||
}
|
||||
|
||||
static dynamicColor<WD = never>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
{
|
||||
@@ -439,6 +445,7 @@ export class Value<Type, WD> {
|
||||
)
|
||||
}
|
||||
static dynamicDatetime<WD = never>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
getA: LazyBuild<
|
||||
WD,
|
||||
{
|
||||
@@ -630,35 +637,34 @@ export class Value<Type, WD> {
|
||||
asRequiredParser(aVariants.validator, a),
|
||||
)
|
||||
}
|
||||
static filteredUnion<WrapperData = never>(
|
||||
getDisabledFn: LazyBuild<WrapperData, string[]>,
|
||||
static filteredUnion<
|
||||
Required extends RequiredDefault<string>,
|
||||
Type extends Record<string, any>,
|
||||
WD = never,
|
||||
>(
|
||||
_wrapperDataContract: WrapperDataContract<WD>,
|
||||
getDisabledFn: LazyBuild<WD, string[]>,
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
required: Required
|
||||
},
|
||||
aVariants: Variants<Type, WD> | Variants<Type, never>,
|
||||
) {
|
||||
return <
|
||||
Required extends RequiredDefault<string>,
|
||||
Type extends Record<string, any>,
|
||||
>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
required: Required
|
||||
},
|
||||
aVariants: Variants<Type, WrapperData> | Variants<Type, never>,
|
||||
) => {
|
||||
return new Value<AsRequired<Type, Required>, WrapperData>(
|
||||
async (options) => ({
|
||||
type: "union" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
...a,
|
||||
variants: await aVariants.build(options as any),
|
||||
...requiredLikeToAbove(a.required),
|
||||
disabled: (await getDisabledFn(options)) || [],
|
||||
immutable: false,
|
||||
}),
|
||||
asRequiredParser(aVariants.validator, a),
|
||||
)
|
||||
}
|
||||
return new Value<AsRequired<Type, Required>, WD>(
|
||||
async (options) => ({
|
||||
type: "union" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
...a,
|
||||
variants: await aVariants.build(options as any),
|
||||
...requiredLikeToAbove(a.required),
|
||||
disabled: (await getDisabledFn(options)) || [],
|
||||
immutable: false,
|
||||
}),
|
||||
asRequiredParser(aVariants.validator, a),
|
||||
)
|
||||
}
|
||||
|
||||
static list<Type, WrapperData>(a: List<Type, WrapperData>) {
|
||||
@@ -686,33 +692,3 @@ export class Value<Type, WD> {
|
||||
return this as any as Value<Type, NewWrapperData>
|
||||
}
|
||||
}
|
||||
|
||||
type Wrapper = { test: 1 | "5" }
|
||||
const valueA = Value.dynamicText<Wrapper>(() => ({
|
||||
name: "a",
|
||||
required: false,
|
||||
}))
|
||||
const variantForC = Variants.of({
|
||||
lnd: {
|
||||
name: "lnd Name",
|
||||
spec: Config.of({
|
||||
name: Value.text({
|
||||
name: "Node Name",
|
||||
required: false,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
})
|
||||
const valueC = Value.filteredUnion<Wrapper>(() => [])(
|
||||
{ name: "a", required: false },
|
||||
variantForC,
|
||||
)
|
||||
const valueB = Value.text({
|
||||
name: "a",
|
||||
required: false,
|
||||
})
|
||||
const test = Config.of({
|
||||
a: valueA,
|
||||
b: valueB,
|
||||
c: valueC,
|
||||
})
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
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(async ({ effects, utils }) => {
|
||||
const smtp = await utils.getSystemSmtp().once()
|
||||
return smtp ? [] : ["system"]
|
||||
})(
|
||||
export const smtpConfig = Value.filteredUnion(
|
||||
neverWrapperDataContract,
|
||||
async ({ effects, utils }) => {
|
||||
const smtp = await utils.getSystemSmtp().once()
|
||||
return smtp ? [] : ["system"]
|
||||
},
|
||||
{
|
||||
name: "SMTP",
|
||||
description: "Optionally provide an SMTP server for sending email",
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as D from "./dependencies"
|
||||
import { Config, ExtractConfigType } from "./builder/config"
|
||||
import { Utils, utils } from "../util"
|
||||
import nullIfEmpty from "../util/nullIfEmpty"
|
||||
import { WrapperDataContract } from "../wrapperData/wrapperDataContract"
|
||||
|
||||
declare const dependencyProof: unique symbol
|
||||
export type DependenciesReceipt = void & {
|
||||
@@ -52,6 +53,7 @@ export function setupConfig<
|
||||
Manifest extends SDKManifest,
|
||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||
>(
|
||||
wrapperDataContract: WrapperDataContract<WD>,
|
||||
spec: Config<Type, WD> | Config<Type, never>,
|
||||
write: Save<WD, Type, Manifest>,
|
||||
read: Read<WD, Type>,
|
||||
@@ -66,7 +68,7 @@ export function setupConfig<
|
||||
const { restart } = await write({
|
||||
input: JSON.parse(JSON.stringify(input)),
|
||||
effects,
|
||||
utils: utils<WD>(effects),
|
||||
utils: utils(wrapperDataContract, effects),
|
||||
dependencies: D.dependenciesSet<Manifest>(),
|
||||
})
|
||||
if (restart) {
|
||||
@@ -74,7 +76,7 @@ export function setupConfig<
|
||||
}
|
||||
}) as ExpectedExports.setConfig,
|
||||
getConfig: (async ({ effects }) => {
|
||||
const myUtils = utils<WD>(effects)
|
||||
const myUtils = utils(wrapperDataContract, effects)
|
||||
const configValue = nullIfEmpty(
|
||||
(await read({ effects, utils: myUtils })) || null,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user