mm_os 4.2.4 → 4.2.7

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 (77) hide show
  1. package/README.md +1 -1
  2. package/README_EN.md +2 -2
  3. package/adapter/adapter.js +105 -52
  4. package/adapter/custom_persistence.js +32 -31
  5. package/adapter/mqtt.js +59 -79
  6. package/adapter/socket.js +188 -58
  7. package/adapter/web.js +92 -68
  8. package/adapter/websocket.js +43 -146
  9. package/com/api/drive.js +732 -708
  10. package/com/api/index.js +196 -198
  11. package/com/api/script.tpl.js +24 -24
  12. package/com/cmd/config.tpl.json +48 -122
  13. package/com/cmd/drive.js +176 -1548
  14. package/com/cmd/index.js +287 -1066
  15. package/com/cmd/job/config.json +66 -0
  16. package/com/cmd/job/index.js +241 -0
  17. package/com/cmd/job/test.js +188 -0
  18. package/com/cmd/script.tpl.js +12 -33
  19. package/com/db/drive.js +2206 -2019
  20. package/com/db/index.js +241 -242
  21. package/com/event/config.tpl.json +3 -1
  22. package/com/event/drive.js +3 -1
  23. package/com/event/index.js +73 -46
  24. package/com/event/script.tpl.js +22 -22
  25. package/com/mqtt/config.tpl.json +16 -8
  26. package/com/mqtt/drive.js +696 -676
  27. package/com/mqtt/index.js +1012 -822
  28. package/com/mqtt/index.test.js +503 -0
  29. package/com/mqtt/mm_mqtt.js +446 -420
  30. package/com/mqtt/script.tpl.js +3 -7
  31. package/com/nav/drive.js +7 -7
  32. package/com/nav/index.js +228 -231
  33. package/com/param/index.js +19 -17
  34. package/com/pendant/index.js +467 -441
  35. package/com/socket/drive.js +679 -651
  36. package/com/socket/index.js +94 -48
  37. package/com/sql/drive.js +1283 -1259
  38. package/com/sql/index.js +152 -150
  39. package/com/static/drive.js +1 -1
  40. package/com/static/index.js +232 -226
  41. package/com/static/script.tpl.js +25 -25
  42. package/com/task/drive.js +428 -405
  43. package/com/task/index.js +154 -148
  44. package/com/task/script.tpl.js +37 -34
  45. package/com/template/drive.js +1 -1
  46. package/com/template/index.js +141 -138
  47. package/com.js +87 -6
  48. package/common/middleware/web_after/index.js +5 -11
  49. package/common/middleware/web_base/index.js +1 -1
  50. package/common/middleware/web_cors/index.js +1 -1
  51. package/common/middleware/web_error/index.js +131 -119
  52. package/common/middleware/web_error/middleware.json +2 -1
  53. package/common/middleware/web_logger/index.js +1 -1
  54. package/common/middleware/web_main/index.js +2 -0
  55. package/common/middleware/web_static/index.js +2 -2
  56. package/common/middleware/web_waf/index.js +1 -1
  57. package/core/app/config.tpl.json +4 -4
  58. package/core/app/index.js +710 -534
  59. package/core/middleware/index.js +1 -9
  60. package/core/mod/config.tpl.json +1 -1
  61. package/core/model/config.tpl.json +1 -1
  62. package/core/plugin/config.tpl.json +15 -3
  63. package/core/plugin/index.js +31 -0
  64. package/core/pusher/index.js +158 -161
  65. package/core/scene/loop.js +1306 -1255
  66. package/core/store/index.js +1794 -1755
  67. package/core/store/sql.js +1488 -1464
  68. package/core/zone/bat/index.js +744 -728
  69. package/core/zone/config.tpl.json +3 -3
  70. package/core/zone/index.js +655 -616
  71. package/os.js +0 -4
  72. package/package.json +16 -16
  73. package/server.js +583 -427
  74. package/com/cmd/nlp.js +0 -525
  75. package/core/app/index copy.js +0 -611
  76. package/software.js +0 -194
  77. package/tcp.js +0 -279
