midway-fatcms 0.0.1-beta.26 → 0.0.1-beta.29
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/dist/config/config.default.js +6 -4
- package/dist/controller/home.controller.js +2 -1
- package/dist/controller/manage/CrudStandardDesignApi.js +8 -8
- package/dist/controller/render/AppRenderController.js +2 -1
- package/dist/middleware/global.middleware.js +22 -9
- package/dist/models/AsyncTaskModel.d.ts +2 -0
- package/dist/models/AsyncTaskModel.js +3 -1
- package/dist/models/RedisKeys.d.ts +2 -0
- package/dist/models/RedisKeys.js +2 -0
- package/dist/models/bizmodels.d.ts +1 -0
- package/dist/service/UserSessionService.d.ts +21 -0
- package/dist/service/UserSessionService.js +71 -1
- package/dist/service/WorkbenchService.d.ts +32 -0
- package/dist/service/WorkbenchService.js +54 -11
- package/dist/service/anyapi/AnyApiSandboxService.js +12 -12
- package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +14 -1
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +70 -25
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +1 -1
- package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.js +11 -2
- package/dist/service/base/RedisCacheService.d.ts +7 -0
- package/dist/service/base/RedisCacheService.js +7 -0
- package/dist/service/crudstd/CrudStdService.d.ts +0 -6
- package/dist/service/crudstd/CrudStdService.js +13 -33
- package/package.json +1 -5
- package/src/config/config.default.ts +0 -207
- package/src/config/seed/aeskey.txt +0 -1
- package/src/config/utils.ts +0 -22
- package/src/configuration.ts +0 -109
- package/src/controller/base/BaseApiController.ts +0 -170
- package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
- package/src/controller/gateway/AsyncTaskController.ts +0 -157
- package/src/controller/gateway/CrudMtdGatewayController.ts +0 -111
- package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
- package/src/controller/gateway/DocGatewayController.ts +0 -173
- package/src/controller/gateway/FileController.ts +0 -109
- package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
- package/src/controller/gateway/PublicApiController.ts +0 -142
- package/src/controller/gateway/StaticController.ts +0 -298
- package/src/controller/helpers.controller.ts +0 -161
- package/src/controller/home.controller.ts +0 -64
- package/src/controller/manage/AnyApiMangeApi.ts +0 -66
- package/src/controller/manage/AppLogMangeApi.ts +0 -53
- package/src/controller/manage/AppMangeApi.ts +0 -53
- package/src/controller/manage/AppPageMangeApi.ts +0 -52
- package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
- package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
- package/src/controller/manage/CrudStandardDesignApi.ts +0 -346
- package/src/controller/manage/DataDictManageApi.ts +0 -78
- package/src/controller/manage/DeployManageApi.ts +0 -175
- package/src/controller/manage/DocLibManageApi.ts +0 -69
- package/src/controller/manage/DocManageApi.ts +0 -99
- package/src/controller/manage/FileManageApi.ts +0 -45
- package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
- package/src/controller/manage/MenuManageApi.ts +0 -58
- package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
- package/src/controller/manage/SuperAdminManageApi.ts +0 -139
- package/src/controller/manage/SysConfigMangeApi.ts +0 -95
- package/src/controller/manage/SystemInfoManageApi.ts +0 -53
- package/src/controller/manage/UserAccountManageApi.ts +0 -94
- package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
- package/src/controller/myinfo/AuthController.ts +0 -108
- package/src/controller/myinfo/MyInfoController.ts +0 -32
- package/src/controller/render/AppRenderController.ts +0 -79
- package/src/controller/test.controller.ts +0 -37
- package/src/filter/default.filter.ts +0 -13
- package/src/filter/notfound.filter.ts +0 -10
- package/src/index.ts +0 -106
- package/src/interface.ts +0 -31
- package/src/libs/crud-pro/CrudPro.ts +0 -165
- package/src/libs/crud-pro/defaultConfigs.ts +0 -15
- package/src/libs/crud-pro/exceptions.ts +0 -124
- package/src/libs/crud-pro/interfaces.ts +0 -190
- package/src/libs/crud-pro/models/ExecuteContext.ts +0 -120
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -96
- package/src/libs/crud-pro/models/FuncContext.ts +0 -21
- package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
- package/src/libs/crud-pro/models/RequestModel.ts +0 -141
- package/src/libs/crud-pro/models/ResModel.ts +0 -19
- package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
- package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
- package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
- package/src/libs/crud-pro/models/Transaction.ts +0 -73
- package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
- package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -102
- package/src/libs/crud-pro/models/keys.ts +0 -159
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -83
- package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -262
- package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
- package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -354
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -185
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -393
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -94
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -86
- package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
- package/src/libs/crud-pro/sql.txt +0 -120
- package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
- package/src/libs/crud-pro/utils/DatabaseName.ts +0 -60
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
- package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
- package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
- package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
- package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
- package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
- package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
- package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
- package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -165
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
- package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +0 -26
- package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
- package/src/libs/global-config/global-config.ts +0 -78
- package/src/libs/utils/common-dto.ts +0 -52
- package/src/libs/utils/crypto-utils.ts +0 -50
- package/src/libs/utils/errorToString.ts +0 -61
- package/src/libs/utils/fatcms-request.ts +0 -103
- package/src/libs/utils/functions.ts +0 -73
- package/src/libs/utils/ordernum-utils.ts +0 -14
- package/src/libs/utils/parseConfig.ts +0 -54
- package/src/libs/utils/parseCreateSql.ts +0 -91
- package/src/libs/utils/render-utils.ts +0 -184
- package/src/middleware/forbidden.middleware.ts +0 -52
- package/src/middleware/global.middleware.ts +0 -280
- package/src/middleware/permission.middleware.ts +0 -80
- package/src/middleware/tx.middleware.ts +0 -30
- package/src/models/AsyncTaskModel.ts +0 -82
- package/src/models/RedisKeys.ts +0 -13
- package/src/models/SystemEntities.ts +0 -115
- package/src/models/SystemPerm.ts +0 -105
- package/src/models/SystemTables.ts +0 -27
- package/src/models/bizmodels.ts +0 -120
- package/src/models/contextLogger.ts +0 -132
- package/src/models/devops.ts +0 -17
- package/src/models/userSession.ts +0 -216
- package/src/schedule/anonymousContext.ts +0 -73
- package/src/schedule/index.ts +0 -12
- package/src/schedule/runSchedule.ts +0 -82
- package/src/schedule/scheduleNames.ts +0 -21
- package/src/service/AuthService.ts +0 -272
- package/src/service/EnumInfoService.ts +0 -130
- package/src/service/FileCenterService.ts +0 -395
- package/src/service/SysConfigService.ts +0 -37
- package/src/service/UserAccountService.ts +0 -107
- package/src/service/UserSessionService.ts +0 -78
- package/src/service/VisitStatService.ts +0 -166
- package/src/service/WorkbenchService.ts +0 -165
- package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
- package/src/service/anyapi/AnyApiService.ts +0 -186
- package/src/service/asyncTask/AsyncTaskRunnerService.ts +0 -266
- package/src/service/asyncTask/AsyncTaskService.ts +0 -21
- package/src/service/asyncTask/handler/ExcelInfoModel.ts +0 -11
- package/src/service/asyncTask/handler/ExportExcelAsyncTaskHandler.ts +0 -245
- package/src/service/asyncTask/handler/ExportExcelByInnerHttpHandler.ts +0 -147
- package/src/service/asyncTask/handler/ExportExcelByStdCrudHandler.ts +0 -138
- package/src/service/base/ApiBaseService.ts +0 -42
- package/src/service/base/ApiRateLimiter.ts +0 -59
- package/src/service/base/BaseService.ts +0 -100
- package/src/service/base/RedisCacheService.ts +0 -38
- package/src/service/crudstd/CrudStdActionService.ts +0 -27
- package/src/service/crudstd/CrudStdConstant.ts +0 -62
- package/src/service/crudstd/CrudStdRelationService.ts +0 -78
- package/src/service/crudstd/CrudStdService.ts +0 -283
- package/src/service/curd/CrudProQuick.ts +0 -131
- package/src/service/curd/CurdMixByAccountService.ts +0 -90
- package/src/service/curd/CurdMixByDictService.ts +0 -114
- package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -219
- package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
- package/src/service/curd/CurdMixByWorkbenchService.ts +0 -71
- package/src/service/curd/CurdMixService.ts +0 -97
- package/src/service/curd/CurdMixUtils.ts +0 -311
- package/src/service/curd/CurdProService.ts +0 -229
- package/src/service/curd/fixCfgModel.ts +0 -139
- package/src/service/proxyapi/ProxyApiLoadService.ts +0 -174
- package/src/service/proxyapi/ProxyApiService.ts +0 -262
- package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
- package/src/service/proxyapi/RouteHandler.ts +0 -8
- package/src/service/proxyapi/RouteTrie.ts +0 -74
- package/src/service/proxyapi/WeightedRandom.ts +0 -37
- package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
- package/src/views/404_app.html +0 -31
- package/src/views/404_workbench.html +0 -34
- package/src/views/static/favicon.ico +0 -0
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import * as _ from 'lodash';
|
|
2
|
-
import { RequestModel } from './RequestModel';
|
|
3
|
-
import { RequestCfgModel } from './RequestCfgModel';
|
|
4
|
-
import { SqlCfgModel } from './SqlCfgModel';
|
|
5
|
-
import { messageParseUtils } from '../utils/MessageParseUtils';
|
|
6
|
-
import { Transaction } from './Transaction';
|
|
7
|
-
import { ColumnRelation, ICrudProCfg, ILogger, IVisitor } from '../interfaces';
|
|
8
|
-
import { IExecuteContextFunc } from './ExecuteContextFunc';
|
|
9
|
-
import { defaultCrudProCfg } from '../defaultConfigs';
|
|
10
|
-
import { ResModelFlexible } from './ResModel';
|
|
11
|
-
|
|
12
|
-
class ExecuteContext {
|
|
13
|
-
// 运行前设置的
|
|
14
|
-
private transaction: Transaction;
|
|
15
|
-
private logger: ILogger;
|
|
16
|
-
private visitor: IVisitor;
|
|
17
|
-
private contextCfg: ICrudProCfg = defaultCrudProCfg;
|
|
18
|
-
public contextFunc: IExecuteContextFunc;
|
|
19
|
-
|
|
20
|
-
// 运行时设置的。
|
|
21
|
-
private sqlCfgModels: SqlCfgModel[] = [];
|
|
22
|
-
private reqModel: RequestModel = null;
|
|
23
|
-
private resModel: ResModelFlexible = {};
|
|
24
|
-
private cfgModel: RequestCfgModel = null;
|
|
25
|
-
|
|
26
|
-
setTransaction(transaction: Transaction) {
|
|
27
|
-
this.transaction = transaction;
|
|
28
|
-
}
|
|
29
|
-
getTransaction(): Transaction {
|
|
30
|
-
return this.transaction;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
setContextCfg(contextCfg: ICrudProCfg) {
|
|
34
|
-
if (typeof contextCfg === 'object') {
|
|
35
|
-
Object.assign(this.contextCfg, contextCfg);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getContextCfg(): ICrudProCfg {
|
|
40
|
-
return this.contextCfg;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setLogger(logger: ILogger) {
|
|
44
|
-
this.logger = logger;
|
|
45
|
-
}
|
|
46
|
-
getLogger(): ILogger {
|
|
47
|
-
return this.logger;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
setVisitor(visitor: IVisitor) {
|
|
51
|
-
this.visitor = visitor;
|
|
52
|
-
}
|
|
53
|
-
getVisitor(): IVisitor {
|
|
54
|
-
return this.visitor;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
getReqModel(): RequestModel {
|
|
58
|
-
return this.reqModel;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
setReqModel(reqModel: RequestModel) {
|
|
62
|
-
this.reqModel = reqModel;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getResModel(): ResModelFlexible {
|
|
66
|
-
return this.resModel;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
getOneObj() {
|
|
70
|
-
return this.resModel['row'];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getResRows(): any[] {
|
|
74
|
-
return this.resModel['rows'];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
setResModelItem(resName: string, data: any) {
|
|
78
|
-
this.resModel[resName] = data;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getResModelItem(resName: string): any {
|
|
82
|
-
return this.resModel[resName];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
getResModelItemLodash(resName: string): any {
|
|
86
|
-
return _.get(this.resModel, resName);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
setCfgModel(cfgModel: RequestCfgModel) {
|
|
90
|
-
this.cfgModel = cfgModel;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
getCfgModel(): RequestCfgModel {
|
|
94
|
-
return this.cfgModel;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getSqlCfgModels(): SqlCfgModel[] {
|
|
98
|
-
return this.sqlCfgModels;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
getResMessage(): string {
|
|
102
|
-
return messageParseUtils.getResMessage(this);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
interface IExecuteContextCustom {
|
|
107
|
-
rows: any[];
|
|
108
|
-
columnsRelation?: ColumnRelation[];
|
|
109
|
-
isCustomContext?: boolean;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
type HandleExecuteContextType = ExecuteContext | IExecuteContextCustom;
|
|
113
|
-
// type HandleExecuteContextType = IExecuteContextCustom
|
|
114
|
-
|
|
115
|
-
interface IExecuteContextHandler {
|
|
116
|
-
handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
|
|
117
|
-
handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void>;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { ExecuteContext, IExecuteContextHandler, HandleExecuteContextType, IExecuteContextCustom };
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { IConnectionPool, IRequestCfgModel, IRequestModel } from '../interfaces';
|
|
2
|
-
import { ExecuteContext } from './ExecuteContext';
|
|
3
|
-
import { SqlCfgModel } from './SqlCfgModel';
|
|
4
|
-
import { RequestCfgModel } from './RequestCfgModel';
|
|
5
|
-
import { RequestModel } from './RequestModel';
|
|
6
|
-
import { KeysOfAuthType } from './keys';
|
|
7
|
-
import { CommonException, Exceptions } from '../exceptions';
|
|
8
|
-
import { MixinUtils } from '../utils/MixinUtils';
|
|
9
|
-
|
|
10
|
-
export interface IExecuteContextFunc {
|
|
11
|
-
setExecuteContext(exeCtx: ExecuteContext);
|
|
12
|
-
getExecuteContext(): ExecuteContext;
|
|
13
|
-
getConnectionPool(sqlCfgModel: SqlCfgModel): Promise<IConnectionPool>;
|
|
14
|
-
getFunctionMap(): any;
|
|
15
|
-
validateByAuthCfg(cfgModel: RequestCfgModel, reqModel: RequestModel): Promise<any>;
|
|
16
|
-
afterExecuteSQLList(): Promise<any>;
|
|
17
|
-
beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel): Promise<any>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class BaseExecuteContextFunc implements IExecuteContextFunc {
|
|
21
|
-
private executeContext: ExecuteContext;
|
|
22
|
-
async getConnectionPool(sqlCfgModel: SqlCfgModel): Promise<IConnectionPool> {
|
|
23
|
-
throw 'getConnectionPool not implemented';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getFunctionMap(): any {
|
|
27
|
-
return {};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 校验请求权限
|
|
32
|
-
* @param cfgModel
|
|
33
|
-
* @param reqModel
|
|
34
|
-
*/
|
|
35
|
-
async validateByAuthCfg(cfgModel: RequestCfgModel, reqModel: RequestModel): Promise<any> {
|
|
36
|
-
if (cfgModel.authType === KeysOfAuthType.free || !cfgModel.authType) {
|
|
37
|
-
return; // 无需校验
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const visitor = reqModel.visitor;
|
|
41
|
-
|
|
42
|
-
if (!visitor.isLogin) {
|
|
43
|
-
throw new CommonException(Exceptions.NOT_LOGIN, '用户没有登陆');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 超级管理员 无需校验
|
|
47
|
-
if (visitor.isSuperAdmin === true) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (cfgModel.authType === KeysOfAuthType.byFuncCode) {
|
|
52
|
-
const funcCodes = cfgModel.authConfig;
|
|
53
|
-
if (MixinUtils.isEmpty(funcCodes)) {
|
|
54
|
-
throw new CommonException(Exceptions.CFG_AUTH_CODE_EMPTY, '缺少权限编码配置');
|
|
55
|
-
}
|
|
56
|
-
if (!MixinUtils.hasAny(visitor.functionCodes, funcCodes)) {
|
|
57
|
-
throw new CommonException(Exceptions.NO_AUTH, '缺少权限: ' + JSON.stringify(funcCodes));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (cfgModel.authType === KeysOfAuthType.byRoleCode) {
|
|
62
|
-
const roleCodes = cfgModel.authConfig;
|
|
63
|
-
if (MixinUtils.isEmpty(roleCodes)) {
|
|
64
|
-
throw new CommonException(Exceptions.CFG_AUTH_CODE_EMPTY, '缺少角色编码配置');
|
|
65
|
-
}
|
|
66
|
-
if (!MixinUtils.hasAny(visitor.roleCodes, roleCodes)) {
|
|
67
|
-
throw new CommonException(Exceptions.NO_AUTH, '缺少角色: ' + JSON.stringify(roleCodes));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* SQL执行完之后做一些额外操作,可以处理一下将要返回的数据。
|
|
74
|
-
* @param exeCtx
|
|
75
|
-
*/
|
|
76
|
-
afterExecuteSQLList(): Promise<any> {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 在执行之前可以根据业务需要修改需要执行的内容
|
|
82
|
-
* @param reqJson
|
|
83
|
-
* @param cfgJson
|
|
84
|
-
*/
|
|
85
|
-
beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel): Promise<any> {
|
|
86
|
-
return Promise.resolve();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getExecuteContext(): ExecuteContext {
|
|
90
|
-
return this.executeContext;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
setExecuteContext(executeContext: ExecuteContext) {
|
|
94
|
-
this.executeContext = executeContext;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { RequestModel } from './RequestModel';
|
|
2
|
-
|
|
3
|
-
class FuncContext {
|
|
4
|
-
/**
|
|
5
|
-
* 执行结果:
|
|
6
|
-
* 在validate/update阶段为空
|
|
7
|
-
* 在execute阶段不为空
|
|
8
|
-
*/
|
|
9
|
-
resModel: any; //通过 res.xx.xx获取
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 请求中的数据
|
|
13
|
-
*/
|
|
14
|
-
reqModel: RequestModel; //通过 req.xx.xx获取
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 当前行中的数据
|
|
18
|
-
*/
|
|
19
|
-
currentValue: any; // 当前值, 使用 $current获取
|
|
20
|
-
}
|
|
21
|
-
export { FuncContext };
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { ColumnRelation, IFuncCfgModel, IRequestCfgModel, ISqlCfgModel, IValidatorCfgItem } from '../interfaces';
|
|
2
|
-
import { SqlCfgModel } from './SqlCfgModel';
|
|
3
|
-
import { MixinUtils } from '../utils/MixinUtils';
|
|
4
|
-
import { KeysOfAuthType, KeysOfSimpleSQL, KeysOfSqlResPicker, SqlDbType } from './keys';
|
|
5
|
-
import { DEFAULT_MAX_LIMIT } from '../defaultConfigs';
|
|
6
|
-
//
|
|
7
|
-
// const columnsRelation = [
|
|
8
|
-
// {
|
|
9
|
-
// relatedType: 'dict',
|
|
10
|
-
// relatedCode: 'SexEnum',
|
|
11
|
-
// sourceColumns: ['sex'],
|
|
12
|
-
// targetColumns: [{ from: 'label', to: 'sexLabel' }],
|
|
13
|
-
// },
|
|
14
|
-
// {
|
|
15
|
-
// relatedType: 'userBasic',
|
|
16
|
-
// // relatedCode: 'SexEnum',
|
|
17
|
-
// sourceColumns: ['created_by'],
|
|
18
|
-
// targetColumns: [{ from: 'userNick', to: 'created_by_user_nick' }],
|
|
19
|
-
// },
|
|
20
|
-
// {
|
|
21
|
-
// relatedType: 'sysConfig',
|
|
22
|
-
// relatedCode: 'SexEnum',
|
|
23
|
-
// sourceColumns: ['sex'],
|
|
24
|
-
// targetColumns: [{ from: 'userNick', to: 'created_by_user_nick' }],
|
|
25
|
-
// },
|
|
26
|
-
// ];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* sqlSimpleName/sqlCfgList 二选一
|
|
30
|
-
* sqlCfgList 优先级高于 sqlSimpleName
|
|
31
|
-
* 如果设置了sqlCfgList,则sqlSimpleName不再生效。
|
|
32
|
-
*/
|
|
33
|
-
class RequestCfgModel {
|
|
34
|
-
columns?: string[]; // "columns": "id,name,age,sex,addr", 可以为空,为空代表 星号*
|
|
35
|
-
columnsRelation?: ColumnRelation[]; //通过列关联其他信息
|
|
36
|
-
uniqueColumn?: string[]; //postgres的惟一键。insert on CONFLICT DO UPDATE
|
|
37
|
-
|
|
38
|
-
sqlTable: string; // 可以为空. originSql中不包含@@table时可以为空
|
|
39
|
-
sqlSchema?: string; // 可以为空
|
|
40
|
-
sqlDatabase?: string; // 可以为空,用此字段进行connection的选择和切换。配合getBizConnectionPool使用
|
|
41
|
-
sqlDbType?: SqlDbType; // 数据库类型,mysql(默认) 、postgres
|
|
42
|
-
maxLimit = DEFAULT_MAX_LIMIT; // 最大一次性返回的数量
|
|
43
|
-
method: string; // 不能为空
|
|
44
|
-
transactionEnable: boolean; // 是否开启事务,默认不开启,每条语句都是autocommit
|
|
45
|
-
transactionIsolation: number; // 事务隔离级别
|
|
46
|
-
sqlSimpleName: KeysOfSimpleSQL; // 二选一 sqlSimpleName sqlCfgList
|
|
47
|
-
sqlCfgList: SqlCfgModel[]; // 二选一 sqlSimpleName sqlCfgList
|
|
48
|
-
functionCfg: Record<string, IFuncCfgModel>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* key 为update哪个字段。 如:{'data.userName': { constString: 'zhangsan' }}
|
|
52
|
-
*/
|
|
53
|
-
updateCfg: Record<string, IFuncCfgModel>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* key 为update哪个字段。 如:{'data.userName': [{ constString: 'zhangsan' },'required']}
|
|
57
|
-
* value 是一个数组,允许添加多个校验器。
|
|
58
|
-
*/
|
|
59
|
-
validateCfg: Record<string, IValidatorCfgItem[]>;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* key为data或condition;value为字段数组
|
|
63
|
-
* 如:{
|
|
64
|
-
* allowCfg: {
|
|
65
|
-
* data: ['id','name','age']
|
|
66
|
-
* }
|
|
67
|
-
* }
|
|
68
|
-
*/
|
|
69
|
-
allowCfg: Record<string, string[]>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* key为data或condition;value为字段数组
|
|
73
|
-
* 如:{
|
|
74
|
-
* rejectCfg: {
|
|
75
|
-
* data: ['id','name','age']
|
|
76
|
-
* }
|
|
77
|
-
* }
|
|
78
|
-
*/
|
|
79
|
-
rejectCfg: Record<string, string[]>;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 鉴权类型;free无需鉴权,login仅登录即可,byRoleCode校验角色,byFuncCode校验功能点
|
|
83
|
-
*/
|
|
84
|
-
authType: KeysOfAuthType;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 鉴权类型为byRole或byFunc时,额外的配置。角色code或功能点code
|
|
88
|
-
*/
|
|
89
|
-
authConfig: string[];
|
|
90
|
-
|
|
91
|
-
constructor(json: Partial<IRequestCfgModel>) {
|
|
92
|
-
Object.assign(this, json);
|
|
93
|
-
this.columns = MixinUtils.parseColumns(json.columns);
|
|
94
|
-
this.authConfig = this.parseAuthConfig(json.authConfig);
|
|
95
|
-
this.sqlCfgList = [];
|
|
96
|
-
this.addSqlCfgModelList(json.sqlCfgList);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private parseAuthConfig(cfg: any): string[] {
|
|
100
|
-
if (!cfg) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
if (Array.isArray(cfg)) {
|
|
104
|
-
return cfg;
|
|
105
|
-
}
|
|
106
|
-
if (typeof cfg === 'string') {
|
|
107
|
-
return [cfg];
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public addSqlCfgModel(resName: string, originSql: string, resPicker?: KeysOfSqlResPicker, executeWhenFunCfg?: IFuncCfgModel) {
|
|
113
|
-
const model = new SqlCfgModel({ resName, originSql });
|
|
114
|
-
if (resPicker) {
|
|
115
|
-
model.resPicker = resPicker;
|
|
116
|
-
}
|
|
117
|
-
if (executeWhenFunCfg) {
|
|
118
|
-
model.executeWhen = executeWhenFunCfg;
|
|
119
|
-
}
|
|
120
|
-
this.addSqlCfgModelIf(model);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private addSqlCfgModelList(list: ISqlCfgModel[]) {
|
|
124
|
-
if (!list || !Array.isArray(list)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
for (let i = 0; i < list.length; i++) {
|
|
128
|
-
const listElement = list[i];
|
|
129
|
-
const model = new SqlCfgModel(listElement);
|
|
130
|
-
this.addSqlCfgModelIf(model);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private addSqlCfgModelIf(model: SqlCfgModel) {
|
|
135
|
-
if (!this.sqlCfgList) {
|
|
136
|
-
this.sqlCfgList = [];
|
|
137
|
-
}
|
|
138
|
-
this.sqlCfgList.push(model);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
export { RequestCfgModel };
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import * as _ from 'lodash';
|
|
2
|
-
import { ILimitOffset, IOrderByItem, IRequestModel, IVisitor } from '../interfaces';
|
|
3
|
-
import { MixinUtils } from '../utils/MixinUtils';
|
|
4
|
-
import { CommonException, Exceptions } from '../exceptions';
|
|
5
|
-
import { DEFAULT_LIMIT } from '../defaultConfigs';
|
|
6
|
-
|
|
7
|
-
class RequestModel {
|
|
8
|
-
visitor: IVisitor;
|
|
9
|
-
|
|
10
|
-
method: string;
|
|
11
|
-
columns?: string[]; // "columns": "id,name,age,sex,addr",
|
|
12
|
-
condition?: Record<string, any>;
|
|
13
|
-
data?: Record<string, any>;
|
|
14
|
-
limit: number;
|
|
15
|
-
offset: number;
|
|
16
|
-
orderBys?: IOrderByItem[];
|
|
17
|
-
|
|
18
|
-
constructor(req: IRequestModel, visitor: IVisitor) {
|
|
19
|
-
Object.assign(this, req);
|
|
20
|
-
this.visitor = visitor;
|
|
21
|
-
this.columns = MixinUtils.parseColumns(req.columns);
|
|
22
|
-
this.orderBys = this.parseOrderBys(req.orderBy);
|
|
23
|
-
const limitOffset = this.parseOffsetList(req);
|
|
24
|
-
this.limit = limitOffset.limit;
|
|
25
|
-
this.offset = limitOffset.offset;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private parseOrderBys(orderByStr: any): IOrderByItem[] {
|
|
29
|
-
if (MixinUtils.isEmpty(orderByStr)) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (Array.isArray(orderByStr)) {
|
|
34
|
-
return orderByStr
|
|
35
|
-
.map(obj => {
|
|
36
|
-
if (typeof obj === 'string') {
|
|
37
|
-
return { fieldName: obj, orderType: 'asc' };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const { fieldName, orderType = 'asc' } = obj;
|
|
41
|
-
if (fieldName) {
|
|
42
|
-
return { fieldName, orderType };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
})
|
|
47
|
-
.filter(o => {
|
|
48
|
-
return !!o;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const orderByResult: IOrderByItem[] = [];
|
|
53
|
-
const orderByArray = orderByStr
|
|
54
|
-
.split(',')
|
|
55
|
-
.map(s => {
|
|
56
|
-
return s.trim();
|
|
57
|
-
})
|
|
58
|
-
.filter(s => !!s);
|
|
59
|
-
|
|
60
|
-
if (MixinUtils.isEmpty(orderByArray)) {
|
|
61
|
-
return orderByResult;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
for (let i = 0; i < orderByArray.length; i++) {
|
|
65
|
-
const orderByItem = orderByArray[i];
|
|
66
|
-
let orderType = 'asc'; //默认升序
|
|
67
|
-
let fieldName = orderByItem;
|
|
68
|
-
|
|
69
|
-
if (orderByItem.endsWith('+')) {
|
|
70
|
-
// 升序
|
|
71
|
-
fieldName = orderByItem.substring(0, orderByItem.length - 1);
|
|
72
|
-
orderType = 'asc'; //升序
|
|
73
|
-
} else if (orderByItem.endsWith('-')) {
|
|
74
|
-
//降序
|
|
75
|
-
fieldName = orderByItem.substring(0, orderByItem.length - 1);
|
|
76
|
-
orderType = 'desc'; //降序
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
fieldName = fieldName.trim();
|
|
80
|
-
|
|
81
|
-
if (MixinUtils.isEmpty(fieldName) || !MixinUtils.isValidFieldName(fieldName)) {
|
|
82
|
-
throw new CommonException(Exceptions.REQUEST_MODEL_PARSE_ORDER_BY_FAILED, orderByItem);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
orderByResult.push({ fieldName, orderType });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return orderByResult;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private parseOffsetList(req: IRequestModel): ILimitOffset {
|
|
92
|
-
const { limit, offset, pageSize, pageNo } = req;
|
|
93
|
-
|
|
94
|
-
const limitOffset: ILimitOffset = {
|
|
95
|
-
limit: DEFAULT_LIMIT,
|
|
96
|
-
offset: 0,
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
if (typeof limit === 'number') {
|
|
100
|
-
limitOffset.limit = limit;
|
|
101
|
-
}
|
|
102
|
-
if (typeof offset === 'number') {
|
|
103
|
-
limitOffset.offset = offset;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (typeof pageNo === 'number' && typeof pageSize === 'number' && pageNo > 0 && pageSize > 0) {
|
|
107
|
-
limitOffset.limit = pageSize;
|
|
108
|
-
limitOffset.offset = (pageNo - 1) * pageSize;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return limitOffset;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* 获取对象数据类型
|
|
116
|
-
* @param attrName
|
|
117
|
-
*/
|
|
118
|
-
getCondOrDataJsonObject(attrName: string): any {
|
|
119
|
-
if (attrName.startsWith('data') || attrName.startsWith('condition')) {
|
|
120
|
-
const jsonObject = _.get(this, attrName);
|
|
121
|
-
if (!jsonObject) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
if (typeof jsonObject !== 'object' && !Array.isArray(jsonObject)) {
|
|
125
|
-
throw new CommonException(Exceptions.RUN_GET_COND_OR_DATA_JSONOBJECT, attrName);
|
|
126
|
-
}
|
|
127
|
-
return jsonObject;
|
|
128
|
-
}
|
|
129
|
-
throw new CommonException(Exceptions.RUN_GET_COND_OR_DATA_JSONOBJECT, attrName);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 获取基本数据类型
|
|
134
|
-
* @param attrName
|
|
135
|
-
*/
|
|
136
|
-
getJsonObjectValue(attrName: string): any {
|
|
137
|
-
return _.get(this, attrName);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export { RequestModel };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
interface ResModelAffected {
|
|
2
|
-
insertId?: string | number;
|
|
3
|
-
affectedRows: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
interface ResModelStandard {
|
|
7
|
-
row?: any;
|
|
8
|
-
rows?: any[];
|
|
9
|
-
total_count?: number;
|
|
10
|
-
affected?: ResModelAffected;
|
|
11
|
-
insert_affected?: ResModelAffected;
|
|
12
|
-
update_affected?: ResModelAffected;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type ResModelFlexible = ResModelStandard & {
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { ResModelAffected, ResModelStandard, ResModelFlexible };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { RequestCfgModel } from './RequestCfgModel';
|
|
2
|
-
import { RequestModel } from './RequestModel';
|
|
3
|
-
import { SqlCfgModel } from './SqlCfgModel';
|
|
4
|
-
import { ExecuteContext } from './ExecuteContext';
|
|
5
|
-
import { IFuncCfgModel, IRequestCfgModel, ITableMeta } from '../interfaces';
|
|
6
|
-
import { FuncContext } from './FuncContext';
|
|
7
|
-
|
|
8
|
-
export interface ICurdProServiceHub {
|
|
9
|
-
getExecuteContext(): ExecuteContext;
|
|
10
|
-
|
|
11
|
-
validateByAllow(cfgModel: RequestCfgModel, reqModel: RequestModel);
|
|
12
|
-
|
|
13
|
-
validateByReject(cfgModel: RequestCfgModel, reqModel: RequestModel);
|
|
14
|
-
|
|
15
|
-
validateByCfg(cfgModel: RequestCfgModel, reqModel: RequestModel);
|
|
16
|
-
|
|
17
|
-
validateByAuthCfg(cfgModel: RequestCfgModel, reqModel: RequestModel): void;
|
|
18
|
-
|
|
19
|
-
updateByCfg(cfgModel: RequestCfgModel, reqModel: RequestModel);
|
|
20
|
-
|
|
21
|
-
getCachedCfgByMethod(method: string, isEnableCache: boolean): Promise<IRequestCfgModel>;
|
|
22
|
-
|
|
23
|
-
generateSQLList(exeCtx: ExecuteContext): Promise<void>;
|
|
24
|
-
|
|
25
|
-
executeSqlCfgModels(exeCtx: ExecuteContext): Promise<void>;
|
|
26
|
-
|
|
27
|
-
convertOriginToExecuteSql(sqlCfgModel: SqlCfgModel): Promise<void>;
|
|
28
|
-
|
|
29
|
-
executeFuncCfg(tmpFunCfg: IFuncCfgModel, exeFunCtx: FuncContext): string;
|
|
30
|
-
|
|
31
|
-
getTableMeta(sqlCfgModel: SqlCfgModel): Promise<ITableMeta>;
|
|
32
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ColumnRelation, IFuncCfgModel, ISqlCfgModel } from '../interfaces';
|
|
2
|
-
import { MixinUtils } from '../utils/MixinUtils';
|
|
3
|
-
import { KeyOfCrudTypes, KeysOfSqlResPicker, SqlDbType } from './keys';
|
|
4
|
-
import { parseJsonObject } from '../../utils/functions';
|
|
5
|
-
|
|
6
|
-
const { isEmpty } = MixinUtils;
|
|
7
|
-
|
|
8
|
-
class SqlCfgModel {
|
|
9
|
-
columns: string[]; // "columns": "id,name,age,sex,addr",
|
|
10
|
-
columnsRelation?: ColumnRelation[]; //只能关联基本信息:如枚举值
|
|
11
|
-
sqlTable: string; // 可以为空. originSql中不包含@@table时可以为空
|
|
12
|
-
sqlSchema?: string; // 可以为空
|
|
13
|
-
sqlDatabase?: string; // 可以为空,用此字段进行connection的选择和切换。配合getBizConnectionPool使用
|
|
14
|
-
sqlDbType?: SqlDbType; // 数据库类型,mysql(默认) 、postgres
|
|
15
|
-
maxLimit: number; // 最大一次性返回的数量
|
|
16
|
-
resName: string;
|
|
17
|
-
resPicker: KeysOfSqlResPicker;
|
|
18
|
-
originSql: string; // 有特殊占位符的SQL, 原始的SQL constructor(resName: string, originSql: string) {}
|
|
19
|
-
validate: IFuncCfgModel; //执行前,进行校验,校验不通过就抛出异常. 校验函数可以返回 boolean或直接抛出异常
|
|
20
|
-
executeWhen: IFuncCfgModel; //满足表达式的结果,才能执行。 默认:true 校验函数必须返回 booleansetResPicker(resPicker: string) {}
|
|
21
|
-
executeSql: string; // 可以运行的SQL
|
|
22
|
-
executeSqlArgs: any[]; //可以运行的SQL的参数setExecuteWhen(executeWhenFunCfg: IFuncCfgModel) {}
|
|
23
|
-
crudType: KeyOfCrudTypes = null;
|
|
24
|
-
|
|
25
|
-
constructor(json: Partial<ISqlCfgModel>) {
|
|
26
|
-
Object.assign(this, json);
|
|
27
|
-
this.columns = MixinUtils.parseColumns(json.columns);
|
|
28
|
-
this.executeWhen = parseJsonObject(json.executeWhen);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public getCrudType(): KeyOfCrudTypes {
|
|
32
|
-
if (!this.crudType) {
|
|
33
|
-
const sql = this.executeSql.trim().toUpperCase();
|
|
34
|
-
if (isEmpty(sql)) {
|
|
35
|
-
this.crudType = KeyOfCrudTypes.EMPTY_SQL;
|
|
36
|
-
} else if (sql.startsWith(KeyOfCrudTypes.SELECT)) {
|
|
37
|
-
this.crudType = KeyOfCrudTypes.SELECT;
|
|
38
|
-
} else if (sql.startsWith(KeyOfCrudTypes.UPDATE)) {
|
|
39
|
-
this.crudType = KeyOfCrudTypes.UPDATE;
|
|
40
|
-
} else if (sql.startsWith(KeyOfCrudTypes.DELETE)) {
|
|
41
|
-
this.crudType = KeyOfCrudTypes.DELETE;
|
|
42
|
-
} else if (sql.startsWith(KeyOfCrudTypes.INSERT)) {
|
|
43
|
-
this.crudType = KeyOfCrudTypes.INSERT;
|
|
44
|
-
} else {
|
|
45
|
-
this.crudType = KeyOfCrudTypes.NOT_CRUD;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return this.crudType;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { SqlCfgModel };
|