@saga-bus/nestjs 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Dean Foran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # @saga-bus/nestjs
2
+
3
+ NestJS module for saga-bus integration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @saga-bus/nestjs
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Setup
14
+
15
+ ```typescript
16
+ // app.module.ts
17
+ import { Module } from "@nestjs/common";
18
+ import { SagaBusModule } from "@saga-bus/nestjs";
19
+ import { InMemoryTransport } from "@saga-bus/transport-inmemory";
20
+ import { InMemorySagaStore } from "@saga-bus/store-inmemory";
21
+
22
+ @Module({
23
+ imports: [
24
+ SagaBusModule.forRoot({
25
+ transport: new InMemoryTransport(),
26
+ store: new InMemorySagaStore(),
27
+ }),
28
+ ],
29
+ })
30
+ export class AppModule {}
31
+ ```
32
+
33
+ ### Async Configuration
34
+
35
+ ```typescript
36
+ SagaBusModule.forRootAsync({
37
+ imports: [ConfigModule],
38
+ useFactory: (config: ConfigService) => ({
39
+ transport: new RabbitMqTransport({
40
+ uri: config.get("RABBITMQ_URI"),
41
+ }),
42
+ store: new PostgresSagaStore({
43
+ pool: new Pool({ connectionString: config.get("DATABASE_URL") }),
44
+ }),
45
+ }),
46
+ inject: [ConfigService],
47
+ });
48
+ ```
49
+
50
+ ## Decorators
51
+
52
+ ### @MessageHandler
53
+
54
+ Handle specific message types:
55
+
56
+ ```typescript
57
+ import { Injectable } from "@nestjs/common";
58
+ import { MessageHandler } from "@saga-bus/nestjs";
59
+
60
+ @Injectable()
61
+ export class OrderHandlers {
62
+ @MessageHandler("OrderCreated")
63
+ async handleOrderCreated(message: OrderCreated) {
64
+ console.log("Order created:", message.payload);
65
+ }
66
+
67
+ @MessageHandler("OrderShipped")
68
+ async handleOrderShipped(message: OrderShipped) {
69
+ console.log("Order shipped:", message.payload);
70
+ }
71
+ }
72
+ ```
73
+
74
+ ### @InjectSagaBus
75
+
76
+ Inject the saga bus service:
77
+
78
+ ```typescript
79
+ import { Injectable } from "@nestjs/common";
80
+ import { InjectSagaBus, SagaBusService } from "@saga-bus/nestjs";
81
+
82
+ @Injectable()
83
+ export class OrderService {
84
+ constructor(@InjectSagaBus() private readonly sagaBus: SagaBusService) {}
85
+
86
+ async createOrder(data: CreateOrderDto) {
87
+ await this.sagaBus.publish(
88
+ { type: "OrderCreated", payload: data },
89
+ { endpoint: "orders" }
90
+ );
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## SagaBusService API
96
+
97
+ ```typescript
98
+ // Publish a message
99
+ await sagaBus.publish(message, options);
100
+
101
+ // Get underlying transport
102
+ const transport = sagaBus.getTransport();
103
+
104
+ // Get underlying store
105
+ const store = sagaBus.getStore();
106
+
107
+ // Get middleware pipeline
108
+ const middleware = sagaBus.getMiddleware();
109
+ ```
110
+
111
+ ## Configuration
112
+
113
+ | Option | Type | Default | Description |
114
+ |--------|------|---------|-------------|
115
+ | `transport` | `Transport` | required | Transport implementation |
116
+ | `store` | `SagaStore` | required | Saga store implementation |
117
+ | `middleware` | `SagaMiddleware[]` | `[]` | Middleware pipeline |
118
+ | `autoStart` | `boolean` | `true` | Auto-start transport |
119
+ | `autoStop` | `boolean` | `true` | Auto-stop on destroy |
120
+
121
+ ## Lifecycle
122
+
123
+ The module automatically:
124
+
125
+ - Starts the transport on module init (if `autoStart: true`)
126
+ - Discovers and registers all `@MessageHandler` decorated methods
127
+ - Stops the transport on module destroy (if `autoStop: true`)
128
+
129
+ ## License
130
+
131
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ InjectSagaBus: () => InjectSagaBus,
25
+ MESSAGE_HANDLER_METADATA: () => MESSAGE_HANDLER_METADATA,
26
+ MessageExplorer: () => MessageExplorer,
27
+ MessageHandler: () => MessageHandler,
28
+ SAGA_BUS_TOKEN: () => SAGA_BUS_TOKEN,
29
+ SagaBusModule: () => SagaBusModule,
30
+ SagaBusService: () => SagaBusService
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+ var import_reflect_metadata2 = require("reflect-metadata");
34
+
35
+ // src/SagaBusModule.ts
36
+ var import_common4 = require("@nestjs/common");
37
+ var import_core2 = require("@nestjs/core");
38
+
39
+ // src/SagaBusService.ts
40
+ var import_common = require("@nestjs/common");
41
+ function _ts_decorate(decorators, target, key, desc) {
42
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
43
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
44
+ 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;
45
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
46
+ }
47
+ __name(_ts_decorate, "_ts_decorate");
48
+ function _ts_metadata(k, v) {
49
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
50
+ }
51
+ __name(_ts_metadata, "_ts_metadata");
52
+ function _ts_param(paramIndex, decorator) {
53
+ return function(target, key) {
54
+ decorator(target, key, paramIndex);
55
+ };
56
+ }
57
+ __name(_ts_param, "_ts_param");
58
+ var SAGA_BUS_OPTIONS = "SAGA_BUS_OPTIONS";
59
+ var SagaBusService = class {
60
+ static {
61
+ __name(this, "SagaBusService");
62
+ }
63
+ transport;
64
+ store;
65
+ middleware;
66
+ autoStart;
67
+ autoStop;
68
+ constructor(options) {
69
+ this.transport = options.transport;
70
+ this.store = options.store;
71
+ this.middleware = options.middleware ?? [];
72
+ this.autoStart = options.autoStart ?? true;
73
+ this.autoStop = options.autoStop ?? true;
74
+ }
75
+ async onModuleInit() {
76
+ if (this.autoStart) {
77
+ await this.transport.start();
78
+ }
79
+ }
80
+ async onModuleDestroy() {
81
+ if (this.autoStop) {
82
+ await this.transport.stop();
83
+ }
84
+ }
85
+ /**
86
+ * Publish a message to the transport.
87
+ */
88
+ async publish(message, options) {
89
+ await this.transport.publish(message, options);
90
+ }
91
+ /**
92
+ * Get the underlying transport.
93
+ */
94
+ getTransport() {
95
+ return this.transport;
96
+ }
97
+ /**
98
+ * Get the underlying store.
99
+ */
100
+ getStore() {
101
+ return this.store;
102
+ }
103
+ /**
104
+ * Get the middleware pipeline.
105
+ */
106
+ getMiddleware() {
107
+ return this.middleware;
108
+ }
109
+ };
110
+ SagaBusService = _ts_decorate([
111
+ (0, import_common.Injectable)(),
112
+ _ts_param(0, (0, import_common.Inject)(SAGA_BUS_OPTIONS)),
113
+ _ts_metadata("design:type", Function),
114
+ _ts_metadata("design:paramtypes", [
115
+ typeof SagaBusModuleOptions === "undefined" ? Object : SagaBusModuleOptions
116
+ ])
117
+ ], SagaBusService);
118
+
119
+ // src/MessageExplorer.ts
120
+ var import_common2 = require("@nestjs/common");
121
+ var import_core = require("@nestjs/core");
122
+
123
+ // src/decorators/MessageHandler.decorator.ts
124
+ var import_reflect_metadata = require("reflect-metadata");
125
+ var MESSAGE_HANDLER_METADATA = "saga-bus:message-handler";
126
+ function MessageHandler(messageType) {
127
+ return (target, propertyKey, _descriptor) => {
128
+ const handlers = Reflect.getMetadata(MESSAGE_HANDLER_METADATA, target.constructor) || [];
129
+ handlers.push({
130
+ messageType,
131
+ methodName: propertyKey
132
+ });
133
+ Reflect.defineMetadata(MESSAGE_HANDLER_METADATA, handlers, target.constructor);
134
+ };
135
+ }
136
+ __name(MessageHandler, "MessageHandler");
137
+
138
+ // src/MessageExplorer.ts
139
+ function _ts_decorate2(decorators, target, key, desc) {
140
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
141
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
142
+ 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;
143
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
144
+ }
145
+ __name(_ts_decorate2, "_ts_decorate");
146
+ function _ts_metadata2(k, v) {
147
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
148
+ }
149
+ __name(_ts_metadata2, "_ts_metadata");
150
+ var MessageExplorer = class {
151
+ static {
152
+ __name(this, "MessageExplorer");
153
+ }
154
+ discoveryService;
155
+ sagaBusService;
156
+ constructor(discoveryService, sagaBusService) {
157
+ this.discoveryService = discoveryService;
158
+ this.sagaBusService = sagaBusService;
159
+ }
160
+ onModuleInit() {
161
+ this.exploreMessageHandlers();
162
+ }
163
+ exploreMessageHandlers() {
164
+ const providers = this.discoveryService.getProviders();
165
+ for (const wrapper of providers) {
166
+ const { instance, metatype } = wrapper;
167
+ if (!instance || !metatype) continue;
168
+ const handlers = Reflect.getMetadata(MESSAGE_HANDLER_METADATA, metatype) || [];
169
+ for (const handler of handlers) {
170
+ this.registerMessageHandler(handler, instance);
171
+ }
172
+ }
173
+ }
174
+ registerMessageHandler(handler, instance) {
175
+ const transport = this.sagaBusService.getTransport();
176
+ const method = instance[handler.methodName];
177
+ if (typeof method !== "function") {
178
+ return;
179
+ }
180
+ void transport.subscribe({
181
+ endpoint: handler.messageType
182
+ }, async (envelope) => {
183
+ await method.call(instance, envelope.payload, envelope);
184
+ });
185
+ }
186
+ };
187
+ MessageExplorer = _ts_decorate2([
188
+ (0, import_common2.Injectable)(),
189
+ _ts_metadata2("design:type", Function),
190
+ _ts_metadata2("design:paramtypes", [
191
+ typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
192
+ typeof SagaBusService === "undefined" ? Object : SagaBusService
193
+ ])
194
+ ], MessageExplorer);
195
+
196
+ // src/decorators/InjectSagaBus.decorator.ts
197
+ var import_common3 = require("@nestjs/common");
198
+ var SAGA_BUS_TOKEN = "SAGA_BUS";
199
+ function InjectSagaBus() {
200
+ return (0, import_common3.Inject)(SAGA_BUS_TOKEN);
201
+ }
202
+ __name(InjectSagaBus, "InjectSagaBus");
203
+
204
+ // src/SagaBusModule.ts
205
+ function _ts_decorate3(decorators, target, key, desc) {
206
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
207
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
208
+ 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;
209
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
210
+ }
211
+ __name(_ts_decorate3, "_ts_decorate");
212
+ var SagaBusModule = class _SagaBusModule {
213
+ static {
214
+ __name(this, "SagaBusModule");
215
+ }
216
+ /**
217
+ * Configure the module with static options.
218
+ */
219
+ static forRoot(options) {
220
+ return {
221
+ module: _SagaBusModule,
222
+ imports: [
223
+ import_core2.DiscoveryModule
224
+ ],
225
+ providers: [
226
+ {
227
+ provide: SAGA_BUS_OPTIONS,
228
+ useValue: options
229
+ },
230
+ SagaBusService,
231
+ {
232
+ provide: SAGA_BUS_TOKEN,
233
+ useExisting: SagaBusService
234
+ },
235
+ MessageExplorer
236
+ ],
237
+ exports: [
238
+ SagaBusService,
239
+ SAGA_BUS_TOKEN
240
+ ]
241
+ };
242
+ }
243
+ /**
244
+ * Configure the module with async options.
245
+ */
246
+ static forRootAsync(options) {
247
+ return {
248
+ module: _SagaBusModule,
249
+ imports: [
250
+ ...options.imports || [],
251
+ import_core2.DiscoveryModule
252
+ ],
253
+ providers: [
254
+ ...this.createAsyncProviders(options),
255
+ SagaBusService,
256
+ {
257
+ provide: SAGA_BUS_TOKEN,
258
+ useExisting: SagaBusService
259
+ },
260
+ MessageExplorer
261
+ ],
262
+ exports: [
263
+ SagaBusService,
264
+ SAGA_BUS_TOKEN
265
+ ]
266
+ };
267
+ }
268
+ static createAsyncProviders(options) {
269
+ if (options.useFactory) {
270
+ return [
271
+ {
272
+ provide: SAGA_BUS_OPTIONS,
273
+ useFactory: options.useFactory,
274
+ inject: options.inject || []
275
+ }
276
+ ];
277
+ }
278
+ const useClass = options.useClass || options.useExisting;
279
+ if (!useClass) {
280
+ throw new Error("Invalid async options: provide useFactory or useClass");
281
+ }
282
+ return [
283
+ {
284
+ provide: SAGA_BUS_OPTIONS,
285
+ useFactory: /* @__PURE__ */ __name(async (factory) => factory.createSagaBusOptions(), "useFactory"),
286
+ inject: [
287
+ useClass
288
+ ]
289
+ },
290
+ ...options.useClass ? [
291
+ {
292
+ provide: options.useClass,
293
+ useClass: options.useClass
294
+ }
295
+ ] : []
296
+ ];
297
+ }
298
+ };
299
+ SagaBusModule = _ts_decorate3([
300
+ (0, import_common4.Global)(),
301
+ (0, import_common4.Module)({})
302
+ ], SagaBusModule);
303
+ // Annotate the CommonJS export names for ESM import in node:
304
+ 0 && (module.exports = {
305
+ InjectSagaBus,
306
+ MESSAGE_HANDLER_METADATA,
307
+ MessageExplorer,
308
+ MessageHandler,
309
+ SAGA_BUS_TOKEN,
310
+ SagaBusModule,
311
+ SagaBusService
312
+ });
313
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/SagaBusModule.ts","../src/SagaBusService.ts","../src/MessageExplorer.ts","../src/decorators/MessageHandler.decorator.ts","../src/decorators/InjectSagaBus.decorator.ts"],"sourcesContent":["import \"reflect-metadata\";\n\nexport { SagaBusModule } from \"./SagaBusModule.js\";\nexport { SagaBusService } from \"./SagaBusService.js\";\nexport { MessageExplorer } from \"./MessageExplorer.js\";\nexport {\n MessageHandler,\n MESSAGE_HANDLER_METADATA,\n type MessageHandlerMetadata,\n} from \"./decorators/MessageHandler.decorator.js\";\nexport {\n InjectSagaBus,\n SAGA_BUS_TOKEN,\n} from \"./decorators/InjectSagaBus.decorator.js\";\nexport type {\n SagaBusModuleOptions,\n SagaBusModuleAsyncOptions,\n SagaBusOptionsFactory,\n} from \"./interfaces/index.js\";\n","import {\n Module,\n DynamicModule,\n Global,\n type Provider,\n type Type,\n} from \"@nestjs/common\";\nimport { DiscoveryModule } from \"@nestjs/core\";\nimport type {\n SagaBusModuleOptions,\n SagaBusModuleAsyncOptions,\n SagaBusOptionsFactory,\n} from \"./interfaces/module-options.interface.js\";\nimport { SagaBusService, SAGA_BUS_OPTIONS } from \"./SagaBusService.js\";\nimport { MessageExplorer } from \"./MessageExplorer.js\";\nimport { SAGA_BUS_TOKEN } from \"./decorators/InjectSagaBus.decorator.js\";\n\n/**\n * NestJS module for saga-bus integration.\n *\n * @example\n * ```typescript\n * @Module({\n * imports: [\n * SagaBusModule.forRoot({\n * transport: new InMemoryTransport(),\n * store: new InMemorySagaStore(),\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n@Global()\n@Module({})\nexport class SagaBusModule {\n /**\n * Configure the module with static options.\n */\n static forRoot(options: SagaBusModuleOptions): DynamicModule {\n return {\n module: SagaBusModule,\n imports: [DiscoveryModule],\n providers: [\n {\n provide: SAGA_BUS_OPTIONS,\n useValue: options,\n },\n SagaBusService,\n {\n provide: SAGA_BUS_TOKEN,\n useExisting: SagaBusService,\n },\n MessageExplorer,\n ],\n exports: [SagaBusService, SAGA_BUS_TOKEN],\n };\n }\n\n /**\n * Configure the module with async options.\n */\n static forRootAsync(options: SagaBusModuleAsyncOptions): DynamicModule {\n return {\n module: SagaBusModule,\n imports: [...(options.imports || []), DiscoveryModule],\n providers: [\n ...this.createAsyncProviders(options),\n SagaBusService,\n {\n provide: SAGA_BUS_TOKEN,\n useExisting: SagaBusService,\n },\n MessageExplorer,\n ],\n exports: [SagaBusService, SAGA_BUS_TOKEN],\n };\n }\n\n private static createAsyncProviders(\n options: SagaBusModuleAsyncOptions\n ): Provider[] {\n if (options.useFactory) {\n return [\n {\n provide: SAGA_BUS_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject || [],\n },\n ];\n }\n\n const useClass = options.useClass || options.useExisting;\n if (!useClass) {\n throw new Error(\n \"Invalid async options: provide useFactory or useClass\"\n );\n }\n\n return [\n {\n provide: SAGA_BUS_OPTIONS,\n useFactory: async (factory: SagaBusOptionsFactory) =>\n factory.createSagaBusOptions(),\n inject: [useClass as Type<SagaBusOptionsFactory>],\n },\n ...(options.useClass\n ? [{ provide: options.useClass, useClass: options.useClass }]\n : []),\n ];\n }\n}\n","import {\n Injectable,\n OnModuleInit,\n OnModuleDestroy,\n Inject,\n} from \"@nestjs/common\";\nimport type {\n Transport,\n SagaStore,\n SagaMiddleware,\n SagaState,\n BaseMessage,\n TransportPublishOptions,\n} from \"@saga-bus/core\";\nimport type { SagaBusModuleOptions } from \"./interfaces/module-options.interface.js\";\n\nexport const SAGA_BUS_OPTIONS = \"SAGA_BUS_OPTIONS\";\n\n/**\n * Service for interacting with the saga bus.\n *\n * Provides access to transport and store, and handles\n * lifecycle management (auto start/stop).\n */\n@Injectable()\nexport class SagaBusService implements OnModuleInit, OnModuleDestroy {\n private readonly transport: Transport;\n private readonly store: SagaStore<SagaState>;\n private readonly middleware: SagaMiddleware[];\n private readonly autoStart: boolean;\n private readonly autoStop: boolean;\n\n constructor(@Inject(SAGA_BUS_OPTIONS) options: SagaBusModuleOptions) {\n this.transport = options.transport;\n this.store = options.store;\n this.middleware = options.middleware ?? [];\n this.autoStart = options.autoStart ?? true;\n this.autoStop = options.autoStop ?? true;\n }\n\n async onModuleInit(): Promise<void> {\n if (this.autoStart) {\n await this.transport.start();\n }\n }\n\n async onModuleDestroy(): Promise<void> {\n if (this.autoStop) {\n await this.transport.stop();\n }\n }\n\n /**\n * Publish a message to the transport.\n */\n async publish<TMessage extends BaseMessage>(\n message: TMessage,\n options: TransportPublishOptions\n ): Promise<void> {\n await this.transport.publish(message, options);\n }\n\n /**\n * Get the underlying transport.\n */\n getTransport(): Transport {\n return this.transport;\n }\n\n /**\n * Get the underlying store.\n */\n getStore(): SagaStore<SagaState> {\n return this.store;\n }\n\n /**\n * Get the middleware pipeline.\n */\n getMiddleware(): SagaMiddleware[] {\n return this.middleware;\n }\n}\n","import { Injectable, OnModuleInit } from \"@nestjs/common\";\nimport { DiscoveryService } from \"@nestjs/core\";\nimport type { MessageEnvelope } from \"@saga-bus/core\";\nimport {\n MESSAGE_HANDLER_METADATA,\n type MessageHandlerMetadata,\n} from \"./decorators/MessageHandler.decorator.js\";\nimport { SagaBusService } from \"./SagaBusService.js\";\n\n/**\n * Discovers and registers message handlers marked with @MessageHandler.\n */\n@Injectable()\nexport class MessageExplorer implements OnModuleInit {\n constructor(\n private readonly discoveryService: DiscoveryService,\n private readonly sagaBusService: SagaBusService\n ) {}\n\n onModuleInit(): void {\n this.exploreMessageHandlers();\n }\n\n private exploreMessageHandlers(): void {\n const providers = this.discoveryService.getProviders();\n\n for (const wrapper of providers) {\n const { instance, metatype } = wrapper;\n if (!instance || !metatype) continue;\n\n const handlers: MessageHandlerMetadata[] =\n Reflect.getMetadata(MESSAGE_HANDLER_METADATA, metatype) || [];\n\n for (const handler of handlers) {\n this.registerMessageHandler(handler, instance);\n }\n }\n }\n\n private registerMessageHandler(\n handler: MessageHandlerMetadata,\n instance: object\n ): void {\n const transport = this.sagaBusService.getTransport();\n const method = (\n instance as Record<string | symbol, (...args: unknown[]) => unknown>\n )[handler.methodName];\n\n if (typeof method !== \"function\") {\n return;\n }\n\n // Subscribe to the message type\n void transport.subscribe(\n { endpoint: handler.messageType },\n async (envelope: MessageEnvelope) => {\n await method.call(instance, envelope.payload, envelope);\n }\n );\n }\n}\n","import \"reflect-metadata\";\n\nexport const MESSAGE_HANDLER_METADATA = \"saga-bus:message-handler\";\n\n/**\n * Metadata for a message handler.\n */\nexport interface MessageHandlerMetadata {\n messageType: string;\n methodName: string | symbol;\n}\n\n/**\n * Decorator to mark a method as a message handler.\n *\n * @example\n * ```typescript\n * @Injectable()\n * export class NotificationService {\n * @MessageHandler(\"OrderCreated\")\n * async onOrderCreated(payload: OrderCreatedPayload): Promise<void> {\n * // Handle message\n * }\n * }\n * ```\n */\nexport function MessageHandler(messageType: string): MethodDecorator {\n return (\n target: object,\n propertyKey: string | symbol,\n _descriptor: PropertyDescriptor\n ) => {\n const handlers: MessageHandlerMetadata[] =\n Reflect.getMetadata(MESSAGE_HANDLER_METADATA, target.constructor) || [];\n handlers.push({\n messageType,\n methodName: propertyKey,\n });\n Reflect.defineMetadata(\n MESSAGE_HANDLER_METADATA,\n handlers,\n target.constructor\n );\n };\n}\n","import { Inject } from \"@nestjs/common\";\n\nexport const SAGA_BUS_TOKEN = \"SAGA_BUS\";\n\n/**\n * Decorator to inject the SagaBusService.\n */\nexport function InjectSagaBus(): ParameterDecorator {\n return Inject(SAGA_BUS_TOKEN);\n}\n"],"mappings":"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","names":["import_reflect_metadata","import_common","import_core","SAGA_BUS_OPTIONS","SagaBusService","transport","store","middleware","autoStart","autoStop","options","onModuleInit","start","onModuleDestroy","stop","publish","message","getTransport","getStore","getMiddleware","import_common","MESSAGE_HANDLER_METADATA","MessageHandler","messageType","target","propertyKey","_descriptor","handlers","Reflect","getMetadata","push","methodName","defineMetadata","MessageExplorer","discoveryService","sagaBusService","onModuleInit","exploreMessageHandlers","providers","getProviders","wrapper","instance","metatype","handlers","Reflect","getMetadata","MESSAGE_HANDLER_METADATA","handler","registerMessageHandler","transport","getTransport","method","methodName","subscribe","endpoint","messageType","envelope","call","payload","import_common","SAGA_BUS_TOKEN","InjectSagaBus","Inject","SagaBusModule","forRoot","options","module","imports","DiscoveryModule","providers","provide","SAGA_BUS_OPTIONS","useValue","SagaBusService","SAGA_BUS_TOKEN","useExisting","MessageExplorer","exports","forRootAsync","createAsyncProviders","useFactory","inject","useClass","Error","factory","createSagaBusOptions"]}
@@ -0,0 +1,163 @@
1
+ import { ModuleMetadata, InjectionToken, Type, DynamicModule, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
+ import { Transport, SagaStore, SagaState, SagaMiddleware, BaseMessage, TransportPublishOptions } from '@saga-bus/core';
3
+ import { DiscoveryService } from '@nestjs/core';
4
+
5
+ /**
6
+ * Options for configuring the SagaBusModule.
7
+ */
8
+ interface SagaBusModuleOptions {
9
+ /**
10
+ * Transport implementation for message delivery.
11
+ */
12
+ transport: Transport;
13
+ /**
14
+ * Saga store implementation for state persistence.
15
+ */
16
+ store: SagaStore<SagaState>;
17
+ /**
18
+ * Middleware pipeline for message processing.
19
+ */
20
+ middleware?: SagaMiddleware[];
21
+ /**
22
+ * Whether to automatically start the transport.
23
+ * @default true
24
+ */
25
+ autoStart?: boolean;
26
+ /**
27
+ * Whether to automatically stop the transport on module destroy.
28
+ * @default true
29
+ */
30
+ autoStop?: boolean;
31
+ }
32
+ /**
33
+ * Factory for creating module options asynchronously.
34
+ */
35
+ interface SagaBusOptionsFactory {
36
+ createSagaBusOptions(): Promise<SagaBusModuleOptions> | SagaBusModuleOptions;
37
+ }
38
+ /**
39
+ * Async options for configuring the SagaBusModule.
40
+ */
41
+ interface SagaBusModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
42
+ /**
43
+ * Factory function for creating options.
44
+ */
45
+ useFactory?: (...args: unknown[]) => Promise<SagaBusModuleOptions> | SagaBusModuleOptions;
46
+ /**
47
+ * Dependencies to inject into the factory.
48
+ */
49
+ inject?: InjectionToken[];
50
+ /**
51
+ * Class that implements SagaBusOptionsFactory.
52
+ */
53
+ useClass?: Type<SagaBusOptionsFactory>;
54
+ /**
55
+ * Existing provider to use.
56
+ */
57
+ useExisting?: Type<SagaBusOptionsFactory>;
58
+ }
59
+
60
+ /**
61
+ * NestJS module for saga-bus integration.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * @Module({
66
+ * imports: [
67
+ * SagaBusModule.forRoot({
68
+ * transport: new InMemoryTransport(),
69
+ * store: new InMemorySagaStore(),
70
+ * }),
71
+ * ],
72
+ * })
73
+ * export class AppModule {}
74
+ * ```
75
+ */
76
+ declare class SagaBusModule {
77
+ /**
78
+ * Configure the module with static options.
79
+ */
80
+ static forRoot(options: SagaBusModuleOptions): DynamicModule;
81
+ /**
82
+ * Configure the module with async options.
83
+ */
84
+ static forRootAsync(options: SagaBusModuleAsyncOptions): DynamicModule;
85
+ private static createAsyncProviders;
86
+ }
87
+
88
+ /**
89
+ * Service for interacting with the saga bus.
90
+ *
91
+ * Provides access to transport and store, and handles
92
+ * lifecycle management (auto start/stop).
93
+ */
94
+ declare class SagaBusService implements OnModuleInit, OnModuleDestroy {
95
+ private readonly transport;
96
+ private readonly store;
97
+ private readonly middleware;
98
+ private readonly autoStart;
99
+ private readonly autoStop;
100
+ constructor(options: SagaBusModuleOptions);
101
+ onModuleInit(): Promise<void>;
102
+ onModuleDestroy(): Promise<void>;
103
+ /**
104
+ * Publish a message to the transport.
105
+ */
106
+ publish<TMessage extends BaseMessage>(message: TMessage, options: TransportPublishOptions): Promise<void>;
107
+ /**
108
+ * Get the underlying transport.
109
+ */
110
+ getTransport(): Transport;
111
+ /**
112
+ * Get the underlying store.
113
+ */
114
+ getStore(): SagaStore<SagaState>;
115
+ /**
116
+ * Get the middleware pipeline.
117
+ */
118
+ getMiddleware(): SagaMiddleware[];
119
+ }
120
+
121
+ /**
122
+ * Discovers and registers message handlers marked with @MessageHandler.
123
+ */
124
+ declare class MessageExplorer implements OnModuleInit {
125
+ private readonly discoveryService;
126
+ private readonly sagaBusService;
127
+ constructor(discoveryService: DiscoveryService, sagaBusService: SagaBusService);
128
+ onModuleInit(): void;
129
+ private exploreMessageHandlers;
130
+ private registerMessageHandler;
131
+ }
132
+
133
+ declare const MESSAGE_HANDLER_METADATA = "saga-bus:message-handler";
134
+ /**
135
+ * Metadata for a message handler.
136
+ */
137
+ interface MessageHandlerMetadata {
138
+ messageType: string;
139
+ methodName: string | symbol;
140
+ }
141
+ /**
142
+ * Decorator to mark a method as a message handler.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * @Injectable()
147
+ * export class NotificationService {
148
+ * @MessageHandler("OrderCreated")
149
+ * async onOrderCreated(payload: OrderCreatedPayload): Promise<void> {
150
+ * // Handle message
151
+ * }
152
+ * }
153
+ * ```
154
+ */
155
+ declare function MessageHandler(messageType: string): MethodDecorator;
156
+
157
+ declare const SAGA_BUS_TOKEN = "SAGA_BUS";
158
+ /**
159
+ * Decorator to inject the SagaBusService.
160
+ */
161
+ declare function InjectSagaBus(): ParameterDecorator;
162
+
163
+ export { InjectSagaBus, MESSAGE_HANDLER_METADATA, MessageExplorer, MessageHandler, type MessageHandlerMetadata, SAGA_BUS_TOKEN, SagaBusModule, type SagaBusModuleAsyncOptions, type SagaBusModuleOptions, type SagaBusOptionsFactory, SagaBusService };
@@ -0,0 +1,163 @@
1
+ import { ModuleMetadata, InjectionToken, Type, DynamicModule, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
+ import { Transport, SagaStore, SagaState, SagaMiddleware, BaseMessage, TransportPublishOptions } from '@saga-bus/core';
3
+ import { DiscoveryService } from '@nestjs/core';
4
+
5
+ /**
6
+ * Options for configuring the SagaBusModule.
7
+ */
8
+ interface SagaBusModuleOptions {
9
+ /**
10
+ * Transport implementation for message delivery.
11
+ */
12
+ transport: Transport;
13
+ /**
14
+ * Saga store implementation for state persistence.
15
+ */
16
+ store: SagaStore<SagaState>;
17
+ /**
18
+ * Middleware pipeline for message processing.
19
+ */
20
+ middleware?: SagaMiddleware[];
21
+ /**
22
+ * Whether to automatically start the transport.
23
+ * @default true
24
+ */
25
+ autoStart?: boolean;
26
+ /**
27
+ * Whether to automatically stop the transport on module destroy.
28
+ * @default true
29
+ */
30
+ autoStop?: boolean;
31
+ }
32
+ /**
33
+ * Factory for creating module options asynchronously.
34
+ */
35
+ interface SagaBusOptionsFactory {
36
+ createSagaBusOptions(): Promise<SagaBusModuleOptions> | SagaBusModuleOptions;
37
+ }
38
+ /**
39
+ * Async options for configuring the SagaBusModule.
40
+ */
41
+ interface SagaBusModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
42
+ /**
43
+ * Factory function for creating options.
44
+ */
45
+ useFactory?: (...args: unknown[]) => Promise<SagaBusModuleOptions> | SagaBusModuleOptions;
46
+ /**
47
+ * Dependencies to inject into the factory.
48
+ */
49
+ inject?: InjectionToken[];
50
+ /**
51
+ * Class that implements SagaBusOptionsFactory.
52
+ */
53
+ useClass?: Type<SagaBusOptionsFactory>;
54
+ /**
55
+ * Existing provider to use.
56
+ */
57
+ useExisting?: Type<SagaBusOptionsFactory>;
58
+ }
59
+
60
+ /**
61
+ * NestJS module for saga-bus integration.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * @Module({
66
+ * imports: [
67
+ * SagaBusModule.forRoot({
68
+ * transport: new InMemoryTransport(),
69
+ * store: new InMemorySagaStore(),
70
+ * }),
71
+ * ],
72
+ * })
73
+ * export class AppModule {}
74
+ * ```
75
+ */
76
+ declare class SagaBusModule {
77
+ /**
78
+ * Configure the module with static options.
79
+ */
80
+ static forRoot(options: SagaBusModuleOptions): DynamicModule;
81
+ /**
82
+ * Configure the module with async options.
83
+ */
84
+ static forRootAsync(options: SagaBusModuleAsyncOptions): DynamicModule;
85
+ private static createAsyncProviders;
86
+ }
87
+
88
+ /**
89
+ * Service for interacting with the saga bus.
90
+ *
91
+ * Provides access to transport and store, and handles
92
+ * lifecycle management (auto start/stop).
93
+ */
94
+ declare class SagaBusService implements OnModuleInit, OnModuleDestroy {
95
+ private readonly transport;
96
+ private readonly store;
97
+ private readonly middleware;
98
+ private readonly autoStart;
99
+ private readonly autoStop;
100
+ constructor(options: SagaBusModuleOptions);
101
+ onModuleInit(): Promise<void>;
102
+ onModuleDestroy(): Promise<void>;
103
+ /**
104
+ * Publish a message to the transport.
105
+ */
106
+ publish<TMessage extends BaseMessage>(message: TMessage, options: TransportPublishOptions): Promise<void>;
107
+ /**
108
+ * Get the underlying transport.
109
+ */
110
+ getTransport(): Transport;
111
+ /**
112
+ * Get the underlying store.
113
+ */
114
+ getStore(): SagaStore<SagaState>;
115
+ /**
116
+ * Get the middleware pipeline.
117
+ */
118
+ getMiddleware(): SagaMiddleware[];
119
+ }
120
+
121
+ /**
122
+ * Discovers and registers message handlers marked with @MessageHandler.
123
+ */
124
+ declare class MessageExplorer implements OnModuleInit {
125
+ private readonly discoveryService;
126
+ private readonly sagaBusService;
127
+ constructor(discoveryService: DiscoveryService, sagaBusService: SagaBusService);
128
+ onModuleInit(): void;
129
+ private exploreMessageHandlers;
130
+ private registerMessageHandler;
131
+ }
132
+
133
+ declare const MESSAGE_HANDLER_METADATA = "saga-bus:message-handler";
134
+ /**
135
+ * Metadata for a message handler.
136
+ */
137
+ interface MessageHandlerMetadata {
138
+ messageType: string;
139
+ methodName: string | symbol;
140
+ }
141
+ /**
142
+ * Decorator to mark a method as a message handler.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * @Injectable()
147
+ * export class NotificationService {
148
+ * @MessageHandler("OrderCreated")
149
+ * async onOrderCreated(payload: OrderCreatedPayload): Promise<void> {
150
+ * // Handle message
151
+ * }
152
+ * }
153
+ * ```
154
+ */
155
+ declare function MessageHandler(messageType: string): MethodDecorator;
156
+
157
+ declare const SAGA_BUS_TOKEN = "SAGA_BUS";
158
+ /**
159
+ * Decorator to inject the SagaBusService.
160
+ */
161
+ declare function InjectSagaBus(): ParameterDecorator;
162
+
163
+ export { InjectSagaBus, MESSAGE_HANDLER_METADATA, MessageExplorer, MessageHandler, type MessageHandlerMetadata, SAGA_BUS_TOKEN, SagaBusModule, type SagaBusModuleAsyncOptions, type SagaBusModuleOptions, type SagaBusOptionsFactory, SagaBusService };
package/dist/index.js ADDED
@@ -0,0 +1,284 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/index.ts
5
+ import "reflect-metadata";
6
+
7
+ // src/SagaBusModule.ts
8
+ import { Module, Global } from "@nestjs/common";
9
+ import { DiscoveryModule } from "@nestjs/core";
10
+
11
+ // src/SagaBusService.ts
12
+ import { Injectable, Inject } from "@nestjs/common";
13
+ function _ts_decorate(decorators, target, key, desc) {
14
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
+ 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;
17
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
18
+ }
19
+ __name(_ts_decorate, "_ts_decorate");
20
+ function _ts_metadata(k, v) {
21
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22
+ }
23
+ __name(_ts_metadata, "_ts_metadata");
24
+ function _ts_param(paramIndex, decorator) {
25
+ return function(target, key) {
26
+ decorator(target, key, paramIndex);
27
+ };
28
+ }
29
+ __name(_ts_param, "_ts_param");
30
+ var SAGA_BUS_OPTIONS = "SAGA_BUS_OPTIONS";
31
+ var SagaBusService = class {
32
+ static {
33
+ __name(this, "SagaBusService");
34
+ }
35
+ transport;
36
+ store;
37
+ middleware;
38
+ autoStart;
39
+ autoStop;
40
+ constructor(options) {
41
+ this.transport = options.transport;
42
+ this.store = options.store;
43
+ this.middleware = options.middleware ?? [];
44
+ this.autoStart = options.autoStart ?? true;
45
+ this.autoStop = options.autoStop ?? true;
46
+ }
47
+ async onModuleInit() {
48
+ if (this.autoStart) {
49
+ await this.transport.start();
50
+ }
51
+ }
52
+ async onModuleDestroy() {
53
+ if (this.autoStop) {
54
+ await this.transport.stop();
55
+ }
56
+ }
57
+ /**
58
+ * Publish a message to the transport.
59
+ */
60
+ async publish(message, options) {
61
+ await this.transport.publish(message, options);
62
+ }
63
+ /**
64
+ * Get the underlying transport.
65
+ */
66
+ getTransport() {
67
+ return this.transport;
68
+ }
69
+ /**
70
+ * Get the underlying store.
71
+ */
72
+ getStore() {
73
+ return this.store;
74
+ }
75
+ /**
76
+ * Get the middleware pipeline.
77
+ */
78
+ getMiddleware() {
79
+ return this.middleware;
80
+ }
81
+ };
82
+ SagaBusService = _ts_decorate([
83
+ Injectable(),
84
+ _ts_param(0, Inject(SAGA_BUS_OPTIONS)),
85
+ _ts_metadata("design:type", Function),
86
+ _ts_metadata("design:paramtypes", [
87
+ typeof SagaBusModuleOptions === "undefined" ? Object : SagaBusModuleOptions
88
+ ])
89
+ ], SagaBusService);
90
+
91
+ // src/MessageExplorer.ts
92
+ import { Injectable as Injectable2 } from "@nestjs/common";
93
+ import { DiscoveryService } from "@nestjs/core";
94
+
95
+ // src/decorators/MessageHandler.decorator.ts
96
+ import "reflect-metadata";
97
+ var MESSAGE_HANDLER_METADATA = "saga-bus:message-handler";
98
+ function MessageHandler(messageType) {
99
+ return (target, propertyKey, _descriptor) => {
100
+ const handlers = Reflect.getMetadata(MESSAGE_HANDLER_METADATA, target.constructor) || [];
101
+ handlers.push({
102
+ messageType,
103
+ methodName: propertyKey
104
+ });
105
+ Reflect.defineMetadata(MESSAGE_HANDLER_METADATA, handlers, target.constructor);
106
+ };
107
+ }
108
+ __name(MessageHandler, "MessageHandler");
109
+
110
+ // src/MessageExplorer.ts
111
+ function _ts_decorate2(decorators, target, key, desc) {
112
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
113
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
114
+ 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;
115
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
116
+ }
117
+ __name(_ts_decorate2, "_ts_decorate");
118
+ function _ts_metadata2(k, v) {
119
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
120
+ }
121
+ __name(_ts_metadata2, "_ts_metadata");
122
+ var MessageExplorer = class {
123
+ static {
124
+ __name(this, "MessageExplorer");
125
+ }
126
+ discoveryService;
127
+ sagaBusService;
128
+ constructor(discoveryService, sagaBusService) {
129
+ this.discoveryService = discoveryService;
130
+ this.sagaBusService = sagaBusService;
131
+ }
132
+ onModuleInit() {
133
+ this.exploreMessageHandlers();
134
+ }
135
+ exploreMessageHandlers() {
136
+ const providers = this.discoveryService.getProviders();
137
+ for (const wrapper of providers) {
138
+ const { instance, metatype } = wrapper;
139
+ if (!instance || !metatype) continue;
140
+ const handlers = Reflect.getMetadata(MESSAGE_HANDLER_METADATA, metatype) || [];
141
+ for (const handler of handlers) {
142
+ this.registerMessageHandler(handler, instance);
143
+ }
144
+ }
145
+ }
146
+ registerMessageHandler(handler, instance) {
147
+ const transport = this.sagaBusService.getTransport();
148
+ const method = instance[handler.methodName];
149
+ if (typeof method !== "function") {
150
+ return;
151
+ }
152
+ void transport.subscribe({
153
+ endpoint: handler.messageType
154
+ }, async (envelope) => {
155
+ await method.call(instance, envelope.payload, envelope);
156
+ });
157
+ }
158
+ };
159
+ MessageExplorer = _ts_decorate2([
160
+ Injectable2(),
161
+ _ts_metadata2("design:type", Function),
162
+ _ts_metadata2("design:paramtypes", [
163
+ typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
164
+ typeof SagaBusService === "undefined" ? Object : SagaBusService
165
+ ])
166
+ ], MessageExplorer);
167
+
168
+ // src/decorators/InjectSagaBus.decorator.ts
169
+ import { Inject as Inject2 } from "@nestjs/common";
170
+ var SAGA_BUS_TOKEN = "SAGA_BUS";
171
+ function InjectSagaBus() {
172
+ return Inject2(SAGA_BUS_TOKEN);
173
+ }
174
+ __name(InjectSagaBus, "InjectSagaBus");
175
+
176
+ // src/SagaBusModule.ts
177
+ function _ts_decorate3(decorators, target, key, desc) {
178
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
179
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
180
+ 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;
181
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
182
+ }
183
+ __name(_ts_decorate3, "_ts_decorate");
184
+ var SagaBusModule = class _SagaBusModule {
185
+ static {
186
+ __name(this, "SagaBusModule");
187
+ }
188
+ /**
189
+ * Configure the module with static options.
190
+ */
191
+ static forRoot(options) {
192
+ return {
193
+ module: _SagaBusModule,
194
+ imports: [
195
+ DiscoveryModule
196
+ ],
197
+ providers: [
198
+ {
199
+ provide: SAGA_BUS_OPTIONS,
200
+ useValue: options
201
+ },
202
+ SagaBusService,
203
+ {
204
+ provide: SAGA_BUS_TOKEN,
205
+ useExisting: SagaBusService
206
+ },
207
+ MessageExplorer
208
+ ],
209
+ exports: [
210
+ SagaBusService,
211
+ SAGA_BUS_TOKEN
212
+ ]
213
+ };
214
+ }
215
+ /**
216
+ * Configure the module with async options.
217
+ */
218
+ static forRootAsync(options) {
219
+ return {
220
+ module: _SagaBusModule,
221
+ imports: [
222
+ ...options.imports || [],
223
+ DiscoveryModule
224
+ ],
225
+ providers: [
226
+ ...this.createAsyncProviders(options),
227
+ SagaBusService,
228
+ {
229
+ provide: SAGA_BUS_TOKEN,
230
+ useExisting: SagaBusService
231
+ },
232
+ MessageExplorer
233
+ ],
234
+ exports: [
235
+ SagaBusService,
236
+ SAGA_BUS_TOKEN
237
+ ]
238
+ };
239
+ }
240
+ static createAsyncProviders(options) {
241
+ if (options.useFactory) {
242
+ return [
243
+ {
244
+ provide: SAGA_BUS_OPTIONS,
245
+ useFactory: options.useFactory,
246
+ inject: options.inject || []
247
+ }
248
+ ];
249
+ }
250
+ const useClass = options.useClass || options.useExisting;
251
+ if (!useClass) {
252
+ throw new Error("Invalid async options: provide useFactory or useClass");
253
+ }
254
+ return [
255
+ {
256
+ provide: SAGA_BUS_OPTIONS,
257
+ useFactory: /* @__PURE__ */ __name(async (factory) => factory.createSagaBusOptions(), "useFactory"),
258
+ inject: [
259
+ useClass
260
+ ]
261
+ },
262
+ ...options.useClass ? [
263
+ {
264
+ provide: options.useClass,
265
+ useClass: options.useClass
266
+ }
267
+ ] : []
268
+ ];
269
+ }
270
+ };
271
+ SagaBusModule = _ts_decorate3([
272
+ Global(),
273
+ Module({})
274
+ ], SagaBusModule);
275
+ export {
276
+ InjectSagaBus,
277
+ MESSAGE_HANDLER_METADATA,
278
+ MessageExplorer,
279
+ MessageHandler,
280
+ SAGA_BUS_TOKEN,
281
+ SagaBusModule,
282
+ SagaBusService
283
+ };
284
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/SagaBusModule.ts","../src/SagaBusService.ts","../src/MessageExplorer.ts","../src/decorators/MessageHandler.decorator.ts","../src/decorators/InjectSagaBus.decorator.ts"],"sourcesContent":["import \"reflect-metadata\";\n\nexport { SagaBusModule } from \"./SagaBusModule.js\";\nexport { SagaBusService } from \"./SagaBusService.js\";\nexport { MessageExplorer } from \"./MessageExplorer.js\";\nexport {\n MessageHandler,\n MESSAGE_HANDLER_METADATA,\n type MessageHandlerMetadata,\n} from \"./decorators/MessageHandler.decorator.js\";\nexport {\n InjectSagaBus,\n SAGA_BUS_TOKEN,\n} from \"./decorators/InjectSagaBus.decorator.js\";\nexport type {\n SagaBusModuleOptions,\n SagaBusModuleAsyncOptions,\n SagaBusOptionsFactory,\n} from \"./interfaces/index.js\";\n","import {\n Module,\n DynamicModule,\n Global,\n type Provider,\n type Type,\n} from \"@nestjs/common\";\nimport { DiscoveryModule } from \"@nestjs/core\";\nimport type {\n SagaBusModuleOptions,\n SagaBusModuleAsyncOptions,\n SagaBusOptionsFactory,\n} from \"./interfaces/module-options.interface.js\";\nimport { SagaBusService, SAGA_BUS_OPTIONS } from \"./SagaBusService.js\";\nimport { MessageExplorer } from \"./MessageExplorer.js\";\nimport { SAGA_BUS_TOKEN } from \"./decorators/InjectSagaBus.decorator.js\";\n\n/**\n * NestJS module for saga-bus integration.\n *\n * @example\n * ```typescript\n * @Module({\n * imports: [\n * SagaBusModule.forRoot({\n * transport: new InMemoryTransport(),\n * store: new InMemorySagaStore(),\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n@Global()\n@Module({})\nexport class SagaBusModule {\n /**\n * Configure the module with static options.\n */\n static forRoot(options: SagaBusModuleOptions): DynamicModule {\n return {\n module: SagaBusModule,\n imports: [DiscoveryModule],\n providers: [\n {\n provide: SAGA_BUS_OPTIONS,\n useValue: options,\n },\n SagaBusService,\n {\n provide: SAGA_BUS_TOKEN,\n useExisting: SagaBusService,\n },\n MessageExplorer,\n ],\n exports: [SagaBusService, SAGA_BUS_TOKEN],\n };\n }\n\n /**\n * Configure the module with async options.\n */\n static forRootAsync(options: SagaBusModuleAsyncOptions): DynamicModule {\n return {\n module: SagaBusModule,\n imports: [...(options.imports || []), DiscoveryModule],\n providers: [\n ...this.createAsyncProviders(options),\n SagaBusService,\n {\n provide: SAGA_BUS_TOKEN,\n useExisting: SagaBusService,\n },\n MessageExplorer,\n ],\n exports: [SagaBusService, SAGA_BUS_TOKEN],\n };\n }\n\n private static createAsyncProviders(\n options: SagaBusModuleAsyncOptions\n ): Provider[] {\n if (options.useFactory) {\n return [\n {\n provide: SAGA_BUS_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject || [],\n },\n ];\n }\n\n const useClass = options.useClass || options.useExisting;\n if (!useClass) {\n throw new Error(\n \"Invalid async options: provide useFactory or useClass\"\n );\n }\n\n return [\n {\n provide: SAGA_BUS_OPTIONS,\n useFactory: async (factory: SagaBusOptionsFactory) =>\n factory.createSagaBusOptions(),\n inject: [useClass as Type<SagaBusOptionsFactory>],\n },\n ...(options.useClass\n ? [{ provide: options.useClass, useClass: options.useClass }]\n : []),\n ];\n }\n}\n","import {\n Injectable,\n OnModuleInit,\n OnModuleDestroy,\n Inject,\n} from \"@nestjs/common\";\nimport type {\n Transport,\n SagaStore,\n SagaMiddleware,\n SagaState,\n BaseMessage,\n TransportPublishOptions,\n} from \"@saga-bus/core\";\nimport type { SagaBusModuleOptions } from \"./interfaces/module-options.interface.js\";\n\nexport const SAGA_BUS_OPTIONS = \"SAGA_BUS_OPTIONS\";\n\n/**\n * Service for interacting with the saga bus.\n *\n * Provides access to transport and store, and handles\n * lifecycle management (auto start/stop).\n */\n@Injectable()\nexport class SagaBusService implements OnModuleInit, OnModuleDestroy {\n private readonly transport: Transport;\n private readonly store: SagaStore<SagaState>;\n private readonly middleware: SagaMiddleware[];\n private readonly autoStart: boolean;\n private readonly autoStop: boolean;\n\n constructor(@Inject(SAGA_BUS_OPTIONS) options: SagaBusModuleOptions) {\n this.transport = options.transport;\n this.store = options.store;\n this.middleware = options.middleware ?? [];\n this.autoStart = options.autoStart ?? true;\n this.autoStop = options.autoStop ?? true;\n }\n\n async onModuleInit(): Promise<void> {\n if (this.autoStart) {\n await this.transport.start();\n }\n }\n\n async onModuleDestroy(): Promise<void> {\n if (this.autoStop) {\n await this.transport.stop();\n }\n }\n\n /**\n * Publish a message to the transport.\n */\n async publish<TMessage extends BaseMessage>(\n message: TMessage,\n options: TransportPublishOptions\n ): Promise<void> {\n await this.transport.publish(message, options);\n }\n\n /**\n * Get the underlying transport.\n */\n getTransport(): Transport {\n return this.transport;\n }\n\n /**\n * Get the underlying store.\n */\n getStore(): SagaStore<SagaState> {\n return this.store;\n }\n\n /**\n * Get the middleware pipeline.\n */\n getMiddleware(): SagaMiddleware[] {\n return this.middleware;\n }\n}\n","import { Injectable, OnModuleInit } from \"@nestjs/common\";\nimport { DiscoveryService } from \"@nestjs/core\";\nimport type { MessageEnvelope } from \"@saga-bus/core\";\nimport {\n MESSAGE_HANDLER_METADATA,\n type MessageHandlerMetadata,\n} from \"./decorators/MessageHandler.decorator.js\";\nimport { SagaBusService } from \"./SagaBusService.js\";\n\n/**\n * Discovers and registers message handlers marked with @MessageHandler.\n */\n@Injectable()\nexport class MessageExplorer implements OnModuleInit {\n constructor(\n private readonly discoveryService: DiscoveryService,\n private readonly sagaBusService: SagaBusService\n ) {}\n\n onModuleInit(): void {\n this.exploreMessageHandlers();\n }\n\n private exploreMessageHandlers(): void {\n const providers = this.discoveryService.getProviders();\n\n for (const wrapper of providers) {\n const { instance, metatype } = wrapper;\n if (!instance || !metatype) continue;\n\n const handlers: MessageHandlerMetadata[] =\n Reflect.getMetadata(MESSAGE_HANDLER_METADATA, metatype) || [];\n\n for (const handler of handlers) {\n this.registerMessageHandler(handler, instance);\n }\n }\n }\n\n private registerMessageHandler(\n handler: MessageHandlerMetadata,\n instance: object\n ): void {\n const transport = this.sagaBusService.getTransport();\n const method = (\n instance as Record<string | symbol, (...args: unknown[]) => unknown>\n )[handler.methodName];\n\n if (typeof method !== \"function\") {\n return;\n }\n\n // Subscribe to the message type\n void transport.subscribe(\n { endpoint: handler.messageType },\n async (envelope: MessageEnvelope) => {\n await method.call(instance, envelope.payload, envelope);\n }\n );\n }\n}\n","import \"reflect-metadata\";\n\nexport const MESSAGE_HANDLER_METADATA = \"saga-bus:message-handler\";\n\n/**\n * Metadata for a message handler.\n */\nexport interface MessageHandlerMetadata {\n messageType: string;\n methodName: string | symbol;\n}\n\n/**\n * Decorator to mark a method as a message handler.\n *\n * @example\n * ```typescript\n * @Injectable()\n * export class NotificationService {\n * @MessageHandler(\"OrderCreated\")\n * async onOrderCreated(payload: OrderCreatedPayload): Promise<void> {\n * // Handle message\n * }\n * }\n * ```\n */\nexport function MessageHandler(messageType: string): MethodDecorator {\n return (\n target: object,\n propertyKey: string | symbol,\n _descriptor: PropertyDescriptor\n ) => {\n const handlers: MessageHandlerMetadata[] =\n Reflect.getMetadata(MESSAGE_HANDLER_METADATA, target.constructor) || [];\n handlers.push({\n messageType,\n methodName: propertyKey,\n });\n Reflect.defineMetadata(\n MESSAGE_HANDLER_METADATA,\n handlers,\n target.constructor\n );\n };\n}\n","import { Inject } from \"@nestjs/common\";\n\nexport const SAGA_BUS_TOKEN = \"SAGA_BUS\";\n\n/**\n * Decorator to inject the SagaBusService.\n */\nexport function InjectSagaBus(): ParameterDecorator {\n return Inject(SAGA_BUS_TOKEN);\n}\n"],"mappings":"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","names":["Module","Global","DiscoveryModule","Injectable","Inject","SAGA_BUS_OPTIONS","SagaBusService","transport","store","middleware","autoStart","autoStop","options","onModuleInit","start","onModuleDestroy","stop","publish","message","getTransport","getStore","getMiddleware","Injectable","DiscoveryService","MESSAGE_HANDLER_METADATA","MessageHandler","messageType","target","propertyKey","_descriptor","handlers","Reflect","getMetadata","push","methodName","defineMetadata","MessageExplorer","discoveryService","sagaBusService","onModuleInit","exploreMessageHandlers","providers","getProviders","wrapper","instance","metatype","handlers","Reflect","getMetadata","MESSAGE_HANDLER_METADATA","handler","registerMessageHandler","transport","getTransport","method","methodName","subscribe","endpoint","messageType","envelope","call","payload","Inject","SAGA_BUS_TOKEN","InjectSagaBus","Inject","SagaBusModule","forRoot","options","module","imports","DiscoveryModule","providers","provide","SAGA_BUS_OPTIONS","useValue","SagaBusService","SAGA_BUS_TOKEN","useExisting","MessageExplorer","exports","forRootAsync","createAsyncProviders","useFactory","inject","useClass","Error","factory","createSagaBusOptions"]}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@saga-bus/nestjs",
3
+ "version": "0.1.0",
4
+ "description": "NestJS module for saga-bus",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/deanforan/saga-bus.git",
26
+ "directory": "packages/nestjs"
27
+ },
28
+ "keywords": [
29
+ "saga",
30
+ "message-bus",
31
+ "nestjs",
32
+ "module",
33
+ "dependency-injection"
34
+ ],
35
+ "dependencies": {
36
+ "@saga-bus/core": "0.1.0"
37
+ },
38
+ "devDependencies": {
39
+ "@nestjs/common": "^10.4.0",
40
+ "@nestjs/core": "^10.4.0",
41
+ "@nestjs/testing": "^10.4.0",
42
+ "@swc/core": "^1.15.3",
43
+ "@types/node": "^20.0.0",
44
+ "reflect-metadata": "^0.2.0",
45
+ "rxjs": "^7.8.0",
46
+ "tsup": "^8.0.0",
47
+ "typescript": "^5.9.2",
48
+ "vitest": "^3.0.0",
49
+ "@repo/eslint-config": "0.0.0",
50
+ "@repo/typescript-config": "0.0.0",
51
+ "@saga-bus/store-inmemory": "1.0.0",
52
+ "@saga-bus/transport-inmemory": "1.0.0"
53
+ },
54
+ "peerDependencies": {
55
+ "@nestjs/common": ">=10.0.0",
56
+ "@nestjs/core": ">=10.0.0",
57
+ "reflect-metadata": ">=0.1.0"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "dev": "tsup --watch",
62
+ "lint": "eslint src/",
63
+ "check-types": "tsc --noEmit",
64
+ "test": "vitest run",
65
+ "test:watch": "vitest"
66
+ }
67
+ }