mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
feat: Add vault through utils + sdk
This commit is contained in:
@@ -4,4 +4,5 @@ export type Manifest = any
|
||||
export const sdk = StartSdk.of()
|
||||
.withManifest({} as any)
|
||||
.withStore<{ storeRoot: { storeLeaf: "value" } }>()
|
||||
.withVault<{ vaultRoot: "value" }>()
|
||||
.build(true)
|
||||
|
||||
@@ -2,11 +2,14 @@ import { Effects } from "../types"
|
||||
import { createMainUtils } from "../util"
|
||||
import { utils } from "../util/utils"
|
||||
|
||||
type WrapperType = {
|
||||
type Store = {
|
||||
config: {
|
||||
someValue: "a" | "b"
|
||||
}
|
||||
}
|
||||
type Vault = {
|
||||
hello: string
|
||||
}
|
||||
const todo = <A>(): A => {
|
||||
throw new Error("not implemented")
|
||||
}
|
||||
@@ -14,14 +17,14 @@ const noop = () => {}
|
||||
describe("Store", () => {
|
||||
test("types", async () => {
|
||||
;async () => {
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn("/config", {
|
||||
utils<Store>(todo<Effects>()).store.setOwn("/config", {
|
||||
someValue: "a",
|
||||
})
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn("/config/someValue", "b")
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn("", {
|
||||
utils<Store>(todo<Effects>()).store.setOwn("/config/someValue", "b")
|
||||
utils<Store>(todo<Effects>()).store.setOwn("", {
|
||||
config: { someValue: "b" },
|
||||
})
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn(
|
||||
utils<Store>(todo<Effects>()).store.setOwn(
|
||||
"/config/someValue",
|
||||
|
||||
// @ts-expect-error Type is wrong for the setting value
|
||||
@@ -33,75 +36,75 @@ describe("Store", () => {
|
||||
"someValue",
|
||||
)
|
||||
|
||||
todo<Effects>().store.set<WrapperType, "/config/someValue">({
|
||||
todo<Effects>().store.set<Store, "/config/someValue">({
|
||||
path: "/config/someValue",
|
||||
value: "b",
|
||||
})
|
||||
todo<Effects>().store.set<WrapperType, "/config/some2Value">({
|
||||
todo<Effects>().store.set<Store, "/config/some2Value">({
|
||||
//@ts-expect-error Path is wrong
|
||||
path: "/config/someValue",
|
||||
//@ts-expect-error Path is wrong
|
||||
value: "someValueIn",
|
||||
})
|
||||
todo<Effects>().store.set<WrapperType, "/config/someValue">({
|
||||
todo<Effects>().store.set<Store, "/config/someValue">({
|
||||
//@ts-expect-error Path is wrong
|
||||
path: "/config/some2Value",
|
||||
value: "a",
|
||||
})
|
||||
;(await createMainUtils<WrapperType>(todo<Effects>())
|
||||
;(await createMainUtils<Store, Vault>(todo<Effects>())
|
||||
.store.getOwn("/config/someValue")
|
||||
.const()) satisfies string
|
||||
;(await createMainUtils<WrapperType>(todo<Effects>())
|
||||
;(await createMainUtils<Store, Vault>(todo<Effects>())
|
||||
.store.getOwn("/config")
|
||||
.const()) satisfies WrapperType["config"]
|
||||
.const()) satisfies Store["config"]
|
||||
await createMainUtils(todo<Effects>())
|
||||
// @ts-expect-error Path is wrong
|
||||
.store.getOwn("/config/somdsfeValue")
|
||||
.const()
|
||||
/// ----------------- ERRORS -----------------
|
||||
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn("", {
|
||||
utils<Store>(todo<Effects>()).store.setOwn("", {
|
||||
// @ts-expect-error Type is wrong for the setting value
|
||||
config: { someValue: "notInAOrB" },
|
||||
})
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn(
|
||||
utils<Store>(todo<Effects>()).store.setOwn(
|
||||
"/config/someValue",
|
||||
// @ts-expect-error Type is wrong for the setting value
|
||||
"notInAOrB",
|
||||
)
|
||||
;(await utils<WrapperType>(todo<Effects>())
|
||||
;(await utils<Store>(todo<Effects>())
|
||||
.store.getOwn("/config/someValue")
|
||||
// @ts-expect-error Const should normally not be callable
|
||||
.const()) satisfies string
|
||||
;(await utils<WrapperType>(todo<Effects>())
|
||||
;(await utils<Store>(todo<Effects>())
|
||||
.store.getOwn("/config")
|
||||
// @ts-expect-error Const should normally not be callable
|
||||
.const()) satisfies WrapperType["config"]
|
||||
await utils<WrapperType>(todo<Effects>())
|
||||
.const()) satisfies Store["config"]
|
||||
await utils<Store>(todo<Effects>())
|
||||
// @ts-expect-error Path is wrong
|
||||
.store.getOwn("/config/somdsfeValue")
|
||||
// @ts-expect-error Const should normally not be callable
|
||||
.const()
|
||||
|
||||
///
|
||||
;(await utils<WrapperType>(todo<Effects>())
|
||||
;(await utils<Store>(todo<Effects>())
|
||||
.store.getOwn("/config/someValue")
|
||||
// @ts-expect-error satisfies type is wrong
|
||||
.const()) satisfies number
|
||||
;(await createMainUtils(todo<Effects>())
|
||||
// @ts-expect-error Path is wrong
|
||||
.store.getOwn("/config/")
|
||||
.const()) satisfies WrapperType["config"]
|
||||
;(await todo<Effects>().store.get<WrapperType, "/config/someValue">({
|
||||
.const()) satisfies Store["config"]
|
||||
;(await todo<Effects>().store.get<Store, "/config/someValue">({
|
||||
path: "/config/someValue",
|
||||
callback: noop,
|
||||
})) satisfies string
|
||||
await todo<Effects>().store.get<WrapperType, "/config/someValue">({
|
||||
await todo<Effects>().store.get<Store, "/config/someValue">({
|
||||
// @ts-expect-error Path is wrong as in it doesn't match above
|
||||
path: "/config/someV2alue",
|
||||
callback: noop,
|
||||
})
|
||||
await todo<Effects>().store.get<WrapperType, "/config/someV2alue">({
|
||||
await todo<Effects>().store.get<Store, "/config/someV2alue">({
|
||||
// @ts-expect-error Path is wrong as in it doesn't exists in wrapper type
|
||||
path: "/config/someV2alue",
|
||||
callback: noop,
|
||||
|
||||
Reference in New Issue
Block a user