mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 20:24:47 +00:00
feat: Move to filtered values
This commit is contained in:
@@ -585,8 +585,13 @@ export class Value<Type, WD, ConfigType> {
|
||||
default?: string | null
|
||||
},
|
||||
aVariants: Variants<Type, WrapperData, ConfigType>,
|
||||
getDisabledFn: LazyBuild<
|
||||
WrapperData,
|
||||
ConfigType,
|
||||
Array<Type extends { unionSelectKey: infer B } ? B & string : never>
|
||||
>,
|
||||
) {
|
||||
return new Value<AsRequired<Type, Required>, WrapperData, ConfigType>(
|
||||
return new Value<Type | null | undefined, WrapperData, ConfigType>(
|
||||
async (options) => ({
|
||||
type: "union" as const,
|
||||
description: null,
|
||||
@@ -594,8 +599,9 @@ export class Value<Type, WD, ConfigType> {
|
||||
...a,
|
||||
variants: await aVariants.build(options as any),
|
||||
...requiredLikeToAbove(a.required),
|
||||
disabled: (await getDisabledFn(options)) || [],
|
||||
}),
|
||||
asRequiredParser(aVariants.validator, a),
|
||||
aVariants.validator.optional(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -103,23 +103,4 @@ export class Variants<Type, WD, ConfigType> {
|
||||
return variants
|
||||
}, validator)
|
||||
}
|
||||
|
||||
/** Danger, don't filter everything!! */
|
||||
disableVariants(
|
||||
fn: LazyBuild<
|
||||
WD,
|
||||
ConfigType,
|
||||
Array<Type extends { unionSelectKey: infer B } ? B : never>
|
||||
>,
|
||||
) {
|
||||
const previousMe = this
|
||||
return new Variants<Type, WD, ConfigType>(async (options) => {
|
||||
const answer = { ...(await previousMe.build(options)) }
|
||||
const filterValues = await fn(options)
|
||||
for (const key of filterValues) {
|
||||
delete answer[key as any]
|
||||
}
|
||||
return answer
|
||||
}, this.validator)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ export interface ValueSpecUnion extends WithStandalone {
|
||||
spec: InputSpec
|
||||
}
|
||||
>
|
||||
disabled?: string[]
|
||||
required: boolean
|
||||
default: string | null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user