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

@sydorenkoalex/ceves

v0.3.0

Published

Event Sourcing framework for Cloudflare Workers and Durable Objects with CQRS and OpenAPI routing

Readme

Ceves - Event Sourcing for Cloudflare Workers

TypeScript Cloudflare Workers License: MIT

Ceves (Command/Event/View/Entity/State) is an event sourcing framework for Cloudflare Workers and Durable Objects. Write your domain logic once, get automatic state persistence, OpenAPI docs, and zero-latency reads. Built with TypeScript-first design and decorator-based patterns.

Why Ceves?

Event sourcing typically requires weeks of infrastructure work: event stores, snapshot management, state restoration, and testing setup. Ceves handles all of that:

  • Zero Infrastructure Code - Write only domain logic (commands, events, state)
  • Zero-Latency State - Durable Objects use built-in transactional storage (no network calls)
  • Automatic OpenAPI - Routes generate OpenAPI docs and Swagger UI automatically
  • Superior DX - Local testing with Wrangler, TypeScript-first, decorator-based
  • Serverless Economics - True pay-per-use pricing on Cloudflare Workers
  • Production Ready - Battle-tested patterns proven in production systems

Installation

npm install ceves

Quick Start

Build your first event-sourced bank account in 5 minutes:

import { CevesApp, R2EventStore, D1SnapshotStore } from 'ceves';

// 1. Define your state
interface BankAccountState extends BaseState {
  balance: number;
}

// 2. Define commands & events
class DepositCommand extends BaseCommand { /* ... */ }
class MoneyDepositedEvent extends BaseEvent {
  apply(state: BankAccountState) {
    return { ...state, balance: state.balance + this.amount };
  }
}

// 3. Create handler
@CommandHandler
class DepositHandler {
  handle(cmd: DepositCommand) {
    return [new MoneyDepositedEvent(cmd)];
  }
}

// 4. Use it!
const app = new CevesApp({
  eventStore: new R2EventStore(env.EVENTS),
  snapshotStore: new D1SnapshotStore(env.DB),
});

const state = await app.execute(depositCommand);

Full Getting Started Guide for complete walkthrough.

See the complete working example in /example with full BankAccount domain implementation.

Example

See /example for a complete Cloudflare Workers example:

  • BankAccount domain (Open, Deposit, Withdraw)
  • Full command and event handlers
  • Comprehensive test suite
  • Wrangler configuration
  • Local development setup

Development

# Install dependencies
npm install

# Run tests
npm test

# Build library
npm run build

# Generate API docs
npm run docs

Core Concepts

  • Commands: Express intent to change state (validated, can fail)
  • Events: Immutable facts that happened (stored forever)
  • State: Derived by replaying events through apply() methods
  • Aggregate: A cluster of domain objects treated as a single unit
  • Event Store: Append-only log of all events (R2)
  • State Persistence: Durable Objects use built-in transactional storage (zero-latency, no snapshots needed)

Architecture

Domain Event Pattern

Ceves separates domain logic from infrastructure concerns:

  • Domain Events: Pure TypeScript classes containing only business data
  • StoredEvent: Infrastructure envelope that wraps domain events with metadata
  • Event Handlers: Receive domain event + metadata as separate parameters
  • Command Handlers: Return domain event instances (not plain objects)
// Domain event - pure business data
export class AccountOpenedEvent implements DomainEvent {
  readonly type = 'AccountOpened' as const;
  constructor(
    public readonly owner: string,
    public readonly initialDeposit: number
  ) {}
}

// Event handler - clean separation
@EventHandler({ eventType: 'AccountOpened', aggregateType: 'account' })
export class AccountOpenedHandler implements IEventHandler<AccountState, AccountOpenedEvent> {
  apply(
    state: AccountState | null,
    event: AccountOpenedEvent,
    metadata: EventMetadata
  ): Omit<AccountState, 'version' | 'orgId'> {
    return {
      id: metadata.aggregateId,
      owner: event.owner,
      balance: event.initialDeposit,
    };
  }
}

// Command handler - returns domain event
@Route({ method: 'POST', path: '/accounts/:id/open' })
export class OpenAccountHandler extends CreateCommandRoute<OpenAccountCommand, AccountState, AccountOpenedEvent> {
  async executeCommand(command: OpenAccountCommand): Promise<AccountOpenedEvent> {
    return new AccountOpenedEvent(command.owner, command.initialDeposit);
  }
}

QueryHandler

Read-only queries via the @QueryHandler decorator:

@QueryHandler
export class GetBalanceQuery implements IQueryHandler<BankAccountState, {}, BalanceResponse> {
  queryType = 'GetBalance';
  aggregateType = 'BankAccountAggregate';
  route = '/accounts/:id/balance';
  method = 'GET' as const;

  async execute(state: BankAccountState): Promise<BalanceResponse> {
    return { balance: state.balance, currency: 'USD' };
  }
}

Documentation

License

MIT - see LICENSE