ee-core 2.9.2-beta.1 → 2.10.0

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 (103) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +65 -65
  3. package/addon/index.js +34 -34
  4. package/addon/window/index.js +98 -98
  5. package/bin/tools.js +8 -8
  6. package/config/cache.js +41 -38
  7. package/config/config.default.js +331 -330
  8. package/config/index.js +75 -73
  9. package/const/channel.js +17 -17
  10. package/const/index.js +8 -8
  11. package/controller/baseContextClass.js +34 -34
  12. package/controller/index.js +34 -34
  13. package/core/index.js +10 -10
  14. package/core/lib/ee.js +216 -216
  15. package/core/lib/loader/context_loader.js +106 -106
  16. package/core/lib/loader/ee_loader.js +435 -435
  17. package/core/lib/loader/file_loader.js +326 -326
  18. package/core/lib/loader/mixin/addon.js +32 -32
  19. package/core/lib/loader/mixin/config.js +130 -130
  20. package/core/lib/loader/mixin/controller.js +125 -125
  21. package/core/lib/loader/mixin/service.js +28 -28
  22. package/core/lib/utils/base_context_class.js +34 -34
  23. package/core/lib/utils/function.js +30 -30
  24. package/core/lib/utils/index.js +133 -133
  25. package/core/lib/utils/sequencify.js +59 -59
  26. package/core/lib/utils/timing.js +77 -77
  27. package/cross/index.js +183 -183
  28. package/cross/spawnProcess.js +183 -183
  29. package/ee/appLoader.js +48 -48
  30. package/ee/application.js +99 -99
  31. package/ee/baseApp.js +103 -102
  32. package/ee/eeApp.js +408 -408
  33. package/ee/index.js +57 -57
  34. package/electron/app/index.js +64 -58
  35. package/electron/index.js +19 -19
  36. package/electron/window/index.js +73 -73
  37. package/electron/window/winState.js +186 -186
  38. package/exception/index.js +112 -112
  39. package/html/boot.html +98 -98
  40. package/html/cross-failure.html +28 -28
  41. package/html/failure.html +28 -28
  42. package/html/index.js +13 -13
  43. package/httpclient/index.js +161 -161
  44. package/index.js +54 -54
  45. package/jobs/baseJobClass.js +16 -16
  46. package/jobs/child/app.js +65 -65
  47. package/jobs/child/forkProcess.js +145 -145
  48. package/jobs/child/index.js +82 -82
  49. package/jobs/child-pool/index.js +213 -213
  50. package/jobs/index.js +8 -8
  51. package/jobs/load-balancer/algorithm/index.js +11 -11
  52. package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
  53. package/jobs/load-balancer/algorithm/polling.js +11 -11
  54. package/jobs/load-balancer/algorithm/random.js +9 -9
  55. package/jobs/load-balancer/algorithm/specify.js +14 -14
  56. package/jobs/load-balancer/algorithm/weights.js +21 -21
  57. package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
  58. package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
  59. package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
  60. package/jobs/load-balancer/consts.js +9 -9
  61. package/jobs/load-balancer/index.js +201 -201
  62. package/jobs/load-balancer/scheduler.js +31 -31
  63. package/jobs/renderer/index.js +141 -141
  64. package/jobs/renderer/loadView.js +40 -40
  65. package/jobs/unification.js +63 -63
  66. package/loader/index.js +172 -172
  67. package/log/index.js +68 -68
  68. package/log/logger.js +86 -80
  69. package/main/index.js +56 -56
  70. package/message/childMessage.js +54 -54
  71. package/message/index.js +18 -18
  72. package/old-utils/index.js +91 -91
  73. package/package.json +38 -38
  74. package/ps/index.js +371 -371
  75. package/services/baseContextClass.js +34 -34
  76. package/services/index.js +40 -40
  77. package/socket/httpServer.js +147 -147
  78. package/socket/index.js +81 -81
  79. package/socket/io.js +27 -27
  80. package/socket/ipcServer.js +112 -112
  81. package/socket/socketServer.js +69 -65
  82. package/storage/index.js +38 -38
  83. package/storage/jsondb/adapters/Base.js +23 -23
  84. package/storage/jsondb/adapters/FileSync.js +64 -52
  85. package/storage/jsondb/main.js +55 -42
  86. package/storage/jsondbStorage.js +195 -195
  87. package/storage/sqliteStorage.js +123 -123
  88. package/utils/co.js +237 -237
  89. package/utils/copyto.js +160 -160
  90. package/utils/depd/index.js +538 -538
  91. package/utils/depd/lib/browser/index.js +77 -77
  92. package/utils/extend.js +73 -73
  93. package/utils/get-port/index.d.ts +64 -64
  94. package/utils/get-port/index.js +148 -148
  95. package/utils/helper.js +220 -220
  96. package/utils/index.js +160 -160
  97. package/utils/ip.js +261 -261
  98. package/utils/is.js +145 -145
  99. package/utils/json.js +72 -72
  100. package/utils/pargv.js +263 -263
  101. package/utils/time/index.js +19 -19
  102. package/utils/time/ms.js +162 -162
  103. package/utils/wrap.js +35 -35
