diff --git a/lib/actions/createAction.ts b/lib/actions/createAction.ts index d72c6d1..ec3b399 100644 --- a/lib/actions/createAction.ts +++ b/lib/actions/createAction.ts @@ -1,11 +1,16 @@ import { Config } from "../config/builder" +import { ExtractConfigType } from "../config/builder/config" import { ActionMetaData, ActionResult, Effects, ExportedAction } from "../types" import { Utils, utils } from "../util" -export class CreatedAction> { +export class CreatedAction< + WrapperData, + ConfigType extends Record | Config, + Type extends Record = ExtractConfigType, +> { private constructor( public readonly myMetaData: Omit & { - input: Config + input: Config }, readonly fn: (options: { effects: Effects @@ -17,14 +22,11 @@ export class CreatedAction> { static of< WrapperData, - Input extends Config, - Type extends Record = (Input extends Config - ? B - : never) & - Record, + ConfigType extends Record | Config, + Type extends Record = ExtractConfigType, >( metaData: Omit & { - input: Config + input: Config }, fn: (options: { effects: Effects @@ -32,7 +34,7 @@ export class CreatedAction> { input: Type }) => Promise, ) { - return new CreatedAction(metaData, fn) + return new CreatedAction(metaData, fn) } exportedAction: ExportedAction = ({ effects, input }) => { diff --git a/lib/config/builder/config.ts b/lib/config/builder/config.ts index 905c2c7..8e5278a 100644 --- a/lib/config/builder/config.ts +++ b/lib/config/builder/config.ts @@ -14,6 +14,11 @@ export type LazyBuild = ( options: LazyBuildOptions, ) => Promise | ExpectedOut +// prettier-ignore +export type ExtractConfigType | Config, any, any>> = + A extends Config ? B : + A + export type MaybeLazyValues = LazyBuild | A /** * Configs are the specs that are used by the os configuration form for this service. diff --git a/lib/config/setupConfig.ts b/lib/config/setupConfig.ts index 42cf321..01c80dc 100644 --- a/lib/config/setupConfig.ts +++ b/lib/config/setupConfig.ts @@ -4,22 +4,30 @@ import { InputSpec } from "./configTypes" import { Utils, nullIfEmpty, once, utils } from "../util" import { GenericManifest } from "../manifest/ManifestTypes" import * as D from "./dependencies" +import { ExtractConfigType } from "./builder/config" declare const dependencyProof: unique symbol export type DependenciesReceipt = void & { [dependencyProof]: never } -export type Save = (options: { +export type Save< + WD, + A extends Record | Config, any, any>, + Manifest extends GenericManifest, +> = (options: { effects: Effects - input: A + input: ExtractConfigType & Record utils: Utils dependencies: D.Dependencies }) => Promise -export type Read = (options: { +export type Read< + WD, + A extends Record | Config, any, any>, +> = (options: { effects: Effects utils: Utils -}) => Promise +}) => Promise & Record)> /** * We want to setup a config export with a get and set, this * is going to be the default helper to setup config, because it will help @@ -29,8 +37,9 @@ export type Read = (options: { */ export function setupConfig< WD, - Type extends Record, + ConfigType extends Record | Config, Manifest extends GenericManifest, + Type extends Record = ExtractConfigType, >( spec: Config, write: Save, @@ -59,7 +68,7 @@ export function setupConfig< spec: await spec.build({ effects, utils: myUtils, - config: configValue, + config: configValue as Type, }), config: configValue, }