typespeed 2.4.6 → 2.4.8

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.schedule = exports.getComponent = exports.getBean = exports.autoware = exports.error = exports.log = exports.resource = exports.bean = exports.component = void 0;
3
+ exports.schedule = exports.getComponent = exports.getBean = exports.autoware = exports.error = exports.logx = exports.log = exports.resource = exports.bean = exports.component = void 0;
4
4
  require("reflect-metadata");
5
5
  const cron = require("cron");
6
6
  const log_factory_class_1 = require("./factory/log-factory.class");
@@ -71,6 +71,17 @@ function log(message, ...optionalParams) {
71
71
  }
72
72
  }
73
73
  exports.log = log;
74
+ function logx(message) {
75
+ message = JSON.stringify(message);
76
+ const logObject = beanMapper.get(log_factory_class_1.default.name);
77
+ if (logObject) {
78
+ logObject["factory"].log(message);
79
+ }
80
+ else {
81
+ console.log(message);
82
+ }
83
+ }
84
+ exports.logx = logx;
74
85
  function error(message, ...optionalParams) {
75
86
  const logObject = beanMapper.get(log_factory_class_1.default.name);
76
87
  if (logObject) {
@@ -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);
@@ -4,10 +4,7 @@
4
4
  "declaration": true,
5
5
  "emitDecoratorMetadata": true,
6
6
  "experimentalDecorators": true,
7
- "allowSyntheticDefaultImports": true,
8
- "forceConsistentCasingInFileNames": true,
9
- "target": "ES2017",
10
- "sourceMap": true,
7
+ "target": "ES6",
11
8
  "outDir": "./dist",
12
9
  "baseUrl": "./",
13
10
  "typeRoots": [
@@ -15,6 +12,6 @@
15
12
  ]
16
13
  },
17
14
  "include": [
18
- "./src/**/*.ts"
15
+ "./src/**.ts"
19
16
  ]
20
17
  }
@@ -160,6 +160,8 @@ declare function autoware(target: any, propertyKey: string): void;
160
160
  declare function resource(...args: any[]): any;
161
161
  /**日志函数,输出打印日志 */
162
162
  declare function log(message?: any, ...optionalParams: any[]): void;
163
+ /**日志函数,输出JSON日志 */
164
+ declare function logx(message: any): void;
163
165
  /**错误日志函数,输出打印错误日志 */
164
166
  declare function error(message?: any, ...optionalParams: any[]): void;
165
167
  /**路由页面前置执行装饰器,参数指向路由页面方法,被装饰的方法将在路由页面之前执行 */
@@ -394,4 +396,4 @@ declare class SocketIo {
394
396
  /**Socket IO 服务实现类 */
395
397
  declare const io: IoServer;
396
398
 
397
- export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, redisSubscriber, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, component, bean, resource, log, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, resultType, cache, Model, SocketIo, io };
399
+ export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, redisSubscriber, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, component, bean, resource, log, logx, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, resultType, cache, Model, SocketIo, io };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.4.6",
3
+ "version": "2.4.8",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -70,6 +70,16 @@ function log(message?: any, ...optionalParams: any[]) {
70
70
  }
71
71
  }
72
72
 
73
+ function logx(message) {
74
+ message = JSON.stringify(message);
75
+ const logObject = beanMapper.get(LogFactory.name);
76
+ if (logObject) {
77
+ logObject["factory"].log(message);
78
+ } else {
79
+ console.log(message);
80
+ }
81
+ }
82
+
73
83
  function error(message?: any, ...optionalParams: any[]) {
74
84
  const logObject = beanMapper.get(LogFactory.name);
75
85
  if (logObject) {
@@ -85,4 +95,4 @@ function schedule(cronTime: string | Date) {
85
95
  }
86
96
  }
87
97
 
88
- export { component, bean, resource, log, error, autoware, getBean, getComponent, schedule };
98
+ export { component, bean, resource, log, logx, error, autoware, getBean, getComponent, schedule };
@@ -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> {
@@ -4,10 +4,7 @@
4
4
  "declaration": true,
5
5
  "emitDecoratorMetadata": true,
6
6
  "experimentalDecorators": true,
7
- "allowSyntheticDefaultImports": true,
8
- "forceConsistentCasingInFileNames": true,
9
- "target": "ES2017",
10
- "sourceMap": true,
7
+ "target": "ES6",
11
8
  "outDir": "./dist",
12
9
  "baseUrl": "./",
13
10
  "typeRoots": [
@@ -15,6 +12,6 @@
15
12
  ]
16
13
  },
17
14
  "include": [
18
- "./src/**/*.ts"
15
+ "./src/**.ts"
19
16
  ]
20
17
  }
@@ -160,6 +160,8 @@ declare function autoware(target: any, propertyKey: string): void;
160
160
  declare function resource(...args: any[]): any;
161
161
  /**日志函数,输出打印日志 */
162
162
  declare function log(message?: any, ...optionalParams: any[]): void;
163
+ /**日志函数,输出JSON日志 */
164
+ declare function logx(message: any): void;
163
165
  /**错误日志函数,输出打印错误日志 */
164
166
  declare function error(message?: any, ...optionalParams: any[]): void;
165
167
  /**路由页面前置执行装饰器,参数指向路由页面方法,被装饰的方法将在路由页面之前执行 */
@@ -394,4 +396,4 @@ declare class SocketIo {
394
396
  /**Socket IO 服务实现类 */
395
397
  declare const io: IoServer;
396
398
 
397
- export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, redisSubscriber, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, component, bean, resource, log, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, resultType, cache, Model, SocketIo, io };
399
+ export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, redisSubscriber, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, component, bean, resource, log, logx, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, resultType, cache, Model, SocketIo, io };