@wallentaine/cqrs-schematics 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/lib/schematics/command/files/__name__.commandHandler.ts.template +4 -2
- package/lib/schematics/event/files/__name__.event.ts.template +3 -3
- package/lib/schematics/event/files/__name__.eventHandler.ts.template +8 -6
- package/lib/schematics/query/files/__name__.queryHandler.ts.template +4 -2
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# CQRS Schematics for NestJS
|
|
2
|
+
|
|
3
|
+
Кастомные схемытики для быстрой генерации CQRS-файлов в NestJS.
|
|
4
|
+
|
|
5
|
+
## Установка
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i -D @wallentaine/cqrs-schematics
|
|
9
|
+
# или
|
|
10
|
+
yarn add --dev @wallentaine/cqrs-schematics
|
|
11
|
+
# или
|
|
12
|
+
pnpm add --dev @wallentaine/cqrs-schematics
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Использование
|
|
16
|
+
|
|
17
|
+
### Базовые команды
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Command
|
|
21
|
+
nest g -c @wallentaine/cqrs-schematics command <Name>
|
|
22
|
+
|
|
23
|
+
# Query
|
|
24
|
+
nest g -c @wallentaine/cqrs-schematics query <Name>
|
|
25
|
+
|
|
26
|
+
# Event
|
|
27
|
+
nest g -c @wallentaine/cqrs-schematics event <Name>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Примеры
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
nest g -c @wallentaine/cqrs-schematics command CreateUser
|
|
34
|
+
nest g -c @wallentaine/cqrs-schematics query GetUserProfile
|
|
35
|
+
nest g -c @wallentaine/cqrs-schematics event UserCreated
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Bash алиасы (добавьте в ~/.bashrc или ~/.zshrc)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
alias ngc="nest g -c @wallentaine/cqrs-schematics command"
|
|
42
|
+
alias ngq="nest g -c @wallentaine/cqrs-schematics query"
|
|
43
|
+
alias nge="nest g -c @wallentaine/cqrs-schematics event"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Теперь комады будут выглядеть так:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
ngc CreatePost
|
|
50
|
+
ngq FindPostById
|
|
51
|
+
nge PostCreated
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Что генерируется
|
|
55
|
+
|
|
56
|
+
Для каждой команды создаются:
|
|
57
|
+
|
|
58
|
+
- Файл с самой командой/запросом/событием
|
|
59
|
+
- Файл `handler` с готовым шаблоном обработчика
|
|
60
|
+
- Файл `httpController` с готовым шаблоном контроллера(для `command` и `query`)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Пример для CreatePost:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
src/commands/CreatePost.command.ts
|
|
67
|
+
src/commands/handlers/CreatePost.commandHandler.ts
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Регистрация
|
|
71
|
+
|
|
72
|
+
Не забудьте добавить обработчик и контроллер в providers модуля:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
@Module({
|
|
76
|
+
providers: [CreatePostCommandHandler, FindPostByIdQueryHandler],
|
|
77
|
+
controllers: [CreatePostHttpController, FindPostByIdHttpController],
|
|
78
|
+
})
|
|
79
|
+
export class PostModule {}
|
|
80
|
+
```
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { Logger } from "@nestjs/common";
|
|
1
2
|
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
|
2
3
|
import { <%= className %>Command } from './<%= name %>.command';
|
|
3
4
|
|
|
4
5
|
@CommandHandler(<%= className %>Command)
|
|
5
6
|
export class <%= className %>CommandHandler implements ICommandHandler<<%= className %>Command> {
|
|
6
|
-
|
|
7
|
+
private readonly logger = new Logger(<%= className %>CommandHandler.name);
|
|
8
|
+
|
|
7
9
|
public constructor() {}
|
|
8
10
|
|
|
9
|
-
async execute(command: <%= className %>Command): Promise<
|
|
11
|
+
async execute(command: <%= className %>Command): Promise<void> {
|
|
10
12
|
// Implement your command logic here
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApplicationEvent, ApplicationEventProps } from '@Libs/Application/Application.event';
|
|
2
2
|
|
|
3
|
-
export class <%= className %>
|
|
4
|
-
public constructor(props:
|
|
3
|
+
export class <%= className %>Event extends ApplicationEvent {
|
|
4
|
+
public constructor(props: ApplicationEventProps<<%= className %>Event>) {
|
|
5
5
|
super();
|
|
6
6
|
}
|
|
7
7
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ApplicationEventProps } from "@Libs/Application/Application.event";
|
|
2
|
+
import { Logger } from "@nestjs/common";
|
|
3
|
+
import { OnEvent } from "@nestjs/event-emitter";
|
|
4
|
+
|
|
5
|
+
export class <%= className %>EventHandler {
|
|
6
|
+
private readonly logger = new Logger(<%= className %>EventHandler.name);
|
|
3
7
|
|
|
4
|
-
@QueryHandler(<%= className %>Query)
|
|
5
|
-
export class <%= className %>QueryHandler implements IQueryHandler<<%= className %>Query> {
|
|
6
|
-
|
|
7
8
|
public constructor() {}
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
@OnEvent()
|
|
11
|
+
async handle(event: ApplicationEventProps<<%= className %>Event>): Promise<void> {
|
|
10
12
|
// Implement your query logic here
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { Logger } from "@nestjs/common";
|
|
1
2
|
import { QueryHandler, IQueryHandler } from '@nestjs/cqrs';
|
|
2
3
|
import { <%= className %>Query } from './<%= name %>.query';
|
|
3
4
|
|
|
4
5
|
@QueryHandler(<%= className %>Query)
|
|
5
6
|
export class <%= className %>QueryHandler implements IQueryHandler<<%= className %>Query> {
|
|
6
|
-
|
|
7
|
+
private readonly logger = new Logger(<%= className %>QueryHandler.name);
|
|
8
|
+
|
|
7
9
|
public constructor() {}
|
|
8
10
|
|
|
9
|
-
async execute(query: <%= className %>Query): Promise<
|
|
11
|
+
async execute(query: <%= className %>Query): Promise<void> {
|
|
10
12
|
// Implement your query logic here
|
|
11
13
|
}
|
|
12
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wallentaine/cqrs-schematics",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"lib/**/*",
|
|
12
|
-
"collection.json"
|
|
12
|
+
"collection.json",
|
|
13
|
+
"README.md"
|
|
13
14
|
],
|
|
14
15
|
"keywords": [
|
|
15
16
|
"nestjs",
|