@acuris/eventstore-api 中文文档教程

发布于 3 年前 浏览 16 项目主页 更新于 2 年前

Eventstore API

基于

  • https://github.com/tim-group/tg-eventstore (Java)
  • https://github.com/araqnid/eventstore (Kotlin)

Usage

阅读流:

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})))
  )
}

阅读整个商店:

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)
    )
}))

Eventstore API

Based on

  • https://github.com/tim-group/tg-eventstore (Java)
  • https://github.com/araqnid/eventstore (Kotlin)

Usage

Reading a stream:

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:

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)
    )
}))
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文