New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eventric

Package Overview
Dependencies
Maintainers
4
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventric - npm Package Compare versions

Comparing version 0.0.26 to 0.0.27

2

package.json

@@ -21,3 +21,3 @@ {

"author": "eFa Team <team@efa-gmbh.com>",
"version": "0.0.26",
"version": "0.0.27",
"repository": {

@@ -24,0 +24,0 @@ "type": "git",

@@ -10,16 +10,9 @@ > Not released yet. This hint will disappear with version 0.1.0.

Information regarding the Building Blocks, Best Practices, API and more can be found in the [Wiki](https://github.com/efacilitation/eventric/wiki).
Basically you define a behavioural API using `commands` and `queries`. Executing a `command` eventually commands a registered `Aggregate` (think of it as an advanced Model). This will result in a so-called `DomainEvent`. The series of `DomainEvents` defines the state of your `Aggregate` and therefore of your application.
**eventric.js** will run on NodeJS as well as in the Browser. Depending on the scenario the `DomainEvents` get directly persisted into the eventric EventStore or send over a `RemoteService` first. The `RemoteService` can also be used to access your API remotely. This makes **eventric.js** really useful for distributed applications.
## Quick Start
Information regarding the API and more can be found in the [Wiki](https://github.com/efacilitation/eventric/wiki).
```shell
npm install eventric
```
For a brief overview on how to use eventric check out this example:
* [TodoApp Example](https://github.com/efacilitation/eventric/wiki/ExampleTodo)
## Philosophy

@@ -33,2 +26,101 @@

## Quick Start
Having discussed the upcoming **TodoApp Project** with the Business-Experts and fellow Developers it got clear that we needed a `BoundedContext` named `collaboration` as part of our application. It will provide the API to work with our `Todo` Aggregate at the DomainModel-Core.
### [Setup BoundedContext](https://github.com/efacilitation/eventric/wiki/eventric#eventricboundedcontext)
> Hint: You should `npm install eventric` and `npm install eventric-store-mongodb` first.
Let's get right into it and create our `BoundedContext`
```javascript
eventric = require('eventric');
collaborationContext = eventric.boundedContext();
```
### [Adding Aggregate](https://github.com/efacilitation/eventric/wiki/BoundedContext#addaggregate)
Now that we created the `collaborationContext` let's add our `Todo` Aggregate, consisting of a simple `changeDescription` method.
```javascript
collaborationContext.addAggregate('Todo', {
changeDescription: function(description) {
this.description = description;
}
});
```
> Hint: values assigned to `this.` are automatically part of the generated `DomainEvent`
### [Adding Commands](https://github.com/efacilitation/eventric/wiki/BoundedContext#addcommand)
To actually work with the `BoundedContext` from the outside world we need `commands` and `queries`. Let's start by adding a simple `command` that will create an instance of our `Todo` Aggregate.
```javascript
collaborationContext.addCommand('createTodo', function(params, callback) {
this.aggregate.create('Todo', callback);
});
```
> Hint: `this.aggregate` is dependency injected
It would be nice if we could change the description of the `Todo`, so let's add this `command` too.
```javascript
collaborationContext.addCommand('changeTodoDescription', function(params, callback) {
this.aggregate.command('Todo', params.id, 'changeDescription', params.description, callback);
});
```
> Hint: If successful this will trigger a *Todo:changeDescription* `DomainEvent`
### [Adding Query](https://github.com/efacilitation/eventric/wiki/BoundedContext#addquery)
And last but not least we want the ability to `query` for a `Todo` by its id.
```javascript
collaborationContext.addQuery('getTodoById', function(params, callback) {
this.repository('Todo').findById(params.id, callback);
});
```
> Hint: `this.repository` is dependency injected
### Executing [Commands](https://github.com/efacilitation/eventric/wiki/BoundedContext#command) and [Queries](https://github.com/efacilitation/eventric/wiki/BoundedContext#query)
Initialize the `collaborationContext`, create a `Todo`, change the description of it and finally query the description again.
```javascript
collaborationContext.initialize(function() {
collaborationContext.command({
name: 'createTodo'
},
function(err, todoId) {
collaborationContext.command({
name: 'changeTodoDescription',
params: {
id: todoId,
description: 'Do something'
}
},
function(err, status) {
collaborationContext.query({
name: 'getTodoById',
params: {
id: todoId
}
},
function(err, readTodo) {
console.log(readTodo.description);
})
});
});
});
```
> `eventric` will implement [promises](https://github.com/kriskowal/q) to avoid such a "[Pyramid of Doom](http://calculist.org/blog/2011/12/14/why-coroutines-wont-work-on-the-web/)" in the future.
This will output `Do something`. Your `Todo` Aggregate is now persisted using EventSourcing.
Congratulations, you have successfully applied DDD (tactical+technical) and CQRS! :)
## Running Tests

@@ -35,0 +127,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc