wip: Creating an sdk builder that has all the generics we need in one place

This commit is contained in:
BluJ
2023-05-08 16:43:47 -06:00
parent e17668da00
commit 2b267c6c60
16 changed files with 275 additions and 51 deletions

View File

@@ -24,9 +24,8 @@ import {
unknown,
} from "ts-matches"
import { once } from "../../util/once"
import { WrapperDataContract } from "../../wrapperData/wrapperDataContract"
type RequiredDefault<A> =
export type RequiredDefault<A> =
| false
| {
default: A | null
@@ -96,7 +95,7 @@ const username = Value.string({
```
*/
export class Value<Type, WD> {
private constructor(
protected constructor(
public build: LazyBuild<WD, ValueSpec>,
public validator: Parser<unknown, Type>,
) {}
@@ -122,7 +121,6 @@ export class Value<Type, WD> {
)
}
static dynamicToggle<WD = never>(
_wrapperDataContract: WrapperDataContract<WD>,
a: LazyBuild<
WD,
{
@@ -186,7 +184,6 @@ export class Value<Type, WD> {
)
}
static dynamicText<WD = never>(
_wrapperDataContract: WrapperDataContract<WD>,
getA: LazyBuild<
WD,
{
@@ -258,7 +255,6 @@ export class Value<Type, WD> {
)
}
static dynamicTextarea<WD = never>(
_wrapperDataContract: WrapperDataContract<WD>,
getA: LazyBuild<
WD,
{
@@ -325,7 +321,6 @@ export class Value<Type, WD> {
)
}
static dynamicNumber<WD = never>(
_wrapperDataContract: WrapperDataContract<WD>,
getA: LazyBuild<
WD,
{
@@ -387,7 +382,6 @@ export class Value<Type, WD> {
}
static dynamicColor<WD = never>(
_wrapperDataContract: WrapperDataContract<WD>,
getA: LazyBuild<
WD,
{
@@ -445,7 +439,6 @@ export class Value<Type, WD> {
)
}
static dynamicDatetime<WD = never>(
_wrapperDataContract: WrapperDataContract<WD>,
getA: LazyBuild<
WD,
{
@@ -642,7 +635,6 @@ export class Value<Type, WD> {
Type extends Record<string, any>,
WD = never,
>(
_wrapperDataContract: WrapperDataContract<WD>,
getDisabledFn: LazyBuild<WD, string[]>,
a: {
name: string

View File

@@ -1,12 +1,14 @@
import { SDKManifest } from "../manifest/ManifestTypes"
import { Dependency } from "../types"
export type Dependencies<T extends SDKManifest> = {
export type ConfigDependencies<T extends SDKManifest> = {
exists(id: keyof T["dependencies"]): Dependency
running(id: keyof T["dependencies"]): Dependency
}
export const dependenciesSet = <T extends SDKManifest>(): Dependencies<T> => ({
export const configDependenciesSet = <
T extends SDKManifest,
>(): ConfigDependencies<T> => ({
exists(id: keyof T["dependencies"]) {
return {
id,

View File

@@ -1,5 +1,5 @@
import "./builder"
import "./setupConfig"
import "./dependencies"
import "./constants"
import "./configDependencies"
import "./configConstants"

View File

@@ -1,6 +1,6 @@
import { Effects, ExpectedExports } from "../types"
import { SDKManifest } from "../manifest/ManifestTypes"
import * as D from "./dependencies"
import * as D from "./configDependencies"
import { Config, ExtractConfigType } from "./builder/config"
import { Utils, utils } from "../util"
import nullIfEmpty from "../util/nullIfEmpty"
@@ -22,7 +22,7 @@ export type Save<
effects: Effects
input: ExtractConfigType<A> & Record<string, any>
utils: Utils<WD>
dependencies: D.Dependencies<Manifest>
dependencies: D.ConfigDependencies<Manifest>
}) => Promise<{
dependenciesReceipt: DependenciesReceipt
restart: boolean
@@ -70,7 +70,7 @@ export function setupConfig<
input: JSON.parse(JSON.stringify(input)),
effects,
utils: utils(wrapperDataContract, effects),
dependencies: D.dependenciesSet<Manifest>(),
dependencies: D.configDependenciesSet<Manifest>(),
})
if (restart) {
await effects.restart()