feat: Remove the vault

This commit is contained in:
Blu-J
2023-05-30 17:36:30 -06:00
parent 613bf74180
commit 3f5dbc6a4b
24 changed files with 308 additions and 515 deletions

View File

@@ -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>
}
}