diff --git a/lib/actions/createAction.ts b/lib/actions/createAction.ts index ec3b399..9b39565 100644 --- a/lib/actions/createAction.ts +++ b/lib/actions/createAction.ts @@ -5,12 +5,12 @@ import { Utils, utils } from "../util" export class CreatedAction< WrapperData, - ConfigType extends Record | Config, + ConfigType extends Record | Config, Type extends Record = ExtractConfigType, > { private constructor( public readonly myMetaData: Omit & { - input: Config + input: Config }, readonly fn: (options: { effects: Effects @@ -22,11 +22,11 @@ export class CreatedAction< static of< WrapperData, - ConfigType extends Record | Config, + ConfigType extends Record | Config, Type extends Record = ExtractConfigType, >( metaData: Omit & { - input: Config + input: Config }, fn: (options: { effects: Effects @@ -52,7 +52,6 @@ export class CreatedAction< input: await this.myMetaData.input.build({ effects, utils: myUtils, - config: null, }), } await effects.exportAction(metaData) diff --git a/lib/autoconfig/setupAutoConfig.ts b/lib/autoconfig/setupAutoConfig.ts index 0c7f072..ca02420 100644 --- a/lib/autoconfig/setupAutoConfig.ts +++ b/lib/autoconfig/setupAutoConfig.ts @@ -1,10 +1,10 @@ -import { GenericManifest } from "../manifest/ManifestTypes" +import { SDKManifest } from "../manifest/ManifestTypes" import { AutoConfig, AutoConfigFrom } from "./AutoConfig" export function setupAutoConfig< WD, Input, - Manifest extends GenericManifest, + Manifest extends SDKManifest, NestedConfigs extends { [key in keyof Manifest["dependencies"]]: unknown }, diff --git a/lib/backup/Backups.ts b/lib/backup/Backups.ts index 0a6eecc..137335e 100644 --- a/lib/backup/Backups.ts +++ b/lib/backup/Backups.ts @@ -1,4 +1,4 @@ -import { GenericManifest } from "../manifest/ManifestTypes" +import { SDKManifest } from "../manifest/ManifestTypes" import * as T from "../types" export type BACKUP = "BACKUP" @@ -37,14 +37,14 @@ type BackupSet = { * ).build()q * ``` */ -export class Backups { +export class Backups { static BACKUP: BACKUP = "BACKUP" constructor( private options = DEFAULT_OPTIONS, private backupSet = [] as BackupSet[], ) {} - static volumes( + static volumes( ...volumeNames: Array ) { return new Backups().addSets( @@ -56,12 +56,12 @@ export class Backups { })), ) } - static addSets( + static addSets( ...options: BackupSet[] ) { return new Backups().addSets(...options) } - static with_options( + static with_options( options?: Partial, ) { return new Backups({ ...DEFAULT_OPTIONS, ...options }) diff --git a/lib/backup/setupBackups.ts b/lib/backup/setupBackups.ts index d9ba69c..a101661 100644 --- a/lib/backup/setupBackups.ts +++ b/lib/backup/setupBackups.ts @@ -1,14 +1,14 @@ import { string } from "ts-matches" import { Backups } from "." -import { GenericManifest } from "../manifest/ManifestTypes" +import { SDKManifest } from "../manifest/ManifestTypes" import { BackupOptions, ExpectedExports } from "../types" import { _ } from "../util" -export type SetupBackupsParams = Array< +export type SetupBackupsParams = Array< (keyof M["volumes"] & string) | Backups > -export function setupBackups( +export function setupBackups( ...args: _> ) { const backups = Array>() diff --git a/lib/config/builder/config.ts b/lib/config/builder/config.ts index f4cfd3d..90f0e44 100644 --- a/lib/config/builder/config.ts +++ b/lib/config/builder/config.ts @@ -5,21 +5,20 @@ import { _ } from "../../util" import { Effects } from "../../types" import { Parser, object } from "ts-matches" -export type LazyBuildOptions = { +export type LazyBuildOptions = { effects: Effects utils: Utils - config: ConfigType | null } -export type LazyBuild = ( - options: LazyBuildOptions, +export type LazyBuild = ( + options: LazyBuildOptions, ) => Promise | ExpectedOut // prettier-ignore -export type ExtractConfigType | Config, any, any>> = - A extends Config ? B : +export type ExtractConfigType | Config, any>> = + A extends Config ? B : A -export type MaybeLazyValues = LazyBuild | A +export type MaybeLazyValues = LazyBuild | A /** * Configs are the specs that are used by the os configuration form for this service. * Here is an example of a simple configuration @@ -76,14 +75,14 @@ export const addNodesSpec = Config.of({ hostname: hostname, port: port }); ``` */ -export class Config, WD, ConfigType> { +export class Config, WD> { private constructor( private readonly spec: { - [K in keyof Type]: Value + [K in keyof Type]: Value }, public validator: Parser, ) {} - async build(options: LazyBuildOptions) { + async build(options: LazyBuildOptions) { const answer = {} as { [K in keyof Type]: ValueSpec } @@ -93,8 +92,8 @@ export class Config, WD, ConfigType> { return answer } - static of, WrapperData, ConfigType>(spec: { - [K in keyof Type]: Value + static of, WrapperData>(spec: { + [K in keyof Type]: Value }) { const validatorObj = {} as { [K in keyof Type]: Parser @@ -103,21 +102,22 @@ export class Config, WD, ConfigType> { validatorObj[key] = spec[key].validator } const validator = object(validatorObj) - return new Config(spec, validator) + return new Config(spec, validator) } static withWrapperData() { return { of>(spec: { - [K in keyof Type]: Value + [K in keyof Type]: Value }) { - return Config.of(spec) + return Config.of(spec) }, } } } + export function topConfig() { return >(spec: { - [K in keyof Type]: Value - }) => Config.of(spec) + [K in keyof Type]: Value + }) => Config.of(spec) } diff --git a/lib/config/builder/list.ts b/lib/config/builder/list.ts index 5822067..a6259ea 100644 --- a/lib/config/builder/list.ts +++ b/lib/config/builder/list.ts @@ -19,12 +19,12 @@ export const authorizationList = List.string({ export const auth = Value.list(authorizationList); ``` */ -export class List { +export class List { private constructor( - public build: LazyBuild, + public build: LazyBuild, public validator: Parser, ) {} - static text( + static text( a: { name: string description?: string | null @@ -45,7 +45,7 @@ export class List { inputmode?: ListValueSpecText["inputmode"] }, ) { - return new List(() => { + return new List(() => { const spec = { type: "text" as const, placeholder: null, @@ -67,10 +67,9 @@ export class List { } }, arrayOf(string)) } - static dynamicText( + static dynamicText( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -92,7 +91,7 @@ export class List { } >, ) { - return new List(async (options) => { + return new List(async (options) => { const { spec: aSpec, ...a } = await getA(options) const spec = { type: "text" as const, @@ -115,7 +114,7 @@ export class List { } }, arrayOf(string)) } - static number( + static number( a: { name: string description?: string | null @@ -134,7 +133,7 @@ export class List { placeholder?: string | null }, ) { - return new List(() => { + return new List(() => { const spec = { type: "number" as const, placeholder: null, @@ -156,10 +155,9 @@ export class List { } }, arrayOf(number)) } - static dynamicNumber( + static dynamicNumber( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -179,7 +177,7 @@ export class List { } >, ) { - return new List(async (options) => { + return new List(async (options) => { const { spec: aSpec, ...a } = await getA(options) const spec = { type: "number" as const, @@ -202,7 +200,7 @@ export class List { } }, arrayOf(number)) } - static obj, WrapperData, ConfigType>( + static obj, WrapperData>( a: { name: string description?: string | null @@ -213,12 +211,12 @@ export class List { maxLength?: number | null }, aSpec: { - spec: Config + spec: Config displayAs?: null | string uniqueBy?: null | UniqueBy }, ) { - return new List(async (options) => { + return new List(async (options) => { const { spec: previousSpecSpec, ...restSpec } = aSpec const specSpec = await previousSpecSpec.build(options) const spec = { diff --git a/lib/config/builder/value.ts b/lib/config/builder/value.ts index 36552d5..d4a4316 100644 --- a/lib/config/builder/value.ts +++ b/lib/config/builder/value.ts @@ -93,18 +93,18 @@ const username = Value.string({ }); ``` */ -export class Value { +export class Value { private constructor( - public build: LazyBuild, + public build: LazyBuild, public validator: Parser, ) {} - static toggle(a: { + static toggle(a: { name: string description?: string | null warning?: string | null default?: boolean | null }) { - return new Value( + return new Value( async () => ({ description: null, warning: null, @@ -115,10 +115,9 @@ export class Value { boolean, ) } - static dynamicToggle( + static dynamicToggle( a: LazyBuild< WD, - CT, { name: string description?: string | null @@ -127,7 +126,7 @@ export class Value { } >, ) { - return new Value( + return new Value( async (options) => ({ description: null, warning: null, @@ -138,7 +137,7 @@ export class Value { boolean, ) } - static text, WD, CT>(a: { + static text, WD>(a: { name: string description?: string | null warning?: string | null @@ -153,7 +152,7 @@ export class Value { /** Default = 'text' */ inputmode?: ValueSpecText["inputmode"] }) { - return new Value, WD, CT>( + return new Value, WD>( async () => ({ type: "text" as const, description: null, @@ -170,10 +169,9 @@ export class Value { asRequiredParser(string, a), ) } - static dynamicText( + static dynamicText( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -191,7 +189,7 @@ export class Value { } >, ) { - return new Value(async (options) => { + return new Value(async (options) => { const a = await getA(options) return { type: "text" as const, @@ -208,7 +206,7 @@ export class Value { } }, string.optional()) } - static textarea(a: { + static textarea(a: { name: string description?: string | null warning?: string | null @@ -217,7 +215,7 @@ export class Value { maxLength?: number | null placeholder?: string | null }) { - return new Value( + return new Value( async () => ({ description: null, @@ -231,10 +229,9 @@ export class Value { string, ) } - static dynamicTextarea( + static dynamicTextarea( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -246,7 +243,7 @@ export class Value { } >, ) { - return new Value(async (options) => { + return new Value(async (options) => { const a = await getA(options) return { description: null, @@ -259,7 +256,7 @@ export class Value { } }, string) } - static number, WD, CT>(a: { + static number, WD>(a: { name: string description?: string | null warning?: string | null @@ -272,7 +269,7 @@ export class Value { units?: string | null placeholder?: string | null }) { - return new Value, WD, CT>( + return new Value, WD>( () => ({ type: "number" as const, description: null, @@ -288,10 +285,9 @@ export class Value { asRequiredParser(number, a), ) } - static dynamicNumber( + static dynamicNumber( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -307,7 +303,7 @@ export class Value { } >, ) { - return new Value(async (options) => { + return new Value(async (options) => { const a = await getA(options) return { type: "number" as const, @@ -323,13 +319,13 @@ export class Value { } }, number.optional()) } - static color, WD, CT>(a: { + static color, WD>(a: { name: string description?: string | null warning?: string | null required: Required }) { - return new Value, WD, CT>( + return new Value, WD>( () => ({ type: "color" as const, description: null, @@ -342,10 +338,9 @@ export class Value { ) } - static dynamicColor( + static dynamicColor( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -354,7 +349,7 @@ export class Value { } >, ) { - return new Value(async (options) => { + return new Value(async (options) => { const a = await getA(options) return { type: "color" as const, @@ -365,7 +360,7 @@ export class Value { } }, string.optional()) } - static datetime, WD, CT>(a: { + static datetime, WD>(a: { name: string description?: string | null warning?: string | null @@ -376,7 +371,7 @@ export class Value { max?: string | null step?: string | null }) { - return new Value, WD, CT>( + return new Value, WD>( () => ({ type: "datetime" as const, description: null, @@ -391,10 +386,9 @@ export class Value { asRequiredParser(string, a), ) } - static dynamicDatetime( + static dynamicDatetime( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -408,7 +402,7 @@ export class Value { } >, ) { - return new Value(async (options) => { + return new Value(async (options) => { const a = await getA(options) return { type: "datetime" as const, @@ -435,7 +429,7 @@ export class Value { required: Required values: B }) { - return new Value, WD, CT>( + return new Value, WD>( () => ({ description: null, warning: null, @@ -451,10 +445,9 @@ export class Value { ) as any, ) } - static dynamicSelect( + static dynamicSelect( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -464,7 +457,7 @@ export class Value { } >, ) { - return new Value(async (options) => { + return new Value(async (options) => { const a = await getA(options) return { description: null, @@ -475,7 +468,7 @@ export class Value { } }, string.optional()) } - static multiselect, WD, CT>(a: { + static multiselect, WD>(a: { name: string description?: string | null warning?: string | null @@ -484,7 +477,7 @@ export class Value { minLength?: number | null maxLength?: number | null }) { - return new Value<(keyof Values)[], WD, CT>( + return new Value<(keyof Values)[], WD>( () => ({ type: "multiselect" as const, minLength: null, @@ -498,10 +491,9 @@ export class Value { ), ) } - static dynamicMultiselect( + static dynamicMultiselect( getA: LazyBuild< WD, - CT, { name: string description?: string | null @@ -513,7 +505,7 @@ export class Value { } >, ) { - return new Value(async (options) => { + return new Value(async (options) => { const a = await getA(options) return { type: "multiselect" as const, @@ -525,15 +517,15 @@ export class Value { } }, arrayOf(string)) } - static object, WrapperData, ConfigType>( + static object, WrapperData>( a: { name: string description?: string | null warning?: string | null }, - previousSpec: Config, + previousSpec: Config, ) { - return new Value(async (options) => { + return new Value(async (options) => { const spec = await previousSpec.build(options as any) return { type: "object" as const, @@ -557,9 +549,9 @@ export class Value { required: Required default?: string | null }, - aVariants: Variants, + aVariants: Variants, ) { - return new Value, WrapperData, ConfigType>( + return new Value, WrapperData>( async (options) => ({ type: "union" as const, description: null, @@ -584,14 +576,13 @@ export class Value { required: Required default?: string | null }, - aVariants: Variants, + aVariants: Variants, getDisabledFn: LazyBuild< WrapperData, - ConfigType, Array >, ) { - return new Value( + return new Value( async (options) => ({ type: "union" as const, description: null, @@ -605,11 +596,9 @@ export class Value { ) } - static list( - a: List, - ) { + static list(a: List) { /// TODO - return new Value( + return new Value( (options) => a.build(options), a.validator, ) diff --git a/lib/config/builder/variants.ts b/lib/config/builder/variants.ts index 0aa39a5..3155d3e 100644 --- a/lib/config/builder/variants.ts +++ b/lib/config/builder/variants.ts @@ -52,9 +52,9 @@ export const pruning = Value.union( ); ``` */ -export class Variants { +export class Variants { private constructor( - public build: LazyBuild, + public build: LazyBuild, public validator: Parser, ) {} // A extends { @@ -70,7 +70,7 @@ export class Variants { >(a: { [K in keyof TypeMap]: { name: string - spec: Config + spec: Config } }) { type TypeOut = { @@ -89,7 +89,7 @@ export class Variants { ), ) as Parser - return new Variants(async (options) => { + return new Variants(async (options) => { const variants = {} as { [K in keyof TypeMap]: { name: string; spec: InputSpec } } diff --git a/lib/config/dependencies.ts b/lib/config/dependencies.ts index 80c7843..f541b0c 100644 --- a/lib/config/dependencies.ts +++ b/lib/config/dependencies.ts @@ -1,14 +1,12 @@ -import { GenericManifest } from "../manifest/ManifestTypes" +import { SDKManifest } from "../manifest/ManifestTypes" import { Dependency, PackageId } from "../types" -export type Dependencies = { +export type Dependencies = { exists(id: keyof T["dependencies"]): Dependency running(id: keyof T["dependencies"]): Dependency } -export const dependenciesSet = < - T extends GenericManifest, ->(): Dependencies => ({ +export const dependenciesSet = (): Dependencies => ({ exists(id: keyof T["dependencies"]) { return { id, diff --git a/lib/config/setupConfig.ts b/lib/config/setupConfig.ts index 01c80dc..05263e7 100644 --- a/lib/config/setupConfig.ts +++ b/lib/config/setupConfig.ts @@ -2,7 +2,7 @@ import { Config } from "./builder" import { DeepPartial, Dependencies, Effects, ExpectedExports } from "../types" import { InputSpec } from "./configTypes" import { Utils, nullIfEmpty, once, utils } from "../util" -import { GenericManifest } from "../manifest/ManifestTypes" +import { SDKManifest } from "../manifest/ManifestTypes" import * as D from "./dependencies" import { ExtractConfigType } from "./builder/config" @@ -13,8 +13,8 @@ export type DependenciesReceipt = void & { export type Save< WD, - A extends Record | Config, any, any>, - Manifest extends GenericManifest, + A extends Record | Config, any>, + Manifest extends SDKManifest, > = (options: { effects: Effects input: ExtractConfigType & Record @@ -23,7 +23,7 @@ export type Save< }) => Promise export type Read< WD, - A extends Record | Config, any, any>, + A extends Record | Config, any>, > = (options: { effects: Effects utils: Utils @@ -37,11 +37,11 @@ export type Read< */ export function setupConfig< WD, - ConfigType extends Record | Config, - Manifest extends GenericManifest, + ConfigType extends Record | Config, + Manifest extends SDKManifest, Type extends Record = ExtractConfigType, >( - spec: Config, + spec: Config, write: Save, read: Read, ) { @@ -68,7 +68,6 @@ export function setupConfig< spec: await spec.build({ effects, utils: myUtils, - config: configValue as Type, }), config: configValue, } diff --git a/lib/inits/migrations/setupMigrations.ts b/lib/inits/migrations/setupMigrations.ts index 1543780..7034eca 100644 --- a/lib/inits/migrations/setupMigrations.ts +++ b/lib/inits/migrations/setupMigrations.ts @@ -1,13 +1,13 @@ import { setupActions } from "../../actions/setupActions" import { EmVer } from "../../emverLite/mod" -import { GenericManifest } from "../../manifest/ManifestTypes" +import { SDKManifest } from "../../manifest/ManifestTypes" import { ExpectedExports } from "../../types" import { once } from "../../util/once" import { Migration } from "./Migration" export class Migrations { private constructor( - readonly manifest: GenericManifest, + readonly manifest: SDKManifest, readonly migrations: Array>, ) {} private sortedMigrations = once(() => { @@ -19,7 +19,7 @@ export class Migrations { }) private currentVersion = once(() => EmVer.parse(this.manifest.version)) static of>>( - manifest: GenericManifest, + manifest: SDKManifest, ...migrations: EnsureUniqueId ) { return new Migrations(manifest, migrations as Array>) @@ -54,7 +54,7 @@ export class Migrations { } export function setupMigrations>>( - manifest: GenericManifest, + manifest: SDKManifest, ...migrations: EnsureUniqueId ) { return Migrations.of(manifest, ...migrations) diff --git a/lib/manifest/ManifestTypes.ts b/lib/manifest/ManifestTypes.ts index 61dc477..97cfb68 100644 --- a/lib/manifest/ManifestTypes.ts +++ b/lib/manifest/ManifestTypes.ts @@ -14,7 +14,7 @@ export interface Container { 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 */ id: string /** A human readable service title */ diff --git a/lib/manifest/setupManifest.ts b/lib/manifest/setupManifest.ts index e8970e5..4dd7ff5 100644 --- a/lib/manifest/setupManifest.ts +++ b/lib/manifest/setupManifest.ts @@ -1,11 +1,11 @@ -import { GenericManifest, ManifestVersion } from "./ManifestTypes" +import { SDKManifest, ManifestVersion } from "./ManifestTypes" export function setupManifest< Id extends string, Version extends ManifestVersion, Dependencies extends Record, Volumes extends Record, - Manifest extends GenericManifest & { + Manifest extends SDKManifest & { dependencies: Dependencies id: Id version: Version diff --git a/lib/test/configBuilder.test.ts b/lib/test/configBuilder.test.ts index cad9e1b..298772a 100644 --- a/lib/test/configBuilder.test.ts +++ b/lib/test/configBuilder.test.ts @@ -303,7 +303,7 @@ describe("values", () => { utils: "utils", } as any test("toggle", async () => { - const value = Value.dynamicToggle<{}, {}>(async () => ({ + const value = Value.dynamicToggle<{}>(async () => ({ name: "Testing", description: null, warning: null, @@ -368,7 +368,7 @@ describe("values", () => { }) }) test("color", async () => { - const value = Value.dynamicColor(async () => ({ + const value = Value.dynamicColor(async () => ({ name: "Testing", required: false, description: null, @@ -387,11 +387,10 @@ describe("values", () => { }) }) test("datetime", async () => { - const value = Value.dynamicDatetime<{ test: "a" }, { test2: 6 }>( - async ({ effects, utils, config }) => { + const value = Value.dynamicDatetime<{ test: "a" }>( + async ({ effects, utils }) => { ;async () => { ;(await utils.getOwnWrapperData("/test").once()) satisfies "a" - config satisfies { test2: 6 } | null } return {