ee-core 4.1.2 → 4.1.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.
Files changed (131) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +65 -65
  3. package/app/application.d.ts +5 -5
  4. package/app/application.js +30 -30
  5. package/app/boot.d.ts +5 -5
  6. package/app/boot.js +80 -80
  7. package/app/dir.d.ts +1 -1
  8. package/app/dir.js +26 -26
  9. package/app/events.d.ts +14 -14
  10. package/app/events.js +55 -55
  11. package/app/index.d.ts +2 -2
  12. package/app/index.js +6 -6
  13. package/config/config_loader.d.ts +13 -13
  14. package/config/config_loader.js +65 -65
  15. package/config/default_config.d.ts +95 -95
  16. package/config/default_config.js +111 -111
  17. package/config/index.d.ts +28 -28
  18. package/config/index.js +24 -24
  19. package/const/channel.d.ts +16 -16
  20. package/const/channel.js +27 -27
  21. package/controller/controller_loader.d.ts +9 -9
  22. package/controller/controller_loader.js +77 -77
  23. package/controller/index.d.ts +2 -2
  24. package/controller/index.js +24 -24
  25. package/core/index.d.ts +2 -2
  26. package/core/index.js +11 -11
  27. package/core/loader/file_loader.d.ts +66 -66
  28. package/core/loader/file_loader.js +211 -211
  29. package/core/utils/index.d.ts +12 -12
  30. package/core/utils/index.js +83 -83
  31. package/core/utils/timing.d.ts +22 -22
  32. package/core/utils/timing.js +78 -78
  33. package/cross/cross.d.ts +19 -19
  34. package/cross/cross.js +151 -151
  35. package/cross/crossProcess.d.ts +29 -29
  36. package/cross/crossProcess.js +172 -172
  37. package/cross/index.d.ts +2 -2
  38. package/cross/index.js +8 -8
  39. package/electron/app/index.d.ts +5 -5
  40. package/electron/app/index.js +48 -48
  41. package/electron/index.d.ts +3 -3
  42. package/electron/index.js +15 -15
  43. package/electron/window/index.d.ts +6 -6
  44. package/electron/window/index.js +268 -268
  45. package/exception/index.d.ts +9 -9
  46. package/exception/index.js +100 -100
  47. package/html/boot.html +98 -98
  48. package/html/cross-failure.html +28 -28
  49. package/html/failure.html +28 -28
  50. package/html/index.d.ts +1 -1
  51. package/html/index.js +10 -10
  52. package/index.d.ts +2 -2
  53. package/index.js +6 -6
  54. package/jobs/child/app.d.ts +1 -1
  55. package/jobs/child/app.js +69 -69
  56. package/jobs/child/index.d.ts +13 -13
  57. package/jobs/child/index.js +85 -85
  58. package/jobs/child/jobProcess.d.ts +16 -16
  59. package/jobs/child/jobProcess.js +133 -133
  60. package/jobs/child-pool/index.d.ts +26 -26
  61. package/jobs/child-pool/index.js +190 -190
  62. package/jobs/index.d.ts +3 -3
  63. package/jobs/index.js +6 -6
  64. package/jobs/load-balancer/algorithm/index.d.ts +4 -4
  65. package/jobs/load-balancer/algorithm/index.js +11 -11
  66. package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -2
  67. package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
  68. package/jobs/load-balancer/algorithm/polling.d.ts +2 -2
  69. package/jobs/load-balancer/algorithm/polling.js +11 -11
  70. package/jobs/load-balancer/algorithm/random.d.ts +2 -2
  71. package/jobs/load-balancer/algorithm/random.js +9 -9
  72. package/jobs/load-balancer/algorithm/specify.d.ts +2 -2
  73. package/jobs/load-balancer/algorithm/specify.js +14 -14
  74. package/jobs/load-balancer/algorithm/weights.d.ts +2 -2
  75. package/jobs/load-balancer/algorithm/weights.js +21 -21
  76. package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -2
  77. package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
  78. package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -2
  79. package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
  80. package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -2
  81. package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
  82. package/jobs/load-balancer/consts.d.ts +8 -8
  83. package/jobs/load-balancer/consts.js +9 -9
  84. package/jobs/load-balancer/index.d.ts +96 -96
  85. package/jobs/load-balancer/index.js +201 -201
  86. package/jobs/load-balancer/scheduler.d.ts +16 -16
  87. package/jobs/load-balancer/scheduler.js +31 -31
  88. package/loader/index.d.ts +9 -9
  89. package/loader/index.js +99 -98
  90. package/log/index.d.ts +5 -5
  91. package/log/index.js +85 -85
  92. package/log/logger.d.ts +1 -1
  93. package/log/logger.js +94 -94
  94. package/message/childMessage.d.ts +10 -10
  95. package/message/childMessage.js +43 -43
  96. package/message/index.d.ts +3 -3
  97. package/message/index.js +9 -9
  98. package/package.json +42 -42
  99. package/ps/index.d.ts +39 -39
  100. package/ps/index.js +294 -294
  101. package/socket/httpServer.d.ts +8 -8
  102. package/socket/httpServer.js +199 -199
  103. package/socket/index.d.ts +10 -10
  104. package/socket/index.js +64 -64
  105. package/socket/ipcServer.d.ts +9 -9
  106. package/socket/ipcServer.js +105 -105
  107. package/socket/socketServer.d.ts +10 -10
  108. package/socket/socketServer.js +81 -81
  109. package/storage/index.d.ts +4 -4
  110. package/storage/index.js +6 -6
  111. package/storage/sqliteStorage.d.ts +16 -16
  112. package/storage/sqliteStorage.js +123 -123
  113. package/tsconfig.json +13 -13
  114. package/utils/extend.d.ts +2 -2
  115. package/utils/extend.js +77 -77
  116. package/utils/helper.d.ts +14 -14
  117. package/utils/helper.js +206 -206
  118. package/utils/index.d.ts +10 -10
  119. package/utils/index.js +167 -167
  120. package/utils/ip.d.ts +2 -2
  121. package/utils/ip.js +221 -221
  122. package/utils/is.d.ts +14 -14
  123. package/utils/is.js +111 -111
  124. package/utils/json.d.ts +5 -5
  125. package/utils/json.js +79 -79
  126. package/utils/pargv.d.ts +3 -3
  127. package/utils/pargv.js +267 -267
  128. package/utils/port/index.d.ts +1 -1
  129. package/utils/port/index.js +125 -125
  130. package/utils/wrap.d.ts +4 -4
  131. package/utils/wrap.js +40 -40
