ee-core 1.2.8 → 1.2.9-bate.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 (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/bin/tools.js +22 -22
  4. package/config/config.default.js +255 -250
  5. package/core/index.js +12 -12
  6. package/core/lib/ee.js +209 -209
  7. package/core/lib/loader/context_loader.js +105 -105
  8. package/core/lib/loader/ee_loader.js +451 -451
  9. package/core/lib/loader/file_loader.js +262 -262
  10. package/core/lib/loader/mixin/config.js +138 -138
  11. package/core/lib/loader/mixin/controller.js +123 -123
  12. package/core/lib/loader/mixin/service.js +29 -29
  13. package/core/lib/utils/base_context_class.js +34 -34
  14. package/core/lib/utils/index.js +100 -100
  15. package/core/lib/utils/sequencify.js +59 -59
  16. package/core/lib/utils/timing.js +77 -77
  17. package/index.js +49 -49
  18. package/lib/appLoader.js +45 -45
  19. package/lib/application.js +80 -80
  20. package/lib/baseApp.js +118 -118
  21. package/lib/constant.js +28 -28
  22. package/lib/eeApp.js +326 -326
  23. package/lib/helper.js +51 -51
  24. package/lib/httpclient.js +136 -136
  25. package/lib/logger.js +46 -46
  26. package/lib/socket/httpServer.js +134 -102
  27. package/lib/socket/io.js +23 -23
  28. package/lib/socket/ipcServer.js +128 -128
  29. package/lib/socket/socketClient.js +50 -50
  30. package/lib/socket/socketServer.js +76 -76
  31. package/lib/socket/start.js +22 -22
  32. package/lib/storage/index.js +33 -33
  33. package/lib/storage/lowdbStorage.js +98 -98
  34. package/lib/storage/sqliteStorage.js +58 -58
  35. package/package.json +45 -45
  36. package/resource/loading.html +21 -21
  37. package/resource/view_example.html +21 -21
  38. package/tools/codeCompress.js +204 -204
  39. package/tools/replaceDist.js +76 -76
  40. package/utils/common.js +90 -90
  41. package/utils/index.js +207 -207
  42. package/utils/wrap.js +37 -37
package/lib/helper.js CHANGED
@@ -1,52 +1,52 @@
1
- 'use strict';
2
-
3
- const is = require('electron-is');
4
- const { app } = require('electron');
5
-
6
- /**
7
- * application quit
8
- *
9
- * @return {undefined}
10
- */
11
- exports.appQuit = function () {
12
- MAIN_WINDOW.destroy();
13
- app.quit();
14
- }
15
-
16
- /**
17
- * get Platform
18
- *
19
- * @return {Object}
20
- */
21
- exports.getPlatform = function () {
22
- let platform = null;
23
- let arch = null;
24
- if (is.windows()) {
25
- platform = 'windows';
26
- } else if (is.macOS()) {
27
- platform = 'macOS';
28
- } else if (is.linux()) {
29
- platform = 'linux';
30
- } else {
31
- platform = 'other';
32
- }
33
-
34
- if (is.x86()) {
35
- arch = '32';
36
- } else if (is.x64()) {
37
- arch = '64';
38
- } else if (process.arch == 'arm') {
39
- arch = 'arm32';
40
- } else if (process.arch == 'arm64') {
41
- arch = 'arm64';
42
- } else {
43
- arch = 'other';
44
- }
45
-
46
- const platfromObj = {
47
- platform: platform,
48
- arch: arch
49
- };
50
-
51
- return platfromObj;
1
+ 'use strict';
2
+
3
+ const is = require('electron-is');
4
+ const { app } = require('electron');
5
+
6
+ /**
7
+ * application quit
8
+ *
9
+ * @return {undefined}
10
+ */
11
+ exports.appQuit = function () {
12
+ MAIN_WINDOW.destroy();
13
+ app.quit();
14
+ }
15
+
16
+ /**
17
+ * get Platform
18
+ *
19
+ * @return {Object}
20
+ */
21
+ exports.getPlatform = function () {
22
+ let platform = null;
23
+ let arch = null;
24
+ if (is.windows()) {
25
+ platform = 'windows';
26
+ } else if (is.macOS()) {
27
+ platform = 'macOS';
28
+ } else if (is.linux()) {
29
+ platform = 'linux';
30
+ } else {
31
+ platform = 'other';
32
+ }
33
+
34
+ if (is.x86()) {
35
+ arch = '32';
36
+ } else if (is.x64()) {
37
+ arch = '64';
38
+ } else if (process.arch == 'arm') {
39
+ arch = 'arm32';
40
+ } else if (process.arch == 'arm64') {
41
+ arch = 'arm64';
42
+ } else {
43
+ arch = 'other';
44
+ }
45
+
46
+ const platfromObj = {
47
+ platform: platform,
48
+ arch: arch
49
+ };
50
+
51
+ return platfromObj;
52
52
  }
package/lib/httpclient.js CHANGED
@@ -1,136 +1,136 @@
1
- 'use strict';
2
-
3
- const Agent = require('agentkeepalive');
4
- const HttpsAgent = require('agentkeepalive').HttpsAgent;
5
- const urllib = require('urllib');
6
- const ms = require('humanize-ms');
7
- const { FrameworkBaseError } = require('egg-errors');
8
-
9
- class HttpClientError extends FrameworkBaseError {
10
- get module() {
11
- return 'httpclient';
12
- }
13
- }
14
-
15
- class HttpClient extends urllib.HttpClient2 {
16
- constructor(app) {
17
- normalizeConfig(app);
18
- const config = app.config.httpclient;
19
- super({
20
- app,
21
- defaultArgs: config.request,
22
- agent: new Agent(config.httpAgent),
23
- httpsAgent: new HttpsAgent(config.httpsAgent),
24
- });
25
- this.app = app;
26
- }
27
-
28
- request(url, args, callback) {
29
- if (typeof args === 'function') {
30
- callback = args;
31
- args = null;
32
- }
33
-
34
- args = args || {};
35
-
36
- // the callback style
37
- if (callback) {
38
- //this.app.deprecate('[httpclient] We now support async for this function, so callback isn\'t recommended.');
39
- super.request(url, args)
40
- .then(result => process.nextTick(() => callback(null, result.data, result.res)))
41
- .catch(err => process.nextTick(() => callback(err)));
42
- return;
43
- }
44
-
45
- // the Promise style
46
- return super.request(url, args)
47
- .catch(err => {
48
- if (err.code === 'ENETUNREACH') {
49
- throw HttpClientError.create(err.message, err.code);
50
- }
51
- throw err;
52
- });
53
- }
54
-
55
- curl(url, args, callback) {
56
- return this.request(url, args, callback);
57
- }
58
-
59
- requestThunk(url, args) {
60
- //this.app.deprecate('[httpclient] Please use `request()` instead of `requestThunk()`');
61
- return callback => {
62
- this.request(url, args, (err, data, res) => {
63
- if (err) {
64
- return callback(err);
65
- }
66
- callback(null, {
67
- data,
68
- status: res.status,
69
- headers: res.headers,
70
- res,
71
- });
72
- });
73
- };
74
- }
75
- }
76
-
77
- function normalizeConfig(app) {
78
- const config = app.config.httpclient;
79
-
80
- // compatibility
81
- if (typeof config.keepAlive === 'boolean') {
82
- config.httpAgent.keepAlive = config.keepAlive;
83
- config.httpsAgent.keepAlive = config.keepAlive;
84
- }
85
- if (config.timeout) {
86
- config.timeout = ms(config.timeout);
87
- config.httpAgent.timeout = config.timeout;
88
- config.httpsAgent.timeout = config.timeout;
89
- }
90
- // compatibility httpclient.freeSocketKeepAliveTimeout => httpclient.freeSocketTimeout
91
- if (config.freeSocketKeepAliveTimeout && !config.freeSocketTimeout) {
92
- config.freeSocketTimeout = config.freeSocketKeepAliveTimeout;
93
- delete config.freeSocketKeepAliveTimeout;
94
- }
95
- if (config.freeSocketTimeout) {
96
- config.freeSocketTimeout = ms(config.freeSocketTimeout);
97
- config.httpAgent.freeSocketTimeout = config.freeSocketTimeout;
98
- config.httpsAgent.freeSocketTimeout = config.freeSocketTimeout;
99
- } else {
100
- // compatibility agent.freeSocketKeepAliveTimeout
101
- if (config.httpAgent.freeSocketKeepAliveTimeout && !config.httpAgent.freeSocketTimeout) {
102
- config.httpAgent.freeSocketTimeout = config.httpAgent.freeSocketKeepAliveTimeout;
103
- delete config.httpAgent.freeSocketKeepAliveTimeout;
104
- }
105
- if (config.httpsAgent.freeSocketKeepAliveTimeout && !config.httpsAgent.freeSocketTimeout) {
106
- config.httpsAgent.freeSocketTimeout = config.httpsAgent.freeSocketKeepAliveTimeout;
107
- delete config.httpsAgent.freeSocketKeepAliveTimeout;
108
- }
109
- }
110
-
111
- if (typeof config.maxSockets === 'number') {
112
- config.httpAgent.maxSockets = config.maxSockets;
113
- config.httpsAgent.maxSockets = config.maxSockets;
114
- }
115
- if (typeof config.maxFreeSockets === 'number') {
116
- config.httpAgent.maxFreeSockets = config.maxFreeSockets;
117
- config.httpsAgent.maxFreeSockets = config.maxFreeSockets;
118
- }
119
-
120
- if (config.httpAgent.timeout < 30000) {
121
- app.coreLogger.warn('[ee:httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
122
- config.httpAgent.timeout);
123
- config.httpAgent.timeout = 30000;
124
- }
125
- if (config.httpsAgent.timeout < 30000) {
126
- app.coreLogger.warn('[ee:httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
127
- config.httpsAgent.timeout);
128
- config.httpsAgent.timeout = 30000;
129
- }
130
-
131
- if (typeof config.request.timeout === 'string') {
132
- config.request.timeout = ms(config.request.timeout);
133
- }
134
- }
135
-
136
- module.exports = HttpClient;
1
+ 'use strict';
2
+
3
+ const Agent = require('agentkeepalive');
4
+ const HttpsAgent = require('agentkeepalive').HttpsAgent;
5
+ const urllib = require('urllib');
6
+ const ms = require('humanize-ms');
7
+ const { FrameworkBaseError } = require('egg-errors');
8
+
9
+ class HttpClientError extends FrameworkBaseError {
10
+ get module() {
11
+ return 'httpclient';
12
+ }
13
+ }
14
+
15
+ class HttpClient extends urllib.HttpClient2 {
16
+ constructor(app) {
17
+ normalizeConfig(app);
18
+ const config = app.config.httpclient;
19
+ super({
20
+ app,
21
+ defaultArgs: config.request,
22
+ agent: new Agent(config.httpAgent),
23
+ httpsAgent: new HttpsAgent(config.httpsAgent),
24
+ });
25
+ this.app = app;
26
+ }
27
+
28
+ request(url, args, callback) {
29
+ if (typeof args === 'function') {
30
+ callback = args;
31
+ args = null;
32
+ }
33
+
34
+ args = args || {};
35
+
36
+ // the callback style
37
+ if (callback) {
38
+ //this.app.deprecate('[httpclient] We now support async for this function, so callback isn\'t recommended.');
39
+ super.request(url, args)
40
+ .then(result => process.nextTick(() => callback(null, result.data, result.res)))
41
+ .catch(err => process.nextTick(() => callback(err)));
42
+ return;
43
+ }
44
+
45
+ // the Promise style
46
+ return super.request(url, args)
47
+ .catch(err => {
48
+ if (err.code === 'ENETUNREACH') {
49
+ throw HttpClientError.create(err.message, err.code);
50
+ }
51
+ throw err;
52
+ });
53
+ }
54
+
55
+ curl(url, args, callback) {
56
+ return this.request(url, args, callback);
57
+ }
58
+
59
+ requestThunk(url, args) {
60
+ //this.app.deprecate('[httpclient] Please use `request()` instead of `requestThunk()`');
61
+ return callback => {
62
+ this.request(url, args, (err, data, res) => {
63
+ if (err) {
64
+ return callback(err);
65
+ }
66
+ callback(null, {
67
+ data,
68
+ status: res.status,
69
+ headers: res.headers,
70
+ res,
71
+ });
72
+ });
73
+ };
74
+ }
75
+ }
76
+
77
+ function normalizeConfig(app) {
78
+ const config = app.config.httpclient;
79
+
80
+ // compatibility
81
+ if (typeof config.keepAlive === 'boolean') {
82
+ config.httpAgent.keepAlive = config.keepAlive;
83
+ config.httpsAgent.keepAlive = config.keepAlive;
84
+ }
85
+ if (config.timeout) {
86
+ config.timeout = ms(config.timeout);
87
+ config.httpAgent.timeout = config.timeout;
88
+ config.httpsAgent.timeout = config.timeout;
89
+ }
90
+ // compatibility httpclient.freeSocketKeepAliveTimeout => httpclient.freeSocketTimeout
91
+ if (config.freeSocketKeepAliveTimeout && !config.freeSocketTimeout) {
92
+ config.freeSocketTimeout = config.freeSocketKeepAliveTimeout;
93
+ delete config.freeSocketKeepAliveTimeout;
94
+ }
95
+ if (config.freeSocketTimeout) {
96
+ config.freeSocketTimeout = ms(config.freeSocketTimeout);
97
+ config.httpAgent.freeSocketTimeout = config.freeSocketTimeout;
98
+ config.httpsAgent.freeSocketTimeout = config.freeSocketTimeout;
99
+ } else {
100
+ // compatibility agent.freeSocketKeepAliveTimeout
101
+ if (config.httpAgent.freeSocketKeepAliveTimeout && !config.httpAgent.freeSocketTimeout) {
102
+ config.httpAgent.freeSocketTimeout = config.httpAgent.freeSocketKeepAliveTimeout;
103
+ delete config.httpAgent.freeSocketKeepAliveTimeout;
104
+ }
105
+ if (config.httpsAgent.freeSocketKeepAliveTimeout && !config.httpsAgent.freeSocketTimeout) {
106
+ config.httpsAgent.freeSocketTimeout = config.httpsAgent.freeSocketKeepAliveTimeout;
107
+ delete config.httpsAgent.freeSocketKeepAliveTimeout;
108
+ }
109
+ }
110
+
111
+ if (typeof config.maxSockets === 'number') {
112
+ config.httpAgent.maxSockets = config.maxSockets;
113
+ config.httpsAgent.maxSockets = config.maxSockets;
114
+ }
115
+ if (typeof config.maxFreeSockets === 'number') {
116
+ config.httpAgent.maxFreeSockets = config.maxFreeSockets;
117
+ config.httpsAgent.maxFreeSockets = config.maxFreeSockets;
118
+ }
119
+
120
+ if (config.httpAgent.timeout < 30000) {
121
+ app.coreLogger.warn('[ee:httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
122
+ config.httpAgent.timeout);
123
+ config.httpAgent.timeout = 30000;
124
+ }
125
+ if (config.httpsAgent.timeout < 30000) {
126
+ app.coreLogger.warn('[ee:httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
127
+ config.httpsAgent.timeout);
128
+ config.httpsAgent.timeout = 30000;
129
+ }
130
+
131
+ if (typeof config.request.timeout === 'string') {
132
+ config.request.timeout = ms(config.request.timeout);
133
+ }
134
+ }
135
+
136
+ module.exports = HttpClient;
package/lib/logger.js CHANGED
@@ -1,47 +1,47 @@
1
- 'use strict';
2
-
3
- const debug = require('debug')('ee-core:logger');
4
- const Loggers = require('egg-logger').EggLoggers;
5
- const assert = require('assert');
6
-
7
- class Logger {
8
- constructor (config) {
9
- debug('Loaded logger');
10
- assert(Object.keys(config).length != 0, `logger config is null`);
11
- this.eggLogger = this.init(config);
12
- }
13
-
14
- /**
15
- * 单例
16
- */
17
- static getInstance (config = {}) {
18
- if (typeof this.instance === 'object') {
19
- return this.instance.eggLogger;
20
- }
21
-
22
- this.instance = new Logger(config);
23
-
24
- // 返回egg-logger实例
25
- return this.instance.eggLogger;
26
- }
27
-
28
- /**
29
- * 初始化模块
30
- */
31
- init(config) {
32
- const loggerConfig = config.logger;
33
- loggerConfig.type = 'application'; // application、agent
34
-
35
- if (config.env === 'prod' && loggerConfig.level === 'DEBUG' && !loggerConfig.allowDebugAtProd) {
36
- loggerConfig.level = 'INFO';
37
- }
38
-
39
- const loggers = new Loggers(config);
40
-
41
- loggers.coreLogger.info('[ee-core:logger] init all loggers with options: %j', loggerConfig);
42
-
43
- return loggers;
44
- };
45
- }
46
-
1
+ 'use strict';
2
+
3
+ const debug = require('debug')('ee-core:logger');
4
+ const Loggers = require('egg-logger').EggLoggers;
5
+ const assert = require('assert');
6
+
7
+ class Logger {
8
+ constructor (config) {
9
+ debug('Loaded logger');
10
+ assert(Object.keys(config).length != 0, `logger config is null`);
11
+ this.eggLogger = this.init(config);
12
+ }
13
+
14
+ /**
15
+ * 单例
16
+ */
17
+ static getInstance (config = {}) {
18
+ if (typeof this.instance === 'object') {
19
+ return this.instance.eggLogger;
20
+ }
21
+
22
+ this.instance = new Logger(config);
23
+
24
+ // 返回egg-logger实例
25
+ return this.instance.eggLogger;
26
+ }
27
+
28
+ /**
29
+ * 初始化模块
30
+ */
31
+ init(config) {
32
+ const loggerConfig = config.logger;
33
+ loggerConfig.type = 'application'; // application、agent
34
+
35
+ if (config.env === 'prod' && loggerConfig.level === 'DEBUG' && !loggerConfig.allowDebugAtProd) {
36
+ loggerConfig.level = 'INFO';
37
+ }
38
+
39
+ const loggers = new Loggers(config);
40
+
41
+ loggers.coreLogger.info('[ee-core:logger] init all loggers with options: %j', loggerConfig);
42
+
43
+ return loggers;
44
+ };
45
+ }
46
+
47
47
  module.exports = Logger;