mm_os 4.2.6 → 4.2.8

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 (74) 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/cmd/config.tpl.json +48 -122
  12. package/com/cmd/drive.js +176 -1548
  13. package/com/cmd/index.js +287 -1066
  14. package/com/cmd/job/config.json +66 -0
  15. package/com/cmd/job/index.js +241 -0
  16. package/com/cmd/job/test.js +188 -0
  17. package/com/cmd/script.tpl.js +12 -33
  18. package/com/db/drive.js +2206 -2019
  19. package/com/db/index.js +241 -242
  20. package/com/event/config.tpl.json +3 -1
  21. package/com/event/drive.js +3 -1
  22. package/com/event/index.js +73 -49
  23. package/com/event/script.tpl.js +1 -1
  24. package/com/mqtt/config.tpl.json +16 -8
  25. package/com/mqtt/drive.js +696 -676
  26. package/com/mqtt/index.js +1012 -822
  27. package/com/mqtt/index.test.js +503 -0
  28. package/com/mqtt/mm_mqtt.js +446 -420
  29. package/com/mqtt/script.tpl.js +3 -7
  30. package/com/nav/drive.js +7 -7
  31. package/com/nav/index.js +228 -231
  32. package/com/param/index.js +19 -17
  33. package/com/pendant/index.js +467 -441
  34. package/com/socket/drive.js +679 -616
  35. package/com/socket/index.js +94 -48
  36. package/com/sql/drive.js +1283 -1259
  37. package/com/sql/index.js +152 -150
  38. package/com/static/drive.js +1 -1
  39. package/com/static/index.js +232 -226
  40. package/com/task/drive.js +428 -405
  41. package/com/task/index.js +154 -148
  42. package/com/template/drive.js +1 -1
  43. package/com/template/index.js +141 -138
  44. package/com.js +87 -6
  45. package/common/middleware/web_after/index.js +4 -10
  46. package/common/middleware/web_base/index.js +1 -1
  47. package/common/middleware/web_cors/index.js +1 -1
  48. package/common/middleware/web_error/index.js +131 -119
  49. package/common/middleware/web_error/middleware.json +2 -1
  50. package/common/middleware/web_logger/index.js +1 -1
  51. package/common/middleware/web_main/index.js +2 -0
  52. package/common/middleware/web_static/index.js +2 -2
  53. package/common/middleware/web_waf/index.js +1 -1
  54. package/core/app/config.tpl.json +4 -4
  55. package/core/app/index.js +710 -534
  56. package/core/middleware/index.js +1 -9
  57. package/core/mod/config.tpl.json +1 -1
  58. package/core/model/config.tpl.json +1 -1
  59. package/core/plugin/config.tpl.json +15 -3
  60. package/core/plugin/index.js +31 -0
  61. package/core/pusher/index.js +158 -161
  62. package/core/scene/loop.js +1306 -1255
  63. package/core/store/index.js +1794 -1755
  64. package/core/store/sql.js +1488 -1464
  65. package/core/zone/bat/index.js +744 -728
  66. package/core/zone/config.tpl.json +3 -3
  67. package/core/zone/index.js +655 -616
  68. package/os.js +0 -4
  69. package/package.json +16 -16
  70. package/server.js +583 -427
  71. package/com/cmd/nlp.js +0 -525
  72. package/core/app/index copy.js +0 -611
  73. package/software.js +0 -194
  74. package/tcp.js +0 -279
