import { UseCaseExecutor , UseCaseExecutorImpl } from "./UseCaseExecutor" ; import { isUseCaseFunction , UseCaseFunction } from "./FunctionalUseCaseContext" ; import { FunctionalUseCase } from "./FunctionalUseCase" ; import { isUseCase , UseCase } from "./UseCase" ; import { Dispatcher } from "./Dispatcher" ; import { assertOK } from "./util/assert" ; export function createUseCaseExecutor ( useCase , dispatcher ) ; export function createUseCaseExecutor < T extends UseCase > ( useCase , dispatcher ) ; export function createUseCaseExecutor ( useCase , dispatcher ) { if ( isUseCase ( useCase ) ) { return new UseCaseExecutorImpl ( { useCase , parent : isUseCase ( dispatcher ) ? dispatcher : null } ) ; } else if ( isUseCaseFunction ( useCase ) ) { assertOK ( Object . getPrototypeOf && Object . getPrototypeOf ( useCase ) !== UseCase , `Context#useCase argument should be instance of UseCase.
The argument is UseCase constructor itself: ${ useCase }` ) ; const functionalUseCase = new FunctionalUseCase ( useCase ) ; return new UseCaseExecutorImpl ( { useCase : functionalUseCase , parent : isUseCase ( dispatcher ) ? dispatcher : null } ) ; } throw new Error ( `Context#useCase argument should be UseCase: ${ useCase }` ) ; }