@@ -1,226 +1,232 @@
1
- const Manager = require('mm_machine').Manager;
2
- const Drive = require('./drive');
3
-
4
- /**
5
- * 静态文件管理类
6
- * @augments {Manager}
7
- * @class
8
- */
9
- class Static extends Manager {
10
- /**
11
- * 配置参数
12
- * @type {object}
13
- */
14
- static config = {
15
- /**
16
- * 名称
17
- * @type {string}
18
- */
19
- name: '',
20
- /**
21
- * 标题
22
- * @type {string}
23
- */
24
- title: '静态文件管理',
25
- /**
26
- * 描述
27
- * @type {string}
28
- */
29
- description: '这是静态文件管理器',
30
- /**
31
- * 检索文件名
32
- * @type {string}
33
- */
34
- filename: 'static.json',
35
- /**
36
- * 模板目录
37
- * @type {string}
38
- */
39
- tpl_dir: __dirname,
40
- /**
41
- * 基础目录
42
- * @type {string}
43
- */
44
- base_dir: '../common/static'.fullname(__dirname),
45
- /**
46
- * 自定义目录,加载项目自定义资源
47
- * @type {string}
48
- */
49
- dir: './app'.fullname(),
50
- /**
51
- * 搜索模式 dir按目录搜索 | file按文件名搜索
52
- * @type {string}
53
- */
54
- search_way: 'file',
55
- /**
56
- * 是否懒加载
57
- * @type {boolean}
58
- */
59
- lazy_load: false,
60
- /**
61
- * 模式
62
- * 1.生产模式,改变文件不会重新加载
63
- * 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
64
- * 3.热重载模式,改变配置文件都会加载配置和脚本
65
- * 4.重载模式,执行完后重新加载脚本,避免变量污染
66
- * 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
67
- * @type {number}
68
- */
69
- mode: 3
70
- };
71
-
72
- /**
73
- * 构造函数
74
- * @param {object} config 配置参数
75
- * @param {object} parent 父级模块
76
- */
77
- constructor(config, parent) {
78
- super({ ...Static.config, ...config }, parent);
79
- }
80
-
81
- /**
82
- * 处理请求
83
- * @param {object} ctx Http请求上下文
84
- * @param {object} next 跳过函数
85
- */
86
- async _handleRequest(ctx, next) {
87
- var md = ctx.method;
88
- var path = ctx.path;
89
- if (md === 'GET' || md === 'HEAD') {
90
- await this._handleGetRequest(ctx, next, path);
91
- } else {
92
- await next();
93
- }
94
- }
95
-
96
- /**
97
- * 处理GET请求
98
- * @param {object} ctx Http请求上下文
99
- * @param {object} next 跳过函数
100
- */
101
- async run(ctx, next) {
102
- var done;
103
- var infos = this.getInfos();
104
- var len = infos.length;
105
- let path = ctx.path;
106
- if (path.indexOf('.') !== -1) {
107
- done = await this._tryServeFile(ctx, infos, len, function () { });
108
- if (!done) {
109
- await next();
110
- }
111
- } else {
112
- await next();
113
- await this._handleDirReq(ctx, infos, len, path);
114
- }
115
- }
116
-
117
- /**
118
- * 尝试提供文件服务
119
- * @param {object} ctx Http请求上下文
120
- * @param {Array} list 驱动列表
121
- * @param {number} len 列表长度
122
- * @param {object} next 跳过函数
123
- * @returns {boolean} 是否成功
124
- */
125
- async _tryServeFile(ctx, infos, len, next) {
126
- for (var i = 0; i < len; i++) {
127
- var info = infos[i];
128
- if (info.state === 1) {
129
- let mod = this.getMod(info.name);
130
- if (mod) {
131
- var done = await mod.run(ctx, next);
132
- if (done) {
133
- return true;
134
- }
135
- }
136
- }
137
- }
138
- return false;
139
- }
140
-
141
- /**
142
- * 处理目录请求
143
- * @param {object} ctx Http请求上下文
144
- * @param {Array} infos 驱动信息列表
145
- * @param {number} len 列表长度
146
- * @param {string} path 请求路径
147
- */
148
- async _handleDirReq(ctx, infos, len, path) {
149
- var q = ctx.request.querystring;
150
- for (var i = 0; i < len; i++) {
151
- var info = infos[i];
152
- if (info.state === 1) {
153
- let mod = this.getMod(info.name);
154
- if (mod) {
155
- var p = mod.config.path;
156
- if (path === p) {
157
- this._handleExactMatch(ctx, q, p);
158
- break;
159
- } else {
160
- var done = await mod.run(ctx, () => { });
161
- if (done) {
162
- break;
163
- }
164
- }
165
- }
166
- }
167
- }
168
- }
169
-
170
- /**
171
- * 处理精确匹配
172
- * @param {object} ctx Http请求上下文
173
- * @param {string} q 查询字符串
174
- * @param {string} p 路径
175
- */
176
- _handleExactMatch(ctx, q, p) {
177
- if (ctx.status === 404) {
178
- if (q) {
179
- ctx.redirect(p + '/?' + q);
180
- } else {
181
- ctx.redirect(p + '/');
182
- }
183
- }
184
- }
185
- }
186
-
187
- /**
188
- * 静态文件驱动类
189
- * @type {Drive}
190
- */
191
- Static.prototype.Drive = Drive;
192
-
193
- exports.Static = Static;
194
-
195
- /**
196
- * 创建全局管理器
197
- */
198
- if (!$.pool.static) {
199
- $.pool.static = {};
200
- }
201
-
202
- /**
203
- * 静态文件管理器
204
- * @param {string} scope 作用域
205
- * @param {string} title 标题
206
- * @returns {object} 返回一个缓存类
207
- */
208
- function staticAdmin(scope, title) {
209
- var sc = scope || $.val.scope + '';
210
- var obj = $.pool.static[sc];
211
- if (!obj) {
212
- $.pool.static[sc] = new Static({
213
- name: sc,
214
- title: title
215
- });
216
- obj = $.pool.static[sc];
217
- }
218
- return obj;
219
- }
220
-
221
- /**
222
- * @module 导出Static管理器
223
- */
224
- if ($.admin) {
225
- $.admin.static = staticAdmin;
226
- }
1
+ const Manager = require("mm_machine").Manager;
2
+ const Drive = require("./drive");
3
+
4
+ /**
5
+ * 静态文件管理类
6
+ * @augments {Manager}
7
+ * @class
8
+ */
9
+ class Static extends Manager {
10
+ /**
11
+ * 配置参数
12
+ * @type {object}
13
+ */
14
+ static config = {
15
+ /**
16
+ * 名称
17
+ * @type {string}
18
+ */
19
+ name: "",
20
+ /**
21
+ * 标题
22
+ * @type {string}
23
+ */
24
+ title: "静态文件管理",
25
+ /**
26
+ * 描述
27
+ * @type {string}
28
+ */
29
+ description: "这是静态文件管理器",
30
+ /**
31
+ * 检索文件名
32
+ * @type {string}
33
+ */
34
+ filename: "static.json",
35
+ /**
36
+ * 模板目录
37
+ * @type {string}
38
+ */
39
+ tpl_dir: __dirname,
40
+ /**
41
+ * 基础目录
42
+ * @type {string}
43
+ */
44
+ base_dir: "../common/static".fullname(__dirname),
45
+ /**
46
+ * 自定义目录,加载项目自定义资源
47
+ * @type {string}
48
+ */
49
+ dir: "./app".fullname(),
50
+ /**
51
+ * 搜索模式 dir按目录搜索 | file按文件名搜索
52
+ * @type {string}
53
+ */
54
+ search_way: "file",
55
+ /**
56
+ * 是否懒加载
57
+ * @type {boolean}
58
+ */
59
+ lazy_load: false,
60
+ /**
61
+ * 模式
62
+ * 1.生产模式,改变文件不会重新加载
63
+ * 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
64
+ * 3.热重载模式,改变配置文件都会加载配置和脚本
65
+ * 4.重载模式,执行完后重新加载脚本,避免变量污染
66
+ * 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
67
+ * @type {number}
68
+ */
69
+ mode: process.env.NODE_ENV === "production" ? 1 : 3,
70
+ };
71
+
72
+ /**
73
+ * 构造函数
74
+ * @param {object} config 配置参数
75
+ * @param {object} parent 父级模块
76
+ */
77
+ constructor(config, parent) {
78
+ super({ ...Static.config, ...config }, parent);
79
+ }
80
+
81
+ /**
82
+ * 处理请求
83
+ * @param {object} ctx Http请求上下文
84
+ * @param {object} next 跳过函数
85
+ */
86
+ async _handleRequest(ctx, next) {
87
+ var md = ctx.method;
88
+ var path = ctx.path;
89
+ if (md === "GET" || md === "HEAD") {
90
+ await this._handleGetRequest(ctx, next, path);
91
+ } else {
92
+ await next();
93
+ }
94
+ }
95
+
96
+ /**
97
+ * 处理GET请求
98
+ * @param {object} ctx Http请求上下文
99
+ * @param {object} next 跳过函数
100
+ */
101
+ async run(ctx, next) {
102
+ var done;
103
+ var infos = this.getInfos();
104
+ var len = infos.length;
105
+ let path = ctx.path;
106
+ if (path.indexOf(".") !== -1) {
107
+ done = await this._tryServeFile(ctx, infos, len, async () => {});
108
+ if (!done) {
109
+ await next();
110
+ }
111
+ } else {
112
+ await next();
113
+ await this._handleDirReq(ctx, infos, len, path);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * 尝试提供文件服务
119
+ * @param {object} ctx Http请求上下文
120
+ * @param {Array} infos 驱动信息列表
121
+ * @param {number} len 列表长度
122
+ * @param {object} next 跳过函数
123
+ * @returns {boolean} 是否成功
124
+ */
125
+ async _tryServeFile(ctx, infos, len, next) {
126
+ for (var i = 0; i < len; i++) {
127
+ var info = infos[i];
128
+ if (info.state === 1) {
129
+ let mod = this.getMod(info.name);
130
+ if (mod) {
131
+ if (!mod.isLoaded()) {
132
+ await mod.do("load");
133
+ }
134
+ var done = await mod.run(ctx, next);
135
+ if (done) {
136
+ return true;
137
+ }
138
+ }
139
+ }
140
+ }
141
+ return false;
142
+ }
143
+
144
+ /**
145
+ * 处理目录请求
146
+ * @param {object} ctx Http请求上下文
147
+ * @param {Array} infos 驱动信息列表
148
+ * @param {number} len 列表长度
149
+ * @param {string} path 请求路径
150
+ */
151
+ async _handleDirReq(ctx, infos, len, path) {
152
+ var q = ctx.request.querystring;
153
+ for (var i = 0; i < len; i++) {
154
+ var info = infos[i];
155
+ if (info.state === 1) {
156
+ let mod = this.getMod(info.name);
157
+ if (mod) {
158
+ var p = mod.config.path;
159
+ if (path === p) {
160
+ this._handleExactMatch(ctx, q, p);
161
+ break;
162
+ } else {
163
+ if (!mod.isLoaded()) {
164
+ await mod.do("load");
165
+ }
166
+ var done = await mod.run(ctx, () => {});
167
+ if (done) {
168
+ break;
169
+ }
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+
176
+ /**
177
+ * 处理精确匹配
178
+ * @param {object} ctx Http请求上下文
179
+ * @param {string} q 查询字符串
180
+ * @param {string} p 路径
181
+ */
182
+ _handleExactMatch(ctx, q, p) {
183
+ if (ctx.status === 404) {
184
+ if (q) {
185
+ ctx.redirect(p + "/?" + q);
186
+ } else {
187
+ ctx.redirect(p + "/");
188
+ }
189
+ }
190
+ }
191
+ }
192
+
193
+ /**
194
+ * 静态文件驱动类
195
+ * @type {Drive}
196
+ */
197
+ Static.prototype.Drive = Drive;
198
+
199
+ exports.Static = Static;
200
+
201
+ /**
202
+ * 创建全局管理器
203
+ */
204
+ if (!$.pool.static) {
205
+ $.pool.static = {};
206
+ }
207
+
208
+ /**
209
+ * 静态文件管理器
210
+ * @param {string} scope 作用域
211
+ * @param {string} title 标题
212
+ * @returns {object} 返回一个缓存类
213
+ */
214
+ function staticAdmin(scope, title) {
215
+ var sc = scope || $.val.scope + "";
216
+ var obj = $.pool.static[sc];
217
+ if (!obj) {
218
+ $.pool.static[sc] = new Static({
219
+ name: sc,
220
+ title: title,
221
+ });
222
+ obj = $.pool.static[sc];
223
+ }
224
+ return obj;
225
+ }
226
+
227
+ /**
228
+ * @module 导出Static管理器
229
+ */
230
+ if ($.admin) {
231
+ $.admin.static = staticAdmin;
232
+ }
@@ -1,28 +1,28 @@
1
- /**
2
- * 执行前
3
- * @param {object} ctx http请求上下文
4
- * @param {object} path 文件路径
5
- */
6
- async function before(ctx, path) {};
7
1
 
8
- /**
9
- * 执行
10
- * @param {object} ctx http请求上下文
11
- * @param {object} path 文件路径
12
- * @returns {boolean} 成功发送返回true,失败返回false
13
- */
14
- async function main(ctx, path) {
15
- return this.send(ctx, path, this.config);
16
- };
2
+ module.exports = {
3
+ /**
4
+ * 执行前
5
+ * @param {object} ctx http请求上下文
6
+ * @param {object} path 文件路径
7
+ */
8
+ async before(ctx, path) { },
17
9
 
18
- /**
19
- * 执行后
20
- * @param {object} ctx http请求上下文
21
- * @param {object} path 文件路径
22
- */
23
- async function after(ctx, path) {};
10
+ /**
11
+ * 执行
12
+ * @param {object} ctx http请求上下文
13
+ * @param {object} path 文件路径
14
+ * @returns {boolean} 成功发送返回true,失败返回false
15
+ */
16
+ async main(ctx, path) {
17
+ return this.send(ctx, path, this.config);
18
+ },
24
19
 
25
-
26
- exports.before = before;
27
- exports.main = main;
28
- exports.after = after;
20
+ /**
21
+ * 执行后
22
+ * @param {object} ctx http请求上下文
23
+ * @param {object} path 文件路径
24
+ */
25
+ async after(ctx, path) {
26
+
27
+ }
28
+ };