/** * A stateful persistent object that represents the state of the pipeline. */ interface StatefulPipelineEntity { state: S; } /** * Saves the state of a pipeline. */ interface StateRepository { update(entity: T, ctx: C): Promise; } /** * An object to be passed as context to all handlers. */ type HandlerContext = unknown; /** * A pipeline state handler. Operates on the current entity state and returns it. * Although it might work just fine, a handler is not expected to modify the pipeline state, not via the entity and not by accessing a repository directly. */ interface Handler { handle(entity: T, ctx: C): Promise; } type OnErrorHandler = (error: Error, entity: T, ctx: C) => Promise; type OnBeforeHandler = (entity: T, ctx: C) => Promise; type OnAfterHandler = (entity: T, ctx: C) => Promise; export { StatefulPipelineEntity, Handler, OnErrorHandler, OnBeforeHandler, OnAfterHandler, HandlerContext, StateRepository };