@@ -1,42 +1,55 @@
1
- const lodash = require('lodash');
2
- const assert = require('assert');
3
- const is = require('is-type-of');
4
-
5
- module.exports = function(adapter) {
6
- assert(typeof adapter === 'object', 'An adapter must be provided');
7
-
8
- // Create a fresh copy of lodash
9
- const _ = lodash.runInContext()
10
- const db = _.chain({})
11
-
12
- // Add write function to lodash
13
- // Calls save before returning result
14
- _.prototype.write = _.wrap(_.prototype.value, function(func) {
15
- const funcRes = func.apply(this)
16
- return db.write(funcRes)
17
- })
18
-
19
- function plant(state) {
20
- db.__wrapped__ = state
21
- return db
22
- }
23
-
24
- // Expose _ for mixins
25
- db._ = _
26
-
27
- db.read = () => {
28
- const r = adapter.read()
29
- return is.promise(r) ? r.then(plant) : plant(r)
30
- }
31
-
32
- db.write = returnValue => {
33
- const w = adapter.write(db.getState())
34
- return is.promise(w) ? w.then(() => returnValue) : returnValue
35
- }
36
-
37
- db.getState = () => db.__wrapped__
38
-
39
- db.setState = state => plant(state)
40
-
41
- return db.read()
42
- }
1
+ const lodash = require('lodash');
2
+ const assert = require('assert');
3
+ const is = require('is-type-of');
4
+ const FileSync = require('./adapters/FileSync');
5
+
6
+ class JsonDBMain {
7
+
8
+ constructor(options = {}) {
9
+ this.opt = options;
10
+ }
11
+
12
+ create() {
13
+ const adapter = new FileSync(this.opt);
14
+
15
+ assert(typeof adapter === 'object', 'An adapter must be provided');
16
+
17
+ // Create a fresh copy of lodash
18
+ const _ = lodash.runInContext()
19
+ const db = _.chain({})
20
+
21
+ // Add write function to lodash
22
+ // Calls save before returning result
23
+ _.prototype.write = _.wrap(_.prototype.value, function(func) {
24
+ const funcRes = func.apply(this)
25
+ return db.write(funcRes)
26
+ })
27
+
28
+ function plant(state) {
29
+ db.__wrapped__ = state
30
+ return db
31
+ }
32
+
33
+ // Expose _ for mixins
34
+ db._ = _
35
+
36
+ db.read = () => {
37
+ const r = adapter.read()
38
+ return is.promise(r) ? r.then(plant) : plant(r)
39
+ }
40
+
41
+ db.write = returnValue => {
42
+ const w = adapter.write(db.getState())
43
+ return is.promise(w) ? w.then(() => returnValue) : returnValue
44
+ }
45
+
46
+ db.getState = () => db.__wrapped__
47
+
48
+ db.setState = state => plant(state)
49
+
50
+ return db.read()
51
+ }
52
+
53
+ }
54
+
55
+ module.exports = JsonDBMain;
@@ -1,196 +1,196 @@
1
- const assert = require('assert');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const Jsondb = require('./jsondb/main');
5
- const FileSync = require('./jsondb/adapters/FileSync');
6
- const _ = require('lodash');
7
- const Constants = require('../const');
8
- const Helper = require('../utils/helper');
9
- const Ps = require('../ps');
10
-
11
- class JsondbStorage {
12
- constructor (name, opt = {}) {
13
- assert(name, `db name ${name} Cannot be empty`);
14
-
15
- // 补全文件名
16
- name = this._addExtname(name);
17
- this.name = name;
18
- this.mode = this.getMode(name);
19
- this.storageDir = this._createStorageDir();
20
- this.fileName = this._formatFileName(name);
21
- this.storageKey = Constants.storageKey;
22
-
23
- this.db = this.table();
24
- }
25
-
26
- /**
27
- * 创建 table
28
- */
29
- table() {
30
- const dbFile = this.getFilePath();
31
- const isSysDB = this.isSystemDB();
32
- const opt = {
33
- source: dbFile,
34
- isSysDB: isSysDB
35
- }
36
- const adapter = new FileSync(opt);
37
- const db = Jsondb(adapter);
38
-
39
- assert(fs.existsSync(dbFile), `error: storage ${dbFile} not exists`);
40
-
41
- return db;
42
- }
43
-
44
- /**
45
- * 补全扩展名
46
- */
47
- _addExtname(name) {
48
- if (path.extname(name) != '.json') {
49
- name += ".json";
50
- }
51
-
52
- return name;
53
- }
54
-
55
- /**
56
- * 创建storage目录
57
- */
58
- _createStorageDir() {
59
- let storageDir = Ps.getStorageDir();
60
-
61
- if (this.mode == 'absolute') {
62
- storageDir = path.dirname(this.name);
63
- }
64
-
65
- if (!fs.existsSync(storageDir)) {
66
- Helper.mkdir(storageDir);
67
- Helper.chmodPath(storageDir, '777');
68
- }
69
-
70
- return storageDir;
71
- }
72
-
73
- /**
74
- * 获取文件名
75
- */
76
- _formatFileName(name) {
77
- let fileName = path.basename(name);
78
- return fileName;
79
- }
80
-
81
- /**
82
- * is system db
83
- */
84
- isSystemDB() {
85
- return (this.name == 'system.json') ? true : false;
86
- }
87
-
88
- /**
89
- * 获取文件绝对路径
90
- */
91
- getFilePath() {
92
- const dbFile = path.join(this.storageDir, this.fileName);
93
- return dbFile;
94
- }
95
-
96
- /**
97
- * 获取file path 模式
98
- */
99
- getMode(name) {
100
- let mode = 'relative';
101
-
102
- // 路径模式
103
- name = name.replace(/[/\\]/g, '/');
104
- if (name.indexOf('/') !== -1) {
105
- const isAbsolute = path.isAbsolute(name);
106
- if (isAbsolute) {
107
- mode = 'absolute';
108
- }
109
- }
110
-
111
- return mode;
112
- }
113
-
114
- /**
115
- * 获取storage目录
116
- */
117
- getStorageDir() {
118
- return this.storageDir;
119
- }
120
-
121
- /**
122
- * 为指定的 name 设置一个对应的值
123
- */
124
- setItem (key, value) {
125
- assert(_.isString(key), `key must be a string`);
126
- assert(key.length != 0, `key cannot be empty`);
127
- assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
128
-
129
- let cacheKey = this.storageKey.cache;
130
- if (!this.db.has(cacheKey).value()) {
131
- this.db.set(cacheKey, {}).write();
132
- }
133
-
134
- let keyId = cacheKey + "." + key;
135
- this.db
136
- .set(keyId, value)
137
- .write();
138
-
139
- return true;
140
- }
141
-
142
- /**
143
- * 根据指定的名字 name 获取对应的值
144
- */
145
- getItem (key) {
146
- assert(_.isString(key), `key must be a string`);
147
- assert(key.length != 0, `key cannot be empty`);
148
-
149
- let cacheKey = this.storageKey.cache;
150
- let keyId = cacheKey + "." + key;
151
- const data = this.db
152
- .get(keyId)
153
- .value();
154
-
155
- return data;
156
- }
157
-
158
- /**
159
- * 设置config对象key属性的值
160
- */
161
- setConfigItem (key, value) {
162
- assert(_.isString(key), `key must be a string`);
163
- assert(key.length != 0, `key cannot be empty`);
164
- assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
165
-
166
- let cacheKey = this.storageKey.cacheConfig;
167
- if (!this.db.has(cacheKey).value()) {
168
- this.db.set(cacheKey, {}).write();
169
- }
170
-
171
- let keyId = cacheKey + "." + key;
172
- this.db
173
- .set(keyId, value)
174
- .write();
175
-
176
- return true;
177
- }
178
-
179
- /**
180
- * 获取config对象key属性的值
181
- */
182
- getConfigItem (key) {
183
- assert(_.isString(key), `key must be a string`);
184
- assert(key.length != 0, `key cannot be empty`);
185
-
186
- let cacheKey = this.storageKey.cacheConfig;
187
- let keyId = cacheKey + "." + key;
188
- const data = this.db
189
- .get(keyId)
190
- .value();
191
-
192
- return data;
193
- }
194
- }
195
-
1
+ const assert = require('assert');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const JsonDBMain = require('./jsondb/main');
5
+ const _ = require('lodash');
6
+ const Constants = require('../const');
7
+ const Helper = require('../utils/helper');
8
+ const Ps = require('../ps');
9
+
10
+ class JsondbStorage {
11
+ constructor (name, opt = {}) {
12
+ assert(name, `db name ${name} Cannot be empty`);
13
+
14
+ // 补全文件名
15
+ name = this._addExtname(name);
16
+ this.name = name;
17
+ this.mode = this.getMode(name);
18
+ this.storageDir = this._createStorageDir();
19
+ this.fileName = this._formatFileName(name);
20
+ this.storageKey = Constants.storageKey;
21
+
22
+ this.db = this.table();
23
+ }
24
+
25
+ /**
26
+ * 创建 table
27
+ */
28
+ table() {
29
+ const dbFile = this.getFilePath();
30
+ const isSysDB = this.isSystemDB();
31
+ const opt = {
32
+ source: dbFile,
33
+ isSysDB: isSysDB
34
+ }
35
+
36
+ const jdbMain = new JsonDBMain(opt);
37
+ const db = jdbMain.create();
38
+
39
+ assert(fs.existsSync(dbFile), `error: storage ${dbFile} not exists`);
40
+
41
+ return db;
42
+ }
43
+
44
+ /**
45
+ * 补全扩展名
46
+ */
47
+ _addExtname(name) {
48
+ if (path.extname(name) != '.json') {
49
+ name += ".json";
50
+ }
51
+
52
+ return name;
53
+ }
54
+
55
+ /**
56
+ * 创建storage目录
57
+ */
58
+ _createStorageDir() {
59
+ let storageDir = Ps.getStorageDir();
60
+
61
+ if (this.mode == 'absolute') {
62
+ storageDir = path.dirname(this.name);
63
+ }
64
+
65
+ if (!fs.existsSync(storageDir)) {
66
+ Helper.mkdir(storageDir);
67
+ Helper.chmodPath(storageDir, '777');
68
+ }
69
+
70
+ return storageDir;
71
+ }
72
+
73
+ /**
74
+ * 获取文件名
75
+ */
76
+ _formatFileName(name) {
77
+ let fileName = path.basename(name);
78
+ return fileName;
79
+ }
80
+
81
+ /**
82
+ * is system db
83
+ */
84
+ isSystemDB() {
85
+ return (this.name == 'system.json') ? true : false;
86
+ }
87
+
88
+ /**
89
+ * 获取文件绝对路径
90
+ */
91
+ getFilePath() {
92
+ const dbFile = path.join(this.storageDir, this.fileName);
93
+ return dbFile;
94
+ }
95
+
96
+ /**
97
+ * 获取file path 模式
98
+ */
99
+ getMode(name) {
100
+ let mode = 'relative';
101
+
102
+ // 路径模式
103
+ name = name.replace(/[/\\]/g, '/');
104
+ if (name.indexOf('/') !== -1) {
105
+ const isAbsolute = path.isAbsolute(name);
106
+ if (isAbsolute) {
107
+ mode = 'absolute';
108
+ }
109
+ }
110
+
111
+ return mode;
112
+ }
113
+
114
+ /**
115
+ * 获取storage目录
116
+ */
117
+ getStorageDir() {
118
+ return this.storageDir;
119
+ }
120
+
121
+ /**
122
+ * 为指定的 name 设置一个对应的值
123
+ */
124
+ setItem (key, value) {
125
+ assert(_.isString(key), `key must be a string`);
126
+ assert(key.length != 0, `key cannot be empty`);
127
+ assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
128
+
129
+ let cacheKey = this.storageKey.cache;
130
+ if (!this.db.has(cacheKey).value()) {
131
+ this.db.set(cacheKey, {}).write();
132
+ }
133
+
134
+ let keyId = cacheKey + "." + key;
135
+ this.db
136
+ .set(keyId, value)
137
+ .write();
138
+
139
+ return true;
140
+ }
141
+
142
+ /**
143
+ * 根据指定的名字 name 获取对应的值
144
+ */
145
+ getItem (key) {
146
+ assert(_.isString(key), `key must be a string`);
147
+ assert(key.length != 0, `key cannot be empty`);
148
+
149
+ let cacheKey = this.storageKey.cache;
150
+ let keyId = cacheKey + "." + key;
151
+ const data = this.db
152
+ .get(keyId)
153
+ .value();
154
+
155
+ return data;
156
+ }
157
+
158
+ /**
159
+ * 设置config对象key属性的值
160
+ */
161
+ setConfigItem (key, value) {
162
+ assert(_.isString(key), `key must be a string`);
163
+ assert(key.length != 0, `key cannot be empty`);
164
+ assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
165
+
166
+ let cacheKey = this.storageKey.cacheConfig;
167
+ if (!this.db.has(cacheKey).value()) {
168
+ this.db.set(cacheKey, {}).write();
169
+ }
170
+
171
+ let keyId = cacheKey + "." + key;
172
+ this.db
173
+ .set(keyId, value)
174
+ .write();
175
+
176
+ return true;
177
+ }
178
+
179
+ /**
180
+ * 获取config对象key属性的值
181
+ */
182
+ getConfigItem (key) {
183
+ assert(_.isString(key), `key must be a string`);
184
+ assert(key.length != 0, `key cannot be empty`);
185
+
186
+ let cacheKey = this.storageKey.cacheConfig;
187
+ let keyId = cacheKey + "." + key;
188
+ const data = this.db
189
+ .get(keyId)
190
+ .value();
191
+
192
+ return data;
193
+ }
194
+ }
195
+
196
196
  module.exports = JsondbStorage;