New: Introducing PHP and Composer Support.Read the Announcement
Socket
Book a DemoInstallSign in
Socket

@vendit-dev/event-store

Package Overview
Dependencies
Maintainers
7
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vendit-dev/event-store

Modern Node.js event store supporting multiple databases for CQRS and Event Sourcing patterns

alpha
Source
npmnpm
Version
2.0.0-alpha.1
Version published
Weekly downloads
13
-48%
Maintainers
7
Weekly downloads
 
Created
Source

@vendit-dev/event-store

npm version TypeScript Node.js License: MIT

A modern, TypeScript-first event store for Node.js supporting multiple databases. Perfect for implementing CQRS (Command Query Responsibility Segregation) and Event Sourcing patterns.

✨ Features

  • 🚀 Modern: Built with TypeScript, ESM modules, and async/await
  • 🔧 Multi-Database: MongoDB, Redis, DynamoDB, Elasticsearch, Azure Table, In-Memory
  • 📦 Zero Dependencies: Minimal core with optional peer dependencies
  • 🎯 Type Safe: Full TypeScript support with strict typing
  • High Performance: Optimized for high-throughput scenarios
  • 🧪 Well Tested: Comprehensive test suite with 90%+ coverage
  • 🔒 Production Ready: Used in production environments

🚀 Quick Start

Installation

npm install @vendit-dev/event-store

# Install database-specific drivers as needed
npm install mongodb         # For MongoDB
npm install redis           # For Redis
npm install @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb  # For DynamoDB
npm install @elastic/elasticsearch  # For Elasticsearch
npm install @azure/data-tables      # For Azure Tables

Basic Usage

import { createEventStore } from '@vendit-dev/event-store';

// Create event store with MongoDB
const eventStore = createEventStore({
  type: 'mongodb',
  options: {
    url: 'mongodb://localhost:27017',
    database: 'eventstore'
  }
});

// Initialize connection
await eventStore.init();

// Get event stream for an aggregate
const stream = await eventStore.getEventStream({ aggregateId: 'user-123' });

// Add events to the stream
stream.addEvent({
  aggregateId: 'user-123',
  payload: { type: 'UserCreated', name: 'John Doe', email: 'john@example.com' }
});

// Commit events
await stream.commit();

📚 Documentation

Event Store Configuration

import { EventStore } from '@vendit-dev/event-store';

const config = {
  type: 'mongodb',
  options: {
    url: 'mongodb://localhost:27017',
    database: 'eventstore',
    collection: 'events'
  },
  maxSnapshotsCount: 10,
  emitStoreEvents: true
};

const eventStore = new EventStore(config);

Supported Databases

DatabaseTypeStatusNotes
In-Memoryinmemory✅ ReadyDevelopment/testing
MongoDBmongodb✅ ReadyRecommended for production
Redisredis✅ ReadyHigh-performance option
DynamoDBdynamodb✅ ReadyAWS-native solution
Elasticsearchelasticsearch✅ ReadySearch-optimized
Azure Tableazuretable✅ ReadyAzure-native solution

Working with Events

// Create event stream
const stream = await eventStore.getEventStream({ 
  aggregateId: 'order-456' 
});

// Add multiple events
stream.addEvent({
  aggregateId: 'order-456',
  payload: { type: 'OrderCreated', customerId: 'cust-123', amount: 100 }
});

stream.addEvent({
  aggregateId: 'order-456', 
  payload: { type: 'OrderItemAdded', productId: 'prod-789', quantity: 2 }
});

// Commit all events atomically
await stream.commit();

// Query events
const events = await eventStore.getEvents({ 
  aggregateId: 'order-456' 
});

console.log(`Found ${events.length} events`);

Snapshots

// Create snapshot
await eventStore.createSnapshot({
  aggregateId: 'user-123',
  revision: 10,
  data: { name: 'John Doe', email: 'john@example.com', isActive: true }
});

// Load from snapshot
const { snapshot, eventStream } = await eventStore.getFromSnapshot({ 
  aggregateId: 'user-123' 
});

if (snapshot) {
  console.log(`Loaded snapshot at revision ${snapshot.revision}`);
  console.log(`${eventStream.events.length} events since snapshot`);
}

🏗️ Architecture

Modern Design Principles

  • ESM Modules: Native ES module support with tree-shaking
  • Async/Await: Promise-based APIs throughout
  • TypeScript First: Written in TypeScript with full type definitions
  • Zero Dependencies: Minimal core footprint
  • Peer Dependencies: Optional database drivers

Performance Optimizations

  • Connection Pooling: Efficient database connection management
  • Batch Operations: Bulk event processing for high throughput
  • Streaming: Memory-efficient processing of large event sets
  • Caching: Intelligent caching strategies per database type

🧪 Testing

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Run with coverage
npm run test:coverage

🛠️ Development

# Clone repository
git clone https://github.com/ScripterSugar/-vendit-dev-event-store.git
cd -vendit-dev-event-store

# Install dependencies
npm install

# Build project
npm run build

# Run in development mode
npm run dev

# Lint code
npm run lint

# Format code
npm run format

📈 Migration from v1.x

This is a complete rewrite with breaking changes. See MIGRATION.md for detailed migration guide.

Key Changes

  • Node.js: Now requires Node.js 18+
  • TypeScript: Full TypeScript rewrite
  • ESM: ES modules instead of CommonJS
  • Async/Await: No more callbacks
  • Modern APIs: Simplified and more intuitive APIs

📋 Requirements

  • Node.js: 18.0.0 or higher
  • npm: 9.0.0 or higher
  • TypeScript: 5.0+ (if using TypeScript)

📄 License

MIT © ScripterSugar

🤝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.

💬 Support

⚠️ Alpha Release: This is an alpha version. APIs may change before the stable release.

Keywords

cqrs

FAQs

Package last updated on 12 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts