chore: Remove the utils

This commit is contained in:
J H
2024-03-18 14:31:01 -06:00
parent 8e2dc8b3ee
commit 5f40fd6038
28 changed files with 424 additions and 543 deletions

View File

@@ -4,6 +4,8 @@ import { List } from "../config/builder/list"
import { Value } from "../config/builder/value"
import { Variants } from "../config/builder/variants"
import { ValueSpec } from "../config/configTypes"
import { setupManifest } from "../manifest/setupManifest"
import { StartSdk } from "../StartSdk"
describe("builder tests", () => {
test("text", async () => {
@@ -379,17 +381,61 @@ describe("values", () => {
})
})
test("datetime", async () => {
const value = Value.dynamicDatetime<{ test: "a" }>(async ({ utils }) => {
;async () => {
;(await utils.store.getOwn("/test").once()) satisfies "a"
}
const sdk = StartSdk.of()
.withManifest(
setupManifest({
id: "testOutput",
title: "",
version: "1.0",
releaseNotes: "",
license: "",
replaces: [],
wrapperRepo: "",
upstreamRepo: "",
supportSite: "",
marketingSite: "",
donationUrl: null,
description: {
short: "",
long: "",
},
containers: {},
images: [],
volumes: [],
assets: [],
alerts: {
install: null,
update: null,
uninstall: null,
restore: null,
start: null,
stop: null,
},
dependencies: {
remoteTest: {
description: "",
requirement: { how: "", type: "opt-in" },
version: "1.0",
},
},
}),
)
.withStore<{ test: "a" }>()
.build(true)
return {
name: "Testing",
required: { default: null },
inputmode: "date",
}
})
const value = Value.dynamicDatetime<{ test: "a" }>(
async ({ effects }) => {
;async () => {
;(await sdk.store.getOwn(effects, "/test").once()) satisfies "a"
}
return {
name: "Testing",
required: { default: null },
inputmode: "date",
}
},
)
const validator = value.validator
validator.unsafeCast("2021-01-01")
validator.unsafeCast(null)

View File

@@ -1,12 +1,11 @@
import { ServiceInterfaceBuilder } from "../interfaces/ServiceInterfaceBuilder"
import { Effects } from "../types"
import { createUtils } from "../util"
import { sdk } from "./output.sdk"
describe("host", () => {
test("Testing that the types work", () => {
async function test(effects: Effects) {
const utils = createUtils<never, never>(effects)
const foo = utils.host.multi("foo")
const foo = sdk.host.multi(effects, "foo")
const fooOrigin = await foo.bindPort(80, {
protocol: "http" as const,
})

View File

@@ -1,6 +1,5 @@
import { MainEffects, StartSdk } from "../StartSdk"
import { Effects } from "../types"
import { createMainUtils } from "../util"
import { createUtils } from "../util/utils"
type Store = {
config: {
@@ -12,26 +11,31 @@ const todo = <A>(): A => {
throw new Error("not implemented")
}
const noop = () => {}
const sdk = StartSdk.of()
.withManifest({} as Manifest)
.withStore<Store>()
.build(true)
describe("Store", () => {
test("types", async () => {
;async () => {
createUtils<Manifest, Store>(todo<Effects>()).store.setOwn("/config", {
sdk.store.setOwn(todo<Effects>(), "/config", {
someValue: "a",
})
createUtils<Manifest, Store>(todo<Effects>()).store.setOwn(
"/config/someValue",
"b",
)
createUtils<Manifest, Store>(todo<Effects>()).store.setOwn("", {
sdk.store.setOwn(todo<Effects>(), "/config/someValue", "b")
sdk.store.setOwn(todo<Effects>(), "", {
config: { someValue: "b" },
})
createUtils<Manifest, Store>(todo<Effects>()).store.setOwn(
sdk.store.setOwn(
todo<Effects>(),
"/config/someValue",
// @ts-expect-error Type is wrong for the setting value
5,
)
createUtils(todo<Effects>()).store.setOwn(
sdk.store.setOwn(
todo<Effects>(),
// @ts-expect-error Path is wrong
"/config/someVae3lue",
"someValue",
@@ -52,49 +56,47 @@ describe("Store", () => {
path: "/config/some2Value",
value: "a",
})
;(await createMainUtils<Manifest, Store>(todo<Effects>())
.store.getOwn("/config/someValue")
;(await sdk.store
.getOwn(todo<MainEffects>(), "/config/someValue")
.const()) satisfies string
;(await createMainUtils<Manifest, Store>(todo<Effects>())
.store.getOwn("/config")
;(await sdk.store
.getOwn(todo<MainEffects>(), "/config")
.const()) satisfies Store["config"]
await createMainUtils(todo<Effects>())
// @ts-expect-error Path is wrong
.store.getOwn("/config/somdsfeValue")
await sdk.store // @ts-expect-error Path is wrong
.getOwn(todo<MainEffects>(), "/config/somdsfeValue")
.const()
/// ----------------- ERRORS -----------------
createUtils<Manifest, Store>(todo<Effects>()).store.setOwn("", {
sdk.store.setOwn(todo<MainEffects>(), "", {
// @ts-expect-error Type is wrong for the setting value
config: { someValue: "notInAOrB" },
})
createUtils<Manifest, Store>(todo<Effects>()).store.setOwn(
sdk.store.setOwn(
todo<MainEffects>(),
"/config/someValue",
// @ts-expect-error Type is wrong for the setting value
"notInAOrB",
)
;(await createUtils<Manifest, Store>(todo<Effects>())
.store.getOwn("/config/someValue")
;(await sdk.store
.getOwn(todo<Effects>(), "/config/someValue")
// @ts-expect-error Const should normally not be callable
.const()) satisfies string
;(await createUtils<Manifest, Store>(todo<Effects>())
.store.getOwn("/config")
;(await sdk.store
.getOwn(todo<Effects>(), "/config")
// @ts-expect-error Const should normally not be callable
.const()) satisfies Store["config"]
await createUtils<Manifest, Store>(todo<Effects>())
// @ts-expect-error Path is wrong
.store.getOwn("/config/somdsfeValue")
await sdk.store // @ts-expect-error Path is wrong
.getOwn("/config/somdsfeValue")
// @ts-expect-error Const should normally not be callable
.const()
///
;(await createUtils<Manifest, Store>(todo<Effects>())
.store.getOwn("/config/someValue")
;(await sdk.store
.getOwn(todo<MainEffects>(), "/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/")
;(await sdk.store // @ts-expect-error Path is wrong
.getOwn(todo<MainEffects>(), "/config/")
.const()) satisfies Store["config"]
;(await todo<Effects>().store.get<Store, "/config/someValue">({
path: "/config/someValue",