npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jthissen/event-store

v1.0.3

Published

An open-source event store based on Node.js and PostgreSQL. The event store ensures that all changes to an application are stored as a sequence of events. This ultimately allows for the reconstruction of the state at any point throughout its history.

Downloads

2

Readme

Description

An open-source event store based on Node.js and PostgreSQL. The event store ensures that all changes to an application are stored as a sequence of events. This ultimately allows for the reconstruction of the state at any point throughout its history.

Download

Git clone or npm install:

git clone [email protected]:jthissen/event-store.git
npm i @jthissen/event-store

How to use

Create

  1. Make sure docker is up and running and start a postgres container (exposed at localhost:5432). Append adminer if you'd like to run that as well (exposed at localhost:8080).
service docker start
docker-compose up -d db adminer
  1. Create the event store. Pass in the connection data and the name of the event store (optional). Furthermore, specify the name of the snapshot store as well as how often a snapshot should be taken (optional). Snapshotting is an optimization technique that reduces time spent on reading events from an event store. If you have hundreds or thousands of events this may come in handy.
const eventStore = new EventStore()
await eventStore.create({
  host: 'localhost',
  port: '5432',
  dbName: 'postgres',
  user: 'postgres',
  password: 'postgres',
  ssl: false,
}, 'example_event_store', 'example_snapshot_store', 10)
  1. Create a bunch of events. See Event-store/src/tests/event-store.test.ts from line 45 and onwards, e.g.:
const updateCalculationEvent: Event = {
      id: uuid(),
      aggregate: { id: '82c01d88-d9a1-4380-ab03-a662069d8a01', name: 'calculation' },
      name: 'updateCalculationEvent',
      data: { pi: 3.1415, theta: 30, radius: 2 },
      metadata: {
        revision: 1,
        timestamp: (new Date()).getTime(),
        correlationId: 'af358d13-5975-42f5-b3f1-db80761320a2',
        causationId: 'af358d13-5975-42f5-b3f1-db80761320a2',
      }
    }

Where:

  • The revision must be incremented by 1 for every event. Every aggregate should keep track of its own individual revision number.
  • The correlationId is the id of the command that caused the event e.g. command -> event -> command -> event.
  • The causationId is the command that caused a chain e.g. command -> event -> command -> event.

The rest should be self-explanatory.

  1. Save as many events as you'd like. Snapshots are saved automatically after x revisions.
await eventStore.saveEvents(createCalculationEvent, updateCalculationEvent, updateCalculationAgainEvent)
  1. Manually save a snapshot.
await this.saveSnapshot(aggregateId, revision, data);

Read

  1. Get events by their aggregate id.
await eventStore.getEventsById(aggregateId)
  1. Get a snapshot by its aggregate id.
await eventStore.getSnapshotById(aggregateId)
  1. Get the most recent event by its aggregate id.
await eventStore.getLastEventById(aggregateId)
  1. Get all events in a chronologic order. Optionally pass the start revision and the end revision.
await eventStore.getAllEventsChronologically(startRevisionNumber, endRevisionNumber)

Run tests locally

Make sure docker is up and running and start a postgres container (exposed at localhost:5432). Append adminer if you'd like to run that as well (exposed at localhost:8080).

service docker start
docker-compose up -d db adminer

Run the tests.

npm run test

License

Do whatever you want to do.