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

aws-event-stream

v1.2.11

Published

A simple and fast EventStore for AWS.

Downloads

29

Readme

aws-event-stream

**This library is based on https://github.com/thiagobustamante/node-eventstore

It is an open source library to create Event Stores that works with AWS using DynamoDB as Provider and SNS to publish messages.

npm version Master Workflow Mutation Tests Workflow Publish Workflow

Motivation

This is an open source library to create Event Stores that works with DynamoDB as persistence providers and SNS notification systems.

The Event Store is a database accompanied by a publication and subscription system. The database stores all the events related to an event stream. The pub / sub system allows other systems or microservices to react to changes in event streams. It is a core component in any event sourcing + CQRS architectures.

Installing

npm install --save aws-event-stream

Usage

Create EventStore

To Create an EventStore you must provide two implementations:

  • A DynamoDBProvider: Responsible for events persistence in the store.
  • A SNSPublisher (Optional): Responsible for notify any process interested in modifications on the store streams.

If there is no publisher provided, the event store will not send any notification.

const awsConfig = { region: 'us-east-1' };

const dynamodbConfig = {
    awsConfig: awsConfig,
    dynamodb: {
        tableName: 'events'
    }
} as Config;

const eventStore = new EventStore(
    new DynamodbProvider(dynamodbConfig),
    new SNSPublisher('arn:sns', awsConfig),
);

DynamodbConfig

The object DynamodbConfig is related to Dynamodb configuration, the possible parameters are:

| Parameter | Description |

| Parameter | Description | | ----------------- | :--------------------------------------------------------------------: | | tableName | The name of the table. | | createTable | True: create the table, False assume that table alreaday exists. | | readCapacityUnit | The total number of read capacity units consumed by the operation. | | writeCapacityUnit | The total number of write capacity units consumed by the operation. | | endpointUrl | An Endpoint object representing the endpoint URL for service requests. | | maxRetries | The maximum amount of retries to attempt with a request. | | httpOptions | A set of options to pass to the low-level HTTP request. | | ttl | Time to Live (TTL) in seconds on the specified table. |

Adding Events

To add Events you need to ask to EventStore a reference to an EventStream. You can add Events passing anything you want as a payload.

const orderStream = eventStore.getEventStream('orders', '123');
await orderStream.addEvent({ data: 'any data', eventType: 'PLACED' });

Reading Events

To read Events you need to ask to EventStore a reference to an EventStream. You can read a stream to receive an ordered list containing all the events in the store.

getEvents()

Returns an array with all events published in the Stream specified.

const orderStream = eventStore.getEventStream('orders', '123');
const events = await orderStream.getEvents();

Example of event from getEvents method:

[
    { 
        'commitTimestamp': 1611206813, 
        'eventType': 'SENT', 
        'payload': {'text': 'EVENT PAYLOAD', 'sequence': 1 }
    },
    { 
        'commitTimestamp': 1611206823, 
        'eventType': 'PLACED', 
        'payload': {'text': 'EVENT PAYLOAD', 'sequence': 2 }
    }
]

Or

Returns an Object with all data from events happened in a Stream. What happens is a merge in all fields from all events, keeping the eventTypes as an array.

The fields which have conflicts will always be considered the last event.

const orderStream = eventStore.getEventStream('orders', '123');
await orderStream.loadFromHistory();

Example of event from loadFromHistory method:

    { 
        'commitTimestamp': 1611206823, 
        'eventTypes': ['SENT', 'PLACED'], 
        'payload': {'text': "EVENT PAYLOAD", 'eventType': 'PLACED'}, 'sequence': 2 
    }

Integration Test

Steps:

  • TMPDIR=/private$TMPDIR docker-compose up
  • npm run test:integration:jest
  • aws dynamodb --endpoint-url=http://localhost:4566 scan --table-name events-now
  • aws sns --endpoint-url=http://localhost:4566 list-topics