typespeed 2.4.8 → 2.4.9

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.
@@ -62,7 +62,8 @@ function rabbitListener(queue) {
62
62
  (async function () {
63
63
  const channel = await getChannel();
64
64
  await channel.assertQueue(queue);
65
- await channel.consume(queue, target[propertyKey], { noAck: true });
65
+ const targetBean = (0, core_decorator_1.getComponent)(target.constructor);
66
+ await channel.consume(queue, targetBean[propertyKey], { noAck: true });
66
67
  }());
67
68
  };
68
69
  }
@@ -47,6 +47,14 @@ class Redis extends ioredis_1.default {
47
47
  return this.subObj;
48
48
  }
49
49
  }
50
+ static async close() {
51
+ if (this.subObj != null) {
52
+ await this.subObj.quit();
53
+ }
54
+ if (this.pubObj != null) {
55
+ await this.pubObj.quit();
56
+ }
57
+ }
50
58
  }
51
59
  Redis.pubObj = null;
52
60
  Redis.subObj = null;
@@ -68,16 +76,18 @@ function redisSubscriber(channel) {
68
76
  }
69
77
  });
70
78
  return function (target, propertyKey) {
71
- redisSubscribers[channel] = target[propertyKey];
79
+ redisSubscribers[channel] = {
80
+ target: target,
81
+ propertyKey: propertyKey
82
+ };
72
83
  };
73
84
  }
74
85
  exports.redisSubscriber = redisSubscriber;
