ee-core 4.0.0-beta.1 → 4.0.1
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/app/application.d.ts +5 -0
- package/app/boot.d.ts +5 -0
- package/app/boot.js +0 -7
- package/app/dir.d.ts +1 -0
- package/app/events.d.ts +14 -0
- package/app/index.d.ts +2 -0
- package/config/config_loader.d.ts +13 -0
- package/config/default_config.d.ts +95 -0
- package/config/default_config.js +2 -1
- package/config/index.d.ts +28 -0
- package/const/channel.d.ts +16 -0
- package/const/channel.js +1 -1
- package/controller/controller_loader.d.ts +9 -0
- package/controller/index.d.ts +2 -0
- package/core/index.d.ts +2 -0
- package/core/loader/file_loader.d.ts +66 -0
- package/core/utils/index.d.ts +12 -0
- package/core/utils/timing.d.ts +22 -0
- package/cross/cross.d.ts +19 -0
- package/cross/cross.js +5 -5
- package/cross/crossProcess.d.ts +29 -0
- package/cross/{spawnProcess.js → crossProcess.js} +12 -7
- package/cross/index.d.ts +2 -0
- package/cross/index.js +2 -2
- package/electron/app/index.d.ts +5 -0
- package/electron/index.d.ts +3 -0
- package/electron/window/index.d.ts +6 -0
- package/exception/index.d.ts +9 -0
- package/exception/index.js +8 -22
- package/html/index.d.ts +1 -0
- package/index.d.ts +2 -0
- package/jobs/child/app.d.ts +1 -0
- package/jobs/child/index.d.ts +13 -0
- package/jobs/child/index.js +2 -2
- package/jobs/child/jobProcess.d.ts +16 -0
- package/jobs/child/{forkProcess.js → jobProcess.js} +3 -18
- package/jobs/child-pool/index.d.ts +26 -0
- package/jobs/child-pool/index.js +13 -38
- package/jobs/index.d.ts +3 -0
- package/jobs/load-balancer/algorithm/index.d.ts +4 -0
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/random.d.ts +2 -0
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
- package/jobs/load-balancer/consts.d.ts +8 -0
- package/jobs/load-balancer/index.d.ts +96 -0
- package/jobs/load-balancer/scheduler.d.ts +16 -0
- package/loader/index.d.ts +9 -0
- package/loader/index.js +4 -22
- package/log/index.d.ts +5 -0
- package/log/logger.d.ts +2 -0
- package/message/childMessage.d.ts +10 -0
- package/message/childMessage.js +2 -12
- package/message/index.d.ts +3 -0
- package/package.json +8 -1
- package/ps/index.d.ts +37 -0
- package/ps/index.js +2 -12
- package/socket/httpServer.d.ts +8 -0
- package/socket/httpServer.js +10 -3
- package/socket/index.d.ts +10 -0
- package/socket/ipcServer.d.ts +9 -0
- package/socket/ipcServer.js +13 -6
- package/socket/socketServer.d.ts +10 -0
- package/socket/socketServer.js +7 -2
- package/storage/index.d.ts +5 -0
- package/storage/sqliteStorage.d.ts +16 -0
- package/storage/sqliteStorage.js +2 -2
- package/tsconfig.json +14 -0
- package/utils/extend.d.ts +2 -0
- package/utils/helper.d.ts +14 -0
- package/utils/helper.js +1 -11
- package/utils/index.d.ts +10 -0
- package/utils/index.js +7 -17
- package/utils/ip.d.ts +2 -0
- package/utils/is.d.ts +14 -0
- package/utils/json.d.ts +5 -0
- package/utils/pargv.d.ts +3 -0
- package/utils/port/index.d.ts +1 -0
- package/utils/wrap.d.ts +4 -0
- package/const/index.js +0 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import IoServer = require("socket.io");
|
|
2
|
+
import IoClient = require("socket.io-client");
|
|
3
|
+
import { HttpServer } from './httpServer';
|
|
4
|
+
import { IpcServer } from './ipcServer';
|
|
5
|
+
import { SocketServer } from './socketServer';
|
|
6
|
+
export declare function loadSocket(): void;
|
|
7
|
+
export declare function getSocketServer(): SocketServer;
|
|
8
|
+
export declare function getHttpServer(): HttpServer;
|
|
9
|
+
export declare function getIpcServer(): IpcServer;
|
|
10
|
+
export { IoServer, IoClient };
|
package/socket/ipcServer.js
CHANGED
|
@@ -6,12 +6,19 @@ const { ipcMain } = require('electron');
|
|
|
6
6
|
const { coreLogger } = require('../log');
|
|
7
7
|
const { getController } = require('../controller');
|
|
8
8
|
const { EXPORTS } = require('../core/loader/file_loader');
|
|
9
|
+
const { getConfig } = require('../config');
|
|
9
10
|
|
|
10
11
|
class IpcServer {
|
|
11
12
|
constructor () {
|
|
13
|
+
const { mainServer } = getConfig();
|
|
14
|
+
this.channelSeparator = mainServer.channelSeparator;
|
|
12
15
|
this.directory = 'controller';
|
|
13
16
|
this.init();
|
|
14
17
|
}
|
|
18
|
+
init() {
|
|
19
|
+
const controller = getController();
|
|
20
|
+
this.loop(controller, this.directory);
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
loop(obj, pathname) {
|
|
17
24
|
const keys = Object.keys(obj);
|
|
@@ -35,7 +42,10 @@ class IpcServer {
|
|
|
35
42
|
const controller = getController();
|
|
36
43
|
const keys = Object.keys(exportObj);
|
|
37
44
|
for (const key of keys) {
|
|
38
|
-
|
|
45
|
+
// Supports two types of routing separators
|
|
46
|
+
// channel: controller.file.function | controller/file/function
|
|
47
|
+
const tmpChannel = `${propertyChain}.${key}`;
|
|
48
|
+
const channel = tmpChannel.split('.').join(this.channelSeparator);
|
|
39
49
|
debug('[register] channel %s', channel);
|
|
40
50
|
|
|
41
51
|
// send/on model
|
|
@@ -71,7 +81,8 @@ class IpcServer {
|
|
|
71
81
|
const cmd = c;
|
|
72
82
|
let fn = null;
|
|
73
83
|
if (is.string(cmd)) {
|
|
74
|
-
const actions = cmd.split(
|
|
84
|
+
const actions = cmd.split(this.channelSeparator);
|
|
85
|
+
debug('[findFn] channel %o', actions);
|
|
75
86
|
let obj = { controller };
|
|
76
87
|
actions.forEach(key => {
|
|
77
88
|
obj = obj[key];
|
|
@@ -88,10 +99,6 @@ class IpcServer {
|
|
|
88
99
|
return null;
|
|
89
100
|
}
|
|
90
101
|
|
|
91
|
-
init() {
|
|
92
|
-
const controller = getController();
|
|
93
|
-
this.loop(controller, this.directory);
|
|
94
|
-
}
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
module.exports = {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Server } from "socket.io";
|
|
2
|
+
import { DefaultEventsMap } from "socket.io/dist/typed-events";
|
|
3
|
+
export declare class SocketServer {
|
|
4
|
+
socket: import("socket.io").Socket<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>;
|
|
5
|
+
io: Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>;
|
|
6
|
+
config: any;
|
|
7
|
+
init(): Promise<void>;
|
|
8
|
+
connect(): void;
|
|
9
|
+
}
|
|
10
|
+
|
package/socket/socketServer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const debug = require('debug')('ee-core:socket:socketServer');
|
|
3
4
|
const is = require('is-type-of');
|
|
4
5
|
const { Server } = require('socket.io');
|
|
5
6
|
const { coreLogger } = require('../log');
|
|
@@ -13,9 +14,11 @@ const { getPort } = require('../utils/port');
|
|
|
13
14
|
*/
|
|
14
15
|
class SocketServer {
|
|
15
16
|
constructor () {
|
|
17
|
+
const { socketServer, mainServer } = getConfig();
|
|
18
|
+
this.config = socketServer;
|
|
19
|
+
this.channelSeparator = mainServer.channelSeparator;
|
|
16
20
|
this.socket = undefined;
|
|
17
21
|
this.io = undefined;
|
|
18
|
-
this.config = getConfig().socketServer;
|
|
19
22
|
this.init();
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -49,8 +52,10 @@ class SocketServer {
|
|
|
49
52
|
const cmd = message.cmd;
|
|
50
53
|
const args = message.args;
|
|
51
54
|
let fn = null;
|
|
55
|
+
debug('[socket] channel %s', cmd);
|
|
52
56
|
if (is.string(cmd)) {
|
|
53
|
-
const actions = cmd.split(
|
|
57
|
+
const actions = cmd.split(this.channelSeparator);
|
|
58
|
+
debug('[findFn] channel %o', actions);
|
|
54
59
|
let obj = { controller };
|
|
55
60
|
actions.forEach(key => {
|
|
56
61
|
obj = obj[key];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
import { Database } from "better-sqlite3";
|
|
3
|
+
export declare class SqliteStorage {
|
|
4
|
+
constructor(name: any, opt?: {});
|
|
5
|
+
name: string;
|
|
6
|
+
mode: string;
|
|
7
|
+
dbDir: string;
|
|
8
|
+
fileName: string;
|
|
9
|
+
db: Database;
|
|
10
|
+
_initDB(opt?: {}): any;
|
|
11
|
+
_formatFileName(name: string): string;
|
|
12
|
+
_createDatabaseDir(): string;
|
|
13
|
+
getMode(name: string): string;
|
|
14
|
+
getDbDir(): string;
|
|
15
|
+
getFilePath(): string;
|
|
16
|
+
}
|
package/storage/sqliteStorage.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const assert = require('assert');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
|
-
const
|
|
6
|
+
const BSqlite = require('better-sqlite3');
|
|
7
7
|
const { mkdir } = require('../utils/helper');
|
|
8
8
|
const { getDataDir } = require('../ps');
|
|
9
9
|
|
|
@@ -32,7 +32,7 @@ class SqliteStorage {
|
|
|
32
32
|
dbPath = this.getFilePath();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const db = new
|
|
35
|
+
const db = new BSqlite(dbPath, options);
|
|
36
36
|
|
|
37
37
|
// 如果是文件类型,判断文件是否创建成功
|
|
38
38
|
if (this.mode != 'memory') {
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"skipLibCheck": true,
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"emitDeclarationOnly": true,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "types",
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"index.js", "app", "config", "const", "controller", "core", "cross", "electron", "exception",
|
|
11
|
+
"html", "jobs", "loader", "log", "message", "ps", "socket", "storage", "utils",
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function fnDebounce(): (fn: any, delayTime: any, isImediate: any, args: any) => any;
|
|
2
|
+
export declare function getRandomString(): string;
|
|
3
|
+
export declare function mkdir(filepath: string, opt?: {}): void;
|
|
4
|
+
export declare function chmodPath(path: string, mode: number | string): void;
|
|
5
|
+
export declare function compareVersion(v1: string, v2: string): 0 | 1 | -1;
|
|
6
|
+
export declare function middleware(fn: Function): any;
|
|
7
|
+
export declare function stringify(obj: any, ignore?: any[]): string;
|
|
8
|
+
export declare function validValue(value: any): boolean;
|
|
9
|
+
export declare function checkConfig(prop: any): boolean;
|
|
10
|
+
export declare function loadConfig(prop: any): any;
|
|
11
|
+
export declare function sleep(ms: number): Promise<any>;
|
|
12
|
+
export declare function replaceArgsValue(argv: any, key: any, value: any): any;
|
|
13
|
+
export declare function getValueFromArgv(argv: any, key: any): any;
|
|
14
|
+
export declare function fileIsExist(filepath: string): boolean;
|
package/utils/helper.js
CHANGED
|
@@ -8,14 +8,6 @@ const { parseArgv } = require('./pargv');
|
|
|
8
8
|
|
|
9
9
|
const _basePath = process.cwd();
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* fnDebounce
|
|
13
|
-
*
|
|
14
|
-
* @param {Function} fn - 回调函数
|
|
15
|
-
* @param {Time} delayTime - 延迟时间(ms)
|
|
16
|
-
* @param {Boolean} isImediate - 是否需要立即调用
|
|
17
|
-
* @param {type} args - 回调函数传入参数
|
|
18
|
-
*/
|
|
19
11
|
function fnDebounce() {
|
|
20
12
|
const fnObject = {};
|
|
21
13
|
let timer;
|
|
@@ -112,9 +104,7 @@ function stringify(obj, ignore = []) {
|
|
|
112
104
|
return JSON.stringify(result);
|
|
113
105
|
}
|
|
114
106
|
|
|
115
|
-
|
|
116
|
-
* 是否有效值
|
|
117
|
-
*/
|
|
107
|
+
// 是否有效值
|
|
118
108
|
function validValue(value) {
|
|
119
109
|
return (
|
|
120
110
|
value !== undefined &&
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +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 };
|
package/utils/index.js
CHANGED
|
@@ -24,19 +24,15 @@ const MachineGuid = {
|
|
|
24
24
|
freebsd: 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid'
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
* 获取项目根目录package.json
|
|
29
|
-
*/
|
|
27
|
+
// 获取项目根目录package.json
|
|
30
28
|
function getPackage() {
|
|
31
29
|
const json = readSync(path.join(getBaseDir(), 'package.json'));
|
|
32
30
|
|
|
33
31
|
return json;
|
|
34
32
|
};
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* @param iface If provided, restrict MAC address fetching to this interface
|
|
39
|
-
*/
|
|
34
|
+
// Get the first proper MAC address
|
|
35
|
+
// iface: If provided, restrict MAC address fetching to this interface
|
|
40
36
|
function getMAC(iface) {
|
|
41
37
|
const zeroRegex = /(?:[0]{1,2}[:-]){5}[0]{1,2}/;
|
|
42
38
|
const list = os.networkInterfaces();
|
|
@@ -68,9 +64,7 @@ function getMAC(iface) {
|
|
|
68
64
|
throw new Error('failed to get the MAC address');
|
|
69
65
|
}
|
|
70
66
|
|
|
71
|
-
|
|
72
|
-
* Check if the input is a valid MAC address
|
|
73
|
-
*/
|
|
67
|
+
// Check if the input is a valid MAC address
|
|
74
68
|
function isMAC(macAddress) {
|
|
75
69
|
const macRegex = /(?:[a-z0-9]{1,2}[:-]){5}[a-z0-9]{1,2}/i;
|
|
76
70
|
return macRegex.test(macAddress);
|
|
@@ -93,18 +87,14 @@ function isJsProject(baseDir) {
|
|
|
93
87
|
return false;
|
|
94
88
|
}
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
* get machine id
|
|
98
|
-
*/
|
|
90
|
+
// get machine id
|
|
99
91
|
function machineIdSync(original) {
|
|
100
92
|
let id = _expose(execSync(MachineGuid[platform]).toString());
|
|
101
93
|
return original ? id : _hash(id);
|
|
102
94
|
}
|
|
103
95
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
* original <Boolean>, If true return original value of machine id, otherwise return hashed value (sha-256), default: false
|
|
107
|
-
*/
|
|
96
|
+
// get machine id (promise)
|
|
97
|
+
// original <Boolean>, If true return original value of machine id, otherwise return hashed value (sha-256), default: false
|
|
108
98
|
function machineId(original) {
|
|
109
99
|
return new Promise((resolve, reject) => {
|
|
110
100
|
return exec(MachineGuid[platform], {}, (err, stdout, stderr) => {
|
package/utils/ip.d.ts
ADDED
package/utils/is.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function renderer(): boolean;
|
|
2
|
+
export declare function main(): boolean;
|
|
3
|
+
export declare function osx(): boolean;
|
|
4
|
+
export declare function macOS(): boolean;
|
|
5
|
+
export declare function windows(): boolean;
|
|
6
|
+
export declare function linux(): boolean;
|
|
7
|
+
export declare function x86(): boolean;
|
|
8
|
+
export declare function x64(): boolean;
|
|
9
|
+
export declare function sandbox(): boolean;
|
|
10
|
+
export declare function mas(): boolean;
|
|
11
|
+
export declare function windowsStore(): boolean;
|
|
12
|
+
export declare function all(...args: any[]): boolean;
|
|
13
|
+
export declare function none(...args: any[]): boolean;
|
|
14
|
+
export declare function one(...args: any[]): boolean;
|
package/utils/json.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function strictParse(str: string): {};
|
|
2
|
+
export declare function readSync(filepath: string): any;
|
|
3
|
+
export declare function writeSync(filepath: string, str: string, options: any): void;
|
|
4
|
+
export declare function read(filepath: string): any;
|
|
5
|
+
export declare function write(filepath: string, str: string, options: any): Promise<void>;
|
package/utils/pargv.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPort(options?: any): Promise<any>;
|
package/utils/wrap.d.ts
ADDED