API for accessing event stores
npm install @acuris/eventstore-apiBased on
- https://github.com/tim-group/tg-eventstore (Java)
- https://github.com/araqnid/eventstore (Kotlin)
Reading a stream:
``typescript`
async function listTransactionHistory(transactionId: string, eventSource: EventSource): Promise<{timestamp: Date, data: Transaction}> {
return lastValueFrom(
eventSource.streamReader.readStreamForwards({category: "transaction", id: transactionId})
.pipe(toArray(), map(re => ({timestamp: re.event.timestamp, data: re.event.data as Transaction})))
)
}
Reading entire store:
`typescript`
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)
)
}))
for formatting so that we have a consistent code style.If you are using IntelliJ then install the Prettier plugin. You can config it to run when you normally run format (see
Languages & Frameworks > Javascript > Prettier` and check "Run on 'Reformat Code' action")