ee-core 4.1.3 → 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
@@ -1,78 +1,78 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const MAP = Symbol('Timing#map');
5
- const LIST = Symbol('Timing#list');
6
-
7
- class Timing {
8
-
9
- constructor() {
10
- this._enable = true;
11
- this[MAP] = new Map();
12
- this[LIST] = [];
13
-
14
- this.init();
15
- }
16
-
17
- init() {
18
- // process start time
19
- this.start('Process Start', Date.now() - Math.floor((process.uptime() * 1000)));
20
- this.end('Process Start');
21
-
22
- if (typeof process.scriptStartTime === 'number') {
23
- // js script start execute time
24
- this.start('Script Start', process.scriptStartTime);
25
- this.end('Script Start');
26
- }
27
- }
28
-
29
- start(name, start) {
30
- if (!name || !this._enable) return;
31
-
32
- if (this[MAP].has(name)) this.end(name);
33
-
34
- start = start || Date.now();
35
- const item = {
36
- name,
37
- start,
38
- end: undefined,
39
- duration: undefined,
40
- pid: process.pid,
41
- index: this[LIST].length,
42
- };
43
- this[MAP].set(name, item);
44
- this[LIST].push(item);
45
- return item;
46
- }
47
-
48
- end(name) {
49
- if (!name || !this._enable) return;
50
- assert(this[MAP].has(name), `should run timing.start('${name}') first`);
51
-
52
- const item = this[MAP].get(name);
53
- item.end = Date.now();
54
- item.duration = item.end - item.start;
55
- return item;
56
- }
57
-
58
- enable() {
59
- this._enable = true;
60
- }
61
-
62
- disable() {
63
- this._enable = false;
64
- }
65
-
66
- clear() {
67
- this[MAP].clear();
68
- this[LIST] = [];
69
- }
70
-
71
- toJSON() {
72
- return this[LIST];
73
- }
74
- }
75
-
76
- module.exports = {
77
- Timing
78
- };
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const MAP = Symbol('Timing#map');
5
+ const LIST = Symbol('Timing#list');
6
+
7
+ class Timing {
8
+
9
+ constructor() {
10
+ this._enable = true;
11
+ this[MAP] = new Map();
12
+ this[LIST] = [];
13
+
14
+ this.init();
15
+ }
16
+
17
+ init() {
18
+ // process start time
19
+ this.start('Process Start', Date.now() - Math.floor((process.uptime() * 1000)));
20
+ this.end('Process Start');
21
+
22
+ if (typeof process.scriptStartTime === 'number') {
23
+ // js script start execute time
24
+ this.start('Script Start', process.scriptStartTime);
25
+ this.end('Script Start');
26
+ }
27
+ }
28
+
29
+ start(name, start) {
30
+ if (!name || !this._enable) return;
31
+
32
+ if (this[MAP].has(name)) this.end(name);
33
+
34
+ start = start || Date.now();
35
+ const item = {
36
+ name,
37
+ start,
38
+ end: undefined,
39
+ duration: undefined,
40
+ pid: process.pid,
41
+ index: this[LIST].length,
42
+ };
43
+ this[MAP].set(name, item);
44
+ this[LIST].push(item);
45
+ return item;
46
+ }
47
+
48
+ end(name) {
49
+ if (!name || !this._enable) return;
50
+ assert(this[MAP].has(name), `should run timing.start('${name}') first`);
51
+
52
+ const item = this[MAP].get(name);
53
+ item.end = Date.now();
54
+ item.duration = item.end - item.start;
55
+ return item;
56
+ }
57
+
58
+ enable() {
59
+ this._enable = true;
60
+ }
61
+
62
+ disable() {
63
+ this._enable = false;
64
+ }
65
+
66
+ clear() {
67
+ this[MAP].clear();
68
+ this[LIST] = [];
69
+ }
70
+
71
+ toJSON() {
72
+ return this[LIST];
73
+ }
74
+ }
75
+
76
+ module.exports = {
77
+ Timing
78
+ };
package/cross/cross.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { EventEmitter } from 'node:events';
2
- import { CrossProcess } from "./crossProcess";
3
- import internal = require("stream");
4
- export declare class Cross {
5
- emitter: EventEmitter<[never]>;
6
- children: {};
7
- childrenMap: {};
8
- create(): Promise<void>;
9
- run(service: string, opt?: {}): Promise<CrossProcess>;
10
- killAll(): void;
11
- kill(pid: string|number): void;
12
- killByName(name: string): void;
13
- getUrl(name: string): string;
14
- getProcByName(name: string): CrossProcess;
15
- getProc(pid: string|number): CrossProcess;
16
- getPids(): string[];
17
- _initEventEmitter(): void;
18
- }
19
- export declare let cross: Cross;
1
+ import { EventEmitter } from 'node:events';
2
+ import { CrossProcess } from "./crossProcess";
3
+ import internal = require("stream");
4
+ export declare class Cross {
5
+ emitter: EventEmitter<[never]>;
6
+ children: {};
7
+ childrenMap: {};
8
+ create(): Promise<void>;
9
+ run(service: string, opt?: {}): Promise<CrossProcess>;
10
+ killAll(): void;
11
+ kill(pid: string|number): void;
12
+ killByName(name: string): void;
13
+ getUrl(name: string): string;
14
+ getProcByName(name: string): CrossProcess;
15
+ getProc(pid: string|number): CrossProcess;
16
+ getPids(): string[];
17
+ _initEventEmitter(): void;
18
+ }
19
+ export declare let cross: Cross;
package/cross/cross.js CHANGED
@@ -1,152 +1,152 @@
1
- 'use strict';
2
-
3
- const EventEmitter = require('events');
4
- const { getConfig } = require('../config');
5
- const { sleep, getValueFromArgv, replaceArgsValue } = require('../utils/helper');
6
- const { CrossProcess } = require('./crossProcess');
7
- const { Events } = require('../const/channel');
8
- const { extend } = require('../utils/extend');
9
- const { getPort } = require('../utils/port');
10
-
11
- class Cross {
12
- constructor() {
13
- this.emitter = undefined;
14
-
15
- // pid唯一
16
- // {pid:{name,entity}, pid:{name,entity}, ...}
17
- this.children = {};
18
-
19
- // name唯一
20
- // {name:pid, name:pid, ...}
21
- this.childrenMap = {};
22
-
23
- // eventEmitter
24
- this._initEventEmitter();
25
- }
26
-
27
- async create() {
28
-
29
- // boot services
30
- const crossCfg = getConfig().cross;
31
- //await sleep(5 * 1000);
32
-
33
- for (let key of Object.keys(crossCfg)) {
34
- let val = crossCfg[key];
35
- if (val.enable == true) {
36
- this.run(key)
37
- }
38
- }
39
- }
40
-
41
- // run
42
- async run(service, opt = {}) {
43
- const crossConf = getConfig().cross;
44
- const defaultOpt = crossConf[service] || {};
45
- const targetConf = extend(true, {}, defaultOpt, opt);
46
- if (Object.keys(targetConf).length == 0) {
47
- throw new Error(`[ee-core] [cross] The service [${service}] config does not exit`);
48
- }
49
-
50
- // format params
51
- let tmpArgs = targetConf.args;
52
- let confPort = parseInt(getValueFromArgv(tmpArgs, 'port'));
53
- // 某些程序给它传入不存在的参数时会报错
54
- if (isNaN(confPort) && targetConf.port > 0) {
55
- confPort = targetConf.port;
56
- }
57
- if (confPort > 0) {
58
- // 动态生成port,传入的端口必须为int
59
- confPort = await getPort({ port: confPort });
60
- // 替换port
61
- targetConf.args = replaceArgsValue(tmpArgs, "port", String(confPort));
62
- }
63
-
64
- // 创建进程
65
- const subProcess = new CrossProcess(this, { targetConf, port: confPort });
66
- let uniqueName = targetConf.name;
67
- if (this.childrenMap.hasOwnProperty(uniqueName)) {
68
- uniqueName = uniqueName + "-" + String(subProcess.pid);
69
- }
70
- this.childrenMap[uniqueName] = subProcess.pid;
71
- subProcess.name = uniqueName;
72
- this.children[subProcess.pid] = {
73
- name: uniqueName,
74
- entity: subProcess
75
- };
76
-
77
- return subProcess;
78
- }
79
-
80
- killAll() {
81
- Object.keys(this.children).forEach(pid => {
82
- this.kill(pid)
83
- });
84
- }
85
-
86
- kill(pid) {
87
- const entity = this.getProc(pid);
88
- if (entity) {
89
- entity.kill();
90
- }
91
- }
92
-
93
- killByName(name) {
94
- const entity = this.getProcByName(name);
95
- if (entity) {
96
- entity.kill();
97
- }
98
- }
99
-
100
- getUrl(name) {
101
- const entity = this.getProcByName(name);
102
- const url = entity.getUrl();
103
-
104
- return url;
105
- }
106
-
107
- // 获取 proc
108
- getProcByName(name) {
109
- const pid = this.childrenMap[name];
110
- if (!pid) {
111
- throw new Error(`[ee-core] [cross] The process named [${name}] does not exit`);
112
- }
113
- const entity = this.getProc(pid);
114
-
115
- return entity;
116
- }
117
-
118
- // 获取 proc
119
- getProc(pid) {
120
- const child = this.children[pid];
121
- if (!pid) {
122
- throw new Error(`[ee-core] [cross] The process pid [${pid}] does not exit`);
123
- }
124
-
125
- return child.entity;
126
- }
127
-
128
- // 获取pids
129
- getPids() {
130
- let pids = Object.keys(this.children);
131
- return pids;
132
- }
133
-
134
- _initEventEmitter() {
135
- this.emitter = new EventEmitter();
136
- this.emitter.on(Events.childProcessExit, (data) => {
137
- const child = this.children[data.pid];
138
- delete this.childrenMap[child.name];
139
- delete this.children[data.pid];
140
- });
141
- this.emitter.on(Events.childProcessError, (data) => {
142
- const child = this.children[data.pid];
143
- delete this.childrenMap[child.name];
144
- delete this.children[data.pid];
145
- });
146
- }
147
- }
148
-
149
- module.exports = {
150
- Cross,
151
- cross: new Cross()
1
+ 'use strict';
2
+
3
+ const EventEmitter = require('events');
4
+ const { getConfig } = require('../config');
5
+ const { sleep, getValueFromArgv, replaceArgsValue } = require('../utils/helper');
6
+ const { CrossProcess } = require('./crossProcess');
7
+ const { Events } = require('../const/channel');
8
+ const { extend } = require('../utils/extend');
9
+ const { getPort } = require('../utils/port');
10
+
11
+ class Cross {
12
+ constructor() {
13
+ this.emitter = undefined;
14
+
15
+ // pid唯一
16
+ // {pid:{name,entity}, pid:{name,entity}, ...}
17
+ this.children = {};
18
+
19
+ // name唯一
20
+ // {name:pid, name:pid, ...}
21
+ this.childrenMap = {};
22
+
23
+ // eventEmitter
24
+ this._initEventEmitter();
25
+ }
26
+
27
+ async create() {
28
+
29
+ // boot services
30
+ const crossCfg = getConfig().cross;
31
+ //await sleep(5 * 1000);
32
+
33
+ for (let key of Object.keys(crossCfg)) {
34
+ let val = crossCfg[key];
35
+ if (val.enable == true) {
36
+ this.run(key)
37
+ }
38
+ }
39
+ }
40
+
41
+ // run
42
+ async run(service, opt = {}) {
43
+ const crossConf = getConfig().cross;
44
+ const defaultOpt = crossConf[service] || {};
45
+ const targetConf = extend(true, {}, defaultOpt, opt);
46
+ if (Object.keys(targetConf).length == 0) {
47
+ throw new Error(`[ee-core] [cross] The service [${service}] config does not exit`);
48
+ }
49
+
50
+ // format params
51
+ let tmpArgs = targetConf.args;
52
+ let confPort = parseInt(getValueFromArgv(tmpArgs, 'port'));
53
+ // 某些程序给它传入不存在的参数时会报错
54
+ if (isNaN(confPort) && targetConf.port > 0) {
55
+ confPort = targetConf.port;
56
+ }
57
+ if (confPort > 0) {
58
+ // 动态生成port,传入的端口必须为int
59
+ confPort = await getPort({ port: confPort });
60
+ // 替换port
61
+ targetConf.args = replaceArgsValue(tmpArgs, "port", String(confPort));
62
+ }
63
+
64
+ // 创建进程
65
+ const subProcess = new CrossProcess(this, { targetConf, port: confPort });
66
+ let uniqueName = targetConf.name;
67
+ if (this.childrenMap.hasOwnProperty(uniqueName)) {
68
+ uniqueName = uniqueName + "-" + String(subProcess.pid);
69
+ }
70
+ this.childrenMap[uniqueName] = subProcess.pid;
71
+ subProcess.name = uniqueName;
72
+ this.children[subProcess.pid] = {
73
+ name: uniqueName,
74
+ entity: subProcess
75
+ };
76
+
77
+ return subProcess;
78
+ }
79
+
80
+ killAll() {
81
+ Object.keys(this.children).forEach(pid => {
82
+ this.kill(pid)
83
+ });
84
+ }
85
+
86
+ kill(pid) {
87
+ const entity = this.getProc(pid);
88
+ if (entity) {
89
+ entity.kill();
90
+ }
91
+ }
92
+
93
+ killByName(name) {
94
+ const entity = this.getProcByName(name);
95
+ if (entity) {
96
+ entity.kill();
97
+ }
98
+ }
99
+
100
+ getUrl(name) {
101
+ const entity = this.getProcByName(name);
102
+ const url = entity.getUrl();
103
+
104
+ return url;
105
+ }
106
+
107
+ // 获取 proc
108
+ getProcByName(name) {
109
+ const pid = this.childrenMap[name];
110
+ if (!pid) {
111
+ throw new Error(`[ee-core] [cross] The process named [${name}] does not exit`);
112
+ }
113
+ const entity = this.getProc(pid);
114
+
115
+ return entity;
116
+ }
117
+
118
+ // 获取 proc
119
+ getProc(pid) {
120
+ const child = this.children[pid];
121
+ if (!pid) {
122
+ throw new Error(`[ee-core] [cross] The process pid [${pid}] does not exit`);
123
+ }
124
+
125
+ return child.entity;
126
+ }
127
+
128
+ // 获取pids
129
+ getPids() {
130
+ let pids = Object.keys(this.children);
131
+ return pids;
132
+ }
133
+
134
+ _initEventEmitter() {
135
+ this.emitter = new EventEmitter();
136
+ this.emitter.on(Events.childProcessExit, (data) => {
137
+ const child = this.children[data.pid];
138
+ delete this.childrenMap[child.name];
139
+ delete this.children[data.pid];
140
+ });
141
+ this.emitter.on(Events.childProcessError, (data) => {
142
+ const child = this.children[data.pid];
143
+ delete this.childrenMap[child.name];
144
+ delete this.children[data.pid];
145
+ });
146
+ }
147
+ }
148
+
149
+ module.exports = {
150
+ Cross,
151
+ cross: new Cross()
152
152
  };
@@ -1,29 +1,29 @@
1
- import EventEmitter = require("events");
2
- export declare class CrossProcess {
3
- constructor(host: any, opt?: {});
4
- emitter: EventEmitter<[never]>;
5
- host: any;
6
- child: any;
7
- pid: number;
8
- port: number;
9
- name: string;
10
- config: {};
11
- /**
12
- * 初始化子进程
13
- */
14
- _init(options?: {}): void;
15
- /**
16
- * kill
17
- */
18
- kill(timeout?: number): void;
19
- getUrl(): string;
20
- getArgsObj(): {
21
- _: any[];
22
- };
23
- setPort(port: string|number): void;
24
- _generateId(): string;
25
- /**
26
- * exit electron
27
- */
28
- _exitElectron(timeout?: number): void;
29
- }
1
+ import EventEmitter = require("events");
2
+ export declare class CrossProcess {
3
+ constructor(host: any, opt?: {});
4
+ emitter: EventEmitter<[never]>;
5
+ host: any;
6
+ child: any;
7
+ pid: number;
8
+ port: number;
9
+ name: string;
10
+ config: {};
11
+ /**
12
+ * 初始化子进程
13
+ */
14
+ _init(options?: {}): void;
15
+ /**
16
+ * kill
17
+ */
18
+ kill(timeout?: number): void;
19
+ getUrl(): string;
20
+ getArgsObj(): {
21
+ _: any[];
22
+ };
23
+ setPort(port: string|number): void;
24
+ _generateId(): string;
25
+ /**
26
+ * exit electron
27
+ */
28
+ _exitElectron(timeout?: number): void;
29
+ }