cqrs
cqrs for javascript
Last updated a year ago by leogiese .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cqrs 
SYNC missed versions from official npm registry.

CQRS

DDD-CQRS-Actor framework.

Document [ chinese ]

Version

cqrs@2.10.11

Install

npm install cqrs

yarn add cqrs

Consumers

  • Auxo (vue & express & cqrs framework)

EventStore

const {Domain} = require("cqrs");
const MongoStore = require("cqrs-mongo-eventstore").default;
const eventstore = new MongoStore("localhost/test");
const domain = new Domain({eventstore});

Roadmap

  • preview core
  • use typescript rewrite core
  • saga rollback
  • join the distributed system
  • DCI support
  • use protobuf message
  • actor GC
  • system time travel

Step

create Actor class

const { Actor } = require("cqrs");
class User extends Actor { /* see example */ }
class Transfer extends Actor { /* see example */ }

register Actor class to domain

const { domain } = require("cqrs"); // get default domain.
domain.register(User).register(Transfer);

create/get an Actor instance


// only javascript object

const user = await domain.create("User", {name:"Leo"});
user.json; // get actor instance data.
user.deduct(120.00); // call instance method.

const userInstance = await domain.get("User",userId); // get a User instance.

Preview Example

Example

User.js

const { Actor } = require("..");

module.exports = class User extends Actor {

    constructor(data) {
        super({ money: data.money || 0, name: data.name, id:data.id });
    }

    changename(name) {
        this.$.apply("changename", name);
    }

    get updater(){
       return {
          changename(data,event){
            return { name: event.name }
          }
       }
    }

}


Transfer.js

const { Actor } = require("cqrs");

module.exports = class Transfer extends Actor {

    constructor(data) {
        super({ finish: false });
    }

    log(event) {
        // console.log(event,"21121----2");
    }

    async transfe(fromUserId, toUserId, money) {
      try{
        const $ = this.$;
        $.sagaBegin();
        $.lock();

          await $.subscribe({ actorType: "User"}, "log");
          // await $.unsubscribe({ actorType: "User"});
          await $.subscribe({ actorType: "User", actorId:toUserId , type: "add" }, "log");
          // await $.unsubscribe({ actorType: "User", actorId:toUserId , type: "add" });


        // console.log(fromUserId,toUserId);
        const fromUser = await $.get("User.payers", fromUserId);
        const toUser = await $.get("User.charger", toUserId);

        fromUser.deduct(money);

        toUser.add(money);

        if (money > 100)
            throw new Error("hhhh")

        $.unlock();
        $.sagaEnd();

        $("finish", null);
      }catch(e){
        // console.log(e);
      }
    }



    get updater(){
      return {
        finish(data,event) {
            return { finish: true }
        }
      }
    }

}

LICENSE

MIT

Current Tags

  • 2.10.25                                ...           latest (a year ago)

