UNPKG

@fraktalio/fmodel-ts

Version:

Functional domain modeling with TypeScript. Optimized for event sourcing and CQRS

68 lines (67 loc) 2.55 kB
import { ISaga } from '../domain/saga'; /** * Action publisher interface * * Used by [SagaManager] * * @typeParam A - Action * @typeParam ARM - Action Result Metadata * @typeParam AM - Action Metadata * * @author Иван Дугалић / Ivan Dugalic / @idugalic */ export interface IActionPublisher<A, ARM, AM> { /** * Publish actions * * @param actions - of Actions with Action Result Metadata of type `A & ARM` * @return list of newly published Actions with Action Metadata of type `A & AM` */ readonly publish: (actions: readonly (A & ARM)[]) => Promise<readonly (A & AM)[]>; } /** * Saga manager interface - Stateless process orchestrator. * * It is reacting on Action Results of type `AR` and produces new actions `A` based on them. * * @typeParam AR - Action Result of type `AR` * @typeParam A - Action of type `A` that are going to be published downstream * @typeParam ARM - Action Result metadata * @typeParam AM - Action metadata * * @author Иван Дугалић / Ivan Dugalic / @idugalic */ export interface ISagaManager<AR, A, ARM, AM> extends ISaga<AR, A>, IActionPublisher<A, ARM, AM> { readonly handle: (actionResult: AR & ARM) => Promise<readonly (A & AM)[]>; } /** * Saga manager - Stateless process orchestrator. * * It is reacting on Action Results of type `AR` and produces new actions `A` based on them. * * @typeParam AR - Action Result of type `AR` * @typeParam A - Action of type `A` that are going to be published downstream * @typeParam ARM - Action Result metadata * @typeParam AM - Action metadata * * @author Иван Дугалић / Ivan Dugalic / @idugalic */ export declare class SagaManager<AR, A, ARM, AM> implements ISagaManager<AR, A, ARM, AM> { protected readonly saga: ISaga<AR, A>; protected readonly actionPublisher: IActionPublisher<A, ARM, AM>; /** * * @param saga - A saga component of type `ISaga`<`AR`, `A`> * @param actionPublisher - Interface for Action publishing */ constructor(saga: ISaga<AR, A>, actionPublisher: IActionPublisher<A, ARM, AM>); react(actionResult: AR): readonly A[]; publish(actions: readonly (A & ARM)[]): Promise<readonly (A & AM)[]>; /** * Handles the action result with metadata of type `AR & ARM` * * @param actionResult - Action Result represent the outcome of some action you want to handle in some way * @return list of Actions with Metadata of type `A & AM` */ handle(actionResult: AR & ARM): Promise<readonly (A & AM)[]>; }