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-projection-tester

v1.0.7

Published

## What this library is

Downloads

9

Readme

Eventstore projection testing framework

What this library is

This is a testing framework for eventstore projections. This can be used to execute eventstore projections and there are a number of tools to easily get access to the data inside the streams

What this library is not

An in memory version of eventstore. This implements the features of eventstore, but it does not implement it in the same way that eventstore does. Eventstore sees state and a position of a projection in a stream as just another stream, but for simplicity, this library does not do that.

Features included

  • fromStream
  • fromCategory
  • foreachStream

How to use

Adding a projection

const engineResult = await runEventstoreEngine(async (engine: EventstoreEngine) => {
    await engine.addProjection('my_projection', 'fromStream("listings").when({});');
});

Adding an event

const newEventStreamName = 'next_emit_stream';
const newEventType = 'NextEventType';
const myField = 123;
const expectedEvent = {
    data: { newField: 'a value', myField },
    metadata: { metadataField: 3 },
    eventType: newEventType,
    created: 2,
};
const engineResult = await runEventstoreEngine(async (engine: EventstoreEngine) => {
    engine.addEvent('my_stream', 'myEventType', { myField }, null);
});

Testing the results

const newEventStreamName = 'next_emit_stream';
const newEventType = 'NextEventType';
const myField = 123;
const expectedEvent = {
    data: { newField: 'a value', myField },
    metadata: { metadataField: 3 },
    eventType: newEventType,
    created: 2,
};
const engineResult = await runEventstoreEngine(async (engine: EventstoreEngine) => {
    await engine.addProjection(
        'myProjection',
        `fromStream('my_stream').when({
        $init: () => { },
        myEventType: (s, e) => {
            let newData = {newField:'a value', myField:e.data.myField};
          emit('${newEventStreamName}', '${newEventType}', newData, {metadataField:3});
        }
      })`,
    );
    engine.addEvent('my_stream', 'myEventType', { myField }, null);
});
expect(engineResult.getTotalEvents()).toBe(2);
expect(engineResult.getEventsForStream(newEventStreamName)).toEqual([expectedEvent]);

Engine Functionality

| Method | Function | | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------- | | addProjection (projectionName: string, projection: string ) : Promise<void> | Gets the total number of projections in the current engine instance | | addEvent(streamId: string, eventType: string, data: any, metadata: Metadata): void | Adds an event to a stream and executes all projections |

Engine Result functionality

| Method | Function | | ---------------------------------------- | ------------------------------------------------------------------- | | getTotalProjections() | Gets the total number of projections in the current engine instance | | getTotalEvents() | Gets the total number of events in all streams | | getStreamNames() | Gets a list of the stream names | | getEventsForStream(streamName: string) | Gets a list of events for a specific stream name | | getEvents() | Gets a listi og all events on all streams |

Timing

All events in Eventstore have a field called created. This field is used to process events in the correct order. To make this library simpler, the created is treated as a number that increments with each event added or emitted vie emit or linkTo. This way you can calculate the expected value per event.