@nestjs/cqrs 10.2.8 → 11.0.0-next.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.
Files changed (85) hide show
  1. package/.circleci/config.yml +29 -1
  2. package/.husky/commit-msg +0 -3
  3. package/.husky/pre-commit +0 -3
  4. package/dist/classes/command.d.ts +9 -0
  5. package/dist/classes/command.js +7 -0
  6. package/dist/classes/constants.d.ts +1 -0
  7. package/dist/classes/constants.js +4 -0
  8. package/dist/classes/index.d.ts +2 -0
  9. package/dist/classes/index.js +18 -0
  10. package/dist/classes/query.d.ts +9 -0
  11. package/dist/classes/query.js +7 -0
  12. package/dist/command-bus.d.ts +26 -7
  13. package/dist/command-bus.js +57 -21
  14. package/dist/constants.d.ts +1 -1
  15. package/dist/constants.js +1 -0
  16. package/dist/cqrs.module.d.ts +5 -4
  17. package/dist/cqrs.module.js +21 -11
  18. package/dist/decorators/command-handler.decorator.d.ts +3 -1
  19. package/dist/decorators/command-handler.decorator.js +8 -3
  20. package/dist/decorators/events-handler.decorator.d.ts +3 -1
  21. package/dist/decorators/events-handler.decorator.js +9 -2
  22. package/dist/decorators/index.d.ts +1 -0
  23. package/dist/decorators/index.js +6 -1
  24. package/dist/decorators/publishable.decorator.d.ts +5 -0
  25. package/dist/decorators/publishable.decorator.js +13 -0
  26. package/dist/decorators/query-handler.decorator.d.ts +3 -1
  27. package/dist/decorators/query-handler.decorator.js +8 -3
  28. package/dist/event-bus.d.ts +51 -10
  29. package/dist/event-bus.js +108 -31
  30. package/dist/event-publisher.d.ts +5 -2
  31. package/dist/event-publisher.js +10 -8
  32. package/dist/exceptions/command-not-found.exception.js +1 -1
  33. package/dist/exceptions/index.d.ts +1 -0
  34. package/dist/exceptions/index.js +6 -1
  35. package/dist/exceptions/invalid-command-handler.exception.js +1 -1
  36. package/dist/exceptions/invalid-events-handler.exception.js +1 -1
  37. package/dist/exceptions/invalid-query-handler.exception.js +1 -1
  38. package/dist/exceptions/invalid-saga.exception.js +1 -1
  39. package/dist/exceptions/query-not-found.exception.js +1 -1
  40. package/dist/exceptions/unsupported-saga-scope.exception.d.ts +3 -0
  41. package/dist/exceptions/unsupported-saga-scope.exception.js +9 -0
  42. package/dist/helpers/default-event-id-provider.d.ts +7 -0
  43. package/dist/helpers/default-event-id-provider.js +10 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.js +7 -1
  46. package/dist/interfaces/commands/command-bus.interface.d.ts +18 -1
  47. package/dist/interfaces/commands/command-handler.interface.d.ts +9 -2
  48. package/dist/interfaces/cqrs-module-options.interface.d.ts +38 -8
  49. package/dist/interfaces/events/event-bus.interface.d.ts +41 -4
  50. package/dist/interfaces/events/event-id-provider.interface.d.ts +12 -0
  51. package/dist/interfaces/events/event-id-provider.interface.js +2 -0
  52. package/dist/interfaces/events/event-publisher.interface.d.ts +7 -4
  53. package/dist/interfaces/index.d.ts +2 -0
  54. package/dist/interfaces/index.js +7 -1
  55. package/dist/interfaces/providers-introspection-result.interface.d.ts +10 -0
  56. package/dist/interfaces/providers-introspection-result.interface.js +2 -0
  57. package/dist/interfaces/queries/query-bus.interface.d.ts +18 -1
  58. package/dist/interfaces/queries/query-handler.interface.d.ts +9 -2
  59. package/dist/interfaces/saga.type.d.ts +1 -1
  60. package/dist/operators/index.js +5 -1
  61. package/dist/operators/of-type.d.ts +1 -1
  62. package/dist/operators/of-type.js +1 -2
  63. package/dist/query-bus.d.ts +26 -6
  64. package/dist/query-bus.js +49 -20
  65. package/dist/scopes/async.context.d.ts +30 -0
  66. package/dist/scopes/async.context.js +58 -0
  67. package/dist/scopes/index.d.ts +1 -0
  68. package/dist/scopes/index.js +17 -0
  69. package/dist/services/explorer.service.d.ts +4 -6
  70. package/dist/services/explorer.service.js +14 -14
  71. package/dist/storages/aggregate-root.storage.d.ts +8 -0
  72. package/dist/storages/aggregate-root.storage.js +21 -0
  73. package/dist/unhandled-exception-bus.d.ts +4 -3
  74. package/dist/unhandled-exception-bus.js +18 -5
  75. package/dist/utils/index.js +5 -1
  76. package/jest.config.js +5 -0
  77. package/package.json +29 -17
  78. package/renovate.json +8 -7
  79. package/test/e2e/basic-flows.spec.ts +106 -0
  80. package/test/e2e/generics.spec.ts +198 -0
  81. package/test/e2e/request-scope.spec.ts +141 -0
  82. package/test/e2e/unhandled-exceptions.spec.ts +73 -0
  83. package/test/jest-e2e.json +9 -0
  84. package/test/utils/wait-immediate.ts +2 -0
  85. package/tsconfig.build.json +10 -0
