typespeed 2.0.11 → 2.0.13

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.
@@ -0,0 +1,9 @@
1
+ declare class RabbitMQ {
2
+ getRabbitMQ(): RabbitMQ;
3
+ publishMessageToExchange(exchange: string, routingKey: string, message: string): Promise<void>;
4
+ sendMessageToQueue(queue: string, message: string): Promise<void>;
5
+ publish(exchange: string, routingKey: string, message: string): Promise<void>;
6
+ send(queue: string, message: string): Promise<void>;
7
+ }
8
+ declare function rabbitListener(queue: string): (target: any, propertyKey: string) => void;
9
+ export { RabbitMQ, rabbitListener };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.rabbitListener = exports.RabbitMQ = void 0;
13
+ const core_decorator_1 = require("../core.decorator");
14
+ const amqplib_1 = require("amqplib");
15
+ let rabbitConnection = null;
16
+ class RabbitMQ {
17
+ getRabbitMQ() {
18
+ if (!(0, core_decorator_1.config)("rabbitmq")) {
19
+ return null;
20
+ }
21
+ return new RabbitMQ();
22
+ }
23
+ async publishMessageToExchange(exchange, routingKey, message) {
24
+ const channel = await getChannel();
25
+ await channel.checkExchange(exchange);
26
+ channel.publish(exchange, routingKey, Buffer.from(message));
27
+ await channel.close();
28
+ }
29
+ async sendMessageToQueue(queue, message) {
30
+ const channel = await getChannel();
31
+ await channel.checkQueue(queue);
32
+ channel.sendToQueue(queue, Buffer.from(message));
33
+ await channel.close();
34
+ }
35
+ async publish(exchange, routingKey, message) {
36
+ await this.publishMessageToExchange(exchange, routingKey, message);
37
+ }
38
+ async send(queue, message) {
39
+ await this.sendMessageToQueue(queue, message);
40
+ }
41
+ }
42
+ __decorate([
43
+ core_decorator_1.bean,
44
+ __metadata("design:type", Function),
45
+ __metadata("design:paramtypes", []),
46
+ __metadata("design:returntype", RabbitMQ)
47
+ ], RabbitMQ.prototype, "getRabbitMQ", null);
48
+ exports.RabbitMQ = RabbitMQ;
49
+ async function getChannel() {
50
+ if (rabbitConnection === null) {
51
+ rabbitConnection = await (0, amqplib_1.connect)((0, core_decorator_1.config)("rabbitmq"));
52
+ process.once('SIGINT', async () => {
53
+ await rabbitConnection.close();
54
+ });
55
+ }
56
+ const channel = await rabbitConnection.createChannel();
57
+ return channel;
58
+ }
59
+ function rabbitListener(queue) {
60
+ return (target, propertyKey) => {
61
+ (async function () {
62
+ const channel = await getChannel();
63
+ await channel.checkQueue(queue);
64
+ await channel.consume(queue, target[propertyKey], { noAck: true });
65
+ }());
66
+ };
67
+ }
68
+ exports.rabbitListener = rabbitListener;
69
+ //# sourceMappingURL=rabbitmq.class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rabbitmq.class.js","sourceRoot":"","sources":["../../src/default/rabbitmq.class.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sDAAiD;AACjD,qCAAkC;AAClC,IAAI,gBAAgB,GAAG,IAAI,CAAC;AAE5B,MAAM,QAAQ;IAGH,WAAW;QACd,IAAI,CAAC,IAAA,uBAAM,EAAC,UAAU,CAAC,EAAE;YACrB,OAAO,IAAI,CAAC;SACf;QACD,OAAO,IAAI,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,QAAgB,EAAE,UAA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,OAAO,GAAG,MAAM,gBAAgB,CAAC,aAAa,EAAE,CAAC;IACvD,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,SAAS,cAAc,CAAC,KAAa;IACjC,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QACxC,CAAC,KAAK;YACF,MAAM,OAAO,GAAG,MAAM,UAAU,EAAE,CAAC;YACnC,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAChC,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,CAAC,EAAE,CAAC,CAAC;IACT,CAAC,CAAA;AACL,CAAC;AAEkB,wCAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"redis.class.js","sourceRoot":"","sources":["../../src/default/redis.class.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,qCAA8B;AAE9B,MAAqB,KAAM,SAAQ,iBAAO;IAG/B,QAAQ;QACX,IAAI,CAAC,IAAA,uBAAM,EAAC,OAAO,CAAC,EAAE;YAClB,OAAO,IAAI,CAAC;SACf;QACD,OAAO,IAAI,KAAK,CAAC,IAAA,uBAAM,EAAC,OAAO,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,YAAY,MAAW;QACnB,KAAK,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;CAEJ;AAZG;IAAC,qBAAI;;;oCACc,KAAK;qCAKvB;AARL,wBAcC"}
1
+ {"version":3,"file":"redis.class.js","sourceRoot":"","sources":["../../src/default/redis.class.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAiD;AACjD,qCAA8B;AAE9B,MAAqB,KAAM,SAAQ,iBAAO;IAG/B,QAAQ;QACX,IAAI,CAAC,IAAA,uBAAM,EAAC,OAAO,CAAC,EAAE;YAClB,OAAO,IAAI,CAAC;SACf;QACD,OAAO,IAAI,KAAK,CAAC,IAAA,uBAAM,EAAC,OAAO,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,YAAY,MAAW;QACnB,KAAK,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;CAEJ;AAZG;IAAC,qBAAI;;;oCACc,KAAK;qCAKvB;AARL,wBAcC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -10,7 +10,7 @@
10
10
  "prebuild": "rm -rf dist",
11
11
  "prepublishOnly": "npm version patch && npm run build",
12
12
  "upgrade": "npm version minor",
13
- "postpublish": "git add . && git commit -m 'Added all built files in dist.' && git push && git push --tags"
13
+ "postpublish": "git push && git push --tags"
14
14
  },
15
15
  "main": "dist/typespeed.js",
16
16
  "bin": {
@@ -23,26 +23,27 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@types/node": "^18.0.6",
26
- "reflect-metadata": "^0.1.13",
27
- "typescript": "^4.7.4",
28
- "walk-sync": "^3.0.0",
29
- "tracer": "^1.1.6",
30
- "express": "^4.18.1",
31
- "consolidate": "^0.16.0",
32
- "mustache": "^4.2.0",
33
- "serve-favicon": "^2.5.0",
26
+ "commander": "^9.4.0",
34
27
  "compression": "^1.7.4",
28
+ "connect-redis": "^6.1.3",
29
+ "consolidate": "^0.16.0",
35
30
  "cookie-parser": "^1.4.6",
36
- "express-session": "^1.17.3",
37
- "multiparty": "^4.2.3",
31
+ "cron": "^2.3.0",
32
+ "express": "^4.18.1",
38
33
  "express-basic-auth": "^1.2.1",
39
34
  "express-jwt": "^7.7.5",
35
+ "express-session": "^1.17.3",
36
+ "ioredis": "^5.2.3",
40
37
  "jsonwebtoken": "^8.5.1",
38
+ "multiparty": "^4.2.3",
39
+ "mustache": "^4.2.0",
41
40
  "mysql2": "^2.3.3",
42
41
  "node-cache": "^5.1.2",
43
- "ioredis": "^5.2.3",
44
- "connect-redis": "^6.1.3",
45
- "cron": "^2.1.0",
46
- "commander": "^9.4.0"
42
+ "reflect-metadata": "^0.1.13",
43
+ "serve-favicon": "^2.5.0",
44
+ "tracer": "^1.1.6",
45
+ "typescript": "^4.7.4",
46
+ "walk-sync": "^3.0.0",
47
+ "amqplib": "0.10.3"
47
48
  }
48
49
  }
