feat: loosely typed container

This commit is contained in:
Harminder Virk
2024-05-31 15:22:03 +05:30
committed by GitHub
parent 2d956931b3
commit 11528526fa
41 changed files with 255 additions and 114 deletions

View File

@@ -1,6 +1,4 @@
export * from "./helper"
export * from "./medusa-workflow"
export * as WorkflowOrchestratorTypes from "./types"
export { IWorkflowEngineService } from "./types/service"
export * from "./utils/composer"
export * as Composer from "./utils/composer"

View File

@@ -1,21 +0,0 @@
import { BaseFilterable, OperatorMap } from "@medusajs/types"
export interface WorkflowExecutionDTO {
id: string
workflow_id: string
transaction_id: string
execution: string
context: string
state: any
created_at: Date
updated_at: Date
deleted_at: Date
}
export interface FilterableWorkflowExecutionProps
extends BaseFilterable<FilterableWorkflowExecutionProps> {
id?: string | string[] | OperatorMap<string>
workflow_id?: string | string[] | OperatorMap<string>
transaction_id?: string | string[] | OperatorMap<string>
state?: string | string[] | OperatorMap<string>
}

View File

@@ -1,3 +0,0 @@
export * from "./common"
export * from "./mutations"
export * from "./service"

View File

@@ -1,7 +0,0 @@
export interface UpsertWorkflowExecutionDTO {
workflow_id: string
transaction_id: string
execution: Record<string, unknown>
context: Record<string, unknown>
state: any
}

View File

@@ -1,127 +0,0 @@
import {
ContainerLike,
Context,
FindConfig,
IModuleService,
} from "@medusajs/types"
import { ReturnWorkflow, UnwrapWorkflowInputDataType } from "../utils/composer"
import {
FilterableWorkflowExecutionProps,
WorkflowExecutionDTO,
} from "./common"
type FlowRunOptions<TData = unknown> = {
input?: TData
context?: Context
resultFrom?: string | string[] | Symbol
throwOnError?: boolean
events?: Record<string, Function>
}
export interface WorkflowOrchestratorRunDTO<T = unknown>
extends FlowRunOptions<T> {
transactionId?: string
container?: ContainerLike
}
export type IdempotencyKeyParts = {
workflowId: string
transactionId: string
stepId: string
action: "invoke" | "compensate"
}
export interface IWorkflowEngineService extends IModuleService {
retrieveWorkflowExecution(
idOrObject:
| string
| {
workflow_id: string
transaction_id: string
},
config?: FindConfig<WorkflowExecutionDTO>,
sharedContext?: Context
): Promise<WorkflowExecutionDTO>
listWorkflowExecution(
filters?: FilterableWorkflowExecutionProps,
config?: FindConfig<WorkflowExecutionDTO>,
sharedContext?: Context
): Promise<WorkflowExecutionDTO[]>
listAndCountWorkflowExecution(
filters?: FilterableWorkflowExecutionProps,
config?: FindConfig<WorkflowExecutionDTO>,
sharedContext?: Context
): Promise<[WorkflowExecutionDTO[], number]>
run<
TWorkflow extends ReturnWorkflow<any, any, any> = ReturnWorkflow<
any,
any,
any
>,
TData = UnwrapWorkflowInputDataType<TWorkflow>
>(
workflowId: string,
options?: WorkflowOrchestratorRunDTO,
sharedContext?: Context
): Promise<{
errors: Error[]
transaction: object
result: any
acknowledgement: object
}>
getRunningTransaction(
workflowId: string,
transactionId: string,
options?: Record<string, any>,
sharedContext?: Context
): Promise<unknown>
setStepSuccess(
{
idempotencyKey,
stepResponse,
options,
}: {
idempotencyKey: string | IdempotencyKeyParts
stepResponse: unknown
options?: Record<string, any>
},
sharedContext?: Context
)
setStepFailure(
{
idempotencyKey,
stepResponse,
options,
}: {
idempotencyKey: string | IdempotencyKeyParts
stepResponse: unknown
options?: Record<string, any>
},
sharedContext?: Context
)
subscribe(
args: {
workflowId: string
transactionId?: string
subscriber: Function
subscriberId?: string
},
sharedContext?: Context
): Promise<void>
unsubscribe(
args: {
workflowId: string
transactionId?: string
subscriberOrId: string | Function
},
sharedContext?: Context
)
}