@warlock.js/herald 4.0.161 → 4.0.163
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/communicators/communicator-registry.d.ts +155 -0
- package/esm/communicators/communicator-registry.d.ts.map +1 -0
- package/esm/communicators/communicator-registry.js +206 -0
- package/esm/communicators/communicator-registry.js.map +1 -0
- package/esm/communicators/communicator.d.ts +100 -0
- package/esm/communicators/communicator.d.ts.map +1 -0
- package/esm/communicators/communicator.js +105 -0
- package/esm/communicators/communicator.js.map +1 -0
- package/esm/communicators/index.d.ts +3 -0
- package/esm/communicators/index.d.ts.map +1 -0
- package/esm/contracts/channel.contract.d.ts +186 -0
- package/esm/contracts/channel.contract.d.ts.map +1 -0
- package/esm/contracts/communicator-driver.contract.d.ts +196 -0
- package/esm/contracts/communicator-driver.contract.d.ts.map +1 -0
- package/esm/contracts/index.d.ts +3 -0
- package/esm/contracts/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,O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Y,EACZ,OAAkC,EAAA;IAElC,OAAO,aAAa,EAAE,CAAC,OAAO,CAAW,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;AAUG;AACI,eAAe,YAAY,CAAiC,KAA6B,EAAA;AAC9F,IAAA,OAAO,aAAa,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;AAcG;AACI,eAAe,iBAAiB,CACrC,QAAsC,EAAA;AAEtC,IAAA,OAAO,aAAa,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { CommunicatorRegistryEvent, CommunicatorRegistryListener } from "../types";
|
|
2
|
+
import { Communicator, type CommunicatorOptions } from "./communicator";
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when a communicator is not found
|
|
5
|
+
*/
|
|
6
|
+
export declare class MissingCommunicatorError extends Error {
|
|
7
|
+
readonly communicatorName?: string;
|
|
8
|
+
constructor(message: string, communicatorName?: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Communicator Registry
|
|
12
|
+
*
|
|
13
|
+
* Maintains registry of named communicators.
|
|
14
|
+
* Similar to DataSourceRegistry in @warlock.js/cascade
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Register a communicator
|
|
19
|
+
* communicatorRegistry.register({
|
|
20
|
+
* name: "default",
|
|
21
|
+
* driver: rabbitMQDriver,
|
|
22
|
+
* isDefault: true,
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Get the default communicator
|
|
26
|
+
* const comm = communicatorRegistry.get();
|
|
27
|
+
*
|
|
28
|
+
* // Get a specific communicator by name
|
|
29
|
+
* const analytics = communicatorRegistry.get("analytics");
|
|
30
|
+
*
|
|
31
|
+
* // Listen for events
|
|
32
|
+
* communicatorRegistry.on("connected", (comm) => {
|
|
33
|
+
* console.log(`${comm.name} connected`);
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare class CommunicatorRegistry {
|
|
38
|
+
private readonly sources;
|
|
39
|
+
private defaultSource?;
|
|
40
|
+
private readonly events;
|
|
41
|
+
/**
|
|
42
|
+
* Register a new communicator
|
|
43
|
+
*
|
|
44
|
+
* Sets up event forwarding from the driver to the registry.
|
|
45
|
+
*
|
|
46
|
+
* @param options - Communicator configuration
|
|
47
|
+
* @returns The registered communicator instance
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const communicator = communicatorRegistry.register({
|
|
52
|
+
* name: "primary",
|
|
53
|
+
* driver: myDriver,
|
|
54
|
+
* isDefault: true,
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
register(options: CommunicatorOptions): Communicator;
|
|
59
|
+
/**
|
|
60
|
+
* Clear all registered communicators
|
|
61
|
+
*/
|
|
62
|
+
clear(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Listen for registry events
|
|
65
|
+
*
|
|
66
|
+
* @param event - Event to listen for
|
|
67
|
+
* @param listener - Callback function
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* communicatorRegistry.on("registered", (comm) => {
|
|
72
|
+
* console.log(`Communicator "${comm.name}" registered`);
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* communicatorRegistry.on("connected", (comm) => {
|
|
76
|
+
* console.log(`Communicator "${comm.name}" connected`);
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
on(event: CommunicatorRegistryEvent, listener: CommunicatorRegistryListener): void;
|
|
81
|
+
/**
|
|
82
|
+
* Listen for a registry event once
|
|
83
|
+
*
|
|
84
|
+
* @param event - Event to listen for
|
|
85
|
+
* @param listener - Callback function
|
|
86
|
+
*/
|
|
87
|
+
once(event: CommunicatorRegistryEvent, listener: CommunicatorRegistryListener): void;
|
|
88
|
+
/**
|
|
89
|
+
* Remove an event listener
|
|
90
|
+
*
|
|
91
|
+
* @param event - Event to stop listening for
|
|
92
|
+
* @param listener - Callback to remove
|
|
93
|
+
*/
|
|
94
|
+
off(event: CommunicatorRegistryEvent, listener: CommunicatorRegistryListener): void;
|
|
95
|
+
/**
|
|
96
|
+
* Get a communicator by name or the default one
|
|
97
|
+
*
|
|
98
|
+
* @param name - Optional communicator name
|
|
99
|
+
* @returns Communicator instance
|
|
100
|
+
* @throws MissingCommunicatorError if not found
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Get default communicator
|
|
105
|
+
* const comm = communicatorRegistry.get();
|
|
106
|
+
*
|
|
107
|
+
* // Get specific communicator
|
|
108
|
+
* const analytics = communicatorRegistry.get("analytics");
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
get(name?: string): Communicator;
|
|
112
|
+
/**
|
|
113
|
+
* Check if a communicator exists
|
|
114
|
+
*
|
|
115
|
+
* @param name - Communicator name to check
|
|
116
|
+
* @returns True if exists
|
|
117
|
+
*/
|
|
118
|
+
has(name: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Check if any communicators are registered
|
|
121
|
+
*/
|
|
122
|
+
hasAny(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Get all registered communicators
|
|
125
|
+
*
|
|
126
|
+
* @returns Array of all communicators
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* // Disconnect all communicators
|
|
131
|
+
* for (const comm of communicatorRegistry.getAll()) {
|
|
132
|
+
* await comm.disconnect();
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
getAll(): Communicator[];
|
|
137
|
+
/**
|
|
138
|
+
* Get all communicator names
|
|
139
|
+
*
|
|
140
|
+
* @returns Array of communicator names
|
|
141
|
+
*/
|
|
142
|
+
getNames(): string[];
|
|
143
|
+
/**
|
|
144
|
+
* Get the default communicator (if any)
|
|
145
|
+
*
|
|
146
|
+
* @returns Default communicator or undefined
|
|
147
|
+
*/
|
|
148
|
+
getDefault(): Communicator | undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Global communicator registry instance
|
|
152
|
+
*/
|
|
153
|
+
export declare const communicatorRegistry: CommunicatorRegistry;
|
|
154
|
+
export {};
|
|
155
|
+
//# sourceMappingURL=communicator-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"communicator-registry.d.ts","sourceRoot":"","sources":["../../src/communicators/communicator-registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAExE;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,SAAgB,gBAAgB,CAAC,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM;CAK9D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,cAAM,oBAAoB;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,aAAa,CAAC,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAE7C;;;;;;;;;;;;;;;;OAgBG;IACI,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY;IA6B3D;;OAEG;IACI,KAAK,IAAI,IAAI;IAKpB;;;;;;;;;;;;;;;;OAgBG;IACI,EAAE,CAAC,KAAK,EAAE,yBAAyB,EAAE,QAAQ,EAAE,4BAA4B,GAAG,IAAI;IAIzF;;;;;OAKG;IACI,IAAI,CAAC,KAAK,EAAE,yBAAyB,EAAE,QAAQ,EAAE,4BAA4B,GAAG,IAAI;IAI3F;;;;;OAKG;IACI,GAAG,CAAC,KAAK,EAAE,yBAAyB,EAAE,QAAQ,EAAE,4BAA4B,GAAG,IAAI;IAI1F;;;;;;;;;;;;;;;OAeG;IACI,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY;IAgBvC;;;;;OAKG;IACI,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC;;OAEG;IACI,MAAM,IAAI,OAAO;IAIxB;;;;;;;;;;;;OAYG;IACI,MAAM,IAAI,YAAY,EAAE;IAI/B;;;;OAIG;IACI,QAAQ,IAAI,MAAM,EAAE;IAI3B;;;;OAIG;IACI,UAAU,IAAI,YAAY,GAAG,SAAS;CAG9C;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,sBAA6B,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {EventEmitter}from'node:events';import {Communicator}from'./communicator.js';/**
|
|
2
|
+
* Error thrown when a communicator is not found
|
|
3
|
+
*/
|
|
4
|
+
class MissingCommunicatorError extends Error {
|
|
5
|
+
communicatorName;
|
|
6
|
+
constructor(message, communicatorName) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "MissingCommunicatorError";
|
|
9
|
+
this.communicatorName = communicatorName;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Communicator Registry
|
|
14
|
+
*
|
|
15
|
+
* Maintains registry of named communicators.
|
|
16
|
+
* Similar to DataSourceRegistry in @warlock.js/cascade
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Register a communicator
|
|
21
|
+
* communicatorRegistry.register({
|
|
22
|
+
* name: "default",
|
|
23
|
+
* driver: rabbitMQDriver,
|
|
24
|
+
* isDefault: true,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Get the default communicator
|
|
28
|
+
* const comm = communicatorRegistry.get();
|
|
29
|
+
*
|
|
30
|
+
* // Get a specific communicator by name
|
|
31
|
+
* const analytics = communicatorRegistry.get("analytics");
|
|
32
|
+
*
|
|
33
|
+
* // Listen for events
|
|
34
|
+
* communicatorRegistry.on("connected", (comm) => {
|
|
35
|
+
* console.log(`${comm.name} connected`);
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
class CommunicatorRegistry {
|
|
40
|
+
sources = new Map();
|
|
41
|
+
defaultSource;
|
|
42
|
+
events = new EventEmitter();
|
|
43
|
+
/**
|
|
44
|
+
* Register a new communicator
|
|
45
|
+
*
|
|
46
|
+
* Sets up event forwarding from the driver to the registry.
|
|
47
|
+
*
|
|
48
|
+
* @param options - Communicator configuration
|
|
49
|
+
* @returns The registered communicator instance
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const communicator = communicatorRegistry.register({
|
|
54
|
+
* name: "primary",
|
|
55
|
+
* driver: myDriver,
|
|
56
|
+
* isDefault: true,
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
register(options) {
|
|
61
|
+
const communicator = new Communicator(options);
|
|
62
|
+
this.sources.set(communicator.name, communicator);
|
|
63
|
+
const isNewDefault = communicator.isDefault || !this.defaultSource;
|
|
64
|
+
if (isNewDefault) {
|
|
65
|
+
this.defaultSource = communicator;
|
|
66
|
+
}
|
|
67
|
+
// Emit registration events
|
|
68
|
+
this.events.emit("registered", communicator);
|
|
69
|
+
if (isNewDefault) {
|
|
70
|
+
this.events.emit("default-registered", communicator);
|
|
71
|
+
}
|
|
72
|
+
// Forward driver events to registry
|
|
73
|
+
communicator.driver.on("connected", () => {
|
|
74
|
+
this.events.emit("connected", communicator);
|
|
75
|
+
});
|
|
76
|
+
communicator.driver.on("disconnected", () => {
|
|
77
|
+
this.events.emit("disconnected", communicator);
|
|
78
|
+
});
|
|
79
|
+
return communicator;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Clear all registered communicators
|
|
83
|
+
*/
|
|
84
|
+
clear() {
|
|
85
|
+
this.defaultSource = undefined;
|
|
86
|
+
this.sources.clear();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Listen for registry events
|
|
90
|
+
*
|
|
91
|
+
* @param event - Event to listen for
|
|
92
|
+
* @param listener - Callback function
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* communicatorRegistry.on("registered", (comm) => {
|
|
97
|
+
* console.log(`Communicator "${comm.name}" registered`);
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* communicatorRegistry.on("connected", (comm) => {
|
|
101
|
+
* console.log(`Communicator "${comm.name}" connected`);
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
on(event, listener) {
|
|
106
|
+
this.events.on(event, listener);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Listen for a registry event once
|
|
110
|
+
*
|
|
111
|
+
* @param event - Event to listen for
|
|
112
|
+
* @param listener - Callback function
|
|
113
|
+
*/
|
|
114
|
+
once(event, listener) {
|
|
115
|
+
this.events.once(event, listener);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Remove an event listener
|
|
119
|
+
*
|
|
120
|
+
* @param event - Event to stop listening for
|
|
121
|
+
* @param listener - Callback to remove
|
|
122
|
+
*/
|
|
123
|
+
off(event, listener) {
|
|
124
|
+
this.events.off(event, listener);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get a communicator by name or the default one
|
|
128
|
+
*
|
|
129
|
+
* @param name - Optional communicator name
|
|
130
|
+
* @returns Communicator instance
|
|
131
|
+
* @throws MissingCommunicatorError if not found
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // Get default communicator
|
|
136
|
+
* const comm = communicatorRegistry.get();
|
|
137
|
+
*
|
|
138
|
+
* // Get specific communicator
|
|
139
|
+
* const analytics = communicatorRegistry.get("analytics");
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
get(name) {
|
|
143
|
+
if (name !== undefined) {
|
|
144
|
+
const source = this.sources.get(name);
|
|
145
|
+
if (!source) {
|
|
146
|
+
throw new MissingCommunicatorError(`Communicator "${name}" is not registered.`, name);
|
|
147
|
+
}
|
|
148
|
+
return source;
|
|
149
|
+
}
|
|
150
|
+
if (!this.defaultSource) {
|
|
151
|
+
throw new MissingCommunicatorError("No default communicator registered.");
|
|
152
|
+
}
|
|
153
|
+
return this.defaultSource;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Check if a communicator exists
|
|
157
|
+
*
|
|
158
|
+
* @param name - Communicator name to check
|
|
159
|
+
* @returns True if exists
|
|
160
|
+
*/
|
|
161
|
+
has(name) {
|
|
162
|
+
return this.sources.has(name);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Check if any communicators are registered
|
|
166
|
+
*/
|
|
167
|
+
hasAny() {
|
|
168
|
+
return this.sources.size > 0;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get all registered communicators
|
|
172
|
+
*
|
|
173
|
+
* @returns Array of all communicators
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // Disconnect all communicators
|
|
178
|
+
* for (const comm of communicatorRegistry.getAll()) {
|
|
179
|
+
* await comm.disconnect();
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
getAll() {
|
|
184
|
+
return Array.from(this.sources.values());
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get all communicator names
|
|
188
|
+
*
|
|
189
|
+
* @returns Array of communicator names
|
|
190
|
+
*/
|
|
191
|
+
getNames() {
|
|
192
|
+
return Array.from(this.sources.keys());
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get the default communicator (if any)
|
|
196
|
+
*
|
|
197
|
+
* @returns Default communicator or undefined
|
|
198
|
+
*/
|
|
199
|
+
getDefault() {
|
|
200
|
+
return this.defaultSource;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Global communicator registry instance
|
|
205
|
+
*/
|
|
206
|
+
const communicatorRegistry = new CommunicatorRegistry();export{MissingCommunicatorError,communicatorRegistry};//# sourceMappingURL=communicator-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"communicator-registry.js","sources":["../../src/communicators/communicator-registry.ts"],"sourcesContent":[null],"names":[],"mappings":"oFAIA;;AAEG;AACG,MAAO,wBAAyB,SAAQ,KAAK,CAAA;AACjC,IAAA,gBAAgB,CAAU;IAE1C,WAAmB,CAAA,OAAe,EAAE,gBAAyB,EAAA;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;AACf,QAAA,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;AACvC,QAAA,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;KAC1C;AACF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACH,MAAM,oBAAoB,CAAA;AACP,IAAA,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;AACnD,IAAA,aAAa,CAAgB;AACpB,IAAA,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;AAE7C;;;;;;;;;;;;;;;;AAgBG;AACI,IAAA,QAAQ,CAAC,OAA4B,EAAA;AAC1C,QAAA,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAElD,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