Neoplastic Plasma Medusa

    resolve-es

    0.23.2 • 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 createStorageLiteAdapter from 'resolve-storage-lite'
     
    const storage = createStorageLiteAdapter({ 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)
      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

    145

    Version

    0.23.2

    License

    MIT

    Unpacked Size

    7.42 kB

    Total Files

    6

    Last publish

    Collaborators

    • resolve-admin
    • reimagined-admin
    • vladihost
    • lykoi18