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.
- package/LICENSE +21 -21
- package/README.md +65 -65
- package/app/application.d.ts +5 -5
- package/app/application.js +30 -30
- package/app/boot.d.ts +5 -5
- package/app/boot.js +80 -80
- package/app/dir.d.ts +1 -1
- package/app/dir.js +26 -26
- package/app/events.d.ts +14 -14
- package/app/events.js +55 -55
- package/app/index.d.ts +2 -2
- package/app/index.js +6 -6
- package/config/config_loader.d.ts +13 -13
- package/config/config_loader.js +65 -65
- package/config/default_config.d.ts +95 -95
- package/config/default_config.js +111 -111
- package/config/index.d.ts +28 -28
- package/config/index.js +24 -24
- package/const/channel.d.ts +16 -16
- package/const/channel.js +27 -27
- package/controller/controller_loader.d.ts +9 -9
- package/controller/controller_loader.js +77 -77
- package/controller/index.d.ts +2 -2
- package/controller/index.js +24 -24
- package/core/index.d.ts +2 -2
- package/core/index.js +11 -11
- package/core/loader/file_loader.d.ts +66 -66
- package/core/loader/file_loader.js +211 -211
- package/core/utils/index.d.ts +12 -12
- package/core/utils/index.js +83 -83
- package/core/utils/timing.d.ts +22 -22
- package/core/utils/timing.js +78 -78
- package/cross/cross.d.ts +19 -19
- package/cross/cross.js +151 -151
- package/cross/crossProcess.d.ts +29 -29
- package/cross/crossProcess.js +172 -172
- package/cross/index.d.ts +2 -2
- package/cross/index.js +8 -8
- package/electron/app/index.d.ts +5 -5
- package/electron/app/index.js +48 -48
- package/electron/index.d.ts +3 -3
- package/electron/index.js +15 -15
- package/electron/window/index.d.ts +6 -6
- package/electron/window/index.js +268 -268
- package/exception/index.d.ts +9 -9
- package/exception/index.js +100 -100
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.d.ts +1 -1
- package/html/index.js +10 -10
- package/index.d.ts +2 -2
- package/index.js +6 -6
- package/jobs/child/app.d.ts +1 -1
- package/jobs/child/app.js +69 -69
- package/jobs/child/index.d.ts +13 -13
- package/jobs/child/index.js +85 -85
- package/jobs/child/jobProcess.d.ts +16 -16
- package/jobs/child/jobProcess.js +133 -133
- package/jobs/child-pool/index.d.ts +26 -26
- package/jobs/child-pool/index.js +190 -190
- package/jobs/index.d.ts +3 -3
- package/jobs/index.js +6 -6
- package/jobs/load-balancer/algorithm/index.d.ts +4 -4
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -2
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -2
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.d.ts +2 -2
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -2
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -2
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.d.ts +8 -8
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.d.ts +96 -96
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.d.ts +16 -16
- package/jobs/load-balancer/scheduler.js +31 -31
- package/loader/index.d.ts +9 -9
- package/loader/index.js +99 -98
- package/log/index.d.ts +5 -5
- package/log/index.js +85 -85
- package/log/logger.d.ts +1 -1
- package/log/logger.js +94 -94
- package/message/childMessage.d.ts +10 -10
- package/message/childMessage.js +43 -43
- package/message/index.d.ts +3 -3
- package/message/index.js +9 -9
- package/package.json +42 -42
- package/ps/index.d.ts +39 -39
- package/ps/index.js +294 -294
- package/socket/httpServer.d.ts +8 -8
- package/socket/httpServer.js +199 -199
- package/socket/index.d.ts +10 -10
- package/socket/index.js +64 -64
- package/socket/ipcServer.d.ts +9 -9
- package/socket/ipcServer.js +105 -105
- package/socket/socketServer.d.ts +10 -10
- package/socket/socketServer.js +81 -81
- package/storage/index.d.ts +4 -4
- package/storage/index.js +6 -6
- package/storage/sqliteStorage.d.ts +16 -16
- package/storage/sqliteStorage.js +123 -123
- package/tsconfig.json +13 -13
- package/utils/extend.d.ts +2 -2
- package/utils/extend.js +77 -77
- package/utils/helper.d.ts +14 -14
- package/utils/helper.js +206 -206
- package/utils/index.d.ts +10 -10
- package/utils/index.js +167 -167
- package/utils/ip.d.ts +2 -2
- package/utils/ip.js +221 -221
- package/utils/is.d.ts +14 -14
- package/utils/is.js +111 -111
- package/utils/json.d.ts +5 -5
- package/utils/json.js +79 -79
- package/utils/pargv.d.ts +3 -3
- package/utils/pargv.js +267 -267
- package/utils/port/index.d.ts +1 -1
- package/utils/port/index.js +125 -125
- package/utils/wrap.d.ts +4 -4
- package/utils/wrap.js +40 -40
package/utils/port/index.js
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const net = require('net');
|
|
3
|
-
const os = require('os');
|
|
4
|
-
|
|
5
|
-
class Locked extends Error {
|
|
6
|
-
constructor(port) {
|
|
7
|
-
super(`${port} is locked`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const lockedPorts = {
|
|
12
|
-
old: new Set(),
|
|
13
|
-
young: new Set()
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// On this interval, the old locked ports are discarded,
|
|
17
|
-
// the young locked ports are moved to old locked ports,
|
|
18
|
-
// and a new young set for locked ports are created.
|
|
19
|
-
const releaseOldLockedPortsIntervalMs = 1000 * 15;
|
|
20
|
-
|
|
21
|
-
// Lazily create interval on first use
|
|
22
|
-
let interval;
|
|
23
|
-
|
|
24
|
-
const getLocalHosts = () => {
|
|
25
|
-
const interfaces = os.networkInterfaces();
|
|
26
|
-
|
|
27
|
-
// Add undefined value for createServer function to use default host,
|
|
28
|
-
// and default IPv4 host in case createServer defaults to IPv6.
|
|
29
|
-
const results = new Set([undefined, '0.0.0.0']);
|
|
30
|
-
|
|
31
|
-
for (const _interface of Object.values(interfaces)) {
|
|
32
|
-
for (const config of _interface) {
|
|
33
|
-
results.add(config.address);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return results;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const checkAvailablePort = options =>
|
|
41
|
-
new Promise((resolve, reject) => {
|
|
42
|
-
const server = net.createServer();
|
|
43
|
-
server.unref();
|
|
44
|
-
server.on('error', reject);
|
|
45
|
-
|
|
46
|
-
server.listen(options, () => {
|
|
47
|
-
const {port} = server.address();
|
|
48
|
-
server.close(() => {
|
|
49
|
-
resolve(port);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const getAvailablePort = async (options, hosts) => {
|
|
55
|
-
if (options.host || options.port === 0) {
|
|
56
|
-
return checkAvailablePort(options);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for (const host of hosts) {
|
|
60
|
-
try {
|
|
61
|
-
await checkAvailablePort({port: options.port, host}); // eslint-disable-line no-await-in-loop
|
|
62
|
-
} catch (error) {
|
|
63
|
-
if (!['EADDRNOTAVAIL', 'EINVAL'].includes(error.code)) {
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return options.port;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const portCheckSequence = function * (ports) {
|
|
73
|
-
if (ports) {
|
|
74
|
-
yield * ports;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
yield 0; // Fall back to 0 if anything else failed
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
async function getPort(options) {
|
|
81
|
-
let ports;
|
|
82
|
-
|
|
83
|
-
if (options) {
|
|
84
|
-
ports = typeof options.port === 'number' ? [options.port] : options.port;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (interval === undefined) {
|
|
88
|
-
interval = setInterval(() => {
|
|
89
|
-
lockedPorts.old = lockedPorts.young;
|
|
90
|
-
lockedPorts.young = new Set();
|
|
91
|
-
}, releaseOldLockedPortsIntervalMs);
|
|
92
|
-
|
|
93
|
-
// Does not exist in some environments (Electron, Jest jsdom env, browser, etc).
|
|
94
|
-
if (interval.unref) {
|
|
95
|
-
interval.unref();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const hosts = getLocalHosts();
|
|
100
|
-
|
|
101
|
-
for (const port of portCheckSequence(ports)) {
|
|
102
|
-
try {
|
|
103
|
-
let availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
104
|
-
while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
|
|
105
|
-
if (port !== 0) {
|
|
106
|
-
throw new Locked(port);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
lockedPorts.young.add(availablePort);
|
|
113
|
-
return availablePort;
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (!['EADDRINUSE', 'EACCES'].includes(error.code) && !(error instanceof Locked)) {
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
throw new Error('No available ports found');
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
module.exports = {
|
|
125
|
-
getPort
|
|
1
|
+
'use strict';
|
|
2
|
+
const net = require('net');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
class Locked extends Error {
|
|
6
|
+
constructor(port) {
|
|
7
|
+
super(`${port} is locked`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const lockedPorts = {
|
|
12
|
+
old: new Set(),
|
|
13
|
+
young: new Set()
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// On this interval, the old locked ports are discarded,
|
|
17
|
+
// the young locked ports are moved to old locked ports,
|
|
18
|
+
// and a new young set for locked ports are created.
|
|
19
|
+
const releaseOldLockedPortsIntervalMs = 1000 * 15;
|
|
20
|
+
|
|
21
|
+
// Lazily create interval on first use
|
|
22
|
+
let interval;
|
|
23
|
+
|
|
24
|
+
const getLocalHosts = () => {
|
|
25
|
+
const interfaces = os.networkInterfaces();
|
|
26
|
+
|
|
27
|
+
// Add undefined value for createServer function to use default host,
|
|
28
|
+
// and default IPv4 host in case createServer defaults to IPv6.
|
|
29
|
+
const results = new Set([undefined, '0.0.0.0']);
|
|
30
|
+
|
|
31
|
+
for (const _interface of Object.values(interfaces)) {
|
|
32
|
+
for (const config of _interface) {
|
|
33
|
+
results.add(config.address);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return results;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const checkAvailablePort = options =>
|
|
41
|
+
new Promise((resolve, reject) => {
|
|
42
|
+
const server = net.createServer();
|
|
43
|
+
server.unref();
|
|
44
|
+
server.on('error', reject);
|
|
45
|
+
|
|
46
|
+
server.listen(options, () => {
|
|
47
|
+
const {port} = server.address();
|
|
48
|
+
server.close(() => {
|
|
49
|
+
resolve(port);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const getAvailablePort = async (options, hosts) => {
|
|
55
|
+
if (options.host || options.port === 0) {
|
|
56
|
+
return checkAvailablePort(options);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const host of hosts) {
|
|
60
|
+
try {
|
|
61
|
+
await checkAvailablePort({port: options.port, host}); // eslint-disable-line no-await-in-loop
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (!['EADDRNOTAVAIL', 'EINVAL'].includes(error.code)) {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return options.port;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const portCheckSequence = function * (ports) {
|
|
73
|
+
if (ports) {
|
|
74
|
+
yield * ports;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
yield 0; // Fall back to 0 if anything else failed
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
async function getPort(options) {
|
|
81
|
+
let ports;
|
|
82
|
+
|
|
83
|
+
if (options) {
|
|
84
|
+
ports = typeof options.port === 'number' ? [options.port] : options.port;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (interval === undefined) {
|
|
88
|
+
interval = setInterval(() => {
|
|
89
|
+
lockedPorts.old = lockedPorts.young;
|
|
90
|
+
lockedPorts.young = new Set();
|
|
91
|
+
}, releaseOldLockedPortsIntervalMs);
|
|
92
|
+
|
|
93
|
+
// Does not exist in some environments (Electron, Jest jsdom env, browser, etc).
|
|
94
|
+
if (interval.unref) {
|
|
95
|
+
interval.unref();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const hosts = getLocalHosts();
|
|
100
|
+
|
|
101
|
+
for (const port of portCheckSequence(ports)) {
|
|
102
|
+
try {
|
|
103
|
+
let availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
104
|
+
while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
|
|
105
|
+
if (port !== 0) {
|
|
106
|
+
throw new Locked(port);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
availablePort = await getAvailablePort({...options, port}, hosts); // eslint-disable-line no-await-in-loop
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
lockedPorts.young.add(availablePort);
|
|
113
|
+
return availablePort;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (!['EADDRINUSE', 'EACCES'].includes(error.code) && !(error instanceof Locked)) {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
throw new Error('No available ports found');
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
module.exports = {
|
|
125
|
+
getPort
|
|
126
126
|
}
|
package/utils/wrap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function getProperties(filepath: any, { caseStyle }: {
|
|
2
|
-
caseStyle: any;
|
|
3
|
-
}): any;
|
|
4
|
-
export declare function defaultCamelize(filepath: any, caseStyle: any): any;
|
|
1
|
+
export declare function getProperties(filepath: any, { caseStyle }: {
|
|
2
|
+
caseStyle: any;
|
|
3
|
+
}): any;
|
|
4
|
+
export declare function defaultCamelize(filepath: any, caseStyle: any): any;
|
package/utils/wrap.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const is = require('is-type-of');
|
|
3
|
-
|
|
4
|
-
function getProperties(filepath, { caseStyle }) {
|
|
5
|
-
// if caseStyle is function, return the result of function
|
|
6
|
-
if (is.function(caseStyle)) {
|
|
7
|
-
const result = caseStyle(filepath);
|
|
8
|
-
assert(is.array(result), `caseStyle expect an array, but got ${result}`);
|
|
9
|
-
return result;
|
|
10
|
-
}
|
|
11
|
-
// use default camelize
|
|
12
|
-
return defaultCamelize(filepath, caseStyle);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function defaultCamelize(filepath, caseStyle) {
|
|
16
|
-
const properties = filepath.substring(0, filepath.lastIndexOf('.')).split('/');
|
|
17
|
-
return properties.map(property => {
|
|
18
|
-
if (!/^[a-z][a-z0-9_-]*$/i.test(property)) {
|
|
19
|
-
throw new Error(`${property} is not match 'a-z0-9_-' in ${filepath}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
|
|
23
|
-
let first = property[0];
|
|
24
|
-
switch (caseStyle) {
|
|
25
|
-
case 'lower':
|
|
26
|
-
first = first.toLowerCase();
|
|
27
|
-
break;
|
|
28
|
-
case 'upper':
|
|
29
|
-
first = first.toUpperCase();
|
|
30
|
-
break;
|
|
31
|
-
case 'camel':
|
|
32
|
-
default:
|
|
33
|
-
}
|
|
34
|
-
return first + property.substring(1);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = {
|
|
39
|
-
getProperties,
|
|
40
|
-
defaultCamelize,
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const is = require('is-type-of');
|
|
3
|
+
|
|
4
|
+
function getProperties(filepath, { caseStyle }) {
|
|
5
|
+
// if caseStyle is function, return the result of function
|
|
6
|
+
if (is.function(caseStyle)) {
|
|
7
|
+
const result = caseStyle(filepath);
|
|
8
|
+
assert(is.array(result), `caseStyle expect an array, but got ${result}`);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
// use default camelize
|
|
12
|
+
return defaultCamelize(filepath, caseStyle);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function defaultCamelize(filepath, caseStyle) {
|
|
16
|
+
const properties = filepath.substring(0, filepath.lastIndexOf('.')).split('/');
|
|
17
|
+
return properties.map(property => {
|
|
18
|
+
if (!/^[a-z][a-z0-9_-]*$/i.test(property)) {
|
|
19
|
+
throw new Error(`${property} is not match 'a-z0-9_-' in ${filepath}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
|
|
23
|
+
let first = property[0];
|
|
24
|
+
switch (caseStyle) {
|
|
25
|
+
case 'lower':
|
|
26
|
+
first = first.toLowerCase();
|
|
27
|
+
break;
|
|
28
|
+
case 'upper':
|
|
29
|
+
first = first.toUpperCase();
|
|
30
|
+
break;
|
|
31
|
+
case 'camel':
|
|
32
|
+
default:
|
|
33
|
+
}
|
|
34
|
+
return first + property.substring(1);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
getProperties,
|
|
40
|
+
defaultCamelize,
|
|
41
41
|
}
|