mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 20:24:47 +00:00
chore: Update dynamic for lists
This commit is contained in:
@@ -67,6 +67,54 @@ export class List<Type, WD, ConfigType> {
|
|||||||
}
|
}
|
||||||
}, arrayOf(string))
|
}, arrayOf(string))
|
||||||
}
|
}
|
||||||
|
static dynamicText<WD, CT>(
|
||||||
|
getA: LazyBuild<
|
||||||
|
WD,
|
||||||
|
CT,
|
||||||
|
{
|
||||||
|
name: string
|
||||||
|
description?: string | null
|
||||||
|
warning?: string | null
|
||||||
|
/** Default = [] */
|
||||||
|
default?: string[]
|
||||||
|
minLength?: number | null
|
||||||
|
maxLength?: number | null
|
||||||
|
spec: {
|
||||||
|
/** Default = false */
|
||||||
|
masked?: boolean
|
||||||
|
placeholder?: string | null
|
||||||
|
minLength?: number | null
|
||||||
|
maxLength?: number | null
|
||||||
|
patterns: Pattern[]
|
||||||
|
/** Default = "text" */
|
||||||
|
inputmode?: ListValueSpecText["inputmode"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>,
|
||||||
|
) {
|
||||||
|
return new List<string[], WD, CT>(async (options) => {
|
||||||
|
const { spec: aSpec, ...a } = await getA(options)
|
||||||
|
const spec = {
|
||||||
|
type: "text" as const,
|
||||||
|
placeholder: null,
|
||||||
|
minLength: null,
|
||||||
|
maxLength: null,
|
||||||
|
masked: false,
|
||||||
|
inputmode: "text" as const,
|
||||||
|
...aSpec,
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
description: null,
|
||||||
|
warning: null,
|
||||||
|
default: [],
|
||||||
|
type: "list" as const,
|
||||||
|
minLength: null,
|
||||||
|
maxLength: null,
|
||||||
|
...a,
|
||||||
|
spec,
|
||||||
|
}
|
||||||
|
}, arrayOf(string))
|
||||||
|
}
|
||||||
static number<WD, CT>(
|
static number<WD, CT>(
|
||||||
a: {
|
a: {
|
||||||
name: string
|
name: string
|
||||||
@@ -108,6 +156,52 @@ export class List<Type, WD, ConfigType> {
|
|||||||
}
|
}
|
||||||
}, arrayOf(number))
|
}, arrayOf(number))
|
||||||
}
|
}
|
||||||
|
static dynamicNumber<WD, CT>(
|
||||||
|
getA: LazyBuild<
|
||||||
|
WD,
|
||||||
|
CT,
|
||||||
|
{
|
||||||
|
name: string
|
||||||
|
description?: string | null
|
||||||
|
warning?: string | null
|
||||||
|
/** Default = [] */
|
||||||
|
default?: string[]
|
||||||
|
minLength?: number | null
|
||||||
|
maxLength?: number | null
|
||||||
|
spec: {
|
||||||
|
integer: boolean
|
||||||
|
min?: number | null
|
||||||
|
max?: number | null
|
||||||
|
step?: string | null
|
||||||
|
units?: string | null
|
||||||
|
placeholder?: string | null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>,
|
||||||
|
) {
|
||||||
|
return new List<number[], WD, CT>(async (options) => {
|
||||||
|
const { spec: aSpec, ...a } = await getA(options)
|
||||||
|
const spec = {
|
||||||
|
type: "number" as const,
|
||||||
|
placeholder: null,
|
||||||
|
min: null,
|
||||||
|
max: null,
|
||||||
|
step: null,
|
||||||
|
units: null,
|
||||||
|
...aSpec,
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
description: null,
|
||||||
|
warning: null,
|
||||||
|
minLength: null,
|
||||||
|
maxLength: null,
|
||||||
|
default: [],
|
||||||
|
type: "list" as const,
|
||||||
|
...a,
|
||||||
|
spec,
|
||||||
|
}
|
||||||
|
}, arrayOf(number))
|
||||||
|
}
|
||||||
static obj<Type extends Record<string, any>, WrapperData, ConfigType>(
|
static obj<Type extends Record<string, any>, WrapperData, ConfigType>(
|
||||||
a: {
|
a: {
|
||||||
name: string
|
name: string
|
||||||
|
|||||||
@@ -609,6 +609,45 @@ describe("Builder List", () => {
|
|||||||
validator.unsafeCast(["test", "text"])
|
validator.unsafeCast(["test", "text"])
|
||||||
testOutput<typeof validator._TYPE, string[]>()(null)
|
testOutput<typeof validator._TYPE, string[]>()(null)
|
||||||
})
|
})
|
||||||
|
describe("dynamic", () => {
|
||||||
|
test("text", async () => {
|
||||||
|
const value = Value.list(
|
||||||
|
List.dynamicText(() => ({
|
||||||
|
name: "test",
|
||||||
|
spec: { patterns: [] },
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
const validator = value.validator
|
||||||
|
validator.unsafeCast(["test", "text"])
|
||||||
|
expect(() => validator.unsafeCast([3,4])).toThrowError()
|
||||||
|
expect(() => validator.unsafeCast(null)).toThrowError()
|
||||||
|
testOutput<typeof validator._TYPE, string[]>()(null)
|
||||||
|
expect(await value.build({} as any)).toMatchObject({
|
||||||
|
name: "test",
|
||||||
|
spec: { patterns: [] },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
test("number", async () => {
|
||||||
|
const value = Value.list(
|
||||||
|
List.dynamicNumber(() => ({
|
||||||
|
name: "test",
|
||||||
|
spec: { integer: true },
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
const validator = value.validator
|
||||||
|
expect(() =>
|
||||||
|
validator.unsafeCast(["test", "text"])).toThrowError()
|
||||||
|
validator.unsafeCast([4,2])
|
||||||
|
expect(() => validator.unsafeCast(null)).toThrowError()
|
||||||
|
validator.unsafeCast([])
|
||||||
|
testOutput<typeof validator._TYPE, number[]>()(null)
|
||||||
|
expect(await value.build({} as any)).toMatchObject({
|
||||||
|
name: "test",
|
||||||
|
spec: { integer: true },
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Nested nullable values", () => {
|
describe("Nested nullable values", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user