@ibiz-template/model-helper 0.6.0 → 0.6.1-alpha.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/dist/index.esm.js +772 -756
- package/dist/index.system.min.js +1 -1
- package/package.json +7 -8
- package/src/index.ts +0 -12
- package/src/model/PSSYSAPP.ts +0 -12
- package/src/model-helper.ts +0 -360
- package/src/model-loader.ts +0 -51
- package/src/model-util.ts +0 -400
- package/src/utils/format-path/format-path.ts +0 -9
- package/src/utils/index.ts +0 -9
- package/src/utils/merge-model/merge-app-menu.ts +0 -84
- package/src/utils/merge-model/merge-model.ts +0 -20
- package/src/utils/plural/plural.ts +0 -30
- package/src/utils/service-path-util/service-path-util.ts +0 -249
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { IAppDERS } from '@ibiz/model-core';
|
|
2
|
-
import { pluralLower } from '../plural/plural';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 获取服务拼接递归对象
|
|
6
|
-
*/
|
|
7
|
-
export type ServicePathDeep = [IAppDERS, ServicePathDeep[]];
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 服务路径项
|
|
11
|
-
*/
|
|
12
|
-
export type ServicePathItem = {
|
|
13
|
-
/**
|
|
14
|
-
* 实体代码名称(标准)
|
|
15
|
-
*
|
|
16
|
-
* @author chitanda
|
|
17
|
-
* @date 2022-08-25 18:08:35
|
|
18
|
-
* @type {string}
|
|
19
|
-
*/
|
|
20
|
-
codeName: string;
|
|
21
|
-
/**
|
|
22
|
-
* 实体代码名称(小写)
|
|
23
|
-
*
|
|
24
|
-
* @author chitanda
|
|
25
|
-
* @date 2022-08-25 18:08:54
|
|
26
|
-
* @type {string}
|
|
27
|
-
*/
|
|
28
|
-
lower: string;
|
|
29
|
-
/**
|
|
30
|
-
* 实体代码名称复数(小写)
|
|
31
|
-
*
|
|
32
|
-
* @author chitanda
|
|
33
|
-
* @date 2022-08-25 18:08:13
|
|
34
|
-
* @type {string}
|
|
35
|
-
*/
|
|
36
|
-
plural: string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 服务路径拼接工具
|
|
41
|
-
*
|
|
42
|
-
* @author chitanda
|
|
43
|
-
* @date 2022-08-22 21:08:52
|
|
44
|
-
* @export
|
|
45
|
-
* @class ServicePathUtil
|
|
46
|
-
*/
|
|
47
|
-
export class ServicePathUtil {
|
|
48
|
-
/**
|
|
49
|
-
* 应用实体关系
|
|
50
|
-
*
|
|
51
|
-
* @author chitanda
|
|
52
|
-
* @date 2022-08-22 22:08:18
|
|
53
|
-
* @protected
|
|
54
|
-
* @type {Map<string, IAppDERS[]>} <应用实体 id, 应用实体父关系>
|
|
55
|
-
*/
|
|
56
|
-
protected entityRsMap: Map<string, IAppDERS[]> = new Map();
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 实体资源路径
|
|
60
|
-
*
|
|
61
|
-
* @author chitanda
|
|
62
|
-
* @date 2022-08-22 22:08:58
|
|
63
|
-
* @protected
|
|
64
|
-
* @type {Map<string, ServicePathItem[][]>}
|
|
65
|
-
*/
|
|
66
|
-
protected entityRsPathMap: Map<string, ServicePathItem[][]> = new Map();
|
|
67
|
-
|
|
68
|
-
constructor(
|
|
69
|
-
protected appDataEntities: IModel[],
|
|
70
|
-
protected allDERss: IAppDERS[],
|
|
71
|
-
) {}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 根据应用主实体过滤从关系集合
|
|
75
|
-
*
|
|
76
|
-
* @author chitanda
|
|
77
|
-
* @date 2023-04-20 17:04:34
|
|
78
|
-
* @protected
|
|
79
|
-
* @param {string} id
|
|
80
|
-
* @return {*} {IAppDERS[]}
|
|
81
|
-
*/
|
|
82
|
-
protected filterDERSs(id: string): IAppDERS[] {
|
|
83
|
-
if (this.entityRsMap.has(id)) {
|
|
84
|
-
return this.entityRsMap.get(id)!;
|
|
85
|
-
}
|
|
86
|
-
const items = this.allDERss.filter(item => {
|
|
87
|
-
if ((item as IModel).rSMode === 2 && item.minorAppDataEntityId === id) {
|
|
88
|
-
return item;
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
});
|
|
92
|
-
if (items.length > 0) {
|
|
93
|
-
this.entityRsMap.set(id, items);
|
|
94
|
-
}
|
|
95
|
-
return items;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 计算指定应用实体所有资源路径
|
|
100
|
-
*
|
|
101
|
-
* @author chitanda
|
|
102
|
-
* @date 2023-04-22 13:04:27
|
|
103
|
-
* @param {string} id
|
|
104
|
-
* @return {*} {string[]}
|
|
105
|
-
*/
|
|
106
|
-
calcRequestPaths(id: string): string[] {
|
|
107
|
-
const paths = this.calcPaths(id);
|
|
108
|
-
return paths.map(path => {
|
|
109
|
-
return path.map(item => `${item.plural}/\${${item.lower}}`).join('/');
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 计算指定实体所有资源路径
|
|
115
|
-
*
|
|
116
|
-
* @author chitanda
|
|
117
|
-
* @date 2023-04-22 13:04:36
|
|
118
|
-
* @protected
|
|
119
|
-
* @param {string} id
|
|
120
|
-
* @return {*} {ServicePathItem[][]} 返回顺序为 [祖父实体,爷爷实体,父实体,当前实体]
|
|
121
|
-
*/
|
|
122
|
-
protected calcPaths(id: string): ServicePathItem[][] {
|
|
123
|
-
const entityRef = this.appDataEntities.find(item => item.id === id);
|
|
124
|
-
if (!entityRef) {
|
|
125
|
-
throw new Error(`未找到实体 ${id}`);
|
|
126
|
-
}
|
|
127
|
-
const { codeName } = entityRef;
|
|
128
|
-
if (this.entityRsPathMap.has(codeName)) {
|
|
129
|
-
return this.entityRsPathMap.get(codeName)!;
|
|
130
|
-
}
|
|
131
|
-
const deRss = this.filterDERSs(id);
|
|
132
|
-
if (deRss) {
|
|
133
|
-
// 已经计算过的应用实体标识
|
|
134
|
-
const ids: string[] = [id];
|
|
135
|
-
const arr = this.calcDeepPath(ids, deRss);
|
|
136
|
-
this.deepFillPath(codeName, [codeName], arr);
|
|
137
|
-
let paths = this.entityRsPathMap.get(codeName);
|
|
138
|
-
if (paths) {
|
|
139
|
-
paths = this.sortPath(paths);
|
|
140
|
-
this.entityRsPathMap.set(codeName, paths);
|
|
141
|
-
return paths;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return [];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 计算递归资源路径
|
|
149
|
-
*
|
|
150
|
-
* @author chitanda
|
|
151
|
-
* @date 2023-08-23 14:08:39
|
|
152
|
-
* @protected
|
|
153
|
-
* @param {string[]} ids
|
|
154
|
-
* @param {IAppDERS[]} deRss
|
|
155
|
-
* @param {number} [num=0]
|
|
156
|
-
* @return {*} {ServicePathDeep[]}
|
|
157
|
-
*/
|
|
158
|
-
protected calcDeepPath(
|
|
159
|
-
ids: string[],
|
|
160
|
-
deRss: IAppDERS[],
|
|
161
|
-
num: number = 0,
|
|
162
|
-
): ServicePathDeep[] {
|
|
163
|
-
if (num > 10) {
|
|
164
|
-
throw new Error('服务路径计算超过最大层级 10');
|
|
165
|
-
}
|
|
166
|
-
num += 1;
|
|
167
|
-
const arr: ServicePathDeep[] = [];
|
|
168
|
-
deRss.forEach(rs => {
|
|
169
|
-
if (ids.includes(rs.majorAppDataEntityId!)) {
|
|
170
|
-
ibiz.log.warn(
|
|
171
|
-
'计算资源关系路径出现循环递归引用,触发实体:',
|
|
172
|
-
rs.majorAppDataEntityId,
|
|
173
|
-
'当前已计算过实体清单: ',
|
|
174
|
-
ids,
|
|
175
|
-
);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
const items = this.filterDERSs(rs.majorAppDataEntityId!);
|
|
179
|
-
arr.push([
|
|
180
|
-
rs,
|
|
181
|
-
this.calcDeepPath([...ids, rs.majorAppDataEntityId!], items, num),
|
|
182
|
-
]);
|
|
183
|
-
});
|
|
184
|
-
return arr;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* 递归填充计算所有资源路径
|
|
189
|
-
*
|
|
190
|
-
* @author chitanda
|
|
191
|
-
* @date 2022-08-22 22:08:04
|
|
192
|
-
* @protected
|
|
193
|
-
* @param {string} deCodeName
|
|
194
|
-
* @param {string[]} pathNames
|
|
195
|
-
* @param {ServicePathDeep[]} items
|
|
196
|
-
*/
|
|
197
|
-
protected deepFillPath(
|
|
198
|
-
deCodeName: string,
|
|
199
|
-
pathNames: string[],
|
|
200
|
-
items: ServicePathDeep[],
|
|
201
|
-
): void {
|
|
202
|
-
items.forEach(item => {
|
|
203
|
-
const [rs, children] = item;
|
|
204
|
-
if (children.length > 0) {
|
|
205
|
-
this.deepFillPath(
|
|
206
|
-
deCodeName,
|
|
207
|
-
[...pathNames, rs.majorDECodeName!],
|
|
208
|
-
children,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
if (!this.entityRsPathMap.has(deCodeName)) {
|
|
212
|
-
this.entityRsPathMap.set(deCodeName, []);
|
|
213
|
-
}
|
|
214
|
-
const arr = this.entityRsPathMap.get(deCodeName)!;
|
|
215
|
-
|
|
216
|
-
arr.push(
|
|
217
|
-
[
|
|
218
|
-
...pathNames.map(pathName => {
|
|
219
|
-
return {
|
|
220
|
-
codeName: pathName,
|
|
221
|
-
lower: pathName.toLowerCase(),
|
|
222
|
-
plural: pluralLower(pathName),
|
|
223
|
-
};
|
|
224
|
-
}),
|
|
225
|
-
{
|
|
226
|
-
codeName: rs.majorDECodeName!,
|
|
227
|
-
lower: rs.majorDECodeName!.toLowerCase(),
|
|
228
|
-
plural: pluralLower(rs.majorDECodeName!),
|
|
229
|
-
},
|
|
230
|
-
].reverse(),
|
|
231
|
-
);
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* 排序资源路径顺序
|
|
237
|
-
*
|
|
238
|
-
* @author chitanda
|
|
239
|
-
* @date 2022-08-22 22:08:44
|
|
240
|
-
* @protected
|
|
241
|
-
* @param {ServicePathItem[][]} paths
|
|
242
|
-
* @return {*} {ServicePathItem[][]}
|
|
243
|
-
*/
|
|
244
|
-
protected sortPath(paths: ServicePathItem[][]): ServicePathItem[][] {
|
|
245
|
-
return paths.sort((a, b) => {
|
|
246
|
-
return b.length - a.length;
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|