@warlock.js/herald 4.0.174 → 4.1.2
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/README.md +36 -33
- package/cjs/index.cjs +1355 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/communicators/broker-registry.d.mts +157 -0
- package/esm/communicators/broker-registry.d.mts.map +1 -0
- package/esm/communicators/broker-registry.mjs +204 -0
- package/esm/communicators/broker-registry.mjs.map +1 -0
- package/esm/communicators/broker.d.mts +104 -0
- package/esm/communicators/broker.d.mts.map +1 -0
- package/esm/communicators/broker.mjs +104 -0
- package/esm/communicators/broker.mjs.map +1 -0
- package/esm/communicators/index.d.mts +2 -0
- package/esm/communicators/index.mjs +4 -0
- package/esm/contracts/broker-driver.contract.d.mts +200 -0
- package/esm/contracts/broker-driver.contract.d.mts.map +1 -0
- package/esm/contracts/channel.contract.d.mts +197 -0
- package/esm/contracts/channel.contract.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +2 -0
- package/esm/decorators/consumable.d.mts +17 -0
- package/esm/decorators/consumable.d.mts.map +1 -0
- package/esm/decorators/consumable.mjs +36 -0
- package/esm/decorators/consumable.mjs.map +1 -0
- package/esm/decorators/index.d.mts +1 -0
- package/esm/decorators/index.mjs +3 -0
- package/esm/drivers/index.d.mts +2 -0
- package/esm/drivers/index.mjs +5 -0
- package/esm/drivers/rabbitmq/index.d.mts +2 -0
- package/esm/drivers/rabbitmq/index.mjs +4 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.mts +85 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.mts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.mjs +352 -0
- package/esm/drivers/rabbitmq/rabbitmq-channel.mjs.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.mts +130 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.mts.map +1 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.mjs +291 -0
- package/esm/drivers/rabbitmq/rabbitmq-driver.mjs.map +1 -0
- package/esm/index.d.mts +20 -0
- package/esm/index.mjs +16 -0
- package/esm/message-managers/event-consumer.d.mts +61 -0
- package/esm/message-managers/event-consumer.d.mts.map +1 -0
- package/esm/message-managers/event-consumer.mjs +63 -0
- package/esm/message-managers/event-consumer.mjs.map +1 -0
- package/esm/message-managers/event-message.d.mts +87 -0
- package/esm/message-managers/event-message.d.mts.map +1 -0
- package/esm/message-managers/event-message.mjs +68 -0
- package/esm/message-managers/event-message.mjs.map +1 -0
- package/esm/message-managers/index.d.mts +3 -0
- package/esm/message-managers/index.mjs +4 -0
- package/esm/message-managers/prepare-consumer-subscription.mjs +42 -0
- package/esm/message-managers/prepare-consumer-subscription.mjs.map +1 -0
- package/esm/message-managers/types.d.mts +23 -0
- package/esm/message-managers/types.d.mts.map +1 -0
- package/esm/types/channel.types.d.mts +23 -0
- package/esm/types/channel.types.d.mts.map +1 -0
- package/esm/types/connection.types.d.mts +67 -0
- package/esm/types/connection.types.d.mts.map +1 -0
- package/esm/types/driver.types.d.mts +13 -0
- package/esm/types/driver.types.d.mts.map +1 -0
- package/esm/types/index.d.mts +7 -0
- package/esm/types/message.types.d.mts +37 -0
- package/esm/types/message.types.d.mts.map +1 -0
- package/esm/types/publish.types.d.mts +16 -0
- package/esm/types/publish.types.d.mts.map +1 -0
- package/esm/types/registry.types.d.mts +8 -0
- package/esm/types/registry.types.d.mts.map +1 -0
- package/esm/types/subscribe.types.d.mts +21 -0
- package/esm/types/subscribe.types.d.mts.map +1 -0
- package/esm/use-case-broadcast.d.mts +41 -0
- package/esm/use-case-broadcast.d.mts.map +1 -0
- package/esm/use-case-broadcast.mjs +30 -0
- package/esm/use-case-broadcast.mjs.map +1 -0
- package/esm/utils/{connect-to-broker.d.ts → connect-to-broker.d.mts} +15 -10
- package/esm/utils/connect-to-broker.d.mts.map +1 -0
- package/esm/utils/connect-to-broker.mjs +168 -0
- package/esm/utils/connect-to-broker.mjs.map +1 -0
- package/esm/utils/index.d.mts +1 -0
- package/esm/utils/index.mjs +3 -0
- package/llms-full.txt +581 -0
- package/llms.txt +12 -0
- package/package.json +46 -46
- package/skills/README.md +21 -0
- package/skills/consume-message/SKILL.md +217 -0
- package/skills/herald-basics/SKILL.md +96 -0
- package/skills/publish-message/SKILL.md +172 -0
- package/skills/request-and-respond/SKILL.md +74 -0
- package/cjs/communicators/broker-registry.d.ts +0 -155
- package/cjs/communicators/broker-registry.d.ts.map +0 -1
- package/cjs/communicators/broker-registry.js +0 -206
- package/cjs/communicators/broker-registry.js.map +0 -1
- package/cjs/communicators/broker.d.ts +0 -100
- package/cjs/communicators/broker.d.ts.map +0 -1
- package/cjs/communicators/broker.js +0 -105
- package/cjs/communicators/broker.js.map +0 -1
- package/cjs/communicators/index.d.ts +0 -3
- package/cjs/communicators/index.d.ts.map +0 -1
- package/cjs/contracts/broker-driver.contract.d.ts +0 -196
- package/cjs/contracts/broker-driver.contract.d.ts.map +0 -1
- package/cjs/contracts/channel.contract.d.ts +0 -191
- package/cjs/contracts/channel.contract.d.ts.map +0 -1
- package/cjs/contracts/index.d.ts +0 -3
- package/cjs/contracts/index.d.ts.map +0 -1
- package/cjs/decorators/consumable.d.ts +0 -13
- package/cjs/decorators/consumable.d.ts.map +0 -1
- package/cjs/decorators/consumable.js +0 -33
- package/cjs/decorators/consumable.js.map +0 -1
- package/cjs/decorators/index.d.ts +0 -2
- package/cjs/decorators/index.d.ts.map +0 -1
- package/cjs/drivers/index.d.ts +0 -2
- package/cjs/drivers/index.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/index.d.ts +0 -3
- package/cjs/drivers/rabbitmq/index.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts +0 -79
- package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js +0 -414
- package/cjs/drivers/rabbitmq/rabbitmq-channel.js.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts +0 -124
- package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts.map +0 -1
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js +0 -347
- package/cjs/drivers/rabbitmq/rabbitmq-driver.js.map +0 -1
- package/cjs/index.d.ts +0 -47
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/message-managers/event-consumer.d.ts +0 -64
- package/cjs/message-managers/event-consumer.d.ts.map +0 -1
- package/cjs/message-managers/event-consumer.js +0 -71
- package/cjs/message-managers/event-consumer.js.map +0 -1
- package/cjs/message-managers/event-message.d.ts +0 -90
- package/cjs/message-managers/event-message.d.ts.map +0 -1
- package/cjs/message-managers/event-message.js +0 -84
- package/cjs/message-managers/event-message.js.map +0 -1
- package/cjs/message-managers/index.d.ts +0 -4
- package/cjs/message-managers/index.d.ts.map +0 -1
- package/cjs/message-managers/prepare-consumer-subscription.d.ts +0 -4
- package/cjs/message-managers/prepare-consumer-subscription.d.ts.map +0 -1
- package/cjs/message-managers/prepare-consumer-subscription.js +0 -40
- package/cjs/message-managers/prepare-consumer-subscription.js.map +0 -1
- package/cjs/message-managers/types.d.ts +0 -20
- package/cjs/message-managers/types.d.ts.map +0 -1
- package/cjs/types/channel.types.d.ts +0 -19
- package/cjs/types/channel.types.d.ts.map +0 -1
- package/cjs/types/connection.types.d.ts +0 -65
- package/cjs/types/connection.types.d.ts.map +0 -1
- package/cjs/types/driver.types.d.ts +0 -10
- package/cjs/types/driver.types.d.ts.map +0 -1
- package/cjs/types/index.d.ts +0 -8
- package/cjs/types/index.d.ts.map +0 -1
- package/cjs/types/message.types.d.ts +0 -34
- package/cjs/types/message.types.d.ts.map +0 -1
- package/cjs/types/publish.types.d.ts +0 -13
- package/cjs/types/publish.types.d.ts.map +0 -1
- package/cjs/types/registry.types.d.ts +0 -4
- package/cjs/types/registry.types.d.ts.map +0 -1
- package/cjs/types/subscribe.types.d.ts +0 -18
- package/cjs/types/subscribe.types.d.ts.map +0 -1
- package/cjs/utils/connect-to-broker.d.ts +0 -131
- package/cjs/utils/connect-to-broker.d.ts.map +0 -1
- package/cjs/utils/connect-to-broker.js +0 -171
- package/cjs/utils/connect-to-broker.js.map +0 -1
- package/cjs/utils/index.d.ts +0 -2
- package/cjs/utils/index.d.ts.map +0 -1
- package/esm/communicators/broker-registry.d.ts +0 -155
- package/esm/communicators/broker-registry.d.ts.map +0 -1
- package/esm/communicators/broker-registry.js +0 -206
- package/esm/communicators/broker-registry.js.map +0 -1
- package/esm/communicators/broker.d.ts +0 -100
- package/esm/communicators/broker.d.ts.map +0 -1
- package/esm/communicators/broker.js +0 -105
- package/esm/communicators/broker.js.map +0 -1
- package/esm/communicators/index.d.ts +0 -3
- package/esm/communicators/index.d.ts.map +0 -1
- package/esm/contracts/broker-driver.contract.d.ts +0 -196
- package/esm/contracts/broker-driver.contract.d.ts.map +0 -1
- package/esm/contracts/channel.contract.d.ts +0 -191
- package/esm/contracts/channel.contract.d.ts.map +0 -1
- package/esm/contracts/index.d.ts +0 -3
- package/esm/contracts/index.d.ts.map +0 -1
- package/esm/decorators/consumable.d.ts +0 -13
- package/esm/decorators/consumable.d.ts.map +0 -1
- package/esm/decorators/consumable.js +0 -33
- package/esm/decorators/consumable.js.map +0 -1
- package/esm/decorators/index.d.ts +0 -2
- package/esm/decorators/index.d.ts.map +0 -1
- package/esm/drivers/index.d.ts +0 -2
- package/esm/drivers/index.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/index.d.ts +0 -3
- package/esm/drivers/rabbitmq/index.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts +0 -79
- package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-channel.js +0 -414
- package/esm/drivers/rabbitmq/rabbitmq-channel.js.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts +0 -124
- package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts.map +0 -1
- package/esm/drivers/rabbitmq/rabbitmq-driver.js +0 -347
- package/esm/drivers/rabbitmq/rabbitmq-driver.js.map +0 -1
- package/esm/index.d.ts +0 -47
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +0 -1
- package/esm/message-managers/event-consumer.d.ts +0 -64
- package/esm/message-managers/event-consumer.d.ts.map +0 -1
- package/esm/message-managers/event-consumer.js +0 -71
- package/esm/message-managers/event-consumer.js.map +0 -1
- package/esm/message-managers/event-message.d.ts +0 -90
- package/esm/message-managers/event-message.d.ts.map +0 -1
- package/esm/message-managers/event-message.js +0 -84
- package/esm/message-managers/event-message.js.map +0 -1
- package/esm/message-managers/index.d.ts +0 -4
- package/esm/message-managers/index.d.ts.map +0 -1
- package/esm/message-managers/prepare-consumer-subscription.d.ts +0 -4
- package/esm/message-managers/prepare-consumer-subscription.d.ts.map +0 -1
- package/esm/message-managers/prepare-consumer-subscription.js +0 -40
- package/esm/message-managers/prepare-consumer-subscription.js.map +0 -1
- package/esm/message-managers/types.d.ts +0 -20
- package/esm/message-managers/types.d.ts.map +0 -1
- package/esm/types/channel.types.d.ts +0 -19
- package/esm/types/channel.types.d.ts.map +0 -1
- package/esm/types/connection.types.d.ts +0 -65
- package/esm/types/connection.types.d.ts.map +0 -1
- package/esm/types/driver.types.d.ts +0 -10
- package/esm/types/driver.types.d.ts.map +0 -1
- package/esm/types/index.d.ts +0 -8
- package/esm/types/index.d.ts.map +0 -1
- package/esm/types/message.types.d.ts +0 -34
- package/esm/types/message.types.d.ts.map +0 -1
- package/esm/types/publish.types.d.ts +0 -13
- package/esm/types/publish.types.d.ts.map +0 -1
- package/esm/types/registry.types.d.ts +0 -4
- package/esm/types/registry.types.d.ts.map +0 -1
- package/esm/types/subscribe.types.d.ts +0 -18
- package/esm/types/subscribe.types.d.ts.map +0 -1
- package/esm/utils/connect-to-broker.d.ts.map +0 -1
- package/esm/utils/connect-to-broker.js +0 -171
- package/esm/utils/connect-to-broker.js.map +0 -1
- package/esm/utils/index.d.ts +0 -2
- package/esm/utils/index.d.ts.map +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//#region ../../@warlock.js/herald/src/communicators/broker.ts
|
|
2
|
+
/**
|
|
3
|
+
* Broker - wrapper around a driver with metadata
|
|
4
|
+
*
|
|
5
|
+
* Similar to DataSource in @warlock.js/cascade
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const broker = new Broker({
|
|
10
|
+
* name: "default",
|
|
11
|
+
* driver: rabbitMQDriver,
|
|
12
|
+
* isDefault: true,
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Get a channel
|
|
16
|
+
* const channel = broker.channel("user.created");
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
var Broker = class {
|
|
20
|
+
/**
|
|
21
|
+
* Create a new Broker
|
|
22
|
+
*
|
|
23
|
+
* @param options - Broker configuration
|
|
24
|
+
*/
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.name = options.name;
|
|
27
|
+
this.driver = options.driver;
|
|
28
|
+
this.isDefault = Boolean(options.isDefault);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Subscribe the given consumer
|
|
32
|
+
*/
|
|
33
|
+
subscribe(consumer) {
|
|
34
|
+
return this.driver.subscribe(consumer);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Publish the given event message
|
|
38
|
+
*/
|
|
39
|
+
publish(event) {
|
|
40
|
+
this.driver.publish(event);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get or create a channel
|
|
44
|
+
*
|
|
45
|
+
* @param name - Channel name
|
|
46
|
+
* @param options - Channel options
|
|
47
|
+
* @returns Channel instance
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // Simple channel
|
|
52
|
+
* const channel = broker.channel("notifications");
|
|
53
|
+
*
|
|
54
|
+
* // Typed channel with schema
|
|
55
|
+
* const orderChannel = broker.channel<OrderPayload>("orders", {
|
|
56
|
+
* schema: OrderSchema,
|
|
57
|
+
* durable: true,
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
channel(name, options) {
|
|
62
|
+
return this.driver.channel(name, options);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if the broker is connected
|
|
66
|
+
*/
|
|
67
|
+
get isConnected() {
|
|
68
|
+
return this.driver.isConnected;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Connect the underlying driver
|
|
72
|
+
*/
|
|
73
|
+
async connect() {
|
|
74
|
+
await this.driver.connect();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Disconnect the underlying driver
|
|
78
|
+
*/
|
|
79
|
+
async disconnect() {
|
|
80
|
+
await this.driver.disconnect();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Start consuming messages
|
|
84
|
+
*/
|
|
85
|
+
async startConsuming() {
|
|
86
|
+
await this.driver.startConsuming();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Stop consuming messages
|
|
90
|
+
*/
|
|
91
|
+
async stopConsuming() {
|
|
92
|
+
await this.driver.stopConsuming();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Health check
|
|
96
|
+
*/
|
|
97
|
+
async healthCheck() {
|
|
98
|
+
return this.driver.healthCheck();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { Broker };
|
|
104
|
+
//# sourceMappingURL=broker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker.mjs","names":[],"sources":["../../../../../../@warlock.js/herald/src/communicators/broker.ts"],"sourcesContent":["import type { BrokerDriverContract } from \"../contracts\";\r\nimport type { ChannelContract } from \"../contracts/channel.contract\";\r\nimport { EventMessage } from \"../message-managers/event-message\";\r\nimport { EventConsumerClass } from \"../message-managers/types\";\r\nimport type { ChannelOptions } from \"../types\";\r\n\r\n/**\r\n * Options for creating a Broker\r\n */\r\nexport interface BrokerOptions {\r\n /** Unique name for this broker */\r\n name: string;\r\n /** The underlying driver */\r\n driver: BrokerDriverContract;\r\n /** Whether this is the default broker */\r\n isDefault?: boolean;\r\n}\r\n\r\n/**\r\n * Broker - wrapper around a driver with metadata\r\n *\r\n * Similar to DataSource in @warlock.js/cascade\r\n *\r\n * @example\r\n * ```typescript\r\n * const broker = new Broker({\r\n * name: \"default\",\r\n * driver: rabbitMQDriver,\r\n * isDefault: true,\r\n * });\r\n *\r\n * // Get a channel\r\n * const channel = broker.channel(\"user.created\");\r\n * ```\r\n */\r\nexport class Broker {\r\n /** Unique name identifying this broker */\r\n public readonly name: string;\r\n\r\n /** The underlying driver */\r\n public readonly driver: BrokerDriverContract;\r\n\r\n /** Whether this is the default broker */\r\n public readonly isDefault: boolean;\r\n\r\n /**\r\n * Create a new Broker\r\n *\r\n * @param options - Broker configuration\r\n */\r\n public constructor(options: BrokerOptions) {\r\n this.name = options.name;\r\n this.driver = options.driver;\r\n this.isDefault = Boolean(options.isDefault);\r\n }\r\n\r\n /**\r\n * Subscribe the given consumer\r\n */\r\n public subscribe(consumer: EventConsumerClass<any>) {\r\n return this.driver.subscribe(consumer);\r\n }\r\n\r\n /**\r\n * Publish the given event message\r\n */\r\n public publish<TPayload = Record<string, any>>(event: EventMessage<TPayload>) {\r\n this.driver.publish(event);\r\n }\r\n\r\n /**\r\n * Get or create a channel\r\n *\r\n * @param name - Channel name\r\n * @param options - Channel options\r\n * @returns Channel instance\r\n *\r\n * @example\r\n * ```typescript\r\n * // Simple channel\r\n * const channel = broker.channel(\"notifications\");\r\n *\r\n * // Typed channel with schema\r\n * const orderChannel = broker.channel<OrderPayload>(\"orders\", {\r\n * schema: OrderSchema,\r\n * durable: true,\r\n * });\r\n * ```\r\n */\r\n public channel<TPayload = unknown>(\r\n name: string,\r\n options?: ChannelOptions<TPayload>,\r\n ): ChannelContract<TPayload> {\r\n return this.driver.channel<TPayload>(name, options);\r\n }\r\n\r\n /**\r\n * Check if the broker is connected\r\n */\r\n public get isConnected(): boolean {\r\n return this.driver.isConnected;\r\n }\r\n\r\n /**\r\n * Connect the underlying driver\r\n */\r\n public async connect(): Promise<void> {\r\n await this.driver.connect();\r\n }\r\n\r\n /**\r\n * Disconnect the underlying driver\r\n */\r\n public async disconnect(): Promise<void> {\r\n await this.driver.disconnect();\r\n }\r\n\r\n /**\r\n * Start consuming messages\r\n */\r\n public async startConsuming(): Promise<void> {\r\n await this.driver.startConsuming();\r\n }\r\n\r\n /**\r\n * Stop consuming messages\r\n */\r\n public async stopConsuming(): Promise<void> {\r\n await this.driver.stopConsuming();\r\n }\r\n\r\n /**\r\n * Health check\r\n */\r\n public async healthCheck() {\r\n return this.driver.healthCheck();\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,IAAa,SAAb,MAAoB;;;;;;CAelB,AAAO,YAAY,SAAwB;EACzC,KAAK,OAAO,QAAQ;EACpB,KAAK,SAAS,QAAQ;EACtB,KAAK,YAAY,QAAQ,QAAQ,SAAS;CAC5C;;;;CAKA,AAAO,UAAU,UAAmC;EAClD,OAAO,KAAK,OAAO,UAAU,QAAQ;CACvC;;;;CAKA,AAAO,QAAwC,OAA+B;EAC5E,KAAK,OAAO,QAAQ,KAAK;CAC3B;;;;;;;;;;;;;;;;;;;;CAqBA,AAAO,QACL,MACA,SAC2B;EAC3B,OAAO,KAAK,OAAO,QAAkB,MAAM,OAAO;CACpD;;;;CAKA,IAAW,cAAuB;EAChC,OAAO,KAAK,OAAO;CACrB;;;;CAKA,MAAa,UAAyB;EACpC,MAAM,KAAK,OAAO,QAAQ;CAC5B;;;;CAKA,MAAa,aAA4B;EACvC,MAAM,KAAK,OAAO,WAAW;CAC/B;;;;CAKA,MAAa,iBAAgC;EAC3C,MAAM,KAAK,OAAO,eAAe;CACnC;;;;CAKA,MAAa,gBAA+B;EAC1C,MAAM,KAAK,OAAO,cAAc;CAClC;;;;CAKA,MAAa,cAAc;EACzB,OAAO,KAAK,OAAO,YAAY;CACjC;AACF"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ChannelOptions } from "../types/channel.types.mjs";
|
|
2
|
+
import { BrokerDriverType, BrokerEvent, BrokerEventListener, HealthCheckResult } from "../types/driver.types.mjs";
|
|
3
|
+
import { ChannelContract } from "./channel.contract.mjs";
|
|
4
|
+
import { EventMessage } from "../message-managers/event-message.mjs";
|
|
5
|
+
import { EventConsumerClass } from "../message-managers/types.mjs";
|
|
6
|
+
//#region ../../@warlock.js/herald/src/contracts/broker-driver.contract.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Broker Driver Contract
|
|
9
|
+
*
|
|
10
|
+
* Base contract for all message bus drivers (RabbitMQ, Kafka, etc.)
|
|
11
|
+
* Similar to DriverContract in @warlock.js/cascade
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Driver implementation
|
|
16
|
+
* class RabbitMQDriver implements BrokerDriverContract {
|
|
17
|
+
* readonly name = "rabbitmq";
|
|
18
|
+
* // ...
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
interface BrokerDriverContract {
|
|
23
|
+
/**
|
|
24
|
+
* Driver name identifier
|
|
25
|
+
*
|
|
26
|
+
* @example "rabbitmq", "kafka", "redis-streams"
|
|
27
|
+
*/
|
|
28
|
+
readonly name: BrokerDriverType;
|
|
29
|
+
/**
|
|
30
|
+
* Whether currently connected to the message broker
|
|
31
|
+
*/
|
|
32
|
+
readonly isConnected: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Establish connection to the message broker
|
|
35
|
+
*
|
|
36
|
+
* @throws Error if connection fails
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* await driver.connect();
|
|
41
|
+
* console.log("Connected to RabbitMQ");
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
connect(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Close connection gracefully
|
|
47
|
+
*
|
|
48
|
+
* Ensures all pending operations complete before disconnecting.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* await driver.disconnect();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
disconnect(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Register event listeners for driver lifecycle events
|
|
58
|
+
*
|
|
59
|
+
* @param event - Event name to listen for
|
|
60
|
+
* @param listener - Callback function
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* driver.on("connected", () => {
|
|
65
|
+
* console.log("Connected to broker");
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* driver.on("disconnected", () => {
|
|
69
|
+
* console.log("Disconnected from broker");
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* driver.on("error", (error) => {
|
|
73
|
+
* console.error("Driver error:", error);
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* driver.on("reconnecting", (attempt) => {
|
|
77
|
+
* console.log(`Reconnection attempt ${attempt}`);
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
on(event: BrokerEvent, listener: BrokerEventListener): void;
|
|
82
|
+
/**
|
|
83
|
+
* Remove an event listener
|
|
84
|
+
*
|
|
85
|
+
* @param event - Event name
|
|
86
|
+
* @param listener - Callback to remove
|
|
87
|
+
*/
|
|
88
|
+
off(event: BrokerEvent, listener: BrokerEventListener): void;
|
|
89
|
+
/**
|
|
90
|
+
* Subscribe the given consumer class to the driver
|
|
91
|
+
*
|
|
92
|
+
* @param consumer - Consumer class to subscribe
|
|
93
|
+
* @returns Unsubscribe function
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* driver.subscribe(UserUpdatedConsumer);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
subscribe(consumer: EventConsumerClass): () => void;
|
|
100
|
+
/**
|
|
101
|
+
* Unsubscribe the given consumer class from the driver
|
|
102
|
+
*
|
|
103
|
+
* @param consumer - Consumer class to unsubscribe
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* driver.unsubscribe(UserUpdatedConsumer);
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
unsubscribe(consumer: EventConsumerClass): void;
|
|
111
|
+
/**
|
|
112
|
+
* Publish the given event message
|
|
113
|
+
*/
|
|
114
|
+
publish<TPayload = Record<string, any>>(event: EventMessage<TPayload>): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get or create a channel
|
|
117
|
+
*
|
|
118
|
+
* Channels are lazy-created and cached for reuse.
|
|
119
|
+
*
|
|
120
|
+
* @param name - Channel/queue/topic name
|
|
121
|
+
* @param options - Channel configuration
|
|
122
|
+
* @returns Channel instance
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // Simple channel
|
|
127
|
+
* const channel = driver.channel("user.created");
|
|
128
|
+
*
|
|
129
|
+
* // With options
|
|
130
|
+
* const orderChannel = driver.channel("orders", {
|
|
131
|
+
* durable: true,
|
|
132
|
+
* deadLetter: { channel: "orders.failed" },
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* // Typed channel
|
|
136
|
+
* const typedChannel = driver.channel<OrderPayload>("orders", {
|
|
137
|
+
* schema: OrderSchema,
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
channel<TPayload = unknown>(name: string, options?: ChannelOptions<TPayload>): ChannelContract<TPayload>;
|
|
142
|
+
/**
|
|
143
|
+
* Start consuming messages from all subscribed channels
|
|
144
|
+
*
|
|
145
|
+
* Call this after setting up all subscriptions to begin processing.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // Set up subscriptions
|
|
150
|
+
* channel1.subscribe(handler1);
|
|
151
|
+
* channel2.subscribe(handler2);
|
|
152
|
+
*
|
|
153
|
+
* // Start consuming
|
|
154
|
+
* await driver.startConsuming();
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
startConsuming(): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Stop consuming messages gracefully
|
|
160
|
+
*
|
|
161
|
+
* Waits for currently processing messages to complete.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* await driver.stopConsuming();
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
stopConsuming(): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Perform a health check on the connection
|
|
171
|
+
*
|
|
172
|
+
* @returns Health check result with status and optional latency
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const health = await driver.healthCheck();
|
|
177
|
+
* if (health.healthy) {
|
|
178
|
+
* console.log(`Healthy, latency: ${health.latency}ms`);
|
|
179
|
+
* } else {
|
|
180
|
+
* console.error(`Unhealthy: ${health.error}`);
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
185
|
+
/**
|
|
186
|
+
* Get list of all channels managed by this driver
|
|
187
|
+
*
|
|
188
|
+
* @returns Array of channel names
|
|
189
|
+
*/
|
|
190
|
+
getChannelNames(): string[];
|
|
191
|
+
/**
|
|
192
|
+
* Close and remove a specific channel
|
|
193
|
+
*
|
|
194
|
+
* @param name - Channel name to close
|
|
195
|
+
*/
|
|
196
|
+
closeChannel(name: string): Promise<void>;
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
export { BrokerDriverContract };
|
|
200
|
+
//# sourceMappingURL=broker-driver.contract.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-driver.contract.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/contracts/broker-driver.contract.ts"],"mappings":";;;;;;;;;;AA0BA;;;;;;;;;;;UAAiB,oBAAA;EAoGI;;;;;EAAA,SA9FV,IAAA,EAAM,gBAAA;EA6HZ;;;EAAA,SAxHM,WAAA;EAsKM;;;;;;;;;;;EAzJf,OAAA,IAAW,OAAA;EAuCD;;;;;;;;;;EA3BV,UAAA,IAAc,OAAA;EA+CJ;;;;;;;;;;;;;;;;;;;;;;;;;EApBV,EAAA,CAAG,KAAA,EAAO,WAAA,EAAa,QAAA,EAAU,mBAAA;EAgIjC;;;;AAAmC;;EAxHnC,GAAA,CAAI,KAAA,EAAO,WAAA,EAAa,QAAA,EAAU,mBAAA;;;;;;;;;;;EAYlC,SAAA,CAAU,QAAA,EAAU,kBAAA;;;;;;;;;;;EAYpB,WAAA,CAAY,QAAA,EAAU,kBAAA;;;;EAKtB,OAAA,YAAmB,MAAA,eAAqB,KAAA,EAAO,YAAA,CAAa,QAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4B5D,OAAA,qBACE,IAAA,UACA,OAAA,GAAU,cAAA,CAAe,QAAA,IACxB,eAAA,CAAgB,QAAA;;;;;;;;;;;;;;;;EAiBnB,cAAA,IAAkB,OAAA;;;;;;;;;;;EAYlB,aAAA,IAAiB,OAAA;;;;;;;;;;;;;;;;EAiBjB,WAAA,IAAe,OAAA,CAAQ,iBAAA;;;;;;EAOvB,eAAA;;;;;;EAOA,YAAA,CAAa,IAAA,WAAe,OAAA;AAAA"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { SubscribeOptions } from "../types/subscribe.types.mjs";
|
|
2
|
+
import { ChannelOptions, ChannelStats } from "../types/channel.types.mjs";
|
|
3
|
+
import { MessageHandler, ResponseHandler, Subscription } from "../types/message.types.mjs";
|
|
4
|
+
import { PublishOptions, RequestOptions } from "../types/publish.types.mjs";
|
|
5
|
+
//#region ../../@warlock.js/herald/src/contracts/channel.contract.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Channel contract - represents a queue (RabbitMQ) or topic (Kafka)
|
|
8
|
+
*
|
|
9
|
+
* Provides a unified pub/sub interface across different message brokers.
|
|
10
|
+
*
|
|
11
|
+
* @template TPayload - The typed payload for messages on this channel
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Get a typed channel
|
|
16
|
+
* const userChannel = herald().channel<UserPayload>("user.created");
|
|
17
|
+
*
|
|
18
|
+
* // Publish
|
|
19
|
+
* await userChannel.publish({ userId: 1, email: "test@example.com" });
|
|
20
|
+
*
|
|
21
|
+
* // Subscribe
|
|
22
|
+
* userChannel.subscribe(async (message, ctx) => {
|
|
23
|
+
* console.log(message.payload.userId);
|
|
24
|
+
* await ctx.ack();
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
interface ChannelContract<TPayload = unknown> {
|
|
29
|
+
/**
|
|
30
|
+
* Channel name/routing key
|
|
31
|
+
*/
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/**
|
|
34
|
+
* Channel options
|
|
35
|
+
*/
|
|
36
|
+
readonly options: ChannelOptions<TPayload>;
|
|
37
|
+
/**
|
|
38
|
+
* Publish a message to this channel
|
|
39
|
+
*
|
|
40
|
+
* @param payload - The message payload
|
|
41
|
+
* @param options - Optional publish options
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* await channel.publish({ orderId: 123 });
|
|
46
|
+
*
|
|
47
|
+
* // With options
|
|
48
|
+
* await channel.publish({ orderId: 123 }, {
|
|
49
|
+
* priority: 5,
|
|
50
|
+
* persistent: true,
|
|
51
|
+
* correlationId: "req-123",
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
publish(payload: TPayload, options?: PublishOptions): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Publish multiple messages in a batch
|
|
58
|
+
*
|
|
59
|
+
* More efficient than publishing one by one.
|
|
60
|
+
*
|
|
61
|
+
* @param messages - Array of payloads to publish
|
|
62
|
+
* @param options - Optional publish options (applied to all messages)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* await channel.publishBatch([
|
|
67
|
+
* { event: "page_view", page: "/home" },
|
|
68
|
+
* { event: "page_view", page: "/products" },
|
|
69
|
+
* ]);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
publishBatch(messages: TPayload[], options?: PublishOptions): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribe to messages on this channel
|
|
75
|
+
*
|
|
76
|
+
* @param handler - Function to handle incoming messages
|
|
77
|
+
* @param options - Optional subscribe options
|
|
78
|
+
* @returns Subscription object for managing the subscription
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const subscription = await channel.subscribe(
|
|
83
|
+
* async (message, ctx) => {
|
|
84
|
+
* await processOrder(message.payload);
|
|
85
|
+
* await ctx.ack();
|
|
86
|
+
* },
|
|
87
|
+
* {
|
|
88
|
+
* prefetch: 10,
|
|
89
|
+
* retry: { maxRetries: 3, delay: 1000 },
|
|
90
|
+
* }
|
|
91
|
+
* );
|
|
92
|
+
*
|
|
93
|
+
* // Later: unsubscribe
|
|
94
|
+
* await subscription.unsubscribe();
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
subscribe(handler: MessageHandler<TPayload>, options?: SubscribeOptions): Promise<Subscription>;
|
|
98
|
+
/**
|
|
99
|
+
* Unsubscribe a consumer by its ID
|
|
100
|
+
*
|
|
101
|
+
* @param consumerId - The consumer ID to unsubscribe
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* await channel.unsubscribeById("consumer-uuid");
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
unsubscribeById(consumerId: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Request-Response pattern (RPC)
|
|
111
|
+
*
|
|
112
|
+
* Publishes a message and waits for a response.
|
|
113
|
+
*
|
|
114
|
+
* @param payload - The request payload
|
|
115
|
+
* @param options - Request options including timeout
|
|
116
|
+
* @returns Promise resolving to the response
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const result = await channel.request<ProcessResult>(
|
|
121
|
+
* { imageUrl: "https://..." },
|
|
122
|
+
* { timeout: 30000 }
|
|
123
|
+
* );
|
|
124
|
+
* console.log(result.processedUrl);
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
request<TResponse = unknown>(payload: TPayload, options?: RequestOptions): Promise<TResponse>;
|
|
128
|
+
/**
|
|
129
|
+
* Register a response handler for RPC pattern
|
|
130
|
+
*
|
|
131
|
+
* The return value of the handler becomes the response.
|
|
132
|
+
*
|
|
133
|
+
* @param handler - Function to handle requests and return responses
|
|
134
|
+
* @returns Subscription for managing the responder
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* channel.respond(async (message, ctx) => {
|
|
139
|
+
* const result = await processImage(message.payload);
|
|
140
|
+
* return { processedUrl: result.url };
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
respond<TResponse = unknown>(handler: ResponseHandler<TPayload, TResponse>): Promise<Subscription>;
|
|
145
|
+
/**
|
|
146
|
+
* Get channel statistics
|
|
147
|
+
*
|
|
148
|
+
* @returns Channel stats including message count and consumer count
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const stats = await channel.stats();
|
|
153
|
+
* console.log(`Messages: ${stats.messageCount}, Consumers: ${stats.consumerCount}`);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
stats(): Promise<ChannelStats>;
|
|
157
|
+
/**
|
|
158
|
+
* Purge all messages from the channel
|
|
159
|
+
*
|
|
160
|
+
* Use with caution - this deletes all pending messages.
|
|
161
|
+
*
|
|
162
|
+
* @returns Number of messages purged
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const purgedCount = await channel.purge();
|
|
167
|
+
* console.log(`Purged ${purgedCount} messages`);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
purge(): Promise<number>;
|
|
171
|
+
/**
|
|
172
|
+
* Check if the channel exists
|
|
173
|
+
*
|
|
174
|
+
* @returns True if the channel exists on the broker
|
|
175
|
+
*/
|
|
176
|
+
exists(): Promise<boolean>;
|
|
177
|
+
/**
|
|
178
|
+
* Delete the channel
|
|
179
|
+
*
|
|
180
|
+
* Use with caution - this removes the queue/topic entirely.
|
|
181
|
+
*/
|
|
182
|
+
delete(): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Assert/create the channel with its options
|
|
185
|
+
*
|
|
186
|
+
* Creates the channel if it doesn't exist, or verifies options match.
|
|
187
|
+
*/
|
|
188
|
+
assert(): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Stop consuming messages on this channel.
|
|
191
|
+
* Cancels all active subscriptions gracefully.
|
|
192
|
+
*/
|
|
193
|
+
stopConsuming(): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
export { ChannelContract };
|
|
197
|
+
//# sourceMappingURL=channel.contract.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.contract.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/contracts/channel.contract.ts"],"mappings":";;;;;;;;;;;AAiCA;;;;;;;;;;;;;;;;UAAiB,eAAA;EAyGuB;;;EAAA,SArG7B,IAAA;EAwHkB;;;EAAA,SAnHlB,OAAA,EAAS,cAAA,CAAe,QAAA;EAoH9B;;;;;;;;;;;;;;;;;;EAhGH,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU,OAAA,GAAU,cAAA,GAAiB,OAAA;EAA3B;;;;;;;;;;;;;;;;EAkB3B,YAAA,CAAa,QAAA,EAAU,QAAA,IAAY,OAAA,GAAU,cAAA,GAAiB,OAAA;EAsC9C;;;;;;;;;;;;;;;;;;;;;;;;EAZhB,SAAA,CAAU,OAAA,EAAS,cAAA,CAAe,QAAA,GAAW,OAAA,GAAU,gBAAA,GAAmB,OAAA,CAAQ,YAAA;EA8FlF;;;;;;;AAawB;;;EA/FxB,eAAA,CAAgB,UAAA,WAAqB,OAAA;;;;;;;;;;;;;;;;;;;EAoBrC,OAAA,sBAA6B,OAAA,EAAS,QAAA,EAAU,OAAA,GAAU,cAAA,GAAiB,OAAA,CAAQ,SAAA;;;;;;;;;;;;;;;;;EAkBnF,OAAA,sBACE,OAAA,EAAS,eAAA,CAAgB,QAAA,EAAU,SAAA,IAClC,OAAA,CAAQ,YAAA;;;;;;;;;;;;EAaX,KAAA,IAAS,OAAA,CAAQ,YAAA;;;;;;;;;;;;;;EAejB,KAAA,IAAS,OAAA;;;;;;EAOT,MAAA,IAAU,OAAA;;;;;;EAOV,MAAA,IAAU,OAAA;;;;;;EAOV,MAAA,IAAU,OAAA;;;;;EAMV,aAAA,IAAiB,OAAA;AAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EventConsumerClass } from "../message-managers/types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/herald/src/decorators/consumable.d.ts
|
|
4
|
+
type ConsumableOptions = {
|
|
5
|
+
broker?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const pendingSubscribers: Set<{
|
|
8
|
+
Consumer: EventConsumerClass;
|
|
9
|
+
options?: ConsumableOptions;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Register the consumer to the broker
|
|
13
|
+
*/
|
|
14
|
+
declare function Consumable(options?: ConsumableOptions): (target: EventConsumerClass) => void;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Consumable, ConsumableOptions, pendingSubscribers };
|
|
17
|
+
//# sourceMappingURL=consumable.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumable.d.mts","names":[],"sources":["../../../../../../@warlock.js/herald/src/decorators/consumable.ts"],"mappings":";;;KAGY,iBAAA;EACV,MAAM;AAAA;AAAA,cAGK,kBAAA,EAAkB,GAAA;YACnB,kBAAA;YACA,iBAAA;AAAA;AAFZ;;;AAAA,iBAQgB,UAAA,CAAW,OAAA,GAAU,iBAAA,IAClB,MAAA,EAAQ,kBAAkB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { brokerRegistry } from "../communicators/broker-registry.mjs";
|
|
2
|
+
import "../communicators/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/herald/src/decorators/consumable.ts
|
|
5
|
+
const pendingSubscribers = /* @__PURE__ */ new Set();
|
|
6
|
+
/**
|
|
7
|
+
* Register the consumer to the broker
|
|
8
|
+
*/
|
|
9
|
+
function Consumable(options) {
|
|
10
|
+
return function(target) {
|
|
11
|
+
const brokerName = options?.broker;
|
|
12
|
+
try {
|
|
13
|
+
const currentBroker = brokerRegistry.get(brokerName);
|
|
14
|
+
if (currentBroker?.isConnected) currentBroker.subscribe(target);
|
|
15
|
+
else pendingSubscribers.add({
|
|
16
|
+
Consumer: target,
|
|
17
|
+
options
|
|
18
|
+
});
|
|
19
|
+
} catch {
|
|
20
|
+
pendingSubscribers.add({
|
|
21
|
+
Consumer: target,
|
|
22
|
+
options
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
brokerRegistry.on("connected", (broker) => {
|
|
28
|
+
for (const { Consumer, options } of pendingSubscribers) {
|
|
29
|
+
if (options?.broker && broker.name !== options.broker) continue;
|
|
30
|
+
broker.subscribe(Consumer);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Consumable, pendingSubscribers };
|
|
36
|
+
//# sourceMappingURL=consumable.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumable.mjs","names":[],"sources":["../../../../../../@warlock.js/herald/src/decorators/consumable.ts"],"sourcesContent":["import { brokerRegistry } from \"../communicators\";\nimport { type EventConsumerClass } from \"../message-managers/types\";\n\nexport type ConsumableOptions = {\n broker?: string;\n};\n\nexport const pendingSubscribers = new Set<{\n Consumer: EventConsumerClass;\n options?: ConsumableOptions;\n}>();\n\n/**\n * Register the consumer to the broker\n */\nexport function Consumable(options?: ConsumableOptions) {\n return function (target: EventConsumerClass) {\n const brokerName = options?.broker;\n\n try {\n const currentBroker = brokerRegistry.get(brokerName);\n\n // if broker is connected, subscribe the consumer\n if (currentBroker?.isConnected) {\n currentBroker.subscribe(target);\n } else {\n pendingSubscribers.add({ Consumer: target, options });\n }\n } catch {\n // mostly it will be an error that broker is not registered yet\n // then add it to the pending subscribers\n pendingSubscribers.add({ Consumer: target, options });\n }\n };\n}\n\n// Register pending consumers on broker's connection is done\nbrokerRegistry.on(\"connected\", (broker) => {\n for (const { Consumer, options } of pendingSubscribers) {\n if (options?.broker && broker.name !== options.broker) {\n continue;\n }\n\n broker.subscribe(Consumer);\n }\n});\n"],"mappings":";;;;AAOA,MAAa,qCAAqB,IAAI,IAGnC;;;;AAKH,SAAgB,WAAW,SAA6B;CACtD,OAAO,SAAU,QAA4B;EAC3C,MAAM,aAAa,SAAS;EAE5B,IAAI;GACF,MAAM,gBAAgB,eAAe,IAAI,UAAU;GAGnD,IAAI,eAAe,aACjB,cAAc,UAAU,MAAM;QAE9B,mBAAmB,IAAI;IAAE,UAAU;IAAQ;GAAQ,CAAC;EAExD,QAAQ;GAGN,mBAAmB,IAAI;IAAE,UAAU;IAAQ;GAAQ,CAAC;EACtD;CACF;AACF;AAGA,eAAe,GAAG,cAAc,WAAW;CACzC,KAAK,MAAM,EAAE,UAAU,aAAa,oBAAoB;EACtD,IAAI,SAAS,UAAU,OAAO,SAAS,QAAQ,QAC7C;EAGF,OAAO,UAAU,QAAQ;CAC3B;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Consumable, ConsumableOptions, pendingSubscribers } from "./consumable.mjs";
|