All Projects → brainhubeu → sqrs

brainhubeu / sqrs

Licence: MIT license
🚌SQRS is a JavaScript library for implementing CQRS pattern.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to sqrs

Xer.cqrs
A lightweight and easy-to-use CQRS + DDD library
Stars: ✭ 96 (+317.39%)
Mutual labels:  query, cqrs, command
Lerna Yarn Workspaces Monorepo
🐉 A Monorepo with multiple packages and a shared build, test, and release process.
Stars: ✭ 201 (+773.91%)
Mutual labels:  jest, lerna
Modern Monorepo Boilerplate
Modern Monorepo Boilerplate with Lerna, TypeScript, React/CRA, HMR, Jest, ESLint/TypeScript.
Stars: ✭ 127 (+452.17%)
Mutual labels:  jest, lerna
LiteBus
LiteBus is an easy-to-use and ambitious in-process mediator providing the foundation to implement CQS. It is implemented with minimum reflection usage and streamable query support.
Stars: ✭ 20 (-13.04%)
Mutual labels:  cqrs, cqs
Entria Fullstack
Monorepo Playground with GraphQL, React, React Native, Relay Modern, TypeScript and Jest
Stars: ✭ 434 (+1786.96%)
Mutual labels:  jest, lerna
Ts Monorepo
Template for setting up a TypeScript monorepo
Stars: ✭ 459 (+1895.65%)
Mutual labels:  jest, lerna
dudulina
CQRS + Event Sourcing library for PHP
Stars: ✭ 53 (+130.43%)
Mutual labels:  cqrs, dependency-injection
Hiboot
hiboot is a high performance web and cli application framework with dependency injection support
Stars: ✭ 150 (+552.17%)
Mutual labels:  command, dependency-injection
Hacker News Resolve
React & Redux & Resolve implementation of Hacker News
Stars: ✭ 79 (+243.48%)
Mutual labels:  cqrs, jest
Bankflix
Aplicação que simula um banco digital, contendo a área do cliente e administrativa, permitindo depósitos e transferências entre contas do mesmo banco. | Application that simulates a digital bank, containing the customer and administrative areas, allowing deposits and transfers between accounts of the same bank.
Stars: ✭ 82 (+256.52%)
Mutual labels:  cqrs, dependency-injection
Typescript Library Starter
Starter kit with zero-config for building a library in TypeScript, featuring RollupJS, Jest, Prettier, TSLint, Semantic Release, and more!
Stars: ✭ 3,943 (+17043.48%)
Mutual labels:  jest, typedoc
inversify-koa-utils
inversify-koa-utils is a module based on inversify-express-utils. This module has utilities for koa 2 applications development using decorators and IoC Dependency Injection (with inversify)
Stars: ✭ 27 (+17.39%)
Mutual labels:  dependency-injection, inversify
medly-components
🧩 Medly components provides numerous themable react components, each with multiple varitaions of sizes, colors, position etc.
Stars: ✭ 66 (+186.96%)
Mutual labels:  jest, lerna
Sketchmine
Tools to validate, generate and analyse sketch files from web pages
Stars: ✭ 114 (+395.65%)
Mutual labels:  jest, lerna
ng-mono-repo-starter
Angular Mono Repo Starter
Stars: ✭ 79 (+243.48%)
Mutual labels:  jest, lerna
Testdeck
Object oriented testing
Stars: ✭ 206 (+795.65%)
Mutual labels:  jest, dependency-injection
Qframework
Unity3D System Design Architecture
Stars: ✭ 2,326 (+10013.04%)
Mutual labels:  cqrs, dependency-injection
node-evented-command
provides simple command/event handling for evented systems like cqrs
Stars: ✭ 15 (-34.78%)
Mutual labels:  cqrs, command
typescript-boilerplate
A modern TypeScript project setup, for Node.js and browsers (using esbuild).
Stars: ✭ 502 (+2082.61%)
Mutual labels:  jest, typedoc
ucollage
An extensible command line image viewer inspired by vim
Stars: ✭ 161 (+600%)
Mutual labels:  command

sqrs

A JavaScript library for implementing CQRS pattern.

Hire us

Travis Last commit license PRs Welcome Renovate enabled

Downloads Activity Minified npm Contributors

Best used with TypeScript as it exposes interfaces for Commands, CommandHandlers, Queries, QueryHandlers and more.

When paired with a dependency injection framework it provides a fully-fledged inversion of control experience in JavaScript.

Installation

To install sqrs run

npm install @brainhubeu/sqrs or yarn add @brainhubeu/sqrs

the packages comes with it's own TypeScript types.

ES2015 execution environment is required. For NodeJS that means at least Node 8 LTS.

Getting started

Introduction to CQRS

In short, CQRS is a pattern that differentiates between read operations and write operations. Write operations are achieved via commands that represent intent to change the system's state, and read operations are achieved via queries that read the system's state. The distinction between the to comes from the principle that asking a question shouldn't change the response.

You can read more about CQRS here:

Using the library

See the longer guide for getting started

Short version

Writing commands (note you don't have to use classes, you can also use object factories):

import { Command } from '@brainhubeu/sqrs';

export class AddNoteCommand implements Command {
  public type = 'add-note';
  public text: string;

  constructor (text: string) {
    this.text = text;
  }
}

Writing command handlers:

import { CommandHandler } from '@brainhubeu/sqrs';

class AddNoteCommandHandler implements CommandHandler {
  public handle (command: AddNoteCommand) {
    // do something with the command
  }
}

Writing queries:

import { Query } from '@brainhubeu/sqrs';

export class GetNotesQuery implements Query<string, Note[]> {
  public queryName = 'GetNotes';
}

Writing query handlers:

import { QueryHandler } from '@brainhubeu/sqrs';

export class GetNotesQueryHandler implements QueryHandler<GetNotesQuery> {
  execute (query: GetNotesQuery): Promise<Note[]> {
    // get notes from somewhere
  }
}

Final usage:

import { DefaultCommandBus, CommandBus, DefaultQueryExecutor, QueryExecutor } from '@brainhubeu/sqrs';

const commandBus: CommandBus = new DefaultCommandBus(
  // created somewhere else
  commandHandlerProvider,
  commandValidatorProvider
);
const queryExecutor: QueryExecutor = new DefaultQueryExecutor(
  // created somewhere else
  queryHandlerProvider
);

const addNoteCommand = new AddNoteCommand('hello');
await commandBus.dispatch(addNoteCommand);

const getNotesQuery = new GetNotesQuery();
const notes = await queryExecutor.execute(getNotesQuery);

API reference

API reference generated from JSDoc comment can be found here

Example project

Example project created using this library can be found here

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].