import { Effects } from "../types" import { createMainUtils } from "../util" import { utils } from "../util/utils" type Store = { config: { someValue: "a" | "b" } } type Vault = { hello: string } const todo = (): A => { throw new Error("not implemented") } const noop = () => {} describe("Store", () => { test("types", async () => { ;async () => { utils(todo()).store.setOwn("/config", { someValue: "a", }) utils(todo()).store.setOwn("/config/someValue", "b") utils(todo()).store.setOwn("", { config: { someValue: "b" }, }) utils(todo()).store.setOwn( "/config/someValue", // @ts-expect-error Type is wrong for the setting value 5, ) utils(todo()).store.setOwn( // @ts-expect-error Path is wrong "/config/someVae3lue", "someValue", ) todo().store.set({ path: "/config/someValue", value: "b", }) todo().store.set({ //@ts-expect-error Path is wrong path: "/config/someValue", //@ts-expect-error Path is wrong value: "someValueIn", }) todo().store.set({ //@ts-expect-error Path is wrong path: "/config/some2Value", value: "a", }) ;(await createMainUtils(todo()) .store.getOwn("/config/someValue") .const()) satisfies string ;(await createMainUtils(todo()) .store.getOwn("/config") .const()) satisfies Store["config"] await createMainUtils(todo()) // @ts-expect-error Path is wrong .store.getOwn("/config/somdsfeValue") .const() /// ----------------- ERRORS ----------------- utils(todo()).store.setOwn("", { // @ts-expect-error Type is wrong for the setting value config: { someValue: "notInAOrB" }, }) utils(todo()).store.setOwn( "/config/someValue", // @ts-expect-error Type is wrong for the setting value "notInAOrB", ) ;(await utils(todo()) .store.getOwn("/config/someValue") // @ts-expect-error Const should normally not be callable .const()) satisfies string ;(await utils(todo()) .store.getOwn("/config") // @ts-expect-error Const should normally not be callable .const()) satisfies Store["config"] await utils(todo()) // @ts-expect-error Path is wrong .store.getOwn("/config/somdsfeValue") // @ts-expect-error Const should normally not be callable .const() /// ;(await utils(todo()) .store.getOwn("/config/someValue") // @ts-expect-error satisfies type is wrong .const()) satisfies number ;(await createMainUtils(todo()) // @ts-expect-error Path is wrong .store.getOwn("/config/") .const()) satisfies Store["config"] ;(await todo().store.get({ path: "/config/someValue", callback: noop, })) satisfies string await todo().store.get({ // @ts-expect-error Path is wrong as in it doesn't match above path: "/config/someV2alue", callback: noop, }) await todo().store.get({ // @ts-expect-error Path is wrong as in it doesn't exists in wrapper type path: "/config/someV2alue", callback: noop, }) } }) })