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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codeforbreakfast/eventsourcing-store-inmemory

v0.2.14

Published

In-memory event store implementation for development and testing - Fast in-memory storage with complete EventStore interface implementation

Downloads

45

Readme

@codeforbreakfast/eventsourcing-store-inmemory

Fast in-memory event store implementation for development and testing. Provides a complete EventStore interface implementation with blazing-fast performance and zero external dependencies.

Features

  • Lightning Fast: Pure in-memory storage with optimal performance
  • 🧪 Perfect for Testing: Ideal for unit tests and development environments
  • 🔒 Type Safe: Full TypeScript support with Effect-ts integration
  • 🎯 Complete Interface: Implements all EventStore operations (append, read, subscribe)
  • 💪 Concurrency Safe: Proper handling of concurrent operations and version conflicts
  • 🚀 Zero Setup: No external dependencies or configuration required

Installation

bun add @codeforbreakfast/eventsourcing-store-inmemory

Quick Start

import { Effect, Stream, Chunk, pipe } from 'effect';
import {
  InMemoryStore,
  makeInMemoryEventStore,
} from '@codeforbreakfast/eventsourcing-store-inmemory';
import { toStreamId, beginning } from '@codeforbreakfast/eventsourcing-store';

type MyEvent = { type: 'UserCreated'; data: { id: string; name: string } };

const program = pipe(
  InMemoryStore.make<MyEvent>(),
  Effect.flatMap(makeInMemoryEventStore),
  Effect.flatMap((eventStore) =>
    pipe(
      toStreamId('user-123'),
      Effect.flatMap((streamId) =>
        pipe(
          beginning(streamId),
          Effect.flatMap((position) => {
            const events = Chunk.of<MyEvent>({
              type: 'UserCreated',
              data: { id: '123', name: 'John' },
            });
            return pipe(events, Stream.fromChunk, Stream.run(eventStore.append(position)));
          }),
          Effect.flatMap(() => beginning(streamId)),
          Effect.flatMap((position) => eventStore.read(position)),
          Effect.flatMap(Stream.runCollect),
          Effect.tap((events) => Effect.log(events))
        )
      )
    )
  )
);

Effect.runPromise(program);

API Reference

InMemoryStore.make<T>()

Creates a new in-memory store instance.

Returns: Effect<InMemoryStore<T>, never, never>

makeInMemoryEventStore(store)

Creates an EventStore implementation backed by the in-memory store.

Parameters:

  • store: InMemoryStore<T> - The in-memory store instance

Returns: Effect<EventStore<T>, never, never>

EventStore Operations

The returned EventStore implements the complete interface:

  • append(position) - Returns a Sink that appends events to a stream at the given position
  • read(position) - Read historical events from a stream starting at position
  • subscribe(position) - Subscribe to both historical and live events from position

Use Cases

Unit Testing

Perfect for testing your event-sourced aggregates and domain logic:

import { describe, it, expect } from 'bun:test';
import { Effect, pipe } from 'effect';
import {
  InMemoryStore,
  makeInMemoryEventStore,
} from '@codeforbreakfast/eventsourcing-store-inmemory';

describe('UserAggregate', () => {
  it('should create user correctly', async () => {
    const eventStore = await pipe(
      InMemoryStore.make(),
      Effect.flatMap(makeInMemoryEventStore),
      Effect.runPromise
    );

    // Test your aggregate logic here
  });
});

Development Environment

Great for local development when you don't want to set up a full database:

import { Effect, pipe } from 'effect';
import {
  InMemoryStore,
  makeInMemoryEventStore,
} from '@codeforbreakfast/eventsourcing-store-inmemory';

const createDevEventStore = () =>
  pipe(InMemoryStore.make(), Effect.flatMap(makeInMemoryEventStore));

Performance

This implementation is optimized for speed and simplicity:

  • Events stored in plain JavaScript arrays
  • O(1) stream lookups using Map data structures
  • Minimal memory overhead
  • No serialization/deserialization overhead

Thread Safety

The in-memory store handles concurrent operations safely:

  • Proper version checking for optimistic concurrency control
  • Atomic append operations
  • Safe subscription management

Related Packages

License

MIT