@@ -0,0 +1,59 @@
1
+ import { bean, config } from "../core.decorator";
2
+ import { connect } from "amqplib";
3
+ let rabbitConnection = null;
4
+
5
+ class RabbitMQ {
6
+
7
+ @bean
8
+ public getRabbitMQ(): RabbitMQ {
9
+ if (!config("rabbitmq")) {
10
+ return null;
11
+ }
12
+ return new RabbitMQ();
13
+ }
14
+
15
+ public async publishMessageToExchange(exchange: string, routingKey: string, message: string): Promise<void> {
16
+ const channel = await getChannel();
17
+ await channel.checkExchange(exchange);
18
+ channel.publish(exchange, routingKey, Buffer.from(message));
19
+ await channel.close();
20
+ }
21
+
22
+ public async sendMessageToQueue(queue: string, message: string): Promise<void> {
23
+ const channel = await getChannel();
24
+ await channel.checkQueue(queue);
25
+ channel.sendToQueue(queue, Buffer.from(message));
26
+ await channel.close();
27
+ }
28
+
29
+ public async publish(exchange: string, routingKey: string, message: string): Promise<void> {
30
+ await this.publishMessageToExchange(exchange, routingKey, message);
31
+ }
32
+
33
+ public async send(queue: string, message: string): Promise<void> {
34
+ await this.sendMessageToQueue(queue, message);
35
+ }
36
+ }
37
+
38
+ async function getChannel() {
39
+ if (rabbitConnection === null) {
40
+ rabbitConnection = await connect(config("rabbitmq"));
41
+ process.once('SIGINT', async () => {
42
+ await rabbitConnection.close();
43
+ });
44
+ }
45
+ const channel = await rabbitConnection.createChannel();
46
+ return channel;
47
+ }
48
+
49
+ function rabbitListener(queue: string) {
50
+ return (target: any, propertyKey: string) => {
51
+ (async function () {
52
+ const channel = await getChannel();
53
+ await channel.checkQueue(queue);
54
+ await channel.consume(queue, target[propertyKey], { noAck: true });
55
+ }());
56
+ }
57
+ }
58
+
59
+ export { RabbitMQ, rabbitListener };
@@ -1,4 +1,4 @@
1
- import { bean, config, log } from "../core.decorator";
1
+ import { bean, config } from "../core.decorator";
2
2
  import IoRedis from "ioredis";
