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.
Files changed (84) hide show
  1. package/app/application.d.ts +5 -0
  2. package/app/boot.d.ts +5 -0
  3. package/app/boot.js +0 -7
  4. package/app/dir.d.ts +1 -0
  5. package/app/events.d.ts +14 -0
  6. package/app/index.d.ts +2 -0
  7. package/config/config_loader.d.ts +13 -0
  8. package/config/default_config.d.ts +95 -0
  9. package/config/default_config.js +2 -1
  10. package/config/index.d.ts +28 -0
  11. package/const/channel.d.ts +16 -0
  12. package/const/channel.js +1 -1
  13. package/controller/controller_loader.d.ts +9 -0
  14. package/controller/index.d.ts +2 -0
  15. package/core/index.d.ts +2 -0
  16. package/core/loader/file_loader.d.ts +66 -0
  17. package/core/utils/index.d.ts +12 -0
  18. package/core/utils/timing.d.ts +22 -0
  19. package/cross/cross.d.ts +19 -0
  20. package/cross/cross.js +5 -5
  21. package/cross/crossProcess.d.ts +29 -0
  22. package/cross/{spawnProcess.js → crossProcess.js} +12 -7
  23. package/cross/index.d.ts +2 -0
  24. package/cross/index.js +2 -2
  25. package/electron/app/index.d.ts +5 -0
  26. package/electron/index.d.ts +3 -0
  27. package/electron/window/index.d.ts +6 -0
  28. package/exception/index.d.ts +9 -0
  29. package/exception/index.js +8 -22
  30. package/html/index.d.ts +1 -0
  31. package/index.d.ts +2 -0
  32. package/jobs/child/app.d.ts +1 -0
  33. package/jobs/child/index.d.ts +13 -0
  34. package/jobs/child/index.js +2 -2
  35. package/jobs/child/jobProcess.d.ts +16 -0
  36. package/jobs/child/{forkProcess.js → jobProcess.js} +3 -18
  37. package/jobs/child-pool/index.d.ts +26 -0
  38. package/jobs/child-pool/index.js +13 -38
  39. package/jobs/index.d.ts +3 -0
  40. package/jobs/load-balancer/algorithm/index.d.ts +4 -0
  41. package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
  42. package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
  43. package/jobs/load-balancer/algorithm/random.d.ts +2 -0
  44. package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
  45. package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
  46. package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
  47. package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
  48. package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
  49. package/jobs/load-balancer/consts.d.ts +8 -0
  50. package/jobs/load-balancer/index.d.ts +96 -0
  51. package/jobs/load-balancer/scheduler.d.ts +16 -0
  52. package/loader/index.d.ts +9 -0
  53. package/loader/index.js +4 -22
  54. package/log/index.d.ts +5 -0
  55. package/log/logger.d.ts +2 -0
  56. package/message/childMessage.d.ts +10 -0
  57. package/message/childMessage.js +2 -12
  58. package/message/index.d.ts +3 -0
  59. package/package.json +8 -1
  60. package/ps/index.d.ts +37 -0
  61. package/ps/index.js +2 -12
  62. package/socket/httpServer.d.ts +8 -0
  63. package/socket/httpServer.js +10 -3
  64. package/socket/index.d.ts +10 -0
  65. package/socket/ipcServer.d.ts +9 -0
  66. package/socket/ipcServer.js +13 -6
  67. package/socket/socketServer.d.ts +10 -0
  68. package/socket/socketServer.js +7 -2
  69. package/storage/index.d.ts +5 -0
  70. package/storage/sqliteStorage.d.ts +16 -0
  71. package/storage/sqliteStorage.js +2 -2
  72. package/tsconfig.json +14 -0
  73. package/utils/extend.d.ts +2 -0
  74. package/utils/helper.d.ts +14 -0
  75. package/utils/helper.js +1 -11
  76. package/utils/index.d.ts +10 -0
  77. package/utils/index.js +7 -17
  78. package/utils/ip.d.ts +2 -0
  79. package/utils/is.d.ts +14 -0
  80. package/utils/json.d.ts +5 -0
  81. package/utils/pargv.d.ts +3 -0
  82. package/utils/port/index.d.ts +1 -0
  83. package/utils/wrap.d.ts +4 -0
  84. 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 };
@@ -0,0 +1,9 @@
1
+ export declare class IpcServer {
2
+ directory: string;
3
+ loop(obj: any, pathname: string): void;
4
+ register(exportObj: any, propertyChain: any): void;
5
+ findFn(controller: any, c: any): {
6
+ controller: any;
7
+ };
8
+ init(): void;
9
+ }
@@ -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
- const channel = `${propertyChain}.${key}`;
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
+
@@ -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,5 @@
1
+ import { SqliteStorage } from "./sqliteStorage";
2
+ import { Database } from "better-sqlite3";
3
+
4
+ export { Database };
5
+ export { SqliteStorage };
@@ -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
+ }
@@ -3,7 +3,7 @@
3
3
  const assert = require('assert');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
- const Database = require('better-sqlite3');
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 Database(dbPath, options);
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,2 @@
1
+ export declare function extend(...args: any[]): any;
2
+ export declare function isPlainObject(obj: any): any;
@@ -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 &&
@@ -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
- * Get the first proper MAC address
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
- * get machine id (promise)
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
@@ -0,0 +1,2 @@
1
+ export declare function publicIpv4(options: any): Promise<any>;
2
+ export declare function publicIpv6(options: any): Promise<any>;
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;
@@ -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>;
@@ -0,0 +1,3 @@
1
+ export declare function parseArgv(args: any, opts: any): {
2
+ _: any[];
3
+ };
@@ -0,0 +1 @@
1
+ export declare function getPort(options?: any): Promise<any>;
@@ -0,0 +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;
package/const/index.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- jobs: {
3
- inspectStartIndex: 5858
4
- }
5
- };