@warlock.js/herald 4.0.100

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 (82) hide show
  1. package/README.md +364 -0
  2. package/cjs/communicators/communicator-registry.d.ts +155 -0
  3. package/cjs/communicators/communicator-registry.d.ts.map +1 -0
  4. package/cjs/communicators/communicator-registry.js +206 -0
  5. package/cjs/communicators/communicator-registry.js.map +1 -0
  6. package/cjs/communicators/communicator.d.ts +90 -0
  7. package/cjs/communicators/communicator.d.ts.map +1 -0
  8. package/cjs/communicators/communicator.js +93 -0
  9. package/cjs/communicators/communicator.js.map +1 -0
  10. package/cjs/communicators/index.d.ts +3 -0
  11. package/cjs/communicators/index.d.ts.map +1 -0
  12. package/cjs/contracts/channel.contract.d.ts +175 -0
  13. package/cjs/contracts/channel.contract.d.ts.map +1 -0
  14. package/cjs/contracts/communicator-driver.contract.d.ts +168 -0
  15. package/cjs/contracts/communicator-driver.contract.d.ts.map +1 -0
  16. package/cjs/contracts/index.d.ts +3 -0
  17. package/cjs/contracts/index.d.ts.map +1 -0
  18. package/cjs/drivers/index.d.ts +2 -0
  19. package/cjs/drivers/index.d.ts.map +1 -0
  20. package/cjs/drivers/rabbitmq/index.d.ts +3 -0
  21. package/cjs/drivers/rabbitmq/index.d.ts.map +1 -0
  22. package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts +70 -0
  23. package/cjs/drivers/rabbitmq/rabbitmq-channel.d.ts.map +1 -0
  24. package/cjs/drivers/rabbitmq/rabbitmq-channel.js +400 -0
  25. package/cjs/drivers/rabbitmq/rabbitmq-channel.js.map +1 -0
  26. package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts +100 -0
  27. package/cjs/drivers/rabbitmq/rabbitmq-driver.d.ts.map +1 -0
  28. package/cjs/drivers/rabbitmq/rabbitmq-driver.js +299 -0
  29. package/cjs/drivers/rabbitmq/rabbitmq-driver.js.map +1 -0
  30. package/cjs/index.d.ts +45 -0
  31. package/cjs/index.d.ts.map +1 -0
  32. package/cjs/index.js +1 -0
  33. package/cjs/index.js.map +1 -0
  34. package/cjs/types.d.ts +396 -0
  35. package/cjs/types.d.ts.map +1 -0
  36. package/cjs/utils/connect-to-communicator.d.ts +86 -0
  37. package/cjs/utils/connect-to-communicator.d.ts.map +1 -0
  38. package/cjs/utils/connect-to-communicator.js +122 -0
  39. package/cjs/utils/connect-to-communicator.js.map +1 -0
  40. package/cjs/utils/index.d.ts +2 -0
  41. package/cjs/utils/index.d.ts.map +1 -0
  42. package/esm/communicators/communicator-registry.d.ts +155 -0
  43. package/esm/communicators/communicator-registry.d.ts.map +1 -0
  44. package/esm/communicators/communicator-registry.js +206 -0
  45. package/esm/communicators/communicator-registry.js.map +1 -0
  46. package/esm/communicators/communicator.d.ts +90 -0
  47. package/esm/communicators/communicator.d.ts.map +1 -0
  48. package/esm/communicators/communicator.js +93 -0
  49. package/esm/communicators/communicator.js.map +1 -0
  50. package/esm/communicators/index.d.ts +3 -0
  51. package/esm/communicators/index.d.ts.map +1 -0
  52. package/esm/contracts/channel.contract.d.ts +175 -0
  53. package/esm/contracts/channel.contract.d.ts.map +1 -0
  54. package/esm/contracts/communicator-driver.contract.d.ts +168 -0
  55. package/esm/contracts/communicator-driver.contract.d.ts.map +1 -0
  56. package/esm/contracts/index.d.ts +3 -0
  57. package/esm/contracts/index.d.ts.map +1 -0
  58. package/esm/drivers/index.d.ts +2 -0
  59. package/esm/drivers/index.d.ts.map +1 -0
  60. package/esm/drivers/rabbitmq/index.d.ts +3 -0
  61. package/esm/drivers/rabbitmq/index.d.ts.map +1 -0
  62. package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts +70 -0
  63. package/esm/drivers/rabbitmq/rabbitmq-channel.d.ts.map +1 -0
  64. package/esm/drivers/rabbitmq/rabbitmq-channel.js +400 -0
  65. package/esm/drivers/rabbitmq/rabbitmq-channel.js.map +1 -0
  66. package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts +100 -0
  67. package/esm/drivers/rabbitmq/rabbitmq-driver.d.ts.map +1 -0
  68. package/esm/drivers/rabbitmq/rabbitmq-driver.js +299 -0
  69. package/esm/drivers/rabbitmq/rabbitmq-driver.js.map +1 -0
  70. package/esm/index.d.ts +45 -0
  71. package/esm/index.d.ts.map +1 -0
  72. package/esm/index.js +1 -0
  73. package/esm/index.js.map +1 -0
  74. package/esm/types.d.ts +396 -0
  75. package/esm/types.d.ts.map +1 -0
  76. package/esm/utils/connect-to-communicator.d.ts +86 -0
  77. package/esm/utils/connect-to-communicator.d.ts.map +1 -0
  78. package/esm/utils/connect-to-communicator.js +122 -0
  79. package/esm/utils/connect-to-communicator.js.map +1 -0
  80. package/esm/utils/index.d.ts +2 -0
  81. package/esm/utils/index.d.ts.map +1 -0
  82. package/package.json +47 -0
@@ -0,0 +1,206 @@
1
+ 'use strict';var node_events=require('node:events'),communicator=require('./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 node_events.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$1 = new communicator.Communicator(options);
62
+ this.sources.set(communicator$1.name, communicator$1);
63
+ const isNewDefault = communicator$1.isDefault || !this.defaultSource;
64
+ if (isNewDefault) {
65
+ this.defaultSource = communicator$1;
66
+ }
67
+ // Emit registration events
68
+ this.events.emit("registered", communicator$1);
69
+ if (isNewDefault) {
70
+ this.events.emit("default-registered", communicator$1);
71
+ }
72
+ // Forward driver events to registry
73
+ communicator$1.driver.on("connected", () => {
74
+ this.events.emit("connected", communicator$1);
75
+ });
76
+ communicator$1.driver.on("disconnected", () => {
77
+ this.events.emit("disconnected", communicator$1);
78
+ });
79
+ return communicator$1;
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();exports.MissingCommunicatorError=MissingCommunicatorError;exports.communicatorRegistry=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":["EventEmitter","communicator","Communicator"],"mappings":"8FAIA;;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,IAAIA,wBAAY,EAAE,CAAC;AAE7C;;;;;;;;;;;;;;;;AAgBG;AACI,IAAA,QAAQ,CAAC,OAA4B,EAAA;AAC1C,QAAA,MAAMC,cAAY,GAAG,IAAIC,yBAAY,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD,cAAY,CAAC,IAAI,EAAEA,cAAY,CAAC,CAAC;QAElD,MAAM,YAAY,GAAGA,cAAY,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;AAEnE,QAAA,IAAI,YAAY,EAAE;AAChB,YAAA,IAAI,CAAC,aAAa,GAAGA,cAAY,CAAC;AACnC,SAAA;;QAGD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAEA,cAAY,CAAC,CAAC;AAE7C,QAAA,IAAI,YAAY,EAAE;YAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAEA,cAAY,CAAC,CAAC;AACtD,SAAA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;AACvF,aAAA;AACD,YAAA,OAAO,MAAM,CAAC;AACf,SAAA;AAED,QAAA,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;AACvB,YAAA,MAAM,IAAI,wBAAwB,CAAC,qCAAqC,CAAC,CAAC;AAC3E,SAAA;QAED,OAAO,IAAI,CAAC,aAAa,CAAC;KAC3B;AAED;;;;;AAKG;AACI,IAAA,GAAG,CAAC,IAAY,EAAA;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;KAC/B;AAED;;AAEG;IACI,MAAM,GAAA;AACX,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;KAC9B;AAED;;;;;;;;;;;;AAYG;IACI,MAAM,GAAA;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;KAC1C;AAED;;;;AAIG;IACI,QAAQ,GAAA;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACxC;AAED;;;;AAIG;IACI,UAAU,GAAA;QACf,OAAO,IAAI,CAAC,aAAa,CAAC;KAC3B;AACF,CAAA;AAED;;AAEG;AACU,MAAA,oBAAoB,GAAG,IAAI,oBAAoB"}
@@ -0,0 +1,90 @@
1
+ import type { CommunicatorDriverContract } from "../contracts";
2
+ import type { ChannelOptions } from "../types";
3
+ import type { ChannelContract } from "../contracts/channel.contract";
4
+ /**
5
+ * Options for creating a Communicator
6
+ */
7
+ export interface CommunicatorOptions {
8
+ /** Unique name for this communicator */
9
+ name: string;
10
+ /** The underlying driver */
11
+ driver: CommunicatorDriverContract;
12
+ /** Whether this is the default communicator */
13
+ isDefault?: boolean;
14
+ }
15
+ /**
16
+ * Communicator - wrapper around a driver with metadata
17
+ *
18
+ * Similar to DataSource in @warlock.js/cascade
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const communicator = new Communicator({
23
+ * name: "default",
24
+ * driver: rabbitMQDriver,
25
+ * isDefault: true,
26
+ * });
27
+ *
28
+ * // Get a channel
29
+ * const channel = communicator.channel("user.created");
30
+ * ```
31
+ */
32
+ export declare class Communicator {
33
+ /** Unique name identifying this communicator */
34
+ readonly name: string;
35
+ /** The underlying driver */
36
+ readonly driver: CommunicatorDriverContract;
37
+ /** Whether this is the default communicator */
38
+ readonly isDefault: boolean;
39
+ /**
40
+ * Create a new Communicator
41
+ *
42
+ * @param options - Communicator configuration
43
+ */
44
+ constructor(options: CommunicatorOptions);
45
+ /**
46
+ * Get or create a channel
47
+ *
48
+ * @param name - Channel name
49
+ * @param options - Channel options
50
+ * @returns Channel instance
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // Simple channel
55
+ * const channel = communicator.channel("notifications");
56
+ *
57
+ * // Typed channel with schema
58
+ * const orderChannel = communicator.channel<OrderPayload>("orders", {
59
+ * schema: OrderSchema,
60
+ * durable: true,
61
+ * });
62
+ * ```
63
+ */
64
+ channel<TPayload = unknown>(name: string, options?: ChannelOptions<TPayload>): ChannelContract<TPayload>;
65
+ /**
66
+ * Check if the communicator is connected
67
+ */
68
+ get isConnected(): boolean;
69
+ /**
70
+ * Connect the underlying driver
71
+ */
72
+ connect(): Promise<void>;
73
+ /**
74
+ * Disconnect the underlying driver
75
+ */
76
+ disconnect(): Promise<void>;
77
+ /**
78
+ * Start consuming messages
79
+ */
80
+ startConsuming(): Promise<void>;
81
+ /**
82
+ * Stop consuming messages
83
+ */
84
+ stopConsuming(): Promise<void>;
85
+ /**
86
+ * Health check
87
+ */
88
+ healthCheck(): Promise<import("../types").HealthCheckResult>;
89
+ }
90
+ //# sourceMappingURL=communicator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"communicator.d.ts","sourceRoot":"","sources":["../../src/communicators/communicator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,MAAM,EAAE,0BAA0B,CAAC;IACnC,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAY;IACvB,gDAAgD;IAChD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,4BAA4B;IAC5B,SAAgB,MAAM,EAAE,0BAA0B,CAAC;IAEnD,+CAA+C;IAC/C,SAAgB,SAAS,EAAE,OAAO,CAAC;IAEnC;;;;OAIG;gBACgB,OAAO,EAAE,mBAAmB;IAM/C;;;;;;;;;;;;;;;;;;OAkBG;IACI,OAAO,CAAC,QAAQ,GAAG,OAAO,EAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,GACjC,eAAe,CAAC,QAAQ,CAAC;IAI5B;;OAEG;IACH,IAAW,WAAW,IAAI,OAAO,CAEhC;IAED;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C;;OAEG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3C;;OAEG;IACU,WAAW;CAGzB"}
@@ -0,0 +1,93 @@
1
+ 'use strict';/**
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
+ * Get or create a channel
37
+ *
38
+ * @param name - Channel name
39
+ * @param options - Channel options
40
+ * @returns Channel instance
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // Simple channel
45
+ * const channel = communicator.channel("notifications");
46
+ *
47
+ * // Typed channel with schema
48
+ * const orderChannel = communicator.channel<OrderPayload>("orders", {
49
+ * schema: OrderSchema,
50
+ * durable: true,
51
+ * });
52
+ * ```
53
+ */
54
+ channel(name, options) {
55
+ return this.driver.channel(name, options);
56
+ }
57
+ /**
58
+ * Check if the communicator is connected
59
+ */
60
+ get isConnected() {
61
+ return this.driver.isConnected;
62
+ }
63
+ /**
64
+ * Connect the underlying driver
65
+ */
66
+ async connect() {
67
+ await this.driver.connect();
68
+ }
69
+ /**
70
+ * Disconnect the underlying driver
71
+ */
72
+ async disconnect() {
73
+ await this.driver.disconnect();
74
+ }
75
+ /**
76
+ * Start consuming messages
77
+ */
78
+ async startConsuming() {
79
+ await this.driver.startConsuming();
80
+ }
81
+ /**
82
+ * Stop consuming messages
83
+ */
84
+ async stopConsuming() {
85
+ await this.driver.stopConsuming();
86
+ }
87
+ /**
88
+ * Health check
89
+ */
90
+ async healthCheck() {
91
+ return this.driver.healthCheck();
92
+ }
93
+ }exports.Communicator=Communicator;//# sourceMappingURL=communicator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"communicator.js","sources":["../../src/communicators/communicator.ts"],"sourcesContent":[null],"names":[],"mappings":"aAgBA;;;;;;;;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 //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/communicators/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,175 @@
1
+ import type { ChannelOptions, ChannelStats, MessageHandler, PublishOptions, RequestOptions, ResponseHandler, Subscription, SubscribeOptions } 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
+ * Request-Response pattern (RPC)
96
+ *
97
+ * Publishes a message and waits for a response.
98
+ *
99
+ * @param payload - The request payload
100
+ * @param options - Request options including timeout
101
+ * @returns Promise resolving to the response
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const result = await channel.request<ProcessResult>(
106
+ * { imageUrl: "https://..." },
107
+ * { timeout: 30000 }
108
+ * );
109
+ * console.log(result.processedUrl);
110
+ * ```
111
+ */
112
+ request<TResponse = unknown>(payload: TPayload, options?: RequestOptions): Promise<TResponse>;
113
+ /**
114
+ * Register a response handler for RPC pattern
115
+ *
116
+ * The return value of the handler becomes the response.
117
+ *
118
+ * @param handler - Function to handle requests and return responses
119
+ * @returns Subscription for managing the responder
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * channel.respond(async (message, ctx) => {
124
+ * const result = await processImage(message.payload);
125
+ * return { processedUrl: result.url };
126
+ * });
127
+ * ```
128
+ */
129
+ respond<TResponse = unknown>(handler: ResponseHandler<TPayload, TResponse>): Promise<Subscription>;
130
+ /**
131
+ * Get channel statistics
132
+ *
133
+ * @returns Channel stats including message count and consumer count
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const stats = await channel.stats();
138
+ * console.log(`Messages: ${stats.messageCount}, Consumers: ${stats.consumerCount}`);
139
+ * ```
140
+ */
141
+ stats(): Promise<ChannelStats>;
142
+ /**
143
+ * Purge all messages from the channel
144
+ *
145
+ * Use with caution - this deletes all pending messages.
146
+ *
147
+ * @returns Number of messages purged
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const purgedCount = await channel.purge();
152
+ * console.log(`Purged ${purgedCount} messages`);
153
+ * ```
154
+ */
155
+ purge(): Promise<number>;
156
+ /**
157
+ * Check if the channel exists
158
+ *
159
+ * @returns True if the channel exists on the broker
160
+ */
161
+ exists(): Promise<boolean>;
162
+ /**
163
+ * Delete the channel
164
+ *
165
+ * Use with caution - this removes the queue/topic entirely.
166
+ */
167
+ delete(): Promise<void>;
168
+ /**
169
+ * Assert/create the channel with its options
170
+ *
171
+ * Creates the channel if it doesn't exist, or verifies options match.
172
+ */
173
+ assert(): Promise<void>;
174
+ }
175
+ //# sourceMappingURL=channel.contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.contract.d.ts","sourceRoot":"","sources":["../../src/contracts/channel.contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EAEZ,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,EACf,YAAY,EACZ,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,eAAe,CAAC,QAAQ,GAAG,OAAO;IACjD;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAE3C;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,c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