@quanticjs/core 1.1.1

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 (181) hide show
  1. package/dist/bootstrap/bootstrapService.d.ts +8 -0
  2. package/dist/bootstrap/bootstrapService.js +58 -0
  3. package/dist/cqrs/PipelineExecutor.d.ts +31 -0
  4. package/dist/cqrs/PipelineExecutor.js +81 -0
  5. package/dist/cqrs/behaviors/CacheBehavior.d.ts +9 -0
  6. package/dist/cqrs/behaviors/CacheBehavior.js +68 -0
  7. package/dist/cqrs/behaviors/DistributedLockBehavior.d.ts +12 -0
  8. package/dist/cqrs/behaviors/DistributedLockBehavior.js +90 -0
  9. package/dist/cqrs/behaviors/FeatureFlagBehavior.d.ts +8 -0
  10. package/dist/cqrs/behaviors/FeatureFlagBehavior.js +58 -0
  11. package/dist/cqrs/behaviors/InvalidateCacheBehavior.d.ts +9 -0
  12. package/dist/cqrs/behaviors/InvalidateCacheBehavior.js +61 -0
  13. package/dist/cqrs/behaviors/LogBehavior.d.ts +9 -0
  14. package/dist/cqrs/behaviors/LogBehavior.js +125 -0
  15. package/dist/cqrs/behaviors/PerformanceBehavior.d.ts +12 -0
  16. package/dist/cqrs/behaviors/PerformanceBehavior.js +56 -0
  17. package/dist/cqrs/behaviors/TransactionalBehavior.d.ts +18 -0
  18. package/dist/cqrs/behaviors/TransactionalBehavior.js +77 -0
  19. package/dist/cqrs/behaviors/ValidationBehavior.d.ts +4 -0
  20. package/dist/cqrs/behaviors/ValidationBehavior.js +33 -0
  21. package/dist/cqrs/behaviors/WorkflowBehavior.d.ts +8 -0
  22. package/dist/cqrs/behaviors/WorkflowBehavior.js +61 -0
  23. package/dist/cqrs/constants.d.ts +2 -0
  24. package/dist/cqrs/constants.js +5 -0
  25. package/dist/cqrs/decorators/Cache.decorator.d.ts +13 -0
  26. package/dist/cqrs/decorators/Cache.decorator.js +18 -0
  27. package/dist/cqrs/decorators/DistributedLock.decorator.d.ts +15 -0
  28. package/dist/cqrs/decorators/DistributedLock.decorator.js +23 -0
  29. package/dist/cqrs/decorators/FeatureFlag.decorator.d.ts +9 -0
  30. package/dist/cqrs/decorators/FeatureFlag.decorator.js +14 -0
  31. package/dist/cqrs/decorators/InvalidateCache.decorator.d.ts +6 -0
  32. package/dist/cqrs/decorators/InvalidateCache.decorator.js +14 -0
  33. package/dist/cqrs/decorators/IsolatedTransaction.decorator.d.ts +14 -0
  34. package/dist/cqrs/decorators/IsolatedTransaction.decorator.js +25 -0
  35. package/dist/cqrs/decorators/Log.decorator.d.ts +11 -0
  36. package/dist/cqrs/decorators/Log.decorator.js +18 -0
  37. package/dist/cqrs/decorators/Validate.decorator.d.ts +24 -0
  38. package/dist/cqrs/decorators/Validate.decorator.js +37 -0
  39. package/dist/cqrs/decorators/Workflow.decorator.d.ts +8 -0
  40. package/dist/cqrs/decorators/Workflow.decorator.js +14 -0
  41. package/dist/cqrs/interfaces/WorkflowEngine.d.ts +14 -0
  42. package/dist/cqrs/interfaces/WorkflowEngine.js +4 -0
  43. package/dist/cqrs/pipeline/QuanticCommandBus.d.ts +37 -0
  44. package/dist/cqrs/pipeline/QuanticCommandBus.js +99 -0
  45. package/dist/cqrs/pipeline/QuanticQueryBus.d.ts +28 -0
  46. package/dist/cqrs/pipeline/QuanticQueryBus.js +78 -0
  47. package/dist/cqrs/pipeline/runPipeline.d.ts +3 -0
  48. package/dist/cqrs/pipeline/runPipeline.js +12 -0
  49. package/dist/cqrs/transaction/TransactionContext.d.ts +18 -0
  50. package/dist/cqrs/transaction/TransactionContext.js +26 -0
  51. package/dist/cqrs/transaction/getTransactionalRepo.d.ts +16 -0
  52. package/dist/cqrs/transaction/getTransactionalRepo.js +22 -0
  53. package/dist/cqrs/validation/ICommandValidator.d.ts +48 -0
  54. package/dist/cqrs/validation/ICommandValidator.js +21 -0
  55. package/dist/entities/BaseEntity.d.ts +5 -0
  56. package/dist/entities/BaseEntity.js +31 -0
  57. package/dist/entities/TenantBaseEntity.d.ts +4 -0
  58. package/dist/entities/TenantBaseEntity.js +22 -0
  59. package/dist/events/DomainEvent.d.ts +14 -0
  60. package/dist/events/DomainEvent.js +27 -0
  61. package/dist/events/OutboxEvent.entity.d.ts +18 -0
  62. package/dist/events/OutboxEvent.entity.js +87 -0
  63. package/dist/events/OutboxPublisherService.d.ts +14 -0
  64. package/dist/events/OutboxPublisherService.js +104 -0
  65. package/dist/events/RedisStreamConsumer.d.ts +43 -0
  66. package/dist/events/RedisStreamConsumer.js +158 -0
  67. package/dist/events/RedisStreamPublisher.d.ts +9 -0
  68. package/dist/events/RedisStreamPublisher.js +60 -0
  69. package/dist/filters/GlobalExceptionFilter.d.ts +11 -0
  70. package/dist/filters/GlobalExceptionFilter.js +102 -0
  71. package/dist/guards/JwtAuthGuard.d.ts +10 -0
  72. package/dist/guards/JwtAuthGuard.js +46 -0
  73. package/dist/guards/JwtStrategy.d.ts +22 -0
  74. package/dist/guards/JwtStrategy.js +47 -0
  75. package/dist/guards/RolesGuard.d.ts +8 -0
  76. package/dist/guards/RolesGuard.js +52 -0
  77. package/dist/index.d.ts +69 -0
  78. package/dist/index.js +146 -0
  79. package/dist/interceptors/ResultInterceptor.d.ts +7 -0
  80. package/dist/interceptors/ResultInterceptor.js +88 -0
  81. package/dist/lifecycle/GracefulShutdownService.d.ts +24 -0
  82. package/dist/lifecycle/GracefulShutdownService.js +93 -0
  83. package/dist/logging/pino-config.d.ts +35 -0
  84. package/dist/logging/pino-config.js +79 -0
  85. package/dist/metrics/MetricsController.d.ts +7 -0
  86. package/dist/metrics/MetricsController.js +42 -0
  87. package/dist/metrics/MetricsService.d.ts +13 -0
  88. package/dist/metrics/MetricsService.js +58 -0
  89. package/dist/middleware/CorrelationIdMiddleware.d.ts +4 -0
  90. package/dist/middleware/CorrelationIdMiddleware.js +33 -0
  91. package/dist/middleware/CorrelationStore.d.ts +11 -0
  92. package/dist/middleware/CorrelationStore.js +9 -0
  93. package/dist/middleware/TenantContextMiddleware.d.ts +7 -0
  94. package/dist/middleware/TenantContextMiddleware.js +27 -0
  95. package/dist/middleware/TenantStore.d.ts +9 -0
  96. package/dist/middleware/TenantStore.js +9 -0
  97. package/dist/redis/redis.module.d.ts +8 -0
  98. package/dist/redis/redis.module.js +49 -0
  99. package/dist/resilience/CircuitBreakerFactory.d.ts +12 -0
  100. package/dist/resilience/CircuitBreakerFactory.js +22 -0
  101. package/dist/result/Result.d.ts +26 -0
  102. package/dist/result/Result.js +62 -0
  103. package/dist/shared-kernel.module.d.ts +13 -0
  104. package/dist/shared-kernel.module.js +87 -0
  105. package/dist/subscribers/TenantSubscriber.d.ts +20 -0
  106. package/dist/subscribers/TenantSubscriber.js +52 -0
  107. package/dist/testing/TestingModuleFactory.d.ts +23 -0
  108. package/dist/testing/TestingModuleFactory.js +63 -0
  109. package/dist/testing/index.d.ts +2 -0
  110. package/dist/testing/index.js +7 -0
  111. package/dist/testing/mocks.d.ts +34 -0
  112. package/dist/testing/mocks.js +62 -0
  113. package/dist/unleash/initial-flags.d.ts +7 -0
  114. package/dist/unleash/initial-flags.js +9 -0
  115. package/dist/unleash/unleash.module.d.ts +9 -0
  116. package/dist/unleash/unleash.module.js +47 -0
  117. package/package.json +140 -0
  118. package/src/bootstrap/bootstrapService.ts +72 -0
  119. package/src/cqrs/behaviors/CacheBehavior.spec.ts +63 -0
  120. package/src/cqrs/behaviors/CacheBehavior.ts +54 -0
  121. package/src/cqrs/behaviors/DistributedLockBehavior.ts +88 -0
  122. package/src/cqrs/behaviors/FeatureFlagBehavior.ts +46 -0
  123. package/src/cqrs/behaviors/InvalidateCacheBehavior.spec.ts +89 -0
  124. package/src/cqrs/behaviors/InvalidateCacheBehavior.ts +50 -0
  125. package/src/cqrs/behaviors/LogBehavior.spec.ts +55 -0
  126. package/src/cqrs/behaviors/LogBehavior.ts +121 -0
  127. package/src/cqrs/behaviors/PerformanceBehavior.spec.ts +48 -0
  128. package/src/cqrs/behaviors/PerformanceBehavior.ts +43 -0
  129. package/src/cqrs/behaviors/TransactionalBehavior.ts +64 -0
  130. package/src/cqrs/behaviors/ValidationBehavior.spec.ts +114 -0
  131. package/src/cqrs/behaviors/ValidationBehavior.ts +29 -0
  132. package/src/cqrs/behaviors/WorkflowBehavior.spec.ts +97 -0
  133. package/src/cqrs/behaviors/WorkflowBehavior.ts +62 -0
  134. package/src/cqrs/constants.ts +2 -0
  135. package/src/cqrs/decorators/Cache.decorator.ts +24 -0
  136. package/src/cqrs/decorators/DistributedLock.decorator.ts +34 -0
  137. package/src/cqrs/decorators/FeatureFlag.decorator.ts +23 -0
  138. package/src/cqrs/decorators/InvalidateCache.decorator.spec.ts +20 -0
  139. package/src/cqrs/decorators/InvalidateCache.decorator.ts +17 -0
  140. package/src/cqrs/decorators/IsolatedTransaction.decorator.ts +24 -0
  141. package/src/cqrs/decorators/Log.decorator.ts +22 -0
  142. package/src/cqrs/decorators/Validate.decorator.ts +39 -0
  143. package/src/cqrs/decorators/Workflow.decorator.ts +22 -0
  144. package/src/cqrs/interfaces/WorkflowEngine.ts +19 -0
  145. package/src/cqrs/pipeline/QuanticCommandBus.ts +69 -0
  146. package/src/cqrs/pipeline/QuanticQueryBus.ts +56 -0
  147. package/src/cqrs/pipeline/runPipeline.ts +22 -0
  148. package/src/cqrs/transaction/TransactionContext.ts +26 -0
  149. package/src/cqrs/transaction/getTransactionalRepo.ts +23 -0
  150. package/src/cqrs/validation/ICommandValidator.ts +55 -0
  151. package/src/entities/BaseEntity.ts +16 -0
  152. package/src/entities/TenantBaseEntity.ts +7 -0
  153. package/src/events/DomainEvent.ts +27 -0
  154. package/src/events/OutboxEvent.entity.ts +56 -0
  155. package/src/events/OutboxPublisherService.ts +94 -0
  156. package/src/events/RedisStreamConsumer.ts +172 -0
  157. package/src/events/RedisStreamPublisher.ts +54 -0
  158. package/src/filters/GlobalExceptionFilter.ts +125 -0
  159. package/src/guards/JwtAuthGuard.ts +29 -0
  160. package/src/guards/JwtStrategy.ts +41 -0
  161. package/src/guards/RolesGuard.ts +39 -0
  162. package/src/index.ts +118 -0
  163. package/src/interceptors/ResultInterceptor.ts +93 -0
  164. package/src/lifecycle/GracefulShutdownService.ts +77 -0
  165. package/src/logging/pino-config.ts +80 -0
  166. package/src/metrics/MetricsController.ts +17 -0
  167. package/src/metrics/MetricsService.ts +55 -0
  168. package/src/middleware/CorrelationIdMiddleware.ts +27 -0
  169. package/src/middleware/CorrelationStore.ts +13 -0
  170. package/src/middleware/TenantContextMiddleware.ts +21 -0
  171. package/src/middleware/TenantStore.ts +11 -0
  172. package/src/redis/redis.module.ts +41 -0
  173. package/src/resilience/CircuitBreakerFactory.ts +33 -0
  174. package/src/result/Result.ts +66 -0
  175. package/src/shared-kernel.module.ts +87 -0
  176. package/src/subscribers/TenantSubscriber.ts +47 -0
  177. package/src/testing/TestingModuleFactory.ts +78 -0
  178. package/src/testing/index.ts +2 -0
  179. package/src/testing/mocks.ts +59 -0
  180. package/src/unleash/unleash.module.ts +45 -0
  181. package/tsconfig.json +22 -0
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var QuanticCommandBus_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.QuanticCommandBus = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const cqrs_1 = require("@nestjs/cqrs");
19
+ const LogBehavior_1 = require("../behaviors/LogBehavior");
20
+ const FeatureFlagBehavior_1 = require("../behaviors/FeatureFlagBehavior");
21
+ const ValidationBehavior_1 = require("../behaviors/ValidationBehavior");
22
+ const CacheBehavior_1 = require("../behaviors/CacheBehavior");
23
+ const DistributedLockBehavior_1 = require("../behaviors/DistributedLockBehavior");
24
+ const TransactionalBehavior_1 = require("../behaviors/TransactionalBehavior");
25
+ const PerformanceBehavior_1 = require("../behaviors/PerformanceBehavior");
26
+ const WorkflowBehavior_1 = require("../behaviors/WorkflowBehavior");
27
+ const InvalidateCacheBehavior_1 = require("../behaviors/InvalidateCacheBehavior");
28
+ const runPipeline_1 = require("./runPipeline");
29
+ /**
30
+ * QuanticCommandBus — wraps the @nestjs/cqrs CommandBus with a behavior pipeline.
31
+ *
32
+ * Pipeline order:
33
+ * InvalidateCache → Log → Performance → FeatureFlag → Validate → Workflow → Cache → DistributedLock → Transactional → Handler
34
+ *
35
+ * Controllers inject the standard CommandBus from @nestjs/cqrs.
36
+ * This class patches its execute() in onModuleInit so the pipeline is transparent.
37
+ */
38
+ let QuanticCommandBus = QuanticCommandBus_1 = class QuanticCommandBus {
39
+ commandBus;
40
+ logBehavior;
41
+ performanceBehavior;
42
+ featureFlagBehavior;
43
+ validationBehavior;
44
+ workflowBehavior;
45
+ cacheBehavior;
46
+ distributedLockBehavior;
47
+ transactionalBehavior;
48
+ invalidateCacheBehavior;
49
+ logger = new common_1.Logger(QuanticCommandBus_1.name);
50
+ behaviors = [];
51
+ originalExecute;
52
+ constructor(commandBus, logBehavior, performanceBehavior, featureFlagBehavior, validationBehavior, workflowBehavior, cacheBehavior, distributedLockBehavior, transactionalBehavior, invalidateCacheBehavior) {
53
+ this.commandBus = commandBus;
54
+ this.logBehavior = logBehavior;
55
+ this.performanceBehavior = performanceBehavior;
56
+ this.featureFlagBehavior = featureFlagBehavior;
57
+ this.validationBehavior = validationBehavior;
58
+ this.workflowBehavior = workflowBehavior;
59
+ this.cacheBehavior = cacheBehavior;
60
+ this.distributedLockBehavior = distributedLockBehavior;
61
+ this.transactionalBehavior = transactionalBehavior;
62
+ this.invalidateCacheBehavior = invalidateCacheBehavior;
63
+ }
64
+ onModuleInit() {
65
+ const optional = (behavior) => behavior ? [(cmd, next) => behavior.execute(cmd, next)] : [];
66
+ this.behaviors = [
67
+ (cmd, next) => this.invalidateCacheBehavior.execute(cmd, next),
68
+ (cmd, next) => this.logBehavior.execute(cmd, next),
69
+ (cmd, next) => this.performanceBehavior.execute(cmd, next),
70
+ ...optional(this.featureFlagBehavior),
71
+ (cmd, next) => this.validationBehavior.execute(cmd, next),
72
+ ...optional(this.workflowBehavior),
73
+ (cmd, next) => this.cacheBehavior.execute(cmd, next),
74
+ (cmd, next) => this.distributedLockBehavior.execute(cmd, next),
75
+ (cmd, next) => this.transactionalBehavior.execute(cmd, next),
76
+ ];
77
+ this.originalExecute = this.commandBus.execute.bind(this.commandBus);
78
+ const self = this;
79
+ this.commandBus.execute = (command) => {
80
+ const handler = () => self.originalExecute(command);
81
+ return (0, runPipeline_1.runPipeline)(command, handler, self.behaviors);
82
+ };
83
+ this.logger.log(`Command pipeline initialized — ${this.behaviors.length} behaviors`);
84
+ }
85
+ };
86
+ exports.QuanticCommandBus = QuanticCommandBus;
87
+ exports.QuanticCommandBus = QuanticCommandBus = QuanticCommandBus_1 = __decorate([
88
+ (0, common_1.Injectable)(),
89
+ __param(3, (0, common_1.Optional)()),
90
+ __param(3, (0, common_1.Inject)(FeatureFlagBehavior_1.FeatureFlagBehavior)),
91
+ __param(5, (0, common_1.Optional)()),
92
+ __param(5, (0, common_1.Inject)(WorkflowBehavior_1.WorkflowBehavior)),
93
+ __metadata("design:paramtypes", [cqrs_1.CommandBus,
94
+ LogBehavior_1.LogBehavior,
95
+ PerformanceBehavior_1.PerformanceBehavior, Object, ValidationBehavior_1.ValidationBehavior, Object, CacheBehavior_1.CacheBehavior,
96
+ DistributedLockBehavior_1.DistributedLockBehavior,
97
+ TransactionalBehavior_1.TransactionalBehavior,
98
+ InvalidateCacheBehavior_1.InvalidateCacheBehavior])
99
+ ], QuanticCommandBus);
@@ -0,0 +1,28 @@
1
+ import { OnModuleInit } from '@nestjs/common';
2
+ import { QueryBus } from '@nestjs/cqrs';
3
+ import { LogBehavior } from '../behaviors/LogBehavior';
4
+ import { FeatureFlagBehavior } from '../behaviors/FeatureFlagBehavior';
5
+ import { ValidationBehavior } from '../behaviors/ValidationBehavior';
6
+ import { CacheBehavior } from '../behaviors/CacheBehavior';
7
+ import { PerformanceBehavior } from '../behaviors/PerformanceBehavior';
8
+ /**
9
+ * QuanticQueryBus — wraps the @nestjs/cqrs QueryBus with a behavior pipeline.
10
+ *
11
+ * Pipeline order:
12
+ * Log → Performance → FeatureFlag → Validate → Cache → Handler
13
+ *
14
+ * Queries skip Workflow, DistributedLock, and Transactional — they are read-only.
15
+ */
16
+ export declare class QuanticQueryBus implements OnModuleInit {
17
+ private readonly queryBus;
18
+ private readonly logBehavior;
19
+ private readonly performanceBehavior;
20
+ private readonly featureFlagBehavior;
21
+ private readonly validationBehavior;
22
+ private readonly cacheBehavior;
23
+ private readonly logger;
24
+ private behaviors;
25
+ private originalExecute;
26
+ constructor(queryBus: QueryBus, logBehavior: LogBehavior, performanceBehavior: PerformanceBehavior, featureFlagBehavior: FeatureFlagBehavior | undefined, validationBehavior: ValidationBehavior, cacheBehavior: CacheBehavior);
27
+ onModuleInit(): void;
28
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var QuanticQueryBus_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.QuanticQueryBus = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const cqrs_1 = require("@nestjs/cqrs");
19
+ const LogBehavior_1 = require("../behaviors/LogBehavior");
20
+ const FeatureFlagBehavior_1 = require("../behaviors/FeatureFlagBehavior");
21
+ const ValidationBehavior_1 = require("../behaviors/ValidationBehavior");
22
+ const CacheBehavior_1 = require("../behaviors/CacheBehavior");
23
+ const PerformanceBehavior_1 = require("../behaviors/PerformanceBehavior");
24
+ const runPipeline_1 = require("./runPipeline");
25
+ /**
26
+ * QuanticQueryBus — wraps the @nestjs/cqrs QueryBus with a behavior pipeline.
27
+ *
28
+ * Pipeline order:
29
+ * Log → Performance → FeatureFlag → Validate → Cache → Handler
30
+ *
31
+ * Queries skip Workflow, DistributedLock, and Transactional — they are read-only.
32
+ */
33
+ let QuanticQueryBus = QuanticQueryBus_1 = class QuanticQueryBus {
34
+ queryBus;
35
+ logBehavior;
36
+ performanceBehavior;
37
+ featureFlagBehavior;
38
+ validationBehavior;
39
+ cacheBehavior;
40
+ logger = new common_1.Logger(QuanticQueryBus_1.name);
41
+ behaviors = [];
42
+ originalExecute;
43
+ constructor(queryBus, logBehavior, performanceBehavior, featureFlagBehavior, validationBehavior, cacheBehavior) {
44
+ this.queryBus = queryBus;
45
+ this.logBehavior = logBehavior;
46
+ this.performanceBehavior = performanceBehavior;
47
+ this.featureFlagBehavior = featureFlagBehavior;
48
+ this.validationBehavior = validationBehavior;
49
+ this.cacheBehavior = cacheBehavior;
50
+ }
51
+ onModuleInit() {
52
+ const optional = (behavior) => behavior ? [(cmd, next) => behavior.execute(cmd, next)] : [];
53
+ this.behaviors = [
54
+ (cmd, next) => this.logBehavior.execute(cmd, next),
55
+ (cmd, next) => this.performanceBehavior.execute(cmd, next),
56
+ ...optional(this.featureFlagBehavior),
57
+ (cmd, next) => this.validationBehavior.execute(cmd, next),
58
+ (cmd, next) => this.cacheBehavior.execute(cmd, next),
59
+ ];
60
+ this.originalExecute = this.queryBus.execute.bind(this.queryBus);
61
+ const self = this;
62
+ this.queryBus.execute = (query) => {
63
+ const handler = () => self.originalExecute(query);
64
+ return (0, runPipeline_1.runPipeline)(query, handler, self.behaviors);
65
+ };
66
+ this.logger.log(`Query pipeline initialized — ${this.behaviors.length} behaviors`);
67
+ }
68
+ };
69
+ exports.QuanticQueryBus = QuanticQueryBus;
70
+ exports.QuanticQueryBus = QuanticQueryBus = QuanticQueryBus_1 = __decorate([
71
+ (0, common_1.Injectable)(),
72
+ __param(3, (0, common_1.Optional)()),
73
+ __param(3, (0, common_1.Inject)(FeatureFlagBehavior_1.FeatureFlagBehavior)),
74
+ __metadata("design:paramtypes", [cqrs_1.QueryBus,
75
+ LogBehavior_1.LogBehavior,
76
+ PerformanceBehavior_1.PerformanceBehavior, Object, ValidationBehavior_1.ValidationBehavior,
77
+ CacheBehavior_1.CacheBehavior])
78
+ ], QuanticQueryBus);
@@ -0,0 +1,3 @@
1
+ import { Result } from '../../result/Result';
2
+ export type BehaviorFn = <T>(command: object, next: () => Promise<Result<T>>) => Promise<Result<T>>;
3
+ export declare function runPipeline<T>(command: object, handler: () => Promise<Result<T>>, behaviors: BehaviorFn[]): Promise<Result<T>>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runPipeline = runPipeline;
4
+ function runPipeline(command, handler, behaviors) {
5
+ let next = handler;
6
+ for (let i = behaviors.length - 1; i >= 0; i--) {
7
+ const behavior = behaviors[i];
8
+ const currentNext = next;
9
+ next = () => behavior(command, currentNext);
10
+ }
11
+ return next();
12
+ }
@@ -0,0 +1,18 @@
1
+ import type { QueryRunner } from 'typeorm';
2
+ /**
3
+ * Ambient transaction context using AsyncLocalStorage.
4
+ *
5
+ * Node.js is single-threaded — each async chain (HTTP request, Bull job,
6
+ * event consumer) gets its own isolated storage. Two concurrent requests
7
+ * never share a QueryRunner.
8
+ *
9
+ * The TransactionalBehavior creates the context for the outermost command;
10
+ * nested commands join automatically.
11
+ */
12
+ export declare class TransactionContext {
13
+ private static readonly storage;
14
+ /** Returns the active QueryRunner for this async scope, or undefined. */
15
+ static get(): QueryRunner | undefined;
16
+ /** Runs `fn` with `queryRunner` as the ambient transaction for all nested calls. */
17
+ static run<T>(queryRunner: QueryRunner, fn: () => Promise<T>): Promise<T>;
18
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionContext = void 0;
4
+ const async_hooks_1 = require("async_hooks");
5
+ /**
6
+ * Ambient transaction context using AsyncLocalStorage.
7
+ *
8
+ * Node.js is single-threaded — each async chain (HTTP request, Bull job,
9
+ * event consumer) gets its own isolated storage. Two concurrent requests
10
+ * never share a QueryRunner.
11
+ *
12
+ * The TransactionalBehavior creates the context for the outermost command;
13
+ * nested commands join automatically.
14
+ */
15
+ class TransactionContext {
16
+ static storage = new async_hooks_1.AsyncLocalStorage();
17
+ /** Returns the active QueryRunner for this async scope, or undefined. */
18
+ static get() {
19
+ return this.storage.getStore();
20
+ }
21
+ /** Runs `fn` with `queryRunner` as the ambient transaction for all nested calls. */
22
+ static run(queryRunner, fn) {
23
+ return this.storage.run(queryRunner, fn);
24
+ }
25
+ }
26
+ exports.TransactionContext = TransactionContext;
@@ -0,0 +1,16 @@
1
+ import type { Repository, ObjectLiteral } from 'typeorm';
2
+ /**
3
+ * Returns a repository bound to the ambient transaction's QueryRunner,
4
+ * or the original repository if no transaction context exists.
5
+ *
6
+ * Usage in command handlers:
7
+ * ```typescript
8
+ * async execute(cmd: CreateUserCommand): Promise<Result<UserDto>> {
9
+ * const repo = getTransactionalRepo(this.userRepo);
10
+ * const user = repo.create({ email: cmd.email });
11
+ * await repo.save(user);
12
+ * return Result.success(toDto(user));
13
+ * }
14
+ * ```
15
+ */
16
+ export declare function getTransactionalRepo<T extends ObjectLiteral>(repo: Repository<T>): Repository<T>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTransactionalRepo = getTransactionalRepo;
4
+ const TransactionContext_1 = require("./TransactionContext");
5
+ /**
6
+ * Returns a repository bound to the ambient transaction's QueryRunner,
7
+ * or the original repository if no transaction context exists.
8
+ *
9
+ * Usage in command handlers:
10
+ * ```typescript
11
+ * async execute(cmd: CreateUserCommand): Promise<Result<UserDto>> {
12
+ * const repo = getTransactionalRepo(this.userRepo);
13
+ * const user = repo.create({ email: cmd.email });
14
+ * await repo.save(user);
15
+ * return Result.success(toDto(user));
16
+ * }
17
+ * ```
18
+ */
19
+ function getTransactionalRepo(repo) {
20
+ const qr = TransactionContext_1.TransactionContext.get();
21
+ return qr ? qr.manager.getRepository(repo.target) : repo;
22
+ }
@@ -0,0 +1,48 @@
1
+ import { Result } from '../../result/Result';
2
+ /**
3
+ * Interface for Zod-based command/query validators.
4
+ *
5
+ * Each command that needs validation gets a separate validator class
6
+ * with a Zod schema. The `@Validate(ValidatorClass)` decorator links
7
+ * the command to its validator.
8
+ *
9
+ * Usage:
10
+ * ```typescript
11
+ * export class BlockUserValidator implements ICommandValidator<BlockUserCommand> {
12
+ * schema = z.object({
13
+ * blockerId: z.string().uuid(),
14
+ * blockedUserId: z.string().uuid(),
15
+ * }).refine(d => d.blockerId !== d.blockedUserId, 'Cannot block yourself');
16
+ *
17
+ * validate(command: BlockUserCommand): Result<void> {
18
+ * return validateCommand(this.schema, command);
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ export interface ICommandValidator<T = any> {
24
+ validate(command: T): Result<void>;
25
+ }
26
+ /**
27
+ * A schema that can safeParse — matches Zod's ZodType without importing it.
28
+ * This avoids Zod v3/v4 compatibility issues across packages.
29
+ */
30
+ interface SafeParseable {
31
+ safeParse(data: unknown): {
32
+ success: true;
33
+ } | {
34
+ success: false;
35
+ error: {
36
+ issues: Array<{
37
+ path: PropertyKey[];
38
+ message: string;
39
+ }>;
40
+ };
41
+ };
42
+ }
43
+ /**
44
+ * Helper: run a Zod schema against a command and return Result<void>.
45
+ * Formats all Zod issues into a single error message.
46
+ */
47
+ export declare function validateCommand(schema: SafeParseable, command: unknown): Result<void>;
48
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateCommand = validateCommand;
4
+ const Result_1 = require("../../result/Result");
5
+ /**
6
+ * Helper: run a Zod schema against a command and return Result<void>.
7
+ * Formats all Zod issues into a single error message.
8
+ */
9
+ function validateCommand(schema, command) {
10
+ const result = schema.safeParse(command);
11
+ if (result.success) {
12
+ return Result_1.Result.success(undefined);
13
+ }
14
+ const messages = result.error.issues
15
+ .map((issue) => {
16
+ const path = issue.path.length > 0 ? `${issue.path.map(String).join('.')}: ` : '';
17
+ return `${path}${issue.message}`;
18
+ })
19
+ .join('; ');
20
+ return Result_1.Result.validationError(messages);
21
+ }
@@ -0,0 +1,5 @@
1
+ export declare abstract class BaseEntity {
2
+ id: string;
3
+ createdAt: Date;
4
+ updatedAt: Date;
5
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BaseEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ class BaseEntity {
15
+ id;
16
+ createdAt;
17
+ updatedAt;
18
+ }
19
+ exports.BaseEntity = BaseEntity;
20
+ __decorate([
21
+ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
22
+ __metadata("design:type", String)
23
+ ], BaseEntity.prototype, "id", void 0);
24
+ __decorate([
25
+ (0, typeorm_1.CreateDateColumn)({ type: 'timestamptz' }),
26
+ __metadata("design:type", Date)
27
+ ], BaseEntity.prototype, "createdAt", void 0);
28
+ __decorate([
29
+ (0, typeorm_1.UpdateDateColumn)({ type: 'timestamptz' }),
30
+ __metadata("design:type", Date)
31
+ ], BaseEntity.prototype, "updatedAt", void 0);
@@ -0,0 +1,4 @@
1
+ import { BaseEntity } from './BaseEntity';
2
+ export declare abstract class TenantBaseEntity extends BaseEntity {
3
+ organizationId: string;
4
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TenantBaseEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const BaseEntity_1 = require("./BaseEntity");
15
+ class TenantBaseEntity extends BaseEntity_1.BaseEntity {
16
+ organizationId;
17
+ }
18
+ exports.TenantBaseEntity = TenantBaseEntity;
19
+ __decorate([
20
+ (0, typeorm_1.Column)({ type: 'uuid' }),
21
+ __metadata("design:type", String)
22
+ ], TenantBaseEntity.prototype, "organizationId", void 0);
@@ -0,0 +1,14 @@
1
+ export interface DomainEventPayload {
2
+ [key: string]: unknown;
3
+ }
4
+ export declare class DomainEvent {
5
+ readonly eventType: string;
6
+ readonly aggregateId: string;
7
+ readonly payload: DomainEventPayload;
8
+ readonly organizationId?: string | undefined;
9
+ readonly eventId: string;
10
+ readonly occurredAt: Date;
11
+ constructor(eventType: string, aggregateId: string, payload: DomainEventPayload, organizationId?: string | undefined);
12
+ /** The Redis Stream key this event should be published to */
13
+ get streamKey(): string;
14
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainEvent = void 0;
4
+ const uuid_1 = require("uuid");
5
+ class DomainEvent {
6
+ eventType;
7
+ aggregateId;
8
+ payload;
9
+ organizationId;
10
+ eventId;
11
+ occurredAt;
12
+ constructor(eventType, aggregateId, payload, organizationId) {
13
+ this.eventType = eventType;
14
+ this.aggregateId = aggregateId;
15
+ this.payload = payload;
16
+ this.organizationId = organizationId;
17
+ this.eventId = (0, uuid_1.v4)();
18
+ this.occurredAt = new Date();
19
+ }
20
+ /** The Redis Stream key this event should be published to */
21
+ get streamKey() {
22
+ // e.g. 'build.completed' → 'arex:events:builds'
23
+ const category = this.eventType.split('.')[0];
24
+ return `arex:events:${category}s`;
25
+ }
26
+ }
27
+ exports.DomainEvent = DomainEvent;
@@ -0,0 +1,18 @@
1
+ export declare enum OutboxEventStatus {
2
+ Pending = "Pending",
3
+ Published = "Published",
4
+ Failed = "Failed"
5
+ }
6
+ export declare class OutboxEvent {
7
+ id: string;
8
+ eventType: string;
9
+ aggregateId: string;
10
+ streamKey: string;
11
+ payload: Record<string, unknown>;
12
+ organizationId: string | null;
13
+ status: OutboxEventStatus;
14
+ publishAttempts: number;
15
+ lastError: string | null;
16
+ createdAt: Date;
17
+ publishedAt: Date | null;
18
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OutboxEvent = exports.OutboxEventStatus = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ var OutboxEventStatus;
15
+ (function (OutboxEventStatus) {
16
+ OutboxEventStatus["Pending"] = "Pending";
17
+ OutboxEventStatus["Published"] = "Published";
18
+ OutboxEventStatus["Failed"] = "Failed";
19
+ })(OutboxEventStatus || (exports.OutboxEventStatus = OutboxEventStatus = {}));
20
+ let OutboxEvent = class OutboxEvent {
21
+ id;
22
+ eventType;
23
+ aggregateId;
24
+ streamKey;
25
+ payload;
26
+ organizationId;
27
+ status;
28
+ publishAttempts;
29
+ lastError;
30
+ createdAt;
31
+ publishedAt;
32
+ };
33
+ exports.OutboxEvent = OutboxEvent;
34
+ __decorate([
35
+ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
36
+ __metadata("design:type", String)
37
+ ], OutboxEvent.prototype, "id", void 0);
38
+ __decorate([
39
+ (0, typeorm_1.Column)({ type: 'varchar' }),
40
+ __metadata("design:type", String)
41
+ ], OutboxEvent.prototype, "eventType", void 0);
42
+ __decorate([
43
+ (0, typeorm_1.Column)({ type: 'varchar' }),
44
+ __metadata("design:type", String)
45
+ ], OutboxEvent.prototype, "aggregateId", void 0);
46
+ __decorate([
47
+ (0, typeorm_1.Column)({ type: 'varchar' }),
48
+ __metadata("design:type", String)
49
+ ], OutboxEvent.prototype, "streamKey", void 0);
50
+ __decorate([
51
+ (0, typeorm_1.Column)({ type: 'jsonb' }),
52
+ __metadata("design:type", Object)
53
+ ], OutboxEvent.prototype, "payload", void 0);
54
+ __decorate([
55
+ (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
56
+ __metadata("design:type", Object)
57
+ ], OutboxEvent.prototype, "organizationId", void 0);
58
+ __decorate([
59
+ (0, typeorm_1.Column)({
60
+ type: 'enum',
61
+ enum: OutboxEventStatus,
62
+ default: OutboxEventStatus.Pending,
63
+ }),
64
+ __metadata("design:type", String)
65
+ ], OutboxEvent.prototype, "status", void 0);
66
+ __decorate([
67
+ (0, typeorm_1.Column)({ type: 'int', default: 0 }),
68
+ __metadata("design:type", Number)
69
+ ], OutboxEvent.prototype, "publishAttempts", void 0);
70
+ __decorate([
71
+ (0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
72
+ __metadata("design:type", Object)
73
+ ], OutboxEvent.prototype, "lastError", void 0);
74
+ __decorate([
75
+ (0, typeorm_1.CreateDateColumn)({ type: 'timestamptz' }),
76
+ __metadata("design:type", Date)
77
+ ], OutboxEvent.prototype, "createdAt", void 0);
78
+ __decorate([
79
+ (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
80
+ __metadata("design:type", Object)
81
+ ], OutboxEvent.prototype, "publishedAt", void 0);
82
+ exports.OutboxEvent = OutboxEvent = __decorate([
83
+ (0, typeorm_1.Entity)('outbox_events'),
84
+ (0, typeorm_1.Index)('idx_outbox_pending', ['status', 'createdAt'], {
85
+ where: `"status" = 'Pending'`,
86
+ })
87
+ ], OutboxEvent);
@@ -0,0 +1,14 @@
1
+ import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
+ import { DataSource } from 'typeorm';
3
+ import { RedisStreamPublisher } from './RedisStreamPublisher';
4
+ export declare class OutboxPublisherService implements OnModuleInit, OnModuleDestroy {
5
+ private readonly dataSource;
6
+ private readonly redisPublisher;
7
+ private readonly logger;
8
+ private timer;
9
+ private processing;
10
+ constructor(dataSource: DataSource, redisPublisher: RedisStreamPublisher);
11
+ onModuleInit(): void;
12
+ onModuleDestroy(): void;
13
+ private pollAndPublish;
14
+ }