3
3
 
4
4
  export default class Redis extends IoRedis {
@@ -0,0 +1,71 @@
1
+ import { component, getMapping, autoware, log } from "../../";
2
+ import { RabbitMQ, rabbitListener } from "../../src/default/rabbitmq.class";
3
+ import { connect } from "amqplib";
4
+
5
+
6
+ @component
7
+ export default class TestMq {
8
+
9
+ @autoware
10
+ private rabbitMQ: RabbitMQ;
11
+
12
+ //@rabbitListener("myqueues")
13
+ public async listen(message) {
14
+ log(" Received by Decorator '%s'", message.content.toString());
15
+ }
16
+
17
+ @getMapping("/mq/sendByMQClass")
18
+ async sendByMQClass() {
19
+ this.rabbitMQ.send("myqueues", "hello world, by MQClass");
20
+ return "sent by MQClass";
21
+ }
22
+
23
+ @getMapping("/mq/sendByQueue")
24
+ async sendMq() {
25
+ const queue = 'myqueues';
26
+ const text = "hello world, by queue";
27
+ const connection = await connect({
28
+ protocol: 'amqp',
29
+ hostname: 'localhost',
30
+ port: 5672,
31
+ username: 'guest',
32
+ password: 'guest'
33
+ });
34
+ const channel = await connection.createChannel();
35
+ await channel.checkQueue(queue);
36
+ channel.sendToQueue(queue, Buffer.from(text));
37
+ console.log(" [x] Sent by queue '%s'", text);
38
+ await channel.close();
39
+ return "sent by queue";
40
+ }
41
+
42
+ @getMapping("/mq/sendByExchange")
43
+ async sendMq2() {
44
+ const exchange = 'myexchanges';
45
+ const text = "hello world, by exchange";
46
+ const connection = await connect('amqp://localhost');
47
+ const channel = await connection.createChannel();
48
+ await channel.checkExchange(exchange);
49
+ channel.publish(exchange, '', Buffer.from(text));
50
+ console.log(" [x] Publish by exchange '%s'", text);
51
+ await channel.close();
52
+ return "sent by exchange";
53
+ }
54
+
55
+ @getMapping("/mq/listen")
56
+ async testMq() {
57
+ const connection = await connect('amqp://localhost');
58
+ const channel = await connection.createChannel();
59
+ const queue = 'myqueues';
60
+ const queue2 = 'myqueues2';
61
+ await channel.checkQueue(queue);
62
+ await channel.checkQueue(queue2);
63
+ await channel.consume(queue, (message) => {
64
+ console.log(" [x] Received '%s'", message.content.toString());
65
+ }, { noAck: true });
66
+ await channel.consume(queue2, (message) => {
67
+ console.log(" [x] Received queue2 '%s'", message.content.toString());
68
+ }, { noAck: true });
69
+ return "ok";
70
+ }
71
+ }