fix: The Types for the new config need to be propagated

This commit is contained in:
BluJ
2023-05-02 09:14:46 -06:00
parent 839170d73f
commit 529a48afb1
3 changed files with 31 additions and 15 deletions

View File

@@ -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<WrapperData, Type extends Record<string, any>> {
export class CreatedAction<
WrapperData,
ConfigType extends Record<string, any> | Config<any, any, any>,
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
> {
private constructor(
public readonly myMetaData: Omit<ActionMetaData, "input"> & {
input: Config<Type, WrapperData, never>
input: Config<Type, WrapperData, Type>
},
readonly fn: (options: {
effects: Effects
@@ -17,14 +22,11 @@ export class CreatedAction<WrapperData, Type extends Record<string, any>> {
static of<
WrapperData,
Input extends Config<Type, WrapperData, never>,
Type extends Record<string, any> = (Input extends Config<any, infer B, any>
? B
: never) &
Record<string, any>,
ConfigType extends Record<string, any> | Config<any, any, any>,
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
>(
metaData: Omit<ActionMetaData, "input"> & {
input: Config<Type, WrapperData, never>
input: Config<Type, WrapperData, Type>
},
fn: (options: {
effects: Effects
@@ -32,7 +34,7 @@ export class CreatedAction<WrapperData, Type extends Record<string, any>> {
input: Type
}) => Promise<ActionResult>,
) {
return new CreatedAction<WrapperData, Type>(metaData, fn)
return new CreatedAction<WrapperData, ConfigType, Type>(metaData, fn)
}
exportedAction: ExportedAction = ({ effects, input }) => {

View File

@@ -14,6 +14,11 @@ export type LazyBuild<WD, ConfigType, ExpectedOut> = (
options: LazyBuildOptions<WD, ConfigType>,
) => Promise<ExpectedOut> | ExpectedOut
// prettier-ignore
export type ExtractConfigType<A extends Record<string, any> | Config<Record<string, any>, any, any>> =
A extends Config<infer B, any, any> ? B :
A
export type MaybeLazyValues<A> = LazyBuild<any, any, A> | A
/**
* Configs are the specs that are used by the os configuration form for this service.

View File

@@ -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<WD, A, Manifest extends GenericManifest> = (options: {
export type Save<
WD,
A extends Record<string, any> | Config<Record<string, any>, any, any>,
Manifest extends GenericManifest,
> = (options: {
effects: Effects
input: A
input: ExtractConfigType<A> & Record<string, any>
utils: Utils<WD>
dependencies: D.Dependencies<Manifest>
}) => Promise<DependenciesReceipt>
export type Read<WD, A> = (options: {
export type Read<
WD,
A extends Record<string, any> | Config<Record<string, any>, any, any>,
> = (options: {
effects: Effects
utils: Utils<WD>
}) => Promise<void | A>
}) => Promise<void | (ExtractConfigType<A> & Record<string, any>)>
/**
* 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<WD, A> = (options: {
*/
export function setupConfig<
WD,
Type extends Record<string, any>,
ConfigType extends Record<string, any> | Config<any, any, any>,
Manifest extends GenericManifest,
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
>(
spec: Config<Type, WD, Type>,
write: Save<WD, Type, Manifest>,
@@ -59,7 +68,7 @@ export function setupConfig<
spec: await spec.build({
effects,
utils: myUtils,
config: configValue,
config: configValue as Type,
}),
config: configValue,
}