cgserver 6.3.5 → 6.4.4
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/lib/Core/Core.js +31 -0
- package/dist/lib/Logic/AsyncQueueTool.js +42 -0
- package/dist/lib/Logic/HelpTool.js +2 -0
- package/dist/lib/Logic/Log.js +47 -6
- package/dist/lib/cgserver.js +3 -1
- package/dist/types/Core/Core.d.ts +1 -0
- package/dist/types/Logic/AsyncQueueTool.d.ts +21 -0
- package/dist/types/Logic/HelpTool.d.ts +2 -0
- package/dist/types/Logic/Log.d.ts +3 -0
- package/dist/types/cgserver.d.ts +1 -0
- package/package.json +1 -1
package/dist/lib/Core/Core.js
CHANGED
|
@@ -5,6 +5,7 @@ let os = require('os');
|
|
|
5
5
|
let request = require('request');
|
|
6
6
|
const _ = require("underscore");
|
|
7
7
|
const crypto = require("crypto");
|
|
8
|
+
const Log_1 = require("../Logic/Log");
|
|
8
9
|
/**
|
|
9
10
|
* 常用的工具函数类
|
|
10
11
|
*/
|
|
@@ -564,5 +565,35 @@ class core {
|
|
|
564
565
|
}, milliseconds);
|
|
565
566
|
});
|
|
566
567
|
}
|
|
568
|
+
static async safeCall(func, thisArg = null, ...params) {
|
|
569
|
+
if (!func) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
if (core.isAsyncFunc(func)) {
|
|
574
|
+
if (thisArg) {
|
|
575
|
+
await func.call(thisArg, params).catch((reason) => {
|
|
576
|
+
Log_1.GLog.error(reason);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
await func(params).catch((reason) => {
|
|
581
|
+
Log_1.GLog.error(reason);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
if (thisArg) {
|
|
587
|
+
func.call(thisArg, params);
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
func(params);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
catch (e) {
|
|
595
|
+
Log_1.GLog.error(e.stack);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
567
598
|
}
|
|
568
599
|
exports.core = core;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GAsyncQueueTool = void 0;
|
|
4
|
+
const cgserver_1 = require("../cgserver");
|
|
5
|
+
class AsyncQueueItem {
|
|
6
|
+
key = "";
|
|
7
|
+
running = false;
|
|
8
|
+
funcs = [];
|
|
9
|
+
constructor(key) {
|
|
10
|
+
this.key = key;
|
|
11
|
+
}
|
|
12
|
+
async add(func, thisArg = null, ...params) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
this.funcs.push({ func: func, thisArg: thisArg, params: params, resolve: resolve });
|
|
15
|
+
this._run();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async _run() {
|
|
19
|
+
if (this.running) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.running = true;
|
|
23
|
+
while (this.funcs.length > 0) {
|
|
24
|
+
let funcitem = this.funcs.shift();
|
|
25
|
+
if (!funcitem.func) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
await cgserver_1.core.safeCall(funcitem.func, funcitem.thisArg, funcitem.params);
|
|
29
|
+
await cgserver_1.core.safeCall(funcitem.resolve);
|
|
30
|
+
}
|
|
31
|
+
this.running = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class AsyncQueueTool {
|
|
35
|
+
//队列数据,一个key队列必须有先后
|
|
36
|
+
_queues;
|
|
37
|
+
add(key, func) {
|
|
38
|
+
this._queues[key] = this._queues[key] || new AsyncQueueItem(key);
|
|
39
|
+
this._queues[key].add(func);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.GAsyncQueueTool = new AsyncQueueTool();
|
package/dist/lib/Logic/Log.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GLog = void 0;
|
|
4
|
-
const Core_1 = require("../Core/Core");
|
|
5
4
|
const colors = require("colors");
|
|
6
5
|
const log4js = require("log4js");
|
|
7
6
|
/**
|
|
@@ -40,29 +39,29 @@ class Log {
|
|
|
40
39
|
this._errorLogger = log4js.getLogger(cfg.categories.default.appenders[2] || "error_log_file");
|
|
41
40
|
}
|
|
42
41
|
error(message, ...optionalParams) {
|
|
43
|
-
if (
|
|
42
|
+
if (this.isObject(message)) {
|
|
44
43
|
message = JSON.stringify(message);
|
|
45
44
|
}
|
|
46
45
|
this._errorLogger.error(message);
|
|
47
46
|
var time = new Date();
|
|
48
|
-
var time_str =
|
|
47
|
+
var time_str = this.format(time, "[YYYY-MM-DD HH:mm:SS.");
|
|
49
48
|
time_str += time.getMilliseconds() + "]";
|
|
50
49
|
console.error(time_str + " " + message);
|
|
51
50
|
}
|
|
52
51
|
info(message, to_console) {
|
|
53
|
-
if (
|
|
52
|
+
if (this.isObject(message)) {
|
|
54
53
|
message = JSON.stringify(message);
|
|
55
54
|
}
|
|
56
55
|
this._logger.info(message);
|
|
57
56
|
if (to_console) {
|
|
58
57
|
var time = new Date();
|
|
59
|
-
var time_str =
|
|
58
|
+
var time_str = this.format(time, "[YYYY-MM-DD HH:mm:SS.");
|
|
60
59
|
time_str += time.getMilliseconds() + "]";
|
|
61
60
|
console.log(time_str + " " + message);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
warn(message, ...optionalParams) {
|
|
65
|
-
if (
|
|
64
|
+
if (this.isObject(message)) {
|
|
66
65
|
message = JSON.stringify(message);
|
|
67
66
|
}
|
|
68
67
|
this._errorLogger.warn(message);
|
|
@@ -73,5 +72,47 @@ class Log {
|
|
|
73
72
|
clientLog(message, ...optionalParams) {
|
|
74
73
|
this._client_logger.error(message);
|
|
75
74
|
}
|
|
75
|
+
isObject(param) {
|
|
76
|
+
return typeof (param) === "object";
|
|
77
|
+
}
|
|
78
|
+
isString(param) {
|
|
79
|
+
return typeof (param) === "string";
|
|
80
|
+
}
|
|
81
|
+
format = function (src, formatStr) {
|
|
82
|
+
if (this.isString(src)) {
|
|
83
|
+
let args = Array.prototype.slice.call(arguments, 1);
|
|
84
|
+
return src.replace(/\{(\d+)\}/g, function (m, i) {
|
|
85
|
+
return args[i];
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (this.isNumber(src)) {
|
|
90
|
+
src = new Date(src);
|
|
91
|
+
}
|
|
92
|
+
let str = formatStr;
|
|
93
|
+
let Week = ['日', '一', '二', '三', '四', '五', '六'];
|
|
94
|
+
let month = src.getMonth() + 1;
|
|
95
|
+
let year = src.getFullYear();
|
|
96
|
+
let date = src.getDate();
|
|
97
|
+
let hour = src.getHours();
|
|
98
|
+
let min = src.getMinutes();
|
|
99
|
+
let sec = src.getSeconds();
|
|
100
|
+
let day = src.getDay();
|
|
101
|
+
str = str.replace(/yyyy|YYYY/, year);
|
|
102
|
+
str = str.replace(/yy|YY/, (year % 100) > 9 ? (year % 100).toString() : '0' + (year % 100));
|
|
103
|
+
str = str.replace(/MM/, month > 9 ? month.toString() : '0' + month);
|
|
104
|
+
str = str.replace(/M/g, month);
|
|
105
|
+
str = str.replace(/w|W/g, Week[day]);
|
|
106
|
+
str = str.replace(/dd|DD/, date > 9 ? date.toString() : '0' + date);
|
|
107
|
+
str = str.replace(/d|D/g, date);
|
|
108
|
+
str = str.replace(/hh|HH/, hour > 9 ? hour.toString() : '0' + hour);
|
|
109
|
+
str = str.replace(/h|H/g, hour);
|
|
110
|
+
str = str.replace(/mm/, min > 9 ? min.toString() : '0' + min);
|
|
111
|
+
str = str.replace(/m/g, min);
|
|
112
|
+
str = str.replace(/ss|SS/, sec > 9 ? sec.toString() : '0' + sec);
|
|
113
|
+
str = str.replace(/s|S/g, sec);
|
|
114
|
+
return str;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
76
117
|
}
|
|
77
118
|
exports.GLog = new Log();
|
package/dist/lib/cgserver.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonProtoFilter = exports.GoogleProtoFilter = exports.MongoCacheModel = exports.GMongoCacheSer = exports.MongoUserModel = exports.MysqlUserModel = exports.MongoUserService = exports.MysqlUserService = exports.GMongoAccountSer = exports.MongoAccountService = exports.GMysqlAccountSer = exports.MysqlAccountService = exports.EAccountFrom = exports.EUserState = exports.ERoleGroup = exports.GLog = exports.GHttpTool = exports.GCacheTool = exports.RedisManager = exports.GRedisMgr = exports.GMysqlMgr = exports.MysqlBaseService = exports.GMSSqlMgr = exports.GMongoMgr = exports.MongoBaseModel = exports.MysqlBaseModel = exports.MongoBaseService = exports.EPropertyType = exports.Type = exports.Table = exports.Property = exports.PrimaryKey = exports.NotNull = exports.AutoIncrement = exports.Timer = exports.core = exports.ServerConfig = exports.GFCfg = exports.FrameworkConfig = exports.Config = exports.FrameworkErrorCode = exports.GTriggerMgr = exports.Trigger = exports.Point = exports.Entity = exports.BehaviorAI = exports.AStar = exports.AiObject = exports.GDBCache = exports.GProtoFactory = void 0;
|
|
4
|
-
exports.GCgServer = exports.WebServerConfig = exports.Response = exports.Request = exports.RazorJs = exports.Engine = exports.GCtrMgr = exports.JsonCreatorValidate = exports.JsonAuthorityValidate = exports.JsonAdminValidate = exports.CreatorValidate = exports.AuthorityValidate = exports.AdminValidate = exports.MongoAccountModel = exports.MysqlAccountModel = exports.MongoBaseUserController = exports.BaseUserController = exports.BaseController = exports.IWebServer = exports.GWechatTool = exports.GWechatOATool = exports.GQQTool = exports.GQiniuTool = exports.GOpenSocial = exports.GEmailTool = exports.GAppleTool = exports.GSmsTool = exports.GAlipayTool = exports.IWebSocket = exports.ISocketServer = exports.IServerWebSocket = exports.IClientWebSocket = void 0;
|
|
4
|
+
exports.GCgServer = exports.GAsyncQueueTool = exports.WebServerConfig = exports.Response = exports.Request = exports.RazorJs = exports.Engine = exports.GCtrMgr = exports.JsonCreatorValidate = exports.JsonAuthorityValidate = exports.JsonAdminValidate = exports.CreatorValidate = exports.AuthorityValidate = exports.AdminValidate = exports.MongoAccountModel = exports.MysqlAccountModel = exports.MongoBaseUserController = exports.BaseUserController = exports.BaseController = exports.IWebServer = exports.GWechatTool = exports.GWechatOATool = exports.GQQTool = exports.GQiniuTool = exports.GOpenSocial = exports.GEmailTool = exports.GAppleTool = exports.GSmsTool = exports.GAlipayTool = exports.IWebSocket = exports.ISocketServer = exports.IServerWebSocket = exports.IClientWebSocket = void 0;
|
|
5
5
|
var ProtoFactory_1 = require("./SocketServer/ProtoFilter/ProtoFactory");
|
|
6
6
|
Object.defineProperty(exports, "GProtoFactory", { enumerable: true, get: function () { return ProtoFactory_1.GProtoFactory; } });
|
|
7
7
|
var DBCache_1 = require("./Database/Decorator/DBCache");
|
|
@@ -157,6 +157,8 @@ var Response_1 = require("./WebServer/Engine/Response");
|
|
|
157
157
|
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return Response_1.Response; } });
|
|
158
158
|
var FrameworkConfig_2 = require("./Config/FrameworkConfig");
|
|
159
159
|
Object.defineProperty(exports, "WebServerConfig", { enumerable: true, get: function () { return FrameworkConfig_2.WebServerConfig; } });
|
|
160
|
+
var AsyncQueueTool_1 = require("./Logic/AsyncQueueTool");
|
|
161
|
+
Object.defineProperty(exports, "GAsyncQueueTool", { enumerable: true, get: function () { return AsyncQueueTool_1.GAsyncQueueTool; } });
|
|
160
162
|
const Log_2 = require("./Logic/Log");
|
|
161
163
|
class CgServer {
|
|
162
164
|
constructor() {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare class AsyncQueueItem {
|
|
2
|
+
key: string;
|
|
3
|
+
running: boolean;
|
|
4
|
+
funcs: {
|
|
5
|
+
func: Function;
|
|
6
|
+
thisArg: any;
|
|
7
|
+
params: any[];
|
|
8
|
+
resolve?: Function;
|
|
9
|
+
}[];
|
|
10
|
+
constructor(key: string);
|
|
11
|
+
add(func: Function, thisArg?: any, ...params: any[]): Promise<unknown>;
|
|
12
|
+
protected _run(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
declare class AsyncQueueTool {
|
|
15
|
+
protected _queues: {
|
|
16
|
+
[key: string]: AsyncQueueItem;
|
|
17
|
+
};
|
|
18
|
+
add(key: string, func: Function): void;
|
|
19
|
+
}
|
|
20
|
+
export declare let GAsyncQueueTool: AsyncQueueTool;
|
|
21
|
+
export {};
|
|
@@ -11,5 +11,8 @@ declare class Log {
|
|
|
11
11
|
warn(message?: any, ...optionalParams: any[]): void;
|
|
12
12
|
record(message?: any, ...optionalParams: any[]): void;
|
|
13
13
|
clientLog(message?: any, ...optionalParams: any[]): void;
|
|
14
|
+
isObject(param: any): boolean;
|
|
15
|
+
isString(param: any): boolean;
|
|
16
|
+
format: (src: any, formatStr: any) => any;
|
|
14
17
|
}
|
|
15
18
|
export {};
|
package/dist/types/cgserver.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export { RazorJs } from './WebServer/Engine/RazorJs';
|
|
|
72
72
|
export { Request } from './WebServer/Engine/Request';
|
|
73
73
|
export { Response } from './WebServer/Engine/Response';
|
|
74
74
|
export { WebServerConfig } from './Config/FrameworkConfig';
|
|
75
|
+
export { GAsyncQueueTool } from './Logic/AsyncQueueTool';
|
|
75
76
|
declare class CgServer {
|
|
76
77
|
constructor();
|
|
77
78
|
init(): void;
|