@warlock.js/herald 4.0.162 → 4.0.164
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/cjs/communicators/communicator-registry.d.ts +155 -0
- package/cjs/communicators/communicator-registry.d.ts.map +1 -0
- package/cjs/communicators/communicator-registry.js +206 -0
- package/cjs/communicators/communicator-registry.js.map +1 -0
- package/cjs/communicators/communicator.d.ts +100 -0
- package/cjs/communicators/communicator.d.ts.map +1 -0
- package/cjs/communicators/communicator.js +105 -0
- package/cjs/communicators/communicator.js.map +1 -0
- package/cjs/communicators/index.d.ts +3 -0
- package/cjs/communicators/index.d.ts.map +1 -0
- package/cjs/contracts/channel.contract.d.ts +186 -0
- package/cjs/contracts/channel.contract.d.ts.map +1 -0
- package/cjs/contracts/communicator-driver.contract.d.ts +196 -0
- package/cjs/contracts/communicator-driver.contract.d.ts.map +1 -0
- package/cjs/contracts/index.d.ts +3 -0
- package/cjs/contracts/index.d.ts.map +1 -0
- package/cjs/decorators/consumable.d.ts +13 -0
- package/cjs/decorators/consumable.d.ts.map +1 -0
- package/cjs/decorators/consumable.js +33 -0
- package/cjs/decorators/consumable.js.map +1 -0
- package/cjs/decorators/index.d.ts +2 -0
- package/cjs/decorators/index.d.ts.map +1 -0
- package/cjs/drivers/index.d.ts +2 -0
- package/cjs/drivers/index.d.ts.map +1 -0
- package/cjs/drivers/rabbitmq/index.d.ts +3 -0
- package/cjs/drivers/rabbitmq/index.d.ts.map +1 -0
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts +78 -0
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts.map +1 -0
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js +412 -0
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js.map +1 -0
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts +122 -0
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts.map +1 -0
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js +346 -0
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js.map +1 -0
- package/cjs/index.d.ts +47 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -0
- package/cjs/message-managers/event-consumer.d.ts +63 -0
- package/cjs/message-managers/event-consumer.d.ts.map +1 -0
- package/cjs/message-managers/event-consumer.js +65 -0
- package/cjs/message-managers/event-consumer.js.map +1 -0
- package/cjs/message-managers/event-message.d.ts +87 -0
- package/cjs/message-managers/event-message.d.ts.map +1 -0
- package/cjs/message-managers/event-message.js +84 -0
- package/cjs/message-managers/event-message.js.map +1 -0
- package/cjs/message-managers/index.d.ts +4 -0
- package/cjs/message-managers/index.d.ts.map +1 -0
- package/cjs/message-managers/prepare-consumer-subscription.d.ts +4 -0
- package/cjs/message-managers/prepare-consumer-subscription.d.ts.map +1 -0
- package/cjs/message-managers/prepare-consumer-subscription.js +39 -0
- package/cjs/message-managers/prepare-consumer-subscription.js.map +1 -0
- package/cjs/message-managers/types.d.ts +20 -0
- package/cjs/message-managers/types.d.ts.map +1 -0
- package/cjs/types.d.ts +399 -0
- package/cjs/types.d.ts.map +1 -0
- package/cjs/utils/connect-to-communicator.d.ts +129 -0
- package/cjs/utils/connect-to-communicator.d.ts.map +1 -0
- package/cjs/utils/connect-to-communicator.js +169 -0
- package/cjs/utils/connect-to-communicator.js.map +1 -0
- package/cjs/utils/index.d.ts +2 -0
- package/cjs/utils/index.d.ts.map +1 -0
- package/esm/decorators/consumable.d.ts +13 -0
- package/esm/decorators/consumable.d.ts.map +1 -0
- package/esm/decorators/consumable.js +33 -0
- package/esm/decorators/consumable.js.map +1 -0
- package/esm/decorators/index.d.ts +2 -0
- package/esm/decorators/index.d.ts.map +1 -0
- package/esm/drivers/index.d.ts +2 -0
- package/esm/drivers/index.d.ts.map +1 -0
- package/esm/drivers/rabbitmq/index.d.ts +3 -0
- package/esm/drivers/rabbitmq/index.d.ts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts +78 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.js +412 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.js.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts +122 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.js +346 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.js.map +1 -0
- package/esm/index.d.ts +47 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -0
- package/esm/message-managers/event-consumer.d.ts +63 -0
- package/esm/message-managers/event-consumer.d.ts.map +1 -0
- package/esm/message-managers/event-consumer.js +65 -0
- package/esm/message-managers/event-consumer.js.map +1 -0
- package/esm/message-managers/event-message.d.ts +87 -0
- package/esm/message-managers/event-message.d.ts.map +1 -0
- package/esm/message-managers/event-message.js +84 -0
- package/esm/message-managers/event-message.js.map +1 -0
- package/esm/message-managers/index.d.ts +4 -0
- package/esm/message-managers/index.d.ts.map +1 -0
- package/esm/message-managers/prepare-consumer-subscription.d.ts +4 -0
- package/esm/message-managers/prepare-consumer-subscription.d.ts.map +1 -0
- package/esm/message-managers/prepare-consumer-subscription.js +39 -0
- package/esm/message-managers/prepare-consumer-subscription.js.map +1 -0
- package/esm/message-managers/types.d.ts +20 -0
- package/esm/message-managers/types.d.ts.map +1 -0
- package/esm/types.d.ts +399 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/utils/connect-to-communicator.d.ts +129 -0
- package/esm/utils/connect-to-communicator.d.ts.map +1 -0
- package/esm/utils/connect-to-communicator.js +169 -0
- package/esm/utils/connect-to-communicator.js.map +1 -0
- package/esm/utils/index.d.ts +2 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Communicator } from "../communicators";
|
|
2
|
+
import type { ChannelContract } from "../contracts";
|
|
3
|
+
import { EventConsumerClass, EventMessage } from "../message-managers";
|
|
4
|
+
import type { ChannelOptions, ConnectionOptions } from "../types";
|
|
5
|
+
/**
|
|
6
|
+
* Connect to a message broker and register the communicator.
|
|
7
|
+
*
|
|
8
|
+
* This is a high-level utility function that simplifies connection setup
|
|
9
|
+
* for most projects. It handles driver instantiation, connection,
|
|
10
|
+
* communicator creation, and automatic registration.
|
|
11
|
+
*
|
|
12
|
+
* **Supported Drivers:**
|
|
13
|
+
* - `rabbitmq` (default) - RabbitMQ/AMQP driver
|
|
14
|
+
* - `kafka` - Apache Kafka driver (coming soon)
|
|
15
|
+
*
|
|
16
|
+
* @param options - Connection configuration options
|
|
17
|
+
* @returns A connected and registered Communicator instance
|
|
18
|
+
* @throws {Error} If connection fails or driver is not implemented
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // RabbitMQ connection
|
|
23
|
+
* const communicator = await connectToCommunicator({
|
|
24
|
+
* driver: "rabbitmq",
|
|
25
|
+
* host: "localhost",
|
|
26
|
+
* port: 5672,
|
|
27
|
+
* username: "guest",
|
|
28
|
+
* password: "guest",
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Use the communicator
|
|
32
|
+
* await communicator.channel("user.created").publish({ userId: 1 });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Multiple communicators
|
|
38
|
+
* await connectToCommunicator({
|
|
39
|
+
* driver: "rabbitmq",
|
|
40
|
+
* name: "notifications",
|
|
41
|
+
* isDefault: true,
|
|
42
|
+
* host: process.env.RABBITMQ_HOST,
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* await connectToCommunicator({
|
|
46
|
+
* driver: "rabbitmq",
|
|
47
|
+
* name: "analytics",
|
|
48
|
+
* host: process.env.ANALYTICS_RABBITMQ_HOST,
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Use default communicator
|
|
52
|
+
* communicators().channel("notifications").publish({ ... });
|
|
53
|
+
*
|
|
54
|
+
* // Use specific communicator
|
|
55
|
+
* communicators("analytics").channel("events").publish({ ... });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function connectToCommunicator(options: ConnectionOptions): Promise<Communicator>;
|
|
59
|
+
/**
|
|
60
|
+
* Get a communicator by name or the default one.
|
|
61
|
+
*
|
|
62
|
+
* This is the main entry point for using communicators in your application.
|
|
63
|
+
*
|
|
64
|
+
* @param name - Optional communicator name (uses default if not provided)
|
|
65
|
+
* @returns Communicator instance
|
|
66
|
+
* @throws MissingCommunicatorError if communicator not found
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Get default communicator
|
|
71
|
+
* const channel = communicators().channel("user.created");
|
|
72
|
+
* await channel.publish({ userId: 1 });
|
|
73
|
+
*
|
|
74
|
+
* // Get specific communicator
|
|
75
|
+
* const analyticsChannel = communicators("analytics").channel("events");
|
|
76
|
+
* await analyticsChannel.publish({ event: "page_view" });
|
|
77
|
+
*
|
|
78
|
+
* // Subscribe to messages
|
|
79
|
+
* communicators()
|
|
80
|
+
* .channel<UserPayload>("user.created")
|
|
81
|
+
* .subscribe(async (message, ctx) => {
|
|
82
|
+
* console.log("User created:", message.payload);
|
|
83
|
+
* await ctx.ack();
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function communicators(name?: string): Communicator;
|
|
88
|
+
/**
|
|
89
|
+
* Get channel instance for the given name from default communicator
|
|
90
|
+
* @param name - Channel name
|
|
91
|
+
* @returns Channel instance
|
|
92
|
+
* @throws MissingCommunicatorError if communicator not found
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const channel = communicatorChannel("user.created");
|
|
97
|
+
* await channel.publish({ userId: 1 });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function communicatorChannel<TPayload = unknown>(name: string, options?: ChannelOptions<TPayload>): ChannelContract<TPayload>;
|
|
101
|
+
/**
|
|
102
|
+
* Publish the given
|
|
103
|
+
* @param event - Event message to publish
|
|
104
|
+
* @returns Promise that resolves when the event is published
|
|
105
|
+
* @throws Error if the event is not published
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* await publishEvent(new UserUpdatedEvent({ id: 1, name: "John Doe" }));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function publishEvent<TPayload = Record<string, any>>(event: EventMessage<TPayload>): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Subscribe the given consumer to the default communicator
|
|
115
|
+
* @param Consumer - Event consumer class
|
|
116
|
+
* @returns Function to unsubscribe the consumer
|
|
117
|
+
* @throws Error if the consumer is not subscribed
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* await subscribeConsumer(UserUpdatedConsumer);
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* // Unsubscribe
|
|
125
|
+
* await unsubscribeConsumer(UserUpdatedConsumer);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function subscribeConsumer<TPayload = Record<string, any>>(Consumer: EventConsumerClass<TPayload>): Promise<() => void>;
|
|
129
|
+
//# sourceMappingURL=connect-to-communicator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-to-communicator.d.ts","sourceRoot":"","sources":["../../src/utils/connect-to-communicator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwB,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAA6B,MAAM,UAAU,CAAC;AAE7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CA+C7F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAEzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,GAAG,OAAO,EACpD,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,GACjC,eAAe,CAAC,QAAQ,CAAC,CAE3B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,QAAQ,CAAC,iBAE/F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpE,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC,uBAGvC"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
'use strict';var communicatorRegistry=require('../communicators/communicator-registry.js');/**
|
|
2
|
+
* Connect to a message broker and register the communicator.
|
|
3
|
+
*
|
|
4
|
+
* This is a high-level utility function that simplifies connection setup
|
|
5
|
+
* for most projects. It handles driver instantiation, connection,
|
|
6
|
+
* communicator creation, and automatic registration.
|
|
7
|
+
*
|
|
8
|
+
* **Supported Drivers:**
|
|
9
|
+
* - `rabbitmq` (default) - RabbitMQ/AMQP driver
|
|
10
|
+
* - `kafka` - Apache Kafka driver (coming soon)
|
|
11
|
+
*
|
|
12
|
+
* @param options - Connection configuration options
|
|
13
|
+
* @returns A connected and registered Communicator instance
|
|
14
|
+
* @throws {Error} If connection fails or driver is not implemented
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // RabbitMQ connection
|
|
19
|
+
* const communicator = await connectToCommunicator({
|
|
20
|
+
* driver: "rabbitmq",
|
|
21
|
+
* host: "localhost",
|
|
22
|
+
* port: 5672,
|
|
23
|
+
* username: "guest",
|
|
24
|
+
* password: "guest",
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Use the communicator
|
|
28
|
+
* await communicator.channel("user.created").publish({ userId: 1 });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Multiple communicators
|
|
34
|
+
* await connectToCommunicator({
|
|
35
|
+
* driver: "rabbitmq",
|
|
36
|
+
* name: "notifications",
|
|
37
|
+
* isDefault: true,
|
|
38
|
+
* host: process.env.RABBITMQ_HOST,
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* await connectToCommunicator({
|
|
42
|
+
* driver: "rabbitmq",
|
|
43
|
+
* name: "analytics",
|
|
44
|
+
* host: process.env.ANALYTICS_RABBITMQ_HOST,
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Use default communicator
|
|
48
|
+
* communicators().channel("notifications").publish({ ... });
|
|
49
|
+
*
|
|
50
|
+
* // Use specific communicator
|
|
51
|
+
* communicators("analytics").channel("events").publish({ ... });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
async function connectToCommunicator(options) {
|
|
55
|
+
// Default values
|
|
56
|
+
const driverType = options.driver ?? "rabbitmq";
|
|
57
|
+
const communicatorName = options.name ?? "default";
|
|
58
|
+
const isDefault = options.isDefault ?? true;
|
|
59
|
+
// Create driver based on type
|
|
60
|
+
let driver;
|
|
61
|
+
switch (driverType) {
|
|
62
|
+
case "rabbitmq": {
|
|
63
|
+
const rabbitOptions = options;
|
|
64
|
+
// Dynamic import to avoid requiring amqplib if not used
|
|
65
|
+
const { RabbitMQDriver } = await Promise.resolve().then(function(){return require('../drivers/rabbitmq/rabbitmq-driver.js')});
|
|
66
|
+
driver = new RabbitMQDriver(rabbitOptions);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "kafka": {
|
|
70
|
+
// const kafkaOptions = options as KafkaConnectionOptions;
|
|
71
|
+
// Dynamic import to avoid requiring kafkajs if not used
|
|
72
|
+
throw new Error("Kafka driver is not yet implemented. Coming soon! For now, please use RabbitMQ.");
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
throw new Error(`Unknown driver: "${driverType}". Supported drivers: rabbitmq, kafka`);
|
|
76
|
+
}
|
|
77
|
+
// Create communicator
|
|
78
|
+
const communicator = communicatorRegistry.communicatorRegistry.register({
|
|
79
|
+
name: communicatorName,
|
|
80
|
+
driver,
|
|
81
|
+
isDefault,
|
|
82
|
+
});
|
|
83
|
+
// Connect to the message broker
|
|
84
|
+
try {
|
|
85
|
+
await driver.connect();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw new Error(`Failed to connect to ${driverType}: ${error instanceof Error ? error.message : String(error)}`);
|
|
89
|
+
}
|
|
90
|
+
return communicator;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get a communicator by name or the default one.
|
|
94
|
+
*
|
|
95
|
+
* This is the main entry point for using communicators in your application.
|
|
96
|
+
*
|
|
97
|
+
* @param name - Optional communicator name (uses default if not provided)
|
|
98
|
+
* @returns Communicator instance
|
|
99
|
+
* @throws MissingCommunicatorError if communicator not found
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Get default communicator
|
|
104
|
+
* const channel = communicators().channel("user.created");
|
|
105
|
+
* await channel.publish({ userId: 1 });
|
|
106
|
+
*
|
|
107
|
+
* // Get specific communicator
|
|
108
|
+
* const analyticsChannel = communicators("analytics").channel("events");
|
|
109
|
+
* await analyticsChannel.publish({ event: "page_view" });
|
|
110
|
+
*
|
|
111
|
+
* // Subscribe to messages
|
|
112
|
+
* communicators()
|
|
113
|
+
* .channel<UserPayload>("user.created")
|
|
114
|
+
* .subscribe(async (message, ctx) => {
|
|
115
|
+
* console.log("User created:", message.payload);
|
|
116
|
+
* await ctx.ack();
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
function communicators(name) {
|
|
121
|
+
return communicatorRegistry.communicatorRegistry.get(name);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get channel instance for the given name from default communicator
|
|
125
|
+
* @param name - Channel name
|
|
126
|
+
* @returns Channel instance
|
|
127
|
+
* @throws MissingCommunicatorError if communicator not found
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const channel = communicatorChannel("user.created");
|
|
132
|
+
* await channel.publish({ userId: 1 });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
function communicatorChannel(name, options) {
|
|
136
|
+
return communicators().channel(name, options);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Publish the given
|
|
140
|
+
* @param event - Event message to publish
|
|
141
|
+
* @returns Promise that resolves when the event is published
|
|
142
|
+
* @throws Error if the event is not published
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* await publishEvent(new UserUpdatedEvent({ id: 1, name: "John Doe" }));
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
async function publishEvent(event) {
|
|
150
|
+
return communicators().publish(event);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Subscribe the given consumer to the default communicator
|
|
154
|
+
* @param Consumer - Event consumer class
|
|
155
|
+
* @returns Function to unsubscribe the consumer
|
|
156
|
+
* @throws Error if the consumer is not subscribed
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* await subscribeConsumer(UserUpdatedConsumer);
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* // Unsubscribe
|
|
164
|
+
* await unsubscribeConsumer(UserUpdatedConsumer);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
async function subscribeConsumer(Consumer) {
|
|
168
|
+
return communicators().subscribe(Consumer);
|
|
169
|
+
}exports.communicatorChannel=communicatorChannel;exports.communicators=communicators;exports.connectToCommunicator=connectToCommunicator;exports.publishEvent=publishEvent;exports.subscribeConsumer=subscribeConsumer;//# sourceMappingURL=connect-to-communicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-to-communicator.js","sources":["../../src/utils/connect-to-communicator.ts"],"sourcesContent":[null],"names":["communicatorRegistry"],"mappings":"2FAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDG;AACI,eAAe,qBAAqB,CAAC,OAA0B,EAAA;;AAEpE,IAAA,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;AAChD,IAAA,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC;AACnD,IAAA,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;;AAG5C,IAAA,IAAI,MAAkC,CAAC;AAEvC,IAAA,QAAQ,UAAU;QAChB,KAAK,UAAU,EAAE;YACf,MAAM,aAAa,GAAG,OAAoC,CAAC;;YAE3D,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,iDAAO,wCAAqC,GAAC,CAAC;AAC/E,YAAA,MAAM,GAAG,IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;YAC3C,MAAM;AACP,SAAA;QAED,KAAK,OAAO,EAAE;;;AAGZ,YAAA,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;AACH,SAAA;AAED,QAAA;AACE,YAA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AAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type EventConsumerClass } from "../message-managers/types";
|
|
2
|
+
export type ConsumableOptions = {
|
|
3
|
+
communicator?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const pendingSubscribers: Set<{
|
|
6
|
+
Consumer: EventConsumerClass;
|
|
7
|
+
options?: ConsumableOptions;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Register the consumer to the communicator
|
|
11
|
+
*/
|
|
12
|
+
export declare function Consumable(options?: ConsumableOptions): (target: EventConsumerClass) => void;
|
|
13
|
+
//# sourceMappingURL=consumable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumable.d.ts","sourceRoot":"","sources":["../../src/decorators/consumable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,kBAAkB;cACnB,kBAAkB;cAClB,iBAAiB;EACzB,CAAC;AAEL;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,YAC3B,kBAAkB,UAkB5C"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {communicatorRegistry}from'../communicators/communicator-registry.js';const pendingSubscribers = new Set();
|
|
2
|
+
/**
|
|
3
|
+
* Register the consumer to the communicator
|
|
4
|
+
*/
|
|
5
|
+
function Consumable(options) {
|
|
6
|
+
return function (target) {
|
|
7
|
+
const communicatorDriver = options?.communicator;
|
|
8
|
+
try {
|
|
9
|
+
const currentCommunicator = communicatorRegistry.get(communicatorDriver);
|
|
10
|
+
// if communicator is connected, subscribe the consumer
|
|
11
|
+
if (currentCommunicator?.isConnected) {
|
|
12
|
+
currentCommunicator.subscribe(target);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
pendingSubscribers.add({ Consumer: target, options });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// mostly it will be an error that communicator is not registered yet
|
|
20
|
+
// then add it to the pending subscribers
|
|
21
|
+
pendingSubscribers.add({ Consumer: target, options });
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
// Register pending consumers on communicator's connection is done
|
|
26
|
+
communicatorRegistry.on("connected", (communicator) => {
|
|
27
|
+
for (const { Consumer, options } of pendingSubscribers) {
|
|
28
|
+
if (options?.communicator && communicator.name !== options.communicator) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
communicator.subscribe(Consumer);
|
|
32
|
+
}
|
|
33
|
+
});export{Consumable,pendingSubscribers};//# sourceMappingURL=consumable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumable.js","sources":["../../src/decorators/consumable.ts"],"sourcesContent":[null],"names":[],"mappings":"6EAOa,MAAA,kBAAkB,GAAG,IAAI,GAAG,GAGpC;AAEL;;AAEG;AACG,SAAU,UAAU,CAAC,OAA2B,EAAA;AACpD,IAAA,OAAO,UAAU,MAA0B,EAAA;AACzC,QAAA,MAAM,kBAAkB,GAAG,OAAO,EAAE,YAAY,CAAC;QAEjD,IAAI;YACF,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;;YAGzE,IAAI,mBAAmB,EAAE,WAAW,EAAE;AACpC,gBAAA,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACvC,aAAA;AAAM,iBAAA;gBACL,kBAAkB,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACvD,aAAA;AACF,SAAA;QAAC,MAAM;;;YAGN,kBAAkB,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACvD,SAAA;AACH,KAAC,CAAC;AACJ,CAAC;AAED;AACA,oBAAoB,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,YAAY,KAAI;IACpD,KAAK,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,kBAAkB,EAAE;QACtD,IAAI,OAAO,EAAE,YAAY,IAAI,YAAY,CAAC,IAAI,KAAK,OAAO,CAAC,YAAY,EAAE;YACvE,SAAS;AACV,SAAA;AAED,QAAA,YAAY,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAClC,KAAA;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/drivers/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/drivers/rabbitmq/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ChannelContract } from "../../contracts";
|
|
2
|
+
import type { ChannelOptions, ChannelStats, MessageHandler, PublishOptions, RequestOptions, ResponseHandler, SubscribeOptions, Subscription } from "../../types";
|
|
3
|
+
/**
|
|
4
|
+
* RabbitMQ Channel Implementation
|
|
5
|
+
*
|
|
6
|
+
* Wraps a RabbitMQ queue/exchange with a unified API.
|
|
7
|
+
*
|
|
8
|
+
* @template TPayload - The typed payload
|
|
9
|
+
*/
|
|
10
|
+
export declare class RabbitMQChannel<TPayload = unknown> implements ChannelContract<TPayload> {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly options: ChannelOptions<TPayload>;
|
|
13
|
+
private readonly amqpChannel;
|
|
14
|
+
private readonly subscriptions;
|
|
15
|
+
private asserted;
|
|
16
|
+
/**
|
|
17
|
+
* Create a new RabbitMQ channel
|
|
18
|
+
*/
|
|
19
|
+
constructor(name: string, amqpChannel: any, options?: ChannelOptions<TPayload>);
|
|
20
|
+
/**
|
|
21
|
+
* Assert the queue exists
|
|
22
|
+
*/
|
|
23
|
+
assert(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Publish a message
|
|
26
|
+
*/
|
|
27
|
+
publish(payload: TPayload, options?: PublishOptions): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Publish multiple messages
|
|
30
|
+
*/
|
|
31
|
+
publishBatch(messages: TPayload[], options?: PublishOptions): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Subscribe to messages
|
|
34
|
+
*
|
|
35
|
+
* Smart auto-ack behavior (when autoAck is not true):
|
|
36
|
+
* - If handler completes successfully without explicit ack/nack/reject → auto-ack
|
|
37
|
+
* - If handler throws an error → auto-nack (with retry if configured)
|
|
38
|
+
* - If handler explicitly calls ack/nack/reject → respects that call
|
|
39
|
+
*/
|
|
40
|
+
subscribe(handler: MessageHandler<TPayload>, options?: SubscribeOptions): Promise<Subscription>;
|
|
41
|
+
/**
|
|
42
|
+
* Unsubscribe by consumer ID
|
|
43
|
+
*/
|
|
44
|
+
unsubscribeById(consumerId: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Stop consuming subscriptions
|
|
47
|
+
*/
|
|
48
|
+
stopConsuming(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Send message to dead-letter queue
|
|
51
|
+
*/
|
|
52
|
+
private sendToDeadLetter;
|
|
53
|
+
/**
|
|
54
|
+
* Request-response pattern
|
|
55
|
+
*/
|
|
56
|
+
request<TResponse = unknown>(payload: TPayload, options?: RequestOptions): Promise<TResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Register response handler for RPC
|
|
59
|
+
*/
|
|
60
|
+
respond<TResponse = unknown>(handler: ResponseHandler<TPayload, TResponse>): Promise<Subscription>;
|
|
61
|
+
/**
|
|
62
|
+
* Get queue statistics
|
|
63
|
+
*/
|
|
64
|
+
stats(): Promise<ChannelStats>;
|
|
65
|
+
/**
|
|
66
|
+
* Purge all messages
|
|
67
|
+
*/
|
|
68
|
+
purge(): Promise<number>;
|
|
69
|
+
/**
|
|
70
|
+
* Check if queue exists
|
|
71
|
+
*/
|
|
72
|
+
exists(): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Delete the queue
|
|
75
|
+
*/
|
|
76
|
+
delete(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=rabbitmq-channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rabbitmq-channel.d.ts","sourceRoot":"","sources":["../../../src/drivers/rabbitmq/rabbitmq-channel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EAGZ,cAAc,EAEd,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,YAAY,EACb,MAAM,aAAa,CAAC;AAErB;;;;;;GAMG;AACH,qBAAa,eAAe,CAAC,QAAQ,GAAG,OAAO,CAAE,YAAW,eAAe,CAAC,QAAQ,CAAC;IACnF,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAElD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAM;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA2C;IACzE,OAAO,CAAC,QAAQ,CAAS;IAEzB;;OAEG;gBACgB,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC;IAMrF;;OAEG;IACU,MAAM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