Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

resolve-es

0.19.8 • Public • Published

resolve-es

npm version

Provides an event store implementation with the capability to use different storage and bus adapters to store and emit events.

Usage

When initializing an event store, pass the following arguments:

storage

Use a reSolve framework adapter

bus

Use a reSolve framework adapter

Example

// Import and initializtion
import createEventStore from 'resolve-es'
import createInFileStorageAdapter from 'resolve-storage-lite'
import createInMemoryBusAdapter from 'resolve-bus-memory'
 
const eventStore = createEventStore({
  storage: createInFileStorageAdapter({ pathToFile: './event-store.db' }),
  bus: createInMemoryBusAdapter()
})
 
// Load events
const eventHandler = async event => {
  console.log('Event from eventstore', event)
  // Eventstore is waiting for event processing so overflow will not occur
  await processEvent(event)
}
 
const eventFilter = {
  skipStorage: false, // Or true to skip event loading from storage
  skipBus: false, // Or true to skip bus subscription
  eventTypes: ['EVENT_TYPE_1', 'EVENT_TYPE_2'], // Or null to load ALL event types
  aggregateIds: ['AGGREGATE_ID_1', 'AGGREGATE_ID_2'], // Or null to load ALL aggregate ids
  startTime: Date.now() - 10000, // Or null to load events from beginnig of time
  finishTime: Date.now() + 10000 // Or null to load events to current time
}
 
const unsubscribe = await eventStore.loadEvents(eventFilter, eventHandler)
 
await unsubscribe() // Or do nothing if skipBus: true
 
// Save event
const event = {
  aggregateId: '1',
  aggregateVersion: 2,
  type: 'UserCreated',
  payload: {
    email: 'test@user.com'
  }
}
 
eventStore.saveEvent(event)

Analytics

install

npm i resolve-es

Downloadsweekly downloads

153

version

0.19.8

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability