mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
fix: The Types for the new config need to be propagated
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
import { Config } from "../config/builder"
|
import { Config } from "../config/builder"
|
||||||
|
import { ExtractConfigType } from "../config/builder/config"
|
||||||
import { ActionMetaData, ActionResult, Effects, ExportedAction } from "../types"
|
import { ActionMetaData, ActionResult, Effects, ExportedAction } from "../types"
|
||||||
import { Utils, utils } from "../util"
|
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(
|
private constructor(
|
||||||
public readonly myMetaData: Omit<ActionMetaData, "input"> & {
|
public readonly myMetaData: Omit<ActionMetaData, "input"> & {
|
||||||
input: Config<Type, WrapperData, never>
|
input: Config<Type, WrapperData, Type>
|
||||||
},
|
},
|
||||||
readonly fn: (options: {
|
readonly fn: (options: {
|
||||||
effects: Effects
|
effects: Effects
|
||||||
@@ -17,14 +22,11 @@ export class CreatedAction<WrapperData, Type extends Record<string, any>> {
|
|||||||
|
|
||||||
static of<
|
static of<
|
||||||
WrapperData,
|
WrapperData,
|
||||||
Input extends Config<Type, WrapperData, never>,
|
ConfigType extends Record<string, any> | Config<any, any, any>,
|
||||||
Type extends Record<string, any> = (Input extends Config<any, infer B, any>
|
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||||
? B
|
|
||||||
: never) &
|
|
||||||
Record<string, any>,
|
|
||||||
>(
|
>(
|
||||||
metaData: Omit<ActionMetaData, "input"> & {
|
metaData: Omit<ActionMetaData, "input"> & {
|
||||||
input: Config<Type, WrapperData, never>
|
input: Config<Type, WrapperData, Type>
|
||||||
},
|
},
|
||||||
fn: (options: {
|
fn: (options: {
|
||||||
effects: Effects
|
effects: Effects
|
||||||
@@ -32,7 +34,7 @@ export class CreatedAction<WrapperData, Type extends Record<string, any>> {
|
|||||||
input: Type
|
input: Type
|
||||||
}) => Promise<ActionResult>,
|
}) => Promise<ActionResult>,
|
||||||
) {
|
) {
|
||||||
return new CreatedAction<WrapperData, Type>(metaData, fn)
|
return new CreatedAction<WrapperData, ConfigType, Type>(metaData, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
exportedAction: ExportedAction = ({ effects, input }) => {
|
exportedAction: ExportedAction = ({ effects, input }) => {
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ export type LazyBuild<WD, ConfigType, ExpectedOut> = (
|
|||||||
options: LazyBuildOptions<WD, ConfigType>,
|
options: LazyBuildOptions<WD, ConfigType>,
|
||||||
) => Promise<ExpectedOut> | ExpectedOut
|
) => 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
|
export type MaybeLazyValues<A> = LazyBuild<any, 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.
|
||||||
|
|||||||
@@ -4,22 +4,30 @@ import { InputSpec } from "./configTypes"
|
|||||||
import { Utils, nullIfEmpty, once, utils } from "../util"
|
import { Utils, nullIfEmpty, once, utils } from "../util"
|
||||||
import { GenericManifest } from "../manifest/ManifestTypes"
|
import { GenericManifest } from "../manifest/ManifestTypes"
|
||||||
import * as D from "./dependencies"
|
import * as D from "./dependencies"
|
||||||
|
import { ExtractConfigType } from "./builder/config"
|
||||||
|
|
||||||
declare const dependencyProof: unique symbol
|
declare const dependencyProof: unique symbol
|
||||||
export type DependenciesReceipt = void & {
|
export type DependenciesReceipt = void & {
|
||||||
[dependencyProof]: never
|
[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
|
effects: Effects
|
||||||
input: A
|
input: ExtractConfigType<A> & Record<string, any>
|
||||||
utils: Utils<WD>
|
utils: Utils<WD>
|
||||||
dependencies: D.Dependencies<Manifest>
|
dependencies: D.Dependencies<Manifest>
|
||||||
}) => Promise<DependenciesReceipt>
|
}) => 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
|
effects: Effects
|
||||||
utils: Utils<WD>
|
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
|
* 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
|
* 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<
|
export function setupConfig<
|
||||||
WD,
|
WD,
|
||||||
Type extends Record<string, any>,
|
ConfigType extends Record<string, any> | Config<any, any, any>,
|
||||||
Manifest extends GenericManifest,
|
Manifest extends GenericManifest,
|
||||||
|
Type extends Record<string, any> = ExtractConfigType<ConfigType>,
|
||||||
>(
|
>(
|
||||||
spec: Config<Type, WD, Type>,
|
spec: Config<Type, WD, Type>,
|
||||||
write: Save<WD, Type, Manifest>,
|
write: Save<WD, Type, Manifest>,
|
||||||
@@ -59,7 +68,7 @@ export function setupConfig<
|
|||||||
spec: await spec.build({
|
spec: await spec.build({
|
||||||
effects,
|
effects,
|
||||||
utils: myUtils,
|
utils: myUtils,
|
||||||
config: configValue,
|
config: configValue as Type,
|
||||||
}),
|
}),
|
||||||
config: configValue,
|
config: configValue,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user