@cqrs-ddd/nestjs 0.5.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.
@@ -0,0 +1,189 @@
1
+ /* Copyright (C) 2026-present Aristotelis — see repository license. */
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 PipelineBootstrap_1;
15
+ import { compilePipelinePlan, createPipelineRunner, PipelineConfigurationError, pipelineOf, validateBehaviorContracts, } from '@cqrs-ddd/pipeline';
16
+ import { Inject, Injectable, Logger, } from '@nestjs/common';
17
+ import { DiscoveryService } from '@nestjs/core';
18
+ import { CommandHandler, EventsHandler, QueryHandler } from '@nestjs/cqrs';
19
+ export const PIPELINE_OPTIONS = Symbol('PIPELINE_OPTIONS');
20
+ // @nestjs/cqrs keeps its handler metadata keys private, so each public handler
21
+ // decorator is applied to a throwaway class to read the one key it records.
22
+ function metadataKey(decorate) {
23
+ const target = class {
24
+ };
25
+ decorate(target);
26
+ const keys = Reflect.getOwnMetadataKeys(target);
27
+ if (keys.length !== 1) {
28
+ throw new Error('A @nestjs/cqrs handler decorator recorded no single metadata key; the installed @nestjs/cqrs is not supported.');
29
+ }
30
+ return keys[0];
31
+ }
32
+ const HANDLER_KINDS = [
33
+ [metadataKey((target) => CommandHandler(class {
34
+ })(target)), 'command'],
35
+ [metadataKey((target) => QueryHandler(class {
36
+ })(target)), 'query'],
37
+ [metadataKey((target) => EventsHandler(class {
38
+ })(target)), 'event'],
39
+ ];
40
+ /**
41
+ * Wraps every `@nestjs/cqrs` handler that runs behaviors with its pipeline, at
42
+ * application bootstrap: `execute` of command and query handlers, `handle` of
43
+ * event handlers. The buses read the method at call time, so they dispatch
44
+ * through the pipeline unchanged.
45
+ *
46
+ * A handler's pipeline comes from its `@UsePipeline`/`@SkipPipeline` and the
47
+ * global behaviors, compiled once. Each behavior instance is the one provider a
48
+ * module registers under the behavior class; this provider never builds one.
49
+ * Startup fails when a behavior has no provider or several, when a handler that
50
+ * runs behaviors is request-scoped (Nest builds such a handler per request, so a
51
+ * wrapped instance would never run), and, in `'strict'` mode, when a behavior's
52
+ * contract is broken. Only this application's own handler instances are wrapped,
53
+ * never their class, and they are restored when the application closes.
54
+ */
55
+ let PipelineBootstrap = PipelineBootstrap_1 = class PipelineBootstrap {
56
+ discovery;
57
+ options;
58
+ logger = new Logger(PipelineBootstrap_1.name);
59
+ restores = [];
60
+ constructor(discovery, options) {
61
+ this.discovery = discovery;
62
+ this.options = options;
63
+ }
64
+ onApplicationBootstrap() {
65
+ try {
66
+ this.wrapHandlers();
67
+ }
68
+ catch (error) {
69
+ this.onModuleDestroy();
70
+ throw error;
71
+ }
72
+ }
73
+ onModuleDestroy() {
74
+ while (this.restores.length > 0)
75
+ this.restores.pop()?.();
76
+ }
77
+ wrapHandlers() {
78
+ const providers = this.discovery.getProviders();
79
+ const mode = this.options.diagnostics ?? 'strict';
80
+ const found = [];
81
+ const behaviors = new Map();
82
+ const behavior = (type, handler) => {
83
+ let instance = behaviors.get(type);
84
+ if (!instance) {
85
+ instance = registeredBehavior(providers, type, handler);
86
+ behaviors.set(type, instance);
87
+ }
88
+ return instance;
89
+ };
90
+ for (const provider of providers) {
91
+ const type = handlerType(provider);
92
+ if (!type)
93
+ continue;
94
+ for (const [key, kind] of HANDLER_KINDS) {
95
+ if (!Reflect.getMetadata(key, type))
96
+ continue;
97
+ this.wrap(provider, type, kind, behavior, mode === 'off' ? undefined : found);
98
+ }
99
+ }
100
+ if (found.length > 0 && mode === 'strict') {
101
+ throw new PipelineConfigurationError(found);
102
+ }
103
+ for (const d of found) {
104
+ this.logger.warn(`[Pipeline Diagnostic] Handler '${d.handlerName}' with behavior '${d.behaviorName}': ${d.message}. Fix: ${d.fix}`);
105
+ }
106
+ }
107
+ wrap(provider, type, kind, behavior, diagnostics) {
108
+ const handlerName = type.name;
109
+ const declared = pipelineOf(type);
110
+ const plan = compilePipelinePlan({
111
+ handlerName,
112
+ requestKind: kind,
113
+ handlerBehaviorTypes: declared.types,
114
+ handlerOptions: declared.options,
115
+ skippedBehaviorTypes: declared.skipped,
116
+ globalBehaviors: this.options.globalBehaviors,
117
+ });
118
+ if (!plan.hasPipeline)
119
+ return;
120
+ if (!provider.isDependencyTreeStatic()) {
121
+ throw new Error(`${handlerName} runs pipeline behaviors but is request-scoped, itself or through a dependency; ` +
122
+ 'Nest builds it per request, so its pipeline would never run. Make it a singleton and read ' +
123
+ 'request data from async context.');
124
+ }
125
+ const method = kind === 'event' ? 'handle' : 'execute';
126
+ const instance = provider.instance;
127
+ const original = instance[method];
128
+ const resolved = plan.behaviorTypes.map((t) => behavior(t, handlerName));
129
+ if (diagnostics) {
130
+ validateBehaviorContracts({
131
+ ...plan,
132
+ handlerType: type,
133
+ handlerName,
134
+ requestKind: kind,
135
+ resolvedBehaviors: new Map(resolved.map((b, i) => [i, b])),
136
+ diagnostics,
137
+ });
138
+ }
139
+ this.logger.debug(`Wrapping ${handlerName}.${method}() [${kind}] with pipeline: [${plan.behaviorTypes.map((t) => t.name).join(' → ')}]`);
140
+ const run = createPipelineRunner(original, {
141
+ handlerType: type,
142
+ handlerName,
143
+ requestKind: kind,
144
+ behaviorOptions: plan.mergedOptions.size > 0 ? plan.mergedOptions : undefined,
145
+ }, resolved, true, this.options.sources);
146
+ const own = Object.getOwnPropertyDescriptor(instance, method);
147
+ Object.defineProperty(instance, method, {
148
+ configurable: true,
149
+ writable: true,
150
+ value: (request) => run(instance, request),
151
+ });
152
+ this.restores.push(() => {
153
+ if (own)
154
+ Object.defineProperty(instance, method, own);
155
+ else
156
+ Reflect.deleteProperty(instance, method);
157
+ });
158
+ }
159
+ };
160
+ PipelineBootstrap = PipelineBootstrap_1 = __decorate([
161
+ Injectable(),
162
+ __param(1, Inject(PIPELINE_OPTIONS)),
163
+ __metadata("design:paramtypes", [DiscoveryService, Object])
164
+ ], PipelineBootstrap);
165
+ export { PipelineBootstrap };
166
+ function handlerType(provider) {
167
+ const type = provider.instance?.constructor ?? provider.metatype;
168
+ return typeof type === 'function' && type !== Object
169
+ ? type
170
+ : undefined;
171
+ }
172
+ function registeredBehavior(providers, type, handler) {
173
+ const registered = providers.filter((provider) => provider.token === type);
174
+ if (registered.length === 0) {
175
+ throw new Error(`${type.name} runs in the pipeline of ${handler}, but no module provides it. Register it as a ` +
176
+ 'provider of the module that configures it.');
177
+ }
178
+ if (registered.length > 1) {
179
+ const modules = registered.map((p) => p.host?.name ?? 'an unknown module');
180
+ throw new Error(`${type.name} is provided by ${modules.join(' and ')}; exactly one module provides each behavior, ` +
181
+ 'otherwise which instance a handler gets would depend on import order.');
182
+ }
183
+ const [provider] = registered;
184
+ if (!provider.isDependencyTreeStatic() || !provider.instance) {
185
+ throw new Error(`${type.name} must be a singleton provider: a pipeline takes one instance of each behavior.`);
186
+ }
187
+ return provider.instance;
188
+ }
189
+ //# sourceMappingURL=pipeline.bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.bootstrap.js","sourceRoot":"","sources":["../../src/pipeline/pipeline.bootstrap.ts"],"names":[],"mappings":"AAAA,sEAAsE;;;;;;;;;;;;;;AAEtE,OAAO,EAGL,mBAAmB,EACnB,oBAAoB,EAKpB,0BAA0B,EAC1B,UAAU,EACV,yBAA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AAC,IAAI,4BAA4B,OAAO,gDAAgD;YAC7F,4CAA4C,CAC/C,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,IAAI,mBAAmB,CAAC,CAAC;QAC3E,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,IAAI,mBAAmB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,+CAA+C;YACjG,uEAAuE,CAC1E,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;IAC9B,IAAI,CAAC,QAAQ,CAAC,sBAAsB,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,IAAI,gFAAgF,CAC7F,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC,QAA6B,CAAC;AAChD,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { type DynamicModule } from '@nestjs/common';
2
+ import { type PipelineOptions } from './pipeline.bootstrap.js';
3
+ /**
4
+ * Runs the `@nestjs/cqrs` handlers through their `@cqrs-ddd/pipeline`
5
+ * pipelines. It places the global behaviors and the context sources; the
6
+ * behavior instances are providers of the modules that configure them, under
7
+ * their behavior class.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * @Module({
12
+ * imports: [
13
+ * PipelineModule.forRoot({
14
+ * sources: contextSources,
15
+ * globalBehaviors: [{ scope: 'all', before: [logging()] }],
16
+ * }),
17
+ * ],
18
+ * providers: [
19
+ * { provide: LoggingBehavior, useFactory: () => new LoggingBehavior(new Logger('Pipeline')) },
20
+ * ],
21
+ * })
22
+ * export class ObservabilityModule {}
23
+ * ```
24
+ */
25
+ export declare class PipelineModule {
26
+ static forRoot(options?: PipelineOptions): DynamicModule;
27
+ }
28
+ //# sourceMappingURL=pipeline.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.module.d.ts","sourceRoot":"","sources":["../../src/pipeline/pipeline.module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBACa,cAAc;IACzB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,eAAoB,GAAG,aAAa,CAS3D;CACF"}
@@ -0,0 +1,50 @@
1
+ /* Copyright (C) 2026-present Aristotelis — see repository license. */
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 PipelineModule_1;
9
+ import { Module } from '@nestjs/common';
10
+ import { DiscoveryModule } from '@nestjs/core';
11
+ import { PIPELINE_OPTIONS, PipelineBootstrap, } from './pipeline.bootstrap.js';
12
+ /**
13
+ * Runs the `@nestjs/cqrs` handlers through their `@cqrs-ddd/pipeline`
14
+ * pipelines. It places the global behaviors and the context sources; the
15
+ * behavior instances are providers of the modules that configure them, under
16
+ * their behavior class.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * @Module({
21
+ * imports: [
22
+ * PipelineModule.forRoot({
23
+ * sources: contextSources,
24
+ * globalBehaviors: [{ scope: 'all', before: [logging()] }],
25
+ * }),
26
+ * ],
27
+ * providers: [
28
+ * { provide: LoggingBehavior, useFactory: () => new LoggingBehavior(new Logger('Pipeline')) },
29
+ * ],
30
+ * })
31
+ * export class ObservabilityModule {}
32
+ * ```
33
+ */
34
+ let PipelineModule = PipelineModule_1 = class PipelineModule {
35
+ static forRoot(options = {}) {
36
+ return {
37
+ module: PipelineModule_1,
38
+ imports: [DiscoveryModule],
39
+ providers: [
40
+ { provide: PIPELINE_OPTIONS, useValue: options },
41
+ PipelineBootstrap,
42
+ ],
43
+ };
44
+ }
45
+ };
46
+ PipelineModule = PipelineModule_1 = __decorate([
47
+ Module({})
48
+ ], PipelineModule);
49
+ export { PipelineModule };
50
+ //# sourceMappingURL=pipeline.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.module.js","sourceRoot":"","sources":["../../src/pipeline/pipeline.module.ts"],"names":[],"mappings":"AAAA,sEAAsE;;;;;;;;AAEtE,OAAO,EAAsB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,GAElB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,cAAc,sBAApB,MAAM,cAAc;IAClB,AAAP,MAAM,CAAC,OAAO,CAAC,OAAO,GAAoB,EAAE;QAC1C,OAAO;YACL,MAAM,kBAAgB;YACtB,OAAO,EAAE,CAAC,eAAe,CAAC;YAC1B,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,EAAE;gBAChD,iBAAiB;aAClB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAXY,cAAc;IAD1B,MAAM,CAAC,EAAE,CAAC;GACE,cAAc,CAW1B"}
package/package.json ADDED
@@ -0,0 +1,119 @@
1
+ {
2
+ "name": "@cqrs-ddd/nestjs",
3
+ "version": "0.5.0",
4
+ "description": "NestJS adapter for the @cqrs-ddd packages: runs @nestjs/cqrs handlers through their pipelines, answers every package error as a NestJS HttpException, and wires correlation and job context",
5
+ "author": "Aristotelis",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "type": "module",
8
+ "engines": {
9
+ "node": ">=22.12.0"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/aristoteliss/ddd-cqrs.git",
14
+ "directory": "packages/nestjs"
15
+ },
16
+ "homepage": "https://aristoteliss.github.io/ddd-cqrs/packages/nestjs/",
17
+ "bugs": {
18
+ "url": "https://github.com/aristoteliss/ddd-cqrs/issues"
19
+ },
20
+ "keywords": [
21
+ "nestjs",
22
+ "cqrs",
23
+ "ddd",
24
+ "pipeline",
25
+ "cqrs-ddd"
26
+ ],
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./correlation": {
33
+ "types": "./dist/correlation.d.ts",
34
+ "default": "./dist/correlation.js"
35
+ },
36
+ "./job-context": {
37
+ "types": "./dist/job-context.d.ts",
38
+ "default": "./dist/job-context.js"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
42
+ "main": "dist/index.js",
43
+ "types": "dist/index.d.ts",
44
+ "files": [
45
+ "dist",
46
+ "LICENSE",
47
+ "COMMERCIAL_LICENSE.txt"
48
+ ],
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "peerDependencies": {
53
+ "@nestjs/common": "^12.1.1",
54
+ "@nestjs/core": "^12.1.1",
55
+ "@nestjs/cqrs": "^12.1.0",
56
+ "@cqrs-ddd/pipeline-feature-flags": "^0.5.0",
57
+ "@cqrs-ddd/core": "^0.5.0",
58
+ "@cqrs-ddd/pipeline-idempotency": "^0.5.0",
59
+ "@cqrs-ddd/pipeline-job-context": "^0.5.0",
60
+ "@cqrs-ddd/pipeline-casl": "^0.5.0",
61
+ "@cqrs-ddd/pipeline-correlation": "^0.5.0",
62
+ "@cqrs-ddd/pipeline-rate-limit": "^0.5.0",
63
+ "@cqrs-ddd/pipeline-zod": "^0.5.0",
64
+ "@cqrs-ddd/pipeline": "^0.5.0"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "@cqrs-ddd/pipeline-casl": {
68
+ "optional": true
69
+ },
70
+ "@cqrs-ddd/pipeline-correlation": {
71
+ "optional": true
72
+ },
73
+ "@cqrs-ddd/pipeline-feature-flags": {
74
+ "optional": true
75
+ },
76
+ "@cqrs-ddd/pipeline-idempotency": {
77
+ "optional": true
78
+ },
79
+ "@cqrs-ddd/pipeline-job-context": {
80
+ "optional": true
81
+ },
82
+ "@cqrs-ddd/pipeline-rate-limit": {
83
+ "optional": true
84
+ },
85
+ "@cqrs-ddd/pipeline-zod": {
86
+ "optional": true
87
+ }
88
+ },
89
+ "devDependencies": {
90
+ "@casl/ability": "^7.0.1",
91
+ "@nestjs/common": "^12.1.1",
92
+ "@nestjs/core": "^12.1.1",
93
+ "@nestjs/cqrs": "^12.1.0",
94
+ "@openfeature/server-sdk": "^1.23.0",
95
+ "@vitest/coverage-v8": "^5.0.3",
96
+ "reflect-metadata": "^0.2.2",
97
+ "rxjs": "^7.8.2",
98
+ "vitest": "^5.0.3",
99
+ "zod": "^4.6.5",
100
+ "@cqrs-ddd/pipeline": "0.5.0",
101
+ "@cqrs-ddd/pipeline-casl": "0.5.0",
102
+ "@cqrs-ddd/pipeline-feature-flags": "0.5.0",
103
+ "@cqrs-ddd/pipeline-correlation": "0.5.0",
104
+ "@cqrs-ddd/pipeline-idempotency": "0.5.0",
105
+ "@cqrs-ddd/pipeline-zod": "0.5.0",
106
+ "@cqrs-ddd/pipeline-job-context": "0.5.0",
107
+ "@cqrs-ddd/core": "0.5.0",
108
+ "@cqrs-ddd/pipeline-rate-limit": "0.5.0"
109
+ },
110
+ "scripts": {
111
+ "build": "tsc -p tsconfig.build.json",
112
+ "build:watch": "tsc -p tsconfig.build.json --watch",
113
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
114
+ "rebuild": "pnpm run clean && pnpm run build",
115
+ "lint": "tsc --noEmit",
116
+ "test": "vitest run",
117
+ "test:watch": "vitest"
118
+ }
119
+ }