Event Nest

Event sourcing primitives and persistence adapters for NestJS applications.
Event Nest

Install the core library and the adapter for your database — PostgreSQL shown here, with MongoDB and Microsoft SQL Server available as well:

pnpm add @event-nest/core @event-nest/postgresql pg

Domain methods record events; Event Nest persists them and rebuilds aggregate state by replay:

import { AggregateRoot, AggregateRootConfig, ApplyEvent, DomainEvent } from "@event-nest/core";

@DomainEvent("user-created")
class UserCreatedEvent {
    constructor(public readonly name: string) {}
}

@AggregateRootConfig({ name: "User" })
class User extends AggregateRoot {
    private name = "";

    private constructor(id: string) {
        super(id);
    }

    static create(id: string, name: string): User {
        const user = new User(id);
        const event = new UserCreatedEvent(name);
        user.applyUserCreated(event);
        user.append(event);
        return user;
    }

    @ApplyEvent(UserCreatedEvent)
    private applyUserCreated(event: UserCreatedEvent): void {
        this.name = event.name;
    }
}
ts

Event Nest is a focused set of libraries — not an application framework, ORM, or distributed event bus. Review Scope and Limitations before adopting it.