mm_os 1.6.8 → 1.6.9
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/core/base/mqtt/index.js +48 -1
- package/core/com/api/index.js +5 -2
- package/core/com/event/drive.js +4 -3
- package/core/com/event/index.js +58 -1
- package/core/com/eventer/com.js +3 -0
- package/core/com/plugin/drive.js +3 -2
- package/core/com/plugin/index.js +3 -0
- package/core/com/sql/index.js +5 -1
- package/index.js +1 -0
- package/package.json +2 -2
package/core/base/mqtt/index.js
CHANGED
|
@@ -192,7 +192,25 @@ MQTT.prototype.main = function(state) {
|
|
|
192
192
|
this.auth(client, username, password, callback);
|
|
193
193
|
return true;
|
|
194
194
|
};
|
|
195
|
-
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 验证发布,决定客户端可以发布哪些主题
|
|
198
|
+
*/
|
|
199
|
+
sr.authorizePublish = (client, topic, payload, callback) => {
|
|
200
|
+
this.authPublish(client, topic, payload, callback);
|
|
201
|
+
return true;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 验证订阅,决定客户端可以订阅哪些主题
|
|
207
|
+
*/
|
|
208
|
+
sr.authorizeSubscribe = (client, topic, callback) => {
|
|
209
|
+
this.authSubscribe(client, topic, callback);
|
|
210
|
+
return true;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
|
|
196
214
|
/**
|
|
197
215
|
* 当服务开启时
|
|
198
216
|
*/
|
|
@@ -234,6 +252,35 @@ MQTT.prototype.auth = function(client, username, password, callback) {
|
|
|
234
252
|
callback(null, bl);
|
|
235
253
|
};
|
|
236
254
|
|
|
255
|
+
/**
|
|
256
|
+
* 验证发布,决定客户端可以发布哪些主题
|
|
257
|
+
* @param {Object} client 客户端
|
|
258
|
+
* @param {String} topic 用户名
|
|
259
|
+
* @param {Object} payload 参数
|
|
260
|
+
* @param {Function} callback 回调函数,回调返回true,则表示验证通过。
|
|
261
|
+
*/
|
|
262
|
+
MQTT.prototype.authPublish = function(client, topic, payload, callback) {
|
|
263
|
+
var bl = true;
|
|
264
|
+
// if(topic == "temperature"){
|
|
265
|
+
// bl = false;
|
|
266
|
+
// }
|
|
267
|
+
// console.log('收到推送', client.id, topic, payload.toString());
|
|
268
|
+
// 回调第二个参数为true表示验证通过, 为false表示验证失败
|
|
269
|
+
callback(null, bl);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 验证订阅,决定客户端可以订阅哪些主题
|
|
274
|
+
* @param {Object} client 客户端
|
|
275
|
+
* @param {String} topic 用户名
|
|
276
|
+
* @param {Function} callback 回调函数,回调返回true,则表示验证通过。
|
|
277
|
+
*/
|
|
278
|
+
MQTT.prototype.authSubscribe = function(client, topic, callback) {
|
|
279
|
+
var bl = true;
|
|
280
|
+
// 回调第二个参数为true表示验证通过, 为false表示验证失败
|
|
281
|
+
callback(null, bl);
|
|
282
|
+
};
|
|
283
|
+
|
|
237
284
|
/**
|
|
238
285
|
* 运行主程序前
|
|
239
286
|
* @param {String} state 状态
|
package/core/com/api/index.js
CHANGED
|
@@ -51,10 +51,13 @@ Api.prototype.run = async function(ctx, db) {
|
|
|
51
51
|
}
|
|
52
52
|
const path = ctx.request.path;
|
|
53
53
|
var lt = this.list;
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
for (var i = 0, o; o = lt[i++];) {
|
|
56
56
|
if (o.config.state === 1 && path.has(o.config.path)) {
|
|
57
57
|
var ret = await o.run(ctx, db);
|
|
58
|
+
if (this.mode) {
|
|
59
|
+
o.load(o.filename);
|
|
60
|
+
}
|
|
58
61
|
if (ret) {
|
|
59
62
|
db.ret = ret;
|
|
60
63
|
break;
|
|
@@ -127,4 +130,4 @@ function api_admin(scope, title) {
|
|
|
127
130
|
/**
|
|
128
131
|
* @module 导出API管理器
|
|
129
132
|
*/
|
|
130
|
-
$.api_admin = api_admin;
|
|
133
|
+
$.api_admin = api_admin;
|
package/core/com/event/drive.js
CHANGED
|
@@ -33,7 +33,7 @@ class Drive extends Item {
|
|
|
33
33
|
// 文件路径, 当调用函数不存在时,会先从文件中加载
|
|
34
34
|
"func_file": "./main.js",
|
|
35
35
|
// 回调函数名 用于决定调用脚本的哪个函数
|
|
36
|
-
"func_name": "
|
|
36
|
+
"func_name": "",
|
|
37
37
|
// 执行顺序, 数字越小,越优先执行
|
|
38
38
|
"sort": 100,
|
|
39
39
|
// 中断循环
|
|
@@ -105,10 +105,11 @@ Drive.prototype.new_config = function(file) {
|
|
|
105
105
|
* 执行事件
|
|
106
106
|
* @param {Object} ctx 请求上下文
|
|
107
107
|
* @param {Object} db 数据管理器
|
|
108
|
+
* @param {String} method 执行方法
|
|
108
109
|
* @return {Object} 执行结果
|
|
109
110
|
*/
|
|
110
|
-
Drive.prototype.run = async function(ctx, db) {
|
|
111
|
-
var ret = await this
|
|
111
|
+
Drive.prototype.run = async function(ctx, db, method = 'main') {
|
|
112
|
+
var ret = await this[method](ctx, db);
|
|
112
113
|
return ret;
|
|
113
114
|
};
|
|
114
115
|
|
package/core/com/event/index.js
CHANGED
|
@@ -140,6 +140,26 @@ Event.prototype.sort = function(stage) {
|
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 执行事件
|
|
146
|
+
*/
|
|
147
|
+
Event.prototype.doing = async function(o, ctx, db) {
|
|
148
|
+
var ret;
|
|
149
|
+
try {
|
|
150
|
+
ret = o.run(ctx, db);
|
|
151
|
+
if (types.isPromise(ret)) {
|
|
152
|
+
ret = await ret;
|
|
153
|
+
}
|
|
154
|
+
if (this.mode) {
|
|
155
|
+
o.load(o.filename);
|
|
156
|
+
}
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error(err);
|
|
159
|
+
}
|
|
160
|
+
return ret;
|
|
161
|
+
}
|
|
162
|
+
|
|
143
163
|
/**
|
|
144
164
|
* 执行函数
|
|
145
165
|
* @param {Array} list 列表
|
|
@@ -152,6 +172,9 @@ Event.prototype.run_sub = async function(list, target, ctx, db) {
|
|
|
152
172
|
for (var i = 0, o; o = list[i++];) {
|
|
153
173
|
if (o.config.state === 1 && target.has(o.config.target)) {
|
|
154
174
|
var ret = await o.run(ctx, db);
|
|
175
|
+
if (this.mode) {
|
|
176
|
+
o.load(o.filename);
|
|
177
|
+
}
|
|
155
178
|
if (ret) {
|
|
156
179
|
db.ret = ret;
|
|
157
180
|
if (o.config.end) {
|
|
@@ -246,6 +269,40 @@ Event.prototype.run = async function(target, ctx, db) {
|
|
|
246
269
|
return ret;
|
|
247
270
|
};
|
|
248
271
|
|
|
272
|
+
/**
|
|
273
|
+
* @description 获取事件
|
|
274
|
+
* @param {String} name 名称
|
|
275
|
+
* @param {String} event_type 事件类型
|
|
276
|
+
* @return {Object} 返回单项配置
|
|
277
|
+
*/
|
|
278
|
+
Event.prototype.get = function(name, event_type = 'main') {
|
|
279
|
+
var obj;
|
|
280
|
+
var lt = this['list_' + event_type];
|
|
281
|
+
var len = lt.length;
|
|
282
|
+
for (var i = 0; i < len; i++) {
|
|
283
|
+
var o = lt[i];
|
|
284
|
+
if (name === o.config.name) {
|
|
285
|
+
obj = o;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return obj;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @description 重载脚本和配置
|
|
294
|
+
* @param {String} file 文件名
|
|
295
|
+
* @return {String} 重载失败返回错误提示,重载成功返回null
|
|
296
|
+
*/
|
|
297
|
+
Event.prototype.reload = function(name, event_type = 'main') {
|
|
298
|
+
var o = this.get(name, event_type);
|
|
299
|
+
if (o) {
|
|
300
|
+
o.load(o.filename);
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
return '没有找到模块';
|
|
304
|
+
}
|
|
305
|
+
|
|
249
306
|
/**
|
|
250
307
|
* @module 导出Event类
|
|
251
308
|
*/
|
|
@@ -274,4 +331,4 @@ $.event_admin = function(scope, title) {
|
|
|
274
331
|
obj = $.pool.event[scope];
|
|
275
332
|
}
|
|
276
333
|
return obj;
|
|
277
|
-
}
|
|
334
|
+
}
|
package/core/com/eventer/com.js
CHANGED
package/core/com/plugin/drive.js
CHANGED
|
@@ -260,10 +260,11 @@ Drive.prototype.main = function(param1, param2) {
|
|
|
260
260
|
* 执行程序
|
|
261
261
|
* @param {Object} param1 参数1
|
|
262
262
|
* @param {Object} param2 参数2
|
|
263
|
+
* @param {String} method 执行方法
|
|
263
264
|
* @return {Object} 返回执行结果
|
|
264
265
|
*/
|
|
265
|
-
Drive.prototype.run = function(param1, param2) {
|
|
266
|
-
return this
|
|
266
|
+
Drive.prototype.run = function(param1, param2, method = 'main') {
|
|
267
|
+
return this[method](param1, param2);
|
|
267
268
|
};
|
|
268
269
|
|
|
269
270
|
/**
|
package/core/com/plugin/index.js
CHANGED
package/core/com/sql/index.js
CHANGED
|
@@ -65,7 +65,11 @@ Sql.prototype.sort = function() {
|
|
|
65
65
|
Sql.prototype.run = async function(name, query, body, db) {
|
|
66
66
|
var obj = this.get(name);
|
|
67
67
|
if (obj) {
|
|
68
|
-
|
|
68
|
+
var ret = await obj.run(query, body, db);
|
|
69
|
+
if (this.mode) {
|
|
70
|
+
o.load(o.filename);
|
|
71
|
+
}
|
|
72
|
+
return ret;
|
|
69
73
|
}
|
|
70
74
|
return null;
|
|
71
75
|
};
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_os",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.9",
|
|
4
4
|
"description": "这是超级美眉服务端框架,用于快速构建应用程序。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"mm_html": "^1.1.1",
|
|
41
41
|
"mm_koa_proxy": "^1.0.0",
|
|
42
42
|
"mm_logs": "^1.1.0",
|
|
43
|
-
"mm_machine": "^1.
|
|
43
|
+
"mm_machine": "^1.6.0",
|
|
44
44
|
"mm_mongodb": "^1.3.9",
|
|
45
45
|
"mm_mqtt": "^1.0.5",
|
|
46
46
|
"mm_mysql": "^1.7.1",
|