ee-core 1.5.0 → 1.5.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 (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/addon/window/index.js +91 -91
  4. package/bin/tools.js +17 -17
  5. package/config/config.default.js +280 -276
  6. package/core/index.js +12 -12
  7. package/core/lib/ee.js +218 -218
  8. package/core/lib/loader/context_loader.js +106 -106
  9. package/core/lib/loader/ee_loader.js +457 -457
  10. package/core/lib/loader/file_loader.js +325 -325
  11. package/core/lib/loader/mixin/addon.js +32 -32
  12. package/core/lib/loader/mixin/config.js +135 -135
  13. package/core/lib/loader/mixin/controller.js +124 -124
  14. package/core/lib/loader/mixin/service.js +28 -28
  15. package/core/lib/utils/base_context_class.js +34 -34
  16. package/core/lib/utils/index.js +127 -127
  17. package/core/lib/utils/sequencify.js +59 -59
  18. package/core/lib/utils/timing.js +77 -77
  19. package/index.js +49 -49
  20. package/lib/appLoader.js +53 -53
  21. package/lib/application.js +84 -84
  22. package/lib/baseApp.js +131 -131
  23. package/lib/constant.js +9 -9
  24. package/lib/eeApp.js +359 -335
  25. package/lib/httpclient.js +136 -136
  26. package/lib/logger.js +46 -46
  27. package/lib/socket/httpServer.js +142 -142
  28. package/lib/socket/io.js +23 -23
  29. package/lib/socket/ipcServer.js +108 -108
  30. package/lib/socket/socketClient.js +50 -50
  31. package/lib/socket/socketServer.js +76 -76
  32. package/lib/socket/start.js +22 -22
  33. package/lib/storage/index.js +33 -33
  34. package/lib/storage/lowdbStorage.js +98 -98
  35. package/lib/storage/sqliteStorage.js +127 -127
  36. package/package.json +45 -45
  37. package/tools/encrypt.js +274 -274
  38. package/tools/replaceDist.js +61 -61
  39. package/utils/common.js +90 -90
  40. package/utils/index.js +246 -246
  41. package/utils/wrap.js +37 -37
@@ -1,99 +1,99 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const lowdb = require('lowdb');
7
- const FileSync = require('lowdb/adapters/FileSync');
8
- const _ = require('lodash');
9
- const constant = require('../constant');
10
- const utilsCommon = require('../../utils/common');
11
-
12
- class LowdbStorage {
13
- constructor (name, opt = {}) {
14
- assert(name, `db name ${name} Cannot be empty`);
15
-
16
- this.name = name;
17
-
18
- // 数据库key列表
19
- this.storageKey = constant.storageKey;
20
-
21
- const storageDir = utilsCommon.getStorageDir();
22
- if (!fs.existsSync(storageDir)) {
23
- utilsCommon.mkdir(storageDir);
24
- utilsCommon.chmodPath(storageDir, '777');
25
- }
26
-
27
- this.db = this.table(name);
28
- }
29
-
30
- /**
31
- * 创建 table
32
- */
33
- table (name) {
34
- assert(name, 'table name is required');
35
-
36
- const dbFile = this.getFilePath(name);
37
- const adapter = new FileSync(dbFile);
38
- const db = lowdb(adapter);
39
-
40
- assert(fs.existsSync(dbFile), `error: storage ${dbFile} not exists`);
41
-
42
- return db;
43
- }
44
-
45
- /**
46
- * 获取db文件名
47
- */
48
- getFileName (name) {
49
- return name + ".json";
50
- }
51
-
52
- /**
53
- * 获取文件绝对路径
54
- */
55
- getFilePath (name) {
56
- const storageDir = utilsCommon.getStorageDir();
57
- const dbFile = path.join(storageDir, this.getFileName(name));
58
- return dbFile;
59
- }
60
-
61
- /**
62
- * 为指定的 name 设置一个对应的值
63
- */
64
- setItem (key, value) {
65
- assert(_.isString(key), `key must be a string`);
66
- assert(key.length != 0, `key cannot be empty`);
67
- assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
68
-
69
- let cacheKey = this.storageKey.cache;
70
- if (!this.db.has(cacheKey).value()) {
71
- this.db.set(cacheKey, {}).write();
72
- }
73
-
74
- let keyId = cacheKey + "." + key;
75
- this.db
76
- .set(keyId, value)
77
- .write();
78
-
79
- return true;
80
- }
81
-
82
- /**
83
- * 根据指定的名字 name 获取对应的值
84
- */
85
- getItem (key) {
86
- assert(_.isString(key), `key must be a string`);
87
- assert(key.length != 0, `key cannot be empty`);
88
-
89
- let cacheKey = this.storageKey.cache;
90
- let keyId = cacheKey + "." + key;
91
- const data = this.db
92
- .get(keyId)
93
- .value();
94
-
95
- return data;
96
- }
97
- }
98
-
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const lowdb = require('lowdb');
7
+ const FileSync = require('lowdb/adapters/FileSync');
8
+ const _ = require('lodash');
9
+ const constant = require('../constant');
10
+ const utilsCommon = require('../../utils/common');
11
+
12
+ class LowdbStorage {
13
+ constructor (name, opt = {}) {
14
+ assert(name, `db name ${name} Cannot be empty`);
15
+
16
+ this.name = name;
17
+
18
+ // 数据库key列表
19
+ this.storageKey = constant.storageKey;
20
+
21
+ const storageDir = utilsCommon.getStorageDir();
22
+ if (!fs.existsSync(storageDir)) {
23
+ utilsCommon.mkdir(storageDir);
24
+ utilsCommon.chmodPath(storageDir, '777');
25
+ }
26
+
27
+ this.db = this.table(name);
28
+ }
29
+
30
+ /**
31
+ * 创建 table
32
+ */
33
+ table (name) {
34
+ assert(name, 'table name is required');
35
+
36
+ const dbFile = this.getFilePath(name);
37
+ const adapter = new FileSync(dbFile);
38
+ const db = lowdb(adapter);
39
+
40
+ assert(fs.existsSync(dbFile), `error: storage ${dbFile} not exists`);
41
+
42
+ return db;
43
+ }
44
+
45
+ /**
46
+ * 获取db文件名
47
+ */
48
+ getFileName (name) {
49
+ return name + ".json";
50
+ }
51
+
52
+ /**
53
+ * 获取文件绝对路径
54
+ */
55
+ getFilePath (name) {
56
+ const storageDir = utilsCommon.getStorageDir();
57
+ const dbFile = path.join(storageDir, this.getFileName(name));
58
+ return dbFile;
59
+ }
60
+
61
+ /**
62
+ * 为指定的 name 设置一个对应的值
63
+ */
64
+ setItem (key, value) {
65
+ assert(_.isString(key), `key must be a string`);
66
+ assert(key.length != 0, `key cannot be empty`);
67
+ assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
68
+
69
+ let cacheKey = this.storageKey.cache;
70
+ if (!this.db.has(cacheKey).value()) {
71
+ this.db.set(cacheKey, {}).write();
72
+ }
73
+
74
+ let keyId = cacheKey + "." + key;
75
+ this.db
76
+ .set(keyId, value)
77
+ .write();
78
+
79
+ return true;
80
+ }
81
+
82
+ /**
83
+ * 根据指定的名字 name 获取对应的值
84
+ */
85
+ getItem (key) {
86
+ assert(_.isString(key), `key must be a string`);
87
+ assert(key.length != 0, `key cannot be empty`);
88
+
89
+ let cacheKey = this.storageKey.cache;
90
+ let keyId = cacheKey + "." + key;
91
+ const data = this.db
92
+ .get(keyId)
93
+ .value();
94
+
95
+ return data;
96
+ }
97
+ }
98
+
99
99
  module.exports = LowdbStorage;
@@ -1,128 +1,128 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const Database = require('better-sqlite3');
7
- const utilsCommon = require('../../utils/common');
8
-
9
- class SqliteStorage {
10
- constructor (name, opt = {}) {
11
- assert(name, `db name ${name} Cannot be empty`);
12
-
13
- this.name = name;
14
- this.mode = this.getMode(name);
15
-
16
- const storageDir = this._createStorageDir();
17
- this.storageDir = storageDir;
18
-
19
- const fileName = this._formatFileName(name);
20
- this.fileName = fileName;
21
-
22
- this.db = this._initDB(opt);
23
- }
24
-
25
- /**
26
- * 初始化db
27
- */
28
- _initDB (opt = {}) {
29
- let options = Object.assign({
30
- timeout: 5000,
31
- }, opt);
32
-
33
- // 存储类型:db文件、内存(:memory:)
34
- let dbPath = this.name;
35
- if (this.mode != 'memory') {
36
- dbPath = this.getFilePath();
37
- }
38
-
39
- const db = new Database(dbPath, options);
40
-
41
- // 如果是文件类型,判断文件是否创建成功
42
- if (this.mode != 'memory') {
43
- assert(fs.existsSync(dbPath), `error: storage ${dbPath} not exists`);
44
- }
45
-
46
- return db;
47
- }
48
-
49
- /**
50
- * 获取文件名
51
- */
52
- _formatFileName (name) {
53
- let fileName = name;
54
- if (this.mode != 'memory') {
55
- fileName = path.basename(name);
56
- }
57
-
58
- return fileName;
59
- }
60
-
61
- /**
62
- * 创建storage目录
63
- */
64
- _createStorageDir () {
65
- let storageDir = utilsCommon.getStorageDir();
66
-
67
- if (this.mode == 'absolute') {
68
- storageDir = path.dirname(this.name);
69
- }
70
-
71
- if (!fs.existsSync(storageDir)) {
72
- utilsCommon.mkdir(storageDir);
73
- utilsCommon.chmodPath(storageDir, '777');
74
- }
75
-
76
- return storageDir;
77
- }
78
-
79
- /**
80
- * 获取file path 模式
81
- */
82
- getMode (name) {
83
- let mode = '';
84
-
85
- // 内存模式
86
- if (name == ':memory:') {
87
- mode = 'memory';
88
- return mode;
89
- }
90
-
91
- assert(path.extname(name) == '.db', `error: storage ${name} file ext name must be .db`);
92
-
93
- // 路径模式
94
- name = name.replace(/[/\\]/g, '/');
95
- if (name.indexOf('/') !== -1) {
96
- const isAbsolute = path.isAbsolute(name);
97
- if (isAbsolute) {
98
- mode = 'absolute';
99
- } else {
100
- mode = 'relative';
101
- }
102
- return mode;
103
- }
104
-
105
- // 仅文件名
106
- mode = 'onlyName';
107
-
108
- return mode;
109
- }
110
-
111
- /**
112
- * 获取storage目录
113
- */
114
- getStorageDir () {
115
- return this.storageDir;
116
- }
117
-
118
- /**
119
- * 获取文件绝对路径
120
- */
121
- getFilePath () {
122
- const dbFile = path.join(this.storageDir, this.fileName);
123
-
124
- return dbFile;
125
- }
126
- }
127
-
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const Database = require('better-sqlite3');
7
+ const utilsCommon = require('../../utils/common');
8
+
9
+ class SqliteStorage {
10
+ constructor (name, opt = {}) {
11
+ assert(name, `db name ${name} Cannot be empty`);
12
+
13
+ this.name = name;
14
+ this.mode = this.getMode(name);
15
+
16
+ const storageDir = this._createStorageDir();
17
+ this.storageDir = storageDir;
18
+
19
+ const fileName = this._formatFileName(name);
20
+ this.fileName = fileName;
21
+
22
+ this.db = this._initDB(opt);
23
+ }
24
+
25
+ /**
26
+ * 初始化db
27
+ */
28
+ _initDB (opt = {}) {
29
+ let options = Object.assign({
30
+ timeout: 5000,
31
+ }, opt);
32
+
33
+ // 存储类型:db文件、内存(:memory:)
34
+ let dbPath = this.name;
35
+ if (this.mode != 'memory') {
36
+ dbPath = this.getFilePath();
37
+ }
38
+
39
+ const db = new Database(dbPath, options);
40
+
41
+ // 如果是文件类型,判断文件是否创建成功
42
+ if (this.mode != 'memory') {
43
+ assert(fs.existsSync(dbPath), `error: storage ${dbPath} not exists`);
44
+ }
45
+
46
+ return db;
47
+ }
48
+
49
+ /**
50
+ * 获取文件名
51
+ */
52
+ _formatFileName (name) {
53
+ let fileName = name;
54
+ if (this.mode != 'memory') {
55
+ fileName = path.basename(name);
56
+ }
57
+
58
+ return fileName;
59
+ }
60
+
61
+ /**
62
+ * 创建storage目录
63
+ */
64
+ _createStorageDir () {
65
+ let storageDir = utilsCommon.getStorageDir();
66
+
67
+ if (this.mode == 'absolute') {
68
+ storageDir = path.dirname(this.name);
69
+ }
70
+
71
+ if (!fs.existsSync(storageDir)) {
72
+ utilsCommon.mkdir(storageDir);
73
+ utilsCommon.chmodPath(storageDir, '777');
74
+ }
75
+
76
+ return storageDir;
77
+ }
78
+
79
+ /**
80
+ * 获取file path 模式
81
+ */
82
+ getMode (name) {
83
+ let mode = '';
84
+
85
+ // 内存模式
86
+ if (name == ':memory:') {
87
+ mode = 'memory';
88
+ return mode;
89
+ }
90
+
91
+ assert(path.extname(name) == '.db', `error: storage ${name} file ext name must be .db`);
92
+
93
+ // 路径模式
94
+ name = name.replace(/[/\\]/g, '/');
95
+ if (name.indexOf('/') !== -1) {
96
+ const isAbsolute = path.isAbsolute(name);
97
+ if (isAbsolute) {
98
+ mode = 'absolute';
99
+ } else {
100
+ mode = 'relative';
101
+ }
102
+ return mode;
103
+ }
104
+
105
+ // 仅文件名
106
+ mode = 'onlyName';
107
+
108
+ return mode;
109
+ }
110
+
111
+ /**
112
+ * 获取storage目录
113
+ */
114
+ getStorageDir () {
115
+ return this.storageDir;
116
+ }
117
+
118
+ /**
119
+ * 获取文件绝对路径
120
+ */
121
+ getFilePath () {
122
+ const dbFile = path.join(this.storageDir, this.fileName);
123
+
124
+ return dbFile;
125
+ }
126
+ }
127
+
128
128
  module.exports = SqliteStorage;
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "ee-core",
3
- "version": "1.5.0",
4
- "description": "ee core",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "author": "",
10
- "license": "ISC",
11
- "bin": {
12
- "ee-core": "./bin/tools.js"
13
- },
14
- "dependencies": {
15
- "agentkeepalive": "^4.2.0",
16
- "bytenode": "^1.3.6",
17
- "co": "^4.6.0",
18
- "debug": "^4.3.3",
19
- "depd": "^2.0.0",
20
- "egg-errors": "^2.3.0",
21
- "egg-logger": "^2.7.1",
22
- "electron-is": "^3.0.0",
23
- "electron-updater": "^4.6.1",
24
- "extend2": "^1.0.1",
25
- "fs-extra": "^10.0.0",
26
- "get-port": "^5.1.1",
27
- "globby": "^10.0.0",
28
- "humanize-ms": "^1.2.1",
29
- "is-type-of": "^1.2.1",
30
- "koa": "^2.13.4",
31
- "koa-body": "^5.0.0",
32
- "koa-convert": "^2.0.0",
33
- "koa-static": "^5.0.0",
34
- "koa2-cors": "^2.0.6",
35
- "lodash": "^4.17.21",
36
- "lowdb": "^1.0.0",
37
- "path-to-regexp": "^6.2.0",
38
- "socket.io": "^4.4.1",
39
- "socket.io-client": "^4.4.1",
40
- "javascript-obfuscator": "^4.0.0",
41
- "urllib": "^2.38.0",
42
- "utility": "^1.17.0"
43
- },
44
- "devDependencies": {}
45
- }
1
+ {
2
+ "name": "ee-core",
3
+ "version": "1.5.1",
4
+ "description": "ee core",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "bin": {
12
+ "ee-core": "./bin/tools.js"
13
+ },
14
+ "dependencies": {
15
+ "agentkeepalive": "^4.2.0",
16
+ "bytenode": "^1.3.6",
17
+ "co": "^4.6.0",
18
+ "debug": "^4.3.3",
19
+ "depd": "^2.0.0",
20
+ "egg-errors": "^2.3.0",
21
+ "egg-logger": "^2.7.1",
22
+ "electron-is": "^3.0.0",
23
+ "electron-updater": "^4.6.1",
24
+ "extend2": "^1.0.1",
25
+ "fs-extra": "^10.0.0",
26
+ "get-port": "^5.1.1",
27
+ "globby": "^10.0.0",
28
+ "humanize-ms": "^1.2.1",
29
+ "is-type-of": "^1.2.1",
30
+ "koa": "^2.13.4",
31
+ "koa-body": "^5.0.0",
32
+ "koa-convert": "^2.0.0",
33
+ "koa-static": "^5.0.0",
34
+ "koa2-cors": "^2.0.6",
35
+ "lodash": "^4.17.21",
36
+ "lowdb": "^1.0.0",
37
+ "path-to-regexp": "^6.2.0",
38
+ "socket.io": "^4.4.1",
39
+ "socket.io-client": "^4.4.1",
40
+ "javascript-obfuscator": "^4.0.0",
41
+ "urllib": "^2.38.0",
42
+ "utility": "^1.17.0"
43
+ },
44
+ "devDependencies": {}
45
+ }