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

eventstore-objects

v1.1.9

Published

A convenient way to handle events sourcing with EventStore DB

Downloads

8

Readme

#EventStore objects

EARLY ALPHA STAGE, DON'T USE IT IN PRODUCTION!

A convenient way to handle events sourcing with EventStore DB.

Store your aggregate events and load the aggregate as a complete object.

Snapshot function included.

Install

npm install --save eventstore-objects

How it works

This modules saves events to a EventStore stream with a given id (string). If the stream doesn't exist, it is automatically created. It also creates snapshots automatically (lazily, on aggregate read) at a given and configurable interval of events. The snapshots are stored as a stream with the main events id plus a configurable suffix (default is '__snapshot').

Aggregates can be retrieved at any point of their history with no effort.

It is important to note that eventstore-objects doesn't use any specific eventType or information overhead when writing to EventStore, so you will be able to use other tools and to read, 'projecting' and understand your streams in many ways without be locked-in.

Eventstore-objects can achieve this by separating (in your configs) the available events into 2 groups: 'set' and 'del'. The 'set' type adds the properties to the aggregate when it is loaded from the events stream, while the 'del' type removes the properties from it. This configuration will only be used on read, without affecting you data or your domain.

Additionally, you can customize the snapshot event, which is the eventType of every snapshot creation, in its separate stream.

How to use

Configuration


var configs = {
  host: "localhost",
  port: 1113,
  credentials: {
      username: "admin",
      password: "changeit"
  },
  debug: false,
  events: {
    // events group: set
    set: ['userCreate', 'userSetName', 'userSetProp'], // as many as you wish
    // events group: del (delete)
    del: ['userDelProp'], // as many as you wish
    snapshot: 'userSnapshot'
  },
  maxEventsBetweenSnapshots: 500,
  snapshotSuffix: '__snapshot'
}
var eventStoreObjects = require('eventstore-objects')(configs);

Write


eventStoreObjects.append('myStreamId', 'myEvent', { my:'data' }, function(error) {
  // do some callback actions
});

Read

Track reads

When a stream is read, you can record it as an event, if you wish to track it.


var readEventName = 'myReadEvent'; // optionally add an event to track reads. Set as null to ignore.
var readEventData = {user_id: 123}; // the data for the read event. Set as null to ignore

Get latest version of the aggregate (head)

By default, the stream is always returned in its latest version.


eventStoreObjects.read('myStreamId', null, null, readEventName, readEventData, function(err, result) {
  if(err){
    console.log(err);
  }
  if (!result) {
    console.log('Object not found!');
  } else {
    console.log(result);
  }
});

The second argument can be set as 'head' too, if you want to be more explicit in your intent:


eventStoreObjects.read('myStreamId', 'head', null, readEventName, readEventData, function(err, result) {
  if(err){
    console.log(err);
  }
  if (!result) {
    console.log('Object not found!');
  } else {
    console.log(result);
  }
});

Get a specific version of the aggregate (by event number)

If you want to read the aggregate as it was at the event 42, just do:


eventStoreObjects.read('myStreamId', 'at', 42, readEventName, readEventData, function(err, result) {
  if(err){
    console.log(err);
  }
  if (!result) {
    console.log('Object not found!');
  } else {
    console.log(result);
  }
});

Disconnect


eventStoreObjects.disconnect();

Connect


eventStoreObjects.connect();