terski / snp-event-stream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SNP Event Stream Example

This example shows a simple POC for implementing subscriptions using event sourcing.

Highlights

Test script output

*** Aggregates
[
  {
    "id": "cjyhpzwdr0000nirty2oabq4u",
    "createdAt": "2019-07-24T20:48:27.565Z",
    "type": "subscription",
    "events": [
      {
        "id": "cjyhpzwe00001nirtywhfuup3",
        "createdAt": "2019-07-24T20:48:27.576Z",
        "type": "create",
        "data": "{\"planId\":\"monthly\",\"startedAt\":\"2019-07-24T20:48:27.456Z\",\"expiresAt\":\"2019-08-23T20:48:27.456Z\"}"
      },
      {
        "id": "cjyhpzwei0003nirto8rbs1ik",
        "createdAt": "2019-07-24T20:48:27.594Z",
        "type": "cancel",
        "data": "{\"cancelledAt\":\"2019-08-03T20:48:27.591Z\"}"
      }
    ]
  }
]
*** Latest snapshot
{
  id: 'cjyhpzwer0004nirt9dblp5fo',
  createdAt: '2019-07-24T20:48:27.603Z',
  aggregateId: 'cjyhpzwdr0000nirty2oabq4u',
  startedAt: '2019-07-24T20:48:27.456Z',
  planId: 'monthly',
  cancelledAt: '2019-08-03T20:48:27.591Z',
  expiresAt: '2019-08-23T20:48:27.456Z'
}

About


Languages

Language:TypeScript 100.0%