feat: Add in the new types of the file and the value

This commit is contained in:
Blu-J
2023-07-28 14:03:29 -06:00
parent ba248eee28
commit 2d52b39409
3 changed files with 22 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ import { Config, LazyBuild, LazyBuildOptions } from "./config"
import { List } from "./list"
import { Variants } from "./variants"
import {
FilePath,
Pattern,
RandomString,
ValueSpec,
@@ -623,7 +624,7 @@ export class Value<Type, Store> {
}
}, spec.validator)
}
static file<Required extends boolean, Store>(a: {
static file<Required extends RequiredDefault<string>, Store>(a: {
name: string
description?: string | null
warning?: string | null
@@ -636,12 +637,13 @@ export class Value<Type, Store> {
warning: null,
...a,
}
if (a.required) {
return new Value<string, Store>(() => buildValue, string)
}
return new Value<string | null | undefined, Store>(
() => buildValue,
string.optional(),
return new Value<AsRequired<FilePath, Required>, Store>(
() => ({
...buildValue,
...requiredLikeToAbove(a.required),
}),
asRequiredParser(object({ filePath: string }), a),
)
}
static dynamicFile<Required extends boolean, Store>(

View File

@@ -58,6 +58,10 @@ export interface ValueSpecTextarea extends WithStandalone {
/** Immutable means it can only be configed at the first config then never again */
immutable: boolean
}
export type FilePath = {
filePath: string
}
export interface ValueSpecNumber extends ListValueSpecNumber, WithStandalone {
required: boolean
default: number | null

View File

@@ -4,10 +4,15 @@ import { Utils } from "../util/utils"
export type SetupExports<Store> = (opts: {
effects: Effects
utils: Utils<Store>
}) => {
ui: ExposeUiPaths<Store>
services: ExposeServicePaths<Store>
}
}) =>
| {
ui: ExposeUiPaths<Store>
services: ExposeServicePaths<Store>
}
| Promise<{
ui: ExposeUiPaths<Store>
services: ExposeServicePaths<Store>
}>
export const setupExports = <Store>(fn: (opts: SetupExports<Store>) => void) =>
fn