@warlock.js/herald 4.0.156 → 4.0.158

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.
Files changed (125) hide show
  1. package/package.json +3 -3
  2. package/cjs/communicators/communicator-registry.d.ts +0 -155
  3. package/cjs/communicators/communicator-registry.d.ts.map +0 -1
  4. package/cjs/communicators/communicator-registry.js +0 -206
  5. package/cjs/communicators/communicator-registry.js.map +0 -1
  6. package/cjs/communicators/communicator.d.ts +0 -100
  7. package/cjs/communicators/communicator.d.ts.map +0 -1
  8. package/cjs/communicators/communicator.js +0 -105
  9. package/cjs/communicators/communicator.js.map +0 -1
  10. package/cjs/communicators/index.d.ts +0 -3
  11. package/cjs/communicators/index.d.ts.map +0 -1
  12. package/cjs/contracts/channel.contract.d.ts +0 -186
  13. package/cjs/contracts/channel.contract.d.ts.map +0 -1
  14. package/cjs/contracts/communicator-driver.contract.d.ts +0 -196
  15. package/cjs/contracts/communicator-driver.contract.d.ts.map +0 -1
  16. package/cjs/contracts/index.d.ts +0 -3
  17. package/cjs/contracts/index.d.ts.map +0 -1
  18. package/cjs/decorators/consumable.d.ts +0 -13
  19. package/cjs/decorators/consumable.d.ts.map +0 -1
  20. package/cjs/decorators/consumable.js +0 -33
  21. package/cjs/decorators/consumable.js.map +0 -1
  22. package/cjs/decorators/index.d.ts +0 -2
  23. package/cjs/decorators/index.d.ts.map +0 -1
  24. package/cjs/drivers/index.d.ts +0 -2
  25. package/cjs/drivers/index.d.ts.map +0 -1
  26. package/cjs/drivers/rabbitmq/index.d.ts +0 -3
  27. package/cjs/drivers/rabbitmq/index.d.ts.map +0 -1
  28. package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts +0 -78
  29. package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts.map +0 -1
  30. package/cjs/drivers/rabbitmq/rabbitmq-channel.js +0 -412
  31. package/cjs/drivers/rabbitmq/rabbitmq-channel.js.map +0 -1
  32. package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts +0 -122
  33. package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts.map +0 -1
  34. package/cjs/drivers/rabbitmq/rabbitmq-driver.js +0 -346
  35. package/cjs/drivers/rabbitmq/rabbitmq-driver.js.map +0 -1
  36. package/cjs/index.d.ts +0 -47
  37. package/cjs/index.d.ts.map +0 -1
  38. package/cjs/index.js +0 -1
  39. package/cjs/index.js.map +0 -1
  40. package/cjs/message-managers/event-consumer.d.ts +0 -63
  41. package/cjs/message-managers/event-consumer.d.ts.map +0 -1
  42. package/cjs/message-managers/event-consumer.js +0 -65
  43. package/cjs/message-managers/event-consumer.js.map +0 -1
  44. package/cjs/message-managers/event-message.d.ts +0 -87
  45. package/cjs/message-managers/event-message.d.ts.map +0 -1
  46. package/cjs/message-managers/event-message.js +0 -84
  47. package/cjs/message-managers/event-message.js.map +0 -1
  48. package/cjs/message-managers/index.d.ts +0 -4
  49. package/cjs/message-managers/index.d.ts.map +0 -1
  50. package/cjs/message-managers/prepare-consumer-subscription.d.ts +0 -4
  51. package/cjs/message-managers/prepare-consumer-subscription.d.ts.map +0 -1
  52. package/cjs/message-managers/prepare-consumer-subscription.js +0 -39
  53. package/cjs/message-managers/prepare-consumer-subscription.js.map +0 -1
  54. package/cjs/message-managers/types.d.ts +0 -20
  55. package/cjs/message-managers/types.d.ts.map +0 -1
  56. package/cjs/types.d.ts +0 -399
  57. package/cjs/types.d.ts.map +0 -1
  58. package/cjs/utils/connect-to-communicator.d.ts +0 -129
  59. package/cjs/utils/connect-to-communicator.d.ts.map +0 -1
  60. package/cjs/utils/connect-to-communicator.js +0 -169
  61. package/cjs/utils/connect-to-communicator.js.map +0 -1
  62. package/cjs/utils/index.d.ts +0 -2
  63. package/cjs/utils/index.d.ts.map +0 -1
  64. package/esm/communicators/communicator-registry.d.ts +0 -155
  65. package/esm/communicators/communicator-registry.d.ts.map +0 -1
  66. package/esm/communicators/communicator-registry.js +0 -206
  67. package/esm/communicators/communicator-registry.js.map +0 -1
  68. package/esm/communicators/communicator.d.ts +0 -100
  69. package/esm/communicators/communicator.d.ts.map +0 -1
  70. package/esm/communicators/communicator.js +0 -105
  71. package/esm/communicators/communicator.js.map +0 -1
  72. package/esm/communicators/index.d.ts +0 -3
  73. package/esm/communicators/index.d.ts.map +0 -1
  74. package/esm/contracts/channel.contract.d.ts +0 -186
  75. package/esm/contracts/channel.contract.d.ts.map +0 -1
  76. package/esm/contracts/communicator-driver.contract.d.ts +0 -196
  77. package/esm/contracts/communicator-driver.contract.d.ts.map +0 -1
  78. package/esm/contracts/index.d.ts +0 -3
  79. package/esm/contracts/index.d.ts.map +0 -1
  80. package/esm/decorators/consumable.d.ts +0 -13
  81. package/esm/decorators/consumable.d.ts.map +0 -1
  82. package/esm/decorators/consumable.js +0 -33
  83. package/esm/decorators/consumable.js.map +0 -1
  84. package/esm/decorators/index.d.ts +0 -2
  85. package/esm/decorators/index.d.ts.map +0 -1
  86. package/esm/drivers/index.d.ts +0 -2
  87. package/esm/drivers/index.d.ts.map +0 -1
  88. package/esm/drivers/rabbitmq/index.d.ts +0 -3
  89. package/esm/drivers/rabbitmq/index.d.ts.map +0 -1
  90. package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts +0 -78
  91. package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts.map +0 -1
  92. package/esm/drivers/rabbitmq/rabbitmq-channel.js +0 -412
  93. package/esm/drivers/rabbitmq/rabbitmq-channel.js.map +0 -1
  94. package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts +0 -122
  95. package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts.map +0 -1
  96. package/esm/drivers/rabbitmq/rabbitmq-driver.js +0 -346
  97. package/esm/drivers/rabbitmq/rabbitmq-driver.js.map +0 -1
  98. package/esm/index.d.ts +0 -47
  99. package/esm/index.d.ts.map +0 -1
  100. package/esm/index.js +0 -1
  101. package/esm/index.js.map +0 -1
  102. package/esm/message-managers/event-consumer.d.ts +0 -63
  103. package/esm/message-managers/event-consumer.d.ts.map +0 -1
  104. package/esm/message-managers/event-consumer.js +0 -65
  105. package/esm/message-managers/event-consumer.js.map +0 -1
  106. package/esm/message-managers/event-message.d.ts +0 -87
  107. package/esm/message-managers/event-message.d.ts.map +0 -1
  108. package/esm/message-managers/event-message.js +0 -84
  109. package/esm/message-managers/event-message.js.map +0 -1
  110. package/esm/message-managers/index.d.ts +0 -4
  111. package/esm/message-managers/index.d.ts.map +0 -1
  112. package/esm/message-managers/prepare-consumer-subscription.d.ts +0 -4
  113. package/esm/message-managers/prepare-consumer-subscription.d.ts.map +0 -1
  114. package/esm/message-managers/prepare-consumer-subscription.js +0 -39
  115. package/esm/message-managers/prepare-consumer-subscription.js.map +0 -1
  116. package/esm/message-managers/types.d.ts +0 -20
  117. package/esm/message-managers/types.d.ts.map +0 -1
  118. package/esm/types.d.ts +0 -399
  119. package/esm/types.d.ts.map +0 -1
  120. package/esm/utils/connect-to-communicator.d.ts +0 -129
  121. package/esm/utils/connect-to-communicator.d.ts.map +0 -1
  122. package/esm/utils/connect-to-communicator.js +0 -169
  123. package/esm/utils/connect-to-communicator.js.map +0 -1
  124. package/esm/utils/index.d.ts +0 -2
  125. package/esm/utils/index.d.ts.map +0 -1
