import { Effects } from "../../../base/lib/types" import { extractJsonPath } from "../../../base/lib/util/PathBuilder" import { StartSdk } from "../StartSdk" type Store = { inputSpec: { 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.inputSpec, { someValue: "a", }) sdk.store.setOwn(todo(), storePath.inputSpec.someValue, "b") sdk.store.setOwn(todo(), storePath, { inputSpec: { someValue: "b" }, }) sdk.store.setOwn( todo(), storePath.inputSpec.someValue, // @ts-expect-error Type is wrong for the setting value 5, ) sdk.store.setOwn( todo(), // @ts-expect-error Path is wrong "/inputSpec/someVae3lue", "someValue", ) todo().store.set({ path: extractJsonPath(storePath.inputSpec.someValue), value: "b", }) todo().store.set({ path: extractJsonPath(storePath.inputSpec.someValue), //@ts-expect-error Path is wrong value: "someValueIn", }) ;(await sdk.store .getOwn(todo(), storePath.inputSpec.someValue) .const()) satisfies string ;(await sdk.store .getOwn(todo(), storePath.inputSpec) .const()) satisfies Store["inputSpec"] await sdk.store // @ts-expect-error Path is wrong .getOwn(todo(), "/inputSpec/somdsfeValue") .const() /// ----------------- ERRORS ----------------- sdk.store.setOwn(todo(), storePath, { // @ts-expect-error Type is wrong for the setting value inputSpec: { someValue: "notInAOrB" }, }) sdk.store.setOwn( todo(), sdk.StorePath.inputSpec.someValue, // @ts-expect-error Type is wrong for the setting value "notInAOrB", ) ;(await sdk.store .getOwn(todo(), storePath.inputSpec.someValue) .const()) satisfies string ;(await sdk.store .getOwn(todo(), storePath.inputSpec) .const()) satisfies Store["inputSpec"] await sdk.store // @ts-expect-error Path is wrong .getOwn("/inputSpec/somdsfeValue") .const() /// ;(await sdk.store .getOwn(todo(), storePath.inputSpec.someValue) // @ts-expect-error satisfies type is wrong .const()) satisfies number await sdk.store // @ts-expect-error Path is wrong .getOwn(todo(), extractJsonPath(storePath.inputSpec)) .const() ;(await todo().store.get({ path: extractJsonPath(storePath.inputSpec.someValue), callback: noop, })) satisfies string await todo().store.get({ // @ts-expect-error Path is wrong as in it doesn't match above path: "/inputSpec/someV2alue", callback: noop, }) await todo().store.get({ // @ts-expect-error Path is wrong as in it doesn't exists in wrapper type path: "/inputSpec/someV2alue", callback: noop, }) } }) })