package/utils/helper.js CHANGED
@@ -1,207 +1,207 @@
1
- const fs = require('fs');
2
- const mkdirp = require('mkdirp');
3
- const convert = require('koa-convert');
4
- const is = require('is-type-of');
5
- const path = require('path');
6
- const chalk = require('chalk');
7
- const { parseArgv } = require('./pargv');
8
-
9
- const _basePath = process.cwd();
10
-
11
- function fnDebounce() {
12
- const fnObject = {};
13
- let timer;
14
-
15
- return (fn, delayTime, isImediate, args) => {
16
- const setTimer = () => {
17
- timer = setTimeout(() => {
18
- fn(args);
19
- clearTimeout(timer);
20
- delete fnObject[fn];
21
- }, delayTime);
22
-
23
- fnObject[fn] = { delayTime, timer };
24
- };
25
-
26
- if (!delayTime || isImediate) return fn(args);
27
-
28
- if (fnObject[fn]) {
29
- clearTimeout(timer);
30
- setTimer(fn, delayTime, args);
31
- } else {
32
- setTimer(fn, delayTime, args);
33
- }
34
- };
35
- }
36
-
37
- // 随机10位字符串
38
- function getRandomString() {
39
- return Math.random().toString(36).substring(2);
40
- };
41
-
42
- // 创建文件夹
43
- function mkdir(filepath, opt = {}) {
44
- mkdirp.sync(filepath, opt);
45
- return
46
- }
47
-
48
- // 修改文件权限
49
- function chmodPath(path, mode) {
50
- let files = [];
51
- if (fs.existsSync(path)) {
52
- files = fs.readdirSync(path);
53
- files.forEach((file, index) => {
54
- const curPath = path + '/' + file;
55
- if (fs.statSync(curPath).isDirectory()) {
56
- this.chmodPath(curPath, mode); // 递归删除文件夹
57
- } else {
58
- fs.chmodSync(curPath, mode);
59
- }
60
- });
61
- fs.chmodSync(path, mode);
62
- }
63
- };
64
-
65
- // 版本号比较
66
- function compareVersion(v1, v2) {
67
- v1 = v1.split('.')
68
- v2 = v2.split('.')
69
- const len = Math.max(v1.length, v2.length)
70
-
71
- while (v1.length < len) {
72
- v1.push('0')
73
- }
74
- while (v2.length < len) {
75
- v2.push('0')
76
- }
77
-
78
- for (let i = 0; i < len; i++) {
79
- const num1 = parseInt(v1[i])
80
- const num2 = parseInt(v2[i])
81
-
82
- if (num1 > num2) {
83
- return 1
84
- } else if (num1 < num2) {
85
- return -1
86
- }
87
- }
88
-
89
- return 0
90
- }
91
-
92
- function middleware(fn) {
93
- return is.generatorFunction(fn) ? convert(fn) : fn;
94
- }
95
-
96
- // 序列化对象
97
- function stringify(obj, ignore = []) {
98
- const result = {};
99
- Object.keys(obj).forEach(key => {
100
- if (!ignore.includes(key)) {
101
- result[key] = obj[key];
102
- }
103
- });
104
- return JSON.stringify(result);
105
- }
106
-
107
- // 是否有效值
108
- function validValue(value) {
109
- return (
110
- value !== undefined &&
111
- value !== null &&
112
- value !== ''
113
- );
114
- }
115
-
116
- function checkConfig(prop) {
117
- const filepath = path.join(_basePath, prop);
118
- if (fs.existsSync(filepath)) {
119
- return true;
120
- }
121
-
122
- return false;
123
- }
124
-
125
- function loadConfig(prop) {
126
- const configFile = prop;
127
- const filepath = path.join(_basePath, configFile);
128
- if (!fs.existsSync(filepath)) {
129
- const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
130
- throw new Error(errorTips)
131
- }
132
- const obj = require(filepath);
133
- if (!obj) return obj;
134
-
135
- let ret = obj;
136
- if (is.function(obj) && !is.class(obj)) {
137
- ret = obj();
138
- }
139
-
140
- return ret || {};
141
- };
142
-
143
- function sleep(ms) {
144
- return new Promise(resolve => setTimeout(resolve, ms));
145
- };
146
-
147
- function replaceArgsValue(argv, key, value) {
148
- key = key + "=";
149
- for (let i = 0; i < argv.length; i++) {
150
- let item = argv[i];
151
- let pos = item.indexOf(key);
152
- if (pos !== -1) {
153
- pos = pos + key.length;
154
- let tmpStr = item.substring(0, pos);
155
- argv[i] = tmpStr + value;
156
- break;
157
- }
158
- }
159
-
160
- return argv;
161
- };
162
-
163
- function getValueFromArgv(argv, key) {
164
- const argvObj = parseArgv(argv);
165
- if (argvObj.hasOwnProperty(key)) {
166
- return argvObj[key];
167
- }
168
-
169
- // match search
170
- key = key + "=";
171
- let value;
172
- for (let i = 0; i < argv.length; i++) {
173
- let item = argv[i];
174
- let pos = item.indexOf(key);
175
- if (pos !== -1) {
176
- pos = pos + key.length;
177
- value = item.substring(pos);
178
- break;
179
- }
180
- }
181
-
182
- return value;
183
- };
184
-
185
- function fileIsExist(filepath) {
186
- if (fs.existsSync(filepath) && fs.statSync(filepath).isFile()) {
187
- return true;
188
- }
189
- return false;
190
- };
191
-
192
- module.exports = {
193
- fnDebounce,
194
- getRandomString,
195
- mkdir,
196
- chmodPath,
197
- compareVersion,
198
- middleware,
199
- stringify,
200
- validValue,
201
- checkConfig,
202
- loadConfig,
203
- sleep,
204
- replaceArgsValue,
205
- getValueFromArgv,
206
- fileIsExist
1
+ const fs = require('fs');
2
+ const mkdirp = require('mkdirp');
3
+ const convert = require('koa-convert');
4
+ const is = require('is-type-of');
5
+ const path = require('path');
6
+ const chalk = require('chalk');
7
+ const { parseArgv } = require('./pargv');
8
+
9
+ const _basePath = process.cwd();
10
+
11
+ function fnDebounce() {
12
+ const fnObject = {};
13
+ let timer;
14
+
15
+ return (fn, delayTime, isImediate, args) => {
16
+ const setTimer = () => {
17
+ timer = setTimeout(() => {
18
+ fn(args);
19
+ clearTimeout(timer);
20
+ delete fnObject[fn];
21
+ }, delayTime);
22
+
23
+ fnObject[fn] = { delayTime, timer };
24
+ };
25
+
26
+ if (!delayTime || isImediate) return fn(args);
27
+
28
+ if (fnObject[fn]) {
29
+ clearTimeout(timer);
30
+ setTimer(fn, delayTime, args);
31
+ } else {
32
+ setTimer(fn, delayTime, args);
33
+ }
34
+ };
35
+ }
36
+
37
+ // 随机10位字符串
38
+ function getRandomString() {
39
+ return Math.random().toString(36).substring(2);
40
+ };
41
+
42
+ // 创建文件夹
43
+ function mkdir(filepath, opt = {}) {
44
+ mkdirp.sync(filepath, opt);
45
+ return
46
+ }
47
+
48
+ // 修改文件权限
49
+ function chmodPath(path, mode) {
50
+ let files = [];
51
+ if (fs.existsSync(path)) {
52
+ files = fs.readdirSync(path);
53
+ files.forEach((file, index) => {
54
+ const curPath = path + '/' + file;
55
+ if (fs.statSync(curPath).isDirectory()) {
56
+ this.chmodPath(curPath, mode); // 递归删除文件夹
57
+ } else {
58
+ fs.chmodSync(curPath, mode);
59
+ }
60
+ });
61
+ fs.chmodSync(path, mode);
62
+ }
63
+ };
64
+
65
+ // 版本号比较
66
+ function compareVersion(v1, v2) {
67
+ v1 = v1.split('.')
68
+ v2 = v2.split('.')
69
+ const len = Math.max(v1.length, v2.length)
70
+
71
+ while (v1.length < len) {
72
+ v1.push('0')
73
+ }
74
+ while (v2.length < len) {
75
+ v2.push('0')
76
+ }
77
+
78
+ for (let i = 0; i < len; i++) {
79
+ const num1 = parseInt(v1[i])
80
+ const num2 = parseInt(v2[i])
81
+
82
+ if (num1 > num2) {
83
+ return 1
84
+ } else if (num1 < num2) {
85
+ return -1
86
+ }
87
+ }
88
+
89
+ return 0
90
+ }
91
+
92
+ function middleware(fn) {
93
+ return is.generatorFunction(fn) ? convert(fn) : fn;
94
+ }
95
+
96
+ // 序列化对象
97
+ function stringify(obj, ignore = []) {
98
+ const result = {};
99
+ Object.keys(obj).forEach(key => {
100
+ if (!ignore.includes(key)) {
101
+ result[key] = obj[key];
102
+ }
103
+ });
104
+ return JSON.stringify(result);
105
+ }
106
+
107
+ // 是否有效值
108
+ function validValue(value) {
109
+ return (
110
+ value !== undefined &&
111
+ value !== null &&
112
+ value !== ''
113
+ );
114
+ }
115
+
116
+ function checkConfig(prop) {
117
+ const filepath = path.join(_basePath, prop);
118
+ if (fs.existsSync(filepath)) {
119
+ return true;
120
+ }
121
+
122
+ return false;
123
+ }
124
+
125
+ function loadConfig(prop) {
126
+ const configFile = prop;
127
+ const filepath = path.join(_basePath, configFile);
128
+ if (!fs.existsSync(filepath)) {
129
+ const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
130
+ throw new Error(errorTips)
131
+ }
132
+ const obj = require(filepath);
133
+ if (!obj) return obj;
134
+
135
+ let ret = obj;
136
+ if (is.function(obj) && !is.class(obj)) {
137
+ ret = obj();
138
+ }
139
+
140
+ return ret || {};
141
+ };
142
+
143
+ function sleep(ms) {
144
+ return new Promise(resolve => setTimeout(resolve, ms));
145
+ };
146
+
147
+ function replaceArgsValue(argv, key, value) {
148
+ key = key + "=";
149
+ for (let i = 0; i < argv.length; i++) {
150
+ let item = argv[i];
151
+ let pos = item.indexOf(key);
152
+ if (pos !== -1) {
153
+ pos = pos + key.length;
154
+ let tmpStr = item.substring(0, pos);
155
+ argv[i] = tmpStr + value;
156
+ break;
157
+ }
158
+ }
159
+
160
+ return argv;
161
+ };
162
+
163
+ function getValueFromArgv(argv, key) {
164
+ const argvObj = parseArgv(argv);
165
+ if (argvObj.hasOwnProperty(key)) {
166
+ return argvObj[key];
167
+ }
168
+
169
+ // match search
170
+ key = key + "=";
171
+ let value;
172
+ for (let i = 0; i < argv.length; i++) {
173
+ let item = argv[i];
174
+ let pos = item.indexOf(key);
175
+ if (pos !== -1) {
176
+ pos = pos + key.length;
177
+ value = item.substring(pos);
178
+ break;
179
+ }
180
+ }
181
+
182
+ return value;
183
+ };
184
+
185
+ function fileIsExist(filepath) {
186
+ if (fs.existsSync(filepath) && fs.statSync(filepath).isFile()) {
187
+ return true;
188
+ }
189
+ return false;
190
+ };
191
+
192
+ module.exports = {
193
+ fnDebounce,
194
+ getRandomString,
195
+ mkdir,
196
+ chmodPath,
197
+ compareVersion,
198
+ middleware,
199
+ stringify,
200
+ validValue,
201
+ checkConfig,
202
+ loadConfig,
203
+ sleep,
204
+ replaceArgsValue,
205
+ getValueFromArgv,
206
+ fileIsExist
207
207
  };
package/utils/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export declare function getPackage(): any;
2
- export declare function getMAC(iface: any): string;
3
- export declare function isMAC(macAddress: string): boolean;
4
- export declare function isFileProtocol(protocol: string): boolean;
5
- export declare function isWebProtocol(protocol: string): boolean;
6
- export declare function isJsProject(baseDir: string): boolean;
7
- export declare function machineIdSync(original: boolean): any;
8
- export declare function machineId(original: boolean): Promise<any>;
9
- import is = require("./is");
10
- export { is };
1
+ export declare function getPackage(): any;
2
+ export declare function getMAC(iface: any): string;
3
+ export declare function isMAC(macAddress: string): boolean;
4
+ export declare function isFileProtocol(protocol: string): boolean;
5
+ export declare function isWebProtocol(protocol: string): boolean;
6
+ export declare function isJsProject(baseDir: string): boolean;
7
+ export declare function machineIdSync(original: boolean): any;
8
+ export declare function machineId(original: boolean): Promise<any>;
9
+ import is = require("./is");
10
+ export { is };