@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/model-helper",
3
- "version": "0.6.0",
3
+ "version": "0.6.1-alpha.2",
4
4
  "description": "控制器包",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -12,12 +12,11 @@
12
12
  },
13
13
  "files": [
14
14
  "dist",
15
- "out",
16
- "src"
15
+ "out"
17
16
  ],
18
17
  "scripts": {
19
18
  "dev": "tsc --watch",
20
- "build": "npm run lint && node ./scripts/build.js && npm run build:rollup && tsc --build",
19
+ "build": "npm run test:run && npm run lint && node ./scripts/build.js && npm run build:rollup && tsc --build",
21
20
  "build:rollup": "rollup -c",
22
21
  "lint": "eslint 'src/**/*.ts'",
23
22
  "lint:fix": "eslint --fix 'src/**/*.ts'",
@@ -33,13 +32,13 @@
33
32
  "author": "chitanda",
34
33
  "license": "MIT",
35
34
  "dependencies": {
36
- "@ibiz/model-core": "^0.1.11",
37
- "@ibiz/rt-model-api": "^0.1.48",
35
+ "@ibiz/model-core": "^0.1.12",
36
+ "@ibiz/rt-model-api": "^0.2.1",
38
37
  "pluralize": "^8.0.0",
39
38
  "ramda": "^0.29.1"
40
39
  },
41
40
  "devDependencies": {
42
- "@ibiz-template/runtime": "^0.6.0",
41
+ "@ibiz-template/runtime": "^0.6.1-alpha.2",
43
42
  "@types/pluralize": "^0.0.33",
44
43
  "@types/ramda": "^0.29.10"
45
44
  },
@@ -47,5 +46,5 @@
47
46
  "@ibiz-template/runtime": "^0.6.0",
48
47
  "ramda": "^0.29.0"
49
48
  },
