mm_os 4.1.7 → 4.1.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.
package/adapter/mqtt.js CHANGED
@@ -31,6 +31,7 @@ class Mqtt extends Adapter {
31
31
  /**
32
32
  * 初始化适配器
33
33
  * @param {object} cache 缓存管理器
34
+ * @returns {object} 适配器实例
34
35
  * @private
35
36
  */
36
37
  Mqtt.prototype._init = function (cache) {
package/adapter/socket.js CHANGED
@@ -21,6 +21,7 @@ class Socket extends Adapter {
21
21
 
22
22
  /**
23
23
  * 初始化适配器
24
+ * @returns {object} 适配器实例
24
25
  * @private
25
26
  */
26
27
  Socket.prototype._init = function () {
package/adapter/web.js CHANGED
@@ -32,7 +32,7 @@ Web.prototype._preset = function () {
32
32
 
33
33
  /**
34
34
  * 使用中间件
35
- * @param {function} middleware 中间件函数
35
+ * @param {Function} middleware 中间件函数
36
36
  */
37
37
  Web.prototype.use = function (middleware) {
38
38
  this.web.use(middleware);
@@ -41,6 +41,7 @@ Web.prototype.use = function (middleware) {
41
41
  /**
42
42
  * 初始化
43
43
  * @param {object} server 服务器实例
44
+ * @returns {object} 适配器实例
44
45
  */
45
46
  Web.prototype.init = function (server) {
46
47
  if (server) {
@@ -137,7 +137,7 @@ WebSocket.prototype._onError = function (client_id, error) {
137
137
 
138
138
  /**
139
139
  * 使用中间件
140
- * @param {function} middleware 中间件函数
140
+ * @param {Function} middleware 中间件函数
141
141
  */
142
142
  WebSocket.prototype.use = function (middleware) {
143
143
  this.broker.use(middleware);
package/com/api/drive.js CHANGED
@@ -50,8 +50,8 @@ class Drive extends Item {
50
50
  };
51
51
  /**
52
52
  * 构造函数
53
- * @param {Object} config 配置项
54
- * @param {Object} parent 父对象
53
+ * @param {object} config 配置项
54
+ * @param {object} parent 父对象
55
55
  * @class
56
56
  */
57
57
  constructor(config, parent) {
@@ -701,7 +701,7 @@ Drive.prototype.getModel = function (type) {
701
701
  model.app = app_name;
702
702
  model.plugin = plugin_name;
703
703
  model.name = model.name || name;
704
- model.path = "/" + app_name + "/" + name;
704
+ model.path = '/' + app_name + '/' + name;
705
705
  return model;
706
706
  };
707
707
 
package/com/api/index.js CHANGED
@@ -114,14 +114,14 @@ Api.prototype.isMatch = function (str, pattern) {
114
114
  if (str === pattern) {
115
115
  return true;
116
116
  } else if (pattern.startsWith('*')) {
117
- const clean = pattern.replaceAll('*', '');
117
+ let clean = pattern.replaceAll('*', '');
118
118
  if (pattern.endsWith('*')) {
119
119
  return str.indexOf(clean) !== -1;
120
120
  } else {
121
121
  return str.endsWith(clean);
122
122
  }
123
123
  } else if (pattern.endsWith('*')) {
124
- const clean = pattern.replaceAll('*', '');
124
+ let clean = pattern.replaceAll('*', '');
125
125
  return str.startsWith(clean);
126
126
  }
127
127
  else {
package/com/cmd/drive.js CHANGED
@@ -177,8 +177,8 @@ Drive.prototype.enhancedMatch = function (msg, db) {
177
177
  Drive.prototype._contextAwareMatch = function (msg, db) {
178
178
  var name = this.config.name.toLowerCase();
179
179
  var title = this.config.title.toLowerCase();
180
- var description = this.config.description.toLowerCase();
181
- var content = (msg.content || '').toLowerCase();
180
+ // var description = this.config.description.toLowerCase();
181
+ // var content = (msg.content || '').toLowerCase();
182
182
 
183
183
  // 1. 基于消息类型的匹配
184
184
  if (this._matchByMsgType(msg, name, title)) {
@@ -21,12 +21,13 @@ module.exports = {
21
21
  async main(msg, db) {
22
22
  let form = msg.form;
23
23
  return {
24
- "location": "梅州",
25
- "datetime": "2023-08-25 12:00",
26
- "weather": "晴朗",
27
- "temperature": "25",
28
- "humidity": "60%",
29
- "wind": "3级"
24
+ location: '梅州',
25
+ datetime: '2023-08-25 12:00',
26
+ weather: '晴朗',
27
+ temperature: '25',
28
+ humidity: '60%',
29
+ wind: '3级',
30
+ ...form
30
31
  }
31
32
  }
32
33
  };
package/com/db/drive.js CHANGED
@@ -65,7 +65,7 @@ Drive.prototype._preset = function () {
65
65
 
66
66
  // 是否设置默认该表仅用户可访问
67
67
  this.query_default_table = ['user'];
68
- }
68
+ };
69
69
 
70
70
  /**
71
71
  * 解析字段类型
@@ -220,14 +220,14 @@ Event.prototype.isMatch = function (str, pattern) {
220
220
  if (str === pattern) {
221
221
  return true;
222
222
  } else if (pattern.startsWith('*')) {
223
- const clean = pattern.replaceAll('*', '');
223
+ let clean = pattern.replaceAll('*', '');
224
224
  if (pattern.endsWith('*')) {
225
225
  return str.indexOf(clean) !== -1;
226
226
  } else {
227
227
  return str.endsWith(clean);
228
228
  }
229
229
  } else if (pattern.endsWith('*')) {
230
- const clean = pattern.replaceAll('*', '');
230
+ let clean = pattern.replaceAll('*', '');
231
231
  return str.startsWith(clean);
232
232
  }
233
233
  else {
package/com/mqtt/index.js CHANGED
@@ -533,7 +533,7 @@ Mqtt.prototype.req = function (topic, method, params, func, timeout = 0) {
533
533
 
534
534
  // 设置超时移除定时器
535
535
  var _this = this;
536
- data.timer = setTimeout(function () {
536
+ data.timer = setTimeout(() => {
537
537
  _this._delMsgById(data.id);
538
538
  }, data.timeout);
539
539
  }
@@ -586,17 +586,17 @@ Mqtt.prototype._handleResponse = function (msg) {
586
586
  }
587
587
 
588
588
  for (var i = 0; i < this.list_msg.length; i++) {
589
- var msg_item = this.list_msg[i];
590
- if (msg_item.id === msg.id && msg_item.func) {
589
+ let o = this.list_msg[i];
590
+ if (o.id === msg.id && o.func) {
591
591
  try {
592
592
  // 执行回调函数
593
- msg_item.func(msg);
593
+ o.func(msg);
594
594
  } catch (error) {
595
595
  console.error('MQTT回调函数执行错误:', error);
596
596
  }
597
597
 
598
598
  // 从列表中移除已处理的消息
599
- this._delMsgById(msg.id);
599
+ this._delMsgById(o.id);
600
600
  break;
601
601
  }
602
602
  }
@@ -642,7 +642,7 @@ Mqtt.prototype.updateOnline = async function () {
642
642
 
643
643
  // 获取所有客户端
644
644
  var drives = await this.getClients();
645
- var { list_online, list_offline, list_has } = this._processDeviceStatus(drives, now, online_expires);
645
+ var { list_online, list_offline } = this._processDeviceStatus(drives, now, online_expires);
646
646
 
647
647
  // 处理未出现的设备
648
648
  // this._processUnseenDevices(drives, list_offline, list_has);
@@ -1,8 +1,4 @@
1
1
  const MQTT = require('mqtt');
2
- const {
3
- v4
4
- } = require('uuid');
5
-
6
2
 
7
3
  /**
8
4
  * @module MQTT客户端
@@ -32,7 +28,6 @@ class Mqtt {
32
28
  */
33
29
  constructor(config) {
34
30
  this.config = {...Mqtt.config, ...config};
35
- var client_id = v4();
36
31
  // mqtt客户端服务器
37
32
  this.client = null;
38
33
 
@@ -7,7 +7,7 @@ const Drive = require('./drive');
7
7
  * @class
8
8
  */
9
9
  class Param extends Manager {
10
- /**
10
+ /**
11
11
  * 配置参数
12
12
  * @type {object}
13
13
  */
@@ -111,6 +111,7 @@ Param.prototype.run = async function(db, name, query, body) {
111
111
  try {
112
112
  return await obj.run(db, query, body);
113
113
  } catch (error) {
114
+ this.log('error', 'Param验证异常:', error);
114
115
  // 参数验证异常时返回null
115
116
  return null;
116
117
  }
@@ -39,7 +39,7 @@ Drive.prototype._getStorageKey = function () {
39
39
  * 确保数据引用有效(热更新后调用)
40
40
  * @private
41
41
  */
42
- Drive.prototype._ensureDataRefs = function () {
42
+ Drive.prototype._ensureRefs = function () {
43
43
  var storage_key = this._getStorageKey();
44
44
 
45
45
  // 检查全局存储是否存在
@@ -291,7 +291,7 @@ Drive.prototype.add = async function (ctx) {
291
291
  */
292
292
  Drive.prototype.send = function (token, method, params) {
293
293
  // 确保数据引用有效(热更新保护)
294
- this._ensureDataRefs();
294
+ this._ensureRefs();
295
295
 
296
296
  var list = this.clients[token];
297
297
  if (list && list.length > 0) {
@@ -319,7 +319,7 @@ Drive.prototype.send = function (token, method, params) {
319
319
  */
320
320
  Drive.prototype.sendAll = function (method, params) {
321
321
  // 确保数据引用有效(热更新保护)
322
- this._ensureDataRefs();
322
+ this._ensureRefs();
323
323
 
324
324
  var data = {
325
325
  method: method,
@@ -349,7 +349,7 @@ Drive.prototype.sendAll = function (method, params) {
349
349
  */
350
350
  Drive.prototype.req = function (token, method, params, func, timeout = 0) {
351
351
  // 确保数据引用有效(热更新保护)
352
- this._ensureDataRefs();
352
+ this._ensureRefs();
353
353
 
354
354
  var list = this.clients[token];
355
355
  if (list && list.length > 0) {
@@ -369,7 +369,7 @@ Drive.prototype.req = function (token, method, params, func, timeout = 0) {
369
369
 
370
370
  // 设置超时移除定时器
371
371
  var _this = this;
372
- data.timer = setTimeout(function() {
372
+ data.timer = setTimeout(() => {
373
373
  _this._delMsgById(data.id);
374
374
  }, data.timeout);
375
375
  }
@@ -395,7 +395,7 @@ Drive.prototype.req = function (token, method, params, func, timeout = 0) {
395
395
  */
396
396
  Drive.prototype.reqAll = function (method, params, func, timeout = 0) {
397
397
  // 确保数据引用有效(热更新保护)
398
- this._ensureDataRefs();
398
+ this._ensureRefs();
399
399
 
400
400
  var data = {
401
401
  id: this._genMsgId(),
@@ -413,7 +413,7 @@ Drive.prototype.reqAll = function (method, params, func, timeout = 0) {
413
413
 
414
414
  // 设置超时移除定时器
415
415
  var _this = this;
416
- data.timer = setTimeout(function() {
416
+ data.timer = setTimeout(() => {
417
417
  _this._delMsgById(data.id);
418
418
  }, data.timeout);
419
419
  }
@@ -446,7 +446,7 @@ Drive.prototype._genMsgId = function () {
446
446
  */
447
447
  Drive.prototype._delMsgById = function (msg_id) {
448
448
  // 确保数据引用有效(热更新保护)
449
- this._ensureDataRefs();
449
+ this._ensureRefs();
450
450
 
451
451
  for (var i = 0; i < this.list_msg.length; i++) {
452
452
  if (this.list_msg[i].id === msg_id) {
@@ -467,24 +467,24 @@ Drive.prototype._delMsgById = function (msg_id) {
467
467
  */
468
468
  Drive.prototype._handleResponse = function (msg) {
469
469
  // 确保数据引用有效(热更新保护)
470
- this._ensureDataRefs();
470
+ this._ensureRefs();
471
471
 
472
472
  if (!msg || !msg.id) {
473
473
  return;
474
474
  }
475
475
 
476
476
  for (var i = 0; i < this.list_msg.length; i++) {
477
- var msg_item = this.list_msg[i];
478
- if (msg_item.id === msg.id && msg_item.func) {
477
+ let o = this.list_msg[i];
478
+ if (o.id === msg.id && o.func) {
479
479
  try {
480
480
  // 执行回调函数
481
- msg_item.func(msg);
481
+ o.func(msg);
482
482
  } catch (error) {
483
483
  console.error('Socket驱动回调函数执行错误:', error);
484
484
  }
485
485
 
486
486
  // 从列表中移除已处理的消息
487
- this._delMsgById(msg.id);
487
+ this._delMsgById(o.id);
488
488
  break;
489
489
  }
490
490
  }
@@ -7,7 +7,7 @@ const Drive = require('./drive');
7
7
  * @class
8
8
  */
9
9
  class Socket extends Manager {
10
- /**
10
+ /**
11
11
  * 配置参数
12
12
  * @type {object}
13
13
  */
@@ -282,17 +282,17 @@ Socket.prototype._handleResponse = function (msg) {
282
282
  }
283
283
 
284
284
  for (var i = 0; i < this.list_msg.length; i++) {
285
- var msg_item = this.list_msg[i];
286
- if (msg_item.id === msg.id && msg_item.func) {
285
+ let o = this.list_msg[i];
286
+ if (o.id === msg.id && o.func) {
287
287
  try {
288
288
  // 执行回调函数
289
- msg_item.func(msg);
289
+ o.func(msg);
290
290
  } catch (error) {
291
291
  console.error('Socket回调函数执行错误:', error);
292
292
  }
293
293
 
294
294
  // 从列表中移除已处理的消息
295
- this._delMsgById(msg.id);
295
+ this._delMsgById(o.id);
296
296
  break;
297
297
  }
298
298
  }
@@ -3,43 +3,44 @@ const Item = require('mm_machine').Item;
3
3
 
4
4
  /**
5
5
  * 主题模板驱动类
6
- * @extends {Item}
7
6
  * @class
8
7
  */
9
8
  class Drive extends Item {
10
- static config = {
11
- "name": "",
12
- "title": "",
13
- "preview": "",
14
- "preview_large": "",
15
- "description": "",
16
- "version": "1.0.0",
17
- "git": ""
18
- };
9
+ static config = {
10
+ name: '',
11
+ title: '',
12
+ description: '',
13
+ version: '1.0.0',
14
+ preview: '',
15
+ preview_large: '',
16
+ git: ''
17
+ };
19
18
 
20
- /**
21
- * 主题模板驱动类
22
- * @param {object} config 主题模板配置
23
- * @param {object} parent 父项
24
- */
25
- constructor(config, parent) {
26
- super({ ...Drive.config, ...config }, parent);
27
- // this.default_file = "./template.json";
28
- // dir, "/static/template".fullname()
29
- }
19
+ /**
20
+ * 主题模板驱动类
21
+ * @param {object} config 主题模板配置
22
+ * @param {object} parent 父项
23
+ */
24
+ constructor(config, parent) {
25
+ super({ ...Drive.config, ...config }, parent);
26
+ // this.default_file = "./template.json";
27
+ // dir, "/static/template".fullname()
28
+ }
30
29
  }
31
30
 
32
31
  /**
33
32
  * 压缩主题模板
33
+ * @param {string} zip_dir 压缩目录
34
+ * @returns {object} 压缩后的文件对象
34
35
  */
35
- Drive.prototype.zip = async function (zip_dir = "/static/file/zip/") {
36
- var file = ("./" + this.config.name + '.zip').fullname(zip_dir);
37
- file.addDir();
38
- var done = await compressing.zip.compressDir(this.getDir(), file);
39
- if (file.hasFile()) {
40
- return file;
41
- }
42
- return null;
36
+ Drive.prototype.zip = async function (zip_dir = '/static/file/zip/') {
37
+ var file = ('./' + this.config.name + '.zip').fullname(zip_dir);
38
+ file.addDir();
39
+ await compressing.zip.compressDir(this.getDir(), file);
40
+ if (file.hasFile()) {
41
+ return file;
42
+ }
43
+ return null;
43
44
  };
44
45
 
45
46
  /**
@@ -75,6 +76,6 @@ Drive.prototype.getModel = function (type) {
75
76
  };
76
77
 
77
78
  module.exports = {
78
- Drive
79
+ Drive
79
80
  };
80
81
 
@@ -3,12 +3,11 @@ const Index = require('mm_machine').Index;
3
3
  const Drive = require('./drive').Drive;
4
4
 
5
5
  /**
6
- * 参数类
7
- * @extends {Index}
6
+ * 主题模板管理类
8
7
  * @class
9
8
  */
10
9
  class Template extends Index {
11
- /**
10
+ /**
12
11
  * 配置参数
13
12
  * @type {object}
14
13
  */
@@ -70,28 +69,26 @@ class Template extends Index {
70
69
  mode: 3
71
70
  };
72
71
 
73
- /**
74
- * 构造函数
75
- * @param {String} scope 作用域
76
- * @param {String} title 标题
77
- * @constructor
78
- */
79
- constructor(config, parent) {
80
- super({ ...Template.config, ...config }, parent);
81
- this.type = "template";
82
- this.title = config.title;
83
- }
72
+ /**
73
+ * 构造函数
74
+ * @param {object} config 配置参数
75
+ * @param {object} parent 父项
76
+ */
77
+ constructor(config, parent) {
78
+ super({ ...Template.config, ...config }, parent);
79
+ }
84
80
  }
85
81
 
86
82
  Template.prototype.Drive = Drive;
87
83
 
88
84
  /**
89
85
  * 解压模板
90
- * @param {Object} file 模板压缩文件
86
+ * @param {string} file 模板压缩文件
87
+ * @returns {object} 解压后的文件对象
91
88
  */
92
89
  Template.prototype.unzip = async function(file) {
93
- var done = await compressing.zip.uncompress(file, "/static/template".fullname());
94
- return done;
90
+ var done = await compressing.zip.uncompress(file, '/static/template'.fullname());
91
+ return done;
95
92
  };
96
93
 
97
94
  /**
@@ -107,7 +104,7 @@ Template.prototype.get = function(key) {
107
104
  * 主题模板模板池
108
105
  */
109
106
  if (!$.pool.template) {
110
- $.pool.template = {};
107
+ $.pool.template = {};
111
108
  }
112
109
 
113
110
  /**
@@ -117,25 +114,25 @@ if (!$.pool.template) {
117
114
  * @returns {object} 返回一个缓存类
118
115
  */
119
116
  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;
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;
130
127
  }
131
128
 
132
129
  /**
133
130
  * @module 导出模板管理器
134
131
  */
135
132
  if ($.admin) {
136
- $.admin.template = templateAdmin;
133
+ $.admin.template = templateAdmin;
137
134
  }
138
135
 
139
136
  module.exports = {
140
- Template
137
+ Template
141
138
  };
@@ -4,10 +4,10 @@
4
4
  module.exports = {
5
5
  /**
6
6
  * 中间件初始化
7
- * @param {object} apapter 适配器
7
+ * @param {object} adapter 适配器
8
8
  * @param {object} eventer 事件处理器
9
9
  */
10
- async _init(apapter, eventer) {
10
+ async _init(adapter, eventer) {
11
11
  var event = $.admin.event('api', 'API事件');
12
12
  // await event.call('update', 'app/');
13
13
  await event.do('init');
@@ -37,11 +37,11 @@ class App extends Drive {
37
37
  'author': 'qww',
38
38
  'scope': 'server',
39
39
  'dir': '',
40
- // 游戏配置,非游戏模块不需要配置
41
- 'game': {
42
- // 游戏类型
43
- 'type': 'card_game'
44
- },
40
+ // // 游戏配置,非游戏模块不需要配置
41
+ // 'game': {
42
+ // // 游戏类型
43
+ // 'type': 'card_game'
44
+ // },
45
45
  'dependencies': [],
46
46
  // // 压缩目录
47
47
  // 'zip_dir': './static/file/zip',
@@ -183,12 +183,12 @@ App.prototype._initManager = async function () {
183
183
  }
184
184
 
185
185
  // 并行执行所有管理器的初始化操作
186
- var init_promises = [];
186
+ var list = [];
187
187
  for (var j = 0; j < managers.length; j++) {
188
- init_promises.push(managers[j].do('init'));
188
+ list.push(managers[j].do('init'));
189
189
  }
190
190
 
191
- await Promise.all(init_promises);
191
+ await Promise.all(list);
192
192
  // console.timeEnd('[TIMING] App._initManager');
193
193
  };
194
194
 
@@ -216,29 +216,16 @@ App.prototype._loadSources = async function () {
216
216
  * 初始化路由相关模块
217
217
  */
218
218
  App.prototype._initRouteMod = async function () {
219
- // console.time('[TIMING] App._initRouteMod');
220
-
221
- // console.time('[TIMING] App._initRouteMod/store+view+model');
222
219
  await Promise.all([
223
220
  this.manager.store.runAll('init', this.sql, this.cache, this.getLogger()),
224
221
  this.manager.view.runAll('init', this.getLogger()),
225
222
  this.manager.model.runAll('init', this.getEventer(), this.getLogger())
226
223
  ]);
227
- // console.timeEnd('[TIMING] App._initRouteMod/store+view+model');
228
-
229
- // console.time('[TIMING] App._initRouteMod/service');
230
224
  await this.manager.service.runAll('init', this.model, this.getEventer(), this.getLogger());
231
- // console.timeEnd('[TIMING] App._initRouteMod/service');
232
-
233
- // console.time('[TIMING] App._initRouteMod/controller+handler');
234
-
235
225
  await Promise.all([
236
226
  this.manager.controller.runAll('init', this.model, this.service, this.view, this.getEventer(), this.getLogger()),
237
227
  this.manager.handler.runAll('init', this, this.getEventer(), this.getLogger())
238
228
  ]);
239
- // console.timeEnd('[TIMING] App._initRouteMod/controller+handler');
240
-
241
- // console.timeEnd('[TIMING] App._initRouteMod');
242
229
  };
243
230
 
244
231
  /**
@@ -246,15 +233,8 @@ App.prototype._initRouteMod = async function () {
246
233
  * @returns {Promise<void>} 初始化完成
247
234
  */
248
235
  App.prototype._initSources = async function () {
249
- // console.time('[TIMING] App._initSources');
250
-
251
- // console.time('[TIMING] App._initSources/plugin');
252
- // await this.manager.plugin.runWait('init', this, this.getEventer(), this.getLogger());
253
- await this.manager.plugin.runAll('init', this, this.getEventer(), this.getLogger());
254
- // console.timeEnd('[TIMING] App._initSources/plugin');
255
-
256
236
  await this._initRouteMod();
257
- // console.timeEnd('[TIMING] App._initSources');
237
+ await this.manager.plugin.runWait('init', this, this.getEventer(), this.getLogger());
258
238
  };
259
239
 
260
240
  /**
@@ -265,7 +245,7 @@ App.prototype._initSources = async function () {
265
245
  * @private
266
246
  */
267
247
  App.prototype._initCore = async function (server, eventer, logger) {
268
- if (logger) {
248
+ if (logger) {
269
249
  this.setLogger(logger);
270
250
  }
271
251
  if (eventer) {
@@ -358,32 +338,6 @@ App.prototype._validateDep = function () {
358
338
  }
359
339
  };
360
340
 
361
- /**
362
- * 记录初始化结果
363
- * @param {Array} results 初始化结果数组
364
- * @private
365
- */
366
- App.prototype._logInitResults = function (results) {
367
- var success = 0;
368
- var error = 0;
369
- var error_modules = [];
370
-
371
- for (var result of results) {
372
- if (result.result && result.result.error_count > 0) {
373
- error += result.result.error_count;
374
- error_modules.push(result.name);
375
- } else {
376
- success++;
377
- }
378
- }
379
-
380
- if (error > 0) {
381
- this.log('warn', `资源初始化完成,成功: ${success}, 失败: ${error}, 失败模块: ${error_modules.join(', ')}`);
382
- } else {
383
- this.log('info', `所有资源初始化成功,共 ${success} 个模块`);
384
- }
385
- };
386
-
387
341
  /**
388
342
  * 压缩插件
389
343
  * @param {string} name 插件名称
package/core/app/index.js CHANGED
@@ -3,24 +3,6 @@ const {
3
3
  Manager,
4
4
  Drive
5
5
  } = require('mm_machine');
6
- const {
7
- Controller
8
- } = require('../controller/index.js');
9
- const {
10
- View
11
- } = require('../view/index.js');
12
- const {
13
- Handler
14
- } = require('../handler/index.js');
15
- const {
16
- Service
17
- } = require('../service/index.js');
18
- const {
19
- Model
20
- } = require('../model/index.js');
21
- const {
22
- Store
23
- } = require('../store/index.js');
24
6
  const {
25
7
  Plugin
26
8
  } = require('../plugin/index.js');
@@ -94,21 +76,6 @@ class App extends Drive {
94
76
  // 管理器集合
95
77
  this.manager = {};
96
78
 
97
- /** == 业务类 == */
98
- // MVC 架构
99
- // 控制器集合
100
- this.controller = {};
101
- // 视图集合
102
- this.view = {};
103
- // 操作器集合
104
- this.handler = {};
105
- // 领域服务
106
- this.service = {};
107
- // 富血模型
108
- this.model = {};
109
- // 仓储
110
- this.store = {};
111
-
112
79
  // 插件,用于功能扩展
113
80
  this.plugin = {};
114
81
  }
@@ -163,12 +130,6 @@ App.prototype._initManager = async function () {
163
130
  // console.time('[TIMING] App._initManager');
164
131
  // 管理器配置列表
165
132
  var mgr_configs = [
166
- { name: 'store', title: '仓储', Module: Store },
167
- { name: 'model', title: '模型', Module: Model },
168
- { name: 'service', title: '服务', Module: Service },
169
- { name: 'handler', title: '操作器', Module: Handler },
170
- { name: 'view', title: '视图', Module: View },
171
- { name: 'controller', title: '控制器', Module: Controller },
172
133
  { name: 'plugin', title: '插件', Module: Plugin }
173
134
  ];
174
135
 
@@ -197,35 +158,7 @@ App.prototype._initManager = async function () {
197
158
  * @returns {Promise<void>} 加载完成
198
159
  */
199
160
  App.prototype._loadSources = async function () {
200
- // console.time('[TIMING] App._loadSources');
201
- // 加载无需依赖关系,所以可以同时加载,内部并行执行
202
- let loadPromises = [
203
- this.manager.store.runAll('load'),
204
- this.manager.model.runAll('load'),
205
- this.manager.service.runAll('load'),
206
- this.manager.handler.runAll('load'),
207
- this.manager.view.runAll('load'),
208
- this.manager.controller.runAll('load'),
209
- this.manager.plugin.runAll('load')
210
- ];
211
- await Promise.all(loadPromises);
212
- // console.timeEnd('[TIMING] App._loadSources');
213
- };
214
-
215
- /**
216
- * 初始化路由相关模块
217
- */
218
- App.prototype._initRouteMod = async function () {
219
- await Promise.all([
220
- this.manager.store.runAll('init', this.sql, this.cache, this.getLogger()),
221
- this.manager.view.runAll('init', this.getLogger()),
222
- this.manager.model.runAll('init', this.getEventer(), this.getLogger())
223
- ]);
224
- await this.manager.service.runAll('init', this.model, this.getEventer(), this.getLogger());
225
- await Promise.all([
226
- this.manager.controller.runAll('init', this.model, this.service, this.view, this.getEventer(), this.getLogger()),
227
- this.manager.handler.runAll('init', this, this.getEventer(), this.getLogger())
228
- ]);
161
+ await this.manager.plugin.runAll('load');
229
162
  };
230
163
 
231
164
  /**
@@ -233,8 +166,7 @@ App.prototype._initRouteMod = async function () {
233
166
  * @returns {Promise<void>} 初始化完成
234
167
  */
235
168
  App.prototype._initSources = async function () {
236
- await this._initRouteMod();
237
- await this.manager.plugin.runWait('init', this, this.getEventer(), this.getLogger());
169
+ await this.manager.plugin.runAll('init', this, this.getEventer(), this.getLogger());
238
170
  };
239
171
 
240
172
  /**
@@ -245,7 +177,7 @@ App.prototype._initSources = async function () {
245
177
  * @private
246
178
  */
247
179
  App.prototype._initCore = async function (server, eventer, logger) {
248
- if (logger) {
180
+ if (logger) {
249
181
  this.setLogger(logger);
250
182
  }
251
183
  if (eventer) {
@@ -301,16 +233,7 @@ App.prototype._initBase = async function () {
301
233
  * 启动资源
302
234
  */
303
235
  App.prototype._startSources = async function () {
304
- // 启动无顺序的管理器(保持并行执行)
305
- let startPromises = [
306
- this.manager.handler.runAll('start'),
307
- this.manager.service.runAll('start'),
308
- this.manager.store.runAll('start'),
309
- this.manager.plugin.runAll('start')
310
- ];
311
-
312
- // 等待其他管理器启动完成
313
- await Promise.all(startPromises);
236
+ await this.manager.plugin.runAll('start');
314
237
  };
315
238
 
316
239
  /**
@@ -329,7 +252,7 @@ App.prototype._startCore = async function () {
329
252
  * @private
330
253
  */
331
254
  App.prototype._validateDep = function () {
332
- var required_managers = ['store', 'model', 'service', 'handler', 'view', 'controller', 'plugin'];
255
+ var required_managers = ['plugin'];
333
256
 
334
257
  for (var name of required_managers) {
335
258
  if (!this.manager[name]) {
@@ -1,6 +1,5 @@
1
1
  const {
2
- Drive,
3
- Manager
2
+ Drive
4
3
  } = require('mm_machine');
5
4
  const {
6
5
  RoomAdmin
@@ -335,9 +335,7 @@ Controller.prototype._after = async function (req, res, result) {
335
335
  /**
336
336
  * 格式化响应
337
337
  * 优化:复用响应对象,减少GC压力
338
- * @param {number} code 响应码
339
- * @param {string} message 响应消息
340
- * @param {object} data 响应数据
338
+ * @param {object} result 响应数据
341
339
  * @returns {object} 格式化后的响应对象
342
340
  */
343
341
  Controller.prototype._formatResponse = function (result) {
@@ -99,7 +99,7 @@ GameWorld.prototype.getTplDir = function () {
99
99
  * @returns {string} 游戏管理器目录
100
100
  */
101
101
  GameWorld.prototype.getDir = function () {
102
- return this.getGame()._
102
+ return this.getGame().getDir();
103
103
  };
104
104
 
105
105
  /**
@@ -73,7 +73,7 @@ Game.prototype._initCore = async function (server, eventer, logger) {
73
73
  return server;
74
74
  };
75
75
  }
76
- if (logger) {
76
+ if (logger) {
77
77
  this.setLogger(logger);
78
78
  }
79
79
  if (eventer) {
@@ -34,12 +34,12 @@ Middleware.prototype.getTplDir = function () {
34
34
 
35
35
  /**
36
36
  * 初始化核心
37
- * @param {object} apapter 适配器
37
+ * @param {object} adapter 适配器
38
38
  * @param {object} eventer 事件总线
39
39
  * @param {object} logger 日志管理器
40
40
  * @returns {Promise<void>}
41
41
  */
42
- Middleware.prototype._initCore = async function (apapter, eventer, logger) {
42
+ Middleware.prototype._initCore = async function (adapter, eventer, logger) {
43
43
  // 初始化依赖项
44
44
  if (logger) {
45
45
  this.setLogger(logger);
@@ -49,9 +49,9 @@ Middleware.prototype._initCore = async function (apapter, eventer, logger) {
49
49
  return eventer;
50
50
  };
51
51
  }
52
- if (apapter) {
52
+ if (adapter) {
53
53
  this.getAdapter = function () {
54
- return apapter[this.config.type];
54
+ return adapter[this.config.type];
55
55
  };
56
56
  }
57
57
  this._register();
@@ -4,11 +4,11 @@
4
4
  module.exports = {
5
5
  /**
6
6
  * 中间件初始化
7
- * @param {object} apapter 适配器
7
+ * @param {object} adapter 适配器
8
8
  * @param {object} eventer 事件处理器
9
9
  */
10
- async _init(apapter, eventer) {
11
- this.log('debug', 'middleware _init 被调用', { apapter, eventer });
10
+ async _init(adapter, eventer) {
11
+ this.log('debug', 'middleware _init 被调用', { adapter, eventer });
12
12
  // 初始化代码写在这
13
13
  // 可在这里注入其他中间件
14
14
  },
@@ -108,51 +108,109 @@ Plugin.prototype._initOptions = function () {
108
108
  this.backupOptions();
109
109
  };
110
110
 
111
+ /**
112
+ * 转换数字类型值
113
+ * @param {*} value 原始值
114
+ * @returns {number} 转换后的值
115
+ * @private
116
+ */
117
+ Plugin.prototype._convertNumber = function (value) {
118
+ if (value === 'null') return 0;
119
+ return Number(value || '0');
120
+ };
121
+
122
+ /**
123
+ * 转换布尔类型值
124
+ * @param {*} value 原始值
125
+ * @returns {boolean} 转换后的值
126
+ * @private
127
+ */
128
+ Plugin.prototype._convertBoolean = function (value) {
129
+ if (!value) return false;
130
+ if (typeof value === 'boolean') return value;
131
+ if (typeof value === 'string') {
132
+ return value === '1' || value === 'true';
133
+ }
134
+ return false;
135
+ };
136
+
137
+ /**
138
+ * 转换对象类型值
139
+ * @param {*} value 原始值
140
+ * @returns {object} 转换后的值
141
+ * @private
142
+ */
143
+ Plugin.prototype._convertObject = function (value) {
144
+ if (value === 'null') return {};
145
+ return value.toJSON ? value.toJSON() : {};
146
+ };
147
+
148
+ /**
149
+ * 转换数组类型值
150
+ * @param {*} value 原始值
151
+ * @returns {Array} 转换后的值
152
+ * @private
153
+ */
154
+ Plugin.prototype._convertArray = function (value) {
155
+ if (value === 'null') return [];
156
+ return value.toJSON ? value.toJSON() : [];
157
+ };
158
+
159
+ /**
160
+ * 转换字符串类型值
161
+ * @param {*} value 原始值
162
+ * @returns {string} 转换后的值
163
+ * @private
164
+ */
165
+ Plugin.prototype._convertString = function (value) {
166
+ if (value === 'null') return null;
167
+ return value || '';
168
+ };
169
+
170
+ /**
171
+ * 转换单个配置项的值
172
+ * @param {object} option 配置项
173
+ * @returns {*} 转换后的值
174
+ * @private
175
+ */
176
+ Plugin.prototype._convertOptionValue = function (option) {
177
+ var val = option.value;
178
+ if (val === 'null') return null;
179
+
180
+ var type = option.type;
181
+ switch (type) {
182
+ case 'number':
183
+ return this._convertNumber(val);
184
+ case 'boolean':
185
+ return this._convertBoolean(val);
186
+ case 'object':
187
+ return this._convertObject(val);
188
+ case 'array':
189
+ return this._convertArray(val);
190
+ case 'string':
191
+ return this._convertString(val);
192
+ default:
193
+ return val;
194
+ }
195
+ };
196
+
111
197
  /**
112
198
  * 获取配置参数
113
- * @return {Object} 返回配置参数
199
+ * @returns {object} 返回配置参数
114
200
  */
115
201
  Plugin.prototype.getConfigOptions = function () {
116
202
  var op = this.config.options || [];
117
203
  var dict = {};
118
204
  for (var i = 0; i < op.length; i++) {
119
205
  var o = op[i];
120
- if (o.type === "number") {
121
- var val = o.value === 'null' ? '0' : o.value;
122
- dict[o.name] = Number(val || '0');
123
- } else if (o.type === "boolean") {
124
- var val = false;
125
- if (o.value) {
126
- if (typeof (o.value) == "string") {
127
- if (o.value == '1' || o.value == 'true') {
128
- val = true;
129
- }
130
- } else if (typeof (o.value) == "boolean") {
131
- val = o.value;
132
- }
133
- }
134
- dict[o.name] = val;
135
- } else if (o.type === "object") {
136
- var val = o.value === 'null' ? '{}' : o.value;
137
- dict[o.name] = o.value.toJSON();
138
- } else if (o.type === "array") {
139
- var val = o.value === 'null' ? '[]' : o.value;
140
- dict[o.name] = o.value.toJSON();
141
- } else if (o.value === "null") {
142
- dict[o.name] = null;
143
- } else if (o.type === "string") {
144
- dict[o.name] = o.value || "";
145
- } else {
146
- dict[o.name] = o.value;
147
- }
206
+ dict[o.name] = this._convertOptionValue(o);
148
207
  }
149
208
  return dict;
150
209
  };
151
210
 
152
211
  /**
153
212
  * 设计配置
154
- * @param {Object} 设置配置
155
- * @return {Object} 返回配置参数
213
+ * @param {object} body 配置参数
156
214
  */
157
215
  Plugin.prototype.designOptions = function (body) {
158
216
  var cg = this.config;
@@ -174,6 +232,7 @@ Plugin.prototype.designOptions = function (body) {
174
232
 
175
233
  /**
176
234
  * 保存配置
235
+ * @param {object} options 配置参数
177
236
  */
178
237
  Plugin.prototype.saveOptions = function (options) {
179
238
  this.options = options;
@@ -192,7 +251,8 @@ Plugin.prototype.backupOptions = function () {
192
251
 
193
252
  /**
194
253
  * 合并配置
195
- * @param {Object} cg 配置
254
+ * @param {object} options 配置参数
255
+ * @returns {object} 返回配置参数
196
256
  */
197
257
  Plugin.prototype.mergeOptions = function (options) {
198
258
  var file = this._getCacheOptionsFile();
@@ -208,10 +268,6 @@ Plugin.prototype.mergeOptions = function (options) {
208
268
  * @returns {string} 缓存配置文件
209
269
  */
210
270
  Plugin.prototype._getCacheOptionsFile = function () {
211
- // let app = this.getApp();
212
- // let app_name = app.config.name;
213
- // let plugin_name = this.config.name;
214
- var l = $.slash;
215
271
  let plugin_name = this.config.name;
216
272
  let app_name = this.getApp().config.name;
217
273
  var file = `/cache/${app_name}/${plugin_name}/config.json`.fullname();
@@ -234,7 +290,7 @@ Drive.prototype.getModel = function (type) {
234
290
  model.app = app_name;
235
291
  model.plugin = plugin_name;
236
292
  model.name = model.name || name;
237
- model.path = "/" + app_name + "/" + name;
293
+ model.path = '/' + app_name + '/' + name;
238
294
  return model;
239
295
  };
240
296
 
package/core/room/room.js CHANGED
@@ -21,7 +21,7 @@ class Room {
21
21
 
22
22
  /**
23
23
  * 房间类构造函数
24
- * @param {Object} config 房间配置对象
24
+ * @param {object} config 房间配置对象
25
25
  */
26
26
  constructor(config) {
27
27
  // 房间ID
@@ -42,7 +42,7 @@ class Room {
42
42
 
43
43
  /**
44
44
  * 设置房间配置
45
- * @param {Object} config 房间配置对象
45
+ * @param {object} config 房间配置对象
46
46
  */
47
47
  Room.prototype.setConfig = function (config) {
48
48
  Object.assign(this.config, config);
@@ -21,6 +21,7 @@ class Scene extends Drive {
21
21
  /**
22
22
  * 构造函数
23
23
  * @param {object} config 配置参数
24
+ * @param {object} parent 父场景对象
24
25
  */
25
26
  constructor(config, parent) {
26
27
  super({ ...Scene.config, ...config || {} }, parent);
@@ -88,6 +88,7 @@ class Zone extends Drive {
88
88
  * @param {number} config.diy_cache 自定义缓存
89
89
  * @param {object} config.sql sql 配置
90
90
  * @param {object} config.cache 缓存配置
91
+ * @param {object} parent 父分区对象
91
92
  */
92
93
  constructor(config, parent) {
93
94
  super({ ...Zone.config, ...config }, parent);
@@ -198,6 +199,7 @@ Zone.prototype._initBase = async function () {
198
199
  * @param {object} app 游戏应用
199
200
  * @param {object} eventer 事件总线
200
201
  * @param {object} logger 日志管理器
202
+ * @returns {object} 返回分区对象
201
203
  */
202
204
  Zone.prototype._initCore = async function (app, eventer, logger) {
203
205
  // 初始化依赖项
@@ -94,6 +94,7 @@ class Zone extends Drive {
94
94
  * @param {number} config.diy_cache 自定义缓存
95
95
  * @param {object} config.sql sql 配置
96
96
  * @param {object} config.cache 缓存配置
97
+ * @param {object} parent 父分区对象
97
98
  */
98
99
  constructor(config, parent) {
99
100
  super({ ...Zone.config, ...config }, parent);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mm_os",
3
3
  "description": "MM_OS服务端架构,用于快速构建应用程序,支持网站建设、小程序后台、AI应用、物联网(IOT/AIOT)、游戏服务端等多种场景。",
4
- "version": "4.1.7",
4
+ "version": "4.1.8",
5
5
  "main": "index.js",
6
6
  "keywords": [
7
7
  "AI",
@@ -31,7 +31,7 @@
31
31
  "js-beautify": "^1.15.4",
32
32
  "koa": "^3.2.1",
33
33
  "koa-body": "^8.0.0",
34
- "koa-compress": "^5.2.1",
34
+ "koa-compress": "^5.2.2",
35
35
  "koa-send": "^5.0.1",
36
36
  "koa-websocket": "^7.0.0",
37
37
  "markdown": "^0.5.0",
@@ -52,14 +52,14 @@
52
52
  "mm_statics": "^1.8.4",
53
53
  "mm_xml": "^1.1.7",
54
54
  "mqtt": "^5.15.1",
55
- "openai": "^6.42.0"
55
+ "openai": "^6.44.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/jest": "^30.0.0",
59
59
  "eslint-formatter-table": "^7.32.1",
60
- "eslint-plugin-jsdoc": "^63.0.2",
60
+ "eslint-plugin-jsdoc": "^63.0.6",
61
61
  "jest": "^30.4.2",
62
- "mm_eslint": "^1.7.1"
62
+ "mm_eslint": "^1.7.5"
63
63
  },
64
64
  "repository": {
65
65
  "type": "git",
@@ -81,4 +81,4 @@
81
81
  "tcp.js",
82
82
  "software.js"
83
83
  ]
84
- }
84
+ }
package/server.js CHANGED
@@ -75,7 +75,7 @@ class Server {
75
75
  expire: 0,
76
76
  max: 0,
77
77
  persist: false, // 是否启用持久化
78
- saveInterval: 60000 // 保存间隔(毫秒)
78
+ save_interval: 60000 // 保存间隔(毫秒)
79
79
  },
80
80
  // 缓存配置
81
81
  redis: {
@@ -88,7 +88,7 @@ class Server {
88
88
  // 数据库
89
89
  database: 0,
90
90
  // 前缀
91
- prefix: "mm_",
91
+ prefix: 'mm_',
92
92
  // 连接超时时间(ms)
93
93
  connect_timeout: 5000,
94
94
  // 重试次数
@@ -160,7 +160,7 @@ class Server {
160
160
  // 是否开启gzip压缩
161
161
  gzip: false,
162
162
  // 静态文件根目录
163
- root: "./static",
163
+ root: './static',
164
164
  // 编译vue文件,启动后会将vue转为js,可让前端通过 import xxx from './xxx.vue' 引入
165
165
  compile_vue: true,
166
166
  // 编译markdown文件,启动后会将markdown转为html
@@ -414,6 +414,7 @@ Server.prototype._stop = async function () {
414
414
 
415
415
  /**
416
416
  * 运行
417
+ * @returns {object} 服务器实例
417
418
  */
418
419
  Server.prototype.run = async function () {
419
420
  // 初始化
package/software.js CHANGED
@@ -22,6 +22,7 @@ class Software {
22
22
 
23
23
  /**
24
24
  * 获取适配器
25
+ * @returns {object} 适配器实例
25
26
  */
26
27
  Software.prototype.getAdapter = function () {
27
28
  return this.getParent().adapter;
@@ -29,6 +30,7 @@ Software.prototype.getAdapter = function () {
29
30
 
30
31
  /**
31
32
  * 获取管理器
33
+ * @returns {object} 管理器实例
32
34
  */
33
35
  Software.prototype.getManager = function () {
34
36
  return this.getParent().manager;
@@ -74,7 +76,7 @@ Software.prototype._initSources = async function () {
74
76
  manager.game.runAll('init', server, server.eventer, server.logger),
75
77
  manager.app.runAll('init', server, server.eventer, server.logger)
76
78
  ]);
77
- await manager.mod.runAll('init', server, server.eventer, server.logger)
79
+ await manager.mod.runAll('init', server, server.eventer, server.logger);
78
80
  };
79
81
 
80
82
  /**
@@ -134,7 +136,7 @@ Software.prototype._createManager = function (name, title, cls) {
134
136
  // 设置到对应的管理器属性
135
137
  server.manager[name] = manager;
136
138
  return manager;
137
- }
139
+ };
138
140
 
139
141
  /**
140
142
  * 启动
@@ -178,6 +180,7 @@ Software.prototype._stopSources = async function () {
178
180
 
179
181
  /**
180
182
  * 运行
183
+ * @returns {object} 软件实例
181
184
  */
182
185
  Software.prototype.run = async function () {
183
186
  await this.load();
package/tcp.js CHANGED
@@ -41,6 +41,7 @@ class TCP {
41
41
 
42
42
  /**
43
43
  * 获取适配器
44
+ * @returns {object} 适配器实例
44
45
  */
45
46
  TCP.prototype.getAdapter = function () {
46
47
  return this.getParent().adapter;
@@ -48,6 +49,7 @@ TCP.prototype.getAdapter = function () {
48
49
 
49
50
  /**
50
51
  * 获取管理器
52
+ * @returns {object} 管理器实例
51
53
  */
52
54
  TCP.prototype.getManager = function () {
53
55
  return this.getParent().manager;
@@ -186,7 +188,7 @@ TCP.prototype._createManager = function (name, title, cls) {
186
188
  // 设置到对应的管理器属性
187
189
  server.manager[name] = manager;
188
190
  return manager;
189
- }
191
+ };
190
192
 
191
193
  /**
192
194
  * 启动
@@ -263,6 +265,7 @@ TCP.prototype._stopSources = async function () {
263
265
 
264
266
  /**
265
267
  * 运行
268
+ * @returns {object} TCP实例
266
269
  */
267
270
  TCP.prototype.run = async function () {
268
271
  await this.load();