@ibiz-template/model-helper 0.4.5 → 0.4.6-dev.0

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.
@@ -1,4 +1,4 @@
1
- import { IAppDataEntity, IAppView, IApplication, IAppLan } from '@ibiz/model-core';
1
+ import { IAppDataEntity, IAppView, IApplication, IAppLan, ISubAppRef } from '@ibiz/model-core';
2
2
  import { DSLHelper } from '@ibiz/rt-model-api';
3
3
  import { ModelUtil } from './model-util';
4
4
  /**
@@ -14,6 +14,15 @@ export declare class ModelHelper {
14
14
  protected defaultAppId: string;
15
15
  protected permission: boolean;
16
16
  protected dsl: DSLHelper;
17
+ /**
18
+ * 当前子应用清单
19
+ *
20
+ * @author chitanda
21
+ * @date 2023-12-06 15:12:30
22
+ * @protected
23
+ * @type {ISubAppRef[]}
24
+ */
25
+ protected subAppRefs: ISubAppRef[];
17
26
  /**
18
27
  * 模型获取工具类缓存
19
28
  *
@@ -32,6 +41,15 @@ export declare class ModelHelper {
32
41
  * @param {boolean} [permission=true] 是否启用权限
33
42
  */
34
43
  constructor(getModel: (url: string) => Promise<IModel>, defaultAppId: string, permission?: boolean);
44
+ /**
45
+ * 初始化应用内容
46
+ *
47
+ * @author chitanda
48
+ * @date 2023-12-06 17:12:51
49
+ * @param {string} [id]
50
+ * @return {*} {Promise<boolean>}
51
+ */
52
+ initApp(id?: string): Promise<boolean>;
35
53
  /**
36
54
  * 初始化具体应用模型工具类
37
55
  *
@@ -52,6 +70,17 @@ export declare class ModelHelper {
52
70
  * @return {*} {Promise<void>}
53
71
  */
54
72
  protected initToHub(appId?: string | IObject): Promise<void>;
73
+ /**
74
+ * 初始化子应用相关内容
75
+ *
76
+ * @author chitanda
77
+ * @date 2023-12-06 15:12:23
78
+ * @protected
79
+ * @param {IApplication} app
80
+ * @param {ISubAppRef} subApp
81
+ * @return {*} {Promise<void>}
82
+ */
83
+ protected initSubApp(app: IApplication, subApp: ISubAppRef): Promise<void>;
55
84
  /**
56
85
  * 获取应用模型
57
86
  *
@@ -81,6 +110,15 @@ export declare class ModelHelper {
81
110
  * @return {*} {Promise<IAppDataEntity>}
82
111
  */
83
112
  getAppDataEntityModel(name: string, appId?: string | IObject, isId?: boolean): Promise<IAppDataEntity>;
