All Projects → andrewwebber → cqrs-typescript

andrewwebber / cqrs-typescript

Licence: other
CQRS implementation in typescript

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to cqrs-typescript

nota
"None Of The Above" - is going to be a secure online voting system, intended to give the electorate better choices. It always adds one additional choice to anything to be voted on: If more than 50% of voters choose "None of the Above", the election is considered null and void.
Stars: ✭ 17 (-41.38%)
Mutual labels:  cqrs, eventsourcing
SplitetFramework
Splitet is a Java based Event Sourcing framework which can be benefited by the teams who are planning to make CQRS transitions with minimum learning curve and ease of adaptation.
Stars: ✭ 159 (+448.28%)
Mutual labels:  cqrs, eventsourcing
nestjs-boilerplate-microservice
Nestjs Microservice boilerplate: apply DDD, CQRS, and Event Sourcing within an event driven architecture
Stars: ✭ 270 (+831.03%)
Mutual labels:  cqrs, eventsourcing
workflow
Functional CQRS Eventsourcing Engine
Stars: ✭ 22 (-24.14%)
Mutual labels:  cqrs, eventsourcing
les
Go directly from an event storming to a working API: Event Markdown / Markup validation & NodeJS CQRS/ES application builder.
Stars: ✭ 48 (+65.52%)
Mutual labels:  cqrs, eventsourcing
chekov
A CQRS/ES framework for building application in Rust
Stars: ✭ 21 (-27.59%)
Mutual labels:  cqrs, eventsourcing
event-store-mgmt-ui
Event Store Management UI
Stars: ✭ 23 (-20.69%)
Mutual labels:  cqrs, eventsourcing
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (+458.62%)
Mutual labels:  cqrs, eventsourcing
fmodel-ts
Functional Domain Modeling with Typescript
Stars: ✭ 41 (+41.38%)
Mutual labels:  cqrs, eventsourcing
eventuous
Minimalistic Event Sourcing library for .NET
Stars: ✭ 236 (+713.79%)
Mutual labels:  cqrs, eventsourcing
nbb
.Net Building Blocks
Stars: ✭ 98 (+237.93%)
Mutual labels:  cqrs, eventsourcing
pdo-snapshot-store
PDO Snapshot Store
Stars: ✭ 24 (-17.24%)
Mutual labels:  cqrs, eventsourcing
Restairline
DDD+CQRS+EventSourcing+Hypermedia API+ASP.NET Core 3.1+Masstransit+terraform+docker+k8s
Stars: ✭ 243 (+737.93%)
Mutual labels:  cqrs, eventsourcing
Totem
Knowledge work at play
Stars: ✭ 56 (+93.1%)
Mutual labels:  cqrs, eventsourcing
Liiklus
Reactive (RSocket/gRPC) Gateway for the event-based systems
Stars: ✭ 192 (+562.07%)
Mutual labels:  cqrs, eventsourcing
awesome cqrs
some links about CQRS / Event Sourcing
Stars: ✭ 61 (+110.34%)
Mutual labels:  cqrs, eventsourcing
Eventflow
Async/await first CQRS+ES and DDD framework for .NET
Stars: ✭ 1,932 (+6562.07%)
Mutual labels:  cqrs, eventsourcing
Eventapis
eventapis is a Java based Event Sourcing framework which can be benefited by the teams who are planning to make CQRS transitions with minimum learning curve and ease of adaptation.
Stars: ✭ 147 (+406.9%)
Mutual labels:  cqrs, eventsourcing
eventsourcing-go
Event Sourcing + CQRS using Golang Tutorial
Stars: ✭ 75 (+158.62%)
Mutual labels:  cqrs, eventsourcing
micro
Functional prooph for microservices
Stars: ✭ 53 (+82.76%)
Mutual labels:  cqrs, eventsourcing

cqrs-typescript

###CQRS implementation in typescript.