174 Versions

  • 2.10.25                                ...           a year ago
  • 2.10.24                                ...           a year ago
  • 2.10.23                                ...           a year ago
  • 2.10.22                                ...           a year ago
  • 2.10.21                                ...           a year ago
  • 2.10.20                                ...           a year ago
  • 2.10.19                                ...           a year ago
  • 2.10.18                                ...           a year ago
  • 2.10.17                                ...           a year ago
  • 2.10.16                                ...           a year ago
  • 2.10.15                                ...           a year ago
  • 2.10.14                                ...           a year ago
  • 2.10.13                                ...           a year ago
  • 2.10.12                                ...           a year ago
  • 2.10.11                                ...           a year ago
  • 2.10.10                                ...           a year ago
  • 2.10.9                                ...           a year ago
  • 2.10.8                                ...           a year ago
  • 2.10.7                                ...           a year ago
  • 2.10.6                                ...           a year ago
  • 2.10.5                                ...           a year ago
  • 2.10.4                                ...           a year ago
  • 2.10.2                                ...           a year ago
  • 2.10.1                                ...           a year ago
  • 2.10.0                                ...           a year ago
  • 2.9.3                                ...           a year ago
  • 2.9.2                                ...           a year ago
  • 2.9.1                                ...           a year ago
  • 2.9.0                                ...           a year ago
  • 2.8.0                                ...           a year ago
  • 2.7.1                                ...           a year ago
  • 2.7.0                                ...           a year ago
  • 2.6.3                                ...           a year ago
  • 2.6.2                                ...           a year ago
  • 2.6.1                                ...           a year ago
  • 2.6.0                                ...           a year ago
  • 2.5.0                                ...           a year ago
  • 2.4.1                                ...           a year ago
  • 2.4.0                                ...           a year ago
  • 2.3.0                                ...           a year ago
  • 2.2.4                                ...           a year ago
  • 2.2.3                                ...           a year ago
  • 2.2.2                                ...           a year ago
  • 2.2.1                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.2                                ...           a year ago
  • 2.1.1                                ...           a year ago
  • 2.1.0                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.6.1                                ...           a year ago
  • 1.6.0                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 3.2.1-pre                                ...           2 years ago
  • 3.2.0-pre                                ...           2 years ago
  • 3.1.1-pre                                ...           2 years ago
  • 3.1.0-pre                                ...           2 years ago
  • 3.0.9-pre                                ...           2 years ago
  • 3.0.8-pre                                ...           2 years ago
  • 3.0.7-pre                                ...           2 years ago
  • 3.0.6-pre                                ...           2 years ago
  • 3.0.5-pre                                ...           2 years ago
  • 3.0.4-pre                                ...           2 years ago
  • 3.0.3-pre                                ...           2 years ago
  • 3.0.2-pre                                ...           2 years ago
  • 3.0.1-pre                                ...           2 years ago
  • 3.0.0-pre                                ...           2 years ago
  • 2.4.0-pre                                ...           2 years ago
  • 2.1.3-pre                                ...           2 years ago
  • 2.1.2-pre                                ...           2 years ago
  • 2.1.1-pre                                ...           2 years ago
  • 2.1.0-pre                                ...           2 years ago
  • 2.0.9-pre                                ...           2 years ago
  • 2.0.8-pre                                ...           2 years ago
  • 2.0.7-pre                                ...           2 years ago
  • 2.0.6-pre                                ...           2 years ago
  • 2.0.5-pre                                ...           2 years ago
  • 2.0.2-pre                                ...           2 years ago
  • 2.0.1-pre                                ...           2 years ago
  • 2.0.0-pre                                ...           2 years ago
  • 1.0.7-pre                                ...           3 years ago
  • 1.0.6-pre                                ...           3 years ago
  • 1.0.5-pre                                ...           3 years ago
  • 1.0.4-pre                                ...           3 years ago
  • 1.0.1-pre                                ...           4 years ago
  • 1.0.0-pre                                ...           4 years ago
  • 0.9.8                                ...           4 years ago
  • 0.9.7                                ...           4 years ago
  • 0.9.6                                ...           4 years ago
  • 0.9.5                                ...           4 years ago
  • 0.9.4                                ...           4 years ago
  • 0.9.3                                ...           4 years ago
  • 0.9.2                                ...           4 years ago
  • 0.9.1                                ...           5 years ago
  • 0.9.0                                ...           5 years ago
  • 0.8.9                                ...           5 years ago
  • 0.8.8                                ...           5 years ago
  • 0.8.7                                ...           5 years ago
  • 0.8.6                                ...           5 years ago
  • 0.8.5                                ...           5 years ago
  • 0.8.4                                ...           5 years ago
  • 0.8.2                                ...           5 years ago
  • 0.8.1                                ...           5 years ago
  • 0.8.0                                ...           5 years ago
  • 0.7.9                                ...           5 years ago
  • 0.7.8                                ...           5 years ago
  • 0.7.7                                ...           5 years ago
  • 0.7.6                                ...           5 years ago
  • 0.7.5                                ...           5 years ago
  • 0.7.4                                ...           5 years ago
  • 0.7.3                                ...           5 years ago
  • 0.7.2                                ...           5 years ago
  • 0.7.1                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.9                                ...           5 years ago
  • 0.6.8                                ...           5 years ago
  • 0.6.7                                ...           5 years ago
  • 0.6.6                                ...           5 years ago
  • 0.6.5                                ...           5 years ago
  • 0.6.4                                ...           5 years ago
  • 0.6.3                                ...           5 years ago
  • 0.6.2                                ...           5 years ago
  • 0.6.1                                ...           5 years ago
  • 0.6.0                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.0.9                                ...           5 years ago
  • 0.0.8                                ...           5 years ago
  • 0.0.7                                ...           5 years ago
  • 0.0.6                                ...           5 years ago
  • 0.0.5                                ...           5 years ago
  • 0.0.4                                ...           5 years ago
  • 0.0.0 [deprecated]           ...           5 years ago
  • 0.0.3                                ...           5 years ago
  • 0.5.4                                ...           7 years ago
  • 0.5.3                                ...           8 years ago
  • 0.5.2                                ...           8 years ago
  • 0.5.1                                ...           8 years ago
  • 0.5.0                                ...           8 years ago
  • 0.4.10                                ...           8 years ago
  • 0.4.9                                ...           8 years ago
  • 0.4.8                                ...           8 years ago
  • 0.4.7                                ...           8 years ago
  • 0.4.6                                ...           8 years ago
  • 0.4.5                                ...           8 years ago
  • 0.4.4                                ...           8 years ago
  • 0.4.3                                ...           8 years ago
  • 0.4.1                                ...           8 years ago
  • 0.4.0                                ...           8 years ago
  • 0.3.16                                ...           8 years ago
  • 0.3.15                                ...           8 years ago
  • 0.3.14                                ...           8 years ago
  • 0.3.13                                ...           8 years ago
  • 0.3.12                                ...           8 years ago
  • 0.3.10                                ...           8 years ago
  • 0.3.9                                ...           8 years ago
  • 0.3.8                                ...           8 years ago
  • 0.3.7                                ...           8 years ago
  • 0.3.6                                ...           8 years ago
  • 0.3.5                                ...           8 years ago
  • 0.3.4                                ...           8 years ago
  • 0.3.3                                ...           8 years ago
  • 0.3.2                                ...           8 years ago
  • 0.3.1                                ...           8 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.5                                ...           8 years ago
  • 0.1.4                                ...           8 years ago
  • 0.1.3                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Downloads
Today 0
This Week 1
This Month 36
Last Day 1
Last Week 1
Last Month 210
Dependencies (3)
Dev Dependencies (15)

Copyright 2014 - 2016 © taobao.org |