@@ -0,0 +1,73 @@
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+ import { take } from 'rxjs';
3
+ import { CommandBus, UnhandledExceptionBus } from '../../src';
4
+ import { AppModule } from '../src/app.module';
5
+ import { UnhandledExceptionCommand } from '../src/errors/commands/unhandled-exception.command';
6
+ import { UnhandledExceptionEvent } from '../src/errors/events/unhandled-exception.event';
7
+
8
+ describe('Unhandled exceptions', () => {
9
+ let moduleRef: TestingModule;
10
+ let unhandledExceptionBus: UnhandledExceptionBus;
11
+
12
+ beforeAll(async () => {
13
+ moduleRef = await Test.createTestingModule({
14
+ imports: [AppModule],
15
+ }).compile();
16
+
17
+ await moduleRef.init();
18
+
19
+ unhandledExceptionBus = moduleRef.get(UnhandledExceptionBus);
20
+ });
21
+
22
+ describe('when exception is thrown from command handler', () => {
23
+ it('should rethrow the exception', async () => {
24
+ const command = new UnhandledExceptionCommand('command');
25
+ const commandBus = moduleRef.get(CommandBus);
26
+ try {
27
+ await commandBus.execute(command);
28
+
29
+ expect(true).toBe(false);
30
+ } catch (error) {
31
+ expect(error).toEqual(
32
+ new Error(`Unhandled exception in ${command.failAt}`),
33
+ );
34
+ }
35
+ });
36
+ });
37
+
38
+ describe('when exception is thrown from event handler', () => {
39
+ it('should forward exception to UnhandledExceptionBus', (done) => {
40
+ const command = new UnhandledExceptionCommand('event');
41
+ const commandBus = moduleRef.get(CommandBus);
42
+
43
+ unhandledExceptionBus.pipe(take(1)).subscribe((exceptionInfo) => {
44
+ expect(exceptionInfo.exception).toEqual(
45
+ new Error(`Unhandled exception in ${command.failAt}`),
46
+ );
47
+ expect(exceptionInfo.cause).toBeInstanceOf(UnhandledExceptionEvent);
48
+ done();
49
+ });
50
+ commandBus.execute(command).catch((err) => done(err));
51
+ });
52
+ });
53
+
54
+ describe('when exception is thrown from saga', () => {
55
+ it('should forward exception to UnhandledExceptionBus', (done) => {
56
+ const command = new UnhandledExceptionCommand('saga');
57
+ const commandBus = moduleRef.get(CommandBus);
58
+
59
+ unhandledExceptionBus.pipe(take(1)).subscribe((exceptionInfo) => {
60
+ expect(exceptionInfo.exception).toEqual(
61
+ new Error(`Unhandled exception in ${command.failAt}`),
62
+ );
63
+ expect(exceptionInfo.cause).toEqual('onError');
64
+ done();
65
+ });
66
+ commandBus.execute(command).catch((err) => done(err));
67
+ });
68
+ });
69
+
70
+ afterAll(async () => {
71
+ await moduleRef.close();
72
+ });
73
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "moduleFileExtensions": ["js", "json", "ts"],
3
+ "rootDir": ".",
4
+ "testEnvironment": "node",
5
+ "testRegex": ".spec.ts$",
6
+ "transform": {
7
+ "^.+\\.(t|j)s$": ["ts-jest", { "tsconfig": "./test/tsconfig.json" }]
8
+ }
9
+ }
@@ -0,0 +1,2 @@
1
+ export const waitImmediate = () =>
2
+ new Promise((resolve) => setImmediate(resolve));
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": [
8
+ "src/**/*",
9
+ ],
10
+ }