import { MainEffects, StartSdk } from "../StartSdk" import { extractJsonPath } from "../store/PathBuilder" import { Effects } from "../types" type Store = { config: { someValue: "a" | "b" } } type Manifest = any const todo = (): A => { throw new Error("not implemented") } const noop = () => {} const sdk = StartSdk.of() .withManifest({} as Manifest) .withStore() .build(true) const storePath = sdk.StorePath describe("Store", () => { test("types", async () => { ;async () => { sdk.store.setOwn(todo(), storePath.config, { someValue: "a", }) sdk.store.setOwn(todo(), storePath.config.someValue, "b") sdk.store.setOwn(todo(), storePath, { config: { someValue: "b" }, }) sdk.store.setOwn( todo(), storePath.config.someValue, // @ts-expect-error Type is wrong for the setting value 5, ) sdk.store.setOwn( todo(), // @ts-expect-error Path is wrong "/config/someVae3lue", "someValue", ) todo().store.set({ path: extractJsonPath(storePath.config.someValue), value: "b", }) todo().store.set({ path: extractJsonPath(storePath.config.someValue), //@ts-expect-error Path is wrong value: "someValueIn", }) ;(await sdk.store .getOwn(todo(), storePath.config.someValue) .const()) satisfies string ;(await sdk.store .getOwn(todo(), storePath.config) .const()) satisfies Store["config"] await sdk.store // @ts-expect-error Path is wrong .getOwn(todo(), "/config/somdsfeValue") .const() /// ----------------- ERRORS ----------------- sdk.store.setOwn(todo(), storePath, { // @ts-expect-error Type is wrong for the setting value config: { someValue: "notInAOrB" }, }) sdk.store.setOwn( todo(), sdk.StorePath.config.someValue, // @ts-expect-error Type is wrong for the setting value "notInAOrB", ) ;(await sdk.store .getOwn(todo(), storePath.config.someValue) // @ts-expect-error Const should normally not be callable .const()) satisfies string ;(await sdk.store .getOwn(todo(), storePath.config) // @ts-expect-error Const should normally not be callable .const()) satisfies Store["config"] await sdk.store // @ts-expect-error Path is wrong .getOwn("/config/somdsfeValue") // @ts-expect-error Const should normally not be callable .const() /// ;(await sdk.store .getOwn(todo(), storePath.config.someValue) // @ts-expect-error satisfies type is wrong .const()) satisfies number await sdk.store // @ts-expect-error Path is wrong .getOwn(todo(), extractJsonPath(storePath.config)) .const() ;(await todo().store.get({ path: extractJsonPath(storePath.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, }) } }) })