This commit is contained in:
2025-12-16 21:05:01 +01:00
parent f61e3a4e5a
commit 7532c7ed6d
207 changed files with 7861 additions and 2606 deletions

View File

@@ -1,4 +1,6 @@
import type { Presenter } from '../presentation';
import type { Result } from './Result';
import type { ApplicationErrorCode } from '../errors/ApplicationErrorCode';
/**
* Use Case interface for commands.
@@ -7,28 +9,29 @@ import type { Presenter } from '../presentation';
* 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.
* If a business rejection is possible, the output must be a Result<T, ApplicationErrorCode<E>> handled by the presenter.
* Use cases do not throw errors; they use error codes in Result.
*
* Example:
* ```typescript
* export type CreateRaceError =
* export type CreateRaceErrorCode =
* | '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> {
* export class CreateRaceUseCase implements UseCase<CreateRaceInput, void, CreateRaceErrorCode, ViewModel, Presenter<Result<void, ApplicationErrorCode<CreateRaceErrorCode>>, ViewModel>> {
* execute(input: CreateRaceInput, presenter: Presenter<Result<void, ApplicationErrorCode<CreateRaceErrorCode>>, ViewModel>): Promise<void> {
* // implementation
* }
* }
* ```
*
* @template Input - The input type for the use case
* @template OutputDTO - The output DTO type, often Result<void, DomainErrorCode>
* @template Success - The success type in the Result passed to the presenter
* @template ErrorCode - The error code type for ApplicationErrorCode
* @template ViewModel - The view model type
* @template P - The presenter type, extending Presenter<OutputDTO, ViewModel>
* @template P - The presenter type, extending Presenter<Result<Success, ApplicationErrorCode<ErrorCode>>, ViewModel>
*/
export interface UseCase<Input, OutputDTO, ViewModel, P extends Presenter<OutputDTO, ViewModel>> {
export interface UseCase<Input, Success, ErrorCode extends string, ViewModel, P extends Presenter<Result<Success, ApplicationErrorCode<ErrorCode>>, ViewModel>> {
execute(input: Input, presenter: P): Promise<void> | void;
}