75
86
  if ((0, typespeed_1.config)("redis")) {
76
- Redis.getInstanceOfRedis("sub").on("message", function (channel, message) {
77
- redisSubscribers[channel](message);
87
+ Redis.getInstanceOfRedis("sub").on("message", async function (channel, message) {
88
+ await (0, core_decorator_1.getComponent)(redisSubscribers[channel].target.constructor)[redisSubscribers[channel].propertyKey](message);
78
89
  });
79
90
  }
80
91
  process.once('SIGINT', () => {
81
- Redis.getInstanceOfRedis("sub") || Redis.getInstanceOfRedis("sub").disconnect();
82
- Redis.getInstanceOfRedis("pub") || Redis.getInstanceOfRedis("pub").disconnect();
92
+ Redis.close();
83
93
  });
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.io = exports.SocketIo = void 0;
4
4
  const socket_io_1 = require("socket.io");
5
5
  const http_1 = require("http");
6
+ const core_decorator_1 = require("../core.decorator");
6
7
  let io = null;
7
8
  exports.io = io;
8
9
  const listeners = { "event": [], "disconnect": null, "error": null, "connected": null };
@@ -10,27 +11,27 @@ class SocketIo {
10
11
  static setIoServer(app, ioSocketConfig) {
11
12
  const httpServer = (0, http_1.createServer)(app);
12
13
  exports.io = io = new socket_io_1.Server(httpServer, ioSocketConfig);
13
- io.use((socket, next) => {
14
+ io.use(async (socket, next) => {
14
15
  if (listeners["connected"] !== null) {
15
- listeners["connected"](socket, async (err) => {
16
+ await (0, core_decorator_1.getComponent)(listeners["connected"].target.constructor)[listeners["connected"].propertyKey](socket, async (err) => {
16
17
  if (listeners["error"] !== null && err) {
17
- await listeners["error"](socket, err);
18
+ await (0, core_decorator_1.getComponent)(listeners["error"].target.constructor)[listeners["error"].propertyKey](socket, err);
18
19
  }
19
20
  });
20
21
  }
21
22
  next();
22
23
  });
23
- io.on("connection", (socket) => {
24
+ io.on("connection", async (socket) => {
24
25
  if (listeners["disconnect"] !== null) {
25
26
  socket.on("disconnect", async (reason) => {
26
- await listeners["disconnect"](socket, reason);
27
+ await (0, core_decorator_1.getComponent)(listeners["disconnect"].target.constructor)[listeners["disconnect"].propertyKey](socket, reason);
27
28
  });
28
29
  }
29
30
  socket.use(async ([event, ...args], next) => {
30
31
  try {
31
32
  for (let listener of listeners["event"]) {
32
33
  if (listener[1] === event) {
33
- await listener[0](socket, ...args);
34
+ await (0, core_decorator_1.getComponent)(listener[0].target.constructor)[listener[0].propertyKey](socket, ...args);
34
35
  }
35
36
  }
36
37
  }
@@ -40,7 +41,7 @@ class SocketIo {
40
41
  });
41
42
  if (listeners["error"] !== null) {
42
43
  socket.on("error", async (err) => {
43
- await listeners["error"](socket, err);
44
+ await (0, core_decorator_1.getComponent)(listeners["error"].target.constructor)[listeners["error"].propertyKey](socket, err);
44
45
  });
45
46
  }
46
47
  });
@@ -48,17 +49,29 @@ class SocketIo {
48
49
  }
49
50
  static onEvent(event) {
50
51
  return (target, propertyKey) => {
51
- listeners["event"].push([target[propertyKey], event]);
52
+ listeners["event"].push([{
53
+ target: target,
54
+ propertyKey: propertyKey
55
+ }, event]);
52
56
  };
53
57
  }
54
58
  static onError(target, propertyKey) {
55
- listeners["error"] = target[propertyKey];
59
+ listeners["error"] = {
60
+ target: target,
61
+ propertyKey: propertyKey
62
+ };
56
63
  }
57
64
  static onDisconnect(target, propertyKey) {
58
- listeners["disconnect"] = target[propertyKey];
65
+ listeners["disconnect"] = {
66
+ target: target,
67
+ propertyKey: propertyKey
68
+ };
59
69
  }
60
70
  static onConnected(target, propertyKey) {
61
- listeners["connected"] = target[propertyKey];
71
+ listeners["connected"] = {
72
+ target: target,
73
+ propertyKey: propertyKey
74
+ };
62
75
  }
63
76
  }
64
77
  exports.SocketIo = SocketIo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.4.8",
3
+ "version": "2.4.9",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -1,4 +1,4 @@
1
- import { bean } from "../core.decorator";
1
+ import { bean, getComponent } from "../core.decorator";
2
2
  import { config } from "../typespeed";
3
3
  import { connect } from "amqplib";
4
4
  let rabbitConnection = null;
@@ -52,7 +52,8 @@ function rabbitListener(queue: string) {
52
52
  (async function () {
53
53
  const channel = await getChannel();
54
54
  await channel.assertQueue(queue);
55
- await channel.consume(queue, target[propertyKey], { noAck: true });
55
+ const targetBean = getComponent(target.constructor);
56
+ await channel.consume(queue, targetBean[propertyKey], { noAck: true });
56
57
  }());
57
58
  }
58
59
  }
@@ -1,4 +1,4 @@
1
- import { bean } from "../core.decorator";
1
+ import { bean, getComponent } from "../core.decorator";
2
2
  import { default as IoRedis, RedisKey} from "ioredis";
3
3
  import { config } from "../typespeed";
4
4
  const redisSubscribers = {};
@@ -42,6 +42,11 @@ class Redis extends IoRedis {
42
42
  return this.subObj;
43
43
  }
44
44
  }
45
+
46
+ static async close() {
47
+ if(this.subObj != null) { await this.subObj.quit(); }
48
+ if(this.pubObj != null) { await this.pubObj.quit(); }
49
+ }
45
50
  }
46
51
 
47
52
  function redisSubscriber(channel: string) {
@@ -54,19 +59,21 @@ function redisSubscriber(channel: string) {
54
59
  }
55
60
  });
56
61
  return function (target: any, propertyKey: string) {
57
- redisSubscribers[channel] = target[propertyKey];
62
+ redisSubscribers[channel] = {
63
+ target: target,
64
+ propertyKey: propertyKey
65
+ };
58
66
  };
59
67
  }
60
68
 
61
69
  if (config("redis")) {
62
- Redis.getInstanceOfRedis("sub").on("message", function (channel, message) {
63
- redisSubscribers[channel](message);
70
+ Redis.getInstanceOfRedis("sub").on("message", async function (channel, message) {
71
+ await getComponent(redisSubscribers[channel].target.constructor)[redisSubscribers[channel].propertyKey](message);
64
72
  });
65
73
  }
66
74
 
67
75
  process.once('SIGINT', () => {
68
- Redis.getInstanceOfRedis("sub") || Redis.getInstanceOfRedis("sub").disconnect();
69
- Redis.getInstanceOfRedis("pub") || Redis.getInstanceOfRedis("pub").disconnect();
76
+ Redis.close();
70
77
  });
71
78
 
72
79
  export { Redis, redisSubscriber };
@@ -1,5 +1,6 @@
1
1
  import { Server as IoServer } from "socket.io";
2
2
  import { createServer } from "http";
3
+ import { getComponent } from "../core.decorator";
3
4
 
4
5
  let io: IoServer = null;
5
6
  const listeners = { "event": [], "disconnect": null, "error": null, "connected": null };
@@ -9,27 +10,27 @@ class SocketIo {
9
10
  public static setIoServer(app, ioSocketConfig) {
10
11
  const httpServer = createServer(app);
11
12
  io = new IoServer(httpServer, ioSocketConfig);
12
- io.use((socket, next) => {
13
+ io.use(async (socket, next) => {
13
14
  if (listeners["connected"] !== null) {
14
- listeners["connected"](socket, async (err) => {
15
+ await getComponent(listeners["connected"].target.constructor)[listeners["connected"].propertyKey](socket, async (err) => {
15
16
  if (listeners["error"] !== null && err) {
16
- await listeners["error"](socket, err);
17
+ await getComponent(listeners["error"].target.constructor)[listeners["error"].propertyKey](socket, err);
17
18
  }
18
19
  });
19
20
  }
20
21
  next();
21
22
  });
22
- io.on("connection", (socket) => {
23
+ io.on("connection", async (socket) => {
23
24
  if (listeners["disconnect"] !== null) {
24
25
  socket.on("disconnect", async (reason) => {
25
- await listeners["disconnect"](socket, reason);
26
+ await getComponent(listeners["disconnect"].target.constructor)[listeners["disconnect"].propertyKey](socket, reason);
26
27
  });
27
28
  }
28
29
  socket.use(async ([event, ...args], next) => {
29
30
  try {
30
31
  for (let listener of listeners["event"]) {
31
32
  if (listener[1] === event) {
32
- await listener[0](socket, ...args);
33
+ await getComponent(listener[0].target.constructor)[listener[0].propertyKey](socket, ...args);
33
34
  }
34
35
  }
35
36
  } catch (err) {
@@ -39,7 +40,7 @@ class SocketIo {
39
40
 
40
41
  if (listeners["error"] !== null) {
41
42
  socket.on("error", async (err) => {
42
- await listeners["error"](socket, err);
43
+ await getComponent(listeners["error"].target.constructor)[listeners["error"].propertyKey](socket, err);
43
44
  });
44
45
  }
45
46
  });
@@ -48,20 +49,32 @@ class SocketIo {
48
49
 
49
50
  public static onEvent(event: string) {
50
51
  return (target: any, propertyKey: string) => {
51
- listeners["event"].push([target[propertyKey], event]);
52
+ listeners["event"].push([{
53
+ target: target,
54
+ propertyKey: propertyKey
55
+ }, event]);
52
56
  }
53
57
  }
54
58
 
55
59
  public static onError(target: any, propertyKey: string) {
56
- listeners["error"] = target[propertyKey];
60
+ listeners["error"] = {
61
+ target: target,
62
+ propertyKey: propertyKey
63
+ };
57
64
  }
58
65
 
59
66
  public static onDisconnect(target: any, propertyKey: string) {
60
- listeners["disconnect"] = target[propertyKey];
67
+ listeners["disconnect"] = {
68
+ target: target,
69
+ propertyKey: propertyKey
70
+ };
61
71
  }
62
72
 
63
73
  public static onConnected(target: any, propertyKey: string) {
64
- listeners["connected"] = target[propertyKey];
74
+ listeners["connected"] = {
75
+ target: target,
76
+ propertyKey: propertyKey
77
+ };
65
78
  }
66
79
  }
67
80