@@ -1,100 +0,0 @@
1
- import type { CommunicatorDriverContract } from "../contracts";
2
- import type { ChannelContract } from "../contracts/channel.contract";
3
- import { EventMessage } from "../message-managers/event-message";
4
- import { EventConsumerClass } from "../message-managers/types";
5
- import type { ChannelOptions } from "../types";
6
- /**
7
- * Options for creating a Communicator
8
- */
9
- export interface CommunicatorOptions {
10
- /** Unique name for this communicator */
11
- name: string;
12
- /** The underlying driver */
13
- driver: CommunicatorDriverContract;
14
- /** Whether this is the default communicator */
15
- isDefault?: boolean;
16
- }
17
- /**
18
- * Communicator - wrapper around a driver with metadata
19
- *
20
- * Similar to DataSource in @warlock.js/cascade
21
- *
22
- * @example
23
- * ```typescript
24
- * const communicator = new Communicator({
25
- * name: "default",
26
- * driver: rabbitMQDriver,
27
- * isDefault: true,
28
- * });
29
- *
30
- * // Get a channel
31
- * const channel = communicator.channel("user.created");
32
- * ```
33
- */
34
- export declare class Communicator {
35
- /** Unique name identifying this communicator */
36
- readonly name: string;
37
- /** The underlying driver */
38
- readonly driver: CommunicatorDriverContract;
39
- /** Whether this is the default communicator */
40
- readonly isDefault: boolean;
41
- /**
42
- * Create a new Communicator
43
- *
44
- * @param options - Communicator configuration
45
- */
46
- constructor(options: CommunicatorOptions);
47
- /**
48
- * Subscribe the given consumer
49
- */
50
- subscribe(consumer: EventConsumerClass<any>): () => void;
51
- /**
52
- * Publish the given event message
53
- */
54
- publish<TPayload = Record<string, any>>(event: EventMessage<TPayload>): void;
55
- /**
56
- * Get or create a channel
57
- *
58
- * @param name - Channel name
59
- * @param options - Channel options
60
- * @returns Channel instance
61
- *
62
- * @example
63
- * ```typescript
64
- * // Simple channel
65
- * const channel = communicator.channel("notifications");
66
- *
67
- * // Typed channel with schema
68
- * const orderChannel = communicator.channel<OrderPayload>("orders", {
69
- * schema: OrderSchema,
70
- * durable: true,
71
- * });
72
- * ```
73
- */
74
- channel<TPayload = unknown>(name: string, options?: ChannelOptions<TPayload>): ChannelContract<TPayload>;
75
- /**
76
- * Check if the communicator is connected
77
- */
78
- get isConnected(): boolean;
79
- /**
80
- * Connect the underlying driver
81
- */
82
- connect(): Promise<void>;
83
- /**
84
- * Disconnect the underlying driver
85
- */
86
- disconnect(): Promise<void>;
87
- /**
88
- * Start consuming messages
89
- */
90
- startConsuming(): Promise<void>;
91
- /**
92
- * Stop consuming messages
93
- */
94
- stopConsuming(): Promise<void>;
95
- /**
96
- * Health check
97
- */
98
- healthCheck(): Promise<import("../types").HealthCheckResult>;
99
- }
100
- //# sourceMappingURL=communicator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"communicator.d.ts","sourceRoot":"","sources":["../../src/communicators/communicator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc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AO,CAAC,IAAI,CAAC;IAI5C;;OAEG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3C;;OAEG;IACU,WAAW;CAGzB"}
@@ -1,105 +0,0 @@
1
- /**
2
- * Communicator - wrapper around a driver with metadata
3
- *
4
- * Similar to DataSource in @warlock.js/cascade
5
- *
6
- * @example
7
- * ```typescript
8
- * const communicator = new Communicator({
9
- * name: "default",
10
- * driver: rabbitMQDriver,
11
- * isDefault: true,
12
- * });
13
- *
14
- * // Get a channel
15
- * const channel = communicator.channel("user.created");
16
- * ```
17
- */
18
- class Communicator {
19
- /** Unique name identifying this communicator */
20
- name;
21
- /** The underlying driver */
22
- driver;
23
- /** Whether this is the default communicator */
24
- isDefault;
25
- /**
26
- * Create a new Communicator
27
- *
28
- * @param options - Communicator configuration
29
- */
30
- constructor(options) {
31
- this.name = options.name;
32
- this.driver = options.driver;
33
- this.isDefault = Boolean(options.isDefault);
34
- }
35
- /**
36
- * Subscribe the given consumer
37
- */
38
- subscribe(consumer) {
39
- return this.driver.subscribe(consumer);
40
- }
41
- /**
42
- * Publish the given event message
43
- */
44
- publish(event) {
45
- this.driver.publish(event);
46
- }
47
- /**
48
- * Get or create a channel
49
- *
50
- * @param name - Channel name
51
- * @param options - Channel options
52
- * @returns Channel instance
53
- *
54
- * @example
55
- * ```typescript
56
- * // Simple channel
57
- * const channel = communicator.channel("notifications");
58
- *
59
- * // Typed channel with schema
60
- * const orderChannel = communicator.channel<OrderPayload>("orders", {
61
- * schema: OrderSchema,
62
- * durable: true,
63
- * });
64
- * ```
65
- */
66
- channel(name, options) {
67
- return this.driver.channel(name, options);
68
- }
69
- /**
70
- * Check if the communicator is connected
71
- */
72
- get isConnected() {
73
- return this.driver.isConnected;
74
- }
75
- /**
76
- * Connect the underlying driver
77
- */
78
- async connect() {
79
- await this.driver.connect();
80
- }
81
- /**
82
- * Disconnect the underlying driver
83
- */
84
- async disconnect() {
85
- await this.driver.disconnect();
86
- }
87
- /**
88
- * Start consuming messages
89
- */
90
- async startConsuming() {
91
- await this.driver.startConsuming();
92
- }
93
- /**
94
- * Stop consuming messages
95
- */
96
- async stopConsuming() {
97
- await this.driver.stopConsuming();
98
- }
99
- /**
100
- * Health check
101
- */
102
- async healthCheck() {
103
- return this.driver.healthCheck();
104
- }
105
- }export{Communicator};//# sourceMappingURL=communicator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"communicator.js","sources":["../../src/communicators/communicator.ts"],"sourcesContent":[null],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;AAgBG;MACU,YAAY,CAAA;;AAEP,IAAA,IAAI,CAAS;;AAGb,IAAA,MAAM,CAA6B;;AAGnC,IAAA,SAAS,CAAU;AAEnC;;;;AAIG;AACH,IAAA,WAAA,CAAmB,OAA4B,EAAA;AAC7C,QAAA,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AACzB,QAAA,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;KAC7C;AAED;;AAEG;AACI,IAAA,SAAS,CAAC,QAAiC,EAAA;QAChD,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;KACxC;AAED;;AAEG;AACI,IAAA,OAAO,CAAiC,KAA6B,EAAA;AAC1E,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KAC5B;AAED;;;;;;;;;;;;;;;;;;AAkBG;IACI,OAAO,CACZ,IAAY,EACZ,OAAkC,EAAA;QAElC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAW,IAAI,EAAE,OAAO,CAAC,CAAC;KACrD;AAED;;AAEG;AACH,IAAA,IAAW,WAAW,GAAA;AACpB,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;KAChC;AAED;;AAEG;AACI,IAAA,MAAM,OAAO,GAAA;AAClB,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;KAC7B;AAED;;AAEG;AACI,IAAA,MAAM,UAAU,GAAA;AACrB,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;KAChC;AAED;;AAEG;AACI,IAAA,MAAM,cAAc,GAAA;AACzB,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;KACpC;AAED;;AAEG;AACI,IAAA,MAAM,aAAa,GAAA;AACxB,QAAA,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;KACnC;AAED;;AAEG;AACI,IAAA,MAAM,WAAW,GAAA;AACtB,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;KAClC;AACF"}
@@ -1,3 +0,0 @@
1
- export * from "./communicator";
2
- export * from "./communicator-registry";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/communicators/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC"}
@@ -1,186 +0,0 @@
1
- import type { ChannelOptions, ChannelStats, MessageHandler, PublishOptions, RequestOptions, ResponseHandler, SubscribeOptions, Subscription } from "../types";
2
- /**
3
- * Channel contract - represents a queue (RabbitMQ) or topic (Kafka)
4
- *
5
- * Provides a unified pub/sub interface across different message brokers.
6
- *
7
- * @template TPayload - The typed payload for messages on this channel
8
- *
9
- * @example
10
- * ```typescript
11
- * // Get a typed channel
12
- * const userChannel = communicators().channel<UserPayload>("user.created");
13
- *
14
- * // Publish
15
- * await userChannel.publish({ userId: 1, email: "test@example.com" });
16
- *
17
- * // Subscribe
18
- * userChannel.subscribe(async (message, ctx) => {
19
- * console.log(message.payload.userId);
20
- * await ctx.ack();
21
- * });
22
- * ```
23
- */
24
- export interface ChannelContract<TPayload = unknown> {
25
- /**
26
- * Channel name/routing key
27
- */
28
- readonly name: string;
29
- /**
30
- * Channel options
31
- */
32
- readonly options: ChannelOptions<TPayload>;
33
- /**
34
- * Publish a message to this channel
35
- *
36
- * @param payload - The message payload
37
- * @param options - Optional publish options
38
- *
39
- * @example
40
- * ```typescript
41
- * await channel.publish({ orderId: 123 });
42
- *
43
- * // With options
44
- * await channel.publish({ orderId: 123 }, {
45
- * priority: 5,
46
- * persistent: true,
47
- * correlationId: "req-123",
48
- * });
49
- * ```
50
- */
51
- publish(payload: TPayload, options?: PublishOptions): Promise<void>;
52
- /**
53
- * Publish multiple messages in a batch
54
- *
55
- * More efficient than publishing one by one.
56
- *
57
- * @param messages - Array of payloads to publish
58
- * @param options - Optional publish options (applied to all messages)
59
- *
60
- * @example
61
- * ```typescript
62
- * await channel.publishBatch([
63
- * { event: "page_view", page: "/home" },
64
- * { event: "page_view", page: "/products" },
65
- * ]);
66
- * ```
67
- */
68
- publishBatch(messages: TPayload[], options?: PublishOptions): Promise<void>;
69
- /**
70
- * Subscribe to messages on this channel
71
- *
72
- * @param handler - Function to handle incoming messages
73
- * @param options - Optional subscribe options
74
- * @returns Subscription object for managing the subscription
75
- *
76
- * @example
77
- * ```typescript
78
- * const subscription = await channel.subscribe(
79
- * async (message, ctx) => {
80
- * await processOrder(message.payload);
81
- * await ctx.ack();
82
- * },
83
- * {
84
- * prefetch: 10,
85
- * retry: { maxRetries: 3, delay: 1000 },
86
- * }
87
- * );
88
- *
89
- * // Later: unsubscribe
90
- * await subscription.unsubscribe();
91
- * ```
92
- */
93
- subscribe(handler: MessageHandler<TPayload>, options?: SubscribeOptions): Promise<Subscription>;
94
- /**
95
- * Unsubscribe a consumer by its ID
96
- *
97
- * @param consumerId - The consumer ID to unsubscribe
98
- *
99
- * @example
100
- * ```typescript
101
- * await channel.unsubscribeById("consumer-uuid");
102
- * ```
103
- */
104
- unsubscribeById(consumerId: string): Promise<void>;
105
- /**
106
- * Request-Response pattern (RPC)
107
- *
108
- * Publishes a message and waits for a response.
109
- *
110
- * @param payload - The request payload
111
- * @param options - Request options including timeout
112
- * @returns Promise resolving to the response
113
- *
114
- * @example
115
- * ```typescript
116
- * const result = await channel.request<ProcessResult>(
117
- * { imageUrl: "https://..." },
118
- * { timeout: 30000 }
119
- * );
120
- * console.log(result.processedUrl);
121
- * ```
122
- */
123
- request<TResponse = unknown>(payload: TPayload, options?: RequestOptions): Promise<TResponse>;
124
- /**
125
- * Register a response handler for RPC pattern
126
- *
127
- * The return value of the handler becomes the response.
128
- *
129
- * @param handler - Function to handle requests and return responses
130
- * @returns Subscription for managing the responder
131
- *
132
- * @example
133
- * ```typescript
134
- * channel.respond(async (message, ctx) => {
135
- * const result = await processImage(message.payload);
136
- * return { processedUrl: result.url };
137
- * });
138
- * ```
139
- */
140
- respond<TResponse = unknown>(handler: ResponseHandler<TPayload, TResponse>): Promise<Subscription>;
141
- /**
142
- * Get channel statistics
143
- *
144
- * @returns Channel stats including message count and consumer count
145
- *
146
- * @example
147
- * ```typescript
148
- * const stats = await channel.stats();
149
- * console.log(`Messages: ${stats.messageCount}, Consumers: ${stats.consumerCount}`);
150
- * ```
151
- */
152
- stats(): Promise<ChannelStats>;
153
- /**
154
- * Purge all messages from the channel
155
- *
156
- * Use with caution - this deletes all pending messages.
157
- *
158
- * @returns Number of messages purged
159
- *
160
- * @example
161
- * ```typescript
162
- * const purgedCount = await channel.purge();
163
- * console.log(`Purged ${purgedCount} messages`);
164
- * ```
165
- */
166
- purge(): Promise<number>;
167
- /**
168
- * Check if the channel exists
169
- *
170
- * @returns True if the channel exists on the broker
171
- */
172
- exists(): Promise<boolean>;
173
- /**
174
- * Delete the channel
175
- *
176
- * Use with caution - this removes the queue/topic entirely.
177
- */
178
- delete(): Promise<void>;
179
- /**
180
- * Assert/create the channel with its options
181
- *
182
- * Creates the channel if it doesn't exist, or verifies options match.
183
- */
184
- assert(): Promise<void>;
185
- }
186
- //# sourceMappingURL=channel.contract.d.ts.map
@@ -1 +0,0 @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AAS,CAAC,GAC5C,OAAO,CAAC,YAAY,CAAC,CAAC;IAEzB;;;;;;;;;;OAUG;IACH,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IAE/B;;;;;;;;;;;;OAYG;IACH,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzB;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3B;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB"}
@@ -1,196 +0,0 @@
1
- import { type EventMessage } from "../message-managers/event-message";
2
- import { EventConsumerClass } from "../message-managers/types";
3
- import type { ChannelOptions, CommunicatorDriverType, CommunicatorEvent, CommunicatorEventListener, HealthCheckResult } from "../types";
4
- import type { ChannelContract } from "./channel.contract";
5
- /**
6
- * Communicator Driver Contract
7
- *
8
- * Base contract for all message bus drivers (RabbitMQ, Kafka, etc.)
9
- * Similar to DriverContract in @warlock.js/cascade
10
- *
11
- * @example
12
- * ```typescript
13
- * // Driver implementation
14
- * class RabbitMQDriver implements CommunicatorDriverContract {
15
- * readonly name = "rabbitmq";
16
- * // ...
17
- * }
18
- * ```
19
- */
20
- export interface CommunicatorDriverContract {
21
- /**
22
- * Driver name identifier
23
- *
24
- * @example "rabbitmq", "kafka", "redis-streams"
25
- */
26
- readonly name: CommunicatorDriverType;
27
- /**
28
- * Whether currently connected to the message broker
29
- */
30
- readonly isConnected: boolean;
31
- /**
32
- * Establish connection to the message broker
33
- *
34
- * @throws Error if connection fails
35
- *
36
- * @example
37
- * ```typescript
38
- * await driver.connect();
39
- * console.log("Connected to RabbitMQ");
40
- * ```
41
- */
42
- connect(): Promise<void>;
43
- /**
44
- * Close connection gracefully
45
- *
46
- * Ensures all pending operations complete before disconnecting.
47
- *
48
- * @example
49
- * ```typescript
50
- * await driver.disconnect();
51
- * ```
52
- */
53
- disconnect(): Promise<void>;
54
- /**
55
- * Register event listeners for driver lifecycle events
56
- *
57
- * @param event - Event name to listen for
58
- * @param listener - Callback function
59
- *
60
- * @example
61
- * ```typescript
62
- * driver.on("connected", () => {
63
- * console.log("Connected to broker");
64
- * });
65
- *
66
- * driver.on("disconnected", () => {
67
- * console.log("Disconnected from broker");
68
- * });
69
- *
70
- * driver.on("error", (error) => {
71
- * console.error("Driver error:", error);
72
- * });
73
- *
74
- * driver.on("reconnecting", (attempt) => {
75
- * console.log(`Reconnection attempt ${attempt}`);
76
- * });
77
- * ```
78
- */
79
- on(event: CommunicatorEvent, listener: CommunicatorEventListener): void;
80
- /**
81
- * Remove an event listener
82
- *
83
- * @param event - Event name
84
- * @param listener - Callback to remove
85
- */
86
- off(event: CommunicatorEvent, listener: CommunicatorEventListener): void;
87
- /**
88
- * Subscribe the given consumer class to the driver
89
- *
90
- * @param consumer - Consumer class to subscribe
91
- * @returns Unsubscribe function
92
- * @example
93
- * ```typescript
94
- * driver.subscribe(UserUpdatedConsumer);
95
- * ```
96
- */
97
- subscribe(consumer: EventConsumerClass): () => void;
98
- /**
99
- * Unsubscribe the given consumer class from the driver
100
- *
101
- * @param consumer - Consumer class to unsubscribe
102
- *
103
- * @example
104
- * ```typescript
105
- * driver.unsubscribe(UserUpdatedConsumer);
106
- * ```
107
- */
108
- unsubscribe(consumer: EventConsumerClass): void;
109
- /**
110
- * Publish the given event message
111
- */
112
- publish<TPayload = Record<string, any>>(event: EventMessage<TPayload>): void;
113
- /**
114
- * Get or create a channel
115
- *
116
- * Channels are lazy-created and cached for reuse.
117
- *
118
- * @param name - Channel/queue/topic name
119
- * @param options - Channel configuration
120
- * @returns Channel instance
121
- *
122
- * @example
123
- * ```typescript
124
- * // Simple channel
125
- * const channel = driver.channel("user.created");
126
- *
127
- * // With options
128
- * const orderChannel = driver.channel("orders", {
129
- * durable: true,
130
- * deadLetter: { channel: "orders.failed" },
131
- * });
132
- *
133
- * // Typed channel
134
- * const typedChannel = driver.channel<OrderPayload>("orders", {
135
- * schema: OrderSchema,
136
- * });
137
- * ```
138
- */
139
- channel<TPayload = unknown>(name: string, options?: ChannelOptions<TPayload>): ChannelContract<TPayload>;
140
- /**
141
- * Start consuming messages from all subscribed channels
142
- *
143
- * Call this after setting up all subscriptions to begin processing.
144
- *
145
- * @example
146
- * ```typescript
147
- * // Set up subscriptions
148
- * channel1.subscribe(handler1);
149
- * channel2.subscribe(handler2);
150
- *
151
- * // Start consuming
152
- * await driver.startConsuming();
153
- * ```
154
- */
155
- startConsuming(): Promise<void>;
156
- /**
157
- * Stop consuming messages gracefully
158
- *
159
- * Waits for currently processing messages to complete.
160
- *
161
- * @example
162
- * ```typescript
163
- * await driver.stopConsuming();
164
- * ```
165
- */
166
- stopConsuming(): Promise<void>;
167
- /**
168
- * Perform a health check on the connection
169
- *
170
- * @returns Health check result with status and optional latency
171
- *
172
- * @example
173
- * ```typescript
174
- * const health = await driver.healthCheck();
175
- * if (health.healthy) {
176
- * console.log(`Healthy, latency: ${health.latency}ms`);
177
- * } else {
178
- * console.error(`Unhealthy: ${health.error}`);
179
- * }
180
- * ```
181
- */
182
- healthCheck(): Promise<HealthCheckResult>;
183
- /**
184
- * Get list of all channels managed by this driver
185
- *
186
- * @returns Array of channel names
187
- */
188
- getChannelNames(): string[];
189
- /**
190
- * Close and remove a specific channel
191
- *
192
- * @param name - Channel name to close
193
- */
194
- closeChannel(name: string): Promise<void>;
195
- }
196
- //# sourceMappingURL=communicator-driver.contract.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"communicator-driver.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/communicator-driver.contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,iBAAiB,EACjB,yBAAyB,EACzB,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,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/B;;;;;;;;;;;;;;OAcG;IACH,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE1C;;;;OAIG;IACH,eAAe,IAAI,MAAM,EAAE,CAAC;IAE5B;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C"}
@@ -1,3 +0,0 @@
1
- export * from "./channel.contract";
2
- export * from "./communicator-driver.contract";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC"}
@@ -1,13 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,33 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,2 +0,0 @@
1
- export * from "./consumable";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}