mm_os 4.1.4 → 4.1.5

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 (2) hide show
  1. package/com/db/drive.js +46 -43
  2. package/package.json +1 -1
package/com/db/drive.js CHANGED
@@ -18,20 +18,20 @@ var keyword_default_tip = '昵称、手机号、钱包地址';
18
18
  class Drive extends Item {
19
19
  static config = {
20
20
  // 库表名称(唯一标识)
21
- 'name': 'db',
21
+ name: '',
22
22
  // 标题(中文名)
23
- 'title': '',
23
+ title: '',
24
24
  // 表名
25
- 'table': '',
25
+ table: '',
26
26
  // 主键,用于实体模型
27
- 'key': '',
27
+ key: '',
28
28
  // 字段
29
- 'fields': [
29
+ fields: [
30
30
  /* */
31
31
  ],
32
- 'index': [],
32
+ index: [],
33
33
  // 主程序文件 - 默认为空
34
- 'main': ''
34
+ main: ''
35
35
  };
36
36
 
37
37
  /**
@@ -48,7 +48,7 @@ class Drive extends Item {
48
48
  /**
49
49
  * 重置配置参数
50
50
  */
51
- Drive.prototype._reset = function () {
51
+ Drive.prototype._preset = function () {
52
52
  this.query_string = ['name', 'title', 'keywords', 'tag', 'description', 'content'];
53
53
 
54
54
  // 是否设置数值类型为可查询
@@ -315,10 +315,10 @@ Drive.prototype.model = function (fields) {
315
315
  */
316
316
  Drive.prototype.newIndexModel = function (o) {
317
317
  return {
318
- 'name': o.Key_name,
319
- 'type': o.Non_unique ? 'unique' : 'index',
320
- 'fields': o.Column_name.replace(/`/g, '').split(','),
321
- 'comment': o.Manager_comment
318
+ name: o.Key_name,
319
+ type: o.Non_unique ? 'unique' : 'index',
320
+ fields: o.Column_name.replace(/`/g, '').split(','),
321
+ comment: o.Manager_comment
322
322
  };
323
323
  };
324
324
 
@@ -385,7 +385,7 @@ Drive.prototype.updateFile = async function (db, cover) {
385
385
  list.push(field);
386
386
  }
387
387
  cg.fields = list;
388
- cg.index = await this._updateFile(db);
388
+ cg.index = await this._updateFile(db);
389
389
  if (!cg.name) {
390
390
  cg.name = cg.table;
391
391
  }
@@ -792,7 +792,7 @@ Drive.prototype._handleConfigFile = function (f, cover) {
792
792
  delete o.description;
793
793
  }
794
794
  $.push(jobj, o, true);
795
- f.saveText(JSON.stringify(jobj, null, 2));
795
+ f.saveJson(jobj);
796
796
  }
797
797
  };
798
798
 
@@ -816,7 +816,11 @@ Drive.prototype.updateApp = async function (cover) {
816
816
  f = dirs.config_file;
817
817
  dir_api = dirs.dir_api;
818
818
  } else {
819
- f = this.config_file + '.db.json';
819
+ if (this.config_file.endsWith('.db.json')) {
820
+ f = this.config_file;
821
+ } else {
822
+ f = this.config_file + '.db.json';
823
+ }
820
824
  }
821
825
 
822
826
  if (f) {
@@ -824,7 +828,9 @@ Drive.prototype.updateApp = async function (cover) {
824
828
  if (!dir_api) {
825
829
  dir_api = f.dirname().dirname();
826
830
  }
831
+ // 处理db配置文件,生成xxx.db.json文件
827
832
  this._handleConfigFile(f, cover);
833
+ // 更新API及相关配置文件
828
834
  this.updateApi(dir_api, cover);
829
835
  }
830
836
  };
@@ -886,7 +892,7 @@ Drive.prototype.updateApi = async function (dir, cover) {
886
892
  var client = this._getApiDir(dir, app, 'client', name);
887
893
  var manage = this._getApiDir(dir, app, 'manage', name);
888
894
 
889
- this.newSql(client, manage, cover);
895
+ await this.newSql(client, manage, cover);
890
896
  await this.newParam(client, manage, cover);
891
897
  this.newApi(client, manage, cover);
892
898
  };
@@ -1048,7 +1054,6 @@ Drive.prototype._procFieldSel = function (field_name, field_type) {
1048
1054
  if (this.isCan(field_name, this.get_obj_not)) {
1049
1055
  res.field_obj += ',`' + field_name + '`';
1050
1056
  }
1051
-
1052
1057
  return res;
1053
1058
  };
1054
1059
 
@@ -1159,7 +1164,7 @@ Drive.prototype._procFieldType = function (
1159
1164
 
1160
1165
  /**
1161
1166
  * 处理单个字段
1162
- * @param {object} field 字段对象
1167
+ * @param {object} o 字段对象
1163
1168
  * @param {object} query 查询对象
1164
1169
  * @param {object} update_obj 更新对象
1165
1170
  * @param {string} uid 用户ID
@@ -1170,14 +1175,12 @@ Drive.prototype._procFieldType = function (
1170
1175
  * @private
1171
1176
  */
1172
1177
  Drive.prototype._procSingleField = async function (
1173
- field, query, update_obj, uid, query_default_user, orderby, keyword
1178
+ o, query, update_obj, uid, query_default_user, orderby, keyword
1174
1179
  ) {
1175
- var o = field;
1176
- var p = o.type;
1177
- var n = o.name;
1180
+ var { type, name } = o;
1178
1181
  var result = {
1179
- field: '',
1180
- field_obj: '',
1182
+ field: '*',
1183
+ field_obj: '*',
1181
1184
  keyword: keyword,
1182
1185
  orderby: orderby,
1183
1186
  update_obj: update_obj,
@@ -1185,12 +1188,12 @@ Drive.prototype._procSingleField = async function (
1185
1188
  format: []
1186
1189
  };
1187
1190
 
1188
- var field_sel = this._procFieldSel(n, p);
1191
+ var field_sel = this._procFieldSel(name, type);
1189
1192
  result.field = field_sel.field;
1190
1193
  result.field_obj = field_sel.field_obj;
1191
1194
 
1192
1195
  var type_info = this._procFieldType(
1193
- p, n, query, update_obj, uid, query_default_user, orderby, keyword
1196
+ type, name, query, update_obj, uid, query_default_user, orderby, keyword
1194
1197
  );
1195
1198
  result.keyword = type_info.keyword;
1196
1199
  result.orderby = type_info.orderby;
@@ -1249,8 +1252,8 @@ Drive.prototype._procFields = async function (fields, table) {
1249
1252
  return {
1250
1253
  query,
1251
1254
  update: update_obj,
1252
- field,
1253
- field_obj,
1255
+ field: field.replace(',', ''),
1256
+ field_obj: field_obj.replace(',', ''),
1254
1257
  query_default,
1255
1258
  format,
1256
1259
  orderby,
@@ -1287,7 +1290,7 @@ Drive.prototype._procKeyword = function (keyword, table) {
1287
1290
  * @returns {object} 基础模型
1288
1291
  * @private
1289
1292
  */
1290
- Drive.prototype._createBaseModel = function (cg, processed, keyword_query) {
1293
+ Drive.prototype._createSqlConfig = function (cg, processed, keyword_query) {
1291
1294
  return {
1292
1295
  name: cg.table,
1293
1296
  title: cg.title,
@@ -1314,7 +1317,7 @@ Drive.prototype._createBaseModel = function (cg, processed, keyword_query) {
1314
1317
  * @param {boolean} cover 是否覆盖文件
1315
1318
  * @private
1316
1319
  */
1317
- Drive.prototype._saveClientConfig = function (client, base_model, orderby, uid, table, cover) {
1320
+ Drive.prototype._saveClientConfig = function (client, base_model, cover, orderby, uid, table) {
1318
1321
  var oj = { ...base_model };
1319
1322
  if (orderby) {
1320
1323
  oj.orderby_default = orderby;
@@ -1364,10 +1367,10 @@ Drive.prototype.newSql = async function (client, manage, cover) {
1364
1367
 
1365
1368
  var processed = await this._procFields(cg.fields, cg.table);
1366
1369
  var keyword_query = this._procKeyword(processed.keyword, cg.table);
1367
- var base_model = this._createBaseModel(cg, processed, keyword_query);
1370
+ var base_model = this._createSqlConfig(cg, processed, keyword_query);
1368
1371
 
1369
1372
  if (client) {
1370
- this._saveClientConfig(client, base_model, processed.orderby, uid, cg.table, cover);
1373
+ this._saveClientConfig(client, base_model, cover, processed.orderby, uid, cg.table);
1371
1374
  }
1372
1375
 
1373
1376
  if (manage) {
@@ -1413,7 +1416,7 @@ Drive.prototype.newParam = async function (client, manage, cover) {
1413
1416
  var o = lt[i];
1414
1417
  var p = o.type;
1415
1418
  var n = o.name;
1416
- var m = this._createBaseModel(o, p, n);
1419
+ var m = this._createParamModel(o, p, n);
1417
1420
 
1418
1421
  if (this._isStringType(p)) {
1419
1422
  keyword = this._processStringField(cm, m, o, n, keyword);
@@ -1465,14 +1468,14 @@ Drive.prototype._initParamConfig = function (cg) {
1465
1468
  };
1466
1469
 
1467
1470
  /**
1468
- * 创建基础模型
1471
+ * 创建参数模型
1469
1472
  * @param {object} field 字段对象
1470
1473
  * @param {string} type 字段类型
1471
1474
  * @param {string} name 字段名
1472
- * @returns {object} 基础模型对象
1475
+ * @returns {object} 参数模型对象
1473
1476
  * @private
1474
1477
  */
1475
- Drive.prototype._createBaseModel = function (field, type, name) {
1478
+ Drive.prototype._createParamModel = function (field, type, name) {
1476
1479
  return {
1477
1480
  name: name,
1478
1481
  title: field.title,
@@ -1846,16 +1849,16 @@ Drive.prototype.isCan = function (name, arr, type) {
1846
1849
  return false;
1847
1850
  }
1848
1851
  if (!arr) {
1849
- return false;
1852
+ return true;
1850
1853
  }
1851
- var bl = false;
1854
+ var bl = true;
1852
1855
  for (var i = 0; i < arr.length; i++) {
1853
1856
  if (name.indexOf(arr[i]) !== -1) {
1854
- bl = true;
1857
+ bl = false;
1855
1858
  break;
1856
1859
  }
1857
1860
  }
1858
- return !bl;
1861
+ return bl;
1859
1862
  };
1860
1863
 
1861
1864
 
@@ -1880,10 +1883,10 @@ Drive.prototype._deteApiPath = function (cg) {
1880
1883
  * 创建基础API配置
1881
1884
  * @param {object} cg 配置对象
1882
1885
  * @param {string} path API路径
1883
- * @returns {object} 基础API配置
1886
+ * @returns {object} API配置
1884
1887
  * @private
1885
1888
  */
1886
- Drive.prototype._createBaseApiConfig = function (cg, path) {
1889
+ Drive.prototype._createApiConfig = function (cg, path) {
1887
1890
  return {
1888
1891
  'name': cg.table,
1889
1892
  'title': cg.title,
@@ -1968,7 +1971,7 @@ Drive.prototype._saveManageApiConfig = function (manage, base_config, cover) {
1968
1971
  Drive.prototype.newApi = async function (client, manage, cover) {
1969
1972
  var cg = this.config;
1970
1973
  var path = this._deteApiPath(cg);
1971
- var base_config = this._createBaseApiConfig(cg, path);
1974
+ var base_config = this._createApiConfig(cg, path);
1972
1975
 
1973
1976
  if (client) {
1974
1977
  this._saveClientApiConfig(client, base_config, cg, cover);
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.4",
4
+ "version": "4.1.5",
5
5
  "main": "index.js",
6
6
  "keywords": [
7
7
  "AI",