chore: Remove the stupid config

This commit is contained in:
BluJ
2023-05-02 14:10:21 -06:00
parent 07251c91a6
commit 747fa39c6c
14 changed files with 111 additions and 129 deletions

View File

@@ -5,12 +5,12 @@ import { Utils, utils } from "../util"
export class CreatedAction< export class CreatedAction<
WrapperData, WrapperData,
ConfigType extends Record<string, any> | Config<any, any, any>, ConfigType extends Record<string, any> | Config<any, any>,
Type extends Record<string, any> = ExtractConfigType<ConfigType>, Type extends Record<string, any> = ExtractConfigType<ConfigType>,
> { > {
private constructor( private constructor(
public readonly myMetaData: Omit<ActionMetaData, "input"> & { public readonly myMetaData: Omit<ActionMetaData, "input"> & {
input: Config<Type, WrapperData, Type> input: Config<Type, WrapperData>
}, },
readonly fn: (options: { readonly fn: (options: {
effects: Effects effects: Effects
@@ -22,11 +22,11 @@ export class CreatedAction<
static of< static of<
WrapperData, WrapperData,
ConfigType extends Record<string, any> | Config<any, any, any>, ConfigType extends Record<string, any> | Config<any, any>,
Type extends Record<string, any> = ExtractConfigType<ConfigType>, Type extends Record<string, any> = ExtractConfigType<ConfigType>,
>( >(
metaData: Omit<ActionMetaData, "input"> & { metaData: Omit<ActionMetaData, "input"> & {
input: Config<Type, WrapperData, Type> input: Config<Type, WrapperData>
}, },
fn: (options: { fn: (options: {
effects: Effects effects: Effects
@@ -52,7 +52,6 @@ export class CreatedAction<
input: await this.myMetaData.input.build({ input: await this.myMetaData.input.build({
effects, effects,
utils: myUtils, utils: myUtils,
config: null,
}), }),
} }
await effects.exportAction(metaData) await effects.exportAction(metaData)

View File

@@ -1,10 +1,10 @@
import { GenericManifest } from "../manifest/ManifestTypes" import { SDKManifest } from "../manifest/ManifestTypes"
import { AutoConfig, AutoConfigFrom } from "./AutoConfig" import { AutoConfig, AutoConfigFrom } from "./AutoConfig"
export function setupAutoConfig< export function setupAutoConfig<
WD, WD,
Input, Input,
Manifest extends GenericManifest, Manifest extends SDKManifest,
NestedConfigs extends { NestedConfigs extends {
[key in keyof Manifest["dependencies"]]: unknown [key in keyof Manifest["dependencies"]]: unknown
}, },

View File

@@ -1,4 +1,4 @@
import { GenericManifest } from "../manifest/ManifestTypes" import { SDKManifest } from "../manifest/ManifestTypes"
import * as T from "../types" import * as T from "../types"
export type BACKUP = "BACKUP" export type BACKUP = "BACKUP"
@@ -37,14 +37,14 @@ type BackupSet<Volumes extends string> = {
* ).build()q * ).build()q
* ``` * ```
*/ */
export class Backups<M extends GenericManifest> { export class Backups<M extends SDKManifest> {
static BACKUP: BACKUP = "BACKUP" static BACKUP: BACKUP = "BACKUP"
constructor( constructor(
private options = DEFAULT_OPTIONS, private options = DEFAULT_OPTIONS,
private backupSet = [] as BackupSet<keyof M["volumes"] & string>[], private backupSet = [] as BackupSet<keyof M["volumes"] & string>[],
) {} ) {}
static volumes<M extends GenericManifest = never>( static volumes<M extends SDKManifest = never>(
...volumeNames: Array<keyof M["volumes"] & string> ...volumeNames: Array<keyof M["volumes"] & string>
) { ) {
return new Backups().addSets( return new Backups().addSets(
@@ -56,12 +56,12 @@ export class Backups<M extends GenericManifest> {
})), })),
) )
} }
static addSets<M extends GenericManifest = never>( static addSets<M extends SDKManifest = never>(
...options: BackupSet<keyof M["volumes"] & string>[] ...options: BackupSet<keyof M["volumes"] & string>[]
) { ) {
return new Backups().addSets(...options) return new Backups().addSets(...options)
} }
static with_options<M extends GenericManifest = never>( static with_options<M extends SDKManifest = never>(
options?: Partial<T.BackupOptions>, options?: Partial<T.BackupOptions>,
) { ) {
return new Backups({ ...DEFAULT_OPTIONS, ...options }) return new Backups({ ...DEFAULT_OPTIONS, ...options })

View File

@@ -1,14 +1,14 @@
import { string } from "ts-matches" import { string } from "ts-matches"
import { Backups } from "." import { Backups } from "."
import { GenericManifest } from "../manifest/ManifestTypes" import { SDKManifest } from "../manifest/ManifestTypes"
import { BackupOptions, ExpectedExports } from "../types" import { BackupOptions, ExpectedExports } from "../types"
import { _ } from "../util" import { _ } from "../util"
export type SetupBackupsParams<M extends GenericManifest> = Array< export type SetupBackupsParams<M extends SDKManifest> = Array<
(keyof M["volumes"] & string) | Backups<M> (keyof M["volumes"] & string) | Backups<M>
> >
export function setupBackups<M extends GenericManifest>( export function setupBackups<M extends SDKManifest>(
...args: _<SetupBackupsParams<M>> ...args: _<SetupBackupsParams<M>>
) { ) {
const backups = Array<Backups<M>>() const backups = Array<Backups<M>>()

View File

@@ -5,21 +5,20 @@ import { _ } from "../../util"
import { Effects } from "../../types" import { Effects } from "../../types"
import { Parser, object } from "ts-matches" import { Parser, object } from "ts-matches"
export type LazyBuildOptions<WD, ConfigType> = { export type LazyBuildOptions<WD> = {
effects: Effects effects: Effects
utils: Utils<WD> utils: Utils<WD>
config: ConfigType | null
} }
export type LazyBuild<WD, ConfigType, ExpectedOut> = ( export type LazyBuild<WD, ExpectedOut> = (
options: LazyBuildOptions<WD, ConfigType>, options: LazyBuildOptions<WD>,
) => Promise<ExpectedOut> | ExpectedOut ) => Promise<ExpectedOut> | ExpectedOut
// prettier-ignore // prettier-ignore
export type ExtractConfigType<A extends Record<string, any> | Config<Record<string, any>, any, any>> = export type ExtractConfigType<A extends Record<string, any> | Config<Record<string, any>, any>> =
A extends Config<infer B, any, any> ? B : A extends Config<infer B, any> ? B :
A A
export type MaybeLazyValues<A> = LazyBuild<any, any, A> | A export type MaybeLazyValues<A> = LazyBuild<any, A> | A
/** /**
* Configs are the specs that are used by the os configuration form for this service. * Configs are the specs that are used by the os configuration form for this service.
* Here is an example of a simple configuration * Here is an example of a simple configuration
@@ -76,14 +75,14 @@ export const addNodesSpec = Config.of({ hostname: hostname, port: port });
``` ```
*/ */
export class Config<Type extends Record<string, any>, WD, ConfigType> { export class Config<Type extends Record<string, any>, WD> {
private constructor( private constructor(
private readonly spec: { private readonly spec: {
[K in keyof Type]: Value<Type[K], WD, ConfigType> [K in keyof Type]: Value<Type[K], WD>
}, },
public validator: Parser<unknown, Type>, public validator: Parser<unknown, Type>,
) {} ) {}
async build(options: LazyBuildOptions<WD, ConfigType>) { async build(options: LazyBuildOptions<WD>) {
const answer = {} as { const answer = {} as {
[K in keyof Type]: ValueSpec [K in keyof Type]: ValueSpec
} }
@@ -93,8 +92,8 @@ export class Config<Type extends Record<string, any>, WD, ConfigType> {
return answer return answer
} }
static of<Type extends Record<string, any>, WrapperData, ConfigType>(spec: { static of<Type extends Record<string, any>, WrapperData>(spec: {
[K in keyof Type]: Value<Type[K], WrapperData, ConfigType> [K in keyof Type]: Value<Type[K], WrapperData>
}) { }) {
const validatorObj = {} as { const validatorObj = {} as {
[K in keyof Type]: Parser<unknown, Type[K]> [K in keyof Type]: Parser<unknown, Type[K]>
@@ -103,21 +102,22 @@ export class Config<Type extends Record<string, any>, WD, ConfigType> {
validatorObj[key] = spec[key].validator validatorObj[key] = spec[key].validator
} }
const validator = object(validatorObj) const validator = object(validatorObj)
return new Config<Type, WrapperData, ConfigType>(spec, validator) return new Config<Type, WrapperData>(spec, validator)
} }
static withWrapperData<WrapperData>() { static withWrapperData<WrapperData>() {
return { return {
of<Type extends Record<string, any>>(spec: { of<Type extends Record<string, any>>(spec: {
[K in keyof Type]: Value<Type[K], WrapperData, Type> [K in keyof Type]: Value<Type[K], WrapperData>
}) { }) {
return Config.of<Type, WrapperData, Type>(spec) return Config.of<Type, WrapperData>(spec)
}, },
} }
} }
} }
export function topConfig<WrapperData>() { export function topConfig<WrapperData>() {
return <Type extends Record<string, any>>(spec: { return <Type extends Record<string, any>>(spec: {
[K in keyof Type]: Value<Type[K], WrapperData, Type> [K in keyof Type]: Value<Type[K], WrapperData>
}) => Config.of<Type, WrapperData, Type>(spec) }) => Config.of<Type, WrapperData>(spec)
} }

View File

@@ -19,12 +19,12 @@ export const authorizationList = List.string({
export const auth = Value.list(authorizationList); export const auth = Value.list(authorizationList);
``` ```
*/ */
export class List<Type, WD, ConfigType> { export class List<Type, WD> {
private constructor( private constructor(
public build: LazyBuild<WD, ConfigType, ValueSpecList>, public build: LazyBuild<WD, ValueSpecList>,
public validator: Parser<unknown, Type>, public validator: Parser<unknown, Type>,
) {} ) {}
static text<WD, CT>( static text<WD>(
a: { a: {
name: string name: string
description?: string | null description?: string | null
@@ -45,7 +45,7 @@ export class List<Type, WD, ConfigType> {
inputmode?: ListValueSpecText["inputmode"] inputmode?: ListValueSpecText["inputmode"]
}, },
) { ) {
return new List<string[], WD, CT>(() => { return new List<string[], WD>(() => {
const spec = { const spec = {
type: "text" as const, type: "text" as const,
placeholder: null, placeholder: null,
@@ -67,10 +67,9 @@ export class List<Type, WD, ConfigType> {
} }
}, arrayOf(string)) }, arrayOf(string))
} }
static dynamicText<WD, CT>( static dynamicText<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -92,7 +91,7 @@ export class List<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new List<string[], WD, CT>(async (options) => { return new List<string[], WD>(async (options) => {
const { spec: aSpec, ...a } = await getA(options) const { spec: aSpec, ...a } = await getA(options)
const spec = { const spec = {
type: "text" as const, type: "text" as const,
@@ -115,7 +114,7 @@ export class List<Type, WD, ConfigType> {
} }
}, arrayOf(string)) }, arrayOf(string))
} }
static number<WD, CT>( static number<WD>(
a: { a: {
name: string name: string
description?: string | null description?: string | null
@@ -134,7 +133,7 @@ export class List<Type, WD, ConfigType> {
placeholder?: string | null placeholder?: string | null
}, },
) { ) {
return new List<number[], WD, CT>(() => { return new List<number[], WD>(() => {
const spec = { const spec = {
type: "number" as const, type: "number" as const,
placeholder: null, placeholder: null,
@@ -156,10 +155,9 @@ export class List<Type, WD, ConfigType> {
} }
}, arrayOf(number)) }, arrayOf(number))
} }
static dynamicNumber<WD, CT>( static dynamicNumber<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -179,7 +177,7 @@ export class List<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new List<number[], WD, CT>(async (options) => { return new List<number[], WD>(async (options) => {
const { spec: aSpec, ...a } = await getA(options) const { spec: aSpec, ...a } = await getA(options)
const spec = { const spec = {
type: "number" as const, type: "number" as const,
@@ -202,7 +200,7 @@ export class List<Type, WD, ConfigType> {
} }
}, arrayOf(number)) }, arrayOf(number))
} }
static obj<Type extends Record<string, any>, WrapperData, ConfigType>( static obj<Type extends Record<string, any>, WrapperData>(
a: { a: {
name: string name: string
description?: string | null description?: string | null
@@ -213,12 +211,12 @@ export class List<Type, WD, ConfigType> {
maxLength?: number | null maxLength?: number | null
}, },
aSpec: { aSpec: {
spec: Config<Type, WrapperData, ConfigType> spec: Config<Type, WrapperData>
displayAs?: null | string displayAs?: null | string
uniqueBy?: null | UniqueBy uniqueBy?: null | UniqueBy
}, },
) { ) {
return new List<Type[], WrapperData, ConfigType>(async (options) => { return new List<Type[], WrapperData>(async (options) => {
const { spec: previousSpecSpec, ...restSpec } = aSpec const { spec: previousSpecSpec, ...restSpec } = aSpec
const specSpec = await previousSpecSpec.build(options) const specSpec = await previousSpecSpec.build(options)
const spec = { const spec = {

View File

@@ -93,18 +93,18 @@ const username = Value.string({
}); });
``` ```
*/ */
export class Value<Type, WD, ConfigType> { export class Value<Type, WD> {
private constructor( private constructor(
public build: LazyBuild<WD, ConfigType, ValueSpec>, public build: LazyBuild<WD, ValueSpec>,
public validator: Parser<unknown, Type>, public validator: Parser<unknown, Type>,
) {} ) {}
static toggle<WD, CT>(a: { static toggle<WD>(a: {
name: string name: string
description?: string | null description?: string | null
warning?: string | null warning?: string | null
default?: boolean | null default?: boolean | null
}) { }) {
return new Value<boolean, WD, CT>( return new Value<boolean, WD>(
async () => ({ async () => ({
description: null, description: null,
warning: null, warning: null,
@@ -115,10 +115,9 @@ export class Value<Type, WD, ConfigType> {
boolean, boolean,
) )
} }
static dynamicToggle<WD, CT>( static dynamicToggle<WD>(
a: LazyBuild< a: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -127,7 +126,7 @@ export class Value<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new Value<boolean, WD, CT>( return new Value<boolean, WD>(
async (options) => ({ async (options) => ({
description: null, description: null,
warning: null, warning: null,
@@ -138,7 +137,7 @@ export class Value<Type, WD, ConfigType> {
boolean, boolean,
) )
} }
static text<Required extends RequiredDefault<DefaultString>, WD, CT>(a: { static text<Required extends RequiredDefault<DefaultString>, WD>(a: {
name: string name: string
description?: string | null description?: string | null
warning?: string | null warning?: string | null
@@ -153,7 +152,7 @@ export class Value<Type, WD, ConfigType> {
/** Default = 'text' */ /** Default = 'text' */
inputmode?: ValueSpecText["inputmode"] inputmode?: ValueSpecText["inputmode"]
}) { }) {
return new Value<AsRequired<string, Required>, WD, CT>( return new Value<AsRequired<string, Required>, WD>(
async () => ({ async () => ({
type: "text" as const, type: "text" as const,
description: null, description: null,
@@ -170,10 +169,9 @@ export class Value<Type, WD, ConfigType> {
asRequiredParser(string, a), asRequiredParser(string, a),
) )
} }
static dynamicText<WD, CT>( static dynamicText<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -191,7 +189,7 @@ export class Value<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new Value<string | null | undefined, WD, CT>(async (options) => { return new Value<string | null | undefined, WD>(async (options) => {
const a = await getA(options) const a = await getA(options)
return { return {
type: "text" as const, type: "text" as const,
@@ -208,7 +206,7 @@ export class Value<Type, WD, ConfigType> {
} }
}, string.optional()) }, string.optional())
} }
static textarea<WD, CT>(a: { static textarea<WD>(a: {
name: string name: string
description?: string | null description?: string | null
warning?: string | null warning?: string | null
@@ -217,7 +215,7 @@ export class Value<Type, WD, ConfigType> {
maxLength?: number | null maxLength?: number | null
placeholder?: string | null placeholder?: string | null
}) { }) {
return new Value<string, WD, CT>( return new Value<string, WD>(
async () => async () =>
({ ({
description: null, description: null,
@@ -231,10 +229,9 @@ export class Value<Type, WD, ConfigType> {
string, string,
) )
} }
static dynamicTextarea<WD, CT>( static dynamicTextarea<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -246,7 +243,7 @@ export class Value<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new Value<string, WD, CT>(async (options) => { return new Value<string, WD>(async (options) => {
const a = await getA(options) const a = await getA(options)
return { return {
description: null, description: null,
@@ -259,7 +256,7 @@ export class Value<Type, WD, ConfigType> {
} }
}, string) }, string)
} }
static number<Required extends RequiredDefault<number>, WD, CT>(a: { static number<Required extends RequiredDefault<number>, WD>(a: {
name: string name: string
description?: string | null description?: string | null
warning?: string | null warning?: string | null
@@ -272,7 +269,7 @@ export class Value<Type, WD, ConfigType> {
units?: string | null units?: string | null
placeholder?: string | null placeholder?: string | null
}) { }) {
return new Value<AsRequired<number, Required>, WD, CT>( return new Value<AsRequired<number, Required>, WD>(
() => ({ () => ({
type: "number" as const, type: "number" as const,
description: null, description: null,
@@ -288,10 +285,9 @@ export class Value<Type, WD, ConfigType> {
asRequiredParser(number, a), asRequiredParser(number, a),
) )
} }
static dynamicNumber<WD, CT>( static dynamicNumber<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -307,7 +303,7 @@ export class Value<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new Value<number | null | undefined, WD, CT>(async (options) => { return new Value<number | null | undefined, WD>(async (options) => {
const a = await getA(options) const a = await getA(options)
return { return {
type: "number" as const, type: "number" as const,
@@ -323,13 +319,13 @@ export class Value<Type, WD, ConfigType> {
} }
}, number.optional()) }, number.optional())
} }
static color<Required extends RequiredDefault<string>, WD, CT>(a: { static color<Required extends RequiredDefault<string>, WD>(a: {
name: string name: string
description?: string | null description?: string | null
warning?: string | null warning?: string | null
required: Required required: Required
}) { }) {
return new Value<AsRequired<string, Required>, WD, CT>( return new Value<AsRequired<string, Required>, WD>(
() => ({ () => ({
type: "color" as const, type: "color" as const,
description: null, description: null,
@@ -342,10 +338,9 @@ export class Value<Type, WD, ConfigType> {
) )
} }
static dynamicColor<WD, CT>( static dynamicColor<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -354,7 +349,7 @@ export class Value<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new Value<string | null | undefined, WD, CT>(async (options) => { return new Value<string | null | undefined, WD>(async (options) => {
const a = await getA(options) const a = await getA(options)
return { return {
type: "color" as const, type: "color" as const,
@@ -365,7 +360,7 @@ export class Value<Type, WD, ConfigType> {
} }
}, string.optional()) }, string.optional())
} }
static datetime<Required extends RequiredDefault<string>, WD, CT>(a: { static datetime<Required extends RequiredDefault<string>, WD>(a: {
name: string name: string
description?: string | null description?: string | null
warning?: string | null warning?: string | null
@@ -376,7 +371,7 @@ export class Value<Type, WD, ConfigType> {
max?: string | null max?: string | null
step?: string | null step?: string | null
}) { }) {
return new Value<AsRequired<string, Required>, WD, CT>( return new Value<AsRequired<string, Required>, WD>(
() => ({ () => ({
type: "datetime" as const, type: "datetime" as const,
description: null, description: null,
@@ -391,10 +386,9 @@ export class Value<Type, WD, ConfigType> {
asRequiredParser(string, a), asRequiredParser(string, a),
) )
} }
static dynamicDatetime<WD, CT>( static dynamicDatetime<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -408,7 +402,7 @@ export class Value<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new Value<string | null | undefined, WD, CT>(async (options) => { return new Value<string | null | undefined, WD>(async (options) => {
const a = await getA(options) const a = await getA(options)
return { return {
type: "datetime" as const, type: "datetime" as const,
@@ -435,7 +429,7 @@ export class Value<Type, WD, ConfigType> {
required: Required required: Required
values: B values: B
}) { }) {
return new Value<AsRequired<keyof B, Required>, WD, CT>( return new Value<AsRequired<keyof B, Required>, WD>(
() => ({ () => ({
description: null, description: null,
warning: null, warning: null,
@@ -451,10 +445,9 @@ export class Value<Type, WD, ConfigType> {
) as any, ) as any,
) )
} }
static dynamicSelect<WD, CT>( static dynamicSelect<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -464,7 +457,7 @@ export class Value<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new Value<string | null | undefined, WD, CT>(async (options) => { return new Value<string | null | undefined, WD>(async (options) => {
const a = await getA(options) const a = await getA(options)
return { return {
description: null, description: null,
@@ -475,7 +468,7 @@ export class Value<Type, WD, ConfigType> {
} }
}, string.optional()) }, string.optional())
} }
static multiselect<Values extends Record<string, string>, WD, CT>(a: { static multiselect<Values extends Record<string, string>, WD>(a: {
name: string name: string
description?: string | null description?: string | null
warning?: string | null warning?: string | null
@@ -484,7 +477,7 @@ export class Value<Type, WD, ConfigType> {
minLength?: number | null minLength?: number | null
maxLength?: number | null maxLength?: number | null
}) { }) {
return new Value<(keyof Values)[], WD, CT>( return new Value<(keyof Values)[], WD>(
() => ({ () => ({
type: "multiselect" as const, type: "multiselect" as const,
minLength: null, minLength: null,
@@ -498,10 +491,9 @@ export class Value<Type, WD, ConfigType> {
), ),
) )
} }
static dynamicMultiselect<WD, CT>( static dynamicMultiselect<WD>(
getA: LazyBuild< getA: LazyBuild<
WD, WD,
CT,
{ {
name: string name: string
description?: string | null description?: string | null
@@ -513,7 +505,7 @@ export class Value<Type, WD, ConfigType> {
} }
>, >,
) { ) {
return new Value<string[], WD, CT>(async (options) => { return new Value<string[], WD>(async (options) => {
const a = await getA(options) const a = await getA(options)
return { return {
type: "multiselect" as const, type: "multiselect" as const,
@@ -525,15 +517,15 @@ export class Value<Type, WD, ConfigType> {
} }
}, arrayOf(string)) }, arrayOf(string))
} }
static object<Type extends Record<string, any>, WrapperData, ConfigType>( static object<Type extends Record<string, any>, WrapperData>(
a: { a: {
name: string name: string
description?: string | null description?: string | null
warning?: string | null warning?: string | null
}, },
previousSpec: Config<Type, WrapperData, ConfigType>, previousSpec: Config<Type, WrapperData>,
) { ) {
return new Value<Type, WrapperData, ConfigType>(async (options) => { return new Value<Type, WrapperData>(async (options) => {
const spec = await previousSpec.build(options as any) const spec = await previousSpec.build(options as any)
return { return {
type: "object" as const, type: "object" as const,
@@ -557,9 +549,9 @@ export class Value<Type, WD, ConfigType> {
required: Required required: Required
default?: string | null default?: string | null
}, },
aVariants: Variants<Type, WrapperData, ConfigType>, aVariants: Variants<Type, WrapperData>,
) { ) {
return new Value<AsRequired<Type, Required>, WrapperData, ConfigType>( return new Value<AsRequired<Type, Required>, WrapperData>(
async (options) => ({ async (options) => ({
type: "union" as const, type: "union" as const,
description: null, description: null,
@@ -584,14 +576,13 @@ export class Value<Type, WD, ConfigType> {
required: Required required: Required
default?: string | null default?: string | null
}, },
aVariants: Variants<Type, WrapperData, ConfigType>, aVariants: Variants<Type, WrapperData>,
getDisabledFn: LazyBuild< getDisabledFn: LazyBuild<
WrapperData, WrapperData,
ConfigType,
Array<Type extends { unionSelectKey: infer B } ? B & string : never> Array<Type extends { unionSelectKey: infer B } ? B & string : never>
>, >,
) { ) {
return new Value<Type | null | undefined, WrapperData, ConfigType>( return new Value<Type | null | undefined, WrapperData>(
async (options) => ({ async (options) => ({
type: "union" as const, type: "union" as const,
description: null, description: null,
@@ -605,11 +596,9 @@ export class Value<Type, WD, ConfigType> {
) )
} }
static list<Type, WrapperData, ConfigType>( static list<Type, WrapperData>(a: List<Type, WrapperData>) {
a: List<Type, WrapperData, ConfigType>,
) {
/// TODO /// TODO
return new Value<Type, WrapperData, ConfigType>( return new Value<Type, WrapperData>(
(options) => a.build(options), (options) => a.build(options),
a.validator, a.validator,
) )

View File

@@ -52,9 +52,9 @@ export const pruning = Value.union(
); );
``` ```
*/ */
export class Variants<Type, WD, ConfigType> { export class Variants<Type, WD> {
private constructor( private constructor(
public build: LazyBuild<WD, ConfigType, ValueSpecUnion["variants"]>, public build: LazyBuild<WD, ValueSpecUnion["variants"]>,
public validator: Parser<unknown, Type>, public validator: Parser<unknown, Type>,
) {} ) {}
// A extends { // A extends {
@@ -70,7 +70,7 @@ export class Variants<Type, WD, ConfigType> {
>(a: { >(a: {
[K in keyof TypeMap]: { [K in keyof TypeMap]: {
name: string name: string
spec: Config<TypeMap[K], WrapperData, ConfigType> spec: Config<TypeMap[K], WrapperData>
} }
}) { }) {
type TypeOut = { type TypeOut = {
@@ -89,7 +89,7 @@ export class Variants<Type, WD, ConfigType> {
), ),
) as Parser<unknown, TypeOut> ) as Parser<unknown, TypeOut>
return new Variants<TypeOut, WrapperData, ConfigType>(async (options) => { return new Variants<TypeOut, WrapperData>(async (options) => {
const variants = {} as { const variants = {} as {
[K in keyof TypeMap]: { name: string; spec: InputSpec } [K in keyof TypeMap]: { name: string; spec: InputSpec }
} }

View File

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

View File

@@ -2,7 +2,7 @@ import { Config } from "./builder"
import { DeepPartial, Dependencies, Effects, ExpectedExports } from "../types" import { DeepPartial, Dependencies, Effects, ExpectedExports } from "../types"
import { InputSpec } from "./configTypes" import { InputSpec } from "./configTypes"
import { Utils, nullIfEmpty, once, utils } from "../util" import { Utils, nullIfEmpty, once, utils } from "../util"
import { GenericManifest } from "../manifest/ManifestTypes" import { SDKManifest } from "../manifest/ManifestTypes"
import * as D from "./dependencies" import * as D from "./dependencies"
import { ExtractConfigType } from "./builder/config" import { ExtractConfigType } from "./builder/config"
@@ -13,8 +13,8 @@ export type DependenciesReceipt = void & {
export type Save< export type Save<
WD, WD,
A extends Record<string, any> | Config<Record<string, any>, any, any>, A extends Record<string, any> | Config<Record<string, any>, any>,
Manifest extends GenericManifest, Manifest extends SDKManifest,
> = (options: { > = (options: {
effects: Effects effects: Effects
input: ExtractConfigType<A> & Record<string, any> input: ExtractConfigType<A> & Record<string, any>
@@ -23,7 +23,7 @@ export type Save<
}) => Promise<DependenciesReceipt> }) => Promise<DependenciesReceipt>
export type Read< export type Read<
WD, WD,
A extends Record<string, any> | Config<Record<string, any>, any, any>, A extends Record<string, any> | Config<Record<string, any>, any>,
> = (options: { > = (options: {
effects: Effects effects: Effects
utils: Utils<WD> utils: Utils<WD>
@@ -37,11 +37,11 @@ export type Read<
*/ */
export function setupConfig< export function setupConfig<
WD, WD,
ConfigType extends Record<string, any> | Config<any, any, any>, ConfigType extends Record<string, any> | Config<any, any>,
Manifest extends GenericManifest, Manifest extends SDKManifest,
Type extends Record<string, any> = ExtractConfigType<ConfigType>, Type extends Record<string, any> = ExtractConfigType<ConfigType>,
>( >(
spec: Config<Type, WD, Type>, spec: Config<Type, WD>,
write: Save<WD, Type, Manifest>, write: Save<WD, Type, Manifest>,
read: Read<WD, Type>, read: Read<WD, Type>,
) { ) {
@@ -68,7 +68,6 @@ export function setupConfig<
spec: await spec.build({ spec: await spec.build({
effects, effects,
utils: myUtils, utils: myUtils,
config: configValue as Type,
}), }),
config: configValue, config: configValue,
} }

View File

@@ -1,13 +1,13 @@
import { setupActions } from "../../actions/setupActions" import { setupActions } from "../../actions/setupActions"
import { EmVer } from "../../emverLite/mod" import { EmVer } from "../../emverLite/mod"
import { GenericManifest } from "../../manifest/ManifestTypes" import { SDKManifest } from "../../manifest/ManifestTypes"
import { ExpectedExports } from "../../types" import { ExpectedExports } from "../../types"
import { once } from "../../util/once" import { once } from "../../util/once"
import { Migration } from "./Migration" import { Migration } from "./Migration"
export class Migrations { export class Migrations {
private constructor( private constructor(
readonly manifest: GenericManifest, readonly manifest: SDKManifest,
readonly migrations: Array<Migration<any>>, readonly migrations: Array<Migration<any>>,
) {} ) {}
private sortedMigrations = once(() => { private sortedMigrations = once(() => {
@@ -19,7 +19,7 @@ export class Migrations {
}) })
private currentVersion = once(() => EmVer.parse(this.manifest.version)) private currentVersion = once(() => EmVer.parse(this.manifest.version))
static of<Migrations extends Array<Migration<any>>>( static of<Migrations extends Array<Migration<any>>>(
manifest: GenericManifest, manifest: SDKManifest,
...migrations: EnsureUniqueId<Migrations> ...migrations: EnsureUniqueId<Migrations>
) { ) {
return new Migrations(manifest, migrations as Array<Migration<any>>) return new Migrations(manifest, migrations as Array<Migration<any>>)
@@ -54,7 +54,7 @@ export class Migrations {
} }
export function setupMigrations<Migrations extends Array<Migration<any>>>( export function setupMigrations<Migrations extends Array<Migration<any>>>(
manifest: GenericManifest, manifest: SDKManifest,
...migrations: EnsureUniqueId<Migrations> ...migrations: EnsureUniqueId<Migrations>
) { ) {
return Migrations.of(manifest, ...migrations) return Migrations.of(manifest, ...migrations)

View File

@@ -14,7 +14,7 @@ export interface Container {
export type ManifestVersion = ValidEmVer export type ManifestVersion = ValidEmVer
export interface GenericManifest { export interface SDKManifest {
/** The package identifier used by the OS. This must be unique amongst all other known packages */ /** The package identifier used by the OS. This must be unique amongst all other known packages */
id: string id: string
/** A human readable service title */ /** A human readable service title */

View File

@@ -1,11 +1,11 @@
import { GenericManifest, ManifestVersion } from "./ManifestTypes" import { SDKManifest, ManifestVersion } from "./ManifestTypes"
export function setupManifest< export function setupManifest<
Id extends string, Id extends string,
Version extends ManifestVersion, Version extends ManifestVersion,
Dependencies extends Record<string, unknown>, Dependencies extends Record<string, unknown>,
Volumes extends Record<string, unknown>, Volumes extends Record<string, unknown>,
Manifest extends GenericManifest & { Manifest extends SDKManifest & {
dependencies: Dependencies dependencies: Dependencies
id: Id id: Id
version: Version version: Version

View File

@@ -303,7 +303,7 @@ describe("values", () => {
utils: "utils", utils: "utils",
} as any } as any
test("toggle", async () => { test("toggle", async () => {
const value = Value.dynamicToggle<{}, {}>(async () => ({ const value = Value.dynamicToggle<{}>(async () => ({
name: "Testing", name: "Testing",
description: null, description: null,
warning: null, warning: null,
@@ -368,7 +368,7 @@ describe("values", () => {
}) })
}) })
test("color", async () => { test("color", async () => {
const value = Value.dynamicColor<null, null>(async () => ({ const value = Value.dynamicColor<null>(async () => ({
name: "Testing", name: "Testing",
required: false, required: false,
description: null, description: null,
@@ -387,11 +387,10 @@ describe("values", () => {
}) })
}) })
test("datetime", async () => { test("datetime", async () => {
const value = Value.dynamicDatetime<{ test: "a" }, { test2: 6 }>( const value = Value.dynamicDatetime<{ test: "a" }>(
async ({ effects, utils, config }) => { async ({ effects, utils }) => {
;async () => { ;async () => {
;(await utils.getOwnWrapperData("/test").once()) satisfies "a" ;(await utils.getOwnWrapperData("/test").once()) satisfies "a"
config satisfies { test2: 6 } | null
} }
return { return {