mm_dao 1.9.0 → 1.9.2
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/README.md +11 -2
- package/index.js +3 -13
- package/lib/admin.js +24 -0
- package/lib/dao.js +38 -1219
- package/lib/dao_crud.js +379 -0
- package/lib/dao_fields.js +145 -0
- package/lib/dao_query.js +238 -0
- package/lib/dao_scope.js +203 -0
- package/lib/dao_stats.js +129 -0
- package/lib/dao_transfer.js +358 -0
- package/lib/manager.js +40 -18
- package/lib/script.tpl.js +4 -4
- package/package.json +70 -63
- package/tool/dao/index.js +176 -0
- package/tool/dao/tool.json +121 -0
- package/tool/dao_admin/index.js +36 -0
- package/tool/dao_admin/tool.json +11 -0
- package/db/mm/user_account/_meta.json +0 -54
- package/db/mm.db +0 -0
- package/eslint.config.js +0 -235
- package/example/index.js +0 -78
- package/test_db/dao_test_1785991977965/account/1.json +0 -6
- package/test_db/dao_test_1785991977965/account/2.json +0 -6
- package/test_db/dao_test_1785991977965/account/_meta.json +0 -18
- package/test_db/dao_test_1785991977965/role/1.json +0 -7
- package/test_db/dao_test_1785991977965/role/2.json +0 -7
- package/test_db/dao_test_1785991977965/role/3.json +0 -7
- package/test_db/dao_test_1785991977965/role/_meta.json +0 -18
- package/test_db/dao_test_1785991977965/tool/_meta.json +0 -18
- package/test_db/dao_test_1785991977965/tool/bow_001.json +0 -8
- package/test_db/dao_test_1785991977965/tool/robe_001.json +0 -8
- package/test_db/dao_test_1785991977965/tool/shield_001.json +0 -8
- package/test_db/dao_test_1785991977965/tool/staff_001.json +0 -8
- package/test_db/dao_test_1785991977965/tool/sword_001.json +0 -8
- package/test_db/dao_test_1785993793800/account/1.json +0 -58
- package/test_db/dao_test_1785993793800/account/2.json +0 -25
- package/test_db/dao_test_1785993793800/account/_meta.json +0 -18
- package/test_db/dao_test_1785993793800/role/1.json +0 -7
- package/test_db/dao_test_1785993793800/role/2.json +0 -7
- package/test_db/dao_test_1785993793800/role/3.json +0 -7
- package/test_db/dao_test_1785993793800/role/_meta.json +0 -18
- package/test_db/dao_test_1785993793800/tool/_meta.json +0 -18
- package/test_db/dao_test_1785993793800/tool/bow_001.json +0 -8
- package/test_db/dao_test_1785993793800/tool/robe_001.json +0 -8
- package/test_db/dao_test_1785993793800/tool/shield_001.json +0 -8
- package/test_db/dao_test_1785993793800/tool/staff_001.json +0 -8
- package/test_db/dao_test_1785993793800/tool/sword_001.json +0 -8
- package/test_db/dao_test_1785993841615/account/1.json +0 -58
- package/test_db/dao_test_1785993841615/account/2.json +0 -25
- package/test_db/dao_test_1785993841615/account/_meta.json +0 -18
- package/test_db/dao_test_1785993841615/role/1.json +0 -7
- package/test_db/dao_test_1785993841615/role/2.json +0 -7
- package/test_db/dao_test_1785993841615/role/3.json +0 -7
- package/test_db/dao_test_1785993841615/role/_meta.json +0 -18
- package/test_db/dao_test_1785993841615/tool/_meta.json +0 -18
- package/test_db/dao_test_1785993841615/tool/bow_001.json +0 -8
- package/test_db/dao_test_1785993841615/tool/robe_001.json +0 -8
- package/test_db/dao_test_1785993841615/tool/shield_001.json +0 -8
- package/test_db/dao_test_1785993841615/tool/staff_001.json +0 -8
- package/test_db/dao_test_1785993841615/tool/sword_001.json +0 -8
- package/test_db/dao_test_1785998204124/account/1.json +0 -58
- package/test_db/dao_test_1785998204124/account/2.json +0 -25
- package/test_db/dao_test_1785998204124/account/_meta.json +0 -18
- package/test_db/dao_test_1785998204124/role/1.json +0 -7
- package/test_db/dao_test_1785998204124/role/2.json +0 -7
- package/test_db/dao_test_1785998204124/role/3.json +0 -7
- package/test_db/dao_test_1785998204124/role/_meta.json +0 -18
- package/test_db/dao_test_1785998204124/tool/_meta.json +0 -18
- package/test_db/dao_test_1785998204124/tool/bow_001.json +0 -8
- package/test_db/dao_test_1785998204124/tool/robe_001.json +0 -8
- package/test_db/dao_test_1785998204124/tool/shield_001.json +0 -8
- package/test_db/dao_test_1785998204124/tool/staff_001.json +0 -8
- package/test_db/dao_test_1785998204124/tool/sword_001.json +0 -8
- package/test_db/dao_test_1785998207460/account/1.json +0 -58
- package/test_db/dao_test_1785998207460/account/2.json +0 -25
- package/test_db/dao_test_1785998207460/account/_meta.json +0 -18
- package/test_db/dao_test_1785998207460/role/1.json +0 -7
- package/test_db/dao_test_1785998207460/role/2.json +0 -7
- package/test_db/dao_test_1785998207460/role/3.json +0 -7
- package/test_db/dao_test_1785998207460/role/_meta.json +0 -18
- package/test_db/dao_test_1785998207460/tool/_meta.json +0 -18
- package/test_db/dao_test_1785998207460/tool/bow_001.json +0 -8
- package/test_db/dao_test_1785998207460/tool/robe_001.json +0 -8
- package/test_db/dao_test_1785998207460/tool/shield_001.json +0 -8
- package/test_db/dao_test_1785998207460/tool/staff_001.json +0 -8
- package/test_db/dao_test_1785998207460/tool/sword_001.json +0 -8
- package/test_db/dao_test_1785998210638/account/1.json +0 -58
- package/test_db/dao_test_1785998210638/account/2.json +0 -25
- package/test_db/dao_test_1785998210638/account/_meta.json +0 -18
- package/test_db/dao_test_1785998210638/role/1.json +0 -7
- package/test_db/dao_test_1785998210638/role/2.json +0 -7
- package/test_db/dao_test_1785998210638/role/3.json +0 -7
- package/test_db/dao_test_1785998210638/role/_meta.json +0 -18
- package/test_db/dao_test_1785998210638/tool/_meta.json +0 -18
- package/test_db/dao_test_1785998210638/tool/bow_001.json +0 -8
- package/test_db/dao_test_1785998210638/tool/robe_001.json +0 -8
- package/test_db/dao_test_1785998210638/tool/shield_001.json +0 -8
- package/test_db/dao_test_1785998210638/tool/staff_001.json +0 -8
- package/test_db/dao_test_1785998210638/tool/sword_001.json +0 -8
- package/test_db/dao_test_1785998213852/account/1.json +0 -58
- package/test_db/dao_test_1785998213852/account/2.json +0 -25
- package/test_db/dao_test_1785998213852/account/_meta.json +0 -18
- package/test_db/dao_test_1785998213852/role/1.json +0 -7
- package/test_db/dao_test_1785998213852/role/2.json +0 -7
- package/test_db/dao_test_1785998213852/role/3.json +0 -7
- package/test_db/dao_test_1785998213852/role/_meta.json +0 -18
- package/test_db/dao_test_1785998213852/tool/_meta.json +0 -18
- package/test_db/dao_test_1785998213852/tool/bow_001.json +0 -8
- package/test_db/dao_test_1785998213852/tool/robe_001.json +0 -8
- package/test_db/dao_test_1785998213852/tool/shield_001.json +0 -8
- package/test_db/dao_test_1785998213852/tool/staff_001.json +0 -8
- package/test_db/dao_test_1785998213852/tool/sword_001.json +0 -8
- package/test_db/dao_test_1785998217094/account/1.json +0 -58
- package/test_db/dao_test_1785998217094/account/2.json +0 -25
- package/test_db/dao_test_1785998217094/account/_meta.json +0 -18
- package/test_db/dao_test_1785998217094/role/1.json +0 -7
- package/test_db/dao_test_1785998217094/role/2.json +0 -7
- package/test_db/dao_test_1785998217094/role/3.json +0 -7
- package/test_db/dao_test_1785998217094/role/_meta.json +0 -18
- package/test_db/dao_test_1785998217094/tool/_meta.json +0 -18
- package/test_db/dao_test_1785998217094/tool/bow_001.json +0 -8
- package/test_db/dao_test_1785998217094/tool/robe_001.json +0 -8
- package/test_db/dao_test_1785998217094/tool/shield_001.json +0 -8
- package/test_db/dao_test_1785998217094/tool/staff_001.json +0 -8
- package/test_db/dao_test_1785998217094/tool/sword_001.json +0 -8
- package/test_db/dao_test_1786000291805/account/1.json +0 -58
- package/test_db/dao_test_1786000291805/account/2.json +0 -25
- package/test_db/dao_test_1786000291805/account/_meta.json +0 -18
- package/test_db/dao_test_1786000291805/role/1.json +0 -7
- package/test_db/dao_test_1786000291805/role/2.json +0 -7
- package/test_db/dao_test_1786000291805/role/3.json +0 -7
- package/test_db/dao_test_1786000291805/role/_meta.json +0 -18
- package/test_db/dao_test_1786000291805/tool/_meta.json +0 -18
- package/test_db/dao_test_1786000291805/tool/bow_001.json +0 -8
- package/test_db/dao_test_1786000291805/tool/robe_001.json +0 -8
- package/test_db/dao_test_1786000291805/tool/shield_001.json +0 -8
- package/test_db/dao_test_1786000291805/tool/staff_001.json +0 -8
- package/test_db/dao_test_1786000291805/tool/sword_001.json +0 -8
- package/test_db/dao_test_1786001183999/account/1.json +0 -58
- package/test_db/dao_test_1786001183999/account/2.json +0 -25
- package/test_db/dao_test_1786001183999/account/_meta.json +0 -18
- package/test_db/dao_test_1786001183999/role/1.json +0 -7
- package/test_db/dao_test_1786001183999/role/2.json +0 -7
- package/test_db/dao_test_1786001183999/role/3.json +0 -7
- package/test_db/dao_test_1786001183999/role/_meta.json +0 -18
- package/test_db/dao_test_1786001183999/tool/_meta.json +0 -18
- package/test_db/dao_test_1786001183999/tool/bow_001.json +0 -8
- package/test_db/dao_test_1786001183999/tool/robe_001.json +0 -8
- package/test_db/dao_test_1786001183999/tool/shield_001.json +0 -8
- package/test_db/dao_test_1786001183999/tool/staff_001.json +0 -8
- package/test_db/dao_test_1786001183999/tool/sword_001.json +0 -8
- package/test_db/dao_test_1786001297521/account/1.json +0 -58
- package/test_db/dao_test_1786001297521/account/2.json +0 -25
- package/test_db/dao_test_1786001297521/account/_meta.json +0 -18
- package/test_db/dao_test_1786001297521/role/1.json +0 -7
- package/test_db/dao_test_1786001297521/role/2.json +0 -7
- package/test_db/dao_test_1786001297521/role/3.json +0 -7
- package/test_db/dao_test_1786001297521/role/_meta.json +0 -18
- package/test_db/dao_test_1786001297521/tool/_meta.json +0 -18
- package/test_db/dao_test_1786001297521/tool/bow_001.json +0 -8
- package/test_db/dao_test_1786001297521/tool/robe_001.json +0 -8
- package/test_db/dao_test_1786001297521/tool/shield_001.json +0 -8
- package/test_db/dao_test_1786001297521/tool/staff_001.json +0 -8
- package/test_db/dao_test_1786001297521/tool/sword_001.json +0 -8
- package/test_db/debug_dao_1785992422444/account/1.json +0 -24
- package/test_db/debug_dao_1785992422444/account/_meta.json +0 -18
- package/test_db/debug_dao_1785992422444/role/1.json +0 -7
- package/test_db/debug_dao_1785992422444/role/2.json +0 -7
- package/test_db/debug_dao_1785992422444/role/_meta.json +0 -18
- package/test_db/debug_dao_1785992422444/tool/_meta.json +0 -18
- package/test_db/debug_dao_1785992422444/tool/shield_001.json +0 -7
- package/test_db/debug_dao_1785992422444/tool/staff_001.json +0 -7
- package/test_db/debug_dao_1785992422444/tool/sword_001.json +0 -7
- package/test_db/debug_dao_1785993785567/account/1.json +0 -47
- package/test_db/debug_dao_1785993785567/account/_meta.json +0 -18
- package/test_db/debug_dao_1785993785567/role/1.json +0 -7
- package/test_db/debug_dao_1785993785567/role/2.json +0 -7
- package/test_db/debug_dao_1785993785567/role/_meta.json +0 -18
- package/test_db/debug_dao_1785993785567/tool/_meta.json +0 -18
- package/test_db/debug_dao_1785993785567/tool/shield_001.json +0 -7
- package/test_db/debug_dao_1785993785567/tool/staff_001.json +0 -7
- package/test_db/debug_dao_1785993785567/tool/sword_001.json +0 -7
- package/test_db/debug_dao_check/tool/_meta.json +0 -18
- package/test_db/debug_dao_check/tool/sword_001.json +0 -6
- package/test_db/test_1785973671479/users/1.json +0 -5
- package/test_db/test_1785973671479/users/_meta.json +0 -20
- package/tests/dao_test.js +0 -213
- package/tests/debug_error_test.js +0 -165
- package/tests/debug_test.js +0 -35
- package/tests/debug_test2.js +0 -45
- package/tests/debug_test3.js +0 -54
- package/tests/detailed_error_test.js +0 -171
- package/tests/main.test.js +0 -261
- package/tests/query.test.js +0 -142
- package/tests/scope.test.js +0 -72
- package/tests/test.js +0 -325
- package/tests/test2.js +0 -64
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* dao —— DAO 登记与表结构工具
|
|
4
|
+
* 清单来自管理器 getInfos,表结构来自模块 Dao 类的 getModel,能力层只做投影。
|
|
5
|
+
*/
|
|
6
|
+
const { constAdmin } = require('mm_consts');
|
|
7
|
+
const { daoAdmin, Dao } = require('../../index.js');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 初始化登记项投影字段常量
|
|
11
|
+
* @returns {void}
|
|
12
|
+
*/
|
|
13
|
+
function initDaoConsts() {
|
|
14
|
+
let consts = constAdmin('dao');
|
|
15
|
+
if (!consts.has('DAO_FIELDS')) {
|
|
16
|
+
consts.set('DAO_FIELDS', ['name', 'title', 'table', 'dir', 'desc']);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
initDaoConsts();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 投影登记项
|
|
24
|
+
* @param {object} cfg 登记配置
|
|
25
|
+
* @returns {object} 投影
|
|
26
|
+
*/
|
|
27
|
+
function project(cfg) {
|
|
28
|
+
let fields = constAdmin('dao').get('DAO_FIELDS');
|
|
29
|
+
let out = {};
|
|
30
|
+
for (let k of fields) out[k] = cfg[k] === undefined ? '' : cfg[k];
|
|
31
|
+
out.fields = Array.isArray(cfg.fields) ? cfg.fields.length : 0;
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 取实例配置:优先显式 config,其次按 name 取登记项
|
|
37
|
+
* @param {object} mgr 管理器
|
|
38
|
+
* @param {object} p 参数
|
|
39
|
+
* @returns {object} 配置
|
|
40
|
+
*/
|
|
41
|
+
function resolveConfig(mgr, p) {
|
|
42
|
+
if (p.config && typeof p.config === 'object') return p.config;
|
|
43
|
+
if (p.name) {
|
|
44
|
+
let cfg = typeof mgr.getInfo === 'function' ? mgr.getInfo(p.name) : null;
|
|
45
|
+
if (cfg) return cfg;
|
|
46
|
+
}
|
|
47
|
+
throw new TypeError('schema 需要 config 或已登记的 name');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 取已登记的 DAO 驱动实例
|
|
52
|
+
* @param {object} mgr 管理器
|
|
53
|
+
* @param {object} p 参数
|
|
54
|
+
* @returns {object} 驱动实例
|
|
55
|
+
*/
|
|
56
|
+
function resolveDrive(mgr, p) {
|
|
57
|
+
if (!p.name) throw new TypeError('name 必须指定已登记的 DAO 名');
|
|
58
|
+
let drive = typeof mgr.getMod === 'function' ? mgr.getMod(p.name) : null;
|
|
59
|
+
if (!drive) throw new Error('DAO 不存在: ' + p.name);
|
|
60
|
+
return drive;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 组装查询参数:query 为主体,顶层分页/排序/字段/表名作为快捷方式覆盖
|
|
65
|
+
* @param {object} p 参数
|
|
66
|
+
* @returns {object} 查询参数
|
|
67
|
+
*/
|
|
68
|
+
function buildQuery(p) {
|
|
69
|
+
let query = p.query && typeof p.query === 'object' && !Array.isArray(p.query) ? { ...p.query } : {};
|
|
70
|
+
for (let key of ['page', 'size', 'orderby', 'field', 'table']) {
|
|
71
|
+
if (p[key] !== undefined && p[key] !== null) query[key] = p[key];
|
|
72
|
+
}
|
|
73
|
+
return query;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 取写入数据
|
|
78
|
+
* @param {object} p 参数
|
|
79
|
+
* @returns {object} 写入数据
|
|
80
|
+
*/
|
|
81
|
+
function buildBody(p) {
|
|
82
|
+
return p.body && typeof p.body === 'object' && !Array.isArray(p.body) ? { ...p.body } : {};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 将模块返回结果转换为工具输出
|
|
87
|
+
* @param {object} ctx 上下文对象
|
|
88
|
+
* @param {object} ret 模块执行结果
|
|
89
|
+
* @returns {object} 工具输出
|
|
90
|
+
*/
|
|
91
|
+
function done(ctx, ret) {
|
|
92
|
+
if (!ret) {
|
|
93
|
+
ctx.output = {
|
|
94
|
+
code: 10000,
|
|
95
|
+
msg: '执行失败:DAO 未返回结果',
|
|
96
|
+
error: { name: 'Error', message: 'DAO 未返回结果' }
|
|
97
|
+
};
|
|
98
|
+
return ctx.output;
|
|
99
|
+
}
|
|
100
|
+
if (ret.error) {
|
|
101
|
+
let message = ret.error.message || ret.error.msg || '执行失败';
|
|
102
|
+
ctx.output = {
|
|
103
|
+
code: 10000,
|
|
104
|
+
msg: message,
|
|
105
|
+
error: { name: 'DaoError', code: ret.error.code, message: message },
|
|
106
|
+
result: ret
|
|
107
|
+
};
|
|
108
|
+
return ctx.output;
|
|
109
|
+
}
|
|
110
|
+
let data = ret.result || {};
|
|
111
|
+
ctx.output = {
|
|
112
|
+
code: 0,
|
|
113
|
+
msg: data.tip || data.msg || '成功',
|
|
114
|
+
result: data
|
|
115
|
+
};
|
|
116
|
+
if (Array.isArray(data.list)) {
|
|
117
|
+
ctx.output.list = data.list;
|
|
118
|
+
ctx.output.count = typeof data.count === 'number' ? data.count : data.list.length;
|
|
119
|
+
} else if (typeof data.count === 'number') {
|
|
120
|
+
ctx.output.count = data.count;
|
|
121
|
+
}
|
|
122
|
+
return ctx.output;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function main(params, ctx, options) {
|
|
126
|
+
void options;
|
|
127
|
+
let p = params || {};
|
|
128
|
+
let action = p.action || 'list';
|
|
129
|
+
const write = (data) => { ctx.output = data; return data; };
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
let mgr = daoAdmin(p.scope || 'os');
|
|
133
|
+
|
|
134
|
+
if (action === 'list') {
|
|
135
|
+
let rows = typeof mgr.getInfos === 'function' ? mgr.getInfos() : [];
|
|
136
|
+
let list = rows.map(project);
|
|
137
|
+
return write({ code: 0, msg: list.length ? '成功' : '当前作用域没有已登记的 DAO', count: list.length, list });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (action === 'schema') {
|
|
141
|
+
let cfg = resolveConfig(mgr, p);
|
|
142
|
+
let inst = new Dao(cfg);
|
|
143
|
+
let model = typeof inst.getModel === 'function' ? inst.getModel() : null;
|
|
144
|
+
if (!model) return write({ code: 10002, msg: '该 DAO 配置无法生成模型', name: cfg.name || '' });
|
|
145
|
+
return write({ code: 0, msg: '成功', name: cfg.name || '', table: model.table || '', schema: model });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (action === 'mods') {
|
|
149
|
+
let mods = typeof mgr.getMods === 'function' ? mgr.getMods() : {};
|
|
150
|
+
let keys = Array.isArray(mods) ? mods.map((o) => (o && (o.name || o.config && o.config.name)) || '') : Object.keys(mods || {});
|
|
151
|
+
return write({ code: 0, msg: '成功', count: keys.length, mods: keys.filter(Boolean) });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (action === 'get' || action === 'get_obj' || action === 'add' || action === 'set' || action === 'del' || action === 'count') {
|
|
155
|
+
let drive = resolveDrive(mgr, p);
|
|
156
|
+
let query = { ...buildQuery(p), method: action };
|
|
157
|
+
let body = buildBody(p);
|
|
158
|
+
let ret = await drive.run(query, body);
|
|
159
|
+
return done(ctx, ret);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (action === 'add_list') {
|
|
163
|
+
let drive = resolveDrive(mgr, p);
|
|
164
|
+
let list = Array.isArray(p.list) ? p.list : (Array.isArray(p.body) ? p.body : null);
|
|
165
|
+
if (!list) throw new TypeError('add_list 需要 list 数组');
|
|
166
|
+
let ret = await drive.addList(drive.db(), list);
|
|
167
|
+
return done(ctx, ret);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return write({ code: 10001, msg: '不支持的操作: ' + action });
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return write({ code: 10000, msg: '执行失败:' + error.message, error: { name: error.name, message: error.message } });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
module.exports = { main };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dao",
|
|
3
|
+
"title": "DAO 登记与表结构",
|
|
4
|
+
"description": "基于 mm_dao 的数据访问对象能力:列出已登记 DAO、取表与字段模型、查看已装载驱动,并执行核心增删改查。适用场景:确认某张表由哪个 DAO 负责、按条件分页查询、新增/修改/删除记录、批量新增、分组计数。工作流提示:先 list 确认 name,再按 action 传 name 与 query/body;查询结果在 list 与 count,写操作结果在 result。",
|
|
5
|
+
"category": "数据访问",
|
|
6
|
+
"group": "store",
|
|
7
|
+
"type": "function",
|
|
8
|
+
"main": "./index.js",
|
|
9
|
+
"params": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"action": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "操作类型: list(登记清单)/schema(表与字段模型)/mods(已装载驱动)/get(条件查询)/get_obj(查询单条)/add(新增)/set(修改)/del(删除)/count(分组计数)/add_list(批量新增)",
|
|
15
|
+
"enum": [
|
|
16
|
+
"list",
|
|
17
|
+
"schema",
|
|
18
|
+
"mods",
|
|
19
|
+
"get",
|
|
20
|
+
"get_obj",
|
|
21
|
+
"add",
|
|
22
|
+
"set",
|
|
23
|
+
"del",
|
|
24
|
+
"count",
|
|
25
|
+
"add_list"
|
|
26
|
+
],
|
|
27
|
+
"default": "list"
|
|
28
|
+
},
|
|
29
|
+
"scope": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "作用域,缺省 os",
|
|
32
|
+
"default": "os"
|
|
33
|
+
},
|
|
34
|
+
"name": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"description": "已登记的 DAO 名(schema/get/get_obj/add/set/del/count/add_list 使用)"
|
|
37
|
+
},
|
|
38
|
+
"config": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"description": "DAO 配置(schema 可选,与 name 二选一)"
|
|
41
|
+
},
|
|
42
|
+
"query": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"description": "查询条件对象(get/get_obj/set/del/count 使用,键为字段名)"
|
|
45
|
+
},
|
|
46
|
+
"body": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"description": "写入数据对象(add/set/del 使用)"
|
|
49
|
+
},
|
|
50
|
+
"page": {
|
|
51
|
+
"type": "number",
|
|
52
|
+
"description": "页码(get 可选,0 表示不分页)"
|
|
53
|
+
},
|
|
54
|
+
"size": {
|
|
55
|
+
"type": "number",
|
|
56
|
+
"description": "每页条数(get 可选,0 表示不分页)"
|
|
57
|
+
},
|
|
58
|
+
"orderby": {
|
|
59
|
+
"type": "string",
|
|
60
|
+
"description": "排序规则(get 可选,如 `id` desc)"
|
|
61
|
+
},
|
|
62
|
+
"field": {
|
|
63
|
+
"type": "string",
|
|
64
|
+
"description": "查询或统计字段(get/count 可选)"
|
|
65
|
+
},
|
|
66
|
+
"table": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"description": "自定义表名(表名配置为 {0} 的 DAO 使用)"
|
|
69
|
+
},
|
|
70
|
+
"list": {
|
|
71
|
+
"type": "array",
|
|
72
|
+
"description": "批量新增数据数组(add_list 必填)"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"required": [
|
|
76
|
+
"action"
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"returns": {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"properties": {
|
|
82
|
+
"code": {
|
|
83
|
+
"type": "number",
|
|
84
|
+
"description": "0 表示成功,1xxxx 表示业务/执行异常"
|
|
85
|
+
},
|
|
86
|
+
"msg": {
|
|
87
|
+
"type": "string",
|
|
88
|
+
"description": "结果描述"
|
|
89
|
+
},
|
|
90
|
+
"list": {
|
|
91
|
+
"type": "array",
|
|
92
|
+
"description": "登记清单(list)"
|
|
93
|
+
},
|
|
94
|
+
"schema": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"description": "表/字段模型(schema)"
|
|
97
|
+
},
|
|
98
|
+
"mods": {
|
|
99
|
+
"type": "array",
|
|
100
|
+
"description": "已装载驱动键(mods)"
|
|
101
|
+
},
|
|
102
|
+
"result": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"description": "模块原始执行结果(get/get_obj/add/set/del/count/add_list)"
|
|
105
|
+
},
|
|
106
|
+
"list": {
|
|
107
|
+
"type": "array",
|
|
108
|
+
"description": "查询结果列表(get/get_obj)"
|
|
109
|
+
},
|
|
110
|
+
"count": {
|
|
111
|
+
"type": "number",
|
|
112
|
+
"description": "结果条数或统计数据(get/count)"
|
|
113
|
+
},
|
|
114
|
+
"error": {
|
|
115
|
+
"type": "object",
|
|
116
|
+
"description": "异常对象 { name, message }"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"handler": "manager"
|
|
121
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { admin } = require('../../index.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 管理数据访问实例池
|
|
6
|
+
* @param {object} params 参数:action/scope
|
|
7
|
+
* @param {object} ctx 执行上下文
|
|
8
|
+
* @returns {Promise<object>} 执行结果
|
|
9
|
+
*/
|
|
10
|
+
async function main(params, ctx) {
|
|
11
|
+
let p = params || {};
|
|
12
|
+
let action = p.action || 'list';
|
|
13
|
+
let scope = p.scope || 'os';
|
|
14
|
+
const done = (data) => {
|
|
15
|
+
if (ctx) ctx.output = data;
|
|
16
|
+
return data;
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
if (action === 'list') {
|
|
20
|
+
let scopes = [...admin.keys()];
|
|
21
|
+
return done({ code: 0, msg: '获取成功', action, count: scopes.length, scopes });
|
|
22
|
+
}
|
|
23
|
+
if (action === 'inspect') {
|
|
24
|
+
let exists = admin.has(scope);
|
|
25
|
+
let instance = exists ? admin.get(scope) : null;
|
|
26
|
+
return done({ code: 0, msg: exists ? '获取成功' : '实例不存在', action, scope, exists, config: instance && instance.config ? instance.config : null });
|
|
27
|
+
}
|
|
28
|
+
if (action === 'del') return done({ code: 0, msg: '删除成功', action, scope, ok: admin.del(scope) });
|
|
29
|
+
if (action === 'clear') { admin.clear(); return done({ code: 0, msg: '实例池已清空', action }); }
|
|
30
|
+
return done({ code: 10001, msg: '不支持的操作: ' + action });
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return done({ code: 10000, msg: '执行失败:' + error.message, error: { name: error.name, message: error.message } });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { main };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dao_admin",
|
|
3
|
+
"title": "数据访问实例管理",
|
|
4
|
+
"description": "管理 mm_dao 的实例池:list 列出实例、inspect 查看配置、del 删除实例、clear 清空实例池。",
|
|
5
|
+
"category": "数据访问",
|
|
6
|
+
"group": "store",
|
|
7
|
+
"type": "function",
|
|
8
|
+
"main": "./index.js",
|
|
9
|
+
"params": { "type": "object", "properties": { "action": { "type": "string", "description": "操作类型: list/inspect/del/clear", "default": "list" }, "scope": { "type": "string", "description": "实例作用域,缺省 os", "default": "os" } }, "required": ["action"] },
|
|
10
|
+
"handler": "manager"
|
|
11
|
+
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"table": "user_account",
|
|
3
|
-
"key": "user_id",
|
|
4
|
-
"auto_increment": 0,
|
|
5
|
-
"created_at": "2026-08-06T00:04:14.434Z",
|
|
6
|
-
"fields": [
|
|
7
|
-
{
|
|
8
|
-
"name": "user_id",
|
|
9
|
-
"type": "INTEGER",
|
|
10
|
-
"not_null": false,
|
|
11
|
-
"auto": true,
|
|
12
|
-
"pk": true,
|
|
13
|
-
"default_value": null,
|
|
14
|
-
"note": ""
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"name": "username",
|
|
18
|
-
"type": "VARCHAR(255)",
|
|
19
|
-
"not_null": false,
|
|
20
|
-
"auto": false,
|
|
21
|
-
"pk": false,
|
|
22
|
-
"default_value": "",
|
|
23
|
-
"note": ""
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"name": "password",
|
|
27
|
-
"type": "VARCHAR(255)",
|
|
28
|
-
"not_null": false,
|
|
29
|
-
"auto": false,
|
|
30
|
-
"pk": false,
|
|
31
|
-
"default_value": "",
|
|
32
|
-
"note": ""
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"name": "gm",
|
|
36
|
-
"type": "INTEGER",
|
|
37
|
-
"not_null": false,
|
|
38
|
-
"auto": false,
|
|
39
|
-
"pk": false,
|
|
40
|
-
"default_value": 1,
|
|
41
|
-
"note": ""
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"name": "vip",
|
|
45
|
-
"type": "INTEGER",
|
|
46
|
-
"not_null": false,
|
|
47
|
-
"auto": false,
|
|
48
|
-
"pk": false,
|
|
49
|
-
"default_value": 0,
|
|
50
|
-
"note": ""
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
"indexes": []
|
|
54
|
-
}
|
package/db/mm.db
DELETED
|
Binary file
|
package/eslint.config.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const namingConventionPlugin = require('mm_eslint');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 基于个人规则的ESLint配置
|
|
7
|
-
* 符合最新ESLint Flat Config格式
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
module.exports = [
|
|
11
|
-
{
|
|
12
|
-
files: ['**/*.js'],
|
|
13
|
-
plugins: {
|
|
14
|
-
'naming-convention': namingConventionPlugin,
|
|
15
|
-
jsdoc: require('eslint-plugin-jsdoc'),
|
|
16
|
-
},
|
|
17
|
-
languageOptions: {
|
|
18
|
-
ecmaVersion: 'latest',
|
|
19
|
-
sourceType: 'module',
|
|
20
|
-
parserOptions: {
|
|
21
|
-
ecmaVersion: 'latest',
|
|
22
|
-
sourceType: 'module',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
// 命名规范规则 - 由自定义插件处理
|
|
27
|
-
rules: {
|
|
28
|
-
// 自定义命名规范插件规则(优先使用)
|
|
29
|
-
'naming-convention/class-name': 'error',
|
|
30
|
-
'naming-convention/function-name': 'error',
|
|
31
|
-
'naming-convention/method-name': 'error',
|
|
32
|
-
'naming-convention/variable-name': 'warn',
|
|
33
|
-
'naming-convention/constant-name': 'error',
|
|
34
|
-
'naming-convention/private-method-naming': 'warn',
|
|
35
|
-
'naming-convention/private-variable-naming': 'warn',
|
|
36
|
-
'naming-convention/param-name': 'warn',
|
|
37
|
-
'naming-convention/property-name': 'warn',
|
|
38
|
-
'naming-convention/instance-property': 'warn',
|
|
39
|
-
'naming-convention/prototype-method': 'error',
|
|
40
|
-
|
|
41
|
-
// 禁用与命名规范插件冲突的默认规则
|
|
42
|
-
camelcase: 'off',
|
|
43
|
-
'id-match': 'off',
|
|
44
|
-
'new-cap': 'off',
|
|
45
|
-
'id-length': 'off',
|
|
46
|
-
'id-denylist': 'off',
|
|
47
|
-
'id-blacklist': 'off',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
{
|
|
52
|
-
// 代码风格规则
|
|
53
|
-
rules: {
|
|
54
|
-
// 最大行长度100字符
|
|
55
|
-
'max-len': [
|
|
56
|
-
'error',
|
|
57
|
-
{
|
|
58
|
-
code: 100,
|
|
59
|
-
ignoreComments: true,
|
|
60
|
-
ignoreUrls: true,
|
|
61
|
-
ignoreStrings: true,
|
|
62
|
-
ignoreTemplateLiterals: true,
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
|
|
66
|
-
// 缩进2空格
|
|
67
|
-
indent: [
|
|
68
|
-
'error',
|
|
69
|
-
2,
|
|
70
|
-
{
|
|
71
|
-
SwitchCase: 1,
|
|
72
|
-
VariableDeclarator: 1,
|
|
73
|
-
outerIIFEBody: 1,
|
|
74
|
-
MemberExpression: 1,
|
|
75
|
-
FunctionDeclaration: { parameters: 1, body: 1 },
|
|
76
|
-
FunctionExpression: { parameters: 1, body: 1 },
|
|
77
|
-
CallExpression: { arguments: 1 },
|
|
78
|
-
ArrayExpression: 1,
|
|
79
|
-
ObjectExpression: 1,
|
|
80
|
-
ImportDeclaration: 1,
|
|
81
|
-
flatTernaryExpressions: false,
|
|
82
|
-
ignoreComments: false,
|
|
83
|
-
},
|
|
84
|
-
],
|
|
85
|
-
|
|
86
|
-
// 单引号
|
|
87
|
-
quotes: [
|
|
88
|
-
'error',
|
|
89
|
-
'single',
|
|
90
|
-
{
|
|
91
|
-
avoidEscape: true,
|
|
92
|
-
allowTemplateLiterals: true,
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
|
|
96
|
-
// 禁止制表符
|
|
97
|
-
'no-tabs': 'error',
|
|
98
|
-
|
|
99
|
-
// 行尾分号
|
|
100
|
-
semi: ['error', 'always'],
|
|
101
|
-
|
|
102
|
-
// 逗号风格
|
|
103
|
-
'comma-style': ['error', 'last'],
|
|
104
|
-
|
|
105
|
-
// 逗号间距
|
|
106
|
-
'comma-spacing': [
|
|
107
|
-
'error',
|
|
108
|
-
{
|
|
109
|
-
before: false,
|
|
110
|
-
after: true,
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
{
|
|
117
|
-
// 错误处理规则
|
|
118
|
-
rules: {
|
|
119
|
-
// 必须进行参数校验
|
|
120
|
-
'no-unused-vars': [
|
|
121
|
-
'error',
|
|
122
|
-
{
|
|
123
|
-
args: 'all',
|
|
124
|
-
caughtErrors: 'all',
|
|
125
|
-
ignoreRestSiblings: true,
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
|
|
129
|
-
// 建议使用try-catch
|
|
130
|
-
'no-unsafe-finally': 'warn',
|
|
131
|
-
|
|
132
|
-
// 禁止直接抛出字符串
|
|
133
|
-
'no-throw-literal': 'error',
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
|
|
137
|
-
{
|
|
138
|
-
// 最佳实践规则
|
|
139
|
-
rules: {
|
|
140
|
-
// 优先使用async/await
|
|
141
|
-
'prefer-promise-reject-errors': 'error',
|
|
142
|
-
|
|
143
|
-
// 避免副作用
|
|
144
|
-
'no-param-reassign': [
|
|
145
|
-
'error',
|
|
146
|
-
{
|
|
147
|
-
props: true,
|
|
148
|
-
ignorePropertyModificationsFor: [
|
|
149
|
-
'acc', // for reduce accumulators
|
|
150
|
-
'accumulator', // for reduce accumulators
|
|
151
|
-
'e', // for e.returnvalue
|
|
152
|
-
'ctx', // for Koa routing
|
|
153
|
-
'context', // for Koa routing
|
|
154
|
-
'req', // for Express requests
|
|
155
|
-
'request', // for Express requests
|
|
156
|
-
'res', // for Express responses
|
|
157
|
-
'response', // for Express responses
|
|
158
|
-
'$scope', // for Angular 1 scopes
|
|
159
|
-
'staticContext', // for ReactRouter context
|
|
160
|
-
],
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
|
|
164
|
-
// 优先链式编程
|
|
165
|
-
'prefer-object-spread': 'error',
|
|
166
|
-
|
|
167
|
-
// 优先函数式编程
|
|
168
|
-
'prefer-arrow-callback': 'error',
|
|
169
|
-
|
|
170
|
-
// 方法长度限制
|
|
171
|
-
'max-lines-per-function': [
|
|
172
|
-
'warn',
|
|
173
|
-
{
|
|
174
|
-
max: 40,
|
|
175
|
-
skipBlankLines: true,
|
|
176
|
-
skipComments: true,
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
|
|
180
|
-
// 复杂度限制
|
|
181
|
-
complexity: ['warn', 10],
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
{
|
|
186
|
-
// JSDoc规则
|
|
187
|
-
rules: {
|
|
188
|
-
// 要求公开方法有JSDoc注释
|
|
189
|
-
'jsdoc/require-jsdoc': [
|
|
190
|
-
'warn',
|
|
191
|
-
{
|
|
192
|
-
publicOnly: true,
|
|
193
|
-
require: {
|
|
194
|
-
FunctionDeclaration: true,
|
|
195
|
-
MethodDefinition: true,
|
|
196
|
-
ClassDeclaration: true,
|
|
197
|
-
ArrowFunctionExpression: false,
|
|
198
|
-
FunctionExpression: false,
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
|
|
203
|
-
// 检查JSDoc语法
|
|
204
|
-
'jsdoc/check-alignment': 'warn',
|
|
205
|
-
'jsdoc/check-indentation': 'warn',
|
|
206
|
-
'jsdoc/check-param-names': 'warn',
|
|
207
|
-
'jsdoc/check-syntax': 'warn',
|
|
208
|
-
'jsdoc/check-tag-names': 'warn',
|
|
209
|
-
'jsdoc/check-types': 'warn',
|
|
210
|
-
'jsdoc/no-undefined-types': 'warn',
|
|
211
|
-
'jsdoc/require-description': 'warn',
|
|
212
|
-
'jsdoc/require-param': 'warn',
|
|
213
|
-
'jsdoc/require-param-description': 'warn',
|
|
214
|
-
'jsdoc/require-param-name': 'warn',
|
|
215
|
-
'jsdoc/require-param-type': 'warn',
|
|
216
|
-
'jsdoc/require-returns': 'warn',
|
|
217
|
-
'jsdoc/require-returns-check': 'warn',
|
|
218
|
-
'jsdoc/require-returns-description': 'warn',
|
|
219
|
-
'jsdoc/require-returns-type': 'warn',
|
|
220
|
-
'jsdoc/valid-types': 'warn',
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
|
|
224
|
-
{
|
|
225
|
-
// 忽略规则
|
|
226
|
-
ignores: [
|
|
227
|
-
'node_modules/**',
|
|
228
|
-
'dist/**',
|
|
229
|
-
'build/**',
|
|
230
|
-
'coverage/**',
|
|
231
|
-
'*.min.js',
|
|
232
|
-
'eslint.config.js'
|
|
233
|
-
],
|
|
234
|
-
},
|
|
235
|
-
];
|