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

@xtaskjs/event-source

v1.0.25

Published

Event sourcing integration for xtaskjs with aggregate repositories, lifecycle wiring, and optional TypeORM and queue adapters.

Readme

@xtaskjs/event-source

Event sourcing integration package for xtaskjs.

This package is part of the xtaskjs project, hosted at xtaskjs.io.

Installation

npm install @xtaskjs/event-source reflect-metadata

Optional adapters:

npm install @xtaskjs/typeorm typeorm
npm install @xtaskjs/queues amqplib

What It Provides

  • Event-sourced aggregate roots with decorator-based event appliers.
  • Aggregate repositories registered in the xtaskjs container for constructor and property injection.
  • A lifecycle-managed event store abstraction with an in-memory implementation by default.
  • A TypeORM event-store adapter for durable stream persistence.
  • An optional queue publisher bridge for pushing stored events to the xtaskjs queues package, including RabbitMQ transports.
  • In-process event subscribers for projections, integrations, and side effects without taking over CQRS responsibilities.

Package Boundary With CQRS

@xtaskjs/event-source is responsible for aggregate rehydration, optimistic stream appends, and stored-event publication.

@xtaskjs/cqrs remains responsible for command, query, and event handler orchestration. You can use both packages together: persist domain events with @xtaskjs/event-source, then project or route them with CQRS or queues.

Configure Event Sourcing

import {
  EventSource,
  createQueueEventPublisher,
  createTypeOrmEventStore,
} from "@xtaskjs/event-source";

@EventSource({
  store: createTypeOrmEventStore({
    dataSourceName: "write-db",
    tableName: "event_store",
  }),
  publisher: createQueueEventPublisher({
    queue: (event) => `domain.${event.eventName}`,
    transportName: "rabbitmq",
  }),
})
class EventSourceConfiguration {}

If you do not configure a store, xtaskjs uses an in-memory event store.

Define An Aggregate

import {
  ApplyEvent,
  EventSourcedAggregate,
  EventSourcedAggregateRoot,
  EventSourceRepository,
  InjectEventSourceRepository,
} from "@xtaskjs/event-source";
import { Service } from "@xtaskjs/core";

class UserRegisteredEvent {
  constructor(
    public readonly id: string,
    public readonly email: string
  ) {}
}

@EventSourcedAggregate({ stream: "users" })
class UserAggregate extends EventSourcedAggregateRoot {
  public email?: string;

  register(id: string, email: string) {
    this.assignStreamId(id);
    this.raiseEvent(new UserRegisteredEvent(id, email));
  }

  @ApplyEvent(UserRegisteredEvent)
  onRegistered(event: UserRegisteredEvent) {
    this.email = event.email;
  }
}

@Service()
class UserService {
  constructor(
    @InjectEventSourceRepository(UserAggregate)
    private readonly users: EventSourceRepository<UserAggregate>
  ) {}

  async register(id: string, email: string) {
    const user = this.users.create(id);
    user.register(id, email);
    await this.users.save(user);
  }
}

Subscribe To Stored Events

import { Service } from "@xtaskjs/core";
import { EventSourceSubscriber, IEventSourceSubscriber } from "@xtaskjs/event-source";

@Service()
@EventSourceSubscriber(UserRegisteredEvent)
class WelcomeProjection implements IEventSourceSubscriber<UserRegisteredEvent> {
  public emails: string[] = [];

  handle(event: UserRegisteredEvent) {
    this.emails.push(event.email);
  }
}

Subscribers receive the event payload, the stored event envelope, and a context with access to the lifecycle manager, store, and bus.

Resources