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/cqrs

v1.1.7

Published

CQRS integration for xtaskjs with read/write datasource bindings.

Readme

@xtaskjs/cqrs

CQRS integration package for xtaskjs.

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

Installation

npm install @xtaskjs/cqrs @xtaskjs/typeorm reflect-metadata typeorm

What It Provides

  • Command, query, and event buses registered in the xtaskjs container.
  • Decorators for command handlers, query handlers, event handlers, process managers, and projection rebuilders.
  • Read/write datasource aliases backed by @xtaskjs/typeorm.
  • Injection decorators for read and write repositories without hard-coding datasource names.
  • Automatic in-memory command idempotency helpers with an overridable store.
  • Lifecycle integration so CQRS bindings are initialized on startup and reset on shutdown.

Configure Read And Write Databases

import { Cqrs } from "@xtaskjs/cqrs";
import { TypeOrmDataSource } from "@xtaskjs/typeorm";

@TypeOrmDataSource({
  name: "write-db",
  type: "sqlite",
  database: "./write.sqlite",
  entities: [UserEntity],
  synchronize: true,
})
class WriteDatabase {}

@TypeOrmDataSource({
  name: "read-db",
  type: "sqlite",
  database: "./read.sqlite",
  entities: [UserProjection],
  synchronize: true,
})
class ReadDatabase {}

@Cqrs({
  writeDataSourceName: "write-db",
  readDataSourceName: "read-db",
})
class CqrsConfiguration {}

Register Handlers

import { Service } from "@xtaskjs/core";
import {
  CommandHandler,
  IdempotentCommand,
  EventHandler,
  ICommandHandler,
  IEventHandler,
  InjectEventBus,
  InjectReadRepository,
  InjectWriteRepository,
  QueryHandler,
  IQueryHandler,
} from "@xtaskjs/cqrs";
import { Repository } from "typeorm";

class CreateUserCommand {
  constructor(public readonly name: string) {}
}

class GetUsersQuery {}

class UserCreatedEvent {
  constructor(public readonly id: number, public readonly name: string) {}
}

@Service()
@IdempotentCommand<CreateUserCommand>({ key: (command) => command.name.toLowerCase() })
@CommandHandler(CreateUserCommand)
class CreateUserHandler implements ICommandHandler<CreateUserCommand, number> {
  constructor(
    @InjectWriteRepository(UserEntity)
    private readonly writeRepository: Repository<UserEntity>,
    @InjectEventBus()
    private readonly eventBus: EventBus
  ) {}

  async execute(command: CreateUserCommand): Promise<number> {
    const user = await this.writeRepository.save(this.writeRepository.create({ name: command.name }));
    await this.eventBus.publish(new UserCreatedEvent(user.id, user.name));
    return user.id;
  }
}

## Process Managers And Projection Rebuilders
Process managers react to events with access to the buses, and projection rebuilders let you reconstruct read models from write-side state.

```typescript
import {
  IProcessManager,
  IProjectionRebuilder,
  ProcessManager,
  ProjectionRebuilder,
} from "@xtaskjs/cqrs";

@Service()
@ProcessManager(UserCreatedEvent)
class WelcomeProcessManager implements IProcessManager<UserCreatedEvent> {
  async handle(event: UserCreatedEvent, context: ProcessManagerContext) {
    await context.commandBus.execute(new SendWelcomeEmailCommand(event.id));
  }
}

@Service()
@ProjectionRebuilder("users")
class UserProjectionRebuilder implements IProjectionRebuilder {
  constructor(
    @InjectWriteRepository(UserEntity)
    private readonly writeRepository: Repository<UserEntity>,
    @InjectReadRepository(UserProjection)
    private readonly readRepository: Repository<UserProjection>
  ) {}

  async rebuild() {
    const users = await this.writeRepository.find();
    await this.readRepository.clear();
    await this.readRepository.save(users.map((user) => ({ ...user })));
  }
}

@Service() @QueryHandler(GetUsersQuery) class GetUsersHandler implements IQueryHandler<GetUsersQuery, string[]> { constructor( @InjectReadRepository(UserProjection) private readonly readRepository: Repository ) {}

async execute(): Promise<string[]> { const users = await this.readRepository.find(); return users.map((user) => user.name); } }

@Service() @EventHandler(UserCreatedEvent) class UserProjectionHandler implements IEventHandler { constructor( @InjectReadRepository(UserProjection) private readonly readRepository: Repository ) {}

async handle(event: UserCreatedEvent): Promise { await this.readRepository.save(this.readRepository.create({ id: event.id, name: event.name })); } }


## Resources
- Website: [xtaskjs.io](https://xtaskjs.io)
- Package: [npmjs.com/package/@xtaskjs/cqrs](https://www.npmjs.com/package/@xtaskjs/cqrs)
- Source: [github.com/xtaskjs/xtask](https://github.com/xtaskjs/xtask)