50
- "gitHead": "fde8aab467f41640a2d9a20bd0237a3d956b69ae"
49
+ "gitHead": "a41c806c321ea5ec6a9b3be23405aeaaba900f98"
51
50
  }
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- import '@ibiz/model-core';
2
- import '@ibiz-template/runtime';
3
-
4
- export * from './model-helper';
5
- export { ModelHelper } from './model-helper';
6
-
7
- declare global {
8
- interface IObject {
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- [key: string | symbol]: any;
11
- }
12
- }
@@ -1,12 +0,0 @@
1
- export const PSSysApp: IModel = {
2
- getAllPSAppDEUIActions: {
3
- New: {
4
- refreshMode: 1,
5
- reloadData: true,
6
- showBusyIndicator: true,
7
- },
8
- Save: {
9
- showBusyIndicator: false,
10
- },
11
- },
12
- };
@@ -1,360 +0,0 @@
1
- import {
2
- IAppCodeList,
3
- IAppDataEntity,
4
- IAppView,
5
- IApplication,
6
- IAppLan,
7
- ISubAppRef,
8
- IAppMenuModel,
9
- IAppMenu,
10
- } from '@ibiz/model-core';
11
- import { DSLHelper } from '@ibiz/rt-model-api';
12
- import { ModelUtil } from './model-util';
13
- import { ModelLoader } from './model-loader';
14
- import { mergeAppMenu, plural } from './utils';
15
-
16
- /**
17
- * 模型加载工具类
18
- *
19
- * @author chitanda
20
- * @date 2023-04-16 17:04:46
21
- * @export
22
- * @class ModelHelper
23
- */
24
- export class ModelHelper {
25
- protected dsl = new DSLHelper();
26
-
27
- /**
28
- * 当前子应用清单
29
- *
30
- * @author chitanda
31
- * @date 2023-12-06 15:12:30
32
- * @protected
33
- * @type {ISubAppRef[]}
34
- */
35
- protected subAppRefs: ISubAppRef[] = [];
36
-
37
- /**
38
- * 模型获取工具类缓存
39
- *
40
- * @author chitanda
41
- * @date 2023-04-16 17:04:56
42
- * @protected
43
- * @type {Map<string, ModelUtil>}
44
- */
45
- protected cache: Map<string, ModelUtil> = new Map();
46
-
47
- /**
48
- * Creates an instance of ModelHelper.
49
- * @author chitanda
50
- * @date 2024-01-08 10:01:20
51
- * @param {(url: string, params?: IParams) => Promise<IModel>} getModel 模型加载方法
52
- * @param {string} defaultAppId 默认应用标识
53
- * @param {boolean} [permission=true] 是否启用权限
54
- */
55
- constructor(
56
- protected getModel: (url: string, params?: IParams) => Promise<IModel>,
57
- protected defaultAppId: string,
58
- protected permission: boolean = true,
59
- ) {
60
- ibiz.hub.registerModelLoaderProvider(new ModelLoader(this));
61
- }
62
-
63
- /**
64
- * 初始化应用内容
65
- *
66
- * @author chitanda
67
- * @date 2023-12-06 17:12:51
68
- * @param {string} [id]
69
- * @return {*} {Promise<boolean>}
70
- */
71
- async initApp(id?: string): Promise<boolean> {
72
- await this.initToHub(id);
73
- return true;
74
- }
75
-
76
- /**
77
- * 初始化具体应用模型工具类
78
- *
79
- * @author chitanda
80
- * @date 2023-04-16 17:04:41
81
- * @param {string} modelTag
82
- * @param {string} [appId=this.defaultAppId]
83
- * @return {*} {Promise<void>}
84
- */
85
- async initModelUtil(
86
- modelTag: string,
87
- appId: string = this.defaultAppId,
88
- ): Promise<void> {
89
- const modelUtil = new ModelUtil(
90
- appId,
91
- modelTag,
92
- this.getModel,
93
- this.defaultAppId === appId,
94
- this.permission,
95
- );
96
- await modelUtil.init();
97
- this.cache.set(appId, modelUtil);
98
- }
99
-
100
- /**
101
- * 初始化模型至Hub中
102
- *
103
- * @author chitanda
104
- * @date 2023-04-17 14:04:55
105
- * @protected
106
- * @param {(string | IObject)} [appId]
107
- * @return {*} {Promise<void>}
108
- */
109
- protected async initToHub(appId?: string | IObject): Promise<void> {
110
- const id: string = this.calcAppId(appId);
111
- const app = ibiz.hub.getApp(id);
112
- const modelUtil = this.getModelUtil(appId);
113
- const appSourceModel = await modelUtil.getAppModel();
114
- // 将引用的视图注册到 hub 清单中,只有主应用才会注册。子应用的注册由主应用在初始化子应用时搞定
115
- if (appSourceModel.getAllPSAppViews && appId === ibiz.env.appId) {
116
- const appViews = appSourceModel.getAllPSAppViews as IModel[];
117
- appViews.forEach(appView => {
118
- ibiz.hub.setAppView(appView.id, appSourceModel.id, appView.priority);
119
- });
120
- }
121
- if (appSourceModel.getDefaultPSAppIndexView) {
122
- const view = appSourceModel.getDefaultPSAppIndexView as IModel;
123
- const name = view.path.split('/').pop().replace('.json', '');
124
- ibiz.hub.defaultAppIndexViewName = name;
125
- }
126
- if (appSourceModel.getAllPSAppCodeLists) {
127
- const codeLists = appSourceModel.getAllPSAppCodeLists as IAppCodeList[];
128
- codeLists.forEach(codeList => {
129
- app.codeList.setCodeList(
130
- this.dsl.appCodeList(codeList) as IAppCodeList,
131
- );
132
- });
133
- }
134
- if (appSourceModel.getAllPSAppDataEntities) {
135
- const dataEntities = appSourceModel.getAllPSAppDataEntities as IModel[];
136
- dataEntities.forEach(dataEntity => {
137
- app.deName2DeCodeName.set(dataEntity.name, dataEntity.codeName);
138
- });
139
- }
140
- // 模型扩展标准视图布局面板
141
- const subViewRefs = app.model.appSubViewTypeRefs || [];
142
- subViewRefs.forEach(item => {
143
- if (item.replaceDefault) {
144
- ibiz.util.layoutPanel.register(
145
- `${item.viewType}_DEFAULT`,
146
- item.viewLayoutPanel!,
147
- );
148
- }
149
- });
150
- // 子应用模型相关处理
151
- {
152
- const { subAppRefs = [] } = app.model;
153
- const { getAllPSSubAppRefs = [] } = appSourceModel;
154
- for (let i = 0; i < subAppRefs.length; i++) {
155
- const subApp = subAppRefs[i];
156
- const sourceSubApp = getAllPSSubAppRefs[i];
157
- // eslint-disable-next-line no-await-in-loop
158
- await this.initSubApp(app, subApp, sourceSubApp);
159
- }
160
- }
161
- }
162
-
163
- /**
164
- * 初始化子应用相关内容
165
- *
166
- * @author chitanda
167
- * @date 2023-12-06 15:12:23
168
- * @protected
169
- * @param {IApplication} app
170
- * @param {ISubAppRef} subApp
171
- * @return {*} {Promise<void>}
172
- */
173
- protected async initSubApp(
174
- app: IApplication,
175
- subApp: ISubAppRef,
176
- sourceSubApp: IModel,
177
- ): Promise<void> {
178
- this.subAppRefs.push(subApp);
179
- const ids = subApp.appViewIds || [];
180
- const views = sourceSubApp.getAllPSAppViews || [];
181
- ids.forEach((id, index) => {
182
- const view = views[index];
183
- ibiz.hub.setAppView(id, subApp.id, view.priority);
184
- });
185
- }
186
-
187
- /**
188
- * 获取应用模型
189
- *
190
- * @author chitanda
191
- * @date 2023-04-16 17:04:13
192
- * @param {(string | IObject)} [appId]
193
- * @return {*} {Promise<IApplication>}
194
- */
195
- async getAppModel(appId?: string | IObject): Promise<IApplication> {
196
- const id: string = this.calcAppId(appId);
197
- if (!this.cache.has(id)) {
198
- const data = ibiz.appData || {};
199
- await this.initModelUtil(data.dynamodeltag, id);
200
- }
201
- const model = await this.getModelUtil(appId).getAppModel();
202
- const app = this.dsl.application(model) as IApplication;
203
- return app;
204
- }
205
-
206
- /**
207
- * 获取应用全局样式
208
- *
209
- * @author chitanda
210
- * @date 2023-09-06 10:09:48
211
- * @param {(string | IObject)} [appId]
212
- * @return {*} {(Promise<string | null>)}
213
- */
214
- getAppStyle(appId?: string | IObject): Promise<string | null> {
215
- return this.getModelUtil(appId).getAppStyle();
216
- }
217
-
218
- /**
219
- * 根据应用实体 codeName 获取应用实体模型
220
- *
221
- * @author chitanda
222
- * @date 2023-04-16 18:04:33
223
- * @param {string} name
224
- * @param {(string | IObject)} [appId]
225
- * @param {boolean} [isId]
226
- * @return {*} {Promise<IAppDataEntity>}
227
- */
228
- async getAppDataEntityModel(
229
- name: string,
230
- appId?: string | IObject,
231
- isId?: boolean,
232
- ): Promise<IAppDataEntity> {
233
- const util = this.getModelUtil(appId);
234
- const model = await util.getAppDataEntityModel(name, isId, true);
235
- const dsl = this.dsl.appDataEntity(model) as IAppDataEntity;
236
- const list = util.servicePathUtil.calcRequestPaths(dsl.id!);
237
- dsl.requestPaths = list;
238
- dsl.codeName2 = plural(dsl.codeName!.toLowerCase());
239
- return dsl;
240
- }
241
-
242
- /**
243
- * 计算应用视图需要合并的子应用模型
244
- *
245
- * @author chitanda
246
- * @date 2023-12-06 16:12:25
247
- * @protected
248
- * @param {IAppView} view
249
- */
250
- protected calcAppViewSubAppModel(view: IAppView): void {
251
- if (view.viewType === 'APPINDEXVIEW') {
252
- if (view.controls) {
253
- view.controls.forEach((ctrl: IAppMenu) => {
254
- if (ctrl.controlType === 'APPMENU') {
255
- ctrl = ctrl as IAppMenuModel;
256
- mergeAppMenu(ctrl, this.subAppRefs);
257
- }
258
- });
259
- }
260
- }
261
- }
262
-
263
- /**
264
- * 根据应用视图 codeName 获取应用视图模型
265
- *
266
- * @author chitanda
267
- * @date 2023-04-16 17:04:38
268
- * @param {string} name
269
- * @param {(string | IObject)} [appId]
270
- * @return {*} {Promise<IAppView>}
271
- */
272
- async getAppViewModel(
273
- name: string,
274
- appId?: string | IObject,
275
- ): Promise<IAppView> {
276
- const model = await this.getModelUtil(appId).getAppViewModel(name);
277
- const dsl = this.dsl.appView(model) as IAppView;
278
- this.calcAppViewSubAppModel(dsl);
279
- return dsl;
280
- }
281
-
282
- /**
283
- * 根据路径和参数加载应用视图模型,主要用于后台根据运行时参数重新计算视图模型
284
- *
285
- * @author chitanda
286
- * @date 2024-01-08 10:01:43
287
- * @param {string} viewId
288
- * @param {IParams} [params]
289
- * @param {string} [appId]
290
- * @return {*} {Promise<IAppView>}
291
- */
292
- async loadAppViewModel(
293
- viewId: string,
294
- params?: IParams,
295
- appId?: string,
296
- ): Promise<IAppView> {
297
- const model = await this.getModelUtil(appId).getAppViewModel(
298
- viewId,
299
- params,
300
- true,
301
- );
302
- const dsl = this.dsl.appView(model) as IAppView;
303
- return dsl;
304
- }
305
-
306
- /**
307
- * 获取应用多语言模型
308
- *
309
- * @author chitanda
310
- * @date 2023-08-24 21:08:17
311
- * @param {string} language
312
- * @param {(string | IObject)} [appId]
313
- * @return {*} {Promise<IAppLan>}
314
- */
315
- async getPSAppLang(
316
- language: string,
317
- appId?: string | IObject,
318
- ): Promise<IAppLan> {
319
- const model = await this.getModelUtil(appId).getPSAppLang(language);
320
- return this.dsl.appLan(model) as IAppLan;
321
- }
322
-
323
- /**
324
- * 获取对应模型工具类
325
- *
326
- * @author chitanda
327
- * @date 2023-04-16 18:04:08
328
- * @protected
329
- * @param {(IObject | string)} context
330
- * @return {*} {ModelUtil}
331
- */
332
- protected getModelUtil(
333
- context: IObject | string = this.defaultAppId,
334
- ): ModelUtil {
335
- const appId: string = this.calcAppId(context);
336
- if (this.cache.has(appId)) {
337
- return this.cache.get(appId)!;
338
- }
339
- throw new Error(`[${appId}]未初始化,请先调用 initModelUtil 方法初始化`);
340
- }
341
-
342
- /**
343
- * 计算应用标识
344
- *
345
- * @author chitanda
346
- * @date 2023-04-16 17:04:19
347
- * @protected
348
- * @param {(IObject | string)} [data=this.defaultAppId]
349
- * @return {*} {string}
350
- */
351
- protected calcAppId(data: IObject | string = this.defaultAppId): string {
352
- let appId: string;
353
- if (typeof data === 'string') {
354
- appId = data;
355
- } else {
356
- appId = (data as { appId: string }).appId;
357
- }
358
- return appId;
359
- }
360
- }
@@ -1,51 +0,0 @@
1
- import { ModelLoaderProvider } from '@ibiz-template/runtime';
2
- import { IApplication, IAppView, IAppDataEntity } from '@ibiz/model-core';
3
- import { ModelHelper } from './model-helper';
4
-
5
- /**
6
- * 模型加载适配器
7
- *
8
- * @author chitanda
9
- * @date 2023-04-17 23:04:44
10
- * @export
11
- * @class ModelLoader
12
- * @implements {ModelLoaderProvider}
13
- */
14
- export class ModelLoader implements ModelLoaderProvider {
15
- constructor(protected helper: ModelHelper) {}
16
-
17
- initApp(id?: string): Promise<boolean> {
18
- return this.helper.initApp(id);
19
- }
20
-
21
- getApp(id?: string): Promise<IApplication> {
22
- return this.helper.getAppModel(id);
23
- }
24
-
25
- getAppView(appId: string, codeName: string): Promise<IAppView> {
26
- return this.helper.getAppViewModel(codeName, appId);
27
- }
28
-
29
- getAppDataEntity(appId: string, id: string): Promise<IAppDataEntity> {
30
- return this.helper.getAppDataEntityModel(id, appId);
31
- }
32
-
33
- getAppDataEntityByCodeName(
34
- appId: string,
35
- codeName: string,
36
- ): Promise<IAppDataEntity> {
37
- return this.helper.getAppDataEntityModel(codeName, appId, false);
38
- }
39
-
40
- getAppStyle(appId: string): Promise<string | null> {
41
- return this.helper.getAppStyle(appId);
42
- }
43
-
44
- loadAppView(
45
- appId: string,
46
- viewId: string,
47
- params: IParams,
48
- ): Promise<IAppView> {
49
- return this.helper.loadAppViewModel(viewId, params, appId);
50
- }
51
- }