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

@requence/event-sourcing

v1.5.0

Published

Event sourcing primitives — aggregate roots, projections, process managers, and event listeners

Downloads

638

Readme

@requence/event-sourcing

A high-performance, type-safe event sourcing library for TypeScript.

Build resilient, auditable systems by storing every state change as an immutable event — then derive your current state by replaying them.

Features

  • Aggregate Roots — define your domain model with events, business rules, and commands using a fluent builder API.
  • Automatic Concurrency Control — aggregate root streams are automatically locked to prevent simultaneous edits and event stream version collisions.
  • Distributed Locking — use redisLock to make the write path safe across multiple instances. Combined with the storage adapter's optimistic-concurrency checks, stream appends are collision-free even when many instances accept commands. See the multi-instance guide for how projections, listeners, and process managers behave when scaling.
  • Concurrency Retry — for the residual races a lock can't cover, pass settled({ maxRetries }) to reload the stream and re-apply the commands on a ConcurrencyError instead of surfacing it (opt-in; defaults to no retry). Where settled() cannot be called — inside process managers and transactions — declare the defaults on the scope instead: createProcessManager(name, { settled }) / transaction(handler, { settled }).
  • Projections — build query-optimized read models from events, with full replay support.
  • Process Managers — coordinate workflows across multiple aggregates.
  • Event Listeners — react to events with lightweight, stateless side effects.
  • Storage Adapters — swap between an in-memory store (great for testing), PostgreSQL via Drizzle, or SurrealDB.
  • Type-Safe Events — leverage Zod schemas and TypeScript for compile-time and runtime guarantees on every event shape.

Install

npm install @requence/event-sourcing zod

Quick Start

import { createAggregateRoot } from '@requence/event-sourcing'
import { createEventStore } from '@requence/event-sourcing/memory'

// 1. Define an aggregate root
const counter = createAggregateRoot('counter')
  .withInitialState({ count: 0 })
  .withEvents(({ z }) => ({
    Incremented: z.object({ amount: z.number() }),
  }))
  .withEventHandlers((state) => ({
    onIncremented({ payload }) {
      state.count += payload.amount
    },
  }))
  .withCommands((state, event) => ({
    increment(amount: number) {
      return event('Incremented', { amount })
    },
  }))

// 2. Create an event store with the aggregate root
const eventStore = createEventStore({
  aggregateRoots: [counter],
})

// 3. Build a read model with a projection
const totals = new Map<string, number>()

eventStore.createProjection('counter-totals').withEventHandlers({
  onIncremented({ streamId, payload }) {
    totals.set(streamId, (totals.get(streamId) ?? 0) + payload.amount)
  },
})

// 4. Execute commands on a new stream
const stream = await counter.newStream().increment(1).increment(5).settled()
console.log(totals.get(stream.streamId)) // 6

Storage Adapters

| Adapter | Import Path | Use Case | | -------------------- | ------------------------------------------- | --------------------- | | In-Memory | @requence/event-sourcing/memory | Testing & prototyping | | PostgreSQL (Drizzle) | @requence/event-sourcing/drizzle/postgres | Production | | SurrealDB | @requence/event-sourcing/surreal | Production |

Documentation

Full documentation — including concept guides, a step-by-step tutorial, and API reference — is available at:

https://event-sourcing.docs.requence.cloud

License

MIT