InMemoryEventStore
API reference for InMemoryEventStore
Class: InMemoryEventStore
Section titled “Class: InMemoryEventStore”In-memory implementation of EventStore for testing and development
This implementation provides a complete event store that runs entirely in memory, making it perfect for unit tests, integration tests, and development scenarios where you don’t need persistence.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new InMemoryEventStore():
InMemoryEventStore
Returns
Section titled “Returns”InMemoryEventStore
Methods
Section titled “Methods”aggregateStream()
Section titled “aggregateStream()”aggregateStream<
State
,EventType
>(streamId
,options
):Promise
<AggregateStreamResult
<State
>>
Aggregate events from a stream to rebuild state
Type Parameters
Section titled “Type Parameters”State
EventType
Section titled “EventType”EventType
extends Readonly
<{ data
: EventData
; metadata?
: PlatformEventMetadata
; type
: string
; }>
Parameters
Section titled “Parameters”streamId
Section titled “streamId”string
The stream identifier
options
Section titled “options”AggregateStreamOptions
<State
, EventType
>
Aggregation options including initial state and evolution function
Returns
Section titled “Returns”Promise
<AggregateStreamResult
<State
>>
Promise resolving to the aggregated state and stream metadata
Implementation of
Section titled “Implementation of”appendToStream()
Section titled “appendToStream()”appendToStream<
EventType
>(streamId
,events
,options?
):Promise
<AppendToStreamResult
>
Append events to a stream
Type Parameters
Section titled “Type Parameters”EventType
Section titled “EventType”EventType
extends Readonly
<{ data
: EventData
; metadata?
: PlatformEventMetadata
; type
: string
; }> = Readonly
<{ data
: EventData
; metadata?
: PlatformEventMetadata
; type
: string
; }>
Parameters
Section titled “Parameters”streamId
Section titled “streamId”string
The stream identifier
events
Section titled “events”EventType
[]
Events to append
options?
Section titled “options?”Append options including expected version
Returns
Section titled “Returns”Promise
<AppendToStreamResult
>
Promise resolving to the append result
Implementation of
Section titled “Implementation of”clear()
Section titled “clear()”clear():
void
Clear all data (utility method for testing)
Returns
Section titled “Returns”void
getAllEvents()
Section titled “getAllEvents()”getAllEvents():
object
[]
Get all events across all streams (utility method for testing)
Returns
Section titled “Returns”object
[]
Array of all events ordered by global position
getAllStreamIds()
Section titled “getAllStreamIds()”getAllStreamIds():
string
[]
Get all stream IDs (utility method for testing)
Returns
Section titled “Returns”string
[]
Array of all stream identifiers
getTotalEventCount()
Section titled “getTotalEventCount()”getTotalEventCount():
number
Get total event count across all streams (utility method for testing)
Returns
Section titled “Returns”number
Total number of events stored
queryEvents()
Section titled “queryEvents()”queryEvents<
EventType
>(options
):Promise
<QueryEventsResult
<EventType
>>
Query events across all streams with flexible filtering options
Type Parameters
Section titled “Type Parameters”EventType
Section titled “EventType”EventType
extends Readonly
<{ data
: EventData
; metadata?
: PlatformEventMetadata
; type
: string
; }>
Parameters
Section titled “Parameters”options
Section titled “options”QueryEventsOptions
= {}
Query parameters for filtering events
Returns
Section titled “Returns”Promise
<QueryEventsResult
<EventType
>>
Promise resolving to the query result with events and pagination info
Implementation of
Section titled “Implementation of”readStream()
Section titled “readStream()”readStream<
EventType
>(streamId
,options?
):Promise
<ReadStreamResult
<EventType
>>
Read events from a stream with options
Type Parameters
Section titled “Type Parameters”EventType
Section titled “EventType”EventType
extends Readonly
<{ data
: EventData
; metadata?
: PlatformEventMetadata
; type
: string
; }>
Parameters
Section titled “Parameters”streamId
Section titled “streamId”string
The stream identifier
options?
Section titled “options?”Read options for filtering and pagination
Returns
Section titled “Returns”Promise
<ReadStreamResult
<EventType
>>
Promise resolving to read result with events and metadata
Implementation of
Section titled “Implementation of”streamExists()
Section titled “streamExists()”streamExists(
streamId
):Promise
<boolean
>
Check if a stream exists (utility method for testing)
Parameters
Section titled “Parameters”streamId
Section titled “streamId”string
The stream identifier
Returns
Section titled “Returns”Promise
<boolean
>
Promise resolving to boolean indicating existence