mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-01 21:13:11 +00:00
feat: Remove the vault
This commit is contained in:
@@ -5,28 +5,24 @@ import { _ } from "../../util"
|
||||
import { Effects } from "../../types"
|
||||
import { Parser, object } from "ts-matches"
|
||||
|
||||
export type LazyBuildOptions<Store, Vault> = {
|
||||
export type LazyBuildOptions<Store> = {
|
||||
effects: Effects
|
||||
utils: Utils<Store, Vault>
|
||||
utils: Utils<Store>
|
||||
}
|
||||
export type LazyBuild<Store, Vault, ExpectedOut> = (
|
||||
options: LazyBuildOptions<Store, Vault>,
|
||||
export type LazyBuild<Store, ExpectedOut> = (
|
||||
options: LazyBuildOptions<Store>,
|
||||
) => Promise<ExpectedOut> | ExpectedOut
|
||||
|
||||
// prettier-ignore
|
||||
export type ExtractConfigType<A extends Record<string, any> | Config<Record<string, any>, any, any> | Config<Record<string, any>, never, never>> =
|
||||
A extends Config<infer B, any, any> | Config<infer B, never, never> ? B :
|
||||
export type ExtractConfigType<A extends Record<string, any> | Config<Record<string, any>, any> | Config<Record<string, any>, never>> =
|
||||
A extends Config<infer B, any> | Config<infer B, never> ? B :
|
||||
A
|
||||
|
||||
export type ConfigSpecOf<
|
||||
A extends Record<string, any>,
|
||||
Store = never,
|
||||
Vault = never,
|
||||
> = {
|
||||
[K in keyof A]: Value<A[K], Store, Vault>
|
||||
export type ConfigSpecOf<A extends Record<string, any>, Store = never> = {
|
||||
[K in keyof A]: Value<A[K], Store>
|
||||
}
|
||||
|
||||
export type MaybeLazyValues<A> = LazyBuild<any, any, A> | A
|
||||
export type MaybeLazyValues<A> = LazyBuild<any, A> | A
|
||||
/**
|
||||
* Configs are the specs that are used by the os configuration form for this service.
|
||||
* Here is an example of a simple configuration
|
||||
@@ -83,20 +79,14 @@ export const addNodesSpec = Config.of({ hostname: hostname, port: port });
|
||||
|
||||
```
|
||||
*/
|
||||
export class Config<
|
||||
Type extends Record<string, any>,
|
||||
Store = never,
|
||||
Vault = never,
|
||||
> {
|
||||
export class Config<Type extends Record<string, any>, Store = never> {
|
||||
private constructor(
|
||||
private readonly spec: {
|
||||
[K in keyof Type]:
|
||||
| Value<Type[K], Store, Vault>
|
||||
| Value<Type[K], never, never>
|
||||
[K in keyof Type]: Value<Type[K], Store> | Value<Type[K], never>
|
||||
},
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
async build(options: LazyBuildOptions<Store, Vault>) {
|
||||
async build(options: LazyBuildOptions<Store>) {
|
||||
const answer = {} as {
|
||||
[K in keyof Type]: ValueSpec
|
||||
}
|
||||
@@ -107,12 +97,8 @@ export class Config<
|
||||
}
|
||||
|
||||
static of<
|
||||
Spec extends Record<
|
||||
string,
|
||||
Value<any, Store, Vault> | Value<any, never, never>
|
||||
>,
|
||||
Spec extends Record<string, Value<any, Store> | Value<any, never>>,
|
||||
Store = never,
|
||||
Vault = never,
|
||||
>(spec: Spec) {
|
||||
const validatorObj = {} as {
|
||||
[K in keyof Spec]: Parser<unknown, any>
|
||||
@@ -124,13 +110,12 @@ export class Config<
|
||||
return new Config<
|
||||
{
|
||||
[K in keyof Spec]: Spec[K] extends
|
||||
| Value<infer T, Store, Vault>
|
||||
| Value<infer T, never, never>
|
||||
| Value<infer T, Store>
|
||||
| Value<infer T, never>
|
||||
? T
|
||||
: never
|
||||
},
|
||||
Store,
|
||||
Vault
|
||||
Store
|
||||
>(spec, validator as any)
|
||||
}
|
||||
|
||||
@@ -149,6 +134,6 @@ export class Config<
|
||||
```
|
||||
*/
|
||||
withStore<NewStore extends Store extends never ? any : Store>() {
|
||||
return this as any as Config<Type, NewStore, Vault>
|
||||
return this as any as Config<Type, NewStore>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ export const authorizationList = List.string({
|
||||
export const auth = Value.list(authorizationList);
|
||||
```
|
||||
*/
|
||||
export class List<Type, Store, Vault> {
|
||||
export class List<Type, Store> {
|
||||
private constructor(
|
||||
public build: LazyBuild<Store, Vault, ValueSpecList>,
|
||||
public build: LazyBuild<Store, ValueSpecList>,
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
static text(
|
||||
@@ -49,7 +49,7 @@ export class List<Type, Store, Vault> {
|
||||
generate?: null | RandomString
|
||||
},
|
||||
) {
|
||||
return new List<string[], never, never>(() => {
|
||||
return new List<string[], never>(() => {
|
||||
const spec = {
|
||||
type: "text" as const,
|
||||
placeholder: null,
|
||||
@@ -74,10 +74,9 @@ export class List<Type, Store, Vault> {
|
||||
return built
|
||||
}, arrayOf(string))
|
||||
}
|
||||
static dynamicText<Store = never, Vault = never>(
|
||||
static dynamicText<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -101,7 +100,7 @@ export class List<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new List<string[], Store, Vault>(async (options) => {
|
||||
return new List<string[], Store>(async (options) => {
|
||||
const { spec: aSpec, ...a } = await getA(options)
|
||||
const spec = {
|
||||
type: "text" as const,
|
||||
@@ -146,7 +145,7 @@ export class List<Type, Store, Vault> {
|
||||
placeholder?: string | null
|
||||
},
|
||||
) {
|
||||
return new List<number[], never, never>(() => {
|
||||
return new List<number[], never>(() => {
|
||||
const spec = {
|
||||
type: "number" as const,
|
||||
placeholder: null,
|
||||
@@ -170,10 +169,9 @@ export class List<Type, Store, Vault> {
|
||||
return built
|
||||
}, arrayOf(number))
|
||||
}
|
||||
static dynamicNumber<Store = never, Vault = never>(
|
||||
static dynamicNumber<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -194,7 +192,7 @@ export class List<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new List<number[], Store, Vault>(async (options) => {
|
||||
return new List<number[], Store>(async (options) => {
|
||||
const { spec: aSpec, ...a } = await getA(options)
|
||||
const spec = {
|
||||
type: "number" as const,
|
||||
@@ -218,7 +216,7 @@ export class List<Type, Store, Vault> {
|
||||
}
|
||||
}, arrayOf(number))
|
||||
}
|
||||
static obj<Type extends Record<string, any>, Store, Vault>(
|
||||
static obj<Type extends Record<string, any>, Store>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -229,12 +227,12 @@ export class List<Type, Store, Vault> {
|
||||
maxLength?: number | null
|
||||
},
|
||||
aSpec: {
|
||||
spec: Config<Type, Store, Vault>
|
||||
spec: Config<Type, Store>
|
||||
displayAs?: null | string
|
||||
uniqueBy?: null | UniqueBy
|
||||
},
|
||||
) {
|
||||
return new List<Type[], Store, Vault>(async (options) => {
|
||||
return new List<Type[], Store>(async (options) => {
|
||||
const { spec: previousSpecSpec, ...restSpec } = aSpec
|
||||
const specSpec = await previousSpecSpec.build(options)
|
||||
const spec = {
|
||||
@@ -276,6 +274,6 @@ export class List<Type, Store, Vault> {
|
||||
```
|
||||
*/
|
||||
withStore<NewStore extends Store extends never ? any : Store>() {
|
||||
return this as any as List<Type, NewStore, Vault>
|
||||
return this as any as List<Type, NewStore>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +94,9 @@ const username = Value.string({
|
||||
});
|
||||
```
|
||||
*/
|
||||
export class Value<Type, Store, Vault> {
|
||||
export class Value<Type, Store> {
|
||||
protected constructor(
|
||||
public build: LazyBuild<Store, Vault, ValueSpec>,
|
||||
public build: LazyBuild<Store, ValueSpec>,
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
static toggle(a: {
|
||||
@@ -108,7 +108,7 @@ export class Value<Type, Store, Vault> {
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<boolean, never, never>(
|
||||
return new Value<boolean, never>(
|
||||
async () => ({
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -120,10 +120,9 @@ export class Value<Type, Store, Vault> {
|
||||
boolean,
|
||||
)
|
||||
}
|
||||
static dynamicToggle<Store = never, Vault = never>(
|
||||
static dynamicToggle<Store = never>(
|
||||
a: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -133,7 +132,7 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<boolean, Store, Vault>(
|
||||
return new Value<boolean, Store>(
|
||||
async (options) => ({
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -165,7 +164,7 @@ export class Value<Type, Store, Vault> {
|
||||
immutable?: boolean
|
||||
generate?: null | RandomString
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, never, never>(
|
||||
return new Value<AsRequired<string, Required>, never>(
|
||||
async () => ({
|
||||
type: "text" as const,
|
||||
description: null,
|
||||
@@ -185,10 +184,9 @@ export class Value<Type, Store, Vault> {
|
||||
asRequiredParser(string, a),
|
||||
)
|
||||
}
|
||||
static dynamicText<Store = never, Vault = never>(
|
||||
static dynamicText<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -211,28 +209,25 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, Store, Vault>(
|
||||
async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "text" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
masked: false,
|
||||
placeholder: null,
|
||||
minLength: null,
|
||||
maxLength: null,
|
||||
patterns: [],
|
||||
inputmode: "text",
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
generate: a.generate ?? null,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
},
|
||||
string.optional(),
|
||||
)
|
||||
return new Value<string | null | undefined, Store>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "text" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
masked: false,
|
||||
placeholder: null,
|
||||
minLength: null,
|
||||
maxLength: null,
|
||||
patterns: [],
|
||||
inputmode: "text",
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
generate: a.generate ?? null,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
}, string.optional())
|
||||
}
|
||||
static textarea(a: {
|
||||
name: string
|
||||
@@ -246,7 +241,7 @@ export class Value<Type, Store, Vault> {
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<string, never, never>(async () => {
|
||||
return new Value<string, never>(async () => {
|
||||
const built: ValueSpecTextarea = {
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -261,10 +256,9 @@ export class Value<Type, Store, Vault> {
|
||||
return built
|
||||
}, string)
|
||||
}
|
||||
static dynamicTextarea<Store = never, Vault = never>(
|
||||
static dynamicTextarea<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -277,7 +271,7 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string, Store, Vault>(async (options) => {
|
||||
return new Value<string, Store>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
description: null,
|
||||
@@ -308,7 +302,7 @@ export class Value<Type, Store, Vault> {
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<AsRequired<number, Required>, never, never>(
|
||||
return new Value<AsRequired<number, Required>, never>(
|
||||
() => ({
|
||||
type: "number" as const,
|
||||
description: null,
|
||||
@@ -326,10 +320,9 @@ export class Value<Type, Store, Vault> {
|
||||
asRequiredParser(number, a),
|
||||
)
|
||||
}
|
||||
static dynamicNumber<Store = never, Vault = never>(
|
||||
static dynamicNumber<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -346,26 +339,23 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<number | null | undefined, Store, Vault>(
|
||||
async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "number" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
min: null,
|
||||
max: null,
|
||||
step: null,
|
||||
units: null,
|
||||
placeholder: null,
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
},
|
||||
number.optional(),
|
||||
)
|
||||
return new Value<number | null | undefined, Store>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "number" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
min: null,
|
||||
max: null,
|
||||
step: null,
|
||||
units: null,
|
||||
placeholder: null,
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
}, number.optional())
|
||||
}
|
||||
static color<Required extends RequiredDefault<string>>(a: {
|
||||
name: string
|
||||
@@ -376,7 +366,7 @@ export class Value<Type, Store, Vault> {
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, never, never>(
|
||||
return new Value<AsRequired<string, Required>, never>(
|
||||
() => ({
|
||||
type: "color" as const,
|
||||
description: null,
|
||||
@@ -391,10 +381,9 @@ export class Value<Type, Store, Vault> {
|
||||
)
|
||||
}
|
||||
|
||||
static dynamicColor<Store = never, Vault = never>(
|
||||
static dynamicColor<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -404,21 +393,18 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, Store, Vault>(
|
||||
async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "color" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
},
|
||||
string.optional(),
|
||||
)
|
||||
return new Value<string | null | undefined, Store>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "color" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
}, string.optional())
|
||||
}
|
||||
static datetime<Required extends RequiredDefault<string>>(a: {
|
||||
name: string
|
||||
@@ -433,7 +419,7 @@ export class Value<Type, Store, Vault> {
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<AsRequired<string, Required>, never, never>(
|
||||
return new Value<AsRequired<string, Required>, never>(
|
||||
() => ({
|
||||
type: "datetime" as const,
|
||||
description: null,
|
||||
@@ -450,10 +436,9 @@ export class Value<Type, Store, Vault> {
|
||||
asRequiredParser(string, a),
|
||||
)
|
||||
}
|
||||
static dynamicDatetime<Store = never, Vault = never>(
|
||||
static dynamicDatetime<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -467,24 +452,21 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, Store, Vault>(
|
||||
async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "datetime" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
inputmode: "datetime-local",
|
||||
min: null,
|
||||
max: null,
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
},
|
||||
string.optional(),
|
||||
)
|
||||
return new Value<string | null | undefined, Store>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "datetime" as const,
|
||||
description: null,
|
||||
warning: null,
|
||||
inputmode: "datetime-local",
|
||||
min: null,
|
||||
max: null,
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
}, string.optional())
|
||||
}
|
||||
static select<
|
||||
Required extends RequiredDefault<string>,
|
||||
@@ -505,7 +487,7 @@ export class Value<Type, Store, Vault> {
|
||||
Default is false */
|
||||
immutable?: boolean
|
||||
}) {
|
||||
return new Value<AsRequired<keyof B, Required>, never, never>(
|
||||
return new Value<AsRequired<keyof B, Required>, never>(
|
||||
() => ({
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -523,10 +505,9 @@ export class Value<Type, Store, Vault> {
|
||||
) as any,
|
||||
)
|
||||
}
|
||||
static dynamicSelect<Store = never, Vault = never>(
|
||||
static dynamicSelect<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -542,21 +523,18 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, Store, Vault>(
|
||||
async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
description: null,
|
||||
warning: null,
|
||||
type: "select" as const,
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
},
|
||||
string.optional(),
|
||||
)
|
||||
return new Value<string | null | undefined, Store>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
description: null,
|
||||
warning: null,
|
||||
type: "select" as const,
|
||||
disabled: false,
|
||||
immutable: false,
|
||||
...a,
|
||||
...requiredLikeToAbove(a.required),
|
||||
}
|
||||
}, string.optional())
|
||||
}
|
||||
static multiselect<Values extends Record<string, string>>(a: {
|
||||
name: string
|
||||
@@ -576,7 +554,7 @@ export class Value<Type, Store, Vault> {
|
||||
*/
|
||||
disabled?: false | string | (string & keyof Values)[]
|
||||
}) {
|
||||
return new Value<(keyof Values)[], never, never>(
|
||||
return new Value<(keyof Values)[], never>(
|
||||
() => ({
|
||||
type: "multiselect" as const,
|
||||
minLength: null,
|
||||
@@ -592,10 +570,9 @@ export class Value<Type, Store, Vault> {
|
||||
),
|
||||
)
|
||||
}
|
||||
static dynamicMultiselect<Store = never, Vault = never>(
|
||||
static dynamicMultiselect<Store = never>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -613,7 +590,7 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string[], Store, Vault>(async (options) => {
|
||||
return new Value<string[], Store>(async (options) => {
|
||||
const a = await getA(options)
|
||||
return {
|
||||
type: "multiselect" as const,
|
||||
@@ -627,15 +604,15 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
}, arrayOf(string))
|
||||
}
|
||||
static object<Type extends Record<string, any>, Store, Vault>(
|
||||
static object<Type extends Record<string, any>, Store>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
},
|
||||
spec: Config<Type, Store, Vault>,
|
||||
spec: Config<Type, Store>,
|
||||
) {
|
||||
return new Value<Type, Store, Vault>(async (options) => {
|
||||
return new Value<Type, Store>(async (options) => {
|
||||
const built = await spec.build(options as any)
|
||||
return {
|
||||
type: "object" as const,
|
||||
@@ -646,7 +623,7 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
}, spec.validator)
|
||||
}
|
||||
static file<Required extends boolean, Store, Vault>(a: {
|
||||
static file<Required extends boolean, Store>(a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
@@ -660,17 +637,16 @@ export class Value<Type, Store, Vault> {
|
||||
...a,
|
||||
}
|
||||
if (a.required) {
|
||||
return new Value<string, Store, Vault>(() => buildValue, string)
|
||||
return new Value<string, Store>(() => buildValue, string)
|
||||
}
|
||||
return new Value<string | null | undefined, Store, Vault>(
|
||||
return new Value<string | null | undefined, Store>(
|
||||
() => buildValue,
|
||||
string.optional(),
|
||||
)
|
||||
}
|
||||
static dynamicFile<Required extends boolean, Store, Vault>(
|
||||
static dynamicFile<Required extends boolean, Store>(
|
||||
a: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -680,7 +656,7 @@ export class Value<Type, Store, Vault> {
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return new Value<string | null | undefined, Store, Vault>(
|
||||
return new Value<string | null | undefined, Store>(
|
||||
async (options) => ({
|
||||
type: "file" as const,
|
||||
description: null,
|
||||
@@ -690,7 +666,7 @@ export class Value<Type, Store, Vault> {
|
||||
string.optional(),
|
||||
)
|
||||
}
|
||||
static union<Required extends RequiredDefault<string>, Type, Store, Vault>(
|
||||
static union<Required extends RequiredDefault<string>, Type, Store>(
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
@@ -706,9 +682,9 @@ export class Value<Type, Store, Vault> {
|
||||
*/
|
||||
disabled?: false | string | string[]
|
||||
},
|
||||
aVariants: Variants<Type, Store, Vault>,
|
||||
aVariants: Variants<Type, Store>,
|
||||
) {
|
||||
return new Value<AsRequired<Type, Required>, Store, Vault>(
|
||||
return new Value<AsRequired<Type, Required>, Store>(
|
||||
async (options) => ({
|
||||
type: "union" as const,
|
||||
description: null,
|
||||
@@ -726,18 +702,17 @@ export class Value<Type, Store, Vault> {
|
||||
Required extends RequiredDefault<string>,
|
||||
Type extends Record<string, any>,
|
||||
Store = never,
|
||||
Vault = never,
|
||||
>(
|
||||
getDisabledFn: LazyBuild<Store, Vault, string[] | false | string>,
|
||||
getDisabledFn: LazyBuild<Store, string[] | false | string>,
|
||||
a: {
|
||||
name: string
|
||||
description?: string | null
|
||||
warning?: string | null
|
||||
required: Required
|
||||
},
|
||||
aVariants: Variants<Type, Store, Vault> | Variants<Type, never, never>,
|
||||
aVariants: Variants<Type, Store> | Variants<Type, never>,
|
||||
) {
|
||||
return new Value<AsRequired<Type, Required>, Store, Vault>(
|
||||
return new Value<AsRequired<Type, Required>, Store>(
|
||||
async (options) => ({
|
||||
type: "union" as const,
|
||||
description: null,
|
||||
@@ -755,11 +730,9 @@ export class Value<Type, Store, Vault> {
|
||||
Required extends RequiredDefault<string>,
|
||||
Type extends Record<string, any>,
|
||||
Store = never,
|
||||
Vault = never,
|
||||
>(
|
||||
getA: LazyBuild<
|
||||
Store,
|
||||
Vault,
|
||||
{
|
||||
disabled: string[] | false | string
|
||||
name: string
|
||||
@@ -768,9 +741,9 @@ export class Value<Type, Store, Vault> {
|
||||
required: Required
|
||||
}
|
||||
>,
|
||||
aVariants: Variants<Type, Store, Vault> | Variants<Type, never, never>,
|
||||
aVariants: Variants<Type, Store> | Variants<Type, never>,
|
||||
) {
|
||||
return new Value<Type | null | undefined, Store, Vault>(async (options) => {
|
||||
return new Value<Type | null | undefined, Store>(async (options) => {
|
||||
const newValues = await getA(options)
|
||||
return {
|
||||
type: "union" as const,
|
||||
@@ -784,11 +757,8 @@ export class Value<Type, Store, Vault> {
|
||||
}, aVariants.validator.optional())
|
||||
}
|
||||
|
||||
static list<Type, Store, Vault>(a: List<Type, Store, Vault>) {
|
||||
return new Value<Type, Store, Vault>(
|
||||
(options) => a.build(options),
|
||||
a.validator,
|
||||
)
|
||||
static list<Type, Store>(a: List<Type, Store>) {
|
||||
return new Value<Type, Store>((options) => a.build(options), a.validator)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -806,6 +776,6 @@ export class Value<Type, Store, Vault> {
|
||||
```
|
||||
*/
|
||||
withStore<NewStore extends Store extends never ? any : Store>() {
|
||||
return this as any as Value<Type, NewStore, Vault>
|
||||
return this as any as Value<Type, NewStore>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,21 +51,20 @@ export const pruning = Value.union(
|
||||
);
|
||||
```
|
||||
*/
|
||||
export class Variants<Type, Store, Vault> {
|
||||
export class Variants<Type, Store> {
|
||||
static text: any
|
||||
private constructor(
|
||||
public build: LazyBuild<Store, Vault, ValueSpecUnion["variants"]>,
|
||||
public build: LazyBuild<Store, ValueSpecUnion["variants"]>,
|
||||
public validator: Parser<unknown, Type>,
|
||||
) {}
|
||||
static of<
|
||||
VariantValues extends {
|
||||
[K in string]: {
|
||||
name: string
|
||||
spec: Config<any, Store, Vault> | Config<any, never, never>
|
||||
spec: Config<any, Store> | Config<any, never>
|
||||
}
|
||||
},
|
||||
Store = never,
|
||||
Vault = never,
|
||||
>(a: VariantValues) {
|
||||
const validator = anyOf(
|
||||
...Object.entries(a).map(([name, { spec }]) =>
|
||||
@@ -82,12 +81,11 @@ export class Variants<Type, Store, Vault> {
|
||||
unionSelectKey: K
|
||||
// prettier-ignore
|
||||
unionValueKey:
|
||||
VariantValues[K]["spec"] extends (Config<infer B, Store,Vault> | Config<infer B, never, never>) ? B :
|
||||
VariantValues[K]["spec"] extends (Config<infer B, Store> | Config<infer B, never>) ? B :
|
||||
never
|
||||
}
|
||||
}[keyof VariantValues],
|
||||
Store,
|
||||
Vault
|
||||
Store
|
||||
>(async (options) => {
|
||||
const variants = {} as {
|
||||
[K in keyof VariantValues]: { name: string; spec: InputSpec }
|
||||
@@ -117,6 +115,6 @@ export class Variants<Type, Store, Vault> {
|
||||
```
|
||||
*/
|
||||
withStore<NewStore extends Store extends never ? any : Store>() {
|
||||
return this as any as Variants<Type, NewStore, Vault>
|
||||
return this as any as Variants<Type, NewStore>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Variants } from "./builder/variants"
|
||||
/**
|
||||
* Base SMTP settings, to be used by StartOS for system wide SMTP
|
||||
*/
|
||||
export const customSmtp = Config.of<ConfigSpecOf<SmtpValue>, never, never>({
|
||||
export const customSmtp = Config.of<ConfigSpecOf<SmtpValue>, never>({
|
||||
server: Value.text({
|
||||
name: "SMTP Server",
|
||||
required: {
|
||||
|
||||
@@ -14,16 +14,15 @@ export type DependenciesReceipt = void & {
|
||||
|
||||
export type Save<
|
||||
Store,
|
||||
Vault,
|
||||
A extends
|
||||
| Record<string, any>
|
||||
| Config<Record<string, any>, any, any>
|
||||
| Config<Record<string, never>, never, never>,
|
||||
| Config<Record<string, any>, any>
|
||||
| Config<Record<string, never>, never>,
|
||||
Manifest extends SDKManifest,
|
||||
> = (options: {
|
||||
effects: Effects
|
||||
input: ExtractConfigType<A> & Record<string, any>
|
||||
utils: Utils<Store, Vault>
|
||||
utils: Utils<Store>
|
||||
dependencies: D.ConfigDependencies<Manifest>
|
||||
}) => Promise<{
|
||||
dependenciesReceipt: DependenciesReceipt
|
||||
@@ -32,14 +31,13 @@ export type Save<
|
||||
}>
|
||||
export type Read<
|
||||
Store,
|
||||
Vault,
|
||||
A extends
|
||||
| Record<string, any>
|
||||
| Config<Record<string, any>, any, any>
|
||||
| Config<Record<string, any>, never, never>,
|
||||
| Config<Record<string, any>, any>
|
||||
| Config<Record<string, any>, never>,
|
||||
> = (options: {
|
||||
effects: Effects
|
||||
utils: Utils<Store, Vault>
|
||||
utils: Utils<Store>
|
||||
}) => Promise<void | (ExtractConfigType<A> & Record<string, any>)>
|
||||
/**
|
||||
* We want to setup a config export with a get and set, this
|
||||
@@ -50,17 +48,16 @@ export type Read<
|
||||
*/
|
||||
export function setupConfig<
|
||||
Store,
|
||||
Vault,
|
||||
ConfigType extends
|
||||
| Record<string, any>
|
||||
| Config<any, any, any>
|
||||
| Config<any, never, never>,
|
||||
| Config<any, any>
|
||||
| Config<any, never>,
|
||||
Manifest extends SDKManifest,
|
||||
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||
>(
|
||||
spec: Config<Type, Store, Vault> | Config<Type, never, never>,
|
||||
write: Save<Store, Vault, Type, Manifest>,
|
||||
read: Read<Store, Vault, Type>,
|
||||
spec: Config<Type, Store> | Config<Type, never>,
|
||||
write: Save<Store, Type, Manifest>,
|
||||
read: Read<Store, Type>,
|
||||
) {
|
||||
const validator = spec.validator
|
||||
return {
|
||||
@@ -82,7 +79,7 @@ export function setupConfig<
|
||||
}
|
||||
}) as ExpectedExports.setConfig,
|
||||
getConfig: (async ({ effects }) => {
|
||||
const myUtils = utils<Store, Vault>(effects)
|
||||
const myUtils = utils<Store>(effects)
|
||||
const configValue = nullIfEmpty(
|
||||
(await read({ effects, utils: myUtils })) || null,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user