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