Negligent Parachute Maintainers

npm

Bring the best of OSS JavaScript development to your projects with npm Orgs - private packages & team management tools.Learn more »

resolve-es

0.20.7 • Public • Published

resolve-es

npm version

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

Usage

When initializing an event store, pass the following arguments:

storage

Use a reSolve framework adapter

publishEvent

The hook function after calling "eventStore.saveEvent"

Example

// Import and initializtion
import createEventStore from 'resolve-es'
import createInFileStorageAdapter from 'resolve-storage-lite'
 
const storage = createInFileStorageAdapter({ databaseFile: './data/event-store.db' })
 
const publishEvent = async (event) => {
  console.log(event) // Send event to subscribers
} 
 
const eventStore = createEventStore({
  storage,
  publishEvent
})
 
// Load events
const eventHandler = async event => {
  console.log('Event from eventstore', event)
  // Event store is waiting for event processing so overflow will not occur
  await processEvent(event)
}
 
const eventFilter = {
  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 beginning of time
  finishTime: Date.now() + 10000 // Or null to load events to current time
}
 
await eventStore.loadEvents(eventFilter, eventHandler)
 
const latestEvent = await getLatestEvent()
 
// Save event
const event = {
  aggregateId: '1',
  aggregateVersion: 2,
  type: 'UserCreated',
  payload: {
    email: 'test@user.com'
  }
}
 
await eventStore.saveEvent(event)

Analytics

install

npm i resolve-es

Downloadsweekly downloads

934

version

0.20.7

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability