mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
fix: Fix the wrapper data types
This commit is contained in:
@@ -619,7 +619,7 @@ describe("Builder List", () => {
|
||||
)
|
||||
const validator = value.validator
|
||||
validator.unsafeCast(["test", "text"])
|
||||
expect(() => validator.unsafeCast([3,4])).toThrowError()
|
||||
expect(() => validator.unsafeCast([3, 4])).toThrowError()
|
||||
expect(() => validator.unsafeCast(null)).toThrowError()
|
||||
testOutput<typeof validator._TYPE, string[]>()(null)
|
||||
expect(await value.build({} as any)).toMatchObject({
|
||||
@@ -636,9 +636,8 @@ describe("Builder List", () => {
|
||||
})),
|
||||
)
|
||||
const validator = value.validator
|
||||
expect(() =>
|
||||
validator.unsafeCast(["test", "text"])).toThrowError()
|
||||
validator.unsafeCast([4,2])
|
||||
expect(() => validator.unsafeCast(["test", "text"])).toThrowError()
|
||||
validator.unsafeCast([4, 2])
|
||||
expect(() => validator.unsafeCast(null)).toThrowError()
|
||||
validator.unsafeCast([])
|
||||
testOutput<typeof validator._TYPE, number[]>()(null)
|
||||
@@ -648,7 +647,6 @@ describe("Builder List", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("Nested nullable values", () => {
|
||||
test("Testing text", async () => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { utils } from "../util"
|
||||
|
||||
type WrapperType = {
|
||||
config: {
|
||||
someValue: string
|
||||
someValue: "a" | "b"
|
||||
}
|
||||
}
|
||||
const todo = <A>(): A => {
|
||||
@@ -12,10 +12,16 @@ const todo = <A>(): A => {
|
||||
const noop = () => {}
|
||||
describe("wrapperData", () => {
|
||||
test.skip("types", async () => {
|
||||
utils<WrapperType>(todo<T.Effects>()).setOwnWrapperData("/config", {
|
||||
someValue: "a",
|
||||
})
|
||||
utils<WrapperType>(todo<T.Effects>()).setOwnWrapperData(
|
||||
"/config/someValue",
|
||||
"someValue",
|
||||
"b",
|
||||
)
|
||||
utils<WrapperType>(todo<T.Effects>()).setOwnWrapperData("", {
|
||||
config: { someValue: "b" },
|
||||
})
|
||||
utils<WrapperType>(todo<T.Effects>()).setOwnWrapperData(
|
||||
"/config/someValue",
|
||||
|
||||
@@ -30,7 +36,7 @@ describe("wrapperData", () => {
|
||||
|
||||
todo<T.Effects>().setWrapperData<WrapperType, "/config/someValue">({
|
||||
path: "/config/someValue",
|
||||
value: "someValueIn",
|
||||
value: "b",
|
||||
})
|
||||
todo<T.Effects>().setWrapperData<WrapperType, "/config/some2Value">({
|
||||
//@ts-expect-error Path is wrong
|
||||
@@ -41,7 +47,7 @@ describe("wrapperData", () => {
|
||||
todo<T.Effects>().setWrapperData<WrapperType, "/config/someValue">({
|
||||
//@ts-expect-error Path is wrong
|
||||
path: "/config/some2Value",
|
||||
value: "someValueIn",
|
||||
value: "a",
|
||||
})
|
||||
;(await utils<WrapperType, {}>(todo<T.Effects>())
|
||||
.getOwnWrapperData("/config/someValue")
|
||||
@@ -53,7 +59,17 @@ describe("wrapperData", () => {
|
||||
// @ts-expect-error Path is wrong
|
||||
.getOwnWrapperData("/config/somdsfeValue")
|
||||
.const()
|
||||
///
|
||||
/// ----------------- ERRORS -----------------
|
||||
|
||||
utils<WrapperType>(todo<T.Effects>()).setOwnWrapperData("", {
|
||||
// @ts-expect-error Type is wrong for the setting value
|
||||
config: { someValue: "notInAOrB" },
|
||||
})
|
||||
utils<WrapperType>(todo<T.Effects>()).setOwnWrapperData(
|
||||
"/config/someValue",
|
||||
// @ts-expect-error Type is wrong for the setting value
|
||||
"notInAOrB",
|
||||
)
|
||||
;(await utils<WrapperType>(todo<T.Effects>())
|
||||
.getOwnWrapperData("/config/someValue")
|
||||
// @ts-expect-error Const should normally not be callable
|
||||
|
||||
@@ -418,13 +418,15 @@ export type Effects = {
|
||||
export type ExtractWrapperData<WrapperData, Path extends string> =
|
||||
Path extends `/${infer A }/${infer Rest }` ? (A extends keyof WrapperData ? ExtractWrapperData<WrapperData[A], `/${Rest}`> : never) :
|
||||
Path extends `/${infer A }` ? (A extends keyof WrapperData ? WrapperData[A] : never) :
|
||||
Path extends '' ? WrapperData :
|
||||
never
|
||||
|
||||
// prettier-ignore
|
||||
type _EnsureWrapperDataPath<WrapperData, Path extends string, Origin extends string> =
|
||||
Path extends `/${infer A }/${infer Rest }` ? (A extends keyof WrapperData ? ExtractWrapperData<WrapperData[A], `/${Rest}`> : never) :
|
||||
Path extends `/${infer A }` ? (A extends keyof WrapperData ? Origin : never) :
|
||||
never
|
||||
Path extends`/${infer A }/${infer Rest}` ? (WrapperData extends {[K in A & string]: infer NextWrapperData} ? _EnsureWrapperDataPath<NextWrapperData, `/${Rest}`, Origin> : never) :
|
||||
Path extends `/${infer A }` ? (WrapperData extends {[K in A]: any} ? Origin : never) :
|
||||
Path extends '' ? Origin :
|
||||
never
|
||||
// prettier-ignore
|
||||
export type EnsureWrapperDataPath<WrapperData, Path extends string> = _EnsureWrapperDataPath<WrapperData, Path, Path>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user