@acuris/eventstore-api

API for accessing event stores

Usage no npm install needed!

<script type="module">
  import acurisEventstoreApi from 'https://cdn.skypack.dev/@acuris/eventstore-api';
</script>

README

Eventstore API

Based on

Usage

Reading a stream:

async function listTransactionHistory(transactionId: string, eventSource: EventSource): Promise<{timestamp: Date, data: Transaction}> {
  return eventSource.streamReader.readStreamForwards({category: "transaction", id: transactionId})
    .pipe(toArray(), map(re => ({timestamp: re.event.timestamp, data: re.event.data as Transaction})))
    .toPromise()
}

Reading entire store:

return new Promise(((resolve, reject) => {
    let lastPosition = position
    eventSource.storeReader.readAll(position).subscribe(
      re => {
        ingestTransaction(re.event.data as Transaction)
        lastPosition = re.position
      },
      err => reject("Failed to read all transactions since " + lastPosition + ": " + err),
      () => resolve(lastPosition)
    )
}))