Skip to content

Commit

Permalink
chore: add more readme (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartekCK committed May 17, 2023
1 parent 9ececd8 commit 633dacb
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 7 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# @ddd-master/* root repository

[![npm](https://img.shields.io/npm/v/@ddd-master/result?color=blue&label=%40ddd-master%2Fresult)](https://www.npmjs.com/package/@ddd-master/result)
[![npm](https://img.shields.io/npm/v/@ddd-master/command-bus?color=blue&label=%40ddd-master%2Fcommand-bus)](https://www.npmjs.com/package/@ddd-master/command-bus)
[![npm](https://img.shields.io/npm/v/@ddd-master/query-bus?color=blue&label=%40ddd-master%2Fquery-bus)](https://www.npmjs.com/package/@ddd-master/query-bus)


The `ddd-master` monorepo is a collection of TypeScript packages designed to support Domain-Driven Design (DDD) architecture in your applications. It includes the following packages:

1. [`@ddd-master/result`](https://github.com/BartekCK/ddd-master/tree/master/libs/result): A package for handling success and failure results in DDD applications.
2. [`@ddd-master/command-bus`](https://github.com/BartekCK/ddd-master/tree/master/libs/command-bus): A package for implementing the command bus pattern in DDD applications.
3. [`@ddd-master/query-bus`](https://github.com/BartekCK/ddd-master/tree/master/libs/query-bus): A package for implementing the query bus pattern in DDD applications.
1. [`@ddd-master/result`](https://github.com/BartekCK/ddd-master/tree/master/libs/result): A package for handling success and failure results in DDD applications.
2. [`@ddd-master/command-bus`](https://github.com/BartekCK/ddd-master/tree/master/libs/command-bus): A package for implementing the command bus pattern in DDD applications.
3. [`@ddd-master/query-bus`](https://github.com/BartekCK/ddd-master/tree/master/libs/query-bus): A package for implementing the query bus pattern in DDD applications.

## Installation

Expand All @@ -31,6 +36,8 @@ The `@ddd-master/command-bus` package implements the command bus pattern in DDD
The `@ddd-master/query-bus` package implements the query bus pattern in DDD applications. It provides a mechanism for executing queries and retrieving query results in a centralized and efficient manner. You can find more details about this package in the [`@ddd-master/query-bus` README](https://github.com/BartekCK/ddd-master/tree/master/libs/query-bus).

## How to release new lib version


1. Create new branch from `master` with name `release/vX.X.X`
2. Update version in `package.json` and `package-lock.json` files by command
```bash
Expand All @@ -53,5 +60,4 @@ Contributions to the `ddd-master` monorepo are welcome! Feel free to open issues

## License

The `ddd-master` monorepo and its packages are open-source software licensed under the [MIT License](https://github.com/BartekCK/ddd-master/blob/master/LICENSE

The `ddd-master` monorepo and its packages are open-source software licensed under the [MIT License](https://github.com/BartekCK/ddd-master/blob/master/LICENSE).
93 changes: 93 additions & 0 deletions libs/command-bus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# @ddd-master/command-bus package

[![npm](https://img.shields.io/npm/v/@ddd-master/command-bus?color=blue&label=%40ddd-master%2Fcommand-bus)](https://www.npmjs.com/package/@ddd-master/command-bus)

The `@ddd-master/command-bus` package is a TypeScript library that provides an implementation of the command bus pattern for Domain-Driven Design (DDD) applications. It allows you to execute commands and perform actions in a centralized and decoupled manner.

## Installation

You can install the `@ddd-master/command-bus` package using npm:

```bash
npm install @ddd-master/command-bus
```

## Usage

To use the `@ddd-master/command-bus` package, you need to define your commands and command handlers.

### Defining Commands

Commands represent actions or requests for changes in the system. You can define a command by implementing the `ICommand` interface. For example:

```typescript
export interface ICreateUserCommand extends ICommand {
email: string;
password: string;
}

export class CreateUserCommand implements ICreateUserCommand {
public readonly email: string;
public readonly password: string;

public constructor({ email, password }: ICreateUserCommand) {
this.email = email;
this.password = password;
}
}
```

### Defining Command Handlers

Command handlers are responsible for executing commands and performing the necessary actions. You can implement the `ICommandHandler` interface to define your command handlers. For example:

```typescript
export class CreateUserCommandHandler implements ICommandHandler<ICreateUserCommand, CreateUserCommandHandlerResult> {
private readonly userRepository: UserRepository;
public constructor({ userRepository }: Dependencies) {
this.userRepository = userRepository;
}

public handle(command: ICommand): CreateUserCommandHandlerResult {
const { email, password } = command as ICreateUserCommand;

const createdUser: User = { email, password };

this.userRepository.save({ user: createdUser });

return { email, password };
}
}
```

### Registering Command Handlers

Once you have your command handlers, you need to register them with the command bus. For example:

```typescript
const commandBus = new CommandBus();
const createUserCommandHandler = new CreateUserCommandHandler();
commandBus.register(CreateUserCommand, createUserCommandHandler);
```

### Executing Commands

To execute a command, you can use the `execute` method of the command bus. For example:

```typescript
const result = commandBus.execute<ICreateUserCommand, CreateUserCommandHandlerResult>(
new CreateUserCommand({ email: '[email protected]', password: '123456' }),
);

const { email, password } = result;
console.log(email, password);
```
The `execute` method returns the result of the command handler. You can access the result and process it accordingly.

## Contributing

Contributions to the `@ddd-master/command-bus` package are welcome! Feel free to open issues or submit pull requests on the [GitHub repository](https://github.com/BartekCK/ddd-master/tree/master/libs/command-bus). Please follow the [code of conduct](https://github.com/BartekCK/ddd-master/blob/master/CODE_OF_CONDUCT.md) when contributing.

## License

The `@ddd-master/command-bus` package is open-source software licensed under the [MIT License](https://github.com/BartekCK/ddd-master/blob/master/LICENSE).
1 change: 1 addition & 0 deletions libs/command-bus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"url": "https://github.com/BartekCK/ddd-master.git",
"directory": "libs/command-bus"
},
"license": "MIT",
"description": "Command bus implementation",
"author": {
"email": "[email protected]"
Expand Down
93 changes: 93 additions & 0 deletions libs/query-bus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# @ddd-master/query-bus package

[![npm](https://img.shields.io/npm/v/@ddd-master/query-bus?color=blue&label=%40ddd-master%2Fquery-bus)](https://www.npmjs.com/package/@ddd-master/query-bus)

The `@ddd-master/query-bus` package is a TypeScript library that provides an implementation of the query bus pattern for Domain-Driven Design (DDD) applications. It enables you to execute queries and retrieve query results in a centralized and efficient manner.

## Installation

You can install the `@ddd-master/query-bus` package using npm:

```bash
npm install @ddd-master/query-bus
```

## Usage

To use the `@ddd-master/query-bus` package, you need to define your queries and query handlers.

### Defining Queries

Queries represent requests for information or data retrieval. You can define a query by implementing the `IQuery` interface. For example:

```typescript
export interface IFindUserQuery extends IQuery {
email: string;
}

export class FindUserQuery implements IFindUserQuery {
public readonly email: string;

public constructor({ email }: IFindUserQuery) {
this.email = email;
}
}
```

### Defining Query Handlers

Query handlers are responsible for executing queries and returning the query results. You can implement the `IQueryHandler` interface to define your query handlers. For example:

```typescript
export class FindUserQueryHandler implements IQueryHandler<IFindUserQuery, FindUserQueryHandlerResult> {
private readonly userRepository: UserRepository;
public constructor({ userRepository }: Dependencies) {
this.userRepository = userRepository;
}

public handle(query: IQuery): FindUserQueryHandlerResult {
const { email } = query as IFindUserQuery;

const user = this.userRepository.getByEmail({ email });

if (!user) {
throw new Error('User not found');
}

return { user };
}
}
```

### Registering Query Handlers

Once you have your query handlers, you need to register them with the query bus. For example:

```typescript
const queryBus = new QueryBus();
const findUserQueryHandler = new FindUserQueryHandler();
queryBus.register(FindUserQuery, findUserQueryHandler);
```

### Executing Queries

To execute a query, you can use the `execute` method of the query bus. For example:

```typescript
const result = queryBus.execute<IFindUserQuery, FindUserQueryHandlerResult>(
new FindUserQuery({ email: '[email protected]' }),
);

const { user } = result;
console.log(user);
```

The `execute` method returns the query result. You can access the result and process it accordingly.

## Contributing

Contributions to the `@ddd-master/query-bus` package are welcome! Feel free to open issues or submit pull requests on the [GitHub repository](https://github.com/BartekCK/ddd-master/tree/master/libs/query-bus). Please follow the [code of conduct](https://github.com/BartekCK/ddd-master/blob/master/CODE_OF_CONDUCT.md) when contributing.

## License

The `@ddd-master/query-bus` package is open-source software licensed under the [MIT License](https://github.com/BartekCK/ddd-master/blob/master/LICENSE).
1 change: 1 addition & 0 deletions libs/query-bus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"url": "https://github.com/BartekCK/ddd-master.git",
"directory": "libs/query-bus"
},
"license": "MIT",
"description": "Query bus implementation",
"author": {
"email": "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions libs/result/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ddd-master Result Library
# @ddd-master/result package

[![npm version](https://badge.fury.io/js/%40ddd-master%2Fresult.svg)](https://badge.fury.io/js/%40ddd-master%2Fresult)
[![npm](https://img.shields.io/npm/v/@ddd-master/result?color=blue&label=%40ddd-master%2Fresult)](https://www.npmjs.com/package/@ddd-master/result)

The `@ddd-master/result` library is a TypeScript package that provides a set of classes and types for handling success and failure results in Domain-Driven Design (DDD) applications. It enables you to encapsulate and communicate the outcome of operations in a structured and type-safe manner.

Expand Down
1 change: 1 addition & 0 deletions libs/result/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"url": "https://github.com/BartekCK/ddd-master.git",
"directory": "libs/result"
},
"license": "MIT",
"description": "DDD Result pattern implementation",
"author": {
"email": "[email protected]"
Expand Down

0 comments on commit 633dacb

Please sign in to comment.