Socket
Socket
Sign inDemoInstall

cqrs

Package Overview
Dependencies
74
Maintainers
3
Versions
183
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0-pre to 3.1.0

aggregate-root.d.ts

71

package.json
{
"name": "cqrs",
"version": "3.1.0-pre",
"description": "cqrs for javascript",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
"scripts": {
"test": "tsc && mocha --require source-map-support/register dist/test && node example/main.js ",
"test2": "tsc && mocha --require source-map-support/register dist/test/test.clusterSystem",
"build": "tsc"
"version": "3.1.0",
"peerDependencies": {
"@angular/common": "^15.0.0",
"@angular/core": "^15.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/liangzeng/cqrs"
},
"keywords": [
"ddd",
"cqrs",
"domain",
"distributed"
],
"author": "Liang Zeng",
"license": "MIT",
"bugs": {
"url": "https://github.com/liangzeng/cqrs/issues"
},
"homepage": "https://github.com/liangzeng/cqrs",
"dependencies": {
"@types/socket.io": "^1.4.29",
"@types/socket.io-client": "^1.4.29",
"debug": "^2.6.8",
"nedb-promise": "^2.0.1",
"protobufjs": "^6.7.3",
"socket.io": "^2.0.3",
"socket.io-client": "^2.0.3",
"uuid": "^3.0.1"
"pouchdb": "^8.0.1",
"pouchdb-find": "^8.0.1",
"tslib": "^2.3.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/mocha": "^2.2.41",
"browserify": "^14.4.0",
"mocha": "^2.5.3",
"should": "^4.3.0",
"source-map-support": "^0.4.15",
"typescript": "^2.3.4"
"module": "fesm2015/cqrs.mjs",
"es2020": "fesm2020/cqrs.mjs",
"esm2020": "esm2020/cqrs.mjs",
"fesm2020": "fesm2020/cqrs.mjs",
"fesm2015": "fesm2015/cqrs.mjs",
"typings": "index.d.ts",
"exports": {
"./package.json": {
"default": "./package.json"
},
".": {
"types": "./index.d.ts",
"esm2020": "./esm2020/cqrs.mjs",
"es2020": "./fesm2020/cqrs.mjs",
"es2015": "./fesm2015/cqrs.mjs",
"node": "./fesm2015/cqrs.mjs",
"default": "./fesm2020/cqrs.mjs"
}
},
"engines": {
"node": ">=8.0.0"
}
}
"sideEffects": false
}

@@ -1,196 +0,24 @@

CQRS
====
DDD-CQRS-Actor framework.
### Document [ [chinese](https://github.com/liangzeng/cqrs/wiki) ]
# Cqrs
Version
=======
cqrs@2.0.6-pre
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 15.0.0.
Install
=======
## Code scaffolding
npm install cqrs@2.0.6-pre --save
Run `ng generate component component-name --project cqrs` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project cqrs`.
> Note: Don't forget to add `--project cqrs` or else it will be added to the default project in your `angular.json` file.
Consumers
=========
+ [Node.js Forum](https://github.com/liangzeng/forum)
## Build
EventStore
==========
+ [mongodb eventstore](https://github.com/liangzeng/cqrs-mongo-eventstore)
```js
const {Domain} = require("cqrs");
const MongoStore = require("cqrs-mongo-eventstore").default;
const eventstore = new MongoStore("localhost/test");
const domain = new Domain({eventstore});
```
Run `ng build cqrs` to build the project. The build artifacts will be stored in the `dist/` directory.
Roadmap
=======
+ preview core
+ use typescript rewrite core
+ saga rollback
+ join the distributed system
+ Actor version support
+ ~~use protobuf message~~
+ ~~actor GC~~
+ ~~system time travel~~
+ ~~DCI support~~
## Publishing
After building your library with `ng build cqrs`, go to the dist folder `cd dist/cqrs` and run `npm publish`.
Step
====
## Running unit tests
#### create Actor class
Run `ng test cqrs` to execute the unit tests via [Karma](https://karma-runner.github.io).
```js
const { Actor } = require("cqrs");
class User extends Actor { /* see example */ }
class Transfer extends Actor { /* see example */ }
```
#### register Actor class to domain
## Further help
```js
const { domain } = require("cqrs"); // get default domain.
domain.register(User).register(Transfer);
```
#### create/get an Actor instance
```js
// 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
===============
see ES6 [Example](https://github.com/liangzeng/cqrs/tree/master/example)
#### User.js
```js
const { Actor } = require("cqrs");
module.exports = class User extends Actor {
constructor(data) {
super({ money: data.money || 0, name: data.name });
}
changename(name) {
this.$(name);
}
deduct(money) {
this.$("deduct", money);
}
add(money) {
this.service.apply("add", money);
}
when(event) {
const data = this.json;
switch (event.type) {
case "changename":
return { name: event.name }
case "deduct":
return { money: data.money - event.data }
case "add":
return { money: data.money + event.data }
}
}
}
```
#### Transfer.js
```js
const { Actor } = require("cqrs");
module.exports = class Transfer extends Actor {
constructor(data) {
super({ finish: false });
}
log(event) {
console.log(event);
}
async transfe(fromUserId, toUserId, money) {
const $ = this.$;
$.lock();
$.once({ actorType: "User", type: "add" }, "log");
const fromUser = await $.get("User", fromUserId);
const toUser = await $.get("User", toUserId);
fromUser.deduct(money);
toUser.add(money);
$.unlock();
$("finish", null);
}
when(event) {
switch (event.type) {
case "finish":
return { finish: true }
}
}
}
```
#### main.js
```js
const { domain, Actor } = require("cqrs");
const User = require("./User");
const Transfer = require("./Transfer");
domain.register(User).register(Transfer);
async function main() {
let fromUser = await domain.create("User", { name: "fromUser" });
fromUser.add(100);
let toUser = await domain.create("User", { name: "toUser" });
const transfer = await domain.create("Transfer", {});
await transfer.transfe(fromUser.id, toUser.id, 15);
fromUser = await domain.get("User", fromUser.id);
toUser = await domain.get("User", toUser.id);
console.log("fromUser's money is " , fromUser.json.money);
console.log("toUser's money is " , toUser.json.money);
}
main();
```
#### out
```
fromUser's money is 85
toUser's money is 15
Event {
data: 100,
type: 'add',
method: 'add',
sagaId: undefined,
index: 0,
id: '6459e760-558e-11e7-87a3-9b10ea692d1e',
actorId: '645887d0-558e-11e7-87a3-9b10ea692d1e',
actorType: 'User',
actorVersion: '1.0',
date: 2017-06-20T07:59:31.542Z }
```
LICENSE
=======
GPL2.0
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc