/
dimamir
/
medusa
Обзор
Документация
Войти
/
dimamir
/
medusa
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/modules/workflow-engine-inmemory/src/services/workflows-module.ts
155 строк
4 KB
Adrien de Peretti
chore(): Move dependencies around (#9278)
24 сен 2024, 17:58
Не верифицирован
24 сен 2024, 17:58
6937d74
Код
Авторство
О чём код?
import { Context, DAL, InternalModuleDeclaration, MedusaContainer, ModulesSdkTypes, WorkflowsSdkTypes, } from "@medusajs/framework/types" import { InjectSharedContext, MedusaContext, ModulesSdkUtils, } from "@medusajs/framework/utils" import type { ReturnWorkflow, UnwrapWorkflowInputDataType, } from "@medusajs/framework/workflows-sdk" import { WorkflowExecution } from "@models" import { WorkflowOrchestratorService } from "@services" type InjectedDependencies = { baseRepository: DAL.RepositoryService workflowExecutionService: ModulesSdkTypes.IMedusaInternalService<any> workflowOrchestratorService: WorkflowOrchestratorService } export class WorkflowsModuleService< TWorkflowExecution extends WorkflowExecution = WorkflowExecution > extends ModulesSdkUtils.MedusaService<{ WorkflowExecution: { dto: WorkflowExecution } }>({ WorkflowExecution }) { protected baseRepository_: DAL.RepositoryService protected workflowExecutionService_: ModulesSdkTypes.IMedusaInternalService<TWorkflowExecution> protected workflowOrchestratorService_: WorkflowOrchestratorService protected container_: MedusaContainer constructor( { baseRepository, workflowExecutionService, workflowOrchestratorService, }: InjectedDependencies, protected readonly moduleDeclaration: InternalModuleDeclaration ) { // @ts-ignore super(...arguments) this.baseRepository_ = baseRepository this.workflowExecutionService_ = workflowExecutionService this.workflowOrchestratorService_ = workflowOrchestratorService } @InjectSharedContext() async run<TWorkflow extends string | ReturnWorkflow<any, any, any>>( workflowIdOrWorkflow: TWorkflow, options: WorkflowsSdkTypes.WorkflowOrchestratorRunDTO< TWorkflow extends ReturnWorkflow<any, any, any> ? UnwrapWorkflowInputDataType<TWorkflow> : unknown > = {}, @MedusaContext() context: Context = {} ) { const ret = await this.workflowOrchestratorService_.run< TWorkflow extends ReturnWorkflow<any, any, any> ? UnwrapWorkflowInputDataType<TWorkflow> : unknown >(workflowIdOrWorkflow, options, context) return ret as any } @InjectSharedContext() async getRunningTransaction( workflowId: string, transactionId: string, @MedusaContext() context: Context = {} ) { return await this.workflowOrchestratorService_.getRunningTransaction( workflowId, transactionId, context ) } @InjectSharedContext() async setStepSuccess( { idempotencyKey, stepResponse, options, }: { idempotencyKey: string | object stepResponse: unknown options?: Record<string, any> }, @MedusaContext() context: Context = {} ) { return await this.workflowOrchestratorService_.setStepSuccess( { idempotencyKey, stepResponse, options, } as any, context ) } @InjectSharedContext() async setStepFailure( { idempotencyKey, stepResponse, options, }: { idempotencyKey: string | object stepResponse: unknown options?: Record<string, any> }, @MedusaContext() context: Context = {} ) { return await this.workflowOrchestratorService_.setStepFailure( { idempotencyKey, stepResponse, options, } as any, context ) } @InjectSharedContext() async subscribe( args: { workflowId: string transactionId?: string subscriber: Function subscriberId?: string }, @MedusaContext() context: Context = {} ) { return this.workflowOrchestratorService_.subscribe(args as any, context) } @InjectSharedContext() async unsubscribe( args: { workflowId: string transactionId?: string subscriberOrId: string | Function }, @MedusaContext() context: Context = {} ) { return this.workflowOrchestratorService_.unsubscribe(args as any, context) } }