@avtechno/sfr 1.0.0 → 1.0.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/dist/index.mjs +2 -2
- package/dist/mq.mjs +3 -3
- package/dist/sfr-pipeline.mjs +5 -6
- package/dist/types/index.d.mts +2 -2
- package/package.json +2 -2
- package/src/index.mts +2 -2
- package/src/mq.mts +3 -3
- package/src/sfr-pipeline.mts +5 -6
- package/src/types/index.d.ts +4 -4
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import path from "path";
|
|
|
4
4
|
import fs from "fs/promises";
|
|
5
5
|
import { REST, WS, MQ } from "./templates.mjs";
|
|
6
6
|
import { SFRPipeline } from "./sfr-pipeline.mjs";
|
|
7
|
-
import { MQLib } from "./mq.mjs";
|
|
7
|
+
import { MQLib, BroadcastMQ, TargetedMQ } from "./mq.mjs";
|
|
8
8
|
const cwd = process.cwd();
|
|
9
9
|
export default async (cfg, oas_cfg, connectors, base_url) => {
|
|
10
10
|
//TODO: Verify connectors
|
|
@@ -81,4 +81,4 @@ function inject(injections) {
|
|
|
81
81
|
...injections.controllers
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
export { REST, WS, MQ, MQLib, inject };
|
|
84
|
+
export { REST, WS, MQ, MQLib, BroadcastMQ, TargetedMQ, inject };
|
package/dist/mq.mjs
CHANGED
|
@@ -60,11 +60,11 @@ export class BroadcastMQ {
|
|
|
60
60
|
* const mq = new BroadcastMQ(channel, "Routing");
|
|
61
61
|
* mq.publish("logsExchange", "error", { level: "error", message: "Something went wrong" });
|
|
62
62
|
*/
|
|
63
|
-
async publish(exchange, key, payload, options) {
|
|
63
|
+
async publish(exchange, key = "", payload, options) {
|
|
64
64
|
switch (this.type) {
|
|
65
65
|
case "Publish-Subscribe": {
|
|
66
66
|
await this.channel.assertExchange(exchange, "fanout", { durable: false });
|
|
67
|
-
this.channel.publish(exchange,
|
|
67
|
+
this.channel.publish(exchange, key, encode_payload(payload), options);
|
|
68
68
|
break;
|
|
69
69
|
}
|
|
70
70
|
case "Routing": {
|
|
@@ -165,7 +165,7 @@ export class TargetedMQ {
|
|
|
165
165
|
async reply(msg, payload) {
|
|
166
166
|
if (this.type !== "Request-Reply")
|
|
167
167
|
return;
|
|
168
|
-
this.channel.sendToQueue(msg.properties.replyTo, encode_payload(payload));
|
|
168
|
+
this.channel.sendToQueue(msg.properties.replyTo, encode_payload(payload), { correlationId: msg.properties.correlationId });
|
|
169
169
|
this.channel.ack(msg);
|
|
170
170
|
}
|
|
171
171
|
/**
|
package/dist/sfr-pipeline.mjs
CHANGED
|
@@ -227,23 +227,22 @@ export class SFRPipeline {
|
|
|
227
227
|
switch (pattern) {
|
|
228
228
|
case "Publish-Subscribe":
|
|
229
229
|
{
|
|
230
|
-
mq.subscribe(dir,
|
|
230
|
+
mq.subscribe(dir, handler.key, {
|
|
231
231
|
options: handler.options,
|
|
232
232
|
fn: validator_fn
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
235
|
break;
|
|
236
236
|
case "Routing": {
|
|
237
|
-
|
|
238
|
-
mq.subscribe(dir, handler.routing_key, {
|
|
237
|
+
mq.subscribe(dir, handler.key, {
|
|
239
238
|
options: handler.options,
|
|
240
239
|
fn: validator_fn
|
|
241
240
|
});
|
|
242
241
|
}
|
|
243
242
|
case "Topic": {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
mq.subscribe(dir, handler.key, {
|
|
244
|
+
options: handler.options,
|
|
245
|
+
fn: validator_fn
|
|
247
246
|
});
|
|
248
247
|
}
|
|
249
248
|
}
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference path="../../src/types/index.d.ts" />
|
|
2
2
|
import { REST, WS, MQ } from "./templates.mjs";
|
|
3
|
-
import { MQLib } from "./mq.mjs";
|
|
3
|
+
import { MQLib, BroadcastMQ, TargetedMQ } from "./mq.mjs";
|
|
4
4
|
declare const _default: (cfg: ParserCFG, oas_cfg: OASConfig, connectors: SFRProtocols, base_url?: string) => Promise<ServiceManifest>;
|
|
5
5
|
export default _default;
|
|
6
6
|
declare function inject(injections: InjectedFacilities): void;
|
|
7
|
-
export { REST, WS, MQ, MQLib, inject };
|
|
7
|
+
export { REST, WS, MQ, MQLib, BroadcastMQ, TargetedMQ, inject };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avtechno/sfr",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "An opinionated way of writing services using ExpressJS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"author": "Emmanuel Abellana",
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"amqplib": "0.10.
|
|
28
|
+
"amqplib": "^0.10.3",
|
|
29
29
|
"express": "^4.18.2",
|
|
30
30
|
"express-session": "^1.17.3",
|
|
31
31
|
"file-type": "^18.5.0",
|
package/src/index.mts
CHANGED
|
@@ -5,7 +5,7 @@ import fs from "fs/promises";
|
|
|
5
5
|
|
|
6
6
|
import { REST, WS, MQ } from "./templates.mjs";
|
|
7
7
|
import { SFRPipeline } from "./sfr-pipeline.mjs";
|
|
8
|
-
import { MQLib } from "./mq.mjs";
|
|
8
|
+
import { MQLib, BroadcastMQ, TargetedMQ } from "./mq.mjs";
|
|
9
9
|
|
|
10
10
|
const cwd = process.cwd();
|
|
11
11
|
|
|
@@ -96,4 +96,4 @@ function inject(injections : InjectedFacilities){
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
export { REST, WS, MQ, MQLib, inject };
|
|
99
|
+
export { REST, WS, MQ, MQLib, BroadcastMQ, TargetedMQ, inject };
|
package/src/mq.mts
CHANGED
|
@@ -61,11 +61,11 @@ export class BroadcastMQ {
|
|
|
61
61
|
* const mq = new BroadcastMQ(channel, "Routing");
|
|
62
62
|
* mq.publish("logsExchange", "error", { level: "error", message: "Something went wrong" });
|
|
63
63
|
*/
|
|
64
|
-
async publish(exchange: string, key: string, payload: any, options?: Options.Publish) {
|
|
64
|
+
async publish(exchange: string, key: string = "", payload: any, options?: Options.Publish) {
|
|
65
65
|
switch (this.type) {
|
|
66
66
|
case "Publish-Subscribe": {
|
|
67
67
|
await this.channel.assertExchange(exchange, "fanout", { durable: false });
|
|
68
|
-
this.channel.publish(exchange,
|
|
68
|
+
this.channel.publish(exchange, key, encode_payload(payload), options);
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -179,7 +179,7 @@ export class TargetedMQ {
|
|
|
179
179
|
async reply(msg: ConsumeMessage, payload: any) {
|
|
180
180
|
if (this.type !== "Request-Reply") return;
|
|
181
181
|
|
|
182
|
-
this.channel.sendToQueue(msg.properties.replyTo, encode_payload(payload));
|
|
182
|
+
this.channel.sendToQueue(msg.properties.replyTo, encode_payload(payload), {correlationId : msg.properties.correlationId});
|
|
183
183
|
this.channel.ack(msg);
|
|
184
184
|
}
|
|
185
185
|
|
package/src/sfr-pipeline.mts
CHANGED
|
@@ -239,24 +239,23 @@ export class SFRPipeline {
|
|
|
239
239
|
if (mq instanceof BroadcastMQ) {
|
|
240
240
|
switch (pattern) {
|
|
241
241
|
case "Publish-Subscribe": {
|
|
242
|
-
mq.subscribe(dir,
|
|
242
|
+
mq.subscribe(dir, handler.key, {
|
|
243
243
|
options: handler.options,
|
|
244
244
|
fn: validator_fn
|
|
245
245
|
})
|
|
246
246
|
} break;
|
|
247
247
|
|
|
248
248
|
case "Routing": {
|
|
249
|
-
|
|
250
|
-
mq.subscribe(dir, handler.routing_key, {
|
|
249
|
+
mq.subscribe(dir, handler.key, {
|
|
251
250
|
options: handler.options,
|
|
252
251
|
fn: validator_fn
|
|
253
252
|
});
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
case "Topic": {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
mq.subscribe(dir, handler.key, {
|
|
257
|
+
options: handler.options,
|
|
258
|
+
fn : validator_fn
|
|
260
259
|
});
|
|
261
260
|
}
|
|
262
261
|
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare type NextFunction = import("express").NextFunction;
|
|
|
14
14
|
declare type RequestHandler = import("express").RequestHandler;
|
|
15
15
|
declare type ExpressRequest = import("express").Request;
|
|
16
16
|
declare type ExpressResponse = import("express").Response;
|
|
17
|
-
declare type ChannelModel = import("amqplib").
|
|
17
|
+
declare type ChannelModel = import("amqplib").ChannelModel;
|
|
18
18
|
declare type Socket = import("socket.io").Socket;
|
|
19
19
|
|
|
20
20
|
declare type BroadcastMQ = import("../mq.mts").BroadcastMQ;
|
|
@@ -258,7 +258,7 @@ declare type NamespaceDeclaration = {
|
|
|
258
258
|
declare type SFRProtocols = {
|
|
259
259
|
REST?: Express;
|
|
260
260
|
WS?: Server;
|
|
261
|
-
MQ?:
|
|
261
|
+
MQ?: ChannelModel;
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
declare type Operation = "Read" | "Write";
|
|
@@ -278,7 +278,6 @@ declare type ParserCFG = {
|
|
|
278
278
|
};
|
|
279
279
|
|
|
280
280
|
declare type Channel = import("amqplib").Channel;
|
|
281
|
-
declare type Connection = import("amqplib").Connection;
|
|
282
281
|
declare type ConsumeMessage = import("amqplib").ConsumeMessage;
|
|
283
282
|
declare type ConsumeOptions = import("amqplib").Options.Consume;
|
|
284
283
|
|
|
@@ -340,6 +339,7 @@ declare type TopicHandlerMap = {
|
|
|
340
339
|
|
|
341
340
|
declare type MQConsumeOptions = {
|
|
342
341
|
options?: ConsumeOptions;
|
|
342
|
+
key? : string;
|
|
343
343
|
queue?: string[];
|
|
344
344
|
fn: MQRequestHandler;
|
|
345
345
|
}
|
|
@@ -358,7 +358,7 @@ declare type MQRequestHandler = (msg: (ConsumeMessage & { content: any }) | null
|
|
|
358
358
|
|
|
359
359
|
declare type MQRequestCtx = {
|
|
360
360
|
channel: Channel;
|
|
361
|
-
connection:
|
|
361
|
+
connection: ChannelModel;
|
|
362
362
|
};
|
|
363
363
|
|
|
364
364
|
type AsyncAPIDocument = {
|