UNPKG

@fraktalio/fmodel-ts

Version:

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

48 lines (47 loc) 1.86 kB
/** * `ISaga` represents the central point of control deciding what to execute next `A`. * It is responsible for mapping different events from aggregates into action results `AR` that the `Saga` then can use to calculate the next actions `A` to be mapped to command of other aggregates. * * @typeParam AR - Action Result type * @typeParam A - Action type * * @author Иван Дугалић / Ivan Dugalic / @idugalic */ export interface ISaga<AR, A> { readonly react: (actionResult: AR) => readonly A[]; } /** * `Saga` is a datatype that represents the central point of control deciding what to execute next `A`. * It is responsible for mapping different events from aggregates into action results `AR` that the `Saga` then can use to calculate the next actions `A` to be mapped to command of other aggregates. * * @typeParam AR - Action Result type * @typeParam A - Action type * * @author Иван Дугалић / Ivan Dugalic / @idugalic */ export declare class Saga<AR, A> implements ISaga<AR, A> { readonly react: (actionResult: AR) => readonly A[]; /** * @constructor Creates `Saga` * @param react - A function/lambda that takes input state of type `AR`, and returns the list of actions `A[]`>. */ constructor(react: (actionResult: AR) => readonly A[]); /** * Left map on `AR`/ActionResult parameter - Contravariant * * @typeParam ARn - New Action Result */ mapContraOnActionResult<ARn>(f: (arn: ARn) => AR): Saga<ARn, A>; /** * Right map on `A`/Action parameter - Covariant * * @typeParam An - New Action */ mapOnAction<An>(f: (a: A) => An): Saga<AR, An>; /** * Combines two choreography sagas into one orchestrating Saga * * @param saga2 - second Saga */ combine<AR2, A2>(saga2: Saga<AR2, A2>): Saga<AR | AR2, A | A2>; }