113
+ /**
114
+ * 计算应用视图需要合并的子应用模型
115
+ *
116
+ * @author chitanda
117
+ * @date 2023-12-06 16:12:25
118
+ * @protected
119
+ * @param {IAppView} view
120
+ */
121
+ protected calcAppViewSubAppModel(view: IAppView): void;
84
122
  /**
85
123
  * 根据应用视图 codeName 获取应用视图模型
86
124
  *
@@ -1 +1 @@
1
- {"version":3,"file":"model-helper.d.ts","sourceRoot":"","sources":["../src/model-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,OAAO,EACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC;;;;;;;GAOG;AACH,qBAAa,WAAW;IAsBpB,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC;IACpD,SAAS,CAAC,YAAY,EAAE,MAAM;IAC9B,SAAS,CAAC,UAAU,EAAE,OAAO;IAvB/B,SAAS,CAAC,GAAG,YAAmB;IAEhC;;;;;;;OAOG;IACH,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAa;IAEpD;;;;;;;OAOG;gBAES,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC1C,YAAY,EAAE,MAAM,EACpB,UAAU,GAAE,OAAc;IAGtC;;;;;;;;OAQG;IACG,aAAa,CACjB,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,MAA0B,GAChC,OAAO,CAAC,IAAI,CAAC;IAeh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MAAM,GAAG,OAAO,EACxB,IAAI,CAAC,EAAE,OAAO,GACb,OAAO,CAAC,cAAc,CAAC;IAU1B;;;;;;;OAOG;IACH,SAAS,CAAC,sBAAsB,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IA2BtD;;;;;;;;OAQG;IACG,eAAe,CACnB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GACvB,OAAO,CAAC,QAAQ,CAAC;IAOpB;;;;;;;;OAQG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GACvB,OAAO,CAAC,OAAO,CAAC;IAKnB;;;;;;;;OAQG;IACH,SAAS,CAAC,YAAY,CACpB,OAAO,GAAE,OAAO,GAAG,MAA0B,GAC5C,SAAS;IAQZ;;;;;;;;OAQG;IACH,SAAS,CAAC,SAAS,CAAC,IAAI,GAAE,OAAO,GAAG,MAA0B,GAAG,MAAM;CASxE"}
@@ -24,6 +24,15 @@ export class ModelHelper {
24
24
  this.defaultAppId = defaultAppId;
25
25
  this.permission = permission;
26
26
  this.dsl = new DSLHelper();
27
+ /**
28
+ * 当前子应用清单
29
+ *
30
+ * @author chitanda
31
+ * @date 2023-12-06 15:12:30
32
+ * @protected
33
+ * @type {ISubAppRef[]}
34
+ */
35
+ this.subAppRefs = [];
27
36
  /**
28
37
  * 模型获取工具类缓存
29
38
  *
@@ -33,6 +42,19 @@ export class ModelHelper {
33
42
  * @type {Map<string, ModelUtil>}
34
43
  */
35
44
  this.cache = new Map();
45
+ ibiz.hub.registerModelLoaderProvider(new ModelLoader(this));
46
+ }
47
+ /**
48
+ * 初始化应用内容
49
+ *
50
+ * @author chitanda
51
+ * @date 2023-12-06 17:12:51
52
+ * @param {string} [id]
53
+ * @return {*} {Promise<boolean>}
54
+ */
55
+ async initApp(id) {
56
+ await this.initToHub(id);
57
+ return true;
36
58
  }
37
59
  /**
38
60
  * 初始化具体应用模型工具类
@@ -44,12 +66,9 @@ export class ModelHelper {
44
66
  * @return {*} {Promise<void>}
45
67
  */
46
68
  async initModelUtil(modelTag, appId = this.defaultAppId) {
47
- ibiz.hub.registerModelLoaderProvider(new ModelLoader(this));
48
69
  const modelUtil = new ModelUtil(appId, modelTag, this.getModel, this.defaultAppId === appId, this.permission);
49
70
  await modelUtil.init();
50
71
  this.cache.set(appId, modelUtil);
51
- await ibiz.hub.getAppAsync(ibiz.env.appId);
52
- await this.initToHub(appId);
53
72
  }
54
73
  /**
55
74
  * 初始化模型至Hub中
@@ -61,7 +80,8 @@ export class ModelHelper {
61
80
  * @return {*} {Promise<void>}
62
81
  */
63
82
  async initToHub(appId) {
64
- const app = ibiz.hub.getApp(appId);
83
+ const id = this.calcAppId(appId);
84
+ const app = ibiz.hub.getApp(id);
65
85
  const modelUtil = this.getModelUtil(appId);
66
86
  const appSourceModel = await modelUtil.getAppModel();
67
87
  // 将引用的视图注册到 hub 清单中
@@ -95,6 +115,30 @@ export class ModelHelper {
95
115
  ibiz.util.layoutPanel.register(`${item.viewType}_DEFAULT`, item.viewLayoutPanel);
96
116
  }
97
117
  });
118
+ // 子应用模型相关处理
119
+ {
120
+ const { subAppRefs = [] } = app.model;
121
+ subAppRefs.forEach(item => {
122
+ this.initSubApp(app, item);
123
+ });
124
+ }
125
+ }
126
+ /**
127
+ * 初始化子应用相关内容
128
+ *
129
+ * @author chitanda
130
+ * @date 2023-12-06 15:12:23
131
+ * @protected
132
+ * @param {IApplication} app
133
+ * @param {ISubAppRef} subApp
134
+ * @return {*} {Promise<void>}
135
+ */
136
+ async initSubApp(app, subApp) {
137
+ this.subAppRefs.push(subApp);
138
+ const ids = subApp.appViewIds || [];
139
+ ids.forEach(id => {
140
+ ibiz.hub.setAppView(id, subApp.id);
141
+ });
98
142
  }
