mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 20:24:47 +00:00
feat: creating the rest of the sdk
This commit is contained in:
@@ -4,13 +4,7 @@ import { List } from "../config/builder/list"
|
||||
import { Value } from "../config/builder/value"
|
||||
import { Variants } from "../config/builder/variants"
|
||||
import { ValueSpec } from "../config/configTypes"
|
||||
import { Parser } from "ts-matches"
|
||||
import {
|
||||
createWrapperDataContract,
|
||||
neverWrapperDataContract,
|
||||
} from "../wrapperData/wrapperDataContract"
|
||||
|
||||
type test = unknown | { test: 5 }
|
||||
describe("builder tests", () => {
|
||||
test("text", async () => {
|
||||
const bitcoinPropertiesBuilt: {
|
||||
@@ -303,7 +297,7 @@ describe("values", () => {
|
||||
utils: "utils",
|
||||
} as any
|
||||
test("toggle", async () => {
|
||||
const value = Value.dynamicToggle(neverWrapperDataContract, async () => ({
|
||||
const value = Value.dynamicToggle(async () => ({
|
||||
name: "Testing",
|
||||
description: null,
|
||||
warning: null,
|
||||
@@ -321,7 +315,7 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("text", async () => {
|
||||
const value = Value.dynamicText(neverWrapperDataContract, async () => ({
|
||||
const value = Value.dynamicText(async () => ({
|
||||
name: "Testing",
|
||||
required: { default: null },
|
||||
}))
|
||||
@@ -337,7 +331,7 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("text with default", async () => {
|
||||
const value = Value.dynamicText(neverWrapperDataContract, async () => ({
|
||||
const value = Value.dynamicText(async () => ({
|
||||
name: "Testing",
|
||||
required: { default: "this is a default value" },
|
||||
}))
|
||||
@@ -352,7 +346,7 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("optional text", async () => {
|
||||
const value = Value.dynamicText(neverWrapperDataContract, async () => ({
|
||||
const value = Value.dynamicText(async () => ({
|
||||
name: "Testing",
|
||||
required: false,
|
||||
}))
|
||||
@@ -368,7 +362,7 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("color", async () => {
|
||||
const value = Value.dynamicColor(neverWrapperDataContract, async () => ({
|
||||
const value = Value.dynamicColor(async () => ({
|
||||
name: "Testing",
|
||||
required: false,
|
||||
description: null,
|
||||
@@ -387,20 +381,17 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("datetime", async () => {
|
||||
const value = Value.dynamicDatetime(
|
||||
createWrapperDataContract<{ test: "a" }>(),
|
||||
async ({ utils }) => {
|
||||
;async () => {
|
||||
;(await utils.getOwnWrapperData("/test").once()) satisfies "a"
|
||||
}
|
||||
const value = Value.dynamicDatetime<{ test: "a" }>(async ({ utils }) => {
|
||||
;async () => {
|
||||
;(await utils.store.getOwn("/test").once()) satisfies "a"
|
||||
}
|
||||
|
||||
return {
|
||||
name: "Testing",
|
||||
required: { default: null },
|
||||
inputmode: "date",
|
||||
}
|
||||
},
|
||||
)
|
||||
return {
|
||||
name: "Testing",
|
||||
required: { default: null },
|
||||
inputmode: "date",
|
||||
}
|
||||
})
|
||||
const validator = value.validator
|
||||
validator.unsafeCast("2021-01-01")
|
||||
validator.unsafeCast(null)
|
||||
@@ -415,18 +406,15 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("textarea", async () => {
|
||||
const value = Value.dynamicTextarea(
|
||||
neverWrapperDataContract,
|
||||
async () => ({
|
||||
name: "Testing",
|
||||
required: false,
|
||||
description: null,
|
||||
warning: null,
|
||||
minLength: null,
|
||||
maxLength: null,
|
||||
placeholder: null,
|
||||
}),
|
||||
)
|
||||
const value = Value.dynamicTextarea(async () => ({
|
||||
name: "Testing",
|
||||
required: false,
|
||||
description: null,
|
||||
warning: null,
|
||||
minLength: null,
|
||||
maxLength: null,
|
||||
placeholder: null,
|
||||
}))
|
||||
const validator = value.validator
|
||||
validator.unsafeCast("test text")
|
||||
expect(() => validator.unsafeCast(null)).toThrowError()
|
||||
@@ -437,7 +425,7 @@ describe("values", () => {
|
||||
})
|
||||
})
|
||||
test("number", async () => {
|
||||
const value = Value.dynamicNumber(neverWrapperDataContract, () => ({
|
||||
const value = Value.dynamicNumber(() => ({
|
||||
name: "Testing",
|
||||
required: { default: null },
|
||||
integer: false,
|
||||
@@ -511,7 +499,6 @@ describe("values", () => {
|
||||
describe("filtering", () => {
|
||||
test("union", async () => {
|
||||
const value = Value.filteredUnion(
|
||||
neverWrapperDataContract,
|
||||
() => ["a", "c"],
|
||||
{
|
||||
name: "Testing",
|
||||
@@ -620,7 +607,7 @@ describe("Builder List", () => {
|
||||
describe("dynamic", () => {
|
||||
test("text", async () => {
|
||||
const value = Value.list(
|
||||
List.dynamicText(neverWrapperDataContract, () => ({
|
||||
List.dynamicText(() => ({
|
||||
name: "test",
|
||||
spec: { patterns: [] },
|
||||
})),
|
||||
@@ -638,7 +625,7 @@ describe("Builder List", () => {
|
||||
})
|
||||
test("number", async () => {
|
||||
const value = Value.list(
|
||||
List.dynamicNumber(neverWrapperDataContract, () => ({
|
||||
List.dynamicNumber(() => ({
|
||||
name: "test",
|
||||
spec: { integer: true },
|
||||
})),
|
||||
|
||||
@@ -423,7 +423,6 @@ oldSpecToBuilder(
|
||||
},
|
||||
{
|
||||
// convert this to `start-sdk/lib` for conversions
|
||||
startSdk: "../..",
|
||||
wrapperData: "./output.wrapperData",
|
||||
startSdk: "./output.sdk",
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
export type WrapperData = {}
|
||||
import { StartSDK } from "../StartSDK"
|
||||
|
||||
export type WrapperData = any
|
||||
export const sdk = StartSDK.of()
|
||||
.withManifest<WrapperData>()
|
||||
.withStore<{ storeRoot: { storeLeaf: "value" } }>()
|
||||
.build()
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { Effects } from "../types"
|
||||
import { createMainUtils, utils } from "../util"
|
||||
import { createWrapperDataContract } from "../wrapperData/wrapperDataContract"
|
||||
import { createMainUtils } from "../util"
|
||||
import { utils } from "../util/utils"
|
||||
|
||||
type WrapperType = {
|
||||
config: {
|
||||
someValue: "a" | "b"
|
||||
}
|
||||
}
|
||||
const wrapperDataContract = createWrapperDataContract<WrapperType>()
|
||||
const todo = <A>(): A => {
|
||||
throw new Error("not implemented")
|
||||
}
|
||||
@@ -15,97 +14,94 @@ const noop = () => {}
|
||||
describe("wrapperData", () => {
|
||||
test("types", async () => {
|
||||
;async () => {
|
||||
utils(wrapperDataContract, todo<Effects>()).setOwnWrapperData("/config", {
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn("/config", {
|
||||
someValue: "a",
|
||||
})
|
||||
utils(wrapperDataContract, todo<Effects>()).setOwnWrapperData(
|
||||
"/config/someValue",
|
||||
"b",
|
||||
)
|
||||
utils(wrapperDataContract, todo<Effects>()).setOwnWrapperData("", {
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn("/config/someValue", "b")
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn("", {
|
||||
config: { someValue: "b" },
|
||||
})
|
||||
utils(wrapperDataContract, todo<Effects>()).setOwnWrapperData(
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn(
|
||||
"/config/someValue",
|
||||
|
||||
// @ts-expect-error Type is wrong for the setting value
|
||||
5,
|
||||
)
|
||||
utils(wrapperDataContract, todo<Effects>()).setOwnWrapperData(
|
||||
utils(todo<Effects>()).store.setOwn(
|
||||
// @ts-expect-error Path is wrong
|
||||
"/config/someVae3lue",
|
||||
"someValue",
|
||||
)
|
||||
|
||||
todo<Effects>().setWrapperData<WrapperType, "/config/someValue">({
|
||||
todo<Effects>().store.set<WrapperType, "/config/someValue">({
|
||||
path: "/config/someValue",
|
||||
value: "b",
|
||||
})
|
||||
todo<Effects>().setWrapperData<WrapperType, "/config/some2Value">({
|
||||
todo<Effects>().store.set<WrapperType, "/config/some2Value">({
|
||||
//@ts-expect-error Path is wrong
|
||||
path: "/config/someValue",
|
||||
//@ts-expect-error Path is wrong
|
||||
value: "someValueIn",
|
||||
})
|
||||
todo<Effects>().setWrapperData<WrapperType, "/config/someValue">({
|
||||
todo<Effects>().store.set<WrapperType, "/config/someValue">({
|
||||
//@ts-expect-error Path is wrong
|
||||
path: "/config/some2Value",
|
||||
value: "a",
|
||||
})
|
||||
;(await createMainUtils(wrapperDataContract, todo<Effects>())
|
||||
.getOwnWrapperData("/config/someValue")
|
||||
;(await createMainUtils<WrapperType>(todo<Effects>())
|
||||
.store.getOwn("/config/someValue")
|
||||
.const()) satisfies string
|
||||
;(await createMainUtils(wrapperDataContract, todo<Effects>())
|
||||
.getOwnWrapperData("/config")
|
||||
;(await createMainUtils<WrapperType>(todo<Effects>())
|
||||
.store.getOwn("/config")
|
||||
.const()) satisfies WrapperType["config"]
|
||||
await createMainUtils(wrapperDataContract, todo<Effects>())
|
||||
await createMainUtils(todo<Effects>())
|
||||
// @ts-expect-error Path is wrong
|
||||
.getOwnWrapperData("/config/somdsfeValue")
|
||||
.store.getOwn("/config/somdsfeValue")
|
||||
.const()
|
||||
/// ----------------- ERRORS -----------------
|
||||
|
||||
utils(wrapperDataContract, todo<Effects>()).setOwnWrapperData("", {
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn("", {
|
||||
// @ts-expect-error Type is wrong for the setting value
|
||||
config: { someValue: "notInAOrB" },
|
||||
})
|
||||
utils(wrapperDataContract, todo<Effects>()).setOwnWrapperData(
|
||||
utils<WrapperType>(todo<Effects>()).store.setOwn(
|
||||
"/config/someValue",
|
||||
// @ts-expect-error Type is wrong for the setting value
|
||||
"notInAOrB",
|
||||
)
|
||||
;(await utils(wrapperDataContract, todo<Effects>())
|
||||
.getOwnWrapperData("/config/someValue")
|
||||
;(await utils<WrapperType>(todo<Effects>())
|
||||
.store.getOwn("/config/someValue")
|
||||
// @ts-expect-error Const should normally not be callable
|
||||
.const()) satisfies string
|
||||
;(await utils(wrapperDataContract, todo<Effects>())
|
||||
.getOwnWrapperData("/config")
|
||||
;(await utils<WrapperType>(todo<Effects>())
|
||||
.store.getOwn("/config")
|
||||
// @ts-expect-error Const should normally not be callable
|
||||
.const()) satisfies WrapperType["config"]
|
||||
await utils(wrapperDataContract, todo<Effects>())
|
||||
await utils<WrapperType>(todo<Effects>())
|
||||
// @ts-expect-error Path is wrong
|
||||
.getOwnWrapperData("/config/somdsfeValue")
|
||||
.store.getOwn("/config/somdsfeValue")
|
||||
// @ts-expect-error Const should normally not be callable
|
||||
.const()
|
||||
|
||||
///
|
||||
;(await utils(wrapperDataContract, todo<Effects>())
|
||||
.getOwnWrapperData("/config/someValue")
|
||||
;(await utils<WrapperType>(todo<Effects>())
|
||||
.store.getOwn("/config/someValue")
|
||||
// @ts-expect-error satisfies type is wrong
|
||||
.const()) satisfies number
|
||||
;(await createMainUtils(wrapperDataContract, todo<Effects>())
|
||||
;(await createMainUtils(todo<Effects>())
|
||||
// @ts-expect-error Path is wrong
|
||||
.getOwnWrapperData("/config/")
|
||||
.store.getOwn("/config/")
|
||||
.const()) satisfies WrapperType["config"]
|
||||
;(await todo<Effects>().getWrapperData<WrapperType, "/config/someValue">({
|
||||
;(await todo<Effects>().store.get<WrapperType, "/config/someValue">({
|
||||
path: "/config/someValue",
|
||||
callback: noop,
|
||||
})) satisfies string
|
||||
await todo<Effects>().getWrapperData<WrapperType, "/config/someValue">({
|
||||
await todo<Effects>().store.get<WrapperType, "/config/someValue">({
|
||||
// @ts-expect-error Path is wrong as in it doesn't match above
|
||||
path: "/config/someV2alue",
|
||||
callback: noop,
|
||||
})
|
||||
await todo<Effects>().getWrapperData<WrapperType, "/config/someV2alue">({
|
||||
await todo<Effects>().store.get<WrapperType, "/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