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
package/com/task/index.js CHANGED
@@ -1,148 +1,154 @@
1
- const Manager = require('mm_machine').Manager;
2
- const Drive = require('./drive');
3
-
4
- /**
5
- * 任务类
6
- * @augments {Manager}
7
- * @class
8
- */
9
- class Task 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: 'task.json',
35
- /**
36
- * 模板目录
37
- * @type {string}
38
- */
39
- tpl_dir: __dirname,
40
- /**
41
- * 基础目录
42
- * @type {string}
43
- */
44
- base_dir: '../common/task'.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({ ...Task.config, ...config }, parent);
79
- }
80
- }
81
-
82
- /**
83
- * 任务驱动类
84
- * @type {Drive}
85
- */
86
- Task.prototype.Drive = Drive;
87
-
88
- /**
89
- * 执行任务
90
- * @param {string} name 要执行的名称
91
- */
92
- Task.prototype.run = async function (name) {
93
- if (name) {
94
- let mod = this.getMod(name);
95
- if (mod) {
96
- await mod.run();
97
- }
98
- } else {
99
- let infos = this.getInfos();
100
- for (var i = 0, info; info = infos[i++];) {
101
- if (info.state === 1) {
102
- try {
103
- let mod = this.getMod(info.name);
104
- if (mod) {
105
- await mod.run();
106
- }
107
- } catch (error) {
108
- this.log('error', '定时任务错误', info.name, error);
109
- }
110
- }
111
- }
112
- }
113
- };
114
-
115
- exports.Task = Task;
116
-
117
- /**
118
- * Task模板池
119
- */
120
- if (!$.pool.task) {
121
- $.pool.task = {};
122
- }
123
-
124
- /**
125
- * Task管理器,用于创建缓存
126
- * @param {string} scope 作用域
127
- * @param {string} title 标题
128
- * @returns {object} 返回一个缓存类
129
- */
130
- function taskAdmin(scope, title) {
131
- var sc = scope || $.val.scope + '';
132
- var obj = $.pool.task[sc];
133
- if (!obj) {
134
- $.pool.task[sc] = new Task({
135
- name: sc,
136
- title: title
137
- });
138
- obj = $.pool.task[sc];
139
- }
140
- return obj;
141
- }
142
-
143
- /**
144
- * @module 导出Task管理器
145
- */
146
- if ($.admin) {
147
- $.admin.task = taskAdmin;
148
- }
1
+ const Manager = require("mm_machine").Manager;
2
+ const Drive = require("./drive");
3
+
4
+ /**
5
+ * 任务类
6
+ * @augments {Manager}
7
+ * @class
8
+ */
9
+ class Task 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: "task.json",
35
+ /**
36
+ * 模板目录
37
+ * @type {string}
38
+ */
39
+ tpl_dir: __dirname,
40
+ /**
41
+ * 基础目录
42
+ * @type {string}
43
+ */
44
+ base_dir: "../common/task".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({ ...Task.config, ...config }, parent);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * 任务驱动类
84
+ * @type {Drive}
85
+ */
86
+ Task.prototype.Drive = Drive;
87
+
88
+ /**
89
+ * 执行任务
90
+ * @param {string} name 要执行的名称
91
+ */
92
+ Task.prototype.run = async function (name) {
93
+ if (name) {
94
+ let mod = this.getMod(name);
95
+ if (mod) {
96
+ if (!mod.isLoaded()) {
97
+ await mod.do("load");
98
+ }
99
+ await mod.run();
100
+ }
101
+ } else {
102
+ let infos = this.getInfos();
103
+ for (var i = 0, info; (info = infos[i++]);) {
104
+ if (info.state === 1) {
105
+ try {
106
+ let mod = this.getMod(info.name);
107
+ if (mod) {
108
+ if (!mod.isLoaded()) {
109
+ await mod.do("load");
110
+ }
111
+ await mod.run();
112
+ }
113
+ } catch (error) {
114
+ this.log("error", "定时任务错误", info.name, error);
115
+ }
116
+ }
117
+ }
118
+ }
119
+ };
120
+
121
+ exports.Task = Task;
122
+
123
+ /**
124
+ * Task模板池
125
+ */
126
+ if (!$.pool.task) {
127
+ $.pool.task = {};
128
+ }
129
+
130
+ /**
131
+ * Task管理器,用于创建缓存
132
+ * @param {string} scope 作用域
133
+ * @param {string} title 标题
134
+ * @returns {object} 返回一个缓存类
135
+ */
136
+ function taskAdmin(scope, title) {
137
+ var sc = scope || $.val.scope + "";
138
+ var obj = $.pool.task[sc];
139
+ if (!obj) {
140
+ $.pool.task[sc] = new Task({
141
+ name: sc,
142
+ title: title,
143
+ });
144
+ obj = $.pool.task[sc];
145
+ }
146
+ return obj;
147
+ }
148
+
149
+ /**
150
+ * @module 导出Task管理器
151
+ */
152
+ if ($.admin) {
153
+ $.admin.task = taskAdmin;
154
+ }
@@ -1,5 +1,5 @@
1
1
  const compressing = require('compressing');
2
- const Item = require('mm_machine').Item;
2
+ const Item = require('mm_machine').Drive;
3
3
 