99
143
  /**
100
144
  * 获取应用模型
@@ -105,6 +149,11 @@ export class ModelHelper {
105
149
  * @return {*} {Promise<IApplication>}
106
150
  */
107
151
  async getAppModel(appId) {
152
+ const id = this.calcAppId(appId);
153
+ if (!this.cache.has(id)) {
154
+ const data = ibiz.appData || {};
155
+ await this.initModelUtil(data.dynamodeltag, id);
156
+ }
108
157
  const model = await this.getModelUtil(appId).getAppModel();
109
158
  const app = this.dsl.application(model);
110
159
  return app;
@@ -139,6 +188,38 @@ export class ModelHelper {
139
188
  dsl.codeName2 = plural(dsl.codeName.toLowerCase());
140
189
  return dsl;
141
190
  }
191
+ /**
192
+ * 计算应用视图需要合并的子应用模型
193
+ *
194
+ * @author chitanda
195
+ * @date 2023-12-06 16:12:25
196
+ * @protected
197
+ * @param {IAppView} view
198
+ */
199
+ calcAppViewSubAppModel(view) {
200
+ if (view.viewType === 'APPINDEXVIEW') {
201
+ if (view.controls) {
202
+ view.controls.forEach((ctrl) => {
203
+ if (ctrl.controlType === 'APPMENU') {
204
+ ctrl = ctrl;
205
+ this.subAppRefs.forEach(subApp => {
206
+ if (subApp &&
207
+ subApp.appMenuModel &&
208
+ subApp.appMenuModel.appMenuItems) {
209
+ if (!ctrl.appMenuItems) {
210
+ ctrl.appMenuItems = [];
211
+ }
212
+ ctrl.appMenuItems = [
213
+ ...ctrl.appMenuItems,
214
+ ...subApp.appMenuModel.appMenuItems,
215
+ ];
216
+ }
217
+ });
218
+ }
219
+ });
220
+ }
221
+ }
222
+ }
142
223
  /**
143
224
  * 根据应用视图 codeName 获取应用视图模型
144
225
  *
@@ -150,7 +231,9 @@ export class ModelHelper {
150
231
  */
151
232
  async getAppViewModel(name, appId) {
152
233
  const model = await this.getModelUtil(appId).getAppViewModel(name);
153
- return this.dsl.appView(model);
234
+ const dsl = this.dsl.appView(model);
235
+ this.calcAppViewSubAppModel(dsl);
236
+ return dsl;
154
237
  }
155
238
  /**
156
239
  * 获取应用多语言模型
@@ -13,6 +13,7 @@ import { ModelHelper } from './model-helper';
13
13
  export declare class ModelLoader implements ModelLoaderProvider {
14
14
  protected helper: ModelHelper;
15
15
  constructor(helper: ModelHelper);
16
+ initApp(id?: string): Promise<boolean>;
16
17
  getApp(id?: string): Promise<IApplication>;
17
18
  getAppView(appId: string, codeName: string): Promise<IAppView>;
18
19
  getAppDataEntity(appId: string, id: string): Promise<IAppDataEntity>;
@@ -1 +1 @@
1
- {"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../src/model-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;GAQG;AACH,qBAAa,WAAY,YAAW,mBAAmB;IACzC,SAAS,CAAC,MAAM,EAAE,WAAW;gBAAnB,MAAM,EAAE,WAAW;IAEzC,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAI1C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI9D,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAIpE,0BAA0B,CACxB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC;IAI1B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAGnD"}
1
+ {"version":3,"file":"model-loader.d.ts","sourceRoot":"","sources":["../src/model-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;GAQG;AACH,qBAAa,WAAY,YAAW,mBAAmB;IACzC,SAAS,CAAC,MAAM,EAAE,WAAW;gBAAnB,MAAM,EAAE,WAAW;IAEzC,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAItC,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAI1C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI9D,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAIpE,0BAA0B,CACxB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC;IAI1B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAGnD"}
@@ -11,6 +11,9 @@ export class ModelLoader {
11
11
  constructor(helper) {
12
12
  this.helper = helper;
13
13
  }
14
+ initApp(id) {
15
+ return this.helper.initApp(id);
16
+ }
14
17
  getApp(id) {
15
18
  return this.helper.getAppModel(id);
16
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/model-helper",
3
- "version": "0.4.5",
3
+ "version": "0.4.6-dev.0",
4
4
  "description": "控制器包",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -29,13 +29,13 @@
29
29
  "author": "chitanda",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "@ibiz/model-core": "^0.0.24",
33
- "@ibiz/rt-model-api": "^0.1.30",
32
+ "@ibiz/model-core": "^0.0.26",
33
+ "@ibiz/rt-model-api": "^0.1.32",
34
34
  "pluralize": "^8.0.0",
35
35
  "ramda": "^0.29.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@ibiz-template/runtime": "^0.4.5",
38
+ "@ibiz-template/runtime": "^0.4.6-dev.0",
39
39
  "@types/pluralize": "^0.0.33",
40
40
  "@types/ramda": "^0.29.9"
41
41
  },
@@ -43,5 +43,5 @@
43
43
  "@ibiz-template/runtime": "^0.4.0",
44
44
  "ramda": "^0.29.0"
45
45
  },
46
- "gitHead": "28b2af793771fa7be9fac2e1c8396081f4002230"
46
+ "gitHead": "b7cde546c542456de87377e49677bdd21b04449d"
47
47
  }
@@ -4,6 +4,9 @@ import {
4
4
  IAppView,
5
5
  IApplication,
6
6
  IAppLan,
7
+ ISubAppRef,
8
+ IAppMenuModel,
9
+ IAppMenu,
7
10
  } from '@ibiz/model-core';
8
11
  import { DSLHelper } from '@ibiz/rt-model-api';
9
12
  import { ModelUtil } from './model-util';
@@ -21,6 +24,16 @@ import { plural } from './utils';
21
24
  export class ModelHelper {
22
25
  protected dsl = new DSLHelper();
23
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
+
24
37
  /**
25
38
  * 模型获取工具类缓存
26
39
  *
@@ -43,7 +56,22 @@ export class ModelHelper {
43
56
  protected getModel: (url: string) => Promise<IModel>,
44
57
  protected defaultAppId: string,
45
58
  protected permission: boolean = true,
46
- ) {}
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
+ }
47
75
 
48
76
  /**
49
77
  * 初始化具体应用模型工具类
@@ -58,7 +86,6 @@ export class ModelHelper {
58
86
  modelTag: string,
59
87
  appId: string = this.defaultAppId,
60
88
  ): Promise<void> {
61
- ibiz.hub.registerModelLoaderProvider(new ModelLoader(this));
62
89
  const modelUtil = new ModelUtil(
63
90
  appId,
64
91
  modelTag,
@@ -68,8 +95,6 @@ export class ModelHelper {
68
95
  );
69
96
  await modelUtil.init();
70
97
  this.cache.set(appId, modelUtil);
71
- await ibiz.hub.getAppAsync(ibiz.env.appId);
72
- await this.initToHub(appId);
73
98
  }
74
99
 
75
100
  /**
@@ -82,7 +107,8 @@ export class ModelHelper {
82
107
  * @return {*} {Promise<void>}
83
108
  */
84
109
  protected async initToHub(appId?: string | IObject): Promise<void> {
85
- const app = ibiz.hub.getApp(appId);
110
+ const id: string = this.calcAppId(appId);
111
+ const app = ibiz.hub.getApp(id);
86
112
  const modelUtil = this.getModelUtil(appId);
87
113
  const appSourceModel = await modelUtil.getAppModel();
88
114
  // 将引用的视图注册到 hub 清单中
@@ -121,6 +147,34 @@ export class ModelHelper {
121
147
  );
122
148
  }
123
149
  });