@@ -64,15 +64,7 @@ Middleware.prototype._initCore = async function (adapter, eventer, logger) {
64
64
  */
65
65
  Middleware.prototype._register = async function () {
66
66
  // 注册中间件到Koa应用
67
- this.getAdapter().use(this.create());
68
- };
69
-
70
- /**
71
- * 注册中间件
72
- * @returns {Promise<void>}
73
- */
74
- Middleware.prototype.register = async function () {
75
- await this._register();
67
+ this.getAdapter().web.use(this.create());
76
68
  };
77
69
 
78
70
  /**
@@ -8,7 +8,7 @@
8
8
  // 版本号
9
9
  "version": "${version || '1.0.0'}",
10
10
  // 作者
11
- "author": "${author || 'mos'}",
11
+ "author": "${author || 'qww'}",
12
12
  // 作用域,决定加载到什么区域
13
13
  "scope": "${scope || 'server'}",
14
14
  // 主文件
@@ -51,7 +51,7 @@
51
51
  "description": "用户的密码",
52
52
  "min": 1,
53
53
  "max": 32,
54
- "default": "123456"
54
+ "default": ""
55
55
  },
56
56
  "salt": {
57
57
  "type": "string",
@@ -9,8 +9,8 @@
9
9
  "version": "${version || '1.0.0'}",
10
10
  // 作者
11
11
  "author": "${author || '(匿名)'}",
12
- // 用于什么应用
13
- "app": "${app || 'sys'}",
12
+ // 用于什么应用
13
+ "app": "${app || 'sys'}",
14
14
  // 主文件
15
15
  "main": "${main || 'index.js'}",
16
16
  // 状态 0:禁用 1:启用
@@ -20,5 +20,17 @@
20
20
  // git仓库地址
21
21
  "git": "${git || ''}",
22
22
  // 依赖的npm module
23
- "dependencies": []
23
+ "dependencies": [],
24
+ // 是否显示在管理员挂件列表中
25
+ "show_admin": true,
26
+ // 是否显示在用户挂件列表中
27
+ "show_user": true,
28
+ // 是否显示在商户挂件列表中
29
+ "show_cloud": true,
30
+ // 是否显示在网站首页挂件列表中
31
+ "show_home": true,
32
+ // 是否显示在GM挂件列表中
33
+ "show_merchant": true,
34
+ // 是否显示在VIP页面列表中
35
+ "show_vip": true
24
36
  }
@@ -294,4 +294,35 @@ Drive.prototype.getModel = function (type) {
294
294
  return model;
295
295
  };
296
296
 
297
+
298
+ /**
299
+ * 安装插件
300
+ * @private
301
+ */
302
+ Plugin.prototype._install = async function () {
303
+ return this;
304
+ };
305
+
306
+ /**
307
+ * 安装插件
308
+ */
309
+ Plugin.prototype.install = async function () {
310
+ return this._install();
311
+ };
312
+
313
+ /**
314
+ * 卸载插件
315
+ * @private
316
+ */
317
+ Plugin.prototype._uninstall = async function () {
318
+ return this;
319
+ };
320
+
321
+ /**
322
+ * 卸载插件
323
+ */
324
+ Plugin.prototype.uninstall = async function () {
325
+ return this._uninstall();
326
+ };
327
+
297
328
  exports.Plugin = Plugin;
@@ -1,161 +1,158 @@
1
- const { Drive } = require('mm_machine');
2
-
3
- /**
4
- * 广播器
5
- * 进行websocket、socket、mqtt广播
6
- */
7
- class Pusher extends Drive {
8
- static config = {
9
- // 广播器名称
10
- name: 'default',
11
- // 推送配置
12
- // 推送类型: websocket, mqtt、socket
13
- type: 'websocket',
14
- // 推送策略: realtime(实时), batch(批量)
15
- strategy: 'realtime',
16
- // 批量推送间隔(毫秒)
17
- batch_interval: 100,
18
- // 推送队列大小
19
- queue_size: 1000,
20
- // 最大重试次数
21
- max_retry: 3,
22
- // 重试间隔(毫秒)
23
- retry_interval: 500,
24
- // 是否启用压缩
25
- compression: false
26
- };
27
- /**
28
- * 构造函数
29
- * @param {object} config 配置参数
30
- * @param {object} parent 父对象
31
- */
32
- constructor(config, parent) {
33
- super({ ...Pusher.config, ...config || {} }, parent);
34
- // 推送队列
35
- this._push_queue = [];
36
- // 推送计时器
37
- this._batch_timer = null;
38
- }
39
- }
40
-
41
- /**
42
- * 获取模板目录
43
- * @returns {string} 模板目录
44
- */
45
- Pusher.prototype.getTplDir = function () {
46
- return __dirname;
47
- };
48
-
49
- /**
50
- * 初始化核心
51
- * @param {object} adapter 适配器
52
- * @param {object} eventer 事件总线
53
- * @param {object} logger 日志管理器
54
- */
55
- Pusher.prototype._initCore = async function (adapter, eventer, logger) {
56
- // 初始化依赖项
57
- if (logger) {
58
- this.setLogger(logger);
59
- }
60
- if (eventer) {
61
- this.getEventer = function () {
62
- return eventer;
63
- };
64
- }
65
- if (adapter) {
66
- this.getAdapter = function () {
67
- return adapter[this.config.type];
68
- };
69
- }
70
-
71
- // 初始化批量推送计时器
72
- if (this.config.strategy === 'batch') {
73
- this._startBatchTimer();
74
- }
75
-
76
- // 注册事件监听
77
- this._registerEvents();
78
- };
79
-
80
- /**
81
- * 注册事件监听
82
- * @private
83
- */
84
- Pusher.prototype._registerEvents = function () {
85
- // 监听实体数据变化事件
86
- let eventer = this.getEventer();
87
- eventer.on('entity_changed', (data) => {
88
- console.log('entity_changed', data);
89
- });
90
-
91
- // 监听实体创建事件
92
- eventer.on('entity_created', (data) => {
93
- console.log('entity_created', data);
94
- });
95
-
96
- // 监听实体删除事件
97
- eventer.on('entity_deleted', (data) => {
98
- console.log('entity_deleted', data);
99
- });
100
- };
101
-
102
- /**
103
- * 广播消息给所有连接的客户端
104
- * @param {string} method 方法名
105
- * @param {object} params 参数
106
- */
107
- Pusher.prototype.broadcast = function (method, params) {
108
- };
109
-
110
- /**
111
- * 启动
112
- */
113
- Pusher.prototype._start = async function () {
114
- this.log('info', '启动');
115
-
116
- // 启动批量推送计时器
117
- if (this.config.strategy === 'batch') {
118
- this._startBatchTimer();
119
- }
120
- };
121
-
122
- /**
123
- * 停止
124
- */
125
- Pusher.prototype._stop = async function () {
126
- // 停止批量推送计时器
127
- if (this._batch_timer) {
128
- clearInterval(this._batch_timer);
129
- this._batch_timer = null;
130
- }
131
-
132
- // 清空推送队列
133
- this._push_queue = [];
134
-
135
- this.log('info', 'stopped');
136
- };
137
-
138
- /**
139
- * 销毁
140
- */
141
- Pusher.prototype._destroy = function () {
142
- try {
143
- // 停止批量推送计时器
144
- if (this._batch_timer) {
145
- clearInterval(this._batch_timer);
146
- this._batch_timer = null;
147
- }
148
-
149
- // 清空存储引用
150
- this._push_queue = [];
151
-
152
- this.log('info', 'destroyed');
153
-
154
- // 移除所有监听器
155
- this.removeAllListeners();
156
- } catch (error) {
157
- this.log('error', `销毁失败`, error);
158
- }
159
- };
160
-
161
- exports.Pusher = Pusher;
1
+ const { Drive } = require("mm_machine");
2
+
3
+ /**
4
+ * 广播器
5
+ * 进行websocket、socket、mqtt广播
6
+ */
7
+ class Pusher extends Drive {
8
+ static config = {
9
+ // 广播器名称
10
+ name: "default",
11
+ // 推送配置
12
+ // 推送类型: websocket, mqtt、socket
13
+ type: "websocket",
14
+ // 推送策略: realtime(实时), batch(批量)
15
+ strategy: "realtime",
16
+ // 批量推送间隔(毫秒)
17
+ batch_interval: 100,
18
+ // 推送队列大小
19
+ queue_size: 1000,
20
+ // 最大重试次数
21
+ max_retry: 3,
22
+ // 重试间隔(毫秒)
23
+ retry_interval: 500,
24
+ // 是否启用压缩
25
+ compression: false,
26
+ };
27
+ /**
28
+ * 构造函数
29
+ * @param {object} config 配置参数
30
+ * @param {object} parent 父对象
31
+ */
32
+ constructor(config, parent) {
33
+ super({ ...Pusher.config, ...(config || {}) }, parent);
34
+ // 推送队列
35
+ this._push_queue = [];
36
+ // 推送计时器
37
+ this._batch_timer = null;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * 获取模板目录
43
+ * @returns {string} 模板目录
44
+ */
45
+ Pusher.prototype.getTplDir = function () {
46
+ return __dirname;
47
+ };
48
+
49
+ /**
50
+ * 初始化核心
51
+ * @param {object} adapter 适配器
52
+ * @param {object} eventer 事件总线
53
+ * @param {object} logger 日志管理器
54
+ */
55
+ Pusher.prototype._initCore = async function (adapter, eventer, logger) {
56
+ // 初始化依赖项
57
+ if (logger) {
58
+ this.setLogger(logger);
59
+ }
60
+ if (eventer) {
61
+ this.getEventer = function () {
62
+ return eventer;
63
+ };
64
+ }
65
+ if (adapter) {
66
+ this.getAdapter = function () {
67
+ return adapter[this.config.type];
68
+ };
69
+ }
70
+
71
+ // 初始化批量推送计时器
72
+ if (this.config.strategy === "batch") {
73
+ this._startBatchTimer();
74
+ }
75
+
76
+ // 注册事件监听
77
+ this._registerEvents();
78
+ };
79
+
80
+ /**
81
+ * 注册事件监听
82
+ * @private
83
+ */
84
+ Pusher.prototype._registerEvents = function () {
85
+ var eventer = this.getEventer();
86
+ this._ev_changed = (data) => {
87
+ this.log("info", "entity_changed", data);
88
+ };
89
+ this._ev_created = (data) => {
90
+ this.log("info", "entity_created", data);
91
+ };
92
+ this._ev_deleted = (data) => {
93
+ this.log("info", "entity_deleted", data);
94
+ };
95
+ eventer.on("entity_changed", this._ev_changed);
96
+ eventer.on("entity_created", this._ev_created);
97
+ eventer.on("entity_deleted", this._ev_deleted);
98
+ };
99
+
100
+ /**
101
+ * 广播消息给所有连接的客户端
102
+ * @param {string} method 方法名
103
+ * @param {object} params 参数
104
+ */
105
+ Pusher.prototype.broadcast = function (method, params) {};
106
+
107
+ /**
108
+ * 启动
109
+ */
110
+ Pusher.prototype._start = async function () {
111
+ this.log("info", "启动");
112
+
113
+ // 启动批量推送计时器
114
+ if (this.config.strategy === "batch") {
115
+ this._startBatchTimer();
116
+ }
117
+ };
118
+
119
+ /**
120
+ * 停止
121
+ */
122
+ Pusher.prototype._stop = async function () {
123
+ // 停止批量推送计时器
124
+ if (this._batch_timer) {
125
+ clearInterval(this._batch_timer);
126
+ this._batch_timer = null;
127
+ }
128
+
129
+ // 清空推送队列
130
+ this._push_queue = [];
131
+
132
+ this.log("info", "stopped");
133
+ };
134
+
135
+ /**
136
+ * 销毁
137
+ */
138
+ Pusher.prototype._destroy = function () {
139
+ try {
140
+ // 停止批量推送计时器
141
+ if (this._batch_timer) {
142
+ clearInterval(this._batch_timer);
143
+ this._batch_timer = null;
144
+ }
145
+
146
+ // 清空存储引用
147
+ this._push_queue = [];
148
+
149
+ this.log("info", "destroyed");
150
+
151
+ // 移除所有监听器
152
+ this.removeAllListeners();
153
+ } catch (error) {
154
+ this.log("error", `销毁失败`, error);
155
+ }
156
+ };
157
+
158
+ exports.Pusher = Pusher;