4
4
  /**
5
5
  * 主题模板驱动类
@@ -1,138 +1,141 @@
1
- const compressing = require('compressing');
2
- const Index = require('mm_machine').Index;
3
- const Drive = require('./drive').Drive;
4
-
5
- /**
6
- * 主题模板管理类
7
- * @class
8
- */
9
- class Template extends Index {
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: 'template管理',
25
- /**
26
- * 描述
27
- * @type {string}
28
- */
29
- description: '这是template管理器',
30
- /**
31
- * 检索文件名
32
- * @type {string}
33
- */
34
- filename: 'template.json',
35
- /**
36
- * 模板目录
37
- * @type {string}
38
- */
39
- tpl_dir: __dirname,
40
- /**
41
- * 基础目录
42
- * @type {string}
43
- */
44
- base_dir: '../common/template'.fullname(__dirname),
45
- /**
46
- * 自定义目录,加载项目自定义资源
47
- * @type {string}
48
- */
49
- dir: './static/template'.fullname(),
50
- /**
51
- * 搜索模式 dir按目录搜索 | file按文件名搜索
52
- * @type {string}
53
- */
54
- search_way: 'file',
55
- /**
56
- * 是否懒加载
57
- * @type {boolean}
58
- */
59
- lazy_load: true,
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({ ...Template.config, ...config }, parent);
79
- }
80
- }
81
-
82
- Template.prototype.Drive = Drive;
83
-
84
- /**
85
- * 解压模板
86
- * @param {string} file 模板压缩文件
87
- * @returns {object} 解压后的文件对象
88
- */
89
- Template.prototype.unzip = async function(file) {
90
- var done = await compressing.zip.uncompress(file, '/static/template'.fullname());
91
- return done;
92
- };
93
-
94
- /**
95
- * 获取模板
96
- * @param {string} key 模板键名
97
- * @returns {object} 模板对象
98
- */
99
- Template.prototype.get = function(key) {
100
- return this.mods[key];
101
- };
102
-
103
- /**
104
- * 主题模板模板池
105
- */
106
- if (!$.pool.template) {
107
- $.pool.template = {};
108
- }
109
-
110
- /**
111
- * 主题模板管理器,用于创建缓存
112
- * @param {string} scope 作用域
113
- * @param {string} title 标题
114
- * @returns {object} 返回一个缓存类
115
- */
116
- function templateAdmin(scope, title) {
117
- var sc = scope || $.val.scope + '';
118
- var obj = $.pool.template[sc];
119
- if (!obj) {
120
- $.pool.template[sc] = new Template({
121
- name: sc,
122
- title: title
123
- });
124
- obj = $.pool.template[sc];
125
- }
126
- return obj;
127
- }
128
-
129
- /**
130
- * @module 导出模板管理器
131
- */
132
- if ($.admin) {
133
- $.admin.template = templateAdmin;
134
- }
135
-
136
- module.exports = {
137
- Template
138
- };
1
+ const compressing = require("compressing");
2
+ const Manager = require("mm_machine").Manager;
3
+ const Drive = require("./drive").Drive;
4
+
5
+ /**
6
+ * 主题模板管理类
7
+ * @class
8
+ */
9
+ class Template 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: "template管理",
25
+ /**
26
+ * 描述
27
+ * @type {string}
28
+ */
29
+ description: "这是template管理器",
30
+ /**
31
+ * 检索文件名
32
+ * @type {string}
33
+ */
34
+ filename: "template.json",
35
+ /**
36
+ * 模板目录
37
+ * @type {string}
38
+ */
39
+ tpl_dir: __dirname,
40
+ /**
41
+ * 基础目录
42
+ * @type {string}
43
+ */
44
+ base_dir: "../common/template".fullname(__dirname),
45
+ /**
46
+ * 自定义目录,加载项目自定义资源
47
+ * @type {string}
48
+ */
49
+ dir: "./static/template".fullname(),
50
+ /**
51
+ * 搜索模式 dir按目录搜索 | file按文件名搜索
52
+ * @type {string}
53
+ */
54
+ search_way: "file",
55
+ /**
56
+ * 是否懒加载
57
+ * @type {boolean}
58
+ */
59
+ lazy_load: true,
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({ ...Template.config, ...config }, parent);
79
+ }
80
+ }
81
+
82
+ Template.prototype.Drive = Drive;
83
+
84
+ /**
85
+ * 解压模板
86
+ * @param {string} file 模板压缩文件
87
+ * @returns {object} 解压后的文件对象
88
+ */
89
+ Template.prototype.unzip = async function (file) {
90
+ var done = await compressing.zip.uncompress(
91
+ file,
92
+ "/static/template".fullname(),
93
+ );
94
+ return done;
95
+ };
96
+
97
+ /**
98
+ * 获取模板
99
+ * @param {string} key 模板键名
100
+ * @returns {object} 模板对象
101
+ */
102
+ Template.prototype.get = function (key) {
103
+ return this.mods[key];
104
+ };
105
+
106
+ /**
107
+ * 主题模板模板池
108
+ */
109
+ if (!$.pool.template) {
110
+ $.pool.template = {};
111
+ }
112
+
113
+ /**
114
+ * 主题模板管理器,用于创建缓存
115
+ * @param {string} scope 作用域
116
+ * @param {string} title 标题
117
+ * @returns {object} 返回一个缓存类
118
+ */
119
+ function templateAdmin(scope, title) {
120
+ var sc = scope || $.val.scope + "";
121
+ var obj = $.pool.template[sc];
122
+ if (!obj) {
123
+ $.pool.template[sc] = new Template({
124
+ name: sc,
125
+ title: title,
126
+ });
127
+ obj = $.pool.template[sc];
128
+ }
129
+ return obj;
130
+ }
131
+
132
+ /**
133
+ * @module 导出模板管理器
134
+ */
135
+ if ($.admin) {
136
+ $.admin.template = templateAdmin;
137
+ }
138
+
139
+ module.exports = {
140
+ Template,
141
+ };