pp-command-bus 1.0.0
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 +522 -0
- package/dist/command-bus/command-bus.spec.d.ts +1 -0
- package/dist/command-bus/command-bus.spec.js +398 -0
- package/dist/command-bus/command-bus.spec.js.map +1 -0
- package/dist/command-bus/command.d.ts +24 -0
- package/dist/command-bus/command.js +53 -0
- package/dist/command-bus/command.js.map +1 -0
- package/dist/command-bus/config/command-bus-config.d.ts +40 -0
- package/dist/command-bus/config/command-bus-config.js +59 -0
- package/dist/command-bus/config/command-bus-config.js.map +1 -0
- package/dist/command-bus/config/command-bus-config.spec.d.ts +1 -0
- package/dist/command-bus/config/command-bus-config.spec.js +162 -0
- package/dist/command-bus/config/command-bus-config.spec.js.map +1 -0
- package/dist/command-bus/config/index.d.ts +1 -0
- package/dist/command-bus/config/index.js +9 -0
- package/dist/command-bus/config/index.js.map +1 -0
- package/dist/command-bus/index.d.ts +79 -0
- package/dist/command-bus/index.js +169 -0
- package/dist/command-bus/index.js.map +1 -0
- package/dist/command-bus/job/index.d.ts +6 -0
- package/dist/command-bus/job/index.js +15 -0
- package/dist/command-bus/job/index.js.map +1 -0
- package/dist/command-bus/job/job-options-builder.d.ts +24 -0
- package/dist/command-bus/job/job-options-builder.js +68 -0
- package/dist/command-bus/job/job-options-builder.js.map +1 -0
- package/dist/command-bus/job/job-options-builder.spec.d.ts +1 -0
- package/dist/command-bus/job/job-options-builder.spec.js +163 -0
- package/dist/command-bus/job/job-options-builder.spec.js.map +1 -0
- package/dist/command-bus/job/job-processor.d.ts +33 -0
- package/dist/command-bus/job/job-processor.js +195 -0
- package/dist/command-bus/job/job-processor.js.map +1 -0
- package/dist/command-bus/job/job-processor.spec.d.ts +1 -0
- package/dist/command-bus/job/job-processor.spec.js +352 -0
- package/dist/command-bus/job/job-processor.spec.js.map +1 -0
- package/dist/command-bus/logging/command-logger.d.ts +21 -0
- package/dist/command-bus/logging/command-logger.js +79 -0
- package/dist/command-bus/logging/command-logger.js.map +1 -0
- package/dist/command-bus/logging/command-logger.spec.d.ts +1 -0
- package/dist/command-bus/logging/command-logger.spec.js +245 -0
- package/dist/command-bus/logging/command-logger.spec.js.map +1 -0
- package/dist/command-bus/logging/index.d.ts +5 -0
- package/dist/command-bus/logging/index.js +13 -0
- package/dist/command-bus/logging/index.js.map +1 -0
- package/dist/command-bus/queue/index.d.ts +5 -0
- package/dist/command-bus/queue/index.js +13 -0
- package/dist/command-bus/queue/index.js.map +1 -0
- package/dist/command-bus/queue/queue-manager.d.ts +24 -0
- package/dist/command-bus/queue/queue-manager.js +60 -0
- package/dist/command-bus/queue/queue-manager.js.map +1 -0
- package/dist/command-bus/queue/queue-manager.spec.d.ts +1 -0
- package/dist/command-bus/queue/queue-manager.spec.js +219 -0
- package/dist/command-bus/queue/queue-manager.spec.js.map +1 -0
- package/dist/command-bus/rpc/index.d.ts +5 -0
- package/dist/command-bus/rpc/index.js +13 -0
- package/dist/command-bus/rpc/index.js.map +1 -0
- package/dist/command-bus/rpc/rpc-coordinator.d.ts +45 -0
- package/dist/command-bus/rpc/rpc-coordinator.js +189 -0
- package/dist/command-bus/rpc/rpc-coordinator.js.map +1 -0
- package/dist/command-bus/rpc/rpc-coordinator.spec.d.ts +1 -0
- package/dist/command-bus/rpc/rpc-coordinator.spec.js +286 -0
- package/dist/command-bus/rpc/rpc-coordinator.spec.js.map +1 -0
- package/dist/command-bus/types/index.d.ts +57 -0
- package/dist/command-bus/types/index.js +3 -0
- package/dist/command-bus/types/index.js.map +1 -0
- package/dist/command-bus/worker/index.d.ts +5 -0
- package/dist/command-bus/worker/index.js +13 -0
- package/dist/command-bus/worker/index.js.map +1 -0
- package/dist/command-bus/worker/worker-orchestrator.d.ts +46 -0
- package/dist/command-bus/worker/worker-orchestrator.js +160 -0
- package/dist/command-bus/worker/worker-orchestrator.js.map +1 -0
- package/dist/command-bus/worker/worker-orchestrator.spec.d.ts +1 -0
- package/dist/command-bus/worker/worker-orchestrator.spec.js +293 -0
- package/dist/command-bus/worker/worker-orchestrator.spec.js.map +1 -0
- package/dist/examples/rpc.demo.d.ts +2 -0
- package/dist/examples/rpc.demo.js +235 -0
- package/dist/examples/rpc.demo.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/pp-command-bus-1.0.0.tgz +0 -0
- package/dist/shared/config/base-config.d.ts +43 -0
- package/dist/shared/config/base-config.js +100 -0
- package/dist/shared/config/base-config.js.map +1 -0
- package/dist/shared/config/base-config.spec.d.ts +1 -0
- package/dist/shared/config/base-config.spec.js +118 -0
- package/dist/shared/config/base-config.spec.js.map +1 -0
- package/dist/shared/config/index.d.ts +1 -0
- package/dist/shared/config/index.js +9 -0
- package/dist/shared/config/index.js.map +1 -0
- package/dist/shared/logging/index.d.ts +2 -0
- package/dist/shared/logging/index.js +8 -0
- package/dist/shared/logging/index.js.map +1 -0
- package/dist/shared/logging/log-level.d.ts +36 -0
- package/dist/shared/logging/log-level.js +53 -0
- package/dist/shared/logging/log-level.js.map +1 -0
- package/dist/shared/logging/logger.d.ts +42 -0
- package/dist/shared/logging/logger.js +63 -0
- package/dist/shared/logging/logger.js.map +1 -0
- package/dist/shared/logging/logger.spec.d.ts +1 -0
- package/dist/shared/logging/logger.spec.js +89 -0
- package/dist/shared/logging/logger.spec.js.map +1 -0
- package/dist/shared/types.d.ts +26 -0
- package/dist/shared/types.js +6 -0
- package/dist/shared/types.js.map +1 -0
- package/package.json +93 -0
package/README.md
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
# PP Command Bus
|
|
2
|
+
|
|
3
|
+
Distributed Command Bus library supporting RPC and job queuing with BullMQ for Redis/DragonflyDB.
|
|
4
|
+
|
|
5
|
+
## Opis
|
|
6
|
+
|
|
7
|
+
**pp-command-bus** to biblioteka do obsługi rozproszonych komend zgodna ze wzorcem **CQRS (Command Query Responsibility Segregation)**. Wspiera:
|
|
8
|
+
|
|
9
|
+
- ✅ **Fire-and-forget commands** - wysyłanie komend bez oczekiwania na wynik
|
|
10
|
+
- ✅ **RPC (Remote Procedure Call)** - synchroniczne wywołania z oczekiwaniem na odpowiedź
|
|
11
|
+
- ✅ **Job queuing** - kolejkowanie zadań z retry, backoff i delayed execution
|
|
12
|
+
- ✅ **BullMQ integration** - wydajna kolejka zadań na Redis/DragonflyDB
|
|
13
|
+
- ✅ **TypeScript** - pełne wsparcie typów i strict mode
|
|
14
|
+
- ✅ **Memory leak protection** - zaawansowana diagnostyka i cleanup
|
|
15
|
+
- ✅ **Command logging** - opcjonalne logowanie komend do plików
|
|
16
|
+
|
|
17
|
+
## Instalacja
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install pp-command-bus
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Wymagania
|
|
24
|
+
|
|
25
|
+
- Node.js >= 14
|
|
26
|
+
- Redis >= 5 lub DragonflyDB
|
|
27
|
+
- TypeScript >= 4.5 (opcjonalnie)
|
|
28
|
+
|
|
29
|
+
## Szybki start
|
|
30
|
+
|
|
31
|
+
### 1. Konfiguracja
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { CommandBus, CommandBusConfig, Command } from 'pp-command-bus';
|
|
35
|
+
|
|
36
|
+
// Konfiguracja CommandBus
|
|
37
|
+
const config = new CommandBusConfig({
|
|
38
|
+
redis: {
|
|
39
|
+
host: 'localhost',
|
|
40
|
+
port: 6379,
|
|
41
|
+
},
|
|
42
|
+
logger: console, // ILogger interface
|
|
43
|
+
concurrency: 5,
|
|
44
|
+
maxAttempts: 3,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Utwórz instancję CommandBus
|
|
48
|
+
const commandBus = new CommandBus(config);
|
|
49
|
+
|
|
50
|
+
// Poczekaj na gotowość (opcjonalnie)
|
|
51
|
+
await commandBus.waitUntilReady();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Definiowanie komend
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
class CreateUserCommand extends Command {
|
|
58
|
+
constructor(
|
|
59
|
+
public readonly email: string,
|
|
60
|
+
public readonly name: string,
|
|
61
|
+
) {
|
|
62
|
+
super();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 3. Rejestracja handlerów
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
commandBus.handle(CreateUserCommand, async (command) => {
|
|
71
|
+
console.log(`Creating user: ${command.name} (${command.email})`);
|
|
72
|
+
|
|
73
|
+
// Twoja logika biznesowa
|
|
74
|
+
const user = await createUser(command.email, command.name);
|
|
75
|
+
|
|
76
|
+
// Zwróć wynik (opcjonalnie)
|
|
77
|
+
return { userId: user.id };
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 4. Wysyłanie komend (Fire-and-forget)
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const command = new CreateUserCommand('jan.kowalski@example.com', 'Jan Kowalski');
|
|
85
|
+
|
|
86
|
+
// Wyślij komendę bez oczekiwania na wynik
|
|
87
|
+
await commandBus.dispatch(command);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 5. RPC - wywołania synchroniczne
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// Wywołaj komendę i poczekaj na wynik
|
|
94
|
+
const result = await commandBus.call<{ userId: string }>(command, 5000); // timeout 5s
|
|
95
|
+
|
|
96
|
+
console.log(`User created with ID: ${result.userId}`);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Konfiguracja zaawansowana
|
|
100
|
+
|
|
101
|
+
### Opcje Redis
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
const config = new CommandBusConfig({
|
|
105
|
+
redis: {
|
|
106
|
+
host: 'localhost',
|
|
107
|
+
port: 6379,
|
|
108
|
+
password: 'your-password',
|
|
109
|
+
db: 0,
|
|
110
|
+
maxRetriesPerRequest: 3,
|
|
111
|
+
enableReadyCheck: true,
|
|
112
|
+
enableOfflineQueue: true,
|
|
113
|
+
},
|
|
114
|
+
// ... pozostałe opcje
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### RPC Persistence
|
|
119
|
+
|
|
120
|
+
Zapisywanie pending RPC calls do Redis dla odporności na restarty:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const config = new CommandBusConfig({
|
|
124
|
+
// ... redis config
|
|
125
|
+
rpcPersistence: true, // Włącz persistence
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Command Logging
|
|
130
|
+
|
|
131
|
+
Logowanie komend do plików w formacie JSON:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
const config = new CommandBusConfig({
|
|
135
|
+
// ... redis config
|
|
136
|
+
commandLog: {
|
|
137
|
+
enabled: true,
|
|
138
|
+
directory: './command-logs',
|
|
139
|
+
rotationInterval: 3600000, // 1 godzina
|
|
140
|
+
maxFiles: 24, // Zachowaj 24 pliki
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Concurrency i Retry
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const config = new CommandBusConfig({
|
|
149
|
+
// ... redis config
|
|
150
|
+
concurrency: 10, // Liczba równoległych workerów
|
|
151
|
+
maxAttempts: 5, // Maksymalna liczba prób
|
|
152
|
+
replyWorkerConcurrency: 3, // Concurrency dla reply workera
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Custom Logger
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import type { ILogger } from 'pp-command-bus';
|
|
160
|
+
|
|
161
|
+
class MyLogger implements ILogger {
|
|
162
|
+
log(message: string, ...args: unknown[]): void {
|
|
163
|
+
// Twoja implementacja
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
error(message: string, ...args: unknown[]): void {
|
|
167
|
+
// Twoja implementacja
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
warn(message: string, ...args: unknown[]): void {
|
|
171
|
+
// Twoja implementacja
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
debug(message: string, ...args: unknown[]): void {
|
|
175
|
+
// Twoja implementacja
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const config = new CommandBusConfig({
|
|
180
|
+
// ... redis config
|
|
181
|
+
logger: new MyLogger(),
|
|
182
|
+
logLevel: 'info', // debug | info | warn | error
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## API Reference
|
|
187
|
+
|
|
188
|
+
### CommandBus
|
|
189
|
+
|
|
190
|
+
#### `dispatch(command: Command): Promise<void>`
|
|
191
|
+
|
|
192
|
+
Wysyła komendę do kolejki bez oczekiwania na wynik (fire-and-forget).
|
|
193
|
+
|
|
194
|
+
#### `call<T>(command: Command, timeout?: number): Promise<T>`
|
|
195
|
+
|
|
196
|
+
Wywołuje komendę synchronicznie i czeka na odpowiedź (RPC). Domyślny timeout: 30s.
|
|
197
|
+
|
|
198
|
+
#### `handle<T>(commandClass, handler): void`
|
|
199
|
+
|
|
200
|
+
Rejestruje handler dla określonej klasy komendy.
|
|
201
|
+
|
|
202
|
+
#### `waitUntilReady(timeout?: number): Promise<void>`
|
|
203
|
+
|
|
204
|
+
Czeka aż CommandBus zakończy inicjalizację. Domyślny timeout: 30s.
|
|
205
|
+
|
|
206
|
+
#### `getMemoryStats(): MemoryStats`
|
|
207
|
+
|
|
208
|
+
Zwraca statystyki pamięci i wewnętrznego stanu (diagnostyka memory leaków).
|
|
209
|
+
|
|
210
|
+
#### `close(): Promise<void>`
|
|
211
|
+
|
|
212
|
+
Zamyka wszystkie połączenia i workery.
|
|
213
|
+
|
|
214
|
+
### Command
|
|
215
|
+
|
|
216
|
+
Klasa bazowa dla wszystkich komend. Każda komenda dziedziczy po `Command`:
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
class MyCommand extends Command {
|
|
220
|
+
constructor(public readonly data: string) {
|
|
221
|
+
super();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Każda komenda ma:
|
|
227
|
+
- `__id` - unikalny UUID
|
|
228
|
+
- `__name` - nazwa klasy komendy
|
|
229
|
+
- `__timestamp` - timestamp utworzenia
|
|
230
|
+
|
|
231
|
+
### CommandBusConfig
|
|
232
|
+
|
|
233
|
+
Konfiguracja CommandBus z opcjami:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
interface CommandBusConfigOptions {
|
|
237
|
+
redis: RedisOptions; // Opcje połączenia Redis
|
|
238
|
+
logger: ILogger; // Logger (console lub custom)
|
|
239
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error'; // Poziom logowania
|
|
240
|
+
concurrency?: number; // Liczba workerów (domyślnie 5)
|
|
241
|
+
maxAttempts?: number; // Maksymalna liczba prób (domyślnie 3)
|
|
242
|
+
replyWorkerConcurrency?: number; // Concurrency reply workera (domyślnie 1)
|
|
243
|
+
rpcPersistence?: boolean; // RPC persistence (domyślnie false)
|
|
244
|
+
commandLog?: CommandLogConfig; // Konfiguracja logowania komend
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Migracja z pp-event-bus 1.x
|
|
249
|
+
|
|
250
|
+
Jeśli używałeś Command Bus z pakietu `pp-event-bus` w wersji 1.x:
|
|
251
|
+
|
|
252
|
+
### Przed:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { CommandBus, Command, CommandBusConfig } from 'pp-event-bus';
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Po:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
npm install pp-command-bus
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { CommandBus, Command, CommandBusConfig } from 'pp-command-bus';
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**Pełna zgodność API** - jedyna zmiana to źródło importu.
|
|
269
|
+
|
|
270
|
+
## Best Practices
|
|
271
|
+
|
|
272
|
+
### 1. Używaj TypeScript
|
|
273
|
+
|
|
274
|
+
Biblioteka jest napisana w TypeScript z strict mode. Wykorzystaj typy dla lepszego DX:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
interface UserCreatedResult {
|
|
278
|
+
userId: string;
|
|
279
|
+
createdAt: Date;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const result = await commandBus.call<UserCreatedResult>(command);
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### 2. Idempotentne handlery
|
|
286
|
+
|
|
287
|
+
Handlery powinny być idempotentne (wielokrotne wykonanie = ten sam rezultat):
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
commandBus.handle(CreateUserCommand, async (command) => {
|
|
291
|
+
// Sprawdź czy użytkownik już istnieje
|
|
292
|
+
const existing = await findUserByEmail(command.email);
|
|
293
|
+
if (existing) {
|
|
294
|
+
return { userId: existing.id }; // Zwróć istniejącego
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Utwórz nowego
|
|
298
|
+
const user = await createUser(command.email, command.name);
|
|
299
|
+
return { userId: user.id };
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### 3. Obsługa błędów
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
commandBus.handle(CreateUserCommand, async (command) => {
|
|
307
|
+
try {
|
|
308
|
+
const user = await createUser(command.email, command.name);
|
|
309
|
+
return { userId: user.id };
|
|
310
|
+
} catch (error) {
|
|
311
|
+
// Loguj błąd
|
|
312
|
+
console.error('Failed to create user:', error);
|
|
313
|
+
|
|
314
|
+
// Rzuć błąd - BullMQ spróbuje ponownie (maxAttempts)
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### 4. Graceful shutdown
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
process.on('SIGTERM', async () => {
|
|
324
|
+
console.log('Shutting down CommandBus...');
|
|
325
|
+
await commandBus.close();
|
|
326
|
+
process.exit(0);
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### 5. Memory leak monitoring
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
setInterval(() => {
|
|
334
|
+
const stats = commandBus.getMemoryStats();
|
|
335
|
+
|
|
336
|
+
console.log('CommandBus memory stats:', {
|
|
337
|
+
pendingRpcCalls: stats.rpc.pendingCallsCount,
|
|
338
|
+
queueCount: stats.queues.commandQueuesCount,
|
|
339
|
+
replyQueuesCacheSize: stats.queues.replyQueuesCacheSize,
|
|
340
|
+
activeWorkers: stats.workers.activeWorkersCount,
|
|
341
|
+
});
|
|
342
|
+
}, 60000); // Co minutę
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Testing
|
|
346
|
+
|
|
347
|
+
### Unit testy
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
import { CommandBus, CommandBusConfig, Command } from 'pp-command-bus';
|
|
351
|
+
|
|
352
|
+
describe('User Commands', () => {
|
|
353
|
+
let commandBus: CommandBus;
|
|
354
|
+
|
|
355
|
+
beforeAll(async () => {
|
|
356
|
+
const config = new CommandBusConfig({
|
|
357
|
+
redis: { host: 'localhost', port: 6379 },
|
|
358
|
+
logger: console,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
commandBus = new CommandBus(config);
|
|
362
|
+
await commandBus.waitUntilReady();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
afterAll(async () => {
|
|
366
|
+
await commandBus.close();
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('should create user', async () => {
|
|
370
|
+
const command = new CreateUserCommand('test@example.com', 'Test User');
|
|
371
|
+
const result = await commandBus.call<{ userId: string }>(command);
|
|
372
|
+
|
|
373
|
+
expect(result.userId).toBeDefined();
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## Troubleshooting
|
|
379
|
+
|
|
380
|
+
### Connection refused (Redis)
|
|
381
|
+
|
|
382
|
+
Upewnij się że Redis działa:
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
redis-cli ping
|
|
386
|
+
# Powinno zwrócić: PONG
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Timeout na RPC call
|
|
390
|
+
|
|
391
|
+
Zwiększ timeout lub sprawdź czy handler został zarejestrowany:
|
|
392
|
+
|
|
393
|
+
```typescript
|
|
394
|
+
// Zwiększ timeout
|
|
395
|
+
const result = await commandBus.call(command, 60000); // 60s
|
|
396
|
+
|
|
397
|
+
// Sprawdź zarejestrowane handlery
|
|
398
|
+
const stats = commandBus.getMemoryStats();
|
|
399
|
+
console.log('Registered handlers:', stats.handlers.handlerNames);
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Memory leaks
|
|
403
|
+
|
|
404
|
+
Użyj `getMemoryStats()` do diagnostyki:
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
const stats = commandBus.getMemoryStats();
|
|
408
|
+
|
|
409
|
+
// Sprawdź pending RPC calls
|
|
410
|
+
if (stats.rpc.pendingCallsCount > 100) {
|
|
411
|
+
console.warn('Too many pending RPC calls!', stats.rpc.pendingCallsDetails);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Sprawdź reply queues cache
|
|
415
|
+
if (stats.queues.replyQueuesCacheSize > 50) {
|
|
416
|
+
console.warn('Reply queues cache too large!');
|
|
417
|
+
}
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
## Licencja
|
|
421
|
+
|
|
422
|
+
MIT
|
|
423
|
+
|
|
424
|
+
## Autorzy
|
|
425
|
+
- Mariusz Lejkowski <m.lejkowski@polskiepolisy.pl>
|
|
426
|
+
|
|
427
|
+
## Wersjonowanie i Releases
|
|
428
|
+
|
|
429
|
+
Projekt używa [Semantic Versioning](https://semver.org/lang/pl/) oraz automatycznych release'ów dzięki [semantic-release](https://github.com/semantic-release/semantic-release).
|
|
430
|
+
|
|
431
|
+
### Konwencja commitów
|
|
432
|
+
|
|
433
|
+
Używamy [Conventional Commits](https://www.conventionalcommits.org/):
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
# Nowa funkcjonalność (minor release)
|
|
437
|
+
feat: dodano wsparcie dla delayed commands
|
|
438
|
+
|
|
439
|
+
# Poprawka błędu (patch release)
|
|
440
|
+
fix: naprawiono memory leak w RPC
|
|
441
|
+
|
|
442
|
+
# Breaking change (major release)
|
|
443
|
+
feat!: zmieniono API CommandBusConfig
|
|
444
|
+
|
|
445
|
+
# Inne typy (patch release)
|
|
446
|
+
docs: zaktualizowano dokumentację API
|
|
447
|
+
perf: zoptymalizowano przetwarzanie komend
|
|
448
|
+
refactor: uproszczono kod RPC handler
|
|
449
|
+
test: dodano testy dla command logging
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### Typy commitów
|
|
453
|
+
|
|
454
|
+
- `feat:` - nowa funkcjonalność (→ minor release)
|
|
455
|
+
- `fix:` - poprawka błędu (→ patch release)
|
|
456
|
+
- `perf:` - optymalizacja wydajności (→ patch release)
|
|
457
|
+
- `docs:` - zmiany w dokumentacji (→ patch release)
|
|
458
|
+
- `style:` - formatowanie kodu (→ patch release)
|
|
459
|
+
- `refactor:` - refaktoryzacja (→ patch release)
|
|
460
|
+
- `test:` - dodanie/poprawka testów (→ patch release)
|
|
461
|
+
- `build:` - zmiany w buildzie/zależnościach (→ patch release)
|
|
462
|
+
- `ci:` - zmiany w CI/CD (→ patch release)
|
|
463
|
+
- `chore:` - inne zmiany (bez release)
|
|
464
|
+
- `!` lub `BREAKING CHANGE:` - breaking change (→ major release)
|
|
465
|
+
|
|
466
|
+
### Proces release
|
|
467
|
+
|
|
468
|
+
1. **Commituj zgodnie z konwencją** - husky sprawdzi format commita
|
|
469
|
+
2. **Merge do master** - GitLab CI automatycznie:
|
|
470
|
+
- Uruchomi testy i linting
|
|
471
|
+
- Zbuduje projekt
|
|
472
|
+
- Wygeneruje nową wersję (semantic-release)
|
|
473
|
+
- Zaktualizuje CHANGELOG.md
|
|
474
|
+
- Opublikuje do npm
|
|
475
|
+
- Utworzy GitLab release
|
|
476
|
+
|
|
477
|
+
### Branch model
|
|
478
|
+
|
|
479
|
+
- `master` - branch produkcyjny (→ release do npm)
|
|
480
|
+
- `beta` - branch pre-release (→ beta release do npm)
|
|
481
|
+
- feature branches - tworzenie nowych funkcjonalności
|
|
482
|
+
|
|
483
|
+
### CI/CD Pipeline
|
|
484
|
+
|
|
485
|
+
GitLab CI wykonuje następujące etapy:
|
|
486
|
+
|
|
487
|
+
**Quality Stage:**
|
|
488
|
+
- `lint` - sprawdzenie jakości kodu (ESLint + Prettier)
|
|
489
|
+
- `test` - testy jednostkowe i coverage
|
|
490
|
+
|
|
491
|
+
**Build Stage:**
|
|
492
|
+
- `build` - kompilacja TypeScript do JavaScript
|
|
493
|
+
|
|
494
|
+
**Release Stage:**
|
|
495
|
+
- `release:production` - automatyczny release z master
|
|
496
|
+
- `release:beta` - automatyczny release z beta
|
|
497
|
+
- `release:dry-run` - podgląd zmian (manual trigger)
|
|
498
|
+
|
|
499
|
+
### Zmienne środowiskowe w GitLab
|
|
500
|
+
|
|
501
|
+
Aby pipeline działał, skonfiguruj w GitLab CI/CD Settings → Variables:
|
|
502
|
+
|
|
503
|
+
- `NPM_TOKEN` - token do publikacji w npm (z scope publish)
|
|
504
|
+
- `GITLAB_TOKEN` - token do tworzenia release'ów w GitLab
|
|
505
|
+
|
|
506
|
+
### Testowanie release lokalnie
|
|
507
|
+
|
|
508
|
+
```bash
|
|
509
|
+
# Podgląd co zostanie wypuszczone
|
|
510
|
+
npm run semantic-release:dry-run
|
|
511
|
+
|
|
512
|
+
# Sprawdzenie ostatniego release
|
|
513
|
+
git tag --sort=-v:refname | head -n 1
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
## Linki
|
|
517
|
+
|
|
518
|
+
- [GitLab Repository](https://gitlab.polskiepolisy.pl/lib/pp-command-bus)
|
|
519
|
+
- [Issue Tracker](https://gitlab.polskiepolisy.pl/lib/pp-command-bus/issues)
|
|
520
|
+
- [BullMQ Documentation](https://docs.bullmq.io/)
|
|
521
|
+
- [Semantic Versioning](https://semver.org/lang/pl/)
|
|
522
|
+
- [Conventional Commits](https://www.conventionalcommits.org/)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|