fix: hooks auto-generated types to have precise input options (#11886)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/workflows-sdk": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: hooks auto-generated types to have precise input options
|
||||||
@@ -4,7 +4,10 @@ import { WorkflowData, WorkflowDataProperties } from "../type"
|
|||||||
/**
|
/**
|
||||||
* Workflow response class encapsulates the return value of a workflow
|
* Workflow response class encapsulates the return value of a workflow
|
||||||
*/
|
*/
|
||||||
export class WorkflowResponse<TResult, THooks = []> {
|
export class WorkflowResponse<
|
||||||
|
TResult,
|
||||||
|
const THooks extends readonly unknown[] = []
|
||||||
|
> {
|
||||||
__type: typeof OrchestrationUtils.SymbolMedusaWorkflowResponse =
|
__type: typeof OrchestrationUtils.SymbolMedusaWorkflowResponse =
|
||||||
OrchestrationUtils.SymbolMedusaWorkflowResponse
|
OrchestrationUtils.SymbolMedusaWorkflowResponse
|
||||||
|
|
||||||
|
|||||||
@@ -27,19 +27,24 @@ export type StepFunctionReturnConfig<TOutput> = {
|
|||||||
type KeysOfUnion<T> = T extends T ? keyof T : never
|
type KeysOfUnion<T> = T extends T ? keyof T : never
|
||||||
export type HookHandler = (...args: any[]) => void | Promise<void>
|
export type HookHandler = (...args: any[]) => void | Promise<void>
|
||||||
|
|
||||||
|
type ConvertHookToObject<THook> = THook extends Hook<infer Name, infer Input>
|
||||||
|
? {
|
||||||
|
[K in Name]: <TOutput, TCompensateInput>(
|
||||||
|
invoke: InvokeFn<Input, TOutput, TCompensateInput>,
|
||||||
|
compensate?: CompensateFn<TCompensateInput>
|
||||||
|
) => void
|
||||||
|
}
|
||||||
|
: never
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to convert an array of hooks to functions
|
* Helper to convert an array of hooks to functions
|
||||||
*/
|
*/
|
||||||
type ConvertHooksToFunctions<THooks extends any[]> = {
|
type ConvertHooksToFunctions<THooks extends any[]> = THooks extends [
|
||||||
[K in keyof THooks]: THooks[K] extends Hook<infer Name, infer Input>
|
infer A,
|
||||||
? {
|
...infer R
|
||||||
[Fn in Name]: <TOutput, TCompensateInput>(
|
]
|
||||||
invoke: InvokeFn<Input, TOutput, TCompensateInput>,
|
? ConvertHookToObject<A> & ConvertHooksToFunctions<R>
|
||||||
compensate?: CompensateFn<TCompensateInput>
|
: {}
|
||||||
) => void
|
|
||||||
}
|
|
||||||
: never
|
|
||||||
}[number]
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A step function to be used in a workflow.
|
* A step function to be used in a workflow.
|
||||||
|
|||||||
Reference in New Issue
Block a user