150
+ // 子应用模型相关处理
151
+ {
152
+ const { subAppRefs = [] } = app.model;
153
+ subAppRefs.forEach(item => {
154
+ this.initSubApp(app, item);
155
+ });
156
+ }
157
+ }
158
+
159
+ /**
160
+ * 初始化子应用相关内容
161
+ *
162
+ * @author chitanda
163
+ * @date 2023-12-06 15:12:23
164
+ * @protected
165
+ * @param {IApplication} app
166
+ * @param {ISubAppRef} subApp
167
+ * @return {*} {Promise<void>}
168
+ */
169
+ protected async initSubApp(
170
+ app: IApplication,
171
+ subApp: ISubAppRef,
172
+ ): Promise<void> {
173
+ this.subAppRefs.push(subApp);
174
+ const ids = subApp.appViewIds || [];
175
+ ids.forEach(id => {
176
+ ibiz.hub.setAppView(id, subApp.id);
177
+ });
124
178
  }
125
179
 
126
180
  /**
@@ -132,6 +186,11 @@ export class ModelHelper {
132
186
  * @return {*} {Promise<IApplication>}
133
187
  */
134
188
  async getAppModel(appId?: string | IObject): Promise<IApplication> {
189
+ const id: string = this.calcAppId(appId);
190
+ if (!this.cache.has(id)) {
191
+ const data = ibiz.appData || {};
192
+ await this.initModelUtil(data.dynamodeltag, id);
193
+ }
135
194
  const model = await this.getModelUtil(appId).getAppModel();
136
195
  const app = this.dsl.application(model) as IApplication;
137
196
  return app;
@@ -173,6 +232,41 @@ export class ModelHelper {
173
232
  return dsl;
174
233
  }
175
234
 
235
+ /**
236
+ * 计算应用视图需要合并的子应用模型
237
+ *
238
+ * @author chitanda
239
+ * @date 2023-12-06 16:12:25
240
+ * @protected
241
+ * @param {IAppView} view
242
+ */
243
+ protected calcAppViewSubAppModel(view: IAppView): void {
244
+ if (view.viewType === 'APPINDEXVIEW') {
245
+ if (view.controls) {
246
+ view.controls.forEach((ctrl: IAppMenu) => {
247
+ if (ctrl.controlType === 'APPMENU') {
248
+ ctrl = ctrl as IAppMenuModel;
249
+ this.subAppRefs.forEach(subApp => {
250
+ if (
251
+ subApp &&
252
+ subApp.appMenuModel &&
253
+ subApp.appMenuModel.appMenuItems
254
+ ) {
255
+ if (!ctrl.appMenuItems) {
256
+ ctrl.appMenuItems = [];
257
+ }
258
+ ctrl.appMenuItems = [
259
+ ...ctrl.appMenuItems,
260
+ ...subApp.appMenuModel.appMenuItems,
261
+ ];
262
+ }
263
+ });
264
+ }
265
+ });
266
+ }
267
+ }
268
+ }
269
+
176
270
  /**
177
271
  * 根据应用视图 codeName 获取应用视图模型
178
272
  *
@@ -187,7 +281,9 @@ export class ModelHelper {
187
281
  appId?: string | IObject,
188
282
  ): Promise<IAppView> {
189
283
  const model = await this.getModelUtil(appId).getAppViewModel(name);
190
- return this.dsl.appView(model) as IAppView;
284
+ const dsl = this.dsl.appView(model) as IAppView;
285
+ this.calcAppViewSubAppModel(dsl);
286
+ return dsl;
191
287
  }
192
288
 
193
289
  /**
@@ -14,6 +14,10 @@ import { ModelHelper } from './model-helper';
14
14
  export class ModelLoader implements ModelLoaderProvider {
15
15
  constructor(protected helper: ModelHelper) {}
16
16
 
17
+ initApp(id?: string): Promise<boolean> {
18
+ return this.helper.initApp(id);
19
+ }
20
+
17
21
  getApp(id?: string): Promise<IApplication> {
18
22
  return this.helper.getAppModel(id);
19
23
  }