typespeed 2.4.7 → 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.
@@ -99,7 +99,10 @@ async function actionExecute(newSql, sqlValues) {
99
99
  async function actionQuery(newSql, sqlValues, dataClassType) {
100
100
  const readConnection = await (0, core_decorator_1.getBean)(data_source_factory_class_1.default).readConnection();
101
101
  const [rows] = await readConnection.query(newSql, sqlValues);
102
- if (rows === null || Object.keys(rows).length === 0 || !dataClassType) {
102
+ if (rows === null || Object.keys(rows).length === 0) {
103
+ return null;
104
+ }
105
+ else if (!dataClassType) {
103
106
  return rows;
104
107
  }
105
108
  const records = [];
@@ -112,7 +115,7 @@ async function actionQuery(newSql, sqlValues, dataClassType) {
112
115
  });
113
116
  records.push(entity);
114
117
  }
115
- return records;
118
+ return Object.keys(records).length === 0 ? null : records;
116
119
  }
117
120
  function convertSQLParams(decoratorSQL, target, propertyKey, args) {
118
121
  const queryValues = [];
@@ -188,7 +191,7 @@ class Model {
188
191
  }
189
192
  else if (typeof limit === 'object') {
190
193
  const total = await actionQuery('SELECT COUNT(*) AS M_COUNTER FROM ' + this.table + ' WHERE ' + sql, values);
191
- if (total === undefined || total[0]['M_COUNTER'] === 0) {
194
+ if (total === null || total[0] === undefined || total[0]['M_COUNTER'] === 0) {
192
195
  return [];
193
196
  }
194
197
  if (limit['pageSize'] !== undefined && limit['pageSize'] < total[0]['M_COUNTER']) {
@@ -220,7 +223,7 @@ class Model {
220
223
  }
221
224
  async find(conditions, sort, fields = '*') {
222
225
  const result = await this.findAll(conditions, sort, fields, 1);
223
- return result.length > 0 ? result[0] : null;
226
+ return result != null && result.length > 0 ? result[0] : null;
224
227
  }
225
228
  async update(conditions, fieldToValues) {
226
229
  const { sql, values } = this.where(conditions);
@@ -238,7 +241,7 @@ class Model {
238
241
  const { sql, values } = this.where(conditions);
239
242
  const newSql = 'SELECT COUNT(*) AS M_COUNTER FROM ' + this.table + ' WHERE ' + sql;
240
243
  const result = await actionQuery(newSql, values);
241
- return result[0]['M_COUNTER'] || 0;
244
+ return result != null && result[0] != undefined ? result[0]['M_COUNTER'] : 0;
242
245
  }
243
246
  async incr(conditions, field, optval = 1) {
244
247
  const { sql, values } = this.where(conditions);
@@ -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.7",
3
+ "version": "2.4.9",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -99,7 +99,9 @@ async function actionExecute(newSql, sqlValues): Promise<ResultSetHeader> {
99
99
  async function actionQuery(newSql, sqlValues, dataClassType?) {
100
100
  const readConnection = await getBean(DataSourceFactory).readConnection();
101
101
  const [rows] = await readConnection.query(newSql, sqlValues);
102
- if (rows === null || Object.keys(rows).length === 0 || !dataClassType) {
102
+ if (rows === null || Object.keys(rows).length === 0){
103
+ return null;
104
+ } else if (!dataClassType) {
103
105
  return rows;
104
106
  }
105
107
  const records = [];
@@ -112,7 +114,7 @@ async function actionQuery(newSql, sqlValues, dataClassType?) {
112
114
  });
113
115
  records.push(entity);
114
116
  }
115
- return records;
117
+ return Object.keys(records).length === 0 ? null : records;
116
118
  }
117
119
 
118
120
  function convertSQLParams(decoratorSQL: string, target: any, propertyKey: string, args: any[]): [string, any[]] {
@@ -192,7 +194,7 @@ class Model {
192
194
  newSql += ' LIMIT ' + limit
193
195
  } else if (typeof limit === 'object') {
194
196
  const total = await actionQuery('SELECT COUNT(*) AS M_COUNTER FROM ' + this.table + ' WHERE ' + sql, values);
195
- if (total === undefined || total[0]['M_COUNTER'] === 0) {
197
+ if (total === null || total[0] === undefined || total[0]['M_COUNTER'] === 0) {
196
198
  return [];
197
199
  }
198
200
  if (limit['pageSize'] !== undefined && limit['pageSize'] < total[0]['M_COUNTER']) {
@@ -226,7 +228,7 @@ class Model {
226
228
 
227
229
  async find<T>(conditions, sort, fields = '*'): Promise<T> {
228
230
  const result = await this.findAll(conditions, sort, fields, 1);
229
- return result.length > 0 ? <T>result[0] : null;
231
+ return result != null && result.length > 0 ? <T>result[0] : null;
230
232
  }
231
233
 
232
234
  async update(conditions, fieldToValues): Promise<number> {
@@ -247,7 +249,7 @@ class Model {
247
249
  const { sql, values } = this.where(conditions);
248
250
  const newSql = 'SELECT COUNT(*) AS M_COUNTER FROM ' + this.table + ' WHERE ' + sql;
249
251
  const result = await actionQuery(newSql, values);
250
- return result[0]['M_COUNTER'] || 0;
252
+ return result != null && result[0] != undefined ? result[0]['M_COUNTER'] : 0;
251
253
  }
252
254
 
253
255
  async incr(conditions, field, optval = 1): Promise<number> {
@@ -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