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

@vytches/ddd-projections

v0.28.0

Published

Event projections and read model capabilities

Downloads

351

Readme

@vytches/ddd-projections

npm version TypeScript License: MIT

Event projections and read-model building for CQRS / Event Sourcing applications

Installation

pnpm add @vytches/ddd-projections

What's included

Core classes

| Export | Kind | Description | | ---------------------------- | -------- | ------------------------------------------------------------------------------------------------- | | ProjectionEngine | class | Orchestrates projection execution; routes events to registered projections | | BaseProjection<TReadModel> | class | Abstract base for projections — implement name, eventTypes, createInitialState(), apply() | | ProjectionBuilder | class | Fluent builder for constructing ProjectionEngine instances | | ProjectionRebuilder | class | Replays historical events to rebuild a projection from scratch | | createProjectionRebuilder | function | Factory shorthand for ProjectionRebuilder |

Capabilities (opt-in projection features)

| Export | Kind | Description | | ------------------------------ | ----- | --------------------------------------------------------------- | | BaseIntervalCapability | class | Base for interval-based capability implementations | | CheckpointCapability | class | Persists last-processed event position for resumable processing | | CircuitBreakerCapability | class | Stops projection processing on repeated failures | | DeadLetterCapability | class | Routes failed events to a dead-letter store | | SnapshotProjectionCapability | class | Periodically snapshots the read model for faster rebuilds |

Interfaces

| Export | Kind | Description | | -------------------------- | --------- | -------------------------------------------------- | | IProjection<TReadModel> | interface | Core projection contract | | IProjectionEngine | interface | Engine contract | | IProjectionCapability | interface | Base capability contract | | IProjectionStore | interface | Read-model persistence contract | | ICapabilityContext | interface | Context passed to capabilities during execution | | ErrorProjectionState | interface | Shape used when a projection enters an error state | | IProjectionRebuildConfig | interface | Configuration for ProjectionRebuilder | | IProjectionRebuilder | interface | Rebuilder contract |

Errors

| Export | Kind | Description | | ----------------- | ----- | --------------------------------------------- | | ProjectionError | class | Error thrown for projection-specific failures |

Quick start

import { BaseProjection, ProjectionEngine } from '@vytches/ddd-projections';
import type { IDomainEvent } from '@vytches/ddd-contracts';

interface OrderReadModel {
  orderId: string;
  status: 'pending' | 'confirmed' | 'shipped';
  total: number;
}

class OrderProjection extends BaseProjection<OrderReadModel> {
  readonly name = 'OrderProjection';
  readonly eventTypes = ['OrderCreated', 'OrderConfirmed', 'OrderShipped'];

  createInitialState(): OrderReadModel {
    return { orderId: '', status: 'pending', total: 0 };
  }

  apply(model: OrderReadModel, event: IDomainEvent): OrderReadModel {
    switch (event.eventName) {
      case 'OrderCreated':
        return {
          ...model,
          orderId: event.payload.orderId,
          total: event.payload.total,
        };
      case 'OrderConfirmed':
        return { ...model, status: 'confirmed' };
      case 'OrderShipped':
        return { ...model, status: 'shipped' };
      default:
        return model;
    }
  }
}

const engine = new ProjectionEngine();
engine.register(new OrderProjection());

// Process an event
await engine.process(orderCreatedEvent);
const state = engine.getState<OrderReadModel>('OrderProjection');

With capabilities

import {
  ProjectionBuilder,
  CheckpointCapability,
  CircuitBreakerCapability,
  SnapshotProjectionCapability,
} from '@vytches/ddd-projections';

const engine = new ProjectionBuilder()
  .withProjection(new OrderProjection())
  .withCapability(new CheckpointCapability(checkpointStore))
  .withCapability(new CircuitBreakerCapability({ threshold: 5 }))
  .withCapability(new SnapshotProjectionCapability({ interval: 100 }))
  .build();

Rebuilding from history

import { createProjectionRebuilder } from '@vytches/ddd-projections';

const rebuilder = createProjectionRebuilder({
  eventStore,
  projections: [new OrderProjection()],
  batchSize: 500,
});

await rebuilder.rebuild();

Package boundaries

@vytches/ddd-projections depends on:

  • @vytches/ddd-contractsIDomainEvent, IEventStore
  • @vytches/ddd-logging — internal logging

License

MIT