API reference / @node-ts/bus-core / InMemoryPersistence
Class: InMemoryPersistence
Defined in: packages/bus-core/src/workflow/persistence/in-memory-persistence.ts:21
A non-durable in-memory persistence for storage and retrieval of workflow state. Before using this, be warned that all workflow state will not survive a process restart or application shut down. As such this should only be used for testing, prototyping or handling unimportant workflows.
Implements
Constructors
Constructor
new InMemoryPersistence(): InMemoryPersistence;Returns
InMemoryPersistence
Methods
getWorkflowState()
getWorkflowState<WorkflowStateType, MessageType>(
workflowStateConstructor,
messageMap,
message,
attributes,
includeCompleted?
): Promise<WorkflowStateType[]>;Defined in: packages/bus-core/src/workflow/persistence/in-memory-persistence.ts:39
Retrieves all workflow state models that match the given messageMap criteria
Type Parameters
| Type Parameter |
|---|
WorkflowStateType extends WorkflowState |
MessageType extends Message |
Parameters
| Parameter | Type | Description |
|---|---|---|
workflowStateConstructor | ClassConstructor<WorkflowStateType> | The workflow model type to retrieve |
messageMap | MessageWorkflowMapping<MessageType, WorkflowStateType> | How the message is mapped to workflow state models |
message | MessageType | The message to map to workflow state |
attributes | MessageAttributes | - |
includeCompleted? | boolean | If completed workflow state items should also be returned. False by default |
Returns
Promise<WorkflowStateType[]>
the matching workflow state as it was saved. The bus restores its classes, so it doesn't need to be converted.
Implementation of
initializeWorkflow()
initializeWorkflow<TWorkflowState>(workflowStateConstructor, _): Promise<void>;Defined in: packages/bus-core/src/workflow/persistence/in-memory-persistence.ts:31
Allows the persistence implementation to set up its internal structure to support the workflow state that it will be persisting. Typically for a database this could mean setting up the internal table schema to support persisting of each of the workflow state models.
Type Parameters
| Type Parameter |
|---|
TWorkflowState extends WorkflowState |
Parameters
| Parameter | Type |
|---|---|
workflowStateConstructor | ClassConstructor<TWorkflowState> |
_ | MessageWorkflowMapping<Message, WorkflowState>[] |
Returns
Promise<void>
Implementation of
Persistence.initializeWorkflow
length()
length(workflowStateConstructor): number;Defined in: packages/bus-core/src/workflow/persistence/in-memory-persistence.ts:122
Gets the number of workflow states held in memory for a workflow state type
Parameters
| Parameter | Type | Description |
|---|---|---|
workflowStateConstructor | ClassConstructor<WorkflowState> | the type of workflow state to count |
Returns
number
the number of workflow states held, including completed ones
Throws
WorkflowStateNotInitialized if the workflow state hasn't been initialized
prepare()
prepare(coreDependencies): void;Defined in: packages/bus-core/src/workflow/persistence/in-memory-persistence.ts:25
An optional function that is called before startup that will provide core dependencies to the persistence. This can be used to fetch loggers etc that are used in initialization steps. A persistence shared by several buses is prepared by each of them.
Parameters
| Parameter | Type | Description |
|---|---|---|
coreDependencies | CoreDependencies | the dependencies of the bus that's preparing the persistence |
Returns
void
Implementation of
saveWorkflowState()
saveWorkflowState<WorkflowStateType>(workflowState): Promise<void>;Defined in: packages/bus-core/src/workflow/persistence/in-memory-persistence.ts:78
Saves a copy of the workflow state with its $version incremented. The $version of the state being saved must match the version held in memory, in the same way as durable persistence adapters enforce optimistic concurrency.
Type Parameters
| Type Parameter |
|---|
WorkflowStateType extends WorkflowState |
Parameters
| Parameter | Type | Description |
|---|---|---|
workflowState | WorkflowStateType | the workflow state to save |
Returns
Promise<void>
Throws
WorkflowStateNotInitialized if the workflow state hasn't been initialized
Throws
WorkflowStateVersionConflict if the workflow state was saved elsewhere since it was read