34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import type { Presenter } from '../presentation';
|
|
|
|
/**
|
|
* Use Case interface for commands.
|
|
*
|
|
* Use cases represent application-level business logic. They coordinate domain objects and repositories,
|
|
* but contain no infrastructure or framework concerns.
|
|
*
|
|
* Commands change system state and return nothing on success. They use a presenter to handle the output.
|
|
* If a business rejection is possible, the output may be a Result<void, E> handled by the presenter.
|
|
* Use cases do not throw errors; they use error codes in Result.
|
|
*
|
|
* Example:
|
|
* ```typescript
|
|
* export type CreateRaceError =
|
|
* | 'INSUFFICIENT_PERMISSIONS'
|
|
* | 'RACE_ALREADY_EXISTS'
|
|
* | 'INVALID_RACE_CONFIG';
|
|
*
|
|
* export class CreateRaceUseCase implements UseCase<CreateRaceInput, Result<void, CreateRaceError>, ViewModel, Presenter<Result<void, CreateRaceError>, ViewModel>> {
|
|
* execute(input: CreateRaceInput, presenter: Presenter<Result<void, CreateRaceError>, ViewModel>): Promise<void> {
|
|
* // implementation
|
|
* }
|
|
* }
|
|
* ```
|
|
*
|
|
* @template Input - The input type for the use case
|
|
* @template OutputDTO - The output DTO type, often Result<void, DomainErrorCode>
|
|
* @template ViewModel - The view model type
|
|
* @template P - The presenter type, extending Presenter<OutputDTO, ViewModel>
|
|
*/
|
|
export interface UseCase<Input, OutputDTO, ViewModel, P extends Presenter<OutputDTO, ViewModel>> {
|
|
execute(input: Input, presenter: P): Promise<void> | void;
|
|
} |