Components avaliable:

  • Event Sourcing
    • Interfaces for creating versioned events
    • Base classes for creating an event sourced aggregates and raising versioned events
  • Command processing
    • Interfaces for creating commands
    • Command bus for sending events
    • Redis based command bus using 'rpoplpush'
    • Command handling registry for signing up for command types
  • Event processing
    • Interfaces for creating events
    • Event bus for sending events
    • Redis based event bus using 'rpoplpush'
    • Event handling registry for signing up for command types

View the tests for more examples on usage.

####Event Sourcing

/// <reference path="mocha.d.ts"/>
/// <reference path="should.d.ts"/>

import CQRS = require('cqrs-typescript');
import should = require('should');
should.equal('actual', 'actual');

interface ICreditAccountEvent extends CQRS.IVersionedEvent{
    amount:number
}

interface IDebitAccountEvent extends CQRS.IVersionedEvent{
    amount:number
}

class BankAccount extends CQRS.EventSourced{
  constructor(id :string){
    super(id);
    this.balance = 0;
  }

  balance : number;

  credit(amount:number) : void {
      this.update({
          name: 'CreditAccount',
          amount: amount,
          version: -1,
          sourceId: ''
      });
  }

  debit(amount:number) : void{
    this.update({
        name: 'DebitAccount',
        amount: amount,
        version: -1,
        sourceId: ''
      });
  }

  private onCreditAccount(e : ICreditAccountEvent):void{
    this.balance += e.amount;
  }

  private onDebitAccount(e : IDebitAccountEvent):void{
    this.balance -= e.amount;
  }
}

var account : BankAccount;

describe('extending from "EventSourced" to create a "bank account"', function() {
  it('should be ok to create one once supplying an id ', function() {
    account = new BankAccount('1');
  });

  it('should be ok to credit the account to 100 by raising an event',function(){
    account.credit(100);
    account.balance.should.be.exactly(100);
    account.getEvents().length.should.be.exactly(1);
    account.getVersion().should.be.exactly(1);
  });

  it('should be ok to credit the account to 150 by raising an event',function(){
    account.credit(50);
    account.balance.should.be.exactly(150);
    account.getEvents().length.should.be.exactly(2);
    account.getVersion().should.be.exactly(2);
  });

  it('should be ok to debit the account by 100 by raising an event',function(){
    account.debit(100);
    account.balance.should.be.exactly(50);
    account.getEvents().length.should.be.exactly(3);
    account.getVersion().should.be.exactly(3);
  });

  it('should be ok to load a bank account from an event stream',function(){
      var accountFromEvents = new BankAccount('1');
      var events = account.getEvents();
      accountFromEvents.loadFromEvents(events);
      accountFromEvents.balance.should.be.exactly(account.balance);
      accountFromEvents.getVersion().should.be.exactly(account.getVersion());
  });
});

####Redis based event sourcing repository

var account = new BankAccount('2');
account.credit(100);
account.credit(100);
account.debit(50);
account.credit(100);
account.debit(200);
account.balance.should.be.exactly(50);

var provider = new CQRS.RedisEventSourcedRepository({ host: "127.0.0.1", port:6379});
it('should connect to a specified Redis server',function(done){
  provider.connect((error)=>{
    should.equal(error, null);
    done();
  });
});

it('should be able to persist an event stream for an given aggregate id',function(done){
  var events = account.getEvents();
  events.length.should.be.exactly(5);
  provider.saveEventsByAggregateId(account.getId(),events, (error)=>{
      should.equal(error, null);
      done();
  });
});

it('should be able to retrieve an event stream by aggregate id and recreate an aggregate instance',function(done){
  provider.getEventsByAggregateId(account.getId(),(error, events)=>{
    should.equal(error, null);
    events.length.should.be.exactly(5);

    var accountFromEvents = new BankAccount(account.getId());
    accountFromEvents.loadFromEvents(events);
    accountFromEvents.balance.should.be.exactly(account.balance);
    done();
  });
});
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].