@avtechno/sfr 1.0.12 → 1.0.14
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/dist/mq.mjs +16 -16
- package/dist/sfr-pipeline.mjs +8 -4
- package/dist/types/mq.d.mts +11 -11
- package/package.json +1 -1
- package/src/mq.mts +16 -16
- package/src/sfr-pipeline.mts +9 -4
package/dist/mq.mjs
CHANGED
|
@@ -45,22 +45,6 @@ export class BaseMQ {
|
|
|
45
45
|
this.channel = channel;
|
|
46
46
|
this.type = type;
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Sends a reply to the message sender in a Request-Reply pattern.
|
|
50
|
-
*
|
|
51
|
-
* @param msg - The original message to reply to.
|
|
52
|
-
* @param payload - The reply message to send back to the requester.
|
|
53
|
-
* @example
|
|
54
|
-
* // Send a response back to the client in a Request-Reply pattern
|
|
55
|
-
* const mq = new TargetedMQ(channel, "Request-Reply");
|
|
56
|
-
* mq.reply(msg, { result: "Processed successfully" });
|
|
57
|
-
*/
|
|
58
|
-
async reply(msg, payload) {
|
|
59
|
-
if (this.type !== "Request-Reply")
|
|
60
|
-
return;
|
|
61
|
-
this.channel.sendToQueue(msg.properties.replyTo, encode_payload(payload), { correlationId: msg.properties.correlationId });
|
|
62
|
-
this.channel.ack(msg);
|
|
63
|
-
}
|
|
64
48
|
}
|
|
65
49
|
/**
|
|
66
50
|
* BroadcastMQ class to handle different types of broadcast communication patterns: Fanout, Direct, and Topic.
|
|
@@ -212,6 +196,22 @@ export class TargetedMQ extends BaseMQ {
|
|
|
212
196
|
}
|
|
213
197
|
}
|
|
214
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Sends a reply to the message sender in a Request-Reply pattern.
|
|
201
|
+
*
|
|
202
|
+
* @param msg - The original message to reply to.
|
|
203
|
+
* @param payload - The reply message to send back to the requester.
|
|
204
|
+
* @example
|
|
205
|
+
* // Send a response back to the client in a Request-Reply pattern
|
|
206
|
+
* const mq = new TargetedMQ(channel, "Request-Reply");
|
|
207
|
+
* mq.reply(msg, { result: "Processed successfully" });
|
|
208
|
+
*/
|
|
209
|
+
async reply(msg, payload) {
|
|
210
|
+
if (this.type !== "Request-Reply")
|
|
211
|
+
return;
|
|
212
|
+
this.channel.sendToQueue(msg.properties.replyTo, encode_payload(payload), { correlationId: msg.properties.correlationId });
|
|
213
|
+
this.channel.ack(msg);
|
|
214
|
+
}
|
|
215
215
|
set_options(options) {
|
|
216
216
|
this.queue_options = options;
|
|
217
217
|
}
|
package/dist/sfr-pipeline.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { logger } from "./logger.mjs";
|
|
|
7
7
|
const CWD = process.cwd();
|
|
8
8
|
const PATTERNS = ["Point-to-Point", "Request-Reply", "Fanout", "Direct", "Topic"];
|
|
9
9
|
const TARGETED_PATTERN = ["Point-to-Point", "Request-Reply"];
|
|
10
|
+
const DEBUG_FLAG = Boolean(process.env.DEBUG_SFR);
|
|
10
11
|
export class SFRPipeline {
|
|
11
12
|
cfg;
|
|
12
13
|
oas_cfg;
|
|
@@ -58,7 +59,8 @@ export class SFRPipeline {
|
|
|
58
59
|
/* @ts-ignore */
|
|
59
60
|
protocols = Object.fromEntries(Object.entries(protocols).filter(([k]) => this.comms[k]).map(([k, v]) => [k, v]));
|
|
60
61
|
await this.fn_binding(protocols);
|
|
61
|
-
|
|
62
|
+
if (DEBUG_FLAG)
|
|
63
|
+
this.print_to_console();
|
|
62
64
|
return this.spec_generation(protocols);
|
|
63
65
|
}
|
|
64
66
|
// Handles the parsing of SFR files from the directory specified under cfg.out config.
|
|
@@ -82,11 +84,13 @@ export class SFRPipeline {
|
|
|
82
84
|
//Import SFRs
|
|
83
85
|
const protocols = await Promise.all(sfr_paths.map((protocol) => import_sfrs(protocol)));
|
|
84
86
|
const REST = protocols[0];
|
|
85
|
-
logger.info(`${Object.keys(protocols[0]).length} REST SFR`);
|
|
86
87
|
const WS = protocols[1];
|
|
87
|
-
logger.info(`${Object.keys(protocols[1]).length} WS SFR`);
|
|
88
88
|
const MQ = protocols[2];
|
|
89
|
-
|
|
89
|
+
if (DEBUG_FLAG) {
|
|
90
|
+
logger.info(`${Object.keys(protocols[0]).length} REST SFR`);
|
|
91
|
+
logger.info(`${Object.keys(protocols[1]).length} WS SFR`);
|
|
92
|
+
logger.info(`${Object.keys(protocols[2]).length} MQ SFR`);
|
|
93
|
+
}
|
|
90
94
|
return { REST, WS, MQ };
|
|
91
95
|
}
|
|
92
96
|
// Handles the binding of the components of each SFR (e.g: executing validators of matching endpoints, injecting controllers to each handler, etc.)
|
package/dist/types/mq.d.mts
CHANGED
|
@@ -31,17 +31,6 @@ export declare class BaseMQ {
|
|
|
31
31
|
channel: Channel;
|
|
32
32
|
protected type: CommunicationPattern;
|
|
33
33
|
constructor(channel: Channel, type: CommunicationPattern);
|
|
34
|
-
/**
|
|
35
|
-
* Sends a reply to the message sender in a Request-Reply pattern.
|
|
36
|
-
*
|
|
37
|
-
* @param msg - The original message to reply to.
|
|
38
|
-
* @param payload - The reply message to send back to the requester.
|
|
39
|
-
* @example
|
|
40
|
-
* // Send a response back to the client in a Request-Reply pattern
|
|
41
|
-
* const mq = new TargetedMQ(channel, "Request-Reply");
|
|
42
|
-
* mq.reply(msg, { result: "Processed successfully" });
|
|
43
|
-
*/
|
|
44
|
-
reply(msg: ConsumeMessage, payload: any): Promise<void>;
|
|
45
34
|
}
|
|
46
35
|
/**
|
|
47
36
|
* BroadcastMQ class to handle different types of broadcast communication patterns: Fanout, Direct, and Topic.
|
|
@@ -110,5 +99,16 @@ export declare class TargetedMQ extends BaseMQ {
|
|
|
110
99
|
* mq.consume("taskQueue", { fn: processTask, options: { noAck: true } });
|
|
111
100
|
*/
|
|
112
101
|
consume(queue: string, cfg: ConsumerConfig): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Sends a reply to the message sender in a Request-Reply pattern.
|
|
104
|
+
*
|
|
105
|
+
* @param msg - The original message to reply to.
|
|
106
|
+
* @param payload - The reply message to send back to the requester.
|
|
107
|
+
* @example
|
|
108
|
+
* // Send a response back to the client in a Request-Reply pattern
|
|
109
|
+
* const mq = new TargetedMQ(channel, "Request-Reply");
|
|
110
|
+
* mq.reply(msg, { result: "Processed successfully" });
|
|
111
|
+
*/
|
|
112
|
+
reply(msg: ConsumeMessage, payload: any): Promise<void>;
|
|
113
113
|
set_options(options: Options.AssertQueue): void;
|
|
114
114
|
}
|
package/package.json
CHANGED
package/src/mq.mts
CHANGED
|
@@ -45,22 +45,7 @@ export class MQLib {
|
|
|
45
45
|
|
|
46
46
|
export class BaseMQ{
|
|
47
47
|
constructor(public channel: Channel, protected type: CommunicationPattern) {}
|
|
48
|
-
/**
|
|
49
|
-
* Sends a reply to the message sender in a Request-Reply pattern.
|
|
50
|
-
*
|
|
51
|
-
* @param msg - The original message to reply to.
|
|
52
|
-
* @param payload - The reply message to send back to the requester.
|
|
53
|
-
* @example
|
|
54
|
-
* // Send a response back to the client in a Request-Reply pattern
|
|
55
|
-
* const mq = new TargetedMQ(channel, "Request-Reply");
|
|
56
|
-
* mq.reply(msg, { result: "Processed successfully" });
|
|
57
|
-
*/
|
|
58
|
-
async reply(msg: ConsumeMessage, payload: any) {
|
|
59
|
-
if (this.type !== "Request-Reply") return;
|
|
60
48
|
|
|
61
|
-
this.channel.sendToQueue(msg.properties.replyTo, encode_payload(payload), {correlationId : msg.properties.correlationId});
|
|
62
|
-
this.channel.ack(msg);
|
|
63
|
-
}
|
|
64
49
|
}
|
|
65
50
|
|
|
66
51
|
/**
|
|
@@ -221,7 +206,22 @@ export class TargetedMQ extends BaseMQ{
|
|
|
221
206
|
}
|
|
222
207
|
}
|
|
223
208
|
|
|
224
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Sends a reply to the message sender in a Request-Reply pattern.
|
|
211
|
+
*
|
|
212
|
+
* @param msg - The original message to reply to.
|
|
213
|
+
* @param payload - The reply message to send back to the requester.
|
|
214
|
+
* @example
|
|
215
|
+
* // Send a response back to the client in a Request-Reply pattern
|
|
216
|
+
* const mq = new TargetedMQ(channel, "Request-Reply");
|
|
217
|
+
* mq.reply(msg, { result: "Processed successfully" });
|
|
218
|
+
*/
|
|
219
|
+
async reply(msg: ConsumeMessage, payload: any) {
|
|
220
|
+
if (this.type !== "Request-Reply") return;
|
|
221
|
+
|
|
222
|
+
this.channel.sendToQueue(msg.properties.replyTo, encode_payload(payload), {correlationId : msg.properties.correlationId});
|
|
223
|
+
this.channel.ack(msg);
|
|
224
|
+
}
|
|
225
225
|
set_options(options : Options.AssertQueue){
|
|
226
226
|
this.queue_options = options;
|
|
227
227
|
}
|
package/src/sfr-pipeline.mts
CHANGED
|
@@ -11,6 +11,8 @@ const CWD = process.cwd();
|
|
|
11
11
|
const PATTERNS: CommunicationPattern[] = ["Point-to-Point", "Request-Reply", "Fanout", "Direct", "Topic"];
|
|
12
12
|
const TARGETED_PATTERN = ["Point-to-Point", "Request-Reply"];
|
|
13
13
|
|
|
14
|
+
const DEBUG_FLAG = Boolean(process.env.DEBUG_SFR);
|
|
15
|
+
|
|
14
16
|
export class SFRPipeline {
|
|
15
17
|
base_url: string;
|
|
16
18
|
pattern_channels: PatternMQSet;
|
|
@@ -66,7 +68,7 @@ export class SFRPipeline {
|
|
|
66
68
|
protocols = Object.fromEntries(Object.entries(protocols).filter(([k])=> this.comms[k]).map(([k, v])=> [k, v]));
|
|
67
69
|
await this.fn_binding(protocols);
|
|
68
70
|
|
|
69
|
-
this.print_to_console();
|
|
71
|
+
if(DEBUG_FLAG)this.print_to_console();
|
|
70
72
|
|
|
71
73
|
return this.spec_generation(protocols);
|
|
72
74
|
}
|
|
@@ -93,11 +95,14 @@ export class SFRPipeline {
|
|
|
93
95
|
//Import SFRs
|
|
94
96
|
const protocols = await Promise.all(sfr_paths.map((protocol) => import_sfrs(protocol)));
|
|
95
97
|
const REST: RESTNamespaceDeclaration = protocols[0];
|
|
96
|
-
logger.info(`${Object.keys(protocols[0]).length} REST SFR`)
|
|
97
98
|
const WS: WSNamespaceDeclaration = protocols[1];
|
|
98
|
-
logger.info(`${Object.keys(protocols[1]).length} WS SFR`)
|
|
99
99
|
const MQ: MQNamespaceDeclaration = protocols[2];
|
|
100
|
-
|
|
100
|
+
|
|
101
|
+
if(DEBUG_FLAG){
|
|
102
|
+
logger.info(`${Object.keys(protocols[0]).length} REST SFR`)
|
|
103
|
+
logger.info(`${Object.keys(protocols[1]).length} WS SFR`)
|
|
104
|
+
logger.info(`${Object.keys(protocols[2]).length} MQ SFR`)
|
|
105
|
+
}
|
|
101
106
|
|
|
102
107
|
return { REST, WS, MQ } as NamespaceDeclaration;
